コード例 #1
0
ファイル: Site.php プロジェクト: akinyeleolubodun/PhireCMS2
 /**
  * Save site
  *
  * @param \Pop\Form\Form $form
  * @return void
  */
 public function save(\Pop\Form\Form $form)
 {
     $fields = $form->getFields();
     $docRoot = substr($fields['document_root'], -1) == '/' && substr($fields['document_root'], -1) == "\\" ? substr($fields['document_root'], 0, -1) : $fields['document_root'];
     if ($fields['base_path'] != '') {
         $basePath = substr($fields['base_path'], 0, 1) != '/' && substr($fields['base_path'], 0, 1) != "\\" ? '/' . $fields['base_path'] : $fields['base_path'];
         if (substr($basePath, -1) == '/' && substr($basePath, -1) == "\\") {
             $basePath = substr($basePath, 0, -1);
         }
     } else {
         $basePath = '';
     }
     $site = new Table\Sites(array('domain' => $fields['domain'], 'document_root' => str_replace('\\', '/', $docRoot), 'base_path' => str_replace('\\', '/', $basePath), 'title' => $fields['title'], 'force_ssl' => (int) $fields['force_ssl'], 'live' => (int) $fields['live']));
     $site->save();
     $this->data['id'] = $site->id;
     $user = Table\Users::findById($this->data['user']->id);
     $siteIds = unserialize($user->site_ids);
     $siteIds[] = $site->id;
     $user->site_ids = serialize($siteIds);
     $user->update();
     $sess = \Pop\Web\Session::getInstance();
     $sess->user->site_ids = $siteIds;
     FieldValue::save($fields, $site->id);
     $this->createFolders($docRoot, $basePath);
     // Copy any themes over
     $themes = Table\Extensions::findAll(null, array('type' => 0));
     if (isset($themes->rows[0])) {
         $themePath = $docRoot . $basePath . CONTENT_PATH . '/extensions/themes';
         foreach ($themes->rows as $theme) {
             if (!file_exists($themePath . '/' . $theme->name)) {
                 copy($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . BASE_PATH . DIRECTORY_SEPARATOR . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme->file, $themePath . '/' . $theme->file);
                 $archive = new \Pop\Archive\Archive($themePath . '/' . $theme->file);
                 $archive->extract($themePath . '/');
                 if ((stripos($theme->file, 'gz') || stripos($theme->file, 'bz')) && file_exists($themePath . '/' . $theme->name . '.tar')) {
                     unlink($themePath . '/' . $theme->name . '.tar');
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: User.php プロジェクト: akinyeleolubodun/PhireCMS2
 /**
  * Save user
  *
  * @param  \Pop\Form\Form $form
  * @param  \Pop\Config    $config
  * @return void
  */
 public function save(\Pop\Form\Form $form, $config)
 {
     $encOptions = $config->encryptionOptions->asArray();
     $fields = $form->getFields();
     $type = Table\UserTypes::findById($fields['type_id']);
     $password = isset($fields['password1']) ? self::encryptPassword($fields['password1'], $type->password_encryption, $encOptions) : '';
     // Set the username according to user type
     $username = isset($fields['username']) ? $fields['username'] : $fields['email1'];
     // Set the role according to user type
     if (isset($fields['role_id'])) {
         $fields['role_id'] = $fields['role_id'] == 0 ? null : $fields['role_id'];
     } else {
         $fields['role_id'] = $type->approval ? null : $type->default_role_id;
     }
     // Set verified or not
     if (!isset($fields['verified'])) {
         $fields['verified'] = $type->verification ? 0 : 1;
     }
     if (isset($fields['site_ids'])) {
         $siteIds = $fields['site_ids'];
     } else {
         $site = Table\Sites::getSite();
         $siteIds = array($site->id);
     }
     // Save the new user
     $user = new Table\Users(array('type_id' => $fields['type_id'], 'role_id' => $fields['role_id'], 'username' => $username, 'password' => $password, 'email' => $fields['email1'], 'verified' => $fields['verified'], 'logins' => null, 'failed_attempts' => 0, 'site_ids' => serialize($siteIds), 'created' => date('Y-m-d H:i:s')));
     $user->save();
     $this->data['id'] = $user->id;
     $sess = Session::getInstance();
     $sess->last_user_id = $user->id;
     FieldValue::save($fields, $user->id);
     // Send verification if needed
     if ($type->verification && !$user->verified) {
         $this->sendVerification($user, $type);
     }
     // Send registration notification to system admin
     if ($type->registration_notification) {
         $this->sendNotification($user, $type);
     }
     $form->clear();
 }
コード例 #3
0
 /**
  * Save role
  *
  * @param \Pop\Form\Form $form
  * @return void
  */
 public function save(\Pop\Form\Form $form)
 {
     $fields = $form->getFields();
     $role = new Table\UserRoles(array('type_id' => $fields['type_id'], 'name' => $fields['name']));
     $role->save();
     $this->data['id'] = $role->id;
     // Add new permissions if any
     $perms = array();
     foreach ($_POST as $key => $value) {
         if (strpos($key, 'resource_new_') !== false) {
             $id = substr($key, strrpos($key, '_') + 1);
             if ($value != '0') {
                 $perm = $_POST['permission_new_' . $id] != '0' ? $_POST['permission_new_' . $id] : '';
                 if ($perm != '') {
                     $perm .= $_POST['type_new_' . $id] != '0' ? '_' . $_POST['type_new_' . $id] : '';
                 }
                 $perms[] = array('resource' => $value, 'permission' => $perm, 'allow' => (int) $_POST['allow_new_' . $id]);
             }
         }
     }
     $role->permissions = serialize($perms);
     $role->update();
     FieldValue::save($fields, $role->id);
 }