define_constants(); $this->includes(); $this->init_hooks(); $this->add_ajax_events(); } /** * Hook into actions and filters * @since 1.0 */ private function init_hooks() { register_activation_hook( __FILE__, array( &$this, 'setup_environment' ) ); register_uninstall_hook(__FILE__, array(&$this, 'clear_environment')); add_action('admin_notices', array( $this,'admin_notice')); add_action('admin_init', array( $this,'admin_notice_ignore')); add_action( 'init', array( $this, 'init' ), 0 ); add_action('widgets_init', array( $this, 'widget_initialises')); add_filter('the_content', array( $this, 'themeidol_view_count_js')); add_action('mts_view_count_after_update', array( $this, 'themeidol_update_view_count')); add_action('admin_menu', array( $this, 'themeidol_add_options_page')); add_filter('plugin_action_links', array( $this, 'themeidol_action_links'), 10, 2); } /** * Define WC Constants */ private function define_constants() { $this->define( 'HEMEIDOL_WIDGET_FILE', __FILE__ ); $this->define( 'THEMEIDOL_WIDGET_BASENAME', plugin_basename( __FILE__ ) ); $this->define( 'THEMEIDOL_WIDGET_JS_URL', plugins_url( '/assets/js/', __FILE__ ) ); $this->define( 'THEMEIDOL_WIDGET_VERSION', $this->version ); $this->define( 'THEMEIDOL_WIDGET_CSS_URL', plugins_url( '/assets/css/', __FILE__ ) ); $this->define( 'THEMEIDOL_WIDGET_IMAGES_URL', plugins_url( '/assets/img/', __FILE__ ) ); $this->define( 'THEMEIDOL_WIDGET_PATH', dirname( __FILE__ ) ); $this->define( 'THEMEIDOL_WIDGET_FILE', __FILE__ ); $this->define( 'THEMEIDOL_WIDGET_CORE', plugin_dir_path(__FILE__).'widgets/'); $this->define( 'THEMEIDOL_WIDGET_ADMIN', plugin_dir_path(__FILE__).'admin/'); } /** * Define constant if not already set * @param string $name * @param string|bool $value */ private function define( $name, $value ) { if ( ! defined( $name ) ) { define( $name, $value ); } } /** * What type of request is this? * string $type ajax, frontend or admin * @return bool */ private function is_request( $type ) { switch ( $type ) { case 'admin' : return is_admin(); case 'ajax' : return defined( 'DOING_AJAX' ); case 'cron' : return defined( 'DOING_CRON' ); case 'frontend' : return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ); } } // Init plugin options to white list our options function themeidol_options_init(){ register_setting( 'themeidol_plugin_options', 'themeidol_options', '' ); wp_register_style( 'themeidol_widgets_admincss', THEMEIDOL_WIDGET_CSS_URL.'options.css'); } /** * Include required core files used in admin and on the frontend. */ public function includes() { //Advert Widget require_once(THEMEIDOL_WIDGET_CORE.'widget-advert.php'); //Flicker Widget require_once(THEMEIDOL_WIDGET_CORE.'widget-flickr.php'); //Recent Post widget require_once(THEMEIDOL_WIDGET_CORE.'widget-recent.php'); //Tweet Widget require_once(THEMEIDOL_WIDGET_CORE.'widget-tweets.php'); //Social Icons Widget require_once(THEMEIDOL_WIDGET_CORE.'widget-social.php'); //WP Author Widget require_once(THEMEIDOL_WIDGET_CORE.'widget-author.php'); //Stylist Post Widget require_once(THEMEIDOL_WIDGET_CORE.'widget-stylish-popular-posts.php'); //Facebook Page like widget require_once(THEMEIDOL_WIDGET_CORE.'widget-fb_pagelike.php'); //Ajax Search Widget require_once(THEMEIDOL_WIDGET_CORE.'widget-wp-ajax-search.php'); //Wp Tab Widget require_once(THEMEIDOL_WIDGET_CORE.'widget-wp-tab.php'); //Instagram Widget require_once(THEMEIDOL_WIDGET_CORE.'widget-wp-instagram.php'); //Quotation widget require_once(THEMEIDOL_WIDGET_CORE.'widget-site2quotes.php'); //Rss Feed widget require_once(THEMEIDOL_WIDGET_CORE.'widget-rss-feed.php'); } /** * Init Themeidolwidgets when WordPress Initialises. */ public function init() { // Set up localisation $this->load_plugin_textdomain(); add_action('wp_enqueue_scripts', array( $this, 'setup_environment_for_styling')); } /** * Init Themeidol widget admin notice Initialises. */ public function admin_notice() { global $current_user ; $user_id = $current_user->ID; /* Check that the user hasn't already clicked to ignore the message */ if ( ! get_user_meta($user_id, 'themeidol_tab_widget_ignore_notice') ) { echo '

