'Name', 'description' => 'Description', 'value' => 'Value' ); protected $journal_name = 'Setting'; protected $journal_field_name = 'id'; static function get ($name, $default = null) { if (!isset(self::$setting_cache[$name])) { $setting = ORM::factory('setting', $name); if ($setting->isExist()) { self::$setting_cache[$name] = $setting->value; } else { self::$setting_cache[$name] = $default; } } return self::$setting_cache[$name]; } static function screenshotLocation ($mode = self::SCREENSHOT_LOCATION_DEFAULT) { $is_local = self::SCREENSHOT_LOCATION_LOCAL == $mode; $is_default_local = (self::SCREENSHOT_LOCATION_DEFAULT == $mode) && (self::get(self::S_SCREENSHOT_LOCAL)); $is_remote = self::SCREENSHOT_LOCATION_REMOTE == $mode; $is_remote_local = (self::SCREENSHOT_LOCATION_DEFAULT == $mode) && (! self::get(self::S_SCREENSHOT_LOCAL)); if ($is_local or $is_default_local) { return url::href('/' . self::get(self::S_SCREENSHOT_LOCAL_DIR)) . '/'; } if ($is_remote or $is_remote_local) { return Setting_Model::get (Setting_Model::S_SCREENSHOT_REMOTE_URL); } } static function getScreenshotLocalDir () { $screenshot_setting = Setting_Model::get (Setting_Model::S_SCREENSHOT_LOCAL_DIR); $screenshot_setting = trim ($screenshot_setting, '/.'); $screenshots_dir = realpath (DOCROOT . DIRECTORY_SEPARATOR . $screenshot_setting) . DIRECTORY_SEPARATOR; return $screenshots_dir; } function update ($value) { if ($this->isExist()) { $this->value = $value; $this->save(); } } function isReadOnly () { return $this->read_only > 0; } function getSystemSettings() { return $this->where('status', self::STATUS_SYSTEM)->find_all(); } function getUserSettings() { return $this->where('status', self::STATUS_USER)->find_all(); } function getHiddenSettings() { return $this->where('status', self::STATUS_HIDDEN)->find_all(); } function getFormName () { return strtolower($this->id); } function attachToForm (Formo_Form $form) { $field_name = $this->getFormName(); if (in_array ($this->id, array (Setting_Model::S_INCOMING_CATEGORY_VISIBILITY, Setting_Model::S_INCOMING_TYPE_VISIBILITY, Setting_Model::S_INCOMING_PACKAGE_VISIBILITY))) { $form->add ('select', $field_name); $form->$field_name->values = $this->getVisibilityList (); $form->$field_name->value = $this->value; } else { $form->add ($this->getInputType (), $field_name); switch ($this->type) { case self::TYPE_TEXT_NOTREQUIRED: $form->add_rules('not_required', $field_name); case self::TYPE_TEXT: case self::TYPE_PASSWORD: $form->$field_name->add_filter ('trim'); $form->set($field_name, 'value', $this->value); $form->set($field_name, 'style', 'width:350px;'); break; case self::TYPE_CHECKBOX: $form->add_rules('not_required', $field_name); if ($this->value > 0) { $form->$field_name->check(); } break; case self::TYPE_THEME: $form->$field_name->values = $this->getThemeList(); $form->$field_name->value = $this->value; break; case self::TYPE_URL: $form->$field_name->add_filter ('trim'); $form->$field_name->add_rule ('valid::url', 'A valid URL is required.'); case self::TYPE_LOCALDIR: $form->$field_name->add_filter ('trim'); $form->set($field_name, 'value', $this->value); $form->set($field_name, 'style', 'width:350px;'); break; default: throw new Exception("Invalid type"); break; } } $form->$field_name->primary_key = $this->id; if ($this->read_only) { $form->$field_name->disabled = 'disabled'; $form->add_rules('not_required', $field_name); } $form->set($field_name, 'label', $this->id); $form->$field_name->add_attribute('description'); $form->set($field_name, 'description', $this->description); } private function getThemeList () { $iterator = new DirectoryIterator(DOCROOT . '/themes'); foreach ($iterator as $i) { if ($i->isDir()) { if (!$i->isDot()) { if (preg_match('/^[\w\-]+$/', $i->getFilename())) { $index = $i->getFilename(); $result[$index] = $i->getFilename(); } } } } ksort($result); $select = array( '' => '* SELECT *' ); return $select + $result; } private function getVisibilityList () { $result = array (); $result [DAL_Catalog::STATE_VISIBLE_EVERYWHERE] = 'Visible'; $result [DAL_Catalog::STATE_VISIBLE_IN_LIST] = 'Visible except homepage'; $result [DAL_Catalog::STATE_HIDDEN] = 'Hidden'; $result [DAL_Catalog::STATE_DISABLED] = 'Disabled'; return $result; } private function getInputType () { $result = array( self::TYPE_TEXT => 'text', self::TYPE_CHECKBOX => 'checkbox', self::TYPE_THEME => 'select', self::TYPE_PASSWORD => 'password', self::TYPE_ADULT => 'select', self::TYPE_LOCALDIR => 'text', self::TYPE_TEXT_NOTREQUIRED => 'text', self::TYPE_URL => 'text', ); return $result[$this->type]; } function save () { if (($this->read_only == 0) || ($this->isForced ())) { parent::save(); } } function loadSetting (Setting $setting) { $this->id = $setting->getName(); $this->value = $setting->getValue(); $this->description = $setting->getDescription(); $this->read_only = intval($setting->isReadOnly()); $this->type = $setting->getType(); $this->status = $setting->getStatus(); $this->preserved = ! $setting->isExportable(); } function setForced ($forced) { $this->forced = (boolean)$forced; } function isForced () { return $this->forced; } function isExportable () { return 0 == $this->preserved; } function export () { if ($this->isExportable()) { return parent::export(); } } function setNotExportableFlagToWebapiprefix() { $item = $this->where('id', 'WEBAPIPASSWORD')->find(); if($item->isExist()) { if($item->isExportable()) { $item->preserved = 1; $item->save(); } } } }