Пример #1
0
 public function initFields($extra = array())
 {
     $this->user = $extra['user'];
     $this->project = $extra['project'];
     if ($this->user->hasPerm('IDF.project-owner', $this->project) or $this->user->hasPerm('IDF.project-member', $this->project)) {
         $this->show_full = true;
     }
     $this->fields['summary'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Summary'), 'initial' => '', 'widget_attrs' => array('maxlength' => 200, 'size' => 67)));
     $this->fields['description'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Description'), 'initial' => '', 'widget' => 'Pluf_Form_Widget_TextareaInput', 'widget_attrs' => array('cols' => 58, 'rows' => 7)));
     $sql = new Pluf_SQL('project=%s', array($this->project->id));
     $commits = Pluf::factory('IDF_Commit')->getList(array('order' => 'creation_dtime DESC', 'nb' => 10, 'filter' => $sql->gen()));
     $choices = array();
     foreach ($commits as $c) {
         $id = strlen($c->scm_id) > 10 ? substr($c->scm_id, 0, 10) : $c->scm_id;
         $ext = mb_strlen($c->summary) > 50 ? mb_substr($c->summary, 0, 47) . '...' : $c->summary;
         $choices[$id . ' - ' . $ext] = $c->scm_id;
     }
     $this->fields['commit'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Commit'), 'initial' => '', 'widget' => 'Pluf_Form_Widget_SelectInput', 'widget_attrs' => array('choices' => $choices)));
     $upload_path = Pluf::f('upload_issue_path', false);
     if (false === $upload_path) {
         throw new Pluf_Exception_SettingError(__('The "upload_issue_path" configuration variable was not set.'));
     }
     $md5 = md5(rand() . microtime() . Pluf_Utils::getRandomString());
     // We add .dummy to try to mitigate security issues in the
     // case of someone allowing the upload path to be accessible
     // to everybody.
     $filename = substr($md5, 0, 2) . '/' . substr($md5, 2, 2) . '/' . substr($md5, 4) . '/%s.dummy';
     $this->fields['patch'] = new Pluf_Form_Field_File(array('required' => true, 'label' => __('Patch'), 'move_function_params' => array('upload_path' => $upload_path, 'upload_path_create' => true, 'file_name' => $filename)));
     if ($this->show_full) {
         $this->fields['status'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Status'), 'initial' => 'New', 'widget_attrs' => array('maxlength' => 20, 'size' => 15)));
     }
 }
Пример #2
0
 public function testValidEmail()
 {
     $emails = array(array('*****@*****.**', true), array('test1@example.com-qwe.', false), array('*****@*****.**', true), array('*****@*****.**', true), array('cal henderson@iamcalx.com', false), array('"cal henderson"@iamcalx.com', true), array('cal@iamcalx', true), array('cal@iamcalx com', false), array('cal@hello world.com', false), array('cal@[hello].com', false), array('cal@[hello world].com', false), array('cal@[hello\\ world].com', false), array('cal@[hello.com]', true), array('cal@[hello world.com]', true), array('cal@[hello\\ world.com]', true), array('abcdefghijklmnopqrstuvwxyz@abcdefghijklmnopqrstuvwxyz', true), array('woo\\ yay@example.com', false), array('woo\\@yay@example.com', false), array('woo\\.yay@example.com', false), array('"woo yay"@example.com', true), array('"woo@yay"@example.com', true), array('"woo.yay"@example.com', true), array('"woo\\"yay"@test.com', true), array('*****@*****.**', true), array('user@???', true), array('*****@*****.**', false));
     foreach ($emails as $email) {
         $this->assertEquals($email[1], Pluf_Utils::isValidEmail($email[0]), $email[0]);
     }
 }
Пример #3
0
 public function clean($value)
 {
     parent::clean($value);
     if (in_array($value, $this->empty_values)) {
         return '';
     }
     if (!Pluf_Utils::isValidUrl($value)) {
         throw new Pluf_Form_Invalid(__('Enter a valid address.'));
     }
     return $value;
 }
Пример #4
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;
 }
Пример #5
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);
 }
Пример #6
0
 public function clean($value)
 {
     parent::clean($value);
     if (in_array($value, $this->empty_values)) {
         $value = '';
     }
     if ($value == '') {
         return $value;
     }
     $emails = preg_split('/\\s*,\\s*/', $value, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($emails as $email) {
         if (!Pluf_Utils::isValidEmail($email)) {
             throw new Pluf_Form_Invalid(__('Please enter one or more valid email addresses.'));
         }
     }
     return implode(',', $emails);
 }
Пример #7
0
 public function initFields($extra = array())
 {
     $this->user = $extra['user'];
     $this->project = $extra['project'];
     $this->issue = $extra['issue'];
     if ($this->user->hasPerm('IDF.project-owner', $this->project) or $this->user->hasPerm('IDF.project-member', $this->project)) {
         $this->show_full = true;
     }
     if ($this->show_full) {
         $this->fields['summary'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Summary'), 'initial' => $this->issue->summary, 'widget_attrs' => array('maxlength' => 200, 'size' => 67)));
     }
     $this->fields['content'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Comment'), 'initial' => '', 'widget' => 'Pluf_Form_Widget_TextareaInput', 'widget_attrs' => array('cols' => 58, 'rows' => 9)));
     $upload_path = Pluf::f('upload_issue_path', false);
     if (false === $upload_path) {
         throw new Pluf_Exception_SettingError(__('The "upload_issue_path" configuration variable was not set.'));
     }
     $md5 = md5(rand() . microtime() . Pluf_Utils::getRandomString());
     // We add .dummy to try to mitigate security issues in the
     // case of someone allowing the upload path to be accessible
     // to everybody.
     for ($i = 1; $i < 4; $i++) {
         $filename = substr($md5, 0, 2) . '/' . substr($md5, 2, 2) . '/' . substr($md5, 4) . '/%s.dummy';
         $this->fields['attachment' . $i] = new Pluf_Form_Field_File(array('required' => false, 'label' => __('Attach a file'), 'move_function_params' => array('upload_path' => $upload_path, 'upload_path_create' => true, 'file_name' => $filename)));
     }
     if ($this->show_full) {
         $this->fields['status'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Status'), 'initial' => $this->issue->get_status()->name, 'widget_attrs' => array('maxlength' => 20, 'size' => 15)));
         $initial = $this->issue->get_owner() == null ? '' : $this->issue->get_owner()->login;
         $this->fields['owner'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Owner'), 'initial' => $initial, 'widget_attrs' => array('maxlength' => 20, 'size' => 15)));
         $tags = $this->issue->get_tags_list();
         for ($i = 1; $i < 7; $i++) {
             $initial = '';
             if (isset($tags[$i - 1])) {
                 if ($tags[$i - 1]->class != 'Other') {
                     $initial = (string) $tags[$i - 1];
                 } else {
                     $initial = $tags[$i - 1]->name;
                 }
             }
             $this->fields['label' . $i] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Labels'), 'initial' => $initial, 'widget_attrs' => array('maxlength' => 50, 'size' => 20)));
         }
     }
 }
Пример #8
0
 public function initFields($extra = array())
 {
     $this->user = $extra['user'];
     $this->project = $extra['project'];
     if ($this->user->hasPerm('IDF.project-owner', $this->project) or $this->user->hasPerm('IDF.project-member', $this->project)) {
         $this->show_full = true;
     }
     $this->fields['summary'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Summary'), 'initial' => '', 'widget_attrs' => array('maxlength' => 200, 'size' => 67)));
     $this->fields['content'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Description'), 'initial' => '', 'widget' => 'Pluf_Form_Widget_TextareaInput', 'widget_attrs' => array('cols' => 58, 'rows' => 13)));
     $upload_path = Pluf::f('upload_issue_path', false);
     if (false === $upload_path) {
         throw new Pluf_Exception_SettingError(__('The "upload_issue_path" configuration variable was not set.'));
     }
     $md5 = md5(rand() . microtime() . Pluf_Utils::getRandomString());
     // We add .dummy to try to mitigate security issues in the
     // case of someone allowing the upload path to be accessible
     // to everybody.
     for ($i = 1; $i < 4; $i++) {
         $filename = substr($md5, 0, 2) . '/' . substr($md5, 2, 2) . '/' . substr($md5, 4) . '/%s.dummy';
         $this->fields['attachment' . $i] = new Pluf_Form_Field_File(array('required' => false, 'label' => __('Attach a file'), 'move_function_params' => array('upload_path' => $upload_path, 'upload_path_create' => true, 'file_name' => $filename)));
     }
     if ($this->show_full) {
         $this->fields['status'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Status'), 'initial' => 'New', 'widget_attrs' => array('maxlength' => 20, 'size' => 15)));
         $this->fields['owner'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Owner'), 'initial' => '', 'widget_attrs' => array('maxlength' => 20, 'size' => 15)));
         for ($i = 1; $i < 7; $i++) {
             $initial = '';
             switch ($i) {
                 case 1:
                     $initial = 'Type:Defect';
                     break;
                 case 2:
                     $initial = 'Priority:Medium';
                     break;
             }
             $this->fields['label' . $i] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Labels'), 'initial' => $initial, 'widget_attrs' => array('maxlength' => 50, 'size' => 20)));
         }
     }
 }
Пример #9
0
 /**
  * Set the password of a user.
  *
  * You need to manually save the user to store the password in the
  * database. The supported algorithms are md5, crc32 and sha1,
  * sha1 being the default.
  *
  * @param string New password
  * @return bool Success
  */
 function setPassword($password)
 {
     $salt = Pluf_Utils::getRandomString(5);
     $this->password = '******' . $salt . ':' . sha1($salt . $password);
     return true;
 }
Пример #10
0
function Pluf_DB_PasswordToDb($val, $db)
{
    $exp = explode(':', $val);
    if (in_array($exp[0], array('sha1', 'md5', 'crc32'))) {
        return $db->esc($val);
    }
    // We need to hash the value.
    $salt = Pluf_Utils::getRandomString(5);
    return $db->esc('sha1:' . $salt . ':' . sha1($salt . $val));
}
Пример #11
0
/**
 * Display the size of the project.
 *
 * @param string Field
 * @param IDF_Project
 * @return string
 */
function IDF_Views_Admin_projectSize($field, $project)
{
    $size = $project->getRepositorySize();
    if ($size == -1) {
        return '';
    }
    return Pluf_Utils::prettySize($size);
}
Пример #12
0
function IDF_Views_Source_PrettySizeSimple($size)
{
    return Pluf_Utils::prettySize($size);
}
Пример #13
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);
 }
Пример #14
0
 public function initFields($extra = array())
 {
     $this->user = $extra['user'];
     $this->project = $extra['project'];
     if ($this->user->hasPerm('IDF.project-owner', $this->project) or $this->user->hasPerm('IDF.project-member', $this->project)) {
         $this->show_full = true;
     }
     $contentTemplate = $this->project->getConf()->getVal('labels_issue_template', IDF_Form_IssueTrackingConf::init_template);
     $this->fields['summary'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Summary'), 'initial' => '', 'widget_attrs' => array('maxlength' => 200, 'size' => 67)));
     $this->fields['content'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Description'), 'initial' => $contentTemplate, 'widget' => 'Pluf_Form_Widget_TextareaInput', 'widget_attrs' => array('cols' => 58, 'rows' => 13)));
     $upload_path = Pluf::f('upload_issue_path', false);
     if (false === $upload_path) {
         throw new Pluf_Exception_SettingError(__('The "upload_issue_path" configuration variable was not set.'));
     }
     $md5 = md5(rand() . microtime() . Pluf_Utils::getRandomString());
     // We add .dummy to try to mitigate security issues in the
     // case of someone allowing the upload path to be accessible
     // to everybody.
     for ($i = 1; $i < 4; $i++) {
         $filename = substr($md5, 0, 2) . '/' . substr($md5, 2, 2) . '/' . substr($md5, 4) . '/%s.dummy';
         $this->fields['attachment' . $i] = new Pluf_Form_Field_File(array('required' => false, 'label' => __('Attach a file'), 'move_function_params' => array('upload_path' => $upload_path, 'upload_path_create' => true, 'file_name' => $filename)));
     }
     if ($this->show_full) {
         $this->fields['status'] = new Pluf_Form_Field_Varchar(array('required' => true, 'label' => __('Status'), 'initial' => 'New', 'widget_attrs' => array('maxlength' => 20, 'size' => 15)));
         $this->fields['owner'] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Owner'), 'initial' => '', 'widget_attrs' => array('maxlength' => 20, 'size' => 15)));
         /*
          * get predefined tags for issues from current project
          *
          * first Type:<...> and Priority:<...> will be used
          *
          */
         $predefined = preg_split("/[\r\n]+/", $extra['project']->getConf()->getVal('labels_issue_predefined'));
         $predefined_type = 'Type:Defect';
         foreach ($predefined as $tag) {
             if (strpos($tag, 'Type:') === 0) {
                 $predefined_type = explode('=', $tag, 2);
                 $predefined_type = trim($predefined_type[0]);
                 break;
             }
         }
         $predefined_priority = 'Priority:Medium';
         foreach ($predefined as $tag) {
             if (strpos($tag, 'Priority:') === 0) {
                 $predefined_priority = explode('=', $tag, 2);
                 $predefined_priority = trim($predefined_priority[0]);
                 break;
             }
         }
         for ($i = 1; $i < 7; $i++) {
             $initial = '';
             switch ($i) {
                 case 1:
                     $initial = $predefined_type;
                     break;
                 case 2:
                     $initial = $predefined_priority;
                     break;
             }
             $this->fields['label' . $i] = new Pluf_Form_Field_Varchar(array('required' => false, 'label' => __('Labels'), 'initial' => $initial, 'widget_attrs' => array('maxlength' => 50, 'size' => 20)));
         }
     }
 }
Пример #15
0
function IDF_Views_Download_Size($field, $down)
{
    return Pluf_Utils::prettySize($down->{$field});
}
Пример #16
0
 /**
  * Calculate the URL safe base64 encoded SHA1 hmac of a string.
  *
  * @param string The string to sign
  * @param string The key
  * @return string The signature
  */
 public static function base64_hmac($value, $key)
 {
     return Pluf_Utils::urlsafe_b64encode(hash_hmac('sha1', $value, $key, true));
 }