예제 #1
0
 protected function processStringRoute($route)
 {
     //Run some route cleaning operations.
     $route = str_replace('\\', '/', $route);
     //Convert backslashes to forward slashes
     //Remove a starting forward slash
     if (substr($route, 0, 1) == '/') {
         $route = substr($route, 1, strlen($route) - 1);
     }
     //Remove trailing forward slash
     if (substr($route, strlen($route) - 1, 1) == '/') {
         $route = substr($route, 0, strlen($route) - 1);
     }
     //End routing information on the first "." occurance
     if (($end = strpos($route, '.')) !== false) {
         $route = substr($route, 0, $end);
     }
     //Check to see if a script exists with that route.
     $scriptRoute = SCRIPT_ROOT . $route . '.php';
     if (file_exists($scriptRoute)) {
         //Check for valid path information
         if (ctype_alnum(str_replace(array('/', '_', '-'), '', $route))) {
             $this->setScript($route)->setType(self::ROUTE_SCRIPT);
         }
     } else {
         //No Script found, routing to controller/action
         //Split the route into it's component elements.
         $splitRoute = explode('/', $route);
         $routeCount = count($splitRoute);
         //If the route only contains a controller add the index action
         if ($routeCount == 0) {
             array_push($splitRoute, 'index');
             array_push($splitRoute, 'index');
         } elseif ($routeCount == 1) {
             array_push($splitRoute, 'index');
         } elseif ($routeCount >= 2) {
             //If the action is numeric, it is not the action. Insert the index action into the route.
             if (is_numeric($splitRoute[1])) {
                 $shift = array_shift($splitRoute);
                 array_unshift($splitRoute, $shift, 'index');
             }
         }
         //Check the Controller value and Set a valid value
         $controller = array_shift($splitRoute);
         if (ctype_alnum(str_replace('-', '', $controller)) && ctype_alpha(substr($controller, 0, 1))) {
             $this->setController(Staple_Link::methodCase($controller));
         } else {
             //Bad info in the route, error out.
             throw new Exception('Invalid Route', Staple_Error::PAGE_NOT_FOUND);
         }
         //Check the Action Value and Set a valid value
         $action = array_shift($splitRoute);
         if (ctype_alnum(str_replace('-', '', $action)) && ctype_alpha(substr($action, 0, 1))) {
             $this->setAction(Staple_Link::methodCase($action));
         } else {
             //Bad info in the route, error out.
             throw new Exception('Invalid Route', Staple_Error::PAGE_NOT_FOUND);
         }
         $this->setParams($splitRoute)->setType(self::ROUTE_MVC);
     }
 }
예제 #2
0
 /**
  * Generate a relative link within the framework.
  * @param mixed $route
  * @param array $get
  * @return string
  */
 public function link($route, array $get = array())
 {
     return Staple_Link::get($route, $get);
 }
예제 #3
0
 /**
  * This function is a temporary fix until the changes are completed to Staple_Route.
  * @param string $action
  * @deprecated
  */
 public function displayPaging($action = NULL)
 {
     //Setup Link Variables
     $linkVars = array_merge($_GET, $this->pageVariables);
     //These two variables would be overridden anyway.
     if (array_key_exists('items', $linkVars)) {
         unset($linkVars['items']);
     }
     if (array_key_exists('page', $linkVars)) {
         unset($linkVars['page']);
     }
     //Set a default link action location if none is submitted.
     if ($action == NULL) {
         $action = Staple_Main::getRoute();
     }
     $buffer = "<div class=\"staple_pager row\">\n<div class=\"staple_pager_pages small-12 medium-11 columns\">\n";
     $pages = $this->getPages();
     if (count($pages) > 1) {
         if ($this->getCurrentPage() == 1) {
             $buffer .= '<a class="button tiny secondary disabled"><i class="fa fa-angle-double-left"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-left"></i></a> ';
         } elseif ($this->getCurrentPage() > 1) {
             $buffer .= '<a class="button tiny" href="' . Staple_Link::get($action, array_merge($linkVars, array('page' => 1))) . '"><i class="fa fa-angle-double-left"></i></a> ';
             $buffer .= '<a class="button tiny" href="' . Staple_Link::get($action, array_merge($linkVars, array('page' => $this->getCurrentPage() - 1))) . '"><i class="fa fa-angle-left"></i></a> ';
         }
         if ($pages[0] != 1) {
             $buffer .= '... ';
         }
         foreach ($pages as $page) {
             if ($this->getCurrentPage() == $page) {
                 $buffer .= '<span class="currentpage button tiny disabled">' . (int) $page . '</span> ';
             } else {
                 $buffer .= '<a class="button tiny secondary" href="' . Staple_Link::get($action, array_merge($linkVars, array('page' => (int) $page))) . '">' . (int) $page . '</a> ';
             }
         }
         if ($pages[count($pages) - 1] != $this->getNumberOfPages()) {
             $buffer .= '... ';
         }
         if ($this->getCurrentPage() == $this->getNumberOfPages()) {
             $buffer .= '<a class="button tiny secondary disabled"><i class="fa fa-angle-right"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-double-right"></i></a>';
         } else {
             $buffer .= '<a class="button tiny" href="' . Staple_Link::get($action, array_merge($linkVars, array('page' => $this->getCurrentPage() + 1))) . '"><i class="fa fa-angle-right"></i></a> ';
             $buffer .= '<a class="button tiny" href="' . Staple_Link::get($action, array_merge($linkVars, array('page' => $this->getNumberOfPages()))) . '"><i class="fa fa-angle-double-right"></i></a>';
         }
     } else {
         $buffer .= '<a class="button tiny secondary disabled"><i class="fa fa-angle-double-left"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-left"></i></a>  <a class="button tiny disabled">1</a> <a class="button tiny secondary disabled"><i class="fa fa-angle-right"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-double-right"></i></a>';
     }
     $buffer .= "</div>\n";
     if ($this->getDisplayItemAmountSelector() === true) {
         $buffer .= "<div class=\"staple_pager_items small-12 medium-1 columns\">\n";
         $buffer .= '<select onChange="window.location=\'' . Staple_Link::get($action, array_merge($linkVars, array('page' => 1))) . "&items='+this.value\">\n";
         foreach ($this->getItemAmountSelections() as $value) {
             $selected = '';
             if ($this->getItemsPerPage() == $value) {
                 $selected = ' selected';
             }
             $buffer .= '<option value="' . $value . '"' . $selected . '>' . $value . "</option>\n";
         }
         $buffer .= "</select>\n";
         $buffer .= "</div>\n";
     }
     $buffer .= "</div>\n";
     return $buffer;
 }
예제 #4
0
 /**
  * 
  * If an array is supplied, a link is created to a controller/action. If a string is
  * supplied, a file link is specified.
  * @param string | array $link
  * @param array $get
  */
 protected function _link($link, array $get = array())
 {
     return Staple_Link::get($link, $get);
 }
예제 #5
0
 public static function Redirect(Staple_Route $route, array $get = array())
 {
     $to = (string) $route;
     if ($get != array()) {
         $to .= '?' . Staple_Link::getArraytoString($get);
     }
     header('Location: ' . $to);
     exit(0);
 }