Ejemplo n.º 1
0
/**
 * Campsite teaser modifier plugin
 *
 * Type:     modifier
 * Name:     teaser
 * Purpose:  build an teaser our of input
 *
 * @param string
 *     $p_input the string or object
 * @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_teaser($p_input)
{
    $pattern = '/<!-- *break *-->/i';
    
    if (is_object($p_input) && method_exists($p_input, '__toString')) {
        $input = $p_input->__toString();
    } else {
         $input = (string) $p_input;
    }
    
    if (preg_match($pattern, $input, $matches, PREG_OFFSET_CAPTURE)) {
        $length = $matches[0][1];
        $output = substr($input, 0, $length);
        $output .= '[...]';
    } else {
        static $length;
        
        if (empty($length)) {
            $length = is_null(SystemPref::Get('teaser_length')) ? 150 : SystemPref::Get('teaser_length');
        }
        $output = mb_substr($input, 0, $length, 'UTF-8');
        $output .= '[...]';
    }
    
    return $output;
} // fn smarty_modifier_camp_date_format
Ejemplo n.º 2
0
/**
 * Send token via email
 *
 * @param string $p_email
 * @param string $p_token
 * @return void
 */
function send_token($p_email, $p_token)
{
    global $Campsite;

    // reset link
    $link = sprintf('%s/admin/password_check_token.php?token=%s&f_email=%s',
        $Campsite['WEBSITE_URL'],
        $p_token,
        $p_email);

    // email message
    $message = getGS("Hi, \n\nfor password recovery, please follow this link: $1", $link);

    // get from email
    $from = SystemPref::Get('PasswordRecoveryFrom');
    if (empty($from)) {
        $from = 'no-reply@' . $_SERVER['SERVER_NAME'];
    }

    // set headers
    $headers = array(
        'MIME-Version: 1.0',
        'Content-type: text/plain; charset=UTF-8',
        "From: $from",
    );

    // send mail
    mail($p_email,
        '=?UTF-8?B?' . base64_encode(getGS('Password recovery')) . '?=',
        trim(html_entity_decode(strip_tags($message), ENT_QUOTES, 'UTF-8')),
        implode("\r\n", $headers));
}
Ejemplo n.º 3
0
    /**
     * Loads the handler specified by the given name.
     * @param $p_handlerName
     * @return object
     */
    public static function factory($p_handlerName = null, $p_path = null)
    {
        static $handlers;

        if (!$p_handlerName) {
            $p_handlerName = SystemPref::Get('TemplateCacheHandler');
        }
        if (!$p_handlerName) {
            return null;
        }
        if (!empty($handlers[$p_handlerName])) {
            return $handlers[$p_handlerName];
        }
        if (is_null($p_path)) {
            $path = dirname(__FILE__) . DIR_SEP. 'cache';
        } else {
            $path = $p_path;
        }
        $filePath = "$path/TemplateCacheHandler_$p_handlerName.php";
        if (file_exists($filePath)) {
            require_once($filePath);
            $className = "TemplateCacheHandler_$p_handlerName";
            if (class_exists($className)) {
                $handlerObj = new $className;
                if ($handlerObj->isSupported()) {
                    $handlers[$p_handlerName] = $handlerObj;
                    return $handlerObj;
                }
            }
        }
        return null;
    }
Ejemplo n.º 4
0
 public function postDispatch()
 {
     // run internal cron scheduler
     if (SystemPref::Get('ExternalCronManagement') == 'N') {
         camp_cron();
     }
 }
Ejemplo n.º 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;
}
Ejemplo n.º 6
0
 public function indexAction()
 {
     $this->view->stats = $this->_helper->service('stat')->getAll();
     // saving them here to retrieve later, because these are not available when run in cli
     SystemPref::set('support_stats_server', $this->view->stats['server']);
     SystemPref::set('support_stats_ip_address', $this->view->stats['ipAddress']);
     SystemPref::set('support_stats_ram_total', $this->view->stats['ramTotal']);
     if ($this->getRequest()->isPost() && $this->_getParam('support_send') !== null) {
         $values = $this->getRequest()->getPost();
         try {
             $askTime = new DateTime($values['stat_ask_time']);
         } catch (Exception $e) {
             $askTime = new DateTime('7 days');
         }
         SystemPref::set('stat_ask_time', $askTime->getTimestamp());
         SystemPref::set('support_send', $values['support_send']);
         $this->_helper->flashMessenger(getGS('Support settings saved.'));
         if ($this->_getParam('action') === 'popup') {
             $this->_helper->redirector('index', '');
         } else {
             $this->_helper->redirector('index');
         }
     }
     $this->view->support_send = SystemPref::get('support_send');
 }
