Jump to content

Recommended Posts

Posted

Hello :)

 

Can anyone help me to see what Im doing rong?

 

I want to call the controller "AdminLiveChatCount" wen the event "Appcontroller.structure" triggers on "body_end" in "admin" side

 

public function getEvents() {
        return array(
               array(
                   'event' => "Appcontroller.structure",
                   'callback' => array("this", "addCode")
               )
          );
}


public function addCode($event) {

      //$params = $event->getParams();

      $params['controller'] = array("AdminLiveChatCount");
      $params['action'] = "body_end";
      $params['portal'] = "admin";

       $event->setParams($params);
}
 
Posted

Im trying to add the event "Appcontroller.structure" to a plugin "plugins/my_name/my_name_plugin.php" but still cannot run :P

 

I have trie almost everithing but no luck  :wacko:

 

My latest try was:

public function getEvents() {
        return array(
               array(
                   'event' => "Appcontroller.structure",
                   'callback' => array("this", "addCode")
               )
          );
}


public function addCode($event) {

      //$params = $event->getParams();

      $params['controller'] .= array("AdminLiveChatCount");
      $params['action'] .= "body_end";
      $params['portal'] .= "admin";

      $event->setParams($params);

        if (!array_key_exists("body_end", $return))
            $return['body_end'] = null;

        $return['body_end'] .= "<p>Hello World!</p>";

        $event->setReturnVal($return);
}

Any help?  :P

 

Thanks in advance ;)

 

PV

 

Posted

i'm now in the ofice so can't try anything , i need to return  to home to make some test .

 

i hope you can arrive to w worked solution before i lose some hours in test also :)

 

 

lol I will trie :P eheh ;)

Posted

OK now Im finally getting something :)

 

 

in /[my-blesta-folder]/plugins/[myplugin]/myplugin_plugin.php

 

added this in "class MyPlugin extends Plugin {"

	/**
	 * Execute evet on Appcontroller.structure
	 */
    public function getEvents() {
            $this->Events->register("Appcontroller.structure", array($this,'addCode'));
            $event = new EventObject("Appcontroller.structure", array('controller' => 'AdminLiveChatCount', 'action' => 'body_end', 'portal' => 'admin'));
            $this->Events->trigger($event);
    }

	/**
	 * On Appcontroller.structure run this
	 */
    public function addCode($event) {
            $params = $event->getParams(); // get current values
            $params['portal'] = "admin"; // only show on admin
            $params['body_end'] = "<p>Hello World!</p>"; // add code in the body_end

            $event->setReturnVal($params); // set values
            //print_r ($params); //output array
    }

Now it outputs correctly the "Hello World!" on body_end but there is a bug, (I think) because I have specify to only show in "admin" but it output in both "client" and "admin"

 

Any help?

 

thanks in advance,

PV

Posted

hello Paul

 

yesterday night i have arrived to a working soltion solution .. when i return to home this night i will post it . but in general , my solutuon was based in :

 

$params = i used it to just check wich controller or class was loaded (like identifcating the location .

 

then i have made a condition to that url , if the $params match my condition then i use $return['head'] to pass my code to header .

 

so the $params has no effect to sent data , is used just to identificating the controller/class admin/client side wich is loaded .

Posted

i have checked the client/admin side , and i found the same result as you, the return is sent to both admin and client side , even if the condition exist in my code .

so all possibilities i have tried , and i'm now 99% sur the output is not controlled in wich side should returned (admin-client) .

@Cody any explication about this ? or our result is true , then no way now to controle wich side should the output show .

from docs this code should make output to client side only .

$params = $event->getParams(); // get any set data previoslly , to not overide other plugin data

$params['portal'] = "client"; // injest the markup in client side structure

$event->setParams($params); // send array of new params with old and new data .

so is a v3.3 bug

the solution is

$return['admin_head']

$return['admin_body_start']

$return['admin_body_end']

$return['client_head']

$return['client_body_start']

$return['client_body_end']

Posted

Didn't I post how to use this event in another thread?

<?php
class MyPluginPlugin extends Plugin {
 
    ...
 
    public function getEvents() {
        return array(
            array(
                'event' => "Appcontroller.structure",
                'callback' => array("this", "run")
            )
            // Add multiple events here
        );
    }
 
    public function run($event) {
        // Fetch current return val
        $result = $event->getReturnVal();

        $params = $event->getParams();
        
        // Set return val if not set
        if (!isset($result['body_start']))
                $result['body_start'] = null;

        // Update return val -- ONLY set if client portal
        if ($params['portal'] == "client")
            $result['body_start'] .= "<p>your HTML goes here</p>";
        
        // Update return val
        $event->setReturnVal($result);
        
        
    }
}
?>

See Plugin Events. Creating Events.

Posted

Didn't I post how to use this event in another thread?

<?php
class MyPluginPlugin extends Plugin {
 
    ...
 
    public function getEvents() {
        return array(
            array(
                'event' => "Appcontroller.structure",
                'callback' => array("this", "run")
            )
            // Add multiple events here
        );
    }
 
    public function run($event) {
        // Fetch current return val
        $result = $event->getReturnVal();
        
        // Set return val if not set
        if (!isset($result['body_start']))
                $result['body_start'] = null;

        // Update return val
        $result['body_start'] .= "<p>your HTML goes here</p>";
        
        // Update return val
        $event->setReturnVal($result);
        
        
    }
}
?>

See Plugin Events.

 

Hello Cody

 

yes, but the probleme is what i have and PauloV also .

 

we can't specify wich side the output shoud returned (client/admin)

 

now all returned data shown in client/admin side both .

 

theQuestion now is howto display just in client or admin side

Posted

i have checked the client/admin side , and i found the same result as you, the return is sent to both admin and client side , even if the condition exist in my code .

so all possibilities i have tried , and i'm now 99% sur the output is not controlled in wich side should returned (admin-client) .

@Cody any explication about this ? or our result is true , then no way now to controle wich side should the output show .

from docs this code should make output to client side only .

$params = $event->getParams(); // get any set data previoslly , to not overide other plugin data

$params['portal'] = "client"; // injest the markup in client side structure

$event->setParams($params); // send array of new params with old and new data .

 

You're using the params wrong for this event.

Posted

Hello Cody

 

yes, but the probleme is what i have and PauloV also .

 

we can't specify wich side the output shoud returned (client/admin)

 

now all returned data shown in client/admin side both .

 

theQuestion now is howto display just in client or admin side

 

See my updated post.

Posted

back again , yes is working now , i get it working for me yesterday withthe same condition , and ihave already told this toPAulov in my post #12 , but i don't know how i have chende this and it stop working .

Another Question if possible ;

how we can make $this->Base_Uri , $this->view_dir inside the myplugin_plugin.php ? answer this and go to sleep :)

