Пример #1
0
 /**
  * Full backup site
  */
 public function fullBackUpAction()
 {
     if ($this->acl->isAllowed('system|database|fullBackUp')) {
         $databaseBackupName = $this->backupDatabaseFile();
         if ($databaseBackupName) {
             $fileName = generateAlias($this->config->website->sitename) . '_' . date('dmY_His') . '_from_UserID_' . $this->_user['id'] . '.backup.001';
             ini_set('max_execution_time', 0);
             $path = APP_DIR . '/backup/sources';
             if (!is_dir($path)) {
                 mkdir($path, 0755);
             }
             $zip = new ZZip(ROOT_PATH, $path . DS . $fileName);
             $zip->notContain('app/backup');
             $zip->notContain('cache');
             //               $zip->notContain('public/images');
             //               $zip->notContain('sql');
             //               $zip->addNeededContains('public/images/attribute-item-icons');
             //               $zip->addNeededContains('public/images/attribute-item-images');
             //               $zip->addNeededContains('public/images/user-images');
             //               $zip->addNeededContains('public/images/tmp');
             //               $zip->addNeededContains('public/images/product-images');
             $zip->addNeededContains('app/backup/database/' . $databaseBackupName);
             if ($zip->zip()) {
                 $this->flashSession->success('Backup site successfully with file name: ' . $path . DS . $fileName);
             } else {
                 $this->flashSession->notice('Backup site error');
             }
         } else {
             $this->flashSession->notice('Error while backup database');
         }
     }
     $this->response->redirect('/admin/system/database/');
 }
Пример #2
0
 public function beforeSave()
 {
     if ($this->alias == '') {
         $this->alias = generateAlias($this->title);
     }
 }
Пример #3
0
 /**
  * Upload avatar
  *
  * @param $user Users
  * @return string
  */
 private function uploadAvatar($user)
 {
     /**
      * @var \Phalcon\Http\Request\File[] $files
      */
     $files = $this->request->getUploadedFiles();
     if (count($files)) {
         foreach ($files as $file) {
             if ($file->getKey() == 'avatar' && $file->getName() != null) {
                 $file_name = $file->getName();
                 $file_size = $file->getSize();
                 $file_type = $file->getRealType();
                 $extension = '.' . pathinfo($file_name)['extension'];
                 //Check file type
                 if (substr($file_type, 0, 5) != 'image') {
                     $this->flashSession->notice('');
                     return false;
                 }
                 //Check file size
                 if ($file_size > MAX_AVATAR_SIZE_UPLOAD) {
                     $this->flashSession->notice(__('m_user_message_avatar_lager_than_x_mb', [MAX_AVATAR_SIZE_UPLOAD / (1024 * 1024)]));
                     return false;
                 }
                 $newAvatarName = md5($this->security->hash($user->user_id . time())) . $extension;
                 if (!is_dir(ROOT_USER_AVATAR_FOLDER_UPLOAD)) {
                     mkdir(ROOT_USER_AVATAR_FOLDER_UPLOAD, 0755, true);
                 }
                 if ($file->moveTo(ROOT_USER_AVATAR_FOLDER_UPLOAD . DS . $newAvatarName)) {
                     if ($user->avatar != '') {
                         $user->avatar = generateAlias($user->avatar, '-', 1000);
                         if (file_exists($user->avatar)) {
                             unlink(ROOT_USER_AVATAR_FOLDER_UPLOAD . DS . $user->avatar);
                         }
                     }
                     return USER_AVATAR_FOLDER_UPLOAD . DS . $newAvatarName;
                 }
             }
         }
     }
     return false;
 }