Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * Display the main page of the application.
  *
  * The main page is only displaying data. So we load the categories
  * and for each category we display the corresponding items.
  *
  * @param Pluf_HTTP_Request Request object
  * @param array Matches against the regex of the dispatcher
  * @return Pluf_HTTP_Response or can throw Exception
  */
 public function main($request, $match)
 {
     // In the main page we want a list of all the Todo lists with
     // a link to edit each of them, a link to see the content and
     // a link to create a new list.
     // Get the complete list of Todo_List object
     $lists = Pluf::factory('Todo_List')->getList();
     // Create a context for the template
     $context = new Pluf_Template_Context(array('page_title' => 'Home', 'lists' => $lists));
     // Load a template
     $tmpl = new Pluf_Template('todo/index.html');
     // Render the template and send the response to the user
     return new Pluf_HTTP_Response($tmpl->render($context));
 }
Ejemplo n.º 3
0
 function __construct($request)
 {
     $content = '';
     try {
         $context = new Pluf_Template_Context(array('query' => $request->query));
         $tmpl = new Pluf_Template('403.html');
         $content = $tmpl->render($context);
         $mimetype = null;
     } catch (Exception $e) {
         $mimetype = 'text/plain';
         $content = 'You are not authorized to view this page. You do not have permission' . "\n" . 'to view the requested directory or page using the credentials supplied.' . "\n\n" . '403 - Forbidden';
     }
     parent::__construct($content, $mimetype);
     $this->status_code = 403;
 }
Ejemplo n.º 4
0
 function __construct($request)
 {
     $content = '';
     try {
         $context = new Pluf_Template_Context(array('query' => $request->query));
         $tmpl = new Pluf_Template('404.html');
         $content = $tmpl->render($context);
         $mimetype = null;
     } catch (Exception $e) {
         $mimetype = 'text/plain';
         $content = sprintf('The requested URL %s was not found on this server.' . "\n" . 'Please check the URL and try again.' . "\n\n" . '404 - Not Found', Pluf_esc($request->query));
     }
     parent::__construct($content, $mimetype);
     $this->status_code = 404;
 }
Ejemplo n.º 5
0
 /**
  * Send the reminder email.
  *
  */
 function save($commit = true)
 {
     if (!$this->isValid()) {
         throw new Exception(__('Cannot save the model from an invalid form.'));
     }
     $account = $this->cleaned_data['account'];
     $sql = new Pluf_SQL('email=%s OR login=%s', array($account, $account));
     $users = Pluf::factory('Pluf_User')->getList(array('filter' => $sql->gen()));
     $return_url = '';
     foreach ($users as $user) {
         if ($user->active) {
             $return_url = Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecoveryInputCode');
             $tmpl = new Pluf_Template('idf/user/passrecovery-email.txt');
             $cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
             $code = trim($cr->encrypt($user->email . ':' . $user->id . ':' . time()), '~');
             $code = substr(md5(Pluf::f('secret_key') . $code), 0, 2) . $code;
             $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecovery', array($code), array(), false);
             $urlic = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecoveryInputCode', array(), array(), false);
             $context = new Pluf_Template_Context(array('url' => Pluf_Template::markSafe($url), 'urlik' => Pluf_Template::markSafe($urlic), 'user' => Pluf_Template::markSafe($user), 'key' => Pluf_Template::markSafe($code)));
             $email = new Pluf_Mail(Pluf::f('from_email'), $user->email, __('Password Recovery - InDefero'));
             $email->setReturnPath(Pluf::f('bounce_email', Pluf::f('from_email')));
             $email->addTextMessage($tmpl->render($context));
             $email->sendMail();
         }
         if (!$user->active and $user->first_name == '---') {
             $return_url = Pluf_HTTP_URL_urlForView('IDF_Views::registerInputKey');
             IDF_Form_Register::sendVerificationEmail($user);
         }
     }
     return $return_url;
 }
Ejemplo n.º 6
0
 function __construct($request)
 {
     $content = '';
     try {
         $context = new Pluf_Template_Context(array('query' => $request->query));
         $tmpl = new Pluf_Template('503.html');
         $content = $tmpl->render($context);
         $mimetype = null;
     } catch (Exception $e) {
         $mimetype = 'text/plain';
         $content = sprintf('The requested URL %s is not available at the moment.' . "\n" . 'Please try again later.' . "\n\n" . '503 - Service Unavailable', Pluf_esc($request->query));
     }
     parent::__construct($content, $mimetype);
     $this->status_code = 503;
     $this->headers['Retry-After'] = 300;
     // retry after 5 minutes
 }
Ejemplo n.º 7
0
/**
 * Render a template file and an array as a reponse.
 *
 * If a none null request object is given, the context used will
 * automatically be a Pluf_Template_Context_Request context and thus
 * the context will be populated using the
 * 'template_context_processors' functions.
 *
 * @param string Template file name
 * @param array Associative array for the context
 * @param Pluf_HTTP_Request Request object (null)
 * @return Pluf_HTTP_Response The response with the rendered template
 */