Posted

Just to say Thanks to naja7host and cody for all the help :)

 

We have since this morning optimise all our plugins for Blesta 3.3 :)  now with the new Events is more easier  :)

 

Here is a working sample of what we did in our Blesta Live Chat Plugin:

	/**
	 * Execute evet on Appcontroller.structure
	 */
   public function getEvents() {
        return array(
            array(
                'event' => "Appcontroller.structure",
                'callback' => array("this", "addCode")
            )
            // Add multiple events here
        );
    }

	/**
	 * On Appcontroller.structure run this
	 */
    public function addCode($event) {

        // Fetch current return val
        $result = $event->getReturnVal();

        $params = $event->getParams();

        // Set return val if not set
        if (!isset($result['body_end']))
                $result['body_end'] = null;

        // Set return val if not set
        if (!isset($result['head']))
                $result['head'] = null;

        // Update return val -- ONLY set if client portal
        if ($params['portal'] == "admin")
            $result['body_end'] .= $this->liveChatAdminInclude();
            $result['head'] .= '
<style type="text/css">
<!--
.bchat_badge {
    top: -8px;
    font-size: 10px;
    font-weight: 700;
    float: none !important; position: relative;
    padding: 2px 5px 3px 5px;color: #fff;
    background-image: linear-gradient(#fa3c45, #dc0d17);
    background-image: -webkit-gradient(linear, center top, center bottom, from(#fa3c45), to(#dc0d17));
    background-image: -webkit-linear-gradient(#fa3c45, #dc0d17);
    -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .7);
    box-shadow: 0px 1px 1px rgba(0,0,0,0.7);
    text-shadow: 0px -1px 0px rgba(0,0,0,0.4);
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;border-radius: 10px;
}
-->
</style>
                            ';

        if ($params['portal'] == "client")
            $result['body_end'] .= $this->liveChatClientInclude();

        // Update return val
        $event->setReturnVal($result);
    }

	/**
	 * On Appcontroller.structure add the code to Admin Side
	 */
    public function liveChatAdminInclude() {
        //print_r($GLOBALS);
		$nick = new Record();
		$nick = $nick->select(array("first_name","last_name"))->from("staff")->where("user_id", "=", $GLOBALS['_SESSION']['blesta_staff_id'])->fetch();
        $nick = $nick->{"first_name"}." ".$nick->{"last_name"};

        $blc_include = file_get_contents(PLUGINDIR . DS . "live_chat" . DS . "views" . DS . "default" . DS . "admin_live_chat_include.pdt");
        $blc_include = str_replace("{{base_web}}", WEBDIR.Configure::get("Route.admin")."/", $blc_include);
        $blc_include = str_replace("{{nick}}", $nick, $blc_include);

        return $blc_include;
    }

	/**
	 * On Appcontroller.structure add the code to Client Side
	 */
    public function liveChatClientInclude() {

        $blc_include = file_get_contents(PLUGINDIR . DS . "live_chat" . DS . "views" . DS . "default" . DS . "client_live_chat_include.pdt");
        $blc_include = str_replace("{{base_uri}}", WEBDIR, $blc_include);

        return $blc_include;
    }
  • 2 weeks later...
Posted

Please note that the AppController.structure event has been updated to use arrays instead of strings for head, body_start, body_end in 3.3.0-b2. This is a backwards incompatible change (with 3.3.0-b1).

Please be prepared to update your plugins if your plugins use the AppController.structure event.

 

See CORE-1421 for more info.

Posted

Please note that the AppController.structure event has been updated to use arrays instead of strings for head, body_start, body_end in 3.3.0-b2. This is a backwards incompatible change (with 3.3.0-b1).

Please be prepared to update your plugins if your plugins use the AppController.structure event.

 

See CORE-1421 for more info.

Will Noted , is thier any possibility to make it inject php function ?

something like

$return_val['body_start'][] = my_own_phpfunction($vars);

Note , i mean leave the function intact and run it inside the caller section (head/body_start/body_end) ?

Posted

Will Noted , is thier any possibility to make it inject php function ?

something like

$return_val['body_start'][] = my_own_phpfunction($vars);

Note , i mean leave the function intact and run it inside the caller section (head/body_start/body_end) ?

 

Why would you need that? You can just call your function inside of your plugin.

Posted

i need this to override some varaible in the body , or to set other that are not set in some pages .

 

also i need it to run my own function in the header , i use it for seo analisys ( the preaction event is not given me some info i need , like the title page and some other vars .

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...