/**
  * @return void
  */
 private function _processCaptcha()
 {
     @session_start();
     $captchaHandler = CampRequest::GetVar('f_captcha_handler', '', 'POST');
     if (!empty($captchaHandler)) {
         $captcha = Captcha::factory($captchaHandler);
         if (!$captcha->validate()) {
             $this->m_error = new PEAR_Error('The code you entered is not the same as the one shown.',
             ACTION_SUBMIT_COMMENT_ERR_INVALID_CAPTCHA_CODE);
             return FALSE;
         }
     } else {
         $f_captcha_code = CampRequest::GetVar('f_captcha_code');
         if (is_null($f_captcha_code) || empty($f_captcha_code)) {
             $this->m_error = new PEAR_Error('Please enter the code shown in the image.',
             ACTION_SUBMIT_COMMENT_ERR_NO_CAPTCHA_CODE);
             return FALSE;
         }
         if (!PhpCaptcha::Validate($f_captcha_code, true)) {
             $this->m_error = new PEAR_Error('The code you entered is not the same with the one shown in the image.',
             ACTION_SUBMIT_COMMENT_ERR_INVALID_CAPTCHA_CODE);
             return FALSE;
         }
     }
     return TRUE;
 }
/**
 * Campsite camp_select function plugin
 *
 * Type:     function
 * Name:     camp_select
 * Purpose:  Provides a...
 *
 * @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_function_camp_select($p_params, &$p_smarty)
{
    global $g_ado_db;

    require_once $p_smarty->_get_plugin_filepath('function','html_options');

    if (!isset($p_params['object']) || !isset($p_params['attribute'])) {
        return;
    }
    if (!isset($p_params['html_code']) || empty($p_params['html_code'])) {
        $p_params['html_code'] = '';
    }

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

    $object = strtolower($p_params['object']);
    $attribute = strtolower($p_params['attribute']);
    $selectTag = false;

    switch($object) {
    case 'user':
        $fieldValue = CampRequest::GetVar('f_user_'.$attribute);
        if ($attribute == 'gender') {
            if (is_null($fieldValue)) {
                $fieldValue = $campsite->user->$attribute;
            }
            $html = '<input type="radio" name="f_user_'.$attribute
                .'" value="M" '.(($fieldValue == 'M') ? 'checked' : '').' '
                . $p_params['html_code'] . '/> '
                .smarty_function_escape_special_chars($p_params['male_name'])
                .' <input type="radio" name="f_user_'.$attribute
                .'" value="F" '.(($fieldValue == 'F') ? 'checked' : '').' '
                . $p_params['html_code'] . ' /> '
                .smarty_function_escape_special_chars($p_params['female_name']);
        } elseif ($attribute == 'title') {
        	require_once($GLOBALS['g_campsiteDir'] . '/admin-files/localizer/Localizer.php');
        	if (!isGS('Mr.')) {
        		camp_load_translation_strings("users", $campsite->language->code);
        	}
        	if (is_null($fieldValue)) {
                $fieldValue = $campsite->user->$attribute;
            }
            $selectTag = true;
            $output = array(getGS('Mr.'), getGS('Mrs.'), getGS('Ms.'), getGS('Dr.'));
            $values = array('Mr.', 'Mrs.', 'Ms.', 'Dr.');
            $html = '<select name="f_user_'.$attribute.'" ' . $p_params['html_code'] . '>';
        } elseif ($attribute == 'country') {
            if (is_null($fieldValue)) {
                $fieldValue = $campsite->user->country_code;
            }
            $sqlQuery = 'SELECT Code, Name FROM Countries '
                       .'GROUP BY Code ASC ORDER BY Name ASC';
            $data = $g_ado_db->GetAll($sqlQuery);
            foreach($data as $country) {
                $output[] = $country['Name'];
                $values[] = $country['Code'];
            }
            $selectTag = true;
            $html = '<select name="f_user_'.$attribute.'" ' . $p_params['html_code'] . '>';
        } elseif ($attribute == 'age') {
            if (is_null($fieldValue)) {
                $fieldValue = $campsite->user->$attribute;
            }
            $selectTag = true;
            $output = array('0-17', '18-24', '25-39', '40-49', '50-65', '65 or over');
            $values = array('0-17', '18-24', '25-39', '40-49', '50-65', '65-');
            $html = '<select name="f_user_'.$attribute.'" ' . $p_params['html_code'] . '>';
        } elseif ($attribute == 'employertype') {
        	require_once($GLOBALS['g_campsiteDir'] . '/admin-files/localizer/Localizer.php');
        	if (!isGS('Corporate')) {
        		camp_load_translation_strings("users", $campsite->language->code);
        	}
        	if (is_null($fieldValue)) {
                $fieldValue = $campsite->user->$attribute;
            }
            $selectTag = true;
            $output = array(getGS('Corporate'), getGS('Non-Governmental'), getGS('Government Agency'), getGS('Academic'), getGS('Media'), getGS('Other'));
            $values = array('Corporate', 'NGO', 'Government Agency', 'Academic', 'Media', 'Other');
            $html = '<select name="f_user_'.$attribute.'" ' . $p_params['html_code'] . '>';
        } elseif (substr($attribute, 0, 4) == 'pref') {
            if (is_null($fieldValue)) {
                $fieldValue = $campsite->user->$attribute;
            }
            $html = '<input type="checkbox" name="f_user_'.$attribute.'" '
                .(($attrValue == 'Y') ? ' value="on" checked />' : ' />')
                .'<input type="hidden" name="f_has_pref'
                .substr($attribute, 4, 1).'" value="1" ' . $p_params['html_code'] . ' />';
        }
        break;

    case 'login':
        if ($attribute == 'rememberuser') {
            if (is_null($fieldValue)) {
                $fieldValue = $campsite->user->$attribute;
            }
            $html = '<input type="checkbox" name="f_login_'.$attribute.'" '
            . $p_params['html_code'] . ' />';
        }
        break;

    case 'subscription':
    	$subsType = strtolower(CampRequest::GetVar('SubsType'));
    	if ($subsType != 'trial' && $subsType != 'paid') {
    		return null;
    	}
    	if ($attribute == 'languages') {
            $publicationLanguages = $campsite->publication->languages_list(false);
            foreach ($publicationLanguages as $language) {
                $output[] = $language->name;
                $values[] = $language->number;
            }
            $selectTag = true;
            $html = '<select name="subscription_language[]" multiple size="3" ';
            if ($subsType == 'paid') {
                $html .= 'onchange="update_subscription_payment();" ';
            }
            $html .= 'id="select_language" ' . $p_params['html_code'] . '>';
        } elseif ($attribute == 'alllanguages') {
        	$html = '<input type="checkbox" name="subs_all_languages" '
                .'onchange="ToggleElementEnabled(\'select_language\');';
            if ($subsType == 'paid') {
                $html .= ' update_subscription_payment();';
            }
            $html .= '" ' . $p_params['html_code'] . ' />';
        } elseif ($attribute == 'section') {
            if ($campsite->subs_by_type == 'publication') {
                $html = '<input type="hidden" name="cb_subs[]" value="'
                    .$campsite->section->number.'" />';
            } elseif ($campsite->subs_by_type == 'section') {
                $html = '<input type="checkbox" name="cb_subs[]" value="'
                    .$campsite->section->number.'" '
                    .'onchange="update_subscription_payment();" '
                    . $p_params['html_code'] . ' />';
            }
        }
        break;

    case 'search':
        if ($attribute == 'mode') {
            $html = '<input type="checkbox" name="f_match_all" '
            . $p_params['html_code'] . ' />';
        } elseif ($attribute == 'level') {
        	require_once($GLOBALS['g_campsiteDir'] . '/admin-files/localizer/Localizer.php');
        	if (!isGS('Publication')) {
        		camp_load_translation_strings("globals", $campsite->language->code);
        	}
            $html = '<select name="f_search_'.$attribute.'" ' . $p_params['html_code'] . '>'
                .'<option value="1" selected="selected">' . getGS('Publication') . '</option>'
                .'<option value="2">' . getGS('Issue') . '</option>'
                .'<option value="3">' . getGS('Section') . '</option>'
                .'</select>';
        } elseif ($attribute == 'section') {
        	require_once($GLOBALS['g_campsiteDir'] . '/admin-files/localizer/Localizer.php');
        	$constraints = array();
            $operator = new Operator('is', 'integer');
            if ($campsite->publication->defined) {
            	$constraints[] = new ComparisonOperation('IdPublication', $operator, $campsite->publication->identifier);
            }
            if ($campsite->language->defined) {
            	$constraints[] = new ComparisonOperation('IdLanguage', $operator, $campsite->language->number);
            }
            if ($campsite->issue->defined) {
            	$constraints[] = new ComparisonOperation('NrIssue', $operator, $campsite->issue->number);
            }
            $sectionsList = Section::GetList($constraints, array('Name'=>'ASC'), 0, 0, $count);
            if (!isGS('-- ALL SECTIONS --')) {
            	camp_load_translation_strings("user_subscription_sections", $campsite->language->code);
            }
            $html = '<select name="f_search_section" ' . $p_params['html_code'] . '>';
            $html .= '<option value="0" selected="selected">' . getGS('-- ALL SECTIONS --') . '</option>';
            foreach ($sectionsList as $section) {
            	$html .= '<option value="' . $section->getSectionNumber() . '">'
            	      . htmlspecialchars($section->getName()) . '</option>';
            }
            $html .= '</select>';
        } elseif ($attribute == 'issue') {
        	$constraints = array();
            $operator = new Operator('is', 'integer');
            if ($campsite->publication->defined) {
                $constraints[] = new ComparisonOperation('IdPublication', $operator, $campsite->publication->identifier);
            }
            if ($campsite->language->defined) {
                $constraints[] = new ComparisonOperation('IdLanguage', $operator, $campsite->language->number);
            }
            $constraints[] = new ComparisonOperation('published', $operator, 'true');
            $issuesList = Issue::GetList($constraints,
                                         array(array('field'=>'bynumber', 'dir'=>'DESC')),
                                         0, 0, $count);
            $html = '<select name="f_search_issue" ' . $p_params['html_code'] . '>';
            $html .= '<option value="0" selected="selected">&nbsp;</option>';
            foreach ($issuesList as $issue) {
            	$issueDesc = $issue->getIssueNumber() . '. '
            	           . $issue->getName()
            	           . ' ('. $issue->getPublicationDate() . ')';
                $html .= '<option value="' . $issue->getIssueNumber() . '">'
                      . htmlspecialchars($issueDesc) . '</option>';
            }
            $html .= '</select>';
        }
    }

    if ($selectTag == true) {
        $html.= smarty_function_html_options(array('output' => $output,
                                                   'values' => $values,
                                                   'selected' => $fieldValue,
                                                   'print_result' => false),
                                             $p_smarty);
        $html.= '</select>';
    }

    return $html;
} // fn smarty_function_camp_select
    /**
     * Reads the input parameters and sets up the interview action.
     *
     * @param array $p_input
     */
    public function __construct(array $p_input)
    {
        $this->m_name = 'interview';
        $this->m_defined = true;
        
        if (!strlen($p_input['f_interview_language_id'])) {
            $this->m_error = new PEAR_Error('An interview language was not selected.',
            ACTION_INTERVIEW_ERR_NO_LANGUAGE);
            return;
        }
        $this->m_properties['language_id'] = $p_input['f_interview_language_id'];
        
        if (!strlen($p_input['f_interview_title'])) {
            $this->m_error = new PEAR_Error('An interview title was not set.',
            ACTION_INTERVIEW_ERR_NO_TITLE);
            return;
        }
        $this->m_properties['title'] = $p_input['f_interview_title'];
        
        if (!isset($p_input['f_interview_description'])) {
            $this->m_error = new PEAR_Error('An description was not set.',
            ACTION_INTERVIEW_ERR_NO_DESCRIPTION);
            return;
        }
        $this->m_properties['description'] = $p_input['f_interview_description'];
        
        if (!strlen($p_input['f_interview_description_short'])) {
            $this->m_error = new PEAR_Error('An short description was not set.',
            ACTION_INTERVIEW_ERR_NO_DESCRIPTION_SHORT);
            return;
        }
        $this->m_properties['description_short'] = $p_input['f_interview_description_short'];

        if (!isset($p_input['f_interview_moderator_user_id'])) {
            $this->m_error = new PEAR_Error('An interview moderator was not selected.',
            ACTION_INTERVIEW_ERR_NO_MODERATOR);
            return;
        }
        $this->m_properties['moderator_user_id'] = $p_input['f_interview_moderator_user_id'];
        
        if (!isset($p_input['f_interview_guest_user_id'])) {
            $this->m_error = new PEAR_Error('An interview guest was not selected.',
            ACTION_INTERVIEW_ERR_NO_GUEST);
            return;
        }
        $this->m_properties['guest_user_id'] = $p_input['f_interview_guest_user_id'];
        
        if (strlen($p_input['f_interview_interview_begin']) != 10) {
            $this->m_error = new PEAR_Error('An interview begin was not set.',
            ACTION_INTERVIEW_ERR_NO_INTERVIEW_BEGIN);
            return;
        }
        $this->m_properties['interview_begin'] = $p_input['f_interview_interview_begin'];
        
        if (strlen($p_input['f_interview_interview_end']) != 10) {
            $this->m_error = new PEAR_Error('An interview end was not set.',
            ACTION_INTERVIEW_ERR_NO_INTERVIEW_END);
            return;
        }
        $this->m_properties['interview_end'] = $p_input['f_interview_interview_end'];
        
        if (strlen($p_input['f_interview_questions_begin']) != 10) {
            $this->m_error = new PEAR_Error('An questions begin was not set.',
            ACTION_INTERVIEW_ERR_NO_QUESTIONS_BEGIN);
            return;
        }
        $this->m_properties['questions_begin'] = $p_input['f_interview_questions_begin'];

        if (strlen($p_input['f_interview_questions_end']) != 10) {
            $this->m_error = new PEAR_Error('An questions end was not set.',
            ACTION_INTERVIEW_ERR_NO_QUESTIONS_END);
            return;
        }
        $this->m_properties['questions_end'] = $p_input['f_interview_questions_end'];

        if (strlen($p_input['f_interview_questions_limit'])) {
            $this->m_properties['questions_limit'] = $p_input['f_interview_questions_limit'];
        } else {
            $this->m_properties['questions_limit'] = 0;
        }
        
        $this->m_properties['image_delete'] = $p_input['f_interview_image_delete'];
        $this->m_properties['image_description'] = $p_input['f_interview_image_description'];
        $files = CampRequest::GetInput('files');
        $this->m_properties['image'] = $files['f_interview_image'];
        
        $this->m_interview = new Interview($p_input['f_interview_id']);
    }
