PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/3.0/modules/tag_albums/-- Theme Files/Grey Dragon 3.2.2/libraries/MY_Theme_View.php

http://github.com/gallery/gallery3-contrib
PHP | 920 lines | 796 code | 86 blank | 38 comment | 151 complexity | 077ef471200e96511d24aae6a90fb8ad MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, LGPL-2.1
  1. <?php defined("SYSPATH") or die("No direct script access.");
  2. /**
  3. * Grey Dragon Theme - a custom theme for Gallery 3
  4. * This theme was designed and built by Serguei Dosyukov, whose blog you will find at http://blog.dragonsoft.us
  5. * Copyright (C) 2009-2012 Serguei Dosyukov
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General
  8. * Public License as published by the Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program; if not, write to
  16. * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. ?>
  19. <?
  20. class Theme_View extends Theme_View_Core {
  21. protected $viewmode = "default";
  22. protected $toolbar_large = FALSE;
  23. protected $paginator_album;
  24. protected $paginator_photo;
  25. protected $sidebarvisible;
  26. protected $sidebarallowed;
  27. protected $sidebar_hideguest = FALSE;
  28. protected $logopath;
  29. protected $favicon = "lib/images/favicon.ico";
  30. protected $appletouchicon;
  31. protected $album_descmode = "hide";
  32. protected $disablephotopage = FALSE;
  33. protected $hidecontextmenu = FALSE;
  34. protected $thumb_ratio = "";
  35. protected $thumb_descmode_a = "overlay";
  36. protected $thumb_descmode = "overlay";
  37. protected $photo_descmode = "overlay_top";
  38. protected $thumb_imgalign = "top";
  39. protected $thumb_metamode = "default";
  40. protected $is_blockheader_visible = TRUE;
  41. protected $is_photometa_visible = FALSE;
  42. protected $disable_seosupport = FALSE;
  43. protected $mainmenu_position = "bottom-left";
  44. protected $breadcrumbs_position = "bottom-right";
  45. protected $breadcrumbs_showinroot = FALSE;
  46. protected $copyright = null;
  47. protected $show_guest_menu = FALSE;
  48. protected $loginmenu_position = "default";
  49. protected $visible_title_length = 15;
  50. protected $title_source = "default";
  51. protected $desc_allowbbcode = FALSE;
  52. protected $enable_pagecache = FALSE;
  53. protected $flex_rows = FALSE;
  54. protected $photo_popupbox = "default";
  55. protected $custom_css_path = "";
  56. protected $thumb_inpage = FALSE;
  57. protected $thumb_random = FALSE;
  58. protected $row_count = 3;
  59. protected $column_count = 3;
  60. protected $crop_factor = -1;
  61. protected $crop_class = "";
  62. protected $_thumb_size_x = 200;
  63. protected $_thumb_size_y = 200;
  64. protected $allow_root_page = FALSE;
  65. protected $show_root_page = FALSE;
  66. protected $show_root_desc = TRUE;
  67. protected $root_feed = "gallery/latest";
  68. protected $root_cyclemode = "fade";
  69. protected $root_delay = 15;
  70. protected $root_description;
  71. protected $permalinks = array("enter" => "?root=no", "root" => "?root=yes");
  72. protected $last_update = 0;
  73. protected $colorpack = "greydragon";
  74. protected $framepack = "greydragon";
  75. protected $themename = "";
  76. protected $themeversion = "";
  77. protected $themecss = array();
  78. protected $is_rtl = FALSE;
  79. protected function ensurevalue($value, $default) {
  80. if ((!isset($value)) or ($value == "")):
  81. return $default;
  82. else:
  83. return $value;
  84. endif;
  85. }
  86. protected function ensureoptionsvalue($key, $default) {
  87. return ($this->ensurevalue(module::get_var("th_greydragon", $key), $default));
  88. }
  89. public function read_session_cmdparam($cmd, $cookie, $issession, $default) {
  90. try {
  91. $_cmd = $_GET[$cmd];
  92. } catch (Exception $e) {
  93. };
  94. if (isset($_cmd)):
  95. $_var = strtolower($_cmd);
  96. $_from_cmd = TRUE;
  97. if ($_var == "default"):
  98. $_var = $default;
  99. endif;
  100. else:
  101. $_from_cmd = FALSE;
  102. if ($cookie):
  103. try {
  104. $_var = $_COOKIE[$cookie];
  105. } catch (Exception $e) {
  106. };
  107. endif;
  108. endif;
  109. if (!isset($_var)):
  110. $_var = $default;
  111. endif;
  112. if ($issession):
  113. if ($_from_cmd):
  114. setcookie($cookie, $_var, 0);
  115. endif;
  116. else:
  117. setcookie($cookie, $_var, time() + 31536000);
  118. endif;
  119. return $_var;
  120. }
  121. public function load_sessioninfo() {
  122. // Sidebar position is kept for 360 days. Can be changed via url
  123. $this->sidebarallowed = $this->ensureoptionsvalue("sidebar_allowed", "any");
  124. $_sb_visible = $this->ensureoptionsvalue("sidebar_visible", "right");
  125. if ($this->sidebarallowed == "default"):
  126. $this->sidebarallowed = $_sb_visible;
  127. $this->sidebarvisible = $_sb_visible;
  128. else:
  129. $this->sidebarvisible = $this->read_session_cmdparam("sb", "gd_sidebar_pos", FALSE, $_sb_visible);
  130. endif;
  131. $this->colorpack = $this->read_session_cmdparam("colorpack", "gd_colorpack", TRUE, $this->ensureoptionsvalue("color_pack", "greydragon"));
  132. $this->framepack = $this->read_session_cmdparam("framepack", "gd_framepack", TRUE, $this->ensureoptionsvalue("frame_pack", "greydragon"));
  133. $this->viewmode = $this->read_session_cmdparam("viewmode", "gd_viewmode", TRUE, $this->ensureoptionsvalue("viewmode", "default"));
  134. $this->is_rtl = $this->read_session_cmdparam("is_rtl", "gd_rtl", TRUE, "no") == "yes";
  135. $this->thumb_ratio = $this->read_session_cmdparam("ratio", "gd_ratio", TRUE, $this->ensureoptionsvalue("thumb_ratio", "photo"));
  136. if ($this->ensureoptionsvalue("allow_root_page", FALSE)):
  137. $_root = $this->read_session_cmdparam("root", "gd_rootpage", TRUE, "yes");
  138. $this->show_root_page = ($_root == "yes");
  139. $this->allow_root_page = TRUE;
  140. if ($this->show_root_page):
  141. $item = $this->item();
  142. if (($item) && ($item->id == item::root()->id)):
  143. if (($this->sidebarvisible == "left") or ($this->sidebarvisible == "right")):
  144. $this->sidebarvisible = "bottom";
  145. endif;
  146. else:
  147. $this->show_root_page = FALSE;
  148. setcookie("gd_rootpage", "no", 0);
  149. endif;
  150. if ($this->ensureoptionsvalue("hide_root_sidebar", FALSE)):
  151. $this->sidebarallowed = "none";
  152. $this->sidebarvisible = "none";
  153. endif;
  154. endif;
  155. endif;
  156. $this->sidebarvisible = $this->ensurevalue($this->sidebarvisible, "right");
  157. switch ($this->sidebarallowed):
  158. case "default":
  159. break;
  160. case "right":
  161. $this->sidebarvisible = "right";
  162. break;
  163. case "left":
  164. $this->sidebarvisible = "left";
  165. break;
  166. case "bottom":
  167. $this->sidebarvisible = "bottom";
  168. break;
  169. case "top":
  170. $this->sidebarvisible = "top";
  171. break;
  172. endswitch;
  173. if ($this->item()):
  174. if ($this->ensureoptionsvalue("sidebar_albumonly", FALSE)):
  175. if (!$this->item()->is_album()):
  176. $this->sidebarvisible = "none";
  177. $this->sidebarallowed = "none";
  178. endif;
  179. endif;
  180. endif;
  181. $this->sidebar_hideguest = $this->ensureoptionsvalue("sidebar_hideguest", FALSE);
  182. if ((identity::active_user()->guest) & ($this->sidebar_hideguest)):
  183. $this->sidebarvisible = "none";
  184. $this->sidebarallowed = "none";
  185. endif;
  186. if (($this->page_subtype == "login") || ($this->page_subtype == "reauthenticate") || ($this->page_subtype == "error")):
  187. $this->sidebarvisible = "none";
  188. $this->sidebarallowed = "none";
  189. endif;
  190. $this->last_update = $this->ensureoptionsvalue("last_update", time());
  191. $this->toolbar_large = $this->ensureoptionsvalue("toolbar_large", FALSE);
  192. $this->row_count = $this->ensureoptionsvalue("row_count", 3);
  193. $this->column_count = $this->ensureoptionsvalue("column_count", 3);
  194. $this->logopath = $this->ensureoptionsvalue("logo_path", url::file("lib/images/logo.png"));
  195. $this->favicon = $this->ensurevalue(module::get_var("gallery", "favicon_url"), url::file("lib/images/favicon.ico"));
  196. $this->appletouchicon = module::get_var("gallery", "apple_touch_icon_url");
  197. $this->horizontal_crop = $this->ensureoptionsvalue("horizontal_crop", FALSE);
  198. $this->album_descmode = $this->ensureoptionsvalue("album_descmode", "hide");
  199. $this->disablephotopage = $this->ensureoptionsvalue("disablephotopage", FALSE);
  200. $this->hidecontextmenu = $this->ensureoptionsvalue("hidecontextmenu", FALSE);
  201. $this->visible_title_length = module::get_var("gallery", "visible_title_length", 15);
  202. $this->title_source = $this->ensureoptionsvalue("title_source", "default");
  203. $this->thumb_descmode_a = $this->ensureoptionsvalue("thumb_descmode_a", "overlay");
  204. $this->thumb_descmode = $this->ensureoptionsvalue("thumb_descmode", "overlay");
  205. $this->photo_descmode = $this->ensureoptionsvalue("photo_descmode", "overlay_top");
  206. $this->thumb_random = $this->ensureoptionsvalue("thumb_random", FALSE);
  207. $this->thumb_imgalign = $this->ensureoptionsvalue("thumb_imgalign", "top");
  208. if (module::is_active("info")):
  209. $this->thumb_metamode = $this->ensureoptionsvalue("thumb_metamode", "default");
  210. $this->is_photometa_visible = (!$this->ensureoptionsvalue("hide_photometa", TRUE));
  211. else:
  212. $this->thumb_metamode = "hide";
  213. $this->is_photometa_visible = FALSE;
  214. endif;
  215. $this->disable_seosupport = $this->ensureoptionsvalue("disable_seosupport", FALSE);
  216. $this->is_blockheader_visible = (!$this->ensureoptionsvalue("hide_blockheader", FALSE));
  217. $this->mainmenu_position = $this->ensureoptionsvalue("mainmenu_position", "default");
  218. $this->show_guest_menu = $this->ensureoptionsvalue("show_guest_menu", FALSE);
  219. $this->breadcrumbs_position = $this->ensureoptionsvalue("breadcrumbs_position", "default");
  220. $this->breadcrumbs_showinroot = $this->ensureoptionsvalue("breadcrumbs_showinroot", FALSE);
  221. $this->desc_allowbbcode = $this->ensureoptionsvalue("desc_allowbbcode", FALSE);
  222. $this->loginmenu_position = $this->ensureoptionsvalue("loginmenu_position", "default");
  223. $this->copyright = $this->ensureoptionsvalue("copyright", null);
  224. $this->paginator_album = $this->ensureoptionsvalue("paginator_album", "top");
  225. $this->paginator_photo = $this->ensureoptionsvalue("paginator_photo", "top");
  226. $this->enable_pagecache = $this->ensureoptionsvalue("enable_pagecache", FALSE);
  227. $this->flex_rows = $this->ensureoptionsvalue("flex_rows", FALSE);
  228. $this->show_root_desc = !$this->ensureoptionsvalue("hide_root_desc", FALSE);
  229. $this->root_feed = $this->ensureoptionsvalue("root_feed", "gallery/latest");
  230. $this->root_cyclemode = $this->ensureoptionsvalue("root_cyclemode", "fade");
  231. $this->root_delay = $this->ensureoptionsvalue("root_delay", "15");
  232. $this->root_description = module::get_var("th_greydragon", "root_description");
  233. if ($this->ensureoptionsvalue("use_permalinks", FALSE)):
  234. $this->permalinks = array("enter" => "enter", "root" => "root");
  235. endif;
  236. if (((module::is_active("shadowbox")) and (module::info("shadowbox")))
  237. or ((module::is_active("fancybox")) and (module::info("fancybox")))
  238. or ((module::is_active("colorbox")) and (module::info("colorbox")))
  239. ):
  240. $this->photo_popupbox = $this->ensureoptionsvalue("photo_popupbox", "default");
  241. else:
  242. $this->photo_popupbox = "none";
  243. endif;
  244. try {
  245. $theme_info = new ArrayObject(parse_ini_file(THEMEPATH . "greydragon/theme.info"), ArrayObject::ARRAY_AS_PROPS);
  246. $this->themename = $theme_info->name;
  247. $this->themeversion = $theme_info->version;
  248. } catch (Exception $e) {
  249. $this->themename = "Grey Dragon Theme";
  250. $this->themeversion = "2.7.+";
  251. }
  252. $this->custom_css_path = $this->ensureoptionsvalue("custom_css_path", "");
  253. switch ($this->thumb_ratio):
  254. /* case "square":
  255. $this->crop_factor = 1;
  256. $this->thumb_type = 'g-thumbtype-sqr';
  257. break;
  258. */
  259. case "digital":
  260. $this->crop_factor = 4/3;
  261. $this->thumb_type = 'g-thumbtype-dgt';
  262. break;
  263. case "digital_ex":
  264. $this->crop_factor = 4/3;
  265. $this->thumb_type = 'g-thumbtype-dgt';
  266. $this->_thumb_size_x = 300;
  267. break;
  268. case "film":
  269. $this->crop_factor = 3/2;
  270. $this->thumb_type = 'g-thumbtype-flm';
  271. break;
  272. case "film_ex":
  273. $this->crop_factor = 3/2;
  274. $this->thumb_type = 'g-thumbtype-flm';
  275. $this->_thumb_size_x = 300;
  276. break;
  277. case "wide":
  278. $this->crop_factor = 16/9;
  279. $this->thumb_type = 'g-thumbtype-wd';
  280. break;
  281. case "wide_ex":
  282. $this->crop_factor = 16/9;
  283. $this->thumb_type = 'g-thumbtype-wd';
  284. $this->_thumb_size_x = 300;
  285. break;
  286. case "photo_ex":
  287. $this->crop_factor = 1;
  288. $this->thumb_type = 'g-thumbtype-sqr';
  289. $this->_thumb_size_x = 300;
  290. break;
  291. case "photo":
  292. default:
  293. $this->crop_factor = 1;
  294. $this->thumb_type = 'g-thumbtype-sqr';
  295. break;
  296. endswitch;
  297. $this->_thumb_size_y = intval($this->_thumb_size_x / $this->crop_factor);
  298. if (($this->sidebarvisible == "none") or ($this->sidebarvisible == "bottom") or ($this->sidebarvisible == "top") ):
  299. $this->thumb_inpage = $this->ensureoptionsvalue("thumb_inpage", FALSE);
  300. endif;
  301. }
  302. public function is_sidebarallowed($align) {
  303. return (($this->sidebarallowed == "any") or ($this->sidebarallowed == $align));
  304. }
  305. public function custom_header() {
  306. if (Kohana::find_file('views', "header.html", FALSE)):
  307. return new View("header.html");
  308. endif;
  309. }
  310. public function custom_footer() {
  311. if (Kohana::find_file('views', "footer.html", FALSE)):
  312. return new View("footer.html");
  313. endif;
  314. }
  315. public function get_item_title($item, $allowbbcode = FALSE, $limit_title_length = 0) {
  316. if (!$item)
  317. return "";
  318. if ($item->is_album()):
  319. $title = $item->title;
  320. else:
  321. switch ($this->title_source):
  322. case "description":
  323. $title = $item->description;
  324. break;
  325. case "no-filename":
  326. $title = $item->title;
  327. $filename = $item->name;
  328. if (strcasecmp($title, $filename) == 0):
  329. $title = "";
  330. else:
  331. if (defined('PATHINFO_FILENAME')):
  332. $filename = pathinfo($filename, PATHINFO_FILENAME);
  333. elseif (strstr($item->filename, '.')):
  334. $filename = substr($filename, 0, strrpos($filename, '.'));
  335. endif;
  336. if (strcasecmp($title, $filename) == 0):
  337. $title = "";
  338. else:
  339. $filename = item::convert_filename_to_title($filename); // Normalize filename to title format
  340. if (strcasecmp($title, $filename) == 0)
  341. $title = "";
  342. endif;
  343. endif;
  344. break;
  345. default:
  346. $title = $item->title;
  347. break;
  348. endswitch;
  349. endif;
  350. $title = html::purify($title);
  351. if ($allowbbcode):
  352. $title = $this->bb2html($title, 1);
  353. else:
  354. $title = $this->bb2html($title, 2);
  355. endif;
  356. if ($limit_title_length):
  357. $title = text::limit_chars($title, $limit_title_length);
  358. endif;
  359. if ($title === "")
  360. $title = t(ucfirst($item->type)) . " " . $item->id;
  361. return $title;
  362. }
  363. public function breadcrumb_menu($theme, $parents) {
  364. $content = "";
  365. if ($this->breadcrumbs_position == "hide"):
  366. // Begin rWatcher Edit -- Add support for $theme->breadcrumbs.
  367. elseif (!empty($theme->breadcrumbs)):
  368. $content .= '<ul class="g-breadcrumbs g-' . $this->breadcrumbs_position . '">';
  369. $i = 0;
  370. foreach ($theme->breadcrumbs as $breadcrumb):
  371. $breadcrumb_class = "";
  372. if ($breadcrumb->last) : $breadcrumb_class = "g-active"; endif;
  373. if ($breadcrumb->first) : $breadcrumb_class = "g-first"; endif;
  374. $content .= '<li class="' . $breadcrumb_class . '">';
  375. $content .= (($i > 0)? " :: " : null );
  376. if (!$breadcrumb->last): $content .= '<a href="' . $breadcrumb->url . '">'; endif;
  377. $content .= html::purify(text::limit_chars($breadcrumb->title, $this->visible_title_length));
  378. if (!$breadcrumb->last): $content .= '</a>'; endif;
  379. $content .= '</li>';
  380. $i++;
  381. endforeach;
  382. $content .= '</ul>';
  383. // End rWatcher Edit.
  384. elseif ($this->item() and (!empty($parents) or (empty($parents) and $this->breadcrumbs_showinroot))):
  385. $content .= '<ul class="g-breadcrumbs g-' . $this->breadcrumbs_position . '">';
  386. $i = 0;
  387. if (!empty($parents)):
  388. foreach ($parents as $parent):
  389. $content .= '<li ' . (($i == 0)? " class=\"g-first\"" : null) . '>';
  390. $content .= (($i > 0)? " :: " : null );
  391. $content .= '<a href="' . $parent->url($parent == $this->item()->parent() ? "show={$this->item()->id}" : null) . '">';
  392. $content .= $this->get_item_title($parent, FALSE, $this->visible_title_length);
  393. $content .= '</a></li>';
  394. $i++;
  395. endforeach;
  396. endif;
  397. $content .= '<li class="g-active ' . (($i == 0)? " g-first" : null) . '"> '. (($i > 0)? " :: " : null ) . $this->get_item_title($this->item(), FALSE, $this->visible_title_length) . '</li>';
  398. $content .= '</ul>';
  399. endif;
  400. return $content;
  401. }
  402. protected function sidebar_menu_item($type, $url, $caption, $css) {
  403. if (!$this->is_sidebarallowed($type)):
  404. return "";
  405. endif;
  406. $iscurrent = ($this->sidebarvisible == $type);
  407. $content_menu = '<li>';
  408. if (!$iscurrent):
  409. $content_menu .= '<a title="' . $caption . '" href="' . $url . '?sb=' . $type . '" rel="nofollow">';
  410. endif;
  411. $content_menu .= '<span class="ui-icon g-sidebar-' . $css;
  412. if ($iscurrent):
  413. $content_menu .= ' g-current';
  414. endif;
  415. $content_menu .= '">' . $caption . '</span>';
  416. if (!$iscurrent):
  417. $content_menu .= '</a>';
  418. endif;
  419. return $content_menu . '</li>';
  420. }
  421. public function sidebar_menu($url) {
  422. if ($this->sidebarallowed != "any"):
  423. return "";
  424. endif;
  425. if ($this->page_subtype == "profile"):
  426. return "";
  427. endif;
  428. $content_menu = $this->sidebar_menu_item("left", $url, t("Sidebar Left"), "left");
  429. $content_menu .= $this->sidebar_menu_item("top", $url, t("Sidebar Top"), "top");
  430. $content_menu .= $this->sidebar_menu_item("none", $url, t("No Sidebar"), "full");
  431. $content_menu .= $this->sidebar_menu_item("bottom", $url, t("Sidebar Bottom"), "bottom");
  432. $content_menu .= $this->sidebar_menu_item("right", $url, t("Sidebar Right"), "right");
  433. return '<ul id="g-viewformat">' . $content_menu . '</ul>';
  434. }
  435. public function add_paginator($position, $isalbum = TRUE) {
  436. if ($isalbum):
  437. $check = (($this->paginator_album == "both") or ($this->paginator_album == $position));
  438. else:
  439. $check = (($this->paginator_photo == "both") or ($this->paginator_photo == $position));
  440. endif;
  441. if ($check):
  442. return ($this->paginator());
  443. else:
  444. return "";
  445. endif;
  446. }
  447. public function get_bodyclass() {
  448. $body_class = "";
  449. if ($this->is_rtl):
  450. $body_class = "rtl";
  451. endif;
  452. if ($this->toolbar_large):
  453. $body_class .= " g-toolbar-large";
  454. endif;
  455. if ($this->viewmode == "mini"):
  456. $body_class .= " viewmode-mini";
  457. endif;
  458. $body_class .= " g-sidebar-" . $this->sidebarvisible;
  459. switch ($this->column_count):
  460. case 5:
  461. $body_class .= " g-column-5";
  462. break;
  463. case 4:
  464. $body_class .= " g-column-4";
  465. break;
  466. case 2:
  467. $body_class .= " g-column-2";
  468. break;
  469. case -1:
  470. $body_class .= " g-column-flex";
  471. break;
  472. case 3:
  473. default:
  474. $body_class .= " g-column-3";
  475. break;
  476. endswitch;
  477. switch ($this->thumb_ratio):
  478. case "digital_ex":
  479. case "film_ex":
  480. case "wide_ex":
  481. case "photo_ex":
  482. $body_class .= ' g-extended';
  483. break;
  484. default:
  485. break;
  486. endswitch;
  487. $body_class .= " g-" . $this->framepack;
  488. return 'class="' . trim($body_class) . '"';
  489. }
  490. public function get_thumb_link($item) {
  491. if ($item->is_album()):
  492. return "";
  493. endif;
  494. if (item::viewable($item)):
  495. if (access::can("view_full", $item)):
  496. $direct_link = $item->file_url();
  497. else:
  498. $direct_link = $item->resize_url();
  499. endif;
  500. return '<a title="' . $this->get_item_title($item) . '" style="display: none;" class="g-sb-preview" rel="g-preview" href="' . $direct_link . '">&nbsp;</a>';
  501. else:
  502. return "";
  503. endif;
  504. }
  505. public function get_thumb_element($item, $addcontext = FALSE, $linkonly = FALSE) {
  506. $thumb_item = $item;
  507. if ($this->thumb_random):
  508. if ($item->is_album() && ($rnd = item::random_query()->where("parent_id", "=", $item->id)->find()) && $rnd->loaded()):
  509. $thumb_item = $rnd;
  510. endif;
  511. endif;
  512. $item_class = $item->is_album() ? "g-album" : "g-photo";
  513. $content = '<li id="g-item-id-' . $item->id . '" class="g-item ' . $item_class . ' ' . $this->thumb_type;
  514. if ($item->is_album()):
  515. $_thumb_descmode = $this->thumb_descmode_a;
  516. else:
  517. $_thumb_descmode = $this->thumb_descmode;
  518. endif;
  519. $content .= ($_thumb_descmode == "bottom")? " g-expanded" : " g-default";
  520. if ($thumb_item->has_thumb()):
  521. $is_portrait = ($thumb_item->thumb_height > $thumb_item->thumb_width);
  522. $_shift = "";
  523. switch ($this->thumb_imgalign):
  524. case "center":
  525. if (($this->crop_factor == 1) and (!$is_portrait)):
  526. $_shift = 'style="margin-top: ' . intval(($this->_thumb_size_y - $thumb_item->thumb_height) / 2) . 'px;"';
  527. elseif ($this->crop_factor > 0):
  528. $_shift = 'style="margin-top: -' . intval(($thumb_item->thumb_height - $this->_thumb_size_y) / 2) . 'px;"';
  529. endif;
  530. break;
  531. case "bottom":
  532. if (($this->crop_factor == 1) and (!$is_portrait)):
  533. $_shift = 'style="margin-top: ' . intval($this->_thumb_size_y - $thumb_item->thumb_height) . 'px;"';
  534. elseif ($this->crop_factor > 0):
  535. $_shift = 'style="margin-top: -' . intval($thumb_item->thumb_height - $this->_thumb_size_y) . 'px;"';
  536. endif;
  537. break;
  538. case "fit":
  539. break;
  540. case "top":
  541. default:
  542. break;
  543. endswitch;
  544. else:
  545. $is_portrait = FALSE;
  546. $_shift = 'style="margin-top: 0px;"';
  547. endif;
  548. $content .= ($is_portrait)? " g-portrait" : " g-landscape";
  549. $content .= '">' . $this->thumb_top($item);
  550. $content .= '<div class="g-thumbslide">';
  551. $thumb_content = '<p class="g-thumbcrop">';
  552. $use_direct_link = (($this->disablephotopage) && (!$item->is_album()));
  553. $class_name = "g-thumblink";
  554. if ($use_direct_link):
  555. $class_name .= ' g-sb-preview" rel="g-preview';
  556. if (access::can("view_full", $item)):
  557. $direct_link = $item->file_url();
  558. else:
  559. $direct_link = $item->resize_url();
  560. endif;
  561. else:
  562. $direct_link = $item->url();
  563. endif;
  564. if ($use_direct_link && module::is_active("exif") && module::info("exif")):
  565. $thumb_content .= '<a class="g-meta-exif-link g-dialog-link" href="' . url::site("exif/show/{$item->id}") . '" title="' . t("Photo details")->for_html_attr() . '">&nbsp;</a>';
  566. endif;
  567. $thumb_content .= '<a title="' . $this->get_item_title($item) . '" '. $_shift . ' class="' . $class_name . '" href="' . $direct_link . '">';
  568. if ($thumb_item->has_thumb()):
  569. if (($this->crop_factor > 1) && ($this->thumb_imgalign == "fit")):
  570. if ($thumb_item->thumb_height > $this->_thumb_size_y):
  571. if ($is_portrait):
  572. $_max = $this->_thumb_size_y;
  573. else:
  574. $_max = intval($this->_thumb_size_x * ($this->_thumb_size_y / $thumb_item->thumb_height));
  575. endif;
  576. else:
  577. $_max = $this->_thumb_size_x;
  578. endif;
  579. $_max = min($thumb_item->thumb_width, $_max);
  580. $thumb_content .= $thumb_item->thumb_img(array(), $_max);
  581. else:
  582. $thumb_content .= $thumb_item->thumb_img();
  583. endif;
  584. else:
  585. $thumb_content .= '<img title="No Image" alt="No Image" src="' . $this->url("images/missing-img.png") . '"/>';
  586. endif;
  587. $thumb_content .= '</a></p>';
  588. if (($this->thumb_metamode != "hide") and ($_thumb_descmode == "overlay_bottom")):
  589. $_thumb_metamode = "merged";
  590. else:
  591. $_thumb_metamode = $this->thumb_metamode;
  592. endif;
  593. if (($_thumb_descmode == "overlay") or ($_thumb_descmode == "overlay_top") or ($_thumb_descmode == "overlay_bottom")):
  594. $thumb_content .= '<ul class="g-description ';
  595. if ($_thumb_descmode == "overlay_top"):
  596. $thumb_content .= 'g-overlay-top';
  597. endif;
  598. if ($_thumb_descmode == "overlay_bottom"):
  599. $thumb_content .= 'g-overlay-bottom';
  600. endif;
  601. $thumb_content .= '"><li class="g-title">' . $this->get_item_title($item, FALSE, $this->visible_title_length) . '</li>';
  602. if ($_thumb_metamode == "merged"):
  603. $thumb_content .= $this->thumb_info($item);
  604. endif;
  605. $thumb_content .= '</ul>';
  606. endif;
  607. if (($_thumb_metamode == "default") and ($_thumb_descmode != "overlay_bottom")):
  608. $thumb_content .= '<ul class="g-metadata">' . $this->thumb_info($item) . '</ul>';
  609. endif;
  610. if ($_thumb_descmode == "bottom"):
  611. $thumb_content .= '<ul class="g-description">';
  612. $thumb_content .= '<li class="g-title">' . $this->get_item_title($item) . '</li>';
  613. if ($_thumb_metamode == "merged"):
  614. $thumb_content .= $this->thumb_info($item);
  615. endif;
  616. $thumb_content .= '</ul>';
  617. endif;
  618. if ($addcontext):
  619. $_text = $this->context_menu($item, "#g-item-id-{$item->id} .g-thumbnail");
  620. $thumb_content .= (stripos($_text, '<li>'))? $_text : null;
  621. endif;
  622. try {
  623. $view = new View("frame.html");
  624. $view->thumb_content = $thumb_content;
  625. $content .= $view;
  626. } catch (Exception $e) {
  627. $content .= $thumb_content;
  628. }
  629. $content .= '</div>';
  630. $content .= $this->thumb_bottom($item);
  631. $content .= '</li>';
  632. return $content;
  633. }
  634. public function get_block_html($module) {
  635. $active = block_manager::get_active("site_sidebar");
  636. $result = "";
  637. foreach ($active as $id => $desc) {
  638. if (($desc[0] == $module) and (method_exists("$desc[0]_block", "get"))) {
  639. $block = call_user_func(array("$desc[0]_block", "get"), $desc[1], $this);
  640. if (!empty($block)) {
  641. $block->id = $id;
  642. $block->css_id = $block->css_id . "-inline";
  643. $result .= $block;
  644. }
  645. }
  646. }
  647. return $result;
  648. }
  649. public function css_link($file, $direct = FALSE) {
  650. if (!$direct):
  651. $file = $this->url("css/" . $file);
  652. endif;
  653. return "\n<link rel=\"stylesheet\" href=\"" . $file . "\" type=\"text/css\" media=\"screen,print,projection\" />\n";
  654. }
  655. public function custom_css_inject($direct) {
  656. $_css = $this->custom_css_path;
  657. if ($_css != ""):
  658. $_fileonly = (stripos($_css, '/') === FALSE);
  659. if ($_fileonly):
  660. if (!$direct):
  661. return $this->css($_css);
  662. endif;
  663. else:
  664. if ($direct):
  665. return $this->css_link($_css, TRUE);
  666. endif;
  667. endif;
  668. else:
  669. return "";
  670. endif;
  671. }
  672. public function theme_js_inject() {
  673. $js = "";
  674. if ($this->show_root_page):
  675. $js .= $this->script("jquery.cycle.js");
  676. endif;
  677. // $js .= $this->script("jquery.touchslider.js");
  678. $js .= $this->script("ui.support.js");
  679. return $js;
  680. }
  681. public function theme_css_inject() {
  682. $css = $this->css("screen.css");
  683. $css .= $this->css("colors.css");
  684. $css .= $this->css("frame.css");
  685. $css .= $this->custom_css_inject(FALSE);
  686. return $css;
  687. }
  688. public function credits() {
  689. if (module::get_var("gallery", "show_credits")):
  690. $version_string = SafeString::of_safe_html('Gallery ' . gallery::VERSION);
  691. return '<ul id="g-credits">'
  692. . '<li class="g-branding"><a id="g-gallery-logo" href="http://gallery.menalto.com" title="' . $version_string . '"></a>'
  693. . '<a id="g-theme-logo" href="http://codex.gallery2.org/Gallery3:Themes:greydragon" target="_blank" title="' . $this->themename . ' ' . $this->themeversion . ' (' . $this->colorpack . ')"></a></li>'
  694. . gallery_theme::credits()
  695. . '</ul>';
  696. else:
  697. return '';
  698. endif;
  699. }
  700. // $mode: bit 1 - use mix mode ($mode in [1, 3]), bit 2 - strips bbcode ($mode in [2, 3])
  701. public function bb2html($text, $mode) {
  702. // Syntax Sample:
  703. // --------------
  704. // [img]http://elouai.com/images/star.gif[/img]
  705. // [url="http://elouai.com"]eLouai[/url]
  706. // [size="25"]HUGE[/size]
  707. // [color="red"]RED[/color]
  708. // [b]bold[/b]
  709. // [i]italic[/i]
  710. // [u]underline[/u]
  711. // [list][*]item[*]item[*]item[/list]
  712. // [code]value="123";[/code]
  713. // [quote]John said yadda yadda yadda[/quote]
  714. static $bbcode_mappings = array(
  715. "#\\[b\\](.*?)\\[/b\\]#" => "<strong>$1</strong>",
  716. "#\\[i\\](.*?)\\[/i\\]#" => "<em>$1</em>",
  717. "#\\[u\\](.*?)\\[/u\\]#" => "<u>$1</u>",
  718. "#\\[s\\](.*?)\\[/s\\]#" => "<strike>$1</strike>",
  719. "#\\[o\\](.*?)\\[/o\\]#" => "<overline>$1</overline>",
  720. "#\\[url\\](.*?)\[/url\\]#" => "<a href=\"$1\">$1</a>",
  721. "#\\[url=(.*?)\\](.*?)\[/url\\]#" => "<a href=\"$1\" target=\"_blank\">$2</a>",
  722. "#\\[mail=(.*?)\\](.*?)\[/mail\\]#" => "<a href=\"mailto:$1\" target=\"_blank\">$2</a>",
  723. "#\\[img\\](.*?)\\[/img\\]#" => "<img src=\"$1\" alt=\"\" />",
  724. "#\\[img=(.*?)\\](.*?)\[/img\\]#" => "<img src=\"$1\" alt=\"$2\" />",
  725. "#\\[quote\\](.*?)\\[/quote\\]#" => "<blockquote><p>$1</p></blockquote>",
  726. "#\\[code\\](.*?)\\[/code\\]#" => "<pre>$1</pre>",
  727. "#\\[size=([^\\[]*)\\]([^\\[]*)\\[/size\\]#" => "<span style=\"font-size: $1;\">$2</span>",
  728. "#\\[color=([^\\[]*)\\]([^\\[]*)\\[/color\\]#" => "<span style=\"color: $1;\">$2</span>",
  729. "#\\[class=([^\\[]*)\\]([^\\[]*)\\[/class\\]#" => "<span class=\"$1\">$2</span>",
  730. "#\\[center\\](.*?)\\[/center\\]#" => "<div style=\"text-align: center;\">$1</div>",
  731. "#\\[list\\](.*?)\\[/list\\]#" => "<ul>$1</ul>",
  732. "#\\[ul\\](.*?)\\[/ul\\]#" => "<ul>$1</ul>",
  733. "#\\[li\\](.*?)\\[/li\\]#" => "<li>$1</li>",
  734. );
  735. static $bbcode_strip = '|[[\/\!]*?[^\[\]]*?]|si';
  736. if (($mode == 1) or ($mode == 3)):
  737. $newtext = str_replace("&lt;", "<", $text);
  738. $newtext = str_replace("&gt;", ">", $newtext);
  739. $newtext = str_replace("&quot;", "\"", $newtext);
  740. else:
  741. // Replace any html brackets with HTML Entities to prevent executing HTML or script
  742. $newtext = str_replace("<", "&lt;", $text);
  743. $newtext = str_replace(">", "&gt;", $newtext);
  744. $newtext = str_replace("&amp;quot;", "&quot;", $newtext);
  745. endif;
  746. // Convert new line chars to html <br /> tags
  747. $newtext = nl2br($newtext);
  748. if (strpos($text, "[") !== false):
  749. if (($mode == 2) or ($mode == 3)):
  750. $newtext = preg_replace($bbcode_strip, '', $newtext);
  751. else:
  752. $newtext = preg_replace(array_keys($bbcode_mappings), array_values($bbcode_mappings), $newtext);
  753. endif;
  754. endif;
  755. return stripslashes($newtext); //stops slashing, useful when pulling from db
  756. }
  757. function curl_get_file_contents($url) {
  758. $curl = curl_init();
  759. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  760. curl_setopt($curl, CURLOPT_URL, $url);
  761. $contents = curl_exec($curl);
  762. curl_close($curl);
  763. if ($contents):
  764. return $contents;
  765. else:
  766. return FALSE;
  767. endif;
  768. }
  769. function valid_url($str) {
  770. return ( ! preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $str)) ? FALSE : TRUE;
  771. }
  772. function get_slideshow_list($limit = 10) {
  773. if( ! function_exists('simplexml_load_string'))
  774. throw new Kohana_User_Exception('Feed Error', 'SimpleXML must be installed!');
  775. $items = array();
  776. $host = 'http://' . $_SERVER['SERVER_NAME'] . '/';
  777. $feed_url = $this->root_feed;
  778. if (!$this->valid_url($feed_url)):
  779. $feed_url = $host . $feed_url;
  780. endif;
  781. $use_file_load = ($this->valid_url($feed_url)) || is_file($feed_url);
  782. $er = error_reporting(0);
  783. // Try to get feed directly
  784. try {
  785. try {
  786. if ($use_file_load):
  787. $feed = simplexml_load_file($feed_url, 'SimpleXMLElement', LIBXML_NOCDATA);
  788. else:
  789. $feed = simplexml_load_string($feed_url, 'SimpleXMLElement', LIBXML_NOCDATA);
  790. endif;
  791. } catch (Exception $e) {
  792. }
  793. } catch (Exception $e) {
  794. };
  795. if (isset($feed) && ($feed)):
  796. // Direct load worked fine
  797. else:
  798. // Direct load did not work, let's try CURL (URL file-access is disabled ?)
  799. try {
  800. $file = $this->curl_get_file_contents($feed_url);
  801. if ($file):
  802. $feed = simplexml_load_string($file, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS);
  803. endif;
  804. } catch (Exception $e) {
  805. };
  806. endif;
  807. error_reporting($er);
  808. if (isset($feed) && ($feed)):
  809. $feed = isset($feed->channel) ? $feed->channel->xpath("//media:content[contains(@url, 'var/resizes')]") : array();
  810. $i = 0;
  811. foreach ($feed as $item):
  812. if ($limit > 0 AND $i++ === $limit)
  813. break;
  814. $items[] = (array) $item;
  815. endforeach;
  816. endif;
  817. return $items;
  818. }
  819. }
  820. ?>