/wp-content/plugins/slidedeck2-professional/slidedeck2-tier20.php
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
- <?php
- /*
- Plugin Name: SlideDeck 2 - Professional Addon Package
- Plugin URI: http://www.slidedeck.com/wordpress
- Description: Professional level addons for SlideDeck 2
- Version: 2.1.20120827
- Author: digital-telepathy
- Author URI: http://www.dtelepathy.com
- License: GPL3
- Copyright 2012 digital-telepathy (email : support@digital-telepathy.com)
- This file is part of SlideDeck.
- SlideDeck is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- SlideDeck is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with SlideDeck. If not, see <http://www.gnu.org/licenses/>.
- */
- if( !defined( "SLIDEDECK2_PROFESSIONAL_DIRNAME" ) ) define( "SLIDEDECK2_PROFESSIONAL_DIRNAME", dirname( __FILE__ ) );
- 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 ) );
- if( !defined( "SLIDEDECK2_PROFESSIONAL_VERSION" ) ) define( "SLIDEDECK2_PROFESSIONAL_VERSION", "2.1.20120827" );
- class SlideDeckPluginProfessional {
- var $namespace = "slidedeck-professional";
- var $package_slug = 'tier_20';
-
- static $friendly_name = "SlideDeck 2 Professional Addon";
-
- // Additional source types loaded by this plugin
- var $sources = array();
-
- function __construct() {
- global $SlideDeckPlugin;
-
- // Fail silently if SlideDeck core is not installed
- if( !class_exists( 'SlideDeckPlugin' ) ) {
- return false;
- }
-
- SlideDeckPlugin::$addons_installed[$this->package_slug] = $this->package_slug;
-
- $this->slidedeck_namespace = SlideDeckPlugin::$namespace;
-
- /**
- * Make this plugin available for translation.
- * Translations can be added to the /languages/ directory.
- */
- load_plugin_textdomain( $this->slidedeck_namespace, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
-
- add_filter( 'slidedeck_create_custom_slidedeck_block', array( &$this, 'slidedeck_create_custom_slidedeck_block' ), 20 );
- add_filter( 'slidedeck_get_sources', array( &$this, 'slidedeck_get_sources' ) );
- add_filter( 'slidedeck_get_lenses', array( &$this, 'slidedeck_get_lenses' ), 9, 2 );
-
- $source_files = (array) glob( SLIDEDECK2_PROFESSIONAL_DIRNAME . '/sources/*/source.php' );
- foreach( (array) $source_files as $filename ) {
- if( is_readable( $filename ) ) {
- include_once( $filename );
-
- $slug = basename( dirname( $filename ) );
- $classname = slidedeck2_get_classname_from_filename( dirname( $filename ) );
- $prefix_classname = "SlideDeckSource_{$classname}";
- if( class_exists( $prefix_classname ) ) {
- $this->sources[$slug] = new $prefix_classname;
- }
- }
- }
-
- // Stock Lenses that come with SlideDeck Professional distribution
- $lens_files = glob( SLIDEDECK2_PROFESSIONAL_DIRNAME . '/lenses/*/lens.php' );
-
- // Load all the custom Lens types
- foreach( (array) $lens_files as $filename ) {
- if( is_readable( $filename ) ) {
- include_once ($filename);
- $classname = slidedeck2_get_classname_from_filename( dirname( $filename ) );
- $prefix_classname = "SlideDeckLens_{$classname}";
-
- if( class_exists( $prefix_classname ) ) {
- $SlideDeckPlugin->lenses[$classname] = new $prefix_classname;
- }
- }
- }
- }
- static function activate() {
- $installed_version = get_option( "slidedeck2_professional_version", "2.0" );
-
- if( !defined( 'SLIDEDECK2_DIRNAME' ) ) {
- die( "<strong>ERROR:</strong> SlideDeck 2 Personal is required for this plugin to be installed" );
- }
-
- if( $installed_version && version_compare( SLIDEDECK2_PROFESSIONAL_VERSION, $installed_version, '>' ) ) {
- if( version_compare( $installed_version, SLIDEDECK2_PROFESSIONAL_VERSION, '<' ) ) {
- if( !class_exists( "SlideDeck" ) ) {
- include( SLIDEDECK2_DIRNAME . '/classes/slidedeck.php' );
- }
- if( !class_exists( "SlideDeckSlide" ) ) {
- include( SLIDEDECK2_PROFESSIONAL_DIRNAME . '/sources/custom/slide-model.php' );
- }
- global $wpdb;
-
- $SlideDeck = new SlideDeck();
- $SlideDeckSlide = new SlideDeckSlide();
-
- $slidedecks = $SlideDeck->get( null, 'post_title', 'ASC', 'publish' );
-
- foreach( $slidedecks as $slidedeck ) {
- $sources = $slidedeck['source'];
- if( !is_array( $sources ) ) {
- $sources = array( $sources );
- }
-
- // Import Media Library SlideDecks
- if( in_array( "medialibrary", $sources ) && !in_array( "custom", $sources ) ) {
- $media_ids = $slidedeck['options']['medialibrary_ids'];
- $slide_counter = 0;
-
- foreach( $media_ids as $media_id ) {
- $media_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE ID = %d", $media_id ) );
- // Get the image meta data
- $meta_data = wp_get_attachment_metadata( $media_id );
-
- // Create the slide
- $slide_id = $SlideDeckSlide->create( $slidedeck['id'], "image", array(
- 'menu_order' => ( $slide_counter + 1 ),
- 'post_title' => $media_post->post_title,
- 'post_excerpt' => $media_post->post_excerpt,
- 'post_content' => $media_post->post_excerpt,
- 'post_date' => $media_post->post_date
- ) );
-
- // Associate the image with the slide
- update_post_meta( $slide_id, "_image_attachment", $media_id );
- update_post_meta( $slide_id, "_image_source", "upload" );
- update_post_meta( $slide_id, "_image_url", "" );
-
- $_layout = "body-text";
- $_caption_position = "left";
- switch( $slidedeck['lens'] ) {
- case "block-title":
- $_layout = "body-text";
- $_caption_position = "left";
- break;
-
- case "fashion":
- $_layout = "body-text";
- $_caption_position = "left";
- break;
-
- case "half-moon":
- $_layout = "body-text";
- $_caption_position = "right";
- break;
-
- case "o-town":
- $_layout = "body-text";
- $_caption_position = "left";
- break;
-
- case "proto":
- $_layout = "body-text";
- $_caption_position = "left";
- break;
- }
- update_post_meta( $slide_id, "_layout", $_layout );
- update_post_meta( $slide_id, "_caption_position", $_caption_position );
-
- $slidedeck['options']['total_slides'] = 999;
-
- $slide_counter++;
- }
-
- // Update the source
- add_post_meta( $slidedeck['id'], "slidedeck_source", "custom" );
- }
-
- // Import Video List SlideDecks
- if( in_array( "listofvideos", $sources ) && !in_array( "custom", $sources ) ) {
- $video_urls = get_post_meta( $slidedeck['id'], "slidedeck_list_of_videos", true );
- $video_urls = explode( "\n", $video_urls );
- $video_urls = array_map( "trim", $video_urls );
-
- $slide_counter = 0;
- foreach( $video_urls as $video_url ) {
- $video_meta = $SlideDeck->get_video_meta_from_url( $video_url );
- // Create the slide
- $slide_id = $SlideDeckSlide->create( $slidedeck['id'], "video", array(
- 'menu_order' => ( $slide_counter + 1 ),
- 'post_title' => slidedeck2_stip_tags_and_truncate_text( $video_meta['title'], $slidedeck['options']['titleLength'] ),
- 'post_excerpt' => slidedeck2_stip_tags_and_truncate_text( $video_meta['description'], $slidedeck['options']['descriptionLength'] ),
- 'post_content' => slidedeck2_stip_tags_and_truncate_text( $video_meta['description'], $slidedeck['options']['descriptionLength'] )
- ) );
-
- update_post_meta( $slide_id, "_permalink", $video_meta['permalink'] );
- update_post_meta( $slide_id, "_video_url", $video_url );
- update_post_meta( $slide_id, "_video_meta", $video_meta );
-
- $_layout = "body-text";
- $_caption_position = "left";
- switch( $slidedeck['lens'] ) {
- case "fashion":
- $_layout = "body-text";
- $_caption_position = "left";
- break;
-
- case "o-town":
- $_layout = "body-text";
- $_caption_position = "left";
- break;
-
- case "video":
- $_layout = "body-text";
- $_caption_position = "left";
- break;
- }
- update_post_meta( $slide_id, "_layout", $_layout );
- update_post_meta( $slide_id, "_caption_position", $_caption_position );
-
- $slidedeck['options']['total_slides'] = 999;
- $slidedeck['options']['show-excerpt'] = true;
- $slidedeck['options']['show-title'] = true;
- $slidedeck['options']['show-readmore'] = true;
-
- $slide_counter++;
- }
-
- // Update the source
- add_post_meta( $slidedeck['id'], "slidedeck_source", "custom" );
-
- // Proto video lens is being deprecated for custom SlideDecks
- if( $slidedeck['lens'] == "video" ) {
- update_post_meta( $slidedeck['id'], "slidedeck_lens", "tool-kit" );
- }
- }
-
- update_post_meta( $slidedeck['id'], "slidedeck_options", $slidedeck['options'] );
- }
- }
- }
- update_option( "slidedeck2_professional_version", SLIDEDECK2_PROFESSIONAL_VERSION );
- }
-
- /**
- * Initialization function to hook into the WordPress init action
- *
- * Instantiates the class on a global variable and sets the class, actions
- * etc. up for use.
- */
- static function instance() {
- global $SlideDeckPluginProfessional;
-
- $slidedeck2_version = defined( 'SLIDEDECK2_VERSION' ) ? SLIDEDECK2_VERSION : "2.0";
-
- if( version_compare( $slidedeck2_version, '2.1', ">=" ) ) {
- // Only instantiate the Class if it hasn't been already
- if( !isset( $SlideDeckPluginProfessional ) ) $SlideDeckPluginProfessional = new SlideDeckPluginProfessional();
- }
- }
-
- /**
- * Hook into slidedeck_create_custom_slidedeck_block filter
- *
- * Outputs the create custom slidedeck block on the manage page, replacing the default
- * with one that actually links to the creation of a Custom SlideDeck since this plugin
- * add-on adds that capability.
- *
- * @param string $html The HTML to be output
- *
- * @return string
- */
- function slidedeck_create_custom_slidedeck_block( $html ) {
- ob_start();
- include( SLIDEDECK2_PROFESSIONAL_DIRNAME . '/views/_create-custom-slidedeck-block.php' );
- $html = ob_get_contents();
- ob_end_clean();
-
- return $html;
- }
-
- /**
- * Hook into slidedeck_get_sources filter
- *
- * Adds additional slide types to the custom SlideDeck content source
- *
- * @param array $slide_types Available slide types
- *
- * @return array
- */
- function slidedeck_get_sources( $sources ) {
- // Loop through this plugin's source additions
- foreach( $this->sources as $source_type_key => $source ) {
- // Only add it to the array if it isn't defined already
- if( !isset( $sources[$source_type_key] ) ) {
- // Add the additional source to the available sources array
- $sources[$source_type_key] = $this->sources[$source_type_key];
- }
- }
-
- return $sources;
- }
-
- /**
- * Hook into slidedeck_get_lenses filter
- *
- * Add the Professional tier lenses to the lenses array
- *
- * @param array $lenses Available slide lenses
- * @param string $slug Slug of lens
- *
- * @uses $SlideDeckPlugin->Lens->get_meta()
- *
- * @return array
- */
- function slidedeck_get_lenses( $lenses, $slug ) {
- global $SlideDeckPlugin;
-
- $all_lens_files = array();
- $folders = !empty( $slug ) ? $slug : "*";
-
- // Get stock lens files that come with SlideDeck distribution
- $lens_files = (array) glob( SLIDEDECK2_PROFESSIONAL_DIRNAME . '/lenses/' . $folders . '/lens.json' );
-
- // Loop through each lens file to build an array of lenses
- foreach( (array) $lens_files as $lens_file ) {
- $key = basename( dirname( $lens_file ) );
- $all_lens_files[$key] = $lens_file;
- }
-
- // Append each lens to the $lenses array including the lens' meta
- foreach ( (array) array_values( $all_lens_files ) as $lens_file ) {
- if ( is_readable( $lens_file ) ) {
- $lens_meta = $SlideDeckPlugin->Lens->get_meta( $lens_file );
- $lenses[$lens_meta['slug']] = $lens_meta;
- }
- }
-
- return $lenses;
- }
- }
- register_activation_hook( __FILE__, array( 'SlideDeckPluginProfessional', 'activate' ) );
- // SlideDeck Personal should load, then Lite, then Professional, then Developer
- add_action( 'plugins_loaded', array( 'SlideDeckPluginProfessional', 'instance' ), 20 );