Exemple #4
0
 /**
  * Returns true of the user was authenticated, false if not
  *
  * @return bool
  */
 protected function isLoggedIn()
 {
     $context = CampTemplate::singleton()->context();
     return (($context->login_action->defined
     && $context->login_action->ok
     && $context->login_action->user_name == $this->uname
     && $this->uname != '')
     || ($this->m_dbObject->getUserId() == CampRequest::GetVar('LoginUserId')
     && $this->m_dbObject->getKeyId() == CampRequest::GetVar('LoginUserKey')
     && $this->m_dbObject->getUserId() > 0
     && $this->m_dbObject->getKeyId() > 0));
 }
Exemple #5
0
// Remove all attempts to get at other parts of the file system
$call_script = str_replace('/../', '/', $call_script);
if ($call_script == '/logout.php') $call_script = $prefix . 'logout.php';

$extension = '';
if (($extension_start = strrpos($call_script, '.')) !== false) {
    $extension = strtolower(substr($call_script, $extension_start));
}

if (($extension == '.php') || ($extension == '')) {

    // If they arent trying to login in...
    if (($call_script != $prefix . 'login.php') && ($call_script != $prefix . 'do_login.php') && $call_script != $prefix . 'password_recovery.php' && $call_script != $prefix . 'password_check_token.php') {

        // Check if the user is logged in already
        list($access, $g_user) = camp_check_admin_access(CampRequest::GetInput());
        if (!$access) {
            // If not logged in: store request
            $request = serialize(array(
                'uri' => $_SERVER['REQUEST_URI'],
                'post' => $_POST,
            ));
            $requestId = sha1($request);
            camp_session_set("request_$requestId", $request);

            // show the login screen
            header("Location: /{$ADMIN}{$prefix}login.php?request=$requestId");
            exit(0);
        }
    }
    /**
     *
     */
    protected function execute()
    {
        $input = CampRequest::GetInput('post');
        $session = CampSession::singleton();

        $this->m_step = (!empty($input['step'])) ? $input['step'] : $this->m_defaultStep;

        switch($this->m_step) {
        case 'precheck':
            break;
        case 'license':
            $session->unsetData('config.db', 'installation');
            $session->unsetData('config.site', 'installation');
            $session->unsetData('config.demo', 'installation');
            $this->preInstallationCheck();
            break;
        case 'database':
            $this->license();
            break;
        case 'mainconfig':
            $prevStep = (isset($input['this_step'])) ? $input['this_step'] : '';
            if ($prevStep != 'loaddemo'
                    && $this->databaseConfiguration($input)) {
                $session->setData('config.db', $this->m_config['database'], 'installation', true);
            }
            break;
        case 'loaddemo':
            $prevStep = (isset($input['this_step'])) ? $input['this_step'] : '';
            if ($prevStep != 'loaddemo'
                    && $this->generalConfiguration($input)) {
                $session->setData('config.site', $this->m_config['mainconfig'], 'installation', true);
            }
            break;
        case 'cronjobs':
            if (isset($input['install_demo'])) {
                $session->setData('config.demo', array('loaddemo' => $input['install_demo']), 'installation', true);
                if ($input['install_demo'] != '0') {
                    if (!$this->loadDemoSite()) {
                        break;
                    }
                }
            }
            break;
        case 'finish':
            if (isset($input['install_demo'])) {
                $session->setData('config.demo', array('loaddemo' => $input['install_demo']), 'installation', true);
                if ($input['install_demo'] != '0') {
                    if (!$this->loadDemoSite()) {
                        break;
                    }
                }
            }
            $this->saveCronJobsScripts();
            if ($this->finish()) {
                $this->saveConfiguration();
                self::InstallPlugins();

                require_once($GLOBALS['g_campsiteDir'].'/classes/SystemPref.php');
                SystemPref::DeleteSystemPrefsFromCache();

                // clear all cache
                require_once($GLOBALS['g_campsiteDir'].'/classes/CampCache.php');
                CampCache::singleton()->clear('user');
                CampCache::singleton()->clear();
                CampTemplate::singleton()->clearCache();
            }
            break;
        }
    } // fn execute
 /**
  * Get template
  *
  * @return MetaTemplate
  */
 private function _getTemplate()
 {
     $templateId = CampRequest::GetVar(CampRequest::TEMPLATE_ID);
     $themePath = $this->m_issue->defined() ? $this->m_issue->theme_path : $this->m_publication->theme_path;
     $template = new MetaTemplate(parent::getTemplate($templateId), $themePath);
     if (!$template->defined()) {
         throw new InvalidArgumentException("Invalid template in URL or no default template specified.", self::INVALID_TEMPLATE);
     }
     CampTemplate::singleton()->config_dir = APPLICATION_PATH . '/../themes/' . $themePath . '_conf';
     return $template;
 }
Exemple #8
0
<?php

/**
 * @package Campsite
 *
 * @author Holman Romero <*****@*****.**>
 * @copyright 2007 MDLF, Inc.
 * @license http://www.gnu.org/licenses/gpl.txt
 * @version $Revision$
 * @link http://www.sourcefabric.org
 */
require_once __DIR__ . '/application.php';
$application->bootstrap('autoloader');
// reads parameters from image link URI
$imageId = (int) CampRequest::GetVar('ImageId', null, 'get');
$articleNr = (int) CampRequest::GetVar('NrArticle', null, 'get');
$imageNr = (int) CampRequest::GetVar('NrImage', null, 'get');
$imageRatio = (int) CampRequest::GetVar('ImageRatio', null, 'get');
$imageResizeWidth = (int) CampRequest::GetVar('ImageWidth', null, 'get');
$imageResizeHeight = (int) CampRequest::GetVar('ImageHeight', null, 'get');
$imageCrop = CampRequest::GetVar('ImageForcecrop', null, 'get');
$resizeCrop = CampRequest::GetVar('ImageCrop', null, 'get');
if (empty($imageId) && !empty($imageNr) && !empty($articleNr)) {
    $articleImage = new ArticleImage($articleNr, null, $imageNr);
    $imageId = $articleImage->getImageId();
}
$showImage = new CampGetImage($imageId, $imageRatio, $imageResizeWidth, $imageResizeHeight, $imageCrop, $resizeCrop);
    /**
     * Sets the URL values.
     *
     * Algorithm:
	 * - identify object (e.g.: publication, language, issue, section, article)
	 *     - object defined
	 *         - valid object?
	 *             - yes: set
	 *             - no: return error
	 *     - object undefined
	 *         - has default value?
	 *             - yes: set
	 *             - no:
	 *                 - object mandatory?
	 *                     - yes: return error
	 *                     - no: continue
     *
     * @return PEAR_Error
     *
     */
    private function setURL()
    {
        $this->setQueryVar('acid', null);

        $this->m_publication = null;
        $this->m_language = null;
        $this->m_issue = null;
        $this->m_section = null;
        $this->m_article = null;

        // gets the publication object based on site name (URI host)
        $alias = preg_replace('/^'.$this->getScheme().':\/\//', '', $this->getBase());
        $aliasObj = new Alias($alias);
        if ($aliasObj->exists()) {
            $this->m_publication = new MetaPublication($aliasObj->getPublicationId());
        }
        if (is_null($this->m_publication) || !$this->m_publication->defined()) {
            return new PEAR_Error("Invalid site name '$alias' in URL.", self::INVALID_SITE_NAME);
        }

        // reads parameters values if any
        $params = str_replace($this->m_config->getSetting('SUBDIR'), '', $this->getPath());
        $cParams = explode('/', trim($params, '/'));
        $cParamsSize = sizeof($cParams);
        if ($cParamsSize >= 1) {
            $cLangCode = $cParams[0];
        }
        if ($cParamsSize >= 2) {
            $cIssueSName = $cParams[1];
        }
        if ($cParamsSize >= 3) {
            $cSectionSName = $cParams[2];
        }
        if ($cParamsSize >= 4) {
            $cArticleSName = $cParams[3];
        }

        // gets the language identifier and sets the language code
        if (!empty($cLangCode)) {
            $langArray = Language::GetLanguages(null, $cLangCode);
            if (is_array($langArray) && sizeof($langArray) == 1) {
                $this->m_language = new MetaLanguage($langArray[0]->getLanguageId());
            }
        } else {
            $this->m_language = new MetaLanguage($this->m_publication->default_language->number);
        }
        if (is_null($this->m_language) || !$this->m_language->defined()) {
            return new PEAR_Error("Invalid language identifier in URL.", self::INVALID_LANGUAGE);
        }

        // gets the issue number and sets the issue short name
        if (!empty($cIssueSName)) {
        	$publishedOnly = !$this->m_preview;
            $issueArray = Issue::GetIssues($this->m_publication->identifier,
            $this->m_language->number, null, $cIssueSName, null, $publishedOnly);
            if (is_array($issueArray) && sizeof($issueArray) == 1) {
                $this->m_issue = new MetaIssue($this->m_publication->identifier,
                $this->m_language->number,
                $issueArray[0]->getIssueNumber());
            } else {
                return new PEAR_Error("Invalid issue identifier in URL.", self::INVALID_ISSUE);
	        }
        } else {
            $issueObj = Issue::GetCurrentIssue($this->m_publication->identifier,
            $this->m_language->number);
            $this->m_issue = new MetaIssue($this->m_publication->identifier,
            $this->m_language->number, $issueObj->getIssueNumber());
            if (!$this->m_issue->defined()) {
                return new PEAR_Error("No published issue was found.", self::INVALID_ISSUE);
            }
        }

        // gets the section number and sets the section short name
        if (!empty($cSectionSName)) {
            $sectionArray = Section::GetSections($this->m_publication->identifier,
            $this->m_issue->number,
            $this->m_language->number,
            $cSectionSName);
            if (is_array($sectionArray) && sizeof($sectionArray) == 1) {
                $this->m_section = new MetaSection($this->m_publication->identifier,
                $this->m_issue->number,
                $this->m_language->number,
                $sectionArray[0]->getSectionNumber());
            } else {
                return new PEAR_Error("Invalid section identifier in URL.", self::INVALID_SECTION);
            }
        }

        // gets the article number and sets the article short name
        if (!empty($cArticleSName)) {
            // we pass article short name as article identifier as they are
            // the same for Campsite, we will have to change this in the future
            $articleObj = new Article($this->m_language->number, $cArticleSName);
            if (!$articleObj->exists() || (!$this->m_preview && !$articleObj->isPublished())) {
                return new PEAR_Error("Invalid article identifier in URL.", self::INVALID_ARTICLE);
            }
            $this->m_article = new MetaArticle($this->m_language->number,
            $articleObj->getArticleNumber());
        }

        $templateId = CampRequest::GetVar(CampRequest::TEMPLATE_ID);
        $this->m_template = new MetaTemplate($this->getTemplate($templateId));
        if (!$this->m_template->defined()) {
            return new PEAR_Error("Invalid template in URL or no default template specified.",
            self::INVALID_TEMPLATE);
        }

        $this->m_validURI = true;
        $this->validateCache(false);
    } // fn setURL
/**
 * Campsite subscription_form block plugin
 *
 * Type:     block
 * Name:     subscription_form
 * Purpose:  Provides a...
 *
 * @param string
 *     $p_params
 * @param string
 *     $p_smarty
 * @param string
 *     $p_content
 *
 * @return
 *
 */
function smarty_block_subscription_form($p_params, $p_content, &$p_smarty, &$p_repeat)
{
    if (!isset($p_params['type']) || strtolower($p_params['type']) != 'by_section' && strtolower($p_params['type']) != 'by_publication') {
        return null;
    }
    // gets the context variable
    $campsite = $p_smarty->getTemplateVars('gimme');
    // gets the URL base
    $urlString = $campsite->url->base;
    if (strtolower($p_params['type']) == 'by_publication') {
        $campsite->subs_by_type = 'publication';
    } elseif (strtolower($p_params['type']) == 'by_section') {
        $campsite->subs_by_type = 'section';
    }
    $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');
    $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 subscription 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'] = '';
    }
    $subsType = strtolower(CampRequest::GetVar('SubsType'));
    if ($subsType != 'trial' && $subsType != 'paid') {
        return null;
    }
    $publication = $campsite->publication;
    $timeUnits = $subsType == 'trial' ? $publication->subscription_trial_time : $publication->subscription_paid_time;
    $sectionsNumber = Section::GetNumUniqueSections($publication->identifier, false);
    if (isset($template)) {
        $url->uri_parameter = "template " . str_replace(' ', "\\ ", $template->name);
    }
    $html = "<form name=\"subscription_form\" action=\"" . $url->uri_path . "\" method=\"post\" " . $p_params['html_code'] . ">\n";
    $html .= "<input type=\"hidden\" name=\"subs_by_type\" value=\"" . $campsite->subs_by_type . "\" />\n";
    if (isset($template)) {
        $html .= "<input type=\"hidden\" name=\"tpl\" value=\"" . $template->identifier . "\" />\n";
    }
    $html .= "<input type=\"hidden\" name=\"SubsType\" value=\"{$subsType}\" />\n" . "<input type=\"hidden\" name=\"tx_subs\" value=\"{$timeUnits}\" />\n" . "<input type=\"hidden\" name=\"nos\" value=\"{$sectionsNumber}\" />\n" . "<input type=\"hidden\" name=\"unitcost\" value=\"" . $publication->subscription_unit_cost . "\" />\n" . "<input type=\"hidden\" name=\"unitcostalllang\" value=\"" . $publication->subscription_unit_cost_all_lang . "\" />\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;
    if ($subsType == 'paid' && isset($p_params['total']) != '') {
        $html .= $p_params['total'] . " <input type=\"text\" name=\"suma\" size=\"10\" " . "READONLY /> " . $currency;
    }
    $html .= "<input type=\"submit\" name=\"f_edit_subscription\" " . "id=\"subscriptionEdit\" value=\"" . smarty_function_escape_special_chars($p_params['submit_button']) . "\" " . $p_params['button_html_code'] . " />\n";
    $html .= "</form>\n";
    ?>
<script type="text/javascript">
/**
 * Returns true if the given object had the given property.
 */
function element_exists(object, property) {
	for (i in object) {
		if (object[i].name == property) {
			return true
		}
	}
	return false
}

/**
 * Used in subscription form; computes the subscription cost and updates
 * the corresponding field in the form.
 */
function update_subscription_payment() {
	var sum = 0
	var i
	var my_form = document.forms["subscription_form"]
	var subs_all_lang = false
	var unitcost = my_form.unitcost.value
	var lang_count = 1
	if (element_exists(my_form.elements, "subs_all_languages")
		&& my_form.subs_all_languages.checked) {
		unitcost = my_form.unitcostalllang.value
	} else if (element_exists(my_form.elements, "subscription_language[]")) {
		lang_count = 0
		for (i=0; i<my_form["subscription_language[]"].options.length; i++) {
			if (my_form["subscription_language[]"].options[i].selected) {
				lang_count++
			}
		}
	}
	for (i = 0; i < my_form.nos.value; i++) {
		if (element_exists(my_form.elements, "by")
			&& my_form.by.value == "publication") {
			sum = parseInt(sum) + parseInt(my_form["tx_subs"].value)
			continue
		}
		if (!my_form["cb_subs[]"][i].checked) {
			continue
		}
		var section = my_form["cb_subs[]"][i].value
		var time_var_name = "tx_subs" + section
		if (element_exists(my_form.elements, time_var_name)) {
			sum = parseInt(sum) + parseInt(my_form[time_var_name].value)
		} else if (element_exists(my_form.elements, "tx_subs")) {
			sum = parseInt(sum) + parseInt(my_form["tx_subs"].value)
		}
	}
	my_form.suma.value = Math.round(100 * sum * unitcost * lang_count) / 100
}

function ToggleElementEnabled(id) {
	if (document.getElementById(id).disabled) {
		document.getElementById(id).disabled = false
	} else {
		document.getElementById(id).disabled = true
	}
}
</script>
<?php 
    return $html;
}
    /**
     * Sets the URL values.
     *
     * @return void
     */
    private function setURL()
    {
        $this->setQueryVar('tpl', null);
        $this->setQueryVar('acid', null);

        $this->m_publication = null;
        $this->m_language = null;
        $this->m_issue = null;
        $this->m_section = null;
        $this->m_article = null;

        // gets the publication object based on site name (URI host)
        $alias = preg_replace('/^'.$this->getScheme().':\/\//', '', $this->getBase());
        $aliasObj = new Alias($alias);
        if ($aliasObj->exists()) {
            $this->m_publication = new MetaPublication($aliasObj->getPublicationId());
        }
        if (is_null($this->m_publication) || !$this->m_publication->defined()) {
            return new PEAR_Error("Invalid site name '$alias' in URL.", self::INVALID_SITE_NAME);
        }

        // sets the language identifier
        if (CampRequest::GetVar(CampRequest::LANGUAGE_ID) > 0) {
            $this->m_language = new MetaLanguage(CampRequest::GetVar(CampRequest::LANGUAGE_ID));
        } else {
            $this->m_language = new MetaLanguage($this->m_publication->default_language->number);
        }
        if (!$this->m_language->defined()) {
            return new PEAR_Error("Invalid language identifier in URL.", self::INVALID_LANGUAGE);
        }

        // sets the issue number
        if (CampRequest::GetVar(CampRequest::ISSUE_NR) > 0) {
            $this->m_issue = new MetaIssue($this->m_publication->identifier,
            $this->m_language->number, CampRequest::GetVar(CampRequest::ISSUE_NR));
        } else {
            $issueObj = Issue::GetCurrentIssue($this->m_publication->identifier,
            $this->m_language->number);
            $this->m_issue = new MetaIssue($this->m_publication->identifier,
            $this->m_language->number, $issueObj->getIssueNumber());
        }
        if (!$this->m_issue->defined()) {
            return new PEAR_Error("Invalid issue identifier in URL.", self::INVALID_ISSUE);
        }

        // sets the section if any
        if (CampRequest::GetVar(CampRequest::SECTION_NR) > 0) {
            $this->m_section = new MetaSection($this->m_publication->identifier,
            $this->m_issue->number, $this->m_language->number,
            CampRequest::GetVar(CampRequest::SECTION_NR));
            if (!$this->m_section->defined()) {
                return new PEAR_Error("Invalid section identifier in URL.", self::INVALID_SECTION);
            }
        }

        // sets the article if any
        if (CampRequest::GetVar(CampRequest::ARTICLE_NR) > 0) {
            $this->m_article = new MetaArticle($this->m_language->number,
            CampRequest::GetVar(CampRequest::ARTICLE_NR));
            if (!$this->m_article->defined()) {
                return new PEAR_Error("Invalid article identifier in URL.", self::INVALID_ARTICLE);
            }
        }

        $this->m_template = new MetaTemplate($this->getTemplate($this->readTemplate()));
        if (!$this->m_template->defined()) {
            return new PEAR_Error("Invalid template in URL or no default template specified.",
            self::INVALID_TEMPLATE);
        }

        $this->m_validURI = true;
        $this->validateCache(false);
    } // fn setURL
