Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty 3.0 problem after updating from 3.0RC4

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Glazz
Smarty Rookie


Joined: 02 Sep 2009
Posts: 7

PostPosted: Fri Nov 12, 2010 6:31 am    Post subject: Smarty 3.0 problem after updating from 3.0RC4 Reply with quote

Hi,

My admin panel is giving me this error after i updated to 3.0.

http://awesomescreenshot.com/02b3fd0e5

Where is the error should be an included page...



Edit:

I found out some errors...
Code:
Strict Standards: Declaration of Skin::display() should be compatible with that of Smarty::display() in E:\Web\www\projectos\Fusephase\sistema\libs\class.skin.php on line 18

Strict Standards: Declaration of Skin::ClearCache() should be compatible with that of Smarty::clearCache() in E:\Web\www\projectos\Fusephase\sistema\libs\class.skin.php on line 18



Here is my class...
Code:


/* ------------------------------------------------------------------------------ *
 | Incluir a class do Smarty.
 * ------------------------------------------------------------------------------ */
   require_once(DIR . 'sistema/libs/Smarty/Smarty.class.php');


/* ------------------------------------------------------------------------------ *
 | Class: Skin();
 * ------------------------------------------------------------------------------ */
class Skin extends Smarty
{
   function __construct($Config)
   {
      parent::__construct();
      
      $this->debugging       = $Config['TPL_debug'];
      
      $this->template_dir    = DIR . 'skins/';
      $this->cache_dir       = DIR . 'sistema/cache/skins/' . SITE_AREA;
      $this->compile_dir     = DIR . 'sistema/cache/skins/' . SITE_AREA;
      $this->left_delimiter     = '{{';
      $this->right_delimiter    = '}}';
      
      $this->caching          = $Config['TPL_cache'];
      $this->cache_lifetime    = $Config['TPL_cache_lifetime'];
      //$this->compile_check    = $Config['TPL_compile_check'];
      $this->force_compile    = $Config['TPL_force_compile'];
       
       
   }


   function display($tpl, $to_screen = true)
   {
      if ($to_screen == true) {
         parent::display($tpl);
      } else {
         return $this->fetch($tpl);
      }
   }


   function ClearCache()
   {
      // clear out all cache files
      $this->clear_all_cache();   
   }
}
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Nov 12, 2010 2:24 pm    Post subject: Reply with quote

Regarding your error on Admin Panel:

You must always delete existing compiled and cached template files after an update of Smarty because of possible internal changes to these files.

The second is the behaviour of PHP. If you extend a Class and use parent:: calls your method and the parent method must have same parameter declartion. Otherwise you get errors when E_STRICT is in the error reporting level.
Back to top
View user's profile Send private message
Glazz
Smarty Rookie


Joined: 02 Sep 2009
Posts: 7

PostPosted: Fri Nov 12, 2010 3:29 pm    Post subject: Reply with quote

Ohh i get it, i've removed the old cached/compiled files and it worked..

With the class i dind't knew about that, changed names of the functions and now works very well Wink
Back to top
View user's profile Send private message
voodoonet
Smarty n00b


Joined: 27 Jul 2015
Posts: 2

PostPosted: Mon Jul 27, 2015 6:45 pm    Post subject: Reply with quote

Hello,
Since I upgraded to php5.6 I have the following errors:
Declaration of pnRender::clear_cache() should be compatible with Smarty::clear_cache

Declaration of pnRender::is_cached() should be compatible with Smarty::is_cache

Declaration of pnRender::fetch() should be compatible with Smarty::fetch

But I don't know how to fix them...
Can someone help?

voodoo
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Jul 27, 2015 7:09 pm    Post subject: Reply with quote

Your pnRender class should have the same parameter declarations as in the Smarty class for the mentioned methods.

If not you get the reported errors when the E_STRICT error level is enabled.
Since PHP 5.4.0 E_STRICT became part of E_ALL error level.

But you should better fix the parameter declarations in the pnRender methods.
Back to top
View user's profile Send private message
voodoonet
Smarty n00b


Joined: 27 Jul 2015
Posts: 2

PostPosted: Tue Jul 28, 2015 7:47 am    Post subject: Reply with quote

Hello,
Thanks a lot for your reply.
But I don't really know how to fix the parameters declaration...
Can you explain me more?
Here is the class I guess.

