public function admin_index($activeSection = null) { $this->set('sections', $sections = SlConfigure::read2("Config.sections")); foreach ($sections as $section => $settings) { if (!SlAuth::isAuthorized('config' . Inflector::camelize($section))) { unset($sections[$i]); } } if (isset($this->data['_section'])) { $activeSection = $this->data['_section']; } if (empty($activeSection) || !isset($sections[$activeSection])) { $activeSection = reset(array_keys($sections)); } $settings = $this->_getSettings($activeSection); $this->set('title', __t(SlConfigure::read2("Config.sections.{$activeSection}"))); if ($this->data) { $locales = SlConfigure::read('I18n.locales'); foreach ($settings as $name => &$setting) { if (is_int($name)) { $name = "setting_{$name}"; } if ($setting['collection'] == 'user') { $setting['collection'] = 'User' . SlAuth::user('id'); } if (empty($setting['translate'])) { if (isset($this->data[$name])) { $value = $this->data[$name]; if (isset($setting['type']) && $setting['type'] == 'json') { $value = json_decode($value, true); } elseif (isset($setting['type']) && $setting['type'] == 'array') { $value = Set::normalize($value, false); } SlConfigure::write($setting['name'], $value, true, $setting['collection']); } } else { foreach ($locales as $locale) { if (isset($this->data["{$name}_{$locale}"])) { $value = $this->data["{$name}_{$locale}"]; if (isset($setting['type']) && $setting['type'] == 'json') { $value = json_decode($value, true); } elseif (isset($setting['type']) && $setting['type'] == 'array') { $value = Set::normalize($value, false); } SlConfigure::write($setting['name'], $value, true, "{$setting['collection']}.{$locale}"); } } } } $settings = $this->_getSettings($activeSection); $this->Session->setFlash(__t('Configuration saved'), array('class' => 'success')); } $this->data['_section'] = $activeSection; $this->set('settings', $settings); }
function parse($html = null, $blockName = 'document', $blockParams = null, $noCycle = false) { $messages = SlConfigure::read2('Message'); if ($messages) { SlSession::delete('Message'); } else { $messages = array(); } $this->vars['bufferedOutput'] = SlConfigure::read('View.bufferedOutput'); SlConfigure::delete('View.bufferedOutput'); if ($messages || $this->vars['bufferedOutput']) { $this->blocks["loop"]->params[0] = $messages; return parent::parse($html, $blockName); } }
public function login() { $this->helpers[] = 'JsValidate.Validation'; $this->AuthUser; $this->set('title', __t('Login')); if (!empty($this->data['AuthUser']['username'])) { if (SlAuth::login($this->data['AuthUser']['username'], $this->data['AuthUser']['password'], array('remember' => $this->data['AuthUser']['remember']))) { $key = empty($this->params['admin']) ? 'Auth.url.afterLogin' : 'Auth.url.afterAdminLogin'; $url = SlConfigure::read2($key); SlSession::delete($key); $this->redirect($url); } else { $this->Session->setFlash(__t('Login error. Check username and password')); } } }
public static function isAuthorized($what, $options = array()) { // root user if (self::user('id') == 1) { return true; } if (is_string($options)) { $options = array('default' => $options); } $options += array('default' => 'deny', 'who' => self::user('roles')); foreach ($options['who'] as $role) { $result = SlConfigure::read2("Auth.acl.{$role}.{$what}"); if ($result !== null) { return $result === true || $result === 'allow'; } } return $options['default'] === true || $options['default'] === 'allow'; }
function _humanizedModelClass() { $prefix = SlConfigure::read2('View.options.modelPrefix'); if (empty($prefix)) { $prefix = $this->plugin; } return Inflector::humanize(preg_replace("/^{$prefix}_/", '', Inflector::underscore($this->modelClass))); }
public function view($node_id) { // node common stuff $this->set('cmsNode', $node = SlNode::read($node_id)); if (!$node) { $this->cakeError(); } $this->set('title', $node['CmsNode']['title']); // contact form specific stuff $fields = array(); $fields2 = empty($node['CmsContactForm']['fields']) ? array('From|email', 'Text|textarea') : explode("\n", $node['CmsContactForm']['fields']); // prepare the array of user fields foreach ($fields2 as $i => $field) { $parts = explode('|', r("\r", " ", $field)); $parts = array_map('trim', $parts); $label = __t(empty($parts[0]) ? 'Unknown' : $parts[0]); $type = empty($parts[1]) ? 'text' : $parts[1]; if ($type === 'email') { $type = 'text'; } // we use only the 'after' setting, assuming that section title and other stuff // can be place here and show up correctly with proper css rules $after = empty($parts[2]) ? null : "<div class='after'>{$parts['2']}</div>"; // 'options' and 'multiple' settings $options = empty($parts[3]) ? null : explode(',', $parts[3]); $multiple = false; if ($options) { $options = array_map('trim', $options); $options = array_combine($options, $options); if ($type === 'checkbox') { $multiple = 'checkbox'; $type = null; } elseif ($type === 'multiple') { $multiple = true; $type = null; } if (!$type) { $type = 'select'; } } $fields["f{$i}"] = compact('label', 'type', 'multiple', 'after'); if ($options) { $fields["f{$i}"]['options'] = $options; } if ($type === 'radio') { $fields["f{$i}"]['legend'] = $label; } } if (!empty($this->data['CmsContactForm'])) { // TODO: Validate feedback fields $this->SwiftMailer->_set(SlConfigure::read('Api.swiftMailer')); $this->SwiftMailer->to = $node['CmsContactForm']['email']; //set variables to template as usual $this->set(compact('fields')); // send email try { if ($this->SwiftMailer->send('contact_form', __t(SlConfigure::read2('Api.swiftMailer.subject'), array('siteTitle' => SlConfigure::read2('Site.title'))), SlConfigure::read2('Api.swiftMailer.method'))) { $this->Session->setFlash(__t('Email sent. Thank you!'), array('class' => 'success')); // after the message has been sent, we no longer need for the form to show $this->viewVars['fields'] = null; } else { $this->Session->setFlash(__t('An unknown error occured.<br /> Please use you email client to send your message to <a href="mailto:{$email}">{$email}</a>', array('email' => $this->SwiftMailer->to)), array('class' => 'error')); } } catch (Exception $e) { $this->Session->setFlash(__t('An internal error occured.<br /> Please use you email client to send your message to <a href="mailto:{$email}">{$email}</a>', array('email' => $this->SwiftMailer->to)), array('class' => 'error')); trigger_error($e->getMessage(), E_USER_WARNING); } } else { $this->set(compact('fields')); } }
function parse($html = null, $blockName = 'document', $blockParams = null) { $blockParams = (array) $blockParams; $blockParams += array('recursive' => $blockName !== 'SimpleMenu' ? -1 : 0, 'level' => 1, 'itemClass' => 'sl-menu-item', 'menuClass' => null, 'class' => 'sl-menu'); // get menu items if (!isset($blockParams['items'])) { if (!isset($blockParams['id'])) { if (preg_match('/^[a-zA-Z0-9_.{}\\/-]+$/', $html)) { $name = parent::parse($html); $html = null; } else { $name = 'cms'; } } elseif (preg_match('/^[0-9]+(-[0-9]+)*$/', $blockParams['id'])) { $name = 'cms.' . r('-', '.children.', $blockParams['id']) . '.children'; } else { $name = $blockParams['id']; } $blockParams['items'] = SlConfigure::read2("Navigation.{$name}"); } $parentId = empty($blockParams['id']) ? '' : $blockParams['id'] . '-'; if (!is_array($blockParams['items']) || !is_array(reset($blockParams['items']))) { return; } $keys = array_keys($blockParams['items']); $first = reset($keys); $last = end($keys); $results = array(); foreach ($blockParams['items'] as $key => $item) { $id = $key; $args = array(); // default template vars values $result = array('itemClass' => "{$blockParams['itemClass']}-child {$blockParams['itemClass']}-{$id}", 'link' => false, 'subItems' => false, 'href' => false, 'id' => $parentId . $id); if ($key == $first) { $result['itemClass'] .= ' ' . $blockParams['itemClass'] . '-first'; } if ($key == $last) { $result['itemClass'] .= ' ' . $blockParams['itemClass'] . '-last'; } // text items if (!is_array($item) && $item) { $item = array('title' => $item); } // get link text if (!empty($item['title'])) { $result['text'] = h(__t($item['title'])); } if (empty($result['text'])) { continue; } // check permissions /*if (!SlAuth::isAuthorized($item, null, null, true)) { continue; } unset($item['allow']); unset($item['deny']);*/ // get link url $url = empty($item['url']) ? false : $item['url']; // set class attributte if (!empty($item['class'])) { $result['itemClass'] .= ' ' . $item['class']; } // set hint attribute if (!empty($item['hint'])) { $args['title'] = __t($item['hint']); } // set onclick attribute if (!empty($item['onclick'])) { $args['onclick'] = $item['onclick']; } // set rel attribute if (!empty($item['rel'])) { $args['rel'] = $item['rel']; } // set target attribute if (!empty($item['target'])) { $args['target'] = $item['target']; } // children? if (!empty($item['children']) && $blockParams['recursive'] != 0) { $result['subItems'] = $this->parse($html, $blockName, array('recursive' => $blockParams['recursive'] - 1, 'class' => $blockParams['class'] . '-' . $id, 'itemClass' => $blockParams['itemClass'] . '-' . $id, 'items' => $item['children'], 'id' => $parentId . $id, 'level' => $blockParams['level'] + 1)); if (strpos($result['subItems'], 'sl-active')) { $result['itemClass'] .= ' sl-child-active'; } } // is this a link? if ($url) { $args['escape'] = false; $args['class'] = $result['itemClass']; $result['link'] = $this->_getHelper('SlHtml')->link('%s', $url, $args); $result['href'] = $this->_getHelper('SlHtml')->url($url); if (strpos($result['subItems'], 'sl-active')) { $result['itemClass'] .= ' sl-active'; } } $results[] = $result; } if (empty($results)) { return; } $this->blocks["loop"]->params[0] = $results; $this->vars['class'] = $blockParams['class']; $this->vars['level'] = $blockParams['level']; if ($blockParams['menuClass']) { $this->vars['class'] .= ' ' . $blockParams['menuClass']; } $this->vars['id'] = empty($blockParams['id']) ? false : $blockParams['id']; return parent::parse($html, $blockName); }
function parse($html = null, $blockName = 'document', $blockParams = null) { if (empty($blockParams['id'])) { if (preg_match('/^[a-zA-Z0-9_.-]+$/', $html)) { $blockParams['id'] = parent::parse($html); $html = null; } else { return; } } $id = $blockParams['id']; $cacheKey = empty($blockParams['cacheKey']) ? 'default' : $blockParams['cacheKey']; $data = SlConfigure::read2("Block.{$id}"); if ($data) { $id = r('.', '-', $id); $this->vars = array('id' => $id, 'title' => false); $defaults = SlConfigure::read2('Block.defaults'); $blocks = array(); foreach ($data as $key => $block) { if ($block) { if (!is_array($block)) { $block = array('body' => $block); } $block = Set::merge($defaults, $block); if (empty($block['id'])) { $block['id'] = "{$id}-{$key}"; } if (!empty($block['cache']) && !is_array($block['cache'])) { $block['cache'] = array('time' => $block['cache']); } if (!empty($block['cache_time'])) { $block['cache']['time'] = $block['cache_time']; } if (isset($block['cache']['time']) && is_numeric($block['cache']['time'])) { $block['cache']['time'] += time(); } if (!empty($block['cache']['spread'])) { if (!is_numeric($block['cache']['time'])) { $block['cache']['time'] = strtotime($block['cache']['time'], time()); } $block['cache']['time'] += mt_rand(-$block['cache']['spread'], $block['cache']['spread']); } if (!empty($block['cache']) && empty($block['cache']['key'])) { $block['cache']['key'] = $block['id'] . '-' . md5(serialize($block) . SlConfigure::read('I18n.lang')); } if (!empty($block['cache']['time'])) { $cacheFile = 'views/block_' . $cacheKey . '_' . $block['cache']['key']; $cache = cache($cacheFile, null, $block['cache']['time']); if (is_string($cache)) { $blocks[] = unserialize($cache); continue; } } // dynamic block (from custom controller) if (!empty($block['url'])) { $block['body'] = Sl::requestAction($block['url']); if (!isset($block['title'])) { $block['title'] = SlConfigure::read('View.lastRenderTitle'); } } elseif (!empty($block['body'])) { $block['body'] = parent::parse($block['body']); } else { continue; } $blocks[] = $block; // update cache if (!empty($block['cache']['time'])) { // we don't wanna cache administrative stuff if (!strpos($block['body'], 'sl-node-actions')) { cache($cacheFile, serialize($block), $block['cache']['time']); } } } } if (empty($blocks)) { return; } $this->blocks["loop"]->params[0] = $blocks; return parent::parse($html, $blockName); } }
protected function _eval($blockParams) { $var = null; if (!empty($blockParams['blockCount'])) { $data = SlConfigure::read2("Block." . $blockParams['blockCount']); $var = count($data); } elseif (!empty($blockParams['config'])) { $var = SlConfigure::read2($blockParams['config']); } elseif (!empty($blockParams['collection'])) { $collections = SlConfigure::read(); $var = in_array($blockParams['collection'], $collections); } elseif (!empty($blockParams['param'])) { $var = $this->_getParam($blockParams['param']); } if ($var !== null) { $blockParams['var'] = '_sl'; $this->vars['_sl'] = $var; } return parent::_eval($blockParams); }
public function input($fieldName, $options = array()) { $view = ClassRegistry::getObject('view'); $this->setEntity($fieldName); $modelKey = $this->model(); $fieldKey = $this->field(); if ($modelKey[0] >= 'A' && $modelKey[0] <= 'Z') { $model = ClassRegistry::init($modelKey); $schema = $model->schema($fieldKey); $options += array('meioUpload' => $model->Behaviors->enabled('MeioUpload') && isset($model->Behaviors->MeioUpload->__fields[$model->alias][$fieldKey]), 'before' => '', 'after' => '', 'translate' => $model->Behaviors->enabled('Translate') && in_array($fieldKey, $model->Behaviors->Translate->settings[$model->alias])); if ($schema['type'] == 'boolean') { $options += array('checkedByDefault' => (bool) $schema['default']); } else { $options += array('default' => $schema['default']); } // if this is a MeioUpload field and a file has been uploaded, then show it if ($options['meioUpload'] && !empty($view->data[$modelKey][$fieldKey]) && is_string($view->data[$modelKey][$fieldKey])) { $meioUploadOptions = $model->Behaviors->MeioUpload->__fields[$model->alias][$fieldKey]; $filename = r(DS, '/', "{$meioUploadOptions['dir']}/{$view->data[$modelKey][$fieldKey]}"); if (isset($meioUploadOptions['thumbsizes']['icon'])) { $iconFilename = r(DS, '/', "{$meioUploadOptions['dir']}/thumb/icon/{$view->data[$modelKey][$fieldKey]}"); $options['before'] .= sprintf('<a class="sl-uploaded-image" href="%s" rel="colorbox" target="_blank"><img src="%s" /></a>', $this->assetUrl($filename), $this->assetUrl($iconFilename)); Pheme::parse('JqueryColorbox'); } else { $options['after'] .= sprintf('<a class="sl-uploaded-file" href="%s" target="_blank">%s</a>', $this->assetUrl($filename), __t('View uploaded file')); } } unset($options['meioUpload']); if (in_array($schema['type'], array('datetime', 'date', 'time'))) { $options += array('dateFormat' => SlConfigure::read2('I18n.options.dateFormat'), 'timeFormat' => SlConfigure::read2('I18n.options.timeFormat')); } } $prefix = SlConfigure::read2('View.options.modelPrefix'); if (empty($prefix)) { $prefix = $this->plugin; } $options += array('label' => __t(Inflector::humanize(r('.', ' ', preg_replace("/^{$prefix}_|_id\$/", '', $fieldName)))), 'translate' => false); if (isset($options['checkedByDefault'])) { if (!isset($view->data[$modelKey][$fieldKey])) { $options['checked'] = $options['checkedByDefault']; } unset($options['checkedByDefault']); } $translate = $options['translate']; unset($options['translate']); if ($translate) { $fields = array(); $catalogs = SlConfigure::read('I18n.catalogs'); $options2 = $options; foreach ($catalogs as $catalog) { $options2['label'] = $catalog['language']; if (isset($options['value']) && is_array($options['value'])) { if (isset($options['value'][$catalog['locale']])) { $options2['value'] = $options['value'][$catalog['locale']]; } else { unset($options2['value']); } } else { unset($options2['value']); } $fields["{$fieldName}_{$catalog['locale']}"] = $options2; } if (count($fields) == 1) { return parent::input(key($fields), array('label' => $options['label']) + $options2); } return $this->inputs(array('legend' => $options['label']) + $fields); } else { return parent::input($fieldName, $options); } }