Exemple #12
0
    /**
     * Class constructor
     */
    final public function __construct()
    {
        global $Campsite;

        if (!is_null($this->m_properties)) {
            return;
        }

        self::$m_nullMetaArticle = new MetaArticle();
        self::$m_nullMetaSection = new MetaSection();

        // register plugin objects and listobjects
        foreach (CampPlugin::GetPluginsInfo(true) as $info) {
        	if (is_array($info['template_engine']['objecttypes'])) {
        		foreach ($info['template_engine']['objecttypes'] as $objecttype) {
        			$this->registerObjectType($objecttype);
        		}
        	}

        	if (is_array($info['template_engine']['listobjects'])) {
        		foreach ($info['template_engine']['listobjects'] as $listobject) {
        			$this->registerListObject($listobject);
        		}
        	}
        }

        $this->m_properties['htmlencoding'] = false;
        $this->m_properties['subs_by_type'] = null;

        $this->m_readonlyProperties['version'] = $Campsite['VERSION'];

        $this->m_readonlyProperties['current_list'] = null;
        $this->m_readonlyProperties['lists'] = array();
        $this->m_readonlyProperties['prev_list_empty'] = null;

        $this->m_readonlyProperties['default_url'] = new MetaURL();
        $this->m_readonlyProperties['url'] = new MetaURL();
        if (!$this->m_readonlyProperties['default_url']->is_valid) {
        	header('HTTP/1.0 404 Not Found');
        	if (!$this->m_readonlyProperties['url']->language->defined) {
        		$this->m_readonlyProperties['url']->language = $this->m_readonlyProperties['url']->publication->default_language;
        		$this->m_readonlyProperties['default_url'] = $this->m_readonlyProperties['url'];
        	}
        }

        $this->m_objects['user'] = $this->m_readonlyProperties['url']->user;
        $this->m_readonlyProperties['preview'] = $this->m_readonlyProperties['url']->preview;

        if (!$this->m_readonlyProperties['preview']) {
        	if (!$this->m_readonlyProperties['url']->article->is_published) {
        		$this->m_readonlyProperties['default_url']->article = self::$m_nullMetaArticle;
                $this->m_readonlyProperties['url']->article = self::$m_nullMetaArticle;
        	}
            if (!$this->m_readonlyProperties['url']->issue->is_published) {
                $this->m_readonlyProperties['default_url']->article = self::$m_nullMetaArticle;
                $this->m_readonlyProperties['url']->article = self::$m_nullMetaArticle;
                $this->m_readonlyProperties['default_url']->section = self::$m_nullMetaSection;
                $this->m_readonlyProperties['url']->section = self::$m_nullMetaSection;
                $this->m_readonlyProperties['default_url']->issue = new MetaIssue();
                $this->m_readonlyProperties['url']->issue = new MetaIssue();
            }
        }

        $this->m_objects['publication'] = $this->m_readonlyProperties['url']->publication;
        $this->m_objects['language'] = $this->m_readonlyProperties['url']->language;
        $this->m_objects['issue'] = $this->m_readonlyProperties['url']->issue;
        $this->m_objects['section'] = $this->m_readonlyProperties['url']->section;
        $this->m_objects['article'] = $this->m_readonlyProperties['url']->article;
        $this->m_objects['template'] = $this->m_readonlyProperties['url']->template;
        if (is_numeric($this->m_readonlyProperties['url']->get_parameter('tpid'))) {
            $this->m_objects['topic'] = new MetaTopic($this->m_readonlyProperties['url']->get_parameter('tpid'));
        }

        $this->m_readonlyProperties['default_template'] = $this->m_objects['template'];
        $this->m_readonlyProperties['default_language'] = $this->m_objects['language'];
        $this->m_readonlyProperties['default_publication'] = $this->m_objects['publication'];
        $this->m_readonlyProperties['default_issue'] = $this->m_objects['issue'];
        $this->m_readonlyProperties['default_section'] = $this->m_objects['section'];
        $this->m_readonlyProperties['default_article'] = $this->m_objects['article'];
        $this->m_readonlyProperties['default_topic'] = $this->topic;

        if (!is_null($commentId = CampRequest::GetVar('acid'))) {
            $this->m_objects['comment'] = new MetaComment($commentId);
        }

        $this->m_readonlyProperties['request_action'] = MetaAction::CreateAction(CampRequest::GetInput(CampRequest::GetMethod()));
        $requestActionName = $this->m_readonlyProperties['request_action']->name;
        if ($requestActionName != 'default') {
        	$this->m_readonlyProperties['request_action']->takeAction($this);
        }

        foreach (MetaAction::ReadAvailableActions() as $actionName=>$actionAttributes) {
            $propertyName = $actionName . '_action';
            if ($requestActionName == $actionName) {
                $this->m_readonlyProperties[$propertyName] =& $this->m_readonlyProperties['request_action'];
            } else {
                $this->m_readonlyProperties[$propertyName] = MetaAction::DefaultAction();
            }
        }

        // Initialize the default comment attribute at the end, after the
        // submit comment action had run.
        $this->m_readonlyProperties['default_comment'] = $this->comment;

        // add browser info
        $this->m_readonlyProperties['browser'] = new Browser;

        // initialize plugins
        foreach (CampPlugin::GetPluginsInfo(true) as $info) {
            if (function_exists($info['template_engine']['init'])) {
                $plugin_init = $info['template_engine']['init'];
                $plugin_init($this);
            }
        }
    } // fn __construct
