camelize() public static method

public static camelize ( $string )
 public function get(Model $model, $name)
 {
     $inflectedName = Inflector::camelize($name);
     $className = 'Cloggy' . $inflectedName;
     $class = ClassRegistry::init('Cloggy.' . $className);
     return $class;
 }
 function find($type, $query = array())
 {
     if (is_array($type)) {
         $query = $type;
     } else {
         $query['type'] = $type;
     }
     if (!is_array($query)) {
         $query = array('Title' => $query);
     }
     $map = array('info' => 'ResponseGroup', 'type' => 'SearchIndex');
     foreach ($map as $old => $new) {
         $query[$new] = $query[$old];
         unset($query[$old]);
     }
     foreach ($query as $key => $val) {
         if (preg_match('/^[a-z]/', $key)) {
             $query[Inflector::camelize($key)] = $val;
             unset($query[$key]);
         }
     }
     $query = am(array('Service' => 'AWSECommerceService', 'AWSAccessKeyId' => $this->config['key'], 'Operation' => 'ItemSearch', 'Version' => '2008-06-28'), $query);
     $r = $this->Http->get('http://ecs.amazonaws.com/onca/xml', $query);
     $r = Set::reverse(new Xml($r));
     return $r;
 }
 /**
  * acl and auth
  *
  * @return void
  */
 public function auth()
 {
     //Configure AuthComponent
     $this->_controller->Auth->authenticate = array(AuthComponent::ALL => array('userModel' => 'User', 'fields' => array('username' => 'username', 'password' => 'password'), 'scope' => array('User.status' => 1)), 'Form');
     $actionPath = 'controllers';
     $this->_controller->Auth->authorize = array(AuthComponent::ALL => array('actionPath' => $actionPath), 'Actions');
     $this->_controller->Auth->loginAction = array('plugin' => null, 'controller' => 'users', 'action' => 'login');
     $this->_controller->Auth->logoutRedirect = array('plugin' => null, 'controller' => 'users', 'action' => 'login');
     $this->_controller->Auth->loginRedirect = array('plugin' => null, 'controller' => 'users', 'action' => 'index');
     if ($this->_controller->Auth->user() && $this->_controller->Auth->user('role_id') == 1) {
         // Role: Admin
         $this->_controller->Auth->allow();
     } else {
         if ($this->_controller->Auth->user()) {
             $roleId = $this->_controller->Auth->user('role_id');
         } else {
             $roleId = 3;
             // Role: Public
         }
         $allowedActions = ClassRegistry::init('Acl.AclPermission')->getAllowedActionsByRoleId($roleId);
         $linkAction = Inflector::camelize($this->_controller->request->params['controller']) . '/' . $this->_controller->request->params['action'];
         if (in_array($linkAction, $allowedActions)) {
             $this->_controller->Auth->allowedActions = array($this->_controller->request->params['action']);
         }
     }
 }
