Inheritance: extends SmartyBC
示例#1
0
 private function preconfigureSmarty()
 {
     $this->smarty->addTemplateDir(realpath(APPLICATION_PATH . '/../themes/' . $this->themesService->getThemePath()));
     $this->smarty->config_dir = realpath(APPLICATION_PATH . '/../themes/' . $this->themesService->getThemePath() . '_conf');
     // reverse templates dir order
     $this->smarty->setTemplateDir(array_reverse($this->smarty->getTemplateDir()));
 }
/**
 * Campsite set_language function plugin
 *
 * Type:     function
 * Name:     set_language
 * Purpose:
 *
 * @param array
 *     $p_params The English name of the language to be set
 * @param object
 *     $p_smarty The Smarty object
 */
function smarty_function_set_language($p_params, &$p_smarty)
{
    // gets the context variable
    $campsite = $p_smarty->get_template_vars('gimme');

    if (isset($p_params['name'])) {
    	$languageName = $p_params['name'];
    } else {
    	$property = array_shift(array_keys($p_params));
        CampTemplate::singleton()->trigger_error("invalid parameter '$property' in set_language");
    	return false;
    }

    if ($campsite->language->defined
            && $campsite->language->english_name == $languageName) {
        return;
    }

    $languages = Language::GetLanguages(null, null, $languageName);
    if (empty($languages)) {
    	$campsite->language->trigger_invalid_value_error('name', $languageName, $p_smarty);
    	return false;
    }
    $campsite->language = new MetaLanguage($languages[0]->getLanguageId());
} // fn smarty_function_set_language
/**
 * Campsite set_section function plugin
 *
 * Type:     function
 * Name:     set_section
 * Purpose:
 *
 * @param array
 *     $p_params[name] The Name of the section to be set
 *     $p_params[number] The Number of the section to be set
 * @param object
 *     $p_smarty The Smarty object
 */
function smarty_function_set_section($p_params, &$p_smarty)
{
    // gets the context variable
    $campsite = $p_smarty->getTemplateVars('gimme');
    if (isset($p_params['number'])) {
        $attrName = 'number';
        $attrValue = $p_params['number'];
        $sectionNumber = intval($p_params['number']);
    } elseif (isset($p_params['name'])) {
        $sections = Section::GetSections($campsite->publication->identifier, $campsite->issue->number, $campsite->language->number, null, $p_params['name']);
        if (isset($sections[0])) {
            $attrName = 'name';
            $attrValue = $p_params['name'];
            $sectionNumber = intval($sections[0]->getSectionNumber());
        } else {
            $campsite->section->trigger_invalid_value_error($attrName, $attrValue, $p_smarty);
            return false;
        }
    } else {
        $property = array_shift(array_keys($p_params));
        CampTemplate::singleton()->trigger_error("invalid parameter '{$property}' in set_section");
        return false;
    }
    if ($campsite->section->defined && $campsite->section->number == $sectionNumber) {
        return;
    }
    $sectionObj = new MetaSection($campsite->publication->identifier, $campsite->issue->number, $campsite->language->number, $sectionNumber);
    if ($sectionObj->defined) {
        $campsite->section = $sectionObj;
    }
}
 public function indexAction()
 {
     if ($this->_getParam('language')) {
         $gimme = CampTemplate::singleton()->context();
         $gimme->language = MetaLanguage::createFromCode($this->_getParam('language'));
     }
 }
示例#5
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;
}
 /**
  * Processes the input parameters passed in an array; drops the invalid
  * parameters and parameters with invalid values. Returns an array of
  * valid parameters.
  *
  * @param array $p_parameters
  * @return array
  */
 protected function ProcessParameters(array $p_parameters)
 {
     $parameters = array();
     foreach ($p_parameters as $parameter => $value) {
         $parameter = strtolower($parameter);
         switch ($parameter) {
             case 'length':
             case 'columns':
             case 'name':
                 if ($parameter == 'length' || $parameter == 'columns') {
                     $intValue = (int) $value;
                     if ("{$intValue}" != $value || $intValue < 0) {
                         CampTemplate::singleton()->trigger_error("invalid value {$value} of parameter {$parameter} in statement list_article_locations");
                     }
                     $parameters[$parameter] = (int) $value;
                 } else {
                     $parameters[$parameter] = $value;
                 }
                 break;
             default:
                 CampTemplate::singleton()->trigger_error("invalid parameter {$parameter} in list_article_locations", $p_smarty);
         }
     }
     $operator = new Operator('is', 'integer');
     $context = CampTemplate::singleton()->context();
     if (!$context->article->defined) {
         CampTemplate::singleton()->trigger_error("undefined environment attribute 'Article' in statement list_article_locations");
         return array();
     }
     $this->m_constraints[] = new ComparisonOperation('article', $operator, $context->article->number);
     return $parameters;
 }
