Ejemplo n.º 1
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @param  array $filters
  * @return \Pop\Form\Form
  */
 public function setFieldValues(array $values = null, $filters = null)
 {
     parent::setFieldValues($values, $filters);
     if ($_POST) {
         // Check the content directory
         if (!file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . $this->content_path)) {
             $this->getElement('content_path')->addValidator(new Validator\NotEqual($this->content_path, $this->i18n->__('The content directory does not exist.')));
         } else {
             $checkDirs = \Phire\Project::checkDirs($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . $this->content_path, true);
             if (count($checkDirs) > 0) {
                 $this->getElement('content_path')->addValidator(new Validator\NotEqual($this->content_path, $this->i18n->__('The content directory (or subdirectories) are not writable.')));
             }
         }
         // If not SQLite, check the DB parameters
         if (strpos($this->db_adapter, 'Sqlite') === false) {
             $this->getElement('db_name')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database name is required.')));
             $this->getElement('db_username')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database username is required.')));
             $this->getElement('db_password')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database password is required.')));
             $this->getElement('db_host')->addValidator(new Validator\NotEmpty(null, $this->i18n->__('The database host is required.')));
         }
         // Check the database credentials
         if ($this->isValid()) {
             $oldError = ini_get('error_reporting');
             error_reporting(E_ERROR);
             $dbCheck = Dbs::check(array('database' => $this->db_name, 'username' => $this->db_username, 'password' => $this->db_password, 'host' => $this->db_host, 'type' => str_replace('\\', '_', $this->db_adapter)));
             // If there is a DB error
             if (null != $dbCheck) {
                 $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, wordwrap($dbCheck, 50, '<br />')));
             } else {
                 // Check the database version
                 if (strpos($this->db_adapter, 'Sqlite') === false) {
                     $adapter = stripos($this->db_adapter, 'Pdo\\') !== false ? str_replace('Pdo\\', '', $this->db_adapter) : $this->db_adapter;
                     $db = Db::factory($adapter, array('database' => $this->db_name, 'username' => $this->db_username, 'password' => $this->db_password, 'host' => $this->db_host, 'type' => strtolower(str_replace('Pdo\\', '', $this->db_adapter))));
                     $version = $db->adapter()->version();
                     $version = substr($version, strrpos($version, ' ') + 1);
                     if (strpos($version, '-') !== false) {
                         $version = substr($version, 0, strpos($version, '-'));
                     }
                     if (stripos($this->db_adapter, 'Mysql') !== false) {
                         $dbVerKey = 'Mysql';
                     } else {
                         if (stripos($this->db_adapter, 'Pgsql') !== false) {
                             $dbVerKey = 'Pgsql';
                         } else {
                             $dbVerKey = null;
                         }
                     }
                     if (null !== $dbVerKey && version_compare($version, self::$dbVersions[$dbVerKey]) < 0) {
                         $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, wordwrap($this->i18n->__('The %1 database version must be %2 or greater. (%3 detected.)', array($dbVerKey, self::$dbVersions[$dbVerKey], $version)), 45, '<br />')));
                     }
                 }
             }
             error_reporting($oldError);
         }
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Get all modules method
  *
  * @param  \Phire\Project $project
  * @return void
  */
 public function getModules(\Phire\Project $project = null)
 {
     $modules = Table\Extensions::findAll('id ASC', array('type' => 1));
     $moduleRows = $modules->rows;
     $moduleDir1 = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules', false, false, false);
     $moduleDir2 = new Dir(__DIR__ . '/../../../../../module', false, false, false);
     $dirs = array_merge($moduleDir1->getFiles(), $moduleDir2->getFiles());
     $moduleFiles = array();
     $formats = Archive::formats();
     foreach ($dirs as $file) {
         if (array_key_exists(substr($file, strrpos($file, '.') + 1), $formats)) {
             $moduleFiles[substr($file, 0, strpos($file, '.'))] = $file;
         }
     }
     foreach ($moduleRows as $key => $module) {
         $moduleName = $module->name;
         if (null !== $project) {
             $cfg = $project->module($module->name);
             if (null !== $cfg && null !== $cfg->module_nav) {
                 $n = !is_array($cfg->module_nav) ? $cfg->module_nav->asArray() : $cfg->module_nav;
                 $modNav = new Nav($n, array('top' => array('id' => strtolower($module->name) . '-nav', 'class' => 'module-nav')));
                 $modNav->setAcl($this->data['acl']);
                 $modNav->setRole($this->data['role']);
                 $moduleRows[$key]->module_nav = $modNav;
             }
         }
         if (isset($moduleFiles[$module->name])) {
             unset($moduleFiles[$module->name]);
         }
         // Get module info
         $assets = unserialize($module->assets);
         $moduleRows[$key]->author = '';
         $moduleRows[$key]->desc = '';
         $moduleRows[$key]->version = '';
         foreach ($assets['info'] as $k => $v) {
             if (stripos($k, 'name') !== false) {
                 $moduleRows[$key]->name = $v;
             } else {
                 if (stripos($k, 'author') !== false) {
                     $moduleRows[$key]->author = $v;
                 } else {
                     if (stripos($k, 'desc') !== false) {
                         $moduleRows[$key]->desc = $v;
                     } else {
                         if (stripos($k, 'version') !== false) {
                             $moduleRows[$key]->version = $v;
                         }
                     }
                 }
             }
         }
         $latest = '';
         $handle = @fopen('http://update.phirecms.org/modules/' . strtolower($moduleName) . '/version', 'r');
         if ($handle !== false) {
             $latest = trim(stream_get_contents($handle));
             fclose($handle);
         }
         if (version_compare($moduleRows[$key]->version, $latest) < 0 && $this->data['acl']->isAuth('Phire\\Controller\\Phire\\Config\\IndexController', 'update')) {
             $moduleRows[$key]->version .= ' (<a href="' . BASE_PATH . APP_URI . '/config/update?module=' . $moduleName . '">' . $this->i18n->__('Update to') . ' ' . $latest . '</a>?)';
         }
     }
     $this->data['modules'] = $moduleRows;
     $this->data['new'] = $moduleFiles;
 }
 /**
  * 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();
     }
 }
Ejemplo n.º 4
0
<?php

/**
 * Phire CMS 2.0 Bootstrap File
 */
