Exemplo n.º 1
0
 /**
  * Converts a string of params to an array of formatted key/value pairs
  *
  * String is supposed to have one parameter per line in the format:
  * my_param_key=value_here
  * another_param=another_value
  *
  * @param Model $model
  * @param string $params
  * @return array
  */
 public function paramsToArray(Model $model, $params)
 {
     $converter = new StringConverter();
     $output = array();
     $params = preg_split('/[\\r\\n]+/', $params);
     foreach ($params as $param) {
         if (strlen($param) == 0) {
             continue;
         }
         if ($param[0] === '[') {
             $options = $converter->parseString('options', $param, array('convertOptionsToArray' => true));
             if (!empty($options)) {
                 $output = array_merge($output, $options);
             }
             continue;
         }
         $paramE = explode('=', $param);
         if (count($paramE) == 2) {
             $key = $paramE['0'];
             $value = trim($paramE['1']);
             $num_check = filter_var($value, FILTER_VALIDATE_INT, array('flags' => FILTER_FLAG_ALLOW_HEX));
             $bool_check = filter_var($value, FILTER_VALIDATE_BOOLEAN, array('flags' => FILTER_NULL_ON_FAILURE));
             if ($num_check !== false) {
                 $value = $num_check;
             } else {
                 if (!is_null($bool_check)) {
                     $value = $bool_check;
                 }
             }
             $output[$key] = $value;
         }
     }
     return $output;
 }
Exemplo n.º 2
0
 /**
  * Filter block shortcode in node body, eg [block:snippet] and replace it with
  * the block content
  *
  * @param CakeEvent $event
  * @return void
  */
 public function filterBlockShortcode($event)
 {
     static $converter = null;
     if (!$converter) {
         $converter = new StringConverter();
     }
     $View = $event->subject;
     $body = null;
     if (isset($event->data['content'])) {
         $body =& $event->data['content'];
     } elseif (isset($event->data['node'])) {
         $body =& $event->data['node'][key($event->data['node'])]['body'];
     }
     $parsed = $converter->parseString('block|b', $body, array('convertOptionsToArray' => true));
     $regex = '/\\[(block|b):([A-Za-z0-9_\\-]*)(.*?)\\]/i';
     foreach ($parsed as $blockAlias => $config) {
         $block = $View->Regions->block($blockAlias);
         preg_match_all($regex, $body, $matches);
         if (isset($matches[2][0])) {
             $replaceRegex = '/' . preg_quote($matches[0][0]) . '/';
             $body = preg_replace($replaceRegex, $block, $body);
         }
     }
     Croogo::dispatchEvent('Helper.Layout.beforeFilter', $View, array('content' => &$body, 'options' => array()));
 }
Exemplo n.º 3
0
 /**
  * Converts a string of params to an array of formatted key/value pairs
  *
  * String is supposed to have one parameter per line in the format:
  * my_param_key=value_here
  * another_param=another_value
  *
  * @param Model $model
  * @param string $params
  * @return array
  */
 public function paramsToArray(Model $model, $params)
 {
     $converter = new StringConverter();
     $output = array();
     $params = preg_split('/[\\r\\n]+/', $params);
     foreach ($params as $param) {
         if (strlen($param) == 0) {
             continue;
         }
         if ($param[0] === '[') {
             $options = $converter->parseString('options', $param, array('convertOptionsToArray' => true));
             if (!empty($options)) {
                 $output = array_merge($output, $options);
             }
             continue;
         }
         $paramE = explode('=', $param);
         if (count($paramE) == 2) {
             $key = $paramE['0'];
             $value = $paramE['1'];
             $output[$key] = trim($value);
         }
     }
     return $output;
 }
Exemplo n.º 4
0
 /**
  * Setup Site.home_url
  *
  * @return void
  */
 public static function routes()
 {
     $homeUrl = Configure::read('Site.home_url');
     if ($homeUrl && strpos($homeUrl, ':') !== false) {
         $converter = new StringConverter();
         $url = $converter->linkStringToArray($homeUrl);
         CroogoRouter::connect('/', $url, array(), array('promote' => true));
     }
     CakePlugin::routes();
 }