/**
 * Campsite search_form block plugin
 *
 * Type:     block
 * Name:     search_form
 * Purpose:  Provides a...
 *
 * @param string $p_params
 *
 * @param string $p_content
 *
 * @param string $p_smarty
 *
 *
 * @return string $html
 */
function smarty_block_search_form($p_params, $p_content, &$p_smarty)
{
    if (!isset($p_content)) {
        return '';
    }

    require_once $p_smarty->_get_plugin_filepath('shared','escape_special_chars');

    // gets the context variable
    $campsite = $p_smarty->get_template_vars('gimme');

    $url = $campsite->url;
    $url->uri_parameter = "";
    $template = null;
    if (isset($p_params['template'])) {
        $template = new MetaTemplate($p_params['template']);
        if (!$template->defined()) {
            CampTemplate::singleton()->trigger_error('invalid template "' . $p_params['template']
            . '" specified in the search form');
            return false;
        }
    } elseif (is_numeric($url->get_parameter('tpl'))) {
        $template = $campsite->default_template;
    }
    if (!isset($p_params['submit_button'])) {
        $p_params['submit_button'] = 'Submit';
    }
    if (!isset($p_params['html_code']) || empty($p_params['html_code'])) {
        $p_params['html_code'] = '';
    }
    if (!isset($p_params['button_html_code']) || empty($p_params['button_html_code'])) {
        $p_params['button_html_code'] = '';
    }

    $searchListIdPrefix = $campsite->list_id_prefix('SearchResultsList');
    if (isset($template)) {
        $url->uri_parameter = "template " . str_replace(' ', "\\ ", $template->name);
    }
    $html = "<form name=\"search_articles\" action=\"" . $url->uri_path . "\" method=\"post\" "
    .$p_params['html_code'].">\n";
    if (isset($template)) {
        $html .= "<input type=\"hidden\" name=\"tpl\" value=\"" . $template->identifier . "\" />\n";
    }
    foreach ($campsite->url->form_parameters as $param) {
        if (strncasecmp($param[name], $searchListIdPrefix, strlen($searchListIdPrefix)) == 0) {
            continue;
        }
        if ($param['name'] == 'tpl') {
            continue;
        }
        $html .= '<input type="hidden" name="'.$param['name']
        .'" value="'.htmlentities($param['value'])."\" />\n";
    }
    $html .= $p_content;
    $html .= "<input type=\"submit\" name=\"f_search_articles\" value=\""
    .smarty_function_escape_special_chars($p_params['submit_button'])
    ."\" ".$p_params['button_html_code']." />\n</form>\n";

    return $html;
} // fn smarty_block_search_form
/**
 * Campsite set_topic function plugin
 *
 * Type:     function
 * Name:     set_topic
 * Purpose:
 *
 * @param array
 *     $p_params[name] The Name of the topic to be set
 *     $p_params[identifier] The Identifier of the topic to be set
 * @param object
 *     $p_smarty The Smarty object
 */
function smarty_function_set_topic($p_params, &$p_smarty)
{
    // gets the context variable
    $campsite = $p_smarty->getTemplateVars('gimme');
    if (isset($p_params['identifier'])) {
        $attrName = 'identifier';
        $attrValue = $p_params['identifier'];
        $topicId = intval($p_params['identifier']);
    } elseif (isset($p_params['name'])) {
        $attrName = 'name';
        $attrValue = $p_params['name'];
        $topicService = \Zend_Registry::get('container')->getService('newscoop_newscoop.topic_service');
        $topic = $topicService->getTopicByFullName($p_params['name']);
        if (!is_null($topic) && $topic) {
            $topicId = $topic->getId();
        } else {
            $campsite->topic->trigger_invalid_value_error($attrName, $attrValue, $p_smarty);
            return false;
        }
    } else {
        $property = array_shift(array_keys($p_params));
        CampTemplate::singleton()->trigger_error("invalid parameter '{$property}' in set_topic");
        return false;
    }
    if ($campsite->topic->defined && $campsite->topic->identifier == $topicId) {
        return;
    }
    $topicObj = new MetaTopic($topicId);
    if ($topicObj->defined) {
        $campsite->topic = $topicObj;
    } else {
        $campsite->topic->trigger_invalid_value_error($attrName, $attrValue, $p_smarty);
    }
}
示例#9
0
 protected function convertParameters($firstResult, $parameters)
 {
     $this->criteria->orderBy = array();
     // run default simple parameters converting
     parent::convertParameters($firstResult, $parameters);
     // apply attributes as a filters
     if (array_key_exists('attributes', $parameters)) {
         $this->criteria->attributes = $this->parseConstraintsString($parameters['attributes']);
     }
     // convert your special parameters into criteria properties.
     if (array_key_exists('search', $parameters)) {
         $this->criteria->query = $parameters['search'];
     } elseif (array_key_exists('filter', $parameters)) {
         $filter = $parameters['filter'];
         $this->criteria->groups = !empty($parameters['editor_groups']) ? array_map('intval', explode(',', $parameters['editor_groups'])) : array();
         switch ($filter) {
             case 'active':
                 $this->criteria->orderBy = array('points' => 'desc');
                 $this->criteria->excludeGroups = true;
                 break;
             case 'editors':
                 $this->criteria->excludeGroups = false;
                 break;
             default:
                 $this->criteria->groups = array();
                 // example: filter="a-c"
                 if (preg_match('/([a-z])-([a-z])/', $filter, $matches)) {
                     $this->criteria->nameRange = range($matches[1], $matches[2]);
                 } else {
                     \CampTemplate::singleton()->trigger_error("invalid parameter {$filter} in filter");
                 }
                 break;
         }
     }
 }
