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
2011-01-21 23:01:06 -08:00
* Copyright ( C ) 2000 - 2011 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 ) {
2009-01-11 00:19:00 +00:00
$this -> theme_name = Input :: instance () -> get ( " theme " , $this -> theme_name );
}
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-11-17 13:42:51 -08:00
if ( $page_type == " collection " ) {
2009-05-09 22:22:30 +00:00
$this -> set_global ( " thumb_proportion " , $this -> thumb_proportion ());
}
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
/**
* Proportion of the current thumb_size ' s to default
* @ return int
*/
public function thumb_proportion () {
// @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.
2009-11-19 11:44:01 -08:00
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
}
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
}
2009-11-14 14:25:39 -08:00
/**
* Set up the data and render a pager .
*
* See themes / wind / views / pager . html for documentation on the variables generated here .
*/
2009-11-14 16:18:49 -08:00
public function paginator () {
$v = new View ( " paginator.html " );
2009-11-14 14:25:39 -08:00
$v -> page_type = $this -> page_type ;
2009-11-17 13:42:51 -08:00
$v -> page_subtype = $this -> page_subtype ;
2009-11-14 14:25:39 -08:00
$v -> first_page_url = null ;
$v -> previous_page_url = null ;
$v -> next_page_url = null ;
$v -> last_page_url = null ;
2009-11-17 13:42:51 -08:00
if ( $this -> page_type == " collection " ) {
2009-11-14 14:25:39 -08:00
$v -> page = $this -> page ;
$v -> max_pages = $this -> max_pages ;
$v -> total = $this -> children_count ;
2009-11-14 16:18:49 -08:00
2009-11-14 14:25:39 -08:00
if ( $this -> page != 1 ) {
2009-11-15 15:24:49 -08:00
$v -> first_page_url = url :: site ( url :: merge ( array ( " page " => 1 )));
$v -> previous_page_url = url :: site ( url :: merge ( array ( " page " => $this -> page - 1 )));
2009-11-14 14:25:39 -08:00
}
if ( $this -> page != $this -> max_pages ) {
2009-11-15 15:24:49 -08:00
$v -> next_page_url = url :: site ( url :: merge ( array ( " page " => $this -> page + 1 )));
$v -> last_page_url = url :: site ( url :: merge ( array ( " page " => $this -> max_pages )));
2009-11-14 14:25:39 -08:00
}
$v -> first_visible_position = ( $this -> page - 1 ) * $this -> page_size + 1 ;
2009-11-18 11:26:19 -08:00
$v -> last_visible_position = min ( $this -> page * $this -> page_size , $v -> total );
2009-11-20 20:29:49 -08:00
} else if ( $this -> page_type == " item " ) {
2009-11-14 14:25:39 -08:00
$v -> position = $this -> position ;
$v -> total = $this -> sibling_count ;
2009-11-15 15:24:49 -08:00
if ( $this -> previous_item ) {
2009-11-14 14:25:39 -08:00
$v -> previous_page_url = $this -> previous_item -> url ();
}
2009-11-15 15:24:49 -08:00
if ( $this -> next_item ) {
2009-11-14 14:25:39 -08:00
$v -> next_page_url = $this -> next_item -> url ();
}
2009-03-08 03:57:02 +00:00
}
2009-11-14 14:25:39 -08:00
return $v ;
2008-11-07 07:33:43 +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 " ;
2008-11-25 02:17:53 +00:00
if ( 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 " ;
if ( method_exists ( $helper_class , $function )) {
$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
}