Example #1
1
 /**
  * Initialize the Cache Engine
  *
  * Called automatically by the cache frontend
  * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
  *
  * @param array $settings array of setting for the engine
  * @return boolean True if the engine has been successfully initialized, false if not
  */
 public function init($settings = array())
 {
     if (!class_exists('Memcache')) {
         return false;
     }
     if (!isset($settings['prefix'])) {
         $settings['prefix'] = Inflector::slug(APP_DIR) . '_';
     }
     $settings += array('engine' => 'Memcache', 'servers' => array('127.0.0.1'), 'compress' => false, 'persistent' => true);
     parent::init($settings);
     if ($this->settings['compress']) {
         $this->settings['compress'] = MEMCACHE_COMPRESSED;
     }
     if (is_string($this->settings['servers'])) {
         $this->settings['servers'] = array($this->settings['servers']);
     }
     if (!isset($this->_Memcache)) {
         $return = false;
         $this->_Memcache = new Memcache();
         foreach ($this->settings['servers'] as $server) {
             list($host, $port) = $this->_parseServerString($server);
             if ($this->_Memcache->addServer($host, $port, $this->settings['persistent'])) {
                 $return = true;
             }
         }
         return $return;
     }
     return true;
 }
Example #2
1
 /**
  * Displays a view
  *
  * @param mixed What page to display
  * @return void
  * @throws NotFoundException When the view file could not be found
  *	or MissingViewException in debug mode.
  */
 public function display()
 {
     $path = func_get_args();
     //debug($path);
     $count = count($path);
     //debug($count);
     if (!$count) {
         return $this->redirect('/');
     }
     $page = $subpage = $title_for_layout = null;
     //debug(Inflector::humanize($path[$count - 1]));
     if (!empty($path[0])) {
         $page = $path[0];
     }
     if (!empty($path[1])) {
         $subpage = $path[1];
     }
     if (!empty($path[$count - 1])) {
         $title_for_layout = Inflector::humanize($path[$count - 1]);
     }
     $this->set(compact('page', 'subpage', 'title_for_layout'));
     //debug($this->render(implode('/', $path)));
     //debug($page);
     //debug($subpage);
     //debug($title_for_layout);
     try {
         $this->render(implode('/', $path));
     } catch (MissingViewException $e) {
         if (Configure::read('debug')) {
             throw $e;
         }
         throw new NotFoundException();
     }
 }
Example #3
0
function smarty_function_header($params, &$smarty)
{
    $self = $smarty->getTemplateVars('self');
    $theme = $smarty->getTemplateVars('theme');
    $title = $smarty->getTemplateVars('page_title');
    $inflector = new Inflector();
    $item_name = prettify($inflector->singularize($smarty->getTemplateVars('controller')));
    if (empty($title) || $title === 'Index') {
        switch ($smarty->getTemplateVars('action')) {
            case 'view':
                $title = $item_name . ' Details';
                break;
            case 'edit':
                $title = 'Editing ' . $item_name . ' Details';
                break;
            case 'new':
                $title = 'Create new ' . $item_name;
                break;
            case 'index':
            default:
                $title = $item_name;
                break;
        }
    }
    return '<h1 class="page_title">' . $title . '</h1>';
}
Example #4
0
 /**
  * undocumented function
  *
  * @param string $string 
  * @param string $count 
  * @param string $showCount 
  * @return void
  * @access public
  */
 function ize($string, $count, $showCount = true)
 {
     if ($count != 1) {
         $inflect = new Inflector();
         return ($showCount ? $count . ' ' : '') . $inflect->pluralize($string);
     }
     return ($showCount ? $count . ' ' : '') . $string;
 }
Example #5
0
 public static function find($value, $columnName = 'id')
 {
     $reflector = new \ReflectionClass(get_called_class());
     $inflector = new Inflector();
     $tableName = $inflector->tableize($reflector->getName());
     $stmt = self::$_connection->prepare("SELECT * FROM " . $tableName . " WHERE `" . $columnName . "` = :Value");
     $stmt->bindParam('Value', $value);
     $stmt->execute();
     $data = $stmt->fetch(\PDO::FETCH_ASSOC);
     return $data;
 }
Example #6
0
function season($indoor)
{
    // The configuration settings values have "0" for the year, to facilitate form input
    $today = date('0-m-d');
    $today_wrap = date('1-m-d');
    // Build the list of applicable seasons
    $seasons = Configure::read('options.season');
    unset($seasons['None']);
    if (empty($seasons)) {
        return 'None';
    }
    foreach (array_keys($seasons) as $season) {
        $season_indoor = Configure::read("season_is_indoor.{$season}");
        if ($indoor != $season_indoor) {
            unset($seasons[$season]);
        }
    }
    // Create array of which season follows which
    $seasons = array_values($seasons);
    $seasons_shift = $seasons;
    array_push($seasons_shift, array_shift($seasons_shift));
    $next = array_combine($seasons, $seasons_shift);
    // Look for the season that has started without the next one starting
    foreach ($next as $a => $b) {
        $start = Configure::read('organization.' . Inflector::slug(low($a)) . '_start');
        $end = Configure::read('organization.' . Inflector::slug(low($b)) . '_start');
        // Check for a season that wraps past the end of the year
        if ($start > $end) {
            $end[0] = '1';
        }
        if ($today >= $start && $today < $end || $today_wrap >= $start && $today_wrap < $end) {
            return $a;
        }
    }
}
 /**
  * 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;
 }
Example #8
0
 /**
  * Assign default forein_model to singular association name
  * @param  Jam_Meta $meta
  * @param  string   $name
  */
 public function initialize(Jam_Meta $meta, $name)
 {
     if (!$this->foreign_model) {
         $this->foreign_model = Inflector::singular($name);
     }
     parent::initialize($meta, $name);
 }
 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;
 }
Example #10
0
 /**
  * main
  *
  * @return void
  */
 public function main()
 {
     $model = $this->in('Model name:');
     $controller = Inflector::pluralize($model);
     $controllerActions = $this->in('Do you want to bake the controller with admin prefix: yes/no', 'y/n', 'n');
     $usePlugin = $this->in("Do you want to bake in plugin: yes/no", 'y/n', 'n');
     if ($usePlugin == 'y') {
         $pluginName = $this->in('Name of your plugin:', null, '');
         if ($pluginName == '') {
             $usePlugin = 'n';
         }
     }
     if ($controllerActions == 'y') {
         $controllerActions = '--admin';
     } else {
         $controllerActions = '--public';
     }
     $theme = 'fuelux';
     $modelCommand = "ajax_template.ext_bake model {$model}";
     $controllerCommand = "ajax_template.ext_bake controller {$controller} {$controllerActions}";
     $viewCommand = "ajax_template.ext_bake view {$controller}";
     $postfix = " --theme {$theme}";
     if ($usePlugin == 'y') {
         $postfix .= " --plugin {$pluginName}";
     }
     $this->dispatchShell($modelCommand . $postfix);
     $this->dispatchShell($controllerCommand . $postfix);
     $this->dispatchShell($viewCommand . $postfix);
 }
Example #11
0
 /**
  * Change the name of the view variable name
  * of the data when its sent to the view
  *
  * @param mixed $name
  * @return mixed
  */
 public function viewVar($name = null)
 {
     if (empty($name)) {
         return $this->config('viewVar') ?: Inflector::variable($this->_model()->name);
     }
     return $this->config('viewVar', $name);
 }
Example #12
0
/**
 * Displays a view
 *
 * @param mixed What page to display
 * @return void
 */
	public function display() {
		$path = func_get_args();

		$count = count($path);
		if (!$count) {
			$this->redirect('/');
		}
		$page = $subpage = $titleForLayout = null;

		if (!empty($path[0])) {
			$page = $path[0];
		}
		if (!empty($path[1])) {
			$subpage = $path[1];
		}
		if (!empty($path[$count - 1])) {
			$titleForLayout = Inflector::humanize($path[$count - 1]);
		}
		$this->set(array(
			'page' => $page,
			'subpage' => $subpage,
			'title_for_layout' => $titleForLayout
		));
		$this->render(implode('/', $path));
	}
 public function display()
 {
     $path = func_get_args();
     $count = count($path);
     if (!$count) {
         $this->redirect('/');
     }
     $page = $subpage = $title_for_layout = null;
     if (!empty($path[0])) {
         $page = $path[0];
     }
     if (!empty($path[1])) {
         $subpage = $path[1];
     }
     if (!empty($path[$count - 1])) {
         $title_for_layout = Inflector::humanize($path[$count - 1]);
     }
     $this->loadModel('Category');
     //$cats = $this->Category->find('list', array('order'=> array('Category.cat_name' => 'ASC')));
     $cats = $this->Category->find('list');
     // print_r($cats);
     $posts = array();
     $index = 1;
     foreach ($cats as $key => $value) {
         $this->loadModel('Post');
         $threads = $this->Post->find('threaded', array('fields' => array('post_id', 'Category.cat_name', 'Topic.topic_subject', 'parent_id'), 'conditions' => array('Category.cat_name' => $value, 'Topic.topic_cat' => $key)));
         $posts[$index]['Category'] = $value;
         $posts[$index]['Threads'] = $threads;
         $index++;
     }
     $this->set('posts', $posts);
     $this->set(compact('page', 'subpage', 'title_for_layout'));
     $this->render(implode('/', $path));
 }
Example #14
0
 public function beforeSave($options = array())
 {
     if (isset($this->data[$this->alias]['slug']) && empty($this->data[$this->alias]['slug'])) {
         $this->data[$this->alias]['slug'] = strtolower(Inflector::slug($this->data[$this->alias]['title'], '-'));
     }
     return parent::beforeSave($options);
 }
Example #15
0
 /**
  * Displays a view
  *
  * @return void
  * @throws NotFoundException When the view file could not be found
  *	or MissingViewException in debug mode.
  */
 public function home()
 {
     // Redirect to tasks page
     Router::redirect('*', array('controller' => 'tasks', 'action' => 'index'));
     $path = func_get_args();
     $count = count($path);
     if (!$count) {
         return $this->redirect('/');
     }
     $page = $subpage = $title_for_layout = null;
     if (!empty($path[0])) {
         $page = $path[0];
     }
     if (!empty($path[1])) {
         $subpage = $path[1];
     }
     if (!empty($path[$count - 1])) {
         $title_for_layout = Inflector::humanize($path[$count - 1]);
     }
     $this->set(compact('page', 'subpage', 'title_for_layout'));
     try {
         $this->render(implode('/', $path));
     } catch (MissingViewException $e) {
         if (Configure::read('debug')) {
             throw $e;
         }
         throw new NotFoundException();
     }
 }
 /**
  * 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']);
         }
     }
 }
 /**
  * Sample action for uploading a twitpic. Not intended for use in your apps.
  */
 public function add()
 {
     if (!empty($this->data)) {
         if ($this->TwitterAuth->isAuthorized) {
             if ($this->Twitpic->save($this->data)) {
                 $this->Session->setFlash(__('Twitpic created successfully', true));
                 $this->redirect(array('action' => 'view', $this->Twitpic->getInsertID()));
             } else {
                 if (!empty($this->Twitpic->response['error'])) {
                     $flashMessage = $this->Twitpic->response['error'];
                 } elseif (!empty($this->Twitpic->validationErrors)) {
                     $flashMessage = '';
                     foreach ($this->Twitpic->validationErrors as $field => $errorMessage) {
                         $flashMessage .= Inflector::humanize($field) . ': ' . $errorMessage;
                     }
                 } else {
                     $flashMessage = __('Unknown error', true);
                 }
             }
         } else {
             $flashMessage = __('You are not authorized', true);
         }
         $this->Session->setFlash($flashMessage);
     }
 }
Example #18
0
 /**
  * Initialize the Cache Engine
  *
  * Called automatically by the cache frontend
  * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
  *
  * @param array $setting array of setting for the engine
  * @return boolean True if the engine has been successfully initialized, false if not
  * @access public
  */
 function init($settings = array())
 {
     if (!class_exists('Memcache')) {
         return false;
     }
     parent::init(array_merge(array('engine' => 'Memcache', 'prefix' => Inflector::slug(APP_DIR) . '_', 'servers' => array('127.0.0.1'), 'compress' => false), $settings));
     if ($this->settings['compress']) {
         $this->settings['compress'] = MEMCACHE_COMPRESSED;
     }
     if (!is_array($this->settings['servers'])) {
         $this->settings['servers'] = array($this->settings['servers']);
     }
     if (!isset($this->__Memcache)) {
         $return = false;
         $this->__Memcache =& new Memcache();
         foreach ($this->settings['servers'] as $server) {
             $parts = explode(':', $server);
             $host = $parts[0];
             $port = 11211;
             if (isset($parts[1])) {
                 $port = $parts[1];
             }
             if ($this->__Memcache->addServer($host, $port)) {
                 $return = true;
             }
         }
         return $return;
     }
     return true;
 }
 /**
  * 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');
 }
Example #20
0
 /**
  * Checks whether the response was cached and set the body accordingly.
  *
  * @param CakeEvent $event containing the request and response object
  * @return CakeResponse with cached content if found, null otherwise
  */
 public function beforeDispatch(CakeEvent $event)
 {
     if (Configure::read('Cache.check') !== true) {
         return;
     }
     $path = $event->data['request']->here();
     if ($path === '/') {
         $path = 'home';
     }
     $prefix = Configure::read('Cache.viewPrefix');
     if ($prefix) {
         $path = $prefix . '_' . $path;
     }
     $path = strtolower(Inflector::slug($path));
     $filename = CACHE . 'views' . DS . $path . '.php';
     if (!file_exists($filename)) {
         $filename = CACHE . 'views' . DS . $path . '_index.php';
     }
     if (file_exists($filename)) {
         $controller = null;
         $view = new View($controller);
         $result = $view->renderCache($filename, microtime(true));
         if ($result !== false) {
             $event->stopPropagation();
             $event->data['response']->body($result);
             return $event->data['response'];
         }
     }
 }
Example #21
0
 /**
  * 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);
     }
 }
Example #22
0
 public function __construct($from, $name, array $config)
 {
     $this->name = $name;
     $this->model_from = $from;
     $this->model_to = array_key_exists('model_to', $config) ? $config['model_to'] : \Inflector::get_namespace($from) . 'Model_' . \Inflector::classify($name);
     $this->key_from = array_key_exists('key_from', $config) ? (array) $config['key_from'] : $this->key_from;
     $this->key_to = array_key_exists('key_to', $config) ? (array) $config['key_to'] : $this->key_to;
     $this->conditions = array_key_exists('conditions', $config) ? (array) $config['conditions'] : array();
     if (!empty($config['table_through'])) {
         $this->table_through = $config['table_through'];
     } else {
         $table_name = array($this->model_from, $this->model_to);
         natcasesort($table_name);
         $table_name = array_merge($table_name);
         $this->table_through = \Inflector::tableize($table_name[0]) . '_' . \Inflector::tableize($table_name[1]);
     }
     $this->key_through_from = !empty($config['key_through_from']) ? (array) $config['key_through_from'] : (array) \Inflector::foreign_key($this->model_from);
     $this->key_through_to = !empty($config['key_through_to']) ? (array) $config['key_through_to'] : (array) \Inflector::foreign_key($this->model_to);
     $this->cascade_save = array_key_exists('cascade_save', $config) ? $config['cascade_save'] : $this->cascade_save;
     $this->cascade_delete = array_key_exists('cascade_delete', $config) ? $config['cascade_delete'] : $this->cascade_delete;
     if (!class_exists($this->model_to)) {
         throw new \FuelException('Related model not found by Many_Many relation "' . $this->name . '": ' . $this->model_to);
     }
     $this->model_to = get_real_class($this->model_to);
 }
Example #23
0
 /**
  * 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;
         }
     }
 }
 /**
  * @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;
 }
Example #25
0
 public function set_values(array $data)
 {
     if (!Valid::url($data['next_url'])) {
         $data['next_url'] = NULL;
     }
     $data['fields'] = array();
     if (!empty($data['field']) and is_array($data['field'])) {
         foreach ($data['field'] as $key => $values) {
             foreach ($values as $index => $value) {
                 if ($index == 0) {
                     continue;
                 }
                 if ($key == 'source') {
                     $value = URL::title($value, '_');
                 }
                 $data['fields'][$index][$key] = $value;
             }
         }
         $data['field'] = NULL;
     }
     $email_type_fields = array();
     foreach ($data['fields'] as $field) {
         $email_type_fields['key'][] = $field['id'];
         $email_type_fields['value'][] = !empty($field['name']) ? $field['name'] : Inflector::humanize($field['id']);
     }
     $this->create_email_type($email_type_fields);
     return parent::set_values($data);
 }
 function admin_add($formId = null)
 {
     $response = false;
     if (!empty($this->request->data)) {
         if (empty($this->request->data['FormField']['name'])) {
             $original_name = 'New Field question';
             $this->request->data['FormField']['name'] = 'new_field';
         } else {
             $original_name = $this->request->data['FormField']['name'];
             $this->request->data['FormField']['name'] = Inflector::slug(strtolower($original_name));
         }
         if (empty($this->request->data['FormField']['label'])) {
             $this->request->data['FormField']['label'] = $original_name;
         }
         $this->FormField->create();
         if ($this->FormField->save($this->request->data)) {
             $response = $this->FormField->id;
         }
         $this->set('response', $response);
         $this->render('../../Plugin/Cforms/View/Elements/ajax_response');
     } elseif ($formId) {
         $this->request->data['FormField']['cform_id'] = $formId;
         $types = $this->FormField->types;
         $this->set('types', $types);
         $this->render('admin_add');
     }
 }
Example #27
0
 /**
  * Tokenize
  * 
  * @param string $action reset|confirm
  * @param string $field password|email
  * @param array $data CakeRequest::data
  * 
  * @return array $user User::find
  */
 public function tokenize(Model $Model, $action, $field, $data = array())
 {
     if (empty($field) || empty($action) || !in_array($field, array('password', 'email')) || !in_array($action, array('reset', 'confirm'))) {
         throw new InvalidArgumentException('Invalid agruments');
     }
     return $this->dispatchMethod('_' . Inflector::variable(sprintf('tokenize_%s_%s', $action, $field)), array($Model, $data));
 }
 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 createColumn(&$column)
 {
     $c = new Column();
     $c->inflectedName = Inflector::instance()->variablize($column['field']);
     $c->name = $column['field'];
     $c->nullable = $column['not_nullable'] ? false : true;
     $c->pk = $column['pk'] ? true : false;
     $c->autoIncrement = false;
     if (substr($column['type'], 0, 9) == 'timestamp') {
         $c->rawType = 'datetime';
         $c->length = 19;
     } elseif ($column['type'] == 'date') {
         $c->rawType = 'date';
         $c->length = 10;
     } else {
         preg_match('/^([A-Za-z0-9_]+)(\\(([0-9]+(,[0-9]+)?)\\))?/', $column['type'], $matches);
         $c->rawType = count($matches) > 0 ? $matches[1] : $column['type'];
         $c->length = count($matches) >= 4 ? intval($matches[3]) : intval($column['attlen']);
         if ($c->length < 0) {
             $c->length = null;
         }
     }
     $c->mapRawType();
     if ($column['default']) {
         preg_match('/^nextval\\(\'(.*)\'\\)$/', $column['default'], $matches);
         if (count($matches) == 2) {
             $c->sequence = $matches[1];
         } else {
             $c->default = $c->cast($column['default'], $this);
         }
     }
     return $c;
 }
Example #30
0
 /**
  * Setup function
  *
  * @param object $Model The calling model
  */
 public function setup(&$Model, $settings = array())
 {
     $Model->RevisionModel = new Model(array('table' => Inflector::tableize($Model->name) . '_revs', 'name' => 'Revision', 'ds' => $Model->useDbConfig));
     $Model->RevisionModel->primaryKey = 'version_id';
     $default = array('fields' => array());
     $this->settings[$Model->alias] = array_merge_recursive($default, $settings);
 }