示例#10
0
 /**
  * Singleton function that returns the global class object.
  *
  * @return object
  *    CampTemplate
  */
 public static function singleton()
 {
     if (!isset(self::$m_instance)) {
         self::$m_instance = new CampTemplate();
     }
     return self::$m_instance;
 }
/**
 * Campsite set_publication function plugin
 *
 * Type:     function
 * Name:     set_publication
 * Purpose:
 *
 * @param array
 *     $p_params[name] The Name of the publication to be set
 *     $p_params[identifier] The Identifier of the publication to be set
 * @param object
 *     $p_smarty The Smarty object
 */
function smarty_function_set_publication($p_params, &$p_smarty)
{
    // gets the context variable
    $campsite = $p_smarty->getTemplateVars('gimme');
    if (isset($p_params['identifier'])) {
        $attrName = 'identifier';
        $attrValue = $p_params['identifier'];
        $publicationId = intval($p_params['identifier']);
    } elseif (isset($p_params['name'])) {
        $attrName = 'name';
        $attrValue = $p_params['name'];
        $publications = Publication::GetPublications($p_params['name']);
        if (!empty($publications)) {
            $publicationId = $publications[0]->getPublicationId();
        } else {
            $campsite->publication->trigger_invalid_value_error($attrName, $attrValue, $p_smarty);
            return false;
        }
    } else {
        $property = array_shift(array_keys($p_params));
        CampTemplate::singleton()->trigger_error("invalid parameter '{$property}' in set_publication");
        return false;
    }
    if ($campsite->publication->defined && $campsite->publication->identifier == $publicationId) {
        return;
    }
    $publicationObj = new MetaPublication($publicationId);
    if ($publicationObj->defined) {
        $campsite->publication = $publicationObj;
    } else {
        $campsite->publication->trigger_invalid_value_error($attrName, $attrValue, $p_smarty);
    }
}
 public function __construct($publicationId, $userId)
 {
     $this->subscriptions = $this->getSubscriptions(\CampTemplate::singleton()->context()->publication->identifier, \CampTemplate::singleton()->context()->user->identifier);
     if (count($this->subscriptions) == 0) {
         $this->subscriptions = array();
     }
 }
 /**
  * Returns the right operand
  *
  * @return mix
  */
 public function getRightOperand()
 {
     // some values have to be computed
     switch (strtolower($this->m_rightOperand)) {
         case 'now()':
             $this->m_rightOperand = strftime('%Y-%m-%d %H:%M:%S');
             break;
         case 'curdate()':
             $this->m_rightOperand = strftime('%Y-%m-%d');
             break;
         case 'curtime()':
             $this->m_rightOperand = strftime('%H:%M:%S');
             break;
         case 'current()':
             // this value indicates that the left operand have to compared with the value from current context
             // e.g. language_number is current()
             $Context = CampTemplate::singleton()->context();
             $object = strtolower($this->m_leftOperand);
             switch ($object) {
                 case 'language':
                 case 'publication':
                 case 'issue':
                 case 'section':
                 case 'article':
                     $this->m_rightOperand = $Context->{$object}->number;
                     break;
                 case 'publication':
                     $this->m_rightOperand = $Context->{$object}->identifier;
                     break;
             }
             break;
     }
     return $this->m_rightOperand;
 }
