Skip to content

Commit

Permalink
* Added new [reader-posts-grid] shortcode
Browse files Browse the repository at this point in the history
* Improved shortcode handling in reader posts
* Other small improvements
  • Loading branch information
Mariusz Misiek committed Dec 16, 2016
1 parent 37ebb7e commit a0992ea
Show file tree
Hide file tree
Showing 27 changed files with 1,129 additions and 160 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Expand Up @@ -4,6 +4,11 @@ Lead developer: Maniu

== Changelog ==

= 1.2.5 =
* Added new [reader-posts-grid] shortcode
* Improved shortcode handling in reader posts
* Other small improvements

= 1.2 =
* Added lists to easily group followed sites
* Added user's private sites to post lists even when blocked
Expand Down
2 changes: 1 addition & 1 deletion dash-notice
Submodule dash-notice updated from bda258 to f4fa6c
3 changes: 3 additions & 0 deletions msreader-files/css/admin.css
Expand Up @@ -158,6 +158,9 @@
.msreader-post-content {
background: #fff;
}
.msreader-post-content h2 {
font-weight: bold !important;
}
.msreader-post-content img {
max-width: 100%;
height: auto;
Expand Down
43 changes: 26 additions & 17 deletions msreader-files/includes/modules.php
Expand Up @@ -11,7 +11,7 @@ abstract class WMD_MSReader_Modules {
var $limit;
var $limit_sample;
var $args;
var $cache_init;
var $cache_init = 1;
var $main = 0;
var $query_hashes = array();
var $user;
Expand Down Expand Up @@ -52,6 +52,8 @@ function __construct($options = array(), $slug) {
$this->details['can_be_default'] = true;
if(!isset($this->details['global_cache']))
$this->details['global_cache'] = false;
if(!isset($this->details['blog_specific_cache']))
$this->details['blog_specific_cache'] = false;
if(!isset($this->details['disable_cache']))
$this->details['disable_cache'] = false;
if(!isset($this->details['cache_time']))
Expand All @@ -60,6 +62,8 @@ function __construct($options = array(), $slug) {
$this->details['default'] = 'other';
if(!is_array($this->details['type']))
$this->details['type'] = array($this->details['type']);
if(!isset($this->details['allow_count']))
$this->details['allow_count'] = false;

//set DB details
$this->db_network_posts = apply_filters('msreader_db_network_posts', $wpdb->base_prefix.'network_posts');
Expand Down Expand Up @@ -130,20 +134,13 @@ function get_excerpt($post) {
$max_sentences = 5;
$max_paragraphs = 3;

if(!shortcode_exists('gallery')) {
add_shortcode( 'gallery' , create_function('', 'return false;'));
$fake_gallery_shortcode_added = 1;
}
$post_content = strip_shortcodes( $post->post_content );

if(isset($fake_gallery_shortcode_added))
remove_shortcode( 'gallery' );
$post_content = preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', $post->post_content);

if(class_exists('DOMDocument')) {
$allowed_tags = array('<strong>','<blockquote>','<em>','<p>', '<span>', '<a>');

$post_content = wpautop(strip_tags($post_content, implode('', $allowed_tags)));

$dom = new DOMDocument();
$dom->loadHTML('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>'.$post_content.'</body></html>');
$elements = $dom->documentElement;
Expand Down Expand Up @@ -284,15 +281,26 @@ function get_limit($limit = 0, $page = 0) {
return 'LIMIT 0,10';
}

function get_allowed_sites() {
$allowed_sites = apply_filters('msreader_allowed_sites', array(), $this->args, $this->details['slug']);
//lets get max 250 newest unique numbers(blog_ids) only
$allowed_sites = array_unique($allowed_sites);
$allowed_sites = array_filter($allowed_sites, 'is_numeric');
arsort($allowed_sites);
$allowed_sites = array_slice($allowed_sites, 0, 250);

return $allowed_sites;
}

//get limit string
function get_public() {
$public = $this->helpers->is_public_only();

if($public) {
$allowed_sites = apply_filters('msreader_filter_blog_public_query_allowed_sites', 'public', $this->args, $this->details['slug']);
$allowed_sites = $this->get_allowed_sites(); //results are safe for query

if(is_array($allowed_sites) && count($allowed_sites) > 0 && array_filter($allowed_sites, 'is_int'))
$query_part = '(blogs.public = 1 OR posts.BLOG_ID IN('.implode(',', array_slice(array_unique($allowed_sites), 0, 50)).')) AND';
if(is_array($allowed_sites) && count($allowed_sites) > 0)
$query_part = '(blogs.public = 1 OR posts.BLOG_ID IN('.implode(',', $allowed_sites).')) AND';
elseif($allowed_sites == 'all')
$query_part = '';
else
Expand Down Expand Up @@ -411,10 +419,11 @@ function get_site_post_link($blog_id, $post_id) {
}

function get_user() {
if(!isset($this->user))
$this->user = get_current_user_id();
return (isset($this->user) && is_numeric($this->user)) ? $this->user : get_current_user_id();
}

return $this->user;
function get_blog() {
return (isset($this->blog) && is_numeric($this->blog)) ? $this->blog : get_current_blog_id();
}

function open_site_post() {
Expand Down
81 changes: 47 additions & 34 deletions msreader-files/includes/modules/follow.php
Expand Up @@ -10,7 +10,8 @@
'button_visibility' => 'both',
'button_visibility_for' => 'loggedin'
),
'type' => 'query'
'type' => 'query',
'allow_count' => true
);

class WMD_MSReader_Module_Follow extends WMD_MSReader_Modules {
Expand Down Expand Up @@ -72,7 +73,7 @@ function get_follow_button($blog_id, $content_type = false) {
else {
$text = __('Following', 'wmd_msreader');
$hover_text = __('Unfollow', 'wmd_msreader');
$class = ' following';
$class = ' following';
$manage_class = '';
}

Expand Down Expand Up @@ -275,9 +276,9 @@ function add_css_js() {

function follow_control(blog_id, post_id, action, button, frontend) {
if(!action && button && button.hasClass('following'))
var action = 'unfollow';
else
var action = 'follow';
var action = 'unfollow';
else
var action = 'follow';

if(blog_id && action) {
if(!frontend)
Expand Down Expand Up @@ -378,7 +379,7 @@ function list_control(blog_id, lists_ids, new_list_name, button) {
}

if(new_list_name.length)
msreader.refresh_sidebar();
msreader.refresh_sidebar();
}
else {
manage_form.find('.msreader-popup-content').html(response);
Expand Down Expand Up @@ -470,9 +471,9 @@ function follow_control($action = 0, $blog_id = 0) {
}
}

if(defined('DOING_AJAX') && isset($_POST['action']) && $_POST['action'] == 'msreader_follow_control')
die();
}
if(defined('DOING_AJAX') && isset($_POST['action']) && $_POST['action'] == 'msreader_follow_control')
die();
}

function list_control($blog_id = false, $lists_ids = array(), $new_list_name = '') {
$lists_ids = $lists_ids ? $lists_ids : (isset($this->args['lists_ids']) ? $this->args['lists_ids'] : array());
Expand Down Expand Up @@ -612,7 +613,7 @@ function list_manage() {
else {
$this->message_type = 0;
$this->message = sprintf(__( 'List already exists. You can manage it <a href="%s">here</a>.', 'wmd_msreader' ), $this->get_module_dashboard_url(array('action' => 'manage', 'follow_list' => $name_exists_key)));
}
}
}
}
}
Expand Down Expand Up @@ -761,17 +762,17 @@ function get_blog_ids_from_textarea($textarea) {

function add_widget($widgets) {
$this->user_follow_data = $this->get_user_follow_data();
$lists = array();

$lists = array();

$user_follow_data_lists = $this->user_follow_data['lists'];
asort($user_follow_data_lists, SORT_NATURAL);
foreach ($user_follow_data_lists as $list_id => $list_name) {
$link = $this->get_module_dashboard_url(array('action' => 'manage', 'follow_list' => $list_id));
$active = ($this->helpers->is_page_link_active($link)) ? 'class="active" ' : '';
$link = $this->get_module_dashboard_url(array('action' => 'manage', 'follow_list' => $list_id));
$active = ($this->helpers->is_page_link_active($link)) ? 'class="active" ' : '';

$lists[] = array('args' => $list_id,'title' => $list_name.'</a><a '.$active.'href="'.$link.'" title="'.__('Manage this list', 'wmd_msreader').'"><span class="msreader-widget-links-element msreader-widget-links-icon dashicons-admin-generic"></span>');
}
$lists[] = array('args' => $list_id,'title' => $list_name.'</a><a '.$active.'href="'.$link.'" title="'.__('Manage this list', 'wmd_msreader').'"><span class="msreader-widget-links-element msreader-widget-links-icon dashicons-admin-generic"></span>');
}

//this is element that will allow to create new lists
$lists[] =
Expand Down Expand Up @@ -814,14 +815,12 @@ function add_widget($widgets) {
}

function widget_recent_posts_add_arg_modules($arg_modules) {
if(is_user_logged_in()) {
$this->user_follow_data = $this->get_user_follow_data();
$user_follow_data_lists = $this->user_follow_data['lists'];
$this->user_follow_data = $this->get_user_follow_data();
$user_follow_data_lists = $this->user_follow_data['lists'];

asort($user_follow_data_lists, SORT_NATURAL);
foreach ($user_follow_data_lists as $list_id => $list_name) {
$arg_modules[] = array('class' => 'my_lists', 'value' => $this->details['slug'].'|'.$list_id, 'title' => __('My Lists', 'wmd_msreader').': '.$list_name);
}
asort($user_follow_data_lists, SORT_NATURAL);
foreach ($user_follow_data_lists as $list_id => $list_name) {
$arg_modules[] = array('class' => 'my_lists', 'value' => $this->details['slug'].'|'.$list_id, 'title' => __('My Lists', 'wmd_msreader').': '.$list_name);
}

return $arg_modules;
Expand Down Expand Up @@ -910,7 +909,7 @@ function get_page_title() {
return $title;
}

function query() {
function query($count = false) {
global $wpdb;

$posts = '';
Expand All @@ -929,6 +928,7 @@ function query() {

$followed_by_user = $this->get_followed_sites(1, $follow_list);


if($followed_by_user) {
$followed_by_user_ready = array();
foreach ($followed_by_user as $blog_id) {
Expand Down Expand Up @@ -982,9 +982,9 @@ function query() {
</div>
</div>
<div class="postbox msreader-widget">
<h3>'.__( 'Edit this list', 'wmd_msreader' ).'</h3>
<div class="inside">
'.__( 'Modify name:', 'wmd_msreader' ).' <input name="name" type="text" value="'.esc_attr($list_name).'"/> <input type="submit" class="button button-secondary button-small" name="change_name" value="'.__( 'Save', 'wmd_msreader' ).'"/><br/>
<h3>'.__( 'Edit this list', 'wmd_msreader' ).'</h3>
<div class="inside">
'.__( 'Modify name:', 'wmd_msreader' ).' <input name="name" type="text" value="'.esc_attr($list_name).'"/> <input type="submit" class="button button-secondary button-small" name="change_name" value="'.__( 'Save', 'wmd_msreader' ).'"/><br/>
'.__( 'Delete it: <small>Mark this checkbox to confirm', 'wmd_msreader' ).' <input name="delete_confirm" type="checkbox" value="1"/> '.__( 'and click</small>', 'wmd_msreader' ).' <input type="submit" class="button button-secondary button-small" name="delete" value="'.__( 'Delete', 'wmd_msreader' ).'"/><br/>
</div>
</div>
Expand All @@ -993,16 +993,24 @@ function query() {

}
else {
$limit = $this->get_limit();
$public = $this->get_public();
$follow_list = isset($this->args[0]) ? $this->args[0] : false;

$followed_by_user = $this->get_followed_sites(1, $follow_list);

$followed_by_user_ids = implode(',', $followed_by_user);

if($count) {
$select = "count(*)";
$limit = "";
}
else {
$limit = $this->get_limit();
$select = "posts.BLOG_ID AS BLOG_ID, ID, post_author, post_date, post_date_gmt, post_content, post_title";
}

$query = "
SELECT posts.BLOG_ID AS BLOG_ID, ID, post_author, post_date, post_date_gmt, post_content, post_title
SELECT $select
FROM $this->db_network_posts AS posts
INNER JOIN $this->db_blogs AS blogs ON blogs.blog_id = posts.BLOG_ID
WHERE $public blogs.archived = 0 AND blogs.spam = 0 AND blogs.deleted = 0
Expand All @@ -1012,8 +1020,11 @@ function query() {
ORDER BY post_date_gmt DESC
$limit
";
$query = apply_filters('msreader_'.$this->details['slug'].'_query', $query, $this->args, $limit, $public, $followed_by_user_ids);
$query = apply_filters('msreader_'.$this->details['slug'].'_query', $query, $this->args, $limit, $public, $followed_by_user_ids, $this->get_user(), $select, $count);

if($count)
$posts = $wpdb->get_var($query);
else
$posts = $wpdb->get_results($query);
}

Expand All @@ -1031,9 +1042,10 @@ function get_empty_message() {

function get_followed_sites($check = 0, $follow_list = 0) {
if($this->get_user()) {
$this->user_follow_data = $this->get_user_follow_data();
//we want to force it to get new data when not on admin as we are probably displaying data for not logged in user
$this->user_follow_data = $this->get_user_follow_data(!is_admin());
if(!$follow_list) {
$followed_by_default = explode(',', str_replace(' ', '', $this->options['follow_by_default']));
$followed_by_default = explode(',', str_replace(' ', '', $this->options['follow_by_default']));
$followed_by_user = array_diff (array_merge($this->user_follow_data['followed'], $followed_by_default), $this->user_follow_data['unfollowed']);
}
else {
Expand All @@ -1058,8 +1070,9 @@ function get_followed_sites($check = 0, $follow_list = 0) {
return array();
}

function get_user_follow_data() {
if(!isset($this->user_follow_data)) {
function get_user_follow_data($force = false) {
//we should store and compare user id here or get rif of this pseudo cache
if(!isset($this->user_follow_data) || $force) {
$this->user_follow_data = get_user_option('msreader_follow', $this->get_user());

$this->user_follow_data = !$this->user_follow_data ? array('followed' => array(), 'unfollowed' => array()) : $this->user_follow_data;
Expand Down
2 changes: 1 addition & 1 deletion msreader-files/includes/modules/my-posts.php
Expand Up @@ -4,7 +4,7 @@
'description' => __( 'Displays current users posts', 'wmd_msreader' ),
'slug' => 'my_posts',
'class' => 'WMD_MSReader_Module_MyPosts',
'type' => 'query'
'type' => array('query', 'query-private')
);

class WMD_MSReader_Module_MyPosts extends WMD_MSReader_Modules {
Expand Down

0 comments on commit a0992ea

Please sign in to comment.