示例#1
0
/**
* Get the favorite button
* @param $post_id int, defaults to current post
* @param $site_id int, defaults to current blog/site
* @return html
*/
function get_favorites_button($post_id = null, $site_id = null)
{
    global $blog_id;
    if (!$post_id) {
        $post_id = get_the_id();
    }
    $site_id = is_multisite() && is_null($site_id) ? $blog_id : $site_id;
    if (!is_multisite()) {
        $site_id = 1;
    }
    $button = new FavoriteButton($post_id, $site_id);
    return $button->display();
}
 /**
  * Add the post type to each favorite
  */
 private function addPostData()
 {
     $this->checkCurrentPost();
     foreach ($this->formatted_favorites as $site => $site_favorites) {
         foreach ($site_favorites['posts'] as $key => $favorite) {
             $site_id = $this->formatted_favorites[$site]['site_id'];
             $this->formatted_favorites[$site]['posts'][$key]['post_type'] = get_post_type($key);
             $this->formatted_favorites[$site]['posts'][$key]['title'] = get_the_title($key);
             $this->formatted_favorites[$site]['posts'][$key]['permalink'] = get_the_permalink($key);
             $this->formatted_favorites[$site]['posts'][$key]['total'] = $this->counter->getCount($key, $site_id);
             $button = new FavoriteButton($key, $site_id);
             $this->formatted_favorites[$site]['posts'][$key]['button'] = $button->display(false);
         }
         $this->formatted_favorites[$site] = array_reverse($this->formatted_favorites[$site]);
     }
 }
示例#3
0
 /**
  * Return an HTML list of favorites for specified user
  * @param $include_button boolean - whether to include the favorite button
  */
 public function getFavoritesList($include_button = false)
 {
     if (is_null($this->site_id) || $this->site_id == '') {
         $this->site_id = get_current_blog_id();
     }
     $favorites = $this->getFavoritesArray();
     $no_favorites = $this->settings_repo->noFavoritesText();
     // Post Type filters for data attr
     $post_types = '';
     if (isset($this->filters['post_type'])) {
         $post_types = implode(',', $this->filters['post_type']);
     }
     if (is_multisite()) {
         switch_to_blog($this->site_id);
     }
     $out = '<ul class="favorites-list" data-userid="' . $this->user_id . '" data-links="true" data-siteid="' . $this->site_id . '" ';
     $out .= $include_button ? 'data-includebuttons="true"' : 'data-includebuttons="false"';
     $out .= $this->links ? ' data-includelinks="true"' : ' data-includelinks="false"';
     $out .= ' data-nofavoritestext="' . $no_favorites . '"';
     $out .= ' data-posttype="' . $post_types . '"';
     $out .= '>';
     foreach ($favorites as $key => $favorite) {
         $out .= '<li data-postid="' . $favorite . '">';
         if ($include_button) {
             $out .= '<p>';
         }
         if ($this->links) {
             $out .= '<a href="' . get_permalink($favorite) . '">';
         }
         $out .= get_the_title($favorite);
         if ($this->links) {
             $out .= '</a>';
         }
         if ($include_button) {
             $button = new FavoriteButton($favorite, $this->site_id);
             $out .= '</p><p>';
             $out .= $button->display(false) . '</p>';
         }
         $out .= '</li>';
     }
     if (empty($favorites)) {
         $out .= '<li data-postid="0" data-nofavorites>' . $no_favorites . '</li>';
     }
     $out .= '</ul>';
     if (is_multisite()) {
         restore_current_blog();
     }
     return $out;
 }