예제 #1
0
 /**
  * Add database navigation links
  * 
  * @param array $categories
  * @return array
  */
 public function getEditLink()
 {
     $controller = $this->request->getControllerName();
     $switch = 'databases';
     if ($controller == 'databases') {
         $switch = 'databases-edit';
     }
     $params = $this->request->getParams();
     $params['controller'] = $switch;
     return $this->request->url_for($params);
 }
예제 #2
0
 /**
  * Create a new Mvc Event
  * 
  * This wires-up the various Mvc classes and makes them
  * available as a convenient package to the application
  */
 public function __construct(Bootstrap $bootstrap)
 {
     // $this->stopwatch = new Stopwatch();
     // framework config
     $this->bootstrap = $bootstrap;
     // path to application root
     $this->app_dir = $bootstrap->getApplicationDir();
     // application config
     $this->registry = Registry::getInstance();
     // controller config
     $this->controller_map = new ControllerMap($this->app_dir);
     // incoming request
     $this->request = Request::createFromGlobals($this->controller_map);
     // outgoing response
     $this->response = $this->getNewResponse();
     // set default view
     $controller = $this->request->getControllerName();
     $action = $this->request->getParam('action', 'index');
     $this->response->setView("{$controller}/{$action}.xsl");
 }
 /**
  * Perform an authentication check on this request
  */
 protected function checkAuthentication($action)
 {
     $id = $this->request->getControllerName();
     $restricted = $this->controller_map->isRestricted($id, $action);
     $requires_login = $this->controller_map->requiresLogin($id, $action);
     // get user from session
     $user = $this->request->getUser();
     // this action requires authentication
     if ($restricted || $requires_login) {
         $redirect_to_login = false;
         // this action requires a logged-in user, but user is not logged-in
         if ($requires_login && !$user->isAuthenticated()) {
             $redirect_to_login = true;
         } elseif ($restricted && !$user->isAuthenticated() && !$user->isInLocalIpRange()) {
             $redirect_to_login = true;
         }
         // redirect to login page
         if ($redirect_to_login == true) {
             return $this->redirectToLogin();
         }
     }
 }
예제 #4
0
 /**
  * Add links to the query object limits
  * 
  * @param Query $query
  */
 public function addQueryLinks(Query $query)
 {
     // we have to pass in the query object here rather than take
     // the property above because adding the links doesn't seem
     // to reflect back in the main object, even though they should
     // be references, maybe because limit objects are in an array?
     // add current query to query object itself
     $params = $query->extractSearchParams();
     $params['controller'] = $this->request->getParam('controller');
     $params['action'] = 'search';
     $params['source'] = $this->request->getParam('source');
     $params['sort'] = $this->request->getParam('sort');
     // url
     $query->url = $this->request->url_for($params);
     // query only
     $query->url_query = Parser::removeLeft($query->url, '?');
     // advanced search
     $params['action'] = 'advanced';
     $query->url_advanced = $this->request->url_for($params);
     // search option links
     $search = $this->registry->getConfig('search');
     if ($search instanceof \SimpleXMLElement) {
         $controller_map = $this->request->getControllerMap();
         // combined results
         $combined = $controller_map->getUrlAlias('combined');
         $combined_id = $combined . '_' . $query->getHash();
         if ($this->request->getSessionData($combined_id) != null) {
             $params = $query->extractSearchParams();
             $params['controller'] = $combined;
             $params['action'] = "results";
             $search->combined_url = $this->request->url_for($params);
         }
         // individual search options
         foreach ($search->xpath("//option") as $option) {
             $id = (string) $option["id"];
             if ((string) $option["source"] != '') {
                 $id .= '_' . (string) $option["source"];
             }
             $id .= '_' . $this->query->getHash();
             // format the number
             // is this the current tab?
             if ($this->request->getControllerName() == (string) $option["id"] && ($this->request->getParam('source') == (string) $option["source"] || (string) $option["source"] == '')) {
                 // mark as current
                 $option->addAttribute('current', "1");
             }
             // create url based on the search terms only!
             $params = $query->extractSearchParams();
             $params['controller'] = $controller_map->getUrlAlias((string) $option["id"]);
             $params['action'] = "results";
             $params['source'] = (string) $option["source"];
             $params['sort'] = $this->request->getParam('sort');
             // results url
             $url = $this->request->url_for($params);
             $option->addAttribute('url', $url);
             // hits url
             $params['action'] = 'hits';
             $url = $this->request->url_for($params);
             $option->addAttribute('url_hits', $url);
             // cached search hit count?
             foreach ($this->request->getAllSessionData() as $session_id => $session_value) {
                 // does this value in the cache have the save id as our tab?
                 $id = str_replace("_" . $query->getHash(), "", $session_id);
                 if ($id == (string) $option["id"]) {
                     // yup, so add it
                     $option->addAttribute('hits', Parser::number_format($session_value));
                 }
             }
         }
         // header('Content-type: text/xml'); echo $search->asXML(); exit;
         $this->registry->setConfig('search', $search);
     }
     // links to remove facets
     foreach ($query->getLimits() as $limit) {
         $params = $this->currentParams();
         $value = $limit->value;
         if ($limit->display != "") {
             $value = $limit->display;
         }
         // urlencode here necessary to support the urlencode above on 'key' urls
         $params = Parser::removeFromArray($params, urlencode($limit->param), $value);
         $limit->remove_url = $this->request->url_for($params);
     }
 }