Forums / Cotonti / Core Labs / set metas from standalone plugin

<<<12

Trustmaster
#16 2009-02-25 22:39
# Orkan :
$output = preg_replace(
'/<meta(.+)name="keywords"([^>]+)>/i', 
'<meta name="keywords" content="'.$my_plugin['meta_keywords'].'" />', 
$output, 1);
This. It's not really a good design to have post-factum overwriting callbacks with regular expressions. It should be avoided if there is a way of assigning data straight into its place.
May the Source be with you!
Orkan
#17 2009-02-26 00:00
Maybe its not the best approach, however much better than disturbing the normal code flow, IMO.
Also, the performance wont hurt that much, since preg_replace() will skip after first match.

Well, for me programming is like a piece of art, but with dervan's solution you're painting someone's portrait a'la Picasso ;-)
Perl - the only language that looks the same before and after RSA encryption.
dervan
#18 2009-02-26 00:41
# Orkan : Well, for me programming is like a piece of art, but with dervan's solution you're painting someone's portrait a'la Picasso ;-)
well at least not Matejko :)

will be other proposals?
need to solve this problem, but not heard of other solutions
Orkan
#19 2009-02-26 01:12
dervan:
no offence, fella
Im only talking about possible programming solution, all the cons and pros and nothing more.
All ideas are welcome!
Perl - the only language that looks the same before and after RSA encryption.
Trustmaster
#20 2009-02-26 01:13
The callback concept is somewhat interesting on its own, further considering the concept of user-defined functions (like sed_parser_custom(), sed_pagination_custom(), etc.). Investigating it even further, you may come up to registering custom handlers, using callbacks instead of hooks and switching to event-driven model. How do you like it?
May the Source be with you!
Orkan
#21 2009-02-26 01:53
Awesome!
I always wonder how to replace the standard plugin->hook system, and this sounds like a million-dollar idea!
If you have more concrete suggestion then go ahead and start a new topic. Im interested!
Perl - the only language that looks the same before and after RSA encryption.
Trustmaster
#22 2009-02-26 02:04
There are several practical solutions known but the drawbacks of choosing callbacks over hooks are already know quite well too:
[list=1]
  • Callbacks are functions. It means that they cannot use variables from global scope implicitly. Which in turn means that plugins need to be changed to use GLOBALS or import the variables they use. Or some other trick if you know it.
  • Callbacks must have been processed by PHP before they are called. It means that mass-loading needs to be performed before the actual request handling is started. It needs to be quite smart not to include files that the current request processing does not require.
  • May the Source be with you!
    dervan
    #23 2009-02-26 04:56
    # Orkan : no offence, fella
    no dust, guy :)


    # Orkan : Im only talking about possible programming solution, ...
    bla bla bla, i see


    =======


    # Kilandor : The only way that moving where header is included would be if a plugin used any data generated by header, which is possible. Then it would completely break it, I truthfully don't know any off hand like this, but it may break future things like a more updated Whoisonline tracking method.

    I can see the reason for moving it, but it doesn't solve all the problems. Also do remember this, we will be getting more advanced hooking methods, so that a hook is only loaded on certain pages/area's. By moving the header all it does is save that hook, and in some cases yes maybe extra processing.

    well

    solution:
    add new hook - standapart

    will change metas from standapart plugin only
    standalone plugin will work as before


    modified code in system/core/plug/plug.inc.php:
    	if (is_array($sed_plugins))
    	{
    		foreach($sed_plugins as $i => $k)
    		{
    			if (($k['pl_hook']=='standapart' || $k['pl_hook']=='standalone') && $k['pl_code']==$e)
    			{ $out['subtitle'] = $k['pl_title']; }
    		}
    	}
    
    	$out['subtitle'] = (empty($L['plu_title'])) ? $out['subtitle'] : $L['plu_title'];
    	$sys['sublocation'] = $out['subtitle'];
    
    	/* ============= */
    
    	$extp0 = array();
    	$extp1 = array();
    
    	if (is_array($sed_plugins))
    	{
    		foreach($sed_plugins as $i => $k)
    		{
    			if ($k['pl_code']==$e)
    			{
    				if ($k['pl_hook']=='standapart')
    				{ $extp0[$i] = $k; }
    				if ($k['pl_hook']=='standalone')
    				{ $extp1[$i] = $k; }
    			}
    		}
    	}
    
    	if (count($extp0)==0 && count($extp1)==0)
    	{
    		header("Location: " . SED_ABSOLUTE_URL . sed_url('message', "msg=907", '', true));
    		exit;
    	}
    
    	$t_plug = new XTemplate($path_skin);
    
    	if (count($extp0)>0)
    	{
    		$extp1 = array(); // disallow standalone hook
    		$t = $t_plug;
    		foreach($extp0 as $k => $pl) { include_once($cfg['plugins_dir'].'/'.$pl['pl_code'].'/'.$pl['pl_file'].'.php'); }
    		unset($t);
    	}
    
    	require_once $cfg['system_dir'] . '/header.php';
    
    	unset($t);
    	$t = $t_plug;
    
    	if (count($extp1)>0)
    	{ foreach($extp1 as $k => $pl) { include_once($cfg['plugins_dir'].'/'.$pl['pl_code'].'/'.$pl['pl_file'].'.php'); } }
    
    	if ($autoassigntags)
    	{
    		$plugin_title = (empty($plugin_title)) ? $L['plu_title'] : $plugin_title;
    
    		if($cfg['homebreadcrumb'])
    		{
    			$bhome = '<a href="'.$cfg['mainurl'].'">'.sed_cc($cfg['maintitle']).'</a> '.$cfg['separator'].' ';
    		}
    		else
    		{
    			$bhome = '';
    		}
    
    		$t-> assign(array(
    			"PLUGIN_TITLE" => $bhome . '<a href="'.sed_url('plug', "e=$e").'">'.$plugin_title."</a>",
    			"PLUGIN_SUBTITLE" => $plugin_subtitle,
    			"PLUGIN_BODY" => $plugin_body
    		));
    	}
    
    	$t->parse("MAIN");
    	$t->out("MAIN");
    	unset($t, $t_plug);
    
    	require_once $cfg['system_dir'] . '/footer.php';
    


    in system/core/admin/admin.plug.inc.php: replace this string
    		$sql3 = sed_sql_query("SELECT pl_code FROM $db_plugins WHERE pl_hook='standalone'");
    
    with
    		$sql3 = sed_sql_query("SELECT pl_code FROM $db_plugins WHERE pl_hook='standapart' OR pl_hook='standalone'");
    


    this code is tested and works
    This post was edited by dervan (2009-02-28 20:53, 15 years ago)
    Kilandor
    #24 2009-02-28 12:33
    Well I see what your doing dervan, its a interesting idea, it would save a header hook everywhere, but as i've said that will be change in the future. But it goes back to exactly what trust was saying, for some people it might cause double processing.

    Maybe we should hold off till then, none of this will be included untill 0.1.0 anyways.

    Here is a idea of how the new Advanced hooking will be improved.
    • Hooks to be allow to be only included on specific areas.
    • Ex, a header hook only included on user.details, or a plugin header hook, only included on plug.php?e=myplugin
    • Timed Hooks, hook is only included on its page, when the time has passed, sorta like a cron.
    • Multi-Hooking, hooking a single php file into multiple area's.

    And maybe more features.

    So it comes down to, do we know any plugins, or possible reasons if we move the header. That could cause problems?

    My thoughts are, it may cause problems with whoisonline.
    It changes the logical flow of things (sorta).

    My only other thought is that, anywhere else outside of standalone, the header.main hook would have to be used anyways. So it would just keep it the same for anything needed.
    Trustmaster
    #25 2009-02-28 14:15
    # Kilandor : Here is a idea of how the new Advanced hooking will be improved.
    • Hooks to be allow to be only included on specific areas.
    • Ex, a header hook only included on user.details, or a plugin header hook, only included on plug.php?e=myplugin
    • Timed Hooks, hook is only included on its page, when the time has passed, sorta like a cron.
    • Multi-Hooking, hooking a single php file into multiple area's.

    And maybe more features.
    It makes me think that we should really try callbacks instead of includes. Pre-include problem most probably has some smart logical solution. But what we need to solve in first place is the scope limitations, otherwise old plugins will become incompatible.

    # Kilandor : So it comes down to, do we know any plugins, or possible reasons if we move the header. That could cause problems?

    My thoughts are, it may cause problems with whoisonline.
    It changes the logical flow of things (sorta).
    No, whosonline is mostly done in common.php. The plugin is just used to display data from sed_online table.
    May the Source be with you!

    <<<12