Пример #1
0
 /**
  * Constructor.
  *
  * If the folder name is not provided, it will default to
  * Pluf::f('template_folders')
  * If the cache folder name is not provided, it will default to
  * Pluf::f('tmp_folder')
  *
  * @param string Template name.
  * @param string Template folder paths (null)
  * @param string Cache folder name (null)
  */
 function __construct($template, $folders = null, $cache = null)
 {
     $this->tpl = $template;
     if (null == $folders) {
         $this->folders = Pluf::f('template_folders');
     } else {
         $this->folders = $folders;
     }
     if (null == $cache) {
         $this->cache = Pluf::f('tmp_folder');
     } else {
         $this->cache = $cache;
     }
     if (defined('IN_UNIT_TESTS')) {
         if (!isset($GLOBALS['_PX_tests_templates'])) {
             $GLOBALS['_PX_tests_templates'] = array();
         }
     }
     $this->compiled_template = $this->getCompiledTemplateName();
     $b = $this->compiled_template[1];
     $this->class = 'Pluf_Template_' . $b;
     $this->compiled_template = $this->compiled_template[0];
     if (!class_exists($this->class, false)) {
         if (!file_exists($this->compiled_template) or Pluf::f('debug')) {
             $compiler = new Pluf_Template_Compiler($this->tpl, $this->folders);
             $this->template_content = $compiler->getCompiledTemplate();
             $this->write($b);
         }
         include $this->compiled_template;
     }
 }
Пример #2
0
 function __construct($exception, $mimetype = null)
 {
     $content = '';
     $admins = Pluf::f('admins', array());
     if (count($admins) > 0) {
         // Get a nice stack trace and send it by emails.
         $stack = Pluf_HTTP_Response_ServerError_Pretty($exception);
         $subject = $exception->getMessage();
         $subject = substr(strip_tags(nl2br($subject)), 0, 50) . '...';
         foreach ($admins as $admin) {
             $email = new Pluf_Mail($admin[1], $admin[1], $subject);
             $email->addTextMessage($stack);
             $email->sendMail();
         }
     }
     try {
         $context = new Pluf_Template_Context(array('message' => $exception->getMessage()));
         $tmpl = new Pluf_Template('500.html');
         $content = $tmpl->render($context);
         $mimetype = null;
     } catch (Exception $e) {
         $mimetype = 'text/plain';
         $content = 'The server encountered an unexpected condition which prevented it from fulfilling your request.' . "\n\n" . 'An email has been sent to the administrators, we will correct this error as soon as possible. Thank you for your comprehension.' . "\n\n" . '500 - Internal Server Error';
     }
     parent::__construct($content, $mimetype);
     $this->status_code = 500;
 }
Пример #3
0
 /**
  * Save the model in the database.
  *
  * @param bool Commit in the database or not. If not, the object
  *             is returned but not saved in the database.
  * @return Object Model with data set from the form.
  */
 function save($commit = true)
 {
     if (!$this->isValid()) {
         throw new Exception(__('Cannot save the model from an invalid form.'));
     }
     return Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailDo', array($this->cleaned_data['key']));
 }
Пример #4
0
/**
 * Returns the path to access the file.
 */
function Pluf_DB_Field_File_Path($field, $method, $model, $args = null)
{
    if (strlen($model->{$field}) != 0) {
        return Pluf::f('upload_path') . '/' . $model->{$field};
    }
    return '';
}
Пример #5
0
 /**
  * @param mixed Values, will be encoded using json_encode
  */
 function __construct($data, $mimetype = null)
 {
     if (null == $mimetype) {
         $mimetype = Pluf::f('mimetype_json', 'application/json') . '; charset=utf-8';
     }
     parent::__construct(json_encode($data), $mimetype);
 }
