array('1',__( 'Advert Space','themeidol-all-widget'),__('Easily insert images without having to resort to writing HTML in a text widget. You can also link the image or add your own advertising code.','themeidol-all-widget')),
'flickr'=>array('1',__('Flickr','themeidol-all-widget'),__('Show your latest images from a Flickr account right into your sidebar, and linking to your Flickr gallery.','themeidol-all-widget')),
'recent'=>array('1',__('Recent Post','themeidol-all-widget'),__('A more powerful version of the default recent posts widget provided by WordPress. This widget allows you to display a thumbnail of each post and also to choose which post type to display.','themeidol-all-widget')),
'tweet'=>array('1',__('Twiteer Feed','themeidol-all-widget'),__('Add twitter feeds on your WordPress site by using the Twitter Feed Widget plugin.','themeidol-all-widget')),
'social'=>array('1',__('Social Icons','themeidol-all-widget'),__('Add links to your preferred social profiles, being able to choose from a long list of available social networks.','themeidol-all-widget')),
'author'=>array('1',__('Author Badge','themeidol-all-widget'),__('Display the profile of a specific user, showing the name, image, and profile description.','themeidol-all-widget')),
'stylist'=>array('1',__('Stylist Post','themeidol-all-widget'),__('Stylish Popular Posts creates a widget which displays popular posts based on the number of comments.','themeidol-all-widget')),
'facebook'=>array('1',__('Facebook Page Like','themeidol-all-widget'),__('This widget adds a Simple Facebook page Like Widget into your WordPress website Sidebar','themeidol-all-widget')),
'ajaxsearch'=>array('1',__('Ajax Search','themeidol-all-widget'),__('Displays instant search results directly beneath a search widget.','themeidol-all-widget')),
'tabs'=>array('1',__('Tabs Widget','themeidol-all-widget'),__('Tab Widget is the AJAXified plugin which loads content by demand, and thus it makes the plugin incredibly lightweight.','themeidol-all-widget')),
'instagram'=>array('1',__('Instagram Photos','themeidol-all-widget'),__('Instagram widget is a no fuss WordPress widget to showcase your latest Instagram pics.','themeidol-all-widget')),
'site2quotes'=>array('1',__('Site2quotes Widget','themeidol-all-widget'),__('This plugin lets you add a Quote of the Day widget to your WordPress page.','themeidol-all-widget')),
'rssfeed'=>array('1',__('Rss Feed','themeidol-all-widget'),__('RSS Feeds is a small & lightweight plugin. Fast and easy to use, it aggregates RSS feeds into your site with widgets.','themeidol-all-widget')),
'dataandtime'=>array('1',__('Date and Time','themeidol-all-widget'),__('Widget that displays the local date and/or time.','themeidol-all-widget')),
'tabslogin'=>array('0',__('Tabbed Login','themeidol-all-widget'),__('Easily add an beautiful tabbed login widget to your site\'s sidebar.">All in one widget Pro for more details','themeidol-all-widget')),
'postslider'=>array('0',__('Post Slider','themeidol-all-widget'),__('Widget Post Slider to display posts image in a slider from category.Please Upgrade to Pro','themeidol-all-widget')),
'facebookTabs'=>array('0',__('Facebook Tabs','themeidol-all-widget'),__('Responsive Facebook Tabs for WordPress. Displays - Facebook Likebox, Facebook Streams, Facebook Activity.Please Upgrade to Pro','themeidol-all-widget')),
'splw'=>array('0',__('Smart Posts','themeidol-all-widget'),__('A widget that displays posts from a specific category/tag/author.Please Upgrade to Pro','themeidol-all-widget')),
'socialcount'=>array('0',__('Social Count','themeidol-all-widget'),__('A widget that displays social count and followers in sidebar.Please Upgrade to Pro','themeidol-all-widget')),
'verticalslider'=>array('0',__('Vertical Slider','themeidol-all-widget'),__('Display latest posts or posts of specific category, which will be used as the vertical slider.Please Upgrade to Pro','themeidol-all-widget')),
'featuredverticalposts'=>array('0',__('Features Posts','themeidol-all-widget'),__('Display latest posts or posts of specific category.Please Upgrade to Pro','themeidol-all-widget')),
'contactinfo'=>array('0',__('Contact Info','themeidol-all-widget'),__('This widget is used to display contact information with map. Only available in premium plugin.Please Upgrade to Pro','themeidol-all-widget')),
);
$this->widgets = apply_filters( 'themeidol_widgets_array', $widgetsArray );
$this->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' ) );
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_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);
// Get and disable the sidebar widgets.
add_action( 'widgets_init', array( $this, 'set_default_sidebar_widgets' ), 100 );
add_action( 'widgets_init', array( $this, 'disable_sidebar_widgets' ), 100 );
// aditional links in plugin description
add_filter('plugin_row_meta', array( $this, 'themeidol_meta_links'), 10, 2);
// enqueue admin scripts
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 100);
add_action('customize_controls_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
}
/**
* 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' );
}
}
/**
* Set the default sidebar widgets.
*
* @return array Sidebar widgets.
*/
public function set_default_sidebar_widgets() {
global $wp_registered_widgets;
$widgets = array();
if ( ! empty( $GLOBALS['wp_widget_factory'] ) ) {
$widgets = $GLOBALS['wp_widget_factory']->widgets;
}
/**
* Filters the available sidebar widgets.
*
* @param array $widgets The globally available sidebar widgets.
*/
$this->sidebar_widgets = apply_filters( 'themeidol_widgets_all_array', $widgets );
$WPdefault=array_merge($GLOBALS['_wp_deprecated_widgets_callbacks'],array('wp_nav_menu_widget','wp_widget_recent_posts' ));
foreach ( $this->sidebar_widgets as $id => $widget_object ) {
// Now here we need to filter the WP default widgets only
$id_base=esc_attr( $id );
if(in_array( strtolower(esc_attr( $id )) , $WPdefault)){
$default[esc_attr( $id ) ]=array('0','(WP)'.esc_html( $widget_object->name ),esc_html( $widget_object->widget_options['description'] ));
}
}
$this->default=apply_filters( 'themeidol_widgets_default_array', $default );
}
/*
* 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() {
//$this->set_default_sidebar_widgets();
$this->themeidol_load_widgets();
}
/*
* Function to include widget Classes
*
*/
public function themeidol_load_widgets() {
$widgets_include = array();
$themeidol_options = get_option('themeidol_options');
$themeidol_default_option = array(
"advert" => '1',
"flickr" => '0',
"recent" => '1',
"tweet" => '0',
"social" => '1',
"author" => '0',
"stylist" => '1',
"facebook" => '0',
"ajaxsearch" => '1',
"tabs" => '0',
"instagram" => '0',
"site2quotes" => '1',
"rssfeed" => '0',
"dataandtime"=> '1'
);
if (false === $themeidol_options) {
$themeidol_options = $themeidol_default_option;
}
foreach ( $this->glob_php( dirname( __FILE__ ) . '/widgets' ) as $file ) {
$widgets_include[] = $file;
}
/**
* Modify which Themeidol Widgets to register.
*
* @module widgets
*
* @since 1.0
*
* @param array $widgets_include An array of widgets to be registered.
*/
$widgets_include = apply_filters( 'themeidol_widgets_to_include', $widgets_include );
$widgetname=array();
foreach( $widgets_include as $include ) {
//Explode file name
if($include!=""):
$file = basename($include, ".php"); // $file is set to "widget_aba"
$widgetname=explode("-",$file);
$wname=$widgetname[1];
// echo "TEST:".$widgetname[1].'
';
if($wname!=""):
if (isset($themeidol_options[$wname]) && $themeidol_options[$wname] == 1):
include $include;
endif;
endif;
endif;
}
}
/**
* Disable Sidebar Widgets.
*
* Gets the list of disabled sidebar widgets and disables
* them for you in WordPress.
*
* @since 1.0.0
*/
public function disable_sidebar_widgets() {
// Enable/Disable other WP default Widgets
$themeidol_options = get_option('themeidol_options');
foreach( $this->default as $key => $value ) {
if (!isset($themeidol_options[$key]) && $themeidol_options[$key] != 1):
unregister_widget( $key );
endif;
}
}
/**
* Returns an array of all PHP files in the specified absolute path.
* Equivalent to glob( "$absolute_path/*.php" ).
*
* @param string $absolute_path The absolute path of the directory to search.
* @return array Array of absolute paths to the PHP files.
*/
public function glob_php( $absolute_path ) {
if ( function_exists( 'glob' ) ) {
return glob( "$absolute_path/*.php" );
}
$absolute_path = untrailingslashit( $absolute_path );
$files = array();
if ( ! $dir = @opendir( $absolute_path ) ) {
return $files;
}
while ( false !== $file = readdir( $dir ) ) {
if ( '.' == substr( $file, 0, 1 ) || '.php' != substr( $file, -4 ) ) {
continue;
}
$file = "$absolute_path/$file";
if ( ! is_file( $file ) ) {
continue;
}
$files[] = $file;
}
closedir( $dir );
return $files;
}
/**
* 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 '