function Pluf_Shortcuts_RenderToResponse($tplfile, $params, $request = null)
{
    $tmpl = new Pluf_Template($tplfile);
    if (is_null($request)) {
        $context = new Pluf_Template_Context($params);
    } else {
        $context = new Pluf_Template_Context_Request($request, $params);
    }
    return new Pluf_HTTP_Response($tmpl->render($context));
}
Ejemplo n.º 8
0
 /**
  * @see Pluf_Template_Tag::start()
  * @param string $token Variables to test.
  * @param string $fallback Literal string to used when all passed variables are false.
  * @throws InvalidArgumentException If no argument is provided.
  */
 public function start($tokens = array(), $fallback = null)
 {
     if (!is_array($tokens) || 0 === count($tokens)) {
         throw new InvalidArgumentException('`firstof` tag requires at least one array as argument');
     }
     $result = (string) $fallback;
     foreach ($tokens as $var) {
         if ($var) {
             $result = Pluf_Template::markSafe((string) $var);
             break;
         }
     }
     echo $result;
 }
Ejemplo n.º 9
0
 /**
  * Returns a HTML snippet with a line-by-line pre-rendered table
  * for the given source content
  *
  * @param array file information as returned by getMimeType or getMimeTypeFromContent
  * @param string the content of the file
  * @return string
  */
 public static function highLight($fileinfo, $content)
 {
     $pretty = '';
     if (self::isSupportedExtension($fileinfo[2])) {
         $pretty = ' prettyprint';
     }
     $table = array();
     $i = 1;
     foreach (preg_split("/\r\n|\r|\n/", $content) as $line) {
         $table[] = '<tr class="c-line"><td class="code-lc" id="L' . $i . '"><a href="#L' . $i . '">' . $i . '</a></td>' . '<td class="code mono' . $pretty . '">' . IDF_Diff::padLine(Pluf_esc($line)) . '</td></tr>';
         $i++;
     }
     return Pluf_Template::markSafe(implode("\n", $table));
 }
