Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../includes
File: updraft-notices.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if (!defined('ABSPATH')) die('No direct access allowed');
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* If we ever change the API of the Updraft_Notices class, then we'll need to rename and version it, e.g. Updraft_Notices_1_0, because otherwise a plugin may find that it's loaded an older instance than it wanted from another plugin.
[5] Fix | Delete
*/
[6] Fix | Delete
abstract class Updraft_Notices {
[7] Fix | Delete
[8] Fix | Delete
protected $notices_content;
[9] Fix | Delete
[10] Fix | Delete
// These variables are just short-hands to be used in advert content.
[11] Fix | Delete
protected $dashboard_top = array('top');
[12] Fix | Delete
[13] Fix | Delete
protected $dashboard_top_or_report = array('top', 'report', 'report-plain');
[14] Fix | Delete
[15] Fix | Delete
protected $dashboard_bottom_or_report = array('bottom', 'report', 'report-plain');
[16] Fix | Delete
[17] Fix | Delete
protected $anywhere = array('top', 'bottom', 'report', 'report-plain');
[18] Fix | Delete
[19] Fix | Delete
protected $autobackup = array('autobackup');
[20] Fix | Delete
[21] Fix | Delete
protected $autobackup_bottom_or_report = array('autobackup', 'bottom', 'report', 'report-plain');
[22] Fix | Delete
[23] Fix | Delete
protected function populate_notices_content() {
[24] Fix | Delete
// Global adverts that appear in all products will be returned to the child to display
[25] Fix | Delete
return array();
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Call this method to setup the notices
[30] Fix | Delete
*/
[31] Fix | Delete
abstract protected function notices_init();
[32] Fix | Delete
[33] Fix | Delete
protected function translation_needed($plugin_base_dir, $product_name) {
[34] Fix | Delete
$wplang = get_locale();
[35] Fix | Delete
if (strlen($wplang) < 1 || 'en_US' == $wplang || 'en_GB' == $wplang) return false;
[36] Fix | Delete
if (defined('WP_LANG_DIR') && is_file(WP_LANG_DIR.'/plugins/'.$product_name.'-'.$wplang.'.mo')) return false;
[37] Fix | Delete
if (is_file($plugin_base_dir.'/languages/'.$product_name.'-'.$wplang.'.mo')) return false;
[38] Fix | Delete
return true;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
protected function url_start($html_allowed, $url, $https = false, $website_home = null) {
[42] Fix | Delete
$proto = ($https) ? 'https' : 'http';
[43] Fix | Delete
if (strpos($url, $website_home) !== false) {
[44] Fix | Delete
return $html_allowed ? "<a href=".apply_filters(str_replace('.', '_', $website_home).'_link', $proto.'://'.$url).">" : "";
[45] Fix | Delete
} else {
[46] Fix | Delete
return $html_allowed ? "<a href=\"$proto://$url\">" : "";
[47] Fix | Delete
}
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
protected function url_end($html_allowed, $url, $https = false) {
[51] Fix | Delete
$proto = ($https) ? 'https' : 'http';
[52] Fix | Delete
return $html_allowed ? '</a>' : " ($proto://$url)";
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
public function do_notice($notice = false, $position = 'top', $return_instead_of_echo = false) {
[56] Fix | Delete
[57] Fix | Delete
$this->notices_init();
[58] Fix | Delete
[59] Fix | Delete
if (false === $notice) $notice = apply_filters('updraft_notices_force_id', false, $this);
[60] Fix | Delete
[61] Fix | Delete
$notice_content = $this->get_notice_data($notice, $position);
[62] Fix | Delete
[63] Fix | Delete
if (false != $notice_content) {
[64] Fix | Delete
return $this->render_specified_notice($notice_content, $return_instead_of_echo, $position);
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* This method will return a notice ready for display.
[70] Fix | Delete
*
[71] Fix | Delete
* @param boolean $notice the notice to grab the data
[72] Fix | Delete
* @param string $position position of notice
[73] Fix | Delete
* @return array
[74] Fix | Delete
*/
[75] Fix | Delete
protected function get_notice_data($notice = false, $position = 'top') {
[76] Fix | Delete
[77] Fix | Delete
// If a specific notice has been passed to this method then return that notice.
[78] Fix | Delete
if ($notice) {
[79] Fix | Delete
if (!isset($this->notices_content[$notice])) return false;
[80] Fix | Delete
[81] Fix | Delete
// Does the notice support the position specified?
[82] Fix | Delete
if (isset($this->notices_content[$notice]['supported_positions']) && !in_array($position, $this->notices_content[$notice]['supported_positions'])) return false;
[83] Fix | Delete
[84] Fix | Delete
/*
[85] Fix | Delete
First check if the advert passed can be displayed and hasn't been dismissed, we do this by checking what dismissed value we should be checking.
[86] Fix | Delete
*/
[87] Fix | Delete
$dismiss_time = $this->notices_content[$notice]['dismiss_time'];
[88] Fix | Delete
[89] Fix | Delete
$dismiss = $this->check_notice_dismissed($dismiss_time);
[90] Fix | Delete
[91] Fix | Delete
if ($dismiss) return false;
[92] Fix | Delete
[93] Fix | Delete
// If the advert has a validity function, then require the advert to be valid
[94] Fix | Delete
if (!empty($this->notices_content[$notice]['validity_function']) && !call_user_func(array($this, $this->notices_content[$notice]['validity_function']))) return false;
[95] Fix | Delete
[96] Fix | Delete
return $this->notices_content[$notice];
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
// create an array to add non-seasonal adverts to so that if a seasonal advert can't be returned we can choose a random advert from this array.
[100] Fix | Delete
$available_notices = array();
[101] Fix | Delete
[102] Fix | Delete
// If Advert wasn't passed then next we should check to see if a seasonal advert can be returned.
[103] Fix | Delete
foreach ($this->notices_content as $notice_id => $notice_data) {
[104] Fix | Delete
// Does the notice support the position specified?
[105] Fix | Delete
if (isset($this->notices_content[$notice_id]['supported_positions']) && !in_array($position, $this->notices_content[$notice_id]['supported_positions'])) continue;
[106] Fix | Delete
[107] Fix | Delete
// If the advert has a validity function, then require the advert to be valid
[108] Fix | Delete
if (!empty($notice_data['validity_function']) && !call_user_func(array($this, $notice_data['validity_function']))) continue;
[109] Fix | Delete
[110] Fix | Delete
if (isset($notice_data['valid_from']) && isset($notice_data['valid_to'])) {
[111] Fix | Delete
[112] Fix | Delete
if ($this->skip_seasonal_notices($notice_data)) return $notice_data;
[113] Fix | Delete
[114] Fix | Delete
} else {
[115] Fix | Delete
[116] Fix | Delete
$dismiss_time = $this->notices_content[$notice_id]['dismiss_time'];
[117] Fix | Delete
$dismiss = $this->check_notice_dismissed($dismiss_time);
[118] Fix | Delete
[119] Fix | Delete
if (!$dismiss) $available_notices[$notice_id] = $notice_data;
[120] Fix | Delete
}
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
if (empty($available_notices)) return false;
[124] Fix | Delete
[125] Fix | Delete
// If a seasonal advert can't be returned then we will return a random advert
[126] Fix | Delete
[127] Fix | Delete
// Here we give a 25% chance for the rate advert to be returned before selecting a random advert from the entire collection which also includes the rate advert
[128] Fix | Delete
if (0 == rand(0, 3) && isset($available_notices['rate'])) return $available_notices['rate'];
[129] Fix | Delete
[130] Fix | Delete
/*
[131] Fix | Delete
Using shuffle here as something like rand which produces a random number and uses that as the array index fails, this is because in future an advert may not be numbered and could have a string as its key which will then cause errors.
[132] Fix | Delete
*/
[133] Fix | Delete
[134] Fix | Delete
shuffle($available_notices);
[135] Fix | Delete
return $available_notices[0];
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
protected function skip_seasonal_notices($notice_data) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
[139] Fix | Delete
return false;
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
abstract protected function check_notice_dismissed($dismiss_time);
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function