PageRenderTime 61ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/wp-lightbox-2/wp-lightbox-2.php

https://bitbucket.org/elimendonca/iatai
PHP | 296 lines | 242 code | 9 blank | 45 comment | 32 complexity | 7d57b8ab0ff0f0de3aa5a39984baf379 MD5 | raw file
  1. <?php
  2. /**
  3. * Plugin Name: WP Lightbox 2
  4. * Plugin URI: http://onlinewebapplication.com/wp-lightbox-2/
  5. * Description: This plugin used to add the lightbox (overlay) effect to the current page images on your WordPress blog.
  6. * Version: 2.27
  7. * Author: masdiblogs
  8. * Author URI: http://profiles.wordpress.org/masdiblogs
  9. * License: GNU General Public License, v2 (or newer)
  10. * License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  11. */
  12. /* Copyright 2011 Pankaj Jha (onlinewebapplication.com)
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation using version 2 of the License.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. /*2.21 - Image Map, Shrink large images to fit smaller screens*/
  25. /*2.22 - Fixed one s, that caused a fatal error*/
  26. /*2.23 - Updated jQuery calls for faster load*/
  27. /*2.24 - Compatible with wordpress 3.4.2*/
  28. /*2.25 - Fixed PHP 5 bug*/
  29. /*2.26 - Compatible with wordpress 3.5*/
  30. /*2.27 - Compatible with wordpress 3.5.1*/
  31. add_action( 'plugins_loaded', 'jqlb_init' );
  32. function jqlb_init() {
  33. if(!defined('ULFBEN_DONATE_URL')){
  34. define('ULFBEN_DONATE_URL', 'http://onlinewebapplication.com/');
  35. }
  36. //JQLB_PLUGIN_DIR == plugin_dir_path(__FILE__);
  37. //JQLB_URL = plugin_dir_url(__FILE__);
  38. //JQLB_STYLES_URL = plugin_dir_url(__FILE__).'styles/'
  39. //JQLB_LANGUAGES_DIR = plugin_dir_path(__FILE__) . 'I18n/'
  40. define('JQLB_SCRIPT', 'wp-lightbox-2.min.js');
  41. load_plugin_textdomain('jqlb', false, dirname( plugin_basename( __FILE__ ) ) . '/I18n/');
  42. //load_plugin_textdomain('jqlb', false, plugin_dir_path(__FILE__).'I18n/');
  43. add_action('admin_init', 'jqlb_register_settings');
  44. add_action('admin_menu', 'jqlb_register_menu_item');
  45. add_action('wp_print_styles', 'jqlb_css');
  46. add_action('wp_print_scripts', 'jqlb_js');
  47. add_filter('plugin_row_meta', 'jqlb_set_plugin_meta', 2, 10);
  48. add_filter('the_content', 'jqlb_autoexpand_rel_wlightbox', 99);
  49. if(get_option('jqlb_comments') == 1){
  50. remove_filter('pre_comment_content', 'wp_rel_nofollow');
  51. add_filter('comment_text', 'jqlb_lightbox_comment', 99);
  52. }
  53. }
  54. function jqlb_set_plugin_meta( $links, $file ) { // Add a link to this plugin's settings page
  55. static $this_plugin;
  56. if(!$this_plugin) $this_plugin = plugin_basename(__FILE__);
  57. if($file == $this_plugin) {
  58. $settings_link = '<a href="options-general.php?page=jquery-lightbox-options">'.__('Settings', 'jqlb').'</a>';
  59. array_unshift($links, $settings_link);
  60. }
  61. return $links;
  62. }
  63. function jqlb_add_admin_footer(){ //shows some plugin info in the footer of the config screen.
  64. $plugin_data = get_plugin_data(__FILE__);
  65. }
  66. function jqlb_register_settings(){
  67. register_setting( 'jqlb-settings-group', 'jqlb_automate', 'jqlb_bool_intval');
  68. register_setting( 'jqlb-settings-group', 'jqlb_comments', 'jqlb_bool_intval');
  69. register_setting( 'jqlb-settings-group', 'jqlb_resize_on_demand', 'jqlb_bool_intval');
  70. register_setting( 'jqlb-settings-group', 'jqlb_show_download', 'jqlb_bool_intval');
  71. register_setting( 'jqlb-settings-group', 'jqlb_navbarOnTop', 'jqlb_bool_intval');
  72. register_setting( 'jqlb-settings-group', 'jqlb_margin_size', 'floatval');
  73. register_setting( 'jqlb-settings-group', 'jqlb_resize_speed', 'jqlb_pos_intval');
  74. register_setting( 'jqlb-settings-group', 'jqlb_help_text');
  75. register_setting( 'jqlb-settings-group', 'jqlb_link_target');
  76. //register_setting( 'jqlb-settings-group', 'jqlb_follow_scroll', 'jqlb_bool_intval');
  77. add_option('jqlb_help_text', '');
  78. add_option('jqlb_link_target', '_self');
  79. add_option('jqlb_automate', 1); //default is to auto-lightbox.
  80. add_option('jqlb_comments', 1);
  81. add_option('jqlb_resize_on_demand', 0);
  82. add_option('jqlb_show_download', 0);
  83. add_option('jqlb_navbarOnTop', 0);
  84. add_option('jqlb_resize_speed', 400);
  85. //add_option('jqlb_follow_scroll', 0);
  86. }
  87. function jqlb_register_menu_item() {
  88. add_options_page('WP Lightbox Options', 'WP Lightbox 2', 'manage_options', 'jquery-lightbox-options', 'jqlb_options_panel');
  89. }
  90. function jqlb_get_locale(){
  91. //$lang_locales and ICL_LANGUAGE_CODE are defined in the WPML plugin (http://wpml.org/)
  92. global $lang_locales;
  93. if (defined('ICL_LANGUAGE_CODE') && isset($lang_locales[ICL_LANGUAGE_CODE])){
  94. $locale = $lang_locales[ICL_LANGUAGE_CODE];
  95. } else {
  96. $locale = get_locale();
  97. }
  98. return $locale;
  99. }
  100. function jqlb_css(){
  101. if(is_admin() || is_feed()){return;}
  102. $locale = jqlb_get_locale();
  103. $fileName = "lightbox.min.{$locale}.css";
  104. $path = plugin_dir_path(__FILE__)."styles/{$fileName}";
  105. if(!is_readable($path)){
  106. $fileName = 'lightbox.min.css';
  107. }
  108. wp_enqueue_style('wp-lightbox-2.min.css', plugin_dir_url(__FILE__).'styles/'.$fileName, false, '1.3.4');
  109. }
  110. function jqlb_js() {
  111. if(is_admin() || is_feed()){return;}
  112. wp_enqueue_script('jquery', '', array(), '1.7.1', true);
  113. wp_enqueue_script('wp-jquery-lightbox', plugins_url(JQLB_SCRIPT, __FILE__ ), Array('jquery'), '1.3.4.1', true);
  114. wp_localize_script('wp-jquery-lightbox', 'JQLBSettings', array(
  115. 'fitToScreen' => get_option('jqlb_resize_on_demand'),
  116. 'resizeSpeed' => get_option('jqlb_resize_speed'),
  117. 'displayDownloadLink' => get_option('jqlb_show_download'),
  118. 'navbarOnTop' => get_option('jqlb_navbarOnTop'),
  119. 'loopImages' => get_option('jqlb_loopImages'),
  120. 'resizeCenter' => get_option('jqlb_resizeCenter'),
  121. 'marginSize' => get_option('jqlb_margin_size'),
  122. 'linkTarget' => get_option('jqlb_link_target'),
  123. //'followScroll' => get_option('jqlb_follow_scroll'),
  124. /* translation */
  125. 'help' => __(get_option('jqlb_help_text'), 'jqlb'),
  126. 'prevLinkTitle' => __('previous image', 'jqlb'),
  127. 'nextLinkTitle' => __('next image', 'jqlb'),
  128. 'prevLinkText' => __('&laquo; Previous', 'jqlb'),
  129. 'nextLinkText' => __('Next &raquo;', 'jqlb'),
  130. 'closeTitle' => __('close image gallery', 'jqlb'),
  131. 'image' => __('Image ', 'jqlb'),
  132. 'of' => __(' of ', 'jqlb'),
  133. 'download' => __('Download', 'jqlb')
  134. ));
  135. }
  136. function jqlb_lightbox_comment($comment){
  137. $comment = str_replace('rel=\'external nofollow\'','', $comment);
  138. $comment = str_replace('rel=\'nofollow\'','', $comment);
  139. $comment = str_replace('rel="external nofollow"','', $comment);
  140. $comment = str_replace('rel="nofollow"','', $comment);
  141. return jqlb_autoexpand_rel_wlightbox($comment);
  142. }
  143. function jqlb_autoexpand_rel_wlightbox($content) {
  144. if(get_option('jqlb_automate') == 1){
  145. global $post;
  146. $id = ($post->ID) ? $post->ID : -1;
  147. $content = jqlb_do_regexp($content, $id);
  148. }
  149. return $content;
  150. }
  151. function jqlb_apply_lightbox($content, $id = -1){
  152. if(!isset($id) || $id === -1){
  153. $id = time().rand(0, 32768);
  154. }
  155. return jqlb_do_regexp($content, $id);
  156. }
  157. /* automatically insert rel="lightbox[nameofpost]" to every image with no manual work.
  158. if there are already rel="lightbox[something]" attributes, they are not clobbered.
  159. Michael Tyson, you are a regular expressions god! - http://atastypixel.com */
  160. function jqlb_do_regexp($content, $id){
  161. $id = esc_attr($id);
  162. $pattern = "/(<a(?![^>]*?rel=['\"]lightbox.*)[^>]*?href=['\"][^'\"]+?\.(?:bmp|gif|jpg|jpeg|png)\?{0,1}\S{0,}['\"][^\>]*)>/i";
  163. $replacement = '$1 rel="lightbox['.$id.']">';
  164. return preg_replace($pattern, $replacement, $content);
  165. }
  166. function jqlb_bool_intval($v){
  167. return $v == 1 ? '1' : '0';
  168. }
  169. function jqlb_pos_intval($v){
  170. return abs(intval($v));
  171. }
  172. function jqlb_options_panel(){
  173. if(!function_exists('current_user_can') || !current_user_can('manage_options')){
  174. die(__('Cheatin&#8217; uh?', 'jqlb'));
  175. }
  176. add_action('in_admin_footer', 'jqlb_add_admin_footer');
  177. ?>
  178. <div class="wrap">
  179. <h2>WP Lightbox 2</h2>
  180. <div id="sideblock" style="float:right;width:270px;margin-left:10px;">
  181. <iframe width=270 height=500 frameborder="0" src="http://demos.onlinewebapplication.com/wp-internal-links/SEOIinternalLinks.html"></iframe>
  182. </div>
  183. <?php include_once(plugin_dir_path(__FILE__).'about.php'); ?>
  184. <form method="post" action="options.php">
  185. <table>
  186. <?php settings_fields('jqlb-settings-group'); ?>
  187. <tr valign="baseline" colspan="2">
  188. <td colspan="">
  189. <?php $check = get_option('jqlb_automate') ? ' checked="yes" ' : ''; ?>
  190. <input type="checkbox" id="jqlb_automate" name="jqlb_automate" value="1" <?php echo $check; ?>/>
  191. <label for="jqlb_automate" title="<?php _e('Let the plugin add necessary html to image links', 'jqlb') ?>"> <?php _e('Auto-lightbox image links', 'jqlb') ?></label>
  192. </td>
  193. </tr>
  194. <tr valign="baseline" colspan="2">
  195. <td colspan="2">
  196. <?php $check = get_option('jqlb_comments') ? ' checked="yes" ' : ''; ?>
  197. <input type="checkbox" id="jqlb_comments" name="jqlb_comments" value="1" <?php echo $check; ?>/>
  198. <label for="jqlb_comments" title="<?php _e('Note: this will disable the nofollow-attribute of comment links, that otherwise interfere with the lightbox.', 'jqlb') ?>"> <?php _e('Enable lightbox in comments (disables <a href="http://codex.wordpress.org/Nofollow">the nofollow attribute!</a>)', 'jqlb') ?></label>
  199. </td>
  200. </tr>
  201. <tr valign="baseline" colspan="2">
  202. <td>
  203. <?php $check = get_option('jqlb_show_download') ? ' checked="yes" ' : ''; ?>
  204. <input type="checkbox" id="jqlb_show_download" name="jqlb_show_download" value="1" <?php echo $check; ?> />
  205. <label for="jqlb_show_download"> <?php _e('Show download link', 'jqlb') ?> </label>
  206. </td>
  207. <td>
  208. <?php $target = get_option('jqlb_link_target'); ?>
  209. <label for="jqlb_link_target" title="<?php _e('_blank: open the image in a new window or tab
  210. _self: open the image in the same frame as it was clicked (default)
  211. _parent: open the image in the parent frameset
  212. _top: open the image in the full body of the window', 'jqlb') ?>"><?php _e('Target for download link:', 'jqlb'); ?></label>
  213. <select id="jqlb_link_target" name="jqlb_link_target">
  214. <option <?php if ('_blank' == $target)echo 'selected="selected"'; ?>>_blank</option>
  215. <option <?php if ('_self' == $target)echo 'selected="selected"'; ?>>_self</option>
  216. <option <?php if ('_top' == $target)echo 'selected="selected"'; ?>>_top</option>
  217. <option <?php if ('_parent' == $target)echo 'selected="selected"'; ?>>_parent</option>
  218. </select>
  219. </td>
  220. </tr>
  221. <tr valign="baseline" colspan="2">
  222. <td colspan="2">
  223. <?php $check = get_option('jqlb_navbarOnTop') ? ' checked="yes" ' : ''; ?>
  224. <input type="checkbox" id="jqlb_navbarOnTop" name="jqlb_navbarOnTop" value="1" <?php echo $check; ?> />
  225. <label for="jqlb_navbarOnTop">
  226. <?php _e('Show image info on top', 'jqlb') ?>
  227. </label>
  228. </td>
  229. </tr>
  230. <tr valign="baseline" colspan="2">
  231. <td>
  232. <?php $check = get_option('jqlb_resize_on_demand') ? ' checked="yes" ' : ''; ?>
  233. <input type="checkbox" id="jqlb_resize_on_demand" name="jqlb_resize_on_demand" value="1" <?php echo $check; ?> />
  234. <label for="jqlb_resize_on_demand"><?php _e('Shrink large images to fit smaller screens', 'jqlb') ?></label>
  235. </td>
  236. <?php IF($check != ''): ?>
  237. <td>
  238. <input type="text" id="jqlb_margin_size" name="jqlb_margin_size" value="<?php echo floatval(get_option('jqlb_margin_size')) ?>" size="3" />
  239. <label for="jqlb_margin_size" title="<?php _e('Keep a distance between the image and the screen edges.', 'jqlb') ?>"><?php _e('Minimum margin to screen edge (default: 0)', 'jqlb') ?></label>
  240. </td>
  241. <?php ENDIF; ?>
  242. </tr>
  243. <tr valign="baseline" colspan="2">
  244. <td colspan="2">
  245. <input type="text" id="jqlb_resize_speed" name="jqlb_resize_speed" value="<?php echo intval(get_option('jqlb_resize_speed')) ?>" size="3" />
  246. <label for="jqlb_resize_speed"><?php _e('Animation duration (in milliseconds) ', 'jqlb') ?></label>
  247. </td>
  248. </tr>
  249. <tr valign="baseline" colspan="2">
  250. <td>
  251. <input type="text" id="jqlb_help_text" name="jqlb_help_text" value="<?php echo get_option('jqlb_help_text'); ?>" size="30" />
  252. <label for="jqlb_help_text"><?php _e('Help text (default: none) ', 'jqlb'); ?></label>
  253. </td>
  254. </tr>
  255. </table>
  256. <p style="font-size:xx-small;font-style:italic;"><?php _e('Browse images with your keyboard: Arrows or P(revious)/N(ext) and X/C/ESC for close.', 'jqlb'); ?></p>
  257. <p class="submit">
  258. <input type="submit" name="Submit" value="<?php _e('Save Changes', 'jqlb') ?>" />
  259. </p>
  260. </form>
  261. <?php
  262. $locale = jqlb_get_locale();
  263. $diskfile = plugin_dir_path(__FILE__)."I18n/howtouse-{$locale}.html";
  264. if (!file_exists($diskfile)){
  265. $diskfile = plugin_dir_path(__FILE__).'I18n/howtouse.html';
  266. }
  267. $text = false;
  268. if(function_exists('file_get_contents')){
  269. $text = @file_get_contents($diskfile);
  270. } else {
  271. $text = @file($diskfile);
  272. if($text !== false){
  273. $text = implode("", $text);
  274. }
  275. }
  276. if($text === false){
  277. $text = '<p>The documentation files are missing! Try <a href="http://wordpress.org/extend/plugins/wp-lightbox-2/">downloading</a> and <a href="http://wordpress.org/extend/plugins/wp-lightbox-2/installation/">re-installing</a> this lightbox plugin.</p>';
  278. }
  279. echo $text;
  280. ?>
  281. </div>
  282. <?php }?>