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

/hs4smf-Subs.php

https://github.com/butch2k/SMF-HS4SMF
PHP | 1485 lines | 1131 code | 116 blank | 238 comment | 153 complexity | 6958520a6bbf313b35068a6ac1f45812 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. *
  4. * @package "Highslide 4 SMF (HS-4-SMF)" Mod for Simple Machines Forum (SMF) V2.0
  5. * @author Spuds
  6. * @copyright (c) 2011 Spuds
  7. * @license Mozilla Public License version 1.1 http://www.mozilla.org/MPL/1.1/.
  8. *
  9. * @version 0.8.2
  10. *
  11. * -----------------------------------------------------------------------------------------------
  12. * Adds a highslide 'lighbox' effect to images and attachments. With the mod enabled all images
  13. * and optionally attachments will expand in place inside of a nice web2.0 frame. Offers advanced
  14. * admin configuration options and smart message based or topic based slide show options
  15. * controls if multiple images or attachments are available. Integrates with Aeva as well.
  16. * -----------------------------------------------------------------------------------------------
  17. */
  18. if (!defined('SMF'))
  19. die('Hacking Attempt...');
  20. /**
  21. * Main traffic cop for the rest for the function.
  22. * - Searches message for all img tags and will wrap them in the correct anchor tag to allow the
  23. * Highslide javascript function to find them
  24. * - $context['hs4smf_img_count'] keeps track of how many images are found for each area ... aeva, message, attachment
  25. *
  26. * @param type $message
  27. * @param type $id_msg
  28. * @return type
  29. */
  30. function hs4smf(&$message, $id_msg = -1)
  31. {
  32. global $context, $modSettings, $settings;
  33. // Mod or BBC disabled?
  34. if (empty($modSettings['hs4smf_enabled']) || empty($modSettings['enableBBC']))
  35. return;
  36. // Init some thangs
  37. $context['hs4smf_img_count'] = 0;
  38. $image_hosters = array('imageshack', 'photobucket', 'ipicture', 'radikal', 'keep4u', 'fotosik', 'xs', 'postimage', 'postimg', 'ggpht', 'flickr', 'smugmug');
  39. $regex = '~(?P<a_tag><a href="(?P<a_link>[^"]*?)"(?:[^>]*?)>|)(?P<img_tag><img src=[""' . '\'](?P<img_src>.*?)[""' . '\'](?:[^>]*?)>)(?:</a>|)~si';
  40. // Do we have Aeva installed, if so lets move the [smg embedded images in to our slidegroups
  41. if ((!empty($modSettings['aeva_enable'])) && !isset($context['smg_disable']))
  42. {
  43. // How many smg images did Aeva render in this message
  44. $smg_count = substr_count($message, 'onclick="return hs.expand(this, slideOptions)');
  45. // If there are some, move them to the proper slide group, leave the aeva group for sig images
  46. if ($smg_count > 0)
  47. {
  48. if (!empty($modSettings['hs4smf_slideshowgrouping']))
  49. $message = str_replace('onclick="return hs.expand(this, slideOptions)', 'onclick="return hs.expand(this, {slideshowGroup:\'' . $id_msg . '\',captionEval:\'{this.thumb.highslide-caption}\'})', $message);
  50. else
  51. $message = str_replace('onclick="return hs.expand(this, slideOptions)', 'onclick="return hs.expand(this, {slideshowGroup:\'fullgroup\'})', $message);
  52. // Track of how many images we are sliding in this message
  53. $context['hs4smf_img_count'] = $smg_count;
  54. hs4smf_track_slidegroup($id_msg);
  55. }
  56. }
  57. // Now Find all the images in this message, be they linked or not, return a numbered and named array for use
  58. $context['hs4smf_img_count'] = 0;
  59. $images = array();
  60. if (preg_match_all($regex, $message, $images, PREG_SET_ORDER))
  61. {
  62. // Get the slide show groupings, message based or topic based
  63. $slidegroup = hs4smf_get_slidegroup($id_msg);
  64. // As long as we have images to work on
  65. foreach ($images as $image)
  66. {
  67. // not on the smileys, avatars, alt="ns" or img tags from attachments, icons etc ...
  68. // primarily to find smileys since they are IN the message, next is the NS override,
  69. // the rest should not happen but .....
  70. if (stripos($image['img_tag'], 'class="smiley"'))
  71. continue;
  72. elseif (stripos($image['img_tag'], 'alt="&quot;ns&quot;"'))
  73. continue;
  74. elseif (stripos($image['img_tag'], 'alt="ns"'))
  75. continue;
  76. elseif (stripos($image['img_tag'], 'type=avatar'))
  77. continue;
  78. elseif (stripos($image['img_tag'], 'class="icon"'))
  79. continue;
  80. elseif (stripos($image['img_tag'], $modSettings['smileys_url']))
  81. continue;
  82. elseif (stripos($image['img_tag'], 'index.php?action=dlattach;'))
  83. continue;
  84. elseif (stripos($image['img_tag'], $settings['images_url']))
  85. continue;
  86. // Non-linked images need to be wrapped in an <a href /a> for Highslide to do its magic, so lets create an anchor tag
  87. if (empty($image['a_tag']) && empty($image['a_link']))
  88. {
  89. $image['a_tag'] = '<a href="' . $image['img_src'] . '">';
  90. $image['a_link'] = $image['img_src'];
  91. $image['replacement'] = $image['a_tag'] . $image['img_tag'] . '</a>';
  92. }
  93. else
  94. $image['replacement'] = $image[0];
  95. // we have special processing needs for image hosting sites in order to find the real image to expand,
  96. // so if we have a valid domain
  97. $domain = array();
  98. if (preg_match('~^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$~i', $image['a_link']))
  99. {
  100. $domain = parse_url($image['a_link']);
  101. $image['domain_url'] = empty($domain['host']) ? '' : $domain['host'];
  102. // See if the image is hosted at a site we support
  103. foreach ($image_hosters as $host)
  104. {
  105. if (stripos($image['domain_url'], $host) !== false)
  106. {
  107. // If image[1] was not set, set it now for externally hosted sites so [img] tags outside
  108. // of a [url] tag will slide
  109. if (empty($image[1]))
  110. $image[1] = $image['a_tag'];
  111. $image = hs4smf_fix_link($image);
  112. break;
  113. }
  114. }
  115. }
  116. // Build the anchor tag replacement, if we created the anchor tag ourselves (none was existing), use
  117. // it to search and replace, otherwise use the original tag ($image[1]) as we could have altered
  118. // the a_tag (image hosting site) in a normal link and need to swap that in
  119. if (empty($image[1]))
  120. $image['replacement'] = str_ireplace($image['a_tag'], hs4wsmf_anchor_link_prepare($image['a_tag'], $slidegroup), $image['replacement']);
  121. else
  122. $image['replacement'] = str_ireplace($image[1], hs4wsmf_anchor_link_prepare($image['a_tag'], $slidegroup), $image['replacement']);
  123. // Check the image tag, if it contains the class bbc_img resized we need to change it so smf does not try to expand it
  124. if (stripos($image['img_tag'], 'bbc_img resized'))
  125. {
  126. $image['img_tag'] = str_ireplace('bbc_img resized', 'bbc_img', $image['img_tag']);
  127. $image['replacement'] = str_ireplace($image[3], $image['img_tag'], $image['replacement']);
  128. }
  129. // Swap out the old with the new
  130. $message = hs4smf_str_replace_once($image[0], $image['replacement'], $message);
  131. }
  132. // Create / update slide show tracking
  133. hs4smf_track_slidegroup($id_msg);
  134. }
  135. return;
  136. }
  137. /**
  138. * Fixes the image link so they point to the full sized image instead of pointing to the image
  139. * hosting site, this allows them to expand in place and not redirect.
  140. *
  141. * @param string $image
  142. */
  143. function hs4smf_fix_link($image)
  144. {
  145. global $context;
  146. /**
  147. * Link thumbnails for image hosting sites
  148. * These href links are not to an image but back to the image host page, where the full sized is returned. Since we know the
  149. * thumbnail image location its generally easy to build the correct link to the full-size image for us to use.
  150. *
  151. * Take the thumbnail image and based on the host strip out the thumb indicator, for example imageshack will have
  152. * http://img266.imageshack.us/imgxyz/952/ltsce5.th.jpg as the thumb, the full size is therefore
  153. * http://img266.imageshack.us/imgxyz/952/ltsce5.jpg
  154. * and so on through the list
  155. */
  156. if (stripos($image['domain_url'], 'imageshack') !== false && preg_match('~(.*?)\.(?:th\.|)(png|gif|jp(e)?g|bmp)$~is' . ($context['utf8'] ? 'u' : ''), $image[4], $out))
  157. $out = (substr($out[1], 0, -1) == '.') ? $out[1] . $out[2] : $out[1] . '.' . $out[2];
  158. elseif (stripos($image['domain_url'], 'photobucket') !== false && preg_match('~(.*?)/(?:th_|)([^/]*?)\.(png|gif|jp(e)?g|bmp)$~is' . ($context['utf8'] ? 'u' : ''), $image[4], $out))
  159. $out = $out[1] . '/' . $out[2] . '.' . $out[3];
  160. elseif (stripos($image['domain_url'], 'ipicture') !== false && preg_match('~(.*?)/(?:thumbs|)/([^/]*?)\.(png|gif|jp(e)?g|bmp)$~is' . ($context['utf8'] ? 'u' : ''), $image[4], $out))
  161. $out = $out[1] . '/' . $out[2] . '.' . $out[3];
  162. elseif (stripos($image['domain_url'], 'radikal') !== false && preg_match('~(.*?)/([^/]*?)t\.(png|gif|jp(e)?g|bmp)$~is' . ($context['utf8'] ? 'u' : ''), $image[4], $out))
  163. $out = $out[1] . '/' . $out[2] . '.' . $out[3];
  164. elseif (stripos($image['domain_url'], 'keep4u') !== false && stripos($image['domain_url'], 'keep4u') !== false && preg_match('~(.*?)/imgs/s/(.+)\.(png|gif|jp(e)?g|bmp)$~is' . ($context['utf8'] ? 'u' : ''), $image[4], $out))
  165. $out = $out[1] . '/imgs/b/' . $out[2] . '.' . $out[3];
  166. elseif (stripos($image['domain_url'], 'fotosik') !== false && preg_match('~(.*?)\.(?:m\.|)(png|gif|jp(e)?g|bmp)$~is' . ($context['utf8'] ? 'u' : ''), $image[4], $out))
  167. {
  168. if (substr($out[1], -1) == 'm')
  169. $out[1] = substr($out[1], 0, strlen($out[1]) - 1);
  170. if (substr($out[1], -3) == 'med')
  171. $out[1] = substr($out[1], 0, strlen($out[1]) - 3);
  172. $out = $out[1] . '.' . $out[2];
  173. }
  174. elseif (stripos($image['domain_url'], 'xs') !== false && preg_match('~(.*?)\.(?:jpg.xs\.|)(png|gif|jp(e)?g|bmp)$~is' . ($context['utf8'] ? 'u' : ''), $image[4], $out))
  175. $out = $out[1] . '.' . $out[2];
  176. elseif (stripos($image['domain_url'], 'postim') !== false && !empty($image[2]))
  177. {
  178. // postimage.org appears to set the full image name based on the user agent, different agents generate different image names ...
  179. $link = array();
  180. $out = $image[2];
  181. ini_set('user_agent', $_SERVER['HTTP_USER_AGENT']);
  182. $page = @file_get_contents($image[2]);
  183. if ($page !== false && preg_match('~<img src=\'(.*?\.(png|gif|jp(e)?g|bmp))\'~is', $page, $link))
  184. $out = $link[1];
  185. }
  186. elseif (stripos($image['domain_url'], 'ggpht') !== false && preg_match('~(.*?)/(?:s\d{3,4}|)/([^/]*?)\.(png|gif|jp(e)?g|bmp)$~is' . ($context['utf8'] ? 'u' : ''), $image[4], $out))
  187. $out = $out[1] . '/' . $out[2] . '.' . $out[3];
  188. elseif (stripos($image['domain_url'], 'flickr') !== false && preg_match('~(.*?)(?:_t\.)(png|gif|jp(e)?g|bmp)$~is' . ($context['utf8'] ? 'u' : ''), $image[4], $out))
  189. $out = $out[1] . '_b.' . $out[2];
  190. elseif (stripos($image['domain_url'], 'smugmug') !== false && preg_match('~(.*?)(?:\/S\/)(.*?)(?:-S)\.(png|gif|jp(e)?g|bmp)$~is' . ($context['utf8'] ? 'u' : ''), $image[4], $out))
  191. $out = $out[1] . '/O/' . $out[2] . '.' . $out[3];
  192. elseif (stripos($image['domain_url'], 'googleusercontent') !== false && preg_match('~(.*?)/(?:s\d{3,4}|)/([^/]*?)\.(png|gif|jp(e)?g|bmp)$~is' . ($context['utf8'] ? 'u' : ''), $image[4], $out))
  193. $out = $out[1] . '/s800/' . $out[2] . '.' . $out[3];
  194. else
  195. return $image;
  196. // update the anchor link and tag with the fixed image
  197. $image['a_tag'] = str_replace($image['a_link'], $out, $image['a_tag']);
  198. $image['a_link'] = $out;
  199. return $image;
  200. }
  201. /**
  202. * Manipulates the anchor tag to update the class and onclick events needed for Highslide
  203. *
  204. * @param string $str
  205. * @param int $slidegroup
  206. * @return string
  207. */
  208. function hs4wsmf_anchor_link_prepare($str, $slidegroup)
  209. {
  210. global $context;
  211. // prepare the link for highslide effect by adding in the class and onclick events
  212. if (preg_match('~href=[\'"][^"\']+\.(?:gif|jpe|jpg|jpeg|png|bmp)~i', $str))
  213. {
  214. if (stripos($str, '"highslide') === false && stripos($str, 'onclick="') === false)
  215. {
  216. // its an image that has not been previously marked for highslide
  217. $context['hs4smf_img_count'] = $context['hs4smf_img_count'] + 1;
  218. if (false !== strpos(strtolower($str), 'class='))
  219. {
  220. // add highslide into an existing class structure
  221. $temp = preg_replace('~(class=[\'"])~i', '$1 highslide ', $str);
  222. return str_replace('>', ' onclick="return hs.expand(this, ' . $slidegroup . ')">', $temp);
  223. }
  224. else
  225. {
  226. // need to add both a class and onclick tags into this anchor link
  227. $temp = '<a ' . preg_replace('~<a([^>]*)>~si', '$1 class="highslide " onclick="return hs.expand(this, ' . $slidegroup . ')"', $str) . '>';
  228. return $temp;
  229. }
  230. }
  231. }
  232. // not an image so leave it alone
  233. return $str;
  234. }
  235. /**
  236. * Simply returns the slideshow group name for a given setup
  237. *
  238. * @param type $id_msg
  239. * @return string
  240. */
  241. function hs4smf_get_slidegroup($id_msg)
  242. {
  243. global $modSettings;
  244. // create the slideshow groupings, message based or topic based
  245. if (isset($modSettings['hs4smf_slideshowgrouping']))
  246. $slidegroup = "{ slideshowGroup: '$id_msg' }";
  247. else
  248. $slidegroup = "{ slideshowGroup: 'fullgroup' }";
  249. return $slidegroup;
  250. }
  251. /**
  252. * Keeps track of the total number of found images in each slideshow group
  253. * - expects $context['hs4smf_img_count'] to be updated to reflect the count of images found
  254. * for each area, aeva, message body and attachments.
  255. *
  256. * @param int $id_msg
  257. */
  258. function hs4smf_track_slidegroup($id_msg)
  259. {
  260. // sets the array key if it has not been set or updates the key if already set and the new value is greater
  261. global $modSettings, $context;
  262. // this should not happen, but here we find ourselfs
  263. $context['hs4smf_img_count'] = isset($context['hs4smf_img_count']) ? $context['hs4smf_img_count'] : 0;
  264. // do the slideshow groupings
  265. if (isset($modSettings['hs4smf_slideshowgrouping']))
  266. {
  267. // create smart slide groups for this message/topic, add this group to our group string for use in building the correct javascript
  268. if (isset($context['hs4smf_slideshow_group'][$id_msg]))
  269. $context['hs4smf_slideshow_group'][$id_msg] += $context['hs4smf_img_count'];
  270. elseif (!isset($context['hs4smf_slideshow_group'][$id_msg]))
  271. $context['hs4smf_slideshow_group'][$id_msg] = $context['hs4smf_img_count'];
  272. }
  273. else
  274. {
  275. // just a single group of all images in this topic, turn on the overlay controls if we have more than 1 image in the topic
  276. if (isset($context['hs4smf_slideshow_group']['fullgroup']))
  277. $context['hs4smf_slideshow_group']['fullgroup'] += $context['hs4smf_img_count'];
  278. elseif (!isset($context['hs4smf_slideshow_group']['fullgroup']))
  279. $context['hs4smf_slideshow_group']['fullgroup'] = $context['hs4smf_img_count'];
  280. }
  281. }
  282. /**
  283. * Some color options just need extra style tweaks to make sure they work
  284. *
  285. * @return string
  286. */
  287. function hs4smf_prepare_extra_headers()
  288. {
  289. global $modSettings, $settings;
  290. $header = "\n";
  291. // dark slideshow controls ?
  292. if (isset($modSettings['hs4smf_slideshowcontrols']) && ($modSettings['hs4smf_slideshowcontrols'] == 3))
  293. $header .= '<style type="text/css">.large-dark .highslide-controls, .large-dark .highslide-controls ul, .large-dark .highslide-controls a {background-image: url(' . $settings['default_theme_url'] . '/hs4smf/graphics/controlbar-black-border.gif);}</style>';
  294. // if the large white controls are placed in the header / caption area, and that area has been exposed, then
  295. // turn off the round corner background if possible so it blends into that area without bleedout
  296. if ((isset($modSettings['hs4smf_slideshowcontrols']) && ($modSettings['hs4smf_slideshowcontrols'] == 2)))
  297. {
  298. $oheader = (($modSettings['hs4smf_slideshownumbers'] == 1) || ((isset($modSettings['hs4smf_headingsource']) && $modSettings['hs4smf_headingsource'] != 0) && $modSettings['hs4smf_headingposition'] == 1));
  299. $ocaption = (($modSettings['hs4smf_slideshownumbers'] == 2) || ((isset($modSettings['hs4smf_captionsource']) && $modSettings['hs4smf_captionsource'] != 0) && $modSettings['hs4smf_captionposition'] == 1));
  300. if ($oheader && in_array(($modSettings['hs4smf_slideshowcontrollocation']), array("4", "5", "6")))
  301. $header .= '<style type="text/css">.highslide-controls {background: none;}.highslide-controls ul {background: none;}</style>' . "\n";
  302. elseif ($ocaption && in_array(($modSettings['hs4smf_slideshowcontrollocation']), array("7", "8", "9")))
  303. $header .= '<style type="text/css">.highslide-controls {background: none;}.highslide-controls ul {background: none;}</style>' . "\n";
  304. }
  305. // frame color of the expand hs4smf_slidebackgroundcolor
  306. if (substr($modSettings['hs4smf_slidebackgroundcolor'], 0, 1) != '#')
  307. $modSettings['hs4smf_slidebackgroundcolor'] = '#' . $modSettings['hs4smf_slidebackgroundcolor'];
  308. if (preg_match('/^#[a-f0-9]{6}$/i', $modSettings['hs4smf_slidebackgroundcolor']))
  309. $header .= '<style type="text/css"> .highslide-wrapper, .highslide-outline {background: ' . $modSettings['hs4smf_slidebackgroundcolor'] . ';}</style>' . "\n";
  310. else
  311. $header .= '<style type="text/css"> .highslide-wrapper, .highslide-outline {background: #FFFFFF;}</style>' . "\n";
  312. return $header;
  313. }
  314. /**
  315. * Poops out the header with the correct css and language css files for the themes.
  316. *
  317. * @param type $force
  318. * @return type
  319. */
  320. function hs4smf_prepare_header($force = false)
  321. {
  322. global $modSettings, $settings, $context;
  323. // if we are in the gallery just let it do what it woudl normally do
  324. if (!$force && $context['current_action'] == 'media')
  325. return;
  326. // build the correct header for css inclusion
  327. $hs_css = $settings['default_theme_url'] . '/hs4smf/highslide.css';
  328. $hs_css_ie = $settings['default_theme_url'] . '/hs4smf/highslide-ie6.css';
  329. // Use the CDN if requested
  330. if (!empty($modSettings['hs4smf_enablecoral']))
  331. {
  332. $hs_css = hs4smf_coralize_uri($hs_css);
  333. $hs_css_ie = hs4smf_coralize_uri($hs_css_ie);
  334. }
  335. // finalize the header string for output into the HTML header
  336. $header = "\n" . '<link rel="stylesheet" href="' . $hs_css . '" type="text/css" media="screen" />' . "\n";
  337. if ($context['browser']['is_ie6'])
  338. $header .= '<link rel="stylesheet" href="' . $hs_css_ie . '" type="text/css" media="screen" />' . "\n";
  339. $header .= hs4smf_prepare_extra_headers();
  340. return $header;
  341. }
  342. /**
  343. * Creates the all important javascipt options for Highslide.
  344. * - Builds the option settings based on the options set in the admin area.
  345. * - Will do some smart corrections to help avoid users choosing conflicting options.
  346. *
  347. * @return type
  348. */
  349. function hs4smf_prepare_footer()
  350. {
  351. global $modSettings, $settings, $context, $amSettings;
  352. // In the gallery, just let Aeva do its thang.
  353. if ($context['current_action'] == 'media')
  354. return;
  355. // build the footer for script inclusion
  356. $hs_script = $settings['default_theme_url'] . '/hs4smf/highslide.js';
  357. $hs_graphics = $settings['default_theme_url'] . '/hs4smf/graphics/';
  358. // Use the CDN if requested
  359. if (!empty($modSettings['hs4smf_enablecoral']))
  360. {
  361. $hs_script = hs4smf_coralize_uri($hs_script);
  362. $hs_graphics = hs4smf_coralize_uri($hs_graphics);
  363. }
  364. // begin to build the footer, lots of busy work to due based on the many admin options
  365. $footer = "\n" . '<!-- HS-4-SMF -->' . "\n";
  366. $footer .= '<script type="text/javascript" src="' . $hs_script . '"></script>' . "\n";
  367. $footer .= '<script type="text/javascript"><!-- // --><![CDATA[' . "\n";
  368. $footer .= 'hs.graphicsDir = \'' . $hs_graphics . '\';' . "\n";
  369. $footer .= (isset($modSettings['hs4smf_enablecredits']) && !empty($modSettings['hs4smf_enablecredits'])) ? 'hs.showCredits = true;' . "\n" : 'hs.showCredits = false;' . "\n";
  370. $footer .= (isset($modSettings['hs4smf_enablegalleryfade']) && !empty($modSettings['hs4smf_enablegalleryfade'])) ? 'hs.fadeInOut = true;' . "\n" . 'hs.transitions = [\'expand\', \'crossfade\'];' . "\n" : 'hs.fadeInOut = false;' . "\n";
  371. $footer .= (isset($modSettings['hs4smf_enablecenter']) && !empty($modSettings['hs4smf_enablecenter'])) ? 'hs.align = \'center\';' . "\n" : '';
  372. $footer .= 'hs.padToMinWidth = true;' . "\n";
  373. // Add the language strings
  374. $footer .= hs4smf_language();
  375. // Caption text Mode
  376. $footer .= hs4smf_caption_text();
  377. // Heading text Mode
  378. $footer .= hs4smf_heading_text();
  379. // Caption position
  380. $footer .= hs4smf_caption_position();
  381. // Heading position
  382. $footer .= hs4smf_heading_position();
  383. // Set the caption and heading width
  384. $footer .= hs4smf_set_width();
  385. // what to do on mouse actions
  386. $footer .= hs4smf_mouse_action();
  387. // heading and caption opacity
  388. $footer .= hs4smf_hc_opacity();
  389. // Overall frame style
  390. $footer .= hs4smf_frame_style();
  391. // Overall dimming opacity
  392. $footer .= hs4smf_dimming_opacity();
  393. // Set the control text style
  394. $footer .= hs4smf_control_wrapper();
  395. // Add the slideshow controls if requested
  396. $footer .= hs4smf_slidshow_controls();
  397. // Finish this script
  398. $footer .= "// ]]></script>\n";
  399. // Any remaining Aeva bits
  400. if (!empty($amSettings['use_lightbox']))
  401. $footer .= aeva_initLightbox_hs4smf();
  402. // clean up for the next pass
  403. unset($context['hs4smf_slideshow']);
  404. unset($context['hs4smf_slideshow_group']);
  405. // return this beast
  406. return $footer;
  407. }
  408. /**
  409. *
  410. * Set the text for the image caption in the popup
  411. * @return string
  412. */
  413. function hs4smf_caption_text()
  414. {
  415. global $modSettings, $context;
  416. $footer = '';
  417. // Caption text Mode
  418. if (!empty($modSettings['hs4smf_captionsource']) && !empty($modSettings['hs4smf_captionposition']))
  419. {
  420. switch ($modSettings['hs4smf_captionsource'])
  421. {
  422. case 1:
  423. $footer = 'hs.captionEval = \'if (this.thumb.title == "" && this.slideshowGroup == "aeva") {this.highslide-caption} else {this.thumb.title} \';' . "\n";
  424. break;
  425. case 2:
  426. $footer = 'hs.captionEval = \' if (this.thumb.alt == "" && this.slideshowGroup == "aeva") {this.highslide-caption} else {this.thumb.alt} \';' . "\n";
  427. break;
  428. case 3:
  429. $footer = 'hs.captionEval = \'if (this.a.title == "" && this.slideshowGroup == "aeva") {this.highslide-caption} else {this.a.title} \';' . "\n";
  430. break;
  431. case 4:
  432. $temp = (isset($context['subject'])) ? htmlspecialchars($context['subject'], ENT_QUOTES) : '';
  433. $footer = 'hs.captionEval = \'if (this.slideshowGroup == "aeva") {this.highslide-caption} else {"' . $temp . '"} \';' . "\n";
  434. default:
  435. break;
  436. }
  437. }
  438. return $footer;
  439. }
  440. /**
  441. * Sets the title text for the image popup
  442. *
  443. * @return string
  444. */
  445. function hs4smf_heading_text()
  446. {
  447. global $modSettings, $context;
  448. $footer = '';
  449. // Heading text Mode
  450. if (!empty($modSettings['hs4smf_headingsource']) && !empty($modSettings['hs4smf_headingposition']))
  451. {
  452. switch ($modSettings['hs4smf_headingsource'])
  453. {
  454. case 1:
  455. $footer = 'hs.headingEval = \'if (this.thumb.title == "") {"&nbsp;"} else {this.thumb.title} \';' . "\n";
  456. break;
  457. case 2:
  458. $footer = 'hs.headingEval = \' if (this.thumb.alt == "") {"&nbsp;"} else {this.thumb.alt} \';' . "\n";
  459. break;
  460. case 3:
  461. $footer = 'hs.headingEval = \'if (this.a.title == "") {"&nbsp;"} else {this.a.title} \';' . "\n";
  462. break;
  463. case 4:
  464. $temp = (isset($context['subject'])) ? htmlspecialchars($context['subject'], ENT_QUOTES) : '';
  465. $footer = 'hs.headingText = \'' . $temp . "'\n";
  466. break;
  467. default:
  468. break;
  469. }
  470. }
  471. return $footer;
  472. }
  473. /**
  474. * Determines where the caption should be placed on the image
  475. *
  476. * @return string
  477. */
  478. function hs4smf_caption_position()
  479. {
  480. global $modSettings;
  481. $footer = '';
  482. // Caption position
  483. if (!empty($modSettings['hs4smf_captionposition']) && !empty($modSettings['hs4smf_captionsource']))
  484. {
  485. switch ($modSettings['hs4smf_captionposition'])
  486. {
  487. case 1:
  488. $footer = 'hs.captionOverlay.position = \'below\';' . "\n";
  489. break;
  490. case 2:
  491. $footer = 'hs.captionOverlay.position = \'bottom\';' . "\n";
  492. break;
  493. default:
  494. break;
  495. }
  496. }
  497. return $footer;
  498. }
  499. /**
  500. * Determines where the heading should be positioned on the image
  501. *
  502. * @return string
  503. */
  504. function hs4smf_heading_position()
  505. {
  506. global $modSettings;
  507. $footer = '';
  508. // Heading position
  509. if (!empty($modSettings['hs4smf_headingposition']) && !empty($modSettings['hs4smf_headingsource']))
  510. {
  511. switch ($modSettings['hs4smf_headingposition'])
  512. {
  513. case 1:
  514. $footer = 'hs.headingOverlay.position = \'above\';' . "\n";
  515. break;
  516. case 2:
  517. $footer = 'hs.headingOverlay.position = \'top\';' . "\n";
  518. break;
  519. default:
  520. break;
  521. }
  522. }
  523. return $footer;
  524. }
  525. /**
  526. * Set the width of the caption overlays
  527. * @return string
  528. */
  529. function hs4smf_set_width()
  530. {
  531. // Set the width of the caption overlays
  532. $footer = '';
  533. $footer = 'hs.captionOverlay.width = \'100%\';' . "\n";
  534. $footer .= 'hs.headingOverlay.width = \'100%\';' . "\n";
  535. return $footer;
  536. }
  537. /**
  538. * Based on the admin settings, decide what to do with the mouse pointer
  539. *
  540. * @return type
  541. */
  542. function hs4smf_mouse_action()
  543. {
  544. global $modSettings;
  545. $footer = '';
  546. // what to do on mouse actions
  547. $footer = (isset($modSettings['hs4smf_sourcemouse']) && !empty($modSettings['hs4smf_sourcemouse'])) ? 'hs.captionOverlay.hideOnMouseOut = true;' . "\n" . 'hs.headingOverlay.hideOnMouseOut = true;' . "\n" : 'hs.captionOverlay.hideOnMouseOut = false;' . "\n" . 'hs.headingOverlay.hideOnMouseOut = false;' . "\n";
  548. return $footer;
  549. }
  550. /**
  551. * Opacity level of the background when the image slides
  552. *
  553. * @return string
  554. */
  555. function hs4smf_hc_opacity()
  556. {
  557. global $modSettings;
  558. $footer = '';
  559. $opacity = 0;
  560. // heading and caption opacity
  561. if (!empty($modSettings['hs4smf_sourceopacity']))
  562. {
  563. $opacity = ($modSettings['hs4smf_sourceopacity'] - 1) / 10;
  564. if ($opacity > 0)
  565. $footer = 'hs.captionOverlay.opacity = ' . $opacity . ";\n" . 'hs.headingOverlay.opacity = ' . $opacity . ";\n";
  566. }
  567. return $footer;
  568. }
  569. /**
  570. * Look of the border around the image
  571. *
  572. * @return string
  573. */
  574. function hs4smf_frame_style()
  575. {
  576. global $modSettings;
  577. $footer = '';
  578. // Style Definitions
  579. $footer = '';
  580. if (!empty($modSettings['hs4smf_appearance']))
  581. {
  582. switch ($modSettings['hs4smf_appearance'])
  583. {
  584. case 1:
  585. $footer = 'hs.outlineType = \'rounded-white\';' . "\n";
  586. break;
  587. case 2:
  588. $footer = 'hs.wrapperClassName = \'wide-border\';' . "\n";
  589. break;
  590. case 3:
  591. $footer = 'hs.wrapperClassName = \'borderless\';' . "\n";
  592. break;
  593. case 4:
  594. $footer = 'hs.outlineType = \'outer-glow\';' . "\n";
  595. break;
  596. case 5:
  597. $footer = 'hs.outlineType = null;' . "\n";
  598. break;
  599. case 6:
  600. $footer = 'hs.outlineType = \'glossy-dark\';' . "\n";
  601. break;
  602. case 7:
  603. $footer = 'hs.wrapperClassName = \'dark borderless floating-caption\';' . "\n";
  604. break;
  605. case 99:
  606. break;
  607. default:
  608. $footer = 'hs.outlineType = \'rounded-white\';' . "\n";
  609. break;
  610. }
  611. }
  612. return $footer;
  613. }
  614. /**
  615. * Converts the acp setting to one the highslide JS understands
  616. *
  617. * @return string
  618. */
  619. function hs4smf_dimming_opacity()
  620. {
  621. global $modSettings;
  622. $footer = '';
  623. $opacity = 0;
  624. // dimming opacity
  625. if (!empty($modSettings['hs4smf_dimmingopacity']))
  626. {
  627. $opacity = ($modSettings['hs4smf_dimmingopacity'] - 1) / 10;
  628. if ($opacity > 0)
  629. $footer = 'hs.dimmingOpacity = ' . $opacity . ";\n";
  630. }
  631. return $footer;
  632. }
  633. /**
  634. * Type of slide control to use, text or graphical
  635. * @global type $modSettings
  636. * @return string
  637. */
  638. function hs4smf_control_wrapper()
  639. {
  640. global $modSettings;
  641. $footer = '';
  642. // set the slidshow control wrapper to use the correct controls
  643. if (isset($modSettings['hs4smf_slideshowcontrols']))
  644. {
  645. switch ($modSettings['hs4smf_slideshowcontrols'])
  646. {
  647. case 0:
  648. $footer = "hs.wrapperClassName = 'text-controls';" . "\n";
  649. break;
  650. case 1:
  651. $footer = "hs.wrapperClassName = 'controls-in-heading';" . "\n";
  652. break;
  653. case 3:
  654. $footer = "hs.wrapperClassName = 'large-dark';" . "\n";
  655. break;
  656. default:
  657. break;
  658. }
  659. }
  660. return $footer;
  661. }
  662. /**
  663. * Determines where to place the slideshow controls (back, forward, play, etc)
  664. * - attempts to adjust / correct the position based on other options the user may have chosen
  665. * such as control style, frame style, footer/header captions, etc
  666. *
  667. * @return string
  668. */
  669. function hs4smf_slidshow_controls()
  670. {
  671. global $txt, $modSettings, $context;
  672. loadLanguage('hs4smf');
  673. $footer = '';
  674. if (!empty($modSettings['hs4smf_endableslideshow']))
  675. {
  676. // do we have an open header bar or footer bar?
  677. $oheader = (($modSettings['hs4smf_slideshownumbers'] == 1) || (!empty($modSettings['hs4smf_headingsource']) && $modSettings['hs4smf_headingposition'] == 1));
  678. $ocaption = (($modSettings['hs4smf_slideshownumbers'] == 2) || (!empty($modSettings['hs4smf_captionsource']) && $modSettings['hs4smf_captionposition'] == 1));
  679. // show image x of y for all the slideshows?
  680. if (isset($modSettings['hs4smf_slideshownumbers']) && !empty($modSettings['hs4smf_slideshownumbers']))
  681. {
  682. $footer .= "hs.lang.number = '" . $txt['hs4smf_image'] . " %1 - %2';\n";
  683. switch ($modSettings['hs4smf_slideshownumbers'])
  684. {
  685. case 1:
  686. $footer .= "hs.numberPosition = 'heading';\n";
  687. break;
  688. case 2:
  689. $footer .= "hs.numberPosition = 'caption';\n";
  690. break;
  691. default:
  692. break;
  693. }
  694. }
  695. // create slidshow groups for each message (that has images) in the post ....
  696. if (isset($context['hs4smf_slideshow_group']))
  697. {
  698. foreach ($context['hs4smf_slideshow_group'] as $slide_group => $slide_count)
  699. {
  700. // start of this slide group
  701. $footer .= "if (hs.addSlideshow) hs.addSlideshow({";
  702. $footer .= "slideshowGroup: '$slide_group',";
  703. // how long to show each image
  704. $interval = (!empty($modSettings['hs4smf_slideshowdelay'])) ? intval($modSettings['hs4smf_slideshowdelay'] * 1000) : 5000;
  705. if ($interval < 1000)
  706. $interval = 5000;
  707. $footer .= "interval: " . $interval . ",";
  708. $footer .= (!empty($modSettings['hs4smf_slideshowrepeat'])) ? "repeat: true," : "repeat: false,";
  709. // if this group only has 1 image then don't show the controls unless we have been told to
  710. $footer .= ($slide_count > 1 || !empty($modSettings['hs4smf_slidecontrolsalways'])) ? "useControls: true," : "useControls: false,";
  711. $footer .= "fixedControls: 'fit',";
  712. // how should the overlay controls appear
  713. $footer .= "overlayOptions: {";
  714. $footer .= "opacity: .80,";
  715. $X = 0;
  716. $Y = 0;
  717. // place the controls, try to avoid collisions with the header and caption locations
  718. switch ($modSettings['hs4smf_slideshowcontrollocation'])
  719. {
  720. case 1:
  721. $footer .= "position: 'above',";
  722. break;
  723. case 4:
  724. $footer .= "position: 'top left',";
  725. // if we are using the graphical control and the header is exposed then place it in there
  726. // otherwise place it based on control size and type
  727. if ($oheader)
  728. {
  729. if (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 1)
  730. {
  731. $X = -5;
  732. $Y = 25;
  733. }
  734. elseif (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 2)
  735. {
  736. $X = -12;
  737. $Y = -22;
  738. }
  739. elseif (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 3)
  740. {
  741. $X = 55;
  742. $Y = -12;
  743. }
  744. }
  745. elseif (isset($modSettings['hs4smf_slideshowcontrols']))
  746. {
  747. switch ($modSettings['hs4smf_slideshowcontrols'])
  748. {
  749. case 1:
  750. $Y = 25;
  751. break;
  752. case 2:
  753. $Y = -15;
  754. $X = 5;
  755. break;
  756. case 3:
  757. $Y = -15;
  758. $X = 5;
  759. break;
  760. case 0:
  761. $Y = 5;
  762. break;
  763. default:
  764. break;
  765. }
  766. }
  767. break;
  768. case 5:
  769. $footer .= "position: 'top center',";
  770. // if we are using the graphical control and the header is exposed then place it in there
  771. // otherwise place it based on control size and type
  772. if ($oheader)
  773. {
  774. if (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 2)
  775. $Y = -55;
  776. elseif (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 0)
  777. $Y = -25;
  778. }
  779. elseif (isset($modSettings['hs4smf_slideshowcontrols']))
  780. {
  781. switch ($modSettings['hs4smf_slideshowcontrols'])
  782. {
  783. case 1:
  784. $Y = 25;
  785. break;
  786. case 2:
  787. $Y = -15;
  788. break;
  789. case 3:
  790. $Y = -15;
  791. break;
  792. case 0:
  793. $Y = 5;
  794. break;
  795. default:
  796. break;
  797. }
  798. }
  799. break;
  800. case 6:
  801. $footer .= "position: 'top right',";
  802. // if we are using the graphical control and the header is exposed then place it in there
  803. // otherwise place it based on control size and type
  804. if ($oheader)
  805. {
  806. if (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 2)
  807. {
  808. $Y = -55;
  809. $X = 15;
  810. }
  811. elseif (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 0)
  812. $Y = -25;
  813. }
  814. elseif (isset($modSettings['hs4smf_slideshowcontrols']))
  815. {
  816. switch ($modSettings['hs4smf_slideshowcontrols'])
  817. {
  818. case 1:
  819. $Y = 25;
  820. $X = -5;
  821. break;
  822. case 2:
  823. $Y = -5;
  824. $X = -5;
  825. break;
  826. case 3:
  827. $Y = -5;
  828. $X = -5;
  829. break;
  830. case 0:
  831. $Y = 5;
  832. break;
  833. default:
  834. break;
  835. }
  836. }
  837. break;
  838. case 7:
  839. $footer .= "position: 'bottom left',";
  840. // if we are using the graphical control then shift it if is not compatible with the header/caption position
  841. if ($ocaption)
  842. {
  843. if (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 2)
  844. {
  845. $X = -10;
  846. $Y = 12;
  847. }
  848. elseif (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 1)
  849. {
  850. $X = -5;
  851. $Y = 20;
  852. }
  853. }
  854. elseif (isset($modSettings['hs4smf_slideshowcontrols']))
  855. {
  856. switch ($modSettings['hs4smf_slideshowcontrols'])
  857. {
  858. case 3:
  859. $X = 5;
  860. $Y = 5;
  861. break;
  862. case 2:
  863. $X = 5;
  864. $Y = 5;
  865. break;
  866. case 1:
  867. $Y = 15;
  868. break;
  869. case 0:
  870. $X = -2;
  871. $Y = -5;
  872. break;
  873. default:
  874. break;
  875. }
  876. }
  877. break;
  878. case 8:
  879. $footer .= "position: 'bottom center',";
  880. // if we are using the graphical control then shift it if is not compatible with the header/caption position
  881. if ($ocaption)
  882. {
  883. if (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 2)
  884. $Y = 45;
  885. elseif (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 3)
  886. $Y = 47;
  887. elseif (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 1)
  888. $Y = 50;
  889. else
  890. $Y = 27;
  891. }
  892. elseif (isset($modSettings['hs4smf_slideshowcontrols']))
  893. {
  894. switch ($modSettings['hs4smf_slideshowcontrols'])
  895. {
  896. case 3:
  897. $Y = 5;
  898. break;
  899. case 2:
  900. $Y = 5;
  901. break;
  902. case 1:
  903. $Y = 20;
  904. break;
  905. case 0:
  906. $Y = -5;
  907. break;
  908. default:
  909. break;
  910. }
  911. }
  912. break;
  913. case 9:
  914. $footer .= "position: 'bottom right',";
  915. // if we are using the graphical control then shift it if is not compatible with the header/caption position
  916. if ($ocaption)
  917. {
  918. if (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 3)
  919. {
  920. $Y = 47;
  921. $X = 10;
  922. }
  923. elseif (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 2)
  924. {
  925. $Y = 47;
  926. $X = 10;
  927. }
  928. elseif (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 1)
  929. {
  930. $Y = 50;
  931. $X = -5;
  932. }
  933. elseif (isset($modSettings['hs4smf_slideshowcontrols']) && $modSettings['hs4smf_slideshowcontrols'] == 0)
  934. {
  935. $Y = 27;
  936. $X = -5;
  937. }
  938. }
  939. elseif (isset($modSettings['hs4smf_slideshowcontrols']))
  940. {
  941. switch ($modSettings['hs4smf_slideshowcontrols'])
  942. {
  943. case 3:
  944. $Y = 5;
  945. $X = -5;
  946. break;
  947. case 2:
  948. $Y = 5;
  949. $X = -5;
  950. break;
  951. case 1:
  952. $Y = 20;
  953. $X = -5;
  954. break;
  955. case 0:
  956. $Y = -5;
  957. break;
  958. default:
  959. break;
  960. }
  961. }
  962. break;
  963. case 10:
  964. $footer .= "position: 'below',";
  965. break;
  966. default:
  967. break;
  968. }
  969. if (isset($modSettings['hs4smf_nudgex']))
  970. $X += $modSettings['hs4smf_nudgex'];
  971. if (isset($modSettings['hs4smf_nudgey']))
  972. $Y += $modSettings['hs4smf_nudgey'];
  973. $footer .= 'offsetX: ' . $X . ',offsetY: ' . $Y . ',';
  974. // last line, no trailing , or ie7- will toss an error for no good reason
  975. $footer .= (isset($modSettings['hs4smf_slideshowmouse']) && !empty($modSettings['hs4smf_slideshowmouse'])) ? 'hideOnMouseOut: true' : 'hideOnMouseOut: false';
  976. $footer .= "}";
  977. $footer .= "});\n";
  978. }
  979. }
  980. }
  981. return $footer;
  982. }
  983. /**
  984. * Language settings used by javascript
  985. *
  986. * @return string
  987. */
  988. function hs4smf_language()
  989. {
  990. global $txt;
  991. loadLanguage('hs4smf');
  992. $footer = 'hs.lang = {
  993. cssDirection:\'' . $txt['cssDirection'] . '\',
  994. loadingText:\'' . $txt['loadingText'] . '\',
  995. loadingTitle:\'' . $txt['loadingTitle'] . '\',
  996. focusTitle:\'' . $txt['focusTitle'] . '\',
  997. fullExpandTitle:\'' . $txt['fullExpandTitle'] . '\',
  998. creditsText:\'' . $txt['creditsText'] . '\',
  999. creditsTitle:\'' . $txt['creditsTitle'] . '\',
  1000. previousText:\'' . $txt['previousText'] . '\',
  1001. nextText:\'' . $txt['nextText'] . '\',
  1002. moveText:\'' . $txt['moveText'] . '\',
  1003. closeText:\'' . $txt['closeText'] . '\',
  1004. closeTitle:\'' . $txt['closeTitle'] . '\',
  1005. resizeTitle:\'' . $txt['resizeTitle'] . '\',
  1006. playText:\'' . $txt['playText'] . '\',
  1007. playTitle:\'' . $txt['playTitle'] . '\',
  1008. pauseText:\'' . $txt['pauseText'] . '\',
  1009. pauseTitle:\'' . $txt['pauseTitle'] . '\',
  1010. previousTitle:\'' . $txt['previousTitle'] . '\',
  1011. nextTitle:\'' . $txt['nextTitle'] . '\',
  1012. moveTitle:\'' . $txt['moveTitle'] . '\',
  1013. fullExpandText:\'' . $txt['fullExpandText'] . '\',
  1014. number:\'' . $txt['imagenumber'] . '\',
  1015. restoreTitle:\'' . $txt['restoreTitle'] . '\'
  1016. };' . "\n";
  1017. return $footer;
  1018. }
  1019. /**
  1020. * Open CDN project, we encode the Highslide js and css files to point to this farm so that
  1021. * they are distributed from a closer server than ours. MIGHT be faster if you have a lot
  1022. * of users from across the globe, if its just a local site, could be slower. Who knows, saw
  1023. * this on the web blog (need to find the link to post) and thought it would be fun
  1024. *
  1025. * @param type $uri
  1026. * @return string
  1027. */
  1028. function hs4smf_coralize_uri($uri)
  1029. {
  1030. // simply adds on the .nyud.net to a link so it points to the open CDN, usally does not work :P
  1031. if (stristr($uri, "http://") === false)
  1032. return $uri;
  1033. $tmp = explode("/", $uri, 4);
  1034. $cor = $tmp[0] . '/' . $tmp[1] . '/' . $tmp[2] . '.nyud.net/' . $tmp[3];
  1035. return $cor;
  1036. }
  1037. /**
  1038. * Looks for the first occurrence of $needle in $haystack and replaces it with $replace, this is a single replace
  1039. *
  1040. * @param type $needle
  1041. * @param type $replace
  1042. * @param type $haystack
  1043. * @return type
  1044. */
  1045. function hs4smf_str_replace_once($needle, $replace, $haystack)
  1046. {
  1047. // Looks for the first occurrence of $needle in $haystack and replaces it with $replace, this is a single replace
  1048. $pos = strpos($haystack, $needle);
  1049. if ($pos === false)
  1050. {
  1051. // Nothing found
  1052. return $haystack;
  1053. }
  1054. return substr_replace($haystack, $replace, $pos, strlen($needle));
  1055. }
  1056. /**
  1057. * Used to format avea slidegroup images (signatures at this point)
  1058. * - adds our styling for any avea media embeds
  1059. * - Optionaly adds in javascipt functions so smg images clicks will count as views
  1060. * - Removes the loading of a second css and highslide.js as well as hs options so all images have
  1061. * the style as defined by hs4smf
  1062. * - Not used when in the gallery, only for messages
  1063. *
  1064. * @return string
  1065. */
  1066. function aeva_initLightbox_hs4smf()
  1067. {
  1068. global $modSettings;
  1069. $script = '
  1070. <script type="text/javascript"><!-- // --><![CDATA[
  1071. function hss(aId, aSelf)
  1072. {
  1073. var aUrl = aSelf.href;
  1074. var ah = document.getElementById(\'hsm\' + aId);
  1075. hs.close(ah);
  1076. hs.expanders[hs.getWrapperKey(ah)] = null;
  1077. ah.href = aUrl;
  1078. hs.expand(ah);
  1079. return false;
  1080. }
  1081. hs.Expander.prototype.onInit = function()
  1082. {
  1083. for (var i = 0, j = this.a.attributes, k = j.length; i < k; i++)
  1084. {
  1085. if (j[i].value.indexOf(\'htmlExpand\') != -1)
  1086. {
  1087. getXMLDocument(\'index.php?action=media;sa=addview;in=\' + this.a.id.substr(3), function() {});
  1088. return;
  1089. }
  1090. }
  1091. }';
  1092. // Count highsliding an smg tag as a gallery view?
  1093. if (!empty($modSettings['hs4smf_gallerycounter']))
  1094. $script .= '
  1095. hs.Expander.prototype.onAfterExpand = function ()
  1096. {
  1097. // This will tickle the avea viewed count when and smg item is expanded in a post
  1098. var view_pattern = new RegExp(";in=([0-9]{1,10}).?","g");
  1099. var match = view_pattern.exec(this.a.href);
  1100. if (match != null) {
  1101. getXMLDocument(\'index.php?action=media;sa=addview;in=\' + match[1], function() {});
  1102. }
  1103. return;
  1104. }';
  1105. $script .= '
  1106. var slideOptions = { slideshowGroup: \'aeva\'' .
  1107. ((!empty($modSettings['hs4smf_enablecenter'])) ? ', align: \'center\',' : ',') . ' useControls: false' .
  1108. ((!empty($modSettings['hs4smf_enablegalleryfade'])) ? ', fadeInOut: true, transitions: [\'expand\', \'crossfade\']' : ', fadeInOut: false') .
  1109. ' };
  1110. var mediaOptions = { slideshowGroup: \'aeva\'' .
  1111. ((!empty($modSettings['hs4smf_enablecenter'])) ? ', align: \'center\',' : ',') .
  1112. ((!empty($modSettings['hs4smf_enablegalleryfade'])) ? ' fadeInOut: true, transitions: [\'expand\', \'crossfade\']' : ' fadeInOut: false') .
  1113. ', width: 1 };
  1114. // ]]>
  1115. </script>';
  1116. return $script;
  1117. }
  1118. /**
  1119. * Replaces Aeva slide settings with this modifications so they act similar
  1120. * @param type $lightbox
  1121. * @return type
  1122. */
  1123. function aeva_initGallery_hs4smf(&$lightbox)
  1124. {
  1125. global $settings, $modSettings, $sourcedir, $context;
  1126. include_once($sourcedir . '/Aeva-Subs.php');
  1127. $context['hs4smf_slideshow_group']['aeva'] = 2;
  1128. // slideshow grouping in messages, remove aeva's and add in hs4smf's
  1129. if ($context['current_action'] == 'media' && !empty($modSettings['hs4smf_enabled']))
  1130. $lightbox = preg_replace('~if \(hs\.addSlideshow\) hs\.addSlideshow\(\{.*\}\);~sU', '', $lightbox);
  1131. // Add the things that aeva does not provide
  1132. $lightbox .= '
  1133. <script type="text/javascript"><!-- // --><![CDATA[
  1134. ';
  1135. $lightbox .= (!empty($modSettings['hs4smf_enablecredits'])) ? 'hs.showCredits = true;' . "\n" : 'hs.showCredits = false;' . "\n";
  1136. $lightbox .= (!empty($modSettings['hs4smf_enablegalleryfade'])) ? ' hs.fadeInOut = true;' . "\n" . ' hs.transitions = [\'expand\', \'crossfade\'];' . "\n" : 'hs.fadeInOut = false;' . "\n";
  1137. $lightbox .= (!empty($modSettings['hs4smf_enablecenter'])) ? ' hs.align = \'center\';' . "\n" : '';
  1138. $lightbox .= ' ' . hs4smf_language();
  1139. $lightbox .= ' ' . hs4smf_caption_text();
  1140. $lightbox .= ' ' . hs4smf_heading_text();
  1141. $lightbox .= hs4smf_caption_position();
  1142. $lightbox .= hs4smf_heading_position();
  1143. $lightbox .= ' ' . hs4smf_set_width();
  1144. $lightbox .= ' ' . hs4smf_mouse_action();
  1145. $lightbox .= ' ' . hs4smf_hc_opacity();
  1146. $lightbox .= ' ' . hs4smf_dimming_opacity();
  1147. $lightbox .= ' ' . hs4smf_control_wrapper();
  1148. $lightbox .= ' ' . hs4smf_slidshow_controls();
  1149. $lightbox .= ' // ]]></script>';
  1150. // change the ones that it does
  1151. $lightbox = str_replace("hs.outlineType = 'rounded-white';", hs4smf_frame_style(), $lightbox);
  1152. $lightbox = str_replace('<link rel="stylesheet" type="text/css" href="' . aeva_theme_url('hs.css') . '" media="screen" />', hs4smf_prepare_header(true), $lightbox);
  1153. $lightbox = str_replace('hs.graphicsDir = \'' . aeva_theme_url('hs/') . '\';', 'hs.graphicsDir = \'' . $settings['default_theme_url'] . '/hs4smf/graphics/\';', $lightbox);
  1154. return;
  1155. }
  1156. /**
  1157. * Case insensitive stripos replacement for php4 from subs-compat
  1158. *
  1159. */
  1160. if (!function_exists('stripos'))
  1161. {
  1162. // case insensitive stripos replacement for php4 from subs-compat
  1163. function stripos($haystack, $needle, $offset = 0)
  1164. {
  1165. return strpos(strtolower($haystack), strtolower($needle), $offset);
  1166. }
  1167. }
  1168. /**
  1169. * Case insensitive str_replace function for those that don't have PHP5 installed
  1170. */
  1171. if (!function_exists('str_ireplace'))
  1172. {
  1173. // case insensitive str_ireplace function for those that don't have PHP5 installed, from php.net
  1174. function str_ireplace($search, $replace, $subject)
  1175. {
  1176. global $context;
  1177. $endu = '~i' . ($context['utf8'] ? 'u' : '');
  1178. if (is_array($search))
  1179. foreach (array_keys($search) as $word)
  1180. $search[$word] = '~' . preg_quote($search[$word], '~') . $endu;
  1181. else
  1182. $search = '~' . preg_quote($search, '~') . $endu;
  1183. return preg_replace($search, $replace, $subject);
  1184. }
  1185. }
  1186. // These 3 functions are our integration hooks, they simply add the info to the admin panel for use
  1187. /**
  1188. * Add highslide ot the modification settings menu
  1189. * @global type $txt
  1190. * @param array $admin_areas
  1191. */
  1192. function iaa_hs4smf(&$admin_areas)
  1193. {
  1194. global $txt;
  1195. loadLanguage('hs4smf');
  1196. $admin_areas['config']['areas']['modsettings']['subsections']['hs4smf'] = array($txt['mods_cat_modifications_hs4smf']);
  1197. }
  1198. /**
  1199. * Adds the subaction to the modify menu
  1200. *
  1201. * @param array $sub_actions
  1202. */
  1203. function imm_hs4smf(&$sub_actions)
  1204. {
  1205. $sub_actions['hs4smf'] = 'Modifyhs4smfsettings';
  1206. }
  1207. /**
  1208. * The settings page for the modificaiton
  1209. */
  1210. function Modifyhs4smfsettings($return_config = false)
  1211. {
  1212. global $txt, $scripturl, $context;
  1213. loadLanguage('hs4smf');
  1214. $context[$context['admin_menu_name']]['tab_data']['tabs']['hs4smf']['description'] = $txt['hs4smf_desc'];
  1215. $config_vars = array(
  1216. array('check', 'hs4smf_enabled', 'postinput' => $txt['hs4smf_enabled_desc']),
  1217. array('title', 'hs4smf_settings'),
  1218. array('check', 'hs4smf_enableonattachments'),
  1219. array('check', 'hs4smf_aeva_format'),
  1220. array('check', 'hs4smf_gallerycounter'),
  1221. array('check', 'hs4smf_enablecenter'),
  1222. array('check', 'hs4smf_enablegalleryfade'),
  1223. array('check', 'hs4smf_sourcemouse'),
  1224. array('check', 'hs4smf_enablecoral', 'postinput' => $txt['hs4smf_enablecoral_desc']),
  1225. array('check', 'hs4smf_enablecredits'),
  1226. // Slideshow Settings
  1227. array('title', 'hs4smf_slideshowsettings'),
  1228. array('check', 'hs4smf_endableslideshow'),
  1229. array('check', 'hs4smf_slideshowgrouping'),
  1230. array('check', 'hs4smf_slideshowmouse'),
  1231. array('int', 'hs4smf_slideshowdelay'),
  1232. array('check', 'hs4smf_slideshowrepeat'),
  1233. array('check', 'hs4smf_slidecontrolsalways'),
  1234. array('select', 'hs4smf_slideshowcontrols', array(
  1235. '0' => $txt['hs4smf_text'],
  1236. '1' => $txt['hs4smf_smallw'],
  1237. '2' => $txt['hs4smf_largew'],
  1238. '3' => $txt['hs4smf_largeb'],
  1239. )),
  1240. array('select', 'hs4smf_slideshownumbers', array(
  1241. '0' => $txt['hs4smf_none'],
  1242. '1' => $txt['hs4smf_inheading'],
  1243. '2' => $txt['hs4smf_incaption'],
  1244. )),
  1245. array('select', 'hs4smf_slideshowcontrollocation', array(
  1246. '1' => $txt['hs4smf_above'],
  1247. '4' => $txt['hs4smf_top'] . ' ' . $txt['hs4smf_left'],
  1248. '5' => $txt['hs4smf_top'] . ' ' . $txt['hs4smf_center'],
  1249. '6' => $txt['hs4smf_top'] . ' ' . $txt['hs4smf_right'],
  1250. '7' => $txt['hs4smf_bottom'] . ' ' . $txt['hs4smf_left'],
  1251. '8' => $txt['hs4smf_bottom'] . ' ' . $txt['hs4smf_center'],
  1252. '9' => $txt['hs4smf_bottom'] . ' ' . $txt['hs4smf_right'],
  1253. '10' => $txt['hs4smf_below'],
  1254. )),
  1255. array('int', 'hs4smf_nudgex'),
  1256. array('int', 'hs4smf_nudgey'),
  1257. // Highslide Appearance
  1258. array('title', 'hs4smf_appearancesettings'),
  1259. array('select', 'hs4smf_appearance', array(
  1260. '1' => $txt['hs4smf_hrw'],
  1261. '2' => $txt['hs4smf_pos'],
  1262. '3' => $txt['hs4smf_borderless'],
  1263. '4' => $txt['hs4smf_dog'],
  1264. '5' => $txt['hs4smf_pas'],
  1265. '6' => $txt['hs4smf_dag'],
  1266. '7' => $txt['hs4smf_dbf'])),
  1267. array('text', 'hs4smf_slidebackgroundcolor'),
  1268. array('select', 'hs4smf_dimmingopacity', array(
  1269. '1' => $txt['hs4smf_00'] . ', ' . $txt['hs4smf_nodimming'],
  1270. '2' => $txt['hs4smf_10'],
  1271. '3' => $txt['hs4smf_20'],
  1272. '4' => $txt['hs4smf_30'],
  1273. '5' => $txt['hs4smf_40'],
  1274. '6' => $txt['hs4smf_50'],
  1275. '7' => $txt['hs4smf_60'],
  1276. '8' => $txt['hs4smf_70'],
  1277. '9' => $txt['hs4smf_80'],
  1278. '10' => $txt['hs4smf_90'],
  1279. '11' => $txt['hs4smf_100'] . ', ' . $txt['hs4smf_fullblack'],
  1280. )),
  1281. '',
  1282. array('select', 'hs4smf_headingsource', array(
  1283. '0' => $txt['hs4smf_none'],
  1284. '1' => $txt['hs4smf_imagetitle'],
  1285. '2' => $txt['hs4smf_imagealt'],
  1286. '3' => $txt['hs4smf_linktitle'],
  1287. '4' => $txt['hs4smf_postsubject']
  1288. )),
  1289. array('select', 'hs4smf_headingposition', array(
  1290. '0' => $txt['hs4smf_none'],
  1291. '1' => $txt['hs4smf_above'] . ' ' . $txt['hs4smf_image'],
  1292. '2' => $txt['hs4smf_overlayedon'] . ' ' . $txt['hs4smf_top'],
  1293. )),
  1294. '',
  1295. array('select', 'hs4smf_captionsource', array(
  1296. '0' => $txt['hs4smf_none'],
  1297. '1' => $txt['hs4smf_imagetitle'],
  1298. '2' => $txt['hs4smf_imagealt'],
  1299. '3' => $txt['hs4smf_linktitle'],
  1300. '4' => $txt['hs4smf_postsubject']
  1301. )),
  1302. array('select', 'hs4smf_captionposition', array(
  1303. '0' => $txt['hs4smf_none'],
  1304. '1' => $txt['hs4smf_below'] . ' ' . $txt['hs4smf_image'],
  1305. '2' => $txt['hs4smf_overlayedon'] . ' ' . $txt['hs4smf_bottom'],
  1306. )),
  1307. '',
  1308. array('select', 'hs4smf_sourceopacity', array(
  1309. '1' => $txt['hs4smf_00'] . ', ' . $txt['hs4smf_nodimming'],
  1310. '2' => $txt['hs4smf_10'],
  1311. '3' => $txt['hs4smf_20'],
  1312. '4' => $txt['hs4smf_30'],
  1313. '5' => $txt['hs4smf_40'],
  1314. '6' => $txt['hs4smf_50'],
  1315. '7' => $txt['hs4smf_60'],
  1316. '8' => $txt['hs4smf_70'],
  1317. '9' => $txt['hs4smf_80'],
  1318. '10' => $txt['hs4smf_90'],
  1319. '11' => $txt['hs4smf_100'] . ', ' . $txt['hs4smf_fullblack'],
  1320. )),
  1321. );
  1322. if ($return_config)
  1323. return $config_vars;
  1324. $context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=hs4smf';
  1325. $context['settings_title'] = $txt['mods_cat_modifications_hs4smf'];
  1326. if (isset($_GET['save']))
  1327. {
  1328. checkSession();
  1329. saveDBSettings($config_vars);
  1330. redirectexit('action=admin;area=modsettings;sa=hs4smf');
  1331. }
  1332. prepareDBSettingContext($config_vars);
  1333. }