Пример #6
0
 /**
  * Process the request.
  *
  * @param Pluf_HTTP_Request The request
  * @return bool false
  */
 function process_request(&$request)
 {
     // Find which language to use. By priority:
     // A session value with 'pluf_language'
     // A cookie with 'pluf_language'
     // The browser information.
     $lang = false;
     if (!empty($request->session)) {
         $lang = $request->session->getData('pluf_language', false);
         if ($lang and !in_array($lang, Pluf::f('languages', array('en')))) {
             $lang = false;
         }
     }
     if ($lang === false and !empty($request->COOKIE[Pluf::f('lang_cookie', 'pluf_language')])) {
         $lang = $request->COOKIE[Pluf::f('lang_cookie', 'pluf_language')];
         if ($lang and !in_array($lang, Pluf::f('languages', array('en')))) {
             $lang = false;
         }
     }
     if ($lang === false) {
         // will default to 'en'
         $lang = Pluf_Translation::getAcceptedLanguage(Pluf::f('languages', array('en')));
     }
     Pluf_Translation::loadSetLocale($lang);
     $request->language_code = $lang;
     return false;
 }
Пример #7
0
    /**
     * Process the response of a view.
     *
     * If the status code and content type are allowed, add the
     * tracking code.
     *
     * @param Pluf_HTTP_Request The request
     * @param Pluf_HTTP_Response The response
     * @return Pluf_HTTP_Response The response
     */
    function process_response($request, $response)
    {
        if (!Pluf::f('google_analytics_id', false)) {
            return $response;
        }
        if (!in_array($response->status_code, array(200, 201, 202, 203, 204, 205, 206, 404, 501))) {
            return $response;
        }
        $ok = false;
        $cts = array('text/html', 'text/html', 'application/xhtml+xml');
        foreach ($cts as $ct) {
            if (false !== strripos($response->headers['Content-Type'], $ct)) {
                $ok = true;
                break;
            }
        }
        if ($ok == false) {
            return $response;
        }
        $js = '<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
</script>
<script type="text/javascript"> try {
var pageTracker = _gat._getTracker("' . Pluf::f('google_analytics_id') . '");
pageTracker._trackPageview(); } catch(err) {}
</script>';
        $response->content = str_replace('</body>', $js . '</body>', $response->content);
        return $response;
    }
Пример #8
0
 public function testAddPrefixedViews()
 {
     $res = Pluf_Dispatcher::addPrefixToViewFile('/alternate', Pluf::f('app_views'));
     $this->assertEquals('#^/alternate/$#', $res[0]['regex']);
     $this->assertEquals('Todo_Views', $res[0]['model']);
     $this->assertEquals('#^/alternate/install/$#', $res[1]['regex']);
 }
Пример #9
0
 function __construct($request, $vars = array())
 {
     $vars = array_merge(array('request' => $request), $vars);
     foreach (Pluf::f('template_context_processors', array()) as $proc) {
         Pluf::loadFunction($proc);
         $vars = array_merge($proc($request), $vars);
     }
     $params = array('request' => $request, 'context' => $vars);
     /**
      * [signal]
      *
      * Pluf_Template_Context_Request::construct
      *
      * [sender]
      *
      * Pluf_Template_Context_Request
      *
      * [description]
      *
      * This signal allows an application to dynamically modify the
      * context array.
      *
      * [parameters]
      *
      * array('request' => $request,
      *       'context' => array());
      *
      */
     Pluf_Signal::send('Pluf_Template_Context_Request::construct', 'Pluf_Template_Context_Request', $params);
     $this->_vars = new Pluf_Template_ContextVars($params['context']);
 }
Пример #10
0
 public static function url($file = '')
 {
     if ($file !== '' && Pluf::f('last_update_file', false) && false !== ($last_update = Pluf::fileExists(Pluf::f('last_update_file')))) {
         $file = $file . '?' . substr(md5(filemtime($last_update)), 0, 5);
     }
     return Pluf::f('url_media', Pluf::f('app_base') . '/media') . $file;
 }
Пример #11
0
 function setUp()
 {
     $GLOBALS['_PX_config']['log_delayed'] = false;
     Pluf_Log::$level = Pluf_Log::ALL;
     Pluf_Log::$stack = array();
     $this->logfile = Pluf::f('pluf_log_file', Pluf::f('tmp_folder', '/tmp') . '/pluf.log');
     @unlink($this->logfile);
 }
