Plugin Directory

Changeset 1866507


Ignore:
Timestamp:
04/30/2018 02:30:20 PM (8 years ago)
Author:
playbuzz
Message:

refactor v1.0.6 to vip code styling

Location:
playbuzz/tags/1.0.6
Files:
1 added
34 edited

Legend:

Unmodified
Added
Removed
  • playbuzz/tags/1.0.6/class-pbconstants.php

    r1831521 r1866507  
    1010 */
    1111if ( ! defined( 'ABSPATH' ) ) {
    12     exit;
     12    exit;
    1313}
    1414/**
     
    1616 */
    1717class PbConstants {
    18     public static $pb_url_param_key = 'pb-story';
    19     public static $pb_url_param_value = 'true';
    20     public static $pb_nonce_key = 'nonce';
    21     public static $pb_nonce_value = 'pb';
     18    public static $pb_url_param_key  = 'pb-story';
     19    public static $pb_url_param_value = 'true';
     20    public static $pb_nonce_key      = 'nonce';
     21    public static $pb_nonce_value    = 'pb';
    2222}
  • playbuzz/tags/1.0.6/class-playbuzzembedcodes.php

    r1831521 r1866507  
    4141        global $wp_version;
    4242
    43         $site_key       = ( ( ( array_key_exists( 'key',               $options ) ) ) ? $options['key'] : str_replace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) ) );
    44         $site_info      = ( ( ( array_key_exists( 'info',              $options ) ) && ( '1' == $options['info']      ) ) ? 'true' : 'false' );
    45         $site_shares    = ( ( ( array_key_exists( 'shares',            $options ) ) && ( '1' == $options['shares']    ) ) ? 'true' : 'false' );
    46         $site_comments  = ( ( ( array_key_exists( 'comments',          $options ) ) && ( '1' == $options['comments'] ) ) ? 'true' : 'false' );
    47         $site_margintop = ( ( ( array_key_exists( 'margin-top',        $options ) ) ) ? $options['margin-top'] : '' );
    48         $width = 'auto';
    49         $height = 'auto';
     43        $site_key       = ( ( ( array_key_exists( 'key', $options ) ) ) ? $options['key'] : str_replace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) ) );
     44        $site_info      = ( ( ( array_key_exists( 'info', $options ) ) && ( '1' == $options['info'] ) ) ? 'true' : 'false' );
     45        $site_shares    = ( ( ( array_key_exists( 'shares', $options ) ) && ( '1' == $options['shares'] ) ) ? 'true' : 'false' );
     46        $site_comments  = ( ( ( array_key_exists( 'comments', $options ) ) && ( '1' == $options['comments'] ) ) ? 'true' : 'false' );
     47        $site_margintop = ( ( ( array_key_exists( 'margin-top', $options ) ) ) ? $options['margin-top'] : '' );
     48        $width          = 'auto';
     49        $height         = 'auto';
    5050
    51         $code = '<script type="text/javascript" src="' . esc_url( $this -> item_script_url ) . '"></script>
     51        $code = '<script type="text/javascript" src="' . esc_url( $this->item_script_url ) . '"></script>
    5252                <div class="pb_feed" data-provider="WordPress ' . esc_attr( $wp_version ) . '"
    5353                data-version=2
  • playbuzz/tags/1.0.6/class-playbuzzi18n.php

    r1831521 r1866507  
    6060        // Load textdomain
    6161
    62         add_action( 'plugins_loaded',  array( $this, 'load_textdomain' ) );
     62        add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
    6363
    6464    }
  • playbuzz/tags/1.0.6/class-playbuzzoptions.php

    r1831521 r1866507  
    55 */
    66if ( ! defined( 'ABSPATH' ) ) {
    7     exit;
     7    exit;
    88}
    99class PlaybuzzOptions {
    10     private $options_name = 'playbuzz';
    11     private $options_default = array(
    12         // General
    13         'key'               => 'default',
    14         'pb_user'           => '',
    15         'pb_channel_id'     => '',
    16         // items
    17         'jshead'            => '1',
    18         'info'              => '1',
    19         'shares'            => '1',
    20         'comments'          => '0',
    21         'recommend'         => '1',
    22         'margin-top'        => '0',
    23         'embeddedon'        => 'content',
    24         'locale'            => 'en-US',
    25         //experiment-mode
    26         'experiment-mode'   => '0',
    27         // Recommendations
    28         'active'            => 'false',
    29         'show'              => 'footer',
    30         'view'              => 'large_images',
    31         'items'             => '3',
    32         'links'             => 'https://www.playbuzz.com',
    33         'section-page'      => '',
    34         // Tags
    35         'tags-mix'          => '1',
    36         'tags-fun'          => '',
    37         'tags-pop'          => '',
    38         'tags-geek'         => '',
    39         'tags-sports'       => '',
    40         'tags-editors-pick' => '',
    41         'more-tags'         => '',
    42     );
    43     public function __construct() {
    44         //set default options case no options set
    45         //should run one time.
    46         if ( ! $this -> get_options() ) {
    47             $this -> set_default_options();
    48         }
    49     }
    50     /**
    51     * get options
    52     * @return mixed
    53     */
    54     public function get_options() {
    55         return get_option( $this -> options_name );
    56     }
    57     /**
    58     * set default options
    59     */
    60     function set_default_options() {
    61         // Set Default values
    62         $options_default = $this -> options_default;
    63         $options_name = $this -> options_name;
    64         // Set API Key
    65         if ( 'default' == $options_default['key'] ) {
    66             // Extract host domain
    67             $domain = parse_url( home_url(), PHP_URL_HOST );
    68             // Remove "www." from the domain
    69             $api = str_replace( 'www.', '', $domain );
    70             // Set API
    71             $options_default['key'] = $api;
    72         }
    73         // Update options on database
    74         update_option( $options_name, $options_default );
    75     }
     10    private $options_name    = 'playbuzz';
     11    private $options_default = array(
     12        // General
     13        'key'               => 'default',
     14        'pb_user'           => '',
     15        'pb_channel_id'     => '',
     16        // items
     17        'jshead'            => '1',
     18        'info'              => '1',
     19        'shares'            => '1',
     20        'comments'          => '0',
     21        'recommend'         => '1',
     22        'margin-top'        => '0',
     23        'embeddedon'        => 'content',
     24        'locale'            => 'en-US',
     25        //experiment-mode
     26        'experiment-mode'   => '0',
     27        // Recommendations
     28        'active'            => 'false',
     29        'show'              => 'footer',
     30        'view'              => 'large_images',
     31        'items'             => '3',
     32        'links'             => 'https://www.playbuzz.com',
     33        'section-page'      => '',
     34        // Tags
     35        'tags-mix'          => '1',
     36        'tags-fun'          => '',
     37        'tags-pop'          => '',
     38        'tags-geek'         => '',
     39        'tags-sports'       => '',
     40        'tags-editors-pick' => '',
     41        'more-tags'         => '',
     42    );
     43    public function __construct() {
     44        //set default options case no options set
     45        //should run one time.
     46        if ( ! $this->get_options() ) {
     47            $this->set_default_options();
     48        }
     49    }
     50    /**
     51    * get options
     52    * @return mixed
     53    */
     54    public function get_options() {
     55        return get_option( $this->options_name );
     56    }
     57    /**
     58    * set default options
     59    */
     60    function set_default_options() {
     61        // Set Default values
     62        $options_default = $this->options_default;
     63        $options_name    = $this->options_name;
     64        // Set API Key
     65        if ( 'default' == $options_default['key'] ) {
     66            // Extract host domain
     67            $domain = wp_parse_url( home_url(), PHP_URL_HOST );
     68            // Remove "www." from the domain
     69            $api = str_replace( 'www.', '', $domain );
     70            // Set API
     71            $options_default['key'] = $api;
     72        }
     73        // Update options on database
     74        update_option( $options_name, $options_default );
     75    }
    7676}
    7777new PlaybuzzOptions();
  • playbuzz/tags/1.0.6/class-playbuzzscriptsstyles.php

    r1831521 r1866507  
    4040    public function playbuzz_styles() {
    4141
    42         $version = $this -> pb_resource_version;
     42        $version = $this->pb_resource_version;
    4343
    4444        // Register Styles
    45         wp_register_style( 'playbuzz-admin',     plugins_url( 'css/admin.css',    __FILE__ ), false, $version );
     45        wp_register_style( 'playbuzz-admin', plugins_url( 'css/admin.css', __FILE__ ), false, $version );
    4646        wp_register_style( 'playbuzz-admin-rtl', plugins_url( 'css/admin-rtl.css', __FILE__ ), false, $version );
    4747
    4848        // Enqueue Styles
    4949        wp_enqueue_style( 'playbuzz-admin' );
    50         if ( is_rtl() ) { wp_enqueue_style( 'playbuzz-admin-rtl' );
     50        if ( is_rtl() ) {
     51            wp_enqueue_style( 'playbuzz-admin-rtl' );
    5152        }
    5253
     
    6566        }
    6667
    67         $version = $this -> pb_resource_version;
    68 
    69         wp_register_script( 'pb-options-model', plugins_url( 'js/options/pb-options-model.js', __FILE__ ), array( 'jquery' ), $version , true );
     68        $version = $this->pb_resource_version;
     69
     70        wp_register_script( 'pb-options-model', plugins_url( 'js/options/pb-options-model.js', __FILE__ ), array( 'jquery' ), $version, true );
    7071        wp_enqueue_script( 'pb-options-model' );
    7172
    72         wp_register_script( 'pb-options-controller', plugins_url( 'js/options/pb-options-controller.js', __FILE__ ), array( 'jquery' ), $version , true );
     73        wp_register_script( 'pb-options-controller', plugins_url( 'js/options/pb-options-controller.js', __FILE__ ), array( 'jquery' ), $version, true );
    7374        wp_enqueue_script( 'pb-options-controller' );
    7475
    75         wp_register_script( '_pb-options', plugins_url( 'js/options/_pb-options.js', __FILE__ ), array( 'jquery' ), $version , true );
     76        wp_register_script( '_pb-options', plugins_url( 'js/options/_pb-options.js', __FILE__ ), array( 'jquery' ), $version, true );
    7677        wp_enqueue_script( '_pb-options' );
    7778    }
     
    8788        }
    8889
    89         $version = $this -> pb_resource_version;
    90 
    91         wp_register_script( 'pb-all-posts-controller', plugins_url( 'js/all-posts/pb-all-posts-controller.js', __FILE__ ), array( 'jquery' ), $version , true );
     90        $version = $this->pb_resource_version;
     91
     92        wp_register_script( 'pb-all-posts-controller', plugins_url( 'js/all-posts/pb-all-posts-controller.js', __FILE__ ), array( 'jquery' ), $version, true );
    9293        wp_enqueue_script( 'pb-all-posts-controller' );
    9394
     
    104105        // Load settings
    105106        $options = get_option( 'playbuzz' );
    106         $version = $this -> pb_resource_version;
     107        $version = $this->pb_resource_version;
    107108
    108109        // Set settings for JS files
     
    114115        // Set localized translation strings for JS files
    115116        $js_translations = array(
    116             'playbuzz' => __( 'Playbuzz', 'playbuzz' ),
    117             'playbuzz_content' => __( 'Playbuzz Content', 'playbuzz' ),
    118             'my_items' => __( 'My Items', 'playbuzz' ),
    119             'create_your_own' => __( '+ Create Your Own', 'playbuzz' ),
    120             'search_term' => __( 'Search Term', 'playbuzz' ),
    121             'search_my_items' => __( 'Search my items', 'playbuzz' ),
    122             'results_for' => __( 'Results for', 'playbuzz' ),
    123             'no_results_found' => __( 'No results found', 'playbuzz' ),
    124             'try_different_search' => __( 'Please try again with a different search.', 'playbuzz' ),
    125             'change_user' => __( 'Change User', 'playbuzz' ),
    126             'server_error' => __( 'Server error', 'playbuzz' ),
    127             'try_in_a_few_minutes' => __( 'Please try again in a few minutes.', 'playbuzz' ),
    128             'no_user' => __( 'No user', 'playbuzz' ),
    129             'set_user' => __( 'Set User', 'playbuzz' ),
    130             'set_your_username' => __( 'Go to the <a href="options-general.php?page=playbuzz&tab=embed" target="_blank">Settings</a> and set your Playbuzz.com username.', 'playbuzz' ),
    131             'you_dont_have_any_items_yet' => __( 'You don\'t have any items (yet!).', 'playbuzz' ),
     117            'playbuzz'                                     => __( 'Playbuzz', 'playbuzz' ),
     118            'playbuzz_content'                             => __( 'Playbuzz Content', 'playbuzz' ),
     119            'my_items'                                     => __( 'My Items', 'playbuzz' ),
     120            'create_your_own'                              => __( '+ Create Your Own', 'playbuzz' ),
     121            'search_term'                                  => __( 'Search Term', 'playbuzz' ),
     122            'search_my_items'                              => __( 'Search my items', 'playbuzz' ),
     123            'results_for'                                  => __( 'Results for', 'playbuzz' ),
     124            'no_results_found'                             => __( 'No results found', 'playbuzz' ),
     125            'try_different_search'                         => __( 'Please try again with a different search.', 'playbuzz' ),
     126            'change_user'                                  => __( 'Change User', 'playbuzz' ),
     127            'server_error'                                 => __( 'Server error', 'playbuzz' ),
     128            'try_in_a_few_minutes'                         => __( 'Please try again in a few minutes.', 'playbuzz' ),
     129            'no_user'                                      => __( 'No user', 'playbuzz' ),
     130            'set_user'                                     => __( 'Set User', 'playbuzz' ),
     131            'set_your_username'                            => __( 'Go to the <a href="options-general.php?page=playbuzz&tab=embed" target="_blank">Settings</a> and set your Playbuzz.com username.', 'playbuzz' ),
     132            'you_dont_have_any_items_yet'                  => __( 'You don\'t have any items (yet!).', 'playbuzz' ),
    132133            'go_to_playbuzz_to_create_your_own_playful_content' => __( 'Go to <a href="https://www.playbuzz.com/" target="_blank">Playbuzz.com</a> to create your own playful content and embed on your site.', 'playbuzz' ),
    133             'page' => __( 'page', 'playbuzz' ),
    134             'jan' => __( 'Jan', 'playbuzz' ),
    135             'feb' => __( 'Feb', 'playbuzz' ),
    136             'mar' => __( 'Mar', 'playbuzz' ),
    137             'apr' => __( 'Apr', 'playbuzz' ),
    138             'may' => __( 'May', 'playbuzz' ),
    139             'jun' => __( 'Jun', 'playbuzz' ),
    140             'jul' => __( 'Jul', 'playbuzz' ),
    141             'aug' => __( 'Aug', 'playbuzz' ),
    142             'sep' => __( 'Sep', 'playbuzz' ),
    143             'oct' => __( 'Oct', 'playbuzz' ),
    144             'nov' => __( 'Nov', 'playbuzz' ),
    145             'dec' => __( 'Dec', 'playbuzz' ),
    146             'show' => __( 'Show', 'playbuzz' ),
    147             'all_types' => __( 'All Types', 'playbuzz' ),
    148             'personality_quiz' => __( 'Personality Quiz', 'playbuzz' ),
    149             'story' => __( 'Story', 'playbuzz' ),
    150             'list' => __( 'List', 'playbuzz' ),
    151             'trivia' => __( 'Trivia', 'playbuzz' ),
    152             'poll' => __( 'Poll', 'playbuzz' ),
    153             'ranked_list' => __( 'Ranked List', 'playbuzz' ),
    154             'gallery_quiz' => __( 'Gallery Quiz', 'playbuzz' ),
    155             'flip_cards' => __( 'Flip Cards', 'playbuzz' ),
    156             'swiper' => __( 'Swiper', 'playbuzz' ),
    157             'video_snaps' => __( 'Video Snaps', 'playbuzz' ),
    158             'convo' => __( 'Convo', 'playbuzz' ),
    159             'countdown' => __( 'Countdown', 'playbuzz' ),
    160             'sort_by' => __( 'Sort By', 'playbuzz' ),
    161             'relevance' => __( 'Relevance', 'playbuzz' ),
    162             'views' => __( 'Views', 'playbuzz' ),
    163             'date' => __( 'Date', 'playbuzz' ),
    164             'discover_playful_content' => __( 'Discover Playful Content', 'playbuzz' ),
    165             'featured_items' => __( 'Featured Items', 'playbuzz' ),
    166             'created_by' => __( 'Created by', 'playbuzz' ),
    167             'by_user' => __( 'by', 'playbuzz' ),
    168             'by' => __( 'By', 'playbuzz' ),
    169             'on' => __( 'on', 'playbuzz' ),
    170             'items' => __( 'items', 'playbuzz' ),
    171             'view' => __( 'View', 'playbuzz' ),
    172             'embed' => __( 'Embed', 'playbuzz' ),
    173             'preview_item' => __( 'Preview item', 'playbuzz' ),
    174             'item_doesnt_exist' => __( 'Playbuzz item does not exist', 'playbuzz' ),
    175             'check_shortcode_url' => __( 'Check shortcode URL in the text editor.', 'playbuzz' ),
    176             'your_item_will_be_embedded_here' => __( 'Your item will be embedded here', 'playbuzz' ),
    177             'playbuzz_item_settings' => __( 'Playbuzz Item Settings', 'playbuzz' ),
    178             'item_settings' => __( 'Item Settings', 'playbuzz' ),
    179             'embedded_item_appearance' => __( 'Embedded Item Appearance', 'playbuzz' ),
    180             'use_site_default_settings' => __( 'Use site default settings', 'playbuzz' ),
    181             'configure_default_settings' => __( 'Configure default settings', 'playbuzz' ),
    182             'custom' => __( 'Custom', 'playbuzz' ),
    183             'display_item_information' => __( 'Display item information', 'playbuzz' ),
     134            'page'                                         => __( 'page', 'playbuzz' ),
     135            'jan'                                          => __( 'Jan', 'playbuzz' ),
     136            'feb'                                          => __( 'Feb', 'playbuzz' ),
     137            'mar'                                          => __( 'Mar', 'playbuzz' ),
     138            'apr'                                          => __( 'Apr', 'playbuzz' ),
     139            'may'                                          => __( 'May', 'playbuzz' ),
     140            'jun'                                          => __( 'Jun', 'playbuzz' ),
     141            'jul'                                          => __( 'Jul', 'playbuzz' ),
     142            'aug'                                          => __( 'Aug', 'playbuzz' ),
     143            'sep'                                          => __( 'Sep', 'playbuzz' ),
     144            'oct'                                          => __( 'Oct', 'playbuzz' ),
     145            'nov'                                          => __( 'Nov', 'playbuzz' ),
     146            'dec'                                          => __( 'Dec', 'playbuzz' ),
     147            'show'                                         => __( 'Show', 'playbuzz' ),
     148            'all_types'                                    => __( 'All Types', 'playbuzz' ),
     149            'personality_quiz'                             => __( 'Personality Quiz', 'playbuzz' ),
     150            'story'                                        => __( 'Story', 'playbuzz' ),
     151            'list'                                         => __( 'List', 'playbuzz' ),
     152            'trivia'                                       => __( 'Trivia', 'playbuzz' ),
     153            'poll'                                         => __( 'Poll', 'playbuzz' ),
     154            'ranked_list'                                  => __( 'Ranked List', 'playbuzz' ),
     155            'gallery_quiz'                                 => __( 'Gallery Quiz', 'playbuzz' ),
     156            'flip_cards'                                   => __( 'Flip Cards', 'playbuzz' ),
     157            'swiper'                                       => __( 'Swiper', 'playbuzz' ),
     158            'video_snaps'                                  => __( 'Video Snaps', 'playbuzz' ),
     159            'convo'                                        => __( 'Convo', 'playbuzz' ),
     160            'countdown'                                    => __( 'Countdown', 'playbuzz' ),
     161            'sort_by'                                      => __( 'Sort By', 'playbuzz' ),
     162            'relevance'                                    => __( 'Relevance', 'playbuzz' ),
     163            'views'                                        => __( 'Views', 'playbuzz' ),
     164            'date'                                         => __( 'Date', 'playbuzz' ),
     165            'discover_playful_content'                     => __( 'Discover Playful Content', 'playbuzz' ),
     166            'featured_items'                               => __( 'Featured Items', 'playbuzz' ),
     167            'created_by'                                   => __( 'Created by', 'playbuzz' ),
     168            'by_user'                                      => __( 'by', 'playbuzz' ),
     169            'by'                                           => __( 'By', 'playbuzz' ),
     170            'on'                                           => __( 'on', 'playbuzz' ),
     171            'items'                                        => __( 'items', 'playbuzz' ),
     172            'view'                                         => __( 'View', 'playbuzz' ),
     173            'embed'                                        => __( 'Embed', 'playbuzz' ),
     174            'preview_item'                                 => __( 'Preview item', 'playbuzz' ),
     175            'item_doesnt_exist'                            => __( 'Playbuzz item does not exist', 'playbuzz' ),
     176            'check_shortcode_url'                          => __( 'Check shortcode URL in the text editor.', 'playbuzz' ),
     177            'your_item_will_be_embedded_here'              => __( 'Your item will be embedded here', 'playbuzz' ),
     178            'playbuzz_item_settings'                       => __( 'Playbuzz Item Settings', 'playbuzz' ),
     179            'item_settings'                                => __( 'Item Settings', 'playbuzz' ),
     180            'embedded_item_appearance'                     => __( 'Embedded Item Appearance', 'playbuzz' ),
     181            'use_site_default_settings'                    => __( 'Use site default settings', 'playbuzz' ),
     182            'configure_default_settings'                   => __( 'Configure default settings', 'playbuzz' ),
     183            'custom'                                       => __( 'Custom', 'playbuzz' ),
     184            'display_item_information'                     => __( 'Display item information', 'playbuzz' ),
    184185            'show_item_thumbnail_name_description_creator' => __( 'Show item thumbnail, name, description, creator.', 'playbuzz' ),
    185             'display_share_buttons' => __( 'Display share buttons', 'playbuzz' ),
    186             'show_share_buttons_with_links_to_your_site' => __( 'Show share buttons with links to YOUR site.', 'playbuzz' ),
    187             'display_more_recommendations' => __( 'Display more recommendations', 'playbuzz' ),
    188             'show_recommendations_for_more_items' => __( 'Show recommendations for more items.', 'playbuzz' ),
    189             'display_facebook_comments' => __( 'Display Facebook comments', 'playbuzz' ),
    190             'show_facebook_comments_in_your_items' => __( 'Show Facebook comments in your items.', 'playbuzz' ),
    191             'site_has_fixed_sticky_top_header' => __( 'Site has fixed (sticky) top header', 'playbuzz' ),
    192             'height' => __( 'Height', 'playbuzz' ),
    193             'px' => __( 'px', 'playbuzz' ),
     186            'display_share_buttons'                        => __( 'Display share buttons', 'playbuzz' ),
     187            'show_share_buttons_with_links_to_your_site'   => __( 'Show share buttons with links to YOUR site.', 'playbuzz' ),
     188            'display_more_recommendations'                 => __( 'Display more recommendations', 'playbuzz' ),
     189            'show_recommendations_for_more_items'          => __( 'Show recommendations for more items.', 'playbuzz' ),
     190            'display_facebook_comments'                    => __( 'Display Facebook comments', 'playbuzz' ),
     191            'show_facebook_comments_in_your_items'         => __( 'Show Facebook comments in your items.', 'playbuzz' ),
     192            'site_has_fixed_sticky_top_header'             => __( 'Site has fixed (sticky) top header', 'playbuzz' ),
     193            'height'                                       => __( 'Height', 'playbuzz' ),
     194            'px'                                           => __( 'px', 'playbuzz' ),
    194195            'use_this_if_your_website_has_top_header_thats_always_visible_even_while_scrolling_down' => __( 'Use this if your website has top header that\'s always visible, even while scrolling down.', 'playbuzz' ),
    195             'cancel' => __( 'Cancel', 'playbuzz' ),
    196             'update_item' => __( 'Update Item', 'playbuzz' ),
    197             'feedback_sent' => __( 'Feedback sent, thank you!', 'playbuzz' ),
    198             'feedback_error' => __( 'Something went wrong please try again...', 'playbuzz' ),
    199             'feedback_missing_required_fields' => __( 'Some required fields are missing.', 'playbuzz' ),
     196            'cancel'                                       => __( 'Cancel', 'playbuzz' ),
     197            'update_item'                                  => __( 'Update Item', 'playbuzz' ),
     198            'feedback_sent'                                => __( 'Feedback sent, thank you!', 'playbuzz' ),
     199            'feedback_error'                               => __( 'Something went wrong please try again...', 'playbuzz' ),
     200            'feedback_missing_required_fields'             => __( 'Some required fields are missing.', 'playbuzz' ),
    200201        );
    201202
     
    224225        wp_enqueue_script( 'pb-alert' );
    225226
    226         //register pb-event
    227         wp_register_script( 'pb-event', plugins_url( 'js/pb-event.js', __FILE__ ), array( 'jquery' ), $version );
    228         wp_enqueue_script( 'pb-event' );
    229 
    230         //register pb-event
    231         wp_register_script( 'pb-search-popup', plugins_url( 'js/pb-search-popup.js', __FILE__ ), array( 'jquery' ), $version );
    232         wp_enqueue_script( 'pb-search-popup' );
     227        //register pb-event
     228        wp_register_script( 'pb-event', plugins_url( 'js/pb-event.js', __FILE__ ), array( 'jquery' ), $version );
     229        wp_enqueue_script( 'pb-event' );
     230
     231        //register pb-event
     232        wp_register_script( 'pb-search-popup', plugins_url( 'js/pb-search-popup.js', __FILE__ ), array( 'jquery' ), $version );
     233        wp_enqueue_script( 'pb-search-popup' );
    233234
    234235        // Register Scripts
     
    237238        // Register Localized Scripts
    238239        wp_localize_script( 'playbuzz-admin', 'site_settings', $js_settings );
    239         wp_localize_script( 'playbuzz-admin', 'translation',   $js_translations );
     240        wp_localize_script( 'playbuzz-admin', 'translation', $js_translations );
    240241
    241242        // Enqueue Scripts
  • playbuzz/tags/1.0.6/class-playbuzzsettings.php

    r1831521 r1866507  
    8080
    8181        // Load settings
    82         $options = get_option( $this->get_option_name() );
    83         $nonce_key = PbConstants::$pb_nonce_key;
     82        $options     = get_option( $this->get_option_name() );
     83        $nonce_key   = PbConstants::$pb_nonce_key;
    8484        $nonce_value = PbConstants::$pb_nonce_value;
    8585
     
    8787        $playbuzz_active_tab = 'embed';
    8888
    89         if ( isset( $_GET['tab'], $_GET[ $nonce_key ] ) && wp_verify_nonce( sanitize_key( $_GET[ $nonce_key ] ) , $nonce_value ) ) {
     89        if ( isset( $_GET['tab'], $_GET[ $nonce_key ] ) && wp_verify_nonce( sanitize_key( $_GET[ $nonce_key ] ), $nonce_value ) ) {
    9090            $playbuzz_active_tab = sanitize_text_field( wp_unslash( $_GET['tab'] ) );
    9191        }
     
    9898            <h1><?php esc_html_e( 'Playbuzz Plugin', 'playbuzz' ); ?></h1>
    9999            <h2 class="nav-tab-wrapper">
    100                 <a href="?page=<?php echo urlencode( $this->get_option_name() ); ?>&tab=embed&<?php echo esc_html( $nonce_key ) . '=' . esc_html( $nonce ); ?>"      class="nav-tab <?php echo  ( 'embed' == $playbuzz_active_tab || 'start' == $playbuzz_active_tab ) ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Site Settings',   'playbuzz' ); ?></a>
    101                 <a href="?page=<?php echo urlencode( $this->get_option_name() ); ?>&tab=shortcodes&<?php echo esc_html( $nonce_key ) . '=' . esc_html( $nonce ); ?>" class="nav-tab <?php echo  'shortcodes' == $playbuzz_active_tab ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Shortcodes',      'playbuzz' ); ?></a>
    102                 <a href="?page=<?php echo urlencode( $this->get_option_name() ); ?>&tab=feedback&<?php echo esc_html( $nonce_key ) . '=' . esc_html( $nonce ); ?>"   class="nav-tab <?php echo  'feedback' == $playbuzz_active_tab ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Feedback',        'playbuzz' ); ?></a>
     100                <a href="?page=<?php echo urlencode( $this->get_option_name() ); ?>&tab=embed&<?php echo esc_html( $nonce_key ) . '=' . esc_html( $nonce ); ?>"      class="nav-tab <?php echo  ( 'embed' == $playbuzz_active_tab || 'start' == $playbuzz_active_tab ) ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Site Settings', 'playbuzz' ); ?></a>
     101                <a href="?page=<?php echo urlencode( $this->get_option_name() ); ?>&tab=shortcodes&<?php echo esc_html( $nonce_key ) . '=' . esc_html( $nonce ); ?>" class="nav-tab <?php echo  'shortcodes' == $playbuzz_active_tab ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Shortcodes', 'playbuzz' ); ?></a>
     102                <a href="?page=<?php echo urlencode( $this->get_option_name() ); ?>&tab=feedback&<?php echo esc_html( $nonce_key ) . '=' . esc_html( $nonce ); ?>"   class="nav-tab <?php echo  'feedback' == $playbuzz_active_tab ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Feedback', 'playbuzz' ); ?></a>
    103103            </h2>
    104104
    105             <?php  if ( 'embed' == $playbuzz_active_tab || 'start' == $playbuzz_active_tab ) { ?>
     105            <?php if ( 'embed' == $playbuzz_active_tab || 'start' == $playbuzz_active_tab ) { ?>
    106106
    107107                <form method="post" action="options.php">
     
    132132                       
    133133                        <label for="<?php echo esc_attr( $this->get_option_name() ); ?>[jshead]">
    134                             <input type="checkbox" id="<?php echo esc_attr( $this->get_option_name() ); ?>[info]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[jshead]" value="1" <?php if ( isset( $options['jshead'] ) && ( '1' == $options['jshead'] ) ) { echo 'checked="checked"';} ?>>
     134                            <input type="checkbox" id="<?php echo esc_attr( $this->get_option_name() ); ?>[info]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[jshead]" value="1"
     135                                                                    <?php
     136                                                                    if ( isset( $options['jshead'] ) && ( '1' == $options['jshead'] ) ) {
     137                                                                        echo 'checked="checked"';}
     138?>
     139>
    135140                            <?php esc_html_e( 'Load scripts in the header', 'playbuzz' ); ?>
    136141                        </label>
     
    138143                       
    139144                        <label for="<?php echo esc_attr( $this->get_option_name() ); ?>[info]">
    140                             <input type="checkbox" id="<?php echo esc_attr( $this->get_option_name() ); ?>[info]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[info]" value="1" <?php if ( isset( $options['info'] ) && ( '1' == $options['info'] ) ) { echo 'checked="checked"';} ?>>
     145                            <input type="checkbox" id="<?php echo esc_attr( $this->get_option_name() ); ?>[info]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[info]" value="1"
     146                                                                    <?php
     147                                                                    if ( isset( $options['info'] ) && ( '1' == $options['info'] ) ) {
     148                                                                        echo 'checked="checked"';}
     149?>
     150>
    141151                            <?php esc_html_e( 'Display item information', 'playbuzz' ); ?>
    142152                        </label>
     
    147157
    148158                        <label for="<?php echo esc_attr( $this->get_option_name() ); ?>[shares]">
    149                             <input type="checkbox" id="<?php echo esc_attr( $this->get_option_name() ); ?>[shares]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[shares]" value="1" <?php if ( isset( $options['shares'] ) && ( '1' == $options['shares'] ) ) { echo 'checked="checked"';} ?>>
     159                            <input type="checkbox" id="<?php echo esc_attr( $this->get_option_name() ); ?>[shares]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[shares]" value="1"
     160                                                                    <?php
     161                                                                    if ( isset( $options['shares'] ) && ( '1' == $options['shares'] ) ) {
     162                                                                        echo 'checked="checked"';}
     163?>
     164>
    150165                            <?php esc_html_e( 'Display share bar', 'playbuzz' ); ?>
    151166                        </label>
     
    153168
    154169                        <label for="<?php echo esc_attr( $this->get_option_name() ); ?>[comments]">
    155                             <input type="checkbox" id="<?php echo esc_attr( $this->get_option_name() ); ?>[comments]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[comments]" value="1" <?php if ( isset( $options['comments'] ) && ( '1' == $options['comments'] ) ) { echo 'checked="checked"';} ?>>
     170                            <input type="checkbox" id="<?php echo esc_attr( $this->get_option_name() ); ?>[comments]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[comments]" value="1"
     171                                                                    <?php
     172                                                                    if ( isset( $options['comments'] ) && ( '1' == $options['comments'] ) ) {
     173                                                                        echo 'checked="checked"';}
     174?>
     175>
    156176                            <?php esc_html_e( 'Display facebook comments', 'playbuzz' ); ?>
    157177                        </label>
     
    175195                            <?php esc_html_e( 'Create Playbuzz items in', 'playbuzz' ); ?>
    176196                            <select id="<?php echo esc_attr( $this->get_option_name() ); ?>[locale]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[locale]">
    177                                 <option value="sq-AL" <?php if ( isset( $options['locale'] ) && ( 'sq-AL' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Albanian', 'playbuzz' ); ?></option>
    178                                 <option value="ar" <?php if ( isset( $options['locale'] ) && ( 'ar' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Arabic', 'playbuzz' ); ?></option>
    179                                 <option value="zh-CN" <?php if ( isset( $options['locale'] ) && ( 'zh-CN' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Chinese (Simplified)', 'playbuzz' ); ?></option>
    180                                 <option value="zh-HK" <?php if ( isset( $options['locale'] ) && ( 'zh-HK' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Chinese (Traditional)', 'playbuzz' ); ?></option>
    181                                 <option value="hr-HR" <?php if ( isset( $options['locale'] ) && ( 'hr-HR' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Croatian', 'playbuzz' ); ?></option>
    182                                 <option value="cs-CZ" <?php if ( isset( $options['locale'] ) && ( 'cs-CZ' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Czech', 'playbuzz' ); ?></option>
    183                                 <option value="da-DK" <?php if ( isset( $options['locale'] ) && ( 'da-DK' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Danish', 'playbuzz' ); ?></option>
    184                                 <option value="nl-NL" <?php if ( isset( $options['locale'] ) && ( 'nl-NL' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Dutch', 'playbuzz' ); ?></option>
    185                                 <option value="en-US" <?php if ( isset( $options['locale'] ) && ( 'en-US' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'English', 'playbuzz' ); ?></option>
    186                                 <option value="et-EE" <?php if ( isset( $options['locale'] ) && ( 'et-EE' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Estonian', 'playbuzz' ); ?></option>
    187                                 <option value="fi-FI" <?php if ( isset( $options['locale'] ) && ( 'fi-FI' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Finnish', 'playbuzz' ); ?></option>
    188                                 <option value="fr-FR" <?php if ( isset( $options['locale'] ) && ( 'fr-FR' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'French', 'playbuzz' ); ?></option>
    189                                 <option value="de-DE" <?php if ( isset( $options['locale'] ) && ( 'de-DE' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'German', 'playbuzz' ); ?></option>
    190                                 <option value="el-GR" <?php if ( isset( $options['locale'] ) && ( 'el-GR' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Greek', 'playbuzz' ); ?></option>
    191                                 <option value="he-IL" <?php if ( isset( $options['locale'] ) && ( 'he-IL' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Hebrew', 'playbuzz' ); ?></option>
    192                                 <option value="hu-HU" <?php if ( isset( $options['locale'] ) && ( 'hu-HU' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Hungarian', 'playbuzz' ); ?></option>
    193                                 <option value="hy-AM" <?php if ( isset( $options['locale'] ) && ( 'hy-AM' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Armenian', 'playbuzz' ); ?></option>
    194                                 <option value="id-ID" <?php if ( isset( $options['locale'] ) && ( 'id-ID' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Indonesian', 'playbuzz' ); ?></option>
    195                                 <option value="it-IT" <?php if ( isset( $options['locale'] ) && ( 'it-IT' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Italian', 'playbuzz' ); ?></option>
    196                                 <option value="ja-JP" <?php if ( isset( $options['locale'] ) && ( 'ja-JP' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Japanese', 'playbuzz' ); ?></option>
    197                                 <option value="ko-KR" <?php if ( isset( $options['locale'] ) && ( 'ko-KR' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Korean', 'playbuzz' ); ?></option>
    198                                 <option value="lv-LV" <?php if ( isset( $options['locale'] ) && ( 'lv-LV' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Latvian', 'playbuzz' ); ?></option>
    199                                 <option value="mn-MN" <?php if ( isset( $options['locale'] ) && ( 'mn-MN' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Mongolian (Cyrillic)', 'playbuzz' ); ?></option>
    200                                 <option value="nb-NO" <?php if ( isset( $options['locale'] ) && ( 'nb-NO' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Norwegian (Bokmål)', 'playbuzz' ); ?></option>
    201                                 <option value="pl-PL" <?php if ( isset( $options['locale'] ) && ( 'pl-PL' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Polish', 'playbuzz' ); ?></option>
    202                                 <option value="pt-BR" <?php if ( isset( $options['locale'] ) && ( 'pt-BR' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Portuguese', 'playbuzz' ); ?></option>
    203                                 <option value="ro-RO" <?php if ( isset( $options['locale'] ) && ( 'ro-RO' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Romanian', 'playbuzz' ); ?></option>
    204                                 <option value="ro-RO" <?php if ( isset( $options['locale'] ) && ( 'ro-RO' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Romanian', 'playbuzz' ); ?></option>
    205                                 <option value="ru-RU" <?php if ( isset( $options['locale'] ) && ( 'ru-RU' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Russian', 'playbuzz' ); ?></option>
    206                                 <option value="es-ES" <?php if ( isset( $options['locale'] ) && ( 'es-ES' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Spanish', 'playbuzz' ); ?></option>
    207                                 <option value="sl-SI" <?php if ( isset( $options['locale'] ) && ( 'sl-SI' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Slovenian', 'playbuzz' ); ?></option>
    208                                 <option value="sv-SE" <?php if ( isset( $options['locale'] ) && ( 'sv-SE' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Swedish', 'playbuzz' ); ?></option>
    209                                 <option value="th-TH" <?php if ( isset( $options['locale'] ) && ( 'th-TH' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Thai', 'playbuzz' ); ?></option>
    210                                 <option value="tr-TR" <?php if ( isset( $options['locale'] ) && ( 'tr-TR' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Turkish', 'playbuzz' ); ?></option>
    211                                 <option value="en" <?php if ( isset( $options['locale'] ) && ( 'en' == $options['locale'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Other', 'playbuzz' ); ?></option>
     197                                <option value="sq-AL"
     198                                <?php
     199                                if ( isset( $options['locale'] ) && ( 'sq-AL' == $options['locale'] ) ) {
     200                                    echo 'selected';}
     201?>
     202><?php esc_html_e( 'Albanian', 'playbuzz' ); ?></option>
     203                                <option value="ar"
     204                                <?php
     205                                if ( isset( $options['locale'] ) && ( 'ar' == $options['locale'] ) ) {
     206                                    echo 'selected';}
     207?>
     208><?php esc_html_e( 'Arabic', 'playbuzz' ); ?></option>
     209                                <option value="zh-CN"
     210                                <?php
     211                                if ( isset( $options['locale'] ) && ( 'zh-CN' == $options['locale'] ) ) {
     212                                    echo 'selected';}
     213?>
     214><?php esc_html_e( 'Chinese (Simplified)', 'playbuzz' ); ?></option>
     215                                <option value="zh-HK"
     216                                <?php
     217                                if ( isset( $options['locale'] ) && ( 'zh-HK' == $options['locale'] ) ) {
     218                                    echo 'selected';}
     219?>
     220><?php esc_html_e( 'Chinese (Traditional)', 'playbuzz' ); ?></option>
     221                                <option value="hr-HR"
     222                                <?php
     223                                if ( isset( $options['locale'] ) && ( 'hr-HR' == $options['locale'] ) ) {
     224                                    echo 'selected';}
     225?>
     226><?php esc_html_e( 'Croatian', 'playbuzz' ); ?></option>
     227                                <option value="cs-CZ"
     228                                <?php
     229                                if ( isset( $options['locale'] ) && ( 'cs-CZ' == $options['locale'] ) ) {
     230                                    echo 'selected';}
     231?>
     232><?php esc_html_e( 'Czech', 'playbuzz' ); ?></option>
     233                                <option value="da-DK"
     234                                <?php
     235                                if ( isset( $options['locale'] ) && ( 'da-DK' == $options['locale'] ) ) {
     236                                    echo 'selected';}
     237?>
     238><?php esc_html_e( 'Danish', 'playbuzz' ); ?></option>
     239                                <option value="nl-NL"
     240                                <?php
     241                                if ( isset( $options['locale'] ) && ( 'nl-NL' == $options['locale'] ) ) {
     242                                    echo 'selected';}
     243?>
     244><?php esc_html_e( 'Dutch', 'playbuzz' ); ?></option>
     245                                <option value="en-US"
     246                                <?php
     247                                if ( isset( $options['locale'] ) && ( 'en-US' == $options['locale'] ) ) {
     248                                    echo 'selected';}
     249?>
     250><?php esc_html_e( 'English', 'playbuzz' ); ?></option>
     251                                <option value="et-EE"
     252                                <?php
     253                                if ( isset( $options['locale'] ) && ( 'et-EE' == $options['locale'] ) ) {
     254                                    echo 'selected';}
     255?>
     256><?php esc_html_e( 'Estonian', 'playbuzz' ); ?></option>
     257                                <option value="fi-FI"
     258                                <?php
     259                                if ( isset( $options['locale'] ) && ( 'fi-FI' == $options['locale'] ) ) {
     260                                    echo 'selected';}
     261?>
     262><?php esc_html_e( 'Finnish', 'playbuzz' ); ?></option>
     263                                <option value="fr-FR"
     264                                <?php
     265                                if ( isset( $options['locale'] ) && ( 'fr-FR' == $options['locale'] ) ) {
     266                                    echo 'selected';}
     267?>
     268><?php esc_html_e( 'French', 'playbuzz' ); ?></option>
     269                                <option value="de-DE"
     270                                <?php
     271                                if ( isset( $options['locale'] ) && ( 'de-DE' == $options['locale'] ) ) {
     272                                    echo 'selected';}
     273?>
     274><?php esc_html_e( 'German', 'playbuzz' ); ?></option>
     275                                <option value="el-GR"
     276                                <?php
     277                                if ( isset( $options['locale'] ) && ( 'el-GR' == $options['locale'] ) ) {
     278                                    echo 'selected';}
     279?>
     280><?php esc_html_e( 'Greek', 'playbuzz' ); ?></option>
     281                                <option value="he-IL"
     282                                <?php
     283                                if ( isset( $options['locale'] ) && ( 'he-IL' == $options['locale'] ) ) {
     284                                    echo 'selected';}
     285?>
     286><?php esc_html_e( 'Hebrew', 'playbuzz' ); ?></option>
     287                                <option value="hu-HU"
     288                                <?php
     289                                if ( isset( $options['locale'] ) && ( 'hu-HU' == $options['locale'] ) ) {
     290                                    echo 'selected';}
     291?>
     292><?php esc_html_e( 'Hungarian', 'playbuzz' ); ?></option>
     293                                <option value="hy-AM"
     294                                <?php
     295                                if ( isset( $options['locale'] ) && ( 'hy-AM' == $options['locale'] ) ) {
     296                                    echo 'selected';}
     297?>
     298><?php esc_html_e( 'Armenian', 'playbuzz' ); ?></option>
     299                                <option value="id-ID"
     300                                <?php
     301                                if ( isset( $options['locale'] ) && ( 'id-ID' == $options['locale'] ) ) {
     302                                    echo 'selected';}
     303?>
     304><?php esc_html_e( 'Indonesian', 'playbuzz' ); ?></option>
     305                                <option value="it-IT"
     306                                <?php
     307                                if ( isset( $options['locale'] ) && ( 'it-IT' == $options['locale'] ) ) {
     308                                    echo 'selected';}
     309?>
     310><?php esc_html_e( 'Italian', 'playbuzz' ); ?></option>
     311                                <option value="ja-JP"
     312                                <?php
     313                                if ( isset( $options['locale'] ) && ( 'ja-JP' == $options['locale'] ) ) {
     314                                    echo 'selected';}
     315?>
     316><?php esc_html_e( 'Japanese', 'playbuzz' ); ?></option>
     317                                <option value="ko-KR"
     318                                <?php
     319                                if ( isset( $options['locale'] ) && ( 'ko-KR' == $options['locale'] ) ) {
     320                                    echo 'selected';}
     321?>
     322><?php esc_html_e( 'Korean', 'playbuzz' ); ?></option>
     323                                <option value="lv-LV"
     324                                <?php
     325                                if ( isset( $options['locale'] ) && ( 'lv-LV' == $options['locale'] ) ) {
     326                                    echo 'selected';}
     327?>
     328><?php esc_html_e( 'Latvian', 'playbuzz' ); ?></option>
     329                                <option value="mn-MN"
     330                                <?php
     331                                if ( isset( $options['locale'] ) && ( 'mn-MN' == $options['locale'] ) ) {
     332                                    echo 'selected';}
     333?>
     334><?php esc_html_e( 'Mongolian (Cyrillic)', 'playbuzz' ); ?></option>
     335                                <option value="nb-NO"
     336                                <?php
     337                                if ( isset( $options['locale'] ) && ( 'nb-NO' == $options['locale'] ) ) {
     338                                    echo 'selected';}
     339?>
     340><?php esc_html_e( 'Norwegian (Bokmål)', 'playbuzz' ); ?></option>
     341                                <option value="pl-PL"
     342                                <?php
     343                                if ( isset( $options['locale'] ) && ( 'pl-PL' == $options['locale'] ) ) {
     344                                    echo 'selected';}
     345?>
     346><?php esc_html_e( 'Polish', 'playbuzz' ); ?></option>
     347                                <option value="pt-BR"
     348                                <?php
     349                                if ( isset( $options['locale'] ) && ( 'pt-BR' == $options['locale'] ) ) {
     350                                    echo 'selected';}
     351?>
     352><?php esc_html_e( 'Portuguese', 'playbuzz' ); ?></option>
     353                                <option value="ro-RO"
     354                                <?php
     355                                if ( isset( $options['locale'] ) && ( 'ro-RO' == $options['locale'] ) ) {
     356                                    echo 'selected';}
     357?>
     358><?php esc_html_e( 'Romanian', 'playbuzz' ); ?></option>
     359                                <option value="ro-RO"
     360                                <?php
     361                                if ( isset( $options['locale'] ) && ( 'ro-RO' == $options['locale'] ) ) {
     362                                    echo 'selected';}
     363?>
     364><?php esc_html_e( 'Romanian', 'playbuzz' ); ?></option>
     365                                <option value="ru-RU"
     366                                <?php
     367                                if ( isset( $options['locale'] ) && ( 'ru-RU' == $options['locale'] ) ) {
     368                                    echo 'selected';}
     369?>
     370><?php esc_html_e( 'Russian', 'playbuzz' ); ?></option>
     371                                <option value="es-ES"
     372                                <?php
     373                                if ( isset( $options['locale'] ) && ( 'es-ES' == $options['locale'] ) ) {
     374                                    echo 'selected';}
     375?>
     376><?php esc_html_e( 'Spanish', 'playbuzz' ); ?></option>
     377                                <option value="sl-SI"
     378                                <?php
     379                                if ( isset( $options['locale'] ) && ( 'sl-SI' == $options['locale'] ) ) {
     380                                    echo 'selected';}
     381?>
     382><?php esc_html_e( 'Slovenian', 'playbuzz' ); ?></option>
     383                                <option value="sv-SE"
     384                                <?php
     385                                if ( isset( $options['locale'] ) && ( 'sv-SE' == $options['locale'] ) ) {
     386                                    echo 'selected';}
     387?>
     388><?php esc_html_e( 'Swedish', 'playbuzz' ); ?></option>
     389                                <option value="th-TH"
     390                                <?php
     391                                if ( isset( $options['locale'] ) && ( 'th-TH' == $options['locale'] ) ) {
     392                                    echo 'selected';}
     393?>
     394><?php esc_html_e( 'Thai', 'playbuzz' ); ?></option>
     395                                <option value="tr-TR"
     396                                <?php
     397                                if ( isset( $options['locale'] ) && ( 'tr-TR' == $options['locale'] ) ) {
     398                                    echo 'selected';}
     399?>
     400><?php esc_html_e( 'Turkish', 'playbuzz' ); ?></option>
     401                                <option value="en"
     402                                <?php
     403                                if ( isset( $options['locale'] ) && ( 'en' == $options['locale'] ) ) {
     404                                    echo 'selected';}
     405?>
     406><?php esc_html_e( 'Other', 'playbuzz' ); ?></option>
    212407                            </select>
    213408                        </label>
     
    223418                            <?php esc_html_e( 'Display embedded items on:', 'playbuzz' ); ?>
    224419                            <select id="<?php echo esc_attr( $this->get_option_name() ); ?>[embeddedon]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[embeddedon]">
    225                                 <option value="content" <?php if ( isset( $options['embeddedon'] ) && ( 'content' == $options['embeddedon'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'Posts & Pages Only',                  'playbuzz' ); ?></option>
    226                                 <option value="all"     <?php if ( isset( $options['embeddedon'] ) && ( 'all' == $options['embeddedon'] ) ) { echo 'selected';} ?>><?php esc_html_e( 'All pages (singular, archive, ect.)', 'playbuzz' ); ?></option>
     420                                <option value="content"
     421                                <?php
     422                                if ( isset( $options['embeddedon'] ) && ( 'content' == $options['embeddedon'] ) ) {
     423                                    echo 'selected';}
     424?>
     425><?php esc_html_e( 'Posts & Pages Only', 'playbuzz' ); ?></option>
     426                                <option value="all"     
     427                                <?php
     428                                if ( isset( $options['embeddedon'] ) && ( 'all' == $options['embeddedon'] ) ) {
     429                                    echo 'selected';}
     430?>
     431><?php esc_html_e( 'All pages (singular, archive, ect.)', 'playbuzz' ); ?></option>
    227432                            </select>
    228433                        </label>
    229                         <p class="description"><?php printf( esc_html__( 'Choose between displaying the embedded content in %1$s only, or in %2$s as well.', 'playbuzz' ), '<a href="https://codex.wordpress.org/Function_Reference/is_singular" target="_blank">singular pages</a>' , '<a href="https://codex.wordpress.org/Template_Hierarchy" target="_blank">archive page</a>' ); ?></p>
     434                        <p class="description"><?php printf( esc_html__( 'Choose between displaying the embedded content in %1$s only, or in %2$s as well.', 'playbuzz' ), '<a href="https://codex.wordpress.org/Function_Reference/is_singular" target="_blank">singular pages</a>', '<a href="https://codex.wordpress.org/Template_Hierarchy" target="_blank">archive page</a>' ); ?></p>
    230435
    231436                    </div>
     
    236441
    237442                        <label for="<?php echo esc_attr( $this->get_option_name() ); ?>[experiment-mode]">
    238                             <input type="checkbox" id="<?php echo esc_attr( $this->get_option_name() ); ?>[experiment-mode]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[experiment-mode]" value="1" <?php if ( isset( $options['experiment-mode'] ) && ( '1' == $options['experiment-mode'] ) ) { echo 'checked="checked"';} ?>>
     443                            <input type="checkbox" id="<?php echo esc_attr( $this->get_option_name() ); ?>[experiment-mode]" name="<?php echo esc_attr( $this->get_option_name() ); ?>[experiment-mode]" value="1"
     444                                                                    <?php
     445                                                                    if ( isset( $options['experiment-mode'] ) && ( '1' == $options['experiment-mode'] ) ) {
     446                                                                        echo 'checked="checked"';}
     447?>
     448>
    239449                            <?php esc_html_e( 'Active experiment mode', 'playbuzz' ); ?>
    240450                        </label>
     
    370580                </div>
    371581
    372             <?php }// End if().
     582            <?php
     583}// End if().
    373584    ?>
    374585
  • playbuzz/tags/1.0.6/class-playbuzzstorycreator.php

    r1831521 r1866507  
    4141
    4242        // get the playbuzz plugin options.
    43         $this -> options = (array) get_option( 'playbuzz' );
     43        $this->options = (array) get_option( 'playbuzz' );
    4444
    4545        //initialize Playbuzz story creator on frontend
     
    8686
    8787        //make sure edit story post
    88         if ( ! $this -> is_pb_story_post( $post ) ) {
     88        if ( ! $this->is_pb_story_post( $post ) ) {
    8989            return;
    9090        }
     
    9393        add_filter( 'the_content', array( $this, 'set_post_template_on_frontend' ) );
    9494
    95         $site_jshead = ( ( ( array_key_exists( 'jshead', $this -> options ) ) && ( '1' == $this -> options['jshead'] ) ) ? true : false );
     95        $site_jshead = ( ( ( array_key_exists( 'jshead', $this->options ) ) && ( '1' == $this->options['jshead'] ) ) ? true : false );
    9696
    9797        if ( $site_jshead ) {
    9898
    9999            //load the feed.js to the front end head section.
    100             $this -> load_resource_frontend();
     100            $this->load_resource_frontend();
    101101
    102102        }
     
    115115
    116116        // checks if user can edit posts or pages
    117         if ( ! $this -> user_have_access() ) {
     117        if ( ! $this->user_have_access() ) {
    118118            return;
    119119        }
     
    128128
    129129        //make sure edit story post
    130         if ( ! $this -> is_pb_story_post( $post ) ) {
     130        if ( ! $this->is_pb_story_post( $post ) ) {
    131131            return;
    132132        }
     
    138138
    139139        //set default meta data to story post.
    140         $this -> set_story_post_meta(
    141             $post -> ID,
    142             $this -> pb_story_post_identify_key,
    143             $this -> pb_story_post_identify_value
     140        $this->set_story_post_meta(
     141            $post->ID,
     142            $this->pb_story_post_identify_key,
     143            $this->pb_story_post_identify_value
    144144        );
    145145
    146146        // load js and css needed for pb story creator to the end of the body.
    147         $this -> load_resource( $post, $hook );
     147        $this->load_resource( $post, $hook );
    148148
    149149    }
     
    155155    public function load_resource_frontend() {
    156156        $embed_codes = new PlaybuzzEmbedCodes();
    157         wp_enqueue_script( $embed_codes -> item_script_handle, $embed_codes -> item_script_url , null , null, false );
     157        wp_enqueue_script( $embed_codes->item_script_handle, $embed_codes->item_script_url, null, null, false );
    158158    }
    159159
     
    164164    public function load_resource( $post, $hook ) {
    165165
    166         $footer = true;
    167         $version = $this -> pb_resource_version;
     166        $footer  = true;
     167        $version = $this->pb_resource_version;
    168168
    169169        //register css
    170         wp_register_style( 'pb-story-creator', plugins_url( 'css/story-creator/pb-story-creator.css',     __FILE__ ), false, $version, false );
     170        wp_register_style( 'pb-story-creator', plugins_url( 'css/story-creator/pb-story-creator.css', __FILE__ ), false, $version, false );
    171171        wp_enqueue_style( 'pb-story-creator' );
    172172
    173173        //register js
    174         wp_register_script( 'pb-creator-sdk', '//cdn.playbuzz.com/creator-sdk/creator-sdk.js' , '', '', false );
     174        wp_register_script( 'pb-creator-sdk', '//cdn.playbuzz.com/creator-sdk/creator-sdk.js', '', '', false );
    175175        wp_enqueue_script( 'pb-creator-sdk' );
    176176
     
    185185
    186186        wp_register_script( '_pb-story-creator', plugins_url( 'js/story-creator/_pb-story-creator.js', __FILE__ ), array( 'jquery' ), $version, $footer );
    187         wp_localize_script('_pb-story-creator', 'pb', array(
    188                 'post' => $post,
     187        wp_localize_script(
     188            '_pb-story-creator', 'pb', array(
     189                'post'    => $post,
    189190                'options' => (array) get_option( 'playbuzz' ),
    190                 'itemId' => $this -> get_story_post_meta( $post -> ID, $this -> pb_story_post_item_id_key ),
     191                'itemId'  => $this->get_story_post_meta( $post->ID, $this->pb_story_post_item_id_key ),
    191192            )
    192193        );
     
    207208
    208209        $nonce_value = PbConstants::$pb_nonce_value;
    209         $nonce_key = PbConstants::$pb_nonce_key;
    210 
    211         if ( isset( $_POST['postId'], $_POST[ $nonce_key ] ) && wp_verify_nonce( sanitize_key( $_POST[ $nonce_key ] ) , $nonce_value ) ) {
     210        $nonce_key   = PbConstants::$pb_nonce_key;
     211
     212        if ( isset( $_POST['postId'], $_POST[ $nonce_key ] ) && wp_verify_nonce( sanitize_key( $_POST[ $nonce_key ] ), $nonce_value ) ) {
    212213            $post_id = sanitize_text_field( wp_unslash( $_POST['postId'] ) );
    213214        }
    214215
    215         if ( isset( $_POST['itemId'], $_POST[ $nonce_key ] ) && wp_verify_nonce( sanitize_key( $_POST[ $nonce_key ] ) , $nonce_value ) ) {
     216        if ( isset( $_POST['itemId'], $_POST[ $nonce_key ] ) && wp_verify_nonce( sanitize_key( $_POST[ $nonce_key ] ), $nonce_value ) ) {
    216217            $item_id = sanitize_text_field( wp_unslash( $_POST['itemId'] ) );
    217218        }
    218219
    219         $this -> set_story_post_meta( $post_id, $this -> pb_story_post_item_id_key , $item_id );
    220         $this -> set_post_template_on_admin( $post_id, $item_id );
     220        $this->set_story_post_meta( $post_id, $this->pb_story_post_item_id_key, $item_id );
     221        $this->set_post_template_on_admin( $post_id, $item_id );
    221222
    222223        echo 'OK';
     
    229230    public function get_post_template( $item_id, $options ) {
    230231
    231         $embed_codes = new PlaybuzzEmbedCodes();
    232         $options['info'] = 'false';
    233         $story_post_content = $embed_codes -> item( $item_id, $options );
     232        $embed_codes        = new PlaybuzzEmbedCodes();
     233        $options['info']    = 'false';
     234        $story_post_content = $embed_codes->item( $item_id, $options );
    234235
    235236        return $story_post_content;
     
    238239    public function set_post_template_on_admin( $post_id, $item_id ) {
    239240
    240         $options = $this -> options;
     241        $options = $this->options;
    241242
    242243        $post = array(
    243244            'ID'           => $post_id,
    244             'post_content' => $this -> get_post_template( $item_id, $options ),
     245            'post_content' => $this->get_post_template( $item_id, $options ),
    245246        );
    246247
     
    258259        global $post;
    259260
    260         $options = $this -> options;
    261         $item_id = $this -> get_story_post_meta( $post -> ID, $this -> pb_story_post_item_id_key );
    262         $story_post_content = $this -> get_post_template( $item_id, $options );
    263 
    264         $embeddedon     = ( ( ( array_key_exists( 'embeddedon', $options ) ) ) ? $options['embeddedon'] : 'content' );
     261        $options            = $this->options;
     262        $item_id            = $this->get_story_post_meta( $post->ID, $this->pb_story_post_item_id_key );
     263        $story_post_content = $this->get_post_template( $item_id, $options );
     264
     265        $embeddedon = ( ( ( array_key_exists( 'embeddedon', $options ) ) ) ? $options['embeddedon'] : 'content' );
    265266
    266267        if ( 'content' == $embeddedon ) {
     
    307308    public function is_old_pb_story_post( $post ) {
    308309
    309         $identify_key = $this -> get_story_post_meta( $post -> ID, $this -> pb_story_post_identify_key );
    310 
    311         return $identify_key == $this -> pb_story_post_identify_value;
     310        $identify_key = $this->get_story_post_meta( $post->ID, $this->pb_story_post_identify_key );
     311
     312        return $identify_key == $this->pb_story_post_identify_value;
    312313    }
    313314
     
    318319    public function is_new_pb_story_post() {
    319320
    320         $pb_url_param_key = PbConstants::$pb_url_param_key;
     321        $pb_url_param_key   = PbConstants::$pb_url_param_key;
    321322        $pb_url_param_value = PbConstants::$pb_url_param_value;
    322323
     
    338339
    339340        //check if is story new post
    340         $is_new_pb_story_post = $this -> is_new_pb_story_post();
     341        $is_new_pb_story_post = $this->is_new_pb_story_post();
    341342
    342343        //check if is old story post
    343         $is_old_pb_story_post = $this -> is_old_pb_story_post( $post );
     344        $is_old_pb_story_post = $this->is_old_pb_story_post( $post );
    344345
    345346        return $is_new_pb_story_post || $is_old_pb_story_post;
     
    355356    public function set_story_post_meta( $id, $key, $value ) {
    356357
    357         if ( $this -> get_story_post_meta( $id, $key ) == '' ) {
    358             add_post_meta( $id,$key,$value );
     358        if ( $this->get_story_post_meta( $id, $key ) == '' ) {
     359            add_post_meta( $id, $key, $value );
    359360        }
    360361
     
    377378     */
    378379    public function remove_post_editor() {
    379         remove_post_type_support( $this -> post_type, 'editor' );
     380        remove_post_type_support( $this->post_type, 'editor' );
    380381    }
    381382
     
    386387    function get_new_post_url() {
    387388
    388         $pb_url_param_key = PbConstants::$pb_url_param_key;
     389        $pb_url_param_key   = PbConstants::$pb_url_param_key;
    389390        $pb_url_param_value = PbConstants::$pb_url_param_value;
    390391
     
    404405
    405406        $args = array(
    406             'id' => 'add-new-story',
     407            'id'     => 'add-new-story',
    407408            'parent' => 'new-content',
    408             'title' => __( 'Playbuzz Item', 'Playbuzz Item' ),
    409             'href' => $this -> get_new_post_url(),
    410             'meta' => array(
     409            'title'  => __( 'Playbuzz Item', 'Playbuzz Item' ),
     410            'href'   => esc_url($this->get_new_post_url()),
     411            'meta'   => array(
    411412                'class' => 'pb-add-new-story',
    412413                'title' => 'Playbuzz Item',
     
    426427            'edit.php',
    427428            __( 'Add New Playbuzz Item', 'Add New Playbuzz Item' ),
    428             '<span class="pb-icon"></span><span class="pb-menu-name">' . esc_html__( 'New Playbuzz', 'New Playbuzz' ) . '</span>',
     429            '<span class="pb-icon"></span><span class="pb-menu-name">' . esc_html__( 'New Playbuzz', 'New Playbuzz' ) . '</span>',
    429430            'edit_posts',
    430             $this -> get_new_post_url()
     431             esc_url($this->get_new_post_url())
    431432        );
    432433
  • playbuzz/tags/1.0.6/class-playbuzztinymce.php

    r1831521 r1866507  
    7272    /*
    7373
    74     * Create TinyMCE
     74    * Create TinyMCE
    7575
    7676    */
     
    181181    function register_tinymce_js( $plugin_array ) {
    182182
    183         $plugin_array[ $this->name ] = plugins_url( 'js/playbuzz-tinymce.js' , __FILE__ );
     183        $plugin_array[ $this->name ] = plugins_url( 'js/playbuzz-tinymce.js', __FILE__ );
    184184
    185185        return $plugin_array;
  • playbuzz/tags/1.0.6/css/admin-rtl.css

    r1831521 r1866507  
    372372
    373373}
    374 
  • playbuzz/tags/1.0.6/css/admin.css

    r1831521 r1866507  
    302302
    303303#playbuzz_item {
    304    
     304
    305305}
    306306#playbuzz_item_header {
     
    540540 */
    541541
    542  
     542
    543543/* Search popup header */
    544544
     
    578578}
    579579#playbuzz_search_header nav:after {
    580     position: absolute;
    581     content: '';
    582     width: 100%;
    583     bottom: 0;
    584     left: 0;
    585     z-index: 1;
     580    position: absolute;
     581    content: '';
     582    width: 100%;
     583    bottom: 0;
     584    left: 0;
     585    z-index: 1;
    586586}
    587587#playbuzz_search_header nav div {
  • playbuzz/tags/1.0.6/css/story-creator/pb-story-creator.css

    r1831521 r1866507  
    1 
    21#pb-story-creator-page #pb-save-post{
    3     float: left;
     2    float: left;
    43}
    54
    65/*
    7     ========================
    8         hide title and title placeholder until changing the text
    9     ========================
     6    ========================
     7        hide title and title placeholder until changing the text
     8    ========================
    109*/
    1110
    1211.wp-heading-inline,
    1312#title-prompt-text{
    14     opacity: 0;
     13    opacity: 0;
    1514}
    1615
    1716.wp-heading-inline.show,
    1817#title-prompt-text.show{
    19     opacity: 1;
     18    opacity: 1;
    2019}
    2120
     
    2423
    2524/*
    26     ========================
    27         hide wp editor
    28     ========================
     25    ========================
     26        hide wp editor
     27    ========================
    2928*/
    3029
    3130#postdivrich{
    32     display: none;
     31    display: none;
    3332}
    3433
    3534
    3635#pb-story-creator{
    37     min-height: 500px;
    38     background: white;
    39     border: 1px solid #e5e5e5;
    40     margin-top: 10px;
     36    min-height: 500px;
     37    background: white;
     38    border: 1px solid #e5e5e5;
     39    margin-top: 10px;
    4140}
    4241
    4342
    4443/*
    45     ========================
    46         hide toggle button
    47     ========================
     44    ========================
     45        hide toggle button
     46    ========================
    4847*/
    4948#pb-story-creator .toggle-indicator{
    50     display: none;
     49    display: none;
    5150}
    5251
    5352/*
    54     ========================
    55         hide meta box header
    56     ========================
     53    ========================
     54        hide meta box header
     55    ========================
    5756*/
    5857
    5958#pb-story-creator > h2{
    60     display: none;
     59    display: none;
    6160}
    6261
    6362/*
    64     ========================
    65        action buttons
    66     ========================
     63    ========================
     64       action buttons
     65    ========================
    6766*/
    6867
     
    7170#publish,
    7271.page-title-action{
    73     display: none !important;
     72    display: none !important;
    7473}
    7574
    7675.page-title-action.show{
    77     display: initial !important;
    78     margin-left: 10px;
     76    display: initial !important;
     77    margin-left: 10px;
    7978}
    8079
     
    8685#pb-publish[disabled="disabled"]
    8786{
    88     pointer-events: none;
     87    pointer-events: none;
    8988}
    90 
    91 
    92 
    93 
    94 
  • playbuzz/tags/1.0.6/css/tinymce-visual-editor-rtl.css

    r1831521 r1866507  
    11.wp_playbuzz_delete {
     2
    23
    34    left: 2%;
    45
     6
    57    right: initial;
     8
    69
    710}
    811
     12
    913.wp_playbuzz_edit {
     14
    1015
    1116    left: 9%;
    1217
     18
    1319    right: initial;
    1420
     21
    1522}
  • playbuzz/tags/1.0.6/js/all-posts/_pb-all-posts.js

    r1831521 r1866507  
    11(function (window, $) {
    22
    3     var pbAllPostsController = new window.PbAllPostsController($);
     3    var pbAllPostsController = new window.PbAllPostsController( $ );
    44
    5     pbAllPostsController.init();
     5    pbAllPostsController.init();
    66
    7 })(window, window.jQuery);
     7})( window, window.jQuery );
  • playbuzz/tags/1.0.6/js/all-posts/pb-all-posts-controller.js

    r1831521 r1866507  
    1 
    21function PbAllPostsController(jQuery) {
    3     this.$ = jQuery;
     2    this.$ = jQuery;
    43}
    54
    65PbAllPostsController.prototype.init = function () {
    7     this.addStoryButton();
     6    this.addStoryButton();
    87};
    98
     
    1312PbAllPostsController.prototype.addStoryButton = function () {
    1413
    15     var $newPost = this.$('.page-title-action');
     14    var $newPost = this.$( '.page-title-action' );
    1615
    17     var $newStory = $newPost.clone().attr({
    18         'id': 'pb-page-title-action',
    19         'href': 'post-new.php?pb-story=true'
    20     });
     16    var $newStory = $newPost.clone().attr(
     17        {
     18            'id': 'pb-page-title-action',
     19            'href': 'post-new.php?pb-story=true'
     20        }
     21    );
    2122
    22     //TODO -- translation
    23     $newStory.html('<span class="pb-icon pb-icon-blue"></span><span class="pb-menu-name">New Playbuzz</span>');
     23    //TODO -- translation
     24    $newStory.html( '<span class="pb-icon pb-icon-blue"></span><span class="pb-menu-name">New Playbuzz</span>' );
    2425
    25     $newPost.after($newStory);
     26    $newPost.after( $newStory );
    2627};
    2728
  • playbuzz/tags/1.0.6/js/options/_pb-options.js

    r1831521 r1866507  
    77    pbOptionsController.init();
    88
    9 })(window, window.jQuery);
     9})( window, window.jQuery );
  • playbuzz/tags/1.0.6/js/options/pb-options-controller.js

    r1831521 r1866507  
    11function PbOptionsController(jQuery, model) {
    2     this.$ = jQuery;
    3     this.model = model;
     2    this.$             = jQuery;
     3    this.model         = model;
    44    this.$channelAlias = this.$( "#pb-channel-alias" );
    5     this.$channelId = this.$( "#pb_channel_id" );
    6     this.$submit = this.$("#submit");
    7     this.isSaving = false;
     5    this.$channelId    = this.$( "#pb_channel_id" );
     6    this.$submit       = this.$( "#submit" );
     7    this.isSaving      = false;
    88    this.submitClicked = false;
    99}
     
    1515
    1616    //listen to change on the channel alias
    17     this.$channelAlias.change(function () {
    18         channelAlias = _this.$( this ).val();
    19         _this.pbChannelAliasChanged( channelAlias );
    20     });
     17    this.$channelAlias.change(
     18        function () {
     19            channelAlias = _this.$( this ).val();
     20            _this.pbChannelAliasChanged( channelAlias );
     21        }
     22    );
    2123
    2224    //backward compatibility for users who already have a  channelAlias
     
    2628    }
    2729
    28     this.$submit.click(function (e) {
     30    this.$submit.click(
     31        function (e) {
    2932
    30         if(_this.isSaving){
    31             e.preventDefault();
    32             _this.submitClicked = true;
     33            if (_this.isSaving) {
     34                e.preventDefault();
     35                _this.submitClicked = true;
     36            }
     37
    3338        }
    34 
    35     });
     39    );
    3640};
    3741
    3842PbOptionsController.prototype.pbChannelAliasChanged = function (channelAlias) {
    3943
    40     var _this = this;
     44    var _this    = this;
    4145    var deferred = this.$.Deferred();
    42    
    43     this.isSaving = true;
     46
     47    this.isSaving = true;
    4448
    4549    //request the user id by the channel alias
    4650    this.model.getUserId( channelAlias )
    4751
    48         .then(function (res) {
    49             _this.changeUserId( res );
    50             _this.isSaving = false;
     52        .then(
     53            function (res) {
     54                _this.changeUserId( res );
     55                _this.isSaving = false;
    5156
    52             if(_this.submitClicked){
    53                 _this.$submit.click();
     57                if (_this.submitClicked) {
     58                    _this.$submit.click();
     59                }
     60
     61                deferred.resolve( res );
    5462            }
     63        )
    5564
    56             deferred.resolve( res );
    57         })
     65        .fail(
     66            function (res) {
     67                _this.isSaving = false;
    5868
    59         .fail(function (res) {
    60             _this.isSaving = false;
    61 
    62             if(_this.submitClicked){
    63                 _this.$submit.click();
    64             }
    65             _this.errorHandler( res );
    66             deferred.reject( res );
    67         });
     69                if (_this.submitClicked) {
     70                    _this.$submit.click();
     71                }
     72                _this.errorHandler( res );
     73                deferred.reject( res );
     74            }
     75        );
    6876
    6977    return deferred.promise();
  • playbuzz/tags/1.0.6/js/options/pb-options-model.js

    r1831521 r1866507  
    11function PbOptionsModel(jQuery, PbApi, pbLogger) {
    2     this.$ = jQuery;
    3     this.api = PbApi;
    4     this.url = "//www.playbuzz.com/GetUserId?channelAlias=";
    5     this.logger = new pbLogger({
    6         environment: 'production',
    7         serviceName: 'wp-plugin'
    8     });
     2    this.$      = jQuery;
     3    this.api    = PbApi;
     4    this.url    = "//www.playbuzz.com/GetUserId?channelAlias=";
     5    this.logger = new pbLogger(
     6        {
     7            environment: 'production',
     8            serviceName: 'wp-plugin'
     9        }
     10    );
    911}
    1012
    1113PbOptionsModel.prototype.getUserId = function (channelAlias) {
    1214
    13     var _this = this;
     15    var _this    = this;
    1416    var deferred = this.$.Deferred();
    15     var url = this.url + channelAlias;
     17    var url      = this.url + channelAlias;
    1618
    1719    _this.api.get( {url: url} )
    1820
    19         .then(function (res) {
     21        .then(
     22            function (res) {
    2023
    21             deferred.resolve( res.payload.id );
     24                deferred.resolve( res.payload.id );
    2225
    23         })
     26            }
     27        )
    2428
    25         .fail(function (err) {
     29        .fail(
     30            function (err) {
    2631
    27             var error = err.statusText;
     32                var error = err.statusText;
    2833
    29             _this.errorHandler( error );
    30             deferred.reject( error );
    31         });
     34                _this.errorHandler( error );
     35                deferred.reject( error );
     36            }
     37        );
    3238
    3339    return deferred.promise();
  • playbuzz/tags/1.0.6/js/pb-alert.js

    r1831521 r1866507  
    1 
    21function PbAlert(jQuery){
    32
    4     this.$ = jQuery;
    5     this.error = 'notice-error';
    6     this.warning = 'notice-warning';
    7     this.success = 'notice-success';
    8     this.msgPlaceholder = '{MSG}';
    9     this.classPlaceholder = '{CLASS}';
    10     this.template =
    11         '<div class="' + this.classPlaceholder + ' notice">' +
    12             '<p>' + this.msgPlaceholder +'</p>' +
    13         '</div>';
     3    this.$                = jQuery;
     4    this.error            = 'notice-error';
     5    this.warning          = 'notice-warning';
     6    this.success          = 'notice-success';
     7    this.msgPlaceholder  = '{MSG}';
     8    this.classPlaceholder = '{CLASS}';
     9    this.template        =
     10        '<div class="' + this.classPlaceholder + ' notice">' +
     11            '<p>' + this.msgPlaceholder + '</p>' +
     12        '</div>';
    1413
    1514}
     
    1716PbAlert.prototype.notify = function (msg, options) {
    1817
    19     var type = !options.type || !this[options.type] ? '' : this[options.type];
    20     var template = this.template.replace(this.msgPlaceholder, msg).replace(this.classPlaceholder, type);
     18    var type     = ! options.type || ! this[options.type] ? '' : this[options.type];
     19    var template = this.template.replace( this.msgPlaceholder, msg ).replace( this.classPlaceholder, type );
    2120
    22     //add alert after placeholder.
    23     options.placeholder.before(template);
     21    //add alert after placeholder.
     22    options.placeholder.before( template );
    2423
    2524};
    2625
    2726
    28 window.PbAlert = new PbAlert(window.jQuery);
     27window.PbAlert = new PbAlert( window.jQuery );
  • playbuzz/tags/1.0.6/js/pb-api.js

    r1831521 r1866507  
    77
    88    var deferred = this.$.Deferred();
    9     data.action = options.action;
     9    data.action  = options.action;
    1010
    11     this.$.ajax({
    12         url: options.url,
    13         method: 'POST',
    14         data: data,
    15         success: function (res) {
    16             deferred.resolve( res );
    17         },
    18         error: function (err) {
    19             deferred.reject( err );
     11    this.$.ajax(
     12        {
     13            url: options.url,
     14            method: 'POST',
     15            data: data,
     16            success: function (res) {
     17                deferred.resolve( res );
     18            },
     19            error: function (err) {
     20                deferred.reject( err );
     21            }
    2022        }
    21     });
     23    );
    2224
    2325    return deferred.promise();
     
    2931    var deferred = this.$.Deferred();
    3032
    31     this.$.ajax({
    32         url: options.url,
    33         method: 'GET',
    34         success: function (res) {
    35             deferred.resolve( res );
    36         },
    37         error: function (err) {
    38             deferred.reject( err );
     33    this.$.ajax(
     34        {
     35            url: options.url,
     36            method: 'GET',
     37            success: function (res) {
     38                deferred.resolve( res );
     39            },
     40            error: function (err) {
     41                deferred.reject( err );
     42            }
    3943        }
    40     });
     44    );
    4145
    4246    return deferred.promise();
  • playbuzz/tags/1.0.6/js/pb-event.js

    r1831521 r1866507  
    1 
    21function PbEvent(sender){
    32
    4     this.sender = sender;
    5     this.listeners = [];
     3    this.sender    = sender;
     4    this.listeners = [];
    65}
    76
    87PbEvent.prototype.listen = function (listener) {
    9     this.listeners.push(listener);
     8    this.listeners.push( listener );
    109};
    1110
    12 PbEvent.prototype.notify  = function (args) {
    13     var index;
     11PbEvent.prototype.notify = function (args) {
     12    var index;
    1413
    15     for (index = 0; index < this.listeners.length; index++) {
    16         this.listeners[index](this.sender, args);
    17     }
     14    for (index = 0; index < this.listeners.length; index++) {
     15        this.listeners[index](this.sender, args);
     16    }
    1817};
    1918
  • playbuzz/tags/1.0.6/js/pb-global.js

    r1831521 r1866507  
    1 
    21/**
    32 *
     
    98function PbGlobal(pb, jQuery, settings) {
    109
    11     this.$ = jQuery;
    12     this.global = this.$.extend({}, pb);
    13     this.toBool = 'comments,info,shares';
    14     this.settings = settings;
     10    this.$        = jQuery;
     11    this.global   = this.$.extend( {}, pb );
     12    this.toBool  = 'comments,info,shares';
     13    this.settings = settings;
    1514
    16     //add settings from url to global object
    17     this.enrich(this.global);
     15    //add settings from url to global object
     16    this.enrich( this.global );
    1817
    19     //normalize the global object
    20     this.normalize(this.global);
     18    //normalize the global object
     19    this.normalize( this.global );
    2120
    22     return this.global;
     21    return this.global;
    2322}
    2423
    2524PbGlobal.prototype.enrich = function(global){
    2625
    27     global.options = this.$.extend(this.settings, global.options);
     26    global.options = this.$.extend( this.settings, global.options );
    2827
    29     return global;
     28    return global;
    3029};
    3130
     
    3736PbGlobal.prototype.normalize = function (global) {
    3837
    39     var _this = this;
     38    var _this = this;
    4039
    41     global.options = parser(global.options);
     40    global.options = parser( global.options );
    4241
    43     return global;
     42    return global;
    4443
     44    function parser(obj) {
     45        for (var key in obj) {
    4546
    46     function parser(obj) {
    47         for(var key in obj){
     47            if (_this.toBool.indexOf( key ) > -1 ) {
     48                obj[key] = Boolean( obj[key] );
     49            }
     50        }
    4851
    49             if(_this.toBool.indexOf(key) > -1 ){
    50                 obj[key] =  Boolean(obj[key]);
    51             }
    52         }
     52        return obj;
    5353
    54         return obj;
    55 
    56     }
     54    }
    5755
    5856};
  • playbuzz/tags/1.0.6/js/pb-jquery.js

    r1831521 r1866507  
    1 
    21/**
    32 *  extensions for jQuery.
    43 */
    54
    6 window.jQuery.extend({
     5window.jQuery.extend(
     6    {
    77
    88
    9     /**
    10     * deserialize query string to json object.
    11     * @docs - https://css-tricks.com/snippets/jquery/get-query-params-object/
    12     * @param str - optional - query string to deserialize.
    13     * @param param - optional - return specific param.
    14     * @returns {*}
    15     */
    16     queryParameters : function(param, str) {
    17         var queryObj = (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
     9        /**
     10    * deserialize query string to json object.
     11    * @docs - https://css-tricks.com/snippets/jquery/get-query-params-object/
     12    * @param str - optional - query string to deserialize.
     13    * @param param - optional - return specific param.
     14    * @returns {*}
     15    */
     16        queryParameters : function(param, str) {
     17            var queryObj = (str || document.location.search).replace( /(^\?)/,'' ).split( "&" ).map( function(n){return n = n.split( "=" ),this[n[0]] = n[1],this}.bind( {} ) )[0];
    1818
    19         if(param){
    20             return queryObj[param];
    21         }
     19            if (param) {
     20                return queryObj[param];
     21            }
    2222
    23         return queryObj;
    24     }
     23            return queryObj;
     24        }
    2525
    26 });
     26    }
     27);
  • playbuzz/tags/1.0.6/js/pb-logger.js

    r1831521 r1866507  
    1 
    21(function (window) {
    32
    4     var PORT = document.location.protocol.indexOf('https') > -1 ? "443" : "5044",
    5         DEV_URL = "//mng-dev-logstash.playbuzz.com:" + PORT,
    6         PROD_URL = "//mng-prd-logstash.playbuzz.com:" + PORT,
    7         SERVICE_NAME = "playbuzz",
    8         ENVIRONMENT = "dev",
    9         LEVEL = "error",
    10         URL = document.location.href,
    11         MESSAGE = "error";
     3    var PORT         = document.location.protocol.indexOf( 'https' ) > -1 ? "443" : "5044",
     4        DEV_URL      = "//mng-dev-logstash.playbuzz.com:" + PORT,
     5        PROD_URL    = "//mng-prd-logstash.playbuzz.com:" + PORT,
     6        SERVICE_NAME = "playbuzz",
     7        ENVIRONMENT = "dev",
     8        LEVEL        = "error",
     9        URL          = document.location.href,
     10        MESSAGE      = "error";
    1211
     12    var OPTIONS = {
     13        'serviceName': SERVICE_NAME,
     14        'level' : LEVEL,
     15        'environment': ENVIRONMENT,
     16        'message': MESSAGE,
     17        'url': URL
     18    };
    1319
    14     var OPTIONS = {
    15         'serviceName': SERVICE_NAME,
    16         'level' : LEVEL,
    17         'environment': ENVIRONMENT,
    18         'message': MESSAGE,
    19         'url': URL
    20     };
     20    /**
     21     * Polyfill for Object.assign
     22     * @param obj1
     23     * @param obj2
     24     * @docs - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
     25     */
     26    function objectAssignPolyfill() {
    2127
     28        Object.assign = function(target, varArgs) { // .length of function is 2
     29            'use strict';
     30            if (target == null) { // TypeError if undefined or null
     31                throw new TypeError( 'Cannot convert undefined or null to object' );
     32            }
    2233
    23     /**
    24      * Polyfill for Object.assign
    25      * @param obj1
    26      * @param obj2
    27      * @docs - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
    28      */
    29     function objectAssignPolyfill() {
     34            var to = Object( target );
    3035
    31         Object.assign = function(target, varArgs) { // .length of function is 2
    32             'use strict';
    33             if (target == null) { // TypeError if undefined or null
    34                 throw new TypeError('Cannot convert undefined or null to object');
    35             }
     36            for (var index = 1; index < arguments.length; index++) {
     37                var nextSource = arguments[index];
    3638
    37             var to = Object(target);
     39                if (nextSource != null) { // Skip over if undefined or null
     40                    for (var nextKey in nextSource) {
     41                        // Avoid bugs when hasOwnProperty is shadowed
     42                        if (Object.prototype.hasOwnProperty.call( nextSource, nextKey )) {
     43                            to[nextKey] = nextSource[nextKey];
     44                        }
     45                    }
     46                }
     47            }
     48            return to;
     49        };
    3850
    39             for (var index = 1; index < arguments.length; index++) {
    40                 var nextSource = arguments[index];
     51    }
    4152
    42                 if (nextSource != null) { // Skip over if undefined or null
    43                     for (var nextKey in nextSource) {
    44                         // Avoid bugs when hasOwnProperty is shadowed
    45                         if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
    46                             to[nextKey] = nextSource[nextKey];
    47                         }
    48                     }
    49                 }
    50             }
    51             return to;
    52         };
     53    /**
     54     * deep merging 2 objects
     55     * @param obj1
     56     * @param obj2
     57     */
     58    function enrichObject(obj1, obj2) {
    5359
    54     }
     60        if (typeof Object.assign != 'function') {
    5561
    56     /**
    57      * deep merging 2 objects
    58      * @param obj1
    59      * @param obj2
    60      */
    61     function enrichObject(obj1, obj2) {
     62            objectAssignPolyfill();
     63        }
    6264
    63         if (typeof Object.assign != 'function') {
     65        return  Object.assign( {}, obj1, obj2 );
    6466
    65             objectAssignPolyfill();
    66         }
     67    }
    6768
    68         return  Object.assign({}, obj1, obj2);
     69    function request(url, options, callback) {
    6970
    70     }
     71        var xmlHttp = new XMLHttpRequest();
    7172
     73        // true for asynchronous
     74        xmlHttp.open( "POST", url, true );
    7275
    73     function request(url, options, callback) {
     76        //Send the proper header information along with the request
     77        //xmlHttp.setRequestHeader("Content-type", "application/json");
    7478
    75         var xmlHttp = new XMLHttpRequest();
     79        xmlHttp.onreadystatechange = function() {
    7680
    77         // true for asynchronous
    78         xmlHttp.open("POST", url, true);
     81            if (xmlHttp.readyState == 4) {
    7982
    80         //Send the proper header information along with the request
    81         //xmlHttp.setRequestHeader("Content-type", "application/json");
     83                callback && callback( xmlHttp.responseText, xmlHttp.status );
    8284
    83         xmlHttp.onreadystatechange = function() {
     85            }
    8486
    85             if (xmlHttp.readyState == 4){
     87        };
    8688
    87                 callback && callback(xmlHttp.responseText, xmlHttp.status);
     89        xmlHttp.send( JSON.stringify( options ) );
    8890
    89             }
     91    }
    9092
    91         };
     93    function PbLogger(options) {
    9294
     95        this.options = enrichObject( OPTIONS ,options || OPTIONS );
    9396
    94         xmlHttp.send(JSON.stringify(options));
     97    }
    9598
    96     }
     99    PbLogger.prototype.log = function (message, level) {
    97100
     101        var isProd = this.options.environment === "production";
     102        var url    = isProd ? PROD_URL : DEV_URL;
     103        var _this  = this;
    98104
    99     function PbLogger(options) {
     105        // enrich options object.
     106        this.options = enrichObject(
     107            this.options, {
     108                message: message,
     109                level: level
     110            }
     111        );
    100112
    101         this.options = enrichObject(OPTIONS ,options || OPTIONS);
    102        
    103     }
     113        //send log to console if not production
     114        if ( ! isProd && window.console[level]) {
     115            window.console[_this.options.level](_this.options.message);
     116        }
    104117
     118        //send log via request
     119        request(
     120            url, this.options, function (responseText, status) {
     121                if (status !== 200 && ! isProd) {
     122                    console.error( responseText );
     123                }
     124            }
     125        );
    105126
     127    };
    106128
    107     PbLogger.prototype.log = function (message, level) {
     129    PbLogger.prototype.info = function (message) {
    108130
    109         var isProd = this.options.environment === "production";
    110         var url = isProd ? PROD_URL : DEV_URL;
    111         var _this = this;
     131        this.log( message, 'info' );
     132    };
    112133
    113         // enrich options object.
    114         this.options = enrichObject(this.options, {
    115             message: message,
    116             level: level
    117         });
     134    PbLogger.prototype.error = function (message) {
    118135
     136        this.log( message, 'error' );
     137    };
    119138
    120         //send log to console if not production
    121         if(!isProd && window.console[level]){
    122             window.console[_this.options.level](_this.options.message);
    123         }
     139    PbLogger.prototype.warn = function (message) {
    124140
    125         //send log via request
    126         request(url, this.options, function (responseText, status) {
    127             if(status !== 200 && !isProd){
    128                 console.error(responseText);
    129             }
    130         });
     141        this.log( message, 'warn' );
     142    };
    131143
    132     };
     144    PbLogger.prototype.debug = function (message) {
    133145
    134     PbLogger.prototype.info = function (message) {
     146        this.log( message, 'debug' );
     147    };
    135148
    136         this.log(message, 'info');
    137     };
     149    window.pbLogger = PbLogger;
    138150
    139     PbLogger.prototype.error = function (message) {
    140 
    141         this.log(message, 'error');
    142     };
    143 
    144     PbLogger.prototype.warn = function (message) {
    145 
    146         this.log(message, 'warn');
    147     };
    148 
    149     PbLogger.prototype.debug = function (message) {
    150 
    151         this.log(message, 'debug');
    152     };
    153 
    154 
    155     window.pbLogger  = PbLogger;
    156 
    157 
    158 })(window);
     151})( window );
  • playbuzz/tags/1.0.6/js/pb-quicktags.js

    r1831521 r1866507  
    11(function () {
    22
    3     function generate_id() {
    4         return Math.round(Math.random() * 1000000);
    5     }
     3    function generate_id() {
     4        return Math.round( Math.random() * 1000000 );
     5    }
    66
    7     function playbuzz_shortcode_generator() {
     7    function playbuzz_shortcode_generator() {
    88
    9         var search = new playbuzz_search();
    10         search.display(playbuzz_generate_shortcode);
     9        var search = new playbuzz_search();
     10        search.display( playbuzz_generate_shortcode );
    1111
    12         function playbuzz_generate_shortcode(itemId) {
    13             var id = generate_id();
    14             var $playbuzz_item_shortcode = '[playbuzz-item item="' + itemId + '" wp-pb-id="' + id + '"]';
    15             QTags.insertContent($playbuzz_item_shortcode);
    16         }
    17     }
     12        function playbuzz_generate_shortcode(itemId) {
     13            var id                      = generate_id();
     14            var $playbuzz_item_shortcode = '[playbuzz-item item="' + itemId + '" wp-pb-id="' + id + '"]';
     15            QTags.insertContent( $playbuzz_item_shortcode );
     16        }
     17    }
    1818
    19     QTags.addButton('playbuzz-shortcode', 'Playbuzz', playbuzz_shortcode_generator);
     19    QTags.addButton( 'playbuzz-shortcode', 'Playbuzz', playbuzz_shortcode_generator );
    2020})();
  • playbuzz/tags/1.0.6/js/pb-search-popup.js

    r1831521 r1866507  
    11var playbuzz_search = function playbuzz_search() {
    22
    3     var apiBaseUrl = document.location.protocol + "//rest-api-v2.playbuzz.com/v2/items";
    4     this.display = display_search_popup;
    5     this.playbuzz_popup = playbuzz_popup;
    6 
    7     // Display search popup
    8     function display_search_popup(on_select_item) {
    9 
    10         // Open Playbuzz Popup
    11         playbuzz_popup();
    12 
    13         // Create popup structure (search popup)
    14         playbuzz_search_popup_structure(on_select_item);
    15 
    16         // Show featured items (on load)
    17         playbuzz_featured_items(1, on_select_item);
    18     }
    19 
    20     // Get attribute from pattern
    21     function get_attr(pattern, attr) {
    22 
    23         n = new RegExp(attr + '=\"([^\"]+)\"', 'g').exec(pattern);
    24         return n ? window.decodeURIComponent(n[1]) : '';
    25 
    26     };
    27 
    28     // Return formatted date
    29     function item_date(published_at) {
    30 
    31         var months = [
    32                 translation.jan,
    33                 translation.feb,
    34                 translation.mar,
    35                 translation.apr,
    36                 translation.may,
    37                 translation.jun,
    38                 translation.jul,
    39                 translation.aug,
    40                 translation.sep,
    41                 translation.oct,
    42                 translation.nov,
    43                 translation.dec
    44             ],
    45             publish_date = new Date(published_at),
    46             published = months[publish_date.getMonth()] + ' ' + publish_date.getDate() + ', ' + publish_date.getFullYear();
    47 
    48         return published;
    49 
    50     }
    51 
    52     // Return item type
    53     function playbuzz_item_type(type) {
    54 
    55         switch (type && type.toLowerCase()) {
    56             case "personality-quiz"    :
    57             case "testyourself"    :
    58                 name = translation.personality_quiz;
    59                 break;
    60             case "story"            :
    61                 name = translation.story;
    62                 break;
    63             case "snap-article"     :
    64                 name = translation.story;
    65                 break;
    66             case "list"            :
    67                 name = translation.list;
    68                 break;
    69             case "trivia"            :
    70             case "multiplechoice"    :
    71                 name = translation.trivia;
    72                 break;
    73             case "poll"                :
    74             case "playbuzzpoll"    :
    75                 name = translation.poll;
    76                 break;
    77             case "ranked-list"      :
    78             case "ranklist"        :
    79                 name = translation.ranked_list;
    80                 break;
    81             case "gallery-quiz"        :
    82             case "gallery"        :
    83                 name = translation.gallery_quiz;
    84                 break;
    85             case "flip-cards"        :
    86             case "reveal"        :
    87                 name = translation.flip_cards;
    88                 break;
    89             case "swiper"            :
    90                 name = translation.swiper;
    91                 break;
    92             case "countdown"        :
    93                 name = translation.countdown;
    94                 break;
    95             case "video-snaps"        :
    96             case "videosnaps"        :
    97                 name = translation.video_snaps;
    98                 break;
    99             case "convo"            :
    100                 name = translation.convo;
    101                 break;
    102             default                :
    103                 name = "";
    104                 break;
    105         }
    106         return name;
    107 
    108     }
    109 
    110     // Clear search info
    111     function clear_search_info() {
    112 
    113         // Clear search form values
    114         (jQuery)("#playbuzz_search").val('');
    115         (jQuery)("#playbuzz_search_type").val('');
    116         (jQuery)("#playbuzz_search_sort").val('');
    117 
    118         // Set proper placeholder text
    119         if ((jQuery)("#playbuzz_popup_tab_myitems").hasClass("playbuzz_active_tab")) {
    120             (jQuery)("#playbuzz_search").attr("placeholder", translation.search_term);
    121         } else {
    122             (jQuery)("#playbuzz_search").attr("placeholder", translation.search_my_items);
    123         }
    124 
    125     }
    126 
    127     // Add shortcode to tinyMCE editor (embed new items from the search popup to the tinyMCE editor)
    128     function remove_search_modal(itemId, format, on_select_item) {
    129         // Close playbuzz search popup
    130         (jQuery)(".playbuzz_popup_overlay_container").remove();
    131         return false;
    132     }
    133 
    134     // Playbuzz popup
    135     function playbuzz_popup() {
    136 
    137         // Create popup structure (using DOM construction for security reasons)
    138         (jQuery)("<div></div>").addClass("playbuzz_popup_overlay_container").appendTo("body");
    139         (jQuery)("<div></div>").addClass("playbuzz_popup_overlay_bg").appendTo(".playbuzz_popup_overlay_container");
    140         (jQuery)("<div></div>").addClass("playbuzz_popup_overlay_border").appendTo(".playbuzz_popup_overlay_bg");
    141         (jQuery)("<div></div>").attr("id", "playbuzz_popup").appendTo(".playbuzz_popup_overlay_border");
    142 
    143     }
    144 
    145     // Playbuzz search popup - create popup structure
    146     function playbuzz_search_popup_structure(on_select_item) {
    147 
    148         // Popup Components
    149         (jQuery)("<div></div>").attr("id", "playbuzz_search_form").attr("name", "search").appendTo("#playbuzz_popup");
    150         (jQuery)("<div></div>").attr("id", "playbuzz_search_header").appendTo("#playbuzz_search_form");
    151         (jQuery)("<div></div>").attr("id", "playbuzz_search_input_form").appendTo("#playbuzz_search_form");
    152         (jQuery)("<div></div>").attr("id", "playbuzz_search_sub_header").appendTo("#playbuzz_search_form");
    153         (jQuery)("<div></div>").attr("id", "playbuzz_search_results").appendTo("#playbuzz_search_form");
    154 
    155         // Header
    156         (jQuery)("<div></div>").attr("id", "playbuzz_popup_close").appendTo("#playbuzz_search_header").click(function () {
    157             (jQuery)(".playbuzz_popup_overlay_container").remove();
    158         });
    159         (jQuery)("<div></div>").addClass("playbuzz_search_logo").appendTo("#playbuzz_search_header").click(function () {
    160             clear_search_info();
    161             playbuzz_featured_items(1, on_select_item);
    162         });
    163         (jQuery)("<span></span>").appendTo(".playbuzz_search_logo").text(translation.playbuzz);
    164         (jQuery)("<nav></nav>").appendTo("#playbuzz_search_header");
    165         (jQuery)("<div></div>").attr("id", "playbuzz_popup_tab_content").click(function () {
    166             clear_search_info();
    167             playbuzz_featured_items(1, on_select_item);
    168         }).addClass("playbuzz_active_tab").appendTo("#playbuzz_search_header nav");
    169         (jQuery)("<div></div>").attr("id", "playbuzz_popup_tab_myitems").click(function () {
    170             clear_search_info();
    171             playbuzz_my_items(1, on_select_item);
    172         }).appendTo("#playbuzz_search_header nav");
    173         (jQuery)("<span></span>").appendTo("#playbuzz_popup_tab_content").text(translation.playbuzz_content);
    174         (jQuery)("<span></span>").appendTo("#playbuzz_popup_tab_myitems").text(translation.my_items);
    175 
    176         // Input form
    177         (jQuery)("<input>").attr("type", "text").attr("id", "playbuzz_search").attr("class", "playbuzz_search").attr("name", "playbuzz_search").attr("size", "16").attr("autocomplete", "off").attr("placeholder", translation.search_term).appendTo("#playbuzz_search_input_form").keyup(function () {
    178             playbuzz_show_screen(on_select_item);
    179         });
    180         (jQuery)("<span></span>").addClass("playbuzz_search_sep").appendTo("#playbuzz_search_input_form").text("|");
    181         (jQuery)("<a></a>").attr("href", "https://www.playbuzz.com/create").attr("target", "_blank").addClass("playbuzz_create_button").appendTo("#playbuzz_search_input_form").text(translation.create_your_own);
    182 
    183         // Sub Header
    184         (jQuery)("<div></div>").addClass("playbuzz_search_fields").appendTo("#playbuzz_search_sub_header");
    185         (jQuery)("<label></label>").attr("for", "playbuzz_search_type").addClass("playbuzz_search_label").appendTo(".playbuzz_search_fields").text(translation.show);
    186         (jQuery)("<select></select>").attr("name", "playbuzz_search_type").attr("id", "playbuzz_search_type").addClass("playbuzz_search_type").appendTo(".playbuzz_search_fields").change(function () {
    187             playbuzz_show_screen(on_select_item);
    188         });
    189         (jQuery)("<option></option>").attr("value", "").appendTo(".playbuzz_search_type").text(translation.all_types);
    190         (jQuery)("<option></option>").attr("value", "story,snap-article").appendTo(".playbuzz_search_type").text(translation.story);
    191         (jQuery)("<option></option>").attr("value", "list").appendTo(".playbuzz_search_type").text(translation.list);
    192         (jQuery)("<option></option>").attr("value", "personality-quiz").appendTo(".playbuzz_search_type").text(translation.personality_quiz);
    193         (jQuery)("<option></option>").attr("value", "poll").appendTo(".playbuzz_search_type").text(translation.poll);
    194         (jQuery)("<option></option>").attr("value", "ranked-list").appendTo(".playbuzz_search_type").text(translation.ranked_list);
    195         (jQuery)("<option></option>").attr("value", "trivia").appendTo(".playbuzz_search_type").text(translation.trivia);
    196         (jQuery)("<option></option>").attr("value", "gallery-quiz").appendTo(".playbuzz_search_type").text(translation.gallery_quiz);
    197         (jQuery)("<option></option>").attr("value", "flip-cards").appendTo(".playbuzz_search_type").text(translation.flip_cards);
    198         (jQuery)("<option></option>").attr("value", "swiper").appendTo(".playbuzz_search_type").text(translation.swiper);
    199         (jQuery)("<option></option>").attr("value", "countdown").appendTo(".playbuzz_search_type").text(translation.countdown);
    200         (jQuery)("<option></option>").attr("value", "video-snaps").appendTo(".playbuzz_search_type").text(translation.video_snaps);
    201         (jQuery)("<option></option>").attr("value", "convo").appendTo(".playbuzz_search_type").text(translation.convo);
    202         (jQuery)("<label></label>").attr("for", "playbuzz_search_sort").addClass("playbuzz_search_label").appendTo(".playbuzz_search_fields").text(translation.sort_by);
    203         (jQuery)("<select></select>").attr("name", "playbuzz_search_sort").attr("id", "playbuzz_search_sort").addClass("playbuzz_search_sort").appendTo(".playbuzz_search_fields").change(function () {
    204             playbuzz_show_screen(on_select_item);
    205         });
    206         (jQuery)("<option></option>").attr("value", "").appendTo(".playbuzz_search_sort").text(translation.relevance);
    207         (jQuery)("<option></option>").attr("value", "publishDate").appendTo(".playbuzz_search_sort").text(translation.date);
    208         (jQuery)("<div></div>").attr("id", "playbuzz_search_for").appendTo("#playbuzz_search_sub_header");
    209         (jQuery)("<p></p>").appendTo("#playbuzz_search_for").text(translation.discover_playful_content);
    210         (jQuery)("<div></div>").addClass("playbuzz_search_sub_divider").appendTo("#playbuzz_search_sub_header");
    211 
    212     }
    213 
    214     // Playbuzz popup error message
    215     function playbuzz_popup_message(popup_title, message_title, message_content) {
    216 
    217         // Popup title
    218         (jQuery)("#playbuzz_search_for").empty().append(
    219             (jQuery)("<p></p>").append(popup_title)
    220         );
    221 
    222         // Popup content
    223         (jQuery)("#playbuzz_search_results").empty().append(
    224             (jQuery)("<div></div>").addClass("playbuzz_error_message").append(
    225                 (jQuery)("<div></div>").addClass("playbuzz_notice").append(
    226                     (jQuery)("<h3></h3>").append(message_title)
    227                 ).append(
    228                     (jQuery)("<p></p>").append(message_content)
    229                 )
    230             )
    231         );
    232 
    233     }
    234 
    235     // Playbuzz no user screen
    236     function playbuzz_no_user() {
    237 
    238         // Update tabs
    239         (jQuery)("#playbuzz_popup_tab_content").removeClass("playbuzz_active_tab");
    240         (jQuery)("#playbuzz_popup_tab_myitems").addClass("playbuzz_active_tab");
    241 
    242         // Popup title
    243         (jQuery)("#playbuzz_search_for").empty().append(
    244             (jQuery)("<p></p>").append(
    245                 (jQuery)("<span></span>").addClass("playbuzz_search_title_user_img").append(
    246                     (jQuery)("<a></a>")
    247                         .attr("target", "_blank")
    248                         .attr("href", "options-general.php?page=playbuzz&tab=embed")
    249                         .addClass("playbuzz_set_username_link")
    250                         .text(translation.set_user)
    251                 )
    252             )
    253         );
    254 
    255         // Popup content
    256         (jQuery)("#playbuzz_search_results").empty().append(
    257             (jQuery)("<div></div>").addClass("playbuzz_error_message").append(
    258                 (jQuery)("<div></div>").addClass("playbuzz_notice").append(
    259                     (jQuery)("<h3></h3>").append(translation.no_user)
    260                 ).append(
    261                     (jQuery)("<p></p>").append(translation.set_your_username)
    262                 )
    263             )
    264         );
    265 
    266     }
    267 
    268     // Playbuzz search results
    269     function playbuzz_search_results(layout, data, popup_title, popup_title_paging, on_select_item) {
    270         // Popup title
    271         (jQuery)("#playbuzz_search_for")
    272             .empty()
    273             .append(
    274                 (jQuery)("<p></p>")
    275                     .append(popup_title)
    276                     .append(popup_title_paging)
    277             );
    278 
    279         // Popup content
    280         (jQuery)("#playbuzz_search_results").empty();
    281         (jQuery)("#playbuzz_search_results")[0].scrollTop = 0;
    282 
    283         (jQuery).each(data, function (key, val) {
    284 
    285             (jQuery)("<div></div>")
    286                 .addClass("playbuzz_" + layout + "_view")
    287                 .appendTo("#playbuzz_search_results")
    288                 .append(
    289                     // thumbnail
    290                     (jQuery)("<div></div>")
    291                         .addClass("playbuzz_present_item_thumb")
    292                         .append(
    293                             (jQuery)("<img>", {src: val.imageMedium})
    294                         )
    295                 )
    296                 .append(
    297                     // desc
    298                     (jQuery)("<div></div>")
    299                         .addClass("playbuzz_present_item_desc")
    300                         .append(
    301                             (jQuery)("<div></div>")
    302                                 .addClass("playbuzz_present_item_title")
    303                                 .text(val.title)
    304                         )
    305                         .append(
    306                             (jQuery)("<div></div>")
    307                                 .addClass("playbuzz_present_item_meta")
    308                                 .text(translation.by + " ")
    309                                 .append(
    310                                     (jQuery)("<span></span>")
    311                                         .text(val.channelName)
    312                                 )
    313                                 .append(" " + translation.on + " " + item_date(val.publishDate))
    314                         )
    315                 )
    316                 .append(
    317                     // type
    318                     (jQuery)("<div></div>")
    319                         .addClass("playbuzz_present_item_type")
    320                         .append(
    321                             (jQuery)("<span></span>")
    322                                 .text(playbuzz_item_type(val.format))
    323                         )
    324                 )
    325                 .append(
    326                     // buttons
    327                     (jQuery)("<div></div>")
    328                         .addClass("playbuzz_present_item_buttons")
    329                         .append(
    330                             (jQuery)("<a></a>")
    331                                 .addClass("button button-secondary")
    332                                 .attr("target", "_blank")
    333                                 .attr("href", val.playbuzzUrl)
    334                                 .text(translation.view)
    335                         )
    336                         .append(
    337                             (jQuery)("<input>")
    338                                 .attr("type", "button")
    339                                 .attr("class", "button button-primary")
    340                                 .attr("value", translation.embed)
    341                                 .click(function () {
    342                                     on_select_item(val.id, val.format);
    343                                     return remove_search_modal();
    344                                 })
    345                         )
    346                 );
    347         });
    348 
    349     }
    350 
    351     // Playbuzz popup pagination
    352     function playbuzz_popup_pagination(total_pages, current_page, type) {
    353 
    354         // Set current page
    355         current_page = (isNaN(current_page)) ? parseInt(current_page) : current_page;
    356         current_page = (current_page < 1) ? 1 : current_page;
    357 
    358         // Set start page
    359         var start_page = current_page - 2;
    360         if (start_page <= 0) {
    361             start_page = 1;
    362         }
    363 
    364         // Set end_page
    365         var end_page = current_page + 2;
    366         if (end_page >= total_pages) {
    367             end_page = total_pages;
    368         }
    369 
    370         // Open pagination container
    371         (jQuery)("<div></div>")
    372             .addClass("playbuzz_item_pagination")
    373             .addClass(type)
    374             .attr("data-function", type)
    375             .appendTo("#playbuzz_search_results");
    376 
    377         // Add prev page link
    378         if (current_page == 1) {
    379             (jQuery)("<a></a>")
    380                 .addClass("playbuzz_prev disabled_pagination")
    381                 .appendTo(".playbuzz_item_pagination");
    382         } else {
    383             (jQuery)("<a></a>")
    384                 .attr("onclick", type + "(" + (current_page - 1) + ")")
    385                 .addClass("playbuzz_prev enabled_pagination")
    386                 .appendTo(".playbuzz_item_pagination");
    387         }
    388 
    389         // Add pages
    390         for (page = start_page; page <= end_page; ++page) {
    391             current_page_class = ((page == current_page) ? " playbuzz_current" : "");
    392 
    393             (jQuery)("<a></a>")
    394                 .attr("onclick", type + "(" + page + ")")
    395                 .addClass("enabled_pagination")
    396                 .addClass(current_page_class)
    397                 .appendTo(".playbuzz_item_pagination")
    398                 .text(page);
    399         }
    400 
    401         // Add next page link
    402         if (current_page == total_pages) {
    403             (jQuery)("<a></a>")
    404                 .addClass("playbuzz_next disabled_pagination")
    405                 .appendTo(".playbuzz_item_pagination");
    406         } else {
    407             (jQuery)("<a></a>")
    408                 .attr("onclick", type + "(" + (current_page + 1) + ")")
    409                 .addClass("playbuzz_next enabled_pagination")
    410                 .appendTo(".playbuzz_item_pagination");
    411         }
    412 
    413     }
    414 
    415     // Playbuzz show popup screen
    416     function playbuzz_show_screen(on_select_item) {
    417 
    418         var is_content_tab = (((jQuery)("#playbuzz_popup_tab_content").hasClass("playbuzz_active_tab")) ? true : false),
    419             is_search = (((jQuery)("#playbuzz_search").val().trim() != '') ? true : false);
    420 
    421         if (is_search) {
    422             if (is_content_tab) {
    423                 playbuzz_general_search(1, on_select_item);
    424             } else {
    425                 playbuzz_user_search(1, on_select_item);
    426             }
    427         } else {
    428             if (is_content_tab) {
    429                 playbuzz_featured_items(1, on_select_item);
    430             } else {
    431                 playbuzz_my_items(1, on_select_item);
    432             }
    433         }
    434 
    435     }
    436 
    437     // Playbuzz featured items screen
    438     function playbuzz_featured_items(current_page, on_select_item) {
    439 
    440         var apiBaseUrl = document.location.protocol + "//rest-api-v2.playbuzz.com/v2/items";
    441 
    442         // Set variables
    443         var results_layout = "grid",
    444             results_title = translation.featured_items,
    445             items_per_page = 30;
    446 
    447         // Update tabs
    448         (jQuery)("#playbuzz_popup_tab_content").addClass("playbuzz_active_tab");
    449         (jQuery)("#playbuzz_popup_tab_myitems").removeClass("playbuzz_active_tab");
    450 
    451         // Load items using the Playbuzz API
    452         (jQuery).ajax({
    453             url: apiBaseUrl,
    454             type: "get",
    455             dataType: "json",
    456             data: {
    457                 internalTags: "EditorsPick_Featured",
    458                 format: (jQuery)("#playbuzz_search_type").val(),
    459                 sort: (jQuery)("#playbuzz_search_sort").val(),
    460                 size: items_per_page,
    461                 from: (current_page * items_per_page) - items_per_page
    462             },
    463             error: function (data) {
    464 
    465                 // Server Error
    466                 playbuzz_popup_message(results_title, translation.server_error, translation.try_in_a_few_minutes);
    467                 console.error("Couldn't get data: ", data);
    468 
    469             },
    470             success: function (data) {
    471 
    472                 // Set variables
    473                 var total_items = data.payload.totalItems,
    474                     total_pages = ((total_items >= items_per_page) ? Math.ceil(total_items / items_per_page) : 1),
    475                     results_pages = ((current_page > 1) ? " <span class='playbuzz_search_title_pagination'>(" + translation.page + " " + current_page + " / " + total_pages + ")" : "");
    476 
    477                 // Data output
    478                 if (total_items > 0) {
    479                     // Show Results
    480                     playbuzz_search_results(results_layout, data.payload.items, results_title, results_pages, on_select_item);
    481                     // Pagination
    482                     if (total_items > items_per_page) {
    483                         playbuzz_popup_pagination(total_pages, current_page, 'playbuzz_featured_items');
    484                     }
    485                 } else {
    486                     // No Search Results
    487                     playbuzz_popup_message(results_title, translation.no_results_found, translation.try_different_search);
    488                 }
    489 
    490             }
    491 
    492         });
    493 
    494     }
    495 
    496     window.playbuzz_featured_items = playbuzz_featured_items;
    497 
    498     function is_playbuzz_url(url) {
    499         var valid = ["http://www.playbuzz.com/", "https://www.playbuzz.com", "www.playbuzz.com"];
    500         for (var i = 0; i < valid.length; i++) {
    501             if (url.indexOf(valid[i]) === 0) {
    502                 return true;
    503             }
    504         }
    505 
    506         return false;
    507     }
    508 
    509     // Playbuzz general search screen
    510     function playbuzz_general_search(current_page, on_select_item) {
    511         var search_param = (jQuery)("#playbuzz_search").val();
    512 
    513         // Set variables
    514         var results_layout = "list",
    515 
    516             string = (jQuery)("#playbuzz_search").val();
    517         if (string.length > 25) {
    518             string = string.substring(0, 16) + "...";
    519         }
    520 
    521         results_title = (translation.results_for + " '" + string + "'"),
    522             items_per_page = 30;
    523 
    524         // Update tabs
    525         (jQuery)("#playbuzz_popup_tab_content").addClass("playbuzz_active_tab");
    526         (jQuery)("#playbuzz_popup_tab_myitems").removeClass("playbuzz_active_tab");
    527 
    528         var dataObject;
    529         if (is_playbuzz_url(search_param)) {
    530             dataObject = {
    531                 playbuzzUrl: search_param
    532             };
    533         } else {
    534             dataObject = {
    535                 q: search_param,
    536                 format: (jQuery)("#playbuzz_search_type").val(),
    537                 sort: (jQuery)("#playbuzz_search_sort").val(),
    538                 size: items_per_page,
    539                 from: (current_page * items_per_page) - items_per_page
    540             };
    541         }
    542 
    543         // Load items using the Playbuzz API
    544         (jQuery).ajax({
    545             url: apiBaseUrl,
    546             type: "get",
    547             dataType: "json",
    548             data: dataObject,
    549             error: function (data) {
    550 
    551                 // Server Error
    552                 playbuzz_popup_message(results_title, translation.server_error, translation.try_in_a_few_minutes);
    553                 console.error("Couldn't get data: ", data);
    554 
    555             },
    556             success: function (data) {
    557 
    558                 // Set variables
    559                 var total_items = data.payload.totalItems,
    560                     total_pages = ((total_items >= items_per_page) ? Math.ceil(total_items / items_per_page) : 1),
    561                     results_pages = ((current_page > 1) ? " <span class='playbuzz_search_title_pagination'>(" + translation.page + " " + current_page + " / " + total_pages + ")" : "");
    562 
    563                 // Data output
    564                 if (total_items > 0) {
    565                     // Show Results
    566                     playbuzz_search_results(results_layout, data.payload.items, results_title, results_pages, on_select_item);
    567                     // Pagination
    568                     if (total_items > items_per_page) {
    569                         playbuzz_popup_pagination(total_pages, current_page, 'playbuzz_general_search');
    570                     }
    571                 } else {
    572                     // No Search Results
    573                     playbuzz_popup_message(results_title, translation.no_results_found, translation.try_different_search);
    574                 }
    575 
    576             }
    577 
    578         });
    579 
    580     }
    581 
    582     window.playbuzz_general_search = playbuzz_general_search;
    583 
    584     // Playbuzz my items screen
    585     function playbuzz_my_items(current_page, on_select_item) {
    586 
    587         // exit if username is not set
    588         if (!site_settings.pb_user || 0 === site_settings.pb_user) {
    589             playbuzz_no_user();
    590             return;
    591         }
    592 
    593         // Set variables
    594         var results_layout = "list",
    595             results_title = ("<span class='playbuzz_search_title_user_img'>" + site_settings.pb_user + "</span>"),
    596             items_per_page = 30;
    597 
    598         // Update tabs
    599         (jQuery)("#playbuzz_popup_tab_content").removeClass("playbuzz_active_tab");
    600         (jQuery)("#playbuzz_popup_tab_myitems").addClass("playbuzz_active_tab");
    601 
    602         // Load items using the Playbuzz API
    603         (jQuery).ajax({
    604             url: apiBaseUrl,
    605             type: "get",
    606             dataType: "json",
    607             data: {
    608                 format: (jQuery)("#playbuzz_search_type").val(),
    609                 sort: (jQuery)("#playbuzz_search_sort").val(),
    610                 size: items_per_page,
    611                 from: (current_page * items_per_page) - items_per_page,
    612                 channelAlias: site_settings.pb_user,
    613                 moderation: "none"
    614             },
    615             error: function (data) {
    616 
    617                 // Server Error
    618                 playbuzz_popup_message(results_title, translation.server_error, translation.try_in_a_few_minutes);
    619                 console.error("Couldn't get data: ", data);
    620 
    621             },
    622             success: function (data) {
    623 
    624                 // Set variables
    625                 var total_items = data.payload.totalItems,
    626                     total_pages = ((total_items >= items_per_page) ? Math.ceil(total_items / items_per_page) : 1),
    627                     results_pages = (" <span class='playbuzz_search_title_pagination'>(" + total_items + " " + translation.items + ")"),
    628                     change_user = ("<a href='options-general.php?page=playbuzz&tab=embed' target='_blank' class='playbuzz_change_username_link'>" + translation.change_user + "</a>");
    629                 create_button = ("<div class='playbuzz_create_button'><a href='https://www.playbuzz.com/create' target='_blank'>" + translation.create_your_own + "</a></div>")
    630 
    631                 // Data output
    632                 if (data.payload.currentItemCount > 0) {
    633 
    634                     // Show Results
    635                     playbuzz_search_results(results_layout, data.payload.items, results_title, results_pages + change_user, on_select_item);
    636                     // Pagination
    637                     if (total_items > items_per_page) {
    638                         playbuzz_popup_pagination(total_pages, current_page, 'playbuzz_my_items');
    639                     }
    640                 } else {
    641                     // No Search Results
    642                     playbuzz_popup_message(results_title + results_pages + change_user, translation.you_dont_have_any_items_yet, translation.go_to_playbuzz_to_create_your_own_playful_content + create_button);
    643                 }
    644 
    645             }
    646 
    647         });
    648 
    649     }
    650 
    651     window.playbuzz_my_items = playbuzz_my_items;
    652 
    653     // Playbuzz user search screen
    654     function playbuzz_user_search(current_page, on_select_item) {
    655         // exit if username is not set
    656         if (!site_settings.pb_user || 0 === site_settings.pb_user) {
    657             playbuzz_no_user();
    658             return;
    659         }
    660 
    661         var search_param = (jQuery)("#playbuzz_search").val();
    662 
    663         if (search_param.length > 25) {
    664             search_param = search_param.substring(0, 16) + "...";
    665         }
    666 
    667         // Set variables
    668         var results_layout = "list",
    669             results_title = (translation.results_for + " '" + search_param + "' "),
    670             items_per_page = 30;
    671 
    672         var dataObject;
    673         if (is_playbuzz_url(search_param)) {
    674             dataObject = {
    675                 playbuzzUrl: search_param
    676             };
    677         } else {
    678             dataObject = {
    679                 q: search_param,
    680                 format: (jQuery)("#playbuzz_search_type").val(),
    681                 sort: (jQuery)("#playbuzz_search_sort").val(),
    682                 size: items_per_page,
    683                 from: (current_page * items_per_page) - items_per_page,
    684                 channelAlias: site_settings.pb_user,
    685                 moderation: "none"
    686             };
    687         }
    688 
    689         // Update tabs
    690         (jQuery)("#playbuzz_popup_tab_content").removeClass("playbuzz_active_tab");
    691         (jQuery)("#playbuzz_popup_tab_myitems").addClass("playbuzz_active_tab");
    692 
    693         // Load items using the Playbuzz API
    694         (jQuery).ajax({
    695             url: apiBaseUrl,
    696             type: "get",
    697             dataType: "json",
    698             data: dataObject,
    699             error: function (data) {
    700 
    701                 // Server Error
    702                 playbuzz_popup_message(results_title, translation.server_error, translation.try_in_a_few_minutes);
    703                 console.error("Couldn't get data: ", data);
    704 
    705             },
    706             success: function (data) {
    707 
    708                 // Set variables
    709                 var total_items = data.payload.totalItems,
    710                     total_pages = ((total_items >= items_per_page) ? Math.ceil(total_items / items_per_page) : 1),
    711                     results_pages = ((current_page > 1) ? " <span class='playbuzz_search_title_pagination'>(" + translation.page + " " + current_page + " / " + total_pages + ")" : "");
    712 
    713                 // Data output
    714                 if (data.payload.items.length > 0) {
    715                     // Show Results
    716                     playbuzz_search_results(results_layout, data.payload.items, results_title, results_pages, on_select_item);
    717                     // Pagination
    718                     if (total_items > items_per_page) {
    719                         playbuzz_popup_pagination(total_pages, current_page, 'playbuzz_user_search');
    720                     }
    721                 } else {
    722                     // No Search Results
    723                     playbuzz_popup_message(results_title, translation.no_results_found, translation.try_different_search);
    724                 }
    725 
    726             }
    727 
    728         });
    729 
    730     }
    731 
    732     window.playbuzz_user_search = playbuzz_user_search;
     3    this.display        = display_search_popup;
     4    this.playbuzz_popup = playbuzz_popup;
     5
     6    var apiBaseUrl = document.location.protocol + "//rest-api-v2.playbuzz.com/v2/items";
     7
     8    // Display search popup
     9    function display_search_popup(on_select_item) {
     10
     11        // Open Playbuzz Popup
     12        playbuzz_popup();
     13
     14        // Create popup structure (search popup)
     15        playbuzz_search_popup_structure( on_select_item );
     16
     17        // Show featured items (on load)
     18        playbuzz_featured_items( 1, on_select_item );
     19    }
     20
     21    // Get attribute from pattern
     22    function get_attr(pattern, attr) {
     23
     24        n = new RegExp( attr + '=\"([^\"]+)\"', 'g' ).exec( pattern );
     25        return n ? window.decodeURIComponent( n[1] ) : '';
     26
     27    };
     28
     29    // Return formatted date
     30    function item_date(published_at) {
     31
     32        var months       = [
     33                translation.jan,
     34                translation.feb,
     35                translation.mar,
     36                translation.apr,
     37                translation.may,
     38                translation.jun,
     39                translation.jul,
     40                translation.aug,
     41                translation.sep,
     42                translation.oct,
     43                translation.nov,
     44                translation.dec
     45            ],
     46            publish_date = new Date( published_at ),
     47            published    = months[publish_date.getMonth()] + ' ' + publish_date.getDate() + ', ' + publish_date.getFullYear();
     48
     49        return published;
     50
     51    }
     52
     53    // Return item type
     54    function playbuzz_item_type(type) {
     55
     56        switch (type && type.toLowerCase()) {
     57            case "personality-quiz"    :
     58            case "testyourself"    :
     59                name = translation.personality_quiz;
     60                break;
     61            case "story"            :
     62                name = translation.story;
     63                break;
     64            case "snap-article"     :
     65                name = translation.story;
     66                break;
     67            case "list"            :
     68                name = translation.list;
     69                break;
     70            case "trivia"            :
     71            case "multiplechoice"    :
     72                name = translation.trivia;
     73                break;
     74            case "poll"                :
     75            case "playbuzzpoll"    :
     76                name = translation.poll;
     77                break;
     78            case "ranked-list"      :
     79            case "ranklist"        :
     80                name = translation.ranked_list;
     81                break;
     82            case "gallery-quiz"        :
     83            case "gallery"        :
     84                name = translation.gallery_quiz;
     85                break;
     86            case "flip-cards"        :
     87            case "reveal"        :
     88                name = translation.flip_cards;
     89                break;
     90            case "swiper"            :
     91                name = translation.swiper;
     92                break;
     93            case "countdown"        :
     94                name = translation.countdown;
     95                break;
     96            case "video-snaps"        :
     97            case "videosnaps"        :
     98                name = translation.video_snaps;
     99                break;
     100            case "convo"            :
     101                name = translation.convo;
     102                break;
     103            default                :
     104                name = "";
     105                break;
     106        }
     107        return name;
     108
     109    }
     110
     111    // Clear search info
     112    function clear_search_info() {
     113
     114        // Clear search form values
     115        (jQuery)( "#playbuzz_search" ).val( '' );
     116        (jQuery)( "#playbuzz_search_type" ).val( '' );
     117        (jQuery)( "#playbuzz_search_sort" ).val( '' );
     118
     119        // Set proper placeholder text
     120        if ((jQuery)( "#playbuzz_popup_tab_myitems" ).hasClass( "playbuzz_active_tab" )) {
     121            (jQuery)( "#playbuzz_search" ).attr( "placeholder", translation.search_term );
     122        } else {
     123            (jQuery)( "#playbuzz_search" ).attr( "placeholder", translation.search_my_items );
     124        }
     125
     126    }
     127
     128    // Add shortcode to tinyMCE editor (embed new items from the search popup to the tinyMCE editor)
     129    function remove_search_modal(itemId, format, on_select_item) {
     130        // Close playbuzz search popup
     131        (jQuery)( ".playbuzz_popup_overlay_container" ).remove();
     132        return false;
     133    }
     134
     135    // Playbuzz popup
     136    function playbuzz_popup() {
     137
     138        // Create popup structure (using DOM construction for security reasons)
     139        (jQuery)( "<div></div>" ).addClass( "playbuzz_popup_overlay_container" ).appendTo( "body" );
     140        (jQuery)( "<div></div>" ).addClass( "playbuzz_popup_overlay_bg" ).appendTo( ".playbuzz_popup_overlay_container" );
     141        (jQuery)( "<div></div>" ).addClass( "playbuzz_popup_overlay_border" ).appendTo( ".playbuzz_popup_overlay_bg" );
     142        (jQuery)( "<div></div>" ).attr( "id", "playbuzz_popup" ).appendTo( ".playbuzz_popup_overlay_border" );
     143
     144    }
     145
     146    // Playbuzz search popup - create popup structure
     147    function playbuzz_search_popup_structure(on_select_item) {
     148
     149        // Popup Components
     150        (jQuery)( "<div></div>" ).attr( "id", "playbuzz_search_form" ).attr( "name", "search" ).appendTo( "#playbuzz_popup" );
     151        (jQuery)( "<div></div>" ).attr( "id", "playbuzz_search_header" ).appendTo( "#playbuzz_search_form" );
     152        (jQuery)( "<div></div>" ).attr( "id", "playbuzz_search_input_form" ).appendTo( "#playbuzz_search_form" );
     153        (jQuery)( "<div></div>" ).attr( "id", "playbuzz_search_sub_header" ).appendTo( "#playbuzz_search_form" );
     154        (jQuery)( "<div></div>" ).attr( "id", "playbuzz_search_results" ).appendTo( "#playbuzz_search_form" );
     155
     156        // Header
     157        (jQuery)( "<div></div>" ).attr( "id", "playbuzz_popup_close" ).appendTo( "#playbuzz_search_header" ).click(
     158            function () {
     159                (jQuery)( ".playbuzz_popup_overlay_container" ).remove();
     160            }
     161        );
     162        (jQuery)( "<div></div>" ).addClass( "playbuzz_search_logo" ).appendTo( "#playbuzz_search_header" ).click(
     163            function () {
     164                clear_search_info();
     165                playbuzz_featured_items( 1, on_select_item );
     166            }
     167        );
     168        (jQuery)( "<span></span>" ).appendTo( ".playbuzz_search_logo" ).text( translation.playbuzz );
     169        (jQuery)( "<nav></nav>" ).appendTo( "#playbuzz_search_header" );
     170        (jQuery)( "<div></div>" ).attr( "id", "playbuzz_popup_tab_content" ).click(
     171            function () {
     172                clear_search_info();
     173                playbuzz_featured_items( 1, on_select_item );
     174            }
     175        ).addClass( "playbuzz_active_tab" ).appendTo( "#playbuzz_search_header nav" );
     176        (jQuery)( "<div></div>" ).attr( "id", "playbuzz_popup_tab_myitems" ).click(
     177            function () {
     178                clear_search_info();
     179                playbuzz_my_items( 1, on_select_item );
     180            }
     181        ).appendTo( "#playbuzz_search_header nav" );
     182        (jQuery)( "<span></span>" ).appendTo( "#playbuzz_popup_tab_content" ).text( translation.playbuzz_content );
     183        (jQuery)( "<span></span>" ).appendTo( "#playbuzz_popup_tab_myitems" ).text( translation.my_items );
     184
     185        // Input form
     186        (jQuery)( "<input>" ).attr( "type", "text" ).attr( "id", "playbuzz_search" ).attr( "class", "playbuzz_search" ).attr( "name", "playbuzz_search" ).attr( "size", "16" ).attr( "autocomplete", "off" ).attr( "placeholder", translation.search_term ).appendTo( "#playbuzz_search_input_form" ).keyup(
     187            function () {
     188                playbuzz_show_screen( on_select_item );
     189            }
     190        );
     191        (jQuery)( "<span></span>" ).addClass( "playbuzz_search_sep" ).appendTo( "#playbuzz_search_input_form" ).text( "|" );
     192        (jQuery)( "<a></a>" ).attr( "href", "https://www.playbuzz.com/create" ).attr( "target", "_blank" ).addClass( "playbuzz_create_button" ).appendTo( "#playbuzz_search_input_form" ).text( translation.create_your_own );
     193
     194        // Sub Header
     195        (jQuery)( "<div></div>" ).addClass( "playbuzz_search_fields" ).appendTo( "#playbuzz_search_sub_header" );
     196        (jQuery)( "<label></label>" ).attr( "for", "playbuzz_search_type" ).addClass( "playbuzz_search_label" ).appendTo( ".playbuzz_search_fields" ).text( translation.show );
     197        (jQuery)( "<select></select>" ).attr( "name", "playbuzz_search_type" ).attr( "id", "playbuzz_search_type" ).addClass( "playbuzz_search_type" ).appendTo( ".playbuzz_search_fields" ).change(
     198            function () {
     199                playbuzz_show_screen( on_select_item );
     200            }
     201        );
     202        (jQuery)( "<option></option>" ).attr( "value", "" ).appendTo( ".playbuzz_search_type" ).text( translation.all_types );
     203        (jQuery)( "<option></option>" ).attr( "value", "story,snap-article" ).appendTo( ".playbuzz_search_type" ).text( translation.story );
     204        (jQuery)( "<option></option>" ).attr( "value", "list" ).appendTo( ".playbuzz_search_type" ).text( translation.list );
     205        (jQuery)( "<option></option>" ).attr( "value", "personality-quiz" ).appendTo( ".playbuzz_search_type" ).text( translation.personality_quiz );
     206        (jQuery)( "<option></option>" ).attr( "value", "poll" ).appendTo( ".playbuzz_search_type" ).text( translation.poll );
     207        (jQuery)( "<option></option>" ).attr( "value", "ranked-list" ).appendTo( ".playbuzz_search_type" ).text( translation.ranked_list );
     208        (jQuery)( "<option></option>" ).attr( "value", "trivia" ).appendTo( ".playbuzz_search_type" ).text( translation.trivia );
     209        (jQuery)( "<option></option>" ).attr( "value", "gallery-quiz" ).appendTo( ".playbuzz_search_type" ).text( translation.gallery_quiz );
     210        (jQuery)( "<option></option>" ).attr( "value", "flip-cards" ).appendTo( ".playbuzz_search_type" ).text( translation.flip_cards );
     211        (jQuery)( "<option></option>" ).attr( "value", "swiper" ).appendTo( ".playbuzz_search_type" ).text( translation.swiper );
     212        (jQuery)( "<option></option>" ).attr( "value", "countdown" ).appendTo( ".playbuzz_search_type" ).text( translation.countdown );
     213        (jQuery)( "<option></option>" ).attr( "value", "video-snaps" ).appendTo( ".playbuzz_search_type" ).text( translation.video_snaps );
     214        (jQuery)( "<option></option>" ).attr( "value", "convo" ).appendTo( ".playbuzz_search_type" ).text( translation.convo );
     215        (jQuery)( "<label></label>" ).attr( "for", "playbuzz_search_sort" ).addClass( "playbuzz_search_label" ).appendTo( ".playbuzz_search_fields" ).text( translation.sort_by );
     216        (jQuery)( "<select></select>" ).attr( "name", "playbuzz_search_sort" ).attr( "id", "playbuzz_search_sort" ).addClass( "playbuzz_search_sort" ).appendTo( ".playbuzz_search_fields" ).change(
     217            function () {
     218                playbuzz_show_screen( on_select_item );
     219            }
     220        );
     221        (jQuery)( "<option></option>" ).attr( "value", "" ).appendTo( ".playbuzz_search_sort" ).text( translation.relevance );
     222        (jQuery)( "<option></option>" ).attr( "value", "publishDate" ).appendTo( ".playbuzz_search_sort" ).text( translation.date );
     223        (jQuery)( "<div></div>" ).attr( "id", "playbuzz_search_for" ).appendTo( "#playbuzz_search_sub_header" );
     224        (jQuery)( "<p></p>" ).appendTo( "#playbuzz_search_for" ).text( translation.discover_playful_content );
     225        (jQuery)( "<div></div>" ).addClass( "playbuzz_search_sub_divider" ).appendTo( "#playbuzz_search_sub_header" );
     226
     227    }
     228
     229    // Playbuzz popup error message
     230    function playbuzz_popup_message(popup_title, message_title, message_content) {
     231
     232        // Popup title
     233        (jQuery)( "#playbuzz_search_for" ).empty().append(
     234            (jQuery)( "<p></p>" ).append( popup_title )
     235        );
     236
     237        // Popup content
     238        (jQuery)( "#playbuzz_search_results" ).empty().append(
     239            (jQuery)( "<div></div>" ).addClass( "playbuzz_error_message" ).append(
     240                (jQuery)( "<div></div>" ).addClass( "playbuzz_notice" ).append(
     241                    (jQuery)( "<h3></h3>" ).append( message_title )
     242                ).append(
     243                    (jQuery)( "<p></p>" ).append( message_content )
     244                )
     245            )
     246        );
     247
     248    }
     249
     250    // Playbuzz no user screen
     251    function playbuzz_no_user() {
     252
     253        // Update tabs
     254        (jQuery)( "#playbuzz_popup_tab_content" ).removeClass( "playbuzz_active_tab" );
     255        (jQuery)( "#playbuzz_popup_tab_myitems" ).addClass( "playbuzz_active_tab" );
     256
     257        // Popup title
     258        (jQuery)( "#playbuzz_search_for" ).empty().append(
     259            (jQuery)( "<p></p>" ).append(
     260                (jQuery)( "<span></span>" ).addClass( "playbuzz_search_title_user_img" ).append(
     261                    (jQuery)( "<a></a>" )
     262                        .attr( "target", "_blank" )
     263                        .attr( "href", "options-general.php?page=playbuzz&tab=embed" )
     264                        .addClass( "playbuzz_set_username_link" )
     265                        .text( translation.set_user )
     266                )
     267            )
     268        );
     269
     270        // Popup content
     271        (jQuery)( "#playbuzz_search_results" ).empty().append(
     272            (jQuery)( "<div></div>" ).addClass( "playbuzz_error_message" ).append(
     273                (jQuery)( "<div></div>" ).addClass( "playbuzz_notice" ).append(
     274                    (jQuery)( "<h3></h3>" ).append( translation.no_user )
     275                ).append(
     276                    (jQuery)( "<p></p>" ).append( translation.set_your_username )
     277                )
     278            )
     279        );
     280
     281    }
     282
     283    // Playbuzz search results
     284    function playbuzz_search_results(layout, data, popup_title, popup_title_paging, on_select_item) {
     285        // Popup title
     286        (jQuery)( "#playbuzz_search_for" )
     287            .empty()
     288            .append(
     289                (jQuery)( "<p></p>" )
     290                    .append( popup_title )
     291                    .append( popup_title_paging )
     292            );
     293
     294        // Popup content
     295        (jQuery)( "#playbuzz_search_results" ).empty();
     296        (jQuery)( "#playbuzz_search_results" )[0].scrollTop = 0;
     297
     298        (jQuery).each(
     299            data, function (key, val) {
     300
     301                (jQuery)( "<div></div>" )
     302                .addClass( "playbuzz_" + layout + "_view" )
     303                .appendTo( "#playbuzz_search_results" )
     304                .append(
     305                    // thumbnail
     306                    (jQuery)( "<div></div>" )
     307                        .addClass( "playbuzz_present_item_thumb" )
     308                        .append(
     309                            (jQuery)( "<img>", {src: val.imageMedium} )
     310                        )
     311                )
     312                .append(
     313                    // desc
     314                    (jQuery)( "<div></div>" )
     315                        .addClass( "playbuzz_present_item_desc" )
     316                        .append(
     317                            (jQuery)( "<div></div>" )
     318                                .addClass( "playbuzz_present_item_title" )
     319                                .text( val.title )
     320                        )
     321                        .append(
     322                            (jQuery)( "<div></div>" )
     323                                .addClass( "playbuzz_present_item_meta" )
     324                                .text( translation.by + " " )
     325                                .append(
     326                                    (jQuery)( "<span></span>" )
     327                                        .text( val.channelName )
     328                                )
     329                                .append( " " + translation.on + " " + item_date( val.publishDate ) )
     330                        )
     331                )
     332                .append(
     333                    // type
     334                    (jQuery)( "<div></div>" )
     335                        .addClass( "playbuzz_present_item_type" )
     336                        .append(
     337                            (jQuery)( "<span></span>" )
     338                                .text( playbuzz_item_type( val.format ) )
     339                        )
     340                )
     341                .append(
     342                    // buttons
     343                    (jQuery)( "<div></div>" )
     344                        .addClass( "playbuzz_present_item_buttons" )
     345                        .append(
     346                            (jQuery)( "<a></a>" )
     347                                .addClass( "button button-secondary" )
     348                                .attr( "target", "_blank" )
     349                                .attr( "href", val.playbuzzUrl )
     350                                .text( translation.view )
     351                        )
     352                        .append(
     353                            (jQuery)( "<input>" )
     354                                .attr( "type", "button" )
     355                                .attr( "class", "button button-primary" )
     356                                .attr( "value", translation.embed )
     357                                .click(
     358                                    function () {
     359                                        on_select_item( val.id, val.format );
     360                                        return remove_search_modal();
     361                                    }
     362                                )
     363                        )
     364                );
     365            }
     366        );
     367
     368    }
     369
     370    // Playbuzz popup pagination
     371    function playbuzz_popup_pagination(total_pages, current_page, type) {
     372
     373        // Set current page
     374        current_page = (isNaN( current_page )) ? parseInt( current_page ) : current_page;
     375        current_page = (current_page < 1) ? 1 : current_page;
     376
     377        // Set start page
     378        var start_page = current_page - 2;
     379        if (start_page <= 0) {
     380            start_page = 1;
     381        }
     382
     383        // Set end_page
     384        var end_page = current_page + 2;
     385        if (end_page >= total_pages) {
     386            end_page = total_pages;
     387        }
     388
     389        // Open pagination container
     390        (jQuery)( "<div></div>" )
     391            .addClass( "playbuzz_item_pagination" )
     392            .addClass( type )
     393            .attr( "data-function", type )
     394            .appendTo( "#playbuzz_search_results" );
     395
     396        // Add prev page link
     397        if (current_page == 1) {
     398            (jQuery)( "<a></a>" )
     399                .addClass( "playbuzz_prev disabled_pagination" )
     400                .appendTo( ".playbuzz_item_pagination" );
     401        } else {
     402            (jQuery)( "<a></a>" )
     403                .attr( "onclick", type + "(" + (current_page - 1) + ")" )
     404                .addClass( "playbuzz_prev enabled_pagination" )
     405                .appendTo( ".playbuzz_item_pagination" );
     406        }
     407
     408        // Add pages
     409        for (page = start_page; page <= end_page; ++page) {
     410            current_page_class = ((page == current_page) ? " playbuzz_current" : "");
     411
     412            (jQuery)( "<a></a>" )
     413                .attr( "onclick", type + "(" + page + ")" )
     414                .addClass( "enabled_pagination" )
     415                .addClass( current_page_class )
     416                .appendTo( ".playbuzz_item_pagination" )
     417                .text( page );
     418        }
     419
     420        // Add next page link
     421        if (current_page == total_pages) {
     422            (jQuery)( "<a></a>" )
     423                .addClass( "playbuzz_next disabled_pagination" )
     424                .appendTo( ".playbuzz_item_pagination" );
     425        } else {
     426            (jQuery)( "<a></a>" )
     427                .attr( "onclick", type + "(" + (current_page + 1) + ")" )
     428                .addClass( "playbuzz_next enabled_pagination" )
     429                .appendTo( ".playbuzz_item_pagination" );
     430        }
     431
     432    }
     433
     434    // Playbuzz show popup screen
     435    function playbuzz_show_screen(on_select_item) {
     436
     437        var is_content_tab = (((jQuery)( "#playbuzz_popup_tab_content" ).hasClass( "playbuzz_active_tab" )) ? true : false),
     438            is_search      = (((jQuery)( "#playbuzz_search" ).val().trim() != '') ? true : false);
     439
     440        if (is_search) {
     441            if (is_content_tab) {
     442                playbuzz_general_search( 1, on_select_item );
     443            } else {
     444                playbuzz_user_search( 1, on_select_item );
     445            }
     446        } else {
     447            if (is_content_tab) {
     448                playbuzz_featured_items( 1, on_select_item );
     449            } else {
     450                playbuzz_my_items( 1, on_select_item );
     451            }
     452        }
     453
     454    }
     455
     456    // Playbuzz featured items screen
     457    function playbuzz_featured_items(current_page, on_select_item) {
     458
     459        var apiBaseUrl = document.location.protocol + "//rest-api-v2.playbuzz.com/v2/items";
     460
     461        // Set variables
     462        var results_layout = "grid",
     463            results_title  = translation.featured_items,
     464            items_per_page = 30;
     465
     466        // Update tabs
     467        (jQuery)( "#playbuzz_popup_tab_content" ).addClass( "playbuzz_active_tab" );
     468        (jQuery)( "#playbuzz_popup_tab_myitems" ).removeClass( "playbuzz_active_tab" );
     469
     470        // Load items using the Playbuzz API
     471        (jQuery).ajax(
     472            {
     473                url: apiBaseUrl,
     474                type: "get",
     475                dataType: "json",
     476                data: {
     477                    internalTags: "EditorsPick_Featured",
     478                    format: (jQuery)( "#playbuzz_search_type" ).val(),
     479                    sort: (jQuery)( "#playbuzz_search_sort" ).val(),
     480                    size: items_per_page,
     481                    from: (current_page * items_per_page) - items_per_page
     482                },
     483                error: function (data) {
     484
     485                    // Server Error
     486                    playbuzz_popup_message( results_title, translation.server_error, translation.try_in_a_few_minutes );
     487                    console.error( "Couldn't get data: ", data );
     488
     489                },
     490                success: function (data) {
     491
     492                    // Set variables
     493                    var total_items = data.payload.totalItems,
     494                    total_pages     = ((total_items >= items_per_page) ? Math.ceil( total_items / items_per_page ) : 1),
     495                    results_pages   = ((current_page > 1) ? " <span class='playbuzz_search_title_pagination'>(" + translation.page + " " + current_page + " / " + total_pages + ")" : "");
     496
     497                    // Data output
     498                    if (total_items > 0) {
     499                        // Show Results
     500                        playbuzz_search_results( results_layout, data.payload.items, results_title, results_pages, on_select_item );
     501                        // Pagination
     502                        if (total_items > items_per_page) {
     503                            playbuzz_popup_pagination( total_pages, current_page, 'playbuzz_featured_items' );
     504                        }
     505                    } else {
     506                        // No Search Results
     507                        playbuzz_popup_message( results_title, translation.no_results_found, translation.try_different_search );
     508                    }
     509
     510                }
     511
     512            }
     513        );
     514
     515    }
     516
     517    window.playbuzz_featured_items = playbuzz_featured_items;
     518
     519    function is_playbuzz_url(url) {
     520        var valid = ["http://www.playbuzz.com/", "https://www.playbuzz.com", "www.playbuzz.com"];
     521        for (var i = 0; i < valid.length; i++) {
     522            if (url.indexOf( valid[i] ) === 0) {
     523                return true;
     524            }
     525        }
     526
     527        return false;
     528    }
     529
     530    // Playbuzz general search screen
     531    function playbuzz_general_search(current_page, on_select_item) {
     532        var search_param = (jQuery)( "#playbuzz_search" ).val();
     533
     534        // Set variables
     535        var results_layout = "list",
     536
     537            string = (jQuery)( "#playbuzz_search" ).val();
     538        if (string.length > 25) {
     539            string = string.substring( 0, 16 ) + "...";
     540        }
     541
     542        results_title      = (translation.results_for + " '" + string + "'"),
     543            items_per_page = 30;
     544
     545        // Update tabs
     546        (jQuery)( "#playbuzz_popup_tab_content" ).addClass( "playbuzz_active_tab" );
     547        (jQuery)( "#playbuzz_popup_tab_myitems" ).removeClass( "playbuzz_active_tab" );
     548
     549        var dataObject;
     550        if (is_playbuzz_url( search_param )) {
     551            dataObject = {
     552                playbuzzUrl: search_param
     553            };
     554        } else {
     555            dataObject = {
     556                q: search_param,
     557                format: (jQuery)( "#playbuzz_search_type" ).val(),
     558                sort: (jQuery)( "#playbuzz_search_sort" ).val(),
     559                size: items_per_page,
     560                from: (current_page * items_per_page) - items_per_page
     561            };
     562        }
     563
     564        // Load items using the Playbuzz API
     565        (jQuery).ajax(
     566            {
     567                url: apiBaseUrl,
     568                type: "get",
     569                dataType: "json",
     570                data: dataObject,
     571                error: function (data) {
     572
     573                    // Server Error
     574                    playbuzz_popup_message( results_title, translation.server_error, translation.try_in_a_few_minutes );
     575                    console.error( "Couldn't get data: ", data );
     576
     577                },
     578                success: function (data) {
     579
     580                    // Set variables
     581                    var total_items = data.payload.totalItems,
     582                    total_pages     = ((total_items >= items_per_page) ? Math.ceil( total_items / items_per_page ) : 1),
     583                    results_pages   = ((current_page > 1) ? " <span class='playbuzz_search_title_pagination'>(" + translation.page + " " + current_page + " / " + total_pages + ")" : "");
     584
     585                    // Data output
     586                    if (total_items > 0) {
     587                        // Show Results
     588                        playbuzz_search_results( results_layout, data.payload.items, results_title, results_pages, on_select_item );
     589                        // Pagination
     590                        if (total_items > items_per_page) {
     591                            playbuzz_popup_pagination( total_pages, current_page, 'playbuzz_general_search' );
     592                        }
     593                    } else {
     594                        // No Search Results
     595                        playbuzz_popup_message( results_title, translation.no_results_found, translation.try_different_search );
     596                    }
     597
     598                }
     599
     600            }
     601        );
     602
     603    }
     604
     605    window.playbuzz_general_search = playbuzz_general_search;
     606
     607    // Playbuzz my items screen
     608    function playbuzz_my_items(current_page, on_select_item) {
     609
     610        // exit if username is not set
     611        if ( ! site_settings.pb_user || 0 === site_settings.pb_user) {
     612            playbuzz_no_user();
     613            return;
     614        }
     615
     616        // Set variables
     617        var results_layout = "list",
     618            results_title  = ("<span class='playbuzz_search_title_user_img'>" + site_settings.pb_user + "</span>"),
     619            items_per_page = 30;
     620
     621        // Update tabs
     622        (jQuery)( "#playbuzz_popup_tab_content" ).removeClass( "playbuzz_active_tab" );
     623        (jQuery)( "#playbuzz_popup_tab_myitems" ).addClass( "playbuzz_active_tab" );
     624
     625        // Load items using the Playbuzz API
     626        (jQuery).ajax(
     627            {
     628                url: apiBaseUrl,
     629                type: "get",
     630                dataType: "json",
     631                data: {
     632                    format: (jQuery)( "#playbuzz_search_type" ).val(),
     633                    sort: (jQuery)( "#playbuzz_search_sort" ).val(),
     634                    size: items_per_page,
     635                    from: (current_page * items_per_page) - items_per_page,
     636                    channelAlias: site_settings.pb_user,
     637                    moderation: "none"
     638                },
     639                error: function (data) {
     640
     641                    // Server Error
     642                    playbuzz_popup_message( results_title, translation.server_error, translation.try_in_a_few_minutes );
     643                    console.error( "Couldn't get data: ", data );
     644
     645                },
     646                success: function (data) {
     647
     648                    // Set variables
     649                    var total_items = data.payload.totalItems,
     650                    total_pages     = ((total_items >= items_per_page) ? Math.ceil( total_items / items_per_page ) : 1),
     651                    results_pages   = (" <span class='playbuzz_search_title_pagination'>(" + total_items + " " + translation.items + ")"),
     652                    change_user     = ("<a href='options-general.php?page=playbuzz&tab=embed' target='_blank' class='playbuzz_change_username_link'>" + translation.change_user + "</a>");
     653                    create_button   = ("<div class='playbuzz_create_button'><a href='https://www.playbuzz.com/create' target='_blank'>" + translation.create_your_own + "</a></div>")
     654
     655                    // Data output
     656                    if (data.payload.currentItemCount > 0) {
     657
     658                        // Show Results
     659                        playbuzz_search_results( results_layout, data.payload.items, results_title, results_pages + change_user, on_select_item );
     660                        // Pagination
     661                        if (total_items > items_per_page) {
     662                            playbuzz_popup_pagination( total_pages, current_page, 'playbuzz_my_items' );
     663                        }
     664                    } else {
     665                        // No Search Results
     666                        playbuzz_popup_message( results_title + results_pages + change_user, translation.you_dont_have_any_items_yet, translation.go_to_playbuzz_to_create_your_own_playful_content + create_button );
     667                    }
     668
     669                }
     670
     671            }
     672        );
     673
     674    }
     675
     676    window.playbuzz_my_items = playbuzz_my_items;
     677
     678    // Playbuzz user search screen
     679    function playbuzz_user_search(current_page, on_select_item) {
     680        // exit if username is not set
     681        if ( ! site_settings.pb_user || 0 === site_settings.pb_user) {
     682            playbuzz_no_user();
     683            return;
     684        }
     685
     686        var search_param = (jQuery)( "#playbuzz_search" ).val();
     687
     688        if (search_param.length > 25) {
     689            search_param = search_param.substring( 0, 16 ) + "...";
     690        }
     691
     692        // Set variables
     693        var results_layout = "list",
     694            results_title  = (translation.results_for + " '" + search_param + "' "),
     695            items_per_page = 30;
     696
     697        var dataObject;
     698        if (is_playbuzz_url( search_param )) {
     699            dataObject = {
     700                playbuzzUrl: search_param
     701            };
     702        } else {
     703            dataObject = {
     704                q: search_param,
     705                format: (jQuery)( "#playbuzz_search_type" ).val(),
     706                sort: (jQuery)( "#playbuzz_search_sort" ).val(),
     707                size: items_per_page,
     708                from: (current_page * items_per_page) - items_per_page,
     709                channelAlias: site_settings.pb_user,
     710                moderation: "none"
     711            };
     712        }
     713
     714        // Update tabs
     715        (jQuery)( "#playbuzz_popup_tab_content" ).removeClass( "playbuzz_active_tab" );
     716        (jQuery)( "#playbuzz_popup_tab_myitems" ).addClass( "playbuzz_active_tab" );
     717
     718        // Load items using the Playbuzz API
     719        (jQuery).ajax(
     720            {
     721                url: apiBaseUrl,
     722                type: "get",
     723                dataType: "json",
     724                data: dataObject,
     725                error: function (data) {
     726
     727                    // Server Error
     728                    playbuzz_popup_message( results_title, translation.server_error, translation.try_in_a_few_minutes );
     729                    console.error( "Couldn't get data: ", data );
     730
     731                },
     732                success: function (data) {
     733
     734                    // Set variables
     735                    var total_items = data.payload.totalItems,
     736                    total_pages     = ((total_items >= items_per_page) ? Math.ceil( total_items / items_per_page ) : 1),
     737                    results_pages   = ((current_page > 1) ? " <span class='playbuzz_search_title_pagination'>(" + translation.page + " " + current_page + " / " + total_pages + ")" : "");
     738
     739                    // Data output
     740                    if (data.payload.items.length > 0) {
     741                        // Show Results
     742                        playbuzz_search_results( results_layout, data.payload.items, results_title, results_pages, on_select_item );
     743                        // Pagination
     744                        if (total_items > items_per_page) {
     745                            playbuzz_popup_pagination( total_pages, current_page, 'playbuzz_user_search' );
     746                        }
     747                    } else {
     748                        // No Search Results
     749                        playbuzz_popup_message( results_title, translation.no_results_found, translation.try_different_search );
     750                    }
     751
     752                }
     753
     754            }
     755        );
     756
     757    }
     758
     759    window.playbuzz_user_search = playbuzz_user_search;
    733760};
  • playbuzz/tags/1.0.6/js/pb-settings.js

    r1831521 r1866507  
    1 
    2 
    3 
    41//PbSettings will collect settings passing via url, as  query parameters and store
    52//them to local storage / session storage under STORAGE_NAME key.
     
    129function PbSettings(storage, jQuery) {
    1310
    14     this.storage = storage;
    15     this.$ = jQuery;
    16     this.STORAGE_NAME = 'PLAYBUZZ';
     11    this.storage      = storage;
     12    this.$            = jQuery;
     13    this.STORAGE_NAME = 'PLAYBUZZ';
    1714
    18     //collect settings from url
    19     this.settingsFromUrl = this.collectUrlSettings();
     15    //collect settings from url
     16    this.settingsFromUrl = this.collectUrlSettings();
    2017
    21     //collect settings from storage
    22     this.settingsFromStorage = this.getFromStorage();
     18    //collect settings from storage
     19    this.settingsFromStorage = this.getFromStorage();
    2320
    24     //merge between settings sources.
    25     this.settings = this.collectSettings(this.settingsFromUrl, this.settingsFromStorage);
     21    //merge between settings sources.
     22    this.settings = this.collectSettings( this.settingsFromUrl, this.settingsFromStorage );
    2623
    27     //save settings
    28     this.putToStorage(this.settings);
     24    //save settings
     25    this.putToStorage( this.settings );
    2926
    30 
    31     return this.getFromStorage();
     27    return this.getFromStorage();
    3228}
    3329/**
     
    3834PbSettings.prototype.collectSettings = function (settingsFromUrl, settingsFromStorage) {
    3935
    40     return this.$.extend(settingsFromStorage, settingsFromUrl);
     36    return this.$.extend( settingsFromStorage, settingsFromUrl );
    4137
    4238};
     
    4844PbSettings.prototype.collectUrlSettings = function () {
    4945
    50     return this.$.queryParameters();
     46    return this.$.queryParameters();
    5147
    5248};
     
    5854PbSettings.prototype.getFromStorage = function () {
    5955
    60    var settings = JSON.parse(this.storage.getItem(this.STORAGE_NAME));
     56    var settings = JSON.parse( this.storage.getItem( this.STORAGE_NAME ) );
    6157
    62    return settings;
     58    return settings;
    6359
    6460};
     
    7167PbSettings.prototype.putToStorage = function (settings) {
    7268
    73     var toStore = JSON.stringify(settings);
     69    var toStore = JSON.stringify( settings );
    7470
    75     this.storage.setItem(this.STORAGE_NAME, toStore);
    76 
     71    this.storage.setItem( this.STORAGE_NAME, toStore );
    7772
    7873};
     
    8378 * @returns {*}
    8479 */
    85 PbSettings.prototype.get =  function (key) {
    86     return key ? this.settings[key] : this.settings;
     80PbSettings.prototype.get = function (key) {
     81    return key ? this.settings[key] : this.settings;
    8782};
    8883
    8984
    90 window.pbSettings = new PbSettings(window.sessionStorage, window.jQuery);
     85window.pbSettings = new PbSettings( window.sessionStorage, window.jQuery );
  • playbuzz/tags/1.0.6/js/playbuzz-admin.js

    r1831521 r1866507  
    1 (jQuery)(document).ready(function(){
    2 
    3     // Site Settings - tags_toggle_triger
     1(jQuery)( document ).ready( function(){
     2    //Site Settings - tags_toggle_trigger
    43
    54    (jQuery)( ".tags_toggle_triger" ).change( function() {
    65
    7         if ( (jQuery)(this).prop( "checked" ) ) {
     6        if ( (jQuery)( this ).prop( "checked" ) ) {
    87
    98            (jQuery)( '.tags_toggle' ).show();
     
    3130                data    : (jQuery)( "#playbuzz_feedback_form" ).serialize(),
    3231
    33                 success : function ( data ) {
     32                success : function () {
    3433
    3534                    (jQuery)( ".playbuzz_feedback_message p" ).text( translation.feedback_sent );
     
    3938                },
    4039
    41                 error   : function ( data ) {
     40                error   : function () {
    4241
    4342                    (jQuery)( ".playbuzz_feedback_message p" ).text( translation.feedback_error );
  • playbuzz/tags/1.0.6/js/playbuzz-tinymce.js

    r1831521 r1866507  
    11(function () {
    22
    3     tinymce.PluginManager.add('playbuzz', function (editor, url) {
    4 
    5         var search = new playbuzz_search();
    6 
    7         // tinymce plugin helpers
    8 
    9         var apiBaseUrl = document.location.protocol + "//rest-api-v2.playbuzz.com/v2/items";
    10 
    11         // Playbuzz item popup - create popup structure
    12         function playbuzz_item_popup_structure(settings_to_use, item_url, info, shares, comments, recommend, margin_top, width, height, links, tags, itemId, format) {
    13 
    14             // Popup Components
    15             (jQuery)("<form></form>").attr("id", "playbuzz_item_form").attr("name", "item").appendTo("#playbuzz_popup");
    16             (jQuery)("<div></div>").attr("id", "playbuzz_item_header").appendTo("#playbuzz_item_form");
    17             (jQuery)("<div></div>").attr("id", "playbuzz_item_body").appendTo("#playbuzz_item_form");
    18             (jQuery)("<div></div>").attr("id", "playbuzz_item_update").appendTo("#playbuzz_item_form");
    19 
    20             // Header
    21             (jQuery)("<div></div>").attr("id", "playbuzz_popup_close").appendTo("#playbuzz_item_header").click(function () {
    22                 (jQuery)(".playbuzz_popup_overlay_container").remove();
    23             });
    24             ;
    25             (jQuery)("<p></p>").addClass("playbuzz_item_header_text").appendTo("#playbuzz_item_header").text(translation.playbuzz_item_settings);
    26 
    27             // Footer
    28             (jQuery)("<input>").attr("id", "playbuzz_item_settings_format").attr("type", "hidden").attr("value", format).appendTo("#playbuzz_item_update");
    29             (jQuery)("<input>").attr("id", "playbuzz_item_settings_url").attr("type", "hidden").attr("value", item_url).appendTo("#playbuzz_item_update");
    30             (jQuery)("<input>").attr("id", "playbuzz_item_settings_id").attr("type", "hidden").attr("value", itemId).appendTo("#playbuzz_item_update");
    31             (jQuery)("<input>").attr("id", "playbuzz_item_settings_width").attr("type", "hidden").attr("value", width).appendTo("#playbuzz_item_update");
    32             (jQuery)("<input>").attr("id", "playbuzz_item_settings_height").attr("type", "hidden").attr("value", height).appendTo("#playbuzz_item_update");
    33             (jQuery)("<input>").attr("id", "playbuzz_item_settings_links").attr("type", "hidden").attr("value", links).appendTo("#playbuzz_item_update");
    34             (jQuery)("<input>").attr("id", "playbuzz_item_settings_tags").attr("type", "hidden").attr("value", tags).appendTo("#playbuzz_item_update");
    35             (jQuery)("<div></div>").addClass("playbuzz_item_cancel_button").appendTo("#playbuzz_item_update").text(translation.cancel).click(function () {
    36                 (jQuery)('.playbuzz_popup_overlay_container').remove();
    37             });
    38             (jQuery)("<div></div>").addClass("playbuzz_item_update_button").appendTo("#playbuzz_item_update").text(translation.update_item);
    39 
    40             // Content
    41             (jQuery)("<div></div>").attr("id", "playbuzz_item_preview").appendTo("#playbuzz_item_body");
    42             (jQuery)("<div></div>").attr("id", "playbuzz_item_settings").appendTo("#playbuzz_item_body");
    43             (jQuery)("<p></p>").addClass("playbuzz_item_settings_title").appendTo("#playbuzz_item_settings").text(translation.item_settings).append((jQuery)("<span></span>").text(translation.embedded_item_appearance));
    44             (jQuery)("<div></div>").addClass("playbuzz_item_settings_select").appendTo("#playbuzz_item_settings");
    45             (jQuery)("<input>").attr("id", "playbuzz_item_settings_default").attr("name", "playbuzz_item_settings").attr("type", "radio").attr("value", "default").appendTo(".playbuzz_item_settings_select");
    46             (jQuery)("<label></label>").attr("for", "playbuzz_item_settings_default").appendTo(".playbuzz_item_settings_select").text(translation.use_site_default_settings).append((jQuery)("<a></a>").attr("target", "_blank").attr("href", "options-general.php?page=playbuzz&tab=embed").text(translation.configure_default_settings));
    47             (jQuery)("<br>").appendTo(".playbuzz_item_settings_select");
    48             (jQuery)("<input>").attr("id", "playbuzz_item_settings_custom").attr("name", "playbuzz_item_settings").attr("type", "radio").attr("value", "custom").appendTo(".playbuzz_item_settings_select");
    49             (jQuery)("<label></label>").attr("for", "playbuzz_item_settings_custom").appendTo(".playbuzz_item_settings_select").text(translation.custom);
    50             (jQuery)("<br>").appendTo(".playbuzz_item_settings_select");
    51 
    52             (jQuery)("<div></div>").addClass("settings_half settings_half1").appendTo(".playbuzz_item_settings_select");
    53             (jQuery)("<input>").attr("id", "playbuzz_item_settings_info").attr("type", "checkbox").appendTo(".settings_half1");
    54             (jQuery)("<label></label>").attr("for", "playbuzz_item_settings_info").appendTo(".settings_half1").text(translation.display_item_information);
    55             (jQuery)("<div></div>").addClass("description").appendTo(".settings_half1").text(translation.show_item_thumbnail_name_description_creator);
    56             (jQuery)("<input>").attr("id", "playbuzz_item_settings_shares").attr("type", "checkbox").appendTo(".settings_half1");
    57             (jQuery)("<label></label>").attr("for", "playbuzz_item_settings_shares").appendTo(".settings_half1").text(translation.display_share_buttons);
    58             (jQuery)("<div></div>").addClass("description").appendTo(".settings_half1").text(translation.show_share_buttons_with_links_to_your_site);
    59 
    60             (jQuery)("<div></div>").addClass("settings_half settings_half2").appendTo(".playbuzz_item_settings_select");
    61             (jQuery)("<input>").attr("id", "playbuzz_item_settings_comments").attr("type", "checkbox").appendTo(".settings_half2");
    62             (jQuery)("<label></label>").attr("for", "playbuzz_item_settings_comments").appendTo(".settings_half2").text(translation.display_facebook_comments);
    63             (jQuery)("<div></div>").addClass("description").appendTo(".settings_half2").text(translation.show_facebook_comments_in_your_items);
    64             (jQuery)("<input>").attr("id", "playbuzz_item_settings_margin").attr("type", "checkbox").appendTo(".settings_half2");
    65             (jQuery)("<label></label>").attr("for", "playbuzz_item_settings_margin").appendTo(".settings_half2").text(translation.site_has_fixed_sticky_top_header);
    66             (jQuery)("<div></div>").addClass("playbuzz_item_settings_margin_top_text").appendTo(".settings_half2").text(translation.height + " ");
    67             (jQuery)("<input>").attr("id", "playbuzz_item_settings_margin_top").attr("type", "input").attr("value", margin_top).appendTo(".playbuzz_item_settings_margin_top_text").text(translation.px);
    68             (jQuery)("<div></div>").addClass("description").appendTo(".settings_half2").text(translation.use_this_if_your_website_has_top_header_thats_always_visible_even_while_scrolling_down);
    69 
    70             // Select Settings
    71             if (settings_to_use == "default") {
    72                 (jQuery)("#playbuzz_item_settings_default").prop('checked', true);
    73             }
    74 
    75             if (settings_to_use == "custom") {
    76                 (jQuery)("#playbuzz_item_settings_custom").prop('checked', true);
    77             }
    78 
    79             if ((typeof info != 'undefined') && (info.length) && ((info == true) || (info > 0) || (info.toLowerCase() == "true") || (info.toLowerCase() == "on") || (info == "1"))) {
    80                 (jQuery)("#playbuzz_item_settings_info").prop('checked', true);
    81             }
    82 
    83             if ((typeof shares != 'undefined') && (shares.length) && ((shares == true) || (shares > 0) || (shares.toLowerCase() == "true") || (shares.toLowerCase() == "on") || (shares == "1"))) {
    84                 (jQuery)("#playbuzz_item_settings_shares").prop('checked', true);
    85             }
    86 
    87             if ((typeof recommend != 'undefined') && (recommend.length) && ((recommend == true) || (recommend > 0) || (recommend.toLowerCase() == "true") || (recommend.toLowerCase() == "on") || (recommend == "1"))) {
    88                 (jQuery)("#playbuzz_item_settings_recommend").prop('checked', true);
    89             }
    90 
    91             if ((typeof comments != 'undefined') && (comments.length) && ((comments == true) || (comments > 0) || (comments.toLowerCase() == "true") || (comments.toLowerCase() == "on") || (comments == "1"))) {
    92                 (jQuery)("#playbuzz_item_settings_comments").prop('checked', true);
    93             }
    94 
    95             if ((typeof margin_top != 'undefined') && (margin_top.length) && ((margin_top == true) || (margin_top > 0) || (margin_top.toLowerCase() == "true") || (margin_top.toLowerCase() == "on") || (margin_top == "1"))) {
    96                 (jQuery)("#playbuzz_item_settings_margin_top").prop('checked', true);
    97             }
    98 
    99         }
    100 
    101 
    102         // Get attribute from pattern
    103         function get_attr(pattern, attr) {
    104 
    105             n = new RegExp(attr + '=\"([^\"]+)\"', 'g').exec(pattern);
    106             return n ? window.decodeURIComponent(n[1]) : '';
    107 
    108         };
    109 
    110         // Return formatted date
    111         function item_date(published_at) {
    112 
    113             var months = [
    114                     translation.jan,
    115                     translation.feb,
    116                     translation.mar,
    117                     translation.apr,
    118                     translation.may,
    119                     translation.jun,
    120                     translation.jul,
    121                     translation.aug,
    122                     translation.sep,
    123                     translation.oct,
    124                     translation.nov,
    125                     translation.dec
    126                 ],
    127                 publish_date = new Date(published_at),
    128                 published = months[publish_date.getMonth()] + ' ' + publish_date.getDate() + ', ' + publish_date.getFullYear();
    129 
    130             return published;
    131 
    132         }
    133 
    134         // Return item type
    135         function playbuzz_item_type(type) {
    136 
    137             switch (type && type.toLowerCase()) {
    138                 case "personality-quiz"    :
    139                 case "testyourself"    :
    140                     name = translation.personality_quiz;
    141                     break;
    142                 case "story"            :
    143                     name = translation.story;
    144                     break;
    145                 case "snap-article"     :
    146                     name = translation.story;
    147                     break;
    148                 case "list"            :
    149                     name = translation.list;
    150                     break;
    151                 case "trivia"            :
    152                 case "multiplechoice"    :
    153                     name = translation.trivia;
    154                     break;
    155                 case "poll"                :
    156                 case "playbuzzpoll"    :
    157                     name = translation.poll;
    158                     break;
    159                 case "ranked-list"      :
    160                 case "ranklist"        :
    161                     name = translation.ranked_list;
    162                     break;
    163                 case "gallery-quiz"        :
    164                 case "gallery"        :
    165                     name = translation.gallery_quiz;
    166                     break;
    167                 case "flip-cards"        :
    168                 case "reveal"        :
    169                     name = translation.flip_cards;
    170                     break;
    171                 case "swiper"            :
    172                     name = translation.swiper;
    173                     break;
    174                 case "countdown"        :
    175                     name = translation.countdown;
    176                     break;
    177                 case "video-snaps"        :
    178                 case "videosnaps"        :
    179                     name = translation.video_snaps;
    180                     break;
    181                 case "convo"            :
    182                     name = translation.convo;
    183                     break;
    184                 default                :
    185                     name = "";
    186                     break;
    187             }
    188             return name;
    189 
    190         }
    191 
    192         // Return random generated id for connecting between short-codes and visual placeholders in wordpress
    193         function generate_id() {
    194             return Math.round(Math.random() * 1000000);
    195         }
    196 
    197         function set_playbuzz_item_shortcode(id, short_code) {
    198             var content = editor.getContent();
    199             var shortcodeRegex = new RegExp('\\[([^\\[\\]]*)wp\\-pb\\-id="' + id + '"[^\\]]*\\]');
    200             var newContent = content.replace(shortcodeRegex, short_code);
    201             editor.setContent(newContent);
    202         }
    203 
    204         function delete_playbuzz_item_shortcode(id) {
    205             set_playbuzz_item_shortcode(id, '');
    206         }
    207 
    208         // any part of the regex is important because tinymce can change the content of any div
    209         var playbuzz_place_holder_pattern = /<div class="wp_playbuzz_container"(.*?)"wp_playbuzz_container_end">(.*?)<\/div>/g;
    210 
    211         /**
    212          *
    213          *  TINYMCE PLUGIN
    214          *
    215          */
    216 
    217         // Add playbuzz search popup
    218         editor.addCommand('search_playbuzz_items', function (ui, v) {
    219 
    220                 search.display(playbuzz_generate_shortcode);
    221 
    222                 function playbuzz_generate_shortcode(itemId) {
    223                     if (tinyMCE && tinyMCE.activeEditor) {
    224                         tinymce.activeEditor.execCommand('mceInsertContent', false, '[playbuzz-item item="' + itemId + '" wp-pb-id="' + generate_id() + '"]<br>');
    225                     }
    226                 }
    227             }
    228         );
    229 
    230         // Add playbuzz button to tinyMCE visual editor
    231         editor.addButton('playbuzz', {
    232             icon: 'playbuzz',
    233             tooltip: 'Playbuzz',
    234             onclick: function () {
    235                 editor.execCommand('search_playbuzz_items');
    236             }
    237         });
    238 
    239         // Replace the shortcode with an item info box
    240         editor.on('BeforeSetContent', function (event) {
    241 
    242             var pbShortcode = /\[([^\[\]]*)playbuzz-(item|post|game)([^\]]*)\]/g;
    243             event.content = event.content.replace(pbShortcode, function (match) {
    244                 return match.indexOf('wp-pb-id') >= 0 ? match : match.replace(']', ' wp-pb-id="' + generate_id() + '"]')
    245             });
    246 
    247             event.content = event.content.replace(/\[playbuzz-item([^\]]*)\]/g, function (all, attr, con) {
    248 
    249                 // Encode all the shortcode attributes, to be stored in <div data-playbuzz-attr="...">
    250                 var encodedShortcodeAttributes = window.encodeURIComponent(attr);
    251 
    252                 // Split shortcode attributes
    253                 var splitedAttr = attr.split(" ");
    254 
    255                 // Extract itemPath from itemUrl -  "http://playbuzz.com/{creatorName}/{gameName}
    256                 var itemId = get_attr(decodeURIComponent(encodedShortcodeAttributes), 'item'),
    257                     itemUrl = get_attr(decodeURIComponent(encodedShortcodeAttributes), 'url'),
    258                     itemPath = itemUrl.split("playbuzz.com/").pop(),
    259                     itemPathArray = itemPath.split("/"),
    260                     creatorName = itemPathArray[0],
    261                     gameName = itemPathArray[1];
    262 
    263                 var data = {
    264                     size: 1,
    265                     moderation: "none"
    266                 };
    267 
    268                 if (itemUrl) {
    269                     data.alias = creatorName + "/" + gameName;
    270                 } else {
    271                     data.id = itemId;
    272                 }
    273 
    274                 // Set random image id
    275                 var id = get_attr(decodeURIComponent(encodedShortcodeAttributes), 'wp-pb-id');
    276 
    277                 // Get Item info
    278                 (jQuery).ajax({
    279                     url: apiBaseUrl,
    280                     type: "get",
    281                     dataType: "json",
    282                     data: data,
    283                     success: function (data) {
    284 
    285                         // Data output
    286                         if (data.payload.totalItems > 0) {
    287 
    288                             var item = data.payload.items[0];
    289 
    290                             // Set item image
    291                             (jQuery)(tinyMCE.activeEditor.dom.doc.body)
    292                                 .find("#playbuzz_placeholder_" + id)
    293                                 .attr("src", item.imageLarge);
    294 
    295                             // Set item info
    296                             (jQuery)(tinyMCE.activeEditor.dom.doc.body)
    297                                 .find("#playbuzz_info_" + id)
    298                                 .empty()
    299                                 .append(
    300                                     // Title
    301                                     (jQuery)("<p></p>")
    302                                         .addClass("wp_playbuzz_title")
    303                                         .text(item.title)
    304                                 )
    305                                 .append(
    306                                     // Meta
    307                                     (jQuery)("<p></p>")
    308                                         .addClass("wp_playbuzz_meta")
    309                                         .text(translation.created_by + " ").append(
    310                                         (jQuery)("<span></span>")
    311                                             .addClass("wp_playbuzz_author")
    312                                             .text(item.channelName)
    313                                     )
    314                                         .append(" " + translation.on + " " + item_date(item.publishDate))
    315                                 );
    316 
    317                         } else {
    318 
    319                             // Set playbuzz logo
    320                             (jQuery)(tinyMCE.activeEditor.dom.doc.body)
    321                                 .find("#playbuzz_placeholder_" + id)
    322                                 .attr("src", url + '/../img/playbuzz-placeholder.png');
    323 
    324                             // Set "item not found" text
    325                             (jQuery)(tinyMCE.activeEditor.dom.doc.body)
    326                                 .find("#playbuzz_info_" + id)
    327                                 .empty()
    328                                 .append(
    329                                     // Title
    330                                     (jQuery)("<p></p>")
    331                                         .addClass("wp_playbuzz_title")
    332                                         .text(translation.item_doesnt_exist)
    333                                 )
    334                                 .append(
    335                                     // Meta
    336                                     (jQuery)("<p></p>")
    337                                         .addClass("wp_playbuzz_meta")
    338                                         .text(translation.check_shortcode_url)
    339                                 );
    340 
    341                         }
    342 
    343                     }
    344 
    345                 });
    346 
    347                 // Shortcode replacement
    348 
    349                 var container = (jQuery)('<div></div>');
    350                 var playbuzz_info = (jQuery)('<div class="wp_playbuzz_info"></div>').attr('id', "playbuzz_info_" + id);
    351                 var playbuzz_image = (jQuery)('<div class="wp_playbuzz_image"></div>').attr('id', "playbuzz_image_" + id);
    352                 var playbuzz_placeholder = (jQuery)('<img class="mceItem wp_playbuzz_placeholder" data-mce-resize="false" data-mce-placeholder="1" />')
    353                     .attr('id', "playbuzz_placeholder_" + id)
    354                     .attr('src', url + "/../img/playbuzz-placeholder.png");
    355                 playbuzz_image.append(playbuzz_placeholder);
    356 
    357                 var playbuzz_embed = (jQuery)('<div class="wp_playbuzz_embed"></div>')
    358                     .attr('id', "playbuzz_embed_" + id)
    359                     .text(translation.your_item_will_be_embedded_here);
    360 
    361                 var playbuzz_buttons = (jQuery)('<div class="wp_playbuzz_buttons"></div>')
    362                     .attr('id', "playbuzz_overlay_" + id)
    363                     .attr('data-playbuzz-attr', encodedShortcodeAttributes);
    364 
    365                 var playbuzz_delete = (jQuery)('<div class="wp_playbuzz_delete"></div>').attr('id', "playbuzz_overlay_close_" + id);
    366                 var playbuzz_edit = (jQuery)('<div class="wp_playbuzz_edit"></div>')
    367                     .attr('id', "playbuzz_overlay_edit_" + id)
    368                     .attr('data-playbuzz-attr', encodedShortcodeAttributes);
    369 
    370                 container
    371                     .append(playbuzz_info)
    372                     .append(playbuzz_image)
    373                     .append(playbuzz_embed)
    374                     .append(playbuzz_buttons)
    375                     .append(playbuzz_delete)
    376                     .append(playbuzz_edit);
    377 
    378                 return '<div class="wp_playbuzz_container" data-wp-pb-id="' + id + '" contenteditable="false">'
    379                     + container.html() +
    380                     '</div>' +
    381                     '<div class="wp_playbuzz_container_end"></div>'; // for the regex in editor on GetContent
    382             });
    383 
    384         });
    385 
    386         // Replace the item info box with the shortcode
    387         editor.on('GetContent', function (event) {
    388 
    389 
    390             var new_content = event.content.replace(playbuzz_place_holder_pattern, function (match, tag) {
    391 
    392                 // Extract shortcode attributes from <div data-playbuzz-attr="...">
    393                 var data = get_attr(tag, 'data-playbuzz-attr');
    394 
    395                 // Create the shortcode
    396                 if (data) {
    397                     return '<p>[playbuzz-item' + data + ']</p>';
    398                 }
    399 
    400                 return match;
    401             });
    402 
    403             event.content = new_content;
    404         });
    405 
    406         // Item edit popup
    407         editor.on('click', function (e) {
    408 
    409             var $placeholder = $(e.target);
    410             // Delete item
    411             if ($placeholder.hasClass('wp_playbuzz_delete')) {
    412                 var $item = (jQuery)($placeholder.closest('.wp_playbuzz_container'))[0];
    413                 var id = $item ? (jQuery)($item).attr('data-wp-pb-id') : 'none';
    414                 delete_playbuzz_item_shortcode(id);
    415                 (jQuery)('.playbuzz_popup_overlay_container').remove();
    416             }
    417 
    418             // Edit item
    419             if ($placeholder.hasClass('wp_playbuzz_buttons') || $placeholder.hasClass('wp_playbuzz_edit')) {
    420                 // Extract shortcode attributes stored in <div data-playbuzz-attr="...">
    421                 var attr = $placeholder.attr('data-playbuzz-attr');
    422                 var $item = (jQuery)($placeholder.closest('.wp_playbuzz_container'))[0];
    423                 var id = $item ? (jQuery)($item).attr('data-wp-pb-id') : 'none';
    424 
    425                 attr = window.decodeURIComponent(attr);
    426 
    427                 // Set values
    428                 var item_url = get_attr(attr, 'url'),
    429                     itemId = get_attr(attr, 'item'),
    430                     info = get_attr(attr, 'info'),
    431                     shares = get_attr(attr, 'shares'),
    432                     comments = get_attr(attr, 'comments'),
    433                     recommend = get_attr(attr, 'recommend'),
    434                     margin_top = get_attr(attr, 'margin-top'),
    435                     width = get_attr(attr, 'width'),
    436                     height = get_attr(attr, 'height'),
    437                     links = get_attr(attr, 'links'),
    438                     tags = get_attr(attr, 'tags'),
    439                     format = get_attr(attr, 'format'),
    440                     itemPath = item_url.split('playbuzz.com/').pop(),
    441                     itemPathArray = itemPath.split("/"),
    442                     creatorName = itemPathArray[0],
    443                     gameName = itemPathArray[1];
    444 
    445                 var data = {
    446                     size: 1,
    447                     moderation: "none"
    448                 };
    449 
    450                 if (item_url) {
    451                     data.alias = creatorName + "/" + gameName;
    452                 } else {
    453                     data.id = itemId;
    454                 }
    455 
    456                 // Which settings to use ? site default or custom item settings
    457                 var settings_to_use = ((info.length > 0) || (shares.length > 0) || (comments.length > 0) || (recommend.length > 0) || (margin_top.length > 0) || (!isNaN(margin_top) && margin_top.trim() != '')) ? 'custom' : 'default';
    458 
    459                 // Open Playbuzz Popup
    460                 search.playbuzz_popup();
    461 
    462                 // Create item popup structure
    463                 playbuzz_item_popup_structure(settings_to_use, item_url, info, shares, comments, recommend, margin_top, width, height, links, tags, itemId, format);
    464 
    465                 // Item Preview
    466                 (jQuery).ajax({
    467                     url: apiBaseUrl,
    468                     type: "get",
    469                     dataType: "json",
    470                     data: data,
    471                     error: function (data) {
    472 
    473                         // Clear preview
    474                         (jQuery)("#playbuzz_item_preview").empty();
    475                         console.error("Couldn't get data: ", data);
    476 
    477                     },
    478                     success: function (data) {
    479 
    480                         if (data.payload.items.length > 0) {
    481 
    482                             var item = data.payload.items[0];
    483 
    484                             // Create preview
    485                             (jQuery)("#playbuzz_item_preview").empty().append(
    486                                 (jQuery)("<table></table>").append(
    487                                     (jQuery)("<tbody></tbody>").append(
    488                                         (jQuery)("<tr></tr>").attr("valign", "top").append(
    489                                             (jQuery)("<td></td>").addClass("playbuzz_item_thumb")
    490                                         ).append(
    491                                             (jQuery)("<td></td>").addClass("playbuzz_item_info")
    492                                         )
    493                                     )
    494                                 )
    495                             );
    496 
    497                             // Add thumb
    498                             (jQuery)("<p></p>").addClass("playbuzz_item_thumb").appendTo("td.playbuzz_item_thumb");
    499                             (jQuery)("<img>").attr("src", item.imageLarge).appendTo("p.playbuzz_item_thumb");
    500 
    501                             // Add info
    502                             (jQuery)("<p></p>").addClass("playbuzz_item_title").appendTo("td.playbuzz_item_info").text(item.title);
    503                             (jQuery)("<p></p>").addClass("playbuzz_item_meta").appendTo("td.playbuzz_item_info").text(translation.created_by + " ").append(
    504                                 (jQuery)("<span></span>").html("<a target='_blank' href='http://www.playbuzz.com/" + item.channelAlias + "'>" + item.channelName + "</a> ")
    505                             ).append(translation.on + " " + item_date(item.publishDate));
    506                             (jQuery)("<p></p>").addClass("playbuzz_item_desc").appendTo("td.playbuzz_item_info").text(item.description);
    507                             (jQuery)("<p></p>").addClass("playbuzz_item_view_type_link").appendTo("td.playbuzz_item_info");
    508                             (jQuery)("<span></span>").addClass("playbuzz_item_type").appendTo("p.playbuzz_item_view_type_link").text(playbuzz_item_type(item.format));
    509                             (jQuery)("<span></span>").addClass("playbuzz_item_link").appendTo("p.playbuzz_item_view_type_link");
    510                             (jQuery)("<a></a>").attr("target", "_blank").attr("href", item.playbuzzUrl).appendTo(".playbuzz_item_link").text(translation.preview_item);
    511 
    512                         }
    513 
    514                     }
    515                 });
    516 
    517                 // Set/Change fields visibility
    518                 function settings_visibility() {
    519                     if ((jQuery)("input[type='radio'][name='playbuzz_item_settings']:checked").val() == 'default') {
    520                         (jQuery)(".settings_half").addClass("settings_disabled");
    521                         (jQuery)("#playbuzz_item_settings_info").prop("disabled", true);
    522                         (jQuery)("#playbuzz_item_settings_shares").prop("disabled", true);
    523                         (jQuery)("#playbuzz_item_settings_recommend").prop("disabled", true);
    524                         (jQuery)("#playbuzz_item_settings_comments").prop("disabled", true);
    525                         (jQuery)("#playbuzz_item_settings_margin").prop("disabled", true);
    526                         (jQuery)("#playbuzz_item_settings_margin_top").prop("disabled", true);
    527                     } else {
    528                         (jQuery)(".settings_half").removeClass("settings_disabled");
    529                         (jQuery)("#playbuzz_item_settings_info").prop("disabled", false);
    530                         (jQuery)("#playbuzz_item_settings_shares").prop("disabled", false);
    531                         (jQuery)("#playbuzz_item_settings_recommend").prop("disabled", false);
    532                         (jQuery)("#playbuzz_item_settings_comments").prop("disabled", false);
    533                         (jQuery)("#playbuzz_item_settings_margin").prop("disabled", false);
    534                         if ((jQuery)("#playbuzz_item_settings_margin").prop("checked")) {
    535                             (jQuery)("#playbuzz_item_settings_margin_top").prop("disabled", false);
    536                         } else {
    537                             (jQuery)("#playbuzz_item_settings_margin_top").prop("disabled", true);
    538                         }
    539                     }
    540                 }
    541 
    542                 settings_visibility();
    543                 (jQuery)("input[type='radio'][name='playbuzz_item_settings']:radio").change(function () {
    544                     settings_visibility();
    545                 });
    546 
    547                 // Margin-top
    548                 if (!isNaN(margin_top) && margin_top.trim() != '') {
    549                     (jQuery)("#playbuzz_item_settings_margin").prop('checked', true);
    550                     (jQuery)("#playbuzz_item_settings_margin_top").prop("disabled", false);
    551                 } else {
    552                     (jQuery)("#playbuzz_item_settings_margin_top").prop("disabled", true);
    553                 }
    554 
    555                 // Change margin top
    556                 (jQuery)("#playbuzz_item_settings_margin").change(function () {
    557                     if ((jQuery)(this).is(':checked')) {
    558                         (jQuery)("#playbuzz_item_settings_margin_top").prop("disabled", false);
    559                     } else {
    560                         (jQuery)("#playbuzz_item_settings_margin_top").prop("disabled", true);
    561                     }
    562                 });
    563 
    564                 // Click Update button
    565                 (jQuery)(".playbuzz_item_update_button").click(function (e) {
    566 
    567                     // start shortcode tag
    568                     var shortcode_str = '[playbuzz-item wp-pb-id="' + id + '"';
    569 
    570                     // use site default settings or custom settings
    571                     default_or_custom = (jQuery)("input[type='radio'][name='playbuzz_item_settings']:checked").val();
    572 
    573                     var new_item_id = (jQuery)("#playbuzz_item_settings_id");
    574 
    575                     if (typeof new_item_id != 'undefined' && new_item_id.length && new_item_id.val() != '') {
    576                         shortcode_str += ' item="' + new_item_id.val() + '"';
    577                     } else {
    578                         // add "url"
    579                         new_item_url = (jQuery)("#playbuzz_item_settings_url");
    580                         if (typeof new_item_url != 'undefined' && new_item_url.length && new_item_url.val() != '') {
    581                             shortcode_str += ' url="' + new_item_url.val() + '"';
    582                         }
    583                     }
    584 
    585                     // add "info"
    586                     new_info = (jQuery)("#playbuzz_item_settings_info").prop("checked");
    587                     if (default_or_custom == 'custom') {
    588                         shortcode_str += ' info="' + new_info + '"';
    589                     }
    590 
    591                     // add "shares"
    592                     new_shares = (jQuery)("#playbuzz_item_settings_shares").prop("checked");
    593                     if (default_or_custom == 'custom') {
    594                         shortcode_str += ' shares="' + new_shares + '"';
    595                     }
    596 
    597                     // add "comments"
    598                     new_comments = (jQuery)("#playbuzz_item_settings_comments").prop("checked");
    599                     if (default_or_custom == 'custom') {
    600                         shortcode_str += ' comments="' + new_comments + '"';
    601                     }
    602 
    603                     // add "recommend"
    604                     new_recommend = (jQuery)("#playbuzz_item_settings_recommend").prop("checked");
    605                     if (default_or_custom == 'custom') {
    606                         shortcode_str += ' recommend="' + new_recommend + '"';
    607                     }
    608 
    609                     // add "links"
    610                     new_links = (jQuery)("#playbuzz_item_settings_links");
    611                     if (typeof new_links != 'undefined' && new_links.length && new_links.val() != '') {
    612                         shortcode_str += ' links="' + new_links.val() + '"';
    613                     }
    614 
    615                     // add "tags"
    616                     new_tags = (jQuery)("#playbuzz_item_settings_tags");
    617                     if (typeof new_tags != 'undefined' && new_tags.length && new_tags.val() != '') {
    618                         shortcode_str += ' tags="' + new_tags.val() + '"';
    619                     }
    620 
    621                     // add "width"
    622                     new_width = (jQuery)("#playbuzz_item_settings_width");
    623                     if (typeof new_width != 'undefined' && new_width.length && new_width.val() != '' && new_width.val() != 'auto') {
    624                         shortcode_str += ' width="' + new_width.val() + '"';
    625                     }
    626 
    627                     // add "height"
    628                     new_height = (jQuery)("#playbuzz_item_settings_height");
    629                     if (typeof new_height != 'undefined' && new_height.length && new_height.val() != '' && new_height.val() != 'auto') {
    630                         shortcode_str += ' height="' + new_height.val() + '"';
    631                     }
    632 
    633                     format = (jQuery)("#playbuzz_item_settings_format");
    634                     if (typeof format != 'undefined' && format.length && format.val() != '') {
    635                         shortcode_str += ' format="' + format.val() + '"';
    636                     }
    637 
    638                     // add "margin-top"
    639                     new_margin_top = (jQuery)("#playbuzz_item_settings_margin_top");
    640                     if (default_or_custom == 'custom' && typeof new_margin_top != 'undefined' && new_margin_top.length && new_margin_top.val() != '' && new_margin_top.val() != '0' && new_margin_top.val() != '0px' && (jQuery)("#playbuzz_item_settings_margin").is(':checked')) {
    641                         shortcode_str += ' margin-top="' + new_margin_top.val() + '"';
    642                     }
    643 
    644                     // End shortcode tag
    645                     shortcode_str += ']';
    646 
    647                     // Remove settings modal
    648                     (jQuery)('.playbuzz_popup_overlay_container').remove();
    649 
    650                     // Replace shortcode in the editor
    651                     set_playbuzz_item_shortcode(id, shortcode_str);
    652                 });
    653 
    654             }
    655 
    656         });
    657 
    658     });
     3    tinymce.PluginManager.add(
     4        'playbuzz', function (editor, url) {
     5
     6                    var search = new playbuzz_search();
     7
     8                    // tinymce plugin helpers
     9
     10                    var apiBaseUrl = document.location.protocol + "//rest-api-v2.playbuzz.com/v2/items";
     11
     12                    // Playbuzz item popup - create popup structure
     13            function playbuzz_item_popup_structure(settings_to_use, item_url, info, shares, comments, recommend, margin_top, width, height, links, tags, itemId, format) {
     14
     15                // Popup Components
     16                (jQuery)( "<form></form>" ).attr( "id", "playbuzz_item_form" ).attr( "name", "item" ).appendTo( "#playbuzz_popup" );
     17                (jQuery)( "<div></div>" ).attr( "id", "playbuzz_item_header" ).appendTo( "#playbuzz_item_form" );
     18                (jQuery)( "<div></div>" ).attr( "id", "playbuzz_item_body" ).appendTo( "#playbuzz_item_form" );
     19                (jQuery)( "<div></div>" ).attr( "id", "playbuzz_item_update" ).appendTo( "#playbuzz_item_form" );
     20
     21                // Header
     22                (jQuery)( "<div></div>" ).attr( "id", "playbuzz_popup_close" ).appendTo( "#playbuzz_item_header" ).click(
     23                    function () {
     24                                (jQuery)( ".playbuzz_popup_overlay_container" ).remove();
     25                    }
     26                );
     27                ;
     28                (jQuery)( "<p></p>" ).addClass( "playbuzz_item_header_text" ).appendTo( "#playbuzz_item_header" ).text( translation.playbuzz_item_settings );
     29
     30                // Footer
     31                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_format" ).attr( "type", "hidden" ).attr( "value", format ).appendTo( "#playbuzz_item_update" );
     32                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_url" ).attr( "type", "hidden" ).attr( "value", item_url ).appendTo( "#playbuzz_item_update" );
     33                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_id" ).attr( "type", "hidden" ).attr( "value", itemId ).appendTo( "#playbuzz_item_update" );
     34                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_width" ).attr( "type", "hidden" ).attr( "value", width ).appendTo( "#playbuzz_item_update" );
     35                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_height" ).attr( "type", "hidden" ).attr( "value", height ).appendTo( "#playbuzz_item_update" );
     36                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_links" ).attr( "type", "hidden" ).attr( "value", links ).appendTo( "#playbuzz_item_update" );
     37                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_tags" ).attr( "type", "hidden" ).attr( "value", tags ).appendTo( "#playbuzz_item_update" );
     38                (jQuery)( "<div></div>" ).addClass( "playbuzz_item_cancel_button" ).appendTo( "#playbuzz_item_update" ).text( translation.cancel ).click(
     39                    function () {
     40                                            (jQuery)( '.playbuzz_popup_overlay_container' ).remove();
     41                    }
     42                );
     43                (jQuery)( "<div></div>" ).addClass( "playbuzz_item_update_button" ).appendTo( "#playbuzz_item_update" ).text( translation.update_item );
     44
     45                // Content
     46                (jQuery)( "<div></div>" ).attr( "id", "playbuzz_item_preview" ).appendTo( "#playbuzz_item_body" );
     47                (jQuery)( "<div></div>" ).attr( "id", "playbuzz_item_settings" ).appendTo( "#playbuzz_item_body" );
     48                (jQuery)( "<p></p>" ).addClass( "playbuzz_item_settings_title" ).appendTo( "#playbuzz_item_settings" ).text( translation.item_settings ).append( (jQuery)( "<span></span>" ).text( translation.embedded_item_appearance ) );
     49                (jQuery)( "<div></div>" ).addClass( "playbuzz_item_settings_select" ).appendTo( "#playbuzz_item_settings" );
     50                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_default" ).attr( "name", "playbuzz_item_settings" ).attr( "type", "radio" ).attr( "value", "default" ).appendTo( ".playbuzz_item_settings_select" );
     51                (jQuery)( "<label></label>" ).attr( "for", "playbuzz_item_settings_default" ).appendTo( ".playbuzz_item_settings_select" ).text( translation.use_site_default_settings ).append( (jQuery)( "<a></a>" ).attr( "target", "_blank" ).attr( "href", "options-general.php?page=playbuzz&tab=embed" ).text( translation.configure_default_settings ) );
     52                (jQuery)( "<br>" ).appendTo( ".playbuzz_item_settings_select" );
     53                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_custom" ).attr( "name", "playbuzz_item_settings" ).attr( "type", "radio" ).attr( "value", "custom" ).appendTo( ".playbuzz_item_settings_select" );
     54                (jQuery)( "<label></label>" ).attr( "for", "playbuzz_item_settings_custom" ).appendTo( ".playbuzz_item_settings_select" ).text( translation.custom );
     55                (jQuery)( "<br>" ).appendTo( ".playbuzz_item_settings_select" );
     56
     57                (jQuery)( "<div></div>" ).addClass( "settings_half settings_half1" ).appendTo( ".playbuzz_item_settings_select" );
     58                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_info" ).attr( "type", "checkbox" ).appendTo( ".settings_half1" );
     59                (jQuery)( "<label></label>" ).attr( "for", "playbuzz_item_settings_info" ).appendTo( ".settings_half1" ).text( translation.display_item_information );
     60                (jQuery)( "<div></div>" ).addClass( "description" ).appendTo( ".settings_half1" ).text( translation.show_item_thumbnail_name_description_creator );
     61                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_shares" ).attr( "type", "checkbox" ).appendTo( ".settings_half1" );
     62                (jQuery)( "<label></label>" ).attr( "for", "playbuzz_item_settings_shares" ).appendTo( ".settings_half1" ).text( translation.display_share_buttons );
     63                (jQuery)( "<div></div>" ).addClass( "description" ).appendTo( ".settings_half1" ).text( translation.show_share_buttons_with_links_to_your_site );
     64
     65                (jQuery)( "<div></div>" ).addClass( "settings_half settings_half2" ).appendTo( ".playbuzz_item_settings_select" );
     66                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_comments" ).attr( "type", "checkbox" ).appendTo( ".settings_half2" );
     67                (jQuery)( "<label></label>" ).attr( "for", "playbuzz_item_settings_comments" ).appendTo( ".settings_half2" ).text( translation.display_facebook_comments );
     68                (jQuery)( "<div></div>" ).addClass( "description" ).appendTo( ".settings_half2" ).text( translation.show_facebook_comments_in_your_items );
     69                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_margin" ).attr( "type", "checkbox" ).appendTo( ".settings_half2" );
     70                (jQuery)( "<label></label>" ).attr( "for", "playbuzz_item_settings_margin" ).appendTo( ".settings_half2" ).text( translation.site_has_fixed_sticky_top_header );
     71                (jQuery)( "<div></div>" ).addClass( "playbuzz_item_settings_margin_top_text" ).appendTo( ".settings_half2" ).text( translation.height + " " );
     72                (jQuery)( "<input>" ).attr( "id", "playbuzz_item_settings_margin_top" ).attr( "type", "input" ).attr( "value", margin_top ).appendTo( ".playbuzz_item_settings_margin_top_text" ).text( translation.px );
     73                (jQuery)( "<div></div>" ).addClass( "description" ).appendTo( ".settings_half2" ).text( translation.use_this_if_your_website_has_top_header_thats_always_visible_even_while_scrolling_down );
     74
     75                // Select Settings
     76                if (settings_to_use == "default") {
     77                    (jQuery)( "#playbuzz_item_settings_default" ).prop( 'checked', true );
     78                }
     79
     80                if (settings_to_use == "custom") {
     81                    (jQuery)( "#playbuzz_item_settings_custom" ).prop( 'checked', true );
     82                }
     83
     84                if ((typeof info != 'undefined') && (info.length) && ((info == true) || (info > 0) || (info.toLowerCase() == "true") || (info.toLowerCase() == "on") || (info == "1"))) {
     85                    (jQuery)( "#playbuzz_item_settings_info" ).prop( 'checked', true );
     86                }
     87
     88                if ((typeof shares != 'undefined') && (shares.length) && ((shares == true) || (shares > 0) || (shares.toLowerCase() == "true") || (shares.toLowerCase() == "on") || (shares == "1"))) {
     89                    (jQuery)( "#playbuzz_item_settings_shares" ).prop( 'checked', true );
     90                }
     91
     92                if ((typeof recommend != 'undefined') && (recommend.length) && ((recommend == true) || (recommend > 0) || (recommend.toLowerCase() == "true") || (recommend.toLowerCase() == "on") || (recommend == "1"))) {
     93                    (jQuery)( "#playbuzz_item_settings_recommend" ).prop( 'checked', true );
     94                }
     95
     96                if ((typeof comments != 'undefined') && (comments.length) && ((comments == true) || (comments > 0) || (comments.toLowerCase() == "true") || (comments.toLowerCase() == "on") || (comments == "1"))) {
     97                    (jQuery)( "#playbuzz_item_settings_comments" ).prop( 'checked', true );
     98                }
     99
     100                if ((typeof margin_top != 'undefined') && (margin_top.length) && ((margin_top == true) || (margin_top > 0) || (margin_top.toLowerCase() == "true") || (margin_top.toLowerCase() == "on") || (margin_top == "1"))) {
     101                    (jQuery)( "#playbuzz_item_settings_margin_top" ).prop( 'checked', true );
     102                }
     103
     104            }
     105
     106                    // Get attribute from pattern
     107            function get_attr(pattern, attr) {
     108
     109                n = new RegExp( attr + '=\"([^\"]+)\"', 'g' ).exec( pattern );
     110                return n ? window.decodeURIComponent( n[1] ) : '';
     111
     112            };
     113
     114                    // Return formatted date
     115            function item_date(published_at) {
     116
     117                var months       = [
     118                        translation.jan,
     119                        translation.feb,
     120                        translation.mar,
     121                        translation.apr,
     122                        translation.may,
     123                        translation.jun,
     124                        translation.jul,
     125                        translation.aug,
     126                        translation.sep,
     127                        translation.oct,
     128                        translation.nov,
     129                        translation.dec
     130                    ],
     131                    publish_date = new Date( published_at ),
     132                    published    = months[publish_date.getMonth()] + ' ' + publish_date.getDate() + ', ' + publish_date.getFullYear();
     133
     134                return published;
     135
     136            }
     137
     138                    // Return item type
     139            function playbuzz_item_type(type) {
     140
     141                switch (type && type.toLowerCase()) {
     142                    case "personality-quiz"    :
     143                    case "testyourself"    :
     144                        name = translation.personality_quiz;
     145                        break;
     146                    case "story"            :
     147                        name = translation.story;
     148                        break;
     149                    case "snap-article"     :
     150                        name = translation.story;
     151                        break;
     152                    case "list"            :
     153                        name = translation.list;
     154                        break;
     155                    case "trivia"            :
     156                    case "multiplechoice"    :
     157                        name = translation.trivia;
     158                        break;
     159                    case "poll"                :
     160                    case "playbuzzpoll"    :
     161                        name = translation.poll;
     162                        break;
     163                    case "ranked-list"      :
     164                    case "ranklist"        :
     165                        name = translation.ranked_list;
     166                        break;
     167                    case "gallery-quiz"        :
     168                    case "gallery"        :
     169                        name = translation.gallery_quiz;
     170                        break;
     171                    case "flip-cards"        :
     172                    case "reveal"        :
     173                        name = translation.flip_cards;
     174                        break;
     175                    case "swiper"            :
     176                        name = translation.swiper;
     177                        break;
     178                    case "countdown"        :
     179                        name = translation.countdown;
     180                        break;
     181                    case "video-snaps"        :
     182                    case "videosnaps"        :
     183                        name = translation.video_snaps;
     184                        break;
     185                    case "convo"            :
     186                        name = translation.convo;
     187                        break;
     188                    default                :
     189                        name = "";
     190                        break;
     191                }
     192                return name;
     193
     194            }
     195
     196                    // Return random generated id for connecting between short-codes and visual placeholders in wordpress
     197            function generate_id() {
     198                return Math.round( Math.random() * 1000000 );
     199            }
     200
     201            function set_playbuzz_item_shortcode(id, short_code) {
     202                var content        = editor.getContent();
     203                var shortcodeRegex = new RegExp( '\\[([^\\[\\]]*)wp\\-pb\\-id="' + id + '"[^\\]]*\\]' );
     204                var newContent     = content.replace( shortcodeRegex, short_code );
     205                editor.setContent( newContent );
     206            }
     207
     208            function delete_playbuzz_item_shortcode(id) {
     209                set_playbuzz_item_shortcode( id, '' );
     210            }
     211
     212                    // any part of the regex is important because tinymce can change the content of any div
     213                    var playbuzz_place_holder_pattern = /<div class="wp_playbuzz_container"(.*?)"wp_playbuzz_container_end">(.*?)<\/div>/g;
     214
     215                    /**
     216         *
     217         *  TINYMCE PLUGIN
     218         *
     219         */
     220
     221                    // Add playbuzz search popup
     222                    editor.addCommand(
     223                        'search_playbuzz_items', function (ui, v) {
     224
     225                            search.display( playbuzz_generate_shortcode );
     226
     227                            function playbuzz_generate_shortcode(itemId) {
     228                                if (tinyMCE && tinyMCE.activeEditor) {
     229                                    tinymce.activeEditor.execCommand( 'mceInsertContent', false, '[playbuzz-item item="' + itemId + '" wp-pb-id="' + generate_id() + '"]<br>' );
     230                                }
     231                            }
     232                        }
     233                    );
     234
     235                    // Add playbuzz button to tinyMCE visual editor
     236                    editor.addButton(
     237                        'playbuzz', {
     238                            icon: 'playbuzz',
     239                            tooltip: 'Playbuzz',
     240                            onclick: function () {
     241                                editor.execCommand( 'search_playbuzz_items' );
     242                            }
     243                        }
     244                    );
     245
     246                    // Replace the shortcode with an item info box
     247                    editor.on(
     248                        'BeforeSetContent', function (event) {
     249
     250                            var pbShortcode = /\[([^\[\]]*)playbuzz-(item|post|game)([^\]]*)\]/g;
     251                            event.content   = event.content.replace(
     252                                pbShortcode, function (match) {
     253                                    return match.indexOf( 'wp-pb-id' ) >= 0 ? match : match.replace( ']', ' wp-pb-id="' + generate_id() + '"]' )
     254                                }
     255                            );
     256
     257                            event.content = event.content.replace(
     258                                /\[playbuzz-item([^\]]*)\]/g, function (all, attr, con) {
     259
     260                                    // Encode all the shortcode attributes, to be stored in <div data-playbuzz-attr="...">
     261                                    var encodedShortcodeAttributes = window.encodeURIComponent( attr );
     262
     263                                    // Split shortcode attributes
     264                                    var splitedAttr = attr.split( " " );
     265
     266                                    // Extract itemPath from itemUrl -  "http://playbuzz.com/{creatorName}/{gameName}
     267                                    var itemId    = get_attr( decodeURIComponent( encodedShortcodeAttributes ), 'item' ),
     268                                    itemUrl       = get_attr( decodeURIComponent( encodedShortcodeAttributes ), 'url' ),
     269                                    itemPath      = itemUrl.split( "playbuzz.com/" ).pop(),
     270                                    itemPathArray = itemPath.split( "/" ),
     271                                    creatorName   = itemPathArray[0],
     272                                    gameName      = itemPathArray[1];
     273
     274                                    var data = {
     275                                        size: 1,
     276                                        moderation: "none"
     277                                    };
     278
     279                                    if (itemUrl) {
     280                                        data.alias = creatorName + "/" + gameName;
     281                                    } else {
     282                                        data.id = itemId;
     283                                    }
     284
     285                                        // Set random image id
     286                                        var id = get_attr( decodeURIComponent( encodedShortcodeAttributes ), 'wp-pb-id' );
     287
     288                                        // Get Item info
     289                                        (jQuery).ajax(
     290                                            {
     291                                                url: apiBaseUrl,
     292                                                type: "get",
     293                                                dataType: "json",
     294                                                data: data,
     295                                                success: function (data) {
     296
     297                                                    // Data output
     298                                                    if (data.payload.totalItems > 0) {
     299
     300                                                        var item = data.payload.items[0];
     301
     302                                                        // Set item image
     303                                                        (jQuery)( tinyMCE.activeEditor.dom.doc.body )
     304                                                            .find( "#playbuzz_placeholder_" + id )
     305                                                            .attr( "src", item.imageLarge );
     306
     307                                                        // Set item info
     308                                                        (jQuery)( tinyMCE.activeEditor.dom.doc.body )
     309                                                            .find( "#playbuzz_info_" + id )
     310                                                            .empty()
     311                                                            .append(
     312                                                                // Title
     313                                                                (jQuery)( "<p></p>" )
     314                                                                    .addClass( "wp_playbuzz_title" )
     315                                                                    .text( item.title )
     316                                                            )
     317                                                            .append(
     318                                                                // Meta
     319                                                                (jQuery)( "<p></p>" )
     320                                                                    .addClass( "wp_playbuzz_meta" )
     321                                                                    .text( translation.created_by + " " ).append(
     322                                                                        (jQuery)( "<span></span>" )
     323                                                                        .addClass( "wp_playbuzz_author" )
     324                                                                        .text( item.channelName )
     325                                                                    )
     326                                                                    .append( " " + translation.on + " " + item_date( item.publishDate ) )
     327                                                            );
     328
     329                                                    } else {
     330
     331                                                        // Set playbuzz logo
     332                                                        (jQuery)( tinyMCE.activeEditor.dom.doc.body )
     333                                                            .find( "#playbuzz_placeholder_" + id )
     334                                                            .attr( "src", url + '/../img/playbuzz-placeholder.png' );
     335
     336                                                        // Set "item not found" text
     337                                                        (jQuery)( tinyMCE.activeEditor.dom.doc.body )
     338                                                            .find( "#playbuzz_info_" + id )
     339                                                            .empty()
     340                                                            .append(
     341                                                                // Title
     342                                                                (jQuery)( "<p></p>" )
     343                                                                    .addClass( "wp_playbuzz_title" )
     344                                                                    .text( translation.item_doesnt_exist )
     345                                                            )
     346                                                            .append(
     347                                                                // Meta
     348                                                                (jQuery)( "<p></p>" )
     349                                                                    .addClass( "wp_playbuzz_meta" )
     350                                                                    .text( translation.check_shortcode_url )
     351                                                            );
     352
     353                                                    }
     354
     355                                                }
     356
     357                                            }
     358                                        );
     359
     360                                    // Shortcode replacement
     361
     362                                    var container            = (jQuery)( '<div></div>' );
     363                                    var playbuzz_info        = (jQuery)( '<div class="wp_playbuzz_info"></div>' ).attr( 'id', "playbuzz_info_" + id );
     364                                    var playbuzz_image       = (jQuery)( '<div class="wp_playbuzz_image"></div>' ).attr( 'id', "playbuzz_image_" + id );
     365                                    var playbuzz_placeholder = (jQuery)( '<img class="mceItem wp_playbuzz_placeholder" data-mce-resize="false" data-mce-placeholder="1" />' )
     366                                    .attr( 'id', "playbuzz_placeholder_" + id )
     367                                    .attr( 'src', url + "/../img/playbuzz-placeholder.png" );
     368                                    playbuzz_image.append( playbuzz_placeholder );
     369
     370                                    var playbuzz_embed = (jQuery)( '<div class="wp_playbuzz_embed"></div>' )
     371                                    .attr( 'id', "playbuzz_embed_" + id )
     372                                    .text( translation.your_item_will_be_embedded_here );
     373
     374                                    var playbuzz_buttons = (jQuery)( '<div class="wp_playbuzz_buttons"></div>' )
     375                                    .attr( 'id', "playbuzz_overlay_" + id )
     376                                    .attr( 'data-playbuzz-attr', encodedShortcodeAttributes );
     377
     378                                    var playbuzz_delete = (jQuery)( '<div class="wp_playbuzz_delete"></div>' ).attr( 'id', "playbuzz_overlay_close_" + id );
     379                                    var playbuzz_edit   = (jQuery)( '<div class="wp_playbuzz_edit"></div>' )
     380                                    .attr( 'id', "playbuzz_overlay_edit_" + id )
     381                                    .attr( 'data-playbuzz-attr', encodedShortcodeAttributes );
     382
     383                                    container
     384                                    .append( playbuzz_info )
     385                                    .append( playbuzz_image )
     386                                    .append( playbuzz_embed )
     387                                    .append( playbuzz_buttons )
     388                                    .append( playbuzz_delete )
     389                                    .append( playbuzz_edit );
     390
     391                                    return '<div class="wp_playbuzz_container" data-wp-pb-id="' + id + '" contenteditable="false">'
     392                                    + container.html() +
     393                                    '</div>' +
     394                                    '<div class="wp_playbuzz_container_end"></div>'; // for the regex in editor on GetContent
     395                                }
     396                            );
     397
     398                        }
     399                    );
     400
     401                    // Replace the item info box with the shortcode
     402                    editor.on(
     403                        'GetContent', function (event) {
     404
     405                            var new_content = event.content.replace(
     406                                playbuzz_place_holder_pattern, function (match, tag) {
     407
     408                                    // Extract shortcode attributes from <div data-playbuzz-attr="...">
     409                                    var data = get_attr( tag, 'data-playbuzz-attr' );
     410
     411                                    // Create the shortcode
     412                                    if (data) {
     413                                        return '<p>[playbuzz-item' + data + ']</p>';
     414                                    }
     415
     416                                    return match;
     417                                }
     418                            );
     419
     420                            event.content = new_content;
     421                        }
     422                    );
     423
     424                    // Item edit popup
     425                    editor.on(
     426                        'click', function (e) {
     427
     428                            var $placeholder = $( e.target );
     429                            // Delete item
     430                            if ($placeholder.hasClass( 'wp_playbuzz_delete' )) {
     431                                var $item = (jQuery)( $placeholder.closest( '.wp_playbuzz_container' ) )[0];
     432                                var id    = $item ? (jQuery)( $item ).attr( 'data-wp-pb-id' ) : 'none';
     433                                delete_playbuzz_item_shortcode( id );
     434                                (jQuery)( '.playbuzz_popup_overlay_container' ).remove();
     435                            }
     436
     437                            // Edit item
     438                            if ($placeholder.hasClass( 'wp_playbuzz_buttons' ) || $placeholder.hasClass( 'wp_playbuzz_edit' )) {
     439                                // Extract shortcode attributes stored in <div data-playbuzz-attr="...">
     440                                var attr  = $placeholder.attr( 'data-playbuzz-attr' );
     441                                var $item = (jQuery)( $placeholder.closest( '.wp_playbuzz_container' ) )[0];
     442                                var id    = $item ? (jQuery)( $item ).attr( 'data-wp-pb-id' ) : 'none';
     443
     444                                attr = window.decodeURIComponent( attr );
     445
     446                                // Set values
     447                                var item_url      = get_attr( attr, 'url' ),
     448                                    itemId        = get_attr( attr, 'item' ),
     449                                    info          = get_attr( attr, 'info' ),
     450                                    shares        = get_attr( attr, 'shares' ),
     451                                    comments      = get_attr( attr, 'comments' ),
     452                                    recommend     = get_attr( attr, 'recommend' ),
     453                                    margin_top    = get_attr( attr, 'margin-top' ),
     454                                    width         = get_attr( attr, 'width' ),
     455                                    height        = get_attr( attr, 'height' ),
     456                                    links         = get_attr( attr, 'links' ),
     457                                    tags          = get_attr( attr, 'tags' ),
     458                                    format        = get_attr( attr, 'format' ),
     459                                    itemPath      = item_url.split( 'playbuzz.com/' ).pop(),
     460                                    itemPathArray = itemPath.split( "/" ),
     461                                    creatorName   = itemPathArray[0],
     462                                    gameName      = itemPathArray[1];
     463
     464                                var data = {
     465                                    size: 1,
     466                                    moderation: "none"
     467                                };
     468
     469                                if (item_url) {
     470                                    data.alias = creatorName + "/" + gameName;
     471                                } else {
     472                                    data.id = itemId;
     473                                }
     474
     475                                // Which settings to use ? site default or custom item settings
     476                                var settings_to_use = ((info.length > 0) || (shares.length > 0) || (comments.length > 0) || (recommend.length > 0) || (margin_top.length > 0) || ( ! isNaN( margin_top ) && margin_top.trim() != '')) ? 'custom' : 'default';
     477
     478                                // Open Playbuzz Popup
     479                                search.playbuzz_popup();
     480
     481                                // Create item popup structure
     482                                playbuzz_item_popup_structure( settings_to_use, item_url, info, shares, comments, recommend, margin_top, width, height, links, tags, itemId, format );
     483
     484                                // Item Preview
     485                                (jQuery).ajax(
     486                                    {
     487                                        url: apiBaseUrl,
     488                                        type: "get",
     489                                        dataType: "json",
     490                                        data: data,
     491                                        error: function (data) {
     492
     493                                            // Clear preview
     494                                            (jQuery)( "#playbuzz_item_preview" ).empty();
     495                                            console.error( "Couldn't get data: ", data );
     496
     497                                        },
     498                                        success: function (data) {
     499
     500                                            if (data.payload.items.length > 0) {
     501
     502                                                var item = data.payload.items[0];
     503
     504                                                // Create preview
     505                                                (jQuery)( "#playbuzz_item_preview" ).empty().append(
     506                                                    (jQuery)( "<table></table>" ).append(
     507                                                        (jQuery)( "<tbody></tbody>" ).append(
     508                                                            (jQuery)( "<tr></tr>" ).attr( "valign", "top" ).append(
     509                                                                (jQuery)( "<td></td>" ).addClass( "playbuzz_item_thumb" )
     510                                                            ).append(
     511                                                                (jQuery)( "<td></td>" ).addClass( "playbuzz_item_info" )
     512                                                            )
     513                                                        )
     514                                                    )
     515                                                );
     516
     517                                                // Add thumb
     518                                                (jQuery)( "<p></p>" ).addClass( "playbuzz_item_thumb" ).appendTo( "td.playbuzz_item_thumb" );
     519                                                (jQuery)( "<img>" ).attr( "src", item.imageLarge ).appendTo( "p.playbuzz_item_thumb" );
     520
     521                                                // Add info
     522                                                (jQuery)( "<p></p>" ).addClass( "playbuzz_item_title" ).appendTo( "td.playbuzz_item_info" ).text( item.title );
     523                                                (jQuery)( "<p></p>" ).addClass( "playbuzz_item_meta" ).appendTo( "td.playbuzz_item_info" ).text( translation.created_by + " " ).append(
     524                                                    (jQuery)( "<span></span>" ).html( "<a target='_blank' href='http://www.playbuzz.com/" + item.channelAlias + "'>" + item.channelName + "</a> " )
     525                                                ).append( translation.on + " " + item_date( item.publishDate ) );
     526                                                (jQuery)( "<p></p>" ).addClass( "playbuzz_item_desc" ).appendTo( "td.playbuzz_item_info" ).text( item.description );
     527                                                (jQuery)( "<p></p>" ).addClass( "playbuzz_item_view_type_link" ).appendTo( "td.playbuzz_item_info" );
     528                                                (jQuery)( "<span></span>" ).addClass( "playbuzz_item_type" ).appendTo( "p.playbuzz_item_view_type_link" ).text( playbuzz_item_type( item.format ) );
     529                                                (jQuery)( "<span></span>" ).addClass( "playbuzz_item_link" ).appendTo( "p.playbuzz_item_view_type_link" );
     530                                                (jQuery)( "<a></a>" ).attr( "target", "_blank" ).attr( "href", item.playbuzzUrl ).appendTo( ".playbuzz_item_link" ).text( translation.preview_item );
     531
     532                                            }
     533
     534                                        }
     535                                    }
     536                                );
     537
     538                                // Set/Change fields visibility
     539                                function settings_visibility() {
     540                                    if ((jQuery)( "input[type='radio'][name='playbuzz_item_settings']:checked" ).val() == 'default') {
     541                                        (jQuery)( ".settings_half" ).addClass( "settings_disabled" );
     542                                        (jQuery)( "#playbuzz_item_settings_info" ).prop( "disabled", true );
     543                                        (jQuery)( "#playbuzz_item_settings_shares" ).prop( "disabled", true );
     544                                        (jQuery)( "#playbuzz_item_settings_recommend" ).prop( "disabled", true );
     545                                        (jQuery)( "#playbuzz_item_settings_comments" ).prop( "disabled", true );
     546                                        (jQuery)( "#playbuzz_item_settings_margin" ).prop( "disabled", true );
     547                                        (jQuery)( "#playbuzz_item_settings_margin_top" ).prop( "disabled", true );
     548                                    } else {
     549                                        (jQuery)( ".settings_half" ).removeClass( "settings_disabled" );
     550                                        (jQuery)( "#playbuzz_item_settings_info" ).prop( "disabled", false );
     551                                        (jQuery)( "#playbuzz_item_settings_shares" ).prop( "disabled", false );
     552                                        (jQuery)( "#playbuzz_item_settings_recommend" ).prop( "disabled", false );
     553                                        (jQuery)( "#playbuzz_item_settings_comments" ).prop( "disabled", false );
     554                                        (jQuery)( "#playbuzz_item_settings_margin" ).prop( "disabled", false );
     555                                        if ((jQuery)( "#playbuzz_item_settings_margin" ).prop( "checked" )) {
     556                                            (jQuery)( "#playbuzz_item_settings_margin_top" ).prop( "disabled", false );
     557                                        } else {
     558                                            (jQuery)( "#playbuzz_item_settings_margin_top" ).prop( "disabled", true );
     559                                        }
     560                                    }
     561                                }
     562
     563                                settings_visibility();
     564                                (jQuery)( "input[type='radio'][name='playbuzz_item_settings']:radio" ).change(
     565                                    function () {
     566                                                settings_visibility();
     567                                    }
     568                                );
     569
     570                                // Margin-top
     571                                if ( ! isNaN( margin_top ) && margin_top.trim() != '') {
     572                                    (jQuery)( "#playbuzz_item_settings_margin" ).prop( 'checked', true );
     573                                    (jQuery)( "#playbuzz_item_settings_margin_top" ).prop( "disabled", false );
     574                                } else {
     575                                    (jQuery)( "#playbuzz_item_settings_margin_top" ).prop( "disabled", true );
     576                                }
     577
     578                                // Change margin top
     579                                (jQuery)( "#playbuzz_item_settings_margin" ).change(
     580                                    function () {
     581                                        if ((jQuery)( this ).is( ':checked' )) {
     582                                            (jQuery)( "#playbuzz_item_settings_margin_top" ).prop( "disabled", false );
     583                                        } else {
     584                                            (jQuery)( "#playbuzz_item_settings_margin_top" ).prop( "disabled", true );
     585                                        }
     586                                    }
     587                                );
     588
     589                                // Click Update button
     590                                (jQuery)( ".playbuzz_item_update_button" ).click(
     591                                    function (e) {
     592
     593                                                                // start shortcode tag
     594                                                                var shortcode_str = '[playbuzz-item wp-pb-id="' + id + '"';
     595
     596                                                                // use site default settings or custom settings
     597                                                                default_or_custom = (jQuery)( "input[type='radio'][name='playbuzz_item_settings']:checked" ).val();
     598
     599                                                                var new_item_id = (jQuery)( "#playbuzz_item_settings_id" );
     600
     601                                        if (typeof new_item_id != 'undefined' && new_item_id.length && new_item_id.val() != '') {
     602                                            shortcode_str += ' item="' + new_item_id.val() + '"';
     603                                        } else {
     604                                            // add "url"
     605                                            new_item_url = (jQuery)( "#playbuzz_item_settings_url" );
     606                                            if (typeof new_item_url != 'undefined' && new_item_url.length && new_item_url.val() != '') {
     607                                                shortcode_str += ' url="' + new_item_url.val() + '"';
     608                                            }
     609                                        }
     610
     611                                                                // add "info"
     612                                                                new_info = (jQuery)( "#playbuzz_item_settings_info" ).prop( "checked" );
     613                                        if (default_or_custom == 'custom') {
     614                                            shortcode_str += ' info="' + new_info + '"';
     615                                        }
     616
     617                                                                // add "shares"
     618                                                                new_shares = (jQuery)( "#playbuzz_item_settings_shares" ).prop( "checked" );
     619                                        if (default_or_custom == 'custom') {
     620                                            shortcode_str += ' shares="' + new_shares + '"';
     621                                        }
     622
     623                                                                // add "comments"
     624                                                                new_comments = (jQuery)( "#playbuzz_item_settings_comments" ).prop( "checked" );
     625                                        if (default_or_custom == 'custom') {
     626                                            shortcode_str += ' comments="' + new_comments + '"';
     627                                        }
     628
     629                                                                // add "recommend"
     630                                                                new_recommend = (jQuery)( "#playbuzz_item_settings_recommend" ).prop( "checked" );
     631                                        if (default_or_custom == 'custom') {
     632                                            shortcode_str += ' recommend="' + new_recommend + '"';
     633                                        }
     634
     635                                                                // add "links"
     636                                                                new_links = (jQuery)( "#playbuzz_item_settings_links" );
     637                                        if (typeof new_links != 'undefined' && new_links.length && new_links.val() != '') {
     638                                            shortcode_str += ' links="' + new_links.val() + '"';
     639                                        }
     640
     641                                                                // add "tags"
     642                                                                new_tags = (jQuery)( "#playbuzz_item_settings_tags" );
     643                                        if (typeof new_tags != 'undefined' && new_tags.length && new_tags.val() != '') {
     644                                            shortcode_str += ' tags="' + new_tags.val() + '"';
     645                                        }
     646
     647                                                                // add "width"
     648                                                                new_width = (jQuery)( "#playbuzz_item_settings_width" );
     649                                        if (typeof new_width != 'undefined' && new_width.length && new_width.val() != '' && new_width.val() != 'auto') {
     650                                            shortcode_str += ' width="' + new_width.val() + '"';
     651                                        }
     652
     653                                                                // add "height"
     654                                                                new_height = (jQuery)( "#playbuzz_item_settings_height" );
     655                                        if (typeof new_height != 'undefined' && new_height.length && new_height.val() != '' && new_height.val() != 'auto') {
     656                                            shortcode_str += ' height="' + new_height.val() + '"';
     657                                        }
     658
     659                                                                format = (jQuery)( "#playbuzz_item_settings_format" );
     660                                        if (typeof format != 'undefined' && format.length && format.val() != '') {
     661                                            shortcode_str += ' format="' + format.val() + '"';
     662                                        }
     663
     664                                                                // add "margin-top"
     665                                                                new_margin_top = (jQuery)( "#playbuzz_item_settings_margin_top" );
     666                                        if (default_or_custom == 'custom' && typeof new_margin_top != 'undefined' && new_margin_top.length && new_margin_top.val() != '' && new_margin_top.val() != '0' && new_margin_top.val() != '0px' && (jQuery)( "#playbuzz_item_settings_margin" ).is( ':checked' )) {
     667                                            shortcode_str += ' margin-top="' + new_margin_top.val() + '"';
     668                                        }
     669
     670                                                                // End shortcode tag
     671                                                                shortcode_str += ']';
     672
     673                                                                // Remove settings modal
     674                                                                (jQuery)( '.playbuzz_popup_overlay_container' ).remove();
     675
     676                                                                // Replace shortcode in the editor
     677                                                                set_playbuzz_item_shortcode( id, shortcode_str );
     678                                    }
     679                                );
     680
     681                            }
     682
     683                        }
     684                    );
     685
     686        }
     687    );
    659688
    660689})();
  • playbuzz/tags/1.0.6/js/story-creator/_pb-story-creator.js

    r1831521 r1866507  
    1 
    21(function (window, $) {
    32
    4     var pbGlobal = new window.PbGlobal(window.pb, $, window.pbSettings),
     3    var pbGlobal = new window.PbGlobal( window.pb, $, window.pbSettings ),
    54
    6         pbStoryCreatorModel = new window.PbStoryCreatorModel($, window.PbCreator, window.PbApi, pbGlobal),
     5        pbStoryCreatorModel = new window.PbStoryCreatorModel( $, window.PbCreator, window.PbApi, pbGlobal ),
    76
    8         pbStoryCreatorView = new window.PbStoryCreatorView($, window.PbEvent),
     7        pbStoryCreatorView = new window.PbStoryCreatorView( $, window.PbEvent ),
    98
    10         pbStoryCreatorController = new window.PbStoryCreatorController(pbStoryCreatorModel, pbStoryCreatorView, $, window.PbAlert, window.wp, window.pbLogger );
     9        pbStoryCreatorController = new window.PbStoryCreatorController( pbStoryCreatorModel, pbStoryCreatorView, $, window.PbAlert, window.wp, window.pbLogger );
    1110
     11    pbStoryCreatorController.init();
    1212
    13     pbStoryCreatorController.init();
    14 
    15 })(window, window.jQuery);
    16 
    17 
    18 
    19 
     13})( window, window.jQuery );
  • playbuzz/tags/1.0.6/js/story-creator/pb-story-creator-controller.js

    r1831521 r1866507  
    1 
    2 
    31function PbStoryCreatorController(model, view, jQuery, PbAlert, wp, pbLogger){
    42
    5     this.model = model;
    6     this.view = view;
    7     this.$ = jQuery;
    8     this.alert = PbAlert;
    9     this.wp = wp;
    10     this.editPost = document.location.pathname.indexOf('post.php') > -1;
    11     this.logger = new pbLogger({
    12         environment: 'production',
    13         serviceName: 'wp-plugin'
    14     });
     3    this.model    = model;
     4    this.view     = view;
     5    this.$        = jQuery;
     6    this.alert    = PbAlert;
     7    this.wp       = wp;
     8    this.editPost = document.location.pathname.indexOf( 'post.php' ) > -1;
     9    this.logger   = new pbLogger(
     10        {
     11            environment: 'production',
     12            serviceName: 'wp-plugin'
     13        }
     14    );
    1515}
    1616/**
     
    2020PbStoryCreatorController.prototype.init = function () {
    2121
    22     var _this = this;
    23 
    24     this.manipulateDom();
    25 
    26     //disable wordpress autosave feature.
    27     this.disableWPAutoSave();
    28 
    29     //initialize creator via creator sdk.
    30     this.model.pbCreator.initialize()
    31 
    32         .then(function (res) {
    33 
    34 
    35             // enable all action buttons
    36             _this.changeAllButtonsStatus('disabled', false);
    37 
    38 
    39         },  _this.errorHandler);
    40 
    41 
    42     // listen to click event on post-preview button
    43     _this.view.postPreview.listen(function (sender, e) {
    44 
    45         _this.actionRunning(_this.view.publish.sender.pb);
    46 
    47         //_this.model.savePost(sender.wp).then(_this.postSuccessHandler.bind(_this), _this.errorHandler.bind(_this));
    48         _this.model.previewPost(sender.wp).then(_this.postSuccessHandler.bind(_this), _this.errorHandler.bind(_this));
    49 
    50     });
    51 
    52     // listen to click event on publish button
    53     _this.view.publish.listen(function (sender, e) {
    54         _this.actionRunning(sender.pb);
    55 
    56         _this.model.publishPost(sender.wp).then(_this.postSuccessHandler.bind(_this), _this.errorHandler.bind(_this));
    57 
    58     });
    59 
    60     // listen to click event on save button
    61     _this.view.savePost.listen(function (sender, e) {
    62         _this.actionRunning(sender.pb);
    63 
    64         _this.model.savePost(sender.wp).then(_this.postSuccessHandler.bind(_this), _this.errorHandler.bind(_this));
    65 
    66     });
    67 
    68     //listen to changes on title input.
    69     _this.view.title.listen(function (sender, e) {
    70         _this.setTitleToCreator(sender.wp.val());
    71     });
     22    var _this = this;
     23
     24    this.manipulateDom();
     25
     26    //disable wordpress autosave feature.
     27    this.disableWPAutoSave();
     28
     29    //initialize creator via creator sdk.
     30    this.model.pbCreator.initialize()
     31
     32        .then(
     33            function (res) {
     34
     35                // enable all action buttons
     36                _this.changeAllButtonsStatus( 'disabled', false );
     37
     38            },  _this.errorHandler
     39        );
     40
     41    // listen to click event on post-preview button
     42    _this.view.postPreview.listen(
     43        function (sender, e) {
     44
     45            _this.actionRunning( _this.view.publish.sender.pb );
     46
     47            //_this.model.savePost(sender.wp).then(_this.postSuccessHandler.bind(_this), _this.errorHandler.bind(_this));
     48            _this.model.previewPost( sender.wp ).then( _this.postSuccessHandler.bind( _this ), _this.errorHandler.bind( _this ) );
     49
     50        }
     51    );
     52
     53    // listen to click event on publish button
     54    _this.view.publish.listen(
     55        function (sender, e) {
     56            _this.actionRunning( sender.pb );
     57
     58            _this.model.publishPost( sender.wp ).then( _this.postSuccessHandler.bind( _this ), _this.errorHandler.bind( _this ) );
     59
     60        }
     61    );
     62
     63    // listen to click event on save button
     64    _this.view.savePost.listen(
     65        function (sender, e) {
     66            _this.actionRunning( sender.pb );
     67
     68            _this.model.savePost( sender.wp ).then( _this.postSuccessHandler.bind( _this ), _this.errorHandler.bind( _this ) );
     69
     70        }
     71    );
     72
     73    //listen to changes on title input.
     74    _this.view.title.listen(
     75        function (sender, e) {
     76            _this.setTitleToCreator( sender.wp.val() );
     77        }
     78    );
    7279
    7380};
     
    7885
    7986PbStoryCreatorController.prototype.disableWPAutoSave = function () {
    80     this.wp.autosave.local.suspend();
    81     this.wp.autosave.server.suspend();
     87    this.wp.autosave.local.suspend();
     88    this.wp.autosave.server.suspend();
    8289};
    8390
     
    8996PbStoryCreatorController.prototype.actionRunning = function (button) {
    9097
    91     this.changeLoaderStatus(button.siblings('.spinner'), 'show');
    92     this.changeAllButtonsStatus('disabled', true);
     98    this.changeLoaderStatus( button.siblings( '.spinner' ), 'show' );
     99    this.changeAllButtonsStatus( 'disabled', true );
    93100};
    94101
     
    100107PbStoryCreatorController.prototype.actionStopped = function () {
    101108
    102     this.changeLoaderStatus(this.$('.spinner'), 'hide');
    103     this.changeAllButtonsStatus('disabled', false);
     109    this.changeLoaderStatus( this.$( '.spinner' ), 'hide' );
     110    this.changeAllButtonsStatus( 'disabled', false );
    104111};
    105112
     
    111118PbStoryCreatorController.prototype.setPropertiesToCreator = function (properties) {
    112119
    113     var _this = this;
    114     var deferred = this.$.Deferred();
    115 
    116     this.model.setProperties(properties)
    117 
    118         .then(function (res) {
    119             deferred.resolve(res);
    120         })
    121 
    122         .fail(function () {
    123             _this.errorHandler();
    124             deferred.reject(res);
    125         });
    126 
    127    return deferred.promise();
     120    var _this    = this;
     121    var deferred = this.$.Deferred();
     122
     123    this.model.setProperties( properties )
     124
     125        .then(
     126            function (res) {
     127                deferred.resolve( res );
     128            }
     129        )
     130
     131        .fail(
     132            function () {
     133                _this.errorHandler();
     134                deferred.reject( res );
     135            }
     136        );
     137
     138    return deferred.promise();
    128139
    129140};
     
    131142PbStoryCreatorController.prototype.setTitleToCreator = function (title) {
    132143
    133     var _this = this;
    134     var deferred = this.$.Deferred();
    135 
    136     this.model.setTitle(title)
    137 
    138         .then(function (res) {
    139             deferred.resolve(res);
    140         })
    141 
    142         .fail(function () {
    143             _this.errorHandler();
    144             deferred.reject(res);
    145         });
    146 
    147    return deferred.promise();
     144    var _this    = this;
     145    var deferred = this.$.Deferred();
     146
     147    this.model.setTitle( title )
     148
     149        .then(
     150            function (res) {
     151                deferred.resolve( res );
     152            }
     153        )
     154
     155        .fail(
     156            function () {
     157                _this.errorHandler();
     158                deferred.reject( res );
     159            }
     160        );
     161
     162    return deferred.promise();
    148163
    149164};
     
    153168 * @param res
    154169 */
    155 PbStoryCreatorController.prototype.postSuccessHandler =  function (res) {
    156 
    157     this.actionStopped();
     170PbStoryCreatorController.prototype.postSuccessHandler = function (res) {
     171
     172    this.actionStopped();
    158173};
    159174
     
    162177 * @param err
    163178 */
    164 PbStoryCreatorController.prototype.errorHandler =  function (err) {
    165 
    166     this.logger.error(err);
    167 
    168     this.alert.notify(err, {
    169         type: 'error',
    170         placeholder: this.$('#post')
    171     });
    172 
    173     this.actionStopped();
     179PbStoryCreatorController.prototype.errorHandler = function (err) {
     180
     181    this.logger.error( err );
     182
     183    this.alert.notify(
     184        err, {
     185            type: 'error',
     186            placeholder: this.$( '#post' )
     187        }
     188    );
     189
     190    this.actionStopped();
    174191
    175192};
     
    181198PbStoryCreatorController.prototype.manipulateDom = function () {
    182199
    183     this.markPage();
    184 
    185     this.customMenu();
    186 
    187     this.customTitle();
    188 
    189     this.removeWpEditor();
    190 
    191     this.changeButtonsStatus([this.view.postPreview.sender.pb, this.view.publish.sender.pb, this.view.savePost.sender.pb], 'disabled', true);
     200    this.markPage();
     201
     202    this.customMenu();
     203
     204    this.customTitle();
     205
     206    this.removeWpEditor();
     207
     208    this.changeButtonsStatus( [this.view.postPreview.sender.pb, this.view.publish.sender.pb, this.view.savePost.sender.pb], 'disabled', true );
    192209
    193210};
     
    196213PbStoryCreatorController.prototype.getAddNewButton = function () {
    197214
    198     //TODO -- translation
    199     var button = this.$('.page-title-action').clone();
    200     var href = button.attr('href');
    201 
    202     button.text('Add New Playbuzz Item').attr('href', href + '?pb-story=true').addClass('show');
    203 
    204     return button;
     215    //TODO -- translation
     216    var button = this.$( '.page-title-action' ).clone();
     217    var href   = button.attr( 'href' );
     218
     219    button.text( 'Add New Playbuzz Item' ).attr( 'href', href + '?pb-story=true' ).addClass( 'show' );
     220
     221    return button;
    205222
    206223};
     
    210227PbStoryCreatorController.prototype.markPage = function () {
    211228
    212     this.$('body').attr('id', 'pb-story-creator-page');
     229    this.$( 'body' ).attr( 'id', 'pb-story-creator-page' );
    213230};
    214231
     
    219236PbStoryCreatorController.prototype.customMenu = function () {
    220237
    221     var $menuPosts = this.$('#menu-posts');
    222     var currentClass = 'current';
    223 
    224     if($menuPosts.find('li.current > a').attr('href') === 'post-new.php'){
    225         $menuPosts.find('li.current').removeClass(currentClass);
    226         $menuPosts.find('a[href$="post-new.php?pb-story=true"]').addClass(currentClass).parent().addClass(currentClass);
    227     }
     238    var $menuPosts   = this.$( '#menu-posts' );
     239    var currentClass = 'current';
     240
     241    if ($menuPosts.find( 'li.current > a' ).attr( 'href' ) === 'post-new.php') {
     242        $menuPosts.find( 'li.current' ).removeClass( currentClass );
     243        $menuPosts.find( 'a[href$="post-new.php?pb-story=true"]' ).addClass( currentClass ).parent().addClass( currentClass );
     244    }
    228245
    229246};
     
    234251PbStoryCreatorController.prototype.customTitle = function(){
    235252
    236     //TODO -- translation
    237     var title = this.editPost ? 'Edit Playbuzz Item' : 'Add New Playbuzz Item';
    238     var titleInput = 'Enter story title here';
    239     var button = this.editPost ? this.getAddNewButton() : null;
    240 
    241 
    242     this.$('.wrap > h1').text('').append(title).append(button).addClass('show');
    243     this.$('#title-prompt-text').text(titleInput).addClass('show');
     253    //TODO -- translation
     254    var title      = this.editPost ? 'Edit Playbuzz Item' : 'Add New Playbuzz Item';
     255    var titleInput = 'Enter story title here';
     256    var button     = this.editPost ? this.getAddNewButton() : null;
     257
     258    this.$( '.wrap > h1' ).text( '' ).append( title ).append( button ).addClass( 'show' );
     259    this.$( '#title-prompt-text' ).text( titleInput ).addClass( 'show' );
    244260};
    245261
     
    248264 */
    249265PbStoryCreatorController.prototype.removeWpEditor = function () {
    250     this.$('#postdivrich').remove();
     266    this.$( '#postdivrich' ).remove();
    251267};
    252268
     
    258274PbStoryCreatorController.prototype.changeLoaderStatus = function (loader, status) {
    259275
    260     if(status === 'show'){
    261         loader.addClass('is-active');
    262     } else{
    263         loader.removeClass('is-active');
    264     }
     276    if (status === 'show') {
     277        loader.addClass( 'is-active' );
     278    } else {
     279        loader.removeClass( 'is-active' );
     280    }
    265281};
    266282
     
    273289PbStoryCreatorController.prototype.changeButtonsStatus = function(buttons, statusName, status){
    274290
    275     if(this.$.isArray(buttons)){
    276 
    277         for(var i = 0; i < buttons.length; i++){
    278             buttons[i].attr(statusName, status);
    279         }
    280 
    281     }
    282     else{
    283         buttons.attr(statusName, status);
    284     }
     291    if (this.$.isArray( buttons )) {
     292
     293        for (var i = 0; i < buttons.length; i++) {
     294            buttons[i].attr( statusName, status );
     295        }
     296
     297    } else {
     298        buttons.attr( statusName, status );
     299    }
    285300
    286301};
     
    292307 */
    293308PbStoryCreatorController.prototype.changeAllButtonsStatus = function (statusName, status) {
    294     this.changeButtonsStatus([this.view.postPreview.sender.pb, this.view.publish.sender.pb, this.view.savePost.sender.pb], statusName, status);
     309    this.changeButtonsStatus( [this.view.postPreview.sender.pb, this.view.publish.sender.pb, this.view.savePost.sender.pb], statusName, status );
    295310};
    296311
  • playbuzz/tags/1.0.6/js/story-creator/pb-story-creator-model.js

    r1831521 r1866507  
    1 
    21function PbStoryCreatorModel(jQuery, pbCreator, PbApi, pbGlobal){
    32
    4     this.$ = jQuery;
    5     this.api = PbApi;
    6     this.global = pbGlobal;
    7     this.url = window.ajaxurl;
    8     this.pbCreator = new PbCreator('pb-story-creator' , this.getPbCreatorOptions());
    9     this.savePostAction = 'save_post_action';
    10     this.data = {
    11         postId: this.global.post.ID,
    12         itemId: '',
    13         nonce: this.$('#pb-story-creator-nonce').val()
    14     };
     3    this.$              = jQuery;
     4    this.api            = PbApi;
     5    this.global        = pbGlobal;
     6    this.url            = window.ajaxurl;
     7    this.pbCreator      = new PbCreator( 'pb-story-creator' , this.getPbCreatorOptions() );
     8    this.savePostAction = 'save_post_action';
     9    this.data          = {
     10        postId: this.global.post.ID,
     11        itemId: '',
     12        nonce: this.$( '#pb-story-creator-nonce' ).val()
     13    };
    1514
    1615}
     
    2221PbStoryCreatorModel.prototype.getPbCreatorOptions = function () {
    2322
    24     var options = {};
    25     var environment = this.global.options['pb-env'];
     23    var options    = {};
     24    var environment = this.global.options['pb-env'];
    2625
    27     options.itemId = this.global.itemId;
    28     options.channelId = this.global.options.pb_channel_id;
    29     options.locale = this.global.options.locale || 'en-US';
     26    options.itemId    = this.global.itemId;
     27    options.channelId = this.global.options.pb_channel_id;
     28    options.locale    = this.global.options.locale || 'en-US';
    3029
     30    if (environment && environment !== "") {
     31        options.environment = environment; }
    3132
    32     if(environment && environment !== ""){ options.environment =  environment; }
    33 
    34 
    35     return options;
     33    return options;
    3634};
    3735
     
    4846PbStoryCreatorModel.prototype.performAction = function (action, actionOnWP, paramsToAction) {
    4947
    50     var _this = this;
    51     var deferred = this.$.Deferred();
     48    var _this    = this;
     49    var deferred = this.$.Deferred();
    5250
    53     //perform action item via creator sdk.
    54     action(paramsToAction)
     51    //perform action item via creator sdk.
     52    action( paramsToAction )
    5553
    56         //save item id via wordpress creator plugin.
    57         .then(function (res) {
     54        //save item id via wordpress creator plugin.
     55        .then(
     56            function (res) {
    5857
    59             _this.data.itemId = res.itemId;
     58                _this.data.itemId = res.itemId;
    6059
    61            return _this.api.post(_this.data, {action: _this.savePostAction, url: _this.url});
     60                return _this.api.post( _this.data, {action: _this.savePostAction, url: _this.url} );
    6261
    63         })
     62            }
     63        )
    6464
    65         //perform action  to wordpress.
    66         .then(function (res) {
     65        //perform action  to wordpress.
     66        .then(
     67            function (res) {
    6768
    68             actionOnWP.click();
    69             deferred.resolve(res);
    70         })
     69                actionOnWP.click();
     70                deferred.resolve( res );
     71            }
     72        )
    7173
    72         .catch(function (err) {
     74        .catch(
     75            function (err) {
    7376
    74             //err.error - response from creator / cdk
    75             //err.statusText - response from wordpress.
    76             var error = err.message || err.statusText;
     77                //err.error - response from creator / cdk
     78                //err.statusText - response from wordpress.
     79                var error = err.message || err.statusText;
    7780
    78             deferred.reject(error);
    79         });
     81                deferred.reject( error );
     82            }
     83        );
    8084
    81 
    82     return deferred.promise();
     85    return deferred.promise();
    8386
    8487};
     
    9194PbStoryCreatorModel.prototype.publishPost = function (publishButton) {
    9295
    93     return this.performAction(this.pbCreator.publish, publishButton);
     96    return this.performAction( this.pbCreator.publish, publishButton );
    9497
    9598};
     
    102105PbStoryCreatorModel.prototype.savePost = function (saveButton) {
    103106
    104     return this.performAction(this.pbCreator.save, saveButton);
     107    return this.performAction( this.pbCreator.save, saveButton );
    105108
    106109};
     
    113116PbStoryCreatorModel.prototype.previewPost = function (previewButton) {
    114117
    115     var redirect = true;
     118    var redirect = true;
    116119
    117     return this.performAction(this.pbCreator.save , previewButton, redirect);
     120    return this.performAction( this.pbCreator.save , previewButton, redirect );
    118121
    119122};
     
    126129PbStoryCreatorModel.prototype.setProperties = function (properties) {
    127130
    128     var _this = this;
    129     var deferred = this.$.Deferred();
     131    var _this    = this;
     132    var deferred = this.$.Deferred();
    130133
    131     this.pbCreator.setItemProperties(properties)
     134    this.pbCreator.setItemProperties( properties )
    132135
    133     .then(function (res) {
     136    .then(
     137        function (res) {
    134138
    135         deferred.resolve(res);
     139            deferred.resolve( res );
    136140
    137     })
     141        }
     142    )
    138143
    139     .catch(function (err) {
     144    .catch(
     145        function (err) {
    140146
    141         deferred.reject(err);
    142     });
     147            deferred.reject( err );
     148        }
     149    );
    143150
    144     return deferred.promise();
     151    return deferred.promise();
    145152
    146153};
     
    153160PbStoryCreatorModel.prototype.setTitle = function (title) {
    154161
    155     var _this = this;
    156     var deferred = this.$.Deferred();
     162    var _this    = this;
     163    var deferred = this.$.Deferred();
    157164
    158     this.pbCreator.setTitle(title)
     165    this.pbCreator.setTitle( title )
    159166
    160     .then(function (res) {
     167    .then(
     168        function (res) {
    161169
    162         deferred.resolve(res);
     170            deferred.resolve( res );
    163171
    164     })
     172        }
     173    )
    165174
    166     .catch(function (err) {
     175    .catch(
     176        function (err) {
    167177
    168         deferred.reject(err);
    169     });
     178            deferred.reject( err );
     179        }
     180    );
    170181
    171     return deferred.promise();
     182    return deferred.promise();
    172183
    173184};
  • playbuzz/tags/1.0.6/js/story-creator/pb-story-creator-view.js

    r1831521 r1866507  
    1 
    2 
    3 
    41function PbStoryCreatorView(jQuery, PbEvent){
    52
    6     var elementsToCreate = ['#save-post', '#post-preview', '#publish'];
    7     var elementsToBind = ['#title'];
     3    var elementsToCreate = ['#save-post', '#post-preview', '#publish'];
     4    var elementsToBind  = ['#title'];
    85
    9     this.$ = jQuery;
    10     this.newElements = this.generateElements(elementsToCreate, true);
    11     this.elements = this.generateElements(elementsToBind);
    12     this.Event = PbEvent;
     6    this.$          = jQuery;
     7    this.newElements = this.generateElements( elementsToCreate, true );
     8    this.elements    = this.generateElements( elementsToBind );
     9    this.Event      = PbEvent;
    1310
    14     this.init();
     11    this.init();
    1512
    1613}
     
    2320PbStoryCreatorView.prototype.generateElements = function (elements, createNewElement) {
    2421
    25     var _elements = {};
    26     var _this = this;
     22    var _elements = {};
     23    var _this    = this;
    2724
    28     for(var i = 0; i < elements.length; i++){
     25    for (var i = 0; i < elements.length; i++) {
    2926
    30         var element = elements[i].substring(1);
    31         var wp = _this.$(elements[i]);
     27        var element = elements[i].substring( 1 );
     28        var wp      = _this.$( elements[i] );
    3229
    33         var pb = createNewElement ? wp.clone().prependTo(wp.parent()).attr('id', 'pb-' + element) : null;
     30        var pb = createNewElement ? wp.clone().prependTo( wp.parent() ).attr( 'id', 'pb-' + element ) : null;
    3431
    35         _elements[element] = {
    36             wp: wp,
    37             pb: pb
    38         }
    39     }
     32        _elements[element] = {
     33            wp: wp,
     34            pb: pb
     35        }
     36    }
    4037
    41 
    42     return _elements;
     38    return _elements;
    4339};
    4440
     
    4642PbStoryCreatorView.prototype.init = function () {
    4743
    48     var _this = this;
     44    var _this = this;
    4945
    50     this.savePost = new this.Event(this.newElements['save-post']);
    51     this.postPreview = new this.Event( this.newElements['post-preview']);
    52     this.publish = new this.Event(this.newElements['publish']);
    53     this.title = new this.Event(this.elements['title']);
     46    this.savePost    = new this.Event( this.newElements['save-post'] );
     47    this.postPreview = new this.Event( this.newElements['post-preview'] );
     48    this.publish     = new this.Event( this.newElements['publish'] );
     49    this.title       = new this.Event( this.elements['title'] );
    5450
     51    // attach listeners to HTML elements
     52    //listen to click event on save-post button
     53    this.newElements['save-post'].pb.click(
     54        function (e) {
     55            e.preventDefault();
     56            _this.savePost.notify( e );
     57        }
     58    );
    5559
     60    //listen to click event on post-preview button
     61    this.newElements['post-preview'].pb.click(
     62        function (e) {
    5663
    57     // attach listeners to HTML elements
    58     //listen to click event on save-post button
    59     this.newElements['save-post'].pb.click(function (e) {
    60         e.preventDefault();
    61         _this.savePost.notify(e);
    62     });
     64            e.preventDefault();
     65            e.stopImmediatePropagation();
    6366
    64     //listen to click event on post-preview button
    65     this.newElements['post-preview'].pb.click(function (e) {
     67            _this.postPreview.notify( e );
    6668
    67         e.preventDefault();
    68         e.stopImmediatePropagation();
     69        }
     70    );
    6971
    70         _this.postPreview.notify(e);
     72    //listen to click event on publish button
     73    this.newElements['publish'].pb.click(
     74        function (e) {
     75            e.preventDefault();
     76            _this.publish.notify( e );
    7177
    72     });
     78        }
     79    );
    7380
    74     //listen to click event on publish button
    75     this.newElements['publish'].pb.click(function (e) {
    76         e.preventDefault();
    77         _this.publish.notify(e);
    78 
    79     });
    80 
    81     //listen to change event on title input
    82     this.elements['title'].wp.change(function (e) {
    83        _this.title.notify(e);
    84     });
     81    //listen to change event on title input
     82    this.elements['title'].wp.change(
     83        function (e) {
     84            _this.title.notify( e );
     85        }
     86    );
    8587
    8688};
  • playbuzz/tags/1.0.6/playbuzz.php

    r1831521 r1866507  
    1616 * Exit if file accessed directly
    1717 */
    18 if (!defined('ABSPATH')) {
    19     exit;
     18if ( ! defined( 'ABSPATH' ) ) {
     19    exit;
    2020}
    2121
     
    2525 * Include plugin files
    2626 */
    27 include_once(plugin_dir_path(__FILE__) . 'class-pbconstants.php');      // Add Constants
    28 include_once(plugin_dir_path(__FILE__) . 'class-playbuzzembedcodes.php');    // Create embed code.
    29 include_once(plugin_dir_path(__FILE__) . 'class-playbuzzoptions.php');      // Add Activation hook
    30 include_once(plugin_dir_path(__FILE__) . 'class-playbuzzi18n.php');           // Add Internationalization support
    31 include_once(plugin_dir_path(__FILE__) . 'class-playbuzzsettings.php');       // Add Setting Page
    32 include_once(plugin_dir_path(__FILE__) . 'class-playbuzzstorycreator.php');  // Add Playbuzz Item post type
    33 include_once(plugin_dir_path(__FILE__) . 'class-playbuzzscriptsstyles.php'); // Load Scripts and Styles
    34 include_once(plugin_dir_path(__FILE__) . 'oembed.php');         // Add oEmbed support
    35 include_once(plugin_dir_path(__FILE__) . 'shortcodes.php');     // Add WordPress Shortcodes
    36 include_once(plugin_dir_path(__FILE__) . 'class-playbuzztinymce.php');        // Add TinyMCE plugin
    37 include_once(plugin_dir_path(__FILE__) . 'class-playbuzz-quicktags.php');        // Add quick-tags plugin
     27include_once( plugin_dir_path( __FILE__ ) . 'class-pbconstants.php' );      // Add Constants
     28include_once( plugin_dir_path( __FILE__ ) . 'class-playbuzzembedcodes.php' );    // Create embed code.
     29include_once( plugin_dir_path( __FILE__ ) . 'class-playbuzzoptions.php' );      // Add Activation hook
     30include_once( plugin_dir_path( __FILE__ ) . 'class-playbuzzi18n.php' );           // Add Internationalization support
     31include_once( plugin_dir_path( __FILE__ ) . 'class-playbuzzsettings.php' );       // Add Setting Page
     32include_once( plugin_dir_path( __FILE__ ) . 'class-playbuzzstorycreator.php' );  // Add Playbuzz Item post type
     33include_once( plugin_dir_path( __FILE__ ) . 'class-playbuzzscriptsstyles.php' ); // Load Scripts and Styles
     34include_once( plugin_dir_path( __FILE__ ) . 'oembed.php' );         // Add oEmbed support
     35include_once( plugin_dir_path( __FILE__ ) . 'shortcodes.php' );     // Add WordPress Shortcodes
     36include_once( plugin_dir_path( __FILE__ ) . 'class-playbuzztinymce.php' );        // Add TinyMCE plugin
     37include_once( plugin_dir_path( __FILE__ ) . 'class-playbuzzquicktags.php' );        // Add quick-tags plugin
    3838
    3939/*
     
    4141 */
    4242function playbuzz_settings_link( $links ) {
    43     $links[] = '<a href="options-general.php?page=playbuzz">' . __('Settings') . '</a>';
    44     return $links;
     43    $links[] = '<a href="options-general.php?page=playbuzz">' . __( 'Settings' ) . '</a>';
     44    return $links;
    4545}
    4646
    47 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'playbuzz_settings_link');
     47add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'playbuzz_settings_link' );
    4848
  • playbuzz/tags/1.0.6/shortcodes.php

    r1831521 r1866507  
    99
    1010
    11 $options = (array) get_option( 'playbuzz' );
     11$options     = (array) get_option( 'playbuzz' );
    1212$site_jshead = ( ( ( array_key_exists( 'jshead', $options ) ) && ( '1' == $options['jshead'] ) ) ? true : false );
    1313
     
    3434
    3535    if ( $found ) {
    36         wp_enqueue_script( 'external-playbuzz-js', '//cdn.playbuzz.com/widget/feed.js' , '', '', false );
     36        wp_enqueue_script( 'external-playbuzz-js', '//cdn.playbuzz.com/widget/feed.js', '', '', false );
    3737    }
    3838
     
    6969 */
    7070add_shortcode( 'playbuzz-section', 'playbuzz_section_shortcode' );
    71 add_shortcode( 'playbuzz-hub',     'playbuzz_section_shortcode' );
     71add_shortcode( 'playbuzz-hub', 'playbuzz_section_shortcode' );
    7272add_shortcode( 'playbuzz-archive', 'playbuzz_section_shortcode' );
    7373
     
    8888
    8989    // Prepare site settings
    90     $site_key       = ( ( ( array_key_exists( 'key',               $options ) ) ) ? $options['key'] : str_replace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) ) );
    91     $site_jshead    = ( ( ( array_key_exists( 'jshead',              $options ) ) && ( '1' == $options['jshead']      ) ) ? 'true' : 'false' );
    92     $site_info      = ( ( ( array_key_exists( 'info',              $options ) ) && ( '1' == $options['info']      ) ) ? 'true' : 'false' );
    93     $site_shares    = ( ( ( array_key_exists( 'shares',            $options ) ) && ( '1' == $options['shares']    ) ) ? 'true' : 'false' );
    94     $site_comments  = ( ( ( array_key_exists( 'comments',          $options ) ) && ( '1' == $options['comments'] ) ) ? 'true' : 'false' );
    95     $site_recommend = ( ( ( array_key_exists( 'recommend',         $options ) ) && ( '1' == $options['recommend'] ) ) ? 'true' : 'false' );
     90    $site_key       = ( ( ( array_key_exists( 'key', $options ) ) ) ? $options['key'] : str_replace( 'www.', '', wp_parse_url( home_url(), PHP_URL_HOST ) ) );
     91    $site_jshead    = ( ( ( array_key_exists( 'jshead', $options ) ) && ( '1' == $options['jshead'] ) ) ? 'true' : 'false' );
     92    $site_info      = ( ( ( array_key_exists( 'info', $options ) ) && ( '1' == $options['info'] ) ) ? 'true' : 'false' );
     93    $site_shares    = ( ( ( array_key_exists( 'shares', $options ) ) && ( '1' == $options['shares'] ) ) ? 'true' : 'false' );
     94    $site_comments  = ( ( ( array_key_exists( 'comments', $options ) ) && ( '1' == $options['comments'] ) ) ? 'true' : 'false' );
     95    $site_recommend = ( ( ( array_key_exists( 'recommend', $options ) ) && ( '1' == $options['recommend'] ) ) ? 'true' : 'false' );
    9696    $site_tags      = '';
    97     $site_tags     .= ( ( ( array_key_exists( 'tags-mix',          $options ) ) && ( '1' == $options['tags-mix']          ) ) ? 'All,'                  : '' );
    98     $site_tags     .= ( ( ( array_key_exists( 'tags-fun',          $options ) ) && ( '1' == $options['tags-fun']          ) ) ? 'Fun,'                  : '' );
    99     $site_tags     .= ( ( ( array_key_exists( 'tags-pop',          $options ) ) && ( '1' == $options['tags-pop']          ) ) ? 'Pop,'                  : '' );
    100     $site_tags     .= ( ( ( array_key_exists( 'tags-geek',         $options ) ) && ( '1' == $options['tags-geek']         ) ) ? 'Geek,'                : '' );
    101     $site_tags     .= ( ( ( array_key_exists( 'tags-sports',       $options ) ) && ( '1' == $options['tags-sports']       ) ) ? 'Sports,'              : '' );
     97    $site_tags     .= ( ( ( array_key_exists( 'tags-mix', $options ) ) && ( '1' == $options['tags-mix'] ) ) ? 'All,' : '' );
     98    $site_tags     .= ( ( ( array_key_exists( 'tags-fun', $options ) ) && ( '1' == $options['tags-fun'] ) ) ? 'Fun,' : '' );
     99    $site_tags     .= ( ( ( array_key_exists( 'tags-pop', $options ) ) && ( '1' == $options['tags-pop'] ) ) ? 'Pop,' : '' );
     100    $site_tags     .= ( ( ( array_key_exists( 'tags-geek', $options ) ) && ( '1' == $options['tags-geek'] ) ) ? 'Geek,' : '' );
     101    $site_tags     .= ( ( ( array_key_exists( 'tags-sports', $options ) ) && ( '1' == $options['tags-sports'] ) ) ? 'Sports,' : '' );
    102102    $site_tags     .= ( ( ( array_key_exists( 'tags-editors-pick', $options ) ) && ( '1' == $options['tags-editors-pick'] ) ) ? 'EditorsPick_Featured,' : '' );
    103     $site_tags     .= ( ( ( array_key_exists( 'more-tags',         $options ) ) ) ? $options['more-tags'] : '' );
     103    $site_tags     .= ( ( ( array_key_exists( 'more-tags', $options ) ) ) ? $options['more-tags'] : '' );
    104104    $site_tags      = rtrim( $site_tags, ',' );
    105     $site_margintop = ( ( ( array_key_exists( 'margin-top',        $options ) ) ) ? $options['margin-top'] : '' );
    106     $embeddedon     = ( ( ( array_key_exists( 'embeddedon',        $options ) ) ) ? $options['embeddedon'] : 'content' );
     105    $site_margintop = ( ( ( array_key_exists( 'margin-top', $options ) ) ) ? $options['margin-top'] : '' );
     106    $embeddedon     = ( ( ( array_key_exists( 'embeddedon', $options ) ) ) ? $options['embeddedon'] : 'content' );
    107107
    108108    // Set default attribute values if the user did not defined any
     
    123123            'height'     => 'auto',          // define custom height (added in 0.3)
    124124            'margin-top' => $site_margintop, // margin top for score bar in case there is a floating bar
    125     ), $atts );
     125        ), $atts
     126    );
    126127
    127128    // Playbuzz Embed Code
     
    147148
    148149    if ( 'story' == $atts['format'] ) {
    149         $code .= 'data-version=2';
     150        $code .= 'data-version=2';
    150151    }
    151152
     
    179180
    180181    // Prepare site settings
    181     $site_key       = ( ( ( array_key_exists( 'key',               $options ) ) ) ? $options['key'] : str_replace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) ) );
    182     $site_info      = ( ( ( array_key_exists( 'info',              $options ) ) && ( '1' == $options['info']      ) ) ? 'true' : 'false' );
    183     $site_shares    = ( ( ( array_key_exists( 'shares',            $options ) ) && ( '1' == $options['shares']    ) ) ? 'true' : 'false' );
    184     $site_comments  = ( ( ( array_key_exists( 'comments',          $options ) ) && ( '1' == $options['comments'] ) ) ? 'true' : 'false' );
    185     $site_recommend = ( ( ( array_key_exists( 'recommend',         $options ) ) && ( '1' == $options['recommend'] ) ) ? 'true' : 'false' );
     182    $site_key       = ( ( ( array_key_exists( 'key', $options ) ) ) ? $options['key'] : str_replace( 'www.', '', wp_parse_url( home_url(), PHP_URL_HOST ) ) );
     183    $site_info      = ( ( ( array_key_exists( 'info', $options ) ) && ( '1' == $options['info'] ) ) ? 'true' : 'false' );
     184    $site_shares    = ( ( ( array_key_exists( 'shares', $options ) ) && ( '1' == $options['shares'] ) ) ? 'true' : 'false' );
     185    $site_comments  = ( ( ( array_key_exists( 'comments', $options ) ) && ( '1' == $options['comments'] ) ) ? 'true' : 'false' );
     186    $site_recommend = ( ( ( array_key_exists( 'recommend', $options ) ) && ( '1' == $options['recommend'] ) ) ? 'true' : 'false' );
    186187    $site_tags      = '';
    187     $site_tags     .= ( ( ( array_key_exists( 'tags-mix',          $options ) ) && ( '1' == $options['tags-mix']          ) ) ? 'All,'                  : '' );
    188     $site_tags     .= ( ( ( array_key_exists( 'tags-fun',          $options ) ) && ( '1' == $options['tags-fun']          ) ) ? 'Fun,'                  : '' );
    189     $site_tags     .= ( ( ( array_key_exists( 'tags-pop',          $options ) ) && ( '1' == $options['tags-pop']          ) ) ? 'Pop,'                  : '' );
    190     $site_tags     .= ( ( ( array_key_exists( 'tags-geek',         $options ) ) && ( '1' == $options['tags-geek']         ) ) ? 'Geek,'                : '' );
    191     $site_tags     .= ( ( ( array_key_exists( 'tags-sports',       $options ) ) && ( '1' == $options['tags-sports']       ) ) ? 'Sports,'              : '' );
     188    $site_tags     .= ( ( ( array_key_exists( 'tags-mix', $options ) ) && ( '1' == $options['tags-mix'] ) ) ? 'All,' : '' );
     189    $site_tags     .= ( ( ( array_key_exists( 'tags-fun', $options ) ) && ( '1' == $options['tags-fun'] ) ) ? 'Fun,' : '' );
     190    $site_tags     .= ( ( ( array_key_exists( 'tags-pop', $options ) ) && ( '1' == $options['tags-pop'] ) ) ? 'Pop,' : '' );
     191    $site_tags     .= ( ( ( array_key_exists( 'tags-geek', $options ) ) && ( '1' == $options['tags-geek'] ) ) ? 'Geek,' : '' );
     192    $site_tags     .= ( ( ( array_key_exists( 'tags-sports', $options ) ) && ( '1' == $options['tags-sports'] ) ) ? 'Sports,' : '' );
    192193    $site_tags     .= ( ( ( array_key_exists( 'tags-editors-pick', $options ) ) && ( '1' == $options['tags-editors-pick'] ) ) ? 'EditorsPick_Featured,' : '' );
    193     $site_tags     .= ( ( ( array_key_exists( 'more-tags',         $options ) ) ) ? $options['more-tags'] : '' );
     194    $site_tags     .= ( ( ( array_key_exists( 'more-tags', $options ) ) ) ? $options['more-tags'] : '' );
    194195    $site_tags      = rtrim( $site_tags, ',' );
    195     $site_margintop = ( ( ( array_key_exists( 'margin-top',        $options ) ) ) ? $options['margin-top'] : '' );
    196     $embeddedon     = ( ( ( array_key_exists( 'embeddedon',        $options ) ) ) ? $options['embeddedon'] : 'content' );
     196    $site_margintop = ( ( ( array_key_exists( 'margin-top', $options ) ) ) ? $options['margin-top'] : '' );
     197    $embeddedon     = ( ( ( array_key_exists( 'embeddedon', $options ) ) ) ? $options['embeddedon'] : 'content' );
    197198
    198199    // Set default attribute values if the user did not defined any
     
    211212            'height'     => 'auto',          // define custom height (added in 0.3)
    212213            'margin-top' => $site_margintop, // margin top for score bar in case there is a floating bar
    213     ), $atts );
     214        ), $atts
     215    );
    214216
    215217    // Playbuzz Embed Code
Note: See TracChangeset for help on using the changeset viewer.