/** * 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; }
public function timelineFragment($request) { $review = $this->get_patch()->get_review(); $url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view', array($request->project->shortname, $review->id)); $out = '<tr class="log"><td><a href="' . $url . '">' . Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')) . '</a></td><td>'; $stag = new IDF_Template_ShowUser(); $user = $stag->start($this->get_submitter(), $request, '', false); $ic = in_array($review->status, $request->project->getTagIdsByStatus('closed')) ? 'issue-c' : 'issue-o'; $out .= sprintf(__('<a href="%1$s" class="%2$s" title="View review">Review %3$d</a>, %4$s'), $url, $ic, $review->id, Pluf_esc($review->summary)) . '</td>'; $out .= "\n" . '<tr class="extra"><td colspan="2"> <div class="helptext right">' . sprintf(__('Update of <a href="%s" class="%s">review %d</a>, by %s'), $url, $ic, $review->id, $user) . '</div></td></tr>'; return Pluf_Template::markSafe($out); }
/** * 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)); }
/** * @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; }
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.'))); }
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.'))); }
/** * Returns the timeline fragment for the commit. * * * @param Pluf_HTTP_Request * @return Pluf_Template_SafeString */ public function timelineFragment($request) { $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::commit', array($request->project->shortname, $this->scm_id)); $out = '<tr class="log"><td><a href="' . $url . '">' . Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')) . '</a></td><td>'; $stag = new IDF_Template_ShowUser(); $user = $stag->start($this->get_author(), $request, $this->origauthor, false); $tag = new IDF_Template_IssueComment(); $out .= $tag->start($this->summary, $request, false); if (0 && $this->fullmessage) { $out .= '<br /><br />' . $tag->start($this->fullmessage, $request, false); } $out .= '</td> </tr> <tr class="extra"> <td colspan="2"> <div class="helptext right">' . sprintf(__('Commit %s, by %s'), '<a href="' . $url . '" class="mono">' . $this->scm_id . '</a>', $user) . '</div></td></tr>'; return Pluf_Template::markSafe($out); }
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'); }
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); }
/** * Registration. * * We just ask for login, email and to agree with the terms. Then, * we go ahead and send a confirmation email. The confirmation * email will allow to set the password, first name and last name * of the user. */ function register($request, $match) { $title = __('Create Your Account'); $params = array('request' => $request); if ($request->method == 'POST') { $form = new IDF_Form_Register($request->POST, $params); if ($form->isValid()) { $user = $form->save(); // It is sending the confirmation email $url = Pluf_HTTP_URL_urlForView('IDF_Views::registerInputKey'); return new Pluf_HTTP_Response_Redirect($url); } } else { if (isset($request->GET['login'])) { $params['initial'] = array('login' => $request->GET['login']); } $form = new IDF_Form_Register(null, $params); } $context = new Pluf_Template_Context(array()); $tmpl = new Pluf_Template('idf/terms.html'); $terms = Pluf_Template::markSafe($tmpl->render($context)); return Pluf_Shortcuts_RenderToResponse('idf/register/index.html', array('page_title' => $title, 'form' => $form, 'terms' => $terms), $request); }
/** * @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); }
/** * 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); }
/** * 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; }
/** * Returns the timeline fragment for the file. * * * @param Pluf_HTTP_Request * @return Pluf_Template_SafeString */ public function timelineFragment($request) { $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::view', array($request->project->shortname, $this->id)); $out = '<tr class="log"><td><a href="' . $url . '">' . Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')) . '</a></td><td>'; $stag = new IDF_Template_ShowUser(); $user = $stag->start($this->get_submitter(), $request, '', false); $out .= sprintf(__('<a href="%1$s" title="View download">Download %2$d</a>, %3$s'), $url, $this->id, Pluf_esc($this->summary)) . '</td>'; $out .= '</tr>'; $out .= "\n" . '<tr class="extra"><td colspan="2"> <div class="helptext right">' . sprintf(__('Addition of <a href="%s">download %d</a>, by %s'), $url, $this->id, $user) . '</div></td></tr>'; return Pluf_Template::markSafe($out); }
function showCompact() { return Pluf_Template::markSafe(Pluf_esc(substr($this->content, 0, 25)) . ' [...] ' . Pluf_esc(substr($this->content, -55))); }
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); }
function IDF_Views_Source_PrettySize($size) { return Pluf_Template::markSafe(str_replace(' ', ' ', Pluf_Utils::prettySize($size))); }
/** * 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; }
/** * 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['public_key']) { $key = new IDF_Key(); $key->user = $this->user; $key->content = $this->cleaned_data['public_key']; if ($commit) { $key->create(); } } if ($commit) { $this->user->update(); // FIXME: go the extra mile and check the input lengths for // all fields here! // FIXME: this is all doubled in admin/UserUpdate! $user_data = IDF_UserData::factory($this->user); // Add or remove avatar - we need to do this here because every // single setter directly leads to a save in the database if ($user_data->avatar != '' && ($this->cleaned_data['remove_custom_avatar'] == 1 || $this->cleaned_data['custom_avatar'] != '')) { $avatar_path = Pluf::f('upload_path') . '/avatars/' . basename($user_data->avatar); if (basename($avatar_path) != '' && is_file($avatar_path)) { unlink($avatar_path); } $user_data->avatar = ''; } if ($this->cleaned_data['custom_avatar'] != '') { $user_data->avatar = $this->cleaned_data['custom_avatar']; } $user_data->description = $this->cleaned_data['description']; $user_data->twitter = $this->cleaned_data['twitter']; $user_data->public_email = $this->cleaned_data['public_email']; $user_data->website = $this->cleaned_data['website']; 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; }
/** * 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'])); }
/** * 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))); }
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'); }
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 = ' '; $line2 = ' '; $line[2] = strlen($line[2]) ? self::padLine(Pluf_esc($line[2])) : ' '; 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> </td><td>...</td><td> </td></tr>' . "\n"; } $cc++; $i++; } return Pluf_Template::markSafe($out); }
public function timelineFragment($request) { $page = $this->get_wikipage(); $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view', array($request->project->shortname, $page->title)); $out = "\n" . '<tr class="log"><td><a href="' . $url . '">' . Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')) . '</a></td><td>'; $stag = new IDF_Template_ShowUser(); $user = $stag->start($this->get_submitter(), $request, '', false); $out .= sprintf(__('<a href="%1$s" title="View page">%2$s</a>, %3$s'), $url, Pluf_esc($page->title), Pluf_esc($this->summary)); if ($this->changedRevision()) { $out .= '<div class="issue-changes-timeline">'; $changes = $this->changes; foreach ($changes as $w => $v) { $out .= '<strong>'; switch ($w) { case 'lb': $out .= __('Labels:'); break; } $out .= '</strong> '; if ($w == 'lb') { $out .= Pluf_esc(implode(', ', $v)); } else { $out .= Pluf_esc($v); } $out .= ' '; } $out .= '</div>'; } $out .= '</td></tr>'; $out .= "\n" . '<tr class="extra"><td colspan="2"> <div class="helptext right">' . sprintf(__('Change of <a href="%s">%s</a>, by %s'), $url, Pluf_esc($page->title), $user) . '</div></td></tr>'; return Pluf_Template::markSafe($out); }
public function timelineFragment($request) { $issue = $this->get_issue(); $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', array($request->project->shortname, $issue->id)); $url .= '#ic' . $this->id; $out = "\n" . '<tr class="log"><td><a href="' . $url . '">' . Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')) . '</a></td><td>'; $stag = new IDF_Template_ShowUser(); $user = $stag->start($this->get_submitter(), $request, '', false); $ic = in_array($issue->status, $request->project->getTagIdsByStatus('closed')) ? 'issue-c' : 'issue-o'; $out .= sprintf(__('<a href="%1$s" class="%2$s" title="View issue">Issue %3$d</a>, %4$s'), $url, $ic, $issue->id, Pluf_esc($issue->summary)); if ($this->changedIssue()) { $out .= '<div class="issue-changes-timeline">'; foreach ($this->changes as $w => $v) { $out .= '<strong>'; switch ($w) { case 'su': $out .= __('Summary:'); break; case 'st': $out .= __('Status:'); break; case 'ow': $out .= __('Owner:'); break; case 'lb': $out .= __('Labels:'); break; } $out .= '</strong> '; if ($w == 'lb') { $out .= Pluf_esc(implode(', ', $v)); } else { $out .= Pluf_esc($v); } $out .= ' '; } $out .= '</div>'; } $out .= '</td></tr>'; $out .= "\n" . '<tr class="extra"><td colspan="2"> <div class="helptext right">' . sprintf(__('Comment on <a href="%s" class="%s">issue %d</a>, by %s'), $url, $ic, $issue->id, $user) . '</div></td></tr>'; return Pluf_Template::markSafe($out); }