Exemple #1
0
 /**
  * Determines if the menu item is part of the current URI
  *
  * @param   string  Url of item to check against
  * @return  mixed   Returns Menu::CURRENT_ITEM for current, Menu::ACTIVE_ITEM for active, or 0
  */
 protected function is_active_url($url)
 {
     $uri = $this->_current_url !== null ? $this->_current_url : $this->_uri;
     $link = trim(URL::site($url), '/');
     // Exact match
     if ($uri === $link) {
         return Menu::CURRENT_ITEM;
     } else {
         $current_pieces = explode('/', $uri);
         array_shift($current_pieces);
         $link_pieces = explode('/', $link);
         array_shift($link_pieces);
         for ($i = 0, $l = count($link_pieces); $i < $l; $i++) {
             if (isset($current_pieces[$i]) and $current_pieces[$i] !== $link_pieces[$i] or empty($current_pieces[$i])) {
                 return 0;
             }
         }
         return Menu::ACTIVE_ITEM;
     }
     return 0;
 }
Exemple #2
0
 /**
  * Outputs the Captcha image.
  *
  * @param boolean $html Html output
  * @return mixed
  */
 public function render($html = true)
 {
     if ($html === true) {
         return '<img src="' . URL::site('captcha/' . $this->id) . '" width="' . $this->width . '" height="' . $this->height . '" alt="Captcha" class="captcha" />';
     }
     // Creates $this->image
     $this->image_create($this->background);
     // Add a random gradient
     if (!$this->background) {
         $color1 = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
         $color2 = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
         $this->image_gradient($color1, $color2);
     }
     // Add a few random circles
     for ($i = 0, $count = mt_rand(10, $this->complexity * 3); $i < $count; $i++) {
         $color = imagecolorallocatealpha($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255), mt_rand(80, 120));
         $size = mt_rand(5, $this->height / 3);
         imagefilledellipse($this->image, mt_rand(0, $this->width), mt_rand(0, $this->height), $size, $size, $color);
     }
     // Calculate character font-size and spacing
     $default_size = min($this->width, $this->height * 2) / strlen($this->response);
     $spacing = (int) ($this->width * 0.9 / strlen($this->response));
     // Background alphabetic character attributes
     $color_limit = mt_rand(96, 160);
     $chars = 'ABEFGJKLPQRTVY';
     // Draw each Captcha character with varying attributes
     for ($i = 0, $strlen = strlen($this->response); $i < $strlen; $i++) {
         // Use different fonts if available
         $font = $this->fontpath . $this->fonts[array_rand($this->fonts)];
         $angle = mt_rand(-40, 20);
         // Scale the character size on image height
         $size = $default_size / 10 * mt_rand(7, 13);
         $box = imageftbbox($size, $angle, $font, $this->response[$i]);
         // Calculate character starting coordinates
         $x = $spacing / 4 + $i * $spacing;
         $y = $this->height / 2 + ($box[2] - $box[5]) / 4;
         // Draw captcha text character
         // Allocate random color, size and rotation attributes to text
         $color = imagecolorallocate($this->image, mt_rand(149, 255), mt_rand(199, 255), mt_rand(0, 255));
         // Write text character to image
         imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response[$i]);
         // Draw "ghost" alphabetic character
         $text_color = imagecolorallocatealpha($this->image, mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand(70, 120));
         $char = $chars[mt_rand(0, 13)];
         imagettftext($this->image, $size * 2, mt_rand(-45, 45), $x - mt_rand(5, 10), $y + mt_rand(5, 10), $text_color, $font, $char);
     }
     // Send the correct HTTP header
     Mii::$app->response->set_header('Content-Type', 'image/' . $this->image_type);
     Mii::$app->response->set_header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
     Mii::$app->response->set_header('Pragma', 'no-cache');
     Mii::$app->response->set_header('Connection', 'close');
     // Pick the correct output function
     $function = 'image' . $this->image_type;
     $function($this->image);
     // Free up resources
     imagedestroy($this->image);
 }
Exemple #3
0
 public static function back_url($default = null)
 {
     if (isset($_GET['back_url'])) {
         return urldecode($_GET['back_url']);
     }
     if ($default === null) {
         return URL::current();
     }
     return $default;
 }
Exemple #4
0
function redirect($url, $use_back_url = false)
{
    if ($use_back_url) {
        $url = \mii\util\URL::back_url($url);
    }
    throw new \mii\web\RedirectHttpException($url);
}
Exemple #5
0
 /**
  * Generates the full URL for a certain page.
  *
  * @param   integer  page number
  * @return  string   page URL
  */
 public function url($page = 1)
 {
     // Clean the page number
     $page = max(1, (int) $page);
     // No page number in URLs to first page
     if ($page === 1 and !$this->first_page_in_url) {
         $page = NULL;
     }
     switch ($this->current_page_source) {
         case 'query_string':
         case 'mixed':
             return URL::site($this->request->uri() . $this->query([$this->current_page_source_key => $page]));
         case 'route':
             return URL::site($this->route->uri(array_merge($this->route_params, array($this->current_page_source_key => $page))) . $this->query());
     }
     return '#';
 }