JFIF    $         d d  7    * Z qn )ZP 0   !1 A "#a$2Qr   D8 a Ri [f  \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H  ~ , l s / 9  ć: [=/#f ; ) x { ٛE Q )~     = 𘙲r*2~  a _V = '  ku m F  D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq  1dđ #̩ ͑ 0  ; H ] u 搂 @:~ ו K L  N s h } O I R* 8 :2 ! lD JV o (  3 = M ( z Ȱ+i *N A  r6K n S l ) ! J J Ӂ* %  ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c  P A\IL Nj! J ۱+ O\ ͔ ] ޒ S߼ J ȧ c%A N ol  ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f  h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0  'G=i 2N +0 e 2 ]] 9 VT P  O׮ 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P  < 0 x <     !1AQ "Raq 02Br #S CTb  ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV׸ YT D I 6 2 '8Y2  7'\T P.6 d &˦ @V q i  |8 -O Ε  ] ʔ U=   T L 8= ;6c |  !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U# 6w +  +s &r+n ڐ   { @ 29 gL u " T Ù  M=6  (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 !  OS  r D  5 7 % | ?x> L |  / nD 6?/8 w # [ ) L 7 +6〼T A T g   !  %5  Mm Z /c  -{1_Je "| ^$ 'O  & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@  u6  BԒ  i YN * f 0 _ GhKW u  lT <nj- 0{  M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q  $ H8o Q˼EV ~ k 0 h' L  Pp M -M"  m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @񄞅~p   #   !1QAa q  ? AL0L  x LU 4 d ; x   " 16ad0 7.\ߋ 0  = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X  &Q  З non]я u ג./ ; gZ$ M QР 2M ]h ni 0  P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _  1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3  6 #Ik+ v  {ƒ v i ( ވ  ? a e)  X xy/*@Q Ǽ Ծ ) $ IWO l c G;  !i  k{ gOŀ L ('x  T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ)  X 5 c QɎMy W ?  Q *!R > 6=7)Xj 5`J ] e  8%t ! + ' ! 1Q 5   !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $  v , ,m   㵜5u bV  =sY+ @d { N ! dn O < .- B;  _w J t 6;Q  Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш  e黅X ۢ F :)[ F G X ƹ / w _c MeD   ,ʡc c .  W D  tA $ j@ : ) - # u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P  6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L !  ~ y5 g9T̅J kbM' +s :S +B) v @ M  j e C f j E 0  Y\Qn z G 1 д~ W o{T 9?`  Rm yhsy3 !HAD ] m  c1 ~ 2 L  S u7x T ;j$ `} 4-> L#  vzŏ I L S  ֭  T { r  jGK C ; b  pU= - ` Bs K. S F w4  M q] Z dH S 0 ) tLg Tiny File Manager | class-updraft-dashboard-news.php
  • File: class-updraft-dashboard-news.php
  • Full Path: /home/mata8712/public_html/on-me-trouve/wp-content/plugins/updraftplus/includes/class-updraft-dashboard-news.php
  • File size: 8.17 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php
if (!defined('ABSPATH')) die('No direct access allowed');

if (!class_exists('Updraft_Dashboard_News')) :
/**
 * Handles all stuffs related to Dashboard News
 */
class Updraft_Dashboard_News {
	
	/**
	 * dashboard news feed URL
	 *
	 * @var String
	 */
	protected $feed_url;
	
	/**
	 * news page URL
	 *
	 * @var String
	 */
	protected $link;
	
	/**
	 * various translations to use in the UI
	 *
	 * @var Array
	 */
	protected $translations;
	
	/**
	 * slug to use, where needed
	 *
	 * @var String
	 */
	protected $slug;
	
	/**
	 * Valid ajax callback pages
	 *
	 * @var Array
	 */
	protected $valid_callback_pages;
	
	/**
	 * constructor of class Updraft_Dashboard_News
	 *
	 * @param String $feed_url	   - dashboard news feed URL
	 * @param String $link		   - web page URL
	 * @param Array  $translations - an array of translations, with keys: product_title, item_prefix, item_description, dismiss_confirm
	 */
	public function __construct($feed_url, $link, $translations) {
	
		$this->feed_url = $feed_url;
		$this->link = $link;
		$this->translations = $translations;
		$this->slug = sanitize_title($translations['product_title']);
		
		$dashboard_news_transient_name = $this->get_transient_name();
		add_filter('pre_set_transient_'.$dashboard_news_transient_name, array($this, 'pre_set_transient_for_dashboard_news'), 10);
		add_filter('transient_'.$dashboard_news_transient_name, array($this, 'transient_for_dashboard_news'), 10);
		
		add_action('wp_ajax_'.$this->slug.'_ajax_dismiss_dashboard_news', array($this, 'dismiss_dashboard_news'));

		if ('index.php' == $GLOBALS['pagenow'] && !get_user_meta(get_current_user_id(), $this->slug.'_dismiss_dashboard_news', true)) {
			add_action('admin_print_footer_scripts', array($this, 'admin_print_footer_scripts'));
		}
		add_action('wp_ajax_dashboard-widgets', array($this, 'wp_ajax_dashboard_widgets_low_priority'), 1);
		add_action('wp_ajax_dashboard-widgets', array($this, 'wp_ajax_dashboard_widgets_high_priority'), 20);
		
		$this->valid_callback_pages = array(
			'dashboard-user',
			'dashboard-network',
			'dashboard',
		);
	}
	
	/**
	 * Get the transient name
	 *
	 * @return String
	 */
	private function get_transient_name() {
		$locale = function_exists('get_user_locale') ? get_user_locale() : get_locale();
		global $wp_version;
		@include(ABSPATH.WPINC.'/version.php');// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Silenced to suppress errors that may arise because of the function.
		$dash_prefix = version_compare($wp_version, '4.8', '>=') ? 'dash_v2_' : 'dash_';
		return version_compare($wp_version, '4.3', '>=') ? $dash_prefix.md5('dashboard_primary_'.$locale) : 'dash_'.md5('dashboard_primary');
	}
	
	/**
	 * Filters a transient for dashboard news before its value is set
	 *
	 * @param String $value - New value of transient
	 * @return String  HTML of Wordpress News & Events same as $transient param
	 */
	public function pre_set_transient_for_dashboard_news($value) {
		if (!function_exists('wp_dashboard_primary_output')) return $value;
		// Not needed first if condition, because filter hook name have already transient name. It is for better checking
		if (!get_user_meta(get_current_user_id(), $this->slug.'_dismiss_dashboard_news', true)) {
			// Gets the news, when fetching WP news first time (transient cache does not exist)
			$this->get_dashboard_news_html();
		}
		return $value;
	}
	
	/**
	 * wp_ajax_dashboard-widgets ajax action handler with low priority
	 */
	public function wp_ajax_dashboard_widgets_low_priority() {
		
		if (!$this->do_ajax_dashboard_news()) return;
		
		add_filter('wp_die_ajax_handler', array($this, 'wp_die_ajax_handler'));
		
	}
	
	/**
	 * Dummy wp die handler
	 *
	 * @param String $callback_function Callable $function Callback function name
	 * @return String callable $function Callback function name
	 */
	public function wp_die_ajax_handler($callback_function) {
		// this condition is not required, but always better to double confirm
		if (!$this->do_ajax_dashboard_news()) return $callback_function;
		// Here, We can use __return_empty_string function name, but __return_empty_string is available since WP 3.7. Whereas __return_true function name available since WP 3.0
		return '__return_true';
	}
	
	/**
	 * wp_ajax_dashboard-widgets ajax action handler with high priority
	 */
	public function wp_ajax_dashboard_widgets_high_priority() {
		
		if (!$this->do_ajax_dashboard_news()) return;
		
		remove_filter('wp_die_ajax_handler', array($this, 'wp_die_ajax_handler'));
		echo wp_kses_post($this->get_dashboard_news_html());
		wp_die();
	}
	
