Beispiel #1
0
 protected function beforeSave()
 {
     parent::beforeSave();
     if ($this->isModified('password') && !empty($this['password'])) {
         $this->setPayload('plain_password', $this['password']);
         $this['password'] = crypt($this['password'], uniqid(mt_rand(), true));
     } else {
         $this->setNotModified('password');
     }
 }
Beispiel #2
0
 protected function beforeSave()
 {
     parent::beforeSave();
     if ($this->isIndexPage()) {
         return;
     }
     if (!$this->isReal()) {
         return;
     }
     if (empty($this['url']) && !empty($this['name'])) {
         $url = fx::util()->strToLatin($this['name']);
         $url = preg_replace("~[^a-z0-9_-]+~i", '-', $url);
         $url = trim($url, '-');
         $url = preg_replace("~\\-+~", '-', $url);
         $this['url'] = $url;
     }
     if (in_array('url', $this->modified) && !empty($this['url']) && !preg_match("~^https?://~", $this['url'])) {
         $url = $this['url'];
         if (!preg_match("~^/~", $url)) {
             $url = '/' . $url;
         }
         $index = 1;
         // check already used page url
         while ($page = fx::data('floxim.main.page')->getByUrl($url, $this['site_id'])) {
             if ($page['id'] != $this['id']) {
                 $index++;
                 $url = preg_replace("~\\-" . ($index - 1) . "\$~", '', $url) . '-' . $index;
             } else {
                 // update the same urlAlias of the same page, see afterUpdate()
                 break;
             }
         }
         //$url = preg_replace("~^/~", '', $url);
         $this['url'] = $url;
     }
 }