/** * Method to output a tag-cloud formatted based on the weight of the tags * * @param array $tags * @param array $options Display options. Valid keys are: * - shuffle: true to shuffle the tag list, false to display them in the same order than passed [default: true] * - extract: Set::extract() compatible format string. Path to extract weight values from the $tags array [default: {n}.GlobalTag.weight] * - before: string to be displayed before each generated link. "%size%" will be replaced with tag size calculated from the weight [default: empty] * - after: string to be displayed after each generated link. "%size%" will be replaced with tag size calculated from the weight [default: empty] * - maxSize: size of the heaviest tag [default: 160] * - minSize: size of the lightest tag [default: 80] * - url: an array containing the default url * - named: the named parameter used to send the tag [default: by] * @return string * @access public */ public function display($tags = null, $options = array()) { if (empty($tags) || !is_array($tags)) { return ''; } $defaults = array('shuffle' => true, 'extract' => '{n}.GlobalTag.weight', 'between' => ' | ', 'maxSize' => 160, 'minSize' => 80, 'url' => array('action' => 'index'), 'named' => 'by'); $options = array_merge($defaults, $options); $weights = Set::extract($tags, $options['extract']); $maxWeight = max($weights); $minWeight = min($weights); // find the range of values $spread = $maxWeight - $minWeight; if (0 == $spread) { $spread = 1; } if ($options['shuffle'] == true) { shuffle($tags); } $cloud = array(); foreach ($tags as $tag) { $options['url'][$options['named']] = $tag['GlobalTag']['keyname']; $url = EventCore::trigger($this, Inflector::camelize($options['url']['plugin']) . '.slugUrl', array('type' => 'tag', 'data' => $options['url'])); $size = $options['minSize'] + ($tag['GlobalTag']['weight'] - $minWeight) * (($options['maxSize'] - $options['minSize']) / $spread); $size = ceil($size); $cloud[] = $this->Html->link($tag['GlobalTag']['name'], current($url['slugUrl']), array('class' => 'tag-' . $tag['GlobalTag']['id'])) . ' '; } return implode($options['between'], $cloud); }
/** * This happens after a find happens. * * @param object $Model Model about to be saved. * @return boolean true if save should proceed, false otherwise * @access public */ public function afterFind($Model, $data) { // skip finds with more than one result. $skip = $Model->findQueryType == 'neighbors' || $Model->findQueryType == 'count' || empty($data) || isset($data[0][0]['count']) || isset($data[0]) && count($data) > 1 || !isset($data[0][$Model->alias][$Model->primaryKey]); if ($skip) { return $data; } if (isset($this->__settings[$Model->alias]['session_tracking']) && $this->__settings[$Model->alias]['session_tracking']) { $this->__session[$Model->alias] = CakeSession::read('Viewable.' . $Model->alias); } $user_id = AuthComponent::user('id'); $view['ViewCount'] = array('user_id' => $user_id > 0 ? $user_id : 0, 'model' => Inflector::camelize($Model->plugin) . '.' . $Model->name, 'foreign_key' => $data[0][$Model->alias][$Model->primaryKey], 'referer' => str_replace(InfinitasRouter::url('/'), '/', $Model->__referer)); $location = EventCore::trigger($this, 'GeoLocation.getLocation'); $location = current($location['getLocation']); foreach ($location as $k => $v) { $view['ViewCount'][$k] = $v; } $view['ViewCount']['year'] = date('Y'); $view['ViewCount']['month'] = date('m'); $view['ViewCount']['day'] = date('j'); $view['ViewCount']['day_of_year'] = date('z'); $view['ViewCount']['week_of_year'] = date('W'); $view['ViewCount']['hour'] = date('G'); // no leading 0 $view['ViewCount']['city'] = $view['ViewCount']['city'] ? $view['ViewCount']['city'] : 'Unknown'; /** * http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_dayofweek * sunday is 1, php uses 0 */ $view['ViewCount']['day_of_week'] = date('w') + 1; $Model->ViewCount->unBindModel(array('belongsTo' => array('GlobalCategory'))); $Model->ViewCount->create(); $Model->ViewCount->save($view); return $data; }
/** * @brief load the user plugins * * This loads up plugins that are installed and active but not part of * the core. * * @access public * * @return void */ public static function loadInstalled() { $object = new StdClass(); foreach ((array) self::listPlugins('notLoaded') as $plugin) { self::load($plugin); EventCore::trigger($object, $plugin . '.requireLibs'); configureCache(EventCore::trigger($object, $plugin . '.setupCache')); EventCore::loadEventHandler($plugin); } }
/** * @brief build up some conditions to only select rows with active pluging data * * This stops things like routes and modules (or any other data) that is plugin * specific being pulled out when a plugin is disabled * * @access private * * @param Model $Model the model doing the find * * @return array conditions to add to a find */ private function __getPossiblePlugins($Model, $field) { $camelCasePlugins = EventCore::getAvailablePlugins(); $mixedCasePlugins = array(''); foreach ($camelCasePlugins as $plugin) { $mixedCasePlugins[] = $plugin; $mixedCasePlugins[] = Inflector::underscore($plugin); } return array('and' => array('or' => array($Model->alias . '.' . $field => $mixedCasePlugins))); }
public function testGetEventInstance() { $this->Events->something = 'foo'; $Event = EventCore::getInstance(); $this->assertTrue(isset($Event->something)); $result = $Event->something; $expected = 'foo'; $this->assertEquals($expected, $result); unset($Event); $this->assertFalse(isset($this->Event)); }
public function parse($url) { $params = parent::parse($url); if (!empty($params['plugin'])) { $plugin = Inflector::camelize($params['plugin']); $data = current(EventCore::trigger($this, $plugin . '.routeParse', $params)); if (isset($data[$plugin]) && $data[$plugin] !== null) { return $data[$plugin]; } } return $params; }
* */ if (!defined('WEBROOT_DIR')) { define('WEBROOT_DIR', basename(dirname(__FILE__))); } if (!defined('WWW_ROOT')) { define('WWW_ROOT', dirname(__FILE__) . DS); } if (!defined('CAKE_CORE_INCLUDE_PATH')) { if (function_exists('ini_set')) { ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path')); } if (!(include 'Cake' . DS . 'bootstrap.php')) { $failed = true; } } else { if (!(include CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) { $failed = true; } } if (!empty($failed)) { trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR); } if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/favicon.ico') { return; } App::uses('Dispatcher', 'Routing'); $Dispatcher = new Dispatcher(); $Dispatcher->dispatch(new CakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding')))); EventCore::trigger(new stdClass(), 'requestDone');
private function __loadHelpers() { $helpers = EventCore::trigger($this, 'requireHelpersToLoad'); foreach ($helpers['requireHelpersToLoad'] as $plugin) { foreach ((array) $plugin as $helper => $config) { if (is_int($helper) && is_string($config)) { $helper = $config; $config = array(); } $this->Helpers->load($helper, $config); } } }
public function startTest() { $this->Event = EventCore::getInstance(); }
protected function _dispatchMails($event, $mails) { foreach ($mails as $mail) { EventCore::trigger($event, 'receiveMails', $mail); } }
/** * @brief add connection to the connection manager * * allow plugins to use their own db configs. If there is a conflict, * eg: a plugin tries to set a config that alreay exists an error will * be thrown and the connection will not be created. * * default is a reserved connection that can only be set in database.php * and not via the events. * * @code * // for databases * array( * 'my_connection' => array( * 'driver' => 'mysqli', * 'persistent' => true, * 'host' => 'localhost', * 'login' => 'username', * 'password' => 'pw', * 'database' => 'db_name', * 'encoding' => 'utf8' * ) * ) * * // or other datasources * array( * 'my_connection' => array( * 'datasource' => 'Emails.Imap' * ) * ) * @endcode * * @access private * * @return void */ private function __setupDatabaseConnections() { $connections = array_filter(current(EventCore::trigger($this, 'requireDatabaseConfigs'))); foreach ($connections as $plugin => $connection) { $key = current(array_keys($connection)); $connection = current($connection); $alreadyUsed = strtolower($key) == 'default' || in_array($key, ConnectionManager::sourceList()); if ($alreadyUsed) { continue; throw new Exception(sprintf(__('The connection "%s" in the plugin "%s" has already been used. Skipping'), $key, $plugin)); } ConnectionManager::create($key, $connection); } }
/** * @brief Set up system configuration. * * Load the default configuration and check if there are any configs * to load from the current plugin. configurations can be completely rewriten * or just added to. * * @access private * * @return void */ protected function __setupConfig() { $configs = ClassRegistry::init('Configs.Config')->getConfig(); $eventData = EventCore::trigger($this, $this->plugin . '.setupConfigStart', $configs); if (isset($eventData['setupConfigStart'][$this->plugin])) { $configs = (array) $eventData['setupConfigStart'][$this->plugin]; if (!array($configs)) { $this->cakeError('eventError', array('message' => 'Your config is wrong.', 'event' => $eventData)); } } $eventData = EventCore::trigger($this, $this->plugin . '.setupConfigEnd'); if (isset($eventData['setupConfigEnd'][$this->plugin])) { $configs = $configs + (array) $eventData['setupConfigEnd'][$this->plugin]; } if (!$this->__writeConfigs($configs)) { $this->cakeError('configError', array('message' => 'Config was not written')); } unset($configs, $eventData); }
/** * Loads and initialises an event class * * @param string $className * @param string $filename * */ private function __loadEventClass($className, $filename = false) { if ($filename === false) { $baseName = Inflector::underscore($className) . '.php'; $pluginName = Inflector::camelize(preg_replace('/_events.php$/', '', $baseName)); $pluginPath = App::pluginPath($pluginName); $filename = $pluginPath . $baseName; } if (!class_exists('LibsEvent')) { //App::Import('file', 'LibsEvent', true, array(), App::pluginPath('libs').'libs_events.php'); } App::Import('file', $className, true, array(), $filename); try { $_this =& EventCore::getInstance(); $_this->__eventClasses[$className] =& new $className(); return true; } catch (Exception $e) { return false; } }
public function pluginsWith($eventName) { return EventCore::pluginsWith($eventName); }
public function getCityForUnknown() { $rows = $this->find('all', array('conditions' => array($this->alias . '.city' => 'Unknown', $this->alias . '.country_code != ' => '-'))); foreach ($rows as $row) { $temp = EventCore::trigger($this, 'getLocation', $row[$this->alias]['ip_address']); $temp = current($temp['getLocation']); if ($temp['country_code'] == 'Unknown') { $temp['country_code'] = '-'; } if (empty($temp['city'])) { unset($temp['city']); } if (empty($temp['continent_code'])) { $temp['continent_code'] = '-'; } $row[$this->alias] = array_merge(array_filter($row[$this->alias]), $temp); $this->save($row); } }
/** * Trigger a event * * @param string $eventName Name of the event to trigger * @param array $data Data to pass to event handler * @return array: */ public function triggerEvent(&$Model, $eventName, $data = array()) { return EventCore::trigger($Model, $eventName, $data); }
* Event to get the values from all the plugins and cache them */ $cachedConfigs = Cache::read('global_configs'); if (!empty($cachedConfigs)) { foreach ($cachedConfigs as $k => $v) { Configure::write($k, $v); } } unset($cacheEngine, $cachedConfigs); InfinitasPlugin::loadCore(); EventCore::trigger(new StdClass(), 'requireLibs'); /** * @todo cake2.0 * Cache::write('global_configs', Configure::getInstance()); */ configureCache(EventCore::trigger(new StdClass(), 'setupCache')); InfinitasPlugin::loadInstalled(); /** * Make sure the json defines are loaded. */ if (!defined('JSON_ERROR_NONE')) { define('JSON_ERROR_NONE', 0); } if (!defined('JSON_ERROR_DEPTH')) { define('JSON_ERROR_DEPTH', 1); } if (!defined('JSON_ERROR_CTRL_CHAR')) { define('JSON_ERROR_CTRL_CHAR', 3); } if (!defined('JSON_ERROR_SYNTAX')) { define('JSON_ERROR_SYNTAX', 4);
/** * @brief load up some fixtures from events * * There are some things that are always loaded up in infinitas like * configs, routes and modules. This gives such plugins a chance to load * fixtures without having to do it manually when writing tests. * * @access public * * @return array the array of fixtures */ public function fixturesFromEvents() { $autoFixtures = EventCore::trigger($this, 'getRequiredFixtures'); foreach ($autoFixtures['getRequiredFixtures'] as $plugin => $fixtureSet) { $this->__autoLoaded[$plugin] = $fixtureSet; $this->__fixturesToLoad = array_merge($this->__fixturesToLoad, $fixtureSet); } return true; }
public function startTest() { $this->Event = EventCore::getInstance(); $this->Cron = ClassRegistry::init('Crons.Cron'); }
/** * Register extensions that are used in the app * * Call all plugins and see what extensions are need, this is cached */ private static function __registerExtensions() { $extensions = Cache::read('extensions', 'routes'); if ($extensions === false) { $extensions = EventCore::trigger(new StdClass(), 'setupExtensions'); $_extensions = array(); foreach ($extensions['setupExtensions'] as $plugin => $ext) { $_extensions = array_merge($_extensions, (array) $ext); } $extensions = array_flip(array_flip($_extensions)); Cache::write('extentions', $extensions, 'routes'); unset($_extensions); } call_user_func_array(array('Router', 'parseExtensions'), $extensions); }
<?php /** * Load all the plugin dirs */ App::build(array('plugins' => array(APP . 'infinitas' . DS, APP . 'extensions' . DS))); /** * Load plugin events */ App::import('Libs', 'Events.Events'); EventCore::getInstance(); /** * Make sure the json defines are loaded. */ if (!defined('JSON_ERROR_NONE')) { define('JSON_ERROR_NONE', 0); } if (!defined('JSON_ERROR_DEPTH')) { define('JSON_ERROR_DEPTH', 1); } if (!defined('JSON_ERROR_CTRL_CHAR')) { define('JSON_ERROR_CTRL_CHAR', 3); } if (!defined('JSON_ERROR_SYNTAX')) { define('JSON_ERROR_SYNTAX', 4); } /** * Escape things for preg_match * * will escape a string for goind preg match. * http://www.php.net/manual/en/function.preg-replace.php#92456
/** * Trigger a event * * @param string $eventName Name of the event to trigger * @param array $data Data to pass to event handler * @return array: */ public function trigger($eventName, $data = array()) { return EventCore::trigger($this, $eventName, $data); }
/** * Extracts the plugin name out of the class name and caches the value * so that the strtolower and other stuff does not need to be called * so many times. * * @param string $className the name of the class being called * @return string the plugin being called. * @access private */ protected function _extractPluginName($className) { $_this = EventCore::getInstance(); if (!isset($_this->pluginNameCache->{$className})) { $_this->pluginNameCache->{$className} = substr($className, 0, strlen($className) - 6); } return $_this->pluginNameCache->{$className}; }