wp/wp-content/plugins/option-tree/ot-loader.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
--- a/wp/wp-content/plugins/option-tree/ot-loader.php	Mon Jun 08 16:11:51 2015 +0000
+++ b/wp/wp-content/plugins/option-tree/ot-loader.php	Tue Jun 09 03:35:32 2015 +0200
@@ -1,15 +1,32 @@
 <?php
 /**
  * Plugin Name: OptionTree
- * Plugin URI:  http://wp.envato.com
+ * Plugin URI:  https://github.com/valendesigns/option-tree/
  * Description: Theme Options UI Builder for WordPress. A simple way to create & save Theme Options and Meta Boxes for free or premium themes.
- * Version:     2.1.4
+ * Version:     2.5.5
  * Author:      Derek Herman
  * Author URI:  http://valendesigns.com
  * License:     GPLv3
  */
 
 /**
+ * Forces Plugin Mode when OptionTree is already loaded and displays an admin notice.
+ */
+if ( class_exists( 'OT_Loader' ) && defined( 'OT_PLUGIN_MODE' ) && OT_PLUGIN_MODE == true ) {
+  
+  add_filter( 'ot_theme_mode', '__return_false', 999 );
+  
+  function ot_conflict_notice() {
+    
+    echo '<div class="error"><p>' . __( 'OptionTree is installed as a plugin and also embedded in your current theme. Please deactivate the plugin to load the theme dependent version of OptionTree, and remove this warning.', 'option-tree' ) . '</p></div>';
+    
+  }
+  
+  add_action( 'admin_notices', 'ot_conflict_notice' );
+  
+}
+
+/**
  * This is the OptionTree loader class.
  *
  * @package   OptionTree
@@ -55,7 +72,7 @@
        *
        * @since     2.1.3
        */
-      define( 'OT_PLUGIN_MODE', strpos( dirname( __FILE__ ), 'plugins/' . basename( dirname( __FILE__ ) ) ) !== false ? true : false );
+      define( 'OT_PLUGIN_MODE', strpos( dirname( __FILE__ ), 'plugins' . DIRECTORY_SEPARATOR . basename( dirname( __FILE__ ) ) ) !== false ? true : false );
       
       /**
        * Path to the languages directory. 
@@ -63,8 +80,27 @@
        * This path will be relative in plugin mode and absolute in theme mode.
        *
        * @since     2.0.10
+       * @updated   2.4.1
        */
-      define( 'OT_LANG_DIR', dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
+      if ( OT_PLUGIN_MODE ) {
+        
+        define( 'OT_LANG_DIR', trailingslashit( dirname( plugin_basename( __FILE__ ) ) ) . trailingslashit( 'languages' ) );
+        
+      } else {
+      
+        if ( apply_filters( 'ot_child_theme_mode', false ) == true ) {
+        
+          $path = ltrim( end( @explode( get_stylesheet(), str_replace( '\\', '/', dirname( __FILE__ ) ) ) ), '/' );
+          define( 'OT_LANG_DIR', trailingslashit( trailingslashit( get_stylesheet_directory() ) . $path ) . trailingslashit( 'languages' ) . 'theme-mode' );
+          
+        } else {
+        
+          $path = ltrim( end( @explode( get_template(), str_replace( '\\', '/', dirname( __FILE__ ) ) ) ), '/' );
+          define( 'OT_LANG_DIR', trailingslashit( trailingslashit( get_template_directory() ) . $path ) . trailingslashit( 'languages' ) . 'theme-mode' );
+          
+        }
+      
+      }
 
       /* load the text domain  */
       if ( OT_PLUGIN_MODE ) {
@@ -95,7 +131,7 @@
         
       } else {
       
-        load_theme_textdomain( 'option-tree', OT_LANG_DIR . 'theme-mode' );
+        load_theme_textdomain( 'option-tree', OT_LANG_DIR );
         
       }
       
@@ -142,19 +178,7 @@
       /**
        * Current Version number.
        */
-      define( 'OT_VERSION', '2.1.4' );
-      
-      /**
-       * For developers: Allow Unfiltered HTML in all the textareas.
-       *
-       * Run a filter and set to true if you want all the
-       * users to be able to post anything in the textareas.
-       * WARNING: This opens a security hole for low level users
-       * to be able to post malicious scripts, you've been warned.
-       *
-       * @since     2.0
-       */
-      define( 'OT_ALLOW_UNFILTERED_HTML', apply_filters( 'ot_allow_unfiltered_html', false ) );
+      define( 'OT_VERSION', '2.5.5' );
       
       /**
        * For developers: Theme mode.
@@ -201,7 +225,7 @@
       define( 'OT_SHOW_OPTIONS_UI', apply_filters( 'ot_show_options_ui', true ) );
       
       /**
-       * For developers: Hide Settings Import
+       * For developers: Show Settings Import
        *
        * Run a filter and set to false if you want to hide the
        * Settings Import options on the Import page.
@@ -211,7 +235,7 @@
       define( 'OT_SHOW_SETTINGS_IMPORT', apply_filters( 'ot_show_settings_import', true ) );
       
       /**
-       * For developers: Hide Settings Export
+       * For developers: Show Settings Export
        *
        * Run a filter and set to false if you want to hide the
        * Settings Import options on the Import page.
@@ -260,6 +284,28 @@
       define( 'OT_META_BOXES', apply_filters( 'ot_meta_boxes', true ) );
       
       /**
+       * For developers: Allow Unfiltered HTML in all the textareas.
+       *
+       * Run a filter and set to true if you want all the
+       * users to be able to post anything in the textareas.
+       * WARNING: This opens a security hole for low level users
+       * to be able to post malicious scripts, you've been warned.
+       *
+       * @since     2.0
+       */
+      define( 'OT_ALLOW_UNFILTERED_HTML', apply_filters( 'ot_allow_unfiltered_html', false ) );
+
+      /**
+       * For developers: Post Formats.
+       *
+       * Run a filter and set to true if you want OptionTree 
+       * to load meta boxes for post formats.
+       *
+       * @since     2.4.0
+       */
+      define( 'OT_POST_FORMATS', apply_filters( 'ot_post_formats', false ) );
+      
+      /**
        * Check if in theme mode.
        *
        * If OT_THEME_MODE and OT_CHILD_THEME_MODE is false, set the 
@@ -273,11 +319,13 @@
         define( 'OT_URL', plugin_dir_url( __FILE__ ) );
       } else {
         if ( true == OT_CHILD_THEME_MODE ) {
-          define( 'OT_DIR', trailingslashit( get_stylesheet_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
-          define( 'OT_URL', trailingslashit( get_stylesheet_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
+          $path = ltrim( end( @explode( get_stylesheet(), str_replace( '\\', '/', dirname( __FILE__ ) ) ) ), '/' );
+          define( 'OT_DIR', trailingslashit( trailingslashit( get_stylesheet_directory() ) . $path ) );
+          define( 'OT_URL', trailingslashit( trailingslashit( get_stylesheet_directory_uri() ) . $path ) );
         } else {
-          define( 'OT_DIR', trailingslashit( get_template_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
-          define( 'OT_URL', trailingslashit( get_template_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
+          $path = ltrim( end( @explode( get_template(), str_replace( '\\', '/', dirname( __FILE__ ) ) ) ), '/' );
+          define( 'OT_DIR', trailingslashit( trailingslashit( get_template_directory() ) . $path ) );
+          define( 'OT_URL', trailingslashit( trailingslashit( get_template_directory_uri() ) . $path ) );
         }
       }
       
@@ -323,15 +371,23 @@
         $files[] = 'ot-meta-box-api';
       }
       
+      /* include the post formats api */
+      if ( OT_META_BOXES == true && OT_POST_FORMATS == true ) {
+        $files[] = 'ot-post-formats-api';
+      }
+      
       /* include the settings & docs pages */
       if ( OT_SHOW_PAGES == true ) {
         $files[] = 'ot-functions-settings-page';
         $files[] = 'ot-functions-docs-page';
       }
       
+      /* include the cleanup api */
+      $files[] = 'ot-cleanup-api';
+      
       /* require the files */
       foreach ( $files as $file ) {
-        $this->load_file( OT_DIR . "includes/{$file}.php" );
+        $this->load_file( OT_DIR . "includes" . DIRECTORY_SEPARATOR . "{$file}.php" );
       }
       
       /* Registers the Theme Option page */
@@ -364,7 +420,7 @@
 
       /* require the files */
       foreach ( $files as $file ) {
-        $this->load_file( OT_DIR . "includes/{$file}.php" );
+        $this->load_file( OT_DIR . "includes" . DIRECTORY_SEPARATOR . "{$file}.php" );
       }
       
     }
