/** * Get all sites method * * @param string $sort * @param string $page * @return void */ public function getAll($sort = null, $page = null) { $order = $this->getSortOrder($sort, $page); $sites = Table\Sites::findAll($order['field'] . ' ' . $order['order']); if ($this->data['acl']->isAuth('Phire\\Controller\\Config\\SitesController', 'remove')) { $removeCheckbox = '<input type="checkbox" name="remove_sites[]" id="remove_sites[{i}]" value="[{id}]" />'; $removeCheckAll = '<input type="checkbox" id="checkall" name="checkall" value="remove_sites" />'; $submit = array('class' => 'remove-btn', 'value' => $this->i18n->__('Remove')); } else { $removeCheckbox = ' '; $removeCheckAll = ' '; $submit = array('class' => 'remove-btn', 'value' => $this->i18n->__('Remove'), 'style' => 'display: none;'); } $options = array('form' => array('id' => 'sites-remove-form', 'action' => BASE_PATH . APP_URI . '/config/sites/remove', 'method' => 'post', 'process' => $removeCheckbox, 'submit' => $submit), 'table' => array('headers' => array('id' => '<a href="' . BASE_PATH . APP_URI . '/sites?sort=id">#</a>', 'edit' => '<span style="display: block; margin: 0 auto; width: 100%; text-align: center;">' . $this->i18n->__('Edit') . '</span>', 'domain' => '<a href="' . BASE_PATH . APP_URI . '/sites?sort=domain">' . $this->i18n->__('Domain') . '</a>', 'document_root' => '<a href="' . BASE_PATH . APP_URI . '/sites?sort=document_root">' . $this->i18n->__('Document Root') . '</a>', 'title' => '<a href="' . BASE_PATH . APP_URI . '/sites?sort=title">' . $this->i18n->__('Title') . '</a>', 'live' => '<a href="' . BASE_PATH . APP_URI . '/sites?sort=live">' . $this->i18n->__('Live') . '</a>', 'process' => $removeCheckAll), 'class' => 'data-table', 'cellpadding' => 0, 'cellspacing' => 0, 'border' => 0), 'separator' => '', 'exclude' => array('force_ssl'), 'indent' => ' '); $siteAry = array(); foreach ($sites->rows as $site) { if ($this->data['acl']->isAuth('Phire\\Controller\\Config\\SitesController', 'edit')) { $edit = '<a class="edit-link" title="' . $this->i18n->__('Edit') . '" href="' . BASE_PATH . APP_URI . '/config/sites/edit/' . $site->id . '">Edit</a>'; } else { $edit = null; } $sAry = array('id' => $site->id, 'title' => $site->title, 'domain' => $site->domain, 'document_root' => $site->document_root, 'base_path' => $site->base_path == '' ? ' ' : $site->base_path, 'live' => $site->live == 1 ? $this->i18n->__('Yes') : $this->i18n->__('No')); if (null !== $edit) { $sAry['edit'] = $edit; } $siteAry[] = $sAry; } if (isset($siteAry[0])) { $this->data['table'] = Html::encode($siteAry, $options, $this->config->pagination_limit, $this->config->pagination_range); } }
/** * Get overview configuration values * * @return array */ public function getOverview() { $cfg = Table\Config::getConfig(); $config = array(); $overview = array(); foreach ($cfg->rows as $c) { $config[$c->setting] = $c->setting == 'media_allowed_types' || $c->setting == 'media_actions' ? unserialize($c->value) : $c->value; } $sysVersion = $config['system_version']; $latest = ''; $handle = fopen('http://update.phirecms.org/system/version', 'r'); if ($handle !== false) { $latest = trim(stream_get_contents($handle)); fclose($handle); } if (version_compare(\Phire\Project::VERSION, $latest) < 0 && $this->data['acl']->isAuth('Phire\\Controller\\Phire\\Config\\IndexController', 'update')) { $sysVersion .= ' (<a href="' . BASE_PATH . APP_URI . '/config/update">' . $this->i18n->__('Update to') . ' ' . $latest . '</a>?)'; } // Set server config settings $overview['system'] = array('system_version' => $sysVersion, 'system_domain' => $config['system_domain'], 'server_operating_system' => $config['server_operating_system'], 'server_software' => $config['server_software'], 'database_version' => $config['database_version'], 'php_version' => $config['php_version'], 'installed_on' => date($this->config->datetime_format, strtotime($config['installed_on'])), 'updated_on' => $config['updated_on'] != '0000-00-00 00:00:00' ? date($this->config->datetime_format, strtotime($config['updated_on'])) : '(' . $this->i18n->__('Never') . ')'); $overview['sites'] = array(); $overview['sites'][$config['system_domain'] . BASE_PATH] = $config['live']; $sites = Table\Sites::findAll('id ASC'); foreach ($sites->rows as $site) { $overview['sites'][$site->domain . $site->base_path] = $site->live; } return $overview; }
/** * Static method to remove field values * * @param int $modelId * @param string $dir * @return void */ public static function remove($modelId, $dir = null) { $fields = \Phire\Table\FieldValues::findAll(null, array('model_id' => $modelId)); if (null === $dir) { $dir = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'media'; } if (isset($fields->rows[0])) { foreach ($fields->rows as $field) { // Get the field values with the field type to check for any files to delete if (isset($field->field_id)) { $sql = \Phire\Table\FieldValues::getSql(); $sql->select(array(DB_PREFIX . 'field_values.field_id', DB_PREFIX . 'field_values.model_id', DB_PREFIX . 'field_values.value', DB_PREFIX . 'fields.type'))->join(DB_PREFIX . 'fields', array('field_id', 'id'), 'LEFT JOIN')->where()->equalTo('field_id', ':field_id')->equalTo('model_id', ':model_id'); $fld = \Phire\Table\FieldValues::execute($sql->render(true), array('field_id' => $field->field_id, 'model_id' => $modelId)); if (isset($fld->field_id)) { // If field type is file, delete file(s) if ($fld->type == 'file') { $file = json_decode($fld->value, true); if (is_array($file)) { foreach ($file as $f) { if (file_exists($dir . '/' . $f)) { \Phire\Model\Media::remove($f, $dir); } else { $sites = Table\Sites::findAll(); foreach ($sites->rows as $site) { if (file_exists($site->document_root . $site->base_path . CONTENT_PATH . '/media/' . $f)) { \Phire\Model\Media::remove($f, $site->document_root . $site->base_path . CONTENT_PATH . '/media'); } } } } } else { if (file_exists($dir . '/' . $file)) { \Phire\Model\Media::remove($file, $dir); } else { $sites = Table\Sites::findAll(); foreach ($sites->rows as $site) { if (file_exists($site->document_root . $site->base_path . CONTENT_PATH . '/media/' . $file)) { \Phire\Model\Media::remove($file, $site->document_root . $site->base_path . CONTENT_PATH . '/media'); } } } } } $fld->delete(); } } } } }
/** * Get the init field values * * @param int $tid * @param boolean $profile * @param int $uid * @param string $action * @param boolean $register * @return array */ protected function getInitFields($tid = 0, $profile = false, $uid = 0, $action, $register = false) { $type = Table\UserTypes::findById($tid); $fields1 = array(); // Continue setting up initial user fields $fields1['email1'] = array('type' => 'text', 'label' => $this->i18n->__('Email'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\Email()); if ($type->email_verification) { $fields1['email2'] = array('type' => 'text', 'label' => $this->i18n->__('Re-Type Email'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\Email()); } // If not email as username, create username field if (!$type->email_as_username) { $fields2 = array('username' => array('type' => 'text', 'label' => $this->i18n->__('Username'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => array(new Validator\AlphaNumeric(), new Validator\LengthGte(4)))); if ($uid != 0) { $fields2['username']['attributes']['onkeyup'] = "phire.updateTitle('#username-title', this);"; } } else { $fields2 = array(); if ($uid != 0) { $fields1['email1']['attributes']['onkeyup'] = "phire.updateTitle('#username-title', this);"; } } // Continue setting up initial user fields if ($type->login) { $fields3 = array('password1' => array('type' => 'password', 'label' => $this->i18n->__('Enter Password'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\LengthGte(6)), 'password2' => array('type' => 'password', 'label' => $this->i18n->__('Re-Type Password'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\LengthGte(6))); } else { $fields3 = array(); } $fieldGroups = array(); $dynamicFields = false; $model = str_replace('Form', 'Model', get_class($this)); $newFields = \Phire\Model\Field::getByModel($model, $tid, $uid); if ($newFields['dynamic']) { $dynamicFields = true; } if ($newFields['hasFile']) { $this->hasFile = true; } foreach ($newFields as $key => $value) { if (is_numeric($key)) { $fieldGroups[] = $value; } } $fields4 = array(); if ($register) { $site = Table\Sites::getSite(); if ($type->use_csrf) { $fields4['csrf'] = array('type' => 'csrf', 'value' => \Pop\Filter\String::random(8)); } if ($type->use_captcha) { $fields4['captcha'] = array('type' => 'captcha', 'label' => $this->i18n->__('Enter Code'), 'captcha' => '<br /><img id="captcha-image" src="' . $site->base_path . '/captcha" /><br /><a class="reload-link" href="#" onclick="document.getElementById(\'captcha-image\').src = \'' . $site->base_path . '/captcha?reload=1\';return false;">' . $this->i18n->__('Reload') . '</a>', 'attributes' => array('size' => 5)); } } // Finish the initial fields $fields4['submit'] = array('type' => 'submit', 'value' => strpos($action, '/register') !== false ? $this->i18n->__('REGISTER') : $this->i18n->__('SAVE'), 'attributes' => array('class' => strpos($action, '/install/user') !== false || $profile ? 'update-btn' : 'save-btn')); if ($profile) { $fields4['submit']['label'] = ' '; $fields4['submit']['attributes']['style'] = 'width: 250px;'; $fields4['profile'] = array('type' => 'hidden', 'value' => 1); $sess = \Pop\Web\Session::getInstance(); if (isset($sess->reset_pwd)) { $fields4['reset_pwd'] = array('type' => 'hidden', 'value' => 1); } } if (!$profile) { $fields4['update'] = array('type' => 'button', 'value' => $this->i18n->__('Update'), 'attributes' => array('onclick' => "return phire.updateForm('#user-form', " . ($this->hasFile || $dynamicFields ? 'true' : 'false') . ");", 'class' => 'update-btn')); } $fields4['type_id'] = array('type' => 'hidden', 'value' => $tid); $fields4['id'] = array('type' => 'hidden', 'value' => 0); if (!$profile) { $fields4['update_value'] = array('type' => 'hidden', 'value' => 0); } // If not profile if (!$profile) { // Get roles for user type $rolesAry = array('0' => '(' . $this->i18n->__('Blocked') . ')'); if ($tid != 0) { $roles = Table\UserRoles::findBy(array('type_id' => $tid), 'id ASC'); foreach ($roles->rows as $role) { $rolesAry[$role->id] = $role->name; } } $siteIds = array('0' => $_SERVER['HTTP_HOST']); $sites = Table\Sites::findAll(); foreach ($sites->rows as $site) { $siteIds[(string) $site->id] = $site->domain; } $fields4['role_id'] = array('type' => 'select', 'required' => true, 'label' => $this->i18n->__('User Role'), 'value' => $rolesAry, 'marked' => $type->default_role_id); $fields4['verified'] = array('type' => 'select', 'label' => $this->i18n->__('Verified'), 'value' => array('1' => $this->i18n->__('Yes'), '0' => $this->i18n->__('No')), 'marked' => '0'); $fields4['failed_attempts'] = array('type' => 'text', 'label' => $this->i18n->__('Failed Attempts'), 'attributes' => array('size' => 3)); $fields4['site_ids'] = array('type' => 'checkbox', 'label' => $this->i18n->__('Allowed Sites'), 'value' => $siteIds); } if (strpos($action, '/install/user') !== false || $profile) { $allFields = array($fields1, $fields2, $fields3); if (count($fieldGroups) > 0) { foreach ($fieldGroups as $fg) { $allFields[] = $fg; } } $allFields[] = $fields4; } else { $allFields = array($fields4, $fields1, $fields2, $fields3); if (count($fieldGroups) > 0) { foreach ($fieldGroups as $fg) { $allFields[] = $fg; } } } return $allFields; }