/** * (non-PHPdoc) * @see \Simplify\Form\Component::onExecuteServices() */ public function onExecuteServices($serviceAction) { switch ($serviceAction) { case \Simplify\Form::SERVICE_UPLOAD: $funcNum = \Simplify::request()->get('CKEditorFuncNum'); //$CKEditor = \Simplify::request()->get('CKEditor'); //$langCode = \Simplify::request()->get('langCode'); $fileUrl = false; $message = false; $response = $this->getBrowser()->upload('upload'); if ($response === \Simplify\Form::RESULT_SUCCESS) { $fileUrl = $this->getBrowser()->getFileUrl(); } else { $message = $this->getBrowser()->getErrors(); } echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$funcNum}, '{$fileUrl}', '{$message}');</script>"; exit; case self::SERVICE_BROWSER: $response = $this->getBrowser()->browse(); if ($response === \Simplify\Form::RESULT_SUCCESS) { $funcNum = \Simplify::request()->get('CKEditorFuncNum'); $fileUrl = $this->getBrowser()->getFileUrl(); echo "<script type='text/javascript'>window.opener.CKEDITOR.tools.callFunction({$funcNum}, '{$fileUrl}');window.close();</script>"; } else { echo $response; } exit; } }
protected function checkPermissions($action, $params) { try { $permissions = array(); if (!empty($this->permissions)) { foreach ($this->permissions as $key => $value) { if ($action === $key) { $permissions = array_merge($permissions, (array) $value); } elseif (substr($key, 0, 1) === '^' && $action !== substr($key, 1)) { $permissions = array_merge($permissions, (array) $value); } elseif (is_numeric($key)) { $permissions = array_merge($permissions, (array) $value); } } } if (!empty($permissions)) { Account::validate($permissions); } parent::beforeAction($action, $params); } catch (LoginRequiredException $e) { $loginUrl = array('route://admin_login', array('redirect' => \Simplify::request()->base() . \Simplify::request()->uri())); \Simplify::response()->redirect($loginUrl); } catch (SecurityException $e) { \Simplify::session()->warnings($e->getMessage()); \Simplify::response()->redirect('route://admin'); } }
/** * (non-PHPdoc) * @see \Simplify\Form\Component::onExecuteServices() */ public function onExecuteServices($serviceAction) { parent::onExecuteServices($serviceAction); switch ($serviceAction) { case 'toggle': $pid = $this->form->getId(); $fid = \Simplify::request()->post($this->getName()); $this->set('value', $this->toggleValue($pid[0], $fid)); break; } return $this->getView(); }
/** * (non-PHPdoc) * * @see Form_Action::onExecute() */ public function onExecute() { parent::onExecute(); $this->onLoadData(); $this->onValidate(); foreach ($this->formData as $row) { $this->form->dispatch(\Simplify\Form::ON_BEFORE_DELETE, $this, $row); } if (\Simplify::request()->method(\Simplify\Request::POST) && \Simplify::request()->post('deleteAction') == 'confirm') { $this->onDelete(); return \Simplify\Form::RESULT_SUCCESS; } }
public function match($uri) { if (isset($this->options['method']) && !preg_match('#^' . $this->options['method'] . '$#i', Simplify::request()->method())) { return false; } if (!preg_match($this->regex, $uri, $found)) { throw new RouterException("Route does not match uri: <b>{$uri}</b>"); } array_shift($found); $params = $this->defaults; foreach ($this->names as $i => $name) { $params[$name] = sy_get_param($found, $i, sy_get_param($this->defaults, $name)); } return new MatchedRoute($this, $params, $uri); }
/** * (non-PHPdoc) * @see RenderableInterface::getLayout() */ public function getLayout() { $filename = empty($this->layout) ? $this->getLayoutFilename() : $this->layout; if (is_null($filename) && \Simplify::request()->ajax() || $filename === false) { $layout = false; } elseif (sy_path_is_absolute($filename)) { $layout = sy_fix_extension($filename, 'html'); if (!file_exists($layout)) { throw new \Simplify\ViewException("Layout not found: file not found: <b>{$layout}</b>"); } } else { $layout = $filename; } return $layout; }
protected function indexAction() { if (\Simplify::request()->get('activate')) { \Amplify\Modules::activateModule(\Simplify::request()->get('module')); \Simplify::response()->redirect(\Simplify::request()->route()); } elseif (\Simplify::request()->get('deactivate')) { \Amplify\Modules::deactivateModule(\Simplify::request()->get('module')); \Simplify::response()->redirect(\Simplify::request()->route()); } try { $modules = \Amplify\Modules::getAllModules(); $this->set('modules', $modules); } catch (AmplifyException $e) { // } }
protected function accountAction() { try { $user = \Amplify\Account::getUser(); $this->Form->id = $user['user_id']; $this->Form->showMenu = false; $this->Form->showItemMenu = false; $result = $this->Form->execute('edit'); if ($result == \Simplify\Form::RESULT_SUCCESS) { \Simplify::session()->notices(__('Sucesso')); return \Simplify::response()->redirect(\Simplify::request()->route()); } } catch (\Simplify\ValidationException $e) { \Simplify::session()->warnings(__('Ocorreram erros')); } $this->set('formBody', $this->Form->render('edit')); }
/** * (non-PHPdoc) * @see \Simplify\Form::execute() */ public function execute($action = null) { $Action = $this->getAction($action); /** * * order * */ if ($Action->show(\Simplify\Form::ACTION_LIST)) { $Action->limit = false; $listAction = \Simplify::request()->get('listAction'); if ($listAction == self::LIST_ACTION_SORT) { $id = \Simplify::request()->get(\Simplify\Form::ID); $index = \Simplify::request()->get('index'); $this->repository()->moveTo($id, $index); } } return parent::execute($action); }
protected function indexAction() { $username = ''; $email = ''; $password = ''; if (\Simplify::request()->method(\Simplify\Request::POST)) { try { $username = \Simplify::request()->post('username'); $email = \Simplify::request()->post('email'); $password = \Simplify::request()->post('password'); \Amplify\Install::performInstall($username, $email, $password); \Simplify::session()->notices(__('Instalação realizada com sucesso.')); $url = \Simplify::request()->get('redirect', \Simplify::router()->make('admin')); \Simplify::response()->redirect($url); } catch (\Simplify\ValidationException $e) { \Simplify::session()->warnings($e->getErrors()); } } $this->set('username', $username); $this->set('email', $email); $this->set('password', $password); }
/** * * @return \Simplify\URL */ public function url() { if (empty($this->url)) { $this->url = new URL(null, array('formAction' => \Simplify::request()->get('formAction'))); } return $this->url; }
/** * (non-PHPdoc) * @see Component::getValue() */ public function getValue() { return $this->editable ? \Simplify::request()->get($this->getName(), $this->getDefaultValue()) : $this->getDefaultValue(); }
function sy_exception_handler($e) { if (sy_debug_level() && Simplify::request()->json()) { header('Content-type: application/json; charset="utf-8"'); $response = array('exception' => array('class' => get_class($e), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString(), 'file' => $e->getFile(), 'line' => $e->getLine())); $output = json_encode($response); } else { $output = ''; $output .= '<p>' . nl2br($e->getMessage()) . '</p><p>'; $output .= '<pre>' . htmlentities($e->getTraceAsString()) . '</pre>'; $output .= '</p>'; $output .= '<p>' . get_class($e) . ' thrown in ' . $e->getFile() . ' at line ' . $e->getLine() . '</p>'; $output .= ''; } ob_clean(); echo $output; exit; }
/** * * @param string $mode * @return string boolean */ public function formMode($mode = null) { return $mode ? \Simplify::request()->get('formMode', $this->mode) == $mode : \Simplify::request()->get('formMode', $this->mode); }
/** * */ protected function logoutAction() { \Amplify\Account::logout(); $url = \Simplify::request()->get('redirect', 'route://admin'); return \Simplify::response()->redirect($url); }
/** * * @return string */ public function getUntilValue($default = null) { return \Simplify::request()->get($this->getName() . '_until', $default); }
/** * (non-PHPdoc) * * @see \Simplify\Form\Action::onExtractData() */ protected function onExtractData(&$data, $row) { $calendarAction = \Simplify::request()->get('calendarAction'); if ($calendarAction == 'data') { $data['title'] = $row['title']; $data['start'] = $row['start']; $data['end'] = $row['end']; $data['allDay'] = sy_get_param($row, 'allDay'); } $data['editUrl'] = $this->url()->format('html')->set('calendarAction', 'edit')->set(Form::ID, $data[Form::ID])->build(); $data['deleteUrl'] = $this->url()->format('html')->set('calendarAction', 'delete')->set(Form::ID, $data[Form::ID])->build(); }
/** * * @return \Simplify\ViewInterface */ public function browse() { $browserAction = \Simplify::request()->get('browserAction'); switch ($browserAction) { case self::ACTION_SELECT: $this->file = \Simplify::request()->get('file'); return \Simplify\Form::RESULT_SUCCESS; } $files = $this->findFiles(); $this->set('files', $files); $this->setTemplate('browser'); $this->setLayout('basic'); return $this->getView(); }
/** * (non-PHPdoc) * @see \Simplify\Form\Action::onPostData() */ public function onPostData() { $post = \Simplify::request()->post('formData'); $files = \Simplify::request()->files('formData'); $elements = $this->getElements(); while ($elements->valid()) { $element = $elements->current(); if (!empty($files)) { foreach ($files as $k => $file) { foreach ($file[$element->getName()] as $field => $value) { $post[$element->getName()][$field][$k] = $value['file']; } } } $element->onPostData($this, $this->formData[$element->getName()]['data'], sy_get_param($post, $element->getName())); $elements->next(); } }
/** * * @return string */ protected function filter() { if ($this->sortGroupColumn) { if (!\Simplify::request()->get()->has($this->sortGroupColumn)) { throw new \Exception("Missing sort group column value"); } $value = \Simplify::request()->get($this->sortGroupColumn); $value = \Simplify::db()->quote($value); $filter = " {$this->sortGroupColumn} = {$value} "; return $filter; } return ' TRUE '; }
/** * (non-PHPdoc) * @see \Simplify\Form\Filter::getValue() */ public function getValue() { $value = \Simplify::request()->get($this->getName()); // if show empty is true, default value makes no sense... if ('' . $value == '' . $this->emptyValue && !$this->showEmpty) { if ('' . $this->getDefaultValue() == '' . $this->emptyValue) { $options = $this->getOptions(); $value = array_shift(array_keys($options)); } else { $value = $this->getDefaultValue(); } } return $value; }
/** * (non-PHPdoc) * * @see \Simplify\Form::execute() */ public function execute($action = null) { $Action = $this->getAction($action); $label = $this->getLabel(); $pk = $this->getPrimaryKey(); $parent = $this->getParent(); $left = $this->getLeft(); $right = $this->getRight(); /** * order */ if ($Action->show(\Simplify\Form::ACTION_LIST)) { $listAction = \Simplify::request()->get('listAction'); if ($listAction == self::LIST_ACTION_SORT) { $id = \Simplify::request()->get(\Simplify\Form::ID); $index = \Simplify::request()->get('index'); $this->repository()->moveTo($id, $index); } } /** * filter by parent */ if ($Action->show(\Simplify\Form::ACTION_LIST)) { $q = $this->repository()->mptt()->query()->select(false)->select("node.{$pk}")->select("CONCAT(REPEAT('–', (COUNT(parent.{$pk}) - 1)), ' ', node.{$label}) AS {$label}")->select("(COUNT(parent.{$pk}) - 1) AS depth"); $data = $q->execute()->fetchAll(); $parents = array(0 => __('Nenhum')); $parents += sy_array_to_options($data, $pk, $label); $filter = new \Simplify\Form\Filter\Select($parent, __('Pai')); $filter->showEmpty = false; $filter->defaultValue = \Simplify::request()->get($parent, '0'); $filter->options = $parents; $this->addFilter($filter); } /** * edit parent */ if ($Action->show(\Simplify\Form::ACTION_EDIT || \Simplify\Form::ACTION_CREATE)) { $q = $this->repository()->mptt()->query()->select(false)->select("node.{$pk}")->select("CONCAT(REPEAT('–', (COUNT(parent.{$pk}) - 1)), ' ', node.{$label}) AS {$label}")->select("(COUNT(parent.{$pk}) - 1) AS depth"); $id = $this->getId(); if (!empty($id[0])) { $row = $this->repository()->find($id[0]); $q->where("node.{$left} NOT BETWEEN {$row[$left]} AND {$row[$right]}"); } $data = $q->execute()->fetchAll(); $parents = array(0 => __('Nenhum')); $parents += sy_array_to_options($data, $pk, $label); $parentSelect = new \Simplify\Form\Element\Select($parent, __('Pai')); $parentSelect->showEmpty = false; $parentSelect->defaultValue = \Simplify::request()->get($parent, '0'); $parentSelect->options = $parents; $this->addElement($parentSelect, \Simplify\Form::ACTION_EDIT | \Simplify\Form::ACTION_CREATE, 0); } return parent::execute($action); }
/** * (non-PHPdoc) * @see \Simplify\Form\Component::onExecuteServices() */ public function onExecuteServices($serviceAction) { switch ($serviceAction) { case \Simplify\Form::SERVICE_UPLOAD: $data = array(); $file = \Simplify::request()->files($this->getName()); try { $upload = new \Simplify\Upload($file); $upload->uploadPath = $this->path; $upload->upload(); $file = $upload->getUploadedPath(); $image['filename'] = $file; $image['thumbUrl'] = $this->getThumbUrl($file, 128, 128); $image['imageUrl'] = $this->getImageUrl($file); $data['success'] = true; $data['image'] = $image; } catch (\Simplify\UploadException $e) { $data['error'] = $e->getErrors(); } $view = $this->getView(\Simplify\View::JSON); $view->copyAll($data); echo $view->render(); exit; break; } }
protected static function loadExtensions(\Twig_Environment $twig) { foreach ((array) \Simplify::config()->get('view:twig:globals') as $name => $value) { $twig->addGlobal($name, $value); } $twig->addGlobal('config', \Simplify::config()); $twig->addGlobal('request', \Simplify::request()); $twig->addGlobal('router', \Simplify::router()); $twig->addFunction(new \Twig_SimpleFunction('makeUrl', array('\\Simplify\\URL', 'make'))); $twig->addFunction(new \Twig_SimpleFunction('optionsValue', array('\\Amplify\\Options', 'value'))); $twig->addFunction(new \Twig_SimpleFunction('thumb', array('\\Simplify\\Thumb', 'factory'))); $twig->addFunction(new \Twig_SimpleFunction('asset', array('\\Simplify\\AssetManager', 'asset'))); $twig->addFunction(new \Twig_SimpleFunction('assets', array('\\Simplify\\AssetManager', 'assets'))); $twig->addFilter(new \Twig_SimpleFilter('truncate', 'sy_truncate')); }
if (!defined('SY_APP_DIR')) { trigger_error('SY_APP_DIR not defined', E_USER_ERROR); } require_once 'Simplify.php'; require_once 'debug.php'; require_once 'l10n.php'; if (!interface_exists('JsonSerializable')) { require_once 'JsonSerializable.php'; } define('SY_DIR', preg_replace('#[\\\\/]+#', '/', __DIR__ . '/')); $config = Simplify::config(); $config['sy:dir'] = SY_DIR; $config['app:path'] = 'app/'; $config['app:dir'] = SY_APP_DIR; // absolute, trailing slash $config['app:url'] = Simplify::request()->url(); // absolute, no trailing slash $config['cache:dir'] = '{www:dir}cache/'; $config['cache:url'] = '{www:url}cache/'; $config['app:assets:path:'] = '{app:path}assets/{theme}/'; $config['app:assets:path:'] = '{app:path}assets/'; $config['templates:path:'] = '{app:dir}templates/{theme}/'; $config['templates:path:'] = '{app:dir}templates/'; $config['public_path'] = '/'; $config['www:dir'] = dirname($_SERVER['SCRIPT_FILENAME']) . '{public_path}'; $config['www:url'] = '{app:url}{public_path}'; $config['files:path'] = 'files/'; $config['files:dir'] = '{www:dir}{files:path}'; $config['files:url'] = '{www:url}{files:path}'; $config['theme'] = 'default'; if (file_exists($config['app:dir'] . 'config/config.php')) {