public static function getExternalConditions($select, $parentModel, $childName, $attributes) { $parentModelName = get_class($parentModel); $parentTableName = $parentModel->getTableName(); // exhibitions $childName = array_key_exists('source', $attributes) ? $attributes['source'] : $childName; $childModelName = Inflector::classify($childName); $childTableName = Bbx_Model::load($childModelName)->getTableName(); // images if (!array_key_exists($childTableName, $select->getPart('from'))) { $select->from($childTableName, array()); // images } if (array_key_exists('as', $attributes)) { $refColumn = $attributes['as'] . '_id'; $polyType = $attributes['as'] . '_type'; } else { $refColumn = Inflector::singularize($parentTableName) . '_id'; } try { $parentModel->getRowData(); $select->where("`" . $childTableName . "`.`" . $refColumn . "` = " . $parentModel->id); } catch (Exception $e) { $select->where("`" . $childTableName . "`.`" . $refColumn . "` = `" . $parentTableName . "`.`id`"); } if (isset($polyType)) { $select->where("`" . $childTableName . "`.`" . $polyType . "` = '" . Inflector::underscore($parentModelName) . "'"); } return $select; }
/** * Configuration method. * * In addition to configuring the settings (see $__defaults above for settings explanation), * this function also loops through the installed plugins and 'registers' those that have a * PluginNameCallback class. * * @param object $controller Controller object * @param array $settings Component settings * @access public * @return void */ public function initialize(&$controller, $settings = array()) { $this->__controller =& $controller; $this->settings = array_merge($this->__defaults, $settings); if (empty($this->settings['priority'])) { $this->settings['priority'] = Configure::listobjects('plugin'); } else { foreach (Configure::listobjects('plugin') as $plugin) { if (!in_array($plugin, $this->settings['priority'])) { array_push($this->settings['priority'], $plugin); } } } foreach ($this->settings['priority'] as $plugin) { $file = Inflector::underscore($plugin) . '_callback'; $className = $plugin . 'Callback'; if (App::import('File', $className, true, array(APP . 'plugins' . DS . Inflector::underscore($plugin)), $file . '.php')) { if (class_exists($className)) { $class = new $className(); ClassRegistry::addObject($className, $class); $this->__registered[] = $className; } } } /** * Called before the controller's beforeFilter method. */ $this->executeCallbacks('initialize'); }
/** * initialize method * * Merge settings and set Config.language to a valid locale * * @return void * @access public */ function initialize(&$Controller, $config = array()) { App::import('Vendor', 'Mi.MiCache'); $lang = MiCache::setting('Site.lang'); if (!$lang) { if (!defined('DEFAULT_LANGUAGE')) { return; } $lang = DEFAULT_LANGUAGE; } elseif (!defined('DEFAULT_LANGUAGE')) { define('DEFAULT_LANGUAGE', $lang); } Configure::write('Config.language', $lang); App::import('Core', 'I18n'); $I18n =& I18n::getInstance(); $I18n->domain = 'default_' . $lang; $I18n->__lang = $lang; $I18n->l10n->get($lang); if (!empty($Controller->plugin)) { $config['plugins'][] = Inflector::underscore($Controller->plugin); } if (!empty($config['plugins'])) { $plugins = array_intersect(MiCache::mi('plugins'), $config['plugins']); $Inst = App::getInstance(); foreach ($plugins as $path => $name) { $Inst->locales[] = $path . DS . 'locale' . DS; } } }
/** * Take care of any minifying requests. * The import is not defined outside the class to avoid errors if the class is read from the console. * * @return void */ public function index($type) { $files = array_unique(explode(',', $_GET['f'])); $plugins = array(); $symLinks = array(); $newFiles = array(); if (!empty($this->request->base)) { $symLinks['/' . $this->request->base] = WWW_ROOT; } foreach ($files as &$file) { if (empty($file)) { continue; } $plugin = false; list($first, $second) = pluginSplit($file); if (CakePlugin::loaded($first) === true) { $file = $second; $plugin = $first; } $pluginPath = !empty($plugin) ? '../Plugin/' . $plugin . '/' . WEBROOT_DIR . '/' : ''; $file = $pluginPath . $type . '/' . $file . '.' . $type; $newFiles[] = $file; if (!empty($plugin) && !isset($plugins[$plugin])) { $plugins[$plugin] = true; $symLinks['/' . $this->request->base . '/' . Inflector::underscore($plugin)] = APP . 'Plugin/' . $plugin . '/' . WEBROOT_DIR . '/'; } } $_GET['f'] = implode(',', $newFiles); $_GET['symlinks'] = $symLinks; App::import('Vendor', 'Minify.minify/index'); $this->response->statusCode('304'); exit; }
/** * Load hooks as helpers * * @return void */ function __loadHooks() { if (Configure::read('Hook.helpers')) { // Set hooks $hooks = Configure::read('Hook.helpers'); $hooksE = explode(',', $hooks); foreach ($hooksE as $hook) { if (strstr($hook, '.')) { $hookE = explode('.', $hook); $plugin = $hookE['0']; $hookHelper = $hookE['1']; $filePath = APP . 'plugins' . DS . Inflector::underscore($plugin) . DS . 'views' . DS . 'helpers' . DS . Inflector::underscore($hookHelper) . '.php'; } else { $plugin = null; $filePath = APP . 'views' . DS . 'helpers' . DS . Inflector::underscore($hook) . '.php'; } if (file_exists($filePath)) { $this->hooks[] = $hook; } } // Set hooks as helpers foreach ($this->hooks as $hook) { $this->helpers[] = $hook; } } }
/** * The vast majority of the custom find types actually follow the same format * so there was little point explicitly writing them all out. Instead, if the * method corresponding to the custom find type doesn't exist, the options are * applied to the model's request property here and then we just call * parent::find('all') to actually trigger the request and return the response * from the API. * * In addition, if you try to fetch a timeline that supports paging, but you * don't specify paging params, you really want all tweets in that timeline * since time imemoriam. But twitter will only return a maximum of 200 per * request. So, we make multiple calls to the API for 200 tweets at a go, for * subsequent pages, then merge the results together before returning them. * * Twitter's API uses a count parameter where in CakePHP we'd normally use * limit, so we also copy the limit value to count so we can use our familiar * params. * * @param string $type * @param array $options * @return mixed */ public function find($type, $options = array()) { if (!empty($options['limit']) && empty($options['count'])) { $options['count'] = $options['limit']; } if ((empty($options['page']) || empty($options['count'])) && array_key_exists($type, $this->allowedFindOptions) && in_array('page', $this->allowedFindOptions[$type]) && in_array('count', $this->allowedFindOptions[$type])) { $options['page'] = 1; $options['count'] = 200; $results = array(); while (($page = $this->find($type, $options)) != false) { $results = array_merge($results, $page); $options['page']++; } return $results; } if (method_exists($this, '_find' . Inflector::camelize($type))) { return parent::find($type, $options); } $this->request['uri']['path'] = '1/statuses/' . Inflector::underscore($type); if (array_key_exists($type, $this->allowedFindOptions)) { $this->request['uri']['query'] = array_intersect_key($options, array_flip($this->allowedFindOptions[$type])); } if (in_array($type, $this->findMethodsRequiringAuth)) { $this->request['auth'] = true; } return parent::find('all', $options); }
/** * MailchimpAppModel::call() * * @return mixed */ public function call($method, array $options = []) { $args = []; foreach ($options as $key => $value) { $args[Inflector::underscore($key)] = $value; } $this->response = $this->Mailchimp->call($method, $args); if (!isset($this->response['status']) || $this->response['status'] !== 'error') { return $this->response; } if ($this->settings['exceptions']) { $errorMsg = "Unknown error"; $errorCode = null; $errorName = null; if (isset($this->response['error'])) { $errorMsg = $this->response['error']; } if (isset($this->response['code'])) { $errorCode = $this->response['code']; } if (isset($this->response['name'])) { $errorName = $this->response['name']; } throw new MailchimpException($errorMsg, $errorCode, $errorName); } return false; }
public function changeStatus(Model $Model, $status, $id = null, $force = false) { if ($id === null) { $id = $Model->getID(); } if ($id === false) { return false; } $force = true; $Model->id = $id; if (!$Model->exists()) { throw new NotFoundException(); } if ($force !== true) { $modelData = $Model->read(); if ($modelData[$Model->alias]['status'] === $status) { CakeLog::write(LOG_WARNING, __d('webshop', 'The status of %1$s with id %2$d is already set to %3$s. Not making a change', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop')); return false; } } else { CakeLog::write(LOG_WARNING, __d('webshop', 'Status change of %1$s with id %2$d is being forced to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop')); } $Model->saveField('status', $status); CakeLog::write(LOG_INFO, __d('webshop', 'Changed status of %1$s with id %2$d to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop')); $eventData = array(); $eventData[Inflector::underscore($Model->name)]['id'] = $id; $eventData[Inflector::underscore($Model->name)]['status'] = $status; $overallEvent = new CakeEvent($Model->name . '.statusChanged', $this, $eventData); $specificEvent = new CakeEvent($Model->name . '.statusChangedTo' . Inflector::camelize($status), $this, $eventData); CakeEventManager::instance()->dispatch($overallEvent); CakeEventManager::instance()->dispatch($specificEvent); return true; }
/** * Initializes the pager. Must be called before using the component. * * Takes user configuration and creates pager object ($this->Pager) * * @access public * @param array $config Configuration options for Pager::factory() method * @see http://pear.php.net/manual/en/package.html.pager.factory.php * @return void */ function init($config) { // Get the correct URL, even with admin routes $here = array(); if (defined('CAKE_ADMIN') && !empty($this->Controller->params[CAKE_ADMIN])) { $here[0] = $this->Controller->params[CAKE_ADMIN]; $here[2] = substr($this->Controller->params['action'], strlen($this->Controller->params[CAKE_ADMIN]) + 1); } else { $here[2] = $this->Controller->params['action']; } $here[1] = Inflector::underscore($this->Controller->params['controller']); ksort($here); $url = implode('/', $here); // Set up the default configuration vars $this->params = array('mode' => 'Sliding', 'perPage' => 10, 'delta' => 5, 'totalItems' => '', 'httpMethod' => 'GET', 'currentPage' => 1, 'linkClass' => 'pager', 'altFirst' => 'First page', 'altPrev ' => 'Previous page', 'altNext' => 'Next page', 'altLast' => 'Last page', 'separator' => '', 'spacesBeforeSeparator' => 1, 'spacesAfterSeparator' => 1, 'useSessions' => false, 'firstPagePre' => '', 'firstPagePost' => '', 'firstPageText' => '<img src="' . $this->Controller->base . '/img/first.gif" alt="">', 'lastPagePre' => '', 'lastPagePost' => '', 'lastPageText' => '<img src="' . $this->Controller->base . '/img/last.gif" alt="">', 'prevImg' => '<img src="' . $this->Controller->base . '/img/prev.gif" alt="">', 'nextImg' => '<img src="' . $this->Controller->base . '/img/next.gif" alt="">', 'altPage' => 'Page', 'clearIfVoid' => true, 'append' => false, 'path' => '', 'fileName' => $this->Controller->base . DS . $url . DS . '%d', 'urlVar' => ''); vendor('Pear/Pager/Pager'); // Merge with user config $this->params = array_merge($this->params, $config); // sanitize requested page number if (!in_array($this->params['currentPage'], range(1, ceil($this->params['totalItems'] / $this->params['perPage'])))) { $this->params['currentPage'] = 1; } $this->Pager =& Pager::factory($this->params); // Set the template vars $this->Controller->set('pageLinks', $this->Pager->getLinks()); $this->Controller->set('currentPage', $this->params['currentPage']); $this->Controller->set('isFirstPage', $this->Pager->isFirstPage()); $this->Controller->set('isLastPage', $this->Pager->isLastPage()); }
/** * beforeRender callback * * @return void * @access public */ public function beforeRender() { parent::beforeRender(); $this->Jquery->uses('jquery', 'ui', 'potato.menu'); $this->_categoryModel = $this->params['menu']['model']; $this->_categoryController = Inflector::underscore(Inflector::pluralize($this->_categoryModel)); }
/** * This function inserts CK Editor for a form input * * @param string $input The name of the field, can be field_name or Model.field_name * @param array $options Options include $options['label'] for a custom label - this can be expanded on if required */ public function input($input, $options = array()) { echo $this->Html->script('//cdn.ckeditor.com/4.4.5.1/standard/ckeditor.js'); $input = explode('.', $input); if (empty($input[1])) { $field = $input[0]; $model = $this->Form->model(); } else { $model = $input[0]; $field = $input[1]; } if (!empty($options['label'])) { echo '<label>' . $options['label'] . '</label>'; } else { echo '<label>' . Inflector::humanize(Inflector::underscore($field)) . '</label>'; } echo $this->Form->error($model . '.' . $field); echo $this->Form->input($model . '.' . $field, array('type' => 'textarea', 'label' => false, 'error' => false, 'required' => false)); ?> <script type="text/javascript"> CKEDITOR.replace('<?php echo Inflector::camelize($model . '_' . $field); ?> ', { customConfig: '<?php echo $this->Html->url('/pages/ckeditor'); ?> ' }); </script> <p> </p> <?php }
public function translations() { $models = array_diff(App::objects('model'), array('AppModel')); $translations = array(); $out = "<?php "; foreach ($models as $model) { $Model = ClassRegistry::init($model); $translations[Inflector::humanize(Inflector::underscore($Model->name))] = true; $translations[$Model->brwConfig['names']['singular']] = true; $translations[$Model->brwConfig['names']['plural']] = true; $schema = (array) $Model->schema(); foreach ($schema as $key => $value) { $translations[Inflector::humanize(str_replace('_id', '', $key))] = true; } foreach ($Model->brwConfig['custom_actions'] as $action => $config) { $translations[$config['title']] = true; if ($config['confirmMessage']) { $translations[$config['confirmMessage']] = true; } } } $translations = array_keys($translations); foreach ($translations as $translation) { $out .= "__('" . $translation . "');\n"; } $forTranslate = ROOT . DS . APP_DIR . DS . 'View' . DS . 'Elements' . DS . '4translate.php'; fwrite(fopen($forTranslate, 'w'), $out); }
/** * beforeFind can be used to cancel find operations, or modify the query that will be executed. * By returning null/false you can abort a find. By returning an array you can modify/replace the query * that is going to be run. * * @param Model $model Model using this behavior * @param array $query Data used to execute this query, i.e. conditions, order, etc. * @return bool|array False or null will abort the operation. You can return an array to replace the * $query that will be eventually run. */ public function beforeFind(Model $model, $query) { $model->Like = ClassRegistry::init('Likes.Like'); $model->LikesUser = ClassRegistry::init('Likes.LikesUser'); $conditions = $query['conditions']; if (is_array($query['conditions']) === false) { return $query; } $columns = array(); if (!isset($query['fields'])) { $columns = 'Like.*'; } else { $columns = $query['fields']; } $columns = Hash::merge((array) $columns, array_keys($conditions)); // Like条件あったらJOIN if (!preg_grep('/^Like\\./', $columns) && !preg_grep('/^LikesUser\\./', $columns)) { return $query; } if (!isset($query['fields'])) { $query['fields'] = '*'; } $query['joins'][] = array('table' => $model->Like->table, 'alias' => $model->Like->alias, 'type' => 'LEFT', 'conditions' => array('Like.plugin_key' => Inflector::underscore($model->plugin), $this->__model . '.' . $this->__field . ' = ' . 'Like.content_key')); $likesUserConditions = array('Like.id = LikesUser.like_id'); if (Current::read('User.id')) { $likesUserConditions['LikesUser.user_id'] = Current::read('User.id'); } else { $likesUserConditions['LikesUser.session_key'] = CakeSession::id(); } $query['joins'][] = array('table' => $model->LikesUser->table, 'alias' => $model->LikesUser->alias, 'type' => 'LEFT', 'conditions' => $likesUserConditions); return $query; }
protected function _assign($model) { if ($this->getRequest()->isHead()) { Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer')->setNoRender(true); return; } $request = $this->getRequest(); $this->_setEtag($model->etag($this->_context)); $modelName = $model instanceof Bbx_Model ? Inflector::underscore(get_class($model)) : Inflector::tableize($model->getModelName()); if ($request->getParam('list') === 'true') { $model->renderAsList(); } if ($this->_context === 'csv') { $this->_helper->authenticate(); } if ($request->getParam('download') == 'true') { $this->_helper->authenticate(); $this->_helper->download($model); } if ($this->_context === 'json') { $options = $this->_context === 'json' ? array('deep' => true) : null; $this->view->assign($model->toArray($options)); } else { $this->view->{$modelName} = $model; } }
/** * Render the current view. * * @return void **/ public function render() { $registry = Components\Registry::instance(); $plugins = $registry->plugins; $vars = $registry->get_view_vars(); $vars['current_controller'] = $registry->controller; $vars['current_action'] = $registry->action; include_once 'application_helper.php'; $helper_classes = array(); $helper_names = array(); foreach (glob(VALET_ROOT . "/core/libs/helpers/*.php") as $file) { $class = str_replace(".php", "", basename($file)); $class = \Inflector::camelize($class); include_once $file; $helper_names[] = $class; } $helper_names[] = "ApplicationHelper"; $controller_helper = $registry->helper(); if (@(include_once \Inflector::underscore($controller_helper))) { $helper_names[] = $controller_helper; } foreach ($helper_names as $class) { $helper = new $class(); foreach (get_class_methods($helper) as $method) { if (substr($method, 0, 1) != '_') { $helper_classes[$method] = $helper; } } } if (!$this->_find_view($registry->view)) { throw new \Error("The view '" . $registry->view . "' could not be found."); } $file = new File($registry->view . ".phtml", $vars, $helper_classes); print $file; }
/** * Controllers initialize function. */ function initialize(&$controller, $settings = array()) { $this->Controller =& $controller; $settings = array_merge(array(), (array) $settings); $this->modelName = $this->Controller->modelClass; $this->prettyModelName = low(Inflector::humanize(Inflector::underscore(Inflector::pluralize($this->modelName)))); }
/** * Loads/constructs a helper. Will return the instance in the registry if it already exists. * By setting `$enable` to false you can disable callbacks for a helper. Alternatively you * can set `$settings['enabled'] = false` to disable callbacks. This alias is provided so that when * declaring $helpers arrays you can disable callbacks on helpers. * * @param string $helper Helper name to load * @param array $settings Settings for the helper. * @return Helper A helper object, Either the existing loaded helper or a new one. * @throws MissingHelperFileException, MissingHelperClassException when the helper could not be found */ public function load($helper, $settings = array()) { list($plugin, $name) = pluginSplit($helper, true); if (isset($this->_loaded[$name])) { return $this->_loaded[$name]; } $helperClass = $name . 'Helper'; if (!class_exists($helperClass)) { if (!App::import('Helper', $helper)) { throw new MissingHelperFileException(array('class' => $helperClass, 'file' => Inflector::underscore($name) . '.php')); } if (!class_exists($helperClass)) { throw new MissingHelperClassException(array('class' => $helperClass, 'file' => Inflector::underscore($name) . '.php')); } } $this->_loaded[$name] = new $helperClass($this->_View, $settings); $vars = array('request', 'theme', 'plugin'); foreach ($vars as $var) { $this->_loaded[$name]->{$var} = $this->_View->{$var}; } $enable = isset($settings['enabled']) ? $settings['enabled'] : true; if ($enable === true) { $this->_enabled[] = $name; } return $this->_loaded[$name]; }
function add() { if (empty($this->data)) { //$this->set('resellers', $this->Customer->Reseller->generateList()); $this->set('customer_list', $this->Customer->generateList(array("OR" => array('Customer.customer_id' => 'IS NULL', 'Customer.customer_id' => 0)), null, null, '{n}.Customer.id', '{n}.Customer.company_name')); //$this->data['Referrer']['customer_id'] = 699; if (isset($this->data['Referrer']['customer_id'])) { $this->set('customer', array('Customer' => array('customer_id' => $this->data['Referrer']['customer_id']))); } else { $this->set('customer', array('Customer' => array('customer_id' => null))); } } else { if ($this->Customer->save($this->data)) { $newcustomer = $this->Customer->getLastInsertId(); if (!empty($this->data['Website']['uri'])) { $this->data['Website']['title'] = empty($this->data['Website']['title']) ? $this->data['Customer']['company_name'] : $this->data['Website']['title']; $this->data['Website']['customer_id'] = $newcustomer; $websitedata['Website'] = $this->data['Website']; $this->Customer->Website->save($websitedata); } $this->Session->setFlash("Customer created successfully."); $this->redirect("/" . Inflector::underscore($this->name) . "/view/{$newcustomer}"); } else { $this->Session->setFlash('Please correct errors below.'); //$this->set('resellers', $this->Customer->Reseller->generateList()); $this->set('customer_list', $this->Customer->generateList(array("OR" => array('Customer.customer_id' => 'IS NULL', 'Customer.customer_id' => 0)), null, null, '{n}.Customer.id', '{n}.Customer.company_name')); } } }
/** * Retrieve an enum list for a Models field and translate the values. * * @param string $model * @param string $field * @param mixed $value * @param string $domain * @return string|array */ public function enum($model, $field, $value = null, $domain = null) { $enum = ClassRegistry::init($model)->enum($field); list($plugin, $model) = pluginSplit($model); // Set domain if (!$domain) { if ($plugin) { $domain = Inflector::underscore($plugin); } else { $domain = 'default'; } } // Cache the translations $key = Inflector::underscore($model) . '.' . Inflector::underscore($field); $cache = $key . '.enum'; if (isset($this->_cached[$cache])) { $enum = $this->_cached[$cache]; } else { foreach ($enum as $k => &$v) { $message = __d($domain, $key . '.' . $k); // Only use message if a translation exists if ($message !== $key . '.' . $k) { $v = $message; } } $this->_cached[$cache] = $enum; } // Filter down by value if ($value !== null) { return isset($enum[$value]) ? $enum[$value] : null; } return $enum; }
function main() { if (empty($this->args)) { return $this->err('Usage: ./cake fixturize <table>'); } if ($this->args[0] == '?') { return $this->out('Usage: ./cake fixturize <table> [-force] [-reindex]'); } $options = array('force' => false, 'reindex' => false); foreach ($this->params as $key => $val) { foreach ($options as $name => $option) { if (isset($this->params[$name]) || isset($this->params['-' . $name]) || isset($this->params[$name[0]])) { $options[$name] = true; } } } foreach ($this->args as $table) { $name = Inflector::classify($table); $Model = new AppModel(array('name' => $name, 'table' => $table)); $file = sprintf('%stests/fixtures/%s_fixture.php', APP, Inflector::underscore($name)); $File = new File($file); if ($File->exists() && !$options['force']) { $this->err(sprintf('File %s already exists, use --force option.', $file)); continue; } $records = $Model->find('all'); $out = array(); $out[] = '<?php'; $out[] = ''; $out[] = sprintf('class %sFixture extends CakeTestFixture {', $name); $out[] = sprintf(' var $name = \'%s\';', $name); $out[] = ' var $records = array('; $File->write(join("\n", $out)); foreach ($records as $record) { $out = array(); $out[] = ' array('; if ($options['reindex']) { foreach (array('old_id', 'vendor_id') as $field) { if ($Model->hasField($field)) { $record[$name][$field] = $record[$name]['id']; break; } } $record[$name]['id'] = String::uuid(); } foreach ($record[$name] as $field => $val) { $out[] = sprintf(' \'%s\' => \'%s\',', addcslashes($field, "'"), addcslashes($val, "'")); } $out[] = ' ),'; $File->write(join("\n", $out)); } $out = array(); $out[] = ' );'; $out[] = '}'; $out[] = ''; $out[] = '?>'; $File->write(join("\n", $out)); $this->out(sprintf('-> Create %sFixture with %d records (%d bytes) in "%s"', $name, count($records), $File->size(), $file)); } }
public function bootstrapScript($url = 'bootstrap.min.js', $options = array()) { $pluginRoot = dirname(dirname(DIRNAME(__FILE__))); $pluginName = end(explode(DS, $pluginRoot)); $url = '/' . Inflector::underscore($pluginName) . '/js/' . $url; return parent::script($url, $options); }
function getElementName() { if (!$this->element) { if ($this->name == 'FilterType') { $this->element = 'default_filter'; $this->elemPlugin = 'CustomFilter'; } else { $path = APP; if ($this->plugin) { $path = App::pluginPath($this->plugin); } $path .= 'view' . DS . 'elements' . DS . Inflector::underscore($this->name) . '_filter'; if (file_exists($path)) { $this->element = Inflector::underscore($this->name) . '_filter'; $this->elemPlugin = $this->plugin ? $this->plugin : false; } else { $this->element = 'default_filter'; $this->elemPlugin = 'CustomFilter'; } } } if (is_null($this->elemPlugin)) { $this->elemPlugin = $this->plugin ? $this->plugin : false; } return array('elem' => $this->element, 'plugin' => $this->elemPlugin); }
/** * Override loadTasks() to handle paths * * @access public */ function loadTasks() { parent::loadTasks(); $task = Inflector::classify($this->command); if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig'))) { if (empty($this->{$task}->path)) { $path = Inflector::underscore(Inflector::pluralize($this->command)); $this->{$task}->path = $this->params['working'] . DS . $path . DS; } if (isset($this->params['connection'])) { $this->{$task}->connection = $this->params['connection']; } foreach ($this->args as $i => $arg) { if (strpos($arg, '.')) { list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg); break; } } if (isset($this->params['plugin'])) { $this->{$task}->plugin = $this->params['plugin']; } if (!is_dir($this->{$task}->path)) { $this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path)); $this->_stop(); } } }
public function failure($message, $element = null, $params = array()) { $method = sprintf('%s_%s', Inflector::underscore($this->settings['style']), 'failure'); if (method_exists($this, $method)) { return call_user_func_array([&$this, $method], func_get_args()); } }
/** * Creates and issue multi call to magento api */ public function multiCall($calls) { $model = Inflector::underscore($this->name); $request = array($this->_getSession(), $calls); $results = $this->query('multiCall', $request); return $results; }
function loadComponent($componentName) { $component = null; $pathing = $this->componentPathing($componentName); if (!isset($this->controller->{$pathing['name']})) { if (!class_exists($pathing['className'])) { if (is_null($pathing['plugin']) || !App::import('Component', $pluginPt . $componentName)) { if (!App::import('Component', $componentName)) { $this->cakeError('missingComponentFile', array(array('className' => $pathing['className'], 'component' => $pathing['name'], 'file' => Inflector::underscore($componentName) . '.php', 'base' => $componentName, 'code' => 500))); return false; } } if (!class_exists($pathing['className'])) { $this->cakeError('missingComponentClass', array(array('className' => $pathing['className'], 'component' => $pathing['name'], 'file' => Inflector::underscore($componentName) . '.php', 'base' => $componentName, 'code' => 500))); return false; } } $component =& new $pathing['className'](); //$component->startup($this->controller); if (isset($component->components) && is_array($component->components)) { foreach ($component->components as $cmp) { $component->{$cmp} = $this->loadComponent($cmp); } } if (method_exists($component, 'initialize')) { $component->initialize($this->controller); } } else { $component =& $this->controller->{$componentName}; } return $component; }
/** * Loads a plugin and optionally loads bootstrapping, routing files or loads a initialization function * * Examples: * * `CakePlugin::load('DebugKit')` will load the DebugKit plugin and will not load any bootstrap nor route files * `CakePlugin::load('DebugKit', array('bootstrap' => true, 'routes' => true))` will load the bootstrap.php and routes.php files * `CakePlugin::load('DebugKit', array('bootstrap' => false, 'routes' => true))` will load routes.php file but not bootstrap.php * `CakePlugin::load('DebugKit', array('bootstrap' => array('config1', 'config2')))` will load config1.php and config2.php files * `CakePlugin::load('DebugKit', array('bootstrap' => 'aCallableMethod'))` will run the aCallableMethod function to initialize it * * Bootstrap initialization functions can be expressed as a PHP callback type, including closures. Callbacks will receive two * parameters (plugin name, plugin configuration) * * It is also possible to load multiple plugins at once. Examples: * * `CakePlugin::load(array('DebugKit', 'ApiGenerator'))` will load the DebugKit and ApiGenerator plugins * `CakePlugin::load(array('DebugKit', 'ApiGenerator'), array('bootstrap' => true))` will load bootstrap file for both plugins * * {{{ * CakePlugin::load(array( * 'DebugKit' => array('routes' => true), * 'ApiGenerator' * ), array('bootstrap' => true)) * }}} * * Will only load the bootstrap for ApiGenerator and only the routes for DebugKit * * @param string|array $plugin name of the plugin to be loaded in CamelCase format or array or plugins to load * @param array $config configuration options for the plugin * @throws MissingPluginException if the folder for the plugin to be loaded is not found * @return void */ public static function load($plugin, $config = array()) { if (is_array($plugin)) { foreach ($plugin as $name => $conf) { list($name, $conf) = is_numeric($name) ? array($conf, $config) : array($name, $conf); self::load($name, $conf); } return; } $config += array('bootstrap' => false, 'routes' => false, 'ignoreMissing' => false); if (empty($config['path'])) { foreach (App::path('plugins') as $path) { if (is_dir($path . $plugin)) { self::$_plugins[$plugin] = $config + array('path' => $path . $plugin . DS); break; } //Backwards compatibility to make easier to migrate to 2.0 $underscored = Inflector::underscore($plugin); if (is_dir($path . $underscored)) { self::$_plugins[$plugin] = $config + array('path' => $path . $underscored . DS); break; } } } else { self::$_plugins[$plugin] = $config; } if (empty(self::$_plugins[$plugin]['path'])) { throw new MissingPluginException(array('plugin' => $plugin)); } if (!empty(self::$_plugins[$plugin]['bootstrap'])) { self::bootstrap($plugin); } }
function afterSave(&$model, $created) { if (empty($this->settings[$model->name])) { return true; } $folderName = Inflector::humanize(Inflector::underscore($model->name)) . ' Attachments'; $folder = $this->FileLibraryFile->FileLibraryFolder->find('first', array('conditions' => array('name' => $folderName, 'is_smart' => true))); if (empty($folder)) { $newFolder = array('FileLibraryFolder' => array('name' => $folderName, 'is_smart' => true)); $this->FileLibraryFile->FileLibraryFolder->create(); $this->FileLibraryFile->FileLibraryFolder->save($newFolder); $folderId = $this->FileLibraryFile->FileLibraryFolder->id; } else { $folderId = $folder['FileLibraryFolder']['id']; } $idsToSave = array(); foreach ($this->settings[$model->name] as $formField => $dbField) { if (!empty($model->data[$model->name][$formField]['name'])) { $data = array('FileLibraryFile' => array()); $data['FileLibraryFile']['file_upload'] = $model->data[$model->name][$formField]; $data['FileLibraryFile']['file_library_folder_id'] = $folderId; $data['FileLibraryFile']['smart_file'] = true; $this->FileLibraryFile->create(); $this->FileLibraryFile->save($data); $idsToSave[$dbField] = $this->FileLibraryFile->id; } } $model->save($idsToSave, array('callbacks' => false)); return true; }
public static function mapResources($controller = array(), $options = array()) { $hasPrefix = isset($options['prefix']); $options = array_merge(array('prefix' => '/', 'id' => self::ID . '|' . self::UUID), $options); $prefix = $options['prefix']; foreach ((array) $controller as $name) { list($plugin, $name) = pluginSplit($name); $urlName = Inflector::underscore($name); $plugin = Inflector::underscore($plugin); if ($plugin && !$hasPrefix) { $prefix = '/' . $plugin . '/'; } foreach (self::$_resourceMap as $params) { if ($params['action'] === 'count') { $url = $prefix . $urlName . '/count'; } else { $url = $prefix . $urlName . ($params['id'] ? '/:id' : ''); } if (!empty($options['controllerClass'])) { $controller = $options['controllerClass']; } else { $controller = $urlName; } Router::connect($url, array('plugin' => $plugin, 'controller' => $controller, 'action' => $params['action'], '[method]' => $params['method']), array('id' => $options['id'], 'pass' => array('id'))); } self::$_resourceMapped[] = $urlName; } return self::$_resourceMapped; }
/** * Verify that the current url is the right url to view the content * * Disabled if debug is > 1 * Doesn't do anything for admin methods, requestAction calls, ajax requests, or if data has been submitted. * Otherwise, check the url matches what the router says should be the url, check slugs and 301 redirect to the * correct url if the url doesn't match * * @return void * @access public */ function check() { if (isset($this->controller->params['requested']) || isset($this->controller->params['admin']) || $this->RequestHandler->isAjax() || $this->controller->data) { return; } $this->here = $here = '/' . trim($this->controller->params['url']['url'], '/'); $params =& $this->controller->params; $defaults = array('controller' => Inflector::underscore($this->controller->name), 'action' => $this->controller->action, 'admin' => !empty($this->controller->params['admin']), 'lang' => $params['lang'], 'theme' => $params['theme']); $url = am($defaults, $this->controller->passedArgs); if (isset($url[0]) && $params['url']['ext'] === 'html') { $id = Configure::read('Site.homeNode'); if (empty($url['admin']) && $url['controller'] === 'nodes' && $url['action'] === 'view' && $url[0] == $id) { $url = am($defaults, array('action' => 'index')); } } if (isset($url[0])) { $conditions = array(); $conditions['Node.id'] = $url[0]; $fields = array('Node.id', 'Revision.slug'); $recursive = 0; $result = $this->controller->Node->find('first', compact('conditions', 'fields', 'recursive')); if (!$result) { $this->controller->redirect($this->controller->Session->read('referer'), null, true); } $url[1] = $result['Revision']['slug']; } $normalized = Router::normalize($url); if ($normalized !== $here) { return $this->controller->redirect($normalized, 301); } }