admin-bar-menu.php
3 years ago
ajax-pagination.php
2 years ago
class-ecs-core.php
2 months ago
class-ecs-module-base.php
1 month ago
class-ecs-modules-manager.php
2 months ago
dynamic-style.php
3 years ago
ecs-dependencies.php
6 years ago
ecs-notices.php
6 years ago
enqueue-styles.php
2 years ago
pro-features.php
2 months ago
pro-preview.php
6 years ago
ecs-notices.php
151 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 | |
| 4 | class Ecs_Notice { |
| 5 | /** |
| 6 | * Message of the notice. |
| 7 | * |
| 8 | * @since 1.2.2 |
| 9 | * @access private |
| 10 | * @var string |
| 11 | */ |
| 12 | private $message = ""; |
| 13 | |
| 14 | /** |
| 15 | * The id of the notice. |
| 16 | * |
| 17 | * @since 1.0.0 |
| 18 | * @access private |
| 19 | * @var string |
| 20 | */ |
| 21 | private $notice = ""; |
| 22 | |
| 23 | /** |
| 24 | * The id of the notice. |
| 25 | * |
| 26 | * @since 1.0.0 |
| 27 | * @access private |
| 28 | * @var string |
| 29 | */ |
| 30 | private $type = "info"; |
| 31 | |
| 32 | /** |
| 33 | * The user role. |
| 34 | * |
| 35 | * @since 1.0.0 |
| 36 | * @access private |
| 37 | * @var string |
| 38 | */ |
| 39 | private $role = 'administrator'; |
| 40 | |
| 41 | public function __construct($message,$notice="") { |
| 42 | $this->message = $message; |
| 43 | $this->notice = $notice; |
| 44 | } |
| 45 | |
| 46 | public function set_role($role){ |
| 47 | $this->role = $role; |
| 48 | } |
| 49 | public function set_type($type){ |
| 50 | $this->type = $type; |
| 51 | } |
| 52 | public function show(){ |
| 53 | add_action('admin_notices', [$this,'admin_notice']); |
| 54 | } |
| 55 | public function admin_notice(){ |
| 56 | $user_id = get_current_user_id(); |
| 57 | if ($this->notice && get_user_meta( $user_id, $this->notice )) return; |
| 58 | $image = '<img width="30px" src="'.ELECS_URL . 'assets/dudaster_icon.png" style="width:32px;margin-right:10px;margin-bottom: -11px;"/> '; |
| 59 | $user = wp_get_current_user(); |
| 60 | if ( in_array( $this->role, (array) $user->roles ) ) { |
| 61 | echo '<div class="notice notice-'.$this->type.' " style="padding-right: 38px; position: relative;"> |
| 62 | <p> '.$image.$this->message.'</p> |
| 63 | <a href="?ecsn_shown='.$this->notice.'"><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></a> |
| 64 | </div>'; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | } |
| 69 | |
| 70 | function ecs_notice_dismiss() { |
| 71 | $user_id = get_current_user_id(); |
| 72 | if ( isset( $_GET['ecsn_shown'] ) ) |
| 73 | if ( $_GET['ecsn_shown']) add_user_meta( $user_id, $_GET['ecsn_shown'] , 'true', true ); |
| 74 | } |
| 75 | add_action( 'admin_init', 'ecs_notice_dismiss' ); |
| 76 | |
| 77 | function ecs_check_for_notification(){ |
| 78 | if (!is_admin()) return; |
| 79 | $user_id = get_current_user_id(); |
| 80 | $current_date = date("Y-m-d"); |
| 81 | $notifications = ecs_load_notifications(); |
| 82 | $i=0; |
| 83 | foreach($notifications as $notification){ |
| 84 | $show[$i] = new Ecs_Notice($notification['message'],$notification['slug']); |
| 85 | $show[$i]->show(); |
| 86 | $i++; |
| 87 | } |
| 88 | } |
| 89 | function ecs_days_old(){ |
| 90 | $user_id = get_current_user_id(); |
| 91 | $nstall="ecs_instalation"; |
| 92 | if ( !get_user_meta( $user_id, $nstall ,true )){ |
| 93 | add_user_meta( $user_id, $nstall , time()); |
| 94 | } |
| 95 | return round((time() - get_user_meta( $user_id, $nstall ,true )) / 86400); |
| 96 | } |
| 97 | function ecs_load_notifications(){ |
| 98 | |
| 99 | $user_id = get_current_user_id(); |
| 100 | $current_date = date("Y-m-d"); |
| 101 | $ecspro = ecs_is_plugin_active('ele-custom-skin-pro.php') ? true : false; |
| 102 | $nver='ecs_notification_verification'; |
| 103 | $ndata='ecs_notification_data'; |
| 104 | $url=''; |
| 105 | $days = ecs_days_old(); |
| 106 | if ( get_user_meta( $user_id, $nver ,true ) < $current_date){ |
| 107 | //get data from url |
| 108 | $content = ecs_data_get($url); |
| 109 | $notifications = json_decode($content,true); |
| 110 | // set the data inside user metadata |
| 111 | if(is_array($notifications)) { |
| 112 | if(is_array(get_user_meta( $user_id, $ndata,true))) update_user_meta( $user_id, $ndata , $notifications ); |
| 113 | else add_user_meta( $user_id, $ndata , $notifications ); |
| 114 | } |
| 115 | // set the date inside user metadata |
| 116 | |
| 117 | if(get_user_meta( $user_id, $nver,true) ) update_user_meta( $user_id, $nver , $current_date ); |
| 118 | else add_user_meta( $user_id, $nver , $current_date, true ); |
| 119 | } |
| 120 | // load notice data from user metadata |
| 121 | |
| 122 | $notifications = get_user_meta( $user_id, $ndata,true); |
| 123 | |
| 124 | $return_notification=[]; |
| 125 | if(is_array($notifications)) foreach($notifications as $notification){ |
| 126 | $startdate = isset($notification['startdate']) ? $notification['startdate'] : ""; |
| 127 | $enddate = isset($notification['enddate']) ? $notification['enddate'] : $current_date; |
| 128 | $target = isset($notification['target']) ? $notification['target'] : "ecs"; |
| 129 | $notification['message'] = isset($notification['message']) ? $notification['message'] : ""; |
| 130 | $notification['days'] = isset($notification['days']) ? $notification['days'] : 0; |
| 131 | $notification['slug'] = isset($notification['slug']) ? $notification['slug'] : 'ecs'.hash('adler32',$notification['message']); |
| 132 | if($startdate <= $current_date && $current_date <= $enddate){ |
| 133 | if (($target == 'ecspro' && $ecspro) || ($target == 'ecs' && !$ecspro)) { |
| 134 | if($notification['message'] && ($notification['days'] >= $days || !$notification['days']) ) $return_notification[] = $notification; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return $return_notification; |
| 140 | } |
| 141 | |
| 142 | function ecs_data_get($url){ |
| 143 | if(!$url) return false; |
| 144 | $response = wp_remote_get($url,array( 'timeout' => 2 )); |
| 145 | if( is_array($response) ) { |
| 146 | $header = $response['headers']; // array of http header lines |
| 147 | $body = $response['body']; // use the content |
| 148 | } |
| 149 | return $body; // to return content |
| 150 | } |
| 151 |