Ejemplo n.º 1
0
 /**
  * Update site
  *
  * @param \Pop\Form\Form $form
  * @return void
  */
 public function update(\Pop\Form\Form $form)
 {
     $fields = $form->getFields();
     $site = Table\Sites::findById($fields['id']);
     $docRoot = substr($fields['document_root'], -1) == '/' && substr($fields['document_root'], -1) == "\\" ? substr($fields['document_root'], 0, -1) : $fields['document_root'];
     $oldDocRoot = $site->document_root;
     $docRoot = str_replace('\\', '/', $docRoot);
     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 = '';
     }
     $basePath = str_replace('\\', '/', $basePath);
     $site->domain = $fields['domain'];
     $site->document_root = $docRoot;
     $site->base_path = $basePath;
     $site->title = $fields['title'];
     $site->force_ssl = (int) $fields['force_ssl'];
     $site->live = (int) $fields['live'];
     $site->update();
     $this->data['id'] = $site->id;
     FieldValue::update($fields, $site->id);
     if ($oldDocRoot != $docRoot) {
         $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');
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Update user
  *
  * @param  \Pop\Form\Form $form
  * @param  \Pop\Config    $config
  * @return void
  */
 public function update(\Pop\Form\Form $form, $config)
 {
     $encOptions = $config->encryptionOptions->asArray();
     $fields = $form->getFields();
     $type = Table\UserTypes::findById($fields['type_id']);
     $user = Table\Users::findById($fields['id']);
     if (isset($user->id)) {
         // If there's a new password, set according to the user type
         if ($fields['password1'] != '' && $fields['password2'] != '') {
             $user->password = self::encryptPassword($fields['password1'], $type->password_encryption, $encOptions);
         }
         // Set role
         if (isset($fields['role_id'])) {
             $roleId = $fields['role_id'] == 0 ? null : $fields['role_id'];
         } else {
             $roleId = $user->role_id;
         }
         // Set verified and attempts
         $verified = isset($fields['verified']) ? $fields['verified'] : $user->verified;
         $failedAttempts = isset($fields['failed_attempts']) ? $fields['failed_attempts'] : $user->failed_attempts;
         $first = null === $user->role_id && null === $user->logins && $type->login;
         if (isset($fields['profile']) && $fields['profile']) {
             $siteIds = $user->site_ids;
         } else {
             $siteIds = isset($fields['site_ids']) ? serialize($fields['site_ids']) : serialize(array());
         }
         // Save the user's updated data
         $user->role_id = $roleId;
         $user->username = isset($fields['username']) ? $fields['username'] : $fields['email1'];
         $user->email = $fields['email1'];
         $user->verified = $verified;
         $user->failed_attempts = $failedAttempts;
         $user->site_ids = $siteIds;
         $user->updated = date('Y-m-d H:i:s');
         $sess = Session::getInstance();
         if (isset($fields['reset_pwd']) && $fields['reset_pwd']) {
             $user->updated_pwd = date('Y-m-d H:i:s');
             unset($sess->reset_pwd);
         }
         $sess->last_user_id = $user->id;
         if ($sess->user->id == $user->id) {
             $sess->user->username = $user->username;
             $sess->user->site_ids = unserialize($siteIds);
         }
         $user->update();
         $this->data['id'] = $user->id;
         FieldValue::update($fields, $user->id);
         // Send verification if needed
         if ($first) {
             $this->sendApproval($user, $type);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Update role
  *
  * @param \Pop\Form\Form $form
  * @return void
  */
 public function update(\Pop\Form\Form $form)
 {
     $fields = $form->getFields();
     $role = Table\UserRoles::findById($fields['id']);
     if (isset($role->id)) {
         $role->type_id = $fields['type_id'];
         $role->name = $fields['name'];
         $role->update();
         $this->data['id'] = $role->id;
     }
     // Add new permissions if any
     $perms = array();
     foreach ($_POST as $key => $value) {
         if (strpos($key, 'resource_new_') !== false || strpos($key, 'resource_cur_') !== false) {
             $id = substr($key, strrpos($key, '_') + 1);
             $cur = strpos($key, 'resource_new_') !== false ? 'new' : 'cur';
             if ($value != '0') {
                 $perm = $_POST['permission_' . $cur . '_' . $id] != '0' ? $_POST['permission_' . $cur . '_' . $id] : '';
                 if ($perm != '') {
                     $perm .= $_POST['type_' . $cur . '_' . $id] != '0' ? '_' . $_POST['type_' . $cur . '_' . $id] : '';
                 }
                 $perms[] = array('resource' => $value, 'permission' => $perm, 'allow' => (int) $_POST['allow_' . $cur . '_' . $id]);
             }
         }
     }
     // Remove and resource/permissions
     foreach ($_POST as $key => $value) {
         if (strpos($key, 'rm_resource_') !== false && isset($value[0])) {
             foreach ($perms as $k => $perm) {
                 if ($role->id . '_' . $perm['resource'] . '_' . $perm['permission'] == $value[0]) {
                     unset($perms[$k]);
                 }
             }
         }
     }
     $role->permissions = serialize($perms);
     $role->update();
     FieldValue::update($fields, $role->id);
 }