示例#1
0
 /**
  * Placeholder code adapted from dummyimage.com
  */
 public static function placeholder($width, $height)
 {
     $file_format = 'gif';
     $width = $width;
     $height = $height;
     $text_angle = 0;
     $font = Load::getModulePath('media') . 'assets/mplus-1c-medium.ttf';
     $img = imageCreate($width, $height);
     $bg_color = imageColorAllocate($img, 196, 196, 196);
     $fg_color = imageColorAllocate($img, 94, 94, 94);
     $lines = 1;
     $text = $width . 'x' . $height;
     $fontsize = max(min($width / strlen($text) * 1.15, $height * 0.5), 5);
     $textBox = self::_imagettfbbox_t($fontsize, $text_angle, $font, $text);
     $textWidth = ceil(($textBox[4] - $textBox[1]) * 1.07);
     $textHeight = ceil((abs($textBox[7]) + abs($textBox[1])) * 1);
     $textX = ceil(($width - $textWidth) / 2);
     $textY = ceil(($height - $textHeight) / 2 + $textHeight);
     imageFilledRectangle($img, 0, 0, $width, $height, $bg_color);
     imagettftext($img, $fontsize, $text_angle, $textX, $textY, $fg_color, $font, $text);
     $offset = 60 * 60 * 24 * 14;
     //14 Days
     $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
     header($ExpStr);
     //Set a far future expire date. This keeps the image locally cached by the user for less hits to the server.
     header('Cache-Control:	max-age=120');
     header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - $offset) . " GMT");
     header('Content-type: image/' . $file_format);
     //Set the header so the browser can interpret it as an image and not a bunch of weird text.
     switch ($file_format) {
         case 'gif':
             imagegif($img);
             break;
         case 'png':
             imagepng($img);
             break;
         case 'jpg':
             imagejpeg($img);
             break;
         case 'jpeg':
             imagejpeg($img);
             break;
     }
     imageDestroy($img);
     exit;
 }
示例#2
0
        } elseif (!String::startsWith($currentRoute, 'admin/login')) {
            $noAccess = !User::current()->hasPermission('admin.access');
            $isAnon = User::current()->isAnonymous();
            if (!$isAnon && $noAccess) {
                Message::error('You do not have admin access permissions.');
                unset($_SESSION[Config::get('user.session_key')]);
            }
            if ($isAnon || $noAccess) {
                Url::redirect('admin/login');
            }
        }
        Admin::setInAdmin(true);
        View::setPath(ROOT . 'core/admin/');
    }
}, 'module.response' => function ($response = null) {
    if (Admin::inAdmin()) {
        View::data('adminContent', $response);
    }
}, 'view.load' => function ($module, $controller, $method) {
    if (Admin::inAdmin()) {
        $paths = array(sprintf('%s/%s', $controller, $method), sprintf('%s_%s', $controller, $method));
        foreach ($paths as $path) {
            $viewFile = Load::getModulePath($module) . Config::get('view.dir') . $path . EXT;
            Log::debug('admin', 'Checking for custom view: ' . $viewFile);
            if (file_exists($viewFile)) {
                Log::debug('admin', 'Loading custom view: ' . $viewFile);
                return $viewFile;
            }
        }
    }
}));