Code:

class pnRender extends Smarty {
    /**
     * The module for wich the object is for
     */
    var $module;

    /**
     * The cache ID of the object
     */
    var $cache_id;

    /**
     * Set if Xanthia is an active module and templates stored in database
     */
    var $userdb;

    /**
     * true if admins wants to expose the template folder, needs admin rights for pnRender too
     */
    var $expose_template;

    /**
     * The class constructor.
     *
     * This function also tries to load a file called usemodules
     * which it expects in the calling modules pntemplates/config
     * folder.
     * This file contains lines like
     *
     * ---snip---
     * module1
     * module2
     * module3
     * ---snap---
     *
     * These modules plugins folders will be added to the plugins_dir
     * array to let a module use plugins from another module.
     *
     * If the usemodules file is not available we do not throw an
     * error message because this might be the usual case for
     * simple templates.
     *
     * @param   string   $module   The module for which this object is for
     */
    function pnRender($module = '')
    {
        // first, get a native Smarty object
        $this->Smarty();

        // Initialize the module property with the name of
        // the topmost module. Foor Hooks, Blocks, API Functions and others
        // you need to set this property to the name of the respective module!
        if (!$module) {
            $module = pnModGetName();
        }
        $this->module = $module;

        // begin holder tag (be nice to others)
        $this->left_delimiter = '<!--[';
        // end holder tag
        $this->right_delimiter = ']-->';

        //---- Plugins handling -----------------------------------------------
        // add the global PostNuke plugins directory
      if (is_dir('system/pnRender/plugins')) {
           array_push($this->plugins_dir, 'system/pnRender/plugins');
      } else if (is_dir('modules/pnRender/plugins')) {
           array_push($this->plugins_dir, 'modules/pnRender/plugins');
      }

        // add the global PostNuke plugins directory
        $modinfo = pnModGetInfo(pnModGetIDFromName('Xanthia'));
        $modpath = ($modinfo['type'] == 3) ? 'system' : 'modules';
        array_push($this->plugins_dir, "$modpath/$modinfo[directory]/plugins");

// uncomment for .8 until modtype=3 for system modules is implemented
        array_push($this->plugins_dir, "system/$modinfo[directory]/plugins");

        // add module specific plugins directories, if they exist
        $theme = pnUserGetTheme();
        $themepath = "themes/$theme/templates/modules/$module/plugins";
        if (file_exists($themepath)) {
            array_push($this->plugins_dir, $themepath);
        }

        $modinfo = pnModGetInfo(pnModGetIDFromName($module));
        $modpath = ($modinfo['type'] == 3) ? 'system' : 'modules';
        $mod_plugs = "$modpath/$modinfo[directory]/pntemplates/plugins";
        // build the path to the config file for usemodules needed later
        $usemod_conf = "$modpath/$modinfo[directory]/pntemplates/config/usemodules";
        if (file_exists($mod_plugs)) {
            array_push($this->plugins_dir, $mod_plugs);
        }

        // add theme specific plugins directories, if they exist
        $themepath = "themes/$theme/plugins";
        if (file_exists($themepath)) {
            array_push($this->plugins_dir, $themepath);
        }

// uncomment for .8 until modtype=3 for system modules is implemented
        $modpath = 'system';
        $mod_plugs = "$modpath/$modinfo[directory]/pntemplates/plugins";
        if (file_exists($mod_plugs)) {
            array_push($this->plugins_dir, $mod_plugs);
        }

        // load the config file
        if( file_exists($usemod_conf) && is_readable($usemod_conf)) {
            $additionalmodules = file($usemod_conf);
            if(is_array($additionalmodules)) {
                foreach($additionalmodules as $addmod) {
                    $this->_add_plugins_dir(trim($addmod));
                }
            }
        }

        // check if the recent 'type' parameter in the URL is admin and if yes,
        // include (modules|system)/Admin/pntemplates/plugins to the plugins_dir array
        $type = pnVarCleanFromInput('type');
        if(!empty($type) && $type=='admin') {
            array_push($this->plugins_dir, "modules/Admin/pntemplates/plugins");
            array_push($this->plugins_dir, "system/Admin/pntemplates/plugins");
        }

        //---- Cache handling -------------------------------------------------
        // use HTML cache system?
        $this->caching = pnModGetVar('pnrender', 'cache');
        $this->cache_lifetime = pnModGetVar('pnrender', 'lifetime');

        // HTML cache directory
        $this->cache_dir = pnConfigGetVar('temp') . '/pnRender_cache';

        //---- Compilation handling -------------------------------------------
        // check for updated templates?
        $this->compile_check = pnModGetVar('pnrender', 'compile_check');

        // force compile template always?
        $this->force_compile = pnModGetVar('pnrender', 'force_compile');

        // safe_mode?
        // This routine is taken from PostCalendar.
      // we don't need this code anymore due to change below
        //$safe_mode     = ini_get('safe_mode');
        //$safe_mode_gid = ini_get('safe_mode_gid');
        //$open_basedir  = ini_get('open_basedir');

        // don't use subdirectories when creating compiled/cached templates
      // this works better in a hosted environment
        $this->use_sub_dirs = false;
        //$this->use_sub_dirs = !((bool)$safe_mode ||
       //                      (bool)$safe_mode_gid ||
        //                      !empty($open_basedir));

        // cache directory (compiled templates)
        $this->compile_dir = pnConfigGetVar('temp') . '/pnRender_compiled';

        // compile id
        $this->compile_id = $this -> module . '|' . $theme . '|' . pnUserGetLang();

        // initialize the cache ID
        $this->cache_id = '';

        // expose templates
        $this->expose_template = (pnModGetVar('pnrender', 'expose_template') == true) ? true : false;

        if (pnModAvailable('Xanthia')){
            $this->userdb = 'userdb';
        }

        $this->register_block('nocache', 'pnRender_block_nocache', false);
    }

