<?php wpfp_link(); ?> where ever you want on a single post. Then create a page which includes that text : {{wp-favorite-posts}} That's it!
Version: 1.4.3
Author: Huseyin Berberoglu
Author URI: http://nxsn.com
*/
/*
Copyright (c) 2009 Hüseyin Berberoğlu (hberberoglu@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
";
}
function wpfp_before_link_img() {
$options = wpfp_get_options();
$option = $options['before_image'];
if ($option == '') {
return "";
} else if ($option == 'custom') {
return "";
} else {
return "
";
}
}
function wpfp_clear_favorites() {
if (wpfp_get_cookie()):
foreach (wpfp_get_cookie() as $post_id => $val) {
wpfp_set_cookie($post_id, "");
wpfp_update_post_meta($post_id, -1);
}
endif;
if (is_user_logged_in()) {
$favorite_post_ids = wpfp_get_user_meta();
if ($favorite_post_ids):
foreach ($favorite_post_ids as $post_id) {
wpfp_update_post_meta($post_id, -1);
}
endif;
if (!delete_usermeta(wpfp_get_user_id(), WPFP_META_KEY)) {
return false;
}
}
return true;
}
function wpfp_do_remove_favorite($post_id) {
$a = true;
if (is_user_logged_in()) {
$user_favorites = wpfp_get_user_meta();
$user_favorites = array_diff($user_favorites, array($post_id));
$user_favorites = array_values($user_favorites);
$a = wpfp_update_user_meta($user_favorites);
}
if ($a) $a = wpfp_set_cookie($_REQUEST['postid'], "");
return $a;
}
function wpfp_content_filter($content) {
if (is_page()):
if (strpos($content,'{{wp-favorite-posts}}')!== false) {
return str_replace('{{wp-favorite-posts}}', wpfp_list_favorite_posts(), $content);
}
endif;
#if (is_single()):
if (strpos($content,'[wpfp-link]')!== false) {
return str_replace('[wpfp-link]', wpfp_link(1), $content);
}
#endif;
return $content;
}
add_filter('the_content','wpfp_content_filter',7);
function wpfp_shortcode_func() {
wpfp_list_favorite_posts();
}
add_shortcode('wp-favorite-posts', 'wpfp_shortcode_func');
function wpfp_add_js_script ( ) {
echo '' . "\n";
wp_enqueue_script( "wp-favroite-posts", WPFP_PATH . "/wpfp.js", array( 'jquery' ) );
}
add_action('wp_print_scripts', 'wpfp_add_js_script');
function wpfp_init() {
$wpfp_options = array();
$wpfp_options['add_favorite'] = "Add to favorites";
$wpfp_options['added'] = "Added to favorites!";
$wpfp_options['remove_favorite'] = "Remove from favorites";
$wpfp_options['removed'] = "Removed from favorites!";
$wpfp_options['clear'] = "Clear favorites";
$wpfp_options['cleared'] = "
Favorites cleared!
"; $wpfp_options['favorites_empty'] = "Favorite list is empty."; $wpfp_options['cookie_warning'] = "Your favorite posts saved to your browsers cookies. If you clear cookies also favorite posts will be deleted."; $wpfp_options['rem'] = "remove"; $wpfp_options['text_only_registered'] = "Only registered users can favorite!"; $wpfp_options['statics'] = 1; $wpfp_options['widget_title'] = ''; $wpfp_options['widget_limit'] = 5; $wpfp_options['before_image'] = 'star.png'; $wpfp_options['custom_before_image'] = ''; add_option('wpfp_options', $wpfp_options, 'Favorite Posts Options'); } add_action('activate_wp-favorite-posts/wp-favorite-posts.php', 'wpfp_init'); function wpfp_config() { include('wpfp-admin.php'); } function wpfp_config_page() { if ( function_exists('add_submenu_page') ) add_options_page(__('Favorite Posts'), __('Favorite Posts'), 'manage_options', 'wp-favorite-posts', 'wpfp_config'); } add_action('admin_menu', 'wpfp_config_page'); function wpfp_update_user_meta($arr) { return update_usermeta(wpfp_get_user_id(),WPFP_META_KEY,$arr); } function wpfp_update_post_meta($post_id, $val) { $val = wpfp_get_post_meta($post_id) + $val; return add_post_meta($post_id, WPFP_META_KEY, $val, true) or update_post_meta($post_id, WPFP_META_KEY, $val); } function wpfp_delete_post_meta($post_id) { return delete_post_meta($post_id, WPFP_META_KEY); } function wpfp_list_most_favorited($limit=5) { global $wpdb; $query = "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key='".WPFP_META_KEY."' AND meta_value > 0 ORDER BY CAST(meta_value AS DECIMAL) DESC LIMIT 0, $limit"; $results = $wpdb->get_results($query); if ($results) { echo "
You must enable statics from favorite posts configuration page.
ID; } function wpfp_get_user_meta($user = "") { if (!empty($user)): $userdata = get_userdatabylogin($user); $user_id = $userdata->ID; return get_usermeta($user_id, WPFP_META_KEY); else: return get_usermeta(wpfp_get_user_id(), WPFP_META_KEY); endif; } function wpfp_get_post_meta($post_id) { $val = get_post_meta($post_id, WPFP_META_KEY, true); if ($val < 0) $val = 0; return $val; } function wpfp_set_cookie($post_id, $str) { $expire = time()+60*60*24*30; return setcookie("wp-favorite-posts[$post_id]", $str, $expire, "/"); } function wpfp_is_user_favlist_public($user) { $user_opts = wpfp_get_user_options($user); if ($user_opts['list_is_public']) return true; else return false; } function wpfp_get_user_options($user) { $userdata = get_userdatabylogin($user); $user_id = $userdata->ID; return get_usermeta($user_id, WPFP_USER_OPTION_KEY); } function wpfp_is_user_can_edit() { if ($_REQUEST['user']) return false; return true; } function wpfp_remove_favorite_link($post_id) { if (wpfp_is_user_can_edit()) { $wpfp_options = wpfp_get_options(); $class = 'wpfp-link remove-parent'; echo "[".$wpfp_options['rem']."]"; } } function wpfp_clear_list_link() { if (wpfp_is_user_can_edit()) { $wpfp_options = wpfp_get_options(); echo wpfp_before_link_img(); echo wpfp_loading_img(); echo "". $wpfp_options['clear'] . ""; } } function wpfp_cookie_warning() { if (!is_user_logged_in() && !isset($_GET['user']) ): echo "".$wpfp_options['cookie_warning']."
"; endif; }