// Calculate and define the base path
if (!defined('BASE_PATH')) {
    $basePath = str_replace(array(realpath($_SERVER['DOCUMENT_ROOT']), '\\'), array('', '/'), realpath(__DIR__));
    define('BASE_PATH', !empty($basePath) ? $basePath : '');
}
// Require the config file
require_once 'config.php';
// Check the path and URI constants
if (!defined('BASE_PATH') || !defined('APP_PATH') || !defined('APP_URI') || !defined('DB_INTERFACE') || !defined('DB_NAME')) {
    throw new \Exception('Error: The config file is not properly configured. Please check the config file or install the system.');
}
// Require the Pop Autoloader class file
require_once __DIR__ . APP_PATH . '/vendor/PopPHPFramework/src/Pop/Loader/Autoloader.php';
// Create the autoloader object and register the Phire application
$autoloader = new \Pop\Loader\Autoloader();
$autoloader->splAutoloadRegister(false);
$autoloader->register('Phire', __DIR__ . APP_PATH . '/vendor/Phire/src');
// Create the Phire project object
$project = \Phire\Project::factory(include __DIR__ . APP_PATH . '/config/project.php', include __DIR__ . APP_PATH . '/vendor/Phire/config/module.php');
Ejemplo n.º 5
0
 /**
  * Get the init field values
  *
  * @param  int         $id
  * @param  \Pop\Config $config
  * @return array
  */
 protected function getInitFields($id = 0, $config = null)
 {
     // Get field groups
     $groups = array('0' => '----');
     $grps = Table\FieldGroups::findAll('id ASC');
     if (isset($grps->rows[0])) {
         foreach ($grps->rows as $grp) {
             $groups[$grp->id] = $grp->name;
         }
     }
     $editors = array('source' => 'Source');
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/js/ckeditor')) {
         $editors['ckeditor'] = 'CKEditor';
     }
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/js/tinymce')) {
         $editors['tinymce'] = 'TinyMCE';
     }
     // Get any current validators
     $fields2 = array();
     $editorDisplay = 'none;';
     if ($id != 0) {
         $fld = Table\Fields::findById($id);
         if (isset($fld->id)) {
             if (strpos($fld->type, 'textarea') !== false) {
                 $editorDisplay = 'block;';
             }
             $validators = unserialize($fld->validators);
             if ($validators != '') {
                 $i = 1;
                 foreach ($validators as $key => $value) {
                     $fields2['validator_cur_' . $i] = array('type' => 'select', 'label' => '&nbsp;', 'value' => $this->validators, 'marked' => $key);
                     $fields2['validator_value_cur_' . $i] = array('type' => 'text', 'attributes' => array('size' => 10, 'style' => 'display: block; padding: 4px 4px 5px 4px; margin: 0 0 4px 0; height: 17px;'), 'value' => $value['value']);
                     $fields2['validator_message_cur_' . $i] = array('type' => 'text', 'attributes' => array('size' => 30, 'style' => 'display: block; padding: 4px 4px 5px 4px; margin: 0 0 4px 0; height: 17px;'), 'value' => $value['message']);
                     $fields2['validator_remove_cur_' . $i] = array('type' => 'checkbox', 'value' => array('Yes' => $this->i18n->__('Remove') . '?'));
                     $i++;
                 }
             }
         }
     }
     // Start creating initial fields
     $fields1 = array('type' => array('type' => 'select', 'label' => $this->i18n->__('Field Type'), 'required' => true, 'value' => array('text' => 'text', 'text-history' => 'text (history)', 'textarea' => 'textarea', 'textarea-history' => 'textarea (history)', 'select' => 'select', 'checkbox' => 'checkbox', 'radio' => 'radio', 'file' => 'file', 'hidden' => 'hidden'), 'attributes' => array('style' => 'width: 200px;', 'onchange' => 'phire.toggleEditor(this);')), 'editor' => array('type' => 'select', 'value' => $editors, 'marked' => 0, 'attributes' => array('style' => 'display: ' . $editorDisplay)), 'name' => array('type' => 'text', 'label' => $this->i18n->__('Field Name'), 'required' => true, 'attributes' => array('size' => 64)), 'label' => array('type' => 'text', 'label' => $this->i18n->__('Field Label'), 'attributes' => array('size' => 64)), 'values' => array('type' => 'text', 'label' => $this->i18n->__('Field Values') . ' <span style="font-size: 0.9em; font-weight: normal;">(' . $this->i18n->__('Pipe delimited') . ')</span>', 'attributes' => array('size' => 64)), 'default_values' => array('type' => 'text', 'label' => $this->i18n->__('Default Field Values') . ' <span style="font-size: 0.9em; font-weight: normal;">(' . $this->i18n->__('Pipe delimited') . ')</span>', 'attributes' => array('size' => 64)), 'attributes' => array('type' => 'text', 'label' => $this->i18n->__('Field Attributes'), 'attributes' => array('size' => 64)), 'validator_new_1' => array('type' => 'select', 'label' => '<a href="#" onclick="phire.addValidator(); return false;">[+]</a> ' . $this->i18n->__('Field Validators') . '<br /><span style="font-size: 0.9em;">(' . $this->i18n->__('Type / Value / Message') . ')</span>', 'value' => $this->validators, 'attributes' => array('style' => 'display: block; padding: 4px 4px 5px 4px; margin: 0 0 4px 0; height: 28px;')), 'validator_value_new_1' => array('type' => 'text', 'attributes' => array('size' => 10, 'style' => 'display: block; padding: 4px 4px 5px 4px; margin: 0 0 4px 0; height: 17px;')), 'validator_message_new_1' => array('type' => 'text', 'attributes' => array('size' => 30, 'style' => 'display: block; padding: 4px 4px 5px 4px; margin: 0 0 4px 0; height: 17px;')));
     if ($id != 0) {
         $fields1['name']['attributes']['onkeyup'] = "phire.updateTitle('#field-title', this);";
     }
     // Create next set of fields
     $fields3 = array();
     $models = Model\Field::getModels($config);
     asort($models);
     $fields3['model_new_1'] = array('type' => 'select', 'label' => '<a href="#" onclick="phire.addModel(); return false;">[+]</a> ' . $this->i18n->__('Model &amp; Type'), 'value' => $models, 'attributes' => array('style' => 'display: block; margin: 0 0 4px 0;', 'onchange' => 'phire.changeModelTypes(this);'));
     $fields3['type_id_new_1'] = array('type' => 'select', 'value' => \Phire\Project::getModelTypes($models), 'attributes' => array('style' => 'display: block; width: 200px; margin: 0 0 4px 0;'));
     if ($id != 0) {
         $field = Table\Fields::findById($id);
         $fieldToModels = null !== $field->models ? unserialize($field->models) : array();
         if (isset($fieldToModels[0])) {
             $i = 1;
             foreach ($fieldToModels as $f2m) {
                 $fields3['model_cur_' . $i] = array('type' => 'select', 'label' => '&nbsp;', 'value' => $models, 'marked' => $f2m['model'], 'attributes' => array('style' => 'display: block; margin: 0 0 4px 0;', 'onchange' => 'phire.changeModelTypes(this);'));
                 $fields3['type_id_cur_' . $i] = array('type' => 'select', 'value' => \Phire\Project::getModelTypes(str_replace('\\', '_', $f2m['model'])), 'marked' => $f2m['type_id'], 'attributes' => array('style' => 'display: block; width: 200px; margin: 0 0 4px 0;'));
                 $fields3['rm_model_cur_' . $i] = array('type' => 'checkbox', 'value' => array($field->id . '_' . $f2m['model'] . '_' . $f2m['type_id'] => 'Remove?'));
                 $i++;
             }
         }
     }
     $fields4 = array();
     $fields4['submit'] = array('type' => 'submit', 'value' => $this->i18n->__('SAVE'), 'attributes' => array('class' => 'save-btn'));
     $fields4['update'] = array('type' => 'button', 'value' => $this->i18n->__('UPDATE'), 'attributes' => array('onclick' => "return phire.updateForm('#field-form', true);", 'class' => 'update-btn'));
     $fields4['order'] = array('type' => 'text', 'label' => $this->i18n->__('Order'), 'value' => 0, 'attributes' => array('size' => 3));
     $fields4['group_id'] = array('type' => 'select', 'label' => $this->i18n->__('Field Group'), 'value' => $groups, 'attributes' => array('style' => 'display: block; width: 200px;'));
     $fields4['encryption'] = array('type' => 'select', 'label' => $this->i18n->__('Encryption'), 'value' => array('0' => $this->i18n->__('None'), '1' => 'MD5', '2' => 'SHA1', '3' => 'Crypt', '4' => 'Bcrypt', '5' => 'Mcrypt (2-Way)', '6' => 'Crypt_MD5', '7' => 'Crypt_SHA256', '8' => 'Crypt_SHA512'), 'marked' => 0, 'attributes' => array('style' => 'display: block; width: 200px;'));
     $fields4['required'] = array('type' => 'select', 'label' => $this->i18n->__('Required'), 'value' => array('0' => $this->i18n->__('No'), '1' => $this->i18n->__('Yes')), 'marked' => 0);
     $fields4['id'] = array('type' => 'hidden', 'value' => 0);
     $fields4['update_value'] = array('type' => 'hidden', 'value' => 0);
     return array($fields4, $fields1, $fields2, $fields3);
 }