Ejemplo n.º 7
0
/**
 * Campsite render function plugin
 *
 * Type:     function
 * Name:     render
 * Purpose:  template rendering
 *
 * @param array
 *     $p_params
 * @param object
 *     $p_smarty The Smarty object
 *
 * @return
 *     rendered content
 */
function smarty_function_render($p_params, &$p_smarty)
{
    if (empty($p_params['file'])) {
        return null;
    }
    $smarty = clone $p_smarty;
    if (SystemPref::Get('TemplateCacheHandler')) {
        $campsiteVector = $smarty->campsiteVector;
        foreach ($campsiteVector as $key => $value) {
            if (isset($p_params[$key])) {
                if (empty($p_params[$key])) {
                    $campsiteVector[$key] = null;
                }
                if (is_int($p_params[$key])) {
                    $campsiteVector[$key] = $p_params[$key];
                }
            }
        }
        if (isset($p_params['params'])) {
            $campsiteVector['params'] = $p_params['params'];
        }
        $smarty->campsiteVector = $campsiteVector;
        if (empty($p_params['cache'])) {
            $template = new Template($p_params['file']);
            $smarty->cache_lifetime = (int)$template->getCacheLifetime();
        } else {
            $smarty->cache_lifetime = (int)$p_params['cache'];
        }
    }
    return $smarty->display($p_params['file']);

} // fn smarty_function_render
Ejemplo n.º 8
0
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $supportSend = \SystemPref::get('support_send');
     if ($supportSend) {
         $stats = $this->getHelper('container')->getService('stat')->getAll();
         $statsUrl = 'http://stat.sourcefabric.org';
         $parameters = array('p' => 'newscoop');
         $parameters['installation_id'] = $stats['installationId'];
         $parameters['server'] = \SystemPref::get('support_stats_server');
         $parameters['ip_address'] = \SystemPref::get('support_stats_ip_address');
         $parameters['ram_used'] = $stats['ramUsed'];
         $parameters['ram_total'] = \SystemPref::get('support_stats_ram_total');
         $parameters['version'] = $stats['version'];
         $parameters['install_method'] = $stats['installMethod'];
         $parameters['publications'] = $stats['publications'];
         $parameters['issues'] = $stats['issues'];
         $parameters['sections'] = $stats['sections'];
         $parameters['articles'] = $stats['articles'];
         $parameters['articles_published'] = $stats['articlesPublished'];
         $parameters['languages'] = $stats['languages'];
         $parameters['authors'] = $stats['authors'];
         $parameters['subscribers'] = $stats['subscribers'];
         $parameters['backend_users'] = $stats['backendUsers'];
         $parameters['images'] = $stats['images'];
         $parameters['attachments'] = $stats['attachments'];
         $parameters['topics'] = $stats['topics'];
         $parameters['comments'] = $stats['comments'];
         $parameters['hits'] = $stats['hits'];
         $client = new \Zend_Http_Client();
         $client->setUri($statsUrl);
         $client->setParameterPost($parameters);
         $response = $client->request('POST');
     }
 }
Ejemplo n.º 9
0
 /**
  * Get maximum upload file size
  *
  * @return string
  */
 public function maxFileSize()
 {
     $maxFileSize = SystemPref::Get('MaxUploadFileSize');
     if (!$maxFileSize) {
         $maxFileSize = ini_get('upload_max_filesize');
     }
     return strtolower((string) $maxFileSize) . 'b';
 }
Ejemplo n.º 10
0
 /**
  * @return boolean
  */
 public function validate()
 {
     $privateKey = SystemPref::Get('PLUGIN_RECAPTCHA_PRIVATE_KEY');
     $resp = recaptcha_check_answer($privateKey,
         $_SERVER['REMOTE_ADDR'],
         $_POST['recaptcha_challenge_field'],
         $_POST['recaptcha_response_field']);
     return $resp->is_valid;
 }
