. */ /* Stop direct call */ if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) die('Sorry, you don\'t have direct access to this page.'); define( 'RPW_PATH', plugin_dir_path(__FILE__) ); if (!class_exists('A5_Image')) require_once RPW_PATH.'class-lib/A5_ImageClass.php'; if (!class_exists('A5_Excerpt')) require_once RPW_PATH.'class-lib/A5_ExcerptClass.php'; if (!class_exists('A5_Recent_Post_Widget')) require_once RPW_PATH.'class-lib/RPW_WidgetClass.php'; if (!class_exists('A5_FormField')) require_once RPW_PATH.'class-lib/A5_FormFieldClass.php'; if (!class_exists('A5_OptionPage')) require_once RPW_PATH.'class-lib/A5_OptionPageClass.php'; if (!class_exists('A5_DynamicCSS')) require_once RPW_PATH.'class-lib/A5_DynamicCSSClass.php'; class RecentPostWidget { const language_file = 'a5-recent-posts'; private static $options; function __construct() { self::$options = get_option('rpw_options'); register_activation_hook( __FILE__, array($this, 'install') ); register_deactivation_hook( __FILE__, array($this, 'uninstall') ); add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); add_filter('plugin_row_meta', array($this, 'register_links'), 10, 2); add_filter('plugin_action_links', array($this, 'register_action_links'), 10, 2); add_action('admin_init', array($this, 'register_settings')); add_action('admin_menu', array($this, 'add_settings_page')); // import laguage files load_plugin_textdomain(self::language_file, false , basename(dirname(__FILE__)).'/languages'); $dynamic_css = new A5_DynamicCSS; $eol = "\r\n"; $tab = "\t"; $css_selector = '.widget_a5_recent_post_widget[id^="a5_recent_post_widget"]'; A5_DynamicCSS::$styles .= $eol.'/* CSS portion of the A5 Recent Post Widget */'.$eol.$eol; $style = '-moz-hyphens: auto;'.$eol.$tab.'-o-hyphens: auto;'.$eol.$tab.'-webkit-hyphens: auto;'.$eol.$tab.'-ms-hyphens: auto;'.$eol.$tab.'hyphens: auto;'; if (!empty(self::$options['rpw_css'])) $style.=$eol.$tab.str_replace('; ', ';'.$eol.$tab, str_replace(array("\r\n", "\n", "\r"), ' ', self::$options['rpw_css'])); A5_DynamicCSS::$styles.='div'.$css_selector.','.$eol.'li'.$css_selector.','.$eol.'aside'.$css_selector.' {'.$eol.$tab.$style.$eol.'}'.$eol; A5_DynamicCSS::$styles.='div'.$css_selector.' img,'.$eol.'li'.$css_selector.' img,'.$eol.'aside'.$css_selector.' img {'.$eol.$tab.'height: auto;'.$eol.$tab.'max-width: 100%;'.$eol.'}'.$eol; if (!empty (self::$options['link'])) : $style=str_replace('; ', ';'.$eol.$tab, str_replace(array("\r\n", "\n", "\r"), ' ', self::$options['link'])); A5_DynamicCSS::$styles.='div'.$css_selector.' a,'.$eol.'li'.$css_selector.' a,'.$eol.'aside'.$css_selector.' a {'.$eol.$tab.$style.$eol.'}'.$eol; endif; if (!empty (self::$options['hover'])) : $style=str_replace('; ', ';'.$eol.$tab, str_replace(array("\r\n", "\n", "\r"), ' ', self::$options['hover'])); A5_DynamicCSS::$styles.='div'.$css_selector.' a:hover,'.$eol.'li'.$css_selector.' a:hover,'.$eol.'aside'.$css_selector.' a:hover {'.$eol.$tab.$style.$eol.'}'.$eol; endif; } /* attach JavaScript file for textarea resizing */ function enqueue_scripts($hook) { if ($hook != 'widgets.php' && $hook != 'settings_page_a5-recent-posts-settings') return; wp_register_script('ta-expander-script', plugins_url('ta-expander.js', __FILE__), array('jquery'), '3.0', true); wp_enqueue_script('ta-expander-script'); } //Additional links on the plugin page function register_links($links, $file) { $base = plugin_basename(__FILE__); if ($file == $base) { $links[] = ''.__('FAQ', self::language_file).''; $links[] = ''.__('Donate', self::language_file).''; } return $links; } function register_action_links( $links, $file ) { $base = plugin_basename(__FILE__); if ($file == $base) array_unshift($links, ''.__('Settings', self::language_file).''); return $links; } // init function register_settings() { register_setting( 'rpw_options', 'rpw_options', array($this, 'validate') ); add_settings_section('rpw_settings', __('Styling of the links', self::language_file), array($this, 'display_section'), 'rpw_styles'); add_settings_field('rpw_link_style', __('Link style:', self::language_file), array($this, 'link_field'), 'rpw_styles', 'rpw_settings'); add_settings_field('rpw_hover_style', __('Hover style:', self::language_file), array($this, 'hover_field'), 'rpw_styles', 'rpw_settings'); add_settings_field('use_own_css', __('Widget container:', self::language_file), array($this, 'rpw_display_css'), 'rpw_styles', 'rpw_settings', array(__('You can enter your own style for the widgets here. This will overwrite the styles of your theme.', self::language_file), __('If you leave this empty, you can still style every instance of the widget individually.', self::language_file))); add_settings_field('rpw_resize', false, array($this, 'resize_field'), 'rpw_styles', 'rpw_settings'); } function display_section() { echo '
'.__('Just put some css code here.', self::language_file).'
'; } function link_field() { a5_textarea('link', 'rpw_options[link]', @self::$options['link'], false, array('cols' => 35, 'rows' => 3)); } function hover_field() { a5_textarea('hover', 'rpw_options[hover]', @self::$options['hover'], false, array('cols' => 35, 'rows' => 3)); } function rpw_display_css($labels) { echo $labels[0].''.$labels[1].''; a5_textarea('rpw_css', 'rpw_options[rpw_css]', @self::$options['rpw_css'], false, array('rows' => 10, 'cols' => 35)); } function resize_field() { a5_resize_textarea(array('link', 'hover', 'rpw_css'), true); } // Creating default options on activation function install() { $default = array( 'tags' => array(), 'sizes' => array() ); add_option('rpw_options', $default); } // Cleaning on deactivation function uninstall() { delete_option('rpw_options'); } // Installing options page function add_settings_page() { $pages=add_options_page('A5 Recent Post '.__('Settings', self::language_file), 'font-weight: bold;
color: #0000ff;
text-decoration: underline;