getCacheLifetime() public method

public getCacheLifetime ( ) : integer
return integer
Example #1
0
/**
 * Campsite render function plugin
 *
 * Type:     function
 * Name:     render
 * Purpose:  template rendering
 *
 * @param array
 *     $p_params
 * @param object
 *     $p_smarty The Smarty object
 *
 * @return
 *     rendered content
 */
function smarty_function_render($p_params, &$p_smarty)
{
    if (empty($p_params['file'])) {
        return null;
    }
    $smarty = CampTemplate::singleton();
    $cache_lifetimeBak = $smarty->cache_lifetime;
    $campsiteVectorBak = $smarty->campsiteVector;
    if (SystemPref::Get('TemplateCacheHandler')) {
        $campsiteVector = $smarty->campsiteVector;
        foreach ($campsiteVector as $key => $value) {
            if (isset($p_params[$key])) {
                if (empty($p_params[$key]) || strtolower($p_params[$key]) == 'off') {
                    $campsiteVector[$key] = null;
                }
                if (is_int($p_params[$key])) {
                    $campsiteVector[$key] = $p_params[$key];
                }
            }
        }
        if (isset($p_params['params'])) {
            $campsiteVector['params'] = $p_params['params'];
        }
        $smarty->campsiteVector = $campsiteVector;
        if (empty($p_params['cache'])) {
            $template = new Template(CampSite::GetURIInstance()->getThemePath() . $p_params['file']);
            $smarty->cache_lifetime = (int) $template->getCacheLifetime();
        } else {
            $smarty->cache_lifetime = (int) $p_params['cache'];
        }
    }
    $smarty->display($p_params['file']);
    $smarty->cache_lifetime = $cache_lifetimeBak;
    $smarty->campsiteVector = $campsiteVectorBak;
}
Example #2
0
/**
 * Campsite render function plugin
 *
 * Type:     function
 * Name:     render
 * Purpose:  template rendering
 *
 * @param array
 *     $p_params
 * @param object
 *     $p_smarty The Smarty object
 *
 * @return
 *     rendered content
 */
