We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

how to use weblog_entries_tagdata

Development and Programming

bhw1's avatar
bhw1
43 posts
16 years ago
bhw1's avatar bhw1

ok so the block from the docs is

if (isset($EXT->extensions['weblog_entries_tagdata']))
{
    $tagdata = $EXT->call_extension('weblog_entries_tagdata', $tagdata, $row);
    echo 'tagdata: '.$tagdata;
    if ($EXT->end_script === TRUE) return $edata;
}

I am using it like

function set_content($tagdata, $row, $callback){
    global $EXT;
    if (isset($EXT->extensions['weblog_entries_tagdata']))
    {
        $tagdata = $EXT->call_extension('weblog_entries_tagdata', $tagdata, $row);
        echo 'tagdata: '.$tagdata;
        if ($EXT->end_script === TRUE) return $edata;
    }
}

Few questions, the docs have it passing “$this” is that required (its not showing in the syntax example, where do I access it? Clearly you cant use that in your own class so is there a standard var that should be used in its content? Where the heck is “$edata” coming from or being set?

I am assuming my code should simply pass the data thru the method unmolested yet when I use it my the content is blank so I assume I am not passing something correctly.

I also cant find much info on the correct use of call_extension(). The data is getting passed into my method set_content() fine, how do I return it? Is that what call_extension does? If not how do I pass the data back? Should $EXT->call_extension return something? I check it and its either a Boolean or blank.

back to pulling out my hair…

Moved to Extensions: Technical Assistance by Moderator

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
16 years ago
Sue Crocker's avatar Sue Crocker

Hi, bhw1. This sort of question is more appropriate in one of the Extension forums. I’m going to move it there for additional community interaction.

       
bhw1's avatar
bhw1
43 posts
16 years ago
bhw1's avatar bhw1

fair enough, if anyone knows of an ext that uses this hook that’s all I would prob need. I’m sure its just how I am using it.

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Have you had a look at the Extension Development docs? They do not contain a specific example with this hook, but it might give you a good handle on the overview.

This might make it click for you:

function set_content($tagdata, $row)
{
    return 'Hello world! - {title}<hr >';
}

Keep in mind that if other extensions are registered to this hook, you’ll want to make sure they work together nicely (this is covered in the docs linked above, too):

function set_content($tagdata, $row)
{
    global $EXT;
    
    $tagdata = ($EXT->last_call !== FALSE) ? $EXT->last_call : $tagdata;
    $tagdata .= 'Modified!';
    return $tagdata;
}
       
bhw1's avatar
bhw1
43 posts
16 years ago
bhw1's avatar bhw1

I did read over that a few times. I guess my confusion is in “$EXT->call_extension” and its use in the doc. I see now all I had to do was return data for it to work. Why is the “$EXT->call_extension” in the doc example used. Or better question when should I be using it.

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Sorry for the confusion, I assume you are meaning the code shown here. That is a reference to the extension hook in the application code, so that you can see at a glance what arguments are sent, and what the return data will impact. You will not need to use any of the Extension class methods in your code; the $last_call and $end_script properties are the only possible things you may need to access from that class, the rest is handled internally.

       
bhw1's avatar
bhw1
43 posts
16 years ago
bhw1's avatar bhw1

Thanks for your help Derek,

I finally have a working solution. However it does not seem as dynmatic as it could be. Thoughts on a better way to handle the set_content() are welcome and I hope the code can help anyone else in my shoes on day.

<?php  if ( ! defined('EXT')) exit('No direct script access allowed');
/**
 * Multi Language for Bayshore content
 *
 * This class swaps {zone1_en} for the correct language as defined in $_SESSION['multi_lang']
 */
 
class Multilang {

    var $settings        = array();
    var $name            = 'Multi Language Ext';
    var $version        = '1.0';
    var $description    = 'Controls the custom field output.';
    var $settings_exist    = 'n';
    var $docs_url        = 'http://ryanmills.net/';

    /**
     * Constructor
     */
    function Multilang($settings = '')
    {
    
    }
    
    
    /**
     * Register hooks by adding them to the database
     */
    function activate_extension()
    {
        global $DB;

        // default settings
        $settings =    array();

        $hook = array(
                        'extension_id'    => '',
                        'class'            => __CLASS__,
                        'method'        => 'set_content',
                        'hook'            => 'weblog_entries_tagdata',
                        'settings'        => serialize($settings),
                        'priority'        => 1,
                        'version'        => $this->version,
                        'enabled'        => 'y'
                    );
    
        $DB->query($DB->insert_string('exp_extensions',    $hook));
    }
    
    // --------------------------------------------------------------------
    
    /**
     * No updates yet.
     * Manual says this function is required.
     * @param string $current currently installed version
     */
    function update_extension($current = '')
    {
        global $DB, $EXT;

        if ($current < '1.0')
        {
            $query = $DB->query("SELECT settings FROM exp_extensions WHERE class = '".$DB->escape_str(__CLASS__)."'");
            
            $this->settings = unserialize($query->row['settings']);
            
            $DB->query($DB->update_string('exp_extensions', array('settings' => serialize($this->settings), 'version' => $this->version), array('class' => __CLASS__)));
        }
        
        return TRUE;
    }
    
    // --------------------------------------------------------------------
    
    /**
     * Uninstalls extension
     */
    function disable_extension()
    {
        global $DB;
        $DB->query("DELETE FROM exp_extensions WHERE class = '".__CLASS__."'");
    }
    
    // --------------------------------------------------------------------
    
    /**
     * EE extension settings
     * @return array
     */
    function settings()
    {
        $settings = array();
        return $settings;
    }
    
    // --------------------------------------------------------------------
    
    /**
     * Set Content
     * @return string
     */
    function set_content($tagdata, $row, $callback){
        global $EXT;
        # init sessions if its not started
        if (session_id() == "") 
        {
            session_start(); 
        }
        
        # Define the default lang
        if( !isset($_GET['set_lang']) ){
            $_GET['multi_lang'] = 'en';
        }
        
        # Make sure no one tries to set a bad lang type.
        if( isset( $_GET['set_lang'] ) ){
            
            if($_GET['set_lang'] == 'en'){
                $_SESSION['multi_lang'] = 'en';
            }
            
            if($_GET['set_lang'] == 'ru'){
                $_SESSION['multi_lang'] = 'ru';
            }
            
            if($_GET['set_lang'] == 'es'){
                $_SESSION['multi_lang'] = 'es';
            }
        }
        
        if (isset($EXT->extensions['weblog_entries_tagdata']))
        {    
            if( $tagdata == '{zone1_en}' ){
                switch($_SESSION['multi_lang']){
                    case 'en':
                        $edata = $row['field_id_4']; // english content
                        break;
                        
                    case 'ru':
                        $edata = $row['field_id_5']; // russian content
                        break;
                        
                    case 'es':
                        $edata = $row['field_id_6']; // spanish content
                        break;
                    
                    default:
                        $edata = $row['field_id_4']; // default english content
                }
                return $edata;
            }
        }
        
    }

}
?>
       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones
if (isset($EXT->extensions['weblog_entries_tagdata']))
 {    
     if( $tagdata == '{zone1_en}' ){
         switch($_SESSION['multi_lang']){
             case 'en':
                 $edata = $row['field_id_4']; // english content
                 break;
                 
             case 'ru':
                 $edata = $row['field_id_5']; // russian content
                 break;
                 
             case 'es':
                 $edata = $row['field_id_6']; // spanish content
                 break;
             
             default:
                 $edata = $row['field_id_4']; // default english content
         }
         return $edata;
     }
 }

You needn’t worry if that array key is set, if it’s not, your code will not be executed. I was thinking something more like this:

switch($_SESSION['multi_lang'])
{
    case 'ru':
        $tagdata = str_replace(LD.'zone1_en'.RD, LD.'zone1_ru'.RD, $tagdata);
        break;       
    case 'es':
        $tagdata = str_replace(LD.'zone1_en'.RD, LD.'zone1_es'.RD, $tagdata);
        break;
    case 'en':
    default:
        break;
}

return $tagdata;

Basically, just switching out the English template variable with the appropriate custom field variable from that weblog based on the language setting. The rest of the weblog module’s entry parsing routine will handle the rest.

Also, you could move the _SESSION language setting logic to an earlier extension hook (like those in the EE Session class), so that it’s available to this and all other methods you may need to use it for.

       
bhw1's avatar
bhw1
43 posts
16 years ago
bhw1's avatar bhw1

Thought i replied to this but i guess i helps to hit submit 😊

Anyway thanks for your help, and I see your point about the changes and have made them.

-Ryan

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.