/**
  * Handles current transaction
  *
  * @param CakeEvent $event Dispatch event
  * @return true
  */
 public function beforeDispatch(CakeEvent $event)
 {
     $request = $event->data['request'];
     $response = $event->data['response'];
     if (!$this->hasNewRelic()) {
         return true;
     }
     // Set NewRelic appName
     $appName = Configure::read('NewRelic.appName');
     if (!empty($appName)) {
         $this->setAppName($appName);
     }
     $ignored = Configure::read('NewRelic.ignoreRoutes');
     $url = '/' . $event->data['request']->url;
     if (!empty($ignored)) {
         foreach ($ignored as $ignoreTest) {
             $cakeRoute = new CakeRoute($ignoreTest);
             if ($cakeRoute->parse($url) !== false) {
                 $this->ignoreTransaction();
                 continue;
             }
         }
     }
     $this->nameTransaction($request->controller . '/' . $request->action);
     return true;
 }
 /**
  * Checks to see if the given URL can be parsed by this route.
  * If the route can be parsed an array of parameters will be returned; if
  * not `false` will be returned.
  *
  * @param string $url The url to attempt to parse.
  * @return mixed Boolean false on failure, otherwise an array or parameters
  */
 public function parse($url)
 {
     $conditionResult = $callbackFunction = null;
     if (isset($this->options['condition'])) {
         $conditionFunctions = !is_array($this->options['condition']) ? array($this->options['condition']) : $this->options['condition'];
         foreach ($conditionFunctions as $conditionFunction) {
             $tempResult = call_user_func($conditionFunction, $url, $this);
             if ($tempResult == false) {
                 $conditionResult = false;
                 break;
             }
         }
     }
     if (isset($this->options['callback']) && is_callable($this->options['callback'])) {
         $callbackFunction = $this->options['callback'];
         unset($this->options['callback']);
     }
     $params = parent::parse($url);
     if (!$params) {
         return false;
     }
     if ($conditionResult === false) {
         return false;
     }
     if (!is_null($callbackFunction)) {
         $params = call_user_func($callbackFunction, $params);
     }
     return $params;
 }
Example #3
0
 public function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     $path = realpath(implode(DS, $params['pass']));
     if (empty($path)) {
         return false;
     }
     $thumb = str_replace(array('/', '\\', '\\\\'), DS, WWW_ROOT . $url);
     $config = realpath(APP . 'Config/thumbs.php') ? include realpath(APP . 'Config/thumbs.php') : (include realpath(APP . 'Plugin/Thumbs/Config/thumbs.php'));
     switch ($params['action']) {
         case "crop":
             $image = $this->_crop($config, $path, $params, $thumb);
             break;
         case "resize":
             $image = $this->_resize($config, $path, $params, $thumb);
             break;
         case "fill":
             $image = $this->_fill($config, $path, $params, $thumb);
             break;
     }
     if (empty($image)) {
         return false;
     }
     $params['image'] = $image;
     return $params;
 }
 /**
  * Parses a string url into an array. Parsed urls will result in an automatic
  * redirection
  *
  * @param string $url The url to parse
  * @return boolean False on failure
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (!$params) {
         return false;
     }
     if (!$this->response) {
         $this->response = new CakeResponse();
     }
     $redirect = $this->defaults;
     if (count($this->defaults) == 1 && !isset($this->defaults['controller'])) {
         $redirect = $this->defaults[0];
     }
     if (isset($this->options['persist']) && is_array($redirect)) {
         $argOptions['context'] = array('action' => $redirect['action'], 'controller' => $redirect['controller']);
         $args = Router::getArgs($params['_args_'], $argOptions);
         $redirect += $args['pass'];
         $redirect += $args['named'];
     }
     $status = 301;
     if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) {
         $status = $this->options['status'];
     }
     $this->response->header(array('Location' => Router::url($redirect, true)));
     $this->response->statusCode($status);
     $this->response->send();
 }
Example #5
0
 /**
  * Parses a string url into an array. Parsed urls will result in an automatic
  * redirection
  *
  * @param string $url The url to parse
  * @return boolean False on failure
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if ($params === false) {
         return false;
     }
     $Domains = new Domains();
     $subdomain = $Domains->getSubdomain();
     $masterDomain = Configure::read('Domain.Master');
     $defaultRoute = Configure::read('Domain.DefaultRoute');
     $Tenant = new Tenant();
     if (!$Tenant->domainExists($subdomain) && $params != $defaultRoute) {
         if (!$this->response) {
             $this->response = new CakeResponse();
         }
         debug($this->response);
         die;
         $status = 307;
         $redirect = $defaultRoute;
         $this->response->header(array('Location' => Router::url($redirect, true)));
         $this->response->statusCode($status);
         $this->response->send();
         $this->_stop();
     }
     return $subdomain;
 }
Example #6
0
 /**
  * Override the parsing function to find an id based on a slug
  *
  * @param string $url Url string
  * @return boolean
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     if (!empty($this->models) && !empty($params['pass'])) {
         foreach ($this->models as $modelName => $options) {
             list($paramType, $paramName) = $this->params($options);
             $slugSet = $this->getSlugs($modelName);
             if (empty($slugSet)) {
                 continue;
             }
             $slugSet = array_flip($slugSet);
             foreach ($params['pass'] as $key => $param) {
                 if (isset($slugSet[$param])) {
                     unset($params['pass'][$key]);
                     if ($paramType == 'pass' && !is_numeric($paramName)) {
                         $params[$paramName] = $slugSet[$param];
                         $params[$paramType][$key] = $slugSet[$param];
                     } else {
                         $params[$paramType][$paramName] = $slugSet[$param];
                     }
                 }
             }
         }
         return $params;
     }
     return false;
 }
Example #7
0
 /**
  * Override the parsing function to find an id based on a slug
  *
  * @param string $url Url string
  * @return boolean
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     if (isset($this->options['models']) && !empty($params['pass'])) {
         foreach ($this->options['models'] as $checkNamed => $slugField) {
             if (is_numeric($checkNamed)) {
                 $checkNamed = $slugField;
                 $slugField = null;
             }
             $slugSet = $this->getSlugs($checkNamed, $slugField);
             if (empty($slugSet)) {
                 continue;
             }
             $slugSet = array_flip($slugSet);
             foreach ($params['pass'] as $key => $pass) {
                 if (isset($slugSet[$pass])) {
                     unset($params['pass'][$key]);
                     $params['named'][$checkNamed] = $slugSet[$pass];
                 }
             }
         }
         return $params;
     }
     return false;
 }
 /**
  * Parses a string url into an array. Parsed urls will result in an automatic
  * redirection
  *
  * @param string $url The url to parse
  * @return boolean False on failure
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (!$params) {
         return false;
     }
     if (!$this->response) {
         $this->response = new CakeResponse();
     }
     $redirect = $this->redirect;
     if (count($this->redirect) == 1 && !isset($this->redirect['controller'])) {
         $redirect = $this->redirect[0];
     }
     if (isset($this->options['persist']) && is_array($redirect)) {
         $redirect += array('named' => $params['named'], 'pass' => $params['pass'], 'url' => array());
         $redirect = Router::reverse($redirect);
     }
     $status = 301;
     if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) {
         $status = $this->options['status'];
     }
     $this->response->header(array('Location' => Router::url($redirect, true)));
     $this->response->statusCode($status);
     $this->response->send();
     $this->_stop();
 }
 public function parse($url)
 {
     if (defined('MYDOMAIN')) {
         $subdomain = substr(env("HTTP_HOST"), 0, strpos(env("HTTP_HOST"), "." . MYDOMAIN));
         $url = '/' . $subdomain . $url;
     }
     return $subdomain == 'www' ? false : parent::parse($url);
 }
Example #10
0
 public function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     return false;
 }
Example #11
0
/**
 * Parses a string URL into an array. If a plugin key is found, it will be copied to the
 * controller parameter
 *
 * @param string $url The URL to parse
 * @return mixed false on failure, or an array of request parameters
 */
	public function parse($url) {
		$params = parent::parse($url);
		if (!$params) {
			return false;
		}
		$params['controller'] = $params['plugin'];
		return $params;
	}
Example #12
0
 /**
  * Checks wether URL is an API route
  *
  * If the route is not an API route, we return false and let the next parser
  * to handle it.
  *
  * @param string $url The URL to attempt to parse.
  * @return mixed Boolean false on failure, otherwise an array or parameters
  * @see CakeRoute::parse()
  */
 public function parse($url)
 {
     $parsed = parent::parse($url);
     if (!isset($parsed['api']) || !isset($parsed['prefix'])) {
         return false;
     }
     $parsed['prefix'] = str_replace('.', '_', $parsed['prefix']);
     return $parsed;
 }
Example #13
0
 public function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     //break up the url into pieces
     $parsed_url = parse_url($_SERVER['REQUEST_URI']);
     $url_p = explode("/", $parsed_url['path']);
     die(print_r($params));
     return false;
 }
Example #14
0
 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;
 }
Example #15
0
 function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     App::import('Component', 'Session');
     $Session = new SessionComponent();
     if ($Session->check('Auth.User.slug')) {
         return $params;
     }
     return false;
 }
Example #16
0
 function parse($url)
 {
     // import the session controller so we can check if they're logged in or not
     App::import('Component', 'Session');
     $Session = new SessionComponent();
     // check the login
     if ($Session->check('Auth.User.email')) {
         // logged in, parse params and return
         return parent::parse($url);
     } else {
         // not logge in, return false
         return false;
     }
 }
Example #17
0
 public function parse($url)
 {
     $params = parent::parse($url);
     App::import("Model", "Dailyop");
     $Dailyop = new Dailyop();
     if (count($params['pass']) <= 0 && !isset($params['named']['datein'])) {
         //$params['named']['datein'] = $Dailyop->getNewsDate();
         //return $params;
     }
     if (isset($params['named']['datein']) && !preg_match('/([0-9]{4})(\\-)([0-9]{2})(\\-)([0-9]{2})/', $params['named']['datein'])) {
         throw new NotFoundException("Invalid News Date");
     }
     //validate the date
     //$params['named']['datein'] = $Dailyop->validateNewsDateRoute($params['named']['datein']);
     return $params;
 }
Example #18
0
 function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     $this->Tutorial = ClassRegistry::init('Tutorial');
     $tutorial = $this->Tutorial->find('first', array('conditions' => array('Tutorial.user_url' => $params['slug']), 'recursive' => -1));
     if (!empty($tutorial)) {
         $params['pass'][] = $tutorial['Tutorial']['id'];
         return $params;
     } else {
         return false;
     }
     return false;
 }
 /**
  * Parses a string url into an array.  If a page is found, it is parsed into
  * the pass key in the route params
  *
  * @param string $url The url to parse
  * @return mixed false on failure, or an array of request parameters
  */
 function parse($url)
 {
     $params = parent::parse($url);
     if (!$params || empty($params['page'])) {
         return false;
     }
     $path = trim(str_replace('//', '', (string) $params['page']), '/');
     if (!file_exists(APP . 'View' . DS . $this->options['controller'] . DS . $path . '.ctp')) {
         return false;
     }
     $params['pass'] = Sanitize::clean(explode('/', $path));
     $params['controller'] = $this->options['controller'];
     $params['action'] = $this->options['action'];
     $params['plugin'] = null;
     unset($params['page']);
     return $params;
 }
 /**
  * Custom Route parsing for SimplePages URL
  * 
  * @param string $url URL to parse
  */
 function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     $slugs = Cache::read('simple_page_slugs');
     if (empty($slugs)) {
         App::import('Model', 'SimplePages.SimplePage');
         $SimplePage = new SimplePage();
         $slugs = $SimplePage->cacheSlugs();
     }
     if (isset($params['slug']) && in_array($params['slug'], $slugs)) {
         return $params;
     }
     return false;
 }
Example #21
0
 public function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     $params['controller'] = "dailyops";
     $params['action'] = "index";
     $date_in = date("Y-m-d");
     if (isset($params['year']) && isset($params['month']) && isset($params['day']) && (strtotime("{$params['year']}-{$params['month']}-{$params['day']}") < time() || isset($_GET['showall']) && preg_match('/(dev\\.|v3\\.)/', $_SERVER['HTTP_HOST']))) {
         $date_in = $params['dateIn'] = "{$params['year']}-{$params['month']}-{$params['day']}";
         $params['action'] = "archive";
     }
     switch ($date_in) {
         case "2013-08-17":
         case "2013-08-18":
             if (in_array(date("Y-m-d"), array("2013-08-17", "2013-08-18"))) {
                 $params['controller'] = "run_and_gun";
                 $params['action'] = "dailyops";
             }
             break;
         case "2013-05-21":
             if (in_array(date("Y-m-d"), array("2013-05-21"))) {
                 $params['controller'] = "bon_voyage";
                 $params['action'] = "view";
             }
             break;
         case "2013-07-07":
         case "2013-07-06":
             if (in_array(date("Y-m-d"), array("2013-07-06", "2013-07-07"))) {
                 $params['controller'] = "element_hold_it_down";
                 $params['action'] = "section";
             }
             break;
         case "2013-04-30":
             if (in_array(date("Y-m-d"), array("2013-04-30"))) {
                 $params['controller'] = "deathwish_video";
                 $params['action'] = "section";
             }
             break;
     }
     return $params;
 }
Example #22
0
 function parse($url)
 {
     return parent::parse($url);
     echo $url;
     debug(parent::parse($url));
     // lista de locales em config/locales.php
     $locales = array_keys(Configure::read('Locales.list'));
     // checando se a url atual possui locale
     $url_exploded = explode('/', $url);
     //limpa indices vazios
     for ($i = 0, $l = count($url_exploded); $i < $l; $i++) {
         if (!strlen($url_exploded[$i])) {
             unset($url_exploded[$i]);
         }
     }
     $url_exploded = array_values($url_exploded);
     $url_locale = $url_exploded[0];
     $matched = false;
     foreach ($locales as $locale) {
         if ($url_locale == $locale) {
             $matched = true;
             break;
         }
     }
     // se encontrou o locale na url, entao remonta ela com language:locale
     if ($matched) {
         unset($url_exploded[0]);
         $url_exploded[] = 'language:' . $locale;
         $url = '/' . implode('/', $url_exploded) . '/';
         debug($url);
     }
     $params = parent::parse($url);
     debug($params);
     die;
     if (empty($params)) {
         return false;
     }
     if ($count) {
         return $params;
     }
     return false;
 }
Example #23
0
 public function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     App::import("Model", "DailyopSection");
     $sec = new DailyopSection();
     $sections = $sec->returnSections();
     $token = Set::extract("/DailyopSection[uri=" . $params['section'] . "]", $sections);
     if (isset($token[0]['DailyopSection']['uri'])) {
         //check to see if we can find the post, and if so, then cache that shit so we can posible use it in the dailyops controller and change the action to view
         if (!empty($params['uri'])) {
             //load up the daily ops model
             App::import("Model", "Dailyop");
             $dop = new Dailyop();
             $slug = md5($_SERVER['REQUEST_URI']);
             //hack it so the router thinks we are admin on dev server;
             //this will allow the router to pass in unpublished posts;
             //auth control will be handled by the controller
             if (!isset($_SERVER['DEVSERVER'])) {
                 $_SERVER['DEVSERVER'] = 0;
             }
             $post = $dop->returnPost(array("Dailyop.uri" => $params['uri'], "DailyopSection.uri" => $params['section']), $_SERVER['DEVSERVER']);
             if (isset($post['Dailyop']['id'])) {
                 $params['action'] = "view";
             } else {
                 if (!empty($params['uri'])) {
                     $params['action'] = $params['uri'];
                 }
             }
         }
         //check the directive
         if (!empty($token[0]['DailyopSection']['directive'])) {
             $params['controller'] = $token[0]['DailyopSection']['directive'];
         } else {
             $params['controller'] = "dailyops";
         }
         return $params;
     }
     return false;
 }
Example #24
0
 public function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     Configure::load('prefecture');
     Configure::load('city');
     $prefectures = Configure::read('prefecture');
     $cities = Configure::read('city');
     if (in_array($params['prefecture'], $prefectures)) {
         if (isset($params['city'])) {
             if (in_array($params['city'], $cities)) {
                 return $params;
             }
             return false;
         }
         return $params;
     }
     return false;
 }
Example #25
0
 function parse($url)
 {
     $params = parent::parse($url);
     //debug($params);
     if (empty($params)) {
         //echo 'billnn1';
         return false;
     } else {
         //debug($params);
     }
     App::import('Model', 'User');
     $Post = new User();
     $count = $Post->find('count', array('conditions' => array('User.username' => $params['uname']), 'recursive' => -1));
     if ($count) {
         //debug($params);
         return $params;
     } else {
         //echo 'blinnn2';
     }
     //echo 'false';
     return false;
 }
 public function parse($url)
 {
     /*
      * parse url
      */
     $params = parent::parse($url);
     if (!$params || empty($params)) {
         return false;
     }
     //get all registered modules
     $registeredModules = Configure::read('Cloggy.modules');
     /*
      * only active at module request
      */
     if (isset($params['name'])) {
         /*
          * setup module name
          */
         $moduleName = Inflector::variable($params['name']);
         $moduleName = ucfirst($moduleName);
         /*
          * check if requested module listed on registered modules
          */
         if (!in_array($moduleName, $registeredModules)) {
             return false;
         } else {
             /*
              * if empty controller it means go to module home controller
              */
             if (!isset($params['controller']) || empty($params['controller'])) {
                 $params['controller'] = $params['name'] . '_home';
             }
             //set flag that current request is module base
             $params['isCloggyModule'] = 1;
         }
     }
     return $params;
 }
Example #27
0
 function parse($url)
 {
     $params = parent::parse($url);
     if (isset($params['slug'])) {
         $username = $params['slug'];
         App::import("Component", "Users.ControllerList");
         $contList = new ControllerListComponent(new ComponentCollection());
         $conts = $contList->getControllers();
         unset($conts[-2]);
         unset($conts[-1]);
         $conts = array_map('strtolower', $conts);
         $usernameTmp = strtolower(str_replace(' ', '', ucwords(str_replace('_', ' ', $username))));
         if (!in_array($usernameTmp, $conts)) {
             $plugins = App::objects('plugins');
             $plugins = array_map('strtolower', $plugins);
             if (in_array($usernameTmp, $plugins)) {
                 return false;
             }
             $customRoutes = Router::$routes;
             $usernameTmp = '/' . $username;
             foreach ($customRoutes as $customRoute) {
                 if (strpos(strtolower($customRoute->template), strtolower($usernameTmp)) !== false) {
                     return false;
                 }
             }
             App::import("Model", "Users.User");
             $userModel = new User();
             $isUser = $userModel->findByUsername($params['slug']);
             if ($isUser) {
                 $params['pass'][0] = $params['slug'];
                 return $params;
             }
         }
         return false;
     }
     return false;
 }
Example #28
0
 /**
  * Test the /** special type on parsing - UTF8.
  *
  * @return void
  */
 public function testParseTrailingUTF8()
 {
     $route = new CakeRoute('/category/**', array('controller' => 'categories', 'action' => 'index'));
     $result = $route->parse('/category/%D9%85%D9%88%D8%A8%D8%A7%DB%8C%D9%84');
     $expected = array('controller' => 'categories', 'action' => 'index', 'pass' => array('موبایل'), 'named' => array());
     $this->assertEquals($expected, $result);
 }
Example #29
0
 /**
  * test that utf-8 patterns work for :section
  *
  * @return void
  */
 public function testUTF8PatternOnSection()
 {
     $route = new CakeRoute('/:section', array('plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index'), array('persist' => array('section'), 'section' => 'آموزش|weblog'));
     $result = $route->parse('/%D8%A2%D9%85%D9%88%D8%B2%D8%B4');
     $expected = array('section' => 'آموزش', 'plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index', 'pass' => array(), 'named' => array());
     $this->assertEquals($expected, $result);
     $result = $route->parse('/weblog');
     $expected = array('section' => 'weblog', 'plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index', 'pass' => array(), 'named' => array());
     $this->assertEquals($expected, $result);
 }
Example #30
0
 /**
  * Testing that patterns on the :action param work properly.
  *
  * @return void
  */
 public function testPatternOnAction()
 {
     $route = new CakeRoute('/blog/:action/*', array('controller' => 'blog_posts'), array('action' => 'other|actions'));
     $result = $route->match(array('controller' => 'blog_posts', 'action' => 'foo'));
     $this->assertFalse($result);
     $result = $route->match(array('controller' => 'blog_posts', 'action' => 'actions'));
     $this->assertEquals('/blog/actions/', $result);
     $result = $route->parse('/blog/other');
     $expected = array('controller' => 'blog_posts', 'action' => 'other', 'pass' => array(), 'named' => array());
     $this->assertEquals($expected, $result);
     $result = $route->parse('/blog/foobar');
     $this->assertFalse($result);
 }