Ejemplo n.º 11
0
	/**
	 * Try to connect the resource based on supplied parameter.
	 *
	 * @param string (optional)
     *      Host/Server alias [online | local]
     *
	 * @return boolean|PEAR_Error
     *
	 */
	public function connect($host = null)
	{
		global $Campsite;
		global $g_ado_db;

		if ($host == 'local') {
			if (isset($g_ado_db)
				&& $g_ado_db->host == $Campsite['DATABASE_SERVER_ADDRESS']) {
				return true;
			} else {
				$g_ado_db = ADONewConnection('mysql');
				$g_ado_db->SetFetchMode(ADODB_FETCH_ASSOC);
				if ($g_ado_db->Connect($Campsite['DATABASE_SERVER_ADDRESS'],
							$Campsite['DATABASE_USER'],
							$Campsite['DATABASE_PASSWORD'],
							$Campsite['DATABASE_NAME'])) {
					return true;
				} else {
					return false;
				}
			}
		}

		$g_ado_db_tmp = $g_ado_db;

       	$this->m_rDbName = $Campsite['DATABASE_NAME'];
		$this->m_rDbHost = SystemPref::Get('DBReplicationHost')
                           . ':'
                           . SystemPref::Get('DBReplicationPort');
		$this->m_rDbUser = SystemPref::Get('DBReplicationUser');
		$this->m_rDbPass = SystemPref::Get('DBReplicationPass');

		if (isset($g_ado_db) && $g_ado_db->host == $this->m_rDbHost) {
			return true;
		}
		if ($this->m_rDbHost == ':'
				|| is_null($this->m_rDbUser)
				|| is_null($this->m_rDbPass)) {
			return false;
		}
		$g_ado_db = ADONewConnection('mysql');
		$g_ado_db->SetFetchMode(ADODB_FETCH_ASSOC);
		if ($g_ado_db->Connect($this->m_rDbHost,
					$this->m_rDbUser,
					$this->m_rDbPass,
					$this->m_rDbName) == false) {
			$g_ado_db = $g_ado_db_tmp;
			return false;
		} else {
			return true;
		}
	} // fn connect
Ejemplo n.º 12
0
 public function preDispatch()
 {
     $uri = CampSite::GetURIInstance();
     $themePath = $uri->getThemePath();
     $this->view = new Newscoop\SmartyView();
     $this->view->addScriptPath(APPLICATION_PATH . '/views/scripts/')->addScriptPath(realpath(APPLICATION_PATH . "/../themes/{$themePath}"));
     $this->view->addPath(realpath(APPLICATION_PATH . "/../themes/{$themePath}"));
     $this->getHelper('viewRenderer')->setView($this->view)->setViewScriptPathSpec(':controller_:action.:suffix')->setViewSuffix('tpl');
     $this->getHelper('layout')->disableLayout();
     $this->view->publication = $this->getRequest()->getServer('SERVER_NAME', 'localhost');
     $this->view->site = \SystemPref::Get('SiteTitle');
     $this->_helper->contextSwitch()->addActionContext('comment-notify', 'xml')->initContext();
 }
Ejemplo n.º 13
0
/**
 * Campsite teaser modifier plugin
 *
 * Type:     modifier
 * Name:     teaser
 * Purpose:  build an teaser our of input
 *
 * @param string
 *     $p_input the string or object
 * @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_teaser($p_input, $p_length = null)
{
    if (empty($length)) {
        $length = is_null(SystemPref::Get('teaser_length')) ? 100 : SystemPref::Get('teaser_length');
    }
    $pattern = '/<!-- *break *-->/i';
    if (is_object($p_input) && method_exists($p_input, '__toString')) {
        $input = $p_input->__toString();
    } else {
        $input = (string) $p_input;
    }
    $output = node_teaser($input, null, $length);
    return $output;
}
Ejemplo n.º 14
0
 private static function GetImageFormats()
 {
     $formats[] = array('width' => 100, 'height' => 100);
     $format_prefs = SystemPref::Get("PLUGIN_BLOG_IMAGE_DERIVATES");
     
     if (strlen($format_prefs)) {
         foreach (explode("\n", $format_prefs) as $format) {
             if (preg_match('/([0-9]*) *[xX] *([0-9]*)/', $format, $matched)) {
                 $formats[] = array('width' => $matched[1], 'height' => $matched[2]);
             }   
         }
     }
     return (array) $formats;
 }
Ejemplo n.º 15
0
 /**
  *  Constructor - pelase DON'T CALL IT, use factory method instead
  *
  *  @param mdefs array, hash array with methods description
  *  @param debug int, XMLRPC debug flag
  *  @param verbose boolean, verbosity flag
  *
  *  @return this
  */
 public function XR_CcClient($mdefs, $debug = 0, $verbose = FALSE)
 {
     $this->mdefs = $mdefs;
     $this->debug = $debug;
     $this->verbose = $verbose;
     $serverPath = "http://" . SystemPref::Get('CampcasterHostName') . ":" . SystemPref::Get('CampcasterHostPort') . SystemPref::Get('CampcasterXRPCPath') . SystemPref::Get('CampcasterXRPCFile');
     if ($this->verbose) {
         echo "serverPath: {$serverPath}\n";
     }
     $url = parse_url($serverPath);
     if ($url === false) {
         $this->client = null;
     } else {
         $this->client = new XML_RPC_Client($url['path'], $url['host'], $url['port']);
     }
 }