Ejemplo n.º 6
0
 /**
  * Static method to get model types
  *
  * @param  \Pop\Config $config
  * @return array
  */
 public static function getResources($config = null)
 {
     $resources = array();
     $exclude = array();
     $override = null;
     // Get any exclude or override config values
     if (null !== $config) {
         $configAry = $config->asArray();
         if (isset($configAry['exclude_controllers'])) {
             $exclude = $configAry['exclude_controllers'];
         }
         if (isset($configAry['override'])) {
             $override = $configAry['override'];
         }
     }
     // If override, set overridden resources
     if (null !== $override) {
         foreach ($override as $resource) {
             $resources[] = $resource;
         }
         // Else, get all controllers from the system and module directories
     } else {
         $systemDirectory = new Dir(realpath(__DIR__ . '/../../../../'), true);
         $systemModuleDirectory = new Dir(realpath(__DIR__ . '/../../../../../module/'), true);
         $moduleDirectory = new Dir(realpath($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules'), true);
         $dirs = array_merge($systemDirectory->getFiles(), $systemModuleDirectory->getFiles(), $moduleDirectory->getFiles());
         sort($dirs);
         // Dir clean up
         foreach ($dirs as $key => $dir) {
             unset($dirs[$key]);
             if (!(strpos($dir, 'config') !== false || strpos($dir, 'index.html') !== false)) {
                 $k = $dir;
                 if (substr($dir, -1) == DIRECTORY_SEPARATOR) {
                     $k = substr($k, 0, -1);
                 }
                 $k = substr($k, strrpos($k, DIRECTORY_SEPARATOR) + 1);
                 $dirs[$k] = $dir;
             }
         }
         // Loop through each directory, looking for controller class files
         foreach ($dirs as $mod => $dir) {
             if (file_exists($dir . 'src/' . $mod . '/Controller')) {
                 $d = new Dir($dir . 'src/' . $mod . '/Controller', true, true, false);
                 $dFiles = $d->getFiles();
                 sort($dFiles);
                 // If found, loop through the files, getting the methods as the "permissions"
                 foreach ($dFiles as $c) {
                     if (strpos($c, 'index.html') === false && strpos($c, 'Abstract') === false) {
                         // Get all public methods from class
                         $class = str_replace(array('.php', DIRECTORY_SEPARATOR), array('', '\\'), substr($c, strpos($c, 'src') + 4));
                         $code = new \ReflectionClass($class);
                         $methods = $code->getMethods(\ReflectionMethod::IS_PUBLIC);
                         $actions = array();
                         foreach ($methods as $value) {
                             if ($value->getName() !== '__construct' && $value->class == $class) {
                                 $action = $value->getName();
                                 if (!isset($exclude[$class]) || isset($exclude[$class]) && is_array($exclude[$class]) && !in_array($action, $exclude[$class])) {
                                     $actions[] = $action;
                                 }
                             }
                         }
                         $types = array(0 => '(All)');
                         if (strpos($class, "\\Controller\\IndexController") === false) {
                             $classAry = explode('\\', $class);
                             $end1 = count($classAry) - 2;
                             $end2 = count($classAry) - 1;
                             $model = $classAry[0] . '_Model_';
                             if (stripos($classAry[$end2], 'index') !== false) {
                                 $model .= $classAry[$end1];
                             } else {
                                 if (substr($classAry[$end2], 0, 4) == 'Type') {
                                     $model .= $classAry[$end1] . 'Type';
                                 } else {
                                     $model .= str_replace('Controller', '', $classAry[$end2]);
                                 }
                             }
                             if (substr($model, -3) == 'ies') {
                                 $model = substr($model, 0, -3) . 'y';
                             } else {
                                 if (substr($model, -1) == 's') {
                                     $model = substr($model, 0, -1);
                                 }
                             }
                             $types = \Phire\Project::getModelTypes($model);
                             // Format the resource and permissions
                             $c = str_replace(array('Controller.php', '\\'), array('', '/'), $c);
                             $c = substr($c, strpos($c, 'Controller') + 11);
                             $c = str_replace('Phire/', '', $c);
                             if (!in_array($class, $exclude) || isset($exclude[$class]) && is_array($exclude[$class])) {
                                 $resources[$class] = array('name' => $c, 'types' => $types, 'actions' => $actions);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $resources;
 }