Exemple #13
0
 /**
  * Get template
  *
  * @return MetaTemplate
  */
 private function _getTemplate()
 {
     $templateId = CampRequest::GetVar(CampRequest::TEMPLATE_ID);
     $themePath = $this->m_issue->defined() ? $this->m_issue->theme_path : $this->m_publication->theme_path;
     $template = new MetaTemplate(parent::getTemplate($templateId), $themePath);
     if (!$template->defined()) {
         throw new InvalidArgumentException("Invalid template in URL or no default template specified.", self::INVALID_TEMPLATE);
     }
     return $template;
 }
    /**
     * Performs the action; returns true on success, false on error.
     *
     * @param $p_context - the current context object
     * @return bool
     */
    public function takeAction(CampContext &$p_context)
    {
        $p_context->default_url->reset_parameter('f_'.$this->m_name);
        $p_context->url->reset_parameter('f_'.$this->m_name);

        if (PEAR::isError($this->m_error)) {
            return false;
        }

        $user = new User($p_context->user->identifier);
        if ($user->getUserId() != CampRequest::GetVar('LoginUserId')
        || $user->getKeyId() != CampRequest::GetVar('LoginUserKey')
        || $user->getUserId() == 0
        || $user->getKeyId() == 0) {
            $this->m_error = new PEAR_Error('You must be logged in to create or edit your subscription.',
            ACTION_EDIT_SUBSCRIPTION_ERR_NO_USER);
            return false;
        }

        $subscriptions = Subscription::GetSubscriptions($p_context->publication->identifier,
        $user->getUserId());
        if (count($subscriptions) == 0) {
            $subscription = new Subscription();
            $created = $subscription->create(array(
			'IdUser' => $user->getUserId(),
			'IdPublication' => $p_context->publication->identifier,
			'Active' => 'Y',
			'Type' => $this->m_subscriptionType == 'trial' ? 'T' : 'P'));
            if (!$created) {
                $this->m_error = new PEAR_Error('Internal error (code 1)',
                ACTION_EDIT_SUBSCRIPTION_ERR_INTERNAL);
                exit(1);
            }
        } else {
            $subscription = $subscriptions[0];
        }

        $publication = new Publication($p_context->publication->identifier);
        $subscriptionDays = $this->computeSubscriptionDays($publication,
        $p_context->publication->subscription_time);

        $startDate = new Date();
        
        $columns = array(
        'StartDate'=>$startDate->getDate(),
        'Days'=>$subscriptionDays,
        'PaidDays'=>($this->m_subscriptionType == 'trial' ? $subscriptionDays : 0),
        'NoticeSent'=>'N'
        );

        if ($this->m_properties['subs_by_type'] == 'publication') {
        	$sectionsList = Section::GetUniqueSections($p_context->publication->identifier);
        	foreach ($sectionsList as $section) {
        		$this->m_sections[] = $section['id'];
        	}
        }
        foreach ($this->m_languages as $languageId) {
            foreach ($this->m_sections as $sectionNumber) {
                $subsSection = new SubscriptionSection($subscription->getSubscriptionId(),
                $sectionNumber, $languageId);
                $subsSection->create($columns);
            }
        }

        $fields = array('SubsType', 'tx_subs', 'nos', 'unitcost', 'unitcostalllang',
        'f_substype', 'cb_subs', 'subs_all_languages', 'suma', 'tpl', 'subscription_language');
        foreach (CampRequest::GetInput() as $field=>$value) {
            if (strncmp('tx_subs', $field, strlen('tx_subs')) == 0) {
                $fields[] = $field;
            }
        }
        foreach ($fields as $fieldName) {
            $p_context->default_url->reset_parameter($fieldName);
            $p_context->url->reset_parameter($fieldName);
        }

        $this->m_error = ACTION_OK;
        return true;
    }