Ejemplo n.º 16
0
    private function __construct()
    {
        parent::Smarty();

        $config = CampSite::GetConfigInstance();

        $this->debugging = $config->getSetting('smarty.debugging');
        $this->force_compile = $config->getSetting('smarty.force_compile');
        $this->compile_check = $config->getSetting('smarty.compile_check');
        $this->use_sub_dirs = $config->getSetting('smarty.use_subdirs');

        // cache settings
        $cacheHandler = SystemPref::Get('TemplateCacheHandler');
        if ($cacheHandler) {
            $this->caching = 1;
            $this->cache_handler_func = "TemplateCacheHandler_$cacheHandler::handler";
            require_once CS_PATH_SITE.DIR_SEP.'classes'.DIR_SEP.'cache'.DIR_SEP."TemplateCacheHandler_$cacheHandler.php";
        } else {
            $this->caching = 0;
        }

        // define dynamic uncached block
        require_once CS_PATH_SMARTY.DIR_SEP.'campsite_plugins/block.dynamic.php';
        $this->register_block('dynamic', 'smarty_block_dynamic', false);

        // define render function
        require_once CS_PATH_SMARTY.DIR_SEP.'campsite_plugins/function.render.php';
        $this->register_function('render', 'smarty_function_render', false);

        $this->left_delimiter = $config->getSetting('smarty.left_delimeter');
        $this->right_delimiter = $config->getSetting('smarty.right_delimeter');

        $this->cache_dir = CS_PATH_SITE.DIR_SEP.'cache';
        $this->config_dir = CS_PATH_SMARTY.DIR_SEP.'configs';

        $plugin_smarty_camp_plugin_paths = array();
        foreach (CampPlugin::GetEnabled() as $CampPlugin) {
            $plugin_smarty_camp_plugin_paths[] = CS_PATH_SITE.DIR_SEP.$CampPlugin->getBasePath().DIR_SEP.'smarty_camp_plugins';
        }

        $this->plugins_dir = array_merge(array(CS_PATH_SMARTY.DIR_SEP.'campsite_plugins',
                                               CS_PATH_SMARTY.DIR_SEP.'plugins'),
                                         $plugin_smarty_camp_plugin_paths);
        $this->template_dir = CS_PATH_TEMPLATES;
        $this->compile_dir = CS_PATH_SITE.DIR_SEP.'templates_cache';
    } // fn __constructor
