WordPress Popular Posts - Version 6.0.0

Version Description

This release introduces a couple of major changes so please review before updating.

  • Minimum required PHP version is now 7.2.
  • Minimum required WordPress version is now 5.3.
  • Breaking change: this version removes code that has been deprecated for a long time. See the release notes for more details.
  • Widget block: fixes an issue where the length of the title when set via theme was being ignored.
  • Widget block: fixes bug with thumbnail not rendering under certain circumstances (thanks the9mm!)
  • Admin: the Statistics screen will now by default only lists posts. See the release notes for more details.
  • Admin: only users with edit_others_posts capability (usually Editors and Administrators) will be able to access certain areas of WPP's dashboard.
  • Admin: makes sure to escape params from add_query_arg().
  • Fixes an issue where widget themes stored in child theme's folder would not be recognized by the plugin.
  • Small improvements / fixes.

Release notes

Download this release

Release Info

Developer hcabrera
Plugin Icon 128x128 WordPress Popular Posts
Version 6.0.0
Comparing to
See all releases

Code changes from version 5.5.1 to 6.0.0

assets/css/admin.css CHANGED
@@ -36,6 +36,8 @@
36
  }
37
 
38
  .wpp-wrapper {
 
 
39
  margin: 20px 20px 0 2px;
40
  -webkit-font-smoothing: subpixel-antialiased;
41
  }
36
  }
37
 
38
  .wpp-wrapper {
39
+ float: none;
40
+ clear: both;
41
  margin: 20px 20px 0 2px;
42
  -webkit-font-smoothing: subpixel-antialiased;
43
  }
assets/js/blocks/block-wpp-widget.asset.php CHANGED
@@ -1 +1 @@
1
- <?php return array('dependencies' => array(), 'version' => 'bd6367a58d4de200ed825558aaf46c2c');
1
+ <?php return array('dependencies' => array(), 'version' => 'e794ee54037b78ab5d747970a401322e');
assets/js/blocks/block-wpp-widget.js CHANGED
@@ -1 +1 @@
1
- !function(){"use strict";var e={};e.flame=React.createElement("svg",{viewBox:"0 0 248 379"},React.createElement("path",{fill:"#fff",d:"M-83,96q0-122.5,0-245H165q0,131,0,262a31.87,31.87,0,0,1-.95-4.33A123.87,123.87,0,0,0,153.47,68.3c-12.28-27.74-31.1-50.64-53-71.21C75.67-26.13,55.85-52,54.32-87.87c-.79-18.47.81-36.24,11.59-52.15,1.08-1.59.38-4.4.5-6.64-2.43.1-5.5-.7-7.18.47a140.91,140.91,0,0,0-17.12,13.72C19.49-110.67,3-84.6-9.51-56A149,149,0,0,0-21.86-3.77c-2,39.4,11.38,73.46,36.17,103.51,1.74,2.11,3.51,4.2,5.27,6.3l-.67,1.07c-3.94-1.07-8-1.83-11.82-3.24C-25.17,91.94-52.36,58.57-51.12,21c.1-2.91.21-6.45-3.51-6.49-2,0-4.76,2.16-5.79,4.09-9.4,17.55-16.35,36-19.73,55.73C-81.38,81.49-82.07,88.76-83,96Z",transform:"translate(83 149)"}),React.createElement("path",{fill:"#ba2f2f",d:"M-83,96c.93-7.24,1.62-14.51,2.85-21.7,3.38-19.69,10.33-38.18,19.73-55.73,1-1.93,3.83-4.11,5.79-4.09,3.72,0,3.61,3.58,3.51,6.49-1.25,37.59,25.94,71,58.2,82.89,3.82,1.41,7.87,2.18,11.82,3.24l.67-1.07c-1.76-2.1-3.52-4.19-5.27-6.3C-10.49,69.68-23.88,35.63-21.86-3.77A149,149,0,0,1-9.51-56c12.48-28.62,29-54.69,51.62-76.5a140.91,140.91,0,0,1,17.12-13.72c1.68-1.18,4.75-.37,7.18-.47-.13,2.24.58,5-.5,6.64-10.78,15.9-12.37,33.68-11.59,52.15,1.53,35.89,21.35,61.74,46.11,85,21.94,20.57,40.76,43.47,53,71.21a123.87,123.87,0,0,1,10.59,40.36A31.87,31.87,0,0,0,165,113v9c-.7,4.24-1.17,8.54-2.13,12.73-10.74,46.51-37.08,78.75-84.34,91.58C72.16,228,65.52,228.79,59,230H43a25.19,25.19,0,0,0-3.12-1.18c-10-2.37-20.21-4.12-30-7.12-45.83-14-75.19-44.64-89-90.24-2.28-7.52-2.64-15.63-3.88-23.46Q-83,102-83,96ZM61.63-143.61c-6.24,5.39-12.87,10.38-18.64,16.22A229,229,0,0,0-8.77-46.26,138.37,138.37,0,0,0-16.63,23c4.69,32.54,20.21,59.59,42.4,83.23,1.34,1.43,2.7,2.83,4.8,5-15.23,1-28-3.3-39.74-10.64-29.74-18.62-46-45.23-46.8-81a138.75,138.75,0,0,0-7.46,14.67A178.29,178.29,0,0,0-78.24,93.09C-80.9,129.7-68,160.25-42.78,185.71c28.91,29.16,65.19,41.42,105.43,38.91,43.82-2.73,80.34-35.08,93.53-79.39,8.68-29.18,3.11-56.71-10.29-83.15C134.15,38.92,117.71,19.34,99,1.57,85-11.65,71.34-25.28,62.72-42.69,46.33-75.79,44.36-109.22,61.63-143.61Z",transform:"translate(83 149)"}),React.createElement("path",{fill:"#fff",d:"M-83,108c1.25,7.84,1.61,15.94,3.88,23.46,13.79,45.6,43.15,76.21,89,90.24,9.82,3,20,4.76,30,7.12A25.19,25.19,0,0,1,43,230H-83Q-83,169-83,108Z",transform:"translate(83 149)"}),React.createElement("path",{fill:"#fff",d:"M59,230c6.52-1.21,13.16-2,19.53-3.69,47.26-12.83,73.6-45.07,84.34-91.58,1-4.18,1.43-8.48,2.13-12.73V230Z",transform:"translate(83 149)"}),React.createElement("path",{fill:"#ba2f2f",d:"M61.63-143.61c-17.28,34.39-15.3,67.82,1.09,100.92C71.34-25.28,85-11.65,99,1.57c18.75,17.77,35.2,37.35,46.94,60.51,13.4,26.44,19,54,10.29,83.15-13.18,44.31-49.71,76.66-93.53,79.39-40.25,2.51-76.52-9.75-105.43-38.91C-68,160.25-80.9,129.7-78.24,93.09A178.29,178.29,0,0,1-63.45,34.31,138.75,138.75,0,0,1-56,19.64c.77,35.79,17.06,62.4,46.8,81C2.54,108,15.33,112.3,30.56,111.3c-2.1-2.21-3.46-3.62-4.8-5C3.57,82.62-11.94,55.57-16.63,23A138.37,138.37,0,0,1-8.77-46.26,229,229,0,0,1,43-127.38C48.76-133.23,55.39-138.22,61.63-143.61Z",transform:"translate(83 149)"}));var t=e;function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function s(e,t){for(var a=0;a<t.length;a++){var s=t[a];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}function r(e,t){return r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},r(e,t)}function o(e,t){if(t&&("object"===a(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function n(e){return n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}var l=wp.serverSideRender,i=wp.element,p=i.Component,u=i.Fragment,c=wp.blockEditor.BlockControls,m=wp.components,d=m.Button,h=m.CheckboxControl,f=m.Disabled,b=m.SelectControl,_=m.Spinner,g=m.TextareaControl,y=m.TextControl,v=m.Toolbar,__=wp.i18n.__,w="wordpress-popular-posts/v1",x=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}(x,e);var t,a,i,p,m=(i=x,p=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=n(i);if(p){var a=n(this).constructor;e=Reflect.construct(t,arguments,a)}else e=t.apply(this,arguments);return o(this,e)});function x(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,x),(t=m.call(this,e)).state={error:null,editMode:!0,themes:null,imgSizes:null,taxonomies:null},t}return t=x,(a=[{key:"componentDidMount",value:function(){var e=this.props.attributes;this.getThemes(),this.getImageSizes(),this.getTaxonomies(),this.setState({editMode:e._editMode})}},{key:"getThemes",value:function(){var e=this;wp.apiFetch({path:w+"/themes"}).then((function(t){e.setState({themes:t})}),(function(t){e.setState({error:t,themes:null})}))}},{key:"getImageSizes",value:function(){var e=this;wp.apiFetch({path:w+"/thumbnails"}).then((function(t){e.setState({imgSizes:t})}),(function(t){e.setState({error:t,imgSizes:null})}))}},{key:"getTaxonomies",value:function(){var e=this,t=this.props.attributes;wp.apiFetch({path:w+"/taxonomies"}).then((function(a){if(a){var s=t.tax.split(";"),r=t.term_id.split(";");if(s.length&&s.length==r.length){for(var o={},n=0;n<s.length;n++)o[s[n]]=r[n];for(var l in a)a[l]._terms=void 0!==o[l]?o[l]:""}}e.setState({taxonomies:a})}),(function(t){e.setState({error:t,taxonomies:null})}))}},{key:"getBlockControls",value:function(){var e=this.props.setAttributes,t=this;return React.createElement(c,null,React.createElement(v,null,React.createElement(d,{label:this.state.editMode?__("Preview","wordpress-popular-posts"):__("Edit","wordpress-popular-posts"),icon:this.state.editMode?"format-image":"edit",onClick:function(){var a=!t.state.editMode;t.setState({editMode:a}),e({_editMode:a})}})))}},{key:"getMainFields",value:function(){var e=this.props,t=e.attributes,a=e.setAttributes;return React.createElement(u,null,React.createElement(y,{label:__("Title","wordpress-popular-posts"),value:t.title,onChange:function(e){e=function(e){var t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;","`":"&grave;"};return e.replace(/[&<>"'/]/gi,(function(e){return t[e]}))}(function(e){var t=document.createElement("div");t.innerHTML=e;var a=t.childNodes[0];return a?a.nodeValue:""}(e)),a({title:e})}}),React.createElement(y,{label:__("Limit","wordpress-popular-posts"),value:t.limit,onChange:function(e){var t=Number.isInteger(Number(e))&&Number(e)>0?e:10;a({limit:Number(t)})}}),React.createElement(b,{label:__("Sort posts by","wordpress-popular-posts"),value:t.order_by,options:[{label:__("Total views","wordpress-popular-posts"),value:"views"},{label:__("Avg. daily views","wordpress-popular-posts"),value:"avg"},{label:__("Comments","wordpress-popular-posts"),value:"comments"}],onChange:function(e){a({order_by:e})}}),React.createElement(b,{label:__("Time Range","wordpress-popular-posts"),value:t.range,options:[{label:__("Last 24 Hours","wordpress-popular-posts"),value:"last24hours"},{label:__("Last 7 days","wordpress-popular-posts"),value:"last7days"},{label:__("Last 30 days","wordpress-popular-posts"),value:"last30days"},{label:__("All-time","wordpress-popular-posts"),value:"all"},{label:__("Custom","wordpress-popular-posts"),value:"custom"}],onChange:function(e){a({range:e})}}),"custom"==t.range&&React.createElement("div",{className:"option-subset"},React.createElement(y,{label:__("Time Quantity","wordpress-popular-posts"),value:t.time_quantity,onChange:function(e){var t=Number.isInteger(Number(e))&&Number(e)>0?e:24;a({time_quantity:Number(t)})}}),React.createElement(b,{label:__("Time Unit","wordpress-popular-posts"),value:t.time_unit,options:[{label:__("Minute(s)","wordpress-popular-posts"),value:"minute"},{label:__("Hour(s)","wordpress-popular-posts"),value:"hour"},{label:__("Day(s)","wordpress-popular-posts"),value:"day"}],onChange:function(e){a({time_unit:e})}})),React.createElement(h,{label:__("Display only posts published within the selected Time Range","wordpress-popular-posts"),checked:t.freshness,onChange:function(e){a({freshness:e})}}))}},{key:"getFiltersFields",value:function(){var e=this.props,t=e.attributes,a=e.setAttributes,s=this,r=[];if(this.state.taxonomies)for(var o in this.state.taxonomies)r.push({name:this.state.taxonomies[o].name,label:this.state.taxonomies[o].labels.singular_name+" ("+this.state.taxonomies[o].name+")",terms:this.state.taxonomies[o]._terms});return React.createElement(u,null,React.createElement("p",{className:"not-a-legend"},React.createElement("strong",null,__("Filters","wordpress-popular-posts"))),React.createElement(y,{label:__("Post type(s)","wordpress-popular-posts"),help:__("Post types must be comma separated.","wordpress-popular-posts"),value:t.post_type,onChange:function(e){var t=e.replace(/[^a-z0-9-_\,]+/gi,"");a({post_type:t})}}),React.createElement(y,{label:__("Post ID(s) to exclude","wordpress-popular-posts"),help:__("IDs must be comma separated.","wordpress-popular-posts"),value:t.pid,onChange:function(e){var t=e.replace(/[^0-9\,]/g,"");a({pid:t})}}),React.createElement(y,{label:__("Author ID(s)","wordpress-popular-posts"),help:__("IDs must be comma separated.","wordpress-popular-posts"),value:t.author,onChange:function(e){var t=e.replace(/[^0-9\,]/g,"");a({author:t})}}),r&&r.filter((function(e){return"post_format"!=e.name})).map((function(e){return React.createElement(y,{label:e.label,help:__("Term IDs must be comma separated, prefix a minus sign to exclude.","wordpress-popular-posts"),value:e.terms,onChange:function(t){return function(e,t){var a=s.state.taxonomies;t=t.replace(/[^0-9-\,]/g,""),a&&void 0!==a[e]&&(a[e]._terms=t,s.setState({taxonomies:a}))}(e.name,t)},onBlur:function(){return function(e){var t=s.state.taxonomies;if(t&&void 0!==t[e]){var r=t[e]._terms.split(",");r.length&&(r=r.map((function(e){return e.trim()})).filter((function(e){return""!=e&&"-"!=e}))),r.length&&(r=Array.from(new Set(r))),t[e]._terms=r.join(","),s.setState({taxonomies:t});var o="",n="";for(var l in s.state.taxonomies)if(s.state.taxonomies.hasOwnProperty(l)){if(!s.state.taxonomies[l]._terms.length)continue;o+=l+";",n+=s.state.taxonomies[l]._terms+";"}o&&n&&(o=o.replace(new RegExp(";$"),""),n=n.replace(new RegExp(";$"),"")),a({tax:o,term_id:n})}}(e.name)}})})))}},{key:"getPostSettingsFields",value:function(){var e=this.props,t=e.attributes,a=e.setAttributes,s=this;function r(e,t){var s=Number.isInteger(Number(t))&&Number(t)>=0?t:0;a("width"==e?{thumbnail_width:Number(s)}:{thumbnail_height:Number(s)})}var o=[];if(this.state.imgSizes)for(var n in this.state.imgSizes)o.push({label:n,value:n});return React.createElement(u,null,React.createElement("p",{className:"not-a-legend"},React.createElement("strong",null,__("Posts settings","wordpress-popular-posts"))),React.createElement(h,{label:__("Shorten title","wordpress-popular-posts"),checked:t.shorten_title,onChange:function(e){a(0==e?{title_length:0,title_by_words:0,shorten_title:e}:{shorten_title:e,title_length:25})}}),t.shorten_title&&React.createElement("div",{className:"option-subset"},React.createElement(y,{label:__("Shorten title to","wordpress-popular-posts"),value:t.title_length,onChange:function(e){var t=Number.isInteger(Number(e))&&Number(e)>=0?e:0;a({title_length:Number(t)})}}),React.createElement(b,{value:t.title_by_words,options:[{label:__("characters","wordpress-popular-posts"),value:0},{label:__("words","wordpress-popular-posts"),value:1}],onChange:function(e){return a({title_by_words:Number(e)})}})),React.createElement(h,{label:__("Display post excerpt","wordpress-popular-posts"),checked:t.display_post_excerpt,onChange:function(e){a(0==e?{excerpt_length:0,excerpt_by_words:0,display_post_excerpt:e}:{display_post_excerpt:e,excerpt_length:55})}}),t.display_post_excerpt&&React.createElement("div",{className:"option-subset"},React.createElement(h,{label:__("Keep text format and links","wordpress-popular-posts"),checked:t.excerpt_format,onChange:function(e){return a({excerpt_format:e})}}),React.createElement(y,{label:__("Excerpt length","wordpress-popular-posts"),value:t.excerpt_length,onChange:function(e){var t=Number.isInteger(Number(e))&&Number(e)>=0?e:0;a({excerpt_length:Number(t)})}}),React.createElement(b,{value:t.excerpt_by_words,options:[{label:__("characters","wordpress-popular-posts"),value:0},{label:__("words","wordpress-popular-posts"),value:1}],onChange:function(e){return a({excerpt_by_words:Number(e)})}})),React.createElement(h,{label:__("Display post thumbnail","wordpress-popular-posts"),checked:t.display_post_thumbnail,onChange:function(e){a(0==e?{thumbnail_width:0,thumbnail_height:0,display_post_thumbnail:e}:{thumbnail_width:75,thumbnail_height:75,display_post_thumbnail:e})}}),t.display_post_thumbnail&&React.createElement("div",{className:"option-subset"},React.createElement(b,{value:t.thumbnail_build,options:[{label:__("Set size manually","wordpress-popular-posts"),value:"manual"},{label:__("Use predefined size","wordpress-popular-posts"),value:"predefined"}],onChange:function(e){"predefined"==e&&a({thumbnail_width:s.state.imgSizes[o[0].value].width,thumbnail_height:s.state.imgSizes[o[0].value].height,thumbnail_size:o[0].value}),a({thumbnail_build:e})}}),"manual"==t.thumbnail_build&&React.createElement(u,null,React.createElement(y,{label:__("Thumbnail width","wordpress-popular-posts"),help:__("Size in px units (pixels)","wordpress-popular-posts"),value:t.thumbnail_width,onChange:function(e){return r("width",e)}}),React.createElement(y,{label:__("Thumbnail height","wordpress-popular-posts"),help:__("Size in px units (pixels)","wordpress-popular-posts"),value:t.thumbnail_height,onChange:function(e){return r("height",e)}})),"predefined"==t.thumbnail_build&&React.createElement(u,null,React.createElement(b,{value:t.thumbnail_size,options:o,onChange:function(e){a({thumbnail_width:s.state.imgSizes[e].width,thumbnail_height:s.state.imgSizes[e].height,thumbnail_size:e})}}))))}},{key:"getStatsTagFields",value:function(){var e=this.props,t=e.attributes,a=e.setAttributes,s=[];if(this.state.taxonomies)for(var r in this.state.taxonomies)s.push({label:this.state.taxonomies[r].labels.singular_name+" ("+this.state.taxonomies[r].name+")",value:this.state.taxonomies[r].name});return React.createElement(u,null,React.createElement("p",{className:"not-a-legend"},React.createElement("strong",null,__("Stats Tag settings","wordpress-popular-posts"))),React.createElement(h,{label:__("Display comments count","wordpress-popular-posts"),checked:t.stats_comments,onChange:function(e){return a({stats_comments:e})}}),React.createElement(h,{label:__("Display views","wordpress-popular-posts"),checked:t.stats_views,onChange:function(e){return a({stats_views:e})}}),React.createElement(h,{label:__("Display author","wordpress-popular-posts"),checked:t.stats_author,onChange:function(e){return a({stats_author:e})}}),React.createElement(h,{label:__("Display date","wordpress-popular-posts"),checked:t.stats_date,onChange:function(e){return a({stats_date:e})}}),t.stats_date&&React.createElement("div",{className:"option-subset"},React.createElement(b,{label:__("Date Format","wordpress-popular-posts"),value:t.stats_date_format,options:[{label:__("Relative","wordpress-popular-posts"),value:"relative"},{label:__("Month Day, Year","wordpress-popular-posts"),value:"F j, Y"},{label:__("yyyy/mm/dd","wordpress-popular-posts"),value:"Y/m/d"},{label:__("mm/dd/yyyy","wordpress-popular-posts"),value:"m/d/Y"},{label:__("dd/mm/yyyy","wordpress-popular-posts"),value:"d/m/Y"},{label:__("WordPress Date Format","wordpress-popular-posts"),value:"wp_date_format"}],onChange:function(e){return a({stats_date_format:e})}})),React.createElement(h,{label:__("Display taxonomy","wordpress-popular-posts"),checked:t.stats_taxonomy,onChange:function(e){return a({stats_taxonomy:e})}}),t.stats_taxonomy&&React.createElement("div",{className:"option-subset"},React.createElement(b,{label:__("Taxonomy","wordpress-popular-posts"),value:t.taxonomy,options:s,onChange:function(e){return a({taxonomy:e})}})))}},{key:"getHTMLMarkupFields",value:function(){var e=this.props,t=e.attributes,a=e.setAttributes,s=this,r=[{label:__("None","wordpress-popular-posts"),value:""}];if(this.state.themes)for(var o in this.state.themes)r.push({label:this.state.themes[o].json.name,value:o});return React.createElement(u,null,React.createElement("p",{className:"not-a-legend"},React.createElement("strong",null,__("HTML Markup settings","wordpress-popular-posts"))),React.createElement(h,{label:__("Use custom HTML Markup","wordpress-popular-posts"),checked:t.custom_html,onChange:function(e){return a({custom_html:e})}}),t.custom_html&&React.createElement("div",{className:"option-subset"},React.createElement(g,{rows:"1",label:__("Before title","wordpress-popular-posts"),value:t.header_start,onChange:function(e){return a({header_start:e})}}),React.createElement(g,{rows:"1",label:__("After title","wordpress-popular-posts"),value:t.header_end,onChange:function(e){return a({header_end:e})}}),React.createElement(g,{rows:"1",label:__("Before popular posts","wordpress-popular-posts"),value:t.wpp_start,onChange:function(e){return a({wpp_start:e})}}),React.createElement(g,{rows:"1",label:__("After popular posts","wordpress-popular-posts"),value:t.wpp_end,onChange:function(e){return a({wpp_end:e})}}),React.createElement(g,{label:__("Post HTML markup","wordpress-popular-posts"),value:t.post_html,onChange:function(e){return a({post_html:e})}})),React.createElement(b,{label:__("Theme","wordpress-popular-posts"),value:t.theme,options:r,onChange:function(e){if(void 0!==s.state.themes[e]){var t=s.state.themes[e].json.config;a({shorten_title:t.shorten_title.active,title_length:t.shorten_title.title_length,title_by_words:t.shorten_title.words?1:0,display_post_excerpt:t["post-excerpt"].active,excerpt_format:t["post-excerpt"].format,excerpt_length:t["post-excerpt"].length,excerpt_by_words:t["post-excerpt"].words?1:0,display_post_thumbnail:t.thumbnail.active,thumbnail_build:t.thumbnail.build,thumbnail_width:t.thumbnail.width,thumbnail_height:t.thumbnail.height,stats_comments:t.stats_tag.comment_count,stats_views:t.stats_tag.views,stats_author:t.stats_tag.author,stats_date:t.stats_tag.date.active,stats_date_format:t.stats_tag.date.format,stats_taxonomy:t.stats_tag.taxonomy.active,taxonomy:t.stats_tag.taxonomy.name,custom_html:!0,wpp_start:t.markup["wpp-start"],wpp_end:t.markup["wpp-end"],post_html:t.markup["post-html"],theme:e})}else a({theme:e})}}))}},{key:"render",value:function(){if(!this.state.taxonomies||!this.state.themes||!this.state.imgSizes)return React.createElement(_,null);var e=this.props,t=e.isSelected,a=e.className,s=e.attributes,r=a;return r+=this.state.editMode?" in-edit-mode":" in-preview-mode",r+=t?" is-selected":"",[this.getBlockControls(),React.createElement("div",{className:r},this.state.editMode&&React.createElement(u,null,this.getMainFields(),this.getFiltersFields(),this.getPostSettingsFields(),this.getStatsTagFields(),this.getHTMLMarkupFields()),!this.state.editMode&&React.createElement(f,null,React.createElement(l,{block:this.props.name,className:a,attributes:s,urlQueryArgs:{isSelected:t}})))]}}])&&s(t.prototype,a),x}(p),R=wp.blocks.registerBlockType,E=wp.i18n.__;R("wordpress-popular-posts/widget",{title:"WordPress Popular Posts",category:"widgets",icon:t.flame,description:E("A highly customizable block that displays your most popular posts.","wordpress-popular-posts"),keywords:["popular","posts","trending","popularity"],attributes:{_editMode:{type:"boolean",default:!0},_isSelected:{type:"boolean",default:!1},title:{type:"string"},limit:{type:"number",default:10},offset:{type:"number",default:0},order_by:{type:"string",default:"views"},range:{type:"string",default:"last24hours"},time_quantity:{type:"number",default:24},time_unit:{type:"string",default:"hour"},freshness:{type:"boolean",default:!1},post_type:{type:"string",default:"post"},pid:{type:"string",default:""},author:{type:"string",default:""},tax:{type:"string",default:""},term_id:{type:"string",default:""},shorten_title:{type:"boolean",default:!1},title_length:{type:"number",default:0},title_by_words:{type:"number",default:0},display_post_excerpt:{type:"boolean",default:!1},excerpt_format:{type:"boolean",default:!1},excerpt_length:{type:"number",default:0},excerpt_by_words:{type:"number",default:0},display_post_thumbnail:{type:"boolean",default:!1},thumbnail_width:{type:"number",default:0},thumbnail_height:{type:"number",default:0},thumbnail_build:{type:"string",default:"manual"},thumbnail_size:{type:"string",default:""},stats_comments:{type:"boolean",default:!1},stats_views:{type:"boolean",default:!0},stats_author:{type:"boolean",default:!1},stats_date:{type:"boolean",default:!1},stats_date_format:{type:"string",default:"F j, Y"},stats_taxonomy:{type:"boolean",default:!1},taxonomy:{type:"string",default:""},custom_html:{type:"boolean",default:!1},header_start:{type:"string",default:"<h2>"},header_end:{type:"string",default:"</h2>"},wpp_start:{type:"string",default:'<ul class="wpp-list">'},wpp_end:{type:"string",default:"</ul>"},post_html:{type:"string",default:'<li>{thumb} {title} <span class="wpp-meta post-stats">{stats}</span></li>'},theme:{type:"string",default:""}},supports:{anchor:!0,align:!0,html:!1},example:{attributes:{_editMode:!1,title:"Popular Posts",limit:3,range:"last7days",display_post_excerpt:!0,excerpt_length:75,display_post_thumbnail:!0,thumbnail_width:75,thumbnail_height:75,stats_views:!1,stats_taxonomy:!0,custom_html:!0,wpp_start:'<ul class="wpp-list wpp-cards">',post_html:'<li>{thumb_img} <div class="wpp-item-data"><div class="taxonomies">{taxonomy}</div>{title} <p class="wpp-excerpt">{excerpt}</p></div></li>',theme:"cards"}},edit:x,save:function(){return null}})}();
1
+ !function(){"use strict";var e={};e.flame=React.createElement("svg",{viewBox:"0 0 248 379"},React.createElement("path",{fill:"#fff",d:"M-83,96q0-122.5,0-245H165q0,131,0,262a31.87,31.87,0,0,1-.95-4.33A123.87,123.87,0,0,0,153.47,68.3c-12.28-27.74-31.1-50.64-53-71.21C75.67-26.13,55.85-52,54.32-87.87c-.79-18.47.81-36.24,11.59-52.15,1.08-1.59.38-4.4.5-6.64-2.43.1-5.5-.7-7.18.47a140.91,140.91,0,0,0-17.12,13.72C19.49-110.67,3-84.6-9.51-56A149,149,0,0,0-21.86-3.77c-2,39.4,11.38,73.46,36.17,103.51,1.74,2.11,3.51,4.2,5.27,6.3l-.67,1.07c-3.94-1.07-8-1.83-11.82-3.24C-25.17,91.94-52.36,58.57-51.12,21c.1-2.91.21-6.45-3.51-6.49-2,0-4.76,2.16-5.79,4.09-9.4,17.55-16.35,36-19.73,55.73C-81.38,81.49-82.07,88.76-83,96Z",transform:"translate(83 149)"}),React.createElement("path",{fill:"#ba2f2f",d:"M-83,96c.93-7.24,1.62-14.51,2.85-21.7,3.38-19.69,10.33-38.18,19.73-55.73,1-1.93,3.83-4.11,5.79-4.09,3.72,0,3.61,3.58,3.51,6.49-1.25,37.59,25.94,71,58.2,82.89,3.82,1.41,7.87,2.18,11.82,3.24l.67-1.07c-1.76-2.1-3.52-4.19-5.27-6.3C-10.49,69.68-23.88,35.63-21.86-3.77A149,149,0,0,1-9.51-56c12.48-28.62,29-54.69,51.62-76.5a140.91,140.91,0,0,1,17.12-13.72c1.68-1.18,4.75-.37,7.18-.47-.13,2.24.58,5-.5,6.64-10.78,15.9-12.37,33.68-11.59,52.15,1.53,35.89,21.35,61.74,46.11,85,21.94,20.57,40.76,43.47,53,71.21a123.87,123.87,0,0,1,10.59,40.36A31.87,31.87,0,0,0,165,113v9c-.7,4.24-1.17,8.54-2.13,12.73-10.74,46.51-37.08,78.75-84.34,91.58C72.16,228,65.52,228.79,59,230H43a25.19,25.19,0,0,0-3.12-1.18c-10-2.37-20.21-4.12-30-7.12-45.83-14-75.19-44.64-89-90.24-2.28-7.52-2.64-15.63-3.88-23.46Q-83,102-83,96ZM61.63-143.61c-6.24,5.39-12.87,10.38-18.64,16.22A229,229,0,0,0-8.77-46.26,138.37,138.37,0,0,0-16.63,23c4.69,32.54,20.21,59.59,42.4,83.23,1.34,1.43,2.7,2.83,4.8,5-15.23,1-28-3.3-39.74-10.64-29.74-18.62-46-45.23-46.8-81a138.75,138.75,0,0,0-7.46,14.67A178.29,178.29,0,0,0-78.24,93.09C-80.9,129.7-68,160.25-42.78,185.71c28.91,29.16,65.19,41.42,105.43,38.91,43.82-2.73,80.34-35.08,93.53-79.39,8.68-29.18,3.11-56.71-10.29-83.15C134.15,38.92,117.71,19.34,99,1.57,85-11.65,71.34-25.28,62.72-42.69,46.33-75.79,44.36-109.22,61.63-143.61Z",transform:"translate(83 149)"}),React.createElement("path",{fill:"#fff",d:"M-83,108c1.25,7.84,1.61,15.94,3.88,23.46,13.79,45.6,43.15,76.21,89,90.24,9.82,3,20,4.76,30,7.12A25.19,25.19,0,0,1,43,230H-83Q-83,169-83,108Z",transform:"translate(83 149)"}),React.createElement("path",{fill:"#fff",d:"M59,230c6.52-1.21,13.16-2,19.53-3.69,47.26-12.83,73.6-45.07,84.34-91.58,1-4.18,1.43-8.48,2.13-12.73V230Z",transform:"translate(83 149)"}),React.createElement("path",{fill:"#ba2f2f",d:"M61.63-143.61c-17.28,34.39-15.3,67.82,1.09,100.92C71.34-25.28,85-11.65,99,1.57c18.75,17.77,35.2,37.35,46.94,60.51,13.4,26.44,19,54,10.29,83.15-13.18,44.31-49.71,76.66-93.53,79.39-40.25,2.51-76.52-9.75-105.43-38.91C-68,160.25-80.9,129.7-78.24,93.09A178.29,178.29,0,0,1-63.45,34.31,138.75,138.75,0,0,1-56,19.64c.77,35.79,17.06,62.4,46.8,81C2.54,108,15.33,112.3,30.56,111.3c-2.1-2.21-3.46-3.62-4.8-5C3.57,82.62-11.94,55.57-16.63,23A138.37,138.37,0,0,1-8.77-46.26,229,229,0,0,1,43-127.38C48.76-133.23,55.39-138.22,61.63-143.61Z",transform:"translate(83 149)"}));var t=e;function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function s(e,t){for(var a=0;a<t.length;a++){var s=t[a];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}function r(e,t){return r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},r(e,t)}function o(e,t){if(t&&("object"===a(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function n(e){return n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}var l=wp.serverSideRender,i=wp.element,p=i.Component,u=i.Fragment,c=wp.blockEditor.BlockControls,m=wp.components,d=m.CheckboxControl,h=m.Disabled,b=m.SelectControl,f=m.Spinner,_=m.TextareaControl,g=m.TextControl,y=m.Toolbar,w=m.ToolbarButton,__=wp.i18n.__,v="wordpress-popular-posts/v1",x=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&r(e,t)}(x,e);var t,a,i,p,m=(i=x,p=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=n(i);if(p){var a=n(this).constructor;e=Reflect.construct(t,arguments,a)}else e=t.apply(this,arguments);return o(this,e)});function x(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,x),(t=m.call(this,e)).state={error:null,editMode:!0,themes:null,imgSizes:null,taxonomies:null},t}return t=x,(a=[{key:"componentDidMount",value:function(){var e=this.props.attributes;this.getThemes(),this.getImageSizes(),this.getTaxonomies(),this.setState({editMode:e._editMode})}},{key:"getThemes",value:function(){var e=this;wp.apiFetch({path:v+"/themes"}).then((function(t){e.setState({themes:t})}),(function(t){e.setState({error:t,themes:null})}))}},{key:"getImageSizes",value:function(){var e=this;wp.apiFetch({path:v+"/thumbnails"}).then((function(t){e.setState({imgSizes:t})}),(function(t){e.setState({error:t,imgSizes:null})}))}},{key:"getTaxonomies",value:function(){var e=this,t=this.props.attributes;wp.apiFetch({path:v+"/taxonomies"}).then((function(a){if(a){var s=t.tax.split(";"),r=t.term_id.split(";");if(s.length&&s.length==r.length){for(var o={},n=0;n<s.length;n++)o[s[n]]=r[n];for(var l in a)a[l]._terms=void 0!==o[l]?o[l]:""}}e.setState({taxonomies:a})}),(function(t){e.setState({error:t,taxonomies:null})}))}},{key:"getBlockControls",value:function(){var e=this.props.setAttributes,t=this;return React.createElement(c,null,React.createElement(y,{label:"{ __('Settings') }"},React.createElement(w,{label:this.state.editMode?__("Preview","wordpress-popular-posts"):__("Edit","wordpress-popular-posts"),icon:this.state.editMode?"format-image":"edit",onClick:function(){var a=!t.state.editMode;t.setState({editMode:a}),e({_editMode:a})}})))}},{key:"getMainFields",value:function(){var e=this.props,t=e.attributes,a=e.setAttributes;return React.createElement(u,null,React.createElement(g,{label:__("Title","wordpress-popular-posts"),value:t.title,onChange:function(e){e=function(e){var t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;","`":"&grave;"};return e.replace(/[&<>"'/]/gi,(function(e){return t[e]}))}(function(e){var t=document.createElement("div");t.innerHTML=e;var a=t.childNodes[0];return a?a.nodeValue:""}(e)),a({title:e})}}),React.createElement(g,{label:__("Limit","wordpress-popular-posts"),value:t.limit,onChange:function(e){var t=Number.isInteger(Number(e))&&Number(e)>0?e:10;a({limit:Number(t)})}}),React.createElement(b,{label:__("Sort posts by","wordpress-popular-posts"),value:t.order_by,options:[{label:__("Total views","wordpress-popular-posts"),value:"views"},{label:__("Avg. daily views","wordpress-popular-posts"),value:"avg"},{label:__("Comments","wordpress-popular-posts"),value:"comments"}],onChange:function(e){a({order_by:e})}}),React.createElement(b,{label:__("Time Range","wordpress-popular-posts"),value:t.range,options:[{label:__("Last 24 Hours","wordpress-popular-posts"),value:"last24hours"},{label:__("Last 7 days","wordpress-popular-posts"),value:"last7days"},{label:__("Last 30 days","wordpress-popular-posts"),value:"last30days"},{label:__("All-time","wordpress-popular-posts"),value:"all"},{label:__("Custom","wordpress-popular-posts"),value:"custom"}],onChange:function(e){a({range:e})}}),"custom"==t.range&&React.createElement("div",{className:"option-subset"},React.createElement(g,{label:__("Time Quantity","wordpress-popular-posts"),value:t.time_quantity,onChange:function(e){var t=Number.isInteger(Number(e))&&Number(e)>0?e:24;a({time_quantity:Number(t)})}}),React.createElement(b,{label:__("Time Unit","wordpress-popular-posts"),value:t.time_unit,options:[{label:__("Minute(s)","wordpress-popular-posts"),value:"minute"},{label:__("Hour(s)","wordpress-popular-posts"),value:"hour"},{label:__("Day(s)","wordpress-popular-posts"),value:"day"}],onChange:function(e){a({time_unit:e})}})),React.createElement(d,{label:__("Display only posts published within the selected Time Range","wordpress-popular-posts"),checked:t.freshness,onChange:function(e){a({freshness:e})}}))}},{key:"getFiltersFields",value:function(){var e=this.props,t=e.attributes,a=e.setAttributes,s=this,r=[];if(this.state.taxonomies)for(var o in this.state.taxonomies)r.push({name:this.state.taxonomies[o].name,label:this.state.taxonomies[o].labels.singular_name+" ("+this.state.taxonomies[o].name+")",terms:this.state.taxonomies[o]._terms});return React.createElement(u,null,React.createElement("p",{className:"not-a-legend"},React.createElement("strong",null,__("Filters","wordpress-popular-posts"))),React.createElement(g,{label:__("Post type(s)","wordpress-popular-posts"),help:__("Post types must be comma separated.","wordpress-popular-posts"),value:t.post_type,onChange:function(e){var t=e.replace(/[^a-z0-9-_\,]+/gi,"");a({post_type:t})}}),React.createElement(g,{label:__("Post ID(s) to exclude","wordpress-popular-posts"),help:__("IDs must be comma separated.","wordpress-popular-posts"),value:t.pid,onChange:function(e){var t=e.replace(/[^0-9\,]/g,"");a({pid:t})}}),React.createElement(g,{label:__("Author ID(s)","wordpress-popular-posts"),help:__("IDs must be comma separated.","wordpress-popular-posts"),value:t.author,onChange:function(e){var t=e.replace(/[^0-9\,]/g,"");a({author:t})}}),r&&r.filter((function(e){return"post_format"!=e.name})).map((function(e){return React.createElement(g,{label:e.label,help:__("Term IDs must be comma separated, prefix a minus sign to exclude.","wordpress-popular-posts"),value:e.terms,onChange:function(t){return function(e,t){var a=s.state.taxonomies;t=t.replace(/[^0-9-\,]/g,""),a&&void 0!==a[e]&&(a[e]._terms=t,s.setState({taxonomies:a}))}(e.name,t)},onBlur:function(){return function(e){var t=s.state.taxonomies;if(t&&void 0!==t[e]){var r=t[e]._terms.split(",");r.length&&(r=r.map((function(e){return e.trim()})).filter((function(e){return""!=e&&"-"!=e}))),r.length&&(r=Array.from(new Set(r))),t[e]._terms=r.join(","),s.setState({taxonomies:t});var o="",n="";for(var l in s.state.taxonomies)if(s.state.taxonomies.hasOwnProperty(l)){if(!s.state.taxonomies[l]._terms.length)continue;o+=l+";",n+=s.state.taxonomies[l]._terms+";"}o&&n&&(o=o.replace(new RegExp(";$"),""),n=n.replace(new RegExp(";$"),"")),a({tax:o,term_id:n})}}(e.name)}})})))}},{key:"getPostSettingsFields",value:function(){var e=this.props,t=e.attributes,a=e.setAttributes,s=this;function r(e,t){var s=Number.isInteger(Number(t))&&Number(t)>=0?t:0;a("width"==e?{thumbnail_width:Number(s)}:{thumbnail_height:Number(s)})}var o=[];if(this.state.imgSizes)for(var n in this.state.imgSizes)o.push({label:n,value:n});return React.createElement(u,null,React.createElement("p",{className:"not-a-legend"},React.createElement("strong",null,__("Posts settings","wordpress-popular-posts"))),React.createElement(d,{label:__("Shorten title","wordpress-popular-posts"),checked:t.shorten_title,onChange:function(e){a(0==e?{title_length:0,title_by_words:0,shorten_title:e}:{shorten_title:e,title_length:25})}}),t.shorten_title&&React.createElement("div",{className:"option-subset"},React.createElement(g,{label:__("Shorten title to","wordpress-popular-posts"),value:t.title_length,onChange:function(e){var t=Number.isInteger(Number(e))&&Number(e)>=0?e:0;a({title_length:Number(t)})}}),React.createElement(b,{value:t.title_by_words,options:[{label:__("characters","wordpress-popular-posts"),value:0},{label:__("words","wordpress-popular-posts"),value:1}],onChange:function(e){return a({title_by_words:Number(e)})}})),React.createElement(d,{label:__("Display post excerpt","wordpress-popular-posts"),checked:t.display_post_excerpt,onChange:function(e){a(0==e?{excerpt_length:0,excerpt_by_words:0,display_post_excerpt:e}:{display_post_excerpt:e,excerpt_length:55})}}),t.display_post_excerpt&&React.createElement("div",{className:"option-subset"},React.createElement(d,{label:__("Keep text format and links","wordpress-popular-posts"),checked:t.excerpt_format,onChange:function(e){return a({excerpt_format:e})}}),React.createElement(g,{label:__("Excerpt length","wordpress-popular-posts"),value:t.excerpt_length,onChange:function(e){var t=Number.isInteger(Number(e))&&Number(e)>=0?e:0;a({excerpt_length:Number(t)})}}),React.createElement(b,{value:t.excerpt_by_words,options:[{label:__("characters","wordpress-popular-posts"),value:0},{label:__("words","wordpress-popular-posts"),value:1}],onChange:function(e){return a({excerpt_by_words:Number(e)})}})),React.createElement(d,{label:__("Display post thumbnail","wordpress-popular-posts"),checked:t.display_post_thumbnail,onChange:function(e){a(0==e?{thumbnail_width:0,thumbnail_height:0,display_post_thumbnail:e}:{thumbnail_width:75,thumbnail_height:75,display_post_thumbnail:e})}}),t.display_post_thumbnail&&React.createElement("div",{className:"option-subset"},React.createElement(b,{value:t.thumbnail_build,options:[{label:__("Set size manually","wordpress-popular-posts"),value:"manual"},{label:__("Use predefined size","wordpress-popular-posts"),value:"predefined"}],onChange:function(e){"predefined"==e&&a({thumbnail_width:s.state.imgSizes[o[0].value].width,thumbnail_height:s.state.imgSizes[o[0].value].height,thumbnail_size:o[0].value}),a({thumbnail_build:e})}}),"manual"==t.thumbnail_build&&React.createElement(u,null,React.createElement(g,{label:__("Thumbnail width","wordpress-popular-posts"),help:__("Size in px units (pixels)","wordpress-popular-posts"),value:t.thumbnail_width,onChange:function(e){return r("width",e)}}),React.createElement(g,{label:__("Thumbnail height","wordpress-popular-posts"),help:__("Size in px units (pixels)","wordpress-popular-posts"),value:t.thumbnail_height,onChange:function(e){return r("height",e)}})),"predefined"==t.thumbnail_build&&React.createElement(u,null,React.createElement(b,{value:t.thumbnail_size,options:o,onChange:function(e){a({thumbnail_width:s.state.imgSizes[e].width,thumbnail_height:s.state.imgSizes[e].height,thumbnail_size:e})}}))))}},{key:"getStatsTagFields",value:function(){var e=this.props,t=e.attributes,a=e.setAttributes,s=[];if(this.state.taxonomies)for(var r in this.state.taxonomies)s.push({label:this.state.taxonomies[r].labels.singular_name+" ("+this.state.taxonomies[r].name+")",value:this.state.taxonomies[r].name});return React.createElement(u,null,React.createElement("p",{className:"not-a-legend"},React.createElement("strong",null,__("Stats Tag settings","wordpress-popular-posts"))),React.createElement(d,{label:__("Display comments count","wordpress-popular-posts"),checked:t.stats_comments,onChange:function(e){return a({stats_comments:e})}}),React.createElement(d,{label:__("Display views","wordpress-popular-posts"),checked:t.stats_views,onChange:function(e){return a({stats_views:e})}}),React.createElement(d,{label:__("Display author","wordpress-popular-posts"),checked:t.stats_author,onChange:function(e){return a({stats_author:e})}}),React.createElement(d,{label:__("Display date","wordpress-popular-posts"),checked:t.stats_date,onChange:function(e){return a({stats_date:e})}}),t.stats_date&&React.createElement("div",{className:"option-subset"},React.createElement(b,{label:__("Date Format","wordpress-popular-posts"),value:t.stats_date_format,options:[{label:__("Relative","wordpress-popular-posts"),value:"relative"},{label:__("Month Day, Year","wordpress-popular-posts"),value:"F j, Y"},{label:__("yyyy/mm/dd","wordpress-popular-posts"),value:"Y/m/d"},{label:__("mm/dd/yyyy","wordpress-popular-posts"),value:"m/d/Y"},{label:__("dd/mm/yyyy","wordpress-popular-posts"),value:"d/m/Y"},{label:__("WordPress Date Format","wordpress-popular-posts"),value:"wp_date_format"}],onChange:function(e){return a({stats_date_format:e})}})),React.createElement(d,{label:__("Display taxonomy","wordpress-popular-posts"),checked:t.stats_taxonomy,onChange:function(e){return a({stats_taxonomy:e})}}),t.stats_taxonomy&&React.createElement("div",{className:"option-subset"},React.createElement(b,{label:__("Taxonomy","wordpress-popular-posts"),value:t.taxonomy,options:s,onChange:function(e){return a({taxonomy:e})}})))}},{key:"getHTMLMarkupFields",value:function(){var e=this.props,t=e.attributes,a=e.setAttributes,s=this,r=[{label:__("None","wordpress-popular-posts"),value:""}];if(this.state.themes)for(var o in this.state.themes)r.push({label:this.state.themes[o].json.name,value:o});return React.createElement(u,null,React.createElement("p",{className:"not-a-legend"},React.createElement("strong",null,__("HTML Markup settings","wordpress-popular-posts"))),React.createElement(d,{label:__("Use custom HTML Markup","wordpress-popular-posts"),checked:t.custom_html,onChange:function(e){return a({custom_html:e})}}),t.custom_html&&React.createElement("div",{className:"option-subset"},React.createElement(_,{rows:"1",label:__("Before title","wordpress-popular-posts"),value:t.header_start,onChange:function(e){return a({header_start:e})}}),React.createElement(_,{rows:"1",label:__("After title","wordpress-popular-posts"),value:t.header_end,onChange:function(e){return a({header_end:e})}}),React.createElement(_,{rows:"1",label:__("Before popular posts","wordpress-popular-posts"),value:t.wpp_start,onChange:function(e){return a({wpp_start:e})}}),React.createElement(_,{rows:"1",label:__("After popular posts","wordpress-popular-posts"),value:t.wpp_end,onChange:function(e){return a({wpp_end:e})}}),React.createElement(_,{label:__("Post HTML markup","wordpress-popular-posts"),value:t.post_html,onChange:function(e){return a({post_html:e})}})),React.createElement(b,{label:__("Theme","wordpress-popular-posts"),value:t.theme,options:r,onChange:function(e){if(void 0!==s.state.themes[e]){var t=s.state.themes[e].json.config;a({shorten_title:t.shorten_title.active,title_length:t.shorten_title.length,title_by_words:t.shorten_title.words?1:0,display_post_excerpt:t["post-excerpt"].active,excerpt_format:t["post-excerpt"].format,excerpt_length:t["post-excerpt"].length,excerpt_by_words:t["post-excerpt"].words?1:0,display_post_thumbnail:t.thumbnail.active,thumbnail_build:t.thumbnail.build,thumbnail_width:t.thumbnail.width,thumbnail_height:t.thumbnail.height,stats_comments:t.stats_tag.comment_count,stats_views:t.stats_tag.views,stats_author:t.stats_tag.author,stats_date:t.stats_tag.date.active,stats_date_format:t.stats_tag.date.format,stats_taxonomy:t.stats_tag.taxonomy.active,taxonomy:t.stats_tag.taxonomy.name,custom_html:!0,wpp_start:t.markup["wpp-start"],wpp_end:t.markup["wpp-end"],post_html:t.markup["post-html"],theme:e})}else a({theme:e})}}))}},{key:"render",value:function(){if(!this.state.taxonomies||!this.state.themes||!this.state.imgSizes)return React.createElement(f,null);var e=this.props,t=e.isSelected,a=e.className,s=e.attributes,r=a;return r+=this.state.editMode?" in-edit-mode":" in-preview-mode",r+=t?" is-selected":"",[this.getBlockControls(),React.createElement("div",{className:r},this.state.editMode&&React.createElement(u,null,this.getMainFields(),this.getFiltersFields(),this.getPostSettingsFields(),this.getStatsTagFields(),this.getHTMLMarkupFields()),!this.state.editMode&&React.createElement(h,null,React.createElement(l,{block:this.props.name,className:a,attributes:s,urlQueryArgs:{isSelected:t}})))]}}])&&s(t.prototype,a),Object.defineProperty(t,"prototype",{writable:!1}),x}(p),R=wp.blocks.registerBlockType,E=wp.i18n.__;R("wordpress-popular-posts/widget",{title:"WordPress Popular Posts",category:"widgets",icon:t.flame,description:E("A highly customizable block that displays your most popular posts.","wordpress-popular-posts"),keywords:["popular","posts","trending","popularity"],attributes:{_editMode:{type:"boolean",default:!0},_isSelected:{type:"boolean",default:!1},title:{type:"string"},limit:{type:"number",default:10},offset:{type:"number",default:0},order_by:{type:"string",default:"views"},range:{type:"string",default:"last24hours"},time_quantity:{type:"number",default:24},time_unit:{type:"string",default:"hour"},freshness:{type:"boolean",default:!1},post_type:{type:"string",default:"post"},pid:{type:"string",default:""},author:{type:"string",default:""},tax:{type:"string",default:""},term_id:{type:"string",default:""},shorten_title:{type:"boolean",default:!1},title_length:{type:"number",default:0},title_by_words:{type:"number",default:0},display_post_excerpt:{type:"boolean",default:!1},excerpt_format:{type:"boolean",default:!1},excerpt_length:{type:"number",default:0},excerpt_by_words:{type:"number",default:0},display_post_thumbnail:{type:"boolean",default:!1},thumbnail_width:{type:"number",default:0},thumbnail_height:{type:"number",default:0},thumbnail_build:{type:"string",default:"manual"},thumbnail_size:{type:"string",default:""},stats_comments:{type:"boolean",default:!1},stats_views:{type:"boolean",default:!0},stats_author:{type:"boolean",default:!1},stats_date:{type:"boolean",default:!1},stats_date_format:{type:"string",default:"F j, Y"},stats_taxonomy:{type:"boolean",default:!1},taxonomy:{type:"string",default:""},custom_html:{type:"boolean",default:!1},header_start:{type:"string",default:"<h2>"},header_end:{type:"string",default:"</h2>"},wpp_start:{type:"string",default:'<ul class="wpp-list">'},wpp_end:{type:"string",default:"</ul>"},post_html:{type:"string",default:'<li>{thumb} {title} <span class="wpp-meta post-stats">{stats}</span></li>'},theme:{type:"string",default:""}},supports:{anchor:!0,align:!0,html:!1},example:{attributes:{_editMode:!1,title:"Popular Posts",limit:3,range:"last7days",display_post_excerpt:!0,excerpt_length:75,display_post_thumbnail:!0,thumbnail_width:75,thumbnail_height:75,stats_views:!1,stats_taxonomy:!0,custom_html:!0,wpp_start:'<ul class="wpp-list wpp-cards">',post_html:'<li>{thumb_img} <div class="wpp-item-data"><div class="taxonomies">{taxonomy}</div>{title} <p class="wpp-excerpt">{excerpt}</p></div></li>',theme:"cards"}},edit:x,save:function(){return null}})}();
i18n/wordpress-popular-posts.pot CHANGED
@@ -5,7 +5,7 @@ msgid ""
5
  msgstr ""
6
  "Project-Id-Version: WordPress Popular Posts\n"
7
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/wordpress-popular-posts\n"
8
- "POT-Creation-Date: 2022-01-11 12:42-0400\n"
9
  "PO-Revision-Date: 2015-04-24 13:30-0430\n"
10
  "Last-Translator: Héctor Cabrera <hcabrerab@gmail.com>\n"
11
  "Language-Team: Héctor Cabrera <me@cabrerahector.com>\n"
@@ -29,7 +29,7 @@ msgstr ""
29
  msgid "Preview"
30
  msgstr ""
31
 
32
- #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/Admin.php:1141
33
  #: src/Block/Widget/edit.js:125
34
  msgid "Edit"
35
  msgstr ""
@@ -39,7 +39,7 @@ msgstr ""
39
  msgid "Title"
40
  msgstr ""
41
 
42
- #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/admin-page.php:142
43
  #: src/Block/Widget/edit.js:181
44
  msgid "Limit"
45
  msgstr ""
@@ -59,7 +59,7 @@ msgstr ""
59
  msgid "Avg. daily views"
60
  msgstr ""
61
 
62
- #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/Admin.php:767
63
  #: src/Block/Widget/edit.js:191 src/Widget/form.php:21
64
  msgid "Comments"
65
  msgstr ""
@@ -73,12 +73,12 @@ msgstr ""
73
  msgid "Last 24 Hours"
74
  msgstr ""
75
 
76
- #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/admin-page.php:198
77
  #: src/Block/Widget/edit.js:200 src/Widget/form.php:35
78
  msgid "Last 7 days"
79
  msgstr ""
80
 
81
- #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/admin-page.php:199
82
  #: src/Block/Widget/edit.js:201 src/Widget/form.php:36
83
  msgid "Last 30 days"
84
  msgstr ""
@@ -88,7 +88,7 @@ msgstr ""
88
  msgid "All-time"
89
  msgstr ""
90
 
91
- #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/admin-page.php:200
92
  #: src/Block/Widget/edit.js:203 src/Widget/form.php:38
93
  msgid "Custom"
94
  msgstr ""
@@ -101,22 +101,22 @@ msgstr ""
101
  msgid "Time Unit"
102
  msgstr ""
103
 
104
- #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/admin-page.php:169
105
- #: src/Admin/admin-page.php:416 src/Block/Widget/edit.js:218 src/Widget/form.php:45
106
  msgid "Minute(s)"
107
  msgstr ""
108
 
109
- #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/admin-page.php:170
110
- #: src/Admin/admin-page.php:417 src/Block/Widget/edit.js:219 src/Widget/form.php:46
111
  msgid "Hour(s)"
112
  msgstr ""
113
 
114
- #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/admin-page.php:171
115
- #: src/Admin/admin-page.php:418 src/Block/Widget/edit.js:220 src/Widget/form.php:47
116
  msgid "Day(s)"
117
  msgstr ""
118
 
119
- #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/admin-page.php:145
120
  #: src/Block/Widget/edit.js:227 src/Widget/form.php:52
121
  msgid "Display only posts published within the selected Time Range"
122
  msgstr ""
@@ -327,119 +327,119 @@ msgstr ""
327
  msgid "Theme"
328
  msgstr ""
329
 
330
- #: src/Admin/Admin.php:373
331
  #, php-format
332
  msgid "%s view in the last hour"
333
  msgid_plural "%s views in the last hour"
334
  msgstr[0] ""
335
  msgstr[1] ""
336
 
337
- #: src/Admin/Admin.php:407 src/Admin/admin-page.php:215
338
  msgid "Trending now"
339
  msgstr ""
340
 
341
- #: src/Admin/Admin.php:495
342
  msgid "View more"
343
  msgstr ""
344
 
345
- #: src/Admin/Admin.php:524
346
  msgid "Use this image"
347
  msgstr ""
348
 
349
- #: src/Admin/Admin.php:528
350
  msgid ""
351
  "This operation will delete all entries from WordPress Popular Posts' cache table and "
352
  "cannot be undone."
353
  msgstr ""
354
 
355
- #: src/Admin/Admin.php:529
356
  msgid "Success! The cache table has been cleared!"
357
  msgstr ""
358
 
359
- #: src/Admin/Admin.php:530
360
  msgid "Error: cache table does not exist."
361
  msgstr ""
362
 
363
- #: src/Admin/Admin.php:531
364
  msgid ""
365
  "This operation will delete all stored info from WordPress Popular Posts' data tables "
366
  "and cannot be undone."
367
  msgstr ""
368
 
369
- #: src/Admin/Admin.php:532
370
  msgid "Success! All data have been cleared!"
371
  msgstr ""
372
 
373
- #: src/Admin/Admin.php:533
374
  msgid "Error: one or both data tables are missing."
375
  msgstr ""
376
 
377
- #: src/Admin/Admin.php:534
378
  msgid "This operation will delete all cached thumbnails and cannot be undone."
379
  msgstr ""
380
 
381
- #: src/Admin/Admin.php:535
382
  msgid "Success! All files have been deleted!"
383
  msgstr ""
384
 
385
- #: src/Admin/Admin.php:536
386
  msgid "The thumbnail cache is already empty!"
387
  msgstr ""
388
 
389
- #: src/Admin/Admin.php:537
390
  msgid "Do you want to continue?"
391
  msgstr ""
392
 
393
- #: src/Admin/Admin.php:538
394
  msgid ""
395
  "Sorry, you do not have enough permissions to do this. Please contact the site "
396
  "administrator for support."
397
  msgstr ""
398
 
399
- #: src/Admin/Admin.php:539
400
  msgid "Invalid action."
401
  msgstr ""
402
 
403
- #: src/Admin/Admin.php:618
404
  msgid "Overview"
405
  msgstr ""
406
 
407
- #: src/Admin/Admin.php:619
408
  msgid ""
409
  "Welcome to WordPress Popular Posts' Dashboard! In this screen you will find statistics "
410
  "on what's popular on your site, tools to further tweak WPP to your needs, and more!"
411
  msgstr ""
412
 
413
- #: src/Admin/Admin.php:625
414
  msgid "Like this plugin?"
415
  msgstr ""
416
 
417
- #: src/Admin/Admin.php:627
418
  msgid ""
419
  "Each donation motivates me to keep releasing free stuff for the WordPress community!"
420
  msgstr ""
421
 
422
- #: src/Admin/Admin.php:634
423
  #, php-format
424
  msgid "You can <a href=\"%s\" target=\"_blank\">leave a review</a>, too!"
425
  msgstr ""
426
 
427
- #: src/Admin/Admin.php:641
428
  #, php-format
429
  msgid ""
430
  "<p><strong>For more information:</strong></p><ul><li><a href=\"%1$s\">Documentation</"
431
  "a></li><li><a href=\"%2$s\">Support</a></li></ul>"
432
  msgstr ""
433
 
434
- #: src/Admin/Admin.php:667
435
  msgid "Settings"
436
  msgstr ""
437
 
438
- #: src/Admin/Admin.php:668
439
  msgid "Support"
440
  msgstr ""
441
 
442
- #: src/Admin/Admin.php:746 src/Admin/Admin.php:1135 src/Admin/Admin.php:1139
443
  #: src/Output.php:788
444
  #, php-format
445
  msgid "%s view"
@@ -447,7 +447,7 @@ msgid_plural "%s views"
447
  msgstr[0] ""
448
  msgstr[1] ""
449
 
450
- #: src/Admin/Admin.php:746 src/Admin/Admin.php:1137 src/Admin/Admin.php:1139
451
  #: src/Output.php:771
452
  #, php-format
453
  msgid "%s comment"
@@ -455,41 +455,41 @@ msgid_plural "%s comments"
455
  msgstr[0] ""
456
  msgstr[1] ""
457
 
458
- #: src/Admin/Admin.php:771
459
  msgid "Views"
460
  msgstr ""
461
 
462
- #: src/Admin/Admin.php:1141
463
  msgid "View"
464
  msgstr ""
465
 
466
- #: src/Admin/Admin.php:1152
467
  msgid ""
468
  "Looks like your site's activity is a little low right now. <br />Spread the word and "
469
  "come back later!"
470
  msgstr ""
471
 
472
- #: src/Admin/Admin.php:1410
473
  #, php-format
474
  msgid ""
475
  "<strong>WordPress Popular Posts:</strong> It seems your site is popular (great!) You "
476
- "may want to check <a href=\"%s\">these suggestions</a> to make sure your website's "
477
  "performance stays up to par."
478
  msgstr ""
479
 
480
- #: src/Admin/Admin.php:1414
481
  msgid "Dismiss"
482
  msgstr ""
483
 
484
- #: src/Admin/Admin.php:1414
485
  msgid "Remind me later"
486
  msgstr ""
487
 
488
- #: src/Admin/admin-page.php:6 src/Admin/admin-page.php:114
489
  msgid "Stats"
490
  msgstr ""
491
 
492
- #: src/Admin/admin-page.php:7 src/Admin/admin-page.php:115
493
  msgid "Tools"
494
  msgstr ""
495
 
@@ -506,44 +506,45 @@ msgstr ""
506
  msgid "Please provide the name of your custom field."
507
  msgstr ""
508
 
509
- #: src/Admin/admin-page.php:113
510
  msgid "Menu"
511
  msgstr ""
512
 
513
- #: src/Admin/admin-page.php:139
514
  msgid "Post type"
515
  msgstr ""
516
 
517
- #: src/Admin/admin-page.php:151 src/Admin/admin-page.php:183 src/Admin/admin-page.php:343
518
- #: src/Admin/admin-page.php:450 src/Admin/admin-page.php:496
 
519
  msgid "Apply"
520
  msgstr ""
521
 
522
- #: src/Admin/admin-page.php:152 src/Admin/admin-page.php:186
523
  msgid "Cancel"
524
  msgstr ""
525
 
526
- #: src/Admin/admin-page.php:161
527
  msgid "Custom Time Range"
528
  msgstr ""
529
 
530
- #: src/Admin/admin-page.php:162
531
  msgid "Date Range"
532
  msgstr ""
533
 
534
- #: src/Admin/admin-page.php:176
535
  msgid "Select a date..."
536
  msgstr ""
537
 
538
- #: src/Admin/admin-page.php:196
539
  msgid "Today"
540
  msgstr ""
541
 
542
- #: src/Admin/admin-page.php:197 src/Widget/form.php:34
543
  msgid "Last 24 hours"
544
  msgstr ""
545
 
546
- #: src/Admin/admin-page.php:204
547
  #, php-format
548
  msgid ""
549
  "Err... A nice little chart is supposed to be here, instead you are seeing this because "
@@ -551,210 +552,212 @@ msgid ""
551
  "browser</a>."
552
  msgstr ""
553
 
554
- #: src/Admin/admin-page.php:213
555
  msgid "See your most viewed posts within the selected time range"
556
  msgstr ""
557
 
558
- #: src/Admin/admin-page.php:213
559
  msgid "Most viewed"
560
  msgstr ""
561
 
562
- #: src/Admin/admin-page.php:214
563
  msgid "See your most commented posts within the selected time range"
564
  msgstr ""
565
 
566
- #: src/Admin/admin-page.php:214
567
  msgid "Most commented"
568
  msgstr ""
569
 
570
- #: src/Admin/admin-page.php:215
571
  msgid "See your most viewed posts within the last hour"
572
  msgstr ""
573
 
574
- #: src/Admin/admin-page.php:216
575
  msgid "See your most viewed posts of all time"
576
  msgstr ""
577
 
578
- #: src/Admin/admin-page.php:216
579
  msgid "Hall of Fame"
580
  msgstr ""
581
 
582
- #: src/Admin/admin-page.php:256
583
  msgid "Thumbnails"
584
  msgstr ""
585
 
586
- #: src/Admin/admin-page.php:262
587
  msgid "Default thumbnail"
588
  msgstr ""
589
 
590
- #: src/Admin/admin-page.php:283
591
  msgid "Change thumbnail"
592
  msgstr ""
593
 
594
- #: src/Admin/admin-page.php:286
595
  msgid "This image will be displayed when no thumbnail is available"
596
  msgstr ""
597
 
598
- #: src/Admin/admin-page.php:290
599
  msgid "Pick image from"
600
  msgstr ""
601
 
602
- #: src/Admin/admin-page.php:293
603
  msgid "Featured image"
604
  msgstr ""
605
 
606
- #: src/Admin/admin-page.php:294
607
  msgid "First image on post"
608
  msgstr ""
609
 
610
- #: src/Admin/admin-page.php:295
611
  msgid "First attachment"
612
  msgstr ""
613
 
614
- #: src/Admin/admin-page.php:296
615
  msgid "Custom field"
616
  msgstr ""
617
 
618
- #: src/Admin/admin-page.php:299
619
  msgid "Tell WordPress Popular Posts where it should get thumbnails from"
620
  msgstr ""
621
 
622
- #: src/Admin/admin-page.php:303
623
  msgid "Lazy load"
624
  msgstr ""
625
 
626
- #: src/Admin/admin-page.php:303 src/Admin/admin-page.php:400 src/Admin/admin-page.php:428
627
- #: src/Widget/form.php:7 src/Widget/form.php:54 src/Widget/form.php:60
628
- #: src/Widget/form.php:88 src/Widget/form.php:98 src/Widget/form.php:190
 
629
  msgid "What is this?"
630
  msgstr ""
631
 
632
- #: src/Admin/admin-page.php:306
633
  msgid "No"
634
  msgstr ""
635
 
636
- #: src/Admin/admin-page.php:307 src/Admin/admin-page.php:322
637
  msgid "Yes"
638
  msgstr ""
639
 
640
- #: src/Admin/admin-page.php:312
641
  msgid "Custom field name"
642
  msgstr ""
643
 
644
- #: src/Admin/admin-page.php:318
645
  msgid "Resize image from Custom field?"
646
  msgstr ""
647
 
648
- #: src/Admin/admin-page.php:321
649
  msgid "No, use image as is"
650
  msgstr ""
651
 
652
- #: src/Admin/admin-page.php:333
653
  msgid "Empty image cache"
654
  msgstr ""
655
 
656
- #: src/Admin/admin-page.php:334
657
  msgid "Use this button to clear WPP's thumbnails cache"
658
  msgstr ""
659
 
660
- #: src/Admin/admin-page.php:354
661
  msgid "Data"
662
  msgstr ""
663
 
664
- #: src/Admin/admin-page.php:360
665
  msgid "Log views from"
666
  msgstr ""
667
 
668
- #: src/Admin/admin-page.php:363
669
  msgid "Visitors only"
670
  msgstr ""
671
 
672
- #: src/Admin/admin-page.php:364
673
  msgid "Logged-in users only"
674
  msgstr ""
675
 
676
- #: src/Admin/admin-page.php:365
677
  msgid "Everyone"
678
  msgstr ""
679
 
680
- #: src/Admin/admin-page.php:371
681
  msgid "Log limit"
682
  msgstr ""
683
 
684
- #: src/Admin/admin-page.php:374 src/Admin/admin-page.php:391 src/Admin/admin-page.php:431
685
- #: src/Admin/admin-page.php:481
686
  msgid "Disabled"
687
  msgstr ""
688
 
689
- #: src/Admin/admin-page.php:375
690
  msgid "Keep data for"
691
  msgstr ""
692
 
693
- #: src/Admin/admin-page.php:379
694
  msgid "day(s)"
695
  msgstr ""
696
 
697
- #: src/Admin/admin-page.php:382
698
  msgid "Data older than the specified time frame will be automatically discarded"
699
  msgstr ""
700
 
701
- #: src/Admin/admin-page.php:388
702
  msgid "Ajaxify widget"
703
  msgstr ""
704
 
705
- #: src/Admin/admin-page.php:392 src/Admin/admin-page.php:432 src/Admin/admin-page.php:480
 
706
  msgid "Enabled"
707
  msgstr ""
708
 
709
- #: src/Admin/admin-page.php:396
710
  msgid ""
711
  "If you are using a caching plugin such as WP Super Cache, enabling this feature will "
712
  "keep the popular list from being cached by it"
713
  msgstr ""
714
 
715
- #: src/Admin/admin-page.php:400
716
  msgid "Data Caching"
717
  msgstr ""
718
 
719
- #: src/Admin/admin-page.php:403
720
  msgid "Never cache"
721
  msgstr ""
722
 
723
- #: src/Admin/admin-page.php:404
724
  msgid "Enable caching"
725
  msgstr ""
726
 
727
- #: src/Admin/admin-page.php:408
728
  msgid ""
729
  "WPP can cache the popular list for a specified amount of time. Recommended for large / "
730
  "high traffic sites"
731
  msgstr ""
732
 
733
- #: src/Admin/admin-page.php:412
734
  msgid "Refresh cache every"
735
  msgstr ""
736
 
737
- #: src/Admin/admin-page.php:419
738
  msgid "Week(s)"
739
  msgstr ""
740
 
741
- #: src/Admin/admin-page.php:420
742
  msgid "Month(s)"
743
  msgstr ""
744
 
745
- #: src/Admin/admin-page.php:421
746
  msgid "Year(s)"
747
  msgstr ""
748
 
749
- #: src/Admin/admin-page.php:424
750
  msgid "Really? That long?"
751
  msgstr ""
752
 
753
- #: src/Admin/admin-page.php:428
754
  msgid "Data Sampling"
755
  msgstr ""
756
 
757
- #: src/Admin/admin-page.php:436
758
  #, php-format
759
  msgid ""
760
  "By default, WordPress Popular Posts stores in database every single visit your site "
@@ -765,49 +768,49 @@ msgid ""
765
  "(for more, <a href=\"%2$s\" target=\"_blank\">please read here</a>)"
766
  msgstr ""
767
 
768
- #: src/Admin/admin-page.php:440
769
  msgid "Sample Rate"
770
  msgstr ""
771
 
772
- #: src/Admin/admin-page.php:444
773
  #, php-format
774
  msgid ""
775
  "A sampling rate of %d is recommended for large / high traffic sites. For lower traffic "
776
  "sites, you should lower the value"
777
  msgstr ""
778
 
779
- #: src/Admin/admin-page.php:461
780
  msgid "Miscellaneous"
781
  msgstr ""
782
 
783
- #: src/Admin/admin-page.php:467
784
  msgid "Open links in"
785
  msgstr ""
786
 
787
- #: src/Admin/admin-page.php:470
788
  msgid "Current window"
789
  msgstr ""
790
 
791
- #: src/Admin/admin-page.php:471
792
  msgid "New tab/window"
793
  msgstr ""
794
 
795
- #: src/Admin/admin-page.php:477
796
  msgid "Use plugin's stylesheet"
797
  msgstr ""
798
 
799
- #: src/Admin/admin-page.php:484
800
  msgid ""
801
  "By default, the plugin includes a stylesheet called wpp.css which you can use to style "
802
  "your popular posts listing. If you wish to use your own stylesheet or do not want it "
803
  "to have it included in the header section of your site, use this."
804
  msgstr ""
805
 
806
- #: src/Admin/admin-page.php:488
807
  msgid "Enable experimental features"
808
  msgstr ""
809
 
810
- #: src/Admin/admin-page.php:510
811
  msgid ""
812
  "WordPress Popular Posts maintains data in two separate tables: one for storing the "
813
  "most popular entries on a daily basis (from now on, \"cache\"), and another one to "
@@ -816,19 +819,19 @@ msgid ""
816
  "tables, please use the buttons below to do so."
817
  msgstr ""
818
 
819
- #: src/Admin/admin-page.php:511
820
  msgid "Empty cache"
821
  msgstr ""
822
 
823
- #: src/Admin/admin-page.php:511
824
  msgid "Use this button to manually clear entries from WPP cache only"
825
  msgstr ""
826
 
827
- #: src/Admin/admin-page.php:512
828
  msgid "Clear all data"
829
  msgstr ""
830
 
831
- #: src/Admin/admin-page.php:512
832
  msgid "Use this button to manually clear entries from all WPP data tables"
833
  msgstr ""
834
 
@@ -872,75 +875,75 @@ msgstr ""
872
  msgid "under %s"
873
  msgstr ""
874
 
875
- #: src/Rest/PostsEndpoint.php:97
876
  msgid "Return popular posts from specified custom post type(s)."
877
  msgstr ""
878
 
879
- #: src/Rest/PostsEndpoint.php:104
880
  msgid "The maximum number of popular posts to return."
881
  msgstr ""
882
 
883
- #: src/Rest/PostsEndpoint.php:112
884
  msgid "Retrieve the most popular entries published within the specified time range."
885
  msgstr ""
886
 
887
- #: src/Rest/PostsEndpoint.php:120
888
  msgid "An offset point for the collection."
889
  msgstr ""
890
 
891
- #: src/Rest/PostsEndpoint.php:128
892
  msgid "Set the sorting option of the popular posts."
893
  msgstr ""
894
 
895
- #: src/Rest/PostsEndpoint.php:136
896
  msgid "Return popular posts from a specified time range."
897
  msgstr ""
898
 
899
- #: src/Rest/PostsEndpoint.php:144
900
  msgid "Specifies the time unit of the custom time range."
901
  msgstr ""
902
 
903
- #: src/Rest/PostsEndpoint.php:152
904
  msgid "Specifies the number of time units of the custom time range."
905
  msgstr ""
906
 
907
- #: src/Rest/PostsEndpoint.php:160
908
  msgid "Post IDs to exclude from the listing."
909
  msgstr ""
910
 
911
- #: src/Rest/PostsEndpoint.php:168
912
  msgid "Include posts in a specified taxonomy."
913
  msgstr ""
914
 
915
- #: src/Rest/PostsEndpoint.php:176
916
  msgid "Taxonomy IDs, separated by comma (prefix a minus sign to exclude)."
917
  msgstr ""
918
 
919
- #: src/Rest/PostsEndpoint.php:184
920
  msgid "Include popular posts from author ID(s)."
921
  msgstr ""
922
 
923
- #: src/Rest/ViewLoggerEndpoint.php:214
924
  msgid "Security nonce."
925
  msgstr ""
926
 
927
- #: src/Rest/ViewLoggerEndpoint.php:220
928
  msgid "The post / page ID."
929
  msgstr ""
930
 
931
- #: src/Rest/ViewLoggerEndpoint.php:227
932
  msgid "Enables Data Sampling."
933
  msgstr ""
934
 
935
- #: src/Rest/ViewLoggerEndpoint.php:234
936
  msgid "Sets the Sampling Rate."
937
  msgstr ""
938
 
939
- #: src/Rest/WidgetEndpoint.php:78
940
  msgid "Invalid Widget Instance ID"
941
  msgstr ""
942
 
943
- #: src/Widget/Widget.php:77
944
  msgid "The most Popular Posts on your blog."
945
  msgstr ""
946
 
@@ -993,10 +996,3 @@ msgstr ""
993
  #: src/Widget/form.php:234
994
  msgid "Please save this widget (or reload this page) to enable WPP themes."
995
  msgstr ""
996
-
997
- #: wordpress-popular-posts.php:52
998
- #, php-format
999
- msgid ""
1000
- "WordPress Popular Posts requires at least PHP %1$s and WordPress %2$s to function "
1001
- "correctly. Your site uses PHP %3$s and WordPress %4$s."
1002
- msgstr ""
5
  msgstr ""
6
  "Project-Id-Version: WordPress Popular Posts\n"
7
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/wordpress-popular-posts\n"
8
+ "POT-Creation-Date: 2022-06-24 15:06-0400\n"
9
  "PO-Revision-Date: 2015-04-24 13:30-0430\n"
10
  "Last-Translator: Héctor Cabrera <hcabrerab@gmail.com>\n"
11
  "Language-Team: Héctor Cabrera <me@cabrerahector.com>\n"
29
  msgid "Preview"
30
  msgstr ""
31
 
32
+ #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/Admin.php:1136
33
  #: src/Block/Widget/edit.js:125
34
  msgid "Edit"
35
  msgstr ""
39
  msgid "Title"
40
  msgstr ""
41
 
42
+ #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/screen-stats.php:21
43
  #: src/Block/Widget/edit.js:181
44
  msgid "Limit"
45
  msgstr ""
59
  msgid "Avg. daily views"
60
  msgstr ""
61
 
62
+ #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/Admin.php:765
63
  #: src/Block/Widget/edit.js:191 src/Widget/form.php:21
64
  msgid "Comments"
65
  msgstr ""
73
  msgid "Last 24 Hours"
74
  msgstr ""
75
 
76
+ #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/screen-stats.php:78
77
  #: src/Block/Widget/edit.js:200 src/Widget/form.php:35
78
  msgid "Last 7 days"
79
  msgstr ""
80
 
81
+ #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/screen-stats.php:79
82
  #: src/Block/Widget/edit.js:201 src/Widget/form.php:36
83
  msgid "Last 30 days"
84
  msgstr ""
88
  msgid "All-time"
89
  msgstr ""
90
 
91
+ #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/screen-stats.php:80
92
  #: src/Block/Widget/edit.js:203 src/Widget/form.php:38
93
  msgid "Custom"
94
  msgstr ""
101
  msgid "Time Unit"
102
  msgstr ""
103
 
104
+ #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/screen-stats.php:49
105
+ #: src/Admin/screen-tools.php:171 src/Block/Widget/edit.js:218 src/Widget/form.php:45
106
  msgid "Minute(s)"
107
  msgstr ""
108
 
109
+ #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/screen-stats.php:50
110
+ #: src/Admin/screen-tools.php:172 src/Block/Widget/edit.js:219 src/Widget/form.php:46
111
  msgid "Hour(s)"
112
  msgstr ""
113
 
114
+ #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/screen-stats.php:51
115
+ #: src/Admin/screen-tools.php:173 src/Block/Widget/edit.js:220 src/Widget/form.php:47
116
  msgid "Day(s)"
117
  msgstr ""
118
 
119
+ #: assets/js/blocks/block-wpp-widget.js:1 src/Admin/screen-stats.php:24
120
  #: src/Block/Widget/edit.js:227 src/Widget/form.php:52
121
  msgid "Display only posts published within the selected Time Range"
122
  msgstr ""
327
  msgid "Theme"
328
  msgstr ""
329
 
330
+ #: src/Admin/Admin.php:371
331
  #, php-format
332
  msgid "%s view in the last hour"
333
  msgid_plural "%s views in the last hour"
334
  msgstr[0] ""
335
  msgstr[1] ""
336
 
337
+ #: src/Admin/Admin.php:405 src/Admin/screen-stats.php:92
338
  msgid "Trending now"
339
  msgstr ""
340
 
341
+ #: src/Admin/Admin.php:493
342
  msgid "View more"
343
  msgstr ""
344
 
345
+ #: src/Admin/Admin.php:522
346
  msgid "Use this image"
347
  msgstr ""
348
 
349
+ #: src/Admin/Admin.php:526
350
  msgid ""
351
  "This operation will delete all entries from WordPress Popular Posts' cache table and "
352
  "cannot be undone."
353
  msgstr ""
354
 
355
+ #: src/Admin/Admin.php:527
356
  msgid "Success! The cache table has been cleared!"
357
  msgstr ""
358
 
359
+ #: src/Admin/Admin.php:528
360
  msgid "Error: cache table does not exist."
361
  msgstr ""
362
 
363
+ #: src/Admin/Admin.php:529
364
  msgid ""
365
  "This operation will delete all stored info from WordPress Popular Posts' data tables "
366
  "and cannot be undone."
367
  msgstr ""
368
 
369
+ #: src/Admin/Admin.php:530
370
  msgid "Success! All data have been cleared!"
371
  msgstr ""
372
 
373
+ #: src/Admin/Admin.php:531
374
  msgid "Error: one or both data tables are missing."
375
  msgstr ""
376
 
377
+ #: src/Admin/Admin.php:532
378
  msgid "This operation will delete all cached thumbnails and cannot be undone."
379
  msgstr ""
380
 
381
+ #: src/Admin/Admin.php:533
382
  msgid "Success! All files have been deleted!"
383
  msgstr ""
384
 
385
+ #: src/Admin/Admin.php:534
386
  msgid "The thumbnail cache is already empty!"
387
  msgstr ""
388
 
389
+ #: src/Admin/Admin.php:535
390
  msgid "Do you want to continue?"
391
  msgstr ""
392
 
393
+ #: src/Admin/Admin.php:536 src/Admin/screen-debug.php:5 src/Admin/screen-tools.php:5
394
  msgid ""
395
  "Sorry, you do not have enough permissions to do this. Please contact the site "
396
  "administrator for support."
397
  msgstr ""
398
 
399
+ #: src/Admin/Admin.php:537
400
  msgid "Invalid action."
401
  msgstr ""
402
 
403
+ #: src/Admin/Admin.php:616
404
  msgid "Overview"
405
  msgstr ""
406
 
407
+ #: src/Admin/Admin.php:617
408
  msgid ""
409
  "Welcome to WordPress Popular Posts' Dashboard! In this screen you will find statistics "
410
  "on what's popular on your site, tools to further tweak WPP to your needs, and more!"
411
  msgstr ""
412
 
413
+ #: src/Admin/Admin.php:623
414
  msgid "Like this plugin?"
415
  msgstr ""
416
 
417
+ #: src/Admin/Admin.php:625
418
  msgid ""
419
  "Each donation motivates me to keep releasing free stuff for the WordPress community!"
420
  msgstr ""
421
 
422
+ #: src/Admin/Admin.php:632
423
  #, php-format
424
  msgid "You can <a href=\"%s\" target=\"_blank\">leave a review</a>, too!"
425
  msgstr ""
426
 
427
+ #: src/Admin/Admin.php:639
428
  #, php-format
429
  msgid ""
430
  "<p><strong>For more information:</strong></p><ul><li><a href=\"%1$s\">Documentation</"
431
  "a></li><li><a href=\"%2$s\">Support</a></li></ul>"
432
  msgstr ""
433
 
434
+ #: src/Admin/Admin.php:665
435
  msgid "Settings"
436
  msgstr ""
437
 
438
+ #: src/Admin/Admin.php:666
439
  msgid "Support"
440
  msgstr ""
441
 
442
+ #: src/Admin/Admin.php:744 src/Admin/Admin.php:1130 src/Admin/Admin.php:1134
443
  #: src/Output.php:788
444
  #, php-format
445
  msgid "%s view"
447
  msgstr[0] ""
448
  msgstr[1] ""
449
 
450
+ #: src/Admin/Admin.php:744 src/Admin/Admin.php:1132 src/Admin/Admin.php:1134
451
  #: src/Output.php:771
452
  #, php-format
453
  msgid "%s comment"
455
  msgstr[0] ""
456
  msgstr[1] ""
457
 
458
+ #: src/Admin/Admin.php:769
459
  msgid "Views"
460
  msgstr ""
461
 
462
+ #: src/Admin/Admin.php:1136
463
  msgid "View"
464
  msgstr ""
465
 
466
+ #: src/Admin/Admin.php:1147
467
  msgid ""
468
  "Looks like your site's activity is a little low right now. <br />Spread the word and "
469
  "come back later!"
470
  msgstr ""
471
 
472
+ #: src/Admin/Admin.php:1406
473
  #, php-format
474
  msgid ""
475
  "<strong>WordPress Popular Posts:</strong> It seems your site is popular (great!) You "
476
+ "may want to check <a href=\"%s\">these recommendations</a> to make sure your website's "
477
  "performance stays up to par."
478
  msgstr ""
479
 
480
+ #: src/Admin/Admin.php:1410
481
  msgid "Dismiss"
482
  msgstr ""
483
 
484
+ #: src/Admin/Admin.php:1410
485
  msgid "Remind me later"
486
  msgstr ""
487
 
488
+ #: src/Admin/admin-page.php:6 src/Admin/admin-page.php:115
489
  msgid "Stats"
490
  msgstr ""
491
 
492
+ #: src/Admin/admin-page.php:7 src/Admin/admin-page.php:116
493
  msgid "Tools"
494
  msgstr ""
495
 
506
  msgid "Please provide the name of your custom field."
507
  msgstr ""
508
 
509
+ #: src/Admin/admin-page.php:114
510
  msgid "Menu"
511
  msgstr ""
512
 
513
+ #: src/Admin/screen-stats.php:18
514
  msgid "Post type"
515
  msgstr ""
516
 
517
+ #: src/Admin/screen-stats.php:30 src/Admin/screen-stats.php:63
518
+ #: src/Admin/screen-tools.php:97 src/Admin/screen-tools.php:205
519
+ #: src/Admin/screen-tools.php:252
520
  msgid "Apply"
521
  msgstr ""
522
 
523
+ #: src/Admin/screen-stats.php:31 src/Admin/screen-stats.php:66
524
  msgid "Cancel"
525
  msgstr ""
526
 
527
+ #: src/Admin/screen-stats.php:41
528
  msgid "Custom Time Range"
529
  msgstr ""
530
 
531
+ #: src/Admin/screen-stats.php:42
532
  msgid "Date Range"
533
  msgstr ""
534
 
535
+ #: src/Admin/screen-stats.php:56
536
  msgid "Select a date..."
537
  msgstr ""
538
 
539
+ #: src/Admin/screen-stats.php:76
540
  msgid "Today"
541
  msgstr ""
542
 
543
+ #: src/Admin/screen-stats.php:77 src/Widget/form.php:34
544
  msgid "Last 24 hours"
545
  msgstr ""
546
 
547
+ #: src/Admin/screen-stats.php:84
548
  #, php-format
549
  msgid ""
550
  "Err... A nice little chart is supposed to be here, instead you are seeing this because "
552
  "browser</a>."
553
  msgstr ""
554
 
555
+ #: src/Admin/screen-stats.php:90
556
  msgid "See your most viewed posts within the selected time range"
557
  msgstr ""
558
 
559
+ #: src/Admin/screen-stats.php:90
560
  msgid "Most viewed"
561
  msgstr ""
562
 
563
+ #: src/Admin/screen-stats.php:91
564
  msgid "See your most commented posts within the selected time range"
565
  msgstr ""
566
 
567
+ #: src/Admin/screen-stats.php:91
568
  msgid "Most commented"
569
  msgstr ""
570
 
571
+ #: src/Admin/screen-stats.php:92
572
  msgid "See your most viewed posts within the last hour"
573
  msgstr ""
574
 
575
+ #: src/Admin/screen-stats.php:93
576
  msgid "See your most viewed posts of all time"
577
  msgstr ""
578
 
579
+ #: src/Admin/screen-stats.php:93
580
  msgid "Hall of Fame"
581
  msgstr ""
582
 
583
+ #: src/Admin/screen-tools.php:10
584
  msgid "Thumbnails"
585
  msgstr ""
586
 
587
+ #: src/Admin/screen-tools.php:16
588
  msgid "Default thumbnail"
589
  msgstr ""
590
 
591
+ #: src/Admin/screen-tools.php:37
592
  msgid "Change thumbnail"
593
  msgstr ""
594
 
595
+ #: src/Admin/screen-tools.php:40
596
  msgid "This image will be displayed when no thumbnail is available"
597
  msgstr ""
598
 
599
+ #: src/Admin/screen-tools.php:44
600
  msgid "Pick image from"
601
  msgstr ""
602
 
603
+ #: src/Admin/screen-tools.php:47
604
  msgid "Featured image"
605
  msgstr ""
606
 
607
+ #: src/Admin/screen-tools.php:48
608
  msgid "First image on post"
609
  msgstr ""
610
 
611
+ #: src/Admin/screen-tools.php:49
612
  msgid "First attachment"
613
  msgstr ""
614
 
615
+ #: src/Admin/screen-tools.php:50
616
  msgid "Custom field"
617
  msgstr ""
618
 
619
+ #: src/Admin/screen-tools.php:53
620
  msgid "Tell WordPress Popular Posts where it should get thumbnails from"
621
  msgstr ""
622
 
623
+ #: src/Admin/screen-tools.php:57
624
  msgid "Lazy load"
625
  msgstr ""
626
 
627
+ #: src/Admin/screen-tools.php:57 src/Admin/screen-tools.php:155
628
+ #: src/Admin/screen-tools.php:183 src/Widget/form.php:7 src/Widget/form.php:54
629
+ #: src/Widget/form.php:60 src/Widget/form.php:88 src/Widget/form.php:98
630
+ #: src/Widget/form.php:190
631
  msgid "What is this?"
632
  msgstr ""
633
 
634
+ #: src/Admin/screen-tools.php:60
635
  msgid "No"
636
  msgstr ""
637
 
638
+ #: src/Admin/screen-tools.php:61 src/Admin/screen-tools.php:76
639
  msgid "Yes"
640
  msgstr ""
641
 
642
+ #: src/Admin/screen-tools.php:66
643
  msgid "Custom field name"
644
  msgstr ""
645
 
646
+ #: src/Admin/screen-tools.php:72
647
  msgid "Resize image from Custom field?"
648
  msgstr ""
649
 
650
+ #: src/Admin/screen-tools.php:75
651
  msgid "No, use image as is"
652
  msgstr ""
653
 
654
+ #: src/Admin/screen-tools.php:87
655
  msgid "Empty image cache"
656
  msgstr ""
657
 
658
+ #: src/Admin/screen-tools.php:88
659
  msgid "Use this button to clear WPP's thumbnails cache"
660
  msgstr ""
661
 
662
+ #: src/Admin/screen-tools.php:109
663
  msgid "Data"
664
  msgstr ""
665
 
666
+ #: src/Admin/screen-tools.php:115
667
  msgid "Log views from"
668
  msgstr ""
669
 
670
+ #: src/Admin/screen-tools.php:118
671
  msgid "Visitors only"
672
  msgstr ""
673
 
674
+ #: src/Admin/screen-tools.php:119
675
  msgid "Logged-in users only"
676
  msgstr ""
677
 
678
+ #: src/Admin/screen-tools.php:120
679
  msgid "Everyone"
680
  msgstr ""
681
 
682
+ #: src/Admin/screen-tools.php:126
683
  msgid "Log limit"
684
  msgstr ""
685
 
686
+ #: src/Admin/screen-tools.php:129 src/Admin/screen-tools.php:146
687
+ #: src/Admin/screen-tools.php:186 src/Admin/screen-tools.php:237
688
  msgid "Disabled"
689
  msgstr ""
690
 
691
+ #: src/Admin/screen-tools.php:130
692
  msgid "Keep data for"
693
  msgstr ""
694
 
695
+ #: src/Admin/screen-tools.php:134
696
  msgid "day(s)"
697
  msgstr ""
698
 
699
+ #: src/Admin/screen-tools.php:137
700
  msgid "Data older than the specified time frame will be automatically discarded"
701
  msgstr ""
702
 
703
+ #: src/Admin/screen-tools.php:143
704
  msgid "Ajaxify widget"
705
  msgstr ""
706
 
707
+ #: src/Admin/screen-tools.php:147 src/Admin/screen-tools.php:187
708
+ #: src/Admin/screen-tools.php:236
709
  msgid "Enabled"
710
  msgstr ""
711
 
712
+ #: src/Admin/screen-tools.php:151
713
  msgid ""
714
  "If you are using a caching plugin such as WP Super Cache, enabling this feature will "
715
  "keep the popular list from being cached by it"
716
  msgstr ""
717
 
718
+ #: src/Admin/screen-tools.php:155
719
  msgid "Data Caching"
720
  msgstr ""
721
 
722
+ #: src/Admin/screen-tools.php:158
723
  msgid "Never cache"
724
  msgstr ""
725
 
726
+ #: src/Admin/screen-tools.php:159
727
  msgid "Enable caching"
728
  msgstr ""
729
 
730
+ #: src/Admin/screen-tools.php:163
731
  msgid ""
732
  "WPP can cache the popular list for a specified amount of time. Recommended for large / "
733
  "high traffic sites"
734
  msgstr ""
735
 
736
+ #: src/Admin/screen-tools.php:167
737
  msgid "Refresh cache every"
738
  msgstr ""
739
 
740
+ #: src/Admin/screen-tools.php:174
741
  msgid "Week(s)"
742
  msgstr ""
743
 
744
+ #: src/Admin/screen-tools.php:175
745
  msgid "Month(s)"
746
  msgstr ""
747
 
748
+ #: src/Admin/screen-tools.php:176
749
  msgid "Year(s)"
750
  msgstr ""
751
 
752
+ #: src/Admin/screen-tools.php:179
753
  msgid "Really? That long?"
754
  msgstr ""
755
 
756
+ #: src/Admin/screen-tools.php:183
757
  msgid "Data Sampling"
758
  msgstr ""
759
 
760
+ #: src/Admin/screen-tools.php:191
761
  #, php-format
762
  msgid ""
763
  "By default, WordPress Popular Posts stores in database every single visit your site "
768
  "(for more, <a href=\"%2$s\" target=\"_blank\">please read here</a>)"
769
  msgstr ""
770
 
771
+ #: src/Admin/screen-tools.php:195
772
  msgid "Sample Rate"
773
  msgstr ""
774
 
775
+ #: src/Admin/screen-tools.php:199
776
  #, php-format
777
  msgid ""
778
  "A sampling rate of %d is recommended for large / high traffic sites. For lower traffic "
779
  "sites, you should lower the value"
780
  msgstr ""
781
 
782
+ #: src/Admin/screen-tools.php:217
783
  msgid "Miscellaneous"
784
  msgstr ""
785
 
786
+ #: src/Admin/screen-tools.php:223
787
  msgid "Open links in"
788
  msgstr ""
789
 
790
+ #: src/Admin/screen-tools.php:226
791
  msgid "Current window"
792
  msgstr ""
793
 
794
+ #: src/Admin/screen-tools.php:227
795
  msgid "New tab/window"
796
  msgstr ""
797
 
798
+ #: src/Admin/screen-tools.php:233
799
  msgid "Use plugin's stylesheet"
800
  msgstr ""
801
 
802
+ #: src/Admin/screen-tools.php:240
803
  msgid ""
804
  "By default, the plugin includes a stylesheet called wpp.css which you can use to style "
805
  "your popular posts listing. If you wish to use your own stylesheet or do not want it "
806
  "to have it included in the header section of your site, use this."
807
  msgstr ""
808
 
809
+ #: src/Admin/screen-tools.php:244
810
  msgid "Enable experimental features"
811
  msgstr ""
812
 
813
+ #: src/Admin/screen-tools.php:265
814
  msgid ""
815
  "WordPress Popular Posts maintains data in two separate tables: one for storing the "
816
  "most popular entries on a daily basis (from now on, \"cache\"), and another one to "
819
  "tables, please use the buttons below to do so."
820
  msgstr ""
821
 
822
+ #: src/Admin/screen-tools.php:266
823
  msgid "Empty cache"
824
  msgstr ""
825
 
826
+ #: src/Admin/screen-tools.php:266
827
  msgid "Use this button to manually clear entries from WPP cache only"
828
  msgstr ""
829
 
830
+ #: src/Admin/screen-tools.php:267
831
  msgid "Clear all data"
832
  msgstr ""
833
 
834
+ #: src/Admin/screen-tools.php:267
835
  msgid "Use this button to manually clear entries from all WPP data tables"
836
  msgstr ""
837
 
875
  msgid "under %s"
876
  msgstr ""
877
 
878
+ #: src/Rest/PostsEndpoint.php:115
879
  msgid "Return popular posts from specified custom post type(s)."
880
  msgstr ""
881
 
882
+ #: src/Rest/PostsEndpoint.php:122
883
  msgid "The maximum number of popular posts to return."
884
  msgstr ""
885
 
886
+ #: src/Rest/PostsEndpoint.php:130
887
  msgid "Retrieve the most popular entries published within the specified time range."
888
  msgstr ""
889
 
890
+ #: src/Rest/PostsEndpoint.php:138
891
  msgid "An offset point for the collection."
892
  msgstr ""
893
 
894
+ #: src/Rest/PostsEndpoint.php:146
895
  msgid "Set the sorting option of the popular posts."
896
  msgstr ""
897
 
898
+ #: src/Rest/PostsEndpoint.php:154
899
  msgid "Return popular posts from a specified time range."
900
  msgstr ""
901
 
902
+ #: src/Rest/PostsEndpoint.php:162
903
  msgid "Specifies the time unit of the custom time range."
904
  msgstr ""
905
 
906
+ #: src/Rest/PostsEndpoint.php:170
907
  msgid "Specifies the number of time units of the custom time range."
908
  msgstr ""
909
 
910
+ #: src/Rest/PostsEndpoint.php:178
911
  msgid "Post IDs to exclude from the listing."
912
  msgstr ""
913
 
914
+ #: src/Rest/PostsEndpoint.php:186
915
  msgid "Include posts in a specified taxonomy."
916
  msgstr ""
917
 
918
+ #: src/Rest/PostsEndpoint.php:194
919
  msgid "Taxonomy IDs, separated by comma (prefix a minus sign to exclude)."
920
  msgstr ""
921
 
922
+ #: src/Rest/PostsEndpoint.php:202
923
  msgid "Include popular posts from author ID(s)."
924
  msgstr ""
925
 
926
+ #: src/Rest/ViewLoggerEndpoint.php:220
927
  msgid "Security nonce."
928
  msgstr ""
929
 
930
+ #: src/Rest/ViewLoggerEndpoint.php:226
931
  msgid "The post / page ID."
932
  msgstr ""
933
 
934
+ #: src/Rest/ViewLoggerEndpoint.php:233
935
  msgid "Enables Data Sampling."
936
  msgstr ""
937
 
938
+ #: src/Rest/ViewLoggerEndpoint.php:240
939
  msgid "Sets the Sampling Rate."
940
  msgstr ""
941
 
942
+ #: src/Rest/WidgetEndpoint.php:83
943
  msgid "Invalid Widget Instance ID"
944
  msgstr ""
945
 
946
+ #: src/Widget/Widget.php:79
947
  msgid "The most Popular Posts on your blog."
948
  msgstr ""
949
 
996
  #: src/Widget/form.php:234
997
  msgid "Please save this widget (or reload this page) to enable WPP themes."
998
  msgstr ""
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -2,10 +2,10 @@
2
  Contributors: hcabrera
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=hcabrerab%40gmail%2ecom&lc=GB&item_name=WordPress%20Popular%20Posts%20Plugin&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG_global%2egif%3aNonHosted
4
  Tags: popular, posts, widget, popularity, top
5
- Requires at least: 4.9
6
- Tested up to: 5.9
7
- Requires PHP: 5.4
8
- Stable tag: 5.5.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -109,6 +109,23 @@ The FAQ section has been moved [here](https://github.com/cabrerahector/wordpress
109
 
110
  == Changelog ==
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  = 5.5.1 =
113
 
114
  **If you're using a caching plugin flushing its cache after upgrading to this version is highly recommended.**
@@ -130,38 +147,6 @@ The FAQ section has been moved [here](https://github.com/cabrerahector/wordpress
130
 
131
  [Release notes](https://cabrerahector.com/wordpress/wordpress-popular-posts-5-5-qol-improvements-and-php-5-announcement/)
132
 
133
- = 5.4.2 =
134
-
135
- - Fixes a rare issue that prevented some users from seeing the Statistics chart (thanks Zsolt!)
136
-
137
- [Release notes](https://cabrerahector.com/wordpress/wordpress-popular-posts-5-4-widget-block-improvements-plus-prep-work-for-csp-support/#5.4.2)
138
-
139
- = 5.4.1 =
140
-
141
- **If you're using a caching plugin flushing its cache after upgrading to this version is highly recommended.**
142
-
143
- - Widget block: fixes WPP block loading block editor JS files on the front end.
144
- - Adds filter hook to disable Block editor support.
145
- - Improves logic of filter hooks `wpp_excerpt_more` and `wpp_title_more`.
146
- - The Parameters section has been moved to the Wiki (see https://git.io/JEOrX).
147
-
148
- [Release notes](https://cabrerahector.com/wordpress/wordpress-popular-posts-5-4-widget-block-improvements-plus-prep-work-for-csp-support/#5.4.1)
149
-
150
- = 5.4.0 =
151
-
152
- **If you're using a caching plugin flushing its cache after upgrading to this version is highly recommended.**
153
-
154
- - The widget block is no longer an experimental feature and is now available to everyone (but it's still a WIP).
155
- - Widget block: adds AJAX support to prevent caching plugins from caching your popular posts block.
156
- - Widget block: adds WPML/Polylang support.
157
- - Widget block: fixes widget heading not displaying.
158
- - Widget themes: allow themes to detect the current post so it can be styled differently.
159
- - Fixes `wpp_excerpt_more` filter hook not working (props to SchweizerSchoggi!)
160
- - Adds filter hook `wpp_title_more` to allow customization of the prefix added to shortened post titles.
161
- - Removes inline JavaScript code from WPP's dashboard in preparation for [WordPress' CSP adoption](https://core.trac.wordpress.org/ticket/51407).
162
-
163
- [Release notes](https://cabrerahector.com/wordpress/wordpress-popular-posts-5-4-widget-block-improvements-plus-prep-work-for-csp-support/)
164
-
165
  [Full Changelog](https://github.com/cabrerahector/wordpress-popular-posts/blob/master/changelog.md)
166
 
167
  == Credits ==
2
  Contributors: hcabrera
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=hcabrerab%40gmail%2ecom&lc=GB&item_name=WordPress%20Popular%20Posts%20Plugin&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG_global%2egif%3aNonHosted
4
  Tags: popular, posts, widget, popularity, top
5
+ Requires at least: 5.3
6
+ Tested up to: 6.0
7
+ Requires PHP: 7.2
8
+ Stable tag: 6.0.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
109
 
110
  == Changelog ==
111
 
112
+ = 6.0.0 =
113
+
114
+ **This release introduces a couple of major changes so please review before updating.**
115
+
116
+ - Minimum required PHP version is now 7.2.
117
+ - Minimum required WordPress version is now 5.3.
118
+ - Breaking change: this version removes code that has been deprecated for a long time. See the release notes for more details.
119
+ - Widget block: fixes an issue where the length of the title when set via theme was being ignored.
120
+ - Widget block: fixes bug with thumbnail not rendering under certain circumstances (thanks the9mm!)
121
+ - Admin: the Statistics screen will now by default only lists posts. See the release notes for more details.
122
+ - Admin: only users with `edit_others_posts` capability (usually Editors and Administrators) will be able to access certain areas of WPP's dashboard.
123
+ - Admin: makes sure to escape params from `add_query_arg()`.
124
+ - Fixes an issue where widget themes stored in child theme's folder would not be recognized by the plugin.
125
+ - Small improvements / fixes.
126
+
127
+ [Release notes](https://cabrerahector.com/wordpress/wordpress-popular-posts-6-0-php-5-support-dropped-minimum-supported-wordpress-changed/)
128
+
129
  = 5.5.1 =
130
 
131
  **If you're using a caching plugin flushing its cache after upgrading to this version is highly recommended.**
147
 
148
  [Release notes](https://cabrerahector.com/wordpress/wordpress-popular-posts-5-5-qol-improvements-and-php-5-announcement/)
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  [Full Changelog](https://github.com/cabrerahector/wordpress-popular-posts/blob/master/changelog.md)
151
 
152
  == Credits ==
src/Activation/Activator.php CHANGED
@@ -27,7 +27,7 @@ class Activator {
27
  * @param bool $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog.
28
  * @global object $wpdb
29
  */
30
- public static function activate($network_wide)
31
  {
32
  global $wpdb;
33
 
@@ -91,7 +91,7 @@ class Activator {
91
  * @param string $prefix
92
  * @global object $wpdb
93
  */
94
- private static function do_db_tables($prefix)
95
  {
96
  global $wpdb;
97
  $charset_collate = "";
27
  * @param bool $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog.
28
  * @global object $wpdb
29
  */
30
+ public static function activate(bool $network_wide)
31
  {
32
  global $wpdb;
33
 
91
  * @param string $prefix
92
  * @global object $wpdb
93
  */
94
+ private static function do_db_tables(string $prefix)
95
  {
96
  global $wpdb;
97
  $charset_collate = "";
src/Activation/Deactivator.php CHANGED
@@ -27,7 +27,7 @@ class Deactivator {
27
  * @global object wpbd
28
  * @param bool network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog
29
  */
30
- public static function deactivate($network_wide)
31
  {
32
  global $wpdb;
33
 
27
  * @global object wpbd
28
  * @param bool network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog
29
  */
30
+ public static function deactivate(bool $network_wide)
31
  {
32
  global $wpdb;
33
 
src/Admin/Admin.php CHANGED
@@ -12,9 +12,7 @@
12
 
13
  namespace WordPressPopularPosts\Admin;
14
 
15
- use WordPressPopularPosts\Helper;
16
- use WordPressPopularPosts\Output;
17
- use WordPressPopularPosts\Query;
18
 
19
  class Admin {
20
 
@@ -49,7 +47,7 @@ class Admin {
49
  * @param array $config Admin settings.
50
  * @param \WordPressPopularPosts\Image $thumbnail Image class.
51
  */
52
- public function __construct(array $config, \WordPressPopularPosts\Image $thumbnail)
53
  {
54
  $this->config = $config;
55
  $this->thumbnail = $thumbnail;
@@ -307,7 +305,7 @@ class Admin {
307
  * @since 3.0.0
308
  * @param int $blog_id New blog ID
309
  */
310
- public function activate_new_site($blog_id)
311
  {
312
  if ( 1 !== did_action('wpmu_new_blog') )
313
  return;
@@ -327,7 +325,7 @@ class Admin {
327
  * @param int $blog_id
328
  * @return array
329
  */
330
- public function delete_site_data($tables, $blog_id)
331
  {
332
  global $wpdb;
333
 
@@ -488,8 +486,8 @@ class Admin {
488
  if ( is_array($options) && ! empty($options) )
489
  $args = Helper::merge_array_r($args, $options);
490
 
491
- $trending = new Query($args);
492
- $posts = $trending->get_posts();
493
 
494
  $this->render_list($posts, 'trending');
495
  echo '<p id="wpp_read_more"><a href="' . admin_url('options-general.php?page=wordpress-popular-posts') . '">' . __('View more', 'wordpress-popular-posts') . '</a><p>';
@@ -654,7 +652,7 @@ class Admin {
654
  * @param string $file
655
  * @return array
656
  */
657
- public function add_plugin_settings_link($links, $file)
658
  {
659
  $plugin_file = 'wordpress-popular-posts/wordpress-popular-posts.php';
660
 
@@ -712,7 +710,7 @@ class Admin {
712
  * @since 4.0.0
713
  * @return string
714
  */
715
- public function get_chart_data($range = 'last7days', $time_unit = 'HOUR', $time_quantity = 24)
716
  {
717
  $dates = $this->get_dates($range, $time_unit, $time_quantity);
718
  $start_date = $dates[0];
@@ -783,11 +781,11 @@ class Admin {
783
  * @since 5.0.0
784
  * @return array|bool
785
  */
786
- private function get_dates($range = 'last7days', $time_unit = 'HOUR', $time_quantity = 24)
787
  {
788
  $valid_ranges = ['today', 'daily', 'last24hours', 'weekly', 'last7days', 'monthly', 'last30days', 'all', 'custom'];
789
  $range = in_array($range, $valid_ranges) ? $range : 'last7days';
790
- $now = new \DateTime(Helper::now(), new \DateTimeZone(Helper::get_timezone()));
791
 
792
  // Determine time range
793
  switch( $range ){
@@ -882,7 +880,7 @@ class Admin {
882
  * @param string $item
883
  * @return array
884
  */
885
- public function get_range_item_count($start_date, $end_date, $item = 'views')
886
  {
887
  global $wpdb;
888
 
@@ -1099,8 +1097,8 @@ class Admin {
1099
 
1100
  }
1101
 
1102
- $popular_items = new \WordPressPopularPosts\Query($args);
1103
- $posts = $popular_items->get_posts();
1104
 
1105
  if ( 'trending' != $items ) {
1106
  remove_all_filters('wpp_query_join', 1);
@@ -1118,12 +1116,9 @@ class Admin {
1118
  * @since 5.0.0
1119
  * @param array
1120
  */
1121
- public function render_list($posts, $list = 'most-viewed')
1122
  {
1123
- if (
1124
- is_array($posts)
1125
- && ! empty($posts)
1126
- ) {
1127
  ?>
1128
  <ol class="popular-posts-list">
1129
  <?php
@@ -1275,7 +1270,7 @@ class Admin {
1275
  * @param string $meta_key Meta key.
1276
  * @param mixed $meta_value Meta value.
1277
  */
1278
- public function updated_post_meta($meta_id, $post_id, $meta_key, $meta_value)
1279
  {
1280
  if ( '_thumbnail_id' == $meta_key ) {
1281
  $this->flush_post_thumbnail($post_id);
@@ -1292,7 +1287,7 @@ class Admin {
1292
  * @param string $meta_key Meta key.
1293
  * @param mixed $meta_value Meta value.
1294
  */
1295
- public function deleted_post_meta($meta_ids, $post_id, $meta_key, $meta_value)
1296
  {
1297
  if ( '_thumbnail_id' == $meta_key ) {
1298
  $this->flush_post_thumbnail($post_id);
@@ -1306,7 +1301,7 @@ class Admin {
1306
  *
1307
  * @param integer $post_id Post ID
1308
  */
1309
- public function flush_post_thumbnail($post_id)
1310
  {
1311
  $wpp_uploads_dir = $this->thumbnail->get_plugin_uploads_dir();
1312
 
@@ -1348,9 +1343,10 @@ class Admin {
1348
  * Purges post from data/summary tables.
1349
  *
1350
  * @since 3.3.0
 
1351
  * @global object $wpdb
1352
  */
1353
- public function purge_post($post_ID)
1354
  {
1355
  global $wpdb;
1356
 
@@ -1407,11 +1403,11 @@ class Admin {
1407
  ?>
1408
  <div class="notice notice-warning">
1409
  <p><?php printf(
1410
- __("<strong>WordPress Popular Posts:</strong> It seems your site is popular (great!) You may want to check <a href=\"%s\">these suggestions</a> to make sure your website's performance stays up to par.", 'wordpress-popular-posts'),
1411
  'https://github.com/cabrerahector/wordpress-popular-posts/wiki/7.-Performance'
1412
  ) ?></p>
1413
  <?php if ( current_user_can('manage_options') ) : ?>
1414
- <p><a class="button button-primary wpp-dismiss-performance-notice" href="<?php echo add_query_arg('wpp_dismiss_performance_notice', '1'); ?>"><?php _e("Dismiss", "wordpress-popular-posts"); ?></a> <a class="button wpp-remind-performance-notice" href="<?php echo add_query_arg('wpp_remind_performance_notice', '1'); ?>"><?php _e("Remind me later", "wordpress-popular-posts"); ?></a> <span class="spinner" style="float: none;"></span></p>
1415
  <?php endif; ?>
1416
  </div>
1417
  <?php
12
 
13
  namespace WordPressPopularPosts\Admin;
14
 
15
+ use WordPressPopularPosts\{Helper, Image, Output, Query};
 
 
16
 
17
  class Admin {
18
 
47
  * @param array $config Admin settings.
48
  * @param \WordPressPopularPosts\Image $thumbnail Image class.
49
  */
50
+ public function __construct(array $config, Image $thumbnail)
51
  {
52
  $this->config = $config;
53
  $this->thumbnail = $thumbnail;
305
  * @since 3.0.0
306
  * @param int $blog_id New blog ID
307
  */
308
+ public function activate_new_site(int $blog_id)
309
  {
310
  if ( 1 !== did_action('wpmu_new_blog') )
311
  return;
325
  * @param int $blog_id
326
  * @return array
327
  */
328
+ public function delete_site_data(array $tables, int $blog_id)
329
  {
330
  global $wpdb;
331
 
486
  if ( is_array($options) && ! empty($options) )
487
  $args = Helper::merge_array_r($args, $options);
488
 
489
+ $query = new Query($args);
490
+ $posts = $query->get_posts();
491
 
492
  $this->render_list($posts, 'trending');
493
  echo '<p id="wpp_read_more"><a href="' . admin_url('options-general.php?page=wordpress-popular-posts') . '">' . __('View more', 'wordpress-popular-posts') . '</a><p>';
652
  * @param string $file
653
  * @return array
654
  */
655
+ public function add_plugin_settings_link(array $links, string $file)
656
  {
657
  $plugin_file = 'wordpress-popular-posts/wordpress-popular-posts.php';
658
 
710
  * @since 4.0.0
711
  * @return string
712
  */
713
+ public function get_chart_data(string $range = 'last7days', string $time_unit = 'HOUR', int $time_quantity = 24)
714
  {
715
  $dates = $this->get_dates($range, $time_unit, $time_quantity);
716
  $start_date = $dates[0];
781
  * @since 5.0.0
782
  * @return array|bool
783
  */
784
+ private function get_dates(string $range = 'last7days', string $time_unit = 'HOUR', int $time_quantity = 24)
785
  {
786
  $valid_ranges = ['today', 'daily', 'last24hours', 'weekly', 'last7days', 'monthly', 'last30days', 'all', 'custom'];
787
  $range = in_array($range, $valid_ranges) ? $range : 'last7days';
788
+ $now = new \DateTime(Helper::now(), wp_timezone());
789
 
790
  // Determine time range
791
  switch( $range ){
880
  * @param string $item
881
  * @return array
882
  */
883
+ public function get_range_item_count(string $start_date, string $end_date, string $item = 'views')
884
  {
885
  global $wpdb;
886
 
1097
 
1098
  }
1099
 
1100
+ $query = new Query($args);
1101
+ $posts = $query->get_posts();
1102
 
1103
  if ( 'trending' != $items ) {
1104
  remove_all_filters('wpp_query_join', 1);
1116
  * @since 5.0.0
1117
  * @param array
1118
  */
1119
+ public function render_list(array $posts, $list = 'most-viewed')
1120
  {
1121
+ if ( ! empty($posts) ) {
 
 
 
1122
  ?>
1123
  <ol class="popular-posts-list">
1124
  <?php
1270
  * @param string $meta_key Meta key.
1271
  * @param mixed $meta_value Meta value.
1272
  */
1273
+ public function updated_post_meta(int $meta_id, int $post_id, string $meta_key, $meta_value) /** @TODO: starting PHP 8.0 $meta_valued can be declared as mixed $meta_value, see https://www.php.net/manual/en/language.types.declarations.php */
1274
  {
1275
  if ( '_thumbnail_id' == $meta_key ) {
1276
  $this->flush_post_thumbnail($post_id);
1287
  * @param string $meta_key Meta key.
1288
  * @param mixed $meta_value Meta value.
1289
  */
1290
+ public function deleted_post_meta(array $meta_ids, int $post_id, string $meta_key, $meta_value) /** @TODO: starting PHP 8.0 $meta_valued can be declared as mixed $meta_value */
1291
  {
1292
  if ( '_thumbnail_id' == $meta_key ) {
1293
  $this->flush_post_thumbnail($post_id);
1301
  *
1302
  * @param integer $post_id Post ID
1303
  */
1304
+ public function flush_post_thumbnail(int $post_id)
1305
  {
1306
  $wpp_uploads_dir = $this->thumbnail->get_plugin_uploads_dir();
1307
 
1343
  * Purges post from data/summary tables.
1344
  *
1345
  * @since 3.3.0
1346
+ * @param int $post_ID
1347
  * @global object $wpdb
1348
  */
1349
+ public function purge_post(int $post_ID)
1350
  {
1351
  global $wpdb;
1352
 
1403
  ?>
1404
  <div class="notice notice-warning">
1405
  <p><?php printf(
1406
+ __("<strong>WordPress Popular Posts:</strong> It seems your site is popular (great!) You may want to check <a href=\"%s\">these recommendations</a> to make sure your website's performance stays up to par.", 'wordpress-popular-posts'),
1407
  'https://github.com/cabrerahector/wordpress-popular-posts/wiki/7.-Performance'
1408
  ) ?></p>
1409
  <?php if ( current_user_can('manage_options') ) : ?>
1410
+ <p><a class="button button-primary wpp-dismiss-performance-notice" href="<?php echo esc_url(add_query_arg('wpp_dismiss_performance_notice', '1')); ?>"><?php _e("Dismiss", "wordpress-popular-posts"); ?></a> <a class="button wpp-remind-performance-notice" href="<?php echo esc_url(add_query_arg('wpp_remind_performance_notice', '1')); ?>"><?php _e("Remind me later", "wordpress-popular-posts"); ?></a> <span class="spinner" style="float: none;"></span></p>
1411
  <?php endif; ?>
1412
  </div>
1413
  <?php
src/Admin/admin-page.php CHANGED
@@ -23,7 +23,7 @@ if ( isset($_POST['section']) ) {
23
 
24
  if ( isset($_POST['wpp-update-stats-options-token']) && wp_verify_nonce($_POST['wpp-update-stats-options-token'], 'wpp-update-stats-options') ) {
25
  $this->config['stats']['limit'] = ( \WordPressPopularPosts\Helper::is_number($_POST['stats_limit']) && $_POST['stats_limit'] > 0 ) ? $_POST['stats_limit'] : 10;
26
- $this->config['stats']['post_type'] = empty($_POST['stats_type']) ? "post,page" : $_POST['stats_type'];
27
  $this->config['stats']['freshness'] = empty($_POST['stats_freshness']) ? false : $_POST['stats_freshness'];
28
 
29
  update_option('wpp_settings_config', $this->config);
@@ -108,14 +108,16 @@ if ( isset($_POST['section']) ) {
108
  }
109
  ?>
110
 
111
- <nav id="wpp-menu">
112
- <ul>
113
- <li><a href="#" title="<?php esc_attr_e('Menu'); ?>"><span><?php _e('Menu'); ?></span></a></li>
114
- <li <?php echo ('stats' == $current ) ? 'class="current"' : ''; ?>><a href="<?php echo admin_url('options-general.php?page=wordpress-popular-posts&tab=stats'); ?>" title="<?php esc_attr_e('Stats', 'wordpress-popular-posts'); ?>"><span><?php _e('Stats', 'wordpress-popular-posts'); ?></span></a></li>
115
- <li <?php echo ('tools' == $current ) ? 'class="current"' : ''; ?>><a href="<?php echo admin_url('options-general.php?page=wordpress-popular-posts&tab=tools'); ?>" title="<?php esc_attr_e('Tools', 'wordpress-popular-posts'); ?>"><span><?php _e('Tools', 'wordpress-popular-posts'); ?></span></a></li>
116
- <li <?php echo ('debug' == $current ) ? 'class="current"' : ''; ?>><a href="<?php echo admin_url('options-general.php?page=wordpress-popular-posts&tab=debug'); ?>" title="Debug"><span>Debug</span></a></li>
117
- </ul>
118
- </nav>
 
 
119
 
120
  <div class="wpp-wrapper wpp-section-<?php echo $current; ?>">
121
  <div class="wpp-header">
@@ -124,457 +126,11 @@ if ( isset($_POST['section']) ) {
124
  </div>
125
 
126
  <?php
127
- // Stats chart
128
- if ( 'stats' == $current ) {
129
- $chart_data = json_decode(
130
- $this->get_chart_data($this->config['stats']['range'], strtoupper($this->config['stats']['time_unit']), $this->config['stats']['time_quantity']),
131
- true
132
- );
133
  ?>
134
-
135
- <a href="#" id="wpp-stats-config-btn" class="dashicons dashicons-admin-generic"></a>
136
-
137
- <div id="wpp-stats-config" class="wpp-lightbox">
138
- <form action="" method="post" id="wpp_stats_options" name="wpp_stats_options">
139
- <label for="stats_type"><?php _e("Post type", 'wordpress-popular-posts'); ?>:</label>
140
- <input type="text" name="stats_type" value="<?php echo esc_attr($this->config['stats']['post_type']); ?>" size="15">
141
-
142
- <label for="stats_limits"><?php _e("Limit", 'wordpress-popular-posts'); ?>:</label>
143
- <input type="text" name="stats_limit" value="<?php echo $this->config['stats']['limit']; ?>" size="5">
144
-
145
- <label for="stats_freshness"><input type="checkbox" class="checkbox" <?php echo ($this->config['stats']['freshness']) ? 'checked="checked"' : ''; ?> id="stats_freshness" name="stats_freshness"> <small><?php _e('Display only posts published within the selected Time Range', 'wordpress-popular-posts'); ?></small></label>
146
-
147
- <div class="clear"></div>
148
- <br /><br />
149
-
150
- <input type="hidden" name="section" value="stats">
151
- <button type="submit" class="button-primary action"><?php _e("Apply", 'wordpress-popular-posts'); ?></button>
152
- <button class="button-secondary action right"><?php _e("Cancel"); ?></button>
153
-
154
- <?php wp_nonce_field('wpp-update-stats-options', 'wpp-update-stats-options-token'); ?>
155
- </form>
156
- </div>
157
-
158
- <div id="wpp-stats-range" class="wpp-lightbox">
159
- <form action="" method="post">
160
- <ul class="wpp-lightbox-tabs">
161
- <li class="active"><a href="#"><?php _e('Custom Time Range', 'wordpress-popular-posts'); ?></a></li>
162
- <li><a href="#"><?php _e('Date Range', 'wordpress-popular-posts'); ?></a></li>
163
- </ul>
164
-
165
- <div class="wpp-lightbox-tab-content wpp-lightbox-tab-content-active" id="custom-time-range">
166
- <input type="text" id="stats_range_time_quantity" name="stats_range_time_quantity" value="<?php echo $this->config['stats']['time_quantity']; ?>">
167
-
168
- <select id="stats_range_time_unit" name="stats_range_time_unit">
169
- <option <?php if ($this->config['stats']['time_unit'] == "minute") { ?>selected="selected"<?php } ?> value="minute"><?php _e("Minute(s)", 'wordpress-popular-posts'); ?></option>
170
- <option <?php if ($this->config['stats']['time_unit'] == "hour") { ?>selected="selected"<?php } ?> value="hour"><?php _e("Hour(s)", 'wordpress-popular-posts'); ?></option>
171
- <option <?php if ($this->config['stats']['time_unit'] == "day") { ?>selected="selected"<?php } ?> value="day"><?php _e("Day(s)", 'wordpress-popular-posts'); ?></option>
172
- </select>
173
- </div>
174
-
175
- <div class="wpp-lightbox-tab-content" id="custom-date-range">
176
- <input type="text" id="stats_range_date" name="stats_range_date" value="" placeholder="<?php esc_attr_e('Select a date...', 'wordpress-popular-posts'); ?>" readonly>
177
- </div>
178
-
179
- <div class="clear"></div>
180
- <br />
181
-
182
- <button type="submit" class="button-primary action">
183
- <?php _e("Apply", 'wordpress-popular-posts'); ?>
184
- </button>
185
- <button class="button-secondary action right">
186
- <?php _e("Cancel"); ?>
187
- </button>
188
- </form>
189
- </div>
190
-
191
- <div id="wpp-chart-wrapper">
192
- <h4><?php echo $chart_data['totals']['label_summary']; ?></h4>
193
- <h5><?php echo $chart_data['totals']['label_date_range']; ?></h5>
194
-
195
- <ul class="wpp-header-nav" id="wpp-time-ranges">
196
- <li <?php echo ('daily' == $this->config['stats']['range'] || 'today' == $this->config['stats']['range'] ) ? ' class="current"' : ''; ?>><a href="#" data-range="today" title="<?php esc_attr_e('Today', 'wordpress-popular-posts'); ?>"><?php _e('Today', 'wordpress-popular-posts'); ?></a></li>
197
- <li <?php echo ('daily' == $this->config['stats']['range'] || 'last24hours' == $this->config['stats']['range'] ) ? ' class="current"' : ''; ?>><a href="#" data-range="last24hours" title="<?php esc_attr_e('Last 24 hours', 'wordpress-popular-posts'); ?>">24h</a></li>
198
- <li <?php echo ('weekly' == $this->config['stats']['range'] || 'last7days' == $this->config['stats']['range'] ) ? ' class="current"' : ''; ?>><a href="#" data-range="last7days" title="<?php esc_attr_e('Last 7 days', 'wordpress-popular-posts'); ?>">7d</a></li>
199
- <li <?php echo ('monthly' == $this->config['stats']['range'] || 'last30days' == $this->config['stats']['range'] ) ? ' class="current"' : ''; ?>><a href="#" data-range="last30days" title="<?php esc_attr_e('Last 30 days', 'wordpress-popular-posts'); ?>">30d</a></li>
200
- <li <?php echo ('custom' == $this->config['stats']['range'] ) ? ' class="current"' : ''; ?>><a href="#" data-range="custom" title="<?php esc_attr_e('Custom', 'wordpress-popular-posts'); ?>"><?php _e('Custom', 'wordpress-popular-posts'); ?></a></li>
201
- </ul>
202
-
203
- <div id="wpp-chart">
204
- <p><?php echo sprintf( __('Err... A nice little chart is supposed to be here, instead you are seeing this because your browser is too old. <br /> Please <a href="%s" target="_blank">get a better browser</a>.', 'wordpress-popular-posts'), 'https://browsehappy.com/'); ?></p>
205
- </div>
206
- </div>
207
- <?php
208
- } // End stats chart
209
- ?>
210
-
211
- <div id="wpp-listing" class="wpp-content"<?php echo ('stats' == $current ) ? '' : ' style="display: none;"'; ?>>
212
- <ul class="wpp-tabbed-nav">
213
- <li class="active"><a href="#" title="<?php esc_attr_e('See your most viewed posts within the selected time range', 'wordpress-popular-posts'); ?>"><span class="wpp-icon-eye"></span><span><?php _e('Most viewed', 'wordpress-popular-posts'); ?></span></a></li>
214
- <li><a href="#" title="<?php esc_attr_e('See your most commented posts within the selected time range', 'wordpress-popular-posts'); ?>"><span class="wpp-icon-comment"></span><span><?php _e('Most commented', 'wordpress-popular-posts'); ?></span></a></li>
215
- <li><a href="#" title="<?php esc_attr_e('See your most viewed posts within the last hour', 'wordpress-popular-posts'); ?>"><span class="wpp-icon-rocket"></span><span><?php _e('Trending now', 'wordpress-popular-posts'); ?></span></a></li>
216
- <li><a href="#" title="<?php esc_attr_e('See your most viewed posts of all time', 'wordpress-popular-posts'); ?>"><span class="wpp-icon-award"></span><span><?php _e('Hall of Fame', 'wordpress-popular-posts'); ?></span></a></li>
217
- </ul>
218
-
219
- <div class="wpp-tab-content wpp-tab-content-active">
220
- <span class="spinner"></span>
221
- </div>
222
-
223
- <div class="wpp-tab-content">
224
- <span class="spinner"></span>
225
- </div>
226
-
227
- <div class="wpp-tab-content">
228
- <span class="spinner"></span>
229
- </div>
230
-
231
- <div class="wpp-tab-content">
232
- <?php
233
- $args = [
234
- 'range' => 'all',
235
- 'post_type' => $this->config['stats']['post_type'],
236
- 'order_by' => 'views',
237
- 'limit' => $this->config['stats']['limit'],
238
- 'stats_tag' => [
239
- 'comment_count' => 1,
240
- 'views' => 1,
241
- 'date' => [
242
- 'active' => 1
243
- ]
244
- ]
245
- ];
246
- $hof = new \WordPressPopularPosts\Query($args);
247
- $posts = $hof->get_posts();
248
-
249
- $this->render_list($posts, 'hof');
250
- ?>
251
- </div>
252
- </div>
253
-
254
- <!-- Start tools -->
255
- <div id="wpp_tools" <?php echo ( "tools" == $current ) ? '' : ' style="display: none;"'; ?>>
256
- <h3 class="wmpp-subtitle"><?php _e("Thumbnails", 'wordpress-popular-posts'); ?></h3>
257
-
258
- <form action="" method="post" id="wpp_thumbnail_options" name="wpp_thumbnail_options">
259
- <table class="form-table">
260
- <tbody>
261
- <tr valign="top">
262
- <th scope="row"><label for="thumb_default"><?php _e("Default thumbnail", 'wordpress-popular-posts'); ?>:</label></th>
263
- <td>
264
- <?php
265
- $fallback_thumbnail_url = trim($this->config['tools']['thumbnail']['default']);
266
-
267
- if ( ! $fallback_thumbnail_url )
268
- $fallback_thumbnail_url = $this->thumbnail->get_default_url();
269
-
270
- $fallback_thumbnail_url = str_replace(
271
- parse_url(
272
- $fallback_thumbnail_url
273
- , PHP_URL_SCHEME
274
- ) . ':',
275
- '',
276
- $fallback_thumbnail_url
277
- );
278
- ?>
279
- <div id="thumb-review">
280
- <img src="<?php echo esc_url($fallback_thumbnail_url); ?>" alt="" />
281
- </div>
282
-
283
- <input id="upload_thumb_button" type="button" class="button" value="<?php _e("Change thumbnail", 'wordpress-popular-posts'); ?>">
284
- <input type="hidden" id="upload_thumb_src" name="upload_thumb_src" value="">
285
-
286
- <p class="description"><?php _e("This image will be displayed when no thumbnail is available", 'wordpress-popular-posts'); ?>.</p>
287
- </td>
288
- </tr>
289
- <tr valign="top">
290
- <th scope="row"><label for="thumb_source"><?php _e("Pick image from", 'wordpress-popular-posts'); ?>:</label></th>
291
- <td>
292
- <select name="thumb_source" id="thumb_source">
293
- <option <?php if ($this->config['tools']['thumbnail']['source'] == "featured") { ?>selected="selected"<?php } ?> value="featured"><?php _e("Featured image", 'wordpress-popular-posts'); ?></option>
294
- <option <?php if ($this->config['tools']['thumbnail']['source'] == "first_image") { ?>selected="selected"<?php } ?> value="first_image"><?php _e("First image on post", 'wordpress-popular-posts'); ?></option>
295
- <option <?php if ($this->config['tools']['thumbnail']['source'] == "first_attachment") { ?>selected="selected"<?php } ?> value="first_attachment"><?php _e("First attachment", 'wordpress-popular-posts'); ?></option>
296
- <option <?php if ($this->config['tools']['thumbnail']['source'] == "custom_field") { ?>selected="selected"<?php } ?> value="custom_field"><?php _e("Custom field", 'wordpress-popular-posts'); ?></option>
297
- </select>
298
- <br />
299
- <p class="description"><?php _e("Tell WordPress Popular Posts where it should get thumbnails from", 'wordpress-popular-posts'); ?>.</p>
300
- </td>
301
- </tr>
302
- <tr valign="top">
303
- <th scope="row"><label for="thumb_lazy_load"><?php _e("Lazy load", 'wordpress-popular-posts'); ?>:</label> <small>[<a href="https://github.com/cabrerahector/wordpress-popular-posts/wiki/7.-Performance#lazy-loading" target="_blank" title="<?php _e('What is this?', 'wordpress-popular-posts'); ?>">?</a>]</small></th>
304
- <td>
305
- <select name="thumb_lazy_load" id="thumb_lazy_load">
306
- <option <?php if ( ! $this->config['tools']['thumbnail']['lazyload'] ) { ?>selected="selected"<?php } ?> value="0"><?php _e("No", 'wordpress-popular-posts'); ?></option>
307
- <option <?php if ( $this->config['tools']['thumbnail']['lazyload'] ) { ?>selected="selected"<?php } ?> value="1"><?php _e("Yes", 'wordpress-popular-posts'); ?></option>
308
- </select>
309
- </td>
310
- </tr>
311
- <tr valign="top" <?php if ($this->config['tools']['thumbnail']['source'] != "custom_field") { ?>style="display: none;"<?php } ?> id="row_custom_field">
312
- <th scope="row"><label for="thumb_field"><?php _e("Custom field name", 'wordpress-popular-posts'); ?>:</label></th>
313
- <td>
314
- <input type="text" id="thumb_field" name="thumb_field" value="<?php echo esc_attr($this->config['tools']['thumbnail']['field']); ?>" size="10" <?php if ($this->config['tools']['thumbnail']['source'] != "custom_field") { ?>style="display: none;"<?php } ?> />
315
- </td>
316
- </tr>
317
- <tr valign="top" <?php if ($this->config['tools']['thumbnail']['source'] != "custom_field") { ?>style="display: none;"<?php } ?> id="row_custom_field_resize">
318
- <th scope="row"><label for="thumb_field_resize"><?php _e("Resize image from Custom field?", 'wordpress-popular-posts'); ?>:</label></th>
319
- <td>
320
- <select name="thumb_field_resize" id="thumb_field_resize">
321
- <option <?php if ( !$this->config['tools']['thumbnail']['resize'] ) { ?>selected="selected"<?php } ?> value="0"><?php _e("No, use image as is", 'wordpress-popular-posts'); ?></option>
322
- <option <?php if ($this->config['tools']['thumbnail']['resize'] == 1 ) { ?>selected="selected"<?php } ?> value="1"><?php _e("Yes", 'wordpress-popular-posts'); ?></option>
323
- </select>
324
- </td>
325
- </tr>
326
- <?php
327
- $wp_upload_dir = wp_get_upload_dir();
328
- if ( is_dir($wp_upload_dir['basedir'] . "/" . 'wordpress-popular-posts') ) :
329
- ?>
330
- <tr valign="top">
331
- <th scope="row"></th>
332
- <td>
333
- <input type="button" name="wpp-reset-image-cache" id="wpp-reset-image-cache" class="button-secondary" value="<?php _e("Empty image cache", 'wordpress-popular-posts'); ?>">
334
- <p class="description"><?php _e("Use this button to clear WPP's thumbnails cache", 'wordpress-popular-posts'); ?>.</p>
335
- </td>
336
- </tr>
337
- <?php
338
- endif;
339
- ?>
340
- <tr valign="top">
341
- <td colspan="2">
342
- <input type="hidden" name="section" value="thumb">
343
- <input type="submit" class="button-primary action" id="btn_th_ops" value="<?php _e("Apply", 'wordpress-popular-posts'); ?>" name="">
344
- </td>
345
- </tr>
346
- </tbody>
347
- </table>
348
-
349
- <?php wp_nonce_field('wpp-update-thumbnail-options', 'wpp-update-thumbnail-options-token'); ?>
350
- </form>
351
- <br />
352
- <p style="display: <?php echo ( current_user_can('manage_options') ) ? 'block' : 'none'; ?>; float:none; clear:both;">&nbsp;</p>
353
-
354
- <h3 class="wmpp-subtitle" style="display: <?php echo ( current_user_can('manage_options') ) ? 'block' : 'none'; ?>"><?php _e("Data", 'wordpress-popular-posts'); ?></h3>
355
-
356
- <form action="" method="post" id="wpp_ajax_options" name="wpp_ajax_options" style="display: <?php echo ( current_user_can('manage_options') ) ? 'block' : 'none'; ?>">
357
- <table class="form-table">
358
- <tbody>
359
- <tr valign="top">
360
- <th scope="row"><label for="log_option"><?php _e("Log views from", 'wordpress-popular-posts'); ?>:</label></th>
361
- <td>
362
- <select name="log_option" id="log_option">
363
- <option <?php if ($this->config['tools']['log']['level'] == 0) { ?>selected="selected"<?php } ?> value="0"><?php _e("Visitors only", 'wordpress-popular-posts'); ?></option>
364
- <option <?php if ($this->config['tools']['log']['level'] == 2) { ?>selected="selected"<?php } ?> value="2"><?php _e("Logged-in users only", 'wordpress-popular-posts'); ?></option>
365
- <option <?php if ($this->config['tools']['log']['level'] == 1) { ?>selected="selected"<?php } ?> value="1"><?php _e("Everyone", 'wordpress-popular-posts'); ?></option>
366
- </select>
367
- <br />
368
- </td>
369
- </tr>
370
- <tr valign="top">
371
- <th scope="row"><label for="log_limit"><?php _e("Log limit", 'wordpress-popular-posts'); ?>:</label></th>
372
- <td>
373
- <select name="log_limit" id="log_limit">
374
- <option <?php if ($this->config['tools']['log']['limit'] == 0) { ?>selected="selected"<?php } ?> value="0"><?php _e("Disabled", 'wordpress-popular-posts'); ?></option>
375
- <option <?php if ($this->config['tools']['log']['limit'] == 1) { ?>selected="selected"<?php } ?> value="1"><?php _e("Keep data for", 'wordpress-popular-posts'); ?></option>
376
- </select>
377
-
378
- <label for="log_expire_time"<?php echo ($this->config['tools']['log']['limit'] == 0) ? ' style="display: none;"' : ''; ?>>
379
- <input type="text" id="log_expire_time" name="log_expire_time" value="<?php echo esc_attr($this->config['tools']['log']['expires_after']); ?>" size="3"> <?php _e("day(s)", 'wordpress-popular-posts'); ?>
380
- </label>
381
-
382
- <p class="description"<?php echo ($this->config['tools']['log']['limit'] == 0) ? ' style="display: none;"' : ''; ?>><?php _e("Data older than the specified time frame will be automatically discarded", 'wordpress-popular-posts'); ?>.</p>
383
-
384
- <br <?php echo (1 == $this->config['tools']['log']['limit']) ? 'style="display: none;"' : ''; ?>/>
385
- </td>
386
- </tr>
387
- <tr valign="top">
388
- <th scope="row"><label for="ajax"><?php _e("Ajaxify widget", 'wordpress-popular-posts'); ?>:</label></th>
389
- <td>
390
- <select name="ajax" id="ajax">
391
- <option <?php if (! $this->config['tools']['ajax']) { ?>selected="selected"<?php } ?> value="0"><?php _e("Disabled", 'wordpress-popular-posts'); ?></option>
392
- <option <?php if ($this->config['tools']['ajax']) { ?>selected="selected"<?php } ?> value="1"><?php _e("Enabled", 'wordpress-popular-posts'); ?></option>
393
- </select>
394
-
395
- <br />
396
- <p class="description"><?php _e("If you are using a caching plugin such as WP Super Cache, enabling this feature will keep the popular list from being cached by it", 'wordpress-popular-posts'); ?>.</p>
397
- </td>
398
- </tr>
399
- <tr valign="top">
400
- <th scope="row"><label for="cache"><?php _e("Data Caching", 'wordpress-popular-posts'); ?>:</label> <small>[<a href="https://github.com/cabrerahector/wordpress-popular-posts/wiki/7.-Performance#caching-db-queries-results" target="_blank" title="<?php _e('What is this?', 'wordpress-popular-posts'); ?>">?</a>]</small></th>
401
- <td>
402
- <select name="cache" id="cache">
403
- <option <?php if ( ! $this->config['tools']['cache']['active'] ) { ?>selected="selected"<?php } ?> value="0"><?php _e("Never cache", 'wordpress-popular-posts'); ?></option>
404
- <option <?php if ( $this->config['tools']['cache']['active'] ) { ?>selected="selected"<?php } ?> value="1"><?php _e("Enable caching", 'wordpress-popular-posts'); ?></option>
405
- </select>
406
-
407
- <br />
408
- <p class="description"><?php _e("WPP can cache the popular list for a specified amount of time. Recommended for large / high traffic sites", 'wordpress-popular-posts'); ?>.</p>
409
- </td>
410
- </tr>
411
- <tr valign="top" <?php if ( ! $this->config['tools']['cache']['active'] ) { ?>style="display: none;"<?php } ?> id="cache_refresh_interval">
412
- <th scope="row"><label for="cache_interval_value"><?php _e("Refresh cache every", 'wordpress-popular-posts'); ?>:</label></th>
413
- <td>
414
- <input name="cache_interval_value" type="text" id="cache_interval_value" value="<?php echo ( isset($this->config['tools']['cache']['interval']['value']) ) ? (int) $this->config['tools']['cache']['interval']['value'] : 1; ?>" class="small-text">
415
- <select name="cache_interval_time" id="cache_interval_time">
416
- <option <?php if ($this->config['tools']['cache']['interval']['time'] == "minute") { ?>selected="selected"<?php } ?> value="minute"><?php _e("Minute(s)", 'wordpress-popular-posts'); ?></option>
417
- <option <?php if ($this->config['tools']['cache']['interval']['time'] == "hour") { ?>selected="selected"<?php } ?> value="hour"><?php _e("Hour(s)", 'wordpress-popular-posts'); ?></option>
418
- <option <?php if ($this->config['tools']['cache']['interval']['time'] == "day") { ?>selected="selected"<?php } ?> value="day"><?php _e("Day(s)", 'wordpress-popular-posts'); ?></option>
419
- <option <?php if ($this->config['tools']['cache']['interval']['time'] == "week") { ?>selected="selected"<?php } ?> value="week"><?php _e("Week(s)", 'wordpress-popular-posts'); ?></option>
420
- <option <?php if ($this->config['tools']['cache']['interval']['time'] == "month") { ?>selected="selected"<?php } ?> value="month"><?php _e("Month(s)", 'wordpress-popular-posts'); ?></option>
421
- <option <?php if ($this->config['tools']['cache']['interval']['time'] == "year") { ?>selected="selected"<?php } ?> value="month"><?php _e("Year(s)", 'wordpress-popular-posts'); ?></option>
422
- </select>
423
- <br />
424
- <p class="description" style="display: none;" id="cache_too_long"><?php _e("Really? That long?", 'wordpress-popular-posts'); ?></p>
425
- </td>
426
- </tr>
427
- <tr valign="top">
428
- <th scope="row"><label for="sampling"><?php _e("Data Sampling", 'wordpress-popular-posts'); ?>:</label> <small>[<a href="https://github.com/cabrerahector/wordpress-popular-posts/wiki/7.-Performance#data-sampling" target="_blank" title="<?php _e('What is this?', 'wordpress-popular-posts'); ?>">?</a>]</small></th>
429
- <td>
430
- <select name="sampling" id="sampling">
431
- <option <?php if ( !$this->config['tools']['sampling']['active'] ) { ?>selected="selected"<?php } ?> value="0"><?php _e("Disabled", 'wordpress-popular-posts'); ?></option>
432
- <option <?php if ( $this->config['tools']['sampling']['active'] ) { ?>selected="selected"<?php } ?> value="1"><?php _e("Enabled", 'wordpress-popular-posts'); ?></option>
433
- </select>
434
-
435
- <br />
436
- <p class="description"><?php echo sprintf( __('By default, WordPress Popular Posts stores in database every single visit your site receives. For small / medium sites this is generally OK, but on large / high traffic sites the constant writing to the database may have an impact on performance. With <a href="%1$s" target="_blank">data sampling</a>, WordPress Popular Posts will store only a subset of your traffic and report on the tendencies detected in that sample set (for more, <a href="%2$s" target="_blank">please read here</a>)', 'wordpress-popular-posts'), 'http://en.wikipedia.org/wiki/Sample_%28statistics%29', 'https://github.com/cabrerahector/wordpress-popular-posts/wiki/7.-Performance#data-sampling'); ?>.</p>
437
- </td>
438
- </tr>
439
- <tr valign="top" <?php if ( ! $this->config['tools']['sampling']['active'] ) { ?>style="display: none;"<?php } ?>>
440
- <th scope="row"><label for="sample_rate"><?php _e("Sample Rate", 'wordpress-popular-posts'); ?>:</label></th>
441
- <td>
442
- <input name="sample_rate" type="text" id="sample_rate" value="<?php echo ( isset($this->config['tools']['sampling']['rate']) ) ? (int) $this->config['tools']['sampling']['rate'] : 100; ?>" class="small-text">
443
- <br />
444
- <p class="description"><?php echo sprintf(__("A sampling rate of %d is recommended for large / high traffic sites. For lower traffic sites, you should lower the value", 'wordpress-popular-posts'), 100); ?>.</p>
445
- </td>
446
- </tr>
447
- <tr valign="top">
448
- <td colspan="2">
449
- <input type="hidden" name="section" value="data">
450
- <input type="submit" class="button-primary action" id="btn_ajax_ops" value="<?php _e("Apply", 'wordpress-popular-posts'); ?>" name="">
451
- </td>
452
- </tr>
453
- </tbody>
454
- </table>
455
-
456
- <?php wp_nonce_field('wpp-update-data-options', 'wpp-update-data-options-token'); ?>
457
- </form>
458
- <br />
459
- <p style="display: block; float:none; clear: both;">&nbsp;</p>
460
-
461
- <h3 class="wmpp-subtitle"><?php _e("Miscellaneous", 'wordpress-popular-posts'); ?></h3>
462
-
463
- <form action="" method="post" id="wpp_link_options" name="wpp_link_options">
464
- <table class="form-table">
465
- <tbody>
466
- <tr valign="top">
467
- <th scope="row"><label for="link_target"><?php _e("Open links in", 'wordpress-popular-posts'); ?>:</label></th>
468
- <td>
469
- <select name="link_target" id="link_target">
470
- <option <?php if ($this->config['tools']['link']['target'] == '_self') { ?>selected="selected"<?php } ?> value="_self"><?php _e("Current window", 'wordpress-popular-posts'); ?></option>
471
- <option <?php if ($this->config['tools']['link']['target'] == '_blank') { ?>selected="selected"<?php } ?> value="_blank"><?php _e("New tab/window", 'wordpress-popular-posts'); ?></option>
472
- </select>
473
- <br />
474
- </td>
475
- </tr>
476
- <tr valign="top">
477
- <th scope="row"><label for="css"><?php _e("Use plugin's stylesheet", 'wordpress-popular-posts'); ?>:</label></th>
478
- <td>
479
- <select name="css" id="css">
480
- <option <?php if ($this->config['tools']['css']) { ?>selected="selected"<?php } ?> value="1"><?php _e("Enabled", 'wordpress-popular-posts'); ?></option>
481
- <option <?php if (!$this->config['tools']['css']) { ?>selected="selected"<?php } ?> value="0"><?php _e("Disabled", 'wordpress-popular-posts'); ?></option>
482
- </select>
483
- <br />
484
- <p class="description"><?php _e("By default, the plugin includes a stylesheet called wpp.css which you can use to style your popular posts listing. If you wish to use your own stylesheet or do not want it to have it included in the header section of your site, use this.", 'wordpress-popular-posts'); ?></p>
485
- </td>
486
- </tr>
487
- <tr valign="top">
488
- <th scope="row"><label for="experimental_features"><?php _e("Enable experimental features", 'wordpress-popular-posts'); ?>:</label></th>
489
- <td>
490
- <input type="checkbox" class="checkbox" id="experimental_features" name="experimental_features" <?php echo ($this->config['tools']['experimental']) ? 'checked="checked"' : ''; ?>>
491
- </td>
492
- </tr>
493
- <tr valign="top">
494
- <td colspan="2">
495
- <input type="hidden" name="section" value="misc">
496
- <input type="submit" class="button-primary action" value="<?php _e("Apply", 'wordpress-popular-posts'); ?>" name="">
497
- </td>
498
- </tr>
499
- </tbody>
500
- </table>
501
-
502
- <?php wp_nonce_field('wpp-update-misc-options', 'wpp-update-misc-options-token'); ?>
503
- </form>
504
- <br />
505
- <p style="display: block; float: none; clear: both;">&nbsp;</p>
506
-
507
- <div style="display: <?php echo ( current_user_can('manage_options') ) ? 'block' : 'none'; ?>">
508
- <br /><br />
509
-
510
- <p><?php _e('WordPress Popular Posts maintains data in two separate tables: one for storing the most popular entries on a daily basis (from now on, "cache"), and another one to keep the All-time data (from now on, "historical data" or just "data"). If for some reason you need to clear the cache table, or even both historical and cache tables, please use the buttons below to do so.', 'wordpress-popular-posts') ?></p>
511
- <p><input type="button" name="wpp-reset-cache" id="wpp-reset-cache" class="button-secondary" value="<?php _e("Empty cache", 'wordpress-popular-posts'); ?>"> <label for="wpp-reset-cache"><small><?php _e('Use this button to manually clear entries from WPP cache only', 'wordpress-popular-posts'); ?></small></label></p>
512
- <p><input type="button" name="wpp-reset-all" id="wpp-reset-all" class="button-secondary" value="<?php _e("Clear all data", 'wordpress-popular-posts'); ?>"> <label for="wpp-reset-all"><small><?php _e('Use this button to manually clear entries from all WPP data tables', 'wordpress-popular-posts'); ?></small></label></p>
513
- </div>
514
- </div>
515
- <!-- End tools -->
516
-
517
- <!-- Start debug -->
518
- <?php
519
- global $wpdb, $wp_version;
520
-
521
- $my_theme = wp_get_theme();
522
- $site_plugins = get_plugins();
523
- $plugin_names = [];
524
- $performance_nag = get_option('wpp_performance_nag');
525
-
526
- if ( ! $performance_nag ) {
527
- $performance_nag = [
528
- 'status' => 0,
529
- 'last_checked' => null
530
- ];
531
- }
532
-
533
- switch($performance_nag['status']) {
534
- case 0:
535
- $performance_nag_status = 'Inactive';
536
- break;
537
- case 1:
538
- $performance_nag_status = 'Active';
539
- break;
540
- case 2:
541
- $performance_nag_status = 'Remind me later';
542
- break;
543
- case 3:
544
- $performance_nag_status = 'Dismissed';
545
- break;
546
- default:
547
- $performance_nag_status = 'Inactive';
548
- break;
549
- }
550
-
551
- foreach( $site_plugins as $main_file => $plugin_meta ) :
552
- if ( ! is_plugin_active($main_file) )
553
- continue;
554
- $plugin_names[] = sanitize_text_field($plugin_meta['Name'] . ' ' . $plugin_meta['Version']);
555
- endforeach;
556
- ?>
557
- <div id="wpp_debug" <?php echo ( "debug" == $current ) ? '' : ' style="display: none;"'; ?>>
558
- <h3>Plugin Configuration</h3>
559
- <p><strong>Performance Nag:</strong> <?php echo $performance_nag_status; ?></p>
560
- <p><strong>Log Limit:</strong> <?php echo ( $this->config['tools']['log']['limit'] ) ? 'Yes, keep data for ' . $this->config['tools']['log']['expires_after'] . ' days' : 'No'; ?></p>
561
- <p><strong>Log Views From:</strong> <?php echo ( 0 == $this->config['tools']['log']['level'] ) ? 'Visitors only' : ( (2 == $this->config['tools']['log']['level']) ? 'Logged-in users only' : 'Everyone' ); ?></p>
562
- <p><strong>Data Caching:</strong> <?php echo ( $this->config['tools']['cache']['active'] ) ? 'Yes, ' . $this->config['tools']['cache']['interval']['value'] . ' ' . $this->config['tools']['cache']['interval']['time'] : 'No'; ?></p>
563
- <p><strong>Data Sampling:</strong> <?php echo ( $this->config['tools']['sampling']['active'] ) ? 'Yes, with a rate of ' . $this->config['tools']['sampling']['rate'] : 'No'; ?></p>
564
- <p><strong>External object cache:</strong> <?php echo ( wp_using_ext_object_cache() ) ? 'Yes' : 'No'; ?></p>
565
- <p><strong>WPP_CACHE_VIEWS:</strong> <?php echo ( defined('WPP_CACHE_VIEWS') && WPP_CACHE_VIEWS ) ? 'Yes' : 'No'; ?></p>
566
-
567
- <br />
568
-
569
- <h3>System Info</h3>
570
- <p><strong>PHP version:</strong> <?php echo phpversion(); ?></p>
571
- <p><strong>PHP extensions:</strong> <?php echo implode(', ', get_loaded_extensions()); ?></p>
572
- <p><strong>Database version:</strong> <?php echo $wpdb->get_var("SELECT VERSION();"); ?></p>
573
- <p><strong>InnoDB availability:</strong> <?php echo $wpdb->get_var("SELECT SUPPORT FROM INFORMATION_SCHEMA.ENGINES WHERE ENGINE = 'InnoDB';"); ?></p>
574
- <p><strong>WordPress version:</strong> <?php echo $wp_version; ?></p>
575
- <p><strong>Multisite:</strong> <?php echo ( function_exists('is_multisite') && is_multisite() ) ? 'Yes' : 'No'; ?></p>
576
- <p><strong>Active plugins:</strong> <?php echo implode(', ', $plugin_names); ?></p>
577
- <p><strong>Theme:</strong> <?php echo $my_theme->get('Name') . ' (' . $my_theme->get('Version') . ') by ' . $my_theme->get('Author'); ?></p>
578
- </div>
579
- <!-- End debug -->
580
- </div>
23
 
24
  if ( isset($_POST['wpp-update-stats-options-token']) && wp_verify_nonce($_POST['wpp-update-stats-options-token'], 'wpp-update-stats-options') ) {
25
  $this->config['stats']['limit'] = ( \WordPressPopularPosts\Helper::is_number($_POST['stats_limit']) && $_POST['stats_limit'] > 0 ) ? $_POST['stats_limit'] : 10;
26
+ $this->config['stats']['post_type'] = empty($_POST['stats_type']) ? "post" : $_POST['stats_type'];
27
  $this->config['stats']['freshness'] = empty($_POST['stats_freshness']) ? false : $_POST['stats_freshness'];
28
 
29
  update_option('wpp_settings_config', $this->config);
108
  }
109
  ?>
110
 
111
+ <?php if ( current_user_can('edit_others_posts') ) : ?>
112
+ <nav id="wpp-menu">
113
+ <ul>
114
+ <li><a href="#" title="<?php esc_attr_e('Menu'); ?>"><span><?php _e('Menu'); ?></span></a></li>
115
+ <li <?php echo ('stats' == $current ) ? 'class="current"' : ''; ?>><a href="<?php echo admin_url('options-general.php?page=wordpress-popular-posts&tab=stats'); ?>" title="<?php esc_attr_e('Stats', 'wordpress-popular-posts'); ?>"><span><?php _e('Stats', 'wordpress-popular-posts'); ?></span></a></li>
116
+ <li <?php echo ('tools' == $current ) ? 'class="current"' : ''; ?>><a href="<?php echo admin_url('options-general.php?page=wordpress-popular-posts&tab=tools'); ?>" title="<?php esc_attr_e('Tools', 'wordpress-popular-posts'); ?>"><span><?php _e('Tools', 'wordpress-popular-posts'); ?></span></a></li>
117
+ <li <?php echo ('debug' == $current ) ? 'class="current"' : ''; ?>><a href="<?php echo admin_url('options-general.php?page=wordpress-popular-posts&tab=debug'); ?>" title="Debug"><span>Debug</span></a></li>
118
+ </ul>
119
+ </nav>
120
+ <?php endif; ?>
121
 
122
  <div class="wpp-wrapper wpp-section-<?php echo $current; ?>">
123
  <div class="wpp-header">
126
  </div>
127
 
128
  <?php
129
+ // Stats
130
+ require_once 'screen-stats.php';
131
+ // Tools
132
+ require_once 'screen-tools.php';
133
+ // Debug
134
+ require_once 'screen-debug.php';
135
  ?>
136
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/Admin/screen-debug.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( 'debug' == $current ) {
3
+
4
+ if ( ! current_user_can('edit_others_posts') ) {
5
+ echo '<p style="text-align: center;">' . __('Sorry, you do not have enough permissions to do this. Please contact the site administrator for support.', 'wordpress-popular-posts') . '</p>';
6
+ }
7
+ else {
8
+ global $wpdb, $wp_version;
9
+
10
+ $my_theme = wp_get_theme();
11
+ $site_plugins = get_plugins();
12
+ $plugin_names = [];
13
+ $performance_nag = get_option('wpp_performance_nag');
14
+
15
+ if ( ! $performance_nag ) {
16
+ $performance_nag = [
17
+ 'status' => 0,
18
+ 'last_checked' => null
19
+ ];
20
+ }
21
+
22
+ switch($performance_nag['status']) {
23
+ case 0:
24
+ $performance_nag_status = 'Inactive';
25
+ break;
26
+ case 1:
27
+ $performance_nag_status = 'Active';
28
+ break;
29
+ case 2:
30
+ $performance_nag_status = 'Remind me later';
31
+ break;
32
+ case 3:
33
+ $performance_nag_status = 'Dismissed';
34
+ break;
35
+ default:
36
+ $performance_nag_status = 'Inactive';
37
+ break;
38
+ }
39
+
40
+ foreach( $site_plugins as $main_file => $plugin_meta ) :
41
+ if ( ! is_plugin_active($main_file) )
42
+ continue;
43
+ $plugin_names[] = sanitize_text_field($plugin_meta['Name'] . ' ' . $plugin_meta['Version']);
44
+ endforeach;
45
+ ?>
46
+ <div id="wpp_debug">
47
+ <h3>Plugin Configuration</h3>
48
+ <p><strong>Performance Nag:</strong> <?php echo $performance_nag_status; ?></p>
49
+ <p><strong>Log Limit:</strong> <?php echo ( $this->config['tools']['log']['limit'] ) ? 'Yes, keep data for ' . $this->config['tools']['log']['expires_after'] . ' days' : 'No'; ?></p>
50
+ <p><strong>Log Views From:</strong> <?php echo ( 0 == $this->config['tools']['log']['level'] ) ? 'Visitors only' : ( (2 == $this->config['tools']['log']['level']) ? 'Logged-in users only' : 'Everyone' ); ?></p>
51
+ <p><strong>Data Caching:</strong> <?php echo ( $this->config['tools']['cache']['active'] ) ? 'Yes, ' . $this->config['tools']['cache']['interval']['value'] . ' ' . $this->config['tools']['cache']['interval']['time'] : 'No'; ?></p>
52
+ <p><strong>Data Sampling:</strong> <?php echo ( $this->config['tools']['sampling']['active'] ) ? 'Yes, with a rate of ' . $this->config['tools']['sampling']['rate'] : 'No'; ?></p>
53
+ <p><strong>External object cache:</strong> <?php echo ( wp_using_ext_object_cache() ) ? 'Yes' : 'No'; ?></p>
54
+ <p><strong>WPP_CACHE_VIEWS:</strong> <?php echo ( defined('WPP_CACHE_VIEWS') && WPP_CACHE_VIEWS ) ? 'Yes' : 'No'; ?></p>
55
+
56
+ <br />
57
+
58
+ <h3>System Info</h3>
59
+ <p><strong>PHP version:</strong> <?php echo phpversion(); ?></p>
60
+ <p><strong>PHP extensions:</strong> <?php echo implode(', ', get_loaded_extensions()); ?></p>
61
+ <p><strong>Database version:</strong> <?php echo $wpdb->get_var("SELECT VERSION();"); ?></p>
62
+ <p><strong>InnoDB availability:</strong> <?php echo $wpdb->get_var("SELECT SUPPORT FROM INFORMATION_SCHEMA.ENGINES WHERE ENGINE = 'InnoDB';"); ?></p>
63
+ <p><strong>WordPress version:</strong> <?php echo $wp_version; ?></p>
64
+ <p><strong>Multisite:</strong> <?php echo ( function_exists('is_multisite') && is_multisite() ) ? 'Yes' : 'No'; ?></p>
65
+ <p><strong>Active plugins:</strong> <?php echo implode(', ', $plugin_names); ?></p>
66
+ <p><strong>Theme:</strong> <?php echo $my_theme->get('Name') . ' (' . $my_theme->get('Version') . ') by ' . $my_theme->get('Author'); ?></p>
67
+ </div>
68
+ <?php
69
+ }
70
+ }
src/Admin/screen-stats.php ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( 'stats' == $current ) {
3
+ $chart_data = json_decode(
4
+ $this->get_chart_data(
5
+ $this->config['stats']['range'],
6
+ strtoupper($this->config['stats']['time_unit']),
7
+ $this->config['stats']['time_quantity']
8
+ ),
9
+ true
10
+ );
11
+ ?>
12
+
13
+ <?php if ( current_user_can('edit_others_posts') ) : ?>
14
+ <a href="#" id="wpp-stats-config-btn" class="dashicons dashicons-admin-generic"></a>
15
+
16
+ <div id="wpp-stats-config" class="wpp-lightbox">
17
+ <form action="" method="post" id="wpp_stats_options" name="wpp_stats_options">
18
+ <label for="stats_type"><?php _e("Post type", 'wordpress-popular-posts'); ?>:</label>
19
+ <input type="text" name="stats_type" value="<?php echo esc_attr($this->config['stats']['post_type']); ?>" size="15">
20
+
21
+ <label for="stats_limits"><?php _e("Limit", 'wordpress-popular-posts'); ?>:</label>
22
+ <input type="text" name="stats_limit" value="<?php echo $this->config['stats']['limit']; ?>" size="5">
23
+
24
+ <label for="stats_freshness"><input type="checkbox" class="checkbox" <?php echo ($this->config['stats']['freshness']) ? 'checked="checked"' : ''; ?> id="stats_freshness" name="stats_freshness"> <small><?php _e('Display only posts published within the selected Time Range', 'wordpress-popular-posts'); ?></small></label>
25
+
26
+ <div class="clear"></div>
27
+ <br /><br />
28
+
29
+ <input type="hidden" name="section" value="stats">
30
+ <button type="submit" class="button-primary action"><?php _e("Apply", 'wordpress-popular-posts'); ?></button>
31
+ <button class="button-secondary action right"><?php _e("Cancel"); ?></button>
32
+
33
+ <?php wp_nonce_field('wpp-update-stats-options', 'wpp-update-stats-options-token'); ?>
34
+ </form>
35
+ </div>
36
+ <?php endif; ?>
37
+
38
+ <div id="wpp-stats-range" class="wpp-lightbox">
39
+ <form action="" method="post">
40
+ <ul class="wpp-lightbox-tabs">
41
+ <li class="active"><a href="#"><?php _e('Custom Time Range', 'wordpress-popular-posts'); ?></a></li>
42
+ <li><a href="#"><?php _e('Date Range', 'wordpress-popular-posts'); ?></a></li>
43
+ </ul>
44
+
45
+ <div class="wpp-lightbox-tab-content wpp-lightbox-tab-content-active" id="custom-time-range">
46
+ <input type="text" id="stats_range_time_quantity" name="stats_range_time_quantity" value="<?php echo $this->config['stats']['time_quantity']; ?>">
47
+
48
+ <select id="stats_range_time_unit" name="stats_range_time_unit">
49
+ <option <?php if ($this->config['stats']['time_unit'] == "minute") { ?>selected="selected"<?php } ?> value="minute"><?php _e("Minute(s)", 'wordpress-popular-posts'); ?></option>
50
+ <option <?php if ($this->config['stats']['time_unit'] == "hour") { ?>selected="selected"<?php } ?> value="hour"><?php _e("Hour(s)", 'wordpress-popular-posts'); ?></option>
51
+ <option <?php if ($this->config['stats']['time_unit'] == "day") { ?>selected="selected"<?php } ?> value="day"><?php _e("Day(s)", 'wordpress-popular-posts'); ?></option>
52
+ </select>
53
+ </div>
54
+
55
+ <div class="wpp-lightbox-tab-content" id="custom-date-range">
56
+ <input type="text" id="stats_range_date" name="stats_range_date" value="" placeholder="<?php esc_attr_e('Select a date...', 'wordpress-popular-posts'); ?>" readonly>
57
+ </div>
58
+
59
+ <div class="clear"></div>
60
+ <br />
61
+
62
+ <button type="submit" class="button-primary action">
63
+ <?php _e("Apply", 'wordpress-popular-posts'); ?>
64
+ </button>
65
+ <button class="button-secondary action right">
66
+ <?php _e("Cancel"); ?>
67
+ </button>
68
+ </form>
69
+ </div>
70
+
71
+ <div id="wpp-chart-wrapper">
72
+ <h4><?php echo $chart_data['totals']['label_summary']; ?></h4>
73
+ <h5><?php echo $chart_data['totals']['label_date_range']; ?></h5>
74
+
75
+ <ul class="wpp-header-nav" id="wpp-time-ranges">
76
+ <li <?php echo ('daily' == $this->config['stats']['range'] || 'today' == $this->config['stats']['range'] ) ? ' class="current"' : ''; ?>><a href="#" data-range="today" title="<?php esc_attr_e('Today', 'wordpress-popular-posts'); ?>"><?php _e('Today', 'wordpress-popular-posts'); ?></a></li>
77
+ <li <?php echo ('daily' == $this->config['stats']['range'] || 'last24hours' == $this->config['stats']['range'] ) ? ' class="current"' : ''; ?>><a href="#" data-range="last24hours" title="<?php esc_attr_e('Last 24 hours', 'wordpress-popular-posts'); ?>">24h</a></li>
78
+ <li <?php echo ('weekly' == $this->config['stats']['range'] || 'last7days' == $this->config['stats']['range'] ) ? ' class="current"' : ''; ?>><a href="#" data-range="last7days" title="<?php esc_attr_e('Last 7 days', 'wordpress-popular-posts'); ?>">7d</a></li>
79
+ <li <?php echo ('monthly' == $this->config['stats']['range'] || 'last30days' == $this->config['stats']['range'] ) ? ' class="current"' : ''; ?>><a href="#" data-range="last30days" title="<?php esc_attr_e('Last 30 days', 'wordpress-popular-posts'); ?>">30d</a></li>
80
+ <li <?php echo ('custom' == $this->config['stats']['range'] ) ? ' class="current"' : ''; ?>><a href="#" data-range="custom" title="<?php esc_attr_e('Custom', 'wordpress-popular-posts'); ?>"><?php _e('Custom', 'wordpress-popular-posts'); ?></a></li>
81
+ </ul>
82
+
83
+ <div id="wpp-chart">
84
+ <p><?php echo sprintf( __('Err... A nice little chart is supposed to be here, instead you are seeing this because your browser is too old. <br /> Please <a href="%s" target="_blank">get a better browser</a>.', 'wordpress-popular-posts'), 'https://browsehappy.com/'); ?></p>
85
+ </div>
86
+ </div>
87
+
88
+ <div id="wpp-listing" class="wpp-content">
89
+ <ul class="wpp-tabbed-nav">
90
+ <li class="active"><a href="#" title="<?php esc_attr_e('See your most viewed posts within the selected time range', 'wordpress-popular-posts'); ?>"><span class="wpp-icon-eye"></span><span><?php _e('Most viewed', 'wordpress-popular-posts'); ?></span></a></li>
91
+ <li><a href="#" title="<?php esc_attr_e('See your most commented posts within the selected time range', 'wordpress-popular-posts'); ?>"><span class="wpp-icon-comment"></span><span><?php _e('Most commented', 'wordpress-popular-posts'); ?></span></a></li>
92
+ <li><a href="#" title="<?php esc_attr_e('See your most viewed posts within the last hour', 'wordpress-popular-posts'); ?>"><span class="wpp-icon-rocket"></span><span><?php _e('Trending now', 'wordpress-popular-posts'); ?></span></a></li>
93
+ <li><a href="#" title="<?php esc_attr_e('See your most viewed posts of all time', 'wordpress-popular-posts'); ?>"><span class="wpp-icon-award"></span><span><?php _e('Hall of Fame', 'wordpress-popular-posts'); ?></span></a></li>
94
+ </ul>
95
+
96
+ <div class="wpp-tab-content wpp-tab-content-active">
97
+ <span class="spinner"></span>
98
+ </div>
99
+
100
+ <div class="wpp-tab-content">
101
+ <span class="spinner"></span>
102
+ </div>
103
+
104
+ <div class="wpp-tab-content">
105
+ <span class="spinner"></span>
106
+ </div>
107
+
108
+ <div class="wpp-tab-content">
109
+ <?php
110
+ $args = [
111
+ 'range' => 'all',
112
+ 'post_type' => $this->config['stats']['post_type'],
113
+ 'order_by' => 'views',
114
+ 'limit' => $this->config['stats']['limit'],
115
+ 'stats_tag' => [
116
+ 'comment_count' => 1,
117
+ 'views' => 1,
118
+ 'date' => [
119
+ 'active' => 1
120
+ ]
121
+ ]
122
+ ];
123
+ $query = new \WordPressPopularPosts\Query($args);
124
+ $posts = $query->get_posts();
125
+
126
+ $this->render_list($posts, 'hof');
127
+ ?>
128
+ </div>
129
+ </div>
130
+ <?php
131
+ }
src/Admin/screen-tools.php ADDED
@@ -0,0 +1,273 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( 'tools' == $current ) {
3
+
4
+ if ( ! current_user_can('edit_others_posts') ) {
5
+ echo '<p style="text-align: center;">' . __('Sorry, you do not have enough permissions to do this. Please contact the site administrator for support.', 'wordpress-popular-posts') . '</p>';
6
+ }
7
+ else {
8
+ ?>
9
+ <div id="wpp_tools">
10
+ <h3 class="wmpp-subtitle"><?php _e("Thumbnails", 'wordpress-popular-posts'); ?></h3>
11
+
12
+ <form action="" method="post" id="wpp_thumbnail_options" name="wpp_thumbnail_options">
13
+ <table class="form-table">
14
+ <tbody>
15
+ <tr valign="top">
16
+ <th scope="row"><label for="thumb_default"><?php _e("Default thumbnail", 'wordpress-popular-posts'); ?>:</label></th>
17
+ <td>
18
+ <?php
19
+ $fallback_thumbnail_url = trim($this->config['tools']['thumbnail']['default']);
20
+
21
+ if ( ! $fallback_thumbnail_url )
22
+ $fallback_thumbnail_url = $this->thumbnail->get_default_url();
23
+
24
+ $fallback_thumbnail_url = str_replace(
25
+ parse_url(
26
+ $fallback_thumbnail_url
27
+ , PHP_URL_SCHEME
28
+ ) . ':',
29
+ '',
30
+ $fallback_thumbnail_url
31
+ );
32
+ ?>
33
+ <div id="thumb-review">
34
+ <img src="<?php echo esc_url($fallback_thumbnail_url); ?>" alt="" />
35
+ </div>
36
+
37
+ <input id="upload_thumb_button" type="button" class="button" value="<?php _e("Change thumbnail", 'wordpress-popular-posts'); ?>">
38
+ <input type="hidden" id="upload_thumb_src" name="upload_thumb_src" value="">
39
+
40
+ <p class="description"><?php _e("This image will be displayed when no thumbnail is available", 'wordpress-popular-posts'); ?>.</p>
41
+ </td>
42
+ </tr>
43
+ <tr valign="top">
44
+ <th scope="row"><label for="thumb_source"><?php _e("Pick image from", 'wordpress-popular-posts'); ?>:</label></th>
45
+ <td>
46
+ <select name="thumb_source" id="thumb_source">
47
+ <option <?php if ($this->config['tools']['thumbnail']['source'] == "featured") { ?>selected="selected"<?php } ?> value="featured"><?php _e("Featured image", 'wordpress-popular-posts'); ?></option>
48
+ <option <?php if ($this->config['tools']['thumbnail']['source'] == "first_image") { ?>selected="selected"<?php } ?> value="first_image"><?php _e("First image on post", 'wordpress-popular-posts'); ?></option>
49
+ <option <?php if ($this->config['tools']['thumbnail']['source'] == "first_attachment") { ?>selected="selected"<?php } ?> value="first_attachment"><?php _e("First attachment", 'wordpress-popular-posts'); ?></option>
50
+ <option <?php if ($this->config['tools']['thumbnail']['source'] == "custom_field") { ?>selected="selected"<?php } ?> value="custom_field"><?php _e("Custom field", 'wordpress-popular-posts'); ?></option>
51
+ </select>
52
+ <br />
53
+ <p class="description"><?php _e("Tell WordPress Popular Posts where it should get thumbnails from", 'wordpress-popular-posts'); ?>.</p>
54
+ </td>
55
+ </tr>
56
+ <tr valign="top">
57
+ <th scope="row"><label for="thumb_lazy_load"><?php _e("Lazy load", 'wordpress-popular-posts'); ?>:</label> <small>[<a href="https://github.com/cabrerahector/wordpress-popular-posts/wiki/7.-Performance#lazy-loading" target="_blank" title="<?php _e('What is this?', 'wordpress-popular-posts'); ?>">?</a>]</small></th>
58
+ <td>
59
+ <select name="thumb_lazy_load" id="thumb_lazy_load">
60
+ <option <?php if ( ! $this->config['tools']['thumbnail']['lazyload'] ) { ?>selected="selected"<?php } ?> value="0"><?php _e("No", 'wordpress-popular-posts'); ?></option>
61
+ <option <?php if ( $this->config['tools']['thumbnail']['lazyload'] ) { ?>selected="selected"<?php } ?> value="1"><?php _e("Yes", 'wordpress-popular-posts'); ?></option>
62
+ </select>
63
+ </td>
64
+ </tr>
65
+ <tr valign="top" <?php if ($this->config['tools']['thumbnail']['source'] != "custom_field") { ?>style="display: none;"<?php } ?> id="row_custom_field">
66
+ <th scope="row"><label for="thumb_field"><?php _e("Custom field name", 'wordpress-popular-posts'); ?>:</label></th>
67
+ <td>
68
+ <input type="text" id="thumb_field" name="thumb_field" value="<?php echo esc_attr($this->config['tools']['thumbnail']['field']); ?>" size="10" <?php if ($this->config['tools']['thumbnail']['source'] != "custom_field") { ?>style="display: none;"<?php } ?> />
69
+ </td>
70
+ </tr>
71
+ <tr valign="top" <?php if ($this->config['tools']['thumbnail']['source'] != "custom_field") { ?>style="display: none;"<?php } ?> id="row_custom_field_resize">
72
+ <th scope="row"><label for="thumb_field_resize"><?php _e("Resize image from Custom field?", 'wordpress-popular-posts'); ?>:</label></th>
73
+ <td>
74
+ <select name="thumb_field_resize" id="thumb_field_resize">
75
+ <option <?php if ( !$this->config['tools']['thumbnail']['resize'] ) { ?>selected="selected"<?php } ?> value="0"><?php _e("No, use image as is", 'wordpress-popular-posts'); ?></option>
76
+ <option <?php if ($this->config['tools']['thumbnail']['resize'] == 1 ) { ?>selected="selected"<?php } ?> value="1"><?php _e("Yes", 'wordpress-popular-posts'); ?></option>
77
+ </select>
78
+ </td>
79
+ </tr>
80
+ <?php
81
+ $wp_upload_dir = wp_get_upload_dir();
82
+ if ( is_dir($wp_upload_dir['basedir'] . "/" . 'wordpress-popular-posts') ) :
83
+ ?>
84
+ <tr valign="top">
85
+ <th scope="row"></th>
86
+ <td>
87
+ <input type="button" name="wpp-reset-image-cache" id="wpp-reset-image-cache" class="button-secondary" value="<?php _e("Empty image cache", 'wordpress-popular-posts'); ?>">
88
+ <p class="description"><?php _e("Use this button to clear WPP's thumbnails cache", 'wordpress-popular-posts'); ?>.</p>
89
+ </td>
90
+ </tr>
91
+ <?php
92
+ endif;
93
+ ?>
94
+ <tr valign="top">
95
+ <td colspan="2">
96
+ <input type="hidden" name="section" value="thumb">
97
+ <input type="submit" class="button-primary action" id="btn_th_ops" value="<?php _e("Apply", 'wordpress-popular-posts'); ?>" name="">
98
+ </td>
99
+ </tr>
100
+ </tbody>
101
+ </table>
102
+
103
+ <?php wp_nonce_field('wpp-update-thumbnail-options', 'wpp-update-thumbnail-options-token'); ?>
104
+ </form>
105
+ <br />
106
+ <p style="display: <?php echo ( current_user_can('manage_options') ) ? 'block' : 'none'; ?>; float:none; clear:both;">&nbsp;</p>
107
+
108
+ <?php if ( current_user_can('manage_options') ) : ?>
109
+ <h3 class="wmpp-subtitle"><?php _e("Data", 'wordpress-popular-posts'); ?></h3>
110
+
111
+ <form action="" method="post" id="wpp_ajax_options" name="wpp_ajax_options">
112
+ <table class="form-table">
113
+ <tbody>
114
+ <tr valign="top">
115
+ <th scope="row"><label for="log_option"><?php _e("Log views from", 'wordpress-popular-posts'); ?>:</label></th>
116
+ <td>
117
+ <select name="log_option" id="log_option">
118
+ <option <?php if ($this->config['tools']['log']['level'] == 0) { ?>selected="selected"<?php } ?> value="0"><?php _e("Visitors only", 'wordpress-popular-posts'); ?></option>
119
+ <option <?php if ($this->config['tools']['log']['level'] == 2) { ?>selected="selected"<?php } ?> value="2"><?php _e("Logged-in users only", 'wordpress-popular-posts'); ?></option>
120
+ <option <?php if ($this->config['tools']['log']['level'] == 1) { ?>selected="selected"<?php } ?> value="1"><?php _e("Everyone", 'wordpress-popular-posts'); ?></option>
121
+ </select>
122
+ <br />
123
+ </td>
124
+ </tr>
125
+ <tr valign="top">
126
+ <th scope="row"><label for="log_limit"><?php _e("Log limit", 'wordpress-popular-posts'); ?>:</label></th>
127
+ <td>
128
+ <select name="log_limit" id="log_limit">
129
+ <option <?php if ($this->config['tools']['log']['limit'] == 0) { ?>selected="selected"<?php } ?> value="0"><?php _e("Disabled", 'wordpress-popular-posts'); ?></option>
130
+ <option <?php if ($this->config['tools']['log']['limit'] == 1) { ?>selected="selected"<?php } ?> value="1"><?php _e("Keep data for", 'wordpress-popular-posts'); ?></option>
131
+ </select>
132
+
133
+ <label for="log_expire_time"<?php echo ($this->config['tools']['log']['limit'] == 0) ? ' style="display: none;"' : ''; ?>>
134
+ <input type="text" id="log_expire_time" name="log_expire_time" value="<?php echo esc_attr($this->config['tools']['log']['expires_after']); ?>" size="3"> <?php _e("day(s)", 'wordpress-popular-posts'); ?>
135
+ </label>
136
+
137
+ <p class="description"<?php echo ($this->config['tools']['log']['limit'] == 0) ? ' style="display: none;"' : ''; ?>><?php _e("Data older than the specified time frame will be automatically discarded", 'wordpress-popular-posts'); ?>.</p>
138
+
139
+ <br <?php echo (1 == $this->config['tools']['log']['limit']) ? 'style="display: none;"' : ''; ?>/>
140
+ </td>
141
+ </tr>
142
+ <tr valign="top">
143
+ <th scope="row"><label for="ajax"><?php _e("Ajaxify widget", 'wordpress-popular-posts'); ?>:</label></th>
144
+ <td>
145
+ <select name="ajax" id="ajax">
146
+ <option <?php if (! $this->config['tools']['ajax']) { ?>selected="selected"<?php } ?> value="0"><?php _e("Disabled", 'wordpress-popular-posts'); ?></option>
147
+ <option <?php if ($this->config['tools']['ajax']) { ?>selected="selected"<?php } ?> value="1"><?php _e("Enabled", 'wordpress-popular-posts'); ?></option>
148
+ </select>
149
+
150
+ <br />
151
+ <p class="description"><?php _e("If you are using a caching plugin such as WP Super Cache, enabling this feature will keep the popular list from being cached by it", 'wordpress-popular-posts'); ?>.</p>
152
+ </td>
153
+ </tr>
154
+ <tr valign="top">
155
+ <th scope="row"><label for="cache"><?php _e("Data Caching", 'wordpress-popular-posts'); ?>:</label> <small>[<a href="https://github.com/cabrerahector/wordpress-popular-posts/wiki/7.-Performance#caching-db-queries-results" target="_blank" title="<?php _e('What is this?', 'wordpress-popular-posts'); ?>">?</a>]</small></th>
156
+ <td>
157
+ <select name="cache" id="cache">
158
+ <option <?php if ( ! $this->config['tools']['cache']['active'] ) { ?>selected="selected"<?php } ?> value="0"><?php _e("Never cache", 'wordpress-popular-posts'); ?></option>
159
+ <option <?php if ( $this->config['tools']['cache']['active'] ) { ?>selected="selected"<?php } ?> value="1"><?php _e("Enable caching", 'wordpress-popular-posts'); ?></option>
160
+ </select>
161
+
162
+ <br />
163
+ <p class="description"><?php _e("WPP can cache the popular list for a specified amount of time. Recommended for large / high traffic sites", 'wordpress-popular-posts'); ?>.</p>
164
+ </td>
165
+ </tr>
166
+ <tr valign="top" <?php if ( ! $this->config['tools']['cache']['active'] ) { ?>style="display: none;"<?php } ?> id="cache_refresh_interval">
167
+ <th scope="row"><label for="cache_interval_value"><?php _e("Refresh cache every", 'wordpress-popular-posts'); ?>:</label></th>
168
+ <td>
169
+ <input name="cache_interval_value" type="text" id="cache_interval_value" value="<?php echo ( isset($this->config['tools']['cache']['interval']['value']) ) ? (int) $this->config['tools']['cache']['interval']['value'] : 1; ?>" class="small-text">
170
+ <select name="cache_interval_time" id="cache_interval_time">
171
+ <option <?php if ($this->config['tools']['cache']['interval']['time'] == "minute") { ?>selected="selected"<?php } ?> value="minute"><?php _e("Minute(s)", 'wordpress-popular-posts'); ?></option>
172
+ <option <?php if ($this->config['tools']['cache']['interval']['time'] == "hour") { ?>selected="selected"<?php } ?> value="hour"><?php _e("Hour(s)", 'wordpress-popular-posts'); ?></option>
173
+ <option <?php if ($this->config['tools']['cache']['interval']['time'] == "day") { ?>selected="selected"<?php } ?> value="day"><?php _e("Day(s)", 'wordpress-popular-posts'); ?></option>
174
+ <option <?php if ($this->config['tools']['cache']['interval']['time'] == "week") { ?>selected="selected"<?php } ?> value="week"><?php _e("Week(s)", 'wordpress-popular-posts'); ?></option>
175
+ <option <?php if ($this->config['tools']['cache']['interval']['time'] == "month") { ?>selected="selected"<?php } ?> value="month"><?php _e("Month(s)", 'wordpress-popular-posts'); ?></option>
176
+ <option <?php if ($this->config['tools']['cache']['interval']['time'] == "year") { ?>selected="selected"<?php } ?> value="month"><?php _e("Year(s)", 'wordpress-popular-posts'); ?></option>
177
+ </select>
178
+ <br />
179
+ <p class="description" style="display: none;" id="cache_too_long"><?php _e("Really? That long?", 'wordpress-popular-posts'); ?></p>
180
+ </td>
181
+ </tr>
182
+ <tr valign="top">
183
+ <th scope="row"><label for="sampling"><?php _e("Data Sampling", 'wordpress-popular-posts'); ?>:</label> <small>[<a href="https://github.com/cabrerahector/wordpress-popular-posts/wiki/7.-Performance#data-sampling" target="_blank" title="<?php _e('What is this?', 'wordpress-popular-posts'); ?>">?</a>]</small></th>
184
+ <td>
185
+ <select name="sampling" id="sampling">
186
+ <option <?php if ( !$this->config['tools']['sampling']['active'] ) { ?>selected="selected"<?php } ?> value="0"><?php _e("Disabled", 'wordpress-popular-posts'); ?></option>
187
+ <option <?php if ( $this->config['tools']['sampling']['active'] ) { ?>selected="selected"<?php } ?> value="1"><?php _e("Enabled", 'wordpress-popular-posts'); ?></option>
188
+ </select>
189
+
190
+ <br />
191
+ <p class="description"><?php echo sprintf( __('By default, WordPress Popular Posts stores in database every single visit your site receives. For small / medium sites this is generally OK, but on large / high traffic sites the constant writing to the database may have an impact on performance. With <a href="%1$s" target="_blank">data sampling</a>, WordPress Popular Posts will store only a subset of your traffic and report on the tendencies detected in that sample set (for more, <a href="%2$s" target="_blank">please read here</a>)', 'wordpress-popular-posts'), 'http://en.wikipedia.org/wiki/Sample_%28statistics%29', 'https://github.com/cabrerahector/wordpress-popular-posts/wiki/7.-Performance#data-sampling'); ?>.</p>
192
+ </td>
193
+ </tr>
194
+ <tr valign="top" <?php if ( ! $this->config['tools']['sampling']['active'] ) { ?>style="display: none;"<?php } ?>>
195
+ <th scope="row"><label for="sample_rate"><?php _e("Sample Rate", 'wordpress-popular-posts'); ?>:</label></th>
196
+ <td>
197
+ <input name="sample_rate" type="text" id="sample_rate" value="<?php echo ( isset($this->config['tools']['sampling']['rate']) ) ? (int) $this->config['tools']['sampling']['rate'] : 100; ?>" class="small-text">
198
+ <br />
199
+ <p class="description"><?php echo sprintf(__("A sampling rate of %d is recommended for large / high traffic sites. For lower traffic sites, you should lower the value", 'wordpress-popular-posts'), 100); ?>.</p>
200
+ </td>
201
+ </tr>
202
+ <tr valign="top">
203
+ <td colspan="2">
204
+ <input type="hidden" name="section" value="data">
205
+ <input type="submit" class="button-primary action" id="btn_ajax_ops" value="<?php _e("Apply", 'wordpress-popular-posts'); ?>" name="">
206
+ </td>
207
+ </tr>
208
+ </tbody>
209
+ </table>
210
+
211
+ <?php wp_nonce_field('wpp-update-data-options', 'wpp-update-data-options-token'); ?>
212
+ </form>
213
+ <br />
214
+ <p style="display: block; float:none; clear: both;">&nbsp;</p>
215
+ <?php endif; ?>
216
+
217
+ <h3 class="wmpp-subtitle"><?php _e("Miscellaneous", 'wordpress-popular-posts'); ?></h3>
218
+
219
+ <form action="" method="post" id="wpp_link_options" name="wpp_link_options">
220
+ <table class="form-table">
221
+ <tbody>
222
+ <tr valign="top">
223
+ <th scope="row"><label for="link_target"><?php _e("Open links in", 'wordpress-popular-posts'); ?>:</label></th>
224
+ <td>
225
+ <select name="link_target" id="link_target">
226
+ <option <?php if ($this->config['tools']['link']['target'] == '_self') { ?>selected="selected"<?php } ?> value="_self"><?php _e("Current window", 'wordpress-popular-posts'); ?></option>
227
+ <option <?php if ($this->config['tools']['link']['target'] == '_blank') { ?>selected="selected"<?php } ?> value="_blank"><?php _e("New tab/window", 'wordpress-popular-posts'); ?></option>
228
+ </select>
229
+ <br />
230
+ </td>
231
+ </tr>
232
+ <tr valign="top">
233
+ <th scope="row"><label for="css"><?php _e("Use plugin's stylesheet", 'wordpress-popular-posts'); ?>:</label></th>
234
+ <td>
235
+ <select name="css" id="css">
236
+ <option <?php if ($this->config['tools']['css']) { ?>selected="selected"<?php } ?> value="1"><?php _e("Enabled", 'wordpress-popular-posts'); ?></option>
237
+ <option <?php if (!$this->config['tools']['css']) { ?>selected="selected"<?php } ?> value="0"><?php _e("Disabled", 'wordpress-popular-posts'); ?></option>
238
+ </select>
239
+ <br />
240
+ <p class="description"><?php _e("By default, the plugin includes a stylesheet called wpp.css which you can use to style your popular posts listing. If you wish to use your own stylesheet or do not want it to have it included in the header section of your site, use this.", 'wordpress-popular-posts'); ?></p>
241
+ </td>
242
+ </tr>
243
+ <tr valign="top">
244
+ <th scope="row"><label for="experimental_features"><?php _e("Enable experimental features", 'wordpress-popular-posts'); ?>:</label></th>
245
+ <td>
246
+ <input type="checkbox" class="checkbox" id="experimental_features" name="experimental_features" <?php echo ($this->config['tools']['experimental']) ? 'checked="checked"' : ''; ?>>
247
+ </td>
248
+ </tr>
249
+ <tr valign="top">
250
+ <td colspan="2">
251
+ <input type="hidden" name="section" value="misc">
252
+ <input type="submit" class="button-primary action" value="<?php _e("Apply", 'wordpress-popular-posts'); ?>" name="">
253
+ </td>
254
+ </tr>
255
+ </tbody>
256
+ </table>
257
+
258
+ <?php wp_nonce_field('wpp-update-misc-options', 'wpp-update-misc-options-token'); ?>
259
+ </form>
260
+ <br />
261
+ <p style="display: block; float: none; clear: both;">&nbsp;</p>
262
+
263
+ <?php if ( current_user_can('manage_options') ) : ?>
264
+ <div style="margin-top: 2em;">
265
+ <p><?php _e('WordPress Popular Posts maintains data in two separate tables: one for storing the most popular entries on a daily basis (from now on, "cache"), and another one to keep the All-time data (from now on, "historical data" or just "data"). If for some reason you need to clear the cache table, or even both historical and cache tables, please use the buttons below to do so.', 'wordpress-popular-posts') ?></p>
266
+ <p><input type="button" name="wpp-reset-cache" id="wpp-reset-cache" class="button-secondary" value="<?php _e("Empty cache", 'wordpress-popular-posts'); ?>"> <label for="wpp-reset-cache"><small><?php _e('Use this button to manually clear entries from WPP cache only', 'wordpress-popular-posts'); ?></small></label></p>
267
+ <p><input type="button" name="wpp-reset-all" id="wpp-reset-all" class="button-secondary" value="<?php _e("Clear all data", 'wordpress-popular-posts'); ?>"> <label for="wpp-reset-all"><small><?php _e('Use this button to manually clear entries from all WPP data tables', 'wordpress-popular-posts'); ?></small></label></p>
268
+ </div>
269
+ <?php endif; ?>
270
+ </div>
271
+ <?php
272
+ }
273
+ }
src/Block/Widget/Widget.php CHANGED
@@ -1,14 +1,15 @@
1
  <?php
2
  namespace WordPressPopularPosts\Block\Widget;
3
 
4
- use WordPressPopularPosts\Helper;
5
- use WordPressPopularPosts\Query;
6
- use WordPressPopularPosts\Output;
7
  use WordPressPopularPosts\Block\Block;
 
8
 
9
  class Widget extends Block
10
  {
11
 
 
 
12
  /**
13
  * Administrative settings.
14
  *
@@ -16,7 +17,7 @@ class Widget extends Block
16
  * @var array
17
  * @access private
18
  */
19
- private $admin_options = [];
20
 
21
  /**
22
  * Image object.
@@ -73,9 +74,9 @@ class Widget extends Block
73
  * @param \WordPressPopularPosts\Translate $translate
74
  * @param \WordPressPopularPosts\Themer $themer
75
  */
76
- public function __construct(array $config, \WordPressPopularPosts\Output $output, \WordPressPopularPosts\Image $thumbnail, \WordPressPopularPosts\Translate $translate, \WordPressPopularPosts\Themer $themer)
77
  {
78
- $this->admin_options = $config;
79
  $this->output = $output;
80
  $this->thumbnail = $thumbnail;
81
  $this->translate = $translate;
@@ -387,7 +388,7 @@ class Widget extends Block
387
  'words' => ( ! empty($excerpt_by_words) && Helper::is_number($excerpt_by_words) && $excerpt_by_words > 0 ),
388
  ],
389
  'thumbnail' => [
390
- 'active' => ( ! empty($thumbnail_width) && Helper::is_number($thumbnail_width) && $thumbnail_width > 0 ),
391
  'width' => ( ! empty($thumbnail_width) && Helper::is_number($thumbnail_width) && $thumbnail_width > 0 ) ? $thumbnail_width : 0,
392
  'height' => ( ! empty($thumbnail_height) && Helper::is_number($thumbnail_height) && $thumbnail_height > 0 ) ? $thumbnail_height : 0,
393
  'build' => 'predefined' == $thumbnail_build ? 'predefined' : 'manual',
@@ -453,43 +454,14 @@ class Widget extends Block
453
 
454
  $isAdmin = isset($_GET['isSelected']) ? $_GET['isSelected'] : false;
455
 
456
- if ( $this->admin_options['tools']['ajax'] && ! is_customize_preview() && ! $isAdmin ) {
457
  $html .= '<script type="application/json">' . json_encode($query_args) . '</script>';
458
  $html .= '<div class="wpp-widget-block-placeholder"></div>';
459
 
460
  return $html . '</div>';
461
  }
462
 
463
- // Return cached results
464
- if ( $this->admin_options['tools']['cache']['active'] ) {
465
-
466
- $key = md5(json_encode($query_args));
467
- $popular_posts = \WordPressPopularPosts\Cache::get($key);
468
-
469
- if ( false === $popular_posts ) {
470
- $popular_posts = new Query($query_args);
471
-
472
- $time_value = $this->admin_options['tools']['cache']['interval']['value']; // eg. 5
473
- $time_unit = $this->admin_options['tools']['cache']['interval']['time']; // eg. 'minute'
474
-
475
- // No popular posts found, check again in 1 minute
476
- if ( ! $popular_posts->get_posts() ) {
477
- $time_value = 1;
478
- $time_unit = 'minute';
479
- }
480
-
481
- \WordPressPopularPosts\Cache::set(
482
- $key,
483
- $popular_posts,
484
- $time_value,
485
- $time_unit
486
- );
487
- }
488
-
489
- } // Get popular posts
490
- else {
491
- $popular_posts = new Query($query_args);
492
- }
493
 
494
  $this->output->set_data($popular_posts->get_posts());
495
  $this->output->set_public_options($query_args);
@@ -509,7 +481,7 @@ class Widget extends Block
509
  * @param array
510
  * @return array
511
  */
512
- private function parse_attributes($atts = [])
513
  {
514
  $out = array();
515
 
1
  <?php
2
  namespace WordPressPopularPosts\Block\Widget;
3
 
4
+ use WordPressPopularPosts\{ Helper, Image, Output, Themer, Translate };
 
 
5
  use WordPressPopularPosts\Block\Block;
6
+ use WordPressPopularPosts\Traits\QueriesPosts;
7
 
8
  class Widget extends Block
9
  {
10
 
11
+ use QueriesPosts;
12
+
13
  /**
14
  * Administrative settings.
15
  *
17
  * @var array
18
  * @access private
19
  */
20
+ private $config = [];
21
 
22
  /**
23
  * Image object.
74
  * @param \WordPressPopularPosts\Translate $translate
75
  * @param \WordPressPopularPosts\Themer $themer
76
  */
77
+ public function __construct(array $config, Output $output, Image $thumbnail, Translate $translate, Themer $themer)
78
  {
79
+ $this->config = $config;
80
  $this->output = $output;
81
  $this->thumbnail = $thumbnail;
82
  $this->translate = $translate;
388
  'words' => ( ! empty($excerpt_by_words) && Helper::is_number($excerpt_by_words) && $excerpt_by_words > 0 ),
389
  ],
390
  'thumbnail' => [
391
+ 'active' => ( 'predefined' == $thumbnail_build && $attributes['display_post_thumbnail'] ) ? true : ( ! empty($thumbnail_width) && Helper::is_number($thumbnail_width) && $thumbnail_width > 0 ),
392
  'width' => ( ! empty($thumbnail_width) && Helper::is_number($thumbnail_width) && $thumbnail_width > 0 ) ? $thumbnail_width : 0,
393
  'height' => ( ! empty($thumbnail_height) && Helper::is_number($thumbnail_height) && $thumbnail_height > 0 ) ? $thumbnail_height : 0,
394
  'build' => 'predefined' == $thumbnail_build ? 'predefined' : 'manual',
454
 
455
  $isAdmin = isset($_GET['isSelected']) ? $_GET['isSelected'] : false;
456
 
457
+ if ( $this->config['tools']['ajax'] && ! is_customize_preview() && ! $isAdmin ) {
458
  $html .= '<script type="application/json">' . json_encode($query_args) . '</script>';
459
  $html .= '<div class="wpp-widget-block-placeholder"></div>';
460
 
461
  return $html . '</div>';
462
  }
463
 
464
+ $popular_posts = $this->maybe_query($query_args);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
 
466
  $this->output->set_data($popular_posts->get_posts());
467
  $this->output->set_public_options($query_args);
481
  * @param array
482
  * @return array
483
  */
484
+ private function parse_attributes(array $atts = [])
485
  {
486
  $out = array();
487
 
src/Block/Widget/edit.js CHANGED
@@ -3,7 +3,7 @@ import { escape_html, unescape_html } from '../utils';
3
  const { serverSideRender: ServerSideRender } = wp;
4
  const { Component, Fragment } = wp.element;
5
  const { BlockControls } = wp.blockEditor;
6
- const { Button, CheckboxControl, Disabled, SelectControl, Spinner, TextareaControl, TextControl, Toolbar } = wp.components;
7
  const { __ } = wp.i18n;
8
  const endpoint = 'wordpress-popular-posts/v1';
9
 
@@ -120,8 +120,8 @@ export class WPPWidgetBlockEdit extends Component
120
 
121
  return (
122
  <BlockControls>
123
- <Toolbar>
124
- <Button
125
  label={ this.state.editMode ? __('Preview', 'wordpress-popular-posts') : __('Edit', 'wordpress-popular-posts') }
126
  icon={ this.state.editMode ? "format-image" : "edit" }
127
  onClick={onPreviewChange}
@@ -621,7 +621,7 @@ export class WPPWidgetBlockEdit extends Component
621
 
622
  setAttributes({
623
  shorten_title: config.shorten_title.active,
624
- title_length: config.shorten_title.title_length,
625
  title_by_words: config.shorten_title.words ? 1 : 0,
626
  display_post_excerpt: config['post-excerpt'].active,
627
  excerpt_format: config['post-excerpt'].format,
3
  const { serverSideRender: ServerSideRender } = wp;
4
  const { Component, Fragment } = wp.element;
5
  const { BlockControls } = wp.blockEditor;
6
+ const { CheckboxControl, Disabled, SelectControl, Spinner, TextareaControl, TextControl, Toolbar, ToolbarButton } = wp.components;
7
  const { __ } = wp.i18n;
8
  const endpoint = 'wordpress-popular-posts/v1';
9
 
120
 
121
  return (
122
  <BlockControls>
123
+ <Toolbar label="{ __('Settings') }">
124
+ <ToolbarButton
125
  label={ this.state.editMode ? __('Preview', 'wordpress-popular-posts') : __('Edit', 'wordpress-popular-posts') }
126
  icon={ this.state.editMode ? "format-image" : "edit" }
127
  onClick={onPreviewChange}
621
 
622
  setAttributes({
623
  shorten_title: config.shorten_title.active,
624
+ title_length: config.shorten_title.length,
625
  title_by_words: config.shorten_title.words ? 1 : 0,
626
  display_post_excerpt: config['post-excerpt'].active,
627
  excerpt_format: config['post-excerpt'].format,
src/Cache.php CHANGED
@@ -34,7 +34,7 @@ class Cache {
34
  * @param string $key The name of the cached data.
35
  * @return mixed
36
  */
37
- public static function get($key)
38
  {
39
  return get_transient($key);
40
  }
@@ -47,7 +47,7 @@ class Cache {
47
  * @param string $key The name of the cached data.
48
  * @param mixed $data The data being stored.
49
  */
50
- public static function set($key = null, $data = [], $time_value = 1, $time_unit = 'minute')
51
  {
52
  if ( !$key )
53
  return false;
34
  * @param string $key The name of the cached data.
35
  * @return mixed
36
  */
37
+ public static function get(string $key)
38
  {
39
  return get_transient($key);
40
  }
47
  * @param string $key The name of the cached data.
48
  * @param mixed $data The data being stored.
49
  */
50
+ public static function set(string $key = null, $data = [], int $time_value = 1, string $time_unit = 'minute') /** @TODO: starting PHP 8.0 $data can be declared as mixed $data */
51
  {
52
  if ( !$key )
53
  return false;
src/Container/Container.php CHANGED
@@ -47,7 +47,7 @@ class Container implements \ArrayAccess
47
  *
48
  * @return bool
49
  */
50
- public function offsetExists($key)
51
  {
52
  return array_key_exists($key, $this->values);
53
  }
@@ -58,7 +58,7 @@ class Container implements \ArrayAccess
58
  * @param mixed $key
59
  * @param mixed $value
60
  */
61
- public function offsetSet($key, $value)
62
  {
63
  $this->values[$key] = $value;
64
  }
@@ -68,7 +68,7 @@ class Container implements \ArrayAccess
68
  *
69
  * @param mixed $key
70
  */
71
- public function offsetUnset($key)
72
  {
73
  unset($this->values[$key]);
74
  }
@@ -80,7 +80,7 @@ class Container implements \ArrayAccess
80
  *
81
  * @return mixed
82
  */
83
- public function offsetGet($key)
84
  {
85
  if ( ! $this->offsetExists($key) ) {
86
  throw new \InvalidArgumentException(sprintf('Container doesn\'t have a value stored for the "%s" key.', $key));
47
  *
48
  * @return bool
49
  */
50
+ public function offsetExists($key) /** @TODO: starting PHP 8.0 $key can be declared as mixed $key, see https://www.php.net/manual/en/language.types.declarations.php */
51
  {
52
  return array_key_exists($key, $this->values);
53
  }
58
  * @param mixed $key
59
  * @param mixed $value
60
  */
61
+ public function offsetSet($key, $value) /** @TODO: starting PHP 8.0 $key and $value can be declared as mixed $key, mixed $value */
62
  {
63
  $this->values[$key] = $value;
64
  }
68
  *
69
  * @param mixed $key
70
  */
71
+ public function offsetUnset($key) /** @TODO: starting PHP 8.0 $key can be declared as mixed $key */
72
  {
73
  unset($this->values[$key]);
74
  }
80
  *
81
  * @return mixed
82
  */
83
+ public function offsetGet($key) /** @TODO: starting PHP 8.0 $key can be declared as mixed $key */
84
  {
85
  if ( ! $this->offsetExists($key) ) {
86
  throw new \InvalidArgumentException(sprintf('Container doesn\'t have a value stored for the "%s" key.', $key));
src/Container/WordPressPopularPostsConfiguration.php CHANGED
@@ -1,7 +1,12 @@
1
  <?php
2
  namespace WordPressPopularPosts\Container;
3
 
4
- use WordPressPopularPosts\Settings;
 
 
 
 
 
5
 
6
  class WordPressPopularPostsConfiguration implements ContainerConfigurationInterface
7
  {
@@ -17,71 +22,131 @@ class WordPressPopularPostsConfiguration implements ContainerConfigurationInterf
17
  $container['widget_options'] = Settings::get('widget_options');
18
 
19
  $container['i18n'] = $container->service(function(Container $container) {
20
- return new \WordPressPopularPosts\I18N($container['admin_options']);
21
  });
22
 
23
  $container['translate'] = $container->service(function(Container $container) {
24
- return new \WordPressPopularPosts\Translate();
25
  });
26
 
27
  $container['image'] = $container->service(function(Container $container) {
28
- return new \WordPressPopularPosts\Image($container['admin_options']);
29
  });
30
 
31
  $container['themer'] = $container->service(function(Container $container) {
32
- return new \WordPressPopularPosts\Themer();
33
  });
34
 
35
  $container['output'] = $container->service(function(Container $container) {
36
- return new \WordPressPopularPosts\Output($container['widget_options'], $container['admin_options'], $container['image'], $container['translate'], $container['themer']);
 
 
 
 
 
 
37
  });
38
 
39
  $container['widget'] = $container->service(function(Container $container) {
40
- return new \WordPressPopularPosts\Widget\Widget($container['widget_options'], $container['admin_options'], $container['output'], $container['image'], $container['translate'], $container['themer']);
 
 
 
 
 
 
 
41
  });
42
 
43
  $container['block_widget'] = $container->service(function(Container $container) {
44
- return new \WordPressPopularPosts\Block\Widget\Widget($container['admin_options'], $container['output'], $container['image'], $container['translate'], $container['themer']);
 
 
 
 
 
 
45
  });
46
 
47
  $container['posts_endpoint'] = $container->service(function(Container $container) {
48
- return new \WordPressPopularPosts\Rest\PostsEndpoint($container['admin_options'], $container['translate']);
 
 
 
49
  });
50
 
51
  $container['view_logger_endpoint'] = $container->service(function(Container $container) {
52
- return new \WordPressPopularPosts\Rest\ViewLoggerEndpoint($container['admin_options'], $container['translate']);
 
 
 
53
  });
54
 
55
  $container['taxonomies_endpoint'] = $container->service(function(Container $container) {
56
- return new \WordPressPopularPosts\Rest\TaxonomiesEndpoint($container['admin_options'], $container['translate']);
 
 
 
57
  });
58
 
59
  $container['themes_endpoint'] = $container->service(function(Container $container) {
60
- return new \WordPressPopularPosts\Rest\ThemesEndpoint($container['admin_options'], $container['translate'], $container['themer']);
 
 
 
 
61
  });
62
 
63
  $container['thumbnails_endpoint'] = $container->service(function(Container $container) {
64
- return new \WordPressPopularPosts\Rest\ThumbnailsEndpoint($container['admin_options'], $container['translate']);
 
 
 
65
  });
66
 
67
  $container['widget_endpoint'] = $container->service(function(Container $container) {
68
- return new \WordPressPopularPosts\Rest\WidgetEndpoint($container['admin_options'], $container['translate'], $container['output']);
 
 
 
 
69
  });
70
 
71
  $container['rest'] = $container->service(function(Container $container) {
72
- return new \WordPressPopularPosts\Rest\Controller($container['posts_endpoint'], $container['view_logger_endpoint'], $container['widget_endpoint'], $container['themes_endpoint'], $container['thumbnails_endpoint'], $container['taxonomies_endpoint']);
 
 
 
 
 
 
 
73
  });
74
 
75
  $container['admin'] = $container->service(function(Container $container) {
76
- return new \WordPressPopularPosts\Admin\Admin($container['admin_options'], $container['image']);
 
 
 
77
  });
78
 
79
  $container['front'] = $container->service(function(Container $container) {
80
- return new \WordPressPopularPosts\Front\Front($container['admin_options'], $container['translate'], $container['output']);
 
 
 
 
81
  });
82
 
83
  $container['wpp'] = $container->service(function(Container $container) {
84
- return new \WordPressPopularPosts\WordPressPopularPosts($container['i18n'], $container['rest'], $container['admin'], $container['front'], $container['widget'], $container['block_widget']);
 
 
 
 
 
 
 
85
  });
86
  }
87
  }
1
  <?php
2
  namespace WordPressPopularPosts\Container;
3
 
4
+ use WordPressPopularPosts\{ Image, I18N, Output, Settings, Themer, Translate, WordPressPopularPosts };
5
+ use WordPressPopularPosts\Admin\Admin;
6
+ use WordPressPopularPosts\Block\Widget\Widget as BlockWidget;
7
+ use WordPressPopularPosts\Front\Front;
8
+ use WordPressPopularPosts\Rest\{ Controller, PostsEndpoint, TaxonomiesEndpoint, ThemesEndpoint, ThumbnailsEndpoint, ViewLoggerEndpoint, WidgetEndpoint };
9
+ use WordPressPopularPosts\Widget\Widget;
10
 
11
  class WordPressPopularPostsConfiguration implements ContainerConfigurationInterface
12
  {
22
  $container['widget_options'] = Settings::get('widget_options');
23
 
24
  $container['i18n'] = $container->service(function(Container $container) {
25
+ return new I18N($container['admin_options']);
26
  });
27
 
28
  $container['translate'] = $container->service(function(Container $container) {
29
+ return new Translate();
30
  });
31
 
32
  $container['image'] = $container->service(function(Container $container) {
33
+ return new Image($container['admin_options']);
34
  });
35
 
36
  $container['themer'] = $container->service(function(Container $container) {
37
+ return new Themer();
38
  });
39
 
40
  $container['output'] = $container->service(function(Container $container) {
41
+ return new Output(
42
+ $container['widget_options'],
43
+ $container['admin_options'],
44
+ $container['image'],
45
+ $container['translate'],
46
+ $container['themer']
47
+ );
48
  });
49
 
50
  $container['widget'] = $container->service(function(Container $container) {
51
+ return new Widget(
52
+ $container['widget_options'],
53
+ $container['admin_options'],
54
+ $container['output'],
55
+ $container['image'],
56
+ $container['translate'],
57
+ $container['themer']
58
+ );
59
  });
60
 
61
  $container['block_widget'] = $container->service(function(Container $container) {
62
+ return new BlockWidget(
63
+ $container['admin_options'],
64
+ $container['output'],
65
+ $container['image'],
66
+ $container['translate'],
67
+ $container['themer']
68
+ );
69
  });
70
 
71
  $container['posts_endpoint'] = $container->service(function(Container $container) {
72
+ return new PostsEndpoint(
73
+ $container['admin_options'],
74
+ $container['translate']
75
+ );
76
  });
77
 
78
  $container['view_logger_endpoint'] = $container->service(function(Container $container) {
79
+ return new ViewLoggerEndpoint(
80
+ $container['admin_options'],
81
+ $container['translate']
82
+ );
83
  });
84
 
85
  $container['taxonomies_endpoint'] = $container->service(function(Container $container) {
86
+ return new TaxonomiesEndpoint(
87
+ $container['admin_options'],
88
+ $container['translate']
89
+ );
90
  });
91
 
92
  $container['themes_endpoint'] = $container->service(function(Container $container) {
93
+ return new ThemesEndpoint(
94
+ $container['admin_options'],
95
+ $container['translate'],
96
+ $container['themer']
97
+ );
98
  });
99
 
100
  $container['thumbnails_endpoint'] = $container->service(function(Container $container) {
101
+ return new ThumbnailsEndpoint(
102
+ $container['admin_options'],
103
+ $container['translate']
104
+ );
105
  });
106
 
107
  $container['widget_endpoint'] = $container->service(function(Container $container) {
108
+ return new WidgetEndpoint(
109
+ $container['admin_options'],
110
+ $container['translate'],
111
+ $container['output']
112
+ );
113
  });
114
 
115
  $container['rest'] = $container->service(function(Container $container) {
116
+ return new Controller(
117
+ $container['posts_endpoint'],
118
+ $container['view_logger_endpoint'],
119
+ $container['widget_endpoint'],
120
+ $container['themes_endpoint'],
121
+ $container['thumbnails_endpoint'],
122
+ $container['taxonomies_endpoint']
123
+ );
124
  });
125
 
126
  $container['admin'] = $container->service(function(Container $container) {
127
+ return new Admin(
128
+ $container['admin_options'],
129
+ $container['image']
130
+ );
131
  });
132
 
133
  $container['front'] = $container->service(function(Container $container) {
134
+ return new Front(
135
+ $container['admin_options'],
136
+ $container['translate'],
137
+ $container['output']
138
+ );
139
  });
140
 
141
  $container['wpp'] = $container->service(function(Container $container) {
142
+ return new WordPressPopularPosts(
143
+ $container['i18n'],
144
+ $container['rest'],
145
+ $container['admin'],
146
+ $container['front'],
147
+ $container['widget'],
148
+ $container['block_widget']
149
+ );
150
  });
151
  }
152
  }
src/Front/Front.php CHANGED
@@ -11,12 +11,13 @@
11
 
12
  namespace WordPressPopularPosts\Front;
13
 
14
- use WordPressPopularPosts\Helper;
15
- use WordPressPopularPosts\Output;
16
- use WordPressPopularPosts\Query;
17
 
18
  class Front {
19
 
 
 
20
  /**
21
  * Plugin options.
22
  *
@@ -47,8 +48,9 @@ class Front {
47
  * @since 5.0.0
48
  * @param array $config Admin settings.
49
  * @param \WordPressPopularPosts\Translate $translate Translate class.
 
50
  */
51
- public function __construct(array $config, \WordPressPopularPosts\Translate $translate, \WordPressPopularPosts\Output $output)
52
  {
53
  $this->config = $config;
54
  $this->translate = $translate;
@@ -145,7 +147,7 @@ class Front {
145
  * @param string $src
146
  * @return string $tag
147
  */
148
- function convert_inline_js_into_json($tag, $handle, $src)
149
  {
150
  if ( 'wpp-js' === $handle ) {
151
  // id attribute found, replace it
@@ -209,7 +211,7 @@ class Front {
209
  * @param int $post_ID
210
  * @return bool|int FALSE if query failed, TRUE on success
211
  */
212
- private function update_views_count($post_ID) {
213
  /*
214
  TODO:
215
  For WordPress Multisite, we must define the DIEONDBERROR constant for database errors to display like so:
@@ -281,7 +283,7 @@ class Front {
281
  * @param array $atts User defined attributes in shortcode tag
282
  * @return string
283
  */
284
- public function wpp_shortcode($atts = null) {
285
  /**
286
  * @var string $header
287
  * @var int $limit
@@ -367,7 +369,7 @@ class Front {
367
  'time_unit' => ( in_array($time_unit, $time_units) ) ? $time_unit : 'hour',
368
  'freshness' => empty($freshness) ? false : $freshness,
369
  'order_by' => ( in_array($order_by, $order_by_values) ) ? $order_by : 'views',
370
- 'post_type' => empty($post_type) ? 'post,page' : $post_type,
371
  'pid' => rtrim(preg_replace('|[^0-9,]|', '', $pid), ","),
372
  'cat' => rtrim(preg_replace('|[^0-9,-]|', '', $cat), ","),
373
  'taxonomy' => empty($taxonomy) ? 'category' : $taxonomy,
@@ -450,38 +452,7 @@ class Front {
450
  $shortcode_content .= htmlspecialchars_decode($header_start, ENT_QUOTES) . $header . htmlspecialchars_decode($header_end, ENT_QUOTES);
451
  }
452
 
453
- // Return cached results
454
- if ( $this->config['tools']['cache']['active'] ) {
455
-
456
- $key = md5(json_encode($shortcode_ops));
457
- $popular_posts = \WordPressPopularPosts\Cache::get($key);
458
-
459
- if ( false === $popular_posts ) {
460
- $popular_posts = new Query($shortcode_ops);
461
-
462
- $time_value = $this->config['tools']['cache']['interval']['value']; // eg. 5
463
- $time_unit = $this->config['tools']['cache']['interval']['time']; // eg. 'minute'
464
-
465
- // No popular posts found, check again in 1 minute
466
- if ( ! $popular_posts->get_posts() ) {
467
- $time_value = 1;
468
- $time_unit = 'minute';
469
- }
470
-
471
- \WordPressPopularPosts\Cache::set(
472
- $key,
473
- $popular_posts,
474
- $time_value,
475
- $time_unit
476
- );
477
- }
478
-
479
- $cached = true;
480
-
481
- } // Get popular posts
482
- else {
483
- $popular_posts = new Query($shortcode_ops);
484
- }
485
 
486
  $this->output->set_data($popular_posts->get_posts());
487
  $this->output->set_public_options($shortcode_ops);
11
 
12
  namespace WordPressPopularPosts\Front;
13
 
14
+ use WordPressPopularPosts\{ Helper, Output, Translate };
15
+ use WordPressPopularPosts\Traits\QueriesPosts;
 
16
 
17
  class Front {
18
 
19
+ use QueriesPosts;
20
+
21
  /**
22
  * Plugin options.
23
  *
48
  * @since 5.0.0
49
  * @param array $config Admin settings.
50
  * @param \WordPressPopularPosts\Translate $translate Translate class.
51
+ * @param \WordPressPopularPosts\Output $output Output class.
52
  */
53
+ public function __construct(array $config, Translate $translate, Output $output)
54
  {
55
  $this->config = $config;
56
  $this->translate = $translate;
147
  * @param string $src
148
  * @return string $tag
149
  */
150
+ function convert_inline_js_into_json(string $tag, string $handle, string $src)
151
  {
152
  if ( 'wpp-js' === $handle ) {
153
  // id attribute found, replace it
211
  * @param int $post_ID
212
  * @return bool|int FALSE if query failed, TRUE on success
213
  */
214
+ private function update_views_count(int $post_ID) {
215
  /*
216
  TODO:
217
  For WordPress Multisite, we must define the DIEONDBERROR constant for database errors to display like so:
283
  * @param array $atts User defined attributes in shortcode tag
284
  * @return string
285
  */
286
+ public function wpp_shortcode($atts = null) { /** @TODO: starting PHP 8.0 $atts can be declared as mixed $meta_value (if not set WP gives an string, and it set we get an array) */
287
  /**
288
  * @var string $header
289
  * @var int $limit
369
  'time_unit' => ( in_array($time_unit, $time_units) ) ? $time_unit : 'hour',
370
  'freshness' => empty($freshness) ? false : $freshness,
371
  'order_by' => ( in_array($order_by, $order_by_values) ) ? $order_by : 'views',
372
+ 'post_type' => empty($post_type) ? 'post' : $post_type,
373
  'pid' => rtrim(preg_replace('|[^0-9,]|', '', $pid), ","),
374
  'cat' => rtrim(preg_replace('|[^0-9,-]|', '', $cat), ","),
375
  'taxonomy' => empty($taxonomy) ? 'category' : $taxonomy,
452
  $shortcode_content .= htmlspecialchars_decode($header_start, ENT_QUOTES) . $header . htmlspecialchars_decode($header_end, ENT_QUOTES);
453
  }
454
 
455
+ $popular_posts = $this->maybe_query($shortcode_ops);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
456
 
457
  $this->output->set_data($popular_posts->get_posts());
458
  $this->output->set_public_options($shortcode_ops);
src/Helper.php CHANGED
@@ -11,7 +11,7 @@ class Helper {
11
  * @param int number
12
  * @return bool
13
  */
14
- public static function is_number($number)
15
  {
16
  return !empty($number) && is_numeric($number) && (intval($number) == floatval($number));
17
  }
@@ -25,7 +25,7 @@ class Helper {
25
  * @param int
26
  * @return mixed string|bool
27
  */
28
- public static function prettify_number($number, $precision = 1)
29
  {
30
  if ( ! is_numeric($number) )
31
  return false;
@@ -70,7 +70,7 @@ class Helper {
70
  * @param string $format
71
  * @return bool
72
  */
73
- public static function is_valid_date($date = null, $format = 'Y-m-d')
74
  {
75
  $d = \DateTime::createFromFormat($format, $date);
76
  return $d && $d->format($format) === $date;
@@ -85,7 +85,7 @@ class Helper {
85
  * @param string $format
86
  * @return array|bool
87
  */
88
- public static function get_date_range($start_date = null, $end_date = null, $format = 'Y-m-d')
89
  {
90
  if (
91
  self::is_valid_date($start_date, $format)
@@ -93,8 +93,8 @@ class Helper {
93
  ) {
94
  $dates = [];
95
 
96
- $begin = new \DateTime($start_date, new \DateTimeZone(Helper::get_timezone()));
97
- $end = new \DateTime($end_date, new \DateTimeZone(Helper::get_timezone()));
98
 
99
  if ( $begin < $end ) {
100
  while( $begin <= $end ) {
@@ -158,7 +158,7 @@ class Helper {
158
  * @param string $string
159
  * @return bool
160
  */
161
- public static function is_timestamp($string)
162
  {
163
  if (
164
  ( is_int($string) || ctype_digit($string) )
@@ -170,31 +170,6 @@ class Helper {
170
  return false;
171
  }
172
 
173
- /**
174
- * Returns site's timezone.
175
- *
176
- * Code borrowed from Rarst's awesome WpDateTime class: https://github.com/Rarst/wpdatetime
177
- *
178
- * @since 5.0.0
179
- * @return string
180
- */
181
- public static function get_timezone()
182
- {
183
- $timezone_string = get_option('timezone_string');
184
-
185
- if ( ! empty($timezone_string) ) {
186
- return $timezone_string;
187
- }
188
-
189
- $offset = get_option('gmt_offset');
190
- $sign = $offset < 0 ? '-' : '+';
191
- $hours = (int) $offset;
192
- $minutes = abs(($offset - (int) $offset) * 60);
193
- $offset = sprintf('%s%02d:%02d', $sign, abs($hours), $minutes);
194
-
195
- return $offset;
196
- }
197
-
198
  /**
199
  * Returns time.
200
  *
@@ -238,7 +213,7 @@ class Helper {
238
  * @param mixed $v variable to display with var_dump()
239
  * @param mixed $v,... unlimited optional number of variables to display with var_dump()
240
  */
241
- public static function debug($v)
242
  {
243
  if ( !defined('WPP_DEBUG') || !WPP_DEBUG )
244
  return;
@@ -259,7 +234,7 @@ class Helper {
259
  * @param bool $truncate_by_words
260
  * @return string
261
  */
262
- public static function truncate($text = '', $length = 25, $truncate_by_words = false, $more = '...')
263
  {
264
  if ( '' !== $text ) {
265
  $charset = get_bloginfo('charset');
@@ -321,7 +296,7 @@ class Helper {
321
  * @param string $scheme
322
  * @return string|bool
323
  */
324
- static function add_scheme($url = null, $scheme = 'https://')
325
  {
326
  $url_args = parse_url($url);
327
 
@@ -348,7 +323,7 @@ class Helper {
348
  * @param string
349
  * @return array|bool
350
  */
351
- static function is_image_url($url)
352
  {
353
  $path = parse_url($url, PHP_URL_PATH);
354
  $encoded_path = array_map('urlencode', explode('/', $path));
11
  * @param int number
12
  * @return bool
13
  */
14
+ public static function is_number($number) /** @TODO: starting PHP 8.0 $number can be declared as mixed $number */
15
  {
16
  return !empty($number) && is_numeric($number) && (intval($number) == floatval($number));
17
  }
25
  * @param int
26
  * @return mixed string|bool
27
  */
28
+ public static function prettify_number($number, $precision = 1) /** @TODO: starting PHP 8.0 $number can be declared as mixed $number */
29
  {
30
  if ( ! is_numeric($number) )
31
  return false;
70
  * @param string $format
71
  * @return bool
72
  */
73
+ public static function is_valid_date(?string $date, $format = 'Y-m-d')
74
  {
75
  $d = \DateTime::createFromFormat($format, $date);
76
  return $d && $d->format($format) === $date;
85
  * @param string $format
86
  * @return array|bool
87
  */
88
+ public static function get_date_range(string $start_date, string $end_date, string $format = 'Y-m-d')
89
  {
90
  if (
91
  self::is_valid_date($start_date, $format)
93
  ) {
94
  $dates = [];
95
 
96
+ $begin = new \DateTime($start_date, wp_timezone());
97
+ $end = new \DateTime($end_date, wp_timezone());
98
 
99
  if ( $begin < $end ) {
100
  while( $begin <= $end ) {
158
  * @param string $string
159
  * @return bool
160
  */
161
+ public static function is_timestamp($string) /** @TODO: starting PHP 8.0 $string can be declared as mixed $string */
162
  {
163
  if (
164
  ( is_int($string) || ctype_digit($string) )
170
  return false;
171
  }
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  /**
174
  * Returns time.
175
  *
213
  * @param mixed $v variable to display with var_dump()
214
  * @param mixed $v,... unlimited optional number of variables to display with var_dump()
215
  */
216
+ public static function debug($v) /** @TODO: remove this function, we don't use it at all */
217
  {
218
  if ( !defined('WPP_DEBUG') || !WPP_DEBUG )
219
  return;
234
  * @param bool $truncate_by_words
235
  * @return string
236
  */
237
+ public static function truncate(string $text = '', int $length = 25, bool $truncate_by_words = false, string $more = '...')
238
  {
239
  if ( '' !== $text ) {
240
  $charset = get_bloginfo('charset');
296
  * @param string $scheme
297
  * @return string|bool
298
  */
299
+ static function add_scheme(?string $url, string $scheme = 'https://')
300
  {
301
  $url_args = parse_url($url);
302
 
323
  * @param string
324
  * @return array|bool
325
  */
326
+ static function is_image_url(string $url)
327
  {
328
  $path = parse_url($url, PHP_URL_PATH);
329
  $encoded_path = array_map('urlencode', explode('/', $path));
src/Image.php CHANGED
@@ -109,7 +109,7 @@ class Image {
109
  * @param string $build Whether to build the image or get an existing one
110
  * @return string
111
  */
112
- public function get($post_id, $size, $source, $crop = true, $build = 'manual')
113
  {
114
  // Bail, $post_id is not an integer
115
  if ( ! is_numeric($post_id) ) {
@@ -194,7 +194,7 @@ class Image {
194
  ) {
195
  // Find corresponding image size
196
  $stock_size = null;
197
- $images_sizes = $this->get_sizes();
198
 
199
  foreach ( $images_sizes as $name => $attr ) :
200
  if (
@@ -337,7 +337,7 @@ class Image {
337
  * @param string $filename
338
  * @return string|bool Full URL to image
339
  */
340
- private function exists($filename)
341
  {
342
  // Do we have thumbnail already?
343
  $file = $this->resolve(trailingslashit($this->get_plugin_uploads_dir()['basedir']) . $filename);
@@ -360,7 +360,7 @@ class Image {
360
  * @param string $name
361
  * @return string|bool Resolved path, or false if not found
362
  */
363
- private function resolve($name)
364
  {
365
  $info = pathinfo($name);
366
 
@@ -409,7 +409,7 @@ class Image {
409
  * @param integer $post_ID
410
  * @return string|boolean Path to image, or false if not found
411
  */
412
- private function url_to_path($url, $post_ID = null)
413
  {
414
  if ( Helper::is_image_url($url) ) {
415
  $attachment_id = $this->get_attachment_id($url);
@@ -436,7 +436,7 @@ class Image {
436
  * @param string $source Image source
437
  * @return array|bool
438
  */
439
- private function get_file_meta($id, $source)
440
  {
441
  // get thumbnail path from the Featured Image
442
  if ( "featured" == $source ) {
@@ -518,7 +518,7 @@ class Image {
518
  * @param string $source Image source
519
  * @return string
520
  */
521
- private function get_alt_attribute($id, $source)
522
  {
523
  $alt = '';
524
 
@@ -576,7 +576,7 @@ class Image {
576
  * @param string $url
577
  * @return int|null
578
  */
579
- private function get_attachment_id($url)
580
  {
581
  $url = Helper::add_scheme(
582
  $url,
@@ -622,7 +622,7 @@ class Image {
622
  * @param string $url Image url.
623
  * @return string|bool Image path, or false on failure.
624
  */
625
- private function fetch_external_image($id, $url)
626
  {
627
  if ( ! Helper::is_image_url($url) )
628
  return false;
@@ -692,7 +692,7 @@ class Image {
692
  * @param bool $crop Whether to crop the image or not
693
  * @return string|bool Image URL on success, false on error
694
  */
695
- private function resize($path, $filename, $size, $crop = true)
696
  {
697
  $image = wp_get_image_editor($path);
698
 
@@ -761,7 +761,7 @@ class Image {
761
  * @param bool $crop Whether to crop the image or not
762
  * @return string|bool Image URL on success, false on error
763
  */
764
- private function generate_thumbnail($path, $filename, $size, $crop = true)
765
  {
766
  $image = wp_get_image_editor($path);
767
 
@@ -795,7 +795,7 @@ class Image {
795
  * @param string $src
796
  * @return string
797
  */
798
- private function get_srcset($src)
799
  {
800
  /**
801
  * Hook to enable/disable retina support.
@@ -833,7 +833,7 @@ class Image {
833
  * @param string $error Error, if the image could not be created
834
  * @return string
835
  */
836
- public function render($src, $size, $class, $alt = '', $error = null)
837
  {
838
  $img_tag = '';
839
 
@@ -864,7 +864,7 @@ class Image {
864
  * @param string $size
865
  * @return array|bool
866
  */
867
- public function get_sizes($size = '')
868
  {
869
  if ( ! is_array($this->available_sizes) || empty($this->available_sizes) ) {
870
  global $_wp_additional_image_sizes;
@@ -906,7 +906,7 @@ class Image {
906
  * @param int|null
907
  * @return string
908
  */
909
- public function get_default_url($post_ID = null)
910
  {
911
  if ( has_filter('wpp_default_thumbnail_url') ) {
912
  $default_thumbnail_url = apply_filters('wpp_default_thumbnail_url', $this->default_thumbnail, $post_ID);
109
  * @param string $build Whether to build the image or get an existing one
110
  * @return string
111
  */
112
+ public function get(int $post_id, array $size, string $source, bool $crop = true, string $build = 'manual')
113
  {
114
  // Bail, $post_id is not an integer
115
  if ( ! is_numeric($post_id) ) {
194
  ) {
195
  // Find corresponding image size
196
  $stock_size = null;
197
+ $images_sizes = $this->get_sizes(null);
198
 
199
  foreach ( $images_sizes as $name => $attr ) :
200
  if (
337
  * @param string $filename
338
  * @return string|bool Full URL to image
339
  */
340
+ private function exists(string $filename)
341
  {
342
  // Do we have thumbnail already?
343
  $file = $this->resolve(trailingslashit($this->get_plugin_uploads_dir()['basedir']) . $filename);
360
  * @param string $name
361
  * @return string|bool Resolved path, or false if not found
362
  */
363
+ private function resolve(string $name)
364
  {
365
  $info = pathinfo($name);
366
 
409
  * @param integer $post_ID
410
  * @return string|boolean Path to image, or false if not found
411
  */
412
+ private function url_to_path(string $url, ?int $post_ID)
413
  {
414
  if ( Helper::is_image_url($url) ) {
415
  $attachment_id = $this->get_attachment_id($url);
436
  * @param string $source Image source
437
  * @return array|bool
438
  */
439
+ private function get_file_meta(int $id, string $source)
440
  {
441
  // get thumbnail path from the Featured Image
442
  if ( "featured" == $source ) {
518
  * @param string $source Image source
519
  * @return string
520
  */
521
+ private function get_alt_attribute(int $id, string $source)
522
  {
523
  $alt = '';
524
 
576
  * @param string $url
577
  * @return int|null
578
  */
579
+ private function get_attachment_id(string $url)
580
  {
581
  $url = Helper::add_scheme(
582
  $url,
622
  * @param string $url Image url.
623
  * @return string|bool Image path, or false on failure.
624
  */
625
+ private function fetch_external_image(int $id, string $url)
626
  {
627
  if ( ! Helper::is_image_url($url) )
628
  return false;
692
  * @param bool $crop Whether to crop the image or not
693
  * @return string|bool Image URL on success, false on error
694
  */
695
+ private function resize(string $path, string $filename, array $size, bool $crop = true)
696
  {
697
  $image = wp_get_image_editor($path);
698
 
761
  * @param bool $crop Whether to crop the image or not
762
  * @return string|bool Image URL on success, false on error
763
  */
764
+ private function generate_thumbnail(string $path, string $filename, array $size, bool $crop = true)
765
  {
766
  $image = wp_get_image_editor($path);
767
 
795
  * @param string $src
796
  * @return string
797
  */
798
+ private function get_srcset(string $src)
799
  {
800
  /**
801
  * Hook to enable/disable retina support.
833
  * @param string $error Error, if the image could not be created
834
  * @return string
835
  */
836
+ public function render(string $src, array $size, string $class, string $alt = '', string $error = '')
837
  {
838
  $img_tag = '';
839
 
864
  * @param string $size
865
  * @return array|bool
866
  */
867
+ public function get_sizes(?string $size)
868
  {
869
  if ( ! is_array($this->available_sizes) || empty($this->available_sizes) ) {
870
  global $_wp_additional_image_sizes;
906
  * @param int|null
907
  * @return string
908
  */
909
+ public function get_default_url(?int $post_ID = null)
910
  {
911
  if ( has_filter('wpp_default_thumbnail_url') ) {
912
  $default_thumbnail_url = apply_filters('wpp_default_thumbnail_url', $this->default_thumbnail, $post_ID);
src/Output.php CHANGED
@@ -91,9 +91,9 @@ class Output {
91
  * @param array $admin_options
92
  * @param WordPressPopularPosts\Image $thumbnail
93
  * @param WordPressPopularPosts\Translate $translate
94
- * @param \WordPressPopularPosts\Themer $themer
95
  */
96
- public function __construct(array $public_options, array $admin_options, Image $thumbnail, Translate $translate, \WordPressPopularPosts\Themer $themer)
97
  {
98
  $this->public_options = $public_options;
99
  $this->admin_options = $admin_options;
@@ -181,8 +181,8 @@ class Output {
181
  ) {
182
  $this->output .= '<div class="popular-posts-sr">';
183
 
184
- if ( @file_exists(get_template_directory() . '/wordpress-popular-posts/themes/' . $this->public_options['theme']['name'] . '/style.css') ) {
185
- $theme_stylesheet = get_template_directory() . '/wordpress-popular-posts/themes/' . $this->public_options['theme']['name'] . '/style.css';
186
  } else {
187
  $theme_stylesheet = $this->themer->get_theme($this->public_options['theme']['name'])['path'] . '/style.css';
188
  }
@@ -268,7 +268,7 @@ class Output {
268
  * @param integer $position
269
  * @return string
270
  */
271
- private function render_post(\stdClass $post_object, $position = 1)
272
  {
273
  $is_single = $this->is_single();
274
  $post = '';
@@ -441,7 +441,7 @@ class Output {
441
  * @param integer $post_id
442
  * @return string
443
  */
444
- private function get_title(\stdClass $post_object, $post_id)
445
  {
446
  if ( $post_object->id != $post_id ) {
447
  $title = get_the_title($post_id);
@@ -465,7 +465,7 @@ class Output {
465
  * @param integer $post_id
466
  * @return string
467
  */
468
- private function get_permalink(\stdClass $post_object, $post_id) {
469
  if ( $post_object->id != $post_id ) {
470
  return get_permalink($post_id);
471
  }
@@ -481,7 +481,7 @@ class Output {
481
  * @param int $post_id
482
  * @return string
483
  */
484
- private function get_thumbnail($post_id)
485
  {
486
  $thumbnail = '';
487
 
@@ -510,7 +510,7 @@ class Output {
510
  * @param integer $post_id
511
  * @return string
512
  */
513
- private function get_excerpt(\stdClass $post_object, $post_id)
514
  {
515
  $excerpt = '';
516
 
@@ -631,7 +631,7 @@ class Output {
631
  * @param integer $post_id
632
  * @return string
633
  */
634
- private function get_taxonomies($post_id)
635
  {
636
  $post_tax = '';
637
 
@@ -695,7 +695,7 @@ class Output {
695
  * @param integer $post_id
696
  * @return string
697
  */
698
- private function get_author(\stdClass $post_object, $post_id)
699
  {
700
  $author = ( $this->public_options['stats_tag']['author'] )
701
  ? get_the_author_meta('display_name', $post_object->uid != $post_id ? get_post_field('post_author', $post_id) : $post_object->uid)
@@ -759,7 +759,7 @@ class Output {
759
  * @return array
760
  */
761
  //private function get_metadata(\stdClass $post_object, $post_id)
762
- private function get_metadata(\stdClass $post_object, $post_id, $date, $post_tax, $author, $pageviews, $comments)
763
  {
764
  $stats = [];
765
 
@@ -823,7 +823,7 @@ class Output {
823
  * @param bool Used to display post rating (if functionality is available)
824
  * @return string
825
  */
826
- private function format_content($string, $data, $rating) {
827
 
828
  if ( empty($string) || ( empty($data) || ! is_array($data) ) )
829
  return false;
91
  * @param array $admin_options
92
  * @param WordPressPopularPosts\Image $thumbnail
93
  * @param WordPressPopularPosts\Translate $translate
94
+ * @param WordPressPopularPosts\Themer $themer
95
  */
96
+ public function __construct(array $public_options, array $admin_options, Image $thumbnail, Translate $translate, Themer $themer)
97
  {
98
  $this->public_options = $public_options;
99
  $this->admin_options = $admin_options;
181
  ) {
182
  $this->output .= '<div class="popular-posts-sr">';
183
 
184
+ if ( @file_exists(get_stylesheet_directory() . '/wordpress-popular-posts/themes/' . $this->public_options['theme']['name'] . '/style.css') ) {
185
+ $theme_stylesheet = get_stylesheet_directory() . '/wordpress-popular-posts/themes/' . $this->public_options['theme']['name'] . '/style.css';
186
  } else {
187
  $theme_stylesheet = $this->themer->get_theme($this->public_options['theme']['name'])['path'] . '/style.css';
188
  }
268
  * @param integer $position
269
  * @return string
270
  */
271
+ private function render_post(\stdClass $post_object, int $position = 1)
272
  {
273
  $is_single = $this->is_single();
274
  $post = '';
441
  * @param integer $post_id
442
  * @return string
443
  */
444
+ private function get_title(\stdClass $post_object, int $post_id)
445
  {
446
  if ( $post_object->id != $post_id ) {
447
  $title = get_the_title($post_id);
465
  * @param integer $post_id
466
  * @return string
467
  */
468
+ private function get_permalink(\stdClass $post_object, int $post_id) {
469
  if ( $post_object->id != $post_id ) {
470
  return get_permalink($post_id);
471
  }
481
  * @param int $post_id
482
  * @return string
483
  */
484
+ private function get_thumbnail(int $post_id)
485
  {
486
  $thumbnail = '';
487
 
510
  * @param integer $post_id
511
  * @return string
512
  */
513
+ private function get_excerpt(\stdClass $post_object, int $post_id)
514
  {
515
  $excerpt = '';
516
 
631
  * @param integer $post_id
632
  * @return string
633
  */
634
+ private function get_taxonomies(int $post_id)
635
  {
636
  $post_tax = '';
637
 
695
  * @param integer $post_id
696
  * @return string
697
  */
698
+ private function get_author(\stdClass $post_object, int $post_id)
699
  {
700
  $author = ( $this->public_options['stats_tag']['author'] )
701
  ? get_the_author_meta('display_name', $post_object->uid != $post_id ? get_post_field('post_author', $post_id) : $post_object->uid)
759
  * @return array
760
  */
761
  //private function get_metadata(\stdClass $post_object, $post_id)
762
+ private function get_metadata(\stdClass $post_object, int $post_id, string $date, string $post_tax, string $author, $pageviews, int $comments) /** @TODO: starting PHP 8.0 $pageviews can be declared as mixed $pageviews */
763
  {
764
  $stats = [];
765
 
823
  * @param bool Used to display post rating (if functionality is available)
824
  * @return string
825
  */
826
+ private function format_content(string $string, array $data, bool $rating) {
827
 
828
  if ( empty($string) || ( empty($data) || ! is_array($data) ) )
829
  return false;
src/Query.php CHANGED
@@ -5,7 +5,13 @@
5
  * To use this class, you must pass it an array of parameters (mostly the same ones used with
6
  * the wpp_get_mostpopular() template tag).
7
  *
8
- * eg.: $popular_posts = new Query(['range' => 'last7days', 'order_by' => 'views', 'limit' => 5]);
 
 
 
 
 
 
9
  *
10
  * @since 4.0.0
11
  * @package WordPressPopularPosts
@@ -49,9 +55,8 @@ class Query {
49
  */
50
  public function __construct(array $options = [])
51
  {
52
- $this->options = $options;
53
- $this->build_query();
54
- $this->run_query();
55
  }
56
 
57
  /**
@@ -59,10 +64,15 @@ class Query {
59
  *
60
  * @since 5.0.0
61
  * @param array $options
 
62
  */
63
  public function set_options(array $options = [])
64
  {
65
  $this->options = $options;
 
 
 
 
66
  }
67
 
68
  /**
@@ -85,7 +95,7 @@ class Query {
85
  (array) $this->options
86
  );
87
 
88
- $now = new \DateTime(Helper::now(), new \DateTimeZone(Helper::get_timezone()));
89
  $args = [];
90
  $fields = "p.ID AS id, p.post_title AS title, p.post_author AS uid";
91
  $table = "";
@@ -489,6 +499,20 @@ class Query {
489
  }
490
  }
491
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492
  /**
493
  * Returns the query string.
494
  *
5
  * To use this class, you must pass it an array of parameters (mostly the same ones used with
6
  * the wpp_get_mostpopular() template tag).
7
  *
8
+ * eg.:
9
+ * $popular_posts = new \WordPressPopularPosts\Query([
10
+ * 'range' => 'last7days',
11
+ * 'order_by' => 'views',
12
+ * 'limit' => 5
13
+ * ]);
14
+ * var_dump( $popular_posts->get_posts() );
15
  *
16
  * @since 4.0.0
17
  * @package WordPressPopularPosts
55
  */
56
  public function __construct(array $options = [])
57
  {
58
+ $this->set_options($options)
59
+ ->execute();
 
60
  }
61
 
62
  /**
64
  *
65
  * @since 5.0.0
66
  * @param array $options
67
+ * @return WordPressPopularPosts\Query
68
  */
69
  public function set_options(array $options = [])
70
  {
71
  $this->options = $options;
72
+ // Reset posts array
73
+ $this->posts = [];
74
+
75
+ return $this;
76
  }
77
 
78
  /**
95
  (array) $this->options
96
  );
97
 
98
+ $now = new \DateTime(Helper::now(),wp_timezone());
99
  $args = [];
100
  $fields = "p.ID AS id, p.post_title AS title, p.post_author AS uid";
101
  $table = "";
499
  }
500
  }
501
 
502
+ /**
503
+ * Executes the query.
504
+ *
505
+ * @since 6.0.0
506
+ * @return WordPressPopularPosts\Query
507
+ */
508
+ public function execute()
509
+ {
510
+ $this->build_query();
511
+ $this->run_query();
512
+
513
+ return $this;
514
+ }
515
+
516
  /**
517
  * Returns the query string.
518
  *
src/Rest/Controller.php CHANGED
@@ -61,7 +61,7 @@ class Controller {
61
  * @param \WordPressPopularPosts\Rest\ThumbnailsEndpoint
62
  * @param \WordPressPopularPosts\Rest\TaxonomiesEndpoint
63
  */
64
- public function __construct(\WordPressPopularPosts\Rest\PostsEndpoint $posts_endpoint, \WordPressPopularPosts\Rest\ViewLoggerEndpoint $view_logger_endpoint, \WordPressPopularPosts\Rest\WidgetEndpoint $widget_endpoint, \WordPressPopularPosts\Rest\ThemesEndpoint $themes_endpoint, \WordPressPopularPosts\Rest\ThumbnailsEndpoint $thumbnails_endpoint, \WordPressPopularPosts\Rest\TaxonomiesEndpoint $taxonomies_endpoint)
65
  {
66
  $this->posts_endpoint = $posts_endpoint;
67
  $this->view_logger_endpoint = $view_logger_endpoint;
61
  * @param \WordPressPopularPosts\Rest\ThumbnailsEndpoint
62
  * @param \WordPressPopularPosts\Rest\TaxonomiesEndpoint
63
  */
64
+ public function __construct(PostsEndpoint $posts_endpoint, ViewLoggerEndpoint $view_logger_endpoint, WidgetEndpoint $widget_endpoint, ThemesEndpoint $themes_endpoint, ThumbnailsEndpoint $thumbnails_endpoint, TaxonomiesEndpoint $taxonomies_endpoint)
65
  {
66
  $this->posts_endpoint = $posts_endpoint;
67
  $this->view_logger_endpoint = $view_logger_endpoint;
src/Rest/Endpoint.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  namespace WordPressPopularPosts\Rest;
3
 
4
- use WordPressPopularPosts\Query;
5
 
6
  abstract class Endpoint extends \WP_REST_Controller {
7
 
@@ -26,9 +26,8 @@ abstract class Endpoint extends \WP_REST_Controller {
26
  *
27
  * @param array
28
  * @param \WordPressPopularPosts\Translate
29
- * @param \WordPressPopularPosts\Output
30
  */
31
- public function __construct(array $config, \WordPressPopularPosts\Translate $translate)
32
  {
33
  $this->config = $config;
34
  $this->translate = $translate;
@@ -41,55 +40,12 @@ abstract class Endpoint extends \WP_REST_Controller {
41
  */
42
  abstract public function register();
43
 
44
- /**
45
- * Gets Query object from cache if it exists,
46
- * otherwise a new Query object will be
47
- * instantiated and returned.
48
- *
49
- * @since 5.0.3
50
- * @param array
51
- * @return Query
52
- */
53
- protected function maybe_query(array $params)
54
- {
55
- // Return cached results
56
- if ( $this->config['tools']['cache']['active'] ) {
57
- $key = 'wpp_' . md5(json_encode($params));
58
- $query = \WordPressPopularPosts\Cache::get($key);
59
-
60
- if ( false === $query ) {
61
- $query = new Query($params);
62
-
63
- $time_value = $this->config['tools']['cache']['interval']['value'];
64
- $time_unit = $this->config['tools']['cache']['interval']['time'];
65
-
66
- // No popular posts found, check again in 1 minute
67
- if ( ! $query->get_posts() ) {
68
- $time_value = 1;
69
- $time_unit = 'minute';
70
- }
71
-
72
- \WordPressPopularPosts\Cache::set(
73
- $key,
74
- $query,
75
- $time_value,
76
- $time_unit
77
- );
78
- }
79
- } // Get real-time popular posts
80
- else {
81
- $query = new Query($params);
82
- }
83
-
84
- return $query;
85
- }
86
-
87
  /**
88
  * Sets language/locale.
89
  *
90
  * @since 5.3.0
91
  */
92
- protected function set_lang($lang)
93
  {
94
  // Multilang support
95
  if ( $lang ) {
1
  <?php
2
  namespace WordPressPopularPosts\Rest;
3
 
4
+ use WordPressPopularPosts\Translate;
5
 
6
  abstract class Endpoint extends \WP_REST_Controller {
7
 
26
  *
27
  * @param array
28
  * @param \WordPressPopularPosts\Translate
 
29
  */
30
+ public function __construct(array $config, Translate $translate)
31
  {
32
  $this->config = $config;
33
  $this->translate = $translate;
40
  */
41
  abstract public function register();
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  /**
44
  * Sets language/locale.
45
  *
46
  * @since 5.3.0
47
  */
48
+ protected function set_lang(?string $lang)
49
  {
50
  // Multilang support
51
  if ( $lang ) {
src/Rest/PostsEndpoint.php CHANGED
@@ -1,8 +1,26 @@
1
  <?php
2
  namespace WordPressPopularPosts\Rest;
3
 
 
 
 
4
  class PostsEndpoint extends Endpoint {
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  /**
7
  * Registers the endpoint(s).
8
  *
1
  <?php
2
  namespace WordPressPopularPosts\Rest;
3
 
4
+ use WordPressPopularPosts\Translate;
5
+ use WordPressPopularPosts\Traits\QueriesPosts;
6
+
7
  class PostsEndpoint extends Endpoint {
8
 
9
+ use QueriesPosts;
10
+
11
+ /**
12
+ * Initializes class.
13
+ *
14
+ * @param array
15
+ * @param \WordPressPopularPosts\Translate
16
+ * @param \WordPressPopularPosts\Output
17
+ */
18
+ public function __construct(array $config, Translate $translate)
19
+ {
20
+ $this->config = $config;
21
+ $this->translate = $translate;
22
+ }
23
+
24
  /**
25
  * Registers the endpoint(s).
26
  *
src/Rest/ThemesEndpoint.php CHANGED
@@ -1,6 +1,9 @@
1
  <?php
2
  namespace WordPressPopularPosts\Rest;
3
 
 
 
 
4
  class ThemesEndpoint extends Endpoint {
5
 
6
  /**
@@ -18,7 +21,7 @@ class ThemesEndpoint extends Endpoint {
18
  * @param \WordPressPopularPosts\Translate
19
  * @param \WordPressPopularPosts\Themer
20
  */
21
- public function __construct(array $config, \WordPressPopularPosts\Translate $translate, \WordPressPopularPosts\Themer $themer)
22
  {
23
  $this->config = $config;
24
  $this->translate = $translate;
1
  <?php
2
  namespace WordPressPopularPosts\Rest;
3
 
4
+ use WordPressPopularPosts\Themer;
5
+ use WordPressPopularPosts\Translate;
6
+
7
  class ThemesEndpoint extends Endpoint {
8
 
9
  /**
21
  * @param \WordPressPopularPosts\Translate
22
  * @param \WordPressPopularPosts\Themer
23
  */
24
+ public function __construct(array $config, Translate $translate, Themer $themer)
25
  {
26
  $this->config = $config;
27
  $this->translate = $translate;
src/Rest/ViewLoggerEndpoint.php CHANGED
@@ -57,6 +57,12 @@ class ViewLoggerEndpoint extends Endpoint {
57
  ? $sampling_rate
58
  : 1;
59
 
 
 
 
 
 
 
60
  // Allow WP themers / coders perform an action
61
  // before updating views count
62
  if ( has_action('wpp_pre_update_views') )
@@ -74,7 +80,7 @@ class ViewLoggerEndpoint extends Endpoint {
74
  && WPP_CACHE_VIEWS
75
  ) {
76
 
77
- $now_datetime = new \DateTime($now, new \DateTimeZone(Helper::get_timezone()));
78
  $timestamp = $now_datetime->getTimestamp();
79
  $date_time = $now_datetime->format('Y-m-d H:i');
80
  $date_time_with_seconds = $now_datetime->format('Y-m-d H:i:s');
@@ -103,7 +109,7 @@ class ViewLoggerEndpoint extends Endpoint {
103
  wp_cache_set('_wpp_cache', $wpp_cache, 'transient', 0);
104
 
105
  // How long has it been since the last time we saved to the database?
106
- $last_update = $now_datetime->diff(new \DateTime($wpp_cache['last_updated'], new \DateTimeZone(Helper::get_timezone())));
107
  $diff_in_minutes = $last_update->days * 24 * 60;
108
  $diff_in_minutes += $last_update->h * 60;
109
  $diff_in_minutes += $last_update->i;
57
  ? $sampling_rate
58
  : 1;
59
 
60
+ $original_views_count = $views;
61
+ $views = apply_filters('wpp_update_views_count_value', $views, $post_ID, $sampling, $sampling_rate);
62
+
63
+ if ( ! Helper::is_number($views) || $views <= 0 )
64
+ $views = $original_views_count;
65
+
66
  // Allow WP themers / coders perform an action
67
  // before updating views count
68
  if ( has_action('wpp_pre_update_views') )
80
  && WPP_CACHE_VIEWS
81
  ) {
82
 
83
+ $now_datetime = new \DateTime($now, wp_timezone());
84
  $timestamp = $now_datetime->getTimestamp();
85
  $date_time = $now_datetime->format('Y-m-d H:i');
86
  $date_time_with_seconds = $now_datetime->format('Y-m-d H:i:s');
109
  wp_cache_set('_wpp_cache', $wpp_cache, 'transient', 0);
110
 
111
  // How long has it been since the last time we saved to the database?
112
+ $last_update = $now_datetime->diff(new \DateTime($wpp_cache['last_updated'], wp_timezone()));
113
  $diff_in_minutes = $last_update->days * 24 * 60;
114
  $diff_in_minutes += $last_update->h * 60;
115
  $diff_in_minutes += $last_update->i;
src/Rest/WidgetEndpoint.php CHANGED
@@ -1,8 +1,13 @@
1
  <?php
2
  namespace WordPressPopularPosts\Rest;
3
 
 
 
 
4
  class WidgetEndpoint extends Endpoint {
5
 
 
 
6
  /**
7
  * Output object.
8
  *
@@ -18,7 +23,7 @@ class WidgetEndpoint extends Endpoint {
18
  * @param \WordPressPopularPosts\Translate
19
  * @param \WordPressPopularPosts\Output
20
  */
21
- public function __construct(array $config, \WordPressPopularPosts\Translate $translate, \WordPressPopularPosts\Output $output)
22
  {
23
  $this->config = $config;
24
  $this->translate = $translate;
1
  <?php
2
  namespace WordPressPopularPosts\Rest;
3
 
4
+ use WordPressPopularPosts\{ Output, Translate };
5
+ use WordPressPopularPosts\Traits\QueriesPosts;
6
+
7
  class WidgetEndpoint extends Endpoint {
8
 
9
+ use QueriesPosts;
10
+
11
  /**
12
  * Output object.
13
  *
23
  * @param \WordPressPopularPosts\Translate
24
  * @param \WordPressPopularPosts\Output
25
  */
26
+ public function __construct(array $config, Translate $translate, Output $output)
27
  {
28
  $this->config = $config;
29
  $this->translate = $translate;
src/Settings.php CHANGED
@@ -94,7 +94,7 @@ class Settings {
94
  'time_quantity' => 24,
95
  'order_by' => 'views',
96
  'limit' => 10,
97
- 'post_type' => 'post,page',
98
  'freshness' => false
99
  ],
100
  'tools' => [
@@ -139,7 +139,7 @@ class Settings {
139
  * @param string $option_set
140
  * @return array
141
  */
142
- public static function get($option_set = null)
143
  {
144
  $options = self::$defaults;
145
 
94
  'time_quantity' => 24,
95
  'order_by' => 'views',
96
  'limit' => 10,
97
+ 'post_type' => 'post',
98
  'freshness' => false
99
  ],
100
  'tools' => [
139
  * @param string $option_set
140
  * @return array
141
  */
142
+ public static function get(string $option_set = '')
143
  {
144
  $options = self::$defaults;
145
 
src/Themer.php CHANGED
@@ -81,7 +81,7 @@ class Themer {
81
  * @since 5.0.0
82
  * @param string $path Path to theme folder
83
  */
84
- private function load_theme($path)
85
  {
86
  $theme_folder = is_string($path) && is_dir($path) && is_readable($path) ? basename($path) : null;
87
  $theme_folder = $theme_folder ? preg_replace("/[^a-z0-9\_\-\.]/i", '', $theme_folder) : null;
@@ -126,7 +126,7 @@ class Themer {
126
  * @param string $theme
127
  * @return array|bool
128
  */
129
- public function get_theme($theme)
130
  {
131
  return isset($this->themes[$theme]) ? $this->themes[$theme] : false;
132
  }
@@ -138,7 +138,7 @@ class Themer {
138
  * @param array
139
  * @return bool
140
  */
141
- public function is_valid_config($json = [])
142
  {
143
  return is_array($json) && ! empty($json) && isset($json['name']) && isset($json['config']) && is_array($json['config']);
144
  }
81
  * @since 5.0.0
82
  * @param string $path Path to theme folder
83
  */
84
+ private function load_theme(string $path)
85
  {
86
  $theme_folder = is_string($path) && is_dir($path) && is_readable($path) ? basename($path) : null;
87
  $theme_folder = $theme_folder ? preg_replace("/[^a-z0-9\_\-\.]/i", '', $theme_folder) : null;
126
  * @param string $theme
127
  * @return array|bool
128
  */
129
+ public function get_theme(string $theme)
130
  {
131
  return isset($this->themes[$theme]) ? $this->themes[$theme] : false;
132
  }
138
  * @param array
139
  * @return bool
140
  */
141
+ public function is_valid_config(array $json)
142
  {
143
  return is_array($json) && ! empty($json) && isset($json['name']) && isset($json['config']) && is_array($json['config']);
144
  }
src/Traits/QueriesPosts.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace WordPressPopularPosts\Traits;
3
+
4
+ use WordPressPopularPosts\Query;
5
+
6
+ trait QueriesPosts
7
+ {
8
+ /**
9
+ * Query object.
10
+ *
11
+ * @since 6.0.0
12
+ * @var \WordPressPopularPosts\Query
13
+ * @access private
14
+ */
15
+ private $query;
16
+
17
+ /**
18
+ * Gets Query object from cache if it exists,
19
+ * otherwise a new Query object will be
20
+ * instantiated and returned.
21
+ *
22
+ * @since 6.0.0
23
+ * @param array
24
+ * @return Query
25
+ */
26
+ protected function maybe_query(array $params)
27
+ {
28
+ // Return cached results
29
+ if ( $this->config['tools']['cache']['active'] ) {
30
+ $key = 'wpp_' . md5(json_encode($params));
31
+ $this->query = \WordPressPopularPosts\Cache::get($key);
32
+
33
+ if ( false === $this->query ) {
34
+ $this->query = new Query($params);
35
+
36
+ $time_value = $this->config['tools']['cache']['interval']['value'];
37
+ $time_unit = $this->config['tools']['cache']['interval']['time'];
38
+
39
+ // No popular posts found, check again in 1 minute
40
+ if ( ! $this->query->get_posts() ) {
41
+ $time_value = 1;
42
+ $time_unit = 'minute';
43
+ }
44
+
45
+ \WordPressPopularPosts\Cache::set(
46
+ $key,
47
+ $this->query,
48
+ $time_value,
49
+ $time_unit
50
+ );
51
+ }
52
+ } // Get real-time popular posts
53
+ else {
54
+ $this->query = new Query($params);
55
+ }
56
+
57
+ return $this->query;
58
+ }
59
+ }
src/Translate.php CHANGED
@@ -69,9 +69,9 @@ class Translate {
69
  * Sets the code of the currently active language.
70
  *
71
  * @since 4.0.0
72
- * @return string|null
73
  */
74
- public function set_current_language($code = null)
75
  {
76
  $this->current_language = $code;
77
  }
@@ -83,7 +83,7 @@ class Translate {
83
  * @param string $lang Language code (eg. 'es')
84
  * @return string|bool
85
  */
86
- public function get_locale($lang = null)
87
  {
88
  // Polylang support
89
  if ( function_exists('PLL') ) {
@@ -111,7 +111,7 @@ class Translate {
111
  * @param string $lang_code
112
  * @return integer
113
  */
114
- public function get_object_id($object_id = null, $object_type = 'post', $return_original_if_missing = true, $lang_code = null)
115
  {
116
  return apply_filters(
117
  'wpml_object_id',
@@ -130,7 +130,7 @@ class Translate {
130
  * @param string $lang
131
  * @return string
132
  */
133
- public function url($original_permalink, $lang)
134
  {
135
  return apply_filters('wpml_permalink', $original_permalink, $lang);
136
  }
@@ -143,7 +143,7 @@ class Translate {
143
  * @param string $object_type
144
  * @return string|null
145
  */
146
- public function get_object_lang_code($object_id = null, $object_type = 'post')
147
  {
148
  return apply_filters(
149
  'wpml_element_language_code',
69
  * Sets the code of the currently active language.
70
  *
71
  * @since 4.0.0
72
+ * @return string
73
  */
74
+ public function set_current_language(string $code)
75
  {
76
  $this->current_language = $code;
77
  }
83
  * @param string $lang Language code (eg. 'es')
84
  * @return string|bool
85
  */
86
+ public function get_locale(string $lang)
87
  {
88
  // Polylang support
89
  if ( function_exists('PLL') ) {
111
  * @param string $lang_code
112
  * @return integer
113
  */
114
+ public function get_object_id(int $object_id, string $object_type = 'post', bool $return_original_if_missing = true, ?string $lang_code = '')
115
  {
116
  return apply_filters(
117
  'wpml_object_id',
130
  * @param string $lang
131
  * @return string
132
  */
133
+ public function url(string $original_permalink, ?string $lang)
134
  {
135
  return apply_filters('wpml_permalink', $original_permalink, $lang);
136
  }
143
  * @param string $object_type
144
  * @return string|null
145
  */
146
+ public function get_object_lang_code(int $object_id, string $object_type = 'post')
147
  {
148
  return apply_filters(
149
  'wpml_element_language_code',
src/Widget/Widget.php CHANGED
@@ -2,11 +2,13 @@
2
 
3
  namespace WordPressPopularPosts\Widget;
4
 
5
- use WordPressPopularPosts\Helper;
6
- use WordPressPopularPosts\Query;
7
 
8
  class Widget extends \WP_Widget {
9
 
 
 
10
  /**
11
  * Default options.
12
  *
@@ -21,7 +23,7 @@ class Widget extends \WP_Widget {
21
  * @since 2.3.3
22
  * @var array
23
  */
24
- private $admin_options = [];
25
 
26
  /**
27
  * Image object.
@@ -66,7 +68,7 @@ class Widget extends \WP_Widget {
66
  * @param \WordPressPopularPosts\Translate $translate
67
  * @param \WordPressPopularPosts\Themer $themer
68
  */
69
- public function __construct(array $options, array $config, \WordPressPopularPosts\Output $output, \WordPressPopularPosts\Image $thumbnail, \WordPressPopularPosts\Translate $translate, \WordPressPopularPosts\Themer $themer)
70
  {
71
  // Create the widget
72
  parent::__construct(
@@ -79,7 +81,7 @@ class Widget extends \WP_Widget {
79
  );
80
 
81
  $this->defaults = $options;
82
- $this->admin_options = $config;
83
  $this->output = $output;
84
  $this->thumbnail = $thumbnail;
85
  $this->translate = $translate;
@@ -159,7 +161,7 @@ class Widget extends \WP_Widget {
159
  $instance['id_base'] = $this->id_base;
160
 
161
  // Get posts
162
- if ( $this->admin_options['tools']['ajax'] && ! is_customize_preview() ) {
163
  ?>
164
  <div class="wpp-widget-placeholder" data-widget-id="<?php echo esc_attr($widget_id); ?>"></div>
165
  <?php
@@ -220,7 +222,7 @@ class Widget extends \WP_Widget {
220
  // FILTERS
221
  // user did not set a post type name, so we fall back to default
222
  $instance['post_type'] = ( '' == $new_instance['post_type'] )
223
- ? 'post,page'
224
  : $new_instance['post_type'];
225
 
226
  $instance['freshness'] = isset($new_instance['freshness']);
@@ -296,7 +298,7 @@ class Widget extends \WP_Widget {
296
 
297
  // Use predefined thumbnail sizes
298
  if ( 'predefined' == $new_instance['thumbnail-size-source'] ) {
299
- $default_thumbnail_sizes = $this->thumbnail->get_sizes();
300
  $size = $default_thumbnail_sizes[$new_instance['thumbnail-size']];
301
 
302
  $instance['thumbnail']['width'] = $size['width'];
@@ -386,46 +388,14 @@ class Widget extends \WP_Widget {
386
  *
387
  * @since 2.3.3
388
  */
389
- public function get_popular($instance = null)
390
  {
391
- if ( is_array($instance) && ! empty($instance) ) {
392
-
393
- // Return cached results
394
- if ( $this->admin_options['tools']['cache']['active'] ) {
395
-
396
- $key = md5(json_encode($instance));
397
- $popular_posts = \WordPressPopularPosts\Cache::get($key);
398
-
399
- if ( false === $popular_posts ) {
400
- $popular_posts = new Query($instance);
401
-
402
- $time_value = $this->admin_options['tools']['cache']['interval']['value']; // eg. 5
403
- $time_unit = $this->admin_options['tools']['cache']['interval']['time']; // eg. 'minute'
404
-
405
- // No popular posts found, check again in 1 minute
406
- if ( ! $popular_posts->get_posts() ) {
407
- $time_value = 1;
408
- $time_unit = 'minute';
409
- }
410
 
411
- \WordPressPopularPosts\Cache::set(
412
- $key,
413
- $popular_posts,
414
- $time_value,
415
- $time_unit
416
- );
417
- }
418
-
419
- } // Get popular posts
420
- else {
421
- $popular_posts = new Query($instance);
422
- }
423
-
424
- $this->output->set_data($popular_posts->get_posts());
425
- $this->output->set_public_options($instance);
426
- $this->output->build_output();
427
- $this->output->output();
428
- }
429
  }
430
 
431
  /**
@@ -454,7 +424,7 @@ class Widget extends \WP_Widget {
454
  * @param array
455
  * @return array
456
  */
457
- public function remove_from_legacy_widget_block($widget_types)
458
  {
459
  $widget_types[] = 'wpp';
460
  return $widget_types;
2
 
3
  namespace WordPressPopularPosts\Widget;
4
 
5
+ use WordPressPopularPosts\{ Helper, Image, Output, Themer, Translate };
6
+ use WordPressPopularPosts\Traits\QueriesPosts;
7
 
8
  class Widget extends \WP_Widget {
9
 
10
+ use QueriesPosts;
11
+
12
  /**
13
  * Default options.
14
  *
23
  * @since 2.3.3
24
  * @var array
25
  */
26
+ private $config = [];
27
 
28
  /**
29
  * Image object.
68
  * @param \WordPressPopularPosts\Translate $translate
69
  * @param \WordPressPopularPosts\Themer $themer
70
  */
71
+ public function __construct(array $options, array $config, Output $output, Image $thumbnail, Translate $translate, Themer $themer)
72
  {
73
  // Create the widget
74
  parent::__construct(
81
  );
82
 
83
  $this->defaults = $options;
84
+ $this->config = $config;
85
  $this->output = $output;
86
  $this->thumbnail = $thumbnail;
87
  $this->translate = $translate;
161
  $instance['id_base'] = $this->id_base;
162
 
163
  // Get posts
164
+ if ( $this->config['tools']['ajax'] && ! is_customize_preview() ) {
165
  ?>
166
  <div class="wpp-widget-placeholder" data-widget-id="<?php echo esc_attr($widget_id); ?>"></div>
167
  <?php
222
  // FILTERS
223
  // user did not set a post type name, so we fall back to default
224
  $instance['post_type'] = ( '' == $new_instance['post_type'] )
225
+ ? 'post'
226
  : $new_instance['post_type'];
227
 
228
  $instance['freshness'] = isset($new_instance['freshness']);
298
 
299
  // Use predefined thumbnail sizes
300
  if ( 'predefined' == $new_instance['thumbnail-size-source'] ) {
301
+ $default_thumbnail_sizes = $this->thumbnail->get_sizes(null);
302
  $size = $default_thumbnail_sizes[$new_instance['thumbnail-size']];
303
 
304
  $instance['thumbnail']['width'] = $size['width'];
388
  *
389
  * @since 2.3.3
390
  */
391
+ public function get_popular(array $instance)
392
  {
393
+ $popular_posts = $this->maybe_query($instance);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
 
395
+ $this->output->set_data($popular_posts->get_posts());
396
+ $this->output->set_public_options($instance);
397
+ $this->output->build_output();
398
+ $this->output->output();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  }
400
 
401
  /**
424
  * @param array
425
  * @return array
426
  */
427
+ public function remove_from_legacy_widget_block(array $widget_types)
428
  {
429
  $widget_types[] = 'wpp';
430
  return $widget_types;
src/Widget/form.php CHANGED
@@ -123,7 +123,7 @@ if ( $taxonomies = get_taxonomies(['public' => true], 'objects') ) {
123
 
124
  <select id="<?php echo $this->get_field_id('thumbnail-size'); ?>" name="<?php echo $this->get_field_name('thumbnail-size'); ?>" class="widefat" style="margin:5px 0;">
125
  <?php
126
- foreach ( $this->thumbnail->get_sizes() as $name => $attr ) :
127
  echo '<option value="' . $name . '"' . ( ($instance['thumbnail']['build'] == 'predefined' && $attr['width'] == $instance['thumbnail']['width'] && $attr['height'] == $instance['thumbnail']['height'] ) ? ' selected="selected"' : '') . '>' . $name . ' (' . $attr['width'] . ' x ' . $attr['height'] . ( $attr['crop'] ? ', hard crop' : ', soft crop') . ')</option>';
128
  endforeach;
129
  ?>
123
 
124
  <select id="<?php echo $this->get_field_id('thumbnail-size'); ?>" name="<?php echo $this->get_field_name('thumbnail-size'); ?>" class="widefat" style="margin:5px 0;">
125
  <?php
126
+ foreach ( $this->thumbnail->get_sizes(null) as $name => $attr ) :
127
  echo '<option value="' . $name . '"' . ( ($instance['thumbnail']['build'] == 'predefined' && $attr['width'] == $instance['thumbnail']['width'] && $attr['height'] == $instance['thumbnail']['height'] ) ? ' selected="selected"' : '') . '>' . $name . ' (' . $attr['width'] . ' x ' . $attr['height'] . ( $attr['crop'] ? ', hard crop' : ', soft crop') . ')</option>';
128
  endforeach;
129
  ?>
src/deprecated.php CHANGED
@@ -3,43 +3,6 @@
3
  * Deprecated functions.
4
  */
5
 
6
- /**
7
- * Template tag - gets popular posts. Deprecated in 2.0.3, use wpp_get_mostpopular instead.
8
- *
9
- * @since 1.0
10
- * @param mixed $args
11
- */
12
- function get_mostpopular($args = NULL) {
13
- trigger_error( 'The get_mostpopular() template tag has been deprecated since 2.0.3. Please use wpp_get_mostpopular() instead.', E_USER_WARNING );
14
- }
15
-
16
  /**
17
  * Deprecated classes.
18
  */
19
-
20
- /**
21
- * Queries the database for popular posts. Deprecated since 5.0.0, use \WordPressPopularPosts\Query instead.
22
- *
23
- * To use this class, you must pass it an array of parameters (mostly the same ones used with
24
- * the wpp_get_mostpopular() template tag). The very minimum required parameters are 'range', 'order_by'
25
- * and 'limit'.
26
- *
27
- * eg.: $popular_posts = new WPP_Query( array('range' => 'last7days', 'order_by' => 'views', 'limit' => 5) );
28
- *
29
- * @since 4.0.0
30
- * @package WordPressPopularPosts
31
- */
32
-
33
- class WPP_Query extends \WordPressPopularPosts\Query {
34
- /**
35
- * Constructor.
36
- *
37
- * @since 4.0.0
38
- * @param array $options
39
- */
40
- public function __construct(array $options = [])
41
- {
42
- parent::__construct($options);
43
- trigger_error('The WPP_Query class has been deprecated since 5.0.0. Please use \WordPressPopularPosts\Query instead.', E_USER_NOTICE);
44
- }
45
- }
3
  * Deprecated functions.
4
  */
5
 
 
 
 
 
 
 
 
 
 
 
6
  /**
7
  * Deprecated classes.
8
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/template-tags.php CHANGED
@@ -13,7 +13,7 @@
13
  * @param bool $number_format Whether to format the number (eg. 9,999) or not (eg. 9999)
14
  * @return string
15
  */
16
- function wpp_get_views($id = NULL, $range = NULL, $number_format = true)
17
  {
18
  // have we got an id?
19
  if ( empty($id) || is_null($id) || ! is_numeric($id) )
@@ -47,7 +47,7 @@ function wpp_get_views($id = NULL, $range = NULL, $number_format = true)
47
  else {
48
  $start_date = new \DateTime(
49
  \WordPressPopularPosts\Helper::now(),
50
- new \DateTimeZone(\WordPressPopularPosts\Helper::get_timezone())
51
  );
52
 
53
  // Determine time range
@@ -141,7 +141,7 @@ function wpp_get_views($id = NULL, $range = NULL, $number_format = true)
141
  * @since 2.0.3
142
  * @param mixed $args
143
  */
144
- function wpp_get_mostpopular($args = NULL)
145
  {
146
  $shortcode = '[wpp';
147
 
13
  * @param bool $number_format Whether to format the number (eg. 9,999) or not (eg. 9999)
14
  * @return string
15
  */
16
+ function wpp_get_views(int $id = NULL, $range = NULL, bool $number_format = true) /** @TODO: starting PHP 8.0 $range can be declared as mixed $range */
17
  {
18
  // have we got an id?
19
  if ( empty($id) || is_null($id) || ! is_numeric($id) )
47
  else {
48
  $start_date = new \DateTime(
49
  \WordPressPopularPosts\Helper::now(),
50
+ wp_timezone()
51
  );
52
 
53
  // Determine time range
141
  * @since 2.0.3
142
  * @param mixed $args
143
  */
144
+ function wpp_get_mostpopular($args = NULL) /** @TODO: starting PHP 8.0 $args can be declared as mixed $args */
145
  {
146
  $shortcode = '[wpp';
147
 
uninstall.php CHANGED
@@ -6,7 +6,7 @@
6
  * @author Hector Cabrera <me@cabrerahector.com>
7
  * @license GPL-2.0+
8
  * @link https://cabrerahector.com
9
- * @copyright 2008-2021 Hector Cabrera
10
  */
11
 
12
  // If uninstall is not called from WordPress, exit
6
  * @author Hector Cabrera <me@cabrerahector.com>
7
  * @license GPL-2.0+
8
  * @link https://cabrerahector.com
9
+ * @copyright 2008-2022 Hector Cabrera
10
  */
11
 
12
  // If uninstall is not called from WordPress, exit
wordpress-popular-posts.php CHANGED
@@ -16,7 +16,9 @@
16
  * Plugin Name: WordPress Popular Posts
17
  * Plugin URI: https://wordpress.org/plugins/wordpress-popular-posts/
18
  * Description: A highly customizable widget that displays the most popular posts on your blog.
19
- * Version: 5.5.1
 
 
20
  * Author: Hector Cabrera
21
  * Author URI: https://cabrerahector.com/
22
  * License: GPL-2.0+
@@ -29,32 +31,8 @@ if ( ! defined( 'WPINC' ) ) {
29
  die();
30
  }
31
 
32
- define('WPP_VERSION', '5.5.1');
33
- define('WPP_MIN_PHP_VERSION', '5.4');
34
- define('WPP_MIN_WP_VERSION', '4.9');
35
 
36
- /** Requirements check */
37
- global $wp_version;
38
-
39
- // We're good, continue!
40
- if ( version_compare(PHP_VERSION, WPP_MIN_PHP_VERSION, '>=') && version_compare($wp_version, WPP_MIN_WP_VERSION, '>=') ) {
41
- $wpp_main_plugin_file = __FILE__;
42
- // Load plugin bootstrap
43
- require __DIR__ . '/src/Bootstrap.php';
44
- } // Nope.
45
- else {
46
- if ( isset($_GET['activate']) )
47
- unset($_GET['activate']);
48
-
49
- function wpp_render_min_requirements_notice() {
50
- global $wp_version;
51
- echo '<div class="notice notice-error"><p>' . sprintf(
52
- __('WordPress Popular Posts requires at least PHP %1$s and WordPress %2$s to function correctly. Your site uses PHP %3$s and WordPress %4$s.', 'wordpress-popular-posts'),
53
- WPP_MIN_PHP_VERSION,
54
- WPP_MIN_WP_VERSION,
55
- PHP_VERSION,
56
- $wp_version
57
- ) . '</p></div>';
58
- }
59
- add_action('admin_notices', 'wpp_render_min_requirements_notice');
60
- }
16
  * Plugin Name: WordPress Popular Posts
17
  * Plugin URI: https://wordpress.org/plugins/wordpress-popular-posts/
18
  * Description: A highly customizable widget that displays the most popular posts on your blog.
19
+ * Version: 6.0.0
20
+ * Requires at least: 5.3
21
+ * Requires PHP: 7.2
22
  * Author: Hector Cabrera
23
  * Author URI: https://cabrerahector.com/
24
  * License: GPL-2.0+
31
  die();
32
  }
33
 
34
+ define('WPP_VERSION', '6.0.0');
 
 
35
 
36
+ $wpp_main_plugin_file = __FILE__;
37
+ // Load plugin bootstrap
38
+ require __DIR__ . '/src/Bootstrap.php';