1
frankblack
constants in blocks VS constants in other module files
  • 2009/9/25 22:33

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


Weird title, I know!

Let's assume I have a block of a module with the following define:
define('_BLOCKDEFINE','blockdefine');


Further I have a file of the same module with the following define:
define('_FILEDEFINE','filedefine');


Both, block and file are rendered on the same page.

Now I add another line to the file:
print_r(get_defined_constants());


This function should deliver all defined constants. Here I get _BLOCKDEFINE AND _FILEDEFINE.

Seems to be expected behaviour?

Now I remove
print_r(get_defined_constants());

and put it into the block.

What do you expect now? WRONG! Now I get only _BLOCKDEFINE

??? Any reason for this ???

I always felt that the blocks were a contaminant inside XOOPS and never well integrated. There has always some extra code written to "mimic" functions of normal module files.

It's no deal for me checking now for defines in the "files", but it is strange.

Just curious and hoping for an answer or a solution.

Used version: 2.3.3 and the reason for my question is that I want to put a trigger in a simple manner.

2
ghia
Re: constants in blocks VS constants in other module files
  • 2009/9/26 7:12

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


A possible explaination for this is your theme.html, where the blocks and content are generated.
First the blocks are done, which 'create' the definition of _BLOCKDEFINE. After the blocks, the content is generated, which adds the additional _FILEDEFINE.
By reversing this order in the theme, you can heve both definitions available in the block, but only _FILEDEFINE in the module.

3
frankblack
Re: constants in blocks VS constants in other module files
  • 2009/9/28 10:50

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


Too bad! Is there any (easy) way that blocks / files communicate with each other?

4
ghia
Re: constants in blocks VS constants in other module files
  • 2009/9/28 11:47

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


What should they have to tell to each other?

5
frankblack
Re: constants in blocks VS constants in other module files
  • 2009/9/28 12:02

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


Case 1: Block A is displayed but NOT block B or module file C. All is fine!
Case 2: Block A and B are displayed at the same time. Block B should not use code which is already executed with Block A.
Case 3: Block A and B and module file C are displayed at the same time. Block A and B should not use code which is already executed with module file C.

So I have to set a flag or something. Thought initially that I could use defines.

6
ghia
Re: constants in blocks VS constants in other module files
  • 2009/9/28 12:07

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Quote:
should not use code which is already executed with
Why is that?
What is the code doing?
What is the problem of repeating it?

7
frankblack
Re: constants in blocks VS constants in other module files
  • 2009/9/28 12:23

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


My problem is that several blocks and files are using the same javascript. IF I add the javascript for every block or file the javascript is added over and over again. At some points the javascript will not work properly. Of course I can say "add the javascript files to your theme". Easy but not elegant, because why should javascript be loaded, when in most places it is not used?

So finally I think I have to hack the core a bit to use a setFlag function.

8
ghia
Re: constants in blocks VS constants in other module files
  • 2009/9/28 12:47

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


I think you can use simply a static varible to remember the javascript output, cfr getInstance of textsanitizer.

9
frankblack
Re: constants in blocks VS constants in other module files
  • 2009/9/28 15:12

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


No idea, how to do this, but found another way.

10
frankblack
Re: constants in blocks VS constants in other module files
  • 2009/9/29 13:35

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


Got it working with defines!! ->WRONG!!!

If you want to set a define-flag inside you can just put it inside the function. If you want to set a define-flag inside a module file you have to put it at a place BEFORE header.php from xoopsroot is included. Simple as that! So I can revert using get_included_files.

I just found out accidently, because one module file (before header.php) was working and the other (after header.php) was not working.


Sorry for wasting others peoples time.

Edit: Rubbish! This is NOT working, when you add another block.

Login

Who's Online

174 user(s) are online (90 user(s) are browsing Support Forums)


Members: 0


Guests: 174


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits