| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * Plugin Name: News Announcement Scroll |
|---|
| 4 | * Plugin URI: https://www.storeapps.org/product/news-announcement-scroll/ |
|---|
| 5 | * Description: A simple vertical scroll news widget for your WordPress website. Easy to use & no coding knowledge required. |
|---|
| 6 | * Version: 9.0.0 |
|---|
| 7 | * Author: StoreApps |
|---|
| 8 | * Author URI: https://www.storeapps.org/ |
|---|
| 9 | * Developer: StoreApps |
|---|
| 10 | * Developer URI: https://www.storeapps.org/ |
|---|
| 11 | * Requires at least: 3.4 |
|---|
| 12 | * Tested up to: 5.5.3 |
|---|
| 13 | * Text Domain: news-announcement-scroll |
|---|
| 14 | * Domain Path: /languages/ |
|---|
| 15 | * License: GNU General Public License v3.0 |
|---|
| 16 | * License URI: http://www.gnu.org/licenses/gpl-3.0.html |
|---|
| 17 | * Copyright (c) 2015-2022 StoreApps. All rights reserved. |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | defined( 'ABSPATH' ) || exit; |
|---|
| 21 | |
|---|
| 22 | if ( preg_match( '#' . basename( __FILE__ ) . '#', $_SERVER['PHP_SELF'] ) ) { |
|---|
| 23 | die( 'You are not allowed to call this page directly.' ); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | global $wpdb, $wp_version, $gNews_db_version; |
|---|
| 27 | $gNews_db_version = '8.2'; |
|---|
| 28 | |
|---|
| 29 | define( 'WP_G_NEWS_ANNOUNCEMENT', $wpdb->prefix . 'news_announcement' ); |
|---|
| 30 | define( 'WP_G_NEWS_HELP', 'https://wordpress.org/plugins/news-announcement-scroll/faq/' ); |
|---|
| 31 | |
|---|
| 32 | if ( ! defined( 'WP_G_NEWS_BASENAME' ) ) { |
|---|
| 33 | define( 'WP_G_NEWS_BASENAME', plugin_basename( __FILE__ ) ); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | if ( ! defined( 'WP_G_NEWS_PLUGIN_NAME' ) ) { |
|---|
| 37 | define( 'WP_G_NEWS_PLUGIN_NAME', trim( dirname( WP_G_NEWS_BASENAME ), '/' ) ); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | if ( ! defined( 'WP_G_NEWS_PLUGIN_URL' ) ) { |
|---|
| 41 | define( 'WP_G_NEWS_PLUGIN_URL', WP_PLUGIN_URL . '/' . WP_G_NEWS_PLUGIN_NAME ); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | if ( ! defined( 'WP_G_NEWS_ADMIN_URL' ) ) { |
|---|
| 45 | define( 'WP_G_NEWS_ADMIN_URL', get_option( 'siteurl' ) . '/wp-admin/options-general.php?page=news-announcement-scroll' ); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | if ( ! defined( 'NAS_OFFICIAL' ) ) { |
|---|
| 49 | define( 'NAS_OFFICIAL', 'If you like <strong>News Announcement Sroll</strong>, please consider leaving us a <a target="_blank" href="https://wordpress.org/support/plugin/news-announcement-scroll/reviews/?filter=5#new-post">★★★★★</a> rating. A huge thank you from StoreApps in advance!' ); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if ( ! defined( 'NAS_URL' ) ) { |
|---|
| 53 | define( 'NAS_URL', plugins_url() . '/' . strtolower( 'news-announcement-scroll' ) . '/' ); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | if ( ! defined( 'NAS_DONATE_URL' ) ) { |
|---|
| 57 | define( 'NAS_DONATE_URL', 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CPTHCDC382KVA' ); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | function news_announcement() { |
|---|
| 62 | wp_register_script( 'nas_gannounce', NAS_URL . 'gAnnounce/gAnnounce.js', array( 'jquery' ) ); |
|---|
| 63 | wp_enqueue_script( 'nas_gannounce' ); |
|---|
| 64 | |
|---|
| 65 | include_once 'gAnnounce/gAnnounce.php'; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | function news_announcement_activation() { |
|---|
| 69 | global $wpdb, $gNews_db_version; |
|---|
| 70 | $gNews_pluginversion = ''; |
|---|
| 71 | $gNews_tableexists = 'YES'; |
|---|
| 72 | $gNews_pluginversion = get_option( 'gNews_pluginversion' ); |
|---|
| 73 | |
|---|
| 74 | if ( $wpdb->get_var( "show tables like '" . WP_G_NEWS_ANNOUNCEMENT . "'" ) != WP_G_NEWS_ANNOUNCEMENT ) { |
|---|
| 75 | $gNews_tableexists = 'NO'; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | if ( ( $gNews_tableexists == 'NO' ) || ( $gNews_pluginversion != $gNews_db_version ) ) { |
|---|
| 79 | $sSql = 'CREATE TABLE ' . WP_G_NEWS_ANNOUNCEMENT . " ( |
|---|
| 80 | gNews_id mediumint(9) NOT NULL AUTO_INCREMENT, |
|---|
| 81 | gNews_text text NOT NULL, |
|---|
| 82 | gNews_order int(11) NOT NULL default '0', |
|---|
| 83 | gNews_status char(3) NOT NULL default 'YES', |
|---|
| 84 | gnews_redirect_link VARCHAR(255), |
|---|
| 85 | gNews_date DATE DEFAULT '0000-00-00' NOT NULL, |
|---|
| 86 | gNews_expiration DATE DEFAULT '0000-00-00' NOT NULL, |
|---|
| 87 | gNews_type VARCHAR(100) DEFAULT 'GROUP1' NOT NULL, |
|---|
| 88 | UNIQUE KEY gNews_id (gNews_id) |
|---|
| 89 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; |
|---|
| 90 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|---|
| 91 | dbDelta( $sSql ); |
|---|
| 92 | |
|---|
| 93 | if ( $gNews_pluginversion == '' ) { |
|---|
| 94 | add_option( 'gNews_pluginversion', '8.3', '', 'no' ); |
|---|
| 95 | } else { |
|---|
| 96 | update_option( 'gNews_pluginversion', $gNews_db_version, 'no' ); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | if ( $gNews_tableexists == 'NO' ) { |
|---|
| 100 | $welcome_text = 'This plugin will create a vertical scrolling announcement news.'; |
|---|
| 101 | $welcome_text1 = 'Use this to show any news on your site.'; |
|---|
| 102 | $rows_affected = $wpdb->insert( |
|---|
| 103 | WP_G_NEWS_ANNOUNCEMENT, |
|---|
| 104 | array( |
|---|
| 105 | 'gNews_text' => $welcome_text, |
|---|
| 106 | 'gNews_type' => 'WIDGET', |
|---|
| 107 | ) |
|---|
| 108 | ); |
|---|
| 109 | $rows_affected = $wpdb->insert( |
|---|
| 110 | WP_G_NEWS_ANNOUNCEMENT, |
|---|
| 111 | array( |
|---|
| 112 | 'gNews_text' => $welcome_text1, |
|---|
| 113 | 'gNews_type' => 'SAMPLE', |
|---|
| 114 | ) |
|---|
| 115 | ); |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | // die(); |
|---|
| 119 | add_option( 'gNewsAnnouncementtitle', 'Announcement', '', 'no' ); |
|---|
| 120 | add_option( 'gNewsAnnouncementfont', 'verdana,arial,sans-serif', '', 'no' ); |
|---|
| 121 | add_option( 'gNewsAnnouncementfontsize', '11px', '', 'no' ); |
|---|
| 122 | add_option( 'gNewsAnnouncementfontweight', 'normal', '', 'no' ); |
|---|
| 123 | add_option( 'gNewsAnnouncementfontcolor', '#FF0000', '', 'no' ); |
|---|
| 124 | add_option( 'gNewsAnnouncementwidth', '180', '', 'no' ); |
|---|
| 125 | add_option( 'gNewsAnnouncementheight', '100', '', 'no' ); |
|---|
| 126 | add_option( 'gNewsAnnouncementslidedirection', '0', '', 'no' ); |
|---|
| 127 | add_option( 'gNewsAnnouncementslidetimeout', '3000', '', 'no' ); |
|---|
| 128 | add_option( 'gNewsAnnouncementtextalign', 'center', '', 'no' ); |
|---|
| 129 | add_option( 'gNewsAnnouncementtextvalign', 'middle', '', 'no' ); |
|---|
| 130 | add_option( 'gNewsAnnouncementnoannouncement ', 'No announcement available', '', 'no' ); |
|---|
| 131 | add_option( 'gNewsAnnouncementorder', '0', '', 'no' ); |
|---|
| 132 | add_option( 'gNewsAnnouncementtype', 'widget', '', 'no' ); |
|---|
| 133 | add_option( '_current_nas_db_version', '8.8.3', '', 'no' ); |
|---|
| 134 | |
|---|
| 135 | if ( ! is_network_admin() && ! isset( $_GET['activate-multi'] ) ) { |
|---|
| 136 | set_transient( '_nas_activation_redirect', 1, 30 ); |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | function database_update_for_8_8_3() { |
|---|
| 141 | global $wpdb; |
|---|
| 142 | |
|---|
| 143 | $sql = 'ALTER TABLE ' . WP_G_NEWS_ANNOUNCEMENT . ' ADD gnews_redirect_link VARCHAR(255) AFTER gNews_status'; |
|---|
| 144 | $result = $wpdb->query( $sql ); |
|---|
| 145 | |
|---|
| 146 | if ( true === $result ) { |
|---|
| 147 | update_option( '_current_nas_db_version', '8.8.3', 'no' ); |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | function nas_database_update() { |
|---|
| 152 | $nas_db_version = get_option( '_current_nas_db_version', 'no' ); |
|---|
| 153 | if ( $nas_db_version == 'no' ) { |
|---|
| 154 | database_update_for_8_8_3(); |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | function nas_redirect_on_activation() { |
|---|
| 159 | if ( ! get_transient( '_nas_activation_redirect' ) ) { |
|---|
| 160 | return; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | // Delete the redirect transient |
|---|
| 164 | delete_transient( '_nas_activation_redirect' ); |
|---|
| 165 | |
|---|
| 166 | wp_redirect( admin_url( 'options-general.php?page=news-announcement-scroll' ) ); |
|---|
| 167 | exit; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | function news_announcement_admin_options() { |
|---|
| 171 | global $wpdb; |
|---|
| 172 | $current_page = isset( $_GET['ac'] ) ? $_GET['ac'] : ''; |
|---|
| 173 | |
|---|
| 174 | wp_register_script( 'nas_gAnnounceform', NAS_URL . 'gAnnounce/gAnnounceform.js', array( 'jquery' ) ); |
|---|
| 175 | wp_enqueue_script( 'nas_gAnnounceform' ); |
|---|
| 176 | |
|---|
| 177 | wp_register_script( 'nas_noenter', NAS_URL . 'gAnnounce/noenter.js', array( 'jquery' ) ); |
|---|
| 178 | wp_enqueue_script( 'nas_noenter' ); |
|---|
| 179 | |
|---|
| 180 | switch ( $current_page ) { |
|---|
| 181 | case 'edit': |
|---|
| 182 | include 'pages/content-management-edit.php'; |
|---|
| 183 | break; |
|---|
| 184 | case 'add': |
|---|
| 185 | include 'pages/content-management-add.php'; |
|---|
| 186 | break; |
|---|
| 187 | case 'set': |
|---|
| 188 | include 'pages/content-setting.php'; |
|---|
| 189 | break; |
|---|
| 190 | default: |
|---|
| 191 | include 'pages/content-management-show.php'; |
|---|
| 192 | break; |
|---|
| 193 | } |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | function widget_news_announcement( $args ) { |
|---|
| 197 | extract( $args ); |
|---|
| 198 | echo $before_widget; |
|---|
| 199 | echo $before_title; |
|---|
| 200 | echo get_option( 'gNewsAnnouncementtitle' ); |
|---|
| 201 | echo $after_title; |
|---|
| 202 | |
|---|
| 203 | wp_register_script( 'nas_gannounce', NAS_URL . 'gAnnounce/gAnnounce.js', array( 'jquery' ) ); |
|---|
| 204 | wp_enqueue_script( 'nas_gannounce' ); |
|---|
| 205 | |
|---|
| 206 | news_announcement(); |
|---|
| 207 | echo $after_widget; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | function news_announcement_widget_control() { |
|---|
| 211 | // No action required |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | function news_announcement_plugins_loaded() { |
|---|
| 215 | if ( function_exists( 'wp_register_sidebar_widget' ) ) { |
|---|
| 216 | wp_register_sidebar_widget( __( 'News announcement scroll', 'news-announcement-scroll' ), __( 'News Announcement Scroll', 'news-announcement-scroll' ), 'widget_news_announcement' ); |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | if ( function_exists( 'wp_register_widget_control' ) ) { |
|---|
| 220 | wp_register_widget_control( __( 'News announcement scroll', 'news-announcement-scroll' ), array( __( 'News announcement scroll', 'news-announcement-scroll' ), 'widgets' ), 'news_announcement_widget_control' ); |
|---|
| 221 | } |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | function news_announcement_add_to_menu() { |
|---|
| 225 | add_options_page( __( 'News announcement scroll', 'news-announcement-scroll' ), __( 'News Announcement Scroll', 'news-announcement-scroll' ), 'manage_options', 'news-announcement-scroll', 'news_announcement_admin_options' ); |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | if ( is_admin() ) { |
|---|
| 229 | add_action( 'admin_menu', 'news_announcement_add_to_menu' ); |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | function news_shortcode( $atts ) { |
|---|
| 233 | global $wpdb; |
|---|
| 234 | |
|---|
| 235 | wp_register_script( 'nas_gannounce', NAS_URL . 'gAnnounce/gAnnounce.js', array( 'jquery' ) ); |
|---|
| 236 | wp_enqueue_script( 'nas_gannounce' ); |
|---|
| 237 | |
|---|
| 238 | $nas = ''; |
|---|
| 239 | $Ann = ''; |
|---|
| 240 | |
|---|
| 241 | if ( ! is_array( $atts ) ) { |
|---|
| 242 | return ''; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | $gNewsAnnouncementtype = $atts['group']; |
|---|
| 246 | |
|---|
| 247 | $sSql = 'SELECT * from ' . WP_G_NEWS_ANNOUNCEMENT . " where gNews_status='YES'"; |
|---|
| 248 | $sSql = $sSql . " and (`gNews_date` <= NOW() or `gNews_date` = '0000-00-00')"; |
|---|
| 249 | $sSql = $sSql . " and (`gNews_expiration` >= NOW() or `gNews_expiration` = '0000-00-00')"; |
|---|
| 250 | |
|---|
| 251 | if ( $gNewsAnnouncementtype != '' ) { |
|---|
| 252 | $sSql = $sSql . " and gNews_type='" . $gNewsAnnouncementtype . "'"; |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | if ( get_option( 'gNewsAnnouncementorder' ) == '1' ) { |
|---|
| 256 | $sSql = $sSql . ' ORDER BY rand()'; |
|---|
| 257 | } else { |
|---|
| 258 | $sSql = $sSql . ' ORDER BY gNews_order'; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | $data = $wpdb->get_results( $sSql ); |
|---|
| 262 | |
|---|
| 263 | $nas = $nas . '<script language="JavaScript" type="text/javascript">'; |
|---|
| 264 | $nas = $nas . 'v_font="' . get_option( 'gNewsAnnouncementfont' ) . '"; '; |
|---|
| 265 | $nas = $nas . 'v_fontSize="' . get_option( 'gNewsAnnouncementfontsize' ) . '"; '; |
|---|
| 266 | $nas = $nas . 'v_fontSizeNS4="' . get_option( 'gNewsAnnouncementfontsize' ) . '"; '; |
|---|
| 267 | $nas = $nas . 'v_fontWeight="' . get_option( 'gNewsAnnouncementfontweight' ) . '"; '; |
|---|
| 268 | $nas = $nas . 'v_fontColor="' . get_option( 'gNewsAnnouncementfontcolor' ) . '"; '; |
|---|
| 269 | $nas = $nas . 'v_textDecoration="none"; '; |
|---|
| 270 | $nas = $nas . 'v_fontColorHover="#FFFFFF"; '; |
|---|
| 271 | $nas = $nas . 'v_textDecorationHover="none"; '; |
|---|
| 272 | $nas = $nas . 'v_top=0;'; |
|---|
| 273 | $nas = $nas . 'v_left=0;'; |
|---|
| 274 | $nas = $nas . 'v_width=' . get_option( 'gNewsAnnouncementwidth' ) . '; '; |
|---|
| 275 | $nas = $nas . 'v_height=' . get_option( 'gNewsAnnouncementheight' ) . '; '; |
|---|
| 276 | $nas = $nas . 'v_paddingTop=0; '; |
|---|
| 277 | $nas = $nas . 'v_paddingLeft=0; '; |
|---|
| 278 | $nas = $nas . 'v_position="relative"; '; |
|---|
| 279 | $nas = $nas . 'v_timeout=' . get_option( 'gNewsAnnouncementslidetimeout' ) . '; '; |
|---|
| 280 | $nas = $nas . 'v_slideSpeed=1;'; |
|---|
| 281 | $nas = $nas . 'v_slideDirection=' . get_option( 'gNewsAnnouncementslidedirection' ) . '; '; |
|---|
| 282 | $nas = $nas . 'v_pauseOnMouseOver=true; '; |
|---|
| 283 | $nas = $nas . 'v_slideStep=1; '; |
|---|
| 284 | $nas = $nas . 'v_textAlign="' . get_option( 'gNewsAnnouncementtextalign' ) . '"; '; |
|---|
| 285 | $nas = $nas . 'v_textVAlign="' . get_option( 'gNewsAnnouncementtextvalign' ) . '"; '; |
|---|
| 286 | $nas = $nas . 'v_bgColor="transparent"; '; |
|---|
| 287 | $nas = $nas . '</script>'; |
|---|
| 288 | |
|---|
| 289 | if ( ! empty( $data ) ) { |
|---|
| 290 | |
|---|
| 291 | foreach ( $data as $data ) { |
|---|
| 292 | |
|---|
| 293 | if ( ! empty( $data->gnews_redirect_link ) ) { |
|---|
| 294 | $data->gNews_text = '<a href="' . $data->gnews_redirect_link . '" style="color:inherit;text-decoration:underline;font-weight:inherit" target="_blank">' . $data->gNews_text . '</a>'; |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | $Ann = $Ann . "['','" . $data->gNews_text . "',''],"; |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | $Ann = substr( $Ann, 0, ( strlen( $Ann ) - 1 ) ); |
|---|
| 301 | $nas = $nas . '<div id="display_news" style="padding-bottom:5px;padding-top:5px;">'; |
|---|
| 302 | $nas = $nas . '<script language="JavaScript" type="text/javascript">'; |
|---|
| 303 | $nas = $nas . 'v_content=[' . $Ann . ']'; |
|---|
| 304 | $nas = $nas . '</script>'; |
|---|
| 305 | $nas = $nas . '</div>'; |
|---|
| 306 | } else { |
|---|
| 307 | ?> |
|---|
| 308 | <div id="display_news"> |
|---|
| 309 | <script language="JavaScript" type="text/javascript"> |
|---|
| 310 | v_content=[['','<?php echo get_option( 'gNewsAnnouncementnoannouncement' ); ?>',''],['','<?php echo get_option( 'gNewsAnnouncementnoannouncement' ); ?>','']] |
|---|
| 311 | </script> |
|---|
| 312 | </div> |
|---|
| 313 | <?php |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | return $nas; |
|---|
| 317 | } |
|---|
| 318 | |
|---|
| 319 | function news_announcement_deactivate() { |
|---|
| 320 | // No action required. |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | function news_announcement_textdomain() { |
|---|
| 324 | load_plugin_textdomain( 'news-announcement-scroll', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | function plugin_action_links( $links ) { |
|---|
| 328 | $action_links = array( |
|---|
| 329 | 'settings' => '<a href="' . admin_url( 'options-general.php?page=news-announcement-scroll' ) . '" title="' . esc_attr( __( 'View News Announcement Scroll Settings', 'news-announcement-scroll' ) ) . '">' . __( 'Settings', 'news-announcement-scroll' ) . '</a>', |
|---|
| 330 | 'docs' => '<a href="https://www.storeapps.org/knowledgebase_category/news-announcement-scroll/" target="_blank" title="' . __( 'Documentation', 'news-announcement-scroll' ) . '">' . __( 'Docs', 'news-announcement-scroll' ) . '</a>', |
|---|
| 331 | ); |
|---|
| 332 | |
|---|
| 333 | return array_merge( $action_links, $links ); |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | add_action( 'plugins_loaded', 'news_announcement_textdomain' ); |
|---|
| 337 | add_action( 'plugins_loaded', 'news_announcement_plugins_loaded' ); |
|---|
| 338 | add_action( 'admin_init', 'nas_redirect_on_activation' ); |
|---|
| 339 | add_action( 'admin_init', 'nas_database_update' ); |
|---|
| 340 | add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'plugin_action_links' ); |
|---|
| 341 | add_shortcode( 'news-announcement', 'news_shortcode' ); |
|---|
| 342 | register_activation_hook( __FILE__, 'news_announcement_activation' ); |
|---|
| 343 | register_deactivation_hook( __FILE__, 'news_announcement_deactivate' ); |
|---|