Пример #12
0
 protected function setUp()
 {
     Pluf::start(dirname(__FILE__) . '/../conf/pluf.config.php');
     Pluf::loadFunction('Pluf_HTTP_URL_buildReverseUrl');
     Pluf::loadFunction('Pluf_HTTP_URL_reverse');
     $d = new Pluf_Dispatcher();
     $d->loadControllers(Pluf::f('app_views'));
 }
Пример #13
0
/**
 * Get the default DB connection.
 *
 * The default database connection is defined in the configuration file
 * through the following configuration variables:
 * - db_login : Login to connect to the database
 * - db_password : Password to the database
 * - db_server : Name of the server
 * - db_database : Name of the database
 * - db_table_prefix : Prefix for the table names
 * - db_version : Version of the database engine
 * - db_engine : Engine for exampe 'MySQL', 'SQLite'
 *
 * Once the first connection is created the following calls to Pluf::db()
 * are getting the same connection.
 *
 */
function Pluf_DB_getConnection($extra = null)
{
    if (isset($GLOBALS['_PX_db']) && (is_resource($GLOBALS['_PX_db']->con_id) or is_object($GLOBALS['_PX_db']->con_id))) {
        return $GLOBALS['_PX_db'];
    }
    $GLOBALS['_PX_db'] = Pluf_DB::get(Pluf::f('db_engine'), Pluf::f('db_server'), Pluf::f('db_database'), Pluf::f('db_login'), Pluf::f('db_password'), Pluf::f('db_table_prefix'), Pluf::f('debug'), Pluf::f('db_version'));
    return $GLOBALS['_PX_db'];
}
Пример #14
0
 /**
  * Predelete to drop the row level permissions.
  */
 function preDelete()
 {
     if (Pluf::f('pluf_use_rowpermission', false)) {
         $_rpt = Pluf::factory('Pluf_RowPermission')->getSqlTable();
         $sql = new Pluf_SQL('owner_class=%s AND owner_id=%s', array($this->_a['model'], $this->_data['id']));
         $this->_con->execute('DELETE FROM ' . $_rpt . ' WHERE ' . $sql->gen());
     }
 }
Пример #15
0
 /**
  * Return a "URL friendly" version in lowercase.
  * 
  * Define the words separator with the configuration 
  * option <code>slug-separator</code>. Default to <code>-</code>.
  *
  * @param $value string Value to convert
  * @return string The slugify version.
  */
 public static function slugify($value)
 {
     $separator = Pluf::f('slug-separator', '-');
     $value = Pluf_Text_UTF8::romanize(Pluf_Text_UTF8::deaccent($value));
     $value = preg_replace('#[^' . $separator . '\\w]#u', $separator, mb_strtolower($value, Pluf::f('encoding', 'UTF-8')));
     // remove redundant
     $value = preg_replace('#' . $separator . '{2,}#u', $separator, trim($value, $separator));
     return $value;
 }
Пример #16
0
 /**
  * Set a value in the cache.
  *
  * @param string Key to store the information
  * @param mixed Value to store
  * @param int Timeout in seconds (null)
  * @return bool Success
  */
 public function set($key, $value, $timeout = null)
 {
     if ($this->memcache) {
         if ($timeout == null) {
             $timeout = Pluf::f('cache_timeout', 300);
         }
         $this->memcache->set($this->keyprefix . $key, serialize($value), Pluf::f('cache_memcached_compress', 0), $timeout);
     }
 }
Пример #17
0
 /**
  * Flush the stack to the disk.
  *
  * @param $stack Array
  */
 public static function write($stack)
 {
     $file = Pluf::f('pluf_log_file', Pluf::f('tmp_folder', '/tmp') . '/pluf.log');
     $out = array();
     foreach ($stack as $elt) {
         $out[] = date(DATE_ISO8601, (int) $elt[0]) . ' ' . Pluf_Log::$reverse[$elt[1]] . ': ' . json_encode($elt[2]);
     }
     file_put_contents($file, implode(PHP_EOL, $out) . PHP_EOL, FILE_APPEND);
 }