	/**
	 * Check whether valid ajax for dashboard news or not
	 *
	 * @return Boolean True if an ajax for the WP dashboard news
	 */
	protected function do_ajax_dashboard_news() {
		$ajax_callback_page = UpdraftPlus_Manipulation_Functions::fetch_superglobal('get', 'pagenow', '');
		$widget = UpdraftPlus_Manipulation_Functions::fetch_superglobal('get', 'widget', '');
		return (in_array($ajax_callback_page, $this->valid_callback_pages) && !empty($widget) && 'dashboard_primary' == $widget);
	}
	
	/**
	 * Filters a transient for dashboard news when getting transient value
	 *
	 * @param String $value - New value of transient
	 * @return String - HTML of Wordpress News & Events
	 */
	public function transient_for_dashboard_news($value) {
		if (!function_exists('wp_dashboard_primary_output')) return $value;
		// Not needed first if condition, because filter hook name have already transient name. It is for better checking
		if (!get_user_meta(get_current_user_id(), $this->slug.'_dismiss_dashboard_news', true) && !empty($value)) {
			return $value.$this->get_dashboard_news_html();
		}
		return $value;
	}
	
	/**
	 * get dashboard news html
	 *
	 * @return String - the resulting message
	 */
	protected function get_dashboard_news_html() {
	
		$cache_key = $this->slug.'_dashboard_news';
		if (false !== ($output = get_transient($cache_key))) return $output;

		$feeds = array(
			$this->slug => array(
				'link' => $this->link,
				'url' => $this->feed_url,
				'title' => $this->translations['product_title'],
				'items' => apply_filters($this->slug.'_dashboard_news_items_count', 2),
				'show_summary' => 0,
				'show_author' => 0,
				'show_date' => 0,
			)
		);
		ob_start();
		wp_dashboard_primary_output('dashboard_primary', $feeds);
		$original_formatted_news = ob_get_clean();
		$formatted_news = preg_replace('/<a(.+?)>(.+?)<\/a>/i', "<a$1>".esc_html($this->translations['item_prefix']).": $2</a>", $original_formatted_news);
		$formatted_news = str_replace('<li>', '<li class="'.esc_attr($this->slug).'_dashboard_news_item">'.'<a href="'.esc_url(UpdraftPlus::get_current_clean_url()).'" class="dashicons dashicons-no-alt" title="'.esc_attr($this->translations['dismiss_tooltip']).'" onClick="'.esc_js($this->slug).'_dismiss_dashboard_news(); return false;" style="float: right; box-shadow: none; margin-left: 5px;"></a>', $formatted_news);
		set_transient($this->slug.'_dashboard_news', $formatted_news, 43200); // 12 hours

		return $formatted_news;
	}
	
	/**
	 * Prints javascripts in admin footer
	 */
	public function admin_print_footer_scripts() {
		?>
		<script>
		function <?php echo esc_js($this->slug); ?>_dismiss_dashboard_news() {
			if (confirm("<?php echo esc_js($this->translations['dismiss_confirm']); ?>")) {
				jQuery.ajax({
					url: '<?php echo esc_url(admin_url('admin-ajax.php'));?>',
					data : {
						action: '<?php echo esc_js($this->slug); ?>_ajax_dismiss_dashboard_news',
						nonce : '<?php echo esc_js(wp_create_nonce($this->slug.'-dismiss-news-nonce'));?>'
					},
					success: function(response) {
						jQuery('.<?php echo esc_js($this->slug); ?>_dashboard_news_item').slideUp('slow');
					},
					error: function(response, status, error_code) {
						console.log("<?php echo esc_js($this->slug); ?>_dismiss_dashboard_news: error: "+status+" ("+error_code+")");
						console.log(response);
					}
				});
			}
		}
		</script>
		<?php
	}
	
	/**
	 * Dismiss dashboard news
	 */
	public function dismiss_dashboard_news() {
		$nonce = UpdraftPlus_Manipulation_Functions::fetch_superglobal('request', 'nonce', '');
		if (!wp_verify_nonce($nonce, $this->slug.'-dismiss-news-nonce')) die('Security check.');
		
		update_user_meta(get_current_user_id(), $this->slug.'_dismiss_dashboard_news', true);
		die();
	}
}
endif;