2008-11-03 05:52:13 +00:00
<? php defined ( "SYSPATH" ) or die ( "No direct script access." );
/**
* Gallery - a web based photo album viewer and editor
2013-01-21 01:22:01 -05:00
* Copyright (C) 2000-2013 Bharat Mediratta
2008-11-03 05:52:13 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
2009-06-28 19:45:11 -07:00
class Theme_View_Core extends Gallery_View {
2008-11-27 16:19:07 +00:00
/**
* Attempts to load a view and pre-load view data.
*
* @throws Kohana_Exception if the requested view cannot be found
* @param string $name view name
2009-11-17 13:42:51 -08:00
* @param string $page_type page type: collection, item, or other
* @param string $page_subtype page sub type: album, photo, tags, etc
2008-11-27 16:19:07 +00:00
* @param string $theme_name view name
* @return void
*/
2009-11-17 13:42:51 -08:00
public function __construct ( $name , $page_type , $page_subtype ) {
2008-11-27 16:19:07 +00:00
parent :: __construct ( $name );
2008-12-24 04:22:22 +00:00
2009-05-27 16:15:00 -07:00
$this -> theme_name = module :: get_var ( "gallery" , "active_site_theme" );
2009-10-22 13:09:20 -07:00
if ( identity :: active_user () -> admin ) {
2012-05-11 15:12:30 -07:00
$theme_name = Input :: instance () -> get ( "theme" );
if ( $theme_name &&
file_exists ( THEMEPATH . $theme_name ) &&
strpos ( realpath ( THEMEPATH . $theme_name ), THEMEPATH ) == 0 ) {
$this -> theme_name = $theme_name ;
}
2009-01-11 00:19:00 +00:00
}
2009-03-16 11:17:27 +00:00
$this -> item = null ;
$this -> tag = null ;
2011-01-03 20:28:54 +01:00
$this -> set_global ( array ( "theme" => $this ,
2011-04-23 07:25:33 -07:00
"theme_info" => theme :: get_info ( $this -> theme_name ),
2011-01-03 20:28:54 +01:00
"user" => identity :: active_user (),
"page_type" => $page_type ,
"page_subtype" => $page_subtype ,
"page_title" => null ));
2009-03-05 00:32:33 +00:00
2010-08-01 21:10:27 -07:00
if ( module :: get_var ( "gallery" , "maintenance_mode" , 0 )) {
2010-08-01 21:00:30 -07:00
if ( identity :: active_user () -> admin ) {
message :: warning ( t ( "This site is currently in maintenance mode. Visit the <a href= \" %maintenance_url \" >maintenance page</a>" , array ( "maintenance_url" => url :: site ( "admin/maintenance" ))));
} else
message :: warning ( t ( "This site is currently in maintenance mode." ));
2009-03-05 00:32:33 +00:00
}
2008-11-04 05:02:37 +00:00
}
2009-05-09 22:22:30 +00:00
/**
2013-03-11 15:59:00 +01:00
* Proportion of the current thumb_size's to default.
*
* Themes can optionally use the $dimension parameter to choose which of the album's
* children will be used to determine the proportion. If set, the proportion will be
* calculated based on the child item with the largest width or height.
*
2011-08-30 20:49:23 -07:00
* @param object Item_Model (optional) check the proportions for this item
2013-03-11 14:42:43 +01:00
* @param int (optional) minimum thumbnail width
2013-03-11 15:59:00 +01:00
* @param string (optional) "width" or "height"
2009-05-09 22:22:30 +00:00
* @return int
*/
2013-03-11 15:59:00 +01:00
public function thumb_proportion ( $item = null , $minimum_size = 0 , $dimension = null ) {
if ( ! in_array ( $dimension , array ( "height" , "width" ))) {
$dimension = null ;
}
// If the item is an album with children, grab an item from that album instead. We're
2013-01-23 14:03:44 -05:00
// interested in the size of the thumbnails in this album, not the thumbnail of the
// album itself.
if ( $item && $item -> is_album () && $item -> children_count ()) {
2013-03-11 15:59:00 +01:00
$orderBy = ( is_null ( $dimension )) ? array ()
: array ( "thumb_" . $dimension => "desc" );
$item = $item -> children ( 1 , null , array (), $orderBy ) -> current ();
2013-01-23 14:03:44 -05:00
}
2011-03-20 10:25:59 -07:00
// By default we have a globally fixed thumbnail size In core code, we just return a fixed
// proportion based on the global thumbnail size, but since modules can override that, we
// return the actual proportions when we have them.
2011-08-30 20:49:23 -07:00
if ( $item && $item -> has_thumb ()) {
2013-03-11 14:42:43 +01:00
return max ( $item -> thumb_width , $item -> thumb_height , $minimum_size ) / 200 ;
2011-03-20 10:25:59 -07:00
} else {
// @TODO change the 200 to a theme supplied value when and if we come up with an
// API to allow the theme to set defaults.
return module :: get_var ( "gallery" , "thumb_size" , 200 ) / 200 ;
}
2009-05-09 22:22:30 +00:00
}
2008-11-05 05:20:20 +00:00
public function item () {
2008-11-27 16:19:07 +00:00
return $this -> item ;
2008-11-05 05:20:20 +00:00
}
2013-02-09 14:53:34 -05:00
public function siblings ( $limit = null , $offset = null ) {
return call_user_func_array (
$this -> siblings_callback [ 0 ],
2013-03-11 23:10:27 +01:00
array_merge ( $this -> siblings_callback [ 1 ], array ( $limit , $offset )));
2013-01-30 19:32:35 -05:00
}
2008-11-28 01:18:45 +00:00
public function tag () {
return $this -> tag ;
}
2008-11-27 04:58:38 +00:00
public function page_type () {
2008-11-27 16:19:07 +00:00
return $this -> page_type ;
2008-11-27 04:58:38 +00:00
}
2009-11-17 13:42:51 -08:00
public function page_subtype () {
return $this -> page_subtype ;
}
2009-11-06 14:08:46 -08:00
public function user_menu () {
$menu = Menu :: factory ( "root" )
-> css_id ( "g-login-menu" )
-> css_class ( "g-inline ui-helper-clear-fix" );
module :: event ( "user_menu" , $menu , $this );
return $menu -> render ();
}
2010-05-14 16:55:15 -07:00
public function site_menu ( $item_css_selector ) {
2009-01-07 09:07:45 +00:00
$menu = Menu :: factory ( "root" );
2010-05-14 16:55:15 -07:00
module :: event ( "site_menu" , $menu , $this , $item_css_selector );
2009-10-27 14:00:32 -07:00
return $menu -> render ();
2008-12-07 19:45:46 +00:00
}
2009-01-04 03:43:12 +00:00
public function album_menu () {
2009-07-28 13:47:22 -07:00
$menu = Menu :: factory ( "root" );
module :: event ( "album_menu" , $menu , $this );
2009-10-27 14:00:32 -07:00
return $menu -> render ();
2009-01-04 03:43:12 +00:00
}
2009-06-14 22:27:26 -07:00
public function tag_menu () {
2009-07-28 13:47:22 -07:00
$menu = Menu :: factory ( "root" );
module :: event ( "tag_menu" , $menu , $this );
2009-10-27 14:00:32 -07:00
return $menu -> render ();
2009-06-14 22:27:26 -07:00
}
2009-01-04 03:43:12 +00:00
public function photo_menu () {
2009-07-28 13:47:22 -07:00
$menu = Menu :: factory ( "root" );
if ( access :: can ( "view_full" , $this -> item ())) {
$menu -> append ( Menu :: factory ( "link" )
-> id ( "fullsize" )
-> label ( t ( "View full size" ))
-> url ( $this -> item () -> file_url ())
2009-10-04 00:27:22 -06:00
-> css_class ( "g-fullsize-link" ));
2009-07-28 13:47:22 -07:00
}
2009-01-04 03:43:12 +00:00
2009-07-28 13:47:22 -07:00
module :: event ( "photo_menu" , $menu , $this );
2009-10-27 14:00:32 -07:00
return $menu -> render ();
2009-06-27 16:27:06 -07:00
}
2009-09-16 20:34:42 -07:00
public function movie_menu () {
$menu = Menu :: factory ( "root" );
module :: event ( "movie_menu" , $menu , $this );
2009-10-27 14:00:32 -07:00
return $menu -> render ();
2009-09-16 20:34:42 -07:00
}
2009-08-10 23:05:05 -07:00
public function context_menu ( $item , $thumbnail_css_selector ) {
2009-07-28 13:47:22 -07:00
$menu = Menu :: factory ( "root" )
-> append ( Menu :: factory ( "submenu" )
2009-08-03 21:45:54 -07:00
-> id ( "context_menu" )
2009-07-28 20:44:50 -07:00
-> label ( t ( "Options" )))
2009-10-04 00:27:22 -06:00
-> css_class ( "g-context-menu" );
2009-01-04 07:40:37 +00:00
2009-08-10 23:05:05 -07:00
module :: event ( "context_menu" , $menu , $this , $item , $thumbnail_css_selector );
2009-10-27 14:00:32 -07:00
return $menu -> render ();
2009-01-04 03:43:12 +00:00
}
2008-12-30 04:13:31 +00:00
/**
* Print out any site wide status information.
*/
public function site_status () {
return site_status :: get ();
}
2008-12-22 06:50:20 +00:00
/**
* Print out any messages waiting for this user.
*/
public function messages () {
return message :: get ();
}
2009-09-30 07:31:11 -07:00
/**
* Print out the sidebar.
*/
public function sidebar_blocks () {
2009-11-13 13:56:05 -08:00
$sidebar = block_manager :: get_html ( "site_sidebar" , $this );
2009-10-22 13:09:20 -07:00
if ( empty ( $sidebar ) && identity :: active_user () -> admin ) {
2009-09-30 07:31:11 -07:00
$sidebar = new View ( "no_sidebar.html" );
}
return $sidebar ;
}
2008-11-22 21:46:34 +00:00
/**
* Handle all theme functions that insert module content.
*/
public function __call ( $function , $args ) {
switch ( $function ) {
2008-11-27 11:33:45 +00:00
case "album_blocks" :
case "album_bottom" :
case "album_top" :
2009-07-29 17:25:53 -07:00
case "body_attributes" :
2008-11-28 09:46:29 +00:00
case "credits" ;
2009-03-12 15:40:08 +00:00
case "dynamic_bottom" :
case "dynamic_top" :
2008-12-22 03:53:36 +00:00
case "footer" :
2008-11-22 21:46:34 +00:00
case "head" :
case "header_bottom" :
2008-11-27 11:33:45 +00:00
case "header_top" :
2011-01-21 00:07:00 -08:00
case "html_attributes" :
2008-11-27 11:33:45 +00:00
case "page_bottom" :
case "page_top" :
case "photo_blocks" :
2009-03-12 15:40:08 +00:00
case "photo_bottom" :
2008-11-27 11:33:45 +00:00
case "photo_top" :
2009-03-31 05:14:40 +00:00
case "resize_bottom" :
case "resize_top" :
2008-11-22 21:46:34 +00:00
case "sidebar_bottom" :
2008-11-27 11:33:45 +00:00
case "sidebar_top" :
2008-12-17 04:45:35 +00:00
case "thumb_bottom" :
case "thumb_info" :
case "thumb_top" :
2008-11-22 21:50:39 +00:00
$blocks = array ();
2009-06-26 07:51:29 -07:00
if ( method_exists ( "gallery_theme" , $function )) {
switch ( count ( $args )) {
case 0 :
$blocks [] = gallery_theme :: $function ( $this );
break ;
case 1 :
$blocks [] = gallery_theme :: $function ( $this , $args [ 0 ]);
break ;
case 2 :
$blocks [] = gallery_theme :: $function ( $this , $args [ 0 ], $args [ 1 ]);
break ;
default :
$blocks [] = call_user_func_array (
array ( "gallery_theme" , $function ),
array_merge ( array ( $this ), $args ));
}
}
2009-06-29 06:08:50 -07:00
2009-05-26 05:28:59 +00:00
foreach ( module :: active () as $module ) {
2009-06-26 07:51:29 -07:00
if ( $module -> name == "gallery" ) {
continue ;
}
2009-01-18 05:01:00 +00:00
$helper_class = " { $module -> name } _theme" ;
2013-03-02 13:25:10 +01:00
if ( class_exists ( $helper_class ) && method_exists ( $helper_class , $function )) {
2008-11-22 21:50:39 +00:00
$blocks [] = call_user_func_array (
array ( $helper_class , $function ),
array_merge ( array ( $this ), $args ));
2008-11-22 21:46:34 +00:00
}
}
2009-06-26 14:37:15 -07:00
2009-11-28 23:48:38 -08:00
$helper_class = theme :: $site_theme_name . "_theme" ;
2013-03-02 13:25:10 +01:00
if ( class_exists ( $helper_class ) && method_exists ( $helper_class , $function )) {
2009-11-28 23:48:38 -08:00
$blocks [] = call_user_func_array (
array ( $helper_class , $function ),
array_merge ( array ( $this ), $args ));
}
2009-01-01 00:16:08 +00:00
if ( Session :: instance () -> get ( "debug" )) {
2010-01-08 12:49:16 -08:00
if ( $function != "head" && $function != "body_attributes" ) {
2008-11-25 02:17:53 +00:00
array_unshift (
2010-01-08 12:49:16 -08:00
$blocks ,
"<div class= \" g-annotated-theme-block g-annotated-theme-block_ $function g-clear-fix \" >" .
2008-11-25 02:17:53 +00:00
"<div class= \" title \" > $function </div>" );
$blocks [] = "</div>" ;
}
}
2008-11-22 21:50:39 +00:00
return implode ( " \n " , $blocks );
2008-11-22 21:46:34 +00:00
default :
throw new Exception ( "@todo UNKNOWN_THEME_FUNCTION: $function " );
}
}
2008-11-27 16:19:07 +00:00
}