/** * Add new object method */ public function addmethodAction() { $project = $this->_getProject(); $objectName = Request::post('object', 'string', ''); $objectMethodSrc = Request::post('method', 'string', ''); $objectMethod = Filter::filterValue(Filter::FILTER_ALPHANUM, $objectMethodSrc); if (!strlen($objectName) || !$project->objectExists($objectName)) { Response::jsonError($this->_lang->get('WRONG_REQUEST')); } if (!strlen($objectMethodSrc)) { Response::jsonError($this->_lang->get('CANT_BE_EMPTY')); } if ($objectMethodSrc !== $objectMethod) { Response::jsonError($this->_lang->get('INVALID_VALUE')); } $methodsManager = $project->getMethodManager(); if ($methodsManager->methodExists($objectName, $objectMethod)) { Response::jsonError($this->_lang->get('SB_UNIQUE')); } if (!$methodsManager->addMethod($objectName, $objectMethod)) { Response::jsonError($this->_lang->get('CANT_EXEC')); } $this->_storeProject(); Response::jsonSuccess(); }
/** * Remove configuration record */ public function deleteAction() { $this->_checkCanDelete(); $data = Request::post('data', 'raw', false); if ($data === false) { Response::jsonSuccess(); } $dataType = json_decode($data); if (!is_array($dataType)) { $data = array(json_decode($data, true)); } else { $data = json_decode($data, true); } $media = Model::factory('Medialib'); $configImage = $media->getConfig()->get('image'); foreach ($data as $item) { $code = Filter::filterValue('pagecode', $item['code']); unset($configImage['sizes'][$code]); unset($configImage['thumb_types'][$code]); } $config = $media->getConfig(); $config->set('image', $configImage); if (!$config->save()) { Response::jsonError($this->_lang->CANT_WRITE_FS); } Response::jsonSuccess(); }
/** * Set advanced property * @param string $key * @param mixed $value * @return boolean - success flag */ public function setAdvancedProperty($key, $value) { if (!isset(self::$advancedProperties[$key])) { return false; } $this->_advancedPropertyValues[$key] = Filter::filterValue(self::$advancedProperties[$key], $value); return true; }
/** * Check if page code is unique */ public function checkcodeAction() { $id = Request::post('id', 'int', 0); $code = Request::post('code', 'string', false); $code = Filter::filterValue('pagecode', $code); $model = Model::factory('Page'); if ($model->checkUnique($id, 'code', $code)) { Response::jsonSuccess(array('code' => $code)); } else { Response::jsonError($this->_lang->SB_UNIQUE); } }
public function subAction() { $subController = Request::getInstance()->getPart(3); $subAction = Request::getInstance()->getPart(4); if ($subController === false || !strlen($subController) || $subAction === false || !strlen($subAction)) { Response::jsonError($this->_lang->WRONG_REQUEST); } $subController = 'Backend_Designer_Sub_' . ucfirst(Filter::filterValue('pagecode', $subController)); $subAction = Filter::filterValue('pagecode', $subAction) . 'Action'; if (!class_exists($subController) || !method_exists($subController, $subAction)) { Response::jsonError($this->_lang->WRONG_REQUEST); } $sub = new $subController(); $sub->{$subAction}(); exit; }
public function indexAction() { $controller = Filter::filterValue('pagecode', Request::getInstance()->getPart(1)); $action = Filter::filterValue('pagecode', Request::getInstance()->getPart(2)); if (!strlen($controller) || !strlen($action)) { Response::jsonError($this->_lang->WRONG_REQUEST . ' c1'); } $apiController = 'Api_' . ucfirst($controller); $apiAction = $action . 'Action'; if (!class_exists($apiController)) { Response::jsonError($this->_lang->WRONG_REQUEST . ' c2'); } $controller = new $apiController(Registry::get('main', 'config'), $this->_db); if (!method_exists($controller, $apiAction)) { Response::jsonError($this->_lang->WRONG_REQUEST . ' c3 ' . $apiAction); } $controller->{$apiAction}(); }
/** * Route request to the Controller * @return void */ public function route() { $cfg = Registry::get('backend', 'config'); $controller = $this->_request->getPart(1); $controller = Utils_String::formatClassName(Filter::filterValue('pagecode', $controller)); if (in_array('Backend_' . $controller . '_Controller', $cfg->get('system_controllers'))) { $controller = 'Backend_' . $controller . '_Controller'; } else { $manager = new Backend_Modules_Manager(); $controller = $manager->getModuleController($controller); if ($controller === false) { if (Request::isAjax()) { Response::jsonError(Lang::lang()->get('WRONG_REQUEST') . ' ' . Request::getInstance()->getUri()); } $controller = 'Backend_Index_Controller'; } } $this->runController($controller, $this->_request->getPart(2)); }
public function testFilterValue() { $this->assertEquals(Filter::filterValue('integer', 123), (int) 123); $this->assertEquals(Filter::filterValue('float', 12.2), (double) 12.2); $this->assertEquals(Filter::filterValue('str', 333), (string) 333); $this->assertEquals(Filter::filterValue('cleaned_string', " <a href='test'>Test</a>"), '<a href='test'>Test</a>'); $this->assertEquals(Filter::filterValue('email', 'cmd<03>@aa.ss'), '*****@*****.**'); $this->assertEquals(Filter::filterValue('raw', 'saa'), 'saa'); $this->assertEquals(Filter::filterValue('alphanum', 'pOl$1@_!;l'), 'pOl1_l'); $this->assertEquals(Filter::filterValue('alpha', 'pOl$1@_!;4l'), 'pOll'); $this->assertEquals(Filter::filterValue('somefilter', '11asdasd 2 d'), 11); $this->assertEquals(Filter::filterValue('alphanum', '~!@#$%^&*()234admin@mail.ru'), '234adminmailru'); $this->assertEquals(Filter::filterValue('login', '~!@#$%^&*()admin@mail.ru\\,\''), '@admin@mail.ru'); $this->assertTrue(is_array(Filter::filterValue('array', 'asd'))); Filter::setDelimiter('-'); $this->assertEquals(Filter::filterValue('pagecode', 'p_Ol$ 1@_!;L'), 'p_ol1_l'); Filter::setDelimiter('_'); $this->assertEquals(Filter::filterValue('pagecode', 'p-Ol$ 1@_!;L'), 'p-ol1-l'); Filter::setDelimiter('/'); }
/** * Prepare filter values , clean empty filters * @param array $filters * @return array */ protected function _cleanFilters(array $filters) { foreach ($filters as $field => $val) { if (!$val instanceof Db_Select_Filter && !is_null($val) && (!is_array($val) && !strlen((string) $val))) { unset($filters[$field]); continue; } if ($this->_objectConfig->fieldExists($field) && $this->_objectConfig->isBoolean($field)) { $filters[$field] = Filter::filterValue(Filter::FILTER_BOOLEAN, $val); } } return $filters; }
/** * Save field config */ public function savefieldAction() { $this->_checkCanEdit(); $part = Request::post('part', 'string', false); $fieldOption = Request::post('fieldoption', 'string', ''); $field = Request::post('field', 'string', ''); $value = Request::post('value', 'string', ''); $accepted = array('select', 'title', 'alias'); if (!$part || !$field || !in_array($fieldOption, $accepted, true)) { Response::jsonError($this->_lang->WRONG_REQUEST . ' 1'); } if ($fieldOption === 'select') { $value = Filter::filterValue('boolean', $value); } $this->_checkLoaded(); $query = $this->_session->get('query'); $part = $query->getPart($part); if ($part === false) { Response::jsonError($this->_lang->WRONG_REQUEST . ' 3'); } $part->setFieldCfg($field, $fieldOption, $value); $this->_session->set('query', $query); Response::jsonSuccess(); }
public function __set($name, $value) { if (!$this->_properties->isValid($name)) { throw new Exception('Trying to set undefined property ' . get_class($this->_properties) . '->' . $name); } switch ($this->_properties->{$name}) { case Ext_Property::Boolean: if (is_string($value) && strlen($value) || !is_string($value)) { $value = Filter::filterValue('boolean', $value); } break; } return $this->_data[$name] = $value; }
public function _routeConfig() { $controller = $this->_request->getPart(0); $pathCode = Filter::filterValue('pagecode', $controller); $routes = Config::factory(Config::File_Array, $this->_appConfig->get('frontend_modules'))->__toArray(); if (isset($routes[$pathCode]) && class_exists($routes[$pathCode]['class'])) { $controllerClass = $routes[$pathCode]['class']; } else { $controllerClass = 'Frontend_Index_Controller'; } $this->runController($controllerClass, $this->_request->getPart(1)); }
/** * Get data from Ext Grid Filters Feature * @param string $container * @param string $method */ public static function extFilters($container = 'filterfeature', $method = 'POST') { if ($method == 'POST') { $filter = self::post($container, 'array', array()); } else { $filter = self::get($container, 'array', array()); } if (empty($filter)) { return array(); } $result = array(); foreach ($filter as $data) { $type = $data['data']['type']; $value = $data['data']['value']; $field = $data['field']; switch ($type) { case 'string': $result[] = new Db_Select_Filter($field, '%' . $value . '%', Db_Select_Filter::LIKE); break; case 'list': if (is_array($value)) { $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::IN); break; } if (strpos($value, ',') !== false) { $list = explode(',', $value); $result[] = new Db_Select_Filter($field, $list, Db_Select_Filter::IN); break; } $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::EQ); break; case 'boolean': $result[] = new Db_Select_Filter($field, Filter::filterValue(Filter::FILTER_BOOLEAN, $value), Db_Select_Filter::EQ); break; case 'numeric': switch ($data['data']['comparison']) { case 'ne': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::NOT); break; case 'eq': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::EQ); break; case 'lt': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::LT); break; case 'gt': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::GT); break; } break; case 'datetime': $value = date('Y-m-d H:i:s', strtotime($value)); switch ($data['data']['comparison']) { case 'ne': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::NOT); break; case 'eq': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::EQ); break; case 'lt': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::LT); break; case 'gt': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::GT); break; } break; case 'date': $value = date('Y-m-d', strtotime($value)); switch ($data['data']['comparison']) { case 'ne': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::NOT); break; case 'eq': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::EQ); break; case 'lt': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::LT); break; case 'gt': $result[] = new Db_Select_Filter($field, $value, Db_Select_Filter::GT); break; } break; } } return $result; }
/** * Create local event fore extended object */ public function addlocaleventAction() { $project = $this->_getProject(); $event = Filter::filterValue(Filter::FILTER_ALPHANUM, $this->_getEvent()); $object = $this->_getObject(); $eventManager = $project->getEventManager(); if ($eventManager->eventExists($object->getName(), $event) || $object->getConfig()->getEvents()->isValid($event)) { Response::jsonError($this->_lang->get('SB_UNIQUE')); } $eventManager->setEvent($object->getName(), $event, '', '', true); $this->_storeProject(); Response::jsonSuccess(); }
/** * Property filter * @param array $fieldInfo - property config data * @param mixed $value * @throws Exception * @return mixed */ public static function filter($fieldInfo, $value) { switch (strtolower($fieldInfo['db_type'])) { case 'tinyint': case 'smallint': case 'mediumint': case 'int': case 'bigint': $value = Filter::filterValue('int', $value); break; case 'float': case 'double': case 'decimal': $value = Filter::filterValue('float', $value); break; case 'bool': case 'boolean': $value = Filter::filterValue('boolean', $value); break; case 'date': case 'time': case 'timestamp': case 'datetime': $value = Filter::filterValue('string', $value); break; case 'tinytext': case 'text': case 'bit': case 'char': case 'varchar': case 'mediumtext': case 'longtext': case 'char': case 'varchar': if (!isset($fieldInfo['allow_html']) || !$fieldInfo['allow_html']) { $value = Filter::filterValue('string', $value); } break; // case 'bit': // $value = preg_replace ('/[^01]*/', '', $value); break; default: throw new Exception('Invalid property type "' . $fieldInfo['db_type'] . '"'); } return $value; }
/** * Save server config */ public function serversSaveAction() { $this->_checkCanEdit(); $serverId = Request::post('id', 'pagecode', ''); if (!strlen($serverId)) { Response::jsonError($this->_lang->WRONG_REQUEST); } $data = Request::postArray(); unset($data['id']); if (!empty($data)) { foreach ($data as $k => &$v) { $v = Filter::filterValue('string', $v); } } $list = $this->_serversConfig->get('list'); $list[$serverId] = $data; $this->_serversConfig->set('list', $list); if (!$this->_serversConfig->save()) { Response::jsonError($this->_lang->CANT_WRITE_FS); } else { Response::jsonSuccess(); } }