Ejemplo n.º 17
0
	/**
     * Checks if failed login attempts exceeds the number of
     * failed login attempts saved in the System Preferences.
     *
	 * @return boolean
	 */
	public static function MaxLoginAttemptsExceeded()
	{
		global $g_ado_db;
		$userIp = getenv('REMOTE_ADDR');
		$maxFailuresAllowed = SystemPref::Get('LoginFailedAttemptsNum');
		if (is_null($maxFailuresAllowed)) {
			$maxFailuresAllowed = 3;
		}
		$queryStr = "SELECT COUNT(*) FROM FailedLoginAttempts WHERE ip_address='".$userIp."'";
		$ip_num = $g_ado_db->GetOne($queryStr);

		if ($ip_num >= $maxFailuresAllowed) {
			return true;
		} else {
			return false;
		}
	} // fn MaxLoginAttemptsExceeded
    /**
     * 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 (!is_null($this->m_error)) {
            return false;
        }

        $user = $p_context->user;
        
        if ($user->defined) {
            $this->m_properties['user_name'] = $p_context->user->name;
            $this->m_properties['user_email'] = $p_context->user->email;
        } else {
            switch(SystemPref::Get('PLUGIN_BLOGCOMMENT_MODE')) {                
                case 'name':
                    if (!strlen($this->m_properties['user_name'])) {
                        $this->m_error = new PEAR_Error('Name was empty.', ACTION_BLOGCOMMENT_ERR_NO_NAME);
                        return false;
                    } 
                break;   
                
                case 'email':
                    if (!strlen($this->m_properties['user_name'])) {
                        $this->m_error = new PEAR_Error('Name was empty.', ACTION_BLOGCOMMENT_ERR_NO_NAME);
                        return false;    
                    }
                    if (!CampMail::ValidateAddress($this->m_properties['user_email'])) {
                        $this->m_error = new PEAR_Error('Email was empty or invalid.', ACTION_BLOGCOMMENT_ERR_NO_EMAIL); 
                        return false;   
                    } 
                break;
                
                case 'registered':
                default:
                    $this->m_error = new PEAR_Error('Only registered users can post comments.', ACTION_BLOGCOMMENT_ERR_NOT_REGISTERED);
                    return false;     
                break;
            }
        }
        
        $this->m_error = ACTION_OK;
        return true;
    }
Ejemplo n.º 19
0
 /**
  * Set session lifetime
  *
  * @return void
  */
 private function setSessionLifetime()
 {
     $auth = Zend_Auth::getInstance();
     $session = new Zend_Session_Namespace($auth->getStorage()->getNamespace());
     $seconds = SystemPref::Get('SiteSessionLifeTime');
     $gc_works = ini_get('session.gc_probability');
     if (!empty($gc_works)) {
         $max_seconds = 0 + ini_get('session.gc_maxlifetime');
         if (!empty($max_seconds)) {
             if ($seconds > $max_seconds) {
                 $seconds = $max_seconds;
             }
         }
     }
     if ($seconds > 0) {
         $session->setExpirationSeconds($seconds);
     }
 }
Ejemplo n.º 20
0
    /**
     * Class constructor.
     *
     * @param integer $p_imageId
     *      The image identifier
     * @param integer $p_imageRatio
     *      The ratio for image resize
     * @param integer $p_imageWidth
     *      The max width for image resize
     * @param integer $p_imageHeight
     *      The max height for image resize
     */
    public function __construct($p_imageId, $p_imageRatio=100, $p_imageWidth = 0, $p_imageHeight = 0)
    {
        $this->m_basePath = $GLOBALS['g_campsiteDir'].'/images/';
        $this->m_ttl = SystemPref::Get('ImagecacheLifetime');

        if (empty($p_imageId) || !is_numeric($p_imageId)) {
            $this->ExitError('Invalid parameters');
        }
        if($p_imageRatio > 0 && $p_imageRatio < 100) {
            $this->m_ratio = $p_imageRatio;
        }
        if($p_imageWidth > 0) {
            $this->m_resizeWidth = $p_imageWidth;
        }
        if($p_imageHeight > 0) {
            $this->m_resizeHeight = $p_imageHeight;
        }
        $this->GetImage($p_imageId);
    }   // fn __construct
Ejemplo n.º 21
0
 /**
  */
 public function __construct()
 {
     parent::__construct();
     $config = CampSite::GetConfigInstance();
     $this->debugging = $config->getSetting('smarty.debugging');
     $this->force_compile = $config->getSetting('smarty.force_compile');
     $this->compile_check = $config->getSetting('smarty.compile_check');
     $this->use_sub_dirs = $config->getSetting('smarty.use_subdirs');
     $this->allow_php_tag = true;
     // cache settings
     $cacheHandler = SystemPref::Get('TemplateCacheHandler');
     $auth = Zend_Auth::getInstance();
     if ($cacheHandler) {
         $this->caching = 1;
         $this->caching_type = 'newscoop';
         CampTemplateCache::factory();
     } else {
         $this->caching = 0;
     }
     if (self::isDevelopment()) {
         $this->force_compile = true;
     }
     // define dynamic uncached block
     require_once APPLICATION_PATH . self::PLUGINS . '/block.dynamic.php';
     $this->registerPlugin('block', 'dynamic', 'smarty_block_dynamic', false);
     // define render function
     require_once APPLICATION_PATH . self::PLUGINS . '/function.render.php';
     $this->registerPlugin('function', 'render', 'smarty_function_render', false);
     $this->left_delimiter = '{{';
     $this->right_delimiter = '}}';
     $this->auto_literal = false;
     $this->cache_dir = APPLICATION_PATH . '/../cache';
     $this->config_dir = APPLICATION_PATH . '/../configs';
     $this->compile_dir = APPLICATION_PATH . '/../cache';
     $this->plugins_dir = array_merge((array) $this->plugins_dir, array(APPLICATION_PATH . self::PLUGINS), self::getPluginsPluginsDir());
     $this->template_dir = array(APPLICATION_PATH . '/../themes/', APPLICATION_PATH . '/../themes/unassigned/system_templates/', APPLICATION_PATH . self::SCRIPTS);
     if (isset($GLOBALS['controller'])) {
         $this->assign('view', $GLOBALS['controller']->view);
     }
 }