Пример #18
0
 /**
  * Process the request.
  *
  * @param Pluf_HTTP_Request The request
  * @return bool false
  */
 function process_request(&$request)
 {
     if (0 !== strpos($request->query, Pluf::f('maintenance_root')) && file_exists(Pluf::f('tmp_folder') . '/MAINTENANCE')) {
         $res = new Pluf_HTTP_Response('Server in maintenance' . "\n\n" . 'We are upgrading the system to make it better for you, please try again later...', 'text/plain');
         $res->status_code = 503;
         return $res;
     }
     return false;
 }
Пример #19
0
function Pluf_Migrations_Install_teardown($params = null)
{
    $models = array('Pluf_Queue', 'Pluf_Search_Stats', 'Pluf_Search_Occ', 'Pluf_Search_Word', 'Pluf_RowPermission', 'Pluf_Permission', 'Pluf_Message', Pluf::f('pluf_custom_group', 'Pluf_Group'), Pluf::f('pluf_custom_user', 'Pluf_User'), 'Pluf_Session', 'Pluf_DB_SchemaInfo');
    $db = Pluf::db();
    $schema = new Pluf_DB_Schema($db);
    foreach ($models as $model) {
        $schema->model = new $model();
        $schema->dropTables();
    }
}
Пример #20
0
 /**
  * Return false or an array with the email and id.
  *
  * This is a static function to be reused by other forms.
  *
  * @param string Confirmation key
  * @return mixed Either false or array(email, id)
  */
 public static function checkKeyHash($key)
 {
     $hash = substr($key, 0, 2);
     $encrypted = substr($key, 2);
     if ($hash != substr(md5(Pluf::f('secret_key') . $encrypted), 0, 2)) {
         return false;
     }
     $cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
     return explode(':', $cr->decrypt($encrypted), 2);
 }
Пример #21
0
 /**
  * Display the configuration variable.
  * 
  * @param string Configuration variable.
  * @param mixed Default value to return display ('').
  * @param bool Display the value (true).
  * @param string Prefix to set to the variable if not displayed ('cfg_').
  */
 function start($cfg, $default = '', $display = true, $prefix = 'cfg_')
 {
     if ($cfg != 'secret_key' or 0 !== strpos($cfg, 'db_')) {
         if ($display) {
             echo Pluf::f($cfg, $default);
         } else {
             $this->context->set($prefix . $cfg, Pluf::f($cfg, $default));
         }
     }
 }
Пример #22
0
 /**
  * Factory.
  *
  * @return Pluf_Cache_* Cache object
  */
 public static function factory()
 {
     if (false === ($engine = Pluf::f('cache_engine', false))) {
         throw new Pluf_Exception_SettingError('"cache_engine" setting not defined.');
     }
     if (!isset($GLOBALS['_PX_Pluf_Cache-' . $engine])) {
         $GLOBALS['_PX_Pluf_Cache-' . $engine] = new $engine();
     }
     return $GLOBALS['_PX_Pluf_Cache-' . $engine];
 }
Пример #23
0
 /**
  * Set a value in the cache.
  *
  * @param string Key to store the information
  * @param mixed Value to store
  * @param int Timeout in seconds (null)
  * @return bool Success
  */
 public function set($key, $value, $timeout = null)
 {
     if ($timeout == null) {
         $timeout = Pluf::f('cache_timeout', 300);
     }
     $value = serialize($value);
     if ($this->compress) {
         $value = gzdeflate($value, 9);
     }
     return apc_store($this->keyprefix . $key, $value, $timeout);
 }
