PageRenderTime 95ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/content/rokbox.php

https://bitbucket.org/ericrlarson/com_biblestudy
PHP | 276 lines | 187 code | 52 blank | 37 comment | 88 complexity | 6cdcaf49a1e33dbee5fe2899e28460c3 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * @package rokbox
  4. * @subpackage plg_content_rokbox
  5. * @version 1.6 August 10, 2010
  6. * @author RocketTheme http://www.rockettheme.com
  7. * @copyright Copyright (C) 2007 - 2010 RocketTheme, LLC
  8. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  9. **/
  10. // no direct access
  11. defined( '_JEXEC' ) or die();
  12. jimport( 'joomla.plugin.plugin' );
  13. require_once(dirname(__FILE__) . '/rokbox/imagehandler.php');
  14. /**
  15. * @package rokbox
  16. * @subpackage plg_content_rokbox
  17. */
  18. class plgContentRokbox extends JPlugin
  19. {
  20. function plgContentRokbox( &$subject, $params )
  21. {
  22. parent::__construct( $subject, $params );
  23. }
  24. function onPrepareContent( &$article, &$params, $limitstart )
  25. {
  26. global $mainframe;
  27. // simple performance check to determine whether bot should process further
  28. if ( strpos( $article->text, 'rokbox' ) === false ) {
  29. return true;
  30. }
  31. // Get plugin info
  32. $plugin =& JPluginHelper::getPlugin('content', 'rokbox');
  33. // define the regular expression for the bot
  34. $regex = "#{rokbox(.*?)}(.*?){/rokbox}#s";
  35. $pluginParams = new JParameter( $plugin->params );
  36. // check whether plugin has been unpublished
  37. if ( !$pluginParams->get( 'enabled', 1 ) ) {
  38. $article->text = preg_replace( $regex, '', $row->text );
  39. return true;
  40. }
  41. // find all instances of plugin and put in $matches
  42. preg_match_all( $regex, $article->text, $matches );
  43. // Number of plugins
  44. $count = count( $matches[0] );
  45. // plugin only processes if there are any instances of the plugin in the text
  46. if ( $count ) {
  47. // Get plugin parameters
  48. $style = $pluginParams->def( 'style', -2 );
  49. $this->plgContentProcessRokboxImages( $article, $matches, $count, $regex, $pluginParams );
  50. }
  51. }
  52. function plgContentProcessRokboxImages( &$row, &$matches, $count, $regex, &$botParams ) {
  53. global $mainframe;
  54. $thumb_ext = $botParams->def( 'thumb_ext', '_thumb');
  55. $thumb_class = $botParams->def( 'thumb_class', 'album');
  56. $thumb_width = $botParams->def( 'thumb_width', '100');
  57. $thumb_height = $botParams->def( 'thumb_height', '100');
  58. $thumb_quality = $botParams->def( 'thumb_quality', '90');
  59. $thumb_custom = $botParams->def( 'thumb_custom', 0);
  60. $thumb_dir = $botParams->def( 'thumb_dir');
  61. $compatibility = $botParams->def( 'compatibility', 'rokbox');
  62. /* thumbnail settings */
  63. $improve_thumbnails = false; // Auto Contrast, Unsharp Mask, Desaturate, White Balance
  64. $thumb_quality = $thumb_quality;
  65. $width = $thumb_size_width = $thumb_width;
  66. $height = $thumb_size_height = $thumb_height;
  67. /* slimbox = lightbox mode */
  68. if ($compatibility == "slimbox") $compatibility = "lightbox";
  69. for ( $i=0; $i < $count; $i++ )
  70. {
  71. $thealbum = '';
  72. $thetitle = '';
  73. $thethumb = '';
  74. $thetype = '';
  75. $thesize = '';
  76. $thetext = '';
  77. $themodule = '';
  78. $thethumbsize = '';
  79. $thethumbcount = 999;
  80. if (@$matches[1][$i]) {
  81. $inline_params = $matches[1][$i];
  82. // get album
  83. $album_matches = array();
  84. preg_match( "# album=\|(.*?)\|#s", $inline_params, $album_matches );
  85. if (isset($album_matches[1])) $thealbum = "(" . trim($album_matches[1]) . ")";
  86. // get size
  87. $size_matches = array();
  88. preg_match( "# size=\|(.*?)\|#s", $inline_params, $size_matches );
  89. if (isset($size_matches[1])) $thesize = "[" . trim($size_matches[1]) . "]";
  90. // get title
  91. $title_matches = array();
  92. preg_match( "# title=\|(.*?)\|#s", $inline_params, $title_matches );
  93. if (isset($title_matches[1])) $thetitle = $title_matches[1];
  94. // get text
  95. $text_matches = array();
  96. preg_match( "# text=\|(.*?)\|#s", $inline_params, $text_matches );
  97. if (isset($text_matches[1])) $thetext = $text_matches[1];
  98. // force image
  99. $type_matches = array();
  100. preg_match( "# type=\|(.*?)\|#s", $inline_params, $type_matches );
  101. if (isset($type_matches[1])) $thetype = $type_matches[1];
  102. // get module
  103. $module_matches = array();
  104. preg_match( "# module=\|(.*?)\|#s", $inline_params, $module_matches );
  105. if (isset($module_matches[1])) $themodule = "[module=".$module_matches[1]."]";
  106. // get thumb
  107. $thumb_matches = array();
  108. preg_match( "# thumb=\|(.*?)\|#s", $inline_params, $thumb_matches );
  109. if (isset($thumb_matches[1])) $thethumb = $thumb_matches[1];
  110. // get thumb sizes
  111. $thumbsize_matches = array();
  112. preg_match( "# thumbsize=\|(.*?)\|#s", $inline_params, $thumbsize_matches );
  113. $thumb_size_width = $thumb_width;
  114. $thumb_size_height = $thumb_height;
  115. if (isset($thumbsize_matches[1])) {
  116. $thethumbsize = $thumbsize_matches[1];
  117. $tsize = explode(" ", $thethumbsize);
  118. if (count($tsize) == 1) {$thumb_size_width = $thumb_size_height = $tsize[0];}
  119. elseif (count($tsize) == 2) {
  120. $thumb_size_width = $tsize[0];
  121. $thumb_size_height = $tsize[1];
  122. }
  123. }
  124. // get thumb count
  125. $thumbcount_matches = array();
  126. preg_match( "# thumbcount=\|(.*?)\|#s", $inline_params, $thumbcount_matches );
  127. if (isset($thumbcount_matches[1])) $thethumbcount = $thumbcount_matches[1];
  128. }
  129. $onsite=1;
  130. $text = '';
  131. $displaythumb = '';
  132. $tmp = @glob(trim($matches[2][$i]));
  133. if (count($tmp) < 1) {
  134. $tmp = array(trim($matches[2][$i]));
  135. $onsite=0;
  136. }
  137. if (!is_array($tmp)) $tmp = array(trim($matches[2][$i]));
  138. if (count($tmp) > 1) {
  139. $text .= '<div class="rokbox-album-wrapper">';
  140. $text .= '<div class="rokbox-album-top"><div class="rokbox-album-top2"><div class="rokbox-album-top3"></div></div></div>';
  141. $text .= '<div class="rokbox-album-inner">';
  142. }
  143. foreach ($tmp as $link){
  144. if (count($tmp) > 1) {
  145. // Check for files only
  146. if (!is_file($link)) continue;
  147. // Check for images only
  148. $last3 = strtolower(substr($link, -3));
  149. $last4 = strtolower(substr($link, -4));
  150. if ($last3 != "jpg" && $last3 != "png" && $last3 != "bmp" && $last3 != "gif" && $last4 != "jpeg") continue;
  151. }
  152. // Prevent thumbs of thumbs
  153. if ( strpos( $link, $thumb_ext ) === false ) {
  154. if (strlen($thethumb)) $image_url = trim($thethumb);
  155. else $image_url = $link;
  156. $extension = substr($image_url,strrpos($image_url,"."));
  157. $image_name = substr($image_url,0,strrpos($image_url, "."));
  158. $just_name = substr($image_name,strrpos($image_name,DS));
  159. $full_url = JURI::base() . $link;
  160. $full_path = JPATH_ROOT . DS . $link;
  161. $thumb_url_custom = JURI::base() . $thumb_dir . DS . $just_name . $thumb_ext . $extension;
  162. $thumb_path_custom = JPATH_ROOT. DS . $thumb_dir . DS . $just_name . $thumb_ext . $extension;
  163. $thumb_url = JURI::base() . $image_name . $thumb_ext . $extension;
  164. $thumb_path = JPATH_ROOT . DS . $image_name . $thumb_ext . $extension;
  165. $isimage = ($extension == '.jpg' || $extension == '.jpeg' || $extension == '.bmp' || $extension == '.png' || $extension == '.gif' ||
  166. $extension == '.JPG' || $extension == '.JPEG' || $extension == '.BMP' || $extension == '.PNG' || $extension == '.GIF');
  167. if ($onsite){
  168. if (!isset($size_matches[1]) && $isimage) {
  169. list($image_width,$image_height)=getimagesize($link);
  170. $thesize = "[" . $image_width . " " . $image_height . "]";
  171. }
  172. $thethumbcount--;
  173. if ($thethumbcount<0) $displaythumb = '" style="display: none;';
  174. } else {
  175. if ($isimage && !isset($size_matches[1]) && $botParams->get('remote_sizes', 0)) {
  176. $remoteSize = @getimagesize($link);
  177. if ($remoteSize) {
  178. list($image_width,$image_height)=$remoteSize;
  179. $thesize = "[" . $image_width . " " . $image_height . "]";
  180. }
  181. }
  182. }
  183. if (!strlen($thethumb) && !strlen($thetype) && strlen($thetext) > 0) {
  184. if (strlen($themodule)) $text = $text . '<a href="' . $link . '" rel="' . $compatibility . $thesize . $thealbum . $displaythumb . $themodule .'" title="' . $thetitle . '">'.$thetext.'</a>';
  185. else $text = $text . '<a href="' . $link . '" rel="' . $compatibility . $thesize . $thealbum . $displaythumb . '" title="' . $thetitle . '">'.$thetext.'</a>';
  186. } else if (!strlen($thethumb) && !strlen($thetype) && !$isimage) {
  187. if (strlen($themodule)) $text = $text . '<a href="' . $link . '" rel="' . $compatibility . $thesize . $thealbum . $displaythumb . $themodule .'" title="' . $thetitle . '">'.$thetitle.'</a>';
  188. else $text = $text . '<a href="' . $link . '" rel="' . $compatibility . $thesize . $thealbum . $displaythumb . '" title="' . $thetitle . '">'.$thetitle.'</a>';
  189. } else {
  190. if (strlen($thethumb) > 0) {
  191. if (strlen($themodule)) $text = $text . '<a href="' . $link . '" rel="' . $compatibility . $thesize . $thealbum . $displaythumb . $themodule . '" title="' . $thetitle . '"><img class="'. $thumb_class . '" src="' . $thethumb . '" alt="' . $thetitle . '" width="'.$thumb_size_width.'" height="'.$thumb_size_height.'" /></a>';
  192. else $text = $text . '<a href="' . $link . '" rel="' . $compatibility . $thesize . $thealbum . $displaythumb . '" title="' . $thetitle . '"><img class="'. $thumb_class . '" src="' . $thethumb . '" alt="' . $thetitle . '" width="'.$thumb_size_width.'" height="'.$thumb_size_height.'" /></a>';
  193. } elseif (!$thumb_custom && file_exists($thumb_path)) {
  194. // thumbnail exists so can do lightbox with thumbnail
  195. if (strlen($themodule)) $text = $text . '<a href="' . $link . '" rel="' . $compatibility . $thesize . $thealbum . $displaythumb . $themodule . '" title="' . $thetitle . '"><img class="'. $thumb_class . '" src="' . $thumb_url . '" alt="' . $thetitle . '" width="'.$thumb_size_width.'" height="'.$thumb_size_height.'" /></a>';
  196. else $text = $text . '<a href="' . $link . '" rel="' . $compatibility . $thesize . $thealbum . $displaythumb . '" title="' . $thetitle . '"><img class="'. $thumb_class . '" src="' . $thumb_url . '" alt="' . $thetitle . '" width="'.$thumb_size_width.'" height="'.$thumb_size_height.'" /></a>';
  197. } elseif (file_exists($thumb_path_custom)) {
  198. if (strlen($themodule)) $text = $text . '<a href="' . $link . '" rel="' . $compatibility . $thesize . $thealbum . $displaythumb . $themodule . '" title="' . $thetitle . '"><img class="'. $thumb_class . '" src="' . $thumb_url_custom . '" alt="' . $thetitle . '" width="'.$thumb_size_width.'" height="'.$thumb_size_height.'" /></a>';
  199. else $text = $text . '<a href="' . $link . '" rel="' . $compatibility . $thesize . $thealbum . $displaythumb . '" title="' . $thetitle . '"><img class="'. $thumb_class . '" src="' . $thumb_url_custom . '" alt="' . $thetitle . '" width="'.$thumb_size_width.'" height="'.$thumb_size_height.'" /></a>';
  200. } elseif ($isimage || $thetype == 'image') {
  201. //try to generate thumbs
  202. if ($thumb_custom) $thumb_path = $thumb_path_custom;
  203. $rd = new imgRedim(false, $improve_thumbnails, JPATH_CACHE);
  204. $image_filename = $full_path; // define source image here
  205. $output_filename = $thumb_path; // define destination image here
  206. $rd->loadImage($image_filename);
  207. $rd->redimToSize($width, $height, true);
  208. $rd->saveImage($output_filename, $thumb_quality);
  209. $text = $text . '<a href="' . $link . '" rel="' . $compatibility . $thesize . $thealbum . $displaythumb . '" title="' . $thetitle . '"><img class="'. $thumb_class . '" src="' . $thumb_url . '" alt="' . $thetitle . '" width="'.$thumb_size_width.'" height="'.$thumb_size_height.'" /></a>';
  210. }
  211. }
  212. $text = $text . ' ';
  213. }
  214. }
  215. if (count($tmp) > 1) {
  216. $text .= '</div>';
  217. $text .= '<div class="rokbox-album-bottom"><div class="rokbox-album-bottom2"><div class="rokbox-album-bottom3"></div></div></div>';
  218. $text .= '</div>';
  219. }
  220. $row->text = str_replace( $matches[0][$i], $text, $row->text );
  221. }
  222. }
  223. }
  224. ?>