Exemple #15
0
 * @author Holman Romero <*****@*****.**>
 * @copyright 2007 MDLF, Inc.
 * @license http://www.gnu.org/licenses/gpl.txt
 * @version $Revision$
 * @link http://www.sourcefabric.org
 */

/**
 * Includes
 */
$GLOBALS['g_campsiteDir'] = dirname(__FILE__);
require_once($GLOBALS['g_campsiteDir'].'/template_engine/classes/CampRequest.php');
require_once($GLOBALS['g_campsiteDir'].'/template_engine/classes/CampGetImage.php');
require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleImage.php');

// reads parameters from image link URI
$imageId = (int) CampRequest::GetVar('ImageId', null, 'get');
$articleNr = (int) CampRequest::GetVar('NrArticle', null, 'get');
$imageNr = (int) CampRequest::GetVar('NrImage', null, 'get');
$imageRatio = (int) CampRequest::GetVar('ImageRatio', null, 'get');
$imageResizeWidth = (int) CampRequest::GetVar('ImageWidth', null, 'get');
$imageResizeHeight = (int) CampRequest::GetVar('ImageHeight', null, 'get');

if (empty($imageId) && !empty($imageNr) && !empty($articleNr)) {
	$articleImage = new ArticleImage($articleNr, null, $imageNr);
	$imageId = $articleImage->getImageId();
}

$showImage = new CampGetImage($imageId, $imageRatio, $imageResizeWidth, $imageResizeHeight);