Ejemplo n.º 22
0
 /**
  * Class constructor.
  *
  * @param integer $p_imageId
  *      The image identifier
  * @param integer $p_imageRatio
  *      The ratio for image resize
  * @param integer $p_imageWidth
  *      The max width for image resize
  * @param integer $p_imageHeight
  *      The max height for image resize
  */
 public function __construct($p_imageId, $p_imageRatio = 100, $p_imageWidth = 0, $p_imageHeight = 0, $p_imageCrop = null, $p_resizeCrop = null)
 {
     $this->m_basePath = $GLOBALS['g_campsiteDir'] . '/images/';
     $this->m_ttl = SystemPref::Get('ImagecacheLifetime');
     if (empty($p_imageId) || !is_numeric($p_imageId)) {
         $this->ExitError('Invalid parameters');
     }
     if ($p_imageRatio > 0 && $p_imageRatio < 100) {
         $this->m_ratio = $p_imageRatio;
     }
     if ($p_imageWidth > 0) {
         $this->m_resizeWidth = $p_imageWidth;
     }
     if ($p_imageHeight > 0) {
         $this->m_resizeHeight = $p_imageHeight;
     }
     if (!is_null($p_imageCrop)) {
         $availableCropOptions = array('top-left', 'top-right', 'bottom-left', 'bottom-right', 'center-left', 'center-right', 'top-center', 'bottom-center', 'top', 'bottom', 'left', 'right', 'center', 'center-center');
         if (in_array($p_imageCrop, $availableCropOptions)) {
             if ($p_imageCrop == 'top' || $p_imageCrop == 'bottom') {
                 $p_imageCrop = $p_imageCrop . '-center';
             }
             if ($p_imageCrop == 'left' || $p_imageCrop == 'right') {
                 $p_imageCrop = 'center-' . $p_imageCrop;
             }
             if ($p_imageCrop == 'center') {
                 $p_imageCrop = 'center-center';
             }
             $this->m_crop = $p_imageCrop;
         }
     }
     if (!is_null($p_resizeCrop)) {
         $availableCropOptions = array('top', 'bottom', 'left', 'right', 'center');
         if (in_array($p_resizeCrop, $availableCropOptions)) {
             $this->m_resizeCrop = $p_resizeCrop;
         }
     }
     $this->GetImage($p_imageId);
 }
Ejemplo n.º 23
0
 /**
  * Set the system preferences to the given value.
  * If the preference key was not already registered, 
  * it will added to database.
  *
  * @param string $p_varName
  * @param mixed $p_value
  *
  * @return void
  */
 public static function Set($p_varName, $p_value)
 {
     global $Campsite;
     global $g_ado_db;
     if (empty($p_varName) || !is_string($p_varName)) {
         return;
     }
     if (!isset($Campsite['system_preferences'])) {
         SystemPref::__LoadConfig();
     }
     if (array_key_exists($p_varName, $Campsite['system_preferences'])) {
         if ($Campsite['system_preferences'][$p_varName] != $p_value) {
             $sql = "UPDATE SystemPreferences SET value=" . $g_ado_db->escape($p_value) . " WHERE varname=" . $g_ado_db->escape($p_varName);
             $g_ado_db->Execute($sql);
             $Campsite['system_preferences'][$p_varName] = $p_value;
             self::StoreSystemPrefsInCache();
         }
     } else {
         $sql = "INSERT INTO SystemPreferences\n\t\t\t\t    (varname, value) VALUES (" . $g_ado_db->escape($p_varName) . ", " . $g_ado_db->escape($p_value) . ")";
         $g_ado_db->Execute($sql);
         $Campsite['system_preferences'][$p_varName] = $p_value;
         self::StoreSystemPrefsInCache();
     }
 }