Ejemplo n.º 10
0
 public function initFields($extra = array())
 {
     $this->user = $extra['user'];
     $this->fields['first_name'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('First name'), 'initial' => $this->user->first_name, 'widget_attrs' => array('maxlength' => 50, 'size' => 15)));
     $this->fields['last_name'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Last name'), 'initial' => $this->user->last_name, 'widget_attrs' => array('maxlength' => 50, 'size' => 20)));
     $this->fields['email'] = new Pluf_Form_Field_Email(array('required' => true, 'label' => __('Email'), 'initial' => $this->user->email, 'widget_attrs' => array('maxlength' => 50, 'size' => 20)));
     $this->fields['language'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Language'), 'initial' => $this->user->language, 'widget' => 'Pluf_Form_Widget_SelectInput', 'widget_attrs' => array('choices' => Pluf_L10n::getInstalledLanguages())));
     $this->fields['password'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Password'), 'initial' => '', 'widget' => 'Pluf_Form_Widget_PasswordInput', 'help_text' => Pluf_Template::markSafe(__('Leave blank if you do not want to change the password.') . '<br />' . __('The password must be hard for other people to find it, but easy for the user to remember.')), 'widget_attrs' => array('maxlength' => 50, 'size' => 15)));
     $this->fields['password2'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Confirm password'), 'initial' => '', 'widget' => 'Pluf_Form_Widget_PasswordInput', 'widget_attrs' => array('maxlength' => 50, 'size' => 15)));
     if ($extra['request']->user->administrator) {
         $this->fields['staff'] = new Pluf_Form_Field_Boolean(array('required' => false, 'label' => __('Staff'), 'initial' => $this->user->staff, 'widget' => 'Pluf_Form_Widget_CheckboxInput', 'help_text' => __('If you give staff rights to a user, you really need to trust him.')));
     }
     $attrs = $extra['request']->user->id == $this->user->id ? array('readonly' => 'readonly') : array();
     $this->fields['active'] = new Pluf_Form_Field_Boolean(array('required' => false, 'label' => __('Active'), 'initial' => $this->user->active, 'widget' => 'Pluf_Form_Widget_CheckboxInput', 'widget_attrs' => $attrs, 'help_text' => __('If the user is not getting the confirmation email or is abusing the system, you can directly enable or disable his account here.')));
 }
Ejemplo n.º 11
0
 public function initFields($extra = array())
 {
     $this->user = $extra['user'];
     $user_data = IDF_UserData::factory($this->user);
     $this->fields['first_name'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('First name'), 'initial' => $this->user->first_name, 'widget_attrs' => array('maxlength' => 50, 'size' => 15)));
     $this->fields['last_name'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Last name'), 'initial' => $this->user->last_name, 'widget_attrs' => array('maxlength' => 50, 'size' => 20)));
     $this->fields['email'] = new Pluf_Form_Field_Email(array('required' => true, 'label' => __('Email'), 'initial' => $this->user->email, 'widget_attrs' => array('maxlength' => 50, 'size' => 20)));
     $this->fields['language'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Language'), 'initial' => $this->user->language, 'widget' => 'Pluf_Form_Widget_SelectInput', 'widget_attrs' => array('choices' => Pluf_L10n::getInstalledLanguages())));
     $this->fields['password'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Password'), 'initial' => '', 'widget' => 'Pluf_Form_Widget_PasswordInput', 'help_text' => Pluf_Template::markSafe(__('Leave blank if you do not want to change the password.') . '<br />' . __('The password must be hard for other people to find it, but easy for the user to remember.')), 'widget_attrs' => array('maxlength' => 50, 'size' => 15)));
     $this->fields['password2'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Confirm password'), 'initial' => '', 'widget' => 'Pluf_Form_Widget_PasswordInput', 'widget_attrs' => array('maxlength' => 50, 'size' => 15)));
     $this->fields['description'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Description'), 'initial' => $user_data->description, 'widget_attrs' => array('rows' => 3, 'cols' => 40), 'widget' => 'Pluf_Form_Widget_TextareaInput'));
     $this->fields['twitter'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Twitter username'), 'initial' => $user_data->twitter, 'widget_attrs' => array('maxlength' => 50, 'size' => 15)));
     $this->fields['public_email'] = new Pluf_Form_Field_Email(array('required' => false, 'label' => __('Public email address'), 'initial' => $user_data->public_email, 'widget_attrs' => array('maxlength' => 50, 'size' => 15)));
     $this->fields['website'] = new Pluf_Form_Field_Url(array('required' => false, 'label' => __('Website URL'), 'initial' => $user_data->website, 'widget_attrs' => array('maxlength' => 50, 'size' => 15)));
     $this->fields['custom_avatar'] = new Pluf_Form_Field_File(array('required' => false, 'label' => __('Upload custom avatar'), 'initial' => '', 'max_size' => Pluf::f('max_upload_size', 2097152), 'move_function_params' => array('upload_path' => Pluf::f('upload_path') . '/avatars', 'upload_path_create' => true, 'upload_overwrite' => true, 'file_name' => 'user_' . $this->user->id . '_%s'), 'help_text' => __('An image file with a width and height not larger than 60 pixels (bigger images are scaled down).')));
     $this->fields['remove_custom_avatar'] = new Pluf_Form_Field_Boolean(array('required' => false, 'label' => __('Remove custom avatar'), 'initial' => false, 'widget' => 'Pluf_Form_Widget_CheckboxInput', 'widget_attrs' => array(), 'help_text' => __('Tick this to delete the custom avatar.')));
     if ($extra['request']->user->administrator) {
         $this->fields['staff'] = new Pluf_Form_Field_Boolean(array('required' => false, 'label' => __('Staff'), 'initial' => $this->user->staff, 'widget' => 'Pluf_Form_Widget_CheckboxInput', 'help_text' => __('If you give staff rights to a user, you really need to trust him.')));
     }
     $attrs = $extra['request']->user->id == $this->user->id ? array('readonly' => 'readonly') : array();
     $this->fields['active'] = new Pluf_Form_Field_Boolean(array('required' => false, 'label' => __('Active'), 'initial' => $this->user->active, 'widget' => 'Pluf_Form_Widget_CheckboxInput', 'widget_attrs' => $attrs, 'help_text' => __('If the user is not getting the confirmation email or is abusing the system, you can directly enable or disable his account here.')));
 }
Ejemplo n.º 12
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;
 }
Ejemplo n.º 13
0
 /**
  * Notification of change of the object.
  *
  * @param IDF_Conf Current configuration
  * @param bool Creation (true)
  */
 public function notify($conf, $create = true)
 {
     // Now we add to the queue, soon we will push everything in
     // the queue, including email notifications and indexing.
     // Even if the url is empty, we add to the queue as some
     // plugins may want to do something with this information in
     // an asynchronous way.
     $project = $this->get_project();
     $scm = $project->getConf()->getVal('scm', 'git');
     $url = str_replace(array('%p', '%r'), array($project->shortname, $this->scm_id), $conf->getVal('webhook_url', ''));
     $payload = array('to_send' => array('project' => $project->shortname, 'rev' => $this->scm_id, 'scm' => $scm, 'summary' => $this->summary, 'fullmessage' => $this->fullmessage, 'author' => $this->origauthor, 'creation_date' => $this->creation_dtime), 'project_id' => $project->id, 'authkey' => $project->getPostCommitHookKey(), 'url' => $url);
     $item = new IDF_Queue();
     $item->type = 'new_commit';
     $item->payload = $payload;
     $item->create();
     if ('' == $conf->getVal('source_notification_email', '')) {
         return;
     }
     $current_locale = Pluf_Translation::getLocale();
     $langs = Pluf::f('languages', array('en'));
     Pluf_Translation::loadSetLocale($langs[0]);
     $context = new Pluf_Template_Context(array('c' => $this, 'project' => $this->get_project(), 'url_base' => Pluf::f('url_base')));
     $tmpl = new Pluf_Template('idf/source/commit-created-email.txt');
     $text_email = $tmpl->render($context);
     $email = new Pluf_Mail(Pluf::f('from_email'), $conf->getVal('source_notification_email'), sprintf(__('New Commit %s - %s (%s)'), $this->scm_id, $this->summary, $this->get_project()->shortname));
     $email->addTextMessage($text_email);
     $email->sendMail();
     Pluf_Translation::loadSetLocale($current_locale);
 }
Ejemplo n.º 14
0
 public function notify($conf, $create = true)
 {
     if ('' == $conf->getVal('review_notification_email', '')) {
         return;
     }
     $current_locale = Pluf_Translation::getLocale();
     $langs = Pluf::f('languages', array('en'));
     Pluf_Translation::loadSetLocale($langs[0]);
     $context = new Pluf_Template_Context(array('review' => $this->get_review(), 'patch' => $this, 'comments' => array(), 'project' => $this->get_review()->get_project(), 'url_base' => Pluf::f('url_base')));
     $tmpl = new Pluf_Template('idf/review/review-created-email.txt');
     $text_email = $tmpl->render($context);
     $addresses = explode(';', $conf->getVal('review_notification_email'));
     foreach ($addresses as $address) {
         $email = new Pluf_Mail(Pluf::f('from_email'), $address, sprintf(__('New Code Review %s - %s (%s)'), $this->get_review()->id, $this->get_review()->summary, $this->get_review()->get_project()->shortname));
         $email->addTextMessage($text_email);
         $email->sendMail();
     }
     Pluf_Translation::loadSetLocale($current_locale);
 }
Ejemplo n.º 15
0
 public function view($request, $match)
 {
     $prj = $request->project;
     $review = Pluf_Shortcuts_GetObjectOr404('IDF_Review', $match[2]);
     $prj->inOr404($review);
     $url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view', array($prj->shortname, $review->id));
     $title = Pluf_Template::markSafe(sprintf(__('Review <a href="%s">%d</a>: %s'), $url, $review->id, $review->summary));
     $patches = $review->get_patches_list();
     $patch = $patches[0];
     $diff = new IDF_Diff(file_get_contents(Pluf::f('upload_issue_path') . '/' . $patch->patch));
     $diff->parse();
     // The form to submit comments is based on the files in the
     // diff
     if ($request->method == 'POST' and !$request->user->isAnonymous()) {
         $form = new IDF_Form_ReviewFileComment($request->POST, array('files' => $diff->files, 'user' => $request->user, 'patch' => $patch, 'project' => $prj));
         if ($form->isValid()) {
             $review_comment = $form->save();
             $review = $patch->get_review();
             $urlr = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view', array($prj->shortname, $review->id));
             $request->user->setMessage(sprintf(__('Your <a href="%s">code review %d</a> has been published.'), $urlr, $review->id));
             $url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::index', array($prj->shortname));
             $review_comment->notify($request->conf);
             return new Pluf_HTTP_Response_Redirect($url);
         }
     } else {
         $form = new IDF_Form_ReviewFileComment(null, array('files' => $diff->files, 'user' => $request->user, 'project' => $prj, 'patch' => $patch));
     }
     $scm = IDF_Scm::get($request->project);
     $files = array();
     $reviewers = array();
     foreach ($diff->files as $filename => $def) {
         $fileinfo = $scm->getPathInfo($filename, $patch->get_commit()->scm_id);
         $sql = new Pluf_SQL('cfile=%s', array($filename));
         $cts = $patch->getFileComments(array('filter' => $sql->gen(), 'order' => 'creation_dtime ASC'));
         foreach ($cts as $ct) {
             $reviewers[] = $ct->get_comment()->get_submitter();
         }
         if (count($def['chunks'])) {
             $orig_file = $fileinfo ? $scm->getFile($fileinfo) : '';
             $files[$filename] = array($diff->fileCompare($orig_file, $def, $filename), $form->f->{md5($filename)}, $cts);
         } else {
             $files[$filename] = array('', $form->f->{md5($filename)}, $cts);
         }
     }
     $reviewers = Pluf_Model_RemoveDuplicates($reviewers);
     return Pluf_Shortcuts_RenderToResponse('idf/review/view.html', array_merge(array('page_title' => $title, 'review' => $review, 'files' => $files, 'diff' => $diff, 'patch' => $patch, 'comments' => $patch->get_comments_list(array('sort' => 'id ASC')), 'form' => $form, 'reviewers' => $reviewers), IDF_Views_Issue::autoCompleteArrays($prj)), $request);
 }
Ejemplo n.º 16
0
 public function testRender()
 {
     $folders = array(dirname(__FILE__) . '/../Pluf_Template_Compiler/tpl1', dirname(__FILE__) . '/../Pluf_Template_Compiler/tpl2');
     $tmpl = new Pluf_Template('tpl-extends.html', $folders);
     $this->assertEquals("This is the base template\n\nHello blockname\n\ntoto \n\nTemplate base \"Bye bye block2\" here:Bye bye block2", $tmpl->render());
 }
Ejemplo n.º 17
0
 public function renderCompared($chunks, $filename)
 {
     $fileinfo = IDF_FileUtil::getMimeType($filename);
     $pretty = '';
     if (IDF_FileUtil::isSupportedExtension($fileinfo[2])) {
         $pretty = ' prettyprint';
     }
     $out = '';
     $cc = 1;
     $i = 0;
     foreach ($chunks as $chunk) {
         foreach ($chunk as $line) {
             $line1 = '&nbsp;';
             $line2 = '&nbsp;';
             $line[2] = strlen($line[2]) ? self::padLine(Pluf_esc($line[2])) : '&nbsp;';
             if ($line[0] and $line[1]) {
                 $class = 'diff-c';
                 $line1 = $line2 = $line[2];
             } elseif ($line[0]) {
                 $class = 'diff-r';
                 $line1 = $line[2];
             } else {
                 $class = 'diff-a';
                 $line2 = $line[2];
             }
             $out .= sprintf('<tr class="diff-line"><td class="diff-lc">%s</td><td class="%s mono%s"><code>%s</code></td><td class="diff-lc">%s</td><td class="%s mono%s"><code>%s</code></td></tr>' . "\n", $line[0], $class, $pretty, $line1, $line[1], $class, $pretty, $line2);
         }
         if (count($chunks) > $cc) {
             $out .= '<tr class="diff-next"><td>...</td><td>&nbsp;</td><td>...</td><td>&nbsp;</td></tr>' . "\n";
         }
         $cc++;
         $i++;
     }
     return Pluf_Template::markSafe($out);
 }
Ejemplo n.º 18
0
 /**
  * We need the user object and the request.
  *
  * If the user object is null (for example a non associated
  * commit), we can use the $text value for an alternative display.
  *
  * @param string Which variable to assign
  * @param Pluf_User
  * @param Pluf_HTTP_Request
  * @param string Alternate text ('')
  */
 function start($var, $user, $request, $text = '')
 {
     $t = new IDF_Template_ShowUser($this->context);
     $this->context->set($var, Pluf_Template::markSafe($t->start($user, $request, $text, false)));
 }
Ejemplo n.º 19
0
/**
 * Hex encode an email excluding the "mailto:".
 */
function Pluf_Template_safeEmail($email)
{
    $email = chunk_split(bin2hex($email), 2, '%');
    $email = '%' . substr($email, 0, strlen($email) - 1);
    return Pluf_Template::markSafe($email);
}
Ejemplo n.º 20
0
 /**
  * @see Pluf_Template_Tag::start()
  * @throws InvalidArgumentException If no argument is provided.
  */
 public function start()
 {
     $nargs = func_num_args();
     if (1 > $nargs) {
         throw new InvalidArgumentException('`cycle` tag requires at least one argument');
     }
     $result = '';
     list($key, $index) = $this->_computeIndex(func_get_args());
     switch ($nargs) {
         # (array or mixed) argument
         case 1:
             $arg = func_get_arg(0);
             if (is_array($arg)) {
                 $result = $arg[$index % count($arg)];
             } else {
                 $result = $arg;
             }
             break;
             # (array) arguments, (string) assign
         # (array) arguments, (string) assign
         case 2:
             $args = func_get_args();
             if (is_array($args[0])) {
                 $last = array_pop($args);
                 if (is_string($last) && '' === $this->context->get($last)) {
                     $value = Pluf_Utils::flattenArray($args[0]);
                     $this->context->set($last, $value);
                     list($assign_key, $assign_index) = $this->_computeIndex(array($value));
                     $result = $value[0];
                 }
                 break;
             }
             # considers all the arguments as a value to use in the cycle
         # considers all the arguments as a value to use in the cycle
         default:
             $args = Pluf_Utils::flattenArray(func_get_args());
             $result = $args[$index % count($args)];
             break;
     }
     echo Pluf_Template::markSafe((string) $result);
 }
Ejemplo n.º 21
0
 /**
  * Notification of change of the object.
  *
  * @param IDF_Conf Current configuration
  * @param bool Creation (true)
  */
 public function notify($conf, $create = true)
 {
     if ('' == $conf->getVal('downloads_notification_email', '')) {
         return;
     }
     $current_locale = Pluf_Translation::getLocale();
     $langs = Pluf::f('languages', array('en'));
     Pluf_Translation::loadSetLocale($langs[0]);
     $context = new Pluf_Template_Context(array('file' => $this, 'urlfile' => $this->getAbsoluteUrl($this->get_project()), 'project' => $this->get_project(), 'tags' => $this->get_tags_list()));
     $tmpl = new Pluf_Template('idf/downloads/download-created-email.txt');
     $text_email = $tmpl->render($context);
     $addresses = explode(',', $conf->getVal('downloads_notification_email'));
     foreach ($addresses as $address) {
         $email = new Pluf_Mail(Pluf::f('from_email'), $address, sprintf(__('New download - %s (%s)'), $this->summary, $this->get_project()->shortname));
         $email->addTextMessage($text_email);
         $email->sendMail();
     }
     Pluf_Translation::loadSetLocale($current_locale);
 }
Ejemplo n.º 22
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.'));
     }
     unset($this->cleaned_data['password2']);
     $update_pass = false;
     if (strlen($this->cleaned_data['password']) == 0) {
         unset($this->cleaned_data['password']);
     } else {
         $update_pass = true;
     }
     $old_email = $this->user->email;
     $new_email = $this->cleaned_data['email'];
     unset($this->cleaned_data['email']);
     if ($old_email != $new_email) {
         $cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
         $encrypted = trim($cr->encrypt($new_email . ':' . $this->user->id . ':' . time()), '~');
         $key = substr(md5(Pluf::f('secret_key') . $encrypted), 0, 2) . $encrypted;
         $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailDo', array($key), array(), false);
         $urlik = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailInputKey', array(), array(), false);
         $context = new Pluf_Template_Context(array('key' => Pluf_Template::markSafe($key), 'url' => Pluf_Template::markSafe($url), 'urlik' => Pluf_Template::markSafe($urlik), 'email' => $new_email, 'user' => $this->user));
         $tmpl = new Pluf_Template('idf/user/changeemail-email.txt');
         $text_email = $tmpl->render($context);
         $email = new Pluf_Mail(Pluf::f('from_email'), $new_email, __('Confirm your new email address.'));
         $email->addTextMessage($text_email);
         $email->sendMail();
         $this->user->setMessage(sprintf(__('A validation email has been sent to "%s" to validate the email address change.'), Pluf_esc($new_email)));
     }
     $this->user->setFromFormData($this->cleaned_data);
     // Add key as needed.
     if ('' !== $this->cleaned_data['ssh_key']) {
         $key = new IDF_Key();
         $key->user = $this->user;
         $key->content = $this->cleaned_data['ssh_key'];
         if ($commit) {
             $key->create();
         }
     }
     if ($commit) {
         $this->user->update();
         if ($update_pass) {
             /**
              * [signal]
              *
              * Pluf_User::passwordUpdated
              *
              * [sender]
              *
              * IDF_Form_UserAccount
              *
              * [description]
              *
              * This signal is sent when the user updated his
              * password from his account page.
              *
              * [parameters]
              *
              * array('user' => $user)
              *
              */
             $params = array('user' => $this->user);
             Pluf_Signal::send('Pluf_User::passwordUpdated', 'IDF_Form_UserAccount', $params);
         }
     }
     return $this->user;
 }
Ejemplo n.º 23
0
 /**
  * Renders the HTML of the input.
  *
  * @param string Name of the field.
  * @param mixed Value for the field, can be a non valid value.
  * @param array Extra attributes to add to the input form (array())
  * @return string The HTML string of the input.
  */
 public function render($name, $value, $extra_attrs = array())
 {
     return Pluf_Template::markSafe(self::getHtml($this->attrs['pubkey']));
 }
Ejemplo n.º 24
0
 function showCompact()
 {
     return Pluf_Template::markSafe(Pluf_esc(substr($this->content, 0, 25)) . ' [...] ' . Pluf_esc(substr($this->content, -55)));
 }
Ejemplo n.º 25
0
 public function timelineFeed($request, $match)
 {
     $prj = $request->project;
     $model_filter = @$match[2];
     $model_filter = @$match[2];
     $all_model_filters = self::getAvailableModelFilters();
     if (!array_key_exists($model_filter, $all_model_filters)) {
         $model_filter = 'all';
     }
     $title = $all_model_filters[$model_filter];
     $classes = self::determineModelClasses($request, $model_filter);
     $sqls = sprintf('model_class IN (%s)', implode(', ', $classes));
     $sql = new Pluf_SQL('project=%s AND ' . $sqls, array($prj->id));
     $params = array('filter' => $sql->gen(), 'order' => 'creation_dtime DESC', 'nb' => 20);
     $items = Pluf::factory('IDF_Timeline')->getList($params);
     $set = new Pluf_Model_Set($items, array('public_dtime' => 'public_dtime'));
     $out = array();
     foreach ($set as $item) {
         if ($item->id) {
             $out[] = $item->feedFragment($request);
         }
     }
     if ($items->count() > 0) {
         $date = Pluf_Date::gmDateToGmString($items[0]->creation_dtime);
     } else {
         $date = gmdate('c');
     }
     $out = Pluf_Template::markSafe(implode("\n", $out));
     $tmpl = new Pluf_Template('idf/index.atom');
     $feedurl = Pluf::f('url_base') . Pluf::f('idf_base') . $request->query;
     $viewurl = Pluf_HTTP_URL_urlForView('IDF_Views_Project::timeline', array($prj->shortname));
     $context = new Pluf_Template_Context_Request($request, array('body' => $out, 'date' => $date, 'title' => $title, 'feedurl' => $feedurl, 'viewurl' => $viewurl));
     return new Pluf_HTTP_Response('<?xml version="1.0" encoding="utf-8"?>' . "\n" . $tmpl->render($context), 'application/atom+xml; charset=utf-8');
 }
Ejemplo n.º 26
0
 /**
  * Notification of change of the object.
  *
  * For the moment, only email, but one can add webhooks later.
  *
  * Usage:
  * <pre>
  * $this->notify($conf); // Notify the creation
  * $this->notify($conf, false); // Notify the update of the object
  * </pre>
  *
  * @param IDF_Conf Current configuration
  * @param bool Creation (true)
  */
 public function notify($conf, $create = true)
 {
     $prj = $this->get_project();
     $to_email = array();
     if ('' != $conf->getVal('issues_notification_email', '')) {
         $langs = Pluf::f('languages', array('en'));
         $to_email[] = array($conf->getVal('issues_notification_email'), $langs[0]);
     }
     $current_locale = Pluf_Translation::getLocale();
     $id = '<' . md5($this->id . md5(Pluf::f('secret_key'))) . '@' . Pluf::f('mail_host', 'localhost') . '>';
     if ($create) {
         if (null != $this->get_owner() and $this->owner != $this->submitter) {
             $email_lang = array($this->get_owner()->email, $this->get_owner()->language);
             if (!in_array($email_lang, $to_email)) {
                 $to_email[] = $email_lang;
             }
         }
         $comments = $this->get_comments_list(array('order' => 'id ASC'));
         $context = new Pluf_Template_Context(array('issue' => $this, 'comment' => $comments[0], 'project' => $prj, 'url_base' => Pluf::f('url_base')));
         foreach ($to_email as $email_lang) {
             Pluf_Translation::loadSetLocale($email_lang[1]);
             $email = new Pluf_Mail(Pluf::f('from_email'), $email_lang[0], sprintf(__('Issue %s - %s (%s)'), $this->id, $this->summary, $prj->shortname));
             $tmpl = new Pluf_Template('idf/issues/issue-created-email.txt');
             $email->addTextMessage($tmpl->render($context));
             $email->addHeaders(array('Message-ID' => $id));
             $email->sendMail();
         }
     } else {
         $comments = $this->get_comments_list(array('order' => 'id DESC'));
         $email_sender = '';
         if (isset($comments[0])) {
             $email_sender = $comments[0]->get_submitter()->email;
         }
         foreach ($this->get_interested_list() as $interested) {
             $email_lang = array($interested->email, $interested->language);
             if (!in_array($email_lang, $to_email)) {
                 $to_email[] = $email_lang;
             }
         }
         $email_lang = array($this->get_submitter()->email, $this->get_submitter()->language);
         if (!in_array($email_lang, $to_email)) {
             $to_email[] = $email_lang;
         }
         if (null != $this->get_owner()) {
             $email_lang = array($this->get_owner()->email, $this->get_owner()->language);
             if (!in_array($email_lang, $to_email)) {
                 $to_email[] = $email_lang;
             }
         }
         $context = new Pluf_Template_Context(array('issue' => $this, 'comments' => $comments, 'project' => $prj, 'url_base' => Pluf::f('url_base')));
         foreach ($to_email as $email_lang) {
             if ($email_lang[0] == $email_sender) {
                 continue;
                 // Do not notify the one having created
                 // the comment
             }
             Pluf_Translation::loadSetLocale($email_lang[1]);
             $email = new Pluf_Mail(Pluf::f('from_email'), $email_lang[0], sprintf(__('Updated Issue %s - %s (%s)'), $this->id, $this->summary, $prj->shortname));
             $tmpl = new Pluf_Template('idf/issues/issue-updated-email.txt');
             $email->addTextMessage($tmpl->render($context));
             $email->addHeaders(array('References' => $id));
             $email->sendMail();
         }
     }
     Pluf_Translation::loadSetLocale($current_locale);
 }
Ejemplo n.º 27
0
 public function view($request, $match)
 {
     $prj = $request->project;
     $issue = Pluf_Shortcuts_GetObjectOr404('IDF_Issue', $match[2]);
     $prj->inOr404($issue);
     $comments = $issue->get_comments_list(array('order' => 'id ASC'));
     $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', array($prj->shortname, $issue->id));
     $title = Pluf_Template::markSafe(sprintf(__('Issue <a href="%s">%d</a>: %s'), $url, $issue->id, $issue->summary));
     $form = false;
     // The form is available only if logged in.
     $starred = false;
     $closed = in_array($issue->status, $prj->getTagIdsByStatus('closed'));
     $interested = $issue->get_interested_list();
     $preview = isset($request->POST['preview']) ? $request->POST['content'] : false;
     if (!$request->user->isAnonymous()) {
         $starred = Pluf_Model_InArray($request->user, $issue->get_interested_list());
         $params = array('project' => $prj, 'user' => $request->user, 'issue' => $issue);
         if ($request->method == 'POST') {
             $form = new IDF_Form_IssueUpdate(array_merge($request->POST, $request->FILES), $params);
             if (!isset($request->POST['preview']) && $form->isValid()) {
                 $issue = $form->save();
                 // Note, should return the
                 // last comment
                 $issue->notify($request->conf, false);
                 $comments = $issue->get_comments_list(array('order' => 'id DESC'));
                 $url .= '#ic' . $comments[0]->id;
                 $request->user->setMessage(sprintf(__('<a href="%s">Issue %d</a> has been updated.'), $url, $issue->id));
                 return new Pluf_HTTP_Response_Redirect($url);
             }
         } else {
             $form = new IDF_Form_IssueUpdate(null, $params);
         }
     }
     $arrays = self::autoCompleteArrays($prj);
     return Pluf_Shortcuts_RenderToResponse('idf/issues/view.html', array_merge(array('issue' => $issue, 'comments' => $comments, 'form' => $form, 'starred' => $starred, 'page_title' => $title, 'closed' => $closed, 'preview' => $preview, 'interested' => $interested->count()), $arrays), $request);
 }
Ejemplo n.º 28
0
 public function timelineFeed($request, $match)
 {
     $prj = $request->project;
     // Need to check the rights
     $rights = array();
     if (true === IDF_Precondition::accessSource($request)) {
         $rights[] = '\'IDF_Commit\'';
         IDF_Scm::syncTimeline($request->project);
     }
     if (true === IDF_Precondition::accessIssues($request)) {
         $rights[] = '\'IDF_Issue\'';
         $rights[] = '\'IDF_IssueComment\'';
     }
     if (true === IDF_Precondition::accessDownloads($request)) {
         $rights[] = '\'IDF_Upload\'';
     }
     if (true === IDF_Precondition::accessWiki($request)) {
         $rights[] = '\'IDF_WikiPage\'';
         $rights[] = '\'IDF_WikiRevision\'';
     }
     if (true === IDF_Precondition::accessReview($request)) {
         $rights[] = '\'IDF_Review_Comment\'';
         $rights[] = '\'IDF_Review_Patch\'';
     }
     if (count($rights) == 0) {
         $rights[] = '\'IDF_Dummy\'';
     }
     $sqls = sprintf('model_class IN (%s)', implode(', ', $rights));
     $sql = new Pluf_SQL('project=%s AND ' . $sqls, array($prj->id));
     $params = array('filter' => $sql->gen(), 'order' => 'creation_dtime DESC', 'nb' => 20);
     $items = Pluf::factory('IDF_Timeline')->getList($params);
     $set = new Pluf_Model_Set($items, array('public_dtime' => 'public_dtime'));
     $out = array();
     foreach ($set as $item) {
         if ($item->id) {
             $out[] = $item->feedFragment($request);
         }
     }
     if ($items->count() > 0) {
         $date = Pluf_Date::gmDateToGmString($items[0]->creation_dtime);
     } else {
         $date = gmdate('c');
     }
     $out = Pluf_Template::markSafe(implode("\n", $out));
     $tmpl = new Pluf_Template('idf/index.atom');
     $title = __('Updates');
     $feedurl = Pluf::f('url_base') . Pluf::f('idf_base') . $request->query;
     $viewurl = Pluf_HTTP_URL_urlForView('IDF_Views_Project::timeline', array($prj->shortname));
     $context = new Pluf_Template_Context_Request($request, array('body' => $out, 'date' => $date, 'title' => $title, 'feedurl' => $feedurl, 'viewurl' => $viewurl));
     return new Pluf_HTTP_Response('<?xml version="1.0" encoding="utf-8"?>' . "\n" . $tmpl->render($context), 'application/atom+xml; charset=utf-8');
 }
Ejemplo n.º 29
0
 /**
  * Notify of the update of the review.
  *
  *
  * @param IDF_Conf Current configuration
  * @param bool Creation (true)
  */
 public function notify($conf, $create = true)
 {
     $patch = $this->get_patch();
     $review = $patch->get_review();
     $prj = $review->get_project();
     $to_email = array();
     if ('' != $conf->getVal('review_notification_email', '')) {
         $langs = Pluf::f('languages', array('en'));
         $to_email[] = array($conf->getVal('issues_notification_email'), $langs[0]);
     }
     $current_locale = Pluf_Translation::getLocale();
     $reviewers = $review->getReviewers();
     if (!Pluf_Model_InArray($review->get_submitter(), $reviewers)) {
         $reviewers[] = $review->get_submitter();
     }
     $comments = $patch->getFileComments(array('order' => 'id DESC'));
     $gcomments = $patch->get_comments_list(array('order' => 'id DESC'));
     $context = new Pluf_Template_Context(array('review' => $review, 'patch' => $patch, 'comments' => $comments, 'gcomments' => $gcomments, 'project' => $prj, 'url_base' => Pluf::f('url_base')));
     // build the list of emails and lang
     foreach ($reviewers as $user) {
         $email_lang = array($user->email, $user->language);
         if (!in_array($email_lang, $to_email)) {
             $to_email[] = $email_lang;
         }
     }
     $tmpl = new Pluf_Template('idf/review/review-updated-email.txt');
     foreach ($to_email as $email_lang) {
         Pluf_Translation::loadSetLocale($email_lang[1]);
         $email = new Pluf_Mail(Pluf::f('from_email'), $email_lang[0], sprintf(__('Updated Code Review %s - %s (%s)'), $review->id, $review->summary, $prj->shortname));
         $email->addTextMessage($tmpl->render($context));
         $email->sendMail();
     }
     Pluf_Translation::loadSetLocale($current_locale);
 }
Ejemplo n.º 30
0
 /**
  * Log the user in.
  *
  * The login form is provided by the login_form.html template.
  * The '_redirect_after' hidden value is used to redirect the user
  * after successfull login. If the view is called with
  * _redirect_after set in the query as a GET variable it will be
  * available as $_redirect_after in the template.
  *
  * @param Request Request object
  * @param array Match
  * @param string Default redirect URL after login ('/')
  * @param array Extra context values (array()).
  * @param string Login form template ('login_form.html')
  * @return Response object
  */
 function login($request, $match, $success_url = '/', $extra_context = array(), $template = 'login_form.html')
 {
     if (!empty($request->REQUEST['_redirect_after'])) {
         $success_url = $request->REQUEST['_redirect_after'];
     }
     $error = '';
     if ($request->method == 'POST') {
         foreach (Pluf::f('auth_backends', array('Pluf_Auth_ModelBackend')) as $backend) {
             $user = call_user_func(array($backend, 'authenticate'), $request->POST);
             if ($user !== false) {
                 break;
             }
         }
         if (false === $user) {
             $error = __('The login or the password is not valid. The login and the password are case sensitive.');
         } else {
             if (!$request->session->getTestCookie()) {
                 $error = __('You need to enable the cookies in your browser to access this website.');
             } else {
                 $request->user = $user;
                 $request->session->clear();
                 $request->session->setData('login_time', gmdate('Y-m-d H:i:s'));
                 $user->last_login = gmdate('Y-m-d H:i:s');
                 $user->update();
                 $request->session->deleteTestCookie();
                 return new Pluf_HTTP_Response_Redirect($success_url);
             }
         }
     }
     // Show the login form
     $request->session->createTestCookie();
     $context = new Pluf_Template_Context_Request($request, array_merge(array('page_title' => __('Sign In'), '_redirect_after' => $success_url, 'error' => $error), $extra_context));
     $tmpl = new Pluf_Template($template);
     return new Pluf_HTTP_Response($tmpl->render($context));
 }