function smarty_function_render($p_params, &$p_smarty)
{
    if (empty($p_params['file'])) {
        return null;
    }
    $smarty = clone $p_smarty;
    if (SystemPref::Get('TemplateCacheHandler')) {
        $campsiteVector = $smarty->campsiteVector;
        foreach ($campsiteVector as $key => $value) {
            if (isset($p_params[$key])) {
                if (empty($p_params[$key])) {
                    $campsiteVector[$key] = null;
                }
                if (is_int($p_params[$key])) {
                    $campsiteVector[$key] = $p_params[$key];
                }
            }
        }
        if (isset($p_params['params'])) {
            $campsiteVector['params'] = $p_params['params'];
        }
        $smarty->campsiteVector = $campsiteVector;
        if (empty($p_params['cache'])) {
            $template = new Template($p_params['file']);
            $smarty->cache_lifetime = (int)$template->getCacheLifetime();
        } else {
            $smarty->cache_lifetime = (int)$p_params['cache'];
        }
    }
    return $smarty->display($p_params['file']);

} // fn smarty_function_render
 /**
  * fetch cached content and its modification time from data source
  *
  * @param  string  $id            unique cache content identifier
  * @param  string  $tpl_name      template name
  * @param  string  $cache_id      cache id
  * @param  string  $compile_id    compile id
  * @param  string  $content       cached content
  * @param  integer $mtime         cache modification timestamp (epoch)
  * @param  integer $cacheLifetime cache lifetime in seconds
  * @return void
  */
 protected function fetch($id, $tpl_name, $cache_id, $compile_id, &$content, &$mtime, $cacheLifetime = 0)
 {
     $themesService = \Zend_Registry::get('container')->getService('newscoop_newscoop.themes_service');
     $handler = new $this->cacheClass();
     $expired = $handler->handler('read', $cache_content, $tpl_name, null, null, null);
     if ($cacheLifetime == 0) {
         $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
         $cacheKey = $cacheService->getCacheKey(array('template', $themesService->getThemePath(), $tpl_name), 'template');
         if ($cacheService->contains($cacheKey)) {
             $cacheLifetime = $cacheService->fetch($cacheKey);
         } else {
             $template = new Template($themesService->getThemePath() . $tpl_name);
             $cacheLifetime = (int) $template->getCacheLifetime();
             $cacheService->save($cacheKey, $cacheLifetime);
         }
     }
     if ($expired != false) {
         $content = $cache_content;
         $mtime = $expired - $cacheLifetime;
     }
 }
    /**
     * Renders the document.
     *
     * Displays the document after parsing it.
     *
     * @param array $p_params
     *
     * @return void
     */
    public function render($p_params)
    {
        $siteinfo = array();
        $context = $p_params['context'];
        $template = $p_params['template'];

        $siteinfo['info_message'] = isset($p_params['info_message']) ? $p_params['info_message'] : null;
        $siteinfo['error_message'] = isset($p_params['error_message']) ? $p_params['error_message'] : null;
        $siteinfo['templates_path'] = isset($p_params['templates_dir'])
                            ? $p_params['templates_dir'] : CS_TEMPLATES_DIR;
        $siteinfo['title'] = $this->getTitle();
        $siteinfo['content_type'] = $this->getMetaTag('Content-Type', true);
        $siteinfo['generator'] = $this->getGenerator();
        $siteinfo['keywords'] = $this->getMetaTag('keywords');
        $siteinfo['description'] = $this->getMetaTag('description');

        if (!file_exists(CS_PATH_SITE.DIR_SEP.$siteinfo['templates_path'].DIR_SEP.$template)
                || $template === false) {
            if (empty($template)) {
                $siteinfo['error_message'] = "No template set for display.";
            } else {
                $siteinfo['error_message'] = "The template '$template' does not exist in the templates directory.";
            }
            $template = CS_SYS_TEMPLATES_DIR.DIR_SEP.'_campsite_error.tpl';
            $siteinfo['templates_path'] = CS_TEMPLATES_DIR;
        }

        $tpl = CampTemplate::singleton();
        $tpl->template_dir = $siteinfo['templates_path'];
        $subdir = $this->m_config->getSetting('SUBDIR');
        if (!empty($subdir)) {
            $siteinfo['templates_path'] = substr($subdir, 1) . '/' . $siteinfo['templates_path'];
        }
        $tpl->assign('gimme', $context);
        $tpl->assign('siteinfo', $siteinfo);

        // on template caching add additional info
        if (SystemPref::Get('TemplateCacheHandler')) {
            $uri = CampSite::GetURIInstance();
            $tpl->campsiteVector = $uri->getCampsiteVector();
            $templateObj = new Template($template);
            $tpl->cache_lifetime = (int)$templateObj->getCacheLifetime();
        }

        try {
            $tpl->display($template);
        }
        catch (Exception $ex) {
            CampTemplate::trigger_error($ex->getMessage(), $tpl);
        }
    } // fn render
Example #5
0
    exit;
}

if (!is_writable($filename)) {
    camp_html_add_msg(camp_get_error_message(CAMP_ERROR_WRITE_FILE, $filename));
}

$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$imageExtensions = array("png", "jpg", "jpeg", "jpe", "gif");

$templateDisplayName = $f_name;
if ($templateObj->exists()) {
    $templateDisplayName .= ' ('.getGS("Template ID:").' '.$templateObj->getTemplateId().')';
}

$f_lifetime = (int)$templateObj->getCacheLifetime();

$crumbs = array();
$crumbs[] = array(getGS("Configure"), "");
$crumbs[] = array(getGS("Templates"), "/$ADMIN/templates/");
$crumbs = array_merge($crumbs, camp_template_path_crumbs($f_path));
$crumbs[] = array(getGS("Edit template").": $templateDisplayName", "");
echo camp_html_breadcrumbs($crumbs);

include_once($GLOBALS['g_campsiteDir']."/$ADMIN_DIR/javascript_common.php");

camp_html_display_msgs();

