PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/slidedeck2-professional/slidedeck2-tier20.php

https://bitbucket.org/russwittmann/baseball
PHP | 357 lines | 206 code | 62 blank | 89 comment | 26 complexity | 6d2cf4e3a94ed3b63e8e18fb534dcb7d MD5 | raw file
Possible License(s): GPL-3.0, AGPL-1.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. /*
  3. Plugin Name: SlideDeck 2 - Professional Addon Package
  4. Plugin URI: http://www.slidedeck.com/wordpress
  5. Description: Professional level addons for SlideDeck 2
  6. Version: 2.1.20120827
  7. Author: digital-telepathy
  8. Author URI: http://www.dtelepathy.com
  9. License: GPL3
  10. Copyright 2012 digital-telepathy (email : support@digital-telepathy.com)
  11. This file is part of SlideDeck.
  12. SlideDeck is free software: you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation, either version 3 of the License, or
  15. (at your option) any later version.
  16. SlideDeck 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 SlideDeck. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. if( !defined( "SLIDEDECK2_PROFESSIONAL_DIRNAME" ) ) define( "SLIDEDECK2_PROFESSIONAL_DIRNAME", dirname( __FILE__ ) );
  24. if( !defined( "SLIDEDECK2_PROFESSIONAL_URLPATH" ) ) define( "SLIDEDECK2_PROFESSIONAL_URLPATH", ( is_ssl() ? str_replace( "http://", "https://", WP_PLUGIN_URL ) : WP_PLUGIN_URL ) . "/" . basename( SLIDEDECK2_PROFESSIONAL_DIRNAME ) );
  25. if( !defined( "SLIDEDECK2_PROFESSIONAL_VERSION" ) ) define( "SLIDEDECK2_PROFESSIONAL_VERSION", "2.1.20120827" );
  26. class SlideDeckPluginProfessional {
  27. var $namespace = "slidedeck-professional";
  28. var $package_slug = 'tier_20';
  29. static $friendly_name = "SlideDeck 2 Professional Addon";
  30. // Additional source types loaded by this plugin
  31. var $sources = array();
  32. function __construct() {
  33. global $SlideDeckPlugin;
  34. // Fail silently if SlideDeck core is not installed
  35. if( !class_exists( 'SlideDeckPlugin' ) ) {
  36. return false;
  37. }
  38. SlideDeckPlugin::$addons_installed[$this->package_slug] = $this->package_slug;
  39. $this->slidedeck_namespace = SlideDeckPlugin::$namespace;
  40. /**
  41. * Make this plugin available for translation.
  42. * Translations can be added to the /languages/ directory.
  43. */
  44. load_plugin_textdomain( $this->slidedeck_namespace, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
  45. add_filter( 'slidedeck_create_custom_slidedeck_block', array( &$this, 'slidedeck_create_custom_slidedeck_block' ), 20 );
  46. add_filter( 'slidedeck_get_sources', array( &$this, 'slidedeck_get_sources' ) );
  47. add_filter( 'slidedeck_get_lenses', array( &$this, 'slidedeck_get_lenses' ), 9, 2 );
  48. $source_files = (array) glob( SLIDEDECK2_PROFESSIONAL_DIRNAME . '/sources/*/source.php' );
  49. foreach( (array) $source_files as $filename ) {
  50. if( is_readable( $filename ) ) {
  51. include_once( $filename );
  52. $slug = basename( dirname( $filename ) );
  53. $classname = slidedeck2_get_classname_from_filename( dirname( $filename ) );
  54. $prefix_classname = "SlideDeckSource_{$classname}";
  55. if( class_exists( $prefix_classname ) ) {
  56. $this->sources[$slug] = new $prefix_classname;
  57. }
  58. }
  59. }
  60. // Stock Lenses that come with SlideDeck Professional distribution
  61. $lens_files = glob( SLIDEDECK2_PROFESSIONAL_DIRNAME . '/lenses/*/lens.php' );
  62. // Load all the custom Lens types
  63. foreach( (array) $lens_files as $filename ) {
  64. if( is_readable( $filename ) ) {
  65. include_once ($filename);
  66. $classname = slidedeck2_get_classname_from_filename( dirname( $filename ) );
  67. $prefix_classname = "SlideDeckLens_{$classname}";
  68. if( class_exists( $prefix_classname ) ) {
  69. $SlideDeckPlugin->lenses[$classname] = new $prefix_classname;
  70. }
  71. }
  72. }
  73. }
  74. static function activate() {
  75. $installed_version = get_option( "slidedeck2_professional_version", "2.0" );
  76. if( !defined( 'SLIDEDECK2_DIRNAME' ) ) {
  77. die( "<strong>ERROR:</strong> SlideDeck 2 Personal is required for this plugin to be installed" );
  78. }
  79. if( $installed_version && version_compare( SLIDEDECK2_PROFESSIONAL_VERSION, $installed_version, '>' ) ) {
  80. if( version_compare( $installed_version, SLIDEDECK2_PROFESSIONAL_VERSION, '<' ) ) {
  81. if( !class_exists( "SlideDeck" ) ) {
  82. include( SLIDEDECK2_DIRNAME . '/classes/slidedeck.php' );
  83. }
  84. if( !class_exists( "SlideDeckSlide" ) ) {
  85. include( SLIDEDECK2_PROFESSIONAL_DIRNAME . '/sources/custom/slide-model.php' );
  86. }
  87. global $wpdb;
  88. $SlideDeck = new SlideDeck();
  89. $SlideDeckSlide = new SlideDeckSlide();
  90. $slidedecks = $SlideDeck->get( null, 'post_title', 'ASC', 'publish' );
  91. foreach( $slidedecks as $slidedeck ) {
  92. $sources = $slidedeck['source'];
  93. if( !is_array( $sources ) ) {
  94. $sources = array( $sources );
  95. }
  96. // Import Media Library SlideDecks
  97. if( in_array( "medialibrary", $sources ) && !in_array( "custom", $sources ) ) {
  98. $media_ids = $slidedeck['options']['medialibrary_ids'];
  99. $slide_counter = 0;
  100. foreach( $media_ids as $media_id ) {
  101. $media_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE ID = %d", $media_id ) );
  102. // Get the image meta data
  103. $meta_data = wp_get_attachment_metadata( $media_id );
  104. // Create the slide
  105. $slide_id = $SlideDeckSlide->create( $slidedeck['id'], "image", array(
  106. 'menu_order' => ( $slide_counter + 1 ),
  107. 'post_title' => $media_post->post_title,
  108. 'post_excerpt' => $media_post->post_excerpt,
  109. 'post_content' => $media_post->post_excerpt,
  110. 'post_date' => $media_post->post_date
  111. ) );
  112. // Associate the image with the slide
  113. update_post_meta( $slide_id, "_image_attachment", $media_id );
  114. update_post_meta( $slide_id, "_image_source", "upload" );
  115. update_post_meta( $slide_id, "_image_url", "" );
  116. $_layout = "body-text";
  117. $_caption_position = "left";
  118. switch( $slidedeck['lens'] ) {
  119. case "block-title":
  120. $_layout = "body-text";
  121. $_caption_position = "left";
  122. break;
  123. case "fashion":
  124. $_layout = "body-text";
  125. $_caption_position = "left";
  126. break;
  127. case "half-moon":
  128. $_layout = "body-text";
  129. $_caption_position = "right";
  130. break;
  131. case "o-town":
  132. $_layout = "body-text";
  133. $_caption_position = "left";
  134. break;
  135. case "proto":
  136. $_layout = "body-text";
  137. $_caption_position = "left";
  138. break;
  139. }
  140. update_post_meta( $slide_id, "_layout", $_layout );
  141. update_post_meta( $slide_id, "_caption_position", $_caption_position );
  142. $slidedeck['options']['total_slides'] = 999;
  143. $slide_counter++;
  144. }
  145. // Update the source
  146. add_post_meta( $slidedeck['id'], "slidedeck_source", "custom" );
  147. }
  148. // Import Video List SlideDecks
  149. if( in_array( "listofvideos", $sources ) && !in_array( "custom", $sources ) ) {
  150. $video_urls = get_post_meta( $slidedeck['id'], "slidedeck_list_of_videos", true );
  151. $video_urls = explode( "\n", $video_urls );
  152. $video_urls = array_map( "trim", $video_urls );
  153. $slide_counter = 0;
  154. foreach( $video_urls as $video_url ) {
  155. $video_meta = $SlideDeck->get_video_meta_from_url( $video_url );
  156. // Create the slide
  157. $slide_id = $SlideDeckSlide->create( $slidedeck['id'], "video", array(
  158. 'menu_order' => ( $slide_counter + 1 ),
  159. 'post_title' => slidedeck2_stip_tags_and_truncate_text( $video_meta['title'], $slidedeck['options']['titleLength'] ),
  160. 'post_excerpt' => slidedeck2_stip_tags_and_truncate_text( $video_meta['description'], $slidedeck['options']['descriptionLength'] ),
  161. 'post_content' => slidedeck2_stip_tags_and_truncate_text( $video_meta['description'], $slidedeck['options']['descriptionLength'] )
  162. ) );
  163. update_post_meta( $slide_id, "_permalink", $video_meta['permalink'] );
  164. update_post_meta( $slide_id, "_video_url", $video_url );
  165. update_post_meta( $slide_id, "_video_meta", $video_meta );
  166. $_layout = "body-text";
  167. $_caption_position = "left";
  168. switch( $slidedeck['lens'] ) {
  169. case "fashion":
  170. $_layout = "body-text";
  171. $_caption_position = "left";
  172. break;
  173. case "o-town":
  174. $_layout = "body-text";
  175. $_caption_position = "left";
  176. break;
  177. case "video":
  178. $_layout = "body-text";
  179. $_caption_position = "left";
  180. break;
  181. }
  182. update_post_meta( $slide_id, "_layout", $_layout );
  183. update_post_meta( $slide_id, "_caption_position", $_caption_position );
  184. $slidedeck['options']['total_slides'] = 999;
  185. $slidedeck['options']['show-excerpt'] = true;
  186. $slidedeck['options']['show-title'] = true;
  187. $slidedeck['options']['show-readmore'] = true;
  188. $slide_counter++;
  189. }
  190. // Update the source
  191. add_post_meta( $slidedeck['id'], "slidedeck_source", "custom" );
  192. // Proto video lens is being deprecated for custom SlideDecks
  193. if( $slidedeck['lens'] == "video" ) {
  194. update_post_meta( $slidedeck['id'], "slidedeck_lens", "tool-kit" );
  195. }
  196. }
  197. update_post_meta( $slidedeck['id'], "slidedeck_options", $slidedeck['options'] );
  198. }
  199. }
  200. }
  201. update_option( "slidedeck2_professional_version", SLIDEDECK2_PROFESSIONAL_VERSION );
  202. }
  203. /**
  204. * Initialization function to hook into the WordPress init action
  205. *
  206. * Instantiates the class on a global variable and sets the class, actions
  207. * etc. up for use.
  208. */
  209. static function instance() {
  210. global $SlideDeckPluginProfessional;
  211. $slidedeck2_version = defined( 'SLIDEDECK2_VERSION' ) ? SLIDEDECK2_VERSION : "2.0";
  212. if( version_compare( $slidedeck2_version, '2.1', ">=" ) ) {
  213. // Only instantiate the Class if it hasn't been already
  214. if( !isset( $SlideDeckPluginProfessional ) ) $SlideDeckPluginProfessional = new SlideDeckPluginProfessional();
  215. }
  216. }
  217. /**
  218. * Hook into slidedeck_create_custom_slidedeck_block filter
  219. *
  220. * Outputs the create custom slidedeck block on the manage page, replacing the default
  221. * with one that actually links to the creation of a Custom SlideDeck since this plugin
  222. * add-on adds that capability.
  223. *
  224. * @param string $html The HTML to be output
  225. *
  226. * @return string
  227. */
  228. function slidedeck_create_custom_slidedeck_block( $html ) {
  229. ob_start();
  230. include( SLIDEDECK2_PROFESSIONAL_DIRNAME . '/views/_create-custom-slidedeck-block.php' );
  231. $html = ob_get_contents();
  232. ob_end_clean();
  233. return $html;
  234. }
  235. /**
  236. * Hook into slidedeck_get_sources filter
  237. *
  238. * Adds additional slide types to the custom SlideDeck content source
  239. *
  240. * @param array $slide_types Available slide types
  241. *
  242. * @return array
  243. */
  244. function slidedeck_get_sources( $sources ) {
  245. // Loop through this plugin's source additions
  246. foreach( $this->sources as $source_type_key => $source ) {
  247. // Only add it to the array if it isn't defined already
  248. if( !isset( $sources[$source_type_key] ) ) {
  249. // Add the additional source to the available sources array
  250. $sources[$source_type_key] = $this->sources[$source_type_key];
  251. }
  252. }
  253. return $sources;
  254. }
  255. /**
  256. * Hook into slidedeck_get_lenses filter
  257. *
  258. * Add the Professional tier lenses to the lenses array
  259. *
  260. * @param array $lenses Available slide lenses
  261. * @param string $slug Slug of lens
  262. *
  263. * @uses $SlideDeckPlugin->Lens->get_meta()
  264. *
  265. * @return array
  266. */
  267. function slidedeck_get_lenses( $lenses, $slug ) {
  268. global $SlideDeckPlugin;
  269. $all_lens_files = array();
  270. $folders = !empty( $slug ) ? $slug : "*";
  271. // Get stock lens files that come with SlideDeck distribution
  272. $lens_files = (array) glob( SLIDEDECK2_PROFESSIONAL_DIRNAME . '/lenses/' . $folders . '/lens.json' );
  273. // Loop through each lens file to build an array of lenses
  274. foreach( (array) $lens_files as $lens_file ) {
  275. $key = basename( dirname( $lens_file ) );
  276. $all_lens_files[$key] = $lens_file;
  277. }
  278. // Append each lens to the $lenses array including the lens' meta
  279. foreach ( (array) array_values( $all_lens_files ) as $lens_file ) {
  280. if ( is_readable( $lens_file ) ) {
  281. $lens_meta = $SlideDeckPlugin->Lens->get_meta( $lens_file );
  282. $lenses[$lens_meta['slug']] = $lens_meta;
  283. }
  284. }
  285. return $lenses;
  286. }
  287. }
  288. register_activation_hook( __FILE__, array( 'SlideDeckPluginProfessional', 'activate' ) );
  289. // SlideDeck Personal should load, then Lite, then Professional, then Developer
  290. add_action( 'plugins_loaded', array( 'SlideDeckPluginProfessional', 'instance' ), 20 );