?>
 /**
  * Performs the action; returns true on success, false on error.
  *
  * @param $p_context - the current context object
  * @return bool
  */
 public function takeAction(CampContext &$p_context)
 {
     $p_context->default_url->reset_parameter('f_' . $this->m_name);
     $p_context->url->reset_parameter('f_' . $this->m_name);
     \CampRequest::SetVar('f_' . $this->m_name);
     $translator = \Zend_Registry::get('container')->getService('translator');
     $userService = \Zend_Registry::get('container')->getService('user');
     if (!is_null($this->m_error)) {
         return false;
     }
     // Check that the article exists.
     $articleMetaObj = $p_context->default_article;
     if (!$articleMetaObj->defined) {
         $this->m_error = new PEAR_Error('The article was not selected. You must view an article in order to post comments.', ACTION_SUBMIT_COMMENT_ERR_NO_ARTICLE);
         return false;
     }
     if (!$articleMetaObj->comments_enabled || $articleMetaObj->comments_locked) {
         $this->m_error = new PEAR_Error('Comments are not enabled for this publication/article.', ACTION_SUBMIT_COMMENT_ERR_NOT_ENABLED);
         return false;
     }
     // Detect if it's a bot bot_detect
     if (!empty($this->m_properties['bot_detect'])) {
         $this->m_error = new PEAR_Error('The comment cannot be submitted.', ACTION_SUBMIT_COMMENT_BOT_DETECTED);
         return false;
     }
     $publication_id = $articleMetaObj->publication->identifier;
     // Get the publication.
     $publicationObj = new Publication($publication_id);
     $user = $p_context->user;
     $userIp = $userService->getUserIp();
     if ($user->defined) {
         $userId = $user->identifier;
         $userEmail = $user->email;
         if ($this->m_properties['nickname'] == '') {
             $userRealName = $user->name;
         } else {
             $userRealName = $this->m_properties['nickname'];
         }
         if ($this->m_properties['is_anonymous']) {
             $userRealName = $translator->trans('Anonymous', array(), 'comments');
         }
     } else {
         if (!$publicationObj->getPublicComments()) {
             $this->m_error = new PEAR_Error('You must be a registered user in order to submit a comment. Please subscribe or log in if you already have a subscription.', ACTION_SUBMIT_COMMENT_ERR_NO_PUBLIC);
             return false;
         } else {
             if (!isset($this->m_properties['reader_email'])) {
                 $this->m_error = new PEAR_Error('EMail field is empty. You must fill in your EMail address.', ACTION_SUBMIT_COMMENT_ERR_NO_EMAIL);
                 return false;
             }
         }
         $userId = null;
         $userEmail = $this->m_properties['reader_email'];
         $userRealName = $this->m_properties['nickname'];
     }
     // Validate the CAPTCHA code if it was enabled for the current publication.
     if ($publicationObj->isCaptchaEnabled()) {
         if ($this->_processCaptcha() === FALSE) {
             return FALSE;
         }
     }
     // Check if the reader was banned from posting comments.
     global $controller;
     $repositoryAcceptance = $controller->getHelper('entity')->getRepository('Newscoop\\Entity\\Comment\\Acceptance');
     $repository = $controller->getHelper('entity')->getRepository('Newscoop\\Entity\\Comment');
     if ($repositoryAcceptance->checkParamsBanned($userRealName, $userEmail, $userIp, $publication_id)) {
         $this->m_error = new PEAR_Error('You are banned from submitting comments.', ACTION_SUBMIT_COMMENT_ERR_BANNED);
         return false;
     }
     // get the article object
     $articleObj = new Article($articleMetaObj->language->number, $articleMetaObj->number);
     // Set the parent to the currently viewed comment if a certain existing
     // comment was selected. Otherwise, set the parent identifier to the root message.
     // Create the comment. If there was an error creating the comment set the
     // error code to 'internal error' and exit.
     $values = array('thread' => $articleMetaObj->number, 'language' => $articleMetaObj->language->code, 'name' => $userRealName, 'email' => $userEmail, 'message' => $this->m_properties['content'], 'subject' => $this->m_properties['subject'], 'parent' => $this->m_properties['parent'], 'ip' => $userIp, 'time_created' => new DateTime());
     // If the user was unknown (public comment) and public comments were moderated
     // or the user was known (subscriber comment) and subscriber comments were moderated
     // set the comment status to 'hold'. Otherwise, set the status to 'approved'.
     if (!is_null($userId) && $publicationObj->commentsSubscribersModerated() || is_null($userId) && $publicationObj->commentsPublicModerated()) {
         $values['status'] = "pending";
     } else {
         $values['status'] = "approved";
     }
     // If the user was known set it
     if (!is_null($userId)) {
         $values['user'] = $userId;
     }
     //If there is a comment idetifier set it the parent of the comment
     if ($p_context->comment->identifier) {
         $values['parent'] = $p_context->comment->identifier;
     }
     $commentObj = $repository->getPrototype();
     $comment = $repository->save($commentObj, $values);
     $repository->flush();
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $cacheService->clearNamespace('comment');
     if (!$comment) {
         $this->m_error = new PEAR_Error('There was an internal error when submitting the comment (code 3).', ACTION_SUBMIT_COMMENT_ERR_INTERNAL);
         return false;
     }
     $p_context->default_url->reset_parameter('f_comment_reader_email');
     $p_context->default_url->reset_parameter('f_comment_subject');
     $p_context->default_url->reset_parameter('f_comment_content');
     $p_context->default_url->reset_parameter('f_comment_parent');
     $p_context->default_url->reset_parameter('f_submit_comment');
     $p_context->default_url->reset_parameter('f_captcha_code');
     $p_context->url->reset_parameter('f_comment_reader_email');
     $p_context->url->reset_parameter('f_comment_subject');
     $p_context->url->reset_parameter('f_comment_content');
     $p_context->url->reset_parameter('f_comment_parent');
     $p_context->url->reset_parameter('f_submit_comment');
     $p_context->url->reset_parameter('f_captcha_code');
     $this->m_properties['rejected'] = false;
     $this->m_error = ACTION_OK;
     header('Location: ' . $_SERVER['REQUEST_URI'], true, 303);
     exit(0);
 }
Exemple #17
0
 private function readUser()
 {
     $userId = CampRequest::GetVar('LoginUserId');
     if (!is_null($userId)) {
         $user = new User($userId);
         if ($user->exists()
         && $user->getKeyId() == CampRequest::GetVar('LoginUserKey')) {
             $this->m_user = new MetaUser($userId);
             $this->m_preview = CampRequest::GetVar('preview') == 'on'
             && $this->m_user->is_admin;
         }
     } else {
         $ipUsers = IPAccess::GetUsersHavingIP($_SERVER['REMOTE_ADDR']);
         if (count($ipUsers) > 0) {
             $this->m_user = new MetaUser($ipUsers[0]->getUserId());
             $this->m_preview = CampRequest::GetVar('preview') == 'on'
             && $this->m_user->is_admin;
         }
     }
 }
 protected function getSubscriptionTime() {
     if (strtolower(CampRequest::GetVar('SubsType')) == 'trial') {
         return $this->subscription_trial_time;
     } elseif (strtolower(CampRequest::GetVar('SubsType')) == 'paid') {
         return $this->subscription_paid_time;
     }
     return null;
 }
Exemple #19
0
 /**
  * Returns a CampHTMLDocument instance.
  *
  * @return object
  *      The CampHTMLDocument instance.
  */
 public static function GetHTMLDocumentInstance()
 {
     $config = self::GetConfigInstance();
     $attributes = array(
                         'type' => CampRequest::GetVar('format', 'html'),
                         'charset' => $config->getSetting('site.charset'),
                         'language' => CampRequest::GetVar('language', 'en')
                         );
     return CampHTMLDocument::singleton($attributes);
 } // fn GetHTMLDocumentInstance