Ejemplo n.º 24
0
    /**
     * Process the image statement given in Campsite internal formatting.
     * Returns a standard image URL.
     *
     * @param array $p_matches
     * @return string
     */
    public static function ProcessImageLink(array $p_matches) {
    	$context = CampTemplate::singleton()->context();
    	$oldImage = $context->image;
        $uri = $context->url;
        if ($uri->article->number == 0) {
            return '';
        }

        $imageNumber = $p_matches[1];
        $detailsString = $p_matches[2];
        $detailsArray = array();
        if (trim($detailsString) != '') {
        	$imageAttributes = 'align|alt|sub|width|height|ratio|\w+';
        	preg_match_all("/[\s]+($imageAttributes)=\"([^\"]+)\"/i", $detailsString, $detailsArray1);
        	$detailsArray1[1] = array_map('strtolower', $detailsArray1[1]);
        	if (count($detailsArray1[1]) > 0) {
        		$detailsArray1 = array_combine($detailsArray1[1], $detailsArray1[2]);
        	} else {
        		$detailsArray1 = array();
        	}
        	preg_match_all("/[\s]+($imageAttributes)=([^\"\s]+)/i", $detailsString, $detailsArray2);
        	$detailsArray2[1] = array_map('strtolower', $detailsArray2[1]);
        	if (count($detailsArray2[1]) > 0) {
        		$detailsArray2 = array_combine($detailsArray2[1], $detailsArray2[2]);
        	} else {
        		$detailsArray2 = array();
        	}
        	$detailsArray = array_merge($detailsArray1, $detailsArray2);
        }

        $articleImage = new ArticleImage($uri->article->number, null, $imageNumber);
        $imageObj = $articleImage->getImage();
        $image = new MetaImage($articleImage->getImageId());
        $context->image = $image;
        $imageSize = @getimagesize($imageObj->getImageStorageLocation());
        unset($imageObj);

        $imageOptions = '';
        $defaultOptions = array('ratio'=>'EditorImageRatio', 'width'=>'EditorImageResizeWidth',
        'height'=>'EditorImageResizeHeight');
        foreach (array('ratio', 'width', 'height') as $imageOption) {
        	$defaultOption = (int)SystemPref::Get($defaultOptions[$imageOption]);
        	if (isset($detailsArray[$imageOption]) && $detailsArray[$imageOption] > 0) {
        		$imageOptions .= " $imageOption " . (int)$detailsArray[$imageOption];
        	} elseif ($imageOption != 'ratio' && $defaultOption > 0) {
        		$imageOptions .= " $imageOption $defaultOption";
        	} elseif ($imageOption == 'ratio' && $defaultOption != 100) {
        		$imageOptions .= " $imageOption $defaultOption";
        	}
        }
        $imageOptions = trim($imageOptions);

        $imgZoomLink = '';
        if (SystemPref::Get("EditorImageZoom") == 'Y' && strlen($imageOptions) > 0) {
        	$uri->uri_parameter = "image";
            $imgZoomLink = '<a href="' . $uri->uri . '" class="photoViewer" ';
            if (isset($detailsArray['sub']) && !empty($detailsArray['sub'])) {
                $imgZoomLink .= 'title="' . $detailsArray['sub'] . '">';
            } else {
                $imgZoomLink .= 'title="">';
            }
        }

        $isCentered = false;
        $imgString = '</p><div class="cs_img"';
        if (isset($detailsArray['align']) && !empty($detailsArray['align'])) {
            if ($detailsArray['align'] == 'middle') {
                $imgString = '</p><div align="center"><div class="cs_img"';
                $isCentered = true;
            } else {
                $imgString .= ' style="float:' . $detailsArray['align'] . ';"';
            }
        }
        $imgString .= '>';
        $imgString .= (strlen($imgZoomLink) > 0) ? '<p>'.$imgZoomLink : '<p>';
        $uri->uri_parameter = "image $imageOptions";
        $imgString .= '<img src="' . $uri->uri . '"';
        if (isset($detailsArray['alt']) && !empty($detailsArray['alt'])) {
            $imgString .= ' alt="' . $detailsArray['alt'] . '"';
        }
        if (isset($detailsArray['sub']) && !empty($detailsArray['sub'])) {
            $imgString .= ' title="' . $detailsArray['sub'] . '"';
        }
        $imgString .= ' border="0"/>';
        $imgString .= (strlen($imgZoomLink) > 0) ? '</a></p>' : '</p>';
        if (isset($detailsArray['sub']) && !empty($detailsArray['sub'])) {
            $imgString .= '<p class="cs_img_caption">';
            $imgString .= $detailsArray['sub'] . '</p>';
        }
        if ($isCentered) {
            $imgString .= '</div></div><p>';
        } else {
            $imgString .= '</div><p>';
        }
        $context->image = $oldImage;

        return $imgString;
    }
