/** * Generates a sorting link with an automatically translated name taken from field_names.po * Also force it to be page 1 of the results * * @param mixed $title * @param mixed $key null * @param array $options array() * @return void * @access public */ public function sort($title, $key = null, $options = array()) { if (!$key) { $key = $title; if (strpos($title, '.')) { $title = str_replace('.', ' ', $title); } else { $view = ClassRegistry::getObject('view'); if (isset($view->viewVars['modelClass'])) { $alias = $view->viewVars['modelClass']; } else { $alias = $view->association ? $view->association : $view->model; } $title = $alias . ' ' . $title; } if (substr($title, -3) == '_id') { $title = substr($title, 0, strlen($title) - 3); } $title = Inflector::humanize(Inflector::underscore($title)); if (!empty($this->params['plugin'])) { $pluginDomain = Inflector::underscore($this->params['plugin']) . '_'; } else { $pluginDomain = ''; } $_title = $title; $title = __d($pluginDomain . 'field_names', $title, true); if ($title === $_title && !empty($alias)) { $alias = Inflector::humanize(Inflector::underscore($alias)); $title = str_replace($alias . ' ', '', $title); } } $options['url']['page'] = 1; return parent::sort($title, $key, $options); }
function __construct($options, $paths = array()) { $this->options = array_merge($this->options, $options); $this->paths = array_merge($this->paths, $paths); $this->View =& ClassRegistry::getObject('view'); $this->exceptions = Configure::read('Asset.exceptions'); }
/** * afterLayout * */ function afterLayout() { parent::afterLayout(); $view =& ClassRegistry::getObject('view'); if (!$view) { return false; } $view->output = $view->output; if (empty($view->ctp)) { $view->ctp = array(); } $tip = ''; $style = 'position: fixed; border-bottom:1px solid #AAAAAA; background:-moz-linear-gradient(center top , #EFEFEF, #CACACA) repeat scroll 0 0 transparent; -moz-border-radius-bottomright:8px; -moz-border-radius-topright:8px; margin:0px; line-height:1.6em; padding:4px 4px; top:0px; left:0px; cursor:pointer;'; $tip = "<div id='clickinit' style='" . $style . "'>" . $this->Html->image('../clickinit/img/clickinit.png') . "</div>"; $tip .= '<script type="text/javascript">var clickinitInitUrl="' . Router::url('/') . 'clickinit/clickinit/init' . '";</script>'; $tip .= $this->Html->script('../clickinit/js/clickinit.js'); if (preg_match('#</body>#', $view->output)) { $view->output = preg_replace('#</body>#', $tip . "\n</body>", $view->output, 1); } }
/** * * Generates nested unordered lists, with support for marking currently selected items * * $data = nested array of page results * * $settings = array with these keys: * * currentPath = array of IDs of the currently active item and all its parents. * each item when rendered is checked to see if it is in this array, and if so, * gets 'class="selected" added to its <li> tag * * initialDepth = how many levels should be expanded past the root. true means infinite, * integer means number of levels to show. (currentPath items and their siblings * are always shown - this is how to produce "open" branches.) * * depthLimit = not implemented yet - should stop us from opening the tree out too far - * so that sub pages don't necessarily show up even if they are currently being viewed * * baseListId = ID of the root UL * * baseListClass = class to apply to the root UL * * TODO: allow custom HTML code for each item - so that edit/delete links could be output too. float:right with css? * * TODO: add a check for show_in_menu as treebehaviour->children() doesn't support find conditions * * */ function generate($data, $settings = array()) { $this->myview = ClassRegistry::getObject('view'); $this->return = ''; $this->__generate($data, $settings); return $this->return; }
function &getInstance() { static $instance = array(); if (!$instance) { $instance[0] =& ClassRegistry::getObject('LoadsysAuthComponent'); } return $instance[0]; }
function render($name, $params = array(), $loadHelpers = false) { $view =& ClassRegistry::getObject('view'); $file = $plugin = $key = null; if (isset($params['cache'])) { $expires = '+1 day'; if (is_array($params['cache'])) { $expires = $params['cache']['time']; $key = Inflector::slug($params['cache']['key']); } elseif ($params['cache'] !== true) { $expires = $params['cache']; $key = implode('_', array_keys($params)); } if ($expires) { $cacheFile = 'partial_' . $key . '_' . Inflector::slug($name); $cache = cache('views' . DS . $cacheFile, null, $expires); if (is_string($cache)) { return $cache; } } } $buf = explode(DS, $name); $buf[count($buf) - 1] = '_' . $buf[count($buf) - 1]; $name = implode(DS, $buf); if ($partial = $view->render($name, false)) { if (isset($params['cache']) && isset($cacheFile) && isset($expires)) { cache('views' . DS . $cacheFile, $partial, $expires); } return $partial; } if (Configure::read() > 0) { return "Not Found: " . str_replace(DS . DS, DS, $view->viewPath . DS . $name); } }
function afterLayout() { $view =& ClassRegistry::getObject('view'); mb_internal_encoding('UTF-8'); $view->output = mb_convert_kana($view->output, 'k'); $view->output = mb_convert_encoding($view->output, 'SJIS', 'UTF-8'); }
/** * Gets and caches an View object reference * * @access protected * @return object The View object reference */ protected function __getView() { if (!$this->View) { return $this->View =& ClassRegistry::getObject('view'); } return $this->View; }
public function _brwCheckPermissions($model, $action = 'read', $id = null) { $Model = ClassRegistry::getObject($model); if (!$Model) { return false; } //really bad patch, fix with proper permissions if ($action == 'read') { return true; } if ($action == 'js_edit') { return true; } if (in_array($action, array('reorder', 'edit_upload', 'delete_upload'))) { $action = 'edit'; } if ($action == 'filter') { $action = 'index'; } if ($action == 'delete_multiple') { $action = 'delete'; } if (!in_array($action, array('index', 'add', 'view', 'delete', 'edit', 'import', 'export'))) { return false; } $Model->Behaviors->attach('Brownie.BrwPanel'); if (!empty($this->Content)) { $actions = $Model->brwConfig['actions']; if (!$actions[$action]) { return false; } } return true; }
function testInstances() { $this->assertTrue(is_a($this->Asset, 'AssetHelper')); $this->assertTrue(is_a($this->Asset->Html, 'HtmlHelper')); $this->assertTrue(is_a($this->View, 'View')); $this->assertTrue(is_a(ClassRegistry::getObject('view'), 'View')); }
/** * Construction * @param array $settings * @return null * @access public */ public function __construct($mappings = array()) { // Grab our View object for use later... $this->view = ClassRegistry::getObject('view'); // Merge our mappings together... $this->mappings = am($this->mappings, $mappings); }
function js($files, $inline = false, $duress = false) { // Register in header to prevent duplicates $registry = ClassRegistry::getObject('javascript'); if (is_array($files)) { $out = ''; foreach ($files as $i) { if ($duress || !isset($registry[$i])) { $out .= "\n\t" . $this->js($i, $inline, $duress); } } if ($out != '' && $inline) { echo $out . "\n"; } return; } ClassRegistry::setObject($files, 1, 'javascript'); if (substr($files, -3) != '.js') { $files = $files . '.js'; } if (false !== strpos($files, MVC_ADMIN)) { // Automatic routing to admin path $files = str_replace(MVC_ADMIN . '/', '', $files); $jsUrl = $this->locateScript($files, true); } else { $jsUrl = $this->locateScript($files); } if ($jsUrl) { $out = sprintf($this->tags['javascriptlink'], $jsUrl); cmsFramework::addScript($out, $inline, $duress); } }
function getObject($type, $name, $args = array()) { $_this =& ClassCollection::getInstance(); $options = $_this->getOption($type, $name); if ($options['singleton']) { $exitant = ClassRegistry::getObject($type . '.' . $name); if ($exitant) { return $exitant; } } $class = $_this->getClass($type, $options, $info); if (!empty($class) && class_exists($class)) { $created = $_this->_createObj($class, $args); if ($options['setName'] && empty($created->name)) { $created->name = $options['name']; } if ($options['setPlugin'] && !isset($created->plugin)) { $created->plugin = $info['plugin']; } if ($created && $options['singleton'] && !$info['isParent']) { $success = ClassRegistry::addObject($type . '.' . $name, $created); } return $created; } return null; }
function beforeRender() { if (ClassRegistry::getObject('view')) { $this->Javascript->link('jquery', false); $this->Javascript->link('jquery.form', false); } }
/** * afterLayout * * @return */ function afterLayout() { parent::afterLayout(); $view =& ClassRegistry::getObject('view'); if ($this->emoji->isMobile()) { if ($this->emoji->isSjisCarrier()) { header("Content-type: application/xhtml+xml; charset=Shift_JIS"); } else { header("Content-type: application/xhtml+xml; charset=UTF-8"); } } else { header('Content-Type: text/html; charset=UTF-8'); } if (isset($view->output)) { if (empty($this->data) || $this->emoji->isMobile()) { $view->output = $this->emoji->filter($view->output, array('DecToUtf8', 'HexToUtf8', 'output')); } else { // for PC form $outputArray = preg_split('/(value ?= ?[\'"][^"]+[\'"])|(<textarea[^>]+>[^<]+<\\/textarea>)/', $view->output, null, PREG_SPLIT_DELIM_CAPTURE); $output = ''; foreach ($outputArray as $key => $value) { if (!preg_match('/value ?= ?[\'"]([^"]+)[\'"]|<textarea[^>]+>([^<]+)<\\/textarea>/', $value)) { $output .= $this->emoji->filter($value, array('DecToUtf8', 'HexToUtf8', 'output')); } else { $output .= $value; } } $view->output = $output; } } }
/** * Add for problem. * * @param string $foreignKey, Book id */ public function add($objectType, $foreignKey) { try { $model = Inflector::classify($objectType); if (!ClassRegistry::isKeySet($model)) { $this->{$model} = ClassRegistry::init(Configure::read('Problems.Models.' . $model)); } else { $this->{$model} = ClassRegistry::getObject($model); } if (get_class($this->{$model}) === 'AppModel') { throw new Exception(__d('problems', 'Could not save the Problem of unallowed type.')); } $result = $this->{$model}->report($foreignKey, $this->Auth->user('id'), $this->request->data); if ($result === true) { $this->_setFlash(__d('problems', 'The problem has been saved'), 'success'); $this->Referer->redirect('/'); } } catch (OutOfBoundsException $e) { $this->_setFlash($e->getMessage(), 'error'); } catch (LogicException $e) { $this->_setFlash($e->getMessage(), 'error'); $this->Referer->redirect('/'); } catch (Exception $e) { $this->_setFlash($e->getMessage(), 'error'); $this->redirect('/'); } $types = $this->{$model}->Problem->types; $this->set(compact('foreignKey', 'types', 'objectType')); }
function _reset($settings = array(), $model = null) { $model = $model === null ? 'VirtualFieldsBehaviorMockModel' : $model; $this->Model = ClassRegistry::init($model); $this->Model->Behaviors->attach('Collectionable.VirtualFields', $settings); $this->Behavior =& ClassRegistry::getObject('VirtualFieldsBehavior'); }
/** * Set the captured block of HTML content to a $variable * * @param string $variable Assigned name * @return void * @author Chris Your */ function for_layout($variable) { if (!$this->view) { $this->view = ClassRegistry::getObject('view'); } $this->view->set("{$variable}_for_layout", ob_get_clean()); }
function input($fieldName, $options = array()) { if (ClassRegistry::isKeySet($this->model())) { $model =& ClassRegistry::getObject($this->model()); if ($model->isOrigamiColumn($fieldName)) { $type = $model->getOrigamiColumnType($fieldName); if (method_exists($this, $type)) { unset($options['type']); // We are specifying the type, so we need to remove any user specified types $out = $this->{$type}($fieldName, $options); // The code is this section is mostly copied from the cake php // FormHelper input method $div = true; $divOptions = array(); if (array_key_exists('div', $options)) { $div = $options['div']; unset($options['div']); } if (!empty($div)) { $divOptions['class'] = 'input'; $divOptions = $this->addClass($divOptions, $type); if (is_string($div)) { $divOptions['class'] = $div; } elseif (is_array($div)) { $divOptions = array_merge($divOptions, $div); } if (in_array($this->field(), $this->fieldset['validates'])) { $divOptions = $this->addClass($divOptions, 'required'); } if (!isset($divOptions['tag'])) { $divOptions['tag'] = 'div'; } } if ($type != 'hidden') { $error = null; if (isset($options['error'])) { $error = $options['error']; unset($options['error']); } if ($error !== false) { $errMsg = $this->error($fieldName, $error); if ($errMsg) { $out .= $errMsg; $divOptions = $this->addClass($divOptions, 'error'); } } } if (isset($divOptions) && isset($divOptions['tag'])) { $tag = $divOptions['tag']; unset($divOptions['tag']); $out = $this->Html->tag($tag, $out, $divOptions); } // end cake php inputs copy return $out; } } } return parent::input($fieldName, $options); }
public function beforeRender() { $view =& ClassRegistry::getObject('view'); if ($view) { $this->Javascript->link(array('/cforms/js/jquery-1.4.2.min.js', '/cforms/js/jquery-ui-1.8.1.custom.min.js', '/cforms/js/form/form.js'), false); $view->addScript($this->Html->css(array('/cforms/css/fancy_white', '/cforms/css/ui-lightness/jquery-ui-1.8.1.custom'))); } }
/** * KeywordConfig モデルを準備する * */ private function setUpModel() { if (ClassRegistry::isKeySet($this->plugin . '.KeywordConfig')) { $this->KeywordConfigModel = ClassRegistry::getObject($this->plugin . '.KeywordConfig'); } else { $this->KeywordConfigModel = ClassRegistry::init($this->plugin . '.KeywordConfig'); } }
public function setUp() { parent::setUp(); $this->containerBackup = ClassRegistry::getObject(ContainerInterface::CLASS); $this->container = $this->getMockForAbstractClass(ContainerInterface::CLASS); $this->replaceContainer($this->container); $this->component = new ContainerComponent(new ComponentCollection(), []); }
/** * Tree generation method. * * Accepts the results of * find('all', array('fields' => array('lft', 'rght', 'whatever'), 'order' => 'lft ASC')); * children(); // if you have the tree behavior of course! * or findAllThreaded(); and generates a tree structure of the data. * * Settings (2nd parameter): * 'model' => name of the model (key) to look for in the data array. defaults to the first model for the current * controller. * 'alias' => the array key to output for a simple ul (not used if element is specified) * 'type' => type of output defaults to ul * 'itemType => type of item output default to li * 'class' => class for top level 'item' * 'element' => path to an element to render to get node contents. * * @param array $data data to loop on * @param array $settings * @return string html representation of the passed data * @access public */ function generate($data, $settings = array()) { $element = false; $class = false; $model = false; $options = ''; $alias = 'name'; $left = 'lft'; $right = 'rght'; $type = 'ul'; $itemType = 'li'; extract($settings); $view =& ClassRegistry::getObject('view'); if (!$model) { $model = Inflector::classify($view->params['models'][0]); } $stack = array(); if ($class) { $options .= ' class="' . $class . '" '; } $return = "\r\n" . '<' . $type . $options . '>'; foreach ($data as $i => $result) { // Prefix while ($stack && $stack[count($stack) - 1] < $result[$model][$right]) { array_pop($stack); $return .= "\r\n" . str_repeat("\t", count($stack) + 1) . '</' . $type . '>'; $return .= '</' . $itemType . '>'; } $return .= "\r\n" . str_repeat("\t", count($stack) + 1) . '<' . $itemType . '>'; // Main Content if ($element) { $return .= $view->renderElement($element, array('data' => $result)); } else { $return .= $this->Html->link($result[$model][$alias], array('controller' => 'store', 'action' => 'browse', $result[$model]['handle'])); } // Suffix if (!isset($result[$model][$right]) || !isset($result[$model][$left]) || isset($result['children'])) { if (isset($result['children'])) { unset($settings['class']); $return .= $this->generate($result['children'], $settings); } $return .= '</' . $itemType . '>'; } elseif ($result[$model][$right] == $result[$model][$left] + 1) { // Has no children $return .= '</' . $itemType . '>'; } else { $return .= '<' . $type . '>'; $stack[] = $result[$model][$right]; } } while ($stack) { array_pop($stack); $return .= "\r\n" . str_repeat("\t", count($stack) + 1) . '</' . $type . '>'; $return .= '</' . $itemType . '>'; } $return .= "\r\n" . '</' . $type . '>' . "\r\n"; return $return; }
/** * construct * * @param View $View */ public function __construct(View $View) { parent::__construct($View); if (ClassRegistry::isKeySet('Page')) { $this->Page = ClassRegistry::getObject('Page'); } else { $this->Page = ClassRegistry::init('Page', 'Model'); } }
public function uninstallPlugin($id) { $pluginContainer = ClassRegistry::getObject('PluginContainer'); $pluginContainer->fetchEntry(); if ($pluginContainer->uninstall($id)) { $this->Session->setFlash(sprintf(__('Uninstalled plugin: %s'), $id), 'default', array('class' => 'flash flash_notice')); } $this->redirect('plugins'); }
function access_element_via_view() { /* Example showing how to access another element in the helper via the View object */ $View =& ClassRegistry::getObject('view'); $View->element('element_name', array('var' => 'hello_world')); }
public function testErrorMessage() { $Contact = ClassRegistry::getObject('Contact'); $Contact->validationErrors['password'] = array('Please provide a password'); $result = $this->Form->input('Contact.password', array('div' => 'row', 'label' => array('class' => 'col col-lg-2 control-label'), 'class' => 'input-with-feedback')); $this->assertTags($result, array(array('div' => array('class' => 'row has-error error')), 'label' => array('for' => 'ContactPassword', 'class' => 'col col-lg-2 control-label'), 'Password', '/label', array('div' => array('class' => 'input password')), 'input' => array('type' => 'password', 'name' => 'data[Contact][password]', 'id' => 'ContactPassword', 'class' => 'input-with-feedback form-error'), array('span' => array('class' => 'help-block text-danger')), 'Please provide a password', '/span', '/div', '/div')); $result = $this->Form->input('Contact.password', array('div' => 'row', 'label' => array('class' => 'col col-lg-2 control-label'), 'class' => 'input-with-feedback', 'errorMessage' => false)); $this->assertTags($result, array(array('div' => array('class' => 'row has-error error')), 'label' => array('for' => 'ContactPassword', 'class' => 'col col-lg-2 control-label'), 'Password', '/label', array('div' => array('class' => 'input password')), 'input' => array('type' => 'password', 'name' => 'data[Contact][password]', 'id' => 'ContactPassword', 'class' => 'input-with-feedback form-error'), '/div', '/div')); }
protected function renderElement($element, $data = array()) { $view = new View(ClassRegistry::getObject('EventController'), false); $view->set('data', $data); $html = $view->element($element, $this->params, true); $view = null; unset($view); return $html; }
public function for_layout($content, $name) { ob_start(); if (!$this->view) { $this->view = ClassRegistry::getObject('view'); } echo $content; $this->view->set($name . '_for_layout', ob_get_clean()); }
/** * Ends a block of output to display in layout */ function blockEnd() { $buffer = @ob_get_contents(); @ob_end_clean(); $out = $buffer; $view =& ClassRegistry::getObject('view'); $view->viewVars[$this->__blockName . '_for_layout'] = $out; $this->__blockName = null; }