Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2014
    Location
    Lisbon
    Posts
    594
    Plugin Contributions
    0

    Default metatags overide using the notifier, to add extra fields from bookx

    Hi
    I'm making some customization on the metatags to incorporate some extra fields related to other module ( bookx )

    I can do this by altering the meta_tags.php ( overinding, etc ), but I was trying to use the notifiers to do it, so I woundt'n need to mess with that file.

    I'm using this notifier

    $zco_notifier->notify('NOTIFY_MODULE_META_TAGS_OVERRIDE', $metatag_page_name, $meta_tags_over_ride, $metatags_title, $metatags_description, $metatags_keywords);

    And this is a example how I'm calling it (?) (I've learn this way)
    Code:
    function __construct() {
    
            global $zco_notifier;
            $notifyme = array();
    
            $notifyme[] = 'NOTIFY_MODULE_META_TAGS_OVERRIDE';
    
            $this->attach($this, $notifyme);
        }  
    
    function update(&$callingClass, $notifier, $paramsArray) {
            if ( $notifier == 'NOTIFY_MODULE_META_TAGS_OVERRIDE' ) {
                $this->tpl_pb_insertMetaTagsFilters($callingClass, $notifier, $paramsArray);
            }
    ok, I've pretty much done all I had to do related to other pages of this modules ( authors, publishers, etc... ) . But to add some more stuff in the products page metatags ( in this case, book fields such as ISBN, etc ), I'm having difficulty, and not sure if this is possible, just using a notifier.

    So I can access the $product_info_metatags, etc, I just can't seen to add stuff to those variables ( title, description, keywords).

    Example ( to add a book subtitle to the meta_products_name :
    PHP Code:
    function tpl_pb_insertMetaTagsFilters(&$callingClass$notifier$paramsArray) {

    global 
    $db$current_page$og_type$og_image$og_title$og_author_books$flag_page$metatags_title$meta_tags_over_ride$metatag_page_name$metatags_keywords$metatags_description;
    global 
    $product_info_metatags$meta_products_name  ,$meta_products_price$meta_products_description;

    switch ( 
    $metatag_page_name ) {

     case 
    'index'

                
    // etc, etc, working ok for other pages! 
     
    break; 

    // FOR THE PRODUCT PAGE 

     
    case (strstr($_GET['main_page'], 'product_') or strstr($_GET['main_page'], 'document_')):

        if ( (isset(
    $_GET['products_id']) && $current_page == 'product_bookx_info' ) ) {
               
           if ( !empty(
    $product_info_metatags->fields['metatags_keywords']) or ! empty($product_info_metatags->fields['metatags_description']) ) {
                        
                        
    $meta_products_name zen_clean_html($meta_products_name $metatag_subtitle);
                        
                    } else {

                        if ( 
    $metatag_subtitle != '' ) {

                            
    $meta_products_name zen_clean_html($meta_products_name $metatag_subtitle);
                        }
                    }

                     
    define('META_TAG_TITLE'str_replace('"','',$review_on $meta_products_name $meta_products_price PRIMARY_SECTION TITLE TAGLINE));
             
          }


    .... but it's not working....
    All I can do for the products page, is to use the other NOTIFY_MODULE_START_META_TAGS, and change the file meta_tags.php directly

    Thanks
    “Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison

  2. #2
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: metatags overide using the notifier

    The scheme of the above is not taking into account all of the other variables that are passed by the notifier.

    Assuming that you wish to keep with the function update instead of updateNotifyModuleMetaTagsOverride (which is supported on ZC 1.5.3 and above, then your update function should have the additional parameters added to it to receive all of the provided variables (again only available in ZC 1.5.3 and above).

    Therefore:
    Code:
    function update(&$callingClass, $notifier, $paramsArray, &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords) {
    
            if ( $notifier == 'NOTIFY_MODULE_META_TAGS_OVERRIDE' ) {
                $this->tpl_pb_insertMetaTagsFilters($callingClass, $notifier, $paramsArray, &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords);
            }
    }
    But, then perhaps the issue really is or also is in the function that is called from there.. For example the use of: $metatag_subtitle... There is no "sharing" of that information, nor do I see where it is populated, so perhaps it is something within the function and it is not executed...

    Further, there is an attempt to redefine the META_TAG_TITLE constant that would have already been assigned within the applicable case statement. Effectively, the only way to be able to define that constant as part of an outside observer is to listen to:

    $zco_notifier->notify('NOTIFY_MODULE_START_META_TAGS', $current_page_base, $metatag_page_name, $meta_tags_over_ride);

    and

    $zco_notifier->notify('NOTIFY_MODULE_META_TAGS_BUILDKEYWORDS', CUSTOM_KEYWORDS, $keywords_string_metatags);

    Otherwise, basically if there are any meta-tags already assigned for the applicable "group" then the constants META_TAG_TITLE, META_TAG_DESCRIPTION, and META_TAG_KEYWORDS would already be defined for that case statement...


    There's a lot going on in the file, and I've provided cursory review/comment. Need to be sure that you are still able to assign/define the item(s) you want depending on the data available and assignments already made. Once a constant is defined, it can not be redefined, therefore if you want to "read" a certain way then it should be assigned before the other code has an opportunity to do so which may involve use of other notifiers.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,486
    Plugin Contributions
    88

    Default Re: metatags overide using the notifier

    Just a minor coding point. Starting with PHP 5.3, a function must be declared to receive its arguments as pass-by-reference; that said, the highlighted code fragment is no longer legal:
    Code:
    function update(&$callingClass, $notifier, $paramsArray, &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords) {
    
            if ( $notifier == 'NOTIFY_MODULE_META_TAGS_OVERRIDE' ) {
                $this->tpl_pb_insertMetaTagsFilters($callingClass, $notifier, $paramsArray, &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords);
            }
    }
    You'll need to revise that to the following, changing the handler's function declaration and removing the reference operator (&) from the four parameters supplied when the function is called:
    Code:
    function update(&$callingClass, $notifier, $paramsArray, &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords) {
    
            if ( $notifier == 'NOTIFY_MODULE_META_TAGS_OVERRIDE' ) {
                $this->tpl_pb_insertMetaTagsFilters($callingClass, $notifier, $paramsArray, $meta_tags_over_ride, $metatags_title, $metatags_description, $metatags_keywords);
            }
    }
    .
    .
    function tpl_pb_insertMetaTagsFilters(&$callingClass, $notifier, $paramsArray,  &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords) {
    See this definition for additional information: http://php.net/manual/en/language.references.pass.php
    Last edited by lat9; 20 Sep 2016 at 05:44 PM. Reason: Added reference

  4. #4
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: metatags overide using the notifier

    Yup and at some point since the near dawn of computers, a dangerous feature of copy and paste has existed...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Aug 2014
    Location
    Lisbon
    Posts
    594
    Plugin Contributions
    0

    Default Re: metatags overide using the notifier

    Hi
    Thanks for the reply. I've try to follow some of your tips , but achieve nothing. I'm simply not at that level.

    I was using a observer to do a lot of stuff, so the update function with all those variables confuses me .... because I dont' know that much.

    Using the NOTIFY_MODULE_START_META_TAGS I can define stuff, but then I need the data from the query $product_info_metatags ( and I can only access it using NOTIFY_MODULE_META_TAGS_OVERRIDE

    I even try to call or pull one into the other, so I could use the info again.... but that's redundant, doens't make much sense, and I failed.

    So I guess I'll stick to what I was doing, that was the use of NOTIFY_MODULE_START_META_TAGS and then add that extra info to the variables present in meta_tags.php file.

    Thanks for the reply's
    “Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison

 

 

Similar Threads

  1. Create Account - modify existing fields or add extra fields?
    By sopretty in forum General Questions
    Replies: 4
    Last Post: 30 Jul 2010, 08:26 PM
  2. Using two modules add extra fields and recaptcha to contact form
    By webmiss in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 22 Feb 2010, 07:43 PM
  3. How to add extra fields in the Write A Review form?
    By oavs in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 5 Dec 2008, 06:08 PM
  4. How do I add extra fields??
    By beetlejuice in forum General Questions
    Replies: 4
    Last Post: 24 Jun 2008, 06:29 PM
  5. Replies: 0
    Last Post: 13 Feb 2008, 04:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR