Example #1
0
 public function routeStartup(Zend_Controller_Request_Abstract $request)
 {
     if (!$this->_issession) {
         $front = Zend_Controller_Front::getInstance();
         $router = $front->getRouter();
         if ($this->_domain) {
             $doms = $this->_model->fetchPairs('id', 'domain');
             if ($doms) {
                 foreach ($doms as $k => $el) {
                     $doms[$k] = @$el[0] ? explode(' ', $el) : array();
                 }
             }
             $lang = $request->getParam('lang');
             if ($lang) {
                 $this->_session->lang = $this->_model->fetchOne('id', array('`stitle` = ?' => $lang));
             } else {
                 if ($doms) {
                     foreach ($doms as $k => $el) {
                         if (in_array($_SERVER['HTTP_HOST'], $el)) {
                             $this->_session->lang = $k;
                             break;
                         }
                     }
                 }
             }
             $this->_lang = $this->_model->fetchRow(null, '(`id` = ' . (int) $this->_session->lang . ') DESC, (`default` = 1) DESC');
             if ($this->_lang) {
                 $this->_lang = new Zkernel_View_Data($this->_lang);
             }
             $this->_lang->_default = $this->getDefault();
             $this->_lang->_ids = $this->_model->fetchIds();
             $this->_lang->_doms = $doms;
         } else {
             $routes = $router->getRoutes();
             $router->removeDefaultRoutes();
             if ($routes) {
                 foreach ($routes as $k => $el) {
                     $router->removeRoute($k);
                 }
             }
             $langRoute = new Zend_Controller_Router_Route(':lang', array('lang' => $this->getDefault()->stitle));
             $router->addRoute('default', $langRoute->chain(new Zend_Controller_Router_Route_Module(array(), $front->getDispatcher(), $front->getRequest())));
             $router->addRoute('lang', $langRoute);
             if ($routes) {
                 foreach ($routes as $k => $el) {
                     $router->addRoute($k, $k == 'fu' || $k == 'minify' ? $el : $langRoute->chain($el));
                 }
             }
         }
     }
     $this->save();
 }
Example #2
0
 /**
  * Attempt to match the current request URL
  * If a match is found, instantiate a new ImboClient
  *
  * @see Zend_Controller_Router_Route::match()
  */
 public function match($path, $partial = false)
 {
     $match = parent::match($path, $partial);
     $config = array();
     $instance = false;
     $imgUrl = '';
     if ($match) {
         $instance = $match['instance'];
         // Check if the passed instance exists
         if (!isset($this->instances[$instance])) {
             throw new Zend_Controller_Router_Exception('Instance "' . $instance . '" does not exist in configuration', 404);
         }
         // If this is not a sub-action, check if this is an XMLHttpRequest
         if ($match['controller'] != 'instance' && (!isset($_SERVER['X_REQUESTED_WITH']) || $_SERVER['X_REQUESTED_WITH'] != 'XMLHttpRequest')) {
             $match['controller'] = 'instance';
             $match['action'] = 'index';
         }
         // Create an imbo client for the given instance and make it available in request
         $config = $this->instances[$instance];
         $match['imboClient'] = new ImboClient\Client($config['host'], $config['pubkey'], $config['privkey']);
         $imgUrl = $match['imboClient']->getImagesUrl();
     }
     // Set active instance name to view so we may use it in frontend
     $frontController = Zend_Controller_Front::getInstance();
     $view = $frontController->getParam('bootstrap')->getResource('view');
     $view->activeInstance = $instance;
     $view->imagesUrl = $imgUrl;
     $view->maxUploadSize = $this->getMaxUploadSize($config);
     return $match;
 }
Example #3
0
 /**
  * Matches a user submitted path with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param  string      $path Path used to match against this routing map
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($request, $partial = false)
 {
     if (!$request instanceof \Zend_Controller_Request_Http) {
         throw new \Zend_Controller_Router_Exception("Route needs a http request");
     }
     $return = parent::match($request->getPathInfo(), $partial);
     if (!$return) {
         return $return;
     }
     if (!($token = $return[$this->_tokenVariable])) {
         throw new \Zend_Controller_Router_Exception("Token not defined", 400);
     }
     if (!($tokenData = \Download\Service\DownloadTokenService::getInstance()->popToken($token))) {
         throw new \Zend_Controller_Router_Exception("Token does not exist or has expired", 400);
     }
     $return = array_merge($return, $tokenData->exportData());
     $return['downloadToken'] = $tokenData;
     $return['module'] = 'download';
     //Data defined inside token
     $return['controller'] = $tokenData->controller;
     $return['action'] = $tokenData->action;
     if (is_array($tokenData->params)) {
         $return += $tokenData->params;
     }
     return $return;
 }
Example #4
0
 public function __construct()
 {
     /* Informações */
     $route = $this->getRoute();
     $defaults = $this->getDefaults();
     /* Construtor */
     parent::__construct($route, $defaults);
 }
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     $language = $request->getParam("language", Zend_Registry::get('Zend_Locale')->getLanguage());
     $locale = new Zend_Locale($language);
     Zend_Registry::get('Zend_Locale')->setLocale($locale);
     $translate = Zend_Registry::get('Zend_Translate');
     $translate->getAdapter()->setLocale(Zend_Registry::get('Zend_Locale'));
     Zend_Controller_Router_Route::setDefaultTranslator($translate);
 }
Example #6
0
 /**
  * Defined by Zend_Application_Resource_Resource
  *
  * @return Zend_Controller_Router_Rewrite
  */
 public function init()
 {
     if (null === $this->_router) {
         $router = $this->getRouter();
         // returns $this->_router
         $router->addConfig($this->_getConfig());
         // add locale chain if using translate
         if ($this->getBootstrap()->hasPluginResource('Translate')) {
             $locale = new Zend_Controller_Router_Route(':locale', array(), array('locale' => '^[a-z]{2}$'));
             $router->addDefaultRoutes();
             foreach ($router->getRoutes() as $name => $route) {
                 //rename existing routes
                 $router->removeRoute($name)->addRoute($name . 'Default', $route)->addRoute($name, $locale->chain($route));
             }
         }
     }
     return $this->_router;
 }
Example #7
0
 public function assemble($data = array(), $reset = false, $encode = false)
 {
     $return = parent::assemble($data, $reset, $encode);
     if ($this->_representationParam !== null) {
         if ($return && isset($data[$this->_representationParam])) {
             $return .= '.' . $data[$this->_representationParam];
         }
     }
     return $return;
 }
Example #8
0
 /**
  * Matches a user submitted path with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param string $path Path used to match against this routing map
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($path, $partial = false)
 {
     $return = parent::match($path, $partial);
     // add the RESTful action mapping
     if ($return) {
         //add the data that is a wildcard to the end of the return array
         $path = trim($path, self::URI_DELIMITER);
         $this->_route = trim($this->_route, self::URI_DELIMITER);
         if ($path != '') {
             $elementsPath = explode(self::URI_DELIMITER, $path);
         }
         if ($this->_route != '') {
             $elementsRoute = explode(self::URI_DELIMITER, $this->_route);
         }
         //and now get rid of all entries that are not a wildcard. when we have done that,
         //we have what we wanted...
         foreach ($elementsRoute as $key => $value) {
             if ($value !== "*") {
                 array_shift($elementsPath);
             } else {
                 break;
             }
         }
         $i = 0;
         foreach ($elementsPath as $value) {
             $return['wild' . $i] = $value;
             $i++;
         }
         //reset things
         $request = $this->_front->getRequest();
         $params = $request->getParams();
         $path = $elementsPath;
         //Store path count for method mapping
         $pathElementCount = count($path);
         // Determine Action
         $requestMethod = strtolower($request->getMethod());
         if ($requestMethod != 'get') {
             if ($request->getParam('_method')) {
                 $return[$this->_actionKey] = strtolower($request->getParam('_method'));
             } elseif ($request->getHeader('X-HTTP-Method-Override')) {
                 $return[$this->_actionKey] = strtolower($request->getHeader('X-HTTP-Method-Override'));
             } else {
                 $return[$this->_actionKey] = $requestMethod;
             }
         } else {
             // this is only an index call, if no options are acutally provided
             if ($pathElementCount > 0) {
                 $return[$this->_actionKey] = 'get';
             } else {
                 $return[$this->_actionKey] = 'index';
             }
         }
     }
     return $return;
 }
Example #9
0
 /**
  * Matches a user submitted path with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param string $path Path used to match against this routing map
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($path, $partial = false)
 {
     $params = parent::match($path, $partial);
     if (!empty($params['controller']) && 'Axis_Admin' !== $params['module']) {
         $params['controller'] = 'admin_' . $params['controller'];
     }
     if ($params) {
         Axis_Area::backend();
     }
     return $params;
 }
Example #10
0
 /**
  * Routes initialization
  *
  * @return Zend_Controller_Router
  */
 protected function _initRoutes()
 {
     $this->bootstrapOptions();
     $router = new \Zend_Controller_Router_Rewrite();
     foreach (\NS\Service\AbstractService::getConfig() as $module => $config) {
         if ($config->routes) {
             foreach ($config->routes as $r => $routeConfig) {
                 $router->addRoute($module . '_' . $r, \Zend_Controller_Router_Route::getInstance($routeConfig));
             }
         }
     }
     \Zend_Controller_Front::getInstance()->setRouter($router);
     return $router;
 }
 /**
  * Matches a user submitted path with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param string $path Path used to match against this routing map
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($path, $partial = false)
 {
     $return = parent::match($path, $partial);
     // add the RESTful action mapping
     if ($return) {
         $request = $this->_front->getRequest();
         $path = $request->getPathInfo();
         $params = $request->getParams();
         $path = trim($path, self::URI_DELIMITER);
         if ($path != '') {
             $path = explode(self::URI_DELIMITER, $path);
         }
         //Store path count for method mapping
         $pathElementCount = count($path);
         // Determine Action
         $requestMethod = strtolower($request->getMethod());
         if ($requestMethod != 'get') {
             if ($request->getParam('_method')) {
                 $return[$this->_actionKey] = strtolower($request->getParam('_method'));
             } elseif ($request->getHeader('X-HTTP-Method-Override')) {
                 $return[$this->_actionKey] = strtolower($request->getHeader('X-HTTP-Method-Override'));
             } else {
                 $return[$this->_actionKey] = $requestMethod;
             }
             // Map PUT and POST to actual create/update actions
             // based on parameter count (posting to resource or collection)
             switch ($return[$this->_actionKey]) {
                 case 'post':
                     if ($pathElementCount > 0) {
                         $return[$this->_actionKey] = 'put';
                     } else {
                         $return[$this->_actionKey] = 'post';
                     }
                     break;
                 case 'put':
                     $return[$this->_actionKey] = 'put';
                     break;
             }
         } else {
             // if the last argument in the path is a numeric value, consider this request a GET of an item
             $lastParam = array_pop($path);
             if (is_numeric($lastParam)) {
                 $return[$this->_actionKey] = 'get';
             } else {
                 $return[$this->_actionKey] = 'index';
             }
         }
     }
     return $return;
 }
Example #12
0
 public function testEscapedSpecialCharsWithTranslation()
 {
     $route = new Zend_Controller_Router_Route('::foo/@@bar/:@myvar');
     $path = $route->assemble(array('myvar' => 'foo'));
     $this->assertEquals($path, ':foo/@bar/en_foo');
     $values = $route->match(':foo/@bar/en_foo');
     $this->assertEquals($values['myvar'], 'foo');
 }
Example #13
0
    public function testAssembleWithRemovedDefaults() // Test for ZF-1197
    {    
        $route = new Zend_Controller_Router_Route(':controller/:action/*', array('controller' => 'index', 'action' => 'index'));
        
        $url = $route->assemble(array('id' => 3));
        $this->assertSame('index/index/id/3', $url);

        $url = $route->assemble(array('action' => 'test'));
        $this->assertSame('index/test', $url);

        $url = $route->assemble(array('action' => 'test', 'id' => 3));
        $this->assertSame('index/test/id/3', $url);

        $url = $route->assemble(array('controller' => 'test'));
        $this->assertSame('test', $url);

        $url = $route->assemble(array('controller' => 'test', 'action' => 'test'));
        $this->assertSame('test/test', $url);

        $url = $route->assemble(array('controller' => 'test', 'id' => 3));
        $this->assertSame('test/index/id/3', $url);

        $url = $route->assemble(array());
        $this->assertSame('', $url);

        $route->match('ctrl');

        $url = $route->assemble(array('id' => 3));
        $this->assertSame('ctrl/index/id/3', $url);

        $url = $route->assemble(array('action' => 'test'));
        $this->assertSame('ctrl/test', $url);

        $url = $route->assemble();
        $this->assertSame('ctrl', $url);
        
        $route->match('index');
        
        $url = $route->assemble();
        $this->assertSame('', $url);
    }
Example #14
0
 /**
  * Initializes translator
  *
  * @return Zend_Translate_Adapter
  */
 public function _initTranslate()
 {
     $log = new Zend_Log();
     if (APPLICATION_ENV == 'development') {
         $log = new Zend_Log();
         $log->addWriter(new Zend_Log_Writer_Firebug());
         //$log->addWriter(new Zend_Log_Writer_Stream(APPLICATION_PATH . '/temporary/log/translate.log'));
     } else {
         $log->addWriter(new Zend_Log_Writer_Null());
     }
     $params['log'] = $log;
     // Create the object and add a language
     $translate = new Zend_Translate('Array', APPLICATION_PATH . '/languages/vi/vi.php', 'vi_VN');
     // Add another translation
     $translate->addTranslation(APPLICATION_PATH . '/languages/en/en.php', 'en_US');
     // Set nb_NO as default translation
     $translate->setLocale('vi_VN');
     Zend_Registry::set('Zend_Translate', $translate);
     Zend_Validate_Abstract::setDefaultTranslator($translate);
     Zend_Form::setDefaultTranslator($translate);
     Zend_Controller_Router_Route::setDefaultTranslator($translate);
     return $translate;
 }
Example #15
0
 /**
  * Assembles user submitted parameters forming a URL path defined by this route
  *
  * We cannot generate http://subdomain.domain.com/ due to the fact
  * that the url helper adds the baseUrl in front of it... *sigh*
  * 
  * @todo figure out a workaround
  * 
  * @param  array $data An array of variable and value pairs used as parameters
  * @param  boolean $reset Whether or not to set route defaults with those provided in $data
  * @return string Route path with user submitted parameters
  */
 public function assemble($data = array(), $reset = false)
 {
     return parent::assemble($data, $reset);
 }
Example #16
0
<?php

$conf = Zend_Registry::get("conf");
try {
    // Translation
    $translateUrl = new Zend_Translate('gettext', APPLICATION_DIRECTORY . '/Joobsbox/Languages/' . $locale . '/LC_MESSAGES/url.mo', $locale, array('disableNotices' => true));
} catch (Exception $e) {
    $translateUrl = new Zend_Translate('gettext', APPLICATION_DIRECTORY . '/Joobsbox/Languages/en/LC_MESSAGES/url.mo', 'en');
}
Zend_Registry::set("Joobsbox_Translate_URL", $translateUrl);
Zend_Controller_Router_Route::setDefaultTranslator($translateUrl);
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$rssRoute = new Zend_Controller_Router_Route('rss/@category/:category', array('controller' => 'rss', 'action' => 'index'));
$mainRoute = new Zend_Controller_Router_Route(':@controller/:@action/*', array('controller' => 'index', 'action' => 'index'));
$mainRoute2 = new Zend_Controller_Router_Route('index.php/:@controller/:@action/*', array('controller' => 'index', 'action' => 'index'));
$router->addRoute("main", $mainRoute);
$router->addRoute("main2", $mainRoute2);
$router->addRoute("rss", $rssRoute);
$mainRoute->assemble(array());
$mainRoute->assemble(array());
$mainRoute2->assemble(array());
$mainRoute2->assemble(array());
$front->setRouter($router);
Example #17
0
 /**
  * Matches a user submitted path with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param string $path Path used to match against this routing map
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($path, $partial = false)
 {
     $params = array();
     $Mvc = new Phorm_Mvc();
     // Проверяем существование идентификатора материала в пути
     // @todo Сделать возможность конфигурирования паттернов урлов материалов
     if (preg_match("#^(/.*?)(/([а-яa-z0-9_-]+)\\.html)?\$#iu", $path, $pathinfo)) {
         // Если мы получили идентификатор материала, то устанавливаем CategoriesController
         if (isset($pathinfo[3])) {
             $params["module"] = "default";
             $params["controller"] = "categories";
             $params["action"] = "index";
             $params["resourceid"] = $pathinfo[3];
             $params["categorypath"] = $pathinfo[1] == "/" ? "/" : $pathinfo[1] . "/";
             $params["categorypath"] = $pathinfo[1] == "/" ? "/" : $pathinfo[1] . "/";
             // Иначе получаем модуль, контроллер и действие из родительского math
         } else {
             $params = parent::match($path, $partial);
             // Проверяем существование MVC-ресурса в базе
             if ($params['mvcinfo'] = $Mvc->getMvcInfo($params)) {
                 $params['WidgetSetId'] = $params['mvcinfo']['widgetssetid'];
                 //print_r($params);
                 return $params;
                 // Если MVC-ресурс не найден, то устанавливаем CategoriesController
             } else {
                 $params["module"] = "default";
                 $params["controller"] = "categories";
                 $params["action"] = "index";
                 $params["categorypath"] = preg_match("#/\$#", $pathinfo[1]) ? $pathinfo[1] : $pathinfo[1] . "/";
             }
         }
     }
     // После всех экзекуций у нас должны остаться только ресурсы для CategoriesControllerа
     $Categories = new Phorm_Categories();
     $Categories->setModule($params["module"]);
     // Проверяем существование раздела
     if ($CategoryInfo = $Categories->getCategoryInfoByPath($params["categorypath"])) {
         $params["categoryinfo"] = $CategoryInfo;
         $params["WidgetSetId"] = $CategoryInfo["widgetssetid"];
         // Если мы на главной странице раздела и есть материал для замещения, то переопределяем идентификатор материала
         if (!isset($params["resourceid"]) && $CategoryInfo["mainresourceid"] > 0) {
             $params["resourceid"] = $CategoryInfo["mainresourceid"];
         }
         // Проверяем существование материала в текущем разделе и модуле по его идентификатору
         if (isset($params["resourceid"])) {
             $Resource = new Phorm_Resource();
             $Resource->setModule($params["module"]);
             $options = array("categoryid" => $CategoryInfo["categoryid"], "moduleid" => $CategoryInfo["moduleid"]);
             if ($ResourceInfo = $Resource->getResourceInfo($params["resourceid"], $options)) {
                 $params["module"] = "default";
                 $params["controller"] = $CategoryInfo["modulecontroller"];
                 $params["action"] = "view";
                 $params["resourceinfo"] = $ResourceInfo;
                 $params["mvcinfo"] = $Mvc->getMvcInfo($params);
                 $params["WidgetSetId"] = $ResourceInfo["widgetssetid"];
                 //print_r($params);
                 return $params;
             }
         } else {
             $params["mvcinfo"] = $Mvc->getMvcInfo($params);
             //print_r($params);
             return $params;
         }
     }
     // Все, что не смогло вернуться выше, попадает в ErrorController notfoundAction
     $params["module"] = "default";
     $params["controller"] = "error";
     $params["action"] = "notfound";
     $params["mvcinfo"] = $Mvc->getMvcInfo($params);
     $params["WidgetSetId"] = $params["mvcinfo"]["widgetssetid"];
     return $params;
 }
Example #18
0
 /**
  * Assembles user submitted parameters forming a URL path defined by this route
  *
  * @param  array $data An array of variable and value pairs used as parameters
  * @param  boolean $reset Whether or not to set route defaults with those provided in $data
  * @return string Route path with user submitted parameters
  */
 public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
 {
     if (!isset($data['locale'])) {
         return parent::assemble($data, $reset, $encode, $partial);
     }
     $locale = $data['locale'];
     unset($data['locale']);
     $assemble = parent::assemble($data, $reset, $encode);
     if (in_array($locale, self::$_locales)) {
         if (isset($this->_defaults['locale'])) {
             $defaultLocale = $this->_defaults['locale'];
         } else {
             $defaultLocale = self::$_defaultLocale;
         }
         if ($locale != $defaultLocale) {
             $assemble = implode($this->_urlDelimiter, array($locale, $assemble));
         }
     }
     return $assemble;
 }
 /**
  * @group ZF-10964
  */
 public function test_RESTfulApp_route_chaining_urlencodedWithPlusSymbol()
 {
     $request = $this->_buildRequest('GET', '/api/user/email%2Btest%40example.com');
     $this->_front->setRequest($request);
     $router = $this->_front->getRouter();
     $router->removeDefaultRoutes();
     $nonRESTRoute = new Zend_Controller_Router_Route('api');
     $RESTRoute = new Zend_Rest_Route($this->_front);
     $router->addRoute("api", $nonRESTRoute->chain($RESTRoute));
     $routedRequest = $router->route($request);
     $this->assertEquals("default", $routedRequest->getParam("module"));
     $this->assertEquals("user", $routedRequest->getParam("controller"));
     $this->assertEquals("get", $routedRequest->getParam("action"));
     $this->assertEquals("*****@*****.**", $routedRequest->getParam("id"));
 }
Example #20
0
 /**
  * Initializes translator
  *
  * @return Zend_Translate_Adapter
  */
 public function _initTranslate()
 {
     // Set cache
     if (isset($this->getContainer()->cache)) {
         Zend_Translate::setCache($this->getContainer()->cache);
     }
     // Get list of supported languages
     /*
     $languages = array();
     $it = new DirectoryIterator(APPLICATION_PATH_COR . DIRECTORY_SEPARATOR . 'languages');
     foreach( $it as $item ) {
       if( $item->isDot() || !$item->isDir() ) {
         continue;
       }
       $name = $item->getBasename();
       if( !Zend_Locale::isLocale($name) ) {
         continue;
       }
       $languages[] = $name;
     }
     */
     // If in development, log untranslated messages
     $params = array('scan' => Zend_Translate_Adapter::LOCALE_DIRECTORY, 'logUntranslated' => true);
     $log = new Zend_Log();
     if (APPLICATION_ENV == 'development') {
         $log = new Zend_Log();
         $log->addWriter(new Zend_Log_Writer_Firebug());
         $log->addWriter(new Zend_Log_Writer_Stream(APPLICATION_PATH . '/temporary/log/translate.log'));
     } else {
         $log->addWriter(new Zend_Log_Writer_Null());
     }
     $params['log'] = $log;
     // Check Locale
     $locale = Zend_Locale::findLocale();
     // Make Sure Language Folder Exist
     $languageFolder = is_dir(APPLICATION_PATH . '/application/languages/' . $locale);
     if ($languageFolder === false) {
         $locale = substr($locale, 0, 2);
         $languageFolder = is_dir(APPLICATION_PATH . '/application/languages/' . $locale);
         if ($languageFolder == false) {
             $locale = 'en';
         }
     }
     // Check which Translation Adapter has been selected
     $db = Engine_Db_Table::getDefaultAdapter();
     $translationAdapter = $db->select()->from('engine4_core_settings', 'value')->where('`name` = ?', 'core.translate.adapter')->query()->fetchColumn();
     // If adapter is 'array', Make sure array files exist
     /*
     if( $translationAdapter == 'array'){
       // Check if Language File Exists
       if( !file_exists(APPLICATION_PATH . '/application/languages/' . $locale . '/' . $locale . '.php')){
         //echo 'Locale does not exist ' . APPLICATION_PATH . '/application/languages/' . $locale . '/' . $locale . '_array.php<br />';
         // Try looking elsewhere
         $newLocale = substr($locale, 0, 2);
         //echo 'Attempting to Look for ' . $newLocale . '<br />';
         if( file_exists(APPLICATION_PATH . '/application/languages/' . $newLocale . '/' . $newLocale . '.php')){
           $locale = $newLocale;
           //echo 'New Locale Found ' . APPLICATION_PATH . '/application/languages/' . $newLocale . '/' . $newLocale . '_array.php<br />';          
         } else { $translationAdapter = 'csv'; $locale = 'en'; }
       }
     }   
     */
     // Use Array Translation Adapter, Loop through all Availible Translations
     if ($translationAdapter == 'array') {
         // Find all Valid Language Arrays
         // Check For Array Files
         $languagePath = APPLICATION_PATH . '/application/languages';
         // Get List of Folders
         $languageFolders = array_filter(glob($languagePath . DIRECTORY_SEPARATOR . '*'), 'is_dir');
         // Look inside Folders for PHP array
         $locale_array = array();
         foreach ($languageFolders as $folder) {
             // Get Locale code
             $locale_code = str_replace($languagePath . DIRECTORY_SEPARATOR, "", $folder);
             $locale_array[] = $locale_code;
             if (!file_exists($folder . DIRECTORY_SEPARATOR . $locale_code . '.php')) {
                 // If Array files do not exist, switch to CSV
                 $translationAdapter = 'csv';
             }
         }
         $language_count = count($locale_array);
         // Add the First One
         $translate = new Zend_Translate(array('adapter' => 'array', 'content' => $languagePath . DIRECTORY_SEPARATOR . $locale_array[0] . DIRECTORY_SEPARATOR . $locale_array[0] . '.php', 'locale' => $locale_array[0]));
         if ($language_count > 1) {
             for ($i = 1; $i < $language_count; $i++) {
                 $translate->addTranslation(array('content' => $languagePath . DIRECTORY_SEPARATOR . $locale_array[$i] . DIRECTORY_SEPARATOR . $locale_array[$i] . '.php', 'locale' => $locale_array[$i]));
             }
         }
         /*
               if( $language_count > 1) {
                 for( $i = 1; $i < $language_count; $i++ ) {
                   $translate->addTranslation(
                           array(
                               'content' => $languageFolders[$i] . DIRECTORY_SEPARATOR . $locale_array[$i] . '.php',
                               'locale' => $locale_array[$i] )              
                                         );
                     echo $locale_array[$i] . ' Translation Added<br />';
                   }
                   
                 }
                * */
     } else {
         $translate = new Zend_Translate('Csv', APPLICATION_PATH . '/application/languages', null, $params);
     }
     Zend_Registry::set('Zend_Translate', $translate);
     Zend_Validate_Abstract::setDefaultTranslator($translate);
     Zend_Form::setDefaultTranslator($translate);
     Zend_Controller_Router_Route::setDefaultTranslator($translate);
     return $translate;
 }
Example #21
0
 public function testAssembleWithVariableMissing()
 {
     $route = new Zend_Controller_Router_Route('archive/:year', array('controller' => 'archive', 'action' => 'show'), array('year' => '\\d+'));
     try {
         $url = $route->assemble();
     } catch (Exception $e) {
     }
     $this->assertTrue($e instanceof Zend_Controller_Router_Exception, 'Expected Zend_Controller_Router_Exception to be thrown');
 }
Example #22
0
 public function testAssembleWithDefaultAndValue()
 {
     $route = new Zend_Controller_Router_Route('authors/:name', array('name' => 'martel'));
     $url = $route->assemble(array('name' => 'mike'));
     $this->assertEquals('authors/mike', $url);
 }
Example #23
0
 /**
  * Assembles user submitted parameters forming a URL path defined by this route
  *
  * @param  array $ An array of variable and value pairs used as parameters
  * @param  boolean $reset Whether or not to set route defaults with those provided in $data
  * @return string Route path with user submitted parameters
  */
 public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
 {
     // TODO: We should take the paramValues/mvcParams into account shouldn't we? For now
     // This router doesn't support full reverse assembly I guess.
     return parent::assemble($data, $reset, $encode, $partial);
 }
Example #24
0
 /**
  * Matches a Request with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param Mage_Webapi_Controller_Request $request
  * @param boolean $partial Partial path matching
  * @return array|bool An array of assigned values or a boolean false on a mismatch
  */
 public function match($request, $partial = false)
 {
     return parent::match(ltrim($request->getPathInfo(), $this->_urlDelimiter), $partial);
 }
Example #25
0
 /**
  * Set a default locale
  *
  * @param  mixed $locale
  * @return void
  */
 public static function setDefaultLocale($locale = null)
 {
     self::$_defaultLocale = $locale;
 }
Example #26
0
 public function testGetDefault()
 {
     $route = new Zend_Controller_Router_Route('users/all', array('controller' => 'ctrl', 'action' => 'act'));
     $this->assertSame('ctrl', $route->getDefault('controller'));
     $this->assertSame(null, $route->getDefault('bogus'));
 }
 /**
  * @group ZF-7848
  */
 public function testChainingWithEmptyStaticRoutesMatchesCorrectly()
 {
     $adminRoute = new Zend_Controller_Router_Route('admin', array('module' => 'admin', 'controller' => 'index', 'action' => 'index'));
     $indexRoute = new Zend_Controller_Router_Route_Static('', array('module' => 'admin', 'controller' => 'index', 'action' => 'index'));
     $loginRoute = new Zend_Controller_Router_Route('login', array('module' => 'admin', 'controller' => 'login', 'action' => 'index'));
     $emptyRoute = $adminRoute->chain($indexRoute);
     $nonEmptyRoute = $adminRoute->chain($loginRoute);
     $request = new Zend_Controller_Request_Http();
     $request->setPathInfo('/admin');
     $values = $emptyRoute->match($request);
     $this->assertEquals(array('module' => 'admin', 'controller' => 'index', 'action' => 'index'), $values);
     $request->setPathInfo('/admin/');
     $values = $emptyRoute->match($request);
     $this->assertEquals(array('module' => 'admin', 'controller' => 'index', 'action' => 'index'), $values);
     $request->setPathInfo('/admin/login');
     $values = $nonEmptyRoute->match($request);
     $this->assertEquals(array('module' => 'admin', 'controller' => 'login', 'action' => 'index'), $values);
 }
Example #28
0
    public function testEncode()
    {
        $route = new Zend_Controller_Router_Route(':controller/:action/*', array('controller' => 'index', 'action' => 'index'));
        
        $url = $route->assemble(array('controller' => 'My Controller'), false, true);
        $this->assertEquals('My+Controller', $url);

        $url = $route->assemble(array('controller' => 'My Controller'), false, false);
        $this->assertEquals('My Controller', $url);

        $token = $route->match('en/foo/id/My Value');
    
        $url = $route->assemble(array(), false, true);
        $this->assertEquals('en/foo/id/My+Value', $url);
        
        $url = $route->assemble(array('id' => 'My Other Value'), false, true);
        $this->assertEquals('en/foo/id/My+Other+Value', $url);
        
        $route = new Zend_Controller_Router_Route(':controller/*', array('controller' => 'My Controller'));
        $url = $route->assemble(array('id' => 1), false, true);
        $this->assertEquals('My+Controller/id/1', $url);
    }
Example #29
0
 /**
  * Get the locale
  *
  * @return mixed
  */
 public function getLocale()
 {
     if ($this->_locale !== null) {
         return $this->_locale;
     } else {
         if (($locale = Zend_Controller_Router_Route::getDefaultLocale()) !== null) {
             return $locale;
         } else {
             try {
                 $locale = Zend_Registry::get('Zend_Locale');
             } catch (Zend_Exception $e) {
                 $locale = null;
             }
             if ($locale !== null) {
                 return $locale;
             }
         }
     }
     return null;
 }
 public function _initRoutes()
 {
     $this->bootstrap('FrontController');
     $this->_frontController = $this->getResource('FrontController');
     $router = $this->_frontController->getRouter();
     $langRoute = new Zend_Controller_Router_Route(':lang/', array('lang' => 'en'));
     $defaultRoute = new Zend_Controller_Router_Route(':controller/:action', array('module' => 'default', 'controller' => 'index', 'action' => 'index'));
     $defaultRoute = $langRoute->chain($defaultRoute);
     $router->addRoute('langRoute', $langRoute);
     $router->addRoute('defaultRoute', $defaultRoute);
 }