示例#14
0
/**
 * Campsite set_issue function plugin
 *
 * Type:     function
 * Name:     set_issue
 * Purpose:
 *
 * @param array
 *     $p_params The number of the issue to be set
 * @param object
 *     $p_smarty The Smarty object
 */
function smarty_function_set_issue($p_params, &$p_smarty)
{
    // gets the context variable
    $campsite = $p_smarty->get_template_vars('gimme');

    if (isset($p_params['number'])) {
    	$issueNumber = intval($p_params['number']);
    } else {
    	$property = array_shift(array_keys($p_params));
        CampTemplate::singleton()->trigger_error("invalid parameter '$property' in set_issue");
    	return false;
    }

    if ($campsite->issue->defined
            && $campsite->issue->number == $issueNumber) {
        return;
    }

    $issueObj = new MetaIssue($campsite->publication->identifier,
                              $campsite->language->number, $issueNumber);
    if ($issueObj->defined) {
        $campsite->issue = $issueObj;
    } else {
    	$campsite->issue->trigger_invalid_value_error('number', $p_params['number'], $p_smarty);
    }
} // fn smarty_function_set_issue
示例#15
0
/**
 * Campsite user_form block plugin
 *
 * Type:     block
 * Name:     user_form
 * Purpose:  Provides a...
 *
 * @param string
 *     $p_params
 * @param string
 *     $p_smarty
 * @param string
 *     $p_content
 *
 * @return
 *
 */
function smarty_block_user_form($p_params, $p_content, &$p_smarty, &$p_repeat)
{
    $p_smarty->smarty->loadPlugin('smarty_function_get_resource_id');
    $resourceId = smarty_function_get_resource_id($p_params, $p_smarty);
    if (!isset($p_content)) {
        return null;
    }
    $p_smarty->smarty->loadPlugin('smarty_shared_escape_special_chars');
    $campsite = $p_smarty->getTemplateVars('gimme');
    $url = $campsite->url;
    $url->uri_parameter = "";
    $template = null;
    if (isset($p_params['template'])) {
        $template = new MetaTemplate($resourceId);
        if (!$template->defined()) {
            CampTemplate::singleton()->trigger_error('invalid template "' . $p_params['template'] . '" specified in the user form');
            return false;
        }
    } elseif (is_numeric($url->get_parameter('tpl'))) {
        $template = $campsite->default_template;
    }
    if (!isset($p_params['submit_button'])) {
        require_once $GLOBALS['g_campsiteDir'] . '/admin-files/localizer/Localizer.php';
        if (!isGS('Submit')) {
            camp_load_translation_strings("globals", $campsite->language->code);
        }
        $p_params['submit_button'] = getGS('Submit');
    }
    if (!isset($p_params['html_code']) || empty($p_params['html_code'])) {
        $p_params['html_code'] = '';
    }
    if (!isset($p_params['button_html_code']) || empty($p_params['button_html_code'])) {
        $p_params['button_html_code'] = '';
    }
    if (isset($template)) {
        $url->uri_parameter = "template " . str_replace(' ', "\\ ", $template->name);
    }
    if ($campsite->user->defined && $campsite->user->subscription->defined) {
        $subsType = $campsite->user->subscription->type == 'T' ? 'trial' : 'paid';
    } else {
        $subsType = null;
    }
    $html = "<form name=\"edit_user\" action=\"" . $url->uri_path . "\" method=\"post\" " . $p_params['html_code'] . ">\n";
    if (!is_null($subsType)) {
        $html .= "<input type=\"hidden\" name=\"f_substype\" value=\"" . $subsType . "\" />\n";
    }
    if (isset($template)) {
        $html .= "<input type=\"hidden\" name=\"tpl\" value=\"" . $template->identifier . "\" />\n";
    }
    foreach ($campsite->url->form_parameters as $param) {
        if ($param['name'] == 'tpl') {
            continue;
        }
        $html .= '<input type="hidden" name="' . $param['name'] . '" value="' . htmlentities($param['value']) . "\" />\n";
    }
    $html .= $p_content;
    $html .= "<input type=\"submit\" name=\"f_edit_user\" value=\"" . smarty_function_escape_special_chars($p_params['submit_button']) . "\" " . $p_params['button_html_code'] . " />\n</form>\n";
    return $html;
}
示例#16
0
 public function getWeekDayName()
 {
     $language = new Language(CampTemplate::singleton()->context()->language->number);
     if (!$language->exists()) {
         return null;
     }
     return $language->getProperty('WDay' . (int) $this->getWeekDay());
 }
