Example #1
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']);
 }
Example #2
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'));
 }
Example #3
0
 public function initFields($extra = array())
 {
     $this->conf = $extra['conf'];
     if ($extra['remote_svn']) {
         $this->fields['svn_username'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Repository username'), 'initial' => $this->conf->getVal('svn_username', ''), 'widget_attrs' => array('size' => '15')));
         $this->fields['svn_password'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Repository password'), 'initial' => $this->conf->getVal('svn_password', ''), 'widget' => 'Pluf_Form_Widget_PasswordInput'));
     }
     Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
     $url = Pluf_HTTP_URL_urlForView('idf_faq') . '#webhooks';
     $this->fields['webhook_url'] = new Pluf_Form_Field_Url(array('required' => false, 'label' => __('Webhook URL'), 'initial' => $this->conf->getVal('webhook_url', ''), 'help_text' => sprintf(__('Learn more about the <a href="%s">post-commit web hooks</a>.'), $url), 'widget_attrs' => array('size' => 35)));
 }
Example #4
0
 /**
  * Validate some possible input for the field.
  *
  * @param mixed Input
  * @return string Path to the file relative to 'upload_path'
  */
 function clean($value)
 {
     parent::clean($value);
     if (is_null($value) and !$this->required) {
         return '';
         // no file
     } elseif (is_null($value) and $this->required) {
         throw new Pluf_Form_Invalid(__('No files were uploaded. Please try to send the file again.'));
     }
     $errors = array();
     $no_files = false;
     switch ($value['error']) {
         case UPLOAD_ERR_OK:
             break;
         case UPLOAD_ERR_INI_SIZE:
             throw new Pluf_Form_Invalid(sprintf(__('The uploaded file is too large. Reduce the size of the file to %s and send it again.'), Pluf_Utils::prettySize(ini_get('upload_max_filesize'))));
             break;
         case UPLOAD_ERR_FORM_SIZE:
             throw new Pluf_Form_Invalid(sprintf(__('The uploaded file is too large. Reduce the size of the file to %s and send it again.'), Pluf_Utils::prettySize($_REQUEST['MAX_FILE_SIZE'])));
             break;
         case UPLOAD_ERR_PARTIAL:
             throw new Pluf_Form_Invalid(__('The upload did not complete. Please try to send the file again.'));
             break;
         case UPLOAD_ERR_NO_FILE:
             if ($this->required) {
                 throw new Pluf_Form_Invalid(__('No files were uploaded. Please try to send the file again.'));
             } else {
                 return '';
                 // no file
             }
             break;
         case UPLOAD_ERR_NO_TMP_DIR:
         case UPLOAD_ERR_CANT_WRITE:
             throw new Pluf_Form_Invalid(__('The server has no temporary folder correctly configured to store the uploaded file.'));
             break;
         case UPLOAD_ERR_EXTENSION:
             throw new Pluf_Form_Invalid(__('The uploaded file has been stopped by an extension.'));
             break;
         default:
             throw new Pluf_Form_Invalid(__('An error occured when upload the file. Please try to send the file again.'));
     }
     if ($value['size'] > $this->max_size) {
         throw new Pluf_Form_Invalid(sprintf(__('The uploaded file is to big (%1$s). Reduce the size to less than %2$s and try again.'), Pluf_Utils::prettySize($value['size']), Pluf_Utils::prettySize($this->max_size)));
     }
     // copy the file to the final destination and updated $value
     // with the final path name. 'final_name' is relative to
     // Pluf::f('upload_path')
     Pluf::loadFunction($this->move_function);
     // Should throw a Pluf_Form_Invalid exception if error or the
     // value to be stored in the database.
     return call_user_func($this->move_function, $value, $this->move_function_params);
 }
Example #5
0
 function __construct($user, $pwd, $server, $dbname, $pfx = '', $debug = false)
 {
     Pluf::loadFunction('Pluf_DB_defaultTypecast');
     $this->type_cast = Pluf_DB_defaultTypecast();
     $this->debug('* MYSQL CONNECT');
     $this->con_id = mysql_connect($server, $user, $pwd);
     $this->debug = $debug;
     $this->pfx = $pfx;
     if (!$this->con_id) {
         throw new Exception($this->getError());
     }
     $this->database($dbname);
     $this->execute('SET NAMES \'utf8\'');
 }
Example #6
0
 function __construct($user, $pwd, $server, $dbname, $pfx = '', $debug = false)
 {
     Pluf::loadFunction('Pluf_DB_defaultTypecast');
     $this->type_cast = Pluf_DB_defaultTypecast();
     $this->debug = $debug;
     $this->pfx = $pfx;
     $this->debug('* SQLITE OPEN');
     $this->type_cast['Pluf_DB_Field_Compressed'] = array('Pluf_DB_CompressedFromDb', 'Pluf_DB_SQLite_CompressedToDb');
     // Connect and let the Exception be thrown in case of problem
     try {
         $this->con_id = new PDO('sqlite:' . $dbname);
     } catch (PDOException $e) {
         throw $e;
     }
 }
Example #7
0
 /**
  * The $request object is used to know what the post login
  * redirect url should be.
  *
  * If the action url of the login page is not set, it will try to
  * get the url from the login view from the 'login_view'
  * configuration key.
  *
  * @param Pluf_HTTP_Request The request object of the current page.
  * @param string The full url of the login page (null)
  */
 function __construct($request, $loginurl = null)
 {
     if ($loginurl !== null) {
         $murl = new Pluf_HTTP_URL();
         $url = $murl->generate($loginurl, array('_redirect_after' => $request->uri), false);
         $encoded = $murl->generate($loginurl, array('_redirect_after' => $request->uri));
     } else {
         Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
         $url = Pluf_HTTP_URL_urlForView(Pluf::f('login_view', 'login_view'), array(), array('_redirect_after' => $request->uri), false);
         $encoded = Pluf_HTTP_URL_urlForView(Pluf::f('login_view', 'login_view'), array(), array('_redirect_after' => $request->uri));
     }
     $content = sprintf(__('<a href="%s">Please, click here to be redirected</a>.'), $encoded);
     parent::__construct($content);
     $this->headers['Location'] = $url;
     $this->status_code = 302;
 }
Example #8
0
 function __construct($user, $pwd, $server, $dbname, $pfx = '', $debug = false)
 {
     Pluf::loadFunction('Pluf_DB_defaultTypecast');
     $this->type_cast = Pluf_DB_defaultTypecast();
     $this->type_cast['Pluf_DB_Field_Boolean'] = array('Pluf_DB_PostgreSQL_BooleanFromDb', 'Pluf_DB_BooleanToDb');
     $this->type_cast['Pluf_DB_Field_Compressed'] = array('Pluf_DB_PostgreSQL_CompressedFromDb', 'Pluf_DB_PostgreSQL_CompressedToDb');
     $this->debug('* POSTGRESQL CONNECT');
     $cstring = '';
     if ($server) {
         $cstring .= 'host=' . $server . ' ';
     }
     $cstring .= 'dbname=' . $dbname . ' user='******' password=' . $pwd;
     }
     $this->debug = $debug;
     $this->pfx = $pfx;
     $this->cur = null;
     $this->con_id = @pg_connect($cstring);
     if (!$this->con_id) {
         throw new Exception($this->getError());
     }
 }
Example #9
0
 /**
  * Run the given migration.
  */
 public function runMigration($migration, $the_way = 'up')
 {
     $target_version = $the_way == 'up' ? $migration[0] : $migration[0] - 1;
     if ($this->display) {
         echo $migration[0] . ' ' . $migration[1] . ' ' . $the_way . "\n";
     }
     if (!$this->dry_run) {
         if ($the_way == 'up') {
             $func = $this->app . '_Migrations_' . $migration[1] . '_up';
         } else {
             $func = $this->app . '_Migrations_' . $migration[1] . '_down';
         }
         Pluf::loadFunction($func);
         $func();
         // Real migration run
         $this->setAppVersion($this->app, $target_version);
     }
 }
Example #10
0
 public function testLoadFunction()
 {
     Pluf::loadFunction('Pluf_HTTP_handleMagicQuotes');
     $this->assertEquals(true, function_exists('Pluf_HTTP_handleMagicQuotes'));
 }
Example #11
0
 /**
  * Helper to load the default database connection.
  *
  * This method is just dispatching to the function define in the
  * configuration by the 'db_get_connection' key or use the default
  * 'Pluf_DB_getConnection'. If you want to use your own function,
  * take a look at the Pluf_DB_getConnection function to use the
  * same approach for your method.
  *
  * The extra parameters can be used to selectively connect to a
  * given database. When the ORM is getting a connection, it is
  * passing the current model as parameter. That way you could get
  * different databases for different models.
  * 
  * @param mixed Extra parameters. 
  * @return resource DB connection.
  */
 public static function &db($extra = null)
 {
     $func = Pluf::f('db_get_connection', 'Pluf_DB_getConnection');
     Pluf::loadFunction($func);
     $a = $func($extra);
     return $a;
 }
Example #12
0
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# ***** END LICENSE BLOCK ***** */
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
Pluf::loadFunction('Pluf_Shortcuts_RenderToResponse');
/**
 * User management views.
 *
 * Edit your account.
 * Add emails for the link between a commit and an account.
 */
class IDF_Views_User
{
    /**
     * Dashboard of a user.
     *
     * Shows all the open issues assigned to the user.
     *
     * TODO: This views is a SQL horror. What needs to be done to cut
     * by many the number of SQL queries:
Example #13
0
/**
 * Display the time in a "6 days, 23 hours ago" style.
 */
function Pluf_Template_timeAgo($date, $f = "withal")
{
    Pluf::loadFunction('Pluf_Date_Easy');
    $date = Pluf_Template_timeFormat($date);
    if ($f == 'withal') {
        return Pluf_Date_Easy($date, null, 2, __('now'));
    } else {
        return Pluf_Date_Easy($date, null, 2, __('now'), false);
    }
}
Example #14
0
 /**
  * Process the request.
  *
  * When processing the request, if a session is found with
  * Pluf_User creditentials the corresponding user is loaded into
  * $request->user.
  *
  * FIXME: We should logout everybody when the session table is emptied.
  *
  * @param Pluf_HTTP_Request The request
  * @return bool false
  */
 function process_request(&$request)
 {
     $session = new Pluf_Session();
     $user_model = Pluf::f('pluf_custom_user', 'Pluf_User');
     $user = new $user_model();
     if (!isset($request->COOKIE[$session->cookie_name])) {
         // No session is defined. We set an empty user and empty
         // session.
         $request->user = $user;
         $request->session = $session;
         if (isset($request->COOKIE[$request->session->test_cookie_name])) {
             $request->session->test_cookie = $request->COOKIE[$request->session->test_cookie_name];
         }
         return false;
     }
     try {
         $data = self::_decodeData($request->COOKIE[$session->cookie_name]);
     } catch (Exception $e) {
         $request->user = $user;
         $request->session = $session;
         if (isset($request->COOKIE[$request->session->test_cookie_name])) {
             $request->session->test_cookie = $request->COOKIE[$request->session->test_cookie_name];
         }
         return false;
     }
     $set_lang = false;
     if (isset($data[$user->session_key])) {
         // We can get the corresponding user
         $found_user = new $user_model($data[$user->session_key]);
         if ($found_user->id == $data[$user->session_key]) {
             // User found!
             $request->user = $found_user;
             // If the last login is from 12h or more, set it to
             // now.
             Pluf::loadFunction('Pluf_Date_Compare');
             if (43200 < Pluf_Date_Compare($request->user->last_login)) {
                 $request->user->last_login = gmdate('Y-m-d H:i:s');
                 $request->user->update();
             }
             $set_lang = $found_user->language;
         } else {
             $request->user = $user;
         }
     } else {
         $request->user = $user;
     }
     if (isset($data['Pluf_Session_key'])) {
         $sql = new Pluf_SQL('session_key=%s', $data['Pluf_Session_key']);
         $found_session = Pluf::factory('Pluf_Session')->getList(array('filter' => $sql->gen()));
         if (isset($found_session[0])) {
             $request->session = $found_session[0];
         } else {
             $request->session = $session;
         }
     } else {
         $request->session = $session;
     }
     if ($set_lang and false == $request->session->getData('pluf_language', false)) {
         $request->session->setData('pluf_language', $set_lang);
     }
     if (isset($request->COOKIE[$request->session->test_cookie_name])) {
         $request->session->test_cookie = $request->COOKIE[$request->session->test_cookie_name];
     }
     return false;
 }
Example #15
0
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# ***** END LICENSE BLOCK ***** */
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
/**
 * Make the links to issues and commits.
 */
class IDF_Template_IssueComment extends Pluf_Template_Tag
{
    private $project = null;
    private $request = null;
    private $scm = null;
    function start($text, $request, $echo = true, $wordwrap = true, $esc = true, $autolink = true, $nl2br = false)
    {
        $this->project = $request->project;
        $this->request = $request;
        $this->scm = IDF_Scm::get($request->project);
        if ($esc) {
            $text = Pluf_esc($text);
Example #16
0
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
n# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# ***** END LICENSE BLOCK ***** */
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
Pluf::loadFunction('Pluf_Template_dateAgo');
/**
 * Base definition of a commit.
 *
 * By having a reference in the database for each commit, one can
 * easily generate a timeline or use the search engine. Commit details
 * are normally always taken from the underlining SCM.
 */
class IDF_Commit extends Pluf_Model
{
    public $_model = __CLASS__;
    function init()
    {
        $this->_a['table'] = 'idf_commits';
        $this->_a['model'] = __CLASS__;
        $this->_a['cols'] = array('id' => array('type' => 'Pluf_DB_Field_Sequence', 'blank' => true), 'project' => array('type' => 'Pluf_DB_Field_Foreignkey', 'model' => 'IDF_Project', 'blank' => false, 'verbose' => __('project'), 'relate_name' => 'commits'), 'author' => array('type' => 'Pluf_DB_Field_Foreignkey', 'model' => 'Pluf_User', 'is_null' => true, 'verbose' => __('submitter'), 'relate_name' => 'submitted_commit', 'help_text' => 'This will allow us to list the latest commits of a user in its profile.'), 'origauthor' => array('type' => 'Pluf_DB_Field_Varchar', 'blank' => false, 'size' => 150, 'help_text' => 'As we do not necessary have the mapping between the author in the database and the scm, we store the scm author commit information here. That way we can update the author info later in the process.'), 'scm_id' => array('type' => 'Pluf_DB_Field_Varchar', 'blank' => false, 'size' => 50, 'index' => true, 'help_text' => 'The id of the commit. For git, it will be the SHA1 hash, for subversion it will be the revision id.'), 'summary' => array('type' => 'Pluf_DB_Field_Varchar', 'blank' => false, 'size' => 250, 'verbose' => __('summary')), 'fullmessage' => array('type' => 'Pluf_DB_Field_Text', 'blank' => true, 'verbose' => __('changelog'), 'help_text' => 'This is the full message of the commit.'), 'creation_dtime' => array('type' => 'Pluf_DB_Field_Datetime', 'blank' => true, 'verbose' => __('creation date'), 'index' => true, 'help_text' => 'Date of creation by the scm'));
Example #17
0
 /**
  * Get the number of days to list.
  *
  * @param string Start date
  * @param string End date
  * @return int Number of days
  */
 function getDayNumber($start, $end)
 {
     Pluf::loadFunction('Pluf_Date_Compare');
     $diff = Pluf_Date_Compare($start . ' 00:00:00', $end . ' 00:00:00');
     return (int) $diff / 86400;
 }
Example #18
0
 function testRecursif()
 {
     $GLOBALS['_PX_views'] = array(array('regex' => '#^/hello/$#', 'base' => '', 'model' => 'Pluf_Tests_Dispatch_Dispatcher', 'method' => 'hello3'), array('regex' => '#^/hello/#', 'base' => '', 'sub' => array(array('regex' => '#^world/$#', 'base' => '', 'model' => 'Pluf_Tests_Dispatch_Dispatcher', 'method' => 'hello'), array('regex' => '#^hello/$#', 'base' => '', 'model' => 'Pluf_Tests_Dispatch_Dispatcher', 'method' => 'hello4'))), array('regex' => '#^/hello1/#', 'base' => '', 'sub' => array(array('regex' => '#^world/$#', 'base' => '', 'model' => 'Pluf_Tests_Dispatch_Dispatcher', 'method' => 'hello1'))), array('regex' => '#^/hello2/#', 'base' => '', 'sub' => array(array('regex' => '#^world/$#', 'base' => '', 'model' => 'Pluf_Tests_Dispatch_Dispatcher', 'method' => 'hello2'))));
     $req1 = (object) array('query' => '/hello/world/');
     // match
     $req2 = (object) array('query' => '/hello/world');
     // match second pass
     $req3 = (object) array('query' => '/hello/you/');
     // no match
     $h1 = (object) array('query' => '/hello1/world/');
     // match
     $h2 = (object) array('query' => '/hello2/world/');
     // match
     $h3 = (object) array('query' => '/hello/');
     // match
     $h4 = (object) array('query' => '/hello/hello/');
     // match
     $this->assertIdentical(200, Pluf_Dispatcher::match($req1)->status_code);
     $this->assertEqual('ok', Pluf_Dispatcher::match($req1)->content);
     $this->assertIdentical(1, Pluf_Dispatcher::match($h1));
     $this->assertIdentical(2, Pluf_Dispatcher::match($h2));
     $this->assertIdentical(3, Pluf_Dispatcher::match($h3));
     $this->assertIdentical(4, Pluf_Dispatcher::match($h4));
     $this->assertIsA(Pluf_Dispatcher::match($req2), 'Pluf_HTTP_Response_Redirect');
     $this->assertIsA(Pluf_Dispatcher::match($req3), 'Pluf_HTTP_Response_NotFound');
     Pluf::loadFunction('Pluf_HTTP_URL_reverse');
     $this->assertEqual('/hello/world/', Pluf_HTTP_URL_reverse('Pluf_Tests_Dispatch_Dispatcher::hello'));
     $this->assertEqual('/hello1/world/', Pluf_HTTP_URL_reverse('Pluf_Tests_Dispatch_Dispatcher::hello1'));
     $this->assertEqual('/hello2/world/', Pluf_HTTP_URL_reverse('Pluf_Tests_Dispatch_Dispatcher::hello2'));
     $this->assertEqual('/hello/', Pluf_HTTP_URL_reverse('Pluf_Tests_Dispatch_Dispatcher::hello3'));
     $this->assertEqual('/hello/hello/', Pluf_HTTP_URL_reverse('Pluf_Tests_Dispatch_Dispatcher::hello4'));
 }
Example #19
0
 /**
  * Return HTML to display the errors.
  */
 public function fieldErrors()
 {
     Pluf::loadFunction('Pluf_Form_renderErrorsAsHTML');
     return new Pluf_Template_SafeString(Pluf_Form_renderErrorsAsHTML($this->errors), true);
 }
Example #20
0
 public static function sendVerificationEmail($user)
 {
     Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
     $from_email = Pluf::f('from_email');
     $cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
     $encrypted = trim($cr->encrypt($user->email . ':' . $user->id), '~');
     $key = substr(md5(Pluf::f('secret_key') . $encrypted), 0, 2) . $encrypted;
     $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::registerConfirmation', array($key), array(), false);
     $urlik = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::registerInputKey', array(), array(), false);
     $context = new Pluf_Template_Context(array('key' => $key, 'url' => $url, 'urlik' => $urlik, 'user' => $user));
     $tmpl = new Pluf_Template('idf/register/confirmation-email.txt');
     $text_email = $tmpl->render($context);
     $email = new Pluf_Mail($from_email, $user->email, __('Confirm the creation of your account.'));
     $email->addTextMessage($text_email);
     $email->sendMail();
 }
Example #21
0
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# ***** END LICENSE BLOCK ***** */
Pluf::loadFunction('Pluf_Text_MarkDown_parse');
/**
 * Make the links to issues and commits.
 */
class IDF_Template_Markdown extends Pluf_Template_Tag
{
    private $project = null;
    private $request = null;
    private $scm = null;
    function start($text, $request)
    {
        $this->project = $request->project;
        $this->request = $request;
        // Replace like in the issue text
        $tag = new IDF_Template_IssueComment();
        $text = $tag->start($text, $request, false, false, false, false);
Example #22
0
 /**
  * Generate the column headers for the table.
  */
 function colHeaders()
 {
     if (empty($this->list_display)) {
         return '<tr><th>' . __('Name') . '</th></tr>' . "\n";
     } else {
         $out = '<tr>';
         foreach ($this->list_display as $key => $col) {
             if (is_array($col)) {
                 $field = $col[0];
                 $name = $col[2];
                 Pluf::loadFunction($col[1]);
             } else {
                 $name = $col;
                 $field = $key;
             }
             if (!$this->sort_link_title) {
                 $out .= '<th><span class="px-header-title">' . Pluf_esc(ucfirst($name)) . '</span>' . $this->headerSortLinks($field) . '</th>';
             } else {
                 $out .= '<th><span class="px-header-title">' . $this->headerSortLinks($field, Pluf_esc(ucfirst($name))) . '</span></th>';
             }
         }
         $out .= '</tr>' . "\n";
         return $out;
     }
 }
Example #23
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.'));
     }
     $password = Pluf_Utils::getPassword();
     $user = new Pluf_User();
     $user->setFromFormData($this->cleaned_data);
     $user->active = true;
     $user->staff = false;
     $user->administrator = false;
     $user->setPassword($password);
     $user->create();
     /**
      * [signal]
      *
      * Pluf_User::passwordUpdated
      *
      * [sender]
      *
      * IDF_Form_Admin_UserCreate
      *
      * [description]
      *
      * This signal is sent when a user is created
      * by the staff.
      *
      * [parameters]
      *
      * array('user' => $user)
      *
      */
     $params = array('user' => $user);
     Pluf_Signal::send('Pluf_User::passwordUpdated', 'IDF_Form_Admin_UserCreate', $params);
     // Create the public key as needed
     if ('' !== $this->cleaned_data['public_key']) {
         $key = new IDF_Key();
         $key->user = $user;
         $key->content = $this->cleaned_data['public_key'];
         $key->create();
     }
     // Send an email to the user with the password
     Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
     $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::login', array(), array(), false);
     $context = new Pluf_Template_Context(array('password' => Pluf_Template::markSafe($password), 'user' => $user, 'url' => Pluf_Template::markSafe($url), 'admin' => $this->request->user));
     $tmpl = new Pluf_Template('idf/gadmin/users/createuser-email.txt');
     $text_email = $tmpl->render($context);
     $email = new Pluf_Mail(Pluf::f('from_email'), $user->email, __('Your details to access your forge.'));
     $email->addTextMessage($text_email);
     $email->sendMail();
     return $user;
 }
Example #24
0
 /**
  * Overloading of the method call.
  *
  * @param string Method
  * @param array Arguments
  */
 function __call($method, $args)
 {
     // The foreign keys of the current object.
     if (isset($this->_m['get'][$method])) {
         if (isset($this->_cache[$method])) {
             return $this->_cache[$method];
         } else {
             $this->_cache[$method] = Pluf::factory($this->_m['get'][$method][0], $this->_data[$this->_m['get'][$method][1]]);
             if ($this->_cache[$method]->id == '') {
                 $this->_cache[$method] = null;
             }
             return $this->_cache[$method];
         }
     }
     // Many to many or foreign keys on the other objects.
     if (isset($this->_m['list'][$method])) {
         if (is_array($this->_m['list'][$method])) {
             $model = $this->_m['list'][$method][0];
         } else {
             $model = $this->_m['list'][$method];
         }
         $args = array_merge(array($model, $method), $args);
         return call_user_func_array(array($this, 'getRelated'), $args);
     }
     // Extra methods added by fields
     if (isset($this->_m['extra'][$method])) {
         $args = array_merge(array($this->_m['extra'][$method][0], $method, $this), $args);
         Pluf::loadFunction($this->_m['extra'][$method][1]);
         return call_user_func_array($this->_m['extra'][$method][1], $args);
     }
     throw new Exception(sprintf('Method "%s" not available.', $method));
 }
Example #25
0
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# ***** END LICENSE BLOCK ***** */
Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
Pluf::loadFunction('Pluf_Shortcuts_RenderToResponse');
Pluf::loadFunction('Pluf_Shortcuts_GetObjectOr404');
Pluf::loadFunction('Pluf_Shortcuts_GetFormForModel');
/**
 * Project's views.
 */
class IDF_Views_Project
{
    /**
     * Home page of a project.
     */
    public $home_precond = array('IDF_Precondition::baseAccess');
    public function home($request, $match)
    {
        $prj = $request->project;
        $team = $prj->getMembershipData();
        $title = (string) $prj;
        $downloads = array();
Example #26
0
 /**
  * Match a query against the actions controllers.
  *
  * @see Pluf_HTTP_URL_reverse
  *
  * @param Pluf_HTTP_Request Request object
  * @return Pluf_HTTP_Response Response object
  */
 public static function match($req, $firstpass = true)
 {
     try {
         $views = $GLOBALS['_PX_views'];
         $to_match = $req->query;
         $n = count($views);
         $i = 0;
         while ($i < $n) {
             $ctl = $views[$i];
             if (preg_match($ctl['regex'], $to_match, $match)) {
                 if (!isset($ctl['sub'])) {
                     return self::send($req, $ctl, $match);
                 } else {
                     // Go in the subtree
                     $views = $ctl['sub'];
                     $i = 0;
                     $n = count($views);
                     $to_match = substr($to_match, strlen($match[0]));
                     continue;
                 }
             }
             $i++;
         }
     } catch (Pluf_HTTP_Error404 $e) {
         // Need to add a 404 error handler
         // something like Pluf::f('404_handler', 'class::method')
     }
     if ($firstpass and substr($req->query, -1) != '/') {
         $req->query .= '/';
         $res = self::match($req, false);
         if ($res->status_code != 404) {
             Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
             $name = isset($req->view[0]['name']) ? $req->view[0]['name'] : $req->view[0]['model'] . '::' . $req->view[0]['method'];
             $url = Pluf_HTTP_URL_urlForView($name, array_slice($req->view[1], 1));
             return new Pluf_HTTP_Response_Redirect($url, 301);
         }
     }
     return new Pluf_HTTP_Response_NotFound($req);
 }