'; printf(__('Like Themeidol all-in-one Widget? You will LOVE our others themes and plugins!','themeidol-all-widget').' '.__('Click here for all the exciting features.','themeidol-all-widget').'', '?themeidol_tab_widget_notice_ignore=0'); echo "

"; } } /** * Init Themeidol widget admin notice close Initialises. */ public function admin_notice_ignore() { $this->themeidol_options_init(); global $current_user; $user_id = $current_user->ID; /* If user clicks to ignore the notice, add that to their user meta */ if ( isset($_GET['themeidol_tab_widget_notice_ignore']) && '0' == $_GET['themeidol_tab_widget_notice_ignore'] ) { add_user_meta($user_id, 'themeidol_tab_widget_ignore_notice', 'true', true); } } /** * Load Localisation files. * */ public function load_plugin_textdomain() { load_plugin_textdomain( 'themeidol-all-widget', false, dirname( THEMEIDOL_WIDGET_BASE ) . '/languages/' ); } /** * Ensure theme and server variable compatibility and setup image sizes. */ public function setup_environment() { $this->add_views_meta_for_posts(); $this->add_thumbnail_support(); $this->add_image_sizes(); $this->themeidol_add_defaults_options(); } // clear Environment public function clear_environment() { delete_option('gab_options'); } // Define default option settings function themeidol_add_defaults_options() { delete_option('gab_options'); $arr = array( "advert" => "1", "flickr" => "1", "recent" => "1", "tweet" => "1", "social" => "1", "author" => "1", "stylist" => "1", "facebook" => "1", "ajaxsearch" => "1", "tabs" => "1", "instagram" => "1", "site2quotes" => "1", "rssfeed" => "1" ); update_option('gab_options', $arr); } // Add menu page function themeidol_add_options_page() { /* Add our plugin submenu and administration screen */ $hook = add_submenu_page( 'options-general.php', // The parent page of this submenu __( 'Themeidol Widget', 'themeidol-all-widget' ), // The submenu title __( 'Themeidol Widget', 'themeidol-all-widget' ), // The screen title 'manage_options', // The capability required for access to this submenu 'themeidol-widget-pack-options', // The slug to use in the URL of the screen array(&$this,'themeidol_render_form') // The function to call to display the screen ); add_action('admin_print_scripts-' . $hook, array($this,'themeidol_smart_widgets_css')); } //Add Settings link in plugin list page public function themeidol_action_links($links, $file){ if($file == 'all-in-one-widget/all-in-one-widget.php'){ $new_links = ''.__('Settings', 'themeidol-all-widget').''; array_unshift($links, $new_links); } return $links; } public function themeidol_smart_widgets_css() { /* Link already registered script to the settings page */ wp_enqueue_style( 'themeidol_widgets_admincss' ); } function themeidol_render_form() { include(THEMEIDOL_WIDGET_ADMIN.'admin-option.php'); } /** * Ensure theme and server variable compatibility and setup image sizes. */ public function setup_environment_for_styling() { wp_enqueue_style('themeidol-widgets', THEMEIDOL_WIDGET_CSS_URL.'style.css'); } /** * Add meta for all existing posts that don't have it * to make them show up in Popular tab */ public function add_views_meta_for_posts() { $allposts = get_posts( 'numberposts=-1&post_type=post&post_status=any' ); foreach( $allposts as $postinfo ) { add_post_meta( $postinfo->ID, '_themeidol_view_count', 0, true ); } } /** * * */ public function widget_initialises() { $themeidol_options = get_option('themeidol_options'); $themeidol_default_option = array( "advert" => 0, "flickr" => 0, "recent" => 0, "tweet" => 0, "social" => 0, "author" => 0, "stylist" => 0, "facebook" => 0, "ajaxsearch" => 0, "tabs" => 0, "instagram" => 0, "site2quotes" => 0, "rssfeed" => 0 ); if (false === $themeidol_options) { $themeidol_options = $themeidol_default_option; } //Add all widgets components //Advert Widget if (isset($themeidol_options['advert']) && $themeidol_options['advert'] == 1): register_widget('Themeidol_Widget_Advert'); endif; //Flicker Widget if (isset($themeidol_options['flickr']) && $themeidol_options['flickr'] == 1): register_widget('Themeidol_Widget_Flickr'); endif; // Recent Post widget if (isset($themeidol_options['recent']) && $themeidol_options['recent'] == 1): register_widget('Themeidol_Widget_RecentPosts'); endif; //Tweet Widget if (isset($themeidol_options['tweet']) && $themeidol_options['tweet'] == 1): register_widget('Themeidol_Widget_Tweets'); endif; // Social Icons Widget if (isset($themeidol_options['social']) && $themeidol_options['social'] == 1): register_widget('Themeidol_Widget_Social'); endif; //WP Author Widget if (isset($themeidol_options['author']) && $themeidol_options['author'] == 1): register_widget('Themeidol_Widget_Author'); endif; //Stylist Post Widget if (isset($themeidol_options['stylist']) && $themeidol_options['stylist'] == 1): register_widget('Themeidol_stylish_popular_posts'); endif; // Facebook Page like widget if (isset($themeidol_options['facebook']) && $themeidol_options['facebook'] == 1): register_widget('Themeidol_facebook_widget'); endif; //Ajax Search Widget if (isset($themeidol_options['ajaxsearch']) && $themeidol_options['ajaxsearch'] == 1): register_widget( 'Themeidol_ajaxsearch_widget' ); endif; //Wp Tab Widget if (isset($themeidol_options['tabs']) && $themeidol_options['tabs'] == 1): register_widget( 'Themeidol_Tab_widget'); endif; //Instagram Widget if (isset($themeidol_options['instagram']) && $themeidol_options['instagram'] == 1): register_widget( 'Themeidol_instagram_widget' ); endif; //Quotation widget if (isset($themeidol_options['site2quotes']) && $themeidol_options['site2quotes'] == 1): register_widget( 'Themeidol_QuoteOfDay_Site2Quotes' ); endif; //Rss Feed widget if (isset($themeidol_options['rssfeed']) && $themeidol_options['rssfeed'] == 1): register_widget('Themeidol_rss_feed_widget'); endif; // } public function add_ajax_events() { add_action('wp_ajax_wpt_view_count', array( $this, 'ajax_themeidol_view_count')); add_action('wp_ajax_nopriv_wpt_view_count',array( $this, 'ajax_themeidol_view_count')); } public function themeidol_view_count_js( $content ) { global $post; $id = $post->ID; $use_ajax = apply_filters( 'mts_view_count_cache_support', true ); $exclude_admins = apply_filters( 'mts_view_count_exclude_admins', false ); // pass in true or a user capaibility if ($exclude_admins === true) $exclude_admins = 'edit_posts'; if ($exclude_admins && current_user_can( $exclude_admins )) return $content; // do not count post views here if (is_single()) { if ( ! has_filter('the_content', 'mts_view_count_js') && $use_ajax) { // prevent additional ajax call if theme has view counter already // enqueue jquery wp_enqueue_script( 'jquery' ); $url = admin_url( 'admin-ajax.php' ); $content .= " "; } // if there's no general filter set and ajax is OFF if (! has_filter('the_content', 'mts_view_count_js') && ! $use_ajax) { $this->themeidol_update_view_count($id); } } return $content; } public function ajax_themeidol_view_count() { // do count if ( isset( $_POST['id'] ) ) { $post_id = intval( $_POST['id']); // apply more sanitizations here if needed } $this->themeidol_update_view_count( $post_id ); } public function themeidol_update_view_count( $post_id ) { $post_id = intval( $post_id); $count = get_post_meta( $post_id, '_themeidol_view_count', true ); update_post_meta( $post_id, '_themeidol_view_count', $count + 1 ); } // Reset post count for specific post or all posts public function themeidol_reset_post_count($post_id = 0) { $post_id = intval( $post_id); if ($post_id == 0) { $allposts = get_posts( 'numberposts=-1&post_type=post&post_status=any' ); foreach( $allposts as $postinfo ) { update_post_meta( $postinfo->ID, '_themeidol_view_count', '0' ); } } else { update_post_meta( $post_id, '_themeidol_view_count', '0' ); } } /** * Ensure post thumbnail support is turned on */ private function add_thumbnail_support() { if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } } /** * Add TW Image sizes to WP * * @since 1.0 */ private function add_image_sizes() { add_image_size( 'popular_posts_img', 600, 360, true ); add_image_size( 'wp_review_small', 65, 65, true ); // small thumb add_image_size( 'wp_review_large', 320, 240, true ); // large thumb } /** * Get the plugin url. * @return string */ public function plugin_url() { return untrailingslashit( plugins_url( '/', __FILE__ ) ); } /** * Get the plugin path. * @return string */ public function plugin_path() { return untrailingslashit( plugin_dir_path( __FILE__ ) ); } /** * Get Ajax URL. * @return string */ public function ajax_url() { return admin_url( 'admin-ajax.php', 'relative' ); } } endif; /** * Returns the main instance of TW to prevent the need to use globals. * * @since 1.0 * @return Themeidolwidgets */ function TW() { return Themeidolwidgets::instance(); } // Global for backwards compatibility. $GLOBALS['themeidolwidgets'] = TW();