    /**
     * Checks whether requested template exists.
     *
     * @param string $template
     */
    function template_exists($template)
    {
        return (bool)$this->get_template_path($template);
    }

    /**
     * Checks which path to use for required template
     *
     * @param string $template
     */
    function get_template_path($template)
    {
      // the current module
        $pnmodgetname = pnModGetName();

        // get the module path to templates
        $module  = $this->module;
        $modinfo = pnModGetInfo(pnModGetIDFromName($module));

        // get the theme path to templates
        $theme = pnUserGetTheme();

        // prepare the values for OS
        $os_pnmodgetname = pnVarPrepForOS($pnmodgetname);
        $os_module       = pnVarPrepForOS($module);
        $os_modpath      = pnVarPrepForOS($modinfo['directory']);
        $os_theme        = pnVarPrepForOS($theme);

        // Define the locations in which we will look for templates
        // (in this order)
      // Note: Paths 1, 3, 5 - This allows for the hook or block functions
        // (such as ratings and comments) to use different templates depending
        // on the top level module. e.g. the comments dialog can be different
        // for news  and polls...
        // They are only evaluated when the calling module is not the current one.
        //
      // 1. The top level module directory in the requested module folder
      // in the theme directory.
      $themehookpath = "themes/$theme/templates/modules/$module/$pnmodgetname";
      // 2. The module directory in the current theme.
        $themepath = "themes/$theme/templates/modules/$module";
      // 3. The top level module directory in the requested module folder
      // in the modules sub folder.
      $modhookpath = "modules/$modinfo[directory]/pntemplates/$pnmodgetname";
      // 4. The module directory in the modules sub folder.
        $modpath = "modules/$modinfo[directory]/pntemplates";
      // 5. The top level module directory in the requested module folder
      // in the system sub folder.
        $syshookpath = "system/$modinfo[directory]/pntemplates/$pnmodgetname";
      // 6. The module directory in the system sub folder.
        $syspath = "system/$modinfo[directory]/pntemplates";

        $ostemplate = pnVarPrepForOS($template); //.'.htm';

        // check the module for which we're looking for a template is the
      // same as the top level mods. This limits the places to look for
      // templates.
      if ($module == $pnmodgetname) {
            $search_path = array($themepath,
                                 $modpath,
                                 $syspath);
      } else {
            $search_path = array($themehookpath,
                                 $themepath,
                                 $modhookpath,
                                 $modpath,
                                 $syshookpath,
                                 $syspath);
      }

       foreach ($search_path as $path) {
            if (file_exists("$path/$ostemplate") && is_readable("$path/$ostemplate")) {
              return $path;
          }
        }

        // when we arrive here, no path was found
        return false;
    }