示例#17
0
 /**
  * Get enabled state
  * @return boolean
  */
 protected function isEnabled()
 {
     $languageId = (int) CampTemplate::singleton()->context()->language->number;
     if ($this->m_dbObject->isEnabled($languageId)) {
         return true;
     }
     return false;
 }
示例#18
0
 protected function getBiography()
 {
     if (is_null($this->m_biography)) {
         $language = (int) CampTemplate::singleton()->context()->language->number;
         $this->m_biography = new MetaAuthorBiography($this->m_dbObject->getId(), $language);
     }
     return $this->m_biography;
 }
示例#19
0
/**
 * Campsite comment_form block plugin
 *
 * Type:     block
 * Name:     comment_form
 * Purpose:  Displays a form for comment input
 *
 * @param string
 *     $p_params
 * @param string
 *     $p_smarty
 * @param string
 *     $p_content
 *
 * @return
 *
 */
function smarty_block_comment_form($p_params, $p_content, &$p_smarty, &$p_repeat)
{
    if (!isset($p_content)) {
        return '';
    }
    $p_smarty->smarty->loadPlugin('smarty_shared_escape_special_chars');
    $campsite = $p_smarty->getTemplateVars('gimme');
    if (!$campsite->article->comments_enabled) {
        return '';
    }
    $url = $campsite->url;
    $url->uri_parameter = "";
    $template = null;
    if (isset($p_params['template'])) {
        $themePath = $campsite->issue->defined() ? $campsite->issue->theme_path : $campsite->publication->theme_path;
        $template = new MetaTemplate($p_params['template'], $themePath);
        if (!$template->defined()) {
            CampTemplate::singleton()->trigger_error('invalid template "' . $p_params['template'] . '" specified in the comment form');
            return false;
        }
    } elseif (is_numeric($url->get_parameter('tpl'))) {
        $template = $campsite->default_template;
    }
    if (!isset($p_params['submit_button'])) {
        $p_params['submit_button'] = 'Submit';
    }
    $anchor = isset($p_params['anchor']) ? '#' . $p_params['anchor'] : null;
    if (!isset($p_params['html_code']) || empty($p_params['html_code'])) {
        $p_params['html_code'] = '';
    }
    if (!isset($p_params['button_html_code']) || empty($p_params['button_html_code'])) {
        $p_params['button_html_code'] = '';
    }
    if (isset($template)) {
        $url->uri_parameter = "template " . str_replace(' ', "\\ ", $template->name);
    }
    $html = "<form name=\"submit_comment\" action=\"" . $url->uri_path . "{$anchor}\" " . "method=\"post\" " . $p_params['html_code'] . ">\n";
    if (isset($template)) {
        $html .= "<input type=\"hidden\" name=\"tpl\" value=\"" . $template->identifier . "\" />\n";
    }
    foreach ($campsite->url->form_parameters as $param) {
        if ($param['name'] == 'tpl') {
            continue;
        }
        $html .= '<input type="hidden" name="' . $param['name'] . '" value="' . htmlentities($param['value']) . "\" />\n";
    }
    if ($campsite->comment->identifier > 0) {
        $html .= "<input type=\"hidden\" name=\"acid\" " . "value=\"" . $campsite->comment->identifier . "\" />\n";
    }
    $html .= $p_content;
    $html .= "<input type=\"submit\" name=\"f_submit_comment\" " . "id=\"article_comment_submit\" value=\"" . smarty_function_escape_special_chars($p_params['submit_button']) . "\" " . $p_params['button_html_code'] . " />\n";
    if (isset($p_params['preview_button']) && !empty($p_params['preview_button'])) {
        $html .= "<input type=\"submit\" name=\"f_preview_comment\" " . "id=\"article_comment_preview\" value=\"" . smarty_function_escape_special_chars($p_params['preview_button']) . "\" " . $p_params['button_html_code'] . " />\n";
    }
    $html .= "</form>\n";
    return $html;
}
示例#20
0
 protected function getDescription($p_languageId = null)
 {
     if (is_null($p_languageId)) {
         $smartyObj = CampTemplate::singleton();
         $contextObj = $smartyObj->getTemplateVars('gimme');
         $p_languageId = $contextObj->language->number;
     }
     return $this->m_dbObject->getDescription($p_languageId);
 }
示例#21
0
 /**
  * Returns a list of MetaLanguage objects - list of languages in which
  * the issue was translated.
  *
  * @param  boolean $p_excludeCurrent
  * @param  array   $p_order
  * @param  boolean $p_allIssues
  * @return array   of MetaLanguage
  */
 public function languages_list($p_excludeCurrent = true, array $p_order = array(), $p_allIssues = false)
 {
     $languages = $this->m_dbObject->getLanguages(false, $p_excludeCurrent, $p_order, $p_allIssues, !CampTemplate::singleton()->context()->preview);
     $metaLanguagesList = array();
     foreach ($languages as $language) {
         $metaLanguagesList[] = new MetaLanguage($language->getLanguageId());
     }
     return $metaLanguagesList;
 }
