/**
  * Method to get model types
  *
  * @return void
  */
 public function json()
 {
     $body = '';
     if (null !== $this->request->getPath(1)) {
         // Get the selected field history value
         if ($this->request->getPath(1) == 'history' && null !== $this->request->getPath(2) && is_numeric($this->request->getPath(2)) && null !== $this->request->getPath(3) && is_numeric($this->request->getPath(3)) && null !== $this->request->getPath(4) && is_numeric($this->request->getPath(4))) {
             $modelId = $this->request->getPath(2);
             $fieldId = $this->request->getPath(3);
             $time = $this->request->getPath(4);
             $value = '';
             $encOptions = $this->project->module('Phire')->encryptionOptions->asArray();
             $fv = Table\FieldValues::findById(array($fieldId, $modelId));
             if (isset($fv->field_id) && null !== $fv->history) {
                 $history = json_decode($fv->history, true);
                 if (isset($history[$time])) {
                     $value = $history[$time];
                     $f = Table\Fields::findById($fieldId);
                     $value = Model\FieldValue::decrypt($value, $f->encryption, $encOptions);
                 }
             }
             $body = array('fieldId' => $fieldId, 'modelId' => $modelId, 'value' => html_entity_decode($value, ENT_QUOTES, 'UTF-8'));
             // Get the field history timestamps
         } else {
             if ($this->request->getPath(1) == 'history' && null !== $this->request->getPath(2) && is_numeric($this->request->getPath(2)) && null !== $this->request->getPath(3) && is_numeric($this->request->getPath(3))) {
                 $modelId = $this->request->getPath(2);
                 $fieldId = $this->request->getPath(3);
                 $fv = Table\FieldValues::findById(array($fieldId, $modelId));
                 if (isset($fv->field_id) && null !== $fv->history) {
                     $body = array_keys(json_decode($fv->history, true));
                     rsort($body);
                 }
                 // Get the model types
             } else {
                 $clsAry = $this->request->getPath();
                 unset($clsAry[0]);
                 $cls = implode('_', $clsAry);
                 $types = \Phire\Project::getModelTypes($cls);
                 $body = array('types' => $types);
             }
         }
         // Build the response and send it
         $response = new Response();
         $response->setHeader('Content-Type', 'application/json; charset=utf-8')->setBody(json_encode($body));
         $response->send();
     }
 }
Example #2
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');
                     }
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * Remove user
  *
  * @param  array   $post
  * @return void
  */
 public function remove(array $post)
 {
     if (isset($post['remove_users'])) {
         foreach ($post['remove_users'] as $id) {
             $user = Table\Users::findById($id);
             if (isset($user->id)) {
                 $user->delete();
             }
             FieldValue::remove($id);
         }
     }
 }
Example #4
0
 /**
  * Remove user role
  *
  * @param  array   $post
  * @return void
  */
 public function remove(array $post)
 {
     if (isset($post['remove_roles'])) {
         foreach ($post['remove_roles'] as $id) {
             $role = Table\UserRoles::findById($id);
             if (isset($role->id)) {
                 $role->delete();
             }
             $sql = Table\UserTypes::getSql();
             if ($sql->getDbType() == \Pop\Db\Sql::SQLITE) {
                 $sql->update(array('default_role_id' => null))->where()->equalTo('default_role_id', $role->id);
                 Table\UserTypes::execute($sql->render(true));
             }
             FieldValue::remove($id);
         }
     }
 }