@@ -378,6 +434,18 @@
      * @since     2.0
      */
     private function hooks() {
+      
+      // Attempt to migrate the settings
+      if ( function_exists( 'ot_maybe_migrate_settings' ) )
+        add_action( 'init', 'ot_maybe_migrate_settings', 1 );
+      
+      // Attempt to migrate the Options
+      if ( function_exists( 'ot_maybe_migrate_options' ) )
+        add_action( 'init', 'ot_maybe_migrate_options', 1 );
+      
+      // Attempt to migrate the Layouts
+      if ( function_exists( 'ot_maybe_migrate_layouts' ) )
+        add_action( 'init', 'ot_maybe_migrate_layouts', 1 );
 
       /* load the Meta Box assets */
       if ( OT_META_BOXES == true ) {
@@ -421,7 +489,10 @@
       
       /* global CSS */
       add_action( 'admin_head', array( $this, 'global_admin_css' ) );
-      
+
+      /* Google Fonts front-end CSS */
+      add_action( 'wp_enqueue_scripts', 'ot_load_google_fonts_css', 1 );
+ 
       /* dynamic front-end CSS */
       add_action( 'wp_enqueue_scripts', 'ot_load_dynamic_css', 999 );
 
@@ -449,6 +520,18 @@
       /* AJAX call to create a new list item */
       add_action( 'wp_ajax_add_list_item', array( $this, 'add_list_item' ) );
       
+      /* AJAX call to create a new social link */
+      add_action( 'wp_ajax_add_social_links', array( $this, 'add_social_links' ) );
+
+      /* AJAX call to retrieve Google Font data */
+      add_action( 'wp_ajax_ot_google_font', array( $this, 'retrieve_google_font' ) );
+      
+      // Adds the temporary hacktastic shortcode
+      add_filter( 'media_view_settings', array( $this, 'shortcode' ), 10, 2 );
+    
+      // AJAX update
+      add_action( 'wp_ajax_gallery_update', array( $this, 'ajax_gallery_update' ) );
+      
       /* Modify the media uploader button */
       add_filter( 'gettext', array( $this, 'change_image_button' ), 10, 3 );
       
@@ -472,9 +555,57 @@
      * Adds the global CSS to fix the menu icon.
      */
     public function global_admin_css() {
+      global $wp_version;
+      
+      $wp_38plus = version_compare( $wp_version, '3.8', '>=' ) ? true : false;
+      $fontsize = $wp_38plus ? '20px' : '16px';
+      $wp_38minus = '';
+      
+      if ( ! $wp_38plus ) {
+        $wp_38minus = '
+        #adminmenu #toplevel_page_ot-settings .menu-icon-generic div.wp-menu-image {
+          background: none;
+        }
+        #adminmenu #toplevel_page_ot-settings .menu-icon-generic div.wp-menu-image:before {
+          padding-left: 6px;
+        }';
+      }
+
       echo '
       <style>
-        #adminmenu #toplevel_page_ot-settings .wp-menu-image img { padding: 5px 0px 1px 6px !important; }
+        @font-face {
+          font-family: "option-tree-font";
+          src:url("' . OT_URL . 'assets/fonts/option-tree-font.eot");
+          src:url("' . OT_URL . 'assets/fonts/option-tree-font.eot?#iefix") format("embedded-opentype"),
+            url("' . OT_URL . 'assets/fonts/option-tree-font.woff") format("woff"),
+            url("' . OT_URL . 'assets/fonts/option-tree-font.ttf") format("truetype"),
+            url("' . OT_URL . 'assets/fonts/option-tree-font.svg#option-tree-font") format("svg");
+          font-weight: normal;
+          font-style: normal;
+        }
+        #adminmenu #toplevel_page_ot-settings .menu-icon-generic div.wp-menu-image:before,
+        #option-tree-header #option-tree-logo a:before {
+          font: normal ' . $fontsize . '/1 "option-tree-font" !important;
+          speak: none;
+          padding: 6px 0;
+          height: 34px;
+          width: 20px;
+          display: inline-block;
+          -webkit-font-smoothing: antialiased;
+          -moz-osx-font-smoothing: grayscale;
+          -webkit-transition: all .1s ease-in-out;
+          -moz-transition:    all .1s ease-in-out;
+          transition:         all .1s ease-in-out;
+        }
+        #adminmenu #toplevel_page_ot-settings .menu-icon-generic div.wp-menu-image:before,
+        #option-tree-header #option-tree-logo a:before {
+          content: "\e785";
+        }
+        #option-tree-header #option-tree-logo a:before {
+          font-size: 20px !important;
+          height: 24px;
+          padding: 2px 0;
+        }'  . $wp_38minus . '
       </style>
       ';
     }