Exemple #20
0
CampCache::singleton()->clear();
SystemPref::DeleteSystemPrefsFromCache();
// replace $campsite by $gimme
require_once $g_documentRoot . '/classes/TemplateConverterNewscoop.php';
$template_files = camp_read_files($g_documentRoot . '/templates');
$converter = new TemplateConverterNewscoop();
if (!empty($template_files)) {
    foreach ($template_files as $template_file) {
        $converter->read($template_file);
        $converter->parse();
        $converter->write();
    }
}
// update plugins
CampPlugin::OnUpgrade();
CampRequest::SetVar('step', 'finish');
$install = new CampInstallation();
$install->initSession();
$step = $install->execute();
// update plugins environment
CampPlugin::OnAfterUpgrade();
CampTemplate::singleton()->clearCache();
// replace javascript by js in .htaccess file
$htaccesspath = $g_documentRoot . '/.htaccess';
if (upgrade_htaccess($htaccesspath) == false) {
    display_upgrade_error('Could not write .htaccess file.<br />Please read the ' . 'UPGRADE.txt file in this same directory to see what changes need to ' . 'be apply for this specific version of Newscoop.', FALSE);
}
if (file_exists($upgrade_trigger_path)) {
    @unlink($upgrade_trigger_path);
}
function display_upgrade_error($p_errorMessage, $exit = TRUE)
Exemple #21
0
 /**
  * Class constructor
  */
 public final function __construct()
 {
     global $Campsite, $controller;
     if (!is_null($this->m_properties)) {
         return;
     }
     $this->login_action = (object) array('is_error' => false, 'error_message' => '');
     self::$m_nullMetaArticle = new MetaArticle();
     self::$m_nullMetaSection = new MetaSection();
     // register plugin objects and listobjects
     foreach (CampPlugin::GetPluginsInfo(true) as $info) {
         if (is_array($info['template_engine']['objecttypes'])) {
             foreach ($info['template_engine']['objecttypes'] as $objecttype) {
                 $this->registerObjectType($objecttype);
             }
         }
         if (is_array($info['template_engine']['listobjects'])) {
             foreach ($info['template_engine']['listobjects'] as $listobject) {
                 $this->registerListObject($listobject);
             }
         }
     }
     $this->m_properties['htmlencoding'] = false;
     $this->m_properties['subs_by_type'] = null;
     $this->m_readonlyProperties['version'] = $Campsite['VERSION'];
     $this->m_readonlyProperties['current_list'] = null;
     $this->m_readonlyProperties['lists'] = array();
     $this->m_readonlyProperties['prev_list_empty'] = null;
     $this->m_readonlyProperties['default_url'] = new MetaURL();
     $this->m_readonlyProperties['url'] = new MetaURL();
     if (!$this->m_readonlyProperties['default_url']->is_valid) {
         header('HTTP/1.0 404 Not Found');
         if (!$this->m_readonlyProperties['url']->language->defined) {
             $this->m_readonlyProperties['url']->language = $this->m_readonlyProperties['url']->publication->default_language;
             $this->m_readonlyProperties['default_url'] = $this->m_readonlyProperties['url'];
         }
     }
     $this->m_objects['user'] = $this->m_readonlyProperties['url']->user;
     $this->m_readonlyProperties['preview'] = $this->m_readonlyProperties['url']->preview;
     if (!$this->m_readonlyProperties['preview']) {
         if (!$this->m_readonlyProperties['url']->article->is_published) {
             $this->m_readonlyProperties['default_url']->article = self::$m_nullMetaArticle;
             $this->m_readonlyProperties['url']->article = self::$m_nullMetaArticle;
         }
         if (!$this->m_readonlyProperties['url']->issue->is_published) {
             $this->m_readonlyProperties['default_url']->article = self::$m_nullMetaArticle;
             $this->m_readonlyProperties['url']->article = self::$m_nullMetaArticle;
             $this->m_readonlyProperties['default_url']->section = self::$m_nullMetaSection;
             $this->m_readonlyProperties['url']->section = self::$m_nullMetaSection;
             $this->m_readonlyProperties['default_url']->issue = new MetaIssue();
             $this->m_readonlyProperties['url']->issue = new MetaIssue();
         }
     }
     $this->m_objects['publication'] = $this->m_readonlyProperties['url']->publication;
     $this->m_objects['language'] = $this->m_readonlyProperties['url']->language;
     $this->m_objects['issue'] = $this->m_readonlyProperties['url']->issue;
     $this->m_objects['section'] = $this->m_readonlyProperties['url']->section;
     $this->m_objects['article'] = $this->m_readonlyProperties['url']->article;
     $this->m_objects['template'] = $this->m_readonlyProperties['url']->template;
     if (is_numeric($this->m_readonlyProperties['url']->get_parameter('tpid'))) {
         $this->m_objects['topic'] = new MetaTopic($this->m_readonlyProperties['url']->get_parameter('tpid'));
     }
     $this->m_readonlyProperties['default_template'] = $this->m_objects['template'];
     $this->m_readonlyProperties['default_language'] = $this->m_objects['language'];
     $this->m_readonlyProperties['default_publication'] = $this->m_objects['publication'];
     $this->m_readonlyProperties['default_issue'] = $this->m_objects['issue'];
     $this->m_readonlyProperties['default_section'] = $this->m_objects['section'];
     $this->m_readonlyProperties['default_article'] = $this->m_objects['article'];
     $this->m_readonlyProperties['default_topic'] = $this->topic;
     if (!is_null($commentId = CampRequest::GetVar('acid'))) {
         $this->m_objects['comment'] = new MetaComment($commentId);
     }
     $this->m_readonlyProperties['request_action'] = MetaAction::CreateAction(CampRequest::GetInput(CampRequest::GetMethod()));
     $requestActionName = $this->m_readonlyProperties['request_action']->name;
     if ($requestActionName != 'default') {
         $this->m_readonlyProperties['request_action']->takeAction($this);
     }
     foreach (MetaAction::ReadAvailableActions() as $actionName => $actionAttributes) {
         $propertyName = $actionName . '_action';
         if ($requestActionName == $actionName) {
             $this->m_readonlyProperties[$propertyName] =& $this->m_readonlyProperties['request_action'];
         } else {
             $this->m_readonlyProperties[$propertyName] = MetaAction::DefaultAction();
         }
     }
     // Initialize the default comment attribute at the end, after the
     // submit comment action had run.
     $this->m_readonlyProperties['default_comment'] = $this->comment;
     // add browser info
     $this->m_readonlyProperties['browser'] = new Browser();
     // initialize plugins
     foreach (CampPlugin::GetPluginsInfo(true) as $info) {
         if (function_exists($info['template_engine']['init'])) {
             $plugin_init = $info['template_engine']['init'];
             $plugin_init($this);
         }
     }
     // initialize geo-map holders
     $this->m_properties['map_dynamic_constraints'] = null;
     $this->m_properties['map_dynamic_areas'] = null;
     $this->m_properties['map_dynamic_max_points'] = 0;
     $this->m_properties['map_dynamic_tot_points'] = 0;
     $this->m_properties['map_dynamic_points_raw'] = null;
     $this->m_properties['map_dynamic_points_objects'] = null;
     $this->m_properties['map_dynamic_meta_article_objects'] = null;
     $this->m_properties['map_dynamic_map_label'] = "";
     $this->m_properties['map_dynamic_id_counter'] = 0;
     $this->m_properties['map_common_header_set'] = false;
     if (defined('APPLICATION_PATH')) {
         $options = $controller->getInvokeArg('bootstrap')->getOptions();
         $form = new \Application_Form_Contact();
         $form->setMethod('POST');
         $request = \Zend_Controller_Front::getInstance()->getRequest();
         if ($request->isPost() && $form->isValid($request->getPost())) {
             $email = new \Zend_Mail('utf-8');
             $email->setFrom($form->email->getValue(), $form->first_name->getValue() . ' ' . $form->last_name->getValue())->setSubject($form->subject->getValue())->setBodyText($form->message->getValue())->addTo($options['email']['contact'])->send();
             $controller->getHelper('flashMessenger')->addMessage("form_contact_done");
             $controller->getHelper('redirector')->gotoUrl($request->getPathInfo());
             exit;
         }
         $this->form_contact = $form;
         $this->flash_messages = $controller->getHelper('flashMessenger')->getMessages();
     }
 }
Exemple #22
0
$siteAlias = new Alias($publicationObj->getDefaultAliasId());
$websiteURL = $scheme.$siteAlias->getName();

$accessParams = "LoginUserId=" . $g_user->getUserId() . "&LoginUserKey=" . $g_user->getKeyId()
				. "&AdminAccess=all";
$urlType = $publicationObj->getProperty('IdURLType');
if ($urlType == 1) {
	$templateObj = new Template($templateId);
	$url = "$websiteURL"  . $Campsite['SUBDIR'] . "/tpl/" . $templateObj->getName()
		. "?IdLanguage=$Language&IdPublication=$Pub&NrIssue=$Issue&$accessParams";
} else {
	$url = "$websiteURL" . $Campsite['SUBDIR'] . '/' . $languageObj->getCode()
		. "/" . $issueObj->getUrlName() . "?$accessParams";
}

$selectedLanguage = (int)CampRequest::GetVar('Language');
$url .= "&previewLang=$selectedLanguage";