示例#22
0
 /**
  *
  */
 public function render()
 {
     $tpl = CampTemplate::singleton();
     $tpl->assign('site_title', $this->m_title);
     $tpl->assign('message', $this->m_message);
     $tpl->assign('package', $this->m_version->getPackage());
     $tpl->assign('version', $this->m_version->getVersion());
     $tpl->assign('release_date', $this->m_version->getReleaseDate());
     $tpl->assign('organization', $this->m_version->getOrganization());
     $tpl->assign('copyright', $this->m_version->getCopyright());
     $tpl->assign('license', $this->m_version->getLicense());
     $tpl->assign('host_os', $this->m_os);
     $tpl->assign('current_step', $this->m_step);
     $tpl->assign('current_step_title', $this->m_steps[$this->m_step]['title']);
     $tpl->assign('step_titles', $this->m_steps);
     $session = CampSession::singleton();
     $config_db = $session->getData('config.db', 'installation');
     $files = array();
     if ($handle = opendir('./sample_templates')) {
         while (false !== ($file = readdir($handle))) {
             if ($file != '.' && $file != '..' && is_dir('./sample_templates/' . $file)) {
                 $files[] = $file;
             }
         }
         closedir($handle);
     }
     $tpl->assign('sample_templates', $files);
     $tpl->assign('overwrite_db', $this->m_overwriteDb);
     $database_conf = dirname(__FILE__) . '/../../conf/database_conf.php';
     if (!empty($config_db)) {
         $tpl->assign('db', $config_db);
     } elseif (file_exists($database_conf)) {
         // use predefined settings
         global $Campsite;
         require_once $database_conf;
         $tpl->assign('db', array('hostname' => $Campsite['db']['host'], 'hostport' => $Campsite['db']['port'], 'username' => $Campsite['db']['user'], 'userpass' => $Campsite['db']['pass'], 'database' => $Campsite['db']['name'], 'predefined' => TRUE));
     } else {
         $tpl->assign('db', array('hostname' => 'localhost', 'username' => 'root', 'database' => 'newscoop', 'hostport' => '', 'userpass' => ''));
     }
     $config_site = $session->getData('config.site', 'installation');
     if (!empty($config_site)) {
         $tpl->assign('mc', $config_site);
     } else {
         $tpl->assign('mc', array('sitetitle' => '', 'adminemail' => ''));
     }
     $config_demo = $session->getData('config.demo', 'installation');
     if (!empty($config_demo)) {
         $tpl->assign('dm', $config_demo);
     } else {
         $tpl->assign('dm', array('loaddemo' => ''));
     }
     $view = new CampInstallationView($this->m_step);
     $tpl->display($this->getTemplateName());
 }
/**
 * Campsite camp_date_format modifier plugin
 *
 * Type:     modifier
 * Name:     camp_date_format
 * Purpose:  format datestamps via MySQL date and time functions
 *
 * @param string
 *     $p_unixtime the date in unixtime format from $smarty.now
 * @param string
 *     $p_format the date format wanted
 *
 * @return
 *     string the formatted date
 *     null in case a non-valid format was passed
 */
