コード例 #1
0
ファイル: xhtml.php プロジェクト: roae/hello-world
 function para($class, $text, $options = array())
 {
     $text = preg_replace('/<\\/p>|<br[^<]*?>/', "\n", $text);
     # se remplazan los <br> y </p> por \n para que los comentarios viejos sean compatibles
     $text = preg_replace("/\\\\|<[^<]+?>/", "", $text);
     #se quitan todos las etiquetas html y las \ que se usan para escapar las comillas
     $text = preg_replace("/\n\\s*\n/", "</p><p>", $text);
     #se remplazan los dos saltos de lineas por una P
     $text = preg_replace('/\\n/', "<br />", $text);
     #se remplazan los saltos de linea que quedan solos por <br />
     #$comment=preg_replace('/[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-\.]+/','[E-mail]',$text);# se quitan los emails que se escriben en el mensaje
     #$comment=preg_replace('/www\.[a-zA-Z0-9\-_]+\.[a-zA-Z0-9]{2,4}|http:\/\/[a-zA-Z0-9\-_]+\.[a-zA-Z0-9]{2,4}|https:\/\/[a-zA-Z0-9\-_]+\.[a-zA-Z0-9]{2,4}/','[URL]',$comment);
     return parent::para($class, $text, $options);
 }
コード例 #2
0
ファイル: users_controller.php プロジェクト: roboshed/Zuluru
 function create_account()
 {
     if (!Configure::read('feature.manage_accounts')) {
         $this->Session->setFlash(__('This system uses ' . Configure::read('feature.manage_name') . ' to manage user accounts. Account creation through Zuluru is disabled.', true), 'default', array('class' => 'info'));
         $this->redirect('/');
     }
     if (!$this->is_admin && !$this->is_manager && $this->UserCache->currentId()) {
         $this->Session->setFlash(__('You are already logged in!', true), 'default', array('class' => 'info'));
         $this->redirect('/');
     }
     $this->_loadAddressOptions();
     $groups = $this->_loadGroupOptions();
     $this->_loadAffiliateOptions();
     $user_model = $this->Auth->authenticate->name;
     $this->set(array('user_model' => $user_model, 'id_field' => $this->Auth->authenticate->primaryKey, 'user_field' => $this->Auth->authenticate->userField, 'email_field' => $this->Auth->authenticate->emailField));
     if (!empty($this->data)) {
         // Set the default error message in advance. If it saves successfully, this will be overwritten.
         $this->Session->setFlash(sprintf(__('The %s could not be saved. Please correct the errors below and try again.', true), __('account', true)), 'default', array('class' => 'warning'));
         // The presence of data in a field that should not be filled in triggers anti-spam measures.
         // Also, anyone that fills the form out in under 15 seconds is a spambot.
         if (Configure::read('feature.antispam') && (!empty($this->data[$user_model]['subject']) || time() - $this->data[$user_model]['timestamp'] < 15)) {
             sleep(15);
             return;
         }
         // Handle affiliations
         if (Configure::read('feature.affiliates')) {
             if (Configure::read('feature.multiple_affiliates')) {
                 if (empty($this->data['Affiliate']['Affiliate'][0])) {
                     $this->Person->Affiliate->validationErrors['Affiliate'] = __('You must select at least one affiliate that you are interested in.', true);
                 }
             } else {
                 if (empty($this->data['Affiliate']['Affiliate'][0]) || count($this->data['Affiliate']['Affiliate']) > 1) {
                     $this->Person->Affiliate->validationErrors['Affiliate'] = __('You must select an affiliate that you are interested in.', true);
                 }
             }
         } else {
             $this->data['Affiliate']['Affiliate'] = array(1);
         }
         // SaveAll doesn't work correctly in this case. Save them separately, to make sure they're all validated.
         $this->Auth->authenticate->saveAll($this->data[$user_model], array('validate' => 'only'));
         $this->Person->saveAll($this->data['Person'], array('validate' => 'only'));
         foreach ($this->data['Person'] as $key => $person) {
             if (!empty($this->data['Person'][$key]['Skill']) && !$this->Person->Skill->saveAll($this->data['Person'][$key]['Skill'], array('validate' => 'only'))) {
                 $this->Person->validationErrors[$key]['Skill'] = $this->Person->Skill->validationErrors;
             }
         }
         // Make sure someone isn't forging their way into an entirely unauthorized level.
         if (!$this->is_admin && !empty($this->data['Group']['Group'])) {
             $selected_groups = $this->Group->find('all', array('contain' => false, 'conditions' => array('id' => $this->data['Group']['Group'])));
             if ($this->is_manager) {
                 $level = 5;
             } else {
                 $level = 3;
             }
             $invalid_groups = Set::extract("/Group[level>{$level}]", $selected_groups);
             if (!empty($invalid_groups)) {
                 $this->Person->Group->validationErrors['Group'] = __('You have selected an invalid group.', true);
             }
         } else {
             $selected_groups = array();
         }
         if ($this->Auth->authenticate->validates() && $this->Person->validates() && $this->Person->Group->validates() && $this->Person->Affiliate->validates()) {
             // User and person records may be in separate databases, so we need a transaction for each
             $user_transaction = new DatabaseTransaction($this->Auth->authenticate);
             $person_transaction = new DatabaseTransaction($this->Person);
             if ($this->Auth->authenticate->save($this->data)) {
                 // Tweak some data to be saved
                 $this->data['Person'][0]['user_id'] = $this->Auth->authenticate->id;
                 foreach ($this->data['Person'] as $key => $person) {
                     $person['complete'] = true;
                     if ($this->is_admin) {
                         if ($key != 0) {
                             $person['status'] = $this->data['Person'][0]['status'];
                         }
                     } else {
                         if (Configure::read('feature.auto_approve')) {
                             if ($key == 0) {
                                 // Check the requested groups and do not auto-approve above a certain level
                                 $invalid_groups = Set::extract('/Group[level>1]', $selected_groups);
                                 if (empty($invalid_groups)) {
                                     $person['status'] = 'active';
                                 }
                             } else {
                                 $person['status'] = 'active';
                             }
                         }
                     }
                     $save = array('Person' => $person, 'Affiliate' => $this->data['Affiliate']);
                     if (!empty($person['Skill'])) {
                         $save['Skill'] = $person['Skill'];
                         unset($person['Skill']);
                     }
                     if ($key == 0) {
                         $save['Group'] = $this->data['Group'];
                     } else {
                         // Assume any secondary profiles are players
                         $save['Group'] = array('Group' => array(GROUP_PLAYER));
                         if (isset($this->data['Person'][0]['status'])) {
                             $save['Person']['status'] = $this->data['Person'][0]['status'];
                         }
                     }
                     $this->Person->create();
                     if (!$this->Person->saveAll($save)) {
                         return;
                     }
                     if (!isset($parent_id)) {
                         $parent_id = $this->Person->id;
                     } else {
                         $this->Person->PeoplePerson->save(array('person_id' => $parent_id, 'relative_id' => $this->Person->id, 'approved' => true), array('validate' => false));
                     }
                 }
                 App::import('Helper', 'Html');
                 $html = new HtmlHelper();
                 if (Configure::read('feature.auto_approve')) {
                     $msg = $html->tag('h2', __('THANK YOU', true)) . $html->para(null, sprintf(__('for creating an account with %s.', true), Configure::read('organization.name')));
                 } else {
                     $msg = $html->para(null, __('Your account has been created.', true) . ' ' . __('It must be approved by an administrator before you will have full access to the site.', true) . ' ' . __('However, you can log in and start exploring right away.', true));
                 }
                 if (isset($this->params['form']['continue'])) {
                     $msg .= $html->para(null, __('Please proceed with entering your next child\'s details below.', true));
                 }
                 $this->Session->setFlash($msg, 'default', array('class' => 'success'));
                 // There may be callbacks to handle
                 // TODO: How to handle this in conjunction with third-party auth systems?
                 $this->data['Person']['id'] = $this->Person->id;
                 $components = Configure::read('callbacks.user');
                 foreach ($components as $name => $config) {
                     $component = $this->_getComponent('User', $name, $this, false, $config);
                     $component->onAdd($this->data);
                 }
                 $user_transaction->commit();
                 $person_transaction->commit();
                 if (!$this->is_logged_in) {
                     // Automatically log the user in
                     $this->data[$this->Auth->authenticate->alias]['password'] = $this->data[$this->Auth->authenticate->alias]['passwd'];
                     $this->Auth->login($this->Auth->hashPasswords($this->data));
                 }
                 if (isset($this->params['form']['continue'])) {
                     $this->redirect(array('controller' => 'people', 'action' => 'add_relative'));
                 }
                 $this->redirect('/');
             }
         }
     } else {
         // By default, select the first group
         $this->data = array('Group' => array('Group' => array(current(array_keys($groups)))));
     }
 }