    /**
     * executes & returns the template results
     *
    * This returns the template output instead of displaying it.
    * Supply a valid template name.
    * As an optional second parameter, you can pass a cache id.
    * As an optional third parameter, you can pass a compile id.
     *
     * @param   string   $template    the name of the template
     * @param   string   $cache_id    (optional) the cache ID
     * @param   string   $compile_id  (optional) the compile ID
    * @return  string   the template output
     */
    function fetch($template, $cache_id=null, $compile_id=null)
    {
        $this->_setup_template($template);

      if (!is_null($cache_id)) {
         $cache_id = $this->module . '|' . $cache_id;
      } else {
         $cache_id = $this->module . '|' . $this->cache_id;
      }

        $output = parent::fetch($template, $cache_id, $compile_id);

        if($this->expose_template == true) {
            $output = "\n<!-- begin of ".$this->template_dir."/$template -->\n"
                    . $output
                    . "\n<!-- end of ".$this->template_dir."/$template -->\n";
        }

        return $output;
    }

    /**
     * executes & displays the template results
     *
    * This displays the template.
    * Supply a valid template name.
    * As an optional second parameter, you can pass a cache id.
    * As an optional third parameter, you can pass a compile id.
     *
     * @param   string   $template    the name of the template
     * @param   string   $cache_id    (optional) the cache ID
     * @param   string   $compile_id  (optional) the compile ID
    * @return  void
     */
    function display($template, $cache_id=null, $compile_id=null)
    {
        echo $this->fetch($template, $cache_id, $compile_id);
    }

    /**
     * finds out if a template is already cached
    *
     * This returns true if there is a valid cache for this template.
    * Right now, we are just passing it to the original Smarty function.
    * We might introduce a function to decide if the cache is in need
    * to be refreshed...
    *
     * @param   string   $template    the name of the template
     * @param   string   $cache_id    (optional) the cache ID
    * @return  boolean
     */
    function is_cached($template, $cache_id=null)
    {
        // insert the condition to check the cache here!
        // if (functioncheckdb($this -> module)) {
        //        return parent :: clear_cache($template, $this -> cache_id);
        //}
       $this->_setup_template($template);

      if ($cache_id) {
         $cache_id = $this->module . '|' . $cache_id;
      } else {
         $cache_id = $this->module . '|' . $this->cache_id;
      }

        return parent::is_cached($template, $cache_id);
    }

    /**
     * clears the cache for a specific template
    *
     * This returns true if there is a valid cache for this template.
    * Right now, we are just passing it to the original Smarty function.
    * We might introduce a function to decide if the cache is in need
    * to be refreshed...
    *
     * @param   string   $template    the name of the template
     * @param   string   $cache_id    (optional) the cache ID
     * @param   string   $compile_id  (optional) the compile ID
     * @param   string   $expire      (optional) minimum age in sec. the cache file must be before it will get cleared.
    * @return  boolean
     */
    function clear_cache($template, $cache_id=null, $compile_id=null, $expire=null)
    {
      if ($cache_id) {
         $cache_id = $this->module . '|' . $cache_id;
      } else {
         $cache_id = $this->module . '|' . $this->cache_id;
      }
        // the cache ID must not end on a |
        $cache_id = preg_replace('/\|$/', '', $cache_id);

        return parent::clear_cache($template, $cache_id, $compile_id, $expire);
    }

    /**
     * clear the entire contents of cache (all templates)
     *
     * Smarty's original clear_all_cache function calls the subclasse's
     * clear_cache function. As we always prepend the module name, this
     * doesn't work here...
     *
     * @param string $exp_time expire time
     * @return boolean results of {@link smarty_core_rm_auto()}
     */
    function clear_all_cache($exp_time = null)
    {
        return parent::clear_cache(null, null, null, $exp_time);
    }

    /**
     * set up paths for the template
     *
     * This function sets the template and the config path according
     * to where the template is found (Theme or Module directory)
     *
     * @param   string   $template   the template name
     * @access  private
     */
    function _setup_template($template)
    {
        // default directory for templates
        $this->template_dir = $this->get_template_path($template);
      //echo $this->template_dir . '<br>';
        $this->config_dir   = $this->template_dir . '/config';
    }