function smarty_modifier_camp_date_format($p_unixtime, $p_format = null, $p_onlyEnglish = false)
{
    static $attributes = array('year'=>'%Y', 'mon'=>'%c', 'mday'=>'%e', 'yday'=>'%j',
                        'wday'=>'%w', 'hour'=>'%H', 'min'=>'%i', 'sec'=>'%S',
                        'mon_name'=>'%M', 'wday_name'=>'%W');
    static $specifiersMap = array('%h'=>'%I', '%i'=>'%M', '%s'=>'%S');
    static $conversionMap = array('%M'=>'__month_name__', '%W'=>'__weekday_name__',
                                  '%c'=>'__month__', '%e'=>'__day_of_the_month__',
                                  '%D'=>'__day_of_the_month_suffix__', '%l'=>'__hour_12_clock__');
    static $numberSuffix = array(0=>'th', 1=>'st', 2=>'nd', 3=>'rd', 4=>'th', 5=>'th', 6=>'th',
                                 7=>'th', 8=>'th', 9=>'th');

    if (array_key_exists(trim(strtolower($p_format)), $attributes)) {
        $p_format = $attributes[trim(strtolower($p_format))];
    }

    // gets the context variable
    $campsite = CampTemplate::singleton()->get_template_vars('gimme');

    // makes sure $p_unixtime is unixtime stamp
    $p_unixtime = smarty_make_timestamp($p_unixtime);

    if (is_null($p_format) || empty($p_format)) {
    	return strftime('%D %T', $p_unixtime);
    }

    $p_replaceCount = 0;
    $p_format = str_replace(array_keys($conversionMap), array_values($conversionMap),
    $p_format, $p_replaceCount);

    $p_format = str_replace(array_keys($specifiersMap), array_values($specifiersMap), $p_format);

    $formattedDate = strftime($p_format, $p_unixtime);
    if ($p_replaceCount > 0) {
    	$languageObj = new Language($campsite->language->number);
        if (!$languageObj->exists()) {
            $languageObj = new Language(1);
        }
        $timeArray = getdate($p_unixtime);
        $suffixNo = $timeArray['mday'] % 10;
        $hour = $timeArray['hours'] % 12;
        if ($hour == 0) {
        	$hour = 12;
        }
        $replaceValues = array($languageObj->getProperty('Month'.$timeArray['mon']),
                               $languageObj->getProperty('WDay'.(1+$timeArray['wday'])),
                               $timeArray['mon'],
                               $timeArray['mday'],
                               $timeArray['mday'].$numberSuffix[$suffixNo],
                               $hour);
        $formattedDate = str_replace(array_values($conversionMap), $replaceValues, $formattedDate);
    }
    return $formattedDate;
} // fn smarty_modifier_camp_date_format
示例#24
0
    protected function getValue()
    {
        if (!isset($this->m_dbObject) || !$this->m_dbObject->exists()) {
            return null;
        }

        $language = CampTemplate::singleton()->context()->language;
        $name = $this->m_dbObject->getName($language->number);
        if (empty($name)) {
            return null;
        }
        return $name.':'.$language->code;
    }
示例#25
0
 public function articlesAction()
 {
     $em = \Zend_Registry::get('container')->get('em');
     $topicId = $this->_getParam('id');
     $gimme = CampTemplate::singleton()->context();
     $language = $em->getRepository('Newscoop\\Entity\\Language')->findOneByCode($this->_getParam('language'));
     $query = $em->getRepository('Newscoop\\NewscoopBundle\\Entity\\Topic')->getSingleTopicQuery($topicId, $language->getCode());
     $topic = $query->getOneOrNullResult();
     if (!$topic) {
         throw new \Exception('We can\'t find that topic');
     }
     $gimme->topic = new \MetaTopic($topic->getId());
     $this->view->topic = $gimme->topic;
 }
/**
 * Function to check if user has access to content.
 *
 * @param array  $params
 * @param object $smarty
 *
 * @return string
 */
function smarty_modifier_has_subscription($user, $smarty)
{
    $context = \CampTemplate::singleton()->context();
    $user = $context->user;
    if (!$user) {
        return false;
    }
    $em = \Zend_Registry::get('container')->getService('em');
    $userSubscriptions = $em->getRepository("Newscoop\\PaywallBundle\\Entity\\UserSubscription")->getValidSubscriptionsBy($user->identifier)->getArrayResult();
    $publication = $context->publication;
    $issue = $context->issue;
    $section = $context->section;
    $article = $context->article;
    try {
        foreach ($userSubscriptions as $key => $value) {
            $specification = $value['subscription']['specification'][0];
            if ($value['subscription']['type'] === 'publication' && $publication) {
                if ($specification['publication'] == $publication->identifier) {
                    return true;
                }
            }
            if ($value['subscription']['type'] === 'issue' && $issue) {
                if ($specification['issue'] == $issue->number && $specification['publication'] == $issue->publication->identifier) {
                    return true;
                }
            }
            if ($value['subscription']['type'] === 'section' && $section) {
                if ($specification['section'] == $section->number && $specification['issue'] == $section->issue->number && $specification['publication'] == $issue->publication->identifier) {
                    return true;
                }
            }
            if ($value['subscription']['type'] === 'article' && $article) {
                if ($specification['article'] == $article->number && $specification['publication'] == $article->publication->identifier && $specification['issue'] == $article->issue->number && $specification['section'] == $article->section->number) {
                    return true;
                }
            }
        }
    } catch (\Exception $e) {
        return false;
    }
    return false;
}
/**
 * Campsite set_article function plugin
 *
 * Type:     function
 * Name:     set_article
 * Purpose:
 *
 * @param array
 *     $p_params[name] The Name of the article to be set
 *     $p_params[number] The Number of the article to be set
 * @param object
 *     $p_smarty The Smarty object
 */
function smarty_function_set_article($p_params, &$p_smarty)
{
    // gets the context variable
    $campsite = $p_smarty->get_template_vars('gimme');

    if (isset($p_params['number'])) {
    	$attrName = 'number';
        $attrValue = $p_params['number'];
        $articleNumber = intval($p_params['number']);
    } elseif (isset($p_params['name'])) {
    	$articles = Article::GetByName($p_params['name'],
    								   $campsite->publication->identifier,
    								   $campsite->issue->number,
    								   $campsite->section->number,
    								   $campsite->language->number);
        if (isset($articles[0])) {
        	$attrName = 'name';
        	$attrValue = $p_params['name'];
            $articleNumber = intval($articles[0]->getArticleNumber());
        } else {
	    	$campsite->article->trigger_invalid_value_error($attrName, $attrValue, $p_smarty);
        	return false;
        }
    } else {
    	$property = array_shift(array_keys($p_params));
    	CampTemplate::singleton()->trigger_error("invalid parameter '$property' in set_article");
        return false;
    }

    if ($campsite->article->defined && $campsite->article->number == $attrValue) {
        return;
    }

    $articleObj = new MetaArticle($campsite->language->number, $articleNumber);
    if ($articleObj->defined) {
        $campsite->article = $articleObj;
    } else {
    	$campsite->article->trigger_invalid_value_error($attrName, $attrValue, $p_smarty);
    }
} // fn smarty_function_set_article
示例#28
0
 /**
  */
 public function preDispatch()
 {
     $themesService = \Zend_Registry::get('container')->getService('newscoop_newscoop.themes_service');
     $controller = $this->getActionController();
     $GLOBALS['controller'] = $controller;
     $request = $this->getRequest();
     $format = $request->getParam('format', null);
     if (isset($format) && $format == "json") {
         return;
     }
     if (!in_array($request->getParam('module', 'default'), $this->modules) || !array_key_exists('module', $request->getParams())) {
         return;
     }
     $themePath = $themesService->getThemePath();
     $controller->view = new Newscoop\SmartyView();
     $controller->view->addScriptPath(APPLICATION_PATH . '/views/scripts/')->addScriptPath(realpath(APPLICATION_PATH . "/../themes/{$themePath}"));
     $controller->view->addPath(realpath(APPLICATION_PATH . "/../themes/{$themePath}"));
     $controller->getHelper('viewRenderer')->setView($controller->view)->setViewScriptPathSpec(':controller_:action.:suffix')->setViewSuffix('tpl');
     $controller->getHelper('layout')->disableLayout();
     // reverse templates directory order
     \CampTemplate::singleton()->setTemplateDir(array_reverse(\CampTemplate::singleton()->getTemplateDir()));
 }
示例#29
0
    /**
     * Class constructor
     *
     * @param string $p_uri
     *      The full URI string
     */
    public function __construct($p_uri = null)
    {
        parent::__construct($p_uri);

        $this->setURLType(URLTYPE_SHORT_NAMES);
        $res = $this->setURL();
        if (PEAR::isError($res)) {
            $this->m_validURI = false;
            $this->m_errorCode = $res->getCode();
            if (!is_null($this->m_publication)) {
            	$tplId = CampSystem::GetInvalidURLTemplate($this->m_publication->identifier);
            	$template = new MetaTemplate($tplId);
            	if ($template->defined()) {
            		$this->m_template = $template;
            	}
            }
            CampTemplate::singleton()->trigger_error($res->getMessage());
        } else {
            $this->m_validURI = true;
        }
        $this->validateCache(false);
    } // fn __construct
示例#30
0
 /**
  * Class constructor
  *
  * @param string $p_uri
  *      The full URI string
  */
 public function __construct($p_uri = null)
 {
     parent::__construct($p_uri);
     try {
         $this->setURLType(URLTYPE_SHORT_NAMES);
         $this->setURL($GLOBALS['controller']->getRequest());
         $this->m_validURI = true;
         $this->validateCache(false);
     } catch (Exception $e) {
         $this->m_validURI = false;
         $this->m_errorCode = $e->getCode();
         if (!is_null($this->m_publication)) {
             $tplId = CampSystem::GetInvalidURLTemplate($this->m_publication->identifier, null, null, !$this->m_preview);
             $themePath = $this->getThemePath();
             $tplId = substr($tplId, strlen($themePath));
             $template = new MetaTemplate($tplId, $themePath);
             if ($template->defined()) {
                 $this->m_template = $template;
             }
         }
         CampTemplate::singleton()->trigger_error($e->getMessage());
     }
 }