if ($g_user->hasPermission("ManageTempl") || $g_user->hasPermission("DeleteTempl")) {
	// Show dual-pane view for those with template management priviledges
?>
<FRAMESET ROWS="60%,*" BORDER="1">
	<FRAME SRC="<?php echo "$url&preview=on"; ?>" NAME="body" FRAMEBORDER="1">
	<FRAME NAME="e" SRC="empty.php" FRAMEBORDER="1">
</FRAMESET>
<?php
} else {
	// Show single pane for everyone else.
?>
	<FRAMESET ROWS="100%">
		<FRAME SRC="<?php print "$url&preview=on"; ?>" NAME="body" FRAMEBORDER="1">
Exemple #23
0
$accessParams = "LoginUserId=" . $g_user->getUserId() . "&LoginUserKey=" . $g_user->getKeyId()
				. "&AdminAccess=all";
if ($publicationObj->getUrlTypeId() == 1) {
	$templateObj = new Template($templateId);
	$url = "$websiteURL/tpl/" . $templateObj->getName() . "?IdLanguage=$f_language_id"
		. "&IdPublication=$f_publication_id&NrIssue=$f_issue_number&NrSection=$f_section_number"
		. "&NrArticle=$f_article_number&$accessParams";
} else {
	$url = ShortURL::GetURL($f_publication_id, $f_language_selected, null, null, $f_article_number);
	if (PEAR::isError($url)) {
		$errorStr = $url->getMessage();
	}
	$url .= '?' . $accessParams;
}

$selectedLanguage = (int)CampRequest::GetVar('f_language_selected');
$url .= "&previewLang=$selectedLanguage";
$siteTitle = (!empty($Campsite['site']['title'])) ? htmlspecialchars($Campsite['site']['title']) : putGS("Newscoop") . $Campsite['VERSION'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en">
<head>
  <title><?php p($siteTitle); ?></title>
</head>
<?php
if ($errorStr != "") {
	camp_html_display_error($errorStr, null, true);
}

if ($g_user->hasPermission("ManageTempl") || $g_user->hasPermission("DeleteTempl")) {
	// Show dual-pane view for those with template management priviledges
Exemple #24
0
 /**
  * Class constructor
  */
 public final function __construct()
 {
     global $Campsite, $controller;
     if (!is_null($this->m_properties)) {
         return;
     }
     $this->login_action = (object) array('is_error' => false, 'error_message' => '');
     self::$m_nullMetaArticle = new MetaArticle();
     self::$m_nullMetaSection = new MetaSection();
     // LEGACY PLUGINS
     // register plugin objects and listobjects
     foreach (CampPlugin::GetPluginsInfo(true) as $info) {
         if (is_array($info['template_engine']['objecttypes'])) {
             foreach ($info['template_engine']['objecttypes'] as $objecttype) {
                 $this->registerObjectType($objecttype);
             }
         }
         if (is_array($info['template_engine']['listobjects'])) {
             foreach ($info['template_engine']['listobjects'] as $listobject) {
                 $this->registerListObject($listobject);
             }
         }
     }
     // Register new plugins system list objects
     $pluginsService = \Zend_Registry::get('container')->get('newscoop.plugins.service');
     $collectedData = $pluginsService->collectListObjects();
     $this->m_listObjects = array_merge($collectedData['listObjects'], $this->m_listObjects);
     CampContext::$m_objectTypes = array_merge($collectedData['objectTypes'], CampContext::$m_objectTypes);
     $this->m_properties['htmlencoding'] = false;
     $this->m_properties['subs_by_type'] = null;
     $this->m_readonlyProperties['version'] = $Campsite['VERSION'];
     $this->m_readonlyProperties['current_list'] = null;
     $this->m_readonlyProperties['lists'] = array();
     $this->m_readonlyProperties['prev_list_empty'] = null;
     $this->m_readonlyProperties['default_url'] = new MetaURL();
     $this->m_readonlyProperties['url'] = new MetaURL();
     if (!$this->m_readonlyProperties['default_url']->is_valid) {
         if (!$this->m_readonlyProperties['url']->language->defined) {
             $this->m_readonlyProperties['url']->language = $this->m_readonlyProperties['url']->publication->default_language;
             $this->m_readonlyProperties['default_url'] = $this->m_readonlyProperties['url'];
         }
     }
     $this->m_objects['user'] = $this->m_readonlyProperties['url']->user;
     $this->m_readonlyProperties['preview'] = $this->m_readonlyProperties['url']->preview;
     if (!$this->m_readonlyProperties['preview']) {
         if (!$this->m_readonlyProperties['url']->article->is_published) {
             $this->m_readonlyProperties['default_url']->article = self::$m_nullMetaArticle;
             $this->m_readonlyProperties['url']->article = self::$m_nullMetaArticle;
         }
         if (!$this->m_readonlyProperties['url']->issue->is_published) {
             $this->m_readonlyProperties['default_url']->article = self::$m_nullMetaArticle;
             $this->m_readonlyProperties['url']->article = self::$m_nullMetaArticle;
             $this->m_readonlyProperties['default_url']->section = self::$m_nullMetaSection;
             $this->m_readonlyProperties['url']->section = self::$m_nullMetaSection;
             $this->m_readonlyProperties['default_url']->issue = new MetaIssue();
             $this->m_readonlyProperties['url']->issue = new MetaIssue();
         }
     }
     $this->m_objects['publication'] = $this->m_readonlyProperties['url']->publication;
     $this->m_objects['language'] = $this->m_readonlyProperties['url']->language;
     $this->m_objects['issue'] = $this->m_readonlyProperties['url']->issue;
     $this->m_objects['section'] = $this->m_readonlyProperties['url']->section;
     $this->m_objects['article'] = $this->m_readonlyProperties['url']->article;
     $this->m_objects['template'] = $this->m_readonlyProperties['url']->template;
     if (is_numeric($this->m_readonlyProperties['url']->get_parameter('tpid'))) {
         $this->m_objects['topic'] = new MetaTopic($this->m_readonlyProperties['url']->get_parameter('tpid'));
     }
     $this->m_readonlyProperties['default_template'] = $this->m_objects['template'];
     $this->m_readonlyProperties['default_language'] = $this->m_objects['language'];
     $this->m_readonlyProperties['default_publication'] = $this->m_objects['publication'];
     $this->m_readonlyProperties['default_issue'] = $this->m_objects['issue'];
     $this->m_readonlyProperties['default_section'] = $this->m_objects['section'];
     $this->m_readonlyProperties['default_article'] = $this->m_objects['article'];
     $this->m_readonlyProperties['default_topic'] = $this->topic;
     if (!is_null($commentId = CampRequest::GetVar('acid'))) {
         $this->m_objects['comment'] = new MetaComment($commentId);
     }
     $this->m_readonlyProperties['request_action'] = MetaAction::CreateAction(CampRequest::GetInput(CampRequest::GetMethod()));
     $requestActionName = $this->m_readonlyProperties['request_action']->name;
     $runAction = true;
     if ($requestActionName == 'submit_comment' && $pluginsService->isInstalled('terwey/plugin-newscoop-comments')) {
         $runAction = false;
     }
     if ($requestActionName != 'default' && $runAction) {
         $this->m_readonlyProperties['request_action']->takeAction($this);
     }
     foreach (MetaAction::ReadAvailableActions() as $actionName => $actionAttributes) {
         $propertyName = $actionName . '_action';
         if ($requestActionName == $actionName) {
             $this->m_readonlyProperties[$propertyName] =& $this->m_readonlyProperties['request_action'];
         } else {
             $this->m_readonlyProperties[$propertyName] = MetaAction::DefaultAction();
         }
     }
     // Initialize the default comment attribute at the end, after the
     // submit comment action had run.
     $this->m_readonlyProperties['default_comment'] = $this->comment;
     // add browser info
     $this->m_readonlyProperties['browser'] = new Browser();
     // initialize plugins
     foreach (CampPlugin::GetPluginsInfo(true) as $info) {
         if (function_exists($info['template_engine']['init'])) {
             $plugin_init = $info['template_engine']['init'];
             $plugin_init($this);
         }
     }
     // initialize geo-map holders
     $this->m_properties['map_dynamic_constraints'] = null;
     $this->m_properties['map_dynamic_areas'] = null;
     $this->m_properties['map_dynamic_max_points'] = 0;
     $this->m_properties['map_dynamic_tot_points'] = 0;
     $this->m_properties['map_dynamic_points_raw'] = null;
     $this->m_properties['map_dynamic_points_objects'] = null;
     $this->m_properties['map_dynamic_meta_article_objects'] = null;
     $this->m_properties['map_dynamic_map_label'] = "";
     $this->m_properties['map_dynamic_id_counter'] = 0;
     $this->m_properties['map_common_header_set'] = false;
     $flashMessenger = new \Newscoop\Controller\Helper\FlashMessenger();
     $this->flash_messages = $flashMessenger->getMessages();
 }
Exemple #25
0
 private function readUser()
 {
     $this->m_preview = false;
     $container = \Zend_Registry::get('container');
     $userService = $container->getService('user');
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $user = $userService->find($auth->getIdentity());
         if (!empty($user)) {
             $this->m_user = new MetaUser($user);
             $this->m_preview = CampRequest::GetVar('preview') === 'on' && $this->m_user->isAdmin();
             if (!$this->m_preview && CampRequest::GetVar('preview') === 'on' && $container->getService('blog')->isBlogger($user)) {
                 $lang = \Language::GetLanguageIdByCode(CampRequest::GetVar('language'));
                 $article = new \Article($lang, CampRequest::GetVar('articleNo'));
                 $this->m_preview = $container->getService('blog')->isUsersArticle($article, $user);
             }
         }
     } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
         // empty in cli
         $ipUsers = IPAccess::GetUsersHavingIP($_SERVER['REMOTE_ADDR']);
         if (!empty($ipUsers)) {
             $user = $userService->find($ipUsers[0]->getUserId());
             $this->m_user = new MetaUser($user);
         }
     }
 }