Пример #1
0
 public static function start($nodeName)
 {
     if (defined('PROFILER_SWITCH') && PROFILER_SWITCH == 1) {
         Profiler::enable();
     }
     return Profiler::start($nodeName);
 }
Пример #2
0
 static function reply($data = array())
 {
     Session::instance()->abort_save();
     header("X-Gallery-API-Version: " . rest::API_VERSION);
     switch (Input::instance()->get("output", "json")) {
         case "json":
             json::reply($data);
             break;
         case "jsonp":
             if (!($callback = Input::instance()->get("callback", ""))) {
                 throw new Rest_Exception("Bad Request", 400, array("errors" => array("callback" => "missing")));
             }
             if (preg_match('/^[$A-Za-z_][0-9A-Za-z_]*$/', $callback) == 1) {
                 header("Content-type: application/javascript; charset=UTF-8");
                 print "{$callback}(" . json_encode($data) . ")";
             } else {
                 throw new Rest_Exception("Bad Request", 400, array("errors" => array("callback" => "invalid")));
             }
             break;
         case "html":
             header("Content-type: text/html; charset=UTF-8");
             if ($data) {
                 $html = preg_replace("#([\\w]+?://[\\w]+[^ \\'\"\n\r\t<]*)#ise", "'<a href=\"\\1\" >\\1</a>'", var_export($data, 1));
             } else {
                 $html = t("Empty response");
             }
             print "<pre>{$html}</pre>";
             if (Session::instance()->get("profiler", false)) {
                 Profiler::enable();
                 $profiler = new Profiler();
                 $profiler->render();
             }
             break;
         default:
             throw new Rest_Exception("Bad Request", 400);
     }
 }
Пример #3
0
<?php

//
Profiler::enable();
Пример #4
0
 static function admin_page_bottom($theme)
 {
     $session = Session::instance();
     if ($session->get("profiler", false)) {
         Profiler::enable();
         $profiler = new Profiler();
         $profiler->render();
     }
     // Redirect to the root album when the admin session expires.
     $content = '<script type="text/javascript">
   var adminReauthCheck = function() {
     $.ajax({url: "' . url::site("admin?reauth_check=1") . '",
             dataType: "json",
             success: function(data){
               if ("location" in data) {
                 document.location = data.location;
               }
             }});
   };
   setInterval("adminReauthCheck();", 60 * 1000);
   </script>';
     if (upgrade_checker::should_auto_check()) {
         $content .= '<script type="text/javascript">
     $.ajax({url: "' . url::site("admin/upgrade_checker/check_now?csrf=" . access::csrf_token()) . '"});
     </script>';
     }
     if ($session->get("l10n_mode", false)) {
         $content .= "\n" . L10n_Client_Controller::l10n_form();
     }
     return $content;
 }
Пример #5
0
 public function __call($function, $args)
 {
     // Force zlib compression off.  Image and movie files are already compressed and
     // recompressing them is CPU intensive.
     if (ini_get("zlib.output_compression")) {
         ini_set("zlib.output_compression", "Off");
     }
     // request_uri: gallery3/var/albums/foo/bar.jpg?m=1234
     $request_uri = rawurldecode(Input::instance()->server("REQUEST_URI"));
     // get rid of query parameters
     // request_uri: gallery3/var/albums/foo/bar.jpg
     $request_uri = preg_replace("/\\?.*/", "", $request_uri);
     // var_uri: gallery3/var/
     $var_uri = url::file("var/");
     // Make sure that the request is for a file inside var
     $offset = strpos(rawurldecode($request_uri), $var_uri);
     if ($offset !== 0) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 1;
         throw $e;
     }
     // file_uri: albums/foo/bar.jpg
     $file_uri = substr($request_uri, strlen($var_uri));
     // type: albums
     // path: foo/bar.jpg
     list($type, $path) = explode("/", $file_uri, 2);
     if ($type != "resizes" && $type != "albums" && $type != "thumbs") {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 2;
         throw $e;
     }
     // Get the item model using the path and type (which corresponds to a var subdir)
     $item = item::find_by_path($path, $type);
     if (!$item->loaded()) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 3;
         throw $e;
     }
     // Make sure we have access to the item
     if (!access::can("view", $item)) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 4;
         throw $e;
     }
     // Make sure we have view_full access to the original
     if ($type == "albums" && !access::can("view_full", $item)) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 5;
         throw $e;
     }
     // Don't try to load a directory
     if ($type == "albums" && $item->is_album()) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 6;
         throw $e;
     }
     // Note: this code is roughly duplicated in data_rest, so if you modify this, please look to
     // see if you should make the same change there as well.
     if ($type == "albums") {
         $file = $item->file_path();
     } else {
         if ($type == "resizes") {
             $file = $item->resize_path();
         } else {
             $file = $item->thumb_path();
         }
     }
     if (!file_exists($file)) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 7;
         throw $e;
     }
     if (gallery::show_profiler()) {
         Profiler::enable();
         $profiler = new Profiler();
         $profiler->render();
         exit;
     }
     header("Content-Length: " . filesize($file));
     header("Pragma:");
     // Check that the content hasn't expired or it wasn't changed since cached
     expires::check(2592000, $item->updated);
     // We don't need to save the session for this request
     Session::instance()->abort_save();
     expires::set(2592000, $item->updated);
     // 30 days
     // Dump out the image.  If the item is a movie or album, then its thumbnail will be a JPG.
     if (($item->is_movie() || $item->is_album()) && $type == "thumbs") {
         header("Content-Type: image/jpeg");
     } else {
         header("Content-Type: {$item->mime_type}");
     }
     if (TEST_MODE) {
         return $file;
     } else {
         // Don't use Kohana::close_buffers(false) here because that only closes all the buffers
         // that Kohana started.  We want to close *all* buffers at this point because otherwise we're
         // going to buffer up whatever file we're proxying (and it may be very large).  This may
         // affect embedding or systems with PHP's output_buffering enabled.
         while (ob_get_level()) {
             if (!@ob_end_clean()) {
                 // ob_end_clean() can return false if the buffer can't be removed for some reason
                 // (zlib output compression buffers sometimes cause problems).
                 break;
             }
         }
         readfile($file);
     }
 }