@@ -483,7 +614,7 @@
      * AJAX utility function for adding a new section.
      */
     public function add_section() {
-      echo ot_sections_view( 'option_tree_settings[sections]', $_REQUEST['count'] );
+      echo ot_sections_view( ot_settings_id() . '[sections]', $_REQUEST['count'] );
       die();
     }
     
@@ -536,6 +667,109 @@
     }
     
     /**
+     * AJAX utility function for adding a new social link.
+     */
+    public function add_social_links() {
+      ot_social_links_view( $_REQUEST['name'], $_REQUEST['count'], array(), $_REQUEST['post_id'], $_REQUEST['get_option'], unserialize( ot_decode( $_REQUEST['settings'] ) ), $_REQUEST['type'] );
+      die();
+    }
+    
+    /**
+     * Fake the gallery shortcode
+     *
+     * The JS takes over and creates the actual shortcode with 
+     * the real attachment IDs on the fly. Here we just need to 
+     * pass in the post ID to get the ball rolling.
+     *
+     * @param     array     The current settings
+     * @param     object    The post object
+     * @return    array
+     *
+     * @access    public
+     * @since     2.2.0
+     */
+    public function shortcode( $settings, $post ) {
+      global $pagenow;
+
+      if ( in_array( $pagenow, array( 'upload.php', 'customize.php' ) ) ) {
+        return $settings;
+      }
+
+      // Set the OptionTree post ID
+      if ( ! is_object( $post ) ) {
+        $post_id = isset( $_GET['post'] ) ? $_GET['post'] : ( isset( $_GET['post_ID'] ) ? $_GET['post_ID'] : 0 );
+        if ( $post_id == 0 && function_exists( 'ot_get_media_post_ID' ) ) {
+          $post_id = ot_get_media_post_ID();
+        }
+        $settings['post']['id'] = $post_id;
+      }
+      
+      // No ID return settings
+      if ( $settings['post']['id'] == 0 )
+        return $settings;
+  
+      // Set the fake shortcode
+      $settings['ot_gallery'] = array( 'shortcode' => "[gallery id='{$settings['post']['id']}']" );
+      
+      // Return settings
+      return $settings;
+      
+    }
+    
+    /**
+     * Returns the AJAX images
+     *
+     * @return    string
+     *
+     * @access    public
+     * @since     2.2.0
+     */
+    public function ajax_gallery_update() {
+    
+      if ( ! empty( $_POST['ids'] ) )  {
+        
+        $return = '';
+        
+        foreach( $_POST['ids'] as $id ) {
+        
+          $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' );
+          
+          $return .= '<li><img  src="' . $thumbnail[0] . '" width="75" height="75" /></li>';
+          
+        }
+        
+        echo $return;
+        exit();
+      
+      }
+      
+    }
+
+    /**
+     * Returns a JSON encoded Google fonts array.
+     *
+     * @return    array
+     *
+     * @access    public
+     * @since     2.5.0
+     */
+    public function retrieve_google_font() {
+
+      if ( isset( $_POST['field_id'], $_POST['family'] ) ) {
+        
+        ot_fetch_google_fonts();
+        
+        echo json_encode( array(
+          'variants' => ot_recognized_google_font_variants( $_POST['field_id'], $_POST['family'] ),
+          'subsets'  => ot_recognized_google_font_subsets( $_POST['field_id'], $_POST['family'] )
+        ) );
+        exit();
+
+      }
+
+    }
+    
+    /**
      * Filters the media uploader button.
      *
      * @return    string
@@ -546,11 +780,11 @@
     public function change_image_button( $translation, $text, $domain ) {
       global $pagenow;
     
-      if ( $pagenow == 'themes.php' && 'default' == $domain && 'Insert into post' == $text ) {
+      if ( $pagenow == apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ) && 'default' == $domain && 'Insert into post' == $text ) {
         
         // Once is enough.
         remove_filter( 'gettext', array( $this, 'ot_change_image_button' ) );
-        return 'Send to OptionTree';
+        return apply_filters( 'ot_upload_text', __( 'Send to OptionTree', 'option-tree' ) );
         
       }
       
@@ -558,6 +792,7 @@
       
     }
     
+    
   }
   
   /**
@@ -570,4 +805,4 @@
 }
 
 /* End of file ot-loader.php */
-/* Location: ./ot-loader.php */
\ No newline at end of file
+/* Location: ./ot-loader.php */