. */ /* 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 resizing */ function afpw_js_sheet() { wp_enqueue_script('ta-expander-script', plugins_url('ta-expander.js', __FILE__), array('jquery'), '2.0', 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. 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']); $noshorts = esc_attr($instance['noshorts']); $readmore = esc_attr($instance['readmore']); $rmtext = esc_attr($instance['rmtext']); $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']); $features = get_posts('numberposts=-1'); ?>













'; $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"'; global $wp_query; $afpw_post_id = get_post($instance['article']); $afpw_post_name = $afpw_post_id->post_name; $afpw_post = ($instance['article'] == $wp_query->get( 'p' ) || $afpw_post_name == $wp_query->get ( 'name' )) ? 'p='.$instance['backup'] : 'p='.$instance['article']; if ($afpw_post=='p=') $afpw_post = 'numberposts=1&orderby=rand'; /* 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); $afpw_args = array( 'post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post->ID ); $afpw_attachments = get_posts( $afpw_args ); if ( $afpw_attachments ) { foreach ( $afpw_attachments as $attachment ) $afpw_image_alt = trim(strip_tags( get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true) )); $afpw_image_title = trim(strip_tags( $attachment->post_title )); } $afpw_title_tag = __('Permalink to', 'advanced-fpw').' '.$post->post_title; // post tile above thumbnail if (!$instance['subtitle']) { ?>

title="">

/i', do_shortcode($post->post_content), $matches); $afpw_thumb = $matches [1] [0]; if ($afpw_thumb) { $host_string = 'http://' . $_SERVER['HTTP_HOST']; if (empty($afpw_image_title)) $afpw_image_title = $post->post_title; if (empty($afpw_image_alt)) $afpw_image_alt = $post->post_title; $afpw_x = $instance['width']; if (strncmp($afpw_thumb, $host_string, strlen($host_string)) == 0) { $realfilepath = $_SERVER['DOCUMENT_ROOT'] . urldecode(substr($afpw_thumb, strlen($host_string))); } else { $realfilepath = $afpw_thumb; } if (file_exists($realfilepath)) { $afpw_size = getimagesize($realfilepath); if (!empty($stw_x)) $afpw_y = intval($afpw_size[1] / ($afpw_size[0] / $afpw_x)); } echo '' . $afpw_image_alt . ''; }} else { if (function_exists('has_post_thumbnail')) { if (has_post_thumbnail() && !$instance['thumb']) { ?>

title="">

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 = trim(preg_replace('/\s\s+/', ' ', str_replace(array("\r\n", "\n", "\r", " "), ' ', strip_tags(preg_replace('/\[caption(.*?)\[\/caption\]/', '', get_the_content()))))); if ($instance['noshorts']) $afpw_text=strip_shortcodes($afpw_text); $afpw_short=array_slice(preg_split("/([\t.!?]+)/", $afpw_text, -1, PREG_SPLIT_DELIM_CAPTURE), 0, 6); $afpw_excerpt=implode($afpw_short); } /* do we want the read more link and do we have text for it? */ if ($instance['readmore']) { $afpw_rmtext=$instance['rmtext']; if (!$afpw_rmtext) $afpw_rmtext='[…]'; $afpw_excerpt.=' '.$afpw_rmtext.''; } echo '

'.do_shortcode($afpw_excerpt).'

'; endforeach; echo $afpw_after_widget; }} } 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 ''; } function afpw_hover_field() { $afpw_options = get_option('afpw_options'); echo ''; } // 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() { $pages=add_options_page(__('Advanced FP Settings', 'advanced-fpw'), 'Advanced Featured Post Widget', 'administrator', 'advanced-fpw-settings', 'advanced_fpw_options_page'); add_action('admin_print_scripts-'.$pages, 'afpw_js_sheet'); } // Calling the options page function advanced_fpw_options_page() { ?>

font-weight: bold;
color: #0000ff;
text-decoration: underline;

add_query_var('afpwfile'); } add_action('template_redirect','afpw_css_template'); function afpw_css_template() { if (get_query_var('afpwfile') == 'css') { header('Content-type: text/css'); echo afpw_write_css(); exit; } } add_action ('wp_print_styles', 'afpw_css'); function afpw_css () { $afpw_options = get_option('afpw_options'); if (count ($afpw_options)!=0 && !empty ($afpw_options)) { $afpw_css_file=get_bloginfo('url')."/?afpwfile=css"; wp_register_style('advanced-fpw', $afpw_css_file, false, '2.1', 'all'); wp_enqueue_style('advanced-fpw'); } } // writing css file function afpw_write_css() { $afpw_styles=get_option('afpw_options'); $css_text="@charset \"UTF-8\";\r\n/* CSS Document */\r\n\r\n"; if (!empty($afpw_styles['link'])) { $afpw_link=str_replace(array("\r\n", "\n", "\r"), ' ', $afpw_styles['link']); $css_text.='.afpwlink {'.$afpw_link.'}\r\n'; } if (!empty($afpw_styles['hover'])) { $afpw_hover=str_replace(array("\r\n", "\n", "\r"), ' ', $afpw_styles['hover']); $css_text.='.afpwlink:hover {'.$afpw_hover.'}'; } return $css_text; } ?>