    /**
     * add a plugins dir to _plugin_dir array
     *
     * This function takes  module name and adds two path two the plugins_dir array
     * when existing
     *
     * @param   string   $module    well known module name
     * @access  private
     */
    function _add_plugins_dir( $module )
    {
        $modinfo = pnModGetInfo(pnModGetIDFromName($module));
        $modpath = ($modinfo['type'] == 3) ? 'system' : 'modules';
        $mod_plugs = "$modpath/$modinfo[directory]/pntemplates/plugins";
        if (file_exists($mod_plugs)) {
            array_push($this->plugins_dir, $mod_plugs);
        }

// uncomment for .8 until modtype=3 for system modules is implemented
        $modpath = 'system';
        $mod_plugs = "$modpath/$modinfo[directory]/pntemplates/plugins";
        if (file_exists($mod_plugs)) {
            array_push($this->plugins_dir, $mod_plugs);
        }
    }

    /**
     * add core data to the template
     *
     * This function adds some basic data to the template depending on the
     * current user and the PN settings.
     *
     * @param   list of module names. all mod vars of these modules will be included too
                The mod vars of the current module will always be included
     * @return  boolean true if ok, otherwise false
     * @access  public
     */
    function add_core_data()
    {
        $pncore = array();
        $pncore['version_num'] = _PN_VERSION_NUM;
        $pncore['version_id'] = _PN_VERSION_ID;
        $pncore['version_sub'] = _PN_VERSION_SUB;
        $pncore['logged_in'] = pnUserLoggedIn();
        $pncore['language'] = pnUserGetLang();
        $pncore['themeinfo'] = pnThemeInfo(pnUserGetTheme());

       pnThemeLoad($pncore['themeinfo']['name']);
      $colors = array();
        $colors['bgcolor1'] = pnThemeGetVar('bgcolor1');
        $colors['bgcolor2'] = pnThemeGetVar('bgcolor2');
        $colors['bgcolor3'] = pnThemeGetVar('bgcolor3');
        $colors['bgcolor4'] = pnThemeGetVar('bgcolor4');
        $colors['bgcolor5'] = pnThemeGetVar('bgcolor5');
        $colors['sepcolor'] = pnThemeGetVar('sepcolor');
        $colors['textcolor1'] = pnThemeGetVar('textcolor1');
        $colors['textcolor2'] = pnThemeGetVar('textcolor2');

        // add userdata
        $pncore['user'] = pnUserGetVars(pnSessionGetVar('uid'));

        // add modvars of current module
        $pncore[$this->module] = pnModGetVar($this->module);

        // add mod vars of all modules supplied as parameter
       foreach (func_get_args() as $modulename) {
           // if the modulename is empty do nothing
           if(!empty($modulename) && !is_array($modulename) && ($modulename<>$this->module)) {
                // check if user wants to have /PNConfig
                if($modulename==_PN_CONFIG_MODULE) {
                    $pnconfig = pnModGetVar(_PN_CONFIG_MODULE);
                    foreach($pnconfig as $key => $value) {
                        // unserialize all config vars
                      $pncore['pnconfig'][$key] = @unserialize($value);
                    }
                } else {
                    $pncore[$modulename] = pnModGetVar($modulename);
                }
            }
        }

        $this->assign('pncore', $pncore);
      $this->assign($colors);
        return true;
    }

}
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jul 28, 2015 3:00 pm    Post subject: Reply with quote

I think you still run Smarty 2, right?

Anyway the methods of your pnRender class should have the same number of parameter and the same default values as the corresponding parent methods of the Smarty class.
pnRender::clear_cache($template=null, $cache_id=null, $compile_id=null, $expire=nulll)

pnRender::is_cached($template, $cache_id = null, $compile_id = null)

pnRender::fetch($template, $cache_id=null, $compile_id=null, $display = false)

Also the next upcoming higher PHP versions like PHP 7 require that you use the __construct() method as constructor.

So pnRender::pnRender() must become pnRender::__construct()
and it must call parent::__construct() instead of $this->Smarty();

The update of Smarty 2 to Smarty::__construct() is already here https://github.com/smarty-php/smarty/tree/v2.6.29
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP