Exemplo n.º 1
0
 /**
  * Class constructor
  *
  * @param AppController $controller
  */
 public function __construct($controller)
 {
     Sl::getInstance()->view = $this;
     parent::__construct($controller);
     $this->theme =& $controller->theme;
     $this->id =& $controller->id;
 }
Exemplo n.º 2
0
 function end($options = null)
 {
     $view = Sl::getInstance()->view;
     $options2 = is_array($options) ? $options : array();
     $options2 += array('validation' => true);
     if ($options2['validation'] && $view->model && isset($view->Validation)) {
         SlConfigure::write('Asset.js.jquery', 'head');
         SlConfigure::write('Asset.js.head.jqueryValidation', 'jquery.validation.min');
         $html = $view->Validation->bind($view->model);
     } else {
         $html = '';
     }
     return parent::end($options) . $html;
 }
Exemplo n.º 3
0
 function saveAll($data = null, $options = array())
 {
     $controller = Sl::getInstance()->controller;
     $isNew = !$controller->id;
     // set associated model info
     if ($controller->modelClass != 'CmsNode') {
         $data['CmsNode'] += array('model' => $controller->modelClass, 'plugin' => $controller->plugin);
     }
     // remove empty Images, Attachments from data to be saved
     if (!empty($data['CmsImage'])) {
         if (empty($data['CmsImage']['id']) && empty($data['CmsImage']['filename']['name'])) {
             unset($data['CmsImage']);
         }
     }
     if (!empty($data['CmsAttachment'])) {
         foreach ($data['CmsAttachment'] as $i => $image) {
             if (empty($image['id']) && empty($image['filename']['name'])) {
                 unset($data['CmsAttachment'][$i]);
             }
         }
     }
     if (!empty($data['ImageGallery'])) {
         foreach ($data['ImageGallery'] as $i => $image) {
             if (empty($image['id']) && empty($image['filename']['name'])) {
                 unset($data['ImageGallery'][$i]);
             }
         }
     }
     if ($isNew) {
         $data['CmsNode']['auth_user_id'] = SlAuth::user('id');
     }
     if (!empty($data['CmsNode']['model'])) {
         if (empty($options['validation']) || $options['validation'] != 'only') {
             if (!parent::saveAll($data, array('validate' => 'only', 'atomic' => true) + $options)) {
                 return false;
             }
         }
         $modelObject = ClassRegistry::init("{$data['CmsNode']['plugin']}.{$data['CmsNode']['model']}");
         if (!$modelObject->saveAll($data, $options)) {
             return false;
         }
         $data['CmsNode'] += array('foreign_key' => $modelObject->id);
     }
     $result = parent::saveAll($data, $options);
     if ($result && $isNew && $this->CmsImage->id) {
         $this->CmsImage->saveField('cms_node_id', $this->id);
     }
     return $result;
 }
Exemplo n.º 4
0
 public function beforeRender()
 {
     //Sl::krumo($this->params);
     if ($this->RequestHandler->isAjax()) {
         if (is_array($this->output)) {
             SlConfigure::write('Sl.debug.requestTime', false);
             Configure::write('debug', 0);
             echo json_encode($this->output);
             die;
         }
     }
     if ($this->layout == 'default') {
         $this->layout = SlConfigure::read('View.layout');
     }
     if (empty($this->layout)) {
         $this->layout = empty($this->params['prefix']) || $this instanceof CakeErrorController && $this->params['prefix'] != 'admin' ? 'default' : $this->params['prefix'];
     }
     $this->theme = SlConfigure::read2('View.theme');
     if (empty($this->viewVars['title'])) {
         $model = $this->_humanizedModelClass();
         switch ($this->action) {
             case 'index':
             case 'admin_index':
                 $this->set('title', __t(Inflector::pluralize($model)));
                 break;
             case 'admin_add':
                 $this->set('title', __t($this->id ? 'Clone {$model}' : 'Add {$model}', array('model' => __t($model))));
                 break;
             case 'admin_edit':
                 $this->set('title', __t('Edit {$model}', array('model' => __t($model))));
                 break;
             default:
                 $this->set('title', null);
         }
     } elseif (empty($this->viewVars['title_for_layout'])) {
         $this->viewVars['title_for_layout'] = $this->viewVars['title'];
     }
     // merge 'site title' and 'view title'
     if (empty($this->viewVars['title_for_layout'])) {
         $this->viewVars['title_for_layout'] = SlConfigure::read2('Site.title');
     } else {
         $this->viewVars['title_for_layout'] .= SlConfigure::read('View.options.titleSep') . SlConfigure::read2('Site.title');
     }
     if (Sl::getInstance()->main && ob_get_level()) {
         SlConfigure::write('View.bufferedOutput', ob_get_clean());
     }
     if (class_exists('Debugger')) {
         Debugger::output('js');
     }
 }
Exemplo n.º 5
0
 /**
  * Automatically determine active collections based on the passed $item
  *
  * @param mixed $item
  */
 public static function setCollectionsMagic($item = null)
 {
     $controller = Sl::getInstance()->controller;
     $collections = array();
     if (is_string($item)) {
         $collections[] = $item;
     } else {
         if ($controller) {
             if (isset($item[$controller->modelClass]['id'])) {
                 $collections["{$controller->modelClass}{$item[$controller->modelClass]['id']}"] = 899;
             }
             if (empty($item['nodes']) && !empty($item['path'][0][$controller->modelClass]['id'])) {
                 $ids = Set::extract("{n}.{$controller->modelClass}.id", $data['path']);
                 foreach ($ids as $i => $id) {
                     $collections["{$controller->modelClass}{$id}"] = 800 + $i;
                 }
             }
         }
         if (!empty($item['nodes'])) {
             foreach ($item['nodes'] as $i => $nodeId) {
                 $collections["Node{$nodeId}"] = 600 + $i;
             }
         }
         if (!empty($item['tags'])) {
             foreach ($item['tags'] as $i => $tagId) {
                 $collections["Tag{$tagId}"] = 400 + $i;
             }
         }
         if (empty($collections) && is_array($item) && Set::numeric($item) && Set::countDim($item, true) == 1) {
             $collections = $item;
         }
     }
     return self::setCollections($collections);
 }
Exemplo n.º 6
0
 protected function _getParam($name)
 {
     $name = explode('.', $name);
     $addr =& Sl::getInstance()->view->params;
     while ($name && isset($addr[$name[0]])) {
         $addr =& $addr[array_shift($name)];
     }
     return $name ? null : $addr;
 }
Exemplo n.º 7
0
 /**
  * A more ajax and user friendly way to var_dump.
  * Use instead of pr()
  *
  * @param mixed $var
  * @param bool $useFireCakeOutsideViews
  */
 static function krumo($var, $options = array())
 {
     $options = array('fireCake' => true, 'debug' => true);
     if ($options['debug'] && !Configure::read()) {
         return;
     }
     if ($options['fireCake'] && empty(Sl::getInstance()->view) && class_exists('FireCake')) {
         return FireCake::fb($var);
     }
     // force Pheme to keep the whitespace and line breaks
     echo "<!--{!preserveWhitespace}-->";
     App::import('vendor', 'krumo', array('file' => 'krumo/class.krumo.php'));
     return krumo::dump($var);
 }
Exemplo n.º 8
0
 public function actionLink($action, $url = null, $options = array())
 {
     $options += array('title' => __t(Inflector::humanize($action)), 'url' => array());
     switch ($action) {
         case 'back':
             $ref = SlSession::read('Routing.ref');
             if (empty($ref)) {
                 $ref = env('HTTP_REFERER');
             }
             if (Sl::url($ref, true) == Sl::url(true)) {
                 $ref = null;
             }
             if ($ref) {
                 $options['url'] = $ref;
             } else {
                 $url2 = array('action' => 'index');
             }
             break;
         case 'clone':
             $url2 = array('action' => 'add');
             break;
         case 'preview':
             $url2 = array('admin' => false, 'action' => 'view');
             break;
         default:
             $url2 = array('action' => $action);
     }
     $url2['ref'] = isset($this->params['named']['ref_override']) ? $this->params['named']['ref_override'] : base64_encode(Sl::getInstance(true)->url(false));
     if ($url !== null) {
         if (is_array($url)) {
             $url2 = $url + $url2;
         } else {
             $url2[] = $url;
         }
     } else {
         // automagically pass filtering params
         foreach ($this->params['named'] as $param => $value) {
             if (preg_match('/_id$/', $param) || $param == 'skin') {
                 $url2[$param] = $value;
             }
         }
     }
     if (is_array($options['url'])) {
         $options['url'] += $url2;
     }
     switch ($action) {
         case 'add':
         case 'clone':
             $options += array('class' => 'add');
             break;
         case 'edit':
             $options += array('class' => 'edit');
             break;
         case 'preview':
             $options += array('target' => '_blank');
             break;
         case 'delete':
             $options += array('confirm' => __t('Delete?'), 'class' => 'remove');
             break;
     }
     $title = $options['title'];
     $url = $options['url'];
     unset($options['title']);
     unset($options['url']);
     return $this->link($title, $url, $options);
 }