. */ /* Stop direct call */ if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die("Sorry, you don't have direct access to this page."); } /* attach JavaScript file for textarea reszing */ $afpw_path = WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)).'/'; function afpw_js_sheet() { global $afpw_path; wp_enqueue_script('ta-resize-script', $afpw_path.'ta-expander.js', false, false, true); } add_action('admin_print_scripts-widgets.php', 'afpw_js_sheet'); //Additional links on the plugin page add_filter('plugin_row_meta', 'afpw_register_links',10,2); function afpw_register_links($links, $file) { $base = plugin_basename(__FILE__); if ($file == $base) { $links[] = ''.__('Settings','advanced-fpw').''; $links[] = ''.__('FAQ','advanced-fpw').''; $links[] = ''.__('Donate','advanced-fpw').''; } return $links; } // extending the widget class class Advanced_Featured_Post_Widget extends WP_Widget { function Advanced_Featured_Post_Widget() { $widget_opts = array( 'description' => __('You can feature a certain post in this widget and display it, where and however you want, in your widget areas. The ID of a backup post can be given to avoid dubble content. Define, on what pages the widget will show.', 'advanced-fpw') ); $control_opts = array( 'width' => 400 ); parent::WP_Widget(false, $name = 'Advanced Featured Post', $widget_opts, $control_opts); } function form($instance) { // setup some default settings $defaults = array( 'homepage' => true, 'category' => true ); $instance = wp_parse_args( (array) $instance, $defaults ); $title = esc_attr($instance['title']); $thumb = esc_attr($instance['thumb']); $image = esc_attr($instance['image']); $article = esc_attr($instance['article']); $backup = esc_attr($instance['backup']); $width = esc_attr($instance['width']); $subtitle = esc_attr($instance['subtitle']); $excerpt = esc_attr($instance['excerpt']); $style = esc_attr($instance['style']); $homepage=esc_attr($instance['homepage']); $frontpage=esc_attr($instance['frontpage']); $page=esc_attr($instance['page']); $category=esc_attr($instance['category']); $single=esc_attr($instance['single']); $date=esc_attr($instance['date']); $tag=esc_attr($instance['tag']); $attachment=esc_attr($instance['attachment']); $taxonomy=esc_attr($instance['taxonomy']); $author=esc_attr($instance['author']); $search=esc_attr($instance['search']); $not_found=esc_attr($instance['not_found']); if (empty($style)) { $style_height=25; } else { $afpw_elements=str_replace(array("\r\n", "\n", "\r"), '|', $style); $style_height=count(explode('|', $afpw_elements))*21; } if (empty($excerpt)) { $excerpt_height=25; } else { $afpw_elements=str_replace(array("\r\n", "\n", "\r"), '|', $excerpt); $excerpt_height=count(explode('|', $afpw_elements))*21; } ?>
"; $afpw_after_widget=""; } echo $afpw_before_widget; if ( $title ) { echo $before_title . $title . $after_title; } $afpw_options = get_option('afpw_options'); if (count ($afpw_options)!=0 && !empty ($afpw_options)) { $afpw_class=" class=\"afpwlink\""; $afpw_stylesheet = WP_PLUGIN_DIR . '/advanced-featured-post-widget/advanced-fpw.css'; $afpw_css_content = file_get_contents($afpw_stylesheet); if (empty($afpw_css_content)) { afpw_write_stylesheet($afpw_options); } } global $wp_query; $afpw_post_id = get_post($instance['article']); $afpw_post_name = $afpw_post_id->post_name; if ($instance['article'] == $wp_query->get( 'p' ) || $afpw_post_name == $wp_query->get ( 'name' )) { $afpw_post = 'p='.$instance['backup']; } else { $afpw_post = 'p='.$instance['article']; } /* This is the actual function of the plugin, it fills the widget with the customized post */ global $post; $afpw_posts = get_posts($afpw_post); foreach($afpw_posts as $post) : setup_postdata($post); // post tile above thumbnail if (!$instance['subtitle']) { ?> /i', $post->post_content, $matches); $afpw_thumb = $matches [1] [0]; if ($afpw_thumb) { $afpw_image_title=$post->get_the_title; $afpw_size=getimagesize($afpw_thumb); $afpw_x=$instance['width']; $afpw_y=intval($afpw_size[1]/($afpw_size[0]/$afpw_x)); ?> "; ?> post_excerpt; } /* in case the excerpt is not definded by theme or anything else, the first 3 sentences of the content are given */ if (!$afpw_excerpt) { $afpw_text=preg_replace('/\[caption(.*?)\[\/caption\]/', '', get_the_content()); $afpw_short=array_slice(preg_split("/([\t.!?]+)/", $afpw_text, -1, PREG_SPLIT_DELIM_CAPTURE), 0, 6); $afpw_excerpt=implode($afpw_short); } echo "
".$afpw_excerpt."
"; endforeach; echo $afpw_after_widget; }} } // writing css to file function afpw_write_stylesheet($afpw_styles) { $afpw_link=str_replace(array("\r\n", "\n", "\r"), '', $afpw_styles['link']); $afpw_hover=str_replace(array("\r\n", "\n", "\r"), '', $afpw_styles['hover']); $afpw_stylesheet = WP_PLUGIN_DIR . '/advanced-featured-post-widget/advanced-fpw.css'; $afpw_link_style=".afpwlink {".$afpw_link."}\r\n.afpwlink:hover {".$afpw_hover."}"; $fp = fopen( $afpw_stylesheet, "w" ); fwrite ($fp, $afpw_link_style); fclose ($fp); } add_action('widgets_init', create_function('', 'return register_widget("Advanced_Featured_Post_Widget");')); // import laguage files load_plugin_textdomain('advanced-fpw', false , basename(dirname(__FILE__)).'/languages'); // init add_action('admin_init', 'afpw_init'); function afpw_init() { register_setting( 'afpw_options', 'afpw_options', 'afpw_validate' ); add_settings_section('afpw_settings', __('Styling of the links', 'advanced-fpw'), 'afpw_display_section', 'afpw_styles'); add_settings_field('afpw_link_style', __('Link style:', 'advanced-fpw'), 'afpw_link_field', 'afpw_styles', 'afpw_settings'); add_settings_field('afpw_hover_style', __('Hover style:', 'advanced-fpw'), 'afpw_hover_field', 'afpw_styles', 'afpw_settings'); } function afpw_display_section() { echo ''.__('Just put some css code here.', 'advanced-fpw').'
'; } function afpw_link_field() { $afpw_options = get_option('afpw_options'); echo "".$afpw_options['link'].""; } function afpw_hover_field() { $afpw_options = get_option('afpw_options'); echo "".$afpw_options['hover'].""; } // Cleaning on deactivation register_deactivation_hook( __FILE__, 'unset_afpw' ); function unset_afpw() { delete_option('afpw_options'); } // Installing options page add_action('admin_menu', 'afpw_admin_menu'); function afpw_admin_menu() { add_options_page(__('Advanced FP Settings', 'advanced-fpw'), 'Advanced Featured Post Widget', 'administrator', 'advanced-fpw-settings', 'advanced_fpw_options_page'); } // Calling the options page function advanced_fpw_options_page() { ?>
font-weight: bold;
color: #0000ff;
text-decoration: underline;