if (in_array($extension, $imageExtensions)) {
    $urlPath = substr($filename, strlen($Campsite['TEMPLATE_DIRECTORY']));
    ?>
 /**
  * Renders the document.
  *
  * Displays the document after parsing it.
  *
  * @param array $p_params
  *
  * @return void
  */
 public function render($p_params)
 {
     $siteinfo = array();
     $context = $p_params['context'];
     $template = $p_params['template'];
     $siteinfo['info_message'] = isset($p_params['info_message']) ? $p_params['info_message'] : null;
     $siteinfo['error_message'] = isset($p_params['error_message']) ? $p_params['error_message'] : null;
     $siteinfo['templates_path'] = isset($p_params['templates_dir']) ? $p_params['templates_dir'] : CS_TEMPLATES_DIR;
     $siteinfo['title'] = $this->getTitle();
     $siteinfo['content_type'] = $this->getMetaTag('Content-Type', true);
     $siteinfo['generator'] = $this->getGenerator();
     $siteinfo['keywords'] = $this->getMetaTag('keywords');
     $siteinfo['description'] = $this->getMetaTag('description');
     $tpl = CampTemplate::singleton();
     $tpl->template_dir = array_unique($tpl->template_dir);
     if (!$template) {
         $siteinfo['error_message'] = "No template set for display.";
     } elseif (!$this->templateExists($template, $tpl)) {
         $siteinfo['error_message'] = "The template '{$template}' does not exist in the templates directory.";
     }
     if (!is_null($siteinfo['error_message'])) {
         $siteinfo['templates_path'] = CS_TEMPLATES_DIR . DIR_SEP . CS_SYS_TEMPLATES_DIR;
         $template = '_campsite_error.tpl';
     }
     $tpl->assign('gimme', $context);
     $tpl->assign('siteinfo', $siteinfo);
     // on template caching add additional info
     if ($tpl->templateCacheHandler) {
         $themesService = \Zend_Registry::get('container')->getService('newscoop_newscoop.themes_service');
         $uri = CampSite::GetURIInstance();
         $smarty = CampTemplate::singleton();
         $tpl->campsiteVector = array_merge($uri->getCampsiteVector(), $smarty->campsiteVector);
         $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
         $cacheKey = $cacheService->getCacheKey(array('template', $themesService->getThemePath(), ltrim($template, '/')), 'template');
         if ($cacheService->contains($cacheKey)) {
             $tpl->cache_lifetime = $cacheService->fetch($cacheKey);
         } else {
             $templateObj = new Template($themesService->getThemePath() . ltrim($template, '/'));
             $tpl->cache_lifetime = (int) $templateObj->getCacheLifetime();
             $cacheService->save($cacheKey, $tpl->cache_lifetime);
         }
     }
     try {
         $tpl->display($template);
     } catch (\Exception $e) {
         // log samrty errors to sentry channel
         $logger = \Zend_Registry::get('container')->get('monolog.logger.sentry');
         $logger->log(\Psr\Log\LogLevel::CRITICAL, 'Uncaught exception', array('exception' => $e));
         CampTemplate::singleton()->trigger_error($e->getMessage(), $tpl);
     }
 }
Example #7
0
/**
 * Campsite render function plugin
 *
 * Type:     function
 * Name:     render
 * Purpose:  template rendering
 *
 * @param array
 *     $p_params
 * @param object
 *     $p_smarty The Smarty object
 *
 * @return
 *     rendered content
 */
function smarty_function_render($p_params, &$p_smarty)
{
    if (empty($p_params['file'])) {
        return null;
    }
    $smarty = CampTemplate::singleton();
    $cache_lifetimeBak = $smarty->cache_lifetime;
    $campsiteVectorBak = $smarty->campsiteVector;
    $cache_statusBak = $smarty->caching;
    if ($smarty->templateCacheHandler) {
        $campsiteVector = $smarty->campsiteVector;
        foreach ($campsiteVector as $key => $value) {
            if (isset($p_params[$key])) {
                if (empty($p_params[$key]) || is_string($p_params[$key]) && strtolower($p_params[$key]) == 'off') {
                    $campsiteVector[$key] = null;
                }
                if (is_int($p_params[$key])) {
                    $campsiteVector[$key] = $p_params[$key];
                }
            }
        }
        if (isset($p_params['params'])) {
            if (is_array($p_params['params'])) {
                $campsiteVector['params'] = '';
                foreach ($p_params['params'] as $key => $value) {
                    $campsiteVector['params'] .= $key . '__' . $value;
                }
            } else {
                $campsiteVector['params'] = $p_params['params'];
            }
        } else {
            $campsiteVector['params'] = null;
        }
        $smarty->campsiteVector = $campsiteVector;
        if (empty($p_params['cache'])) {
            $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
            $themesService = \Zend_Registry::get('container')->getService('newscoop_newscoop.themes_service');
            $cacheKey = $cacheService->getCacheKey(array('template', $themesService->getThemePath(), $p_params['file']), 'template');
            if ($cacheService->contains($cacheKey)) {
                $smarty->cache_lifetime = $cacheService->fetch($cacheKey);
            } else {
                $template = new Template($themesService->getThemePath() . $p_params['file']);
                $smarty->cache_lifetime = (int) $template->getCacheLifetime();
                $cacheService->save($cacheKey, $smarty->cache_lifetime);
            }
        } elseif ($p_params['cache'] == 'off') {
            $smarty->caching = 0;
        } else {
            $smarty->cache_lifetime = (int) $p_params['cache'];
        }
    }
    // add parameters as variables in rendered file
    foreach ($p_params as $key => $value) {
        if ($key != 'params' && $key != 'file') {
            $smarty->assign($key, $value);
        }
    }
    $smarty->display($p_params['file']);
    // clear assigned variables
    foreach ($p_params as $key => $value) {
        if ($key != 'params' && $key != 'file') {
            $smarty->clearAssign($key);
        }
    }
    $smarty->cache_lifetime = $cache_lifetimeBak;
    $smarty->campsiteVector = $campsiteVectorBak;
    $smarty->caching = $cache_statusBak;
}
Example #8
0
             print "\n\t\t<TR $tr_class>";
             print "\n\t\t\t<TD><INPUT TYPE=\"checkbox\" VALUE=\"";
             if ($templateObj->exists()) { p($templateObj->getTemplateId()); } else { putGS("N/A"); }
             print "\" NAME=\"f_template_code[]\" ID=\"checkbox_" . $counter . "\" CLASS=\"input_checkbox\" onclick=\"checkboxClick(this, " . $counter . ");\" /></TD>";
             print "\n\t\t\t<TD><IMG SRC='".$Campsite["ADMIN_IMAGE_BASE_URL"]."/generic.gif' BORDER='0'> $filename</TD>";
         }
         print "\n\t\t\t<td align=\"center\">";
         if ($templateObj->exists()) {
             echo $templateObj->getTemplateId();
         } else {
             putGS("N/A");
         }
         print "</td>";
         print "\n\t\t\t<td align=\"center\">";
         if ($templateObj->exists()) {
             echo $templateObj->getCacheLifetime();
         } else {
             putGS("N/A");
         }
         print "</td>";
         if ($g_user->hasPermission("ManageTempl")){
             print "\n\t\t\t<TD ALIGN=\"CENTER\"><A HREF=\"/".$ADMIN.'/templates/dup.php?Path='.urlencode($listbasedir).'&Name='.urlencode($filename).'"><IMG SRC="'.$Campsite["ADMIN_IMAGE_BASE_URL"].'/duplicate.png" BORDER="0" ALT="'.getGS('Duplicate file').'" TITLE="'.getGS('Duplicate file').'"></A></TD>';
             print "\n\t\t\t<TD ALIGN=\"CENTER\"><A HREF=\"/".$ADMIN.'/templates/rename.php?Path='.urlencode($listbasedir).'&Name='.urlencode($filename).'"><IMG SRC="'.$Campsite["ADMIN_IMAGE_BASE_URL"].'/rename.png" BORDER="0" ALT="'.getGS('Rename file').'" TITLE="'.getGS('Rename file').'"></A?</TD>';
         }
         if ($g_user->hasPermission("DeleteTempl")) {
             print "\n\t\t\t<TD ALIGN=\"CENTER\"><A HREF=\"/".$ADMIN.'/templates/do_del.php?What=1&Path='.urlencode($listbasedir).'&Name='.urlencode($filename).'&'.SecurityToken::URLParameter().'" onclick="return confirm(\''.getGS('Are you sure you want to delete the template object $1 from folder $2?', htmlspecialchars($filename),htmlspecialchars($currentFolder)).'\');"><IMG SRC="'.$Campsite["ADMIN_IMAGE_BASE_URL"].'/delete.png" BORDER="0" ALT="'.getGS('Delete file').'" TITLE="'.getGS('Delete file').'"></A></TD>';
         }
         print "</TR>\n";
         $counter++;
     }
 }