Ejemplo n.º 25
0
 public static function GetTopicInfoByPref($p_prefName, $p_languageId = null)
 {
     //global $g_ado_db;
     $topic_name_str = SystemPref::Get($p_prefName);
     if (empty($topic_name_str)) {
         return null;
     }
     $topic_name_obj = new TopicName($topic_name_str, $p_languageId);
     if (!$topic_name_obj->m_exists) {
         return null;
     }
     /*
             'SELECT fk_topic_id FROM TopicName WHERE name = ? AND fk_language_id = ?';
     
     		$rows = $g_ado_db->GetAll($sql);
     		foreach ($rows as $row) {
     			$tmpObj = new TopicName();
     			$tmpObj->fetch($row);
     			$names[$row['fk_language_id']] = $tmpObj;
     		}
     		return $names;
     */
     return array('name' => $topic_name_str, 'id' => $topic_name_obj->getTopicId());
 }
Ejemplo n.º 26
0
    /**
     * @param string $p_value
     * @return boolean
     */
    public function setKeywords($p_value)
    {
        require_once($GLOBALS['g_campsiteDir'].'/classes/SystemPref.php');
        $keywordsSeparator = SystemPref::Get('KeywordSeparator');
        $p_value = str_replace($keywordsSeparator, ",", $p_value);
        CampCache::singleton()->clear('user');

        return parent::setProperty('Keywords', $p_value);
    } // fn setKeywords
Ejemplo n.º 27
0
    //if ($needs_menu) {
        //$content .= "</td></tr>\n</table>\n";
    //}
    //$content .= "</html>\n";
    echo $content;

    camp_html_clear_msgs(true);
} elseif (file_exists($Campsite['HTML_DIR'] . "/$ADMIN_DIR/$call_script")) {
    readfile($Campsite['HTML_DIR'] . "/$ADMIN_DIR/$call_script");
} else {
    header("HTTP/1.1 404 Not found");
    exit;
}

// run internal cron scheduler
if (SystemPref::Get('ExternalCronManagement') == 'N') {
    flush();
    camp_cron();
}

/**
 * Sets a user-defined error function.
 *
 *  The function set_error_handler() works differently in PHP 4 & 5.
 *  This function is a wrapper interface, to both versions of
 *  set_error_handler.
 *
 * @param $p_function The function to execute on error
 * @return void
 */
function camp_set_error_handler($p_function)
Ejemplo n.º 28
0
 function __construct(&$smarty)
 {
     $this->smarty = $smarty;
     $this->cacheClass = 'TemplateCacheHandler_' . SystemPref::Get('TemplateCacheHandler');
 }
Ejemplo n.º 29
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
Ejemplo n.º 30
0
$campsite = new CampSite();
// loads site configuration settings
$campsite->loadConfiguration(CS_PATH_CONFIG . DIR_SEP . 'configuration.php');
// starts the session
$campsite->initSession();
$session = CampSite::GetSessionInstance();
$configDb = array('hostname' => $Campsite['db']['host'], 'hostport' => $Campsite['db']['port'], 'username' => $Campsite['db']['user'], 'userpass' => $Campsite['db']['pass'], 'database' => $Campsite['db']['name']);
$session->setData('config.db', $configDb, 'installation');
// upgrading the database
$res = camp_upgrade_database($Campsite['DATABASE_NAME'], true, true);
if ($res !== 0) {
    display_upgrade_error("While upgrading the database: {$res}");
}
CampCache::singleton()->clear('user');
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();