PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/fs_index.php

http://fotoslide.googlecode.com/
PHP | 183 lines | 78 code | 25 blank | 80 comment | 7 complexity | 0979e30651679f8a99dc6039ddbe703b MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: FotoSlide
  4. Plugin URI: http://www.kevinbradwick.co.uk/
  5. Description: A plugin that renders multiple slideshows on your site
  6. Version: 2.0
  7. Author: Kevin Bradwick, Marko Heijnen
  8. Author URI: http://www.kevinbradwick.co.uk
  9. Licence: GPL2
  10. Copyright 2010 Kevin Bradwick <kbradwick@gmail.com>
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License, version 2, as
  13. published by the Free Software Foundation.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. global $wpdb;
  23. // define url to plugin directory
  24. defined('WP_PLUGIN_URL') || define(WP_PLUGIN_URL, WP_CONTENT_URL . '/plugins', true);
  25. // define admin url
  26. define('WP_PLUGIN_BASE_URL', get_bloginfo('url') . '/wp-admin/upload.php?page=fotoslide', true);
  27. // define db table name
  28. define('FS_TABLENAME', $wpdb->prefix.'fs_galleries', true);
  29. // load the helpers
  30. require_once(dirname(__FILE__).'/fs_helpers.php');
  31. // load admin menu
  32. require_once(dirname(__FILE__).'/fs_admin.php');
  33. // array holder for galleries
  34. $pageGalleries = array();
  35. /**
  36. * Register plugin activation
  37. *
  38. * Upon registering, the plugin will check for the exsitence of
  39. * the necessary table and create it if they do not exist
  40. *
  41. * @return null
  42. */
  43. function fs_activation()
  44. {
  45. global $wpdb;
  46. $schema = str_replace('{tablename}', FS_TABLENAME, file_get_contents(dirname(__FILE__).'/assets/schema.sql'));
  47. $wpdb->query($schema);
  48. }
  49. add_action('activate_fotoslide/fs_index.php', 'fs_activation');
  50. /**
  51. * Regiser scripts
  52. *
  53. * This will register the javascripts required
  54. * for the plugin to work. All scripts are placed in
  55. * the footer for better performance, so make sure
  56. * the template function wp_footer() is used in your
  57. * theme files.
  58. *
  59. * @return null
  60. */
  61. function fs_register_scripts()
  62. {
  63. wp_register_script( 'intelislide', plugins_url( 'assets/intelislide.jquery.min.js', __FILE__ ), array('jquery'), '1.0', false );
  64. }
  65. add_action('init','fs_register_scripts');
  66. /**
  67. * Register shortcode
  68. *
  69. * This adds the shortcode fs to the system so that
  70. * you can use the fs shortcode tag in the theme
  71. * files.
  72. *
  73. * @param array
  74. * @return null
  75. */
  76. function fs_shortcode( $params )
  77. {
  78. if(isset($params['id'])) {
  79. global $pageGalleries;
  80. $pageGalleries[] = $params['id'];
  81. echo fs_render_slider($params['id']);
  82. }
  83. }
  84. add_shortcode('fs','fs_shortcode');
  85. /**
  86. * Render galleries
  87. *
  88. * This filters a post/page content for the shortcode and
  89. * renders the appropriate gallery on the page
  90. *
  91. * @param string
  92. * @return null
  93. */
  94. function fs_filter_content( $content )
  95. {
  96. global $pageGalleries;
  97. $pattern = '/\[fs\sid=\"([0-9]*)\"\]/i';
  98. $galleries = array();
  99. if(preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) {
  100. foreach($matches as $gallery) {
  101. $slider = fs_render_slider(trim($gallery[1]));
  102. if($slider) {
  103. $content = str_replace('[fs id="'.$gallery[1].'"]', $slider, $content);
  104. $galleries[] = (int)$gallery[1];
  105. } else {
  106. $content = preg_replace('/\[fs\sid=\"'.$gallery[1].'\"\]/', '', $content);
  107. }
  108. }
  109. }
  110. if(count($galleries) > 0)
  111. $pageGalleries = $galleries;
  112. return $content;
  113. }
  114. add_filter('the_content','fs_filter_content');
  115. /**
  116. * Prepeare galleries code into the footer
  117. */
  118. function fs_prepare_js( $galleries = array() )
  119. {
  120. global $pageGalleries, $wpdb;
  121. if(count($pageGalleries) > 0) {
  122. wp_print_scripts('intelislide');
  123. $galleries = $wpdb->get_results("SELECT * FROM ".FS_TABLENAME." WHERE id IN(".implode(',',$pageGalleries).")");
  124. ?>
  125. <!-- simpleslide -->
  126. <script type="text/javascript">
  127. //<![CDATA[
  128. jQuery(document).ready(function($) {
  129. <?php foreach($galleries as $gallery) : ?>
  130. $("#fotoslide-<?php echo $gallery->id; ?>").intelislide({width:<?php echo $gallery->width; ?>,height:<?php echo $gallery->height; ?>,tagType:'span',transitionSpeed:<?php echo $gallery->transition_speed; ?>,timeout:<?php echo $gallery->timeout; ?>});
  131. <?php endforeach; ?>
  132. });
  133. //]]>
  134. </script>
  135. <?php
  136. }
  137. }
  138. add_action('wp_footer','fs_prepare_js');
  139. /**
  140. * Add icon to the page/post editor for selecting and inserting
  141. * FotoSlide galleries
  142. *
  143. * @return null
  144. */
  145. function fs_media_buttons()
  146. {
  147. ?>
  148. <a class="thickbox" href="<?php echo WP_PLUGIN_URL; ?>/fotoslide/fs_galselect.php?TB_iframe=1&amp;height=400" title="<?php _e('Select a FotoSlide gallery'); ?>">
  149. <img src="<?php echo WP_PLUGIN_URL; ?>/fotoslide/assets/photos.png" alt="FotoSlide Gallery Selector" />
  150. </a>
  151. <?php
  152. }
  153. add_action('media_buttons','fs_media_buttons',11);