| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Contains core logic for the widget | |
| 4 | - * | |
| 3 | +* Contains the widget admin and its registration | |
| 4 | +* | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | if( ! defined( 'ABSPATH' ) ) exit; |
| 8 | 8 | |
| @@ -9,14 +9,16 @@ | ||
| 9 | 9 | class SRR_Widget{ |
| 10 | 10 | |
| 11 | 11 | public static function init(){ |
| 12 | 12 | |
| 13 | - add_action( 'widgets_init', array( __class__, 'init_widget' ) ); | |
| 13 | + add_action( 'widgets_init', array( __CLASS__, 'init_widget' ) ); | |
| 14 | 14 | |
| 15 | - add_action( 'wp_enqueue_scripts', array( __class__, 'public_scripts' ) ); | |
| 15 | + add_action( 'wp_enqueue_scripts', array( __CLASS__, 'public_scripts' ) ); | |
| 16 | 16 | |
| 17 | - add_action( 'admin_enqueue_scripts', array( __class__, 'admin_scripts' ) ); | |
| 17 | + add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_scripts' ) ); | |
| 18 | 18 | |
| 19 | + add_filter( 'plugin_action_links_' . SRR_BASE_NAME, array( __CLASS__, 'action_links' ) ); | |
| 20 | + | |
| 19 | 21 | } |
| 20 | 22 | |
| 21 | 23 | public static function init_widget(){ |
| 22 | 24 | |
| @@ -25,258 +27,34 @@ | ||
| 25 | 27 | } |
| 26 | 28 | |
| 27 | 29 | public static function public_scripts(){ |
| 28 | 30 | |
| 29 | - wp_enqueue_script( 'jquery-easy-ticker-js', SRR_URL . 'public/js/jquery.easy-ticker.min.js', array( 'jquery', 'super-rss-reader-js' ), SRR_VERSION ); | |
| 30 | - wp_enqueue_script( 'super-rss-reader-js', SRR_URL . 'public/js/script.min.js', array( 'jquery' ), SRR_VERSION ); | |
| 31 | - wp_enqueue_style( 'super-rss-reader-css', SRR_URL . 'public/css/style.min.css', array(), SRR_VERSION ); | |
| 31 | + wp_enqueue_script( 'jquery-easy-ticker', SRR_URL . 'public/js/jquery.easy-ticker.min.js', array( 'jquery' ), SRR_VERSION ); | |
| 32 | + wp_enqueue_script( 'super-rss-reader', SRR_URL . 'public/js/script.min.js', array( 'jquery' ), SRR_VERSION ); | |
| 32 | 33 | |
| 34 | + wp_enqueue_style( 'super-rss-reader', SRR_URL . 'public/css/style.min.css', array(), SRR_VERSION ); | |
| 35 | + | |
| 33 | 36 | } |
| 34 | 37 | |
| 35 | 38 | public static function admin_scripts( $hook ){ |
| 36 | 39 | |
| 37 | 40 | if( $hook == 'widgets.php' ){ |
| 38 | - wp_enqueue_style( 'srr_admin_css', SRR_URL . 'admin/css/style.css' ); | |
| 39 | - wp_enqueue_script( 'srr_admin_js', SRR_URL . 'admin/js/script.js' ); | |
| 41 | + wp_enqueue_style( 'srr_admin_css', SRR_URL . 'admin/css/style-widget.css', array(), SRR_VERSION ); | |
| 42 | + wp_enqueue_script( 'srr_admin_js', SRR_URL . 'admin/js/script-widget.js', array( 'jquery' ), SRR_VERSION ); | |
| 40 | 43 | } |
| 41 | 44 | |
| 42 | 45 | } |
| 43 | 46 | |
| 44 | - public static function default_settings(){ | |
| 45 | - return array( | |
| 46 | - 'title' => '', | |
| 47 | - 'urls' => '', | |
| 48 | - 'tab_titles' => '', | |
| 49 | - 'count' => 5, | |
| 50 | - 'show_date' => 0, | |
| 51 | - 'show_desc' => 1, | |
| 52 | - 'show_author' => 0, | |
| 53 | - 'show_thumb' => 1, | |
| 54 | - 'open_newtab' => 1, | |
| 55 | - 'strip_desc' => 100, | |
| 56 | - 'add_nofollow' => 1, | |
| 57 | - 'read_more' => '[...]', | |
| 58 | - 'rich_desc' => 0 , | |
| 59 | - 'color_style' => 'none', | |
| 60 | - 'enable_ticker' => 1, | |
| 61 | - 'visible_items' => 5, | |
| 62 | - 'strip_title' => 0, | |
| 63 | - 'ticker_speed' => 4, | |
| 64 | - ); | |
| 65 | - } | |
| 47 | + public static function render_feed( $options ){ | |
| 66 | 48 | |
| 67 | - public static function color_themes(){ | |
| 68 | - return array( | |
| 69 | - 'No style' => 'none', | |
| 70 | - 'Grey' => 'grey', | |
| 71 | - 'Dark' => 'dark', | |
| 72 | - 'Orange' => 'orange', | |
| 73 | - 'Simple modern' => 'smodern' | |
| 74 | - ); | |
| 49 | + $feed = new SRR_Feed( $options ); | |
| 50 | + echo $feed->html(); | |
| 51 | + | |
| 75 | 52 | } |
| 76 | 53 | |
| 77 | - public static function render_feed( $settings ){ | |
| 78 | - | |
| 79 | - $settings = wp_parse_args( $settings, self::default_settings() ); | |
| 80 | - | |
| 81 | - $urls = stripslashes( $settings['urls'] ); | |
| 82 | - $tab_titles = stripslashes( $settings['tab_titles'] ); | |
| 83 | - $count = intval( $settings['count'] ); | |
| 84 | - | |
| 85 | - $show_date = intval( $settings['show_date'] ); | |
| 86 | - $show_desc = intval( $settings['show_desc'] ); | |
| 87 | - $show_author = intval( $settings['show_author'] ); | |
| 88 | - $show_thumb = stripslashes( $settings['show_thumb'] ); | |
| 89 | - $open_newtab = intval( $settings['open_newtab'] ); | |
| 90 | - $add_nofollow = intval( $settings['add_nofollow'] ); | |
| 91 | - $strip_desc = intval( $settings['strip_desc'] ); | |
| 92 | - $strip_title = intval( $settings['strip_title'] ); | |
| 93 | - $read_more = htmlspecialchars( $settings['read_more'] ); | |
| 94 | - $rich_desc = intval( $settings['rich_desc'] ); | |
| 95 | - | |
| 96 | - $color_theme = stripslashes( $settings['color_style'] ); | |
| 97 | - $enable_ticker = intval( $settings['enable_ticker'] ); | |
| 98 | - $visible_items = intval( $settings['visible_items'] ); | |
| 99 | - $ticker_speed = intval( $settings['ticker_speed'] ) * 1000; | |
| 100 | - | |
| 101 | - if( empty( $urls ) ){ | |
| 102 | - return ''; | |
| 103 | - } | |
| 104 | - | |
| 105 | - $url_delim = strpos( $urls, ',' ) !== false ? ',' : "\n"; | |
| 106 | - $tab_title_delim = strpos( $tab_titles, ',' ) !== false ? ',' : "\n"; | |
| 107 | - | |
| 108 | - $rand = array(); | |
| 109 | - $url = explode( $url_delim, $urls ); | |
| 110 | - $tab_title = explode( $tab_title_delim, $tab_titles ); | |
| 111 | - $url_count = count( $url ); | |
| 112 | - | |
| 113 | - // Generating the tabs | |
| 114 | - if( $url_count > 1 ){ | |
| 115 | - echo '<ul class="srr-tab-wrap srr-tab-style-' . $color_theme . ' srr-clearfix">'; | |
| 116 | - for( $i=0; $i < $url_count; $i++ ){ | |
| 117 | - | |
| 118 | - // Get the Feed URL | |
| 119 | - $feed_url = trim( $url[$i] ); | |
| 120 | - $rss = fetch_feed( $feed_url ); | |
| 121 | - $rand[$i] = rand(100, 999); | |
| 122 | - | |
| 123 | - if( !is_wp_error( $rss ) ){ | |
| 124 | - | |
| 125 | - if( isset( $tab_title[$i] ) && !empty( $tab_title[$i] ) ){ | |
| 126 | - $rss_title = $tab_title[$i]; | |
| 127 | - }else{ | |
| 128 | - $rss_title = esc_attr( strip_tags( $rss->get_title() ) ); | |
| 129 | - } | |
| 130 | - | |
| 131 | - echo '<li data-tab="srr-tab-' . $rand[$i] . '">' . $rss_title . '</li>'; | |
| 132 | - }else{ | |
| 133 | - echo '<li data-tab="srr-tab-' . $rand[$i] . '">Error</li>'; | |
| 134 | - } | |
| 135 | - | |
| 136 | - } | |
| 137 | - echo '</ul>'; | |
| 138 | - } | |
| 139 | - | |
| 140 | - // Generating the feed items | |
| 141 | - for( $i=0; $i < $url_count; $i++ ){ | |
| 142 | - | |
| 143 | - // Get the Feed URL | |
| 144 | - $feed_url = trim( $url[$i] ); | |
| 145 | - if( isset( $url[$i] ) ){ | |
| 146 | - $rss = fetch_feed( $feed_url ); | |
| 147 | - }else{ | |
| 148 | - return ''; | |
| 149 | - } | |
| 150 | - | |
| 151 | - if( method_exists( $rss, 'enable_order_by_date' ) ){ | |
| 152 | - $rss->enable_order_by_date( false ); | |
| 153 | - } | |
| 154 | - | |
| 155 | - // Check for feed errors | |
| 156 | - if (!is_wp_error( $rss ) ){ | |
| 157 | - $max_items = $rss->get_item_quantity( $count ); | |
| 158 | - $rss_items = $rss->get_items( 0, $max_items ); | |
| 159 | - $rss_title = esc_attr( strip_tags( $rss->get_title() ) ); | |
| 160 | - $rss_desc = esc_attr( strip_tags( $rss->get_description() ) ); | |
| 161 | - }else{ | |
| 162 | - echo '<div class="srr-wrap srr-style-' . $color_theme .'" data-id="srr-tab-' . $rand[$i] . '"><p>RSS Error: ' . $rss->get_error_message() . '</p></div>'; | |
| 163 | - continue; | |
| 164 | - } | |
| 165 | - | |
| 166 | - $randAttr = isset($rand[$i]) ? ' data-id="srr-tab-' . $rand[$i] . '" ' : ''; | |
| 167 | - | |
| 168 | - // Outer Wrap start | |
| 169 | - echo '<div class="srr-wrap ' . (($enable_ticker == 1 ) ? 'srr-vticker' : '' ) . ' srr-style-' . $color_theme . '" data-visible="' . $visible_items . '" data-speed="' . $ticker_speed . '"' . $randAttr . '><div>'; | |
| 170 | - | |
| 171 | - // Check feed items | |
| 172 | - if ($max_items == 0){ | |
| 173 | - echo '<div>No items.</div>'; | |
| 174 | - }else{ | |
| 175 | - $j=1; | |
| 176 | - // Loop through each feed item | |
| 177 | - foreach ($rss_items as $item){ | |
| 178 | - | |
| 179 | - // Getting link | |
| 180 | - $link = $item->get_link(); | |
| 181 | - while ( stristr( $link, 'http' ) != $link ){ $link = substr( $link, 1 ); } | |
| 182 | - $link = esc_url(strip_tags($link)); | |
| 183 | - | |
| 184 | - // Getting title | |
| 185 | - $title = esc_attr(strip_tags($item->get_title())); | |
| 186 | - if ( empty($title) ) | |
| 187 | - $title = __('No Title'); | |
| 188 | - | |
| 189 | - if( $strip_title != 0 ){ | |
| 190 | - $titleLen = strlen($title); | |
| 191 | - $title = wp_html_excerpt( $title, $strip_title ); | |
| 192 | - $title = ($titleLen > $strip_title) ? $title . ' ...' : $title; | |
| 193 | - } | |
| 194 | - | |
| 195 | - // Open links in new tab | |
| 196 | - $new_tab = ($open_newtab) ? ' target="_blank"' : ''; | |
| 197 | - | |
| 198 | - // Add no follow attribute | |
| 199 | - $no_follow = ($add_nofollow) ? ' rel="nofollow"' : ''; | |
| 200 | - | |
| 201 | - // Getting date | |
| 202 | - $date = $item->get_date('j F Y'); | |
| 203 | - | |
| 204 | - // Getting thumbnail if present @since v2.2 | |
| 205 | - $thumb = ''; | |
| 206 | - if ($show_thumb == 1 && $enclosure = $item->get_enclosure()){ | |
| 207 | - $thumb_url = $enclosure->get_thumbnail(); | |
| 208 | - if(!empty($thumb_url)) | |
| 209 | - $thumb = '<img src="' . $thumb_url . '" alt="' . $title . '" class="srr-thumb" align="left"/>'; | |
| 210 | - } | |
| 211 | - | |
| 212 | - // Getting description | |
| 213 | - $desc = ''; | |
| 214 | - if( $rich_desc == 1 ){ | |
| 215 | - $desc = strip_tags( str_replace( 'eval', '', $item->get_description() ) , '<p><a><img><em><strong><font><strike><s><u><i>'); | |
| 216 | - | |
| 217 | - }else{ | |
| 218 | - $read_more = ''; | |
| 219 | - $desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) ); | |
| 220 | - if($strip_desc != 0){ | |
| 221 | - $desc = wp_html_excerpt( $desc, $strip_desc ); | |
| 222 | - $read_more = ( !empty( $read_more ) ) ? '<a href="' . $link . '" title="Read more"' . $new_tab . $no_follow . '>' . $read_more . '</a>' : ''; | |
| 223 | - | |
| 224 | - if ( '[...]' == substr( $desc, -5 ) ) | |
| 225 | - $desc = substr( $desc, 0, -5 ); | |
| 226 | - elseif ( '[…]' != substr( $desc, -10 ) ) | |
| 227 | - $desc .= ''; | |
| 228 | - | |
| 229 | - $desc = esc_html( $desc ); | |
| 230 | - } | |
| 231 | - | |
| 232 | - $desc = $thumb . $desc . ' ' . $read_more; | |
| 233 | - | |
| 234 | - } | |
| 235 | - | |
| 236 | - // Getting the author | |
| 237 | - $author = $item->get_author(); | |
| 238 | - if ( is_object($author) ) { | |
| 239 | - $author = $author->get_name(); | |
| 240 | - $author = esc_html(strip_tags($author)); | |
| 241 | - } | |
| 242 | - | |
| 243 | - echo "\n\t"; | |
| 244 | - | |
| 245 | - // Display the feed items | |
| 246 | - echo '<div class="srr-item ' . (($j%2 == 0) ? 'even' : 'odd') . '">'; | |
| 247 | - echo '<div class="srr-title"><a href="' . $link . '"' . $new_tab . $no_follow . ' title="Posted on ' . $date . '">' . $title . '</a></div>'; | |
| 248 | - echo '<div class="srr-meta">'; | |
| 249 | - | |
| 250 | - if($show_date && !empty($date)) | |
| 251 | - echo '<time class="srr-date">' . $date . '</time>'; | |
| 252 | - | |
| 253 | - if($show_author && !empty($author)) | |
| 254 | - echo ' - <cite class="srr-author">' . $author . '</cite>'; | |
| 255 | - | |
| 256 | - echo '</div>'; | |
| 257 | - | |
| 258 | - if($show_desc) | |
| 259 | - echo '<p class="srr-summary srr-clearfix">' . $desc . '</p>'; | |
| 260 | - | |
| 261 | - echo '</div>'; | |
| 262 | - // End display | |
| 263 | - | |
| 264 | - $j++; | |
| 265 | - } | |
| 266 | - } | |
| 267 | - | |
| 268 | - // Outer wrap end | |
| 269 | - echo "\n\n</div> | |
| 270 | - </div>\n\n" ; | |
| 271 | - | |
| 272 | - if ( !is_wp_error($rss) ) | |
| 273 | - $rss->__destruct(); | |
| 274 | - | |
| 275 | - unset($rss); | |
| 276 | - | |
| 277 | - } | |
| 278 | - | |
| 54 | + public static function action_links( $links ){ | |
| 55 | + array_unshift( $links, '<a href="https://www.aakashweb.com/wordpress-plugins/super-rss-reader/?utm_source=admin&utm_medium=plugin-list&utm_campaign=srr-pro" target="_blank"><b>' . esc_html__( 'Upgrade to PRO', 'super-rss-reader' ) . '</b></a>' ); | |
| 56 | + return $links; | |
| 279 | 57 | } |
| 280 | 58 | |
| 281 | 59 | } |
| 282 | 60 | |