Пример #6
0
 static function admin_page_bottom($theme)
 {
     $session = Session::instance();
     if ($session->get("profiler", false)) {
         Profiler::enable();
         $profiler = new Profiler();
         $profiler->render();
     }
     // Redirect to the root album when the admin session expires.
     $admin_session_redirect_check = '<script type="text/javascript">
   var adminReauthCheck = function() {
     $.ajax({url: "' . url::site("admin?reauth_check=1") . '",
             dataType: "json",
             success: function(data){
               if ("location" in data) {
                 document.location = data.location;
               }
             }});
   };
   setInterval("adminReauthCheck();", 60 * 1000);
   </script>';
     print $admin_session_redirect_check;
     if ($session->get("l10n_mode", false)) {
         return L10n_Client_Controller::l10n_form();
     }
 }
Пример #7
0
 /**
  * Construct new page controller
  */
 function __construct()
 {
     parent::__construct();
     // Init page values
     $this->country = Session::instance()->get('country', false);
     // AJAX requests output without template
     if (request::is_ajax()) {
         $this->auto_render = false;
         $this->history = false;
         return;
     }
     // Use profiler only when an admin is logged in
     if ($this->visitor->logged_in('admin')) {
         Profiler::enable();
     }
     // Bind the generic page variables
     $this->template->bind('skin', $this->skin)->bind('skin_imports', $this->skin_imports)->bind('stylesheets', $this->stylesheets)->bind('language', $this->language)->bind('page_width', $this->page_width)->bind('page_main', $this->page_main)->bind('page_id', $this->page_id)->bind('page_class', $this->page_class)->bind('page_title', $this->page_title)->bind('page_subtitle', $this->page_subtitle);
     // Add controller name as default page id
     $this->page_id = Router::$controller;
     // Init page values
     $this->menu = Kohana::config('site.menu');
     $skin_path = 'ui/' . Kohana::config('site.skin') . '/';
     $this->skin = $skin_path . 'skin.less';
     $this->skin_imports = array('ui/layout.less', 'ui/widget.less', 'ui/jquery-ui.css', 'ui/site.css', $skin_path . 'jquery-ui.css');
     $this->page_width = Session::instance()->get('page_width', 'fixed');
     $this->page_main = Session::instance()->get('page_main', 'left');
     //$this->stylesheets = array('ui/' . Kohana::config('site.skin') . '/skin', 'ui/' . Kohana::config('site.skin') . '/jquery-ui');
     $this->breadcrumb = array();
     //html::anchor('/', __('Home')));
     $this->tabs = array();
     // If a country is seleced, add custom stylesheet
     if ($this->country && Kohana::config('site.country_css')) {
         widget::add('head', html::stylesheet('ui/' . utf8::strtolower($this->country) . '/skin'));
     }
     // Generic views
     widget::add('actions', View::factory('generic/actions')->bind('actions', $this->page_actions));
     // widget::add('breadcrumb', View::factory('generic/breadcrumb')->bind('breadcrumb', $this->breadcrumb));
     widget::add('navigation', View::factory('generic/navigation')->bind('items', $this->menu)->bind('selected', $this->page_id));
     widget::add('tabs', View::factory('generic/tabs_top')->bind('tabs', $this->tabs)->bind('selected', $this->tab_id));
     // Header
     widget::add('header', View::factory('generic/header'));
     // Footer
     widget::add('footer', View_Mod::factory('events/events_list', array('mod_id' => 'footer-events-new', 'mod_class' => 'article unit size1of4 cut events', 'mod_title' => __('New events'), 'events' => ORM::factory('event')->order_by('id', 'DESC')->find_all(10))));
     widget::add('footer', View_Mod::factory('forum/topics_list', array('mod_id' => 'footer-topics-active', 'mod_class' => 'article unit size1of4 cut topics', 'mod_title' => __('New posts'), 'topics' => ORM::factory('forum_topic')->order_by('last_post_id', 'DESC')->find_all(10))));
     widget::add('footer', View_Mod::factory('blog/entries_list', array('mod_id' => 'footer-blog-entries', 'mod_class' => 'article unit size1of4 cut blogentries', 'mod_title' => __('New blogs'), 'entries' => ORM::factory('blog_entry')->find_latest(10))));
     // Dock
     $classes = array(html::anchor('set/width/narrow', __('Narrow'), array('onclick' => '$("body").addClass("fixed").removeClass("liquid"); $.get(this.href); return false;')), html::anchor('set/width/wide', __('Wide'), array('onclick' => '$("body").addClass("liquid").removeClass("narrow"); $.get(this.href); return false;')), html::anchor('set/main/left', __('Left'), array('onclick' => '$("body").addClass("left").removeClass("right"); $.get(this.href); return false;')), html::anchor('set/main/right', __('Right'), array('onclick' => '$("body").addClass("right").removeClass("left"); $.get(this.href); return false;')));
     widget::add('dock2', __('Layout: ') . implode(', ', $classes));
     // Language selection
     $available_languages = Kohana::config('locale.languages');
     if (count($available_languages)) {
         $languages = array();
         foreach ($available_languages as $lang => $locale) {
             $languages[] = html::anchor('set/lang/' . $lang, html::chars($locale[2]));
         }
         widget::add('dock2', ' | ' . __('Language: ') . implode(', ', $languages));
     }
     if ($this->user) {
         // Authenticated view
         widget::add('dock', __('[#:id] :user', array(':id' => $this->user->id, ':user' => html::nick($this->user->id, $this->user->username))));
         $new_messages = array();
         if ($this->user->newcomments) {
             $new_messages[] = html::anchor(url::user($this->user), __(':commentsC', array(':comments' => $this->user->newcomments)), array('title' => __('New comments'), 'class' => 'new-comments'));
         }
         if (!empty($new_messages)) {
             widget::add('dock', ' - ' . __('New messages: ') . implode(' ', $new_messages));
         }
         // Logout also from Facebook
         if (FB::enabled() && Visitor::instance()->get_provider()) {
             widget::add('dock', ' - ' . html::anchor('sign/out', FB::icon() . __('Sign out'), array('onclick' => "FB.Connect.logoutAndRedirect('/sign/out'); return false;")));
         } else {
             widget::add('dock', ' - ' . html::anchor('sign/out', __('Sign out')));
         }
         if (Kohana::config('site.inviteonly')) {
             //				widget::add('dock', ' | ' . html::anchor('sign/up', __('Send invite')));
         }
         // Admin functions
         if ($this->visitor->logged_in('admin')) {
             widget::add('dock2', ' | ' . __('Admin: ') . html::anchor('roles', __('Roles')) . ', ' . html::anchor('tags', __('Tags')) . ', ' . html::anchor('#kohana-profiler', __('Profiler'), array('onclick' => '$("#kohana-profiler").toggle();')));
         }
     } else {
         // Non-authenticated view
         $form = form::open('sign/in');
         $form .= form::input('username', null, 'title="' . __('Username') . '"');
         $form .= form::password('password', '', 'title="' . __('Password') . '"');
         $form .= form::submit('submit', __('Sign in'));
         $form .= form::close();
         $form .= html::anchor('/sign/up', __('Sign up'));
         if (FB::enabled()) {
             $form .= ' | ' . FB::fbml_login();
         }
         widget::add('dock', $form);
     }
     // End
     widget::add('end', View::factory('generic/end'));
     // Analytics
     $google_analytics = Kohana::config('site.google_analytics');
     if ($google_analytics) {
         widget::add('head', html::script_source("\nvar _gaq = _gaq || []; _gaq.push(['_setAccount', '" . $google_analytics . "']); _gaq.push(['_trackPageview']);\n(function() {\n\tvar ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n\tga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n\t(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);\n})();\n"));
     }
     // Ads
     $ads = Kohana::config('site.ads');
     if ($ads && $ads['enabled']) {
         foreach ($ads['slots'] as $ad => $slot) {
             widget::add($slot, View::factory('ads/' . $ad));
         }
     }
     // Facebook connect
     if (FB::enabled()) {
         FB::init();
     }
 }