Пример #24
0
 /**
  * Generate a new session key.
  */
 function getNewSessionKey()
 {
     while (1) {
         $key = md5(microtime() . rand(0, 123456789) . rand(0, 123456789) . Pluf::f('secret_key'));
         $sess = $this->getList(array('filter' => 'session_key=\'' . $key . '\''));
         if (count($sess) == 0) {
             break;
         }
     }
     return $key;
 }
Пример #25
0
 function callbackWikiPage($m)
 {
     $sql = new Pluf_SQL('project=%s AND title=%s', array($this->project->id, $m[2]));
     $pages = Pluf::factory('IDF_WikiPage')->getList(array('filter' => $sql->gen()));
     if ($pages->count() != 1 and $this->request->rights['hasWikiAccess'] and !$this->request->user->isAnonymous()) {
         return '<img style="vertical-align: text-bottom;" alt=" " src="' . Pluf::f('url_media') . '/idf/img/add.png" /><a href="' . Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::create', array($this->project->shortname), array('name' => $m[2])) . '" title="' . __('Create this documentation page') . '">' . $m[1] . '</a>';
     }
     if (!$this->request->rights['hasWikiAccess'] or $pages->count() == 0) {
         return $m[1];
     }
     return '<a href="' . Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view', array($this->project->shortname, $pages[0]->title)) . '" title="' . Pluf_esc($pages[0]->summary) . '">' . $m[1] . '</a>';
 }
Пример #26
0
 /**
  * Clean the attachments post failure.
  */
 function failed()
 {
     $upload_path = Pluf::f('upload_issue_path', false);
     if ($upload_path == false) {
         return;
     }
     for ($i = 1; $i < 4; $i++) {
         if (!empty($this->cleaned_data['attachment' . $i]) and file_exists($upload_path . '/' . $this->cleaned_data['attachment' . $i])) {
             @unlink($upload_path . '/' . $this->cleaned_data['attachment' . $i]);
         }
     }
 }
Пример #27
0
 /**
  * Create a new migration.
  *
  * @param mixed Application or array of applications to migrate.
  */
 public function __construct($app = null)
 {
     if (!is_null($app)) {
         if (is_array($app)) {
             $this->apps = $app;
         } else {
             $this->apps = array($app);
         }
     } else {
         $this->apps = Pluf::f('installed_apps');
     }
 }
Пример #28
0
function IDF_Migrations_9ShortDescription_down($params = null)
{
    $table = Pluf::factory('IDF_Project')->getSqlTable();
    $sql = array();
    $sql['PostgreSQL'] = 'ALTER TABLE ' . $table . ' DROP COLUMN "shortdesc"';
    $sql['MySQL'] = 'ALTER TABLE ' . $table . ' DROP COLUMN `shortdesc`';
    $db = Pluf::db();
    $engine = Pluf::f('db_engine');
    if (!isset($sql[$engine])) {
        throw new Exception('SQLite complex migration not supported.');
    }
    $db->execute($sql[$engine]);
}
Пример #29
0
 function testAssertLog()
 {
     if (Pluf::f('test_log_testremote', false) == false) {
         return;
     }
     Pluf_Log::activeAssert();
     $GLOBALS['_PX_config']['log_delayed'] = true;
     assert('Pluf_Log::alog("hello")');
     $this->assertEqual(count(Pluf_Log::$stack), 1);
     $GLOBALS['_PX_config']['log_delayed'] = false;
     assert('Pluf_Log::alog("hello")');
     $this->assertEqual(count(Pluf_Log::$stack), 0);
 }
Пример #30
0
function IDF_Migrations_12DownloadDesc_down($params = null)
{
    $table = Pluf::factory('IDF_Upload')->getSqlTable();
    $sql = array();
    $sql['PostgreSQL'] = 'ALTER TABLE ' . $table . ' DROP COLUMN "changelog"';
    $sql['MySQL'] = 'ALTER TABLE ' . $table . ' DROP COLUMN `changelog`';
    $db = Pluf::db();
    $engine = Pluf::f('db_engine');
    if (!isset($sql[$engine])) {
        throw new Exception('SQLite complex migration not supported.');
    }
    $db->execute($sql[$engine]);
}