示例#4
0
 /**
  * Setup a particular upload field
  *
  * @param Model $model Model instance
  * @param string $field Name of field being modified
  * @param array $options array of configuration settings for a field
  * @return void
  */
 protected function _setupField(Model $model, $field, $options)
 {
     if (is_int($field)) {
         $field = $options;
         $options = array();
     }
     $this->defaults['rootDir'] = ROOT . DS . APP_DIR . DS;
     if (!isset($this->settings[$model->alias][$field])) {
         $options = array_merge($this->defaults, (array) $options);
         $options['fields'] += $this->defaults['fields'];
         $options['rootDir'] = $this->_getRootDir($options['rootDir']);
         $options['thumbnailName'] = $this->_getThumbnailName($options['thumbnailName'], $options['thumbnailPrefixStyle']);
         $options['thumbnailPath'] = Folder::slashTerm($this->_path($model, $field, array('isThumbnail' => true, 'path' => $options['thumbnailPath'] === null ? $options['path'] : $options['thumbnailPath'], 'rootDir' => $options['rootDir'])));
         $options['path'] = Folder::slashTerm($this->_path($model, $field, array('isThumbnail' => false, 'path' => $options['path'], 'rootDir' => $options['rootDir'])));
         if (!in_array($options['thumbnailMethod'], $this->_resizeMethods)) {
             $options['thumbnailMethod'] = 'imagick';
         }
         if (!in_array($options['pathMethod'], $this->_pathMethods)) {
             $options['pathMethod'] = 'primaryKey';
         }
         $options['pathMethod'] = '_getPath' . Inflector::camelize($options['pathMethod']);
         $options['thumbnailMethod'] = '_resize' . Inflector::camelize($options['thumbnailMethod']);
         $this->settings[$model->alias][$field] = $options;
     }
 }
 function load($admin, $useDbAssociations = false)
 {
     // Load an instance of the admin model object
     $plugin = Inflector::camelize($admin->plugin);
     $modelObj = ClassRegistry::init(array('class' => "{$plugin}.{$admin->modelName}Admin", 'table' => $admin->useTable, 'ds' => $admin->useDbConfig));
     $adminModelObj = ClassRegistry::init(array('class' => "{$plugin}.{$admin->modelName}Admin", 'table' => $admin->useTable, 'ds' => $admin->useDbConfig));
     $modelClass = $admin->modelName . 'Admin';
     $primaryKey = $adminModelObj->primaryKey;
     $displayField = $adminModelObj->displayField;
     $schema = $adminModelObj->schema(true);
     $fields = array_keys($schema);
     $controllerName = $this->_controllerName($admin->modelName);
     $controllerRoute = $this->_pluralName($admin->modelName);
     $pluginControllerName = $this->_controllerName($admin->modelName . 'Admin');
     $singularVar = Inflector::variable($modelClass);
     $singularName = $this->_singularName($modelClass);
     $singularHumanName = $this->_singularHumanName($this->_controllerName($admin->modelName));
     $pluralVar = Inflector::variable($pluginControllerName);
     $pluralName = $this->_pluralName($modelClass);
     $pluralHumanName = Inflector::humanize($this->_pluralName($controllerName));
     if ($useDbAssociations) {
         $associations = $this->loadAssociations($modelObj, $admin);
     } else {
         $associations = $this->__associations($adminModelObj);
     }
     return compact('admin', 'modelObj', 'adminModelObj', 'modelClass', 'primaryKey', 'displayField', 'schema', 'fields', 'controllerName', 'controllerRoute', 'pluginControllerName', 'singularVar', 'singularName', 'singularHumanName', 'pluralVar', 'pluralName', 'pluralHumanName', 'associations');
 }
 /**
  * beforeRender is used for pre-render processing.
  * Search the model schema for enum fields and transform
  * them to use selects instead of text-input boxes
  *
  * During the model loop, we also check for form validation
  * errors, and add them to an array, so that we can consolidate
  * errors at the top of the page.
  *
  * This code is probably Mysql specific.
  */
 function beforeRender()
 {
     $this->_persistValidation();
     $validationErrors = array();
     foreach ($this->modelNames as $model) {
         // add validationerrors to view
         if (is_array($this->{$model}->validationErrors)) {
             $validationErrors = array_merge($validationErrors, array_values($this->{$model}->validationErrors));
         }
         // enum fixer
         foreach ($this->{$model}->_schema as $var => $field) {
             // === used here because 0 != FALSE
             if (strpos($field['type'], 'enum') === FALSE) {
                 continue;
             }
             preg_match_all("/\\'([^\\']+)\\'/", $field['type'], $strEnum);
             if (is_array($strEnum[1])) {
                 $varName = Inflector::camelize(Inflector::pluralize($var));
                 $varName[0] = strtolower($varName[0]);
                 // make nice cases in <selects>
                 $names = array();
                 foreach ($strEnum[1] as $name) {
                     $names[] = ucwords(strtolower($name));
                 }
                 $this->set($varName, array_combine($strEnum[1], $names));
             }
         }
     }
     $this->set('validationErrors', $validationErrors);
 }
示例#7
0
 function beforeFilter()
 {
     parent::beforeFilter();
     $this->getConfig = Configure::read('webConfig');
     $this->theme = $this->getConfig['template'];
     $this->layout = $this->getConfig['template'];
     //Collemos a configuración da tenda da bbdd
     $this->set('config', $this->getConfig);
     //Collemos os tamaños das imxes da bbdd para cada controlador
     if (isset($this->getConfig['image_' . $this->params->controller])) {
         $imageSize = explode('x', $this->getConfig['image_' . $this->params->controller]);
         $this->set('imageSize', $imageSize);
     }
     //Collemos o nome da web (para os meta tags)
     $this->set('webName', $this->getConfig['webName']);
     $this->Auth->allow('index', 'view', 'contact', 'about');
     $this->setDefaults();
     //MODO MANTEMENTO
     //----------------------------------------------------------------------
     $this->manteinance();
     //Default language for dashboard
     $dashboardActions = array('add', 'edit', 'viewList');
     $controller = Inflector::camelize(Inflector::singularize($this->params['controller']));
     if (in_array($this->params['action'], $dashboardActions)) {
         $this->{$controller}->locale = $this->getConfig['default_language'];
     } else {
         $this->{$controller}->locale = Configure::read('Config.language');
     }
 }
示例#8
0
 /**
  * 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);
 }
 protected function _getFullAssetPath($path)
 {
     $filepath = preg_replace('/^' . preg_quote($this->Helper->request->webroot, '/') . '/', '', urldecode($path));
     $webrootPath = WWW_ROOT . str_replace('/', DS, $filepath);
     if (file_exists($webrootPath)) {
         //@codingStandardsIgnoreStart
         return $webrootPath;
         //@codingStandardsIgnoreEnd
     }
     $segments = explode('/', ltrim($filepath, '/'));
     if ($segments[0] === 'theme') {
         $theme = $segments[1];
         unset($segments[0], $segments[1]);
         $themePath = App::themePath($theme) . 'webroot' . DS . implode(DS, $segments);
         //@codingStandardsIgnoreStart
         return $themePath;
         //@codingStandardsIgnoreEnd
     } else {
         $plugin = Inflector::camelize($segments[0]);
         if (CakePlugin::loaded($plugin)) {
             unset($segments[0]);
             $pluginPath = CakePlugin::path($plugin) . 'webroot' . DS . implode(DS, $segments);
             //@codingStandardsIgnoreStart
             return $pluginPath;
             //@codingStandardsIgnoreEnd
         }
     }
     return false;
 }
示例#10
0
 function parse($html = null, $blockName = 'document', $blockParams = null)
 {
     $blockParams = (array) $blockParams;
     $blockParams += array('id' => null);
     if ($blockParams['id']) {
         $oldVars = $this->vars;
         $this->vars = SlNode::get($blockParams['id'], array('auth' => true));
     }
     if ($blockName === 'NodeView') {
         $skin = empty(SL::getInstance()->view->params['named']['skin']) ? Inflector::camelize($this->_getVar('CmsNode.skin')) : Inflector::camelize(SL::getInstance()->view->params['named']['skin']);
         $skin = $skin && Pheme::init("NodeView{$skin}") ? "NodeView{$skin}" : "NodeViewDefault";
     } else {
         $skin = $blockName;
     }
     if ($skin != $blockName) {
         PhemeParser::$parseCallStack[] = Pheme::get($skin);
         $result = parent::parse($html, $skin);
         array_pop(PhemeParser::$parseCallStack);
     } else {
         $result = parent::parse($html, $skin);
     }
     if (isset($oldVars)) {
         $this->vars = $oldVars;
     }
     return $result;
 }
示例#11
0
 /**
  * initialize
  * 
  * @param Controller $controller
  * @return void
  * @access public
  */
 function initialize(&$controller)
 {
     /* 未インストール・インストール中の場合はすぐリターン */
     if (!isInstalled()) {
         return;
     }
     $plugins = Configure::read('Baser.enablePlugins');
     /* プラグインフックコンポーネントが実際に存在するかチェックしてふるいにかける */
     $pluginHooks = array();
     if ($plugins) {
         foreach ($plugins as $plugin) {
             $pluginName = Inflector::camelize($plugin);
             if (App::import('Component', $pluginName . '.' . $pluginName . 'Hook')) {
                 $pluginHooks[] = $pluginName;
             }
         }
     }
     /* プラグインフックを初期化 */
     foreach ($pluginHooks as $pluginName) {
         $className = $pluginName . 'HookComponent';
         $this->pluginHooks[$pluginName] =& new $className();
         // 各プラグインの関数をフックに登録する
         if (isset($this->pluginHooks[$pluginName]->registerHooks)) {
             foreach ($this->pluginHooks[$pluginName]->registerHooks as $hookName) {
                 $this->registerHook($hookName, $pluginName);
             }
         }
     }
     /* initialize のフックを実行 */
     $this->executeHook('initialize', $controller);
 }
 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;
 }
示例#13
0
    /**
    * 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>&nbsp;</p>
		<?php 
    }
示例#14
0
 /**
  * Truncates all tables and loads fixtures into db
  *
  * @return void
  * @access public
  */
 function main()
 {
     if (!empty($this->args)) {
         if ($this->args[0] == 'chmod') {
             return $this->chmod();
         }
         $fixtures = $this->args;
         foreach ($fixtures as $i => $fixture) {
             $fixtures[$i] = APP . 'tests/fixtures/' . $fixture . '_fixture.php';
         }
     } else {
         App::import('Folder');
         $Folder = new Folder(APP . 'tests/fixtures');
         $fixtures = $Folder->findRecursive('.+_fixture\\.php');
     }
     $db = ConnectionManager::getDataSource('default');
     $records = 0;
     foreach ($fixtures as $path) {
         require_once $path;
         $name = str_replace('_fixture.php', '', basename($path));
         $class = Inflector::camelize($name) . 'Fixture';
         $Fixture =& new $class($db);
         $this->out('-> Truncating table "' . $Fixture->table . '"');
         $db->truncate($Fixture->table);
         $Fixture->insert($db);
         $fixtureRecords = count($Fixture->records);
         $records += $fixtureRecords;
         $this->out('-> Inserting ' . $fixtureRecords . ' records for "' . $Fixture->table . '"');
     }
     $this->out(sprintf('-> Done inserting %d records for %d tables', $records, count($fixtures)));
 }
示例#15
0
 public function _init()
 {
     /*
      * Auto bind the model
      * 
      * If the controller -class has defined the variable "bindModelName", then we use the name in that variable,
      * otherwise use the name of controller
      * 
      * Example:
      * 
      * class FoobarController extends Controller {
      * 		var $bindModelName = "users";
      * }
      * 
      * This would cause the controller to automatically bind to model "users" instead of "foobar"
      * 
      */
     $this->autoBindModel = Model::getModelIfExists(empty($this->bindModelName) ? $this->controllerName : $this->bindModelName);
     /*
      * Add the AUTOLOAD -models to this Controller. Autoload -models are models
      * which are always available via $this->Modelname in all controllers
      */
     if (property_exists('AppConfiguration', 'AUTOLOAD_MODELS')) {
         foreach (AppConfiguration::$AUTOLOAD_MODELS as $model) {
             $casedName = Inflector::camelize($model);
             $this->{$casedName} = Model::getModel($model);
         }
     }
 }
示例#16
0
 /**
  * Inits PO file from POT file.
  *
  * @param string|null $language Language code to use.
  * @return void|int
  */
 public function init($language = null)
 {
     if (!$language) {
         $language = strtolower($this->in('Please specify language code, e.g. `en`, `eng`, `en_US` etc.'));
     }
     if (strlen($language) < 2) {
         return $this->error('Invalid language code. Valid is `en`, `eng`, `en_US` etc.');
     }
     $this->_paths = [APP];
     if ($this->param('plugin')) {
         $plugin = Inflector::camelize($this->param('plugin'));
         $this->_paths = [Plugin::classPath($plugin)];
     }
     $response = $this->in('What folder?', null, rtrim($this->_paths[0], DS) . DS . 'Locale');
     $sourceFolder = rtrim($response, DS) . DS;
     $targetFolder = $sourceFolder . $language . DS;
     if (!is_dir($targetFolder)) {
         mkdir($targetFolder, 0775, true);
     }
     $count = 0;
     $iterator = new \DirectoryIterator($sourceFolder);
     foreach ($iterator as $fileinfo) {
         if (!$fileinfo->isFile()) {
             continue;
         }
         $filename = $fileinfo->getFilename();
         $newFilename = $fileinfo->getBasename('.pot');
         $newFilename = $newFilename . '.po';
         $this->createFile($targetFolder . $newFilename, file_get_contents($sourceFolder . $filename));
         $count++;
     }
     $this->out('Generated ' . $count . ' PO files in ' . $targetFolder);
 }
示例#17
0
 /**
  * Builds asset file path based off url
  *
  * @param string $url
  * @return string Absolute path for asset file
  */
 static function getAssetFile($url)
 {
     $parts = explode('/', $url);
     if ($parts[0] === 'theme') {
         $file = '';
         $fileFragments = explode(',', $url);
         $fileNumber = count($fileFragments);
         foreach ($fileFragments as $k => $fileFragment) {
             $fileParts = explode('/', $fileFragment);
             unset($fileParts[0], $fileParts[1]);
             if ($fileNumber == $k + 1) {
                 $file .= urldecode(implode(DS, $fileParts));
             } else {
                 $file .= urldecode(implode(DS, $fileParts)) . ',';
             }
         }
         $themeName = $parts[1];
         $path = Configure::read('App.www_root') . 'theme' . DS . $themeName;
         if (!file_exists($path)) {
             $path = App::themePath($themeName) . 'webroot';
         }
         return array($path, $file);
     }
     $plugin = Inflector::camelize($parts[0]);
     if (CakePlugin::loaded($plugin)) {
         unset($parts[0]);
         $fileFragment = urldecode(implode(DS, $parts));
         $pluginWebroot = CakePlugin::path($plugin) . 'webroot';
         return array($pluginWebroot, $fileFragment);
     } else {
         return array(WWW_ROOT, $_GET['f']);
     }
 }
示例#18
0
 /**
  * beforeRender
  *
  * @param string $viewFile
  * @return void
  */
 public function beforeRender($viewFile)
 {
     $actions = Configure::read('Wysiwyg.actions');
     if (is_array($actions)) {
         foreach ($actions as $key => $value) {
             if (is_string($value)) {
                 $this->actions[] = $value;
             } else {
                 $this->actions[] = $key;
             }
         }
     }
     $action = Inflector::camelize($this->request->params['controller']) . '/' . $this->request->params['action'];
     if (!empty($actions) && in_array($action, $this->actions)) {
         $this->Html->script('/ckeditor/js/wysiwyg', array('inline' => false));
         $this->Html->script('/ckeditor/js/ckeditor', array('inline' => false));
         $ckeditorActions = Configure::read('Wysiwyg.actions');
         if (!isset($ckeditorActions[$action])) {
             return;
         }
         $actionItems = $ckeditorActions[$action];
         $out = null;
         foreach ($actionItems as $actionItem) {
             $element = $actionItem['elements'];
             unset($actionItem['elements']);
             $config = empty($actionItem) ? '{}' : $this->Js->object($actionItem);
             $out .= sprintf('Croogo.Wysiwyg.Ckeditor.setup("%s", %s);', $element, $config);
         }
         $this->Js->buffer($out);
     }
 }
 function add()
 {
     if ($this->RequestHandler->isPost() && !empty($this->data['Watcher']['user_id'])) {
         $Model =& ClassRegistry::init($this->params['named']['object_type']);
         if ($Model->read(null, $this->params['named']['object_id']) && $this->Watcher->User->read(null, $this->data['Watcher']['user_id'])) {
             $Model->add_watcher($this->Watcher->User->data);
         }
     }
     Configure::write('debug', 0);
     extract($this->params['named']);
     $Model =& ClassRegistry::init(Inflector::camelize($object_type));
     $data = $Model->read(null, $object_id);
     $project_id = $Model->get_watched_project_id();
     $project = $this->Project->read('identifier', $project_id);
     $this->params['project_id'] = $project['Project']['identifier'];
     parent::_findProject();
     $members = $this->Project->members($project_id);
     if (!empty($data['Watcher'])) {
         foreach ($data['Watcher'] as $value) {
             if (array_key_exists($value['user_id'], $members)) {
                 unset($members[$value['user_id']]);
             }
         }
     }
     $this->set(array_merge(compact('members', 'object_type', 'object_id', 'data')));
     if ($this->RequestHandler->isAjax()) {
         $this->render('_watchers');
         $this->layout = 'ajax';
     } else {
         $this->redirect(env('HTTP_REFERER'));
     }
 }
示例#20
0
 /**
  * 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;
 }
示例#21
0
 /**
  * ウィジェットエリアを表示する
  *
  * @param $no ウィジェットエリアNO
  * @param array $options オプション
  *  `subDir` (boolean) エレメントのパスについてプレフィックスによるサブディレクトリを追加するかどうか
  *  ※ その他のパラメータについては、View::element() を参照
  */
 public function show($no, $options = array())
 {
     $options = array_merge(array('subDir' => true), $options);
     $WidgetArea = ClassRegistry::init('WidgetArea');
     $widgetArea = $WidgetArea->find('first', array('conditions' => array('WidgetArea.id' => $no)));
     if (empty($widgetArea['WidgetArea']['widgets'])) {
         return;
     }
     $widgets = BcUtil::unserialize($widgetArea['WidgetArea']['widgets']);
     usort($widgets, array('BcWidgetAreaHelper', '_widgetSort'));
     foreach ($widgets as $key => $widget) {
         $key = key($widget);
         if ($widget[$key]['status']) {
             $params = array();
             $plugin = '';
             $params['widget'] = true;
             if (empty($_SESSION['Auth']['User']) && !isset($cache)) {
                 $params['cache'] = '+1 month';
             }
             $params = am($params, $widget[$key]);
             $params[$no . '_' . $widget[$key]['id']] = $no . '_' . $widget[$key]['id'];
             // 同じタイプのウィジェットでキャッシュを特定する為に必要
             if (!empty($params['plugin'])) {
                 $plugin = Inflector::camelize($params['plugin']) . '.';
                 unset($params['plugin']);
             }
             $this->_View->BcBaser->element($plugin . 'widgets/' . $widget[$key]['element'], $params, $options);
         }
     }
 }
示例#22
0
文件: Base.php 项目: kurbmedia/Valet
 /**
  * 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;
 }
示例#23
0
 /**
  * List actions of a particular Controller.
  *
  * @param string  $name Controller name (the name only, without having Controller at the end)
  * @param string  $path full path to the controller file including file extension
  * @param boolean $all  default is false. it true, private actions will be returned too.
  *
  * @return array
  */
 public function listActions($name, $path)
 {
     // base methods
     if (strstr($path, APP . 'plugins')) {
         $plugin = $this->getPluginFromPath($path);
         $pacName = Inflector::camelize($plugin) . 'AppController';
         // pac - PluginAppController
         $pacPath = APP . 'plugins' . DS . $plugin . DS . $plugin . '_app_controller.php';
         App::import('Controller', $pacName, null, null, $pacPath);
         $baseMethods = get_class_methods($pacName);
     } else {
         $baseMethods = get_class_methods('AppController');
     }
     $controllerName = $name . 'Controller';
     App::import('Controller', $controllerName, null, null, $path);
     $methods = get_class_methods($controllerName);
     // filter out methods
     foreach ($methods as $k => $method) {
         if (strpos($method, '_', 0) === 0) {
             unset($methods[$k]);
             continue;
         }
         if (in_array($method, $baseMethods)) {
             unset($methods[$k]);
             continue;
         }
     }
     return $methods;
 }
示例#24
0
文件: Redisdb.php 项目: noikiy/inovi
 public function __construct($type)
 {
     $this->type = $type;
     $this->dbName = 'RDB_' . $type;
     $this->lock = STORAGE_PATH . DS . Inflector::camelize('redis_db') . '.lock';
     $this->db = container()->redis();
 }
 /**
  * Retrieves and paints the list of tests cases in an HTML format.
  *
  * @return void
  */
 public function testCaseList()
 {
     $testCases = parent::testCaseList();
     $core = $this->params['core'];
     $plugin = $this->params['plugin'];
     $buffer = "<h3>App Test Cases:</h3>\n<ul>";
     $urlExtra = null;
     if ($core) {
         $buffer = "<h3>Core Test Cases:</h3>\n<ul>";
         $urlExtra = '&core=true';
     } elseif ($plugin) {
         $buffer = "<h3>" . Inflector::humanize($plugin) . " Test Cases:</h3>\n<ul>";
         $urlExtra = '&plugin=' . $plugin;
     }
     if (count($testCases) < 1) {
         $buffer .= "<strong>EMPTY</strong>";
     }
     foreach ($testCases as $testCase) {
         $title = explode(DS, str_replace('.test.php', '', $testCase));
         $title[count($title) - 1] = Inflector::camelize($title[count($title) - 1]);
         $title = implode(' / ', $title);
         $buffer .= "<li><a href='" . $this->baseUrl() . "?case=" . urlencode($testCase) . $urlExtra . "'>" . $title . "</a></li>\n";
     }
     $buffer .= "</ul>\n";
     echo $buffer;
 }
示例#26
0
 /**
  * Connect to the controller and run our action.
  *
  * @return void
  **/
 private function _connect($class_path, $action, $parameters)
 {
     $parts = explode("/", $class_path);
     $controller = array_pop($parts);
     if (!isset($action) || empty($action)) {
         $action = "index";
     }
     Components\Registry::instance()->controller = $controller;
     Components\Registry::instance()->action = $action;
     Components\Registry::instance()->view = $class_path . "/" . $action;
     $file_path = $class_path . "_controller.php";
     $class = \Inflector::camelize($controller . "_controller");
     require_once 'application_controller.php';
     if ($this->_find_controller($file_path)) {
         include_once $file_path;
     } else {
         throw new \Error("No controller found for path.");
     }
     $controller = new $class();
     if (!method_exists($controller, $action)) {
         throw new \Error("Method '{$action}' does not exist on {$class}.");
         return;
     }
     $controller->params =& $parameters;
     $controller->{$action}();
     \View\Base::instance()->render();
 }
 /**
  * @return object
  */
 public static function get($type, $name)
 {
     $name = Inflector::camelize($name);
     $registry = GummRegistry::getRegistry();
     $regKey = $type . '_' . $name;
     if (isset($registry[$regKey])) {
         return $registry[$regKey];
     }
     App::import($type, $name);
     $objName = false;
     switch (strtolower($type)) {
         case 'model':
             $objName = $name . 'Model';
             break;
         case 'controller':
             $objName = $name . 'Controller';
             break;
         case 'helper':
             $objName = $name . 'Helper';
             break;
         case 'widget':
             $objName = $name;
             break;
         case 'component':
             $objName = $name . 'Component';
             break;
         case 'editor':
             $objName = $name . 'Editor';
             break;
     }
     $obj = new $objName();
     GummRegistry::updateRegistry($regKey, $obj);
     return $obj;
 }
 /**
  * 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);
 }
 function pick($layout_scheme)
 {
     App::import('Config', 'Typographer.' . $layout_scheme . '_config');
     $c_layout_scheme = Inflector::camelize($layout_scheme);
     //carrega os instrumentos e as configurações deste layout específico/
     $tools = Configure::read('Typographer.' . $c_layout_scheme . '.tools');
     $used_automatic_classes = Configure::read('Typographer.' . $c_layout_scheme . '.used_automatic_classes');
     foreach ($this->controller->helpers as $helper => $params) {
         if (is_array($params)) {
             if (isset($params['receive_tools'])) {
                 $this->controller->helpers[$helper]['tools'] = $tools;
                 unset($params['receive_tools']);
             }
             if (isset($params['receive_automatic_classes'])) {
                 $this->controller->helpers[$helper]['used_automatic_classes'] = $used_automatic_classes;
                 unset($params['used_automatic_classes']);
             }
         }
     }
     if (!isset($this->controller->view) || $this->controller->view == 'View') {
         $this->controller->view = 'Typographer.Type';
     }
     $this->controller->set('used_automatic_classes', $used_automatic_classes);
     $this->controller->set($tools);
     $this->controller->set('layout_scheme', $layout_scheme);
 }
 public function display($name = null, $settings = array(), $renderOptions = array())
 {
     if (!$name) {
         return false;
     }
     $id = uniqid();
     if (isset($settings['id'])) {
         $id = $settings['id'];
         unset($settings['id']);
     }
     $settings = array('settings' => $settings);
     $this->autoRender = false;
     $name = Inflector::camelize($name);
     $className = $name . 'LayoutElement';
     App::import('LayoutElement', $name);
     if ($_settings = $this->RequestHandler->getNamed('settings')) {
         $settings = array('settings' => $_settings);
     }
     if ($_renderOptions = $this->RequestHandler->getNamed('renderOptions')) {
         $renderOptions = $_renderOptions;
     }
     $Element = new $className($settings);
     $Element->id($id);
     $Element->render($renderOptions);
 }