PluginProbe ʕ •ᴥ•ʔ
Download Manager / trunk
Download Manager vtrunk
3.3.62 3.3.61 3.3.60 3.3.59 3.3.58 3.3.57 3.3.56 trunk 2.1.3 2.3.0 2.5.96 2.5.97 2.6.2 2.6.96 2.8.3 2.9.99 3.0.4 3.1.05 3.1.07 3.1.08 3.1.11 3.1.12 3.1.14 3.1.17 3.1.18 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.2.04 3.2.13 3.2.14 3.2.16 3.2.18 3.2.19 3.2.21 3.2.22 3.2.23 3.2.24 3.2.25 3.2.27 3.2.28 3.2.29 3.2.30 3.2.31 3.2.32 3.2.33 3.2.34 3.2.35 3.2.37 3.2.38 3.2.39 3.2.40 3.2.41 3.2.42 3.2.43 3.2.44 3.2.45 3.2.46 3.2.47 3.2.48 3.2.49 3.2.50 3.2.51 3.2.52 3.2.53 3.2.54 3.2.55 3.2.56 3.2.57 3.2.58 3.2.59 3.2.60 3.2.61 3.2.63 3.2.64 3.2.65 3.2.66 3.2.67 3.2.68 3.2.69 3.2.70 3.2.71 3.2.72 3.2.73 3.2.74 3.2.75 3.2.76 3.2.77 3.2.78 3.2.79 3.2.80 3.2.81 3.2.82 3.2.83 3.2.84 3.2.85 3.2.86 3.2.87 3.2.88 3.2.89 3.2.90 3.2.91 3.2.92 3.2.93 3.2.94 3.2.95 3.2.96 3.2.97 3.2.98 3.2.99 3.3.00 3.3.01 3.3.02 3.3.03 3.3.04 3.3.05 3.3.06 3.3.07 3.3.08 3.3.09 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.15 3.3.16 3.3.17 3.3.18 3.3.19 3.3.20 3.3.21 3.3.22 3.3.23 3.3.24 3.3.25 3.3.26 3.3.27 3.3.28 3.3.29 3.3.30 3.3.31 3.3.32 3.3.33 3.3.34 3.3.35 3.3.36 3.3.37 3.3.38 3.3.39 3.3.40 3.3.41 3.3.42 3.3.43 3.3.44 3.3.45 3.3.46 3.3.47 3.3.48 3.3.49 3.3.50 3.3.51 3.3.52 3.3.53 3.3.54 3.3.55
download-manager / src / __ / Apply.php
download-manager / src / __ Last commit date
HTML 1 year ago views 5 months ago Apply.php 6 months ago Cron.php 1 year ago CronJob.php 7 months ago CronJobs.php 2 months ago Crypt.php 1 month ago DownloadStats.php 5 months ago Email.php 4 days ago EmailCron.php 1 year ago FileSystem.php 1 year ago Installer.php 8 hours ago Messages.php 1 year ago Query.php 4 months ago Session.php 8 hours ago Settings.php 4 years ago SimpleMath.php 4 years ago TempStorage.php 8 hours ago Template.php 5 months ago UI.php 6 months ago Updater.php 4 years ago UserAgent.php 2 years ago __.php 1 month ago __MailUI.php 3 years ago
Apply.php
763 lines
1 <?php
2
3 namespace WPDM\__;
4
5
6 class Apply
7 {
8
9 function __construct()
10 {
11
12
13
14
15
16 $this->adminActions();
17 $this->frontendActions();
18
19 }
20
21 function frontendActions()
22 {
23
24 add_filter('wpdm_custom_data', array($this, 'skipLocks'), 10, 2);
25 add_action("wp_ajax_nopriv_showLockOptions", array($this, 'showLockOptions'));
26 add_action("wp_ajax_showLockOptions", array($this, 'showLockOptions'));
27
28 add_action('wp_ajax_wpdm_verify_file_pass', array($this, 'checkFilePassword'));
29 add_action('wp_ajax_nopriv_wpdm_verify_file_pass', array($this, 'checkFilePassword'));
30
31 add_action("wp_ajax_wpdm_generate_password", [$this, 'generatePassword']);
32 add_action("wp_ajax_wpdm-activate-shop", [$this, 'activatePremiumPackage']);
33
34 add_filter( 'wp_kses_allowed_html', [$this, 'allowStyleTagInKses'], 10, 2 );
35
36 if (is_admin()) return;
37
38 add_action("init", array($this, 'triggerDownload'), 9);
39 add_action('init', array($this, 'addWriteRules'), 0);
40
41
42 add_filter('widget_text', 'do_shortcode');
43
44 add_action('query_vars', array($this, 'dashboardPageVars'), 1);
45 add_action('request', array($this, 'rssFeed'));
46 add_filter('pre_get_posts', array($this, 'queryTag'));
47
48 add_filter('ajax_query_attachments_args', array($this, 'usersMediaQuery'));
49
50
51 add_action('wp_head', array($this, 'addGenerator'), 9999);
52 add_filter('post_comments_feed_link', array($this, 'removeCommentFeed'));
53
54 add_filter('the_excerpt_embed', array($this, 'oEmbed'));
55
56 add_action('wp_head', array($this, 'wpHead'), 999999);
57
58
59 }
60
61 function adminActions()
62 {
63 if (!is_admin()) return;
64 add_action('after_switch_theme', array($this, 'flashRules'));
65 add_action('save_post', array($this, 'dashboardPages'));
66 add_action('wp_ajax_clear_cache', array($this, 'clearCache'));
67 add_action('wp_ajax_clear_stats', array($this, 'clearStats'));
68 add_action('admin_head', array($this, 'uiColors'));
69
70 }
71
72 function authorPage($wp_query)
73 {
74 if ((int)$wp_query->is_author === 1 && ($ppid = WPDM()->setting->author_profile('int')) > 0 && $ppid === $wp_query->query_vars['page_id']) {
75 wpdmdd($ppid);
76 unset($wp_query->query['post_type']);
77 $pagename = get_pagename($ppid);
78 $wp_query->query = array('page' => '', 'pagename' => $pagename);
79 $wp_query->set('author_name', null);
80 $wp_query->set('pagename', $pagename);
81 $wp_query->is_archive = false;
82 $wp_query->is_post_type_archive = false;
83 $wp_query->queried_object_id = $ppid;
84 $wp_query->queried_object = get_post($ppid);
85 }
86 //wpdmdd($wp_query);
87 return $wp_query;
88 }
89
90 function skipLocks($data, $id)
91 {
92 global $current_user;
93 $skiplocks = maybe_unserialize(get_option('__wpdm_skip_locks', array()));
94 if (is_user_logged_in()) {
95 foreach ($skiplocks as $lock) {
96 unset($data[$lock . "_lock"]); // = 0;
97 }
98 }
99
100 return $data;
101 }
102
103 function docStream()
104 {
105 if (strstr($_SERVER['REQUEST_URI'], 'wpdm-doc-preview')) {
106 preg_match("/wpdm\-doc\-preview\/([0-9]+)/", $_SERVER['REQUEST_URI'], $mat);
107 $file_id = $mat[1];
108 $files = WPDM()->package->getFiles($file_id);
109 if (count($files) == 0) die('No file found!');
110 $sfile = '';
111 foreach ($files as $i => $sfile) {
112 $ifile = $sfile;
113 $sfile = explode(".", $sfile);
114 $fext = end($sfile);
115 if (in_array(end($sfile), array('pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'))) {
116 $sfile = $ifile;
117 break;
118 }
119 }
120 if ($sfile == '') die('No supported document found!');
121 if (file_exists(UPLOAD_DIR . $sfile)) $sfile = UPLOAD_DIR . $sfile;
122 if (!file_exists($sfile)) die('No supported document found!');
123
124 if (strstr($sfile, '://')) header("location: {$sfile}");
125 else
126 FileSystem::downloadFile($sfile, basename($sfile));
127 die();
128 }
129 }
130
131 function addWriteRules()
132 {
133 global $wp_rewrite;
134 $udb_page_id = get_option('__wpdm_user_dashboard', 0);
135 if ($udb_page_id) {
136 $page_name = get_post_field("post_name", $udb_page_id);
137 add_rewrite_rule('^' . $page_name . '/(.+)/?', 'index.php?page_id=' . $udb_page_id . '&udb_page=$matches[1]', 'top');
138 //dd($wp_rewrite);
139 }
140 $adb_page_id = get_option('__wpdm_author_dashboard', 0);
141
142 if ($adb_page_id) {
143 $page_name = get_post_field("post_name", $adb_page_id);
144 add_rewrite_rule('^' . $page_name . '/(.+)/?', 'index.php?page_id=' . $adb_page_id . '&adb_page=$matches[1]', 'top');
145 }
146
147 $ap_page_id = get_option('__wpdm_author_profile', 0);
148
149 if ($ap_page_id) {
150 $page_name = get_post_field("post_name", $ap_page_id);
151 add_rewrite_rule('^' . $page_name . '/(.+)/?$', 'index.php?pagename=' . $page_name . '&profile=$matches[1]', 'top');
152 }
153
154 //wpdmdd($wp_rewrite);
155 //add_rewrite_rule('^wpdmdl/([0-9]+)/?', 'index.php?wpdmdl=$matches[1]', 'top');
156 //add_rewrite_rule('^wpdmdl/([0-9]+)/ind/([^\/]+)/?', 'index.php?wpdmdl=$matches[1]&ind=$matches[2]', 'top');
157 //if(is_404()) dd('404');
158 //$wp_rewrite->flush_rules();
159 //dd($wp_rewrite);
160 }
161
162 function flashRules()
163 {
164 $this->addWriteRules();
165 global $wp_rewrite;
166 $wp_rewrite->flush_rules();
167 }
168
169 function wpdmproTemplates($template){
170 $_template = basename($template);
171 $style_global = get_option('__wpdm_cpage_style', 'basic');
172 $style = get_term_meta(get_queried_object_id(), '__wpdm_style', true);
173 $style = in_array($style, ['basic', 'ltpl']) ? $style : $style_global;
174 if($style === 'ltpl' && (is_tax('wpdmcategory') || is_post_type_archive('wpdmpro'))){
175 $template = Template::locate("taxonomy-wpdmcategory.php", WPDM_TPL_FALLBACK, WPDM_TPL_FALLBACK);
176 }
177 /*if($_template !== 'single-wpdmpro.php' && is_singular('wpdmpro')){
178 $template = Template::locate("single-wpdmpro.php", WPDM_TPL_FALLBACK, WPDM_TPL_FALLBACK);
179 }*/
180 return $template;
181 }
182
183 function dashboardPages($post_id)
184 {
185 if (wp_is_post_revision($post_id)) return;
186 if (get_post_type($post_id) !== 'page') return;
187 $page_id = get_option('__wpdm_user_dashboard', 0);
188 $post = get_post($post_id);
189 $flush = 0;
190
191 //If no dashboard page is selected ( $page_id === 0 )
192 // And current page is dashboard shorotcode
193 if ((int)$page_id === 0 && has_shortcode($post->post_content, "wpdm_user_dashboard")) {
194 update_option('__wpdm_user_dashboard', $post_id);
195 $flush = 1;
196 }
197
198 $page_id = get_option('__wpdm_author_profile', 0);
199
200 if ((int)$page_id === 0 && has_shortcode($post->post_content, "wpdm_user_profile")) {
201 update_option('__wpdm_author_profile', $post_id);
202 $flush = 1;
203 }
204
205 if ($flush == 1) {
206 $this->addWriteRules();
207 global $wp_rewrite;
208 $wp_rewrite->flush_rules();
209 }
210
211 }
212
213 function dashboardPageVars($vars)
214 {
215 array_push($vars, 'udb_page', 'adb_page', 'page_id', 'wpdmdl', 'ind', 'profile', 'wpdm_asset_key');
216 return $vars;
217 }
218
219
220 /**
221 * @usage Process Download Request from lock options
222 */
223 function triggerDownload()
224 {
225
226 global $wpdb, $current_user, $wp_query;
227 if (preg_match("/\/wpdmdl\/([\d]+)-([^\/]+)\/(.+)/", $_SERVER['REQUEST_URI'])) {
228 $uri = trim(__::valueof($_SERVER, 'REQUEST_URI', ['validate' => 'txt']), '/');
229 $download_url_base = get_option('__wpdm_download_url_base', 'download');
230 $uri = explode("/" . $download_url_base . "/", $uri);
231 $parts = explode("/", $uri[1]);
232 $parts = explode("-", $parts[0]);
233 $_REQUEST['wpdmdl'] = $_GET['wpdmdl'] = (int)$parts[0];
234 $wp_query->query_vars['wpdmdl'] = (int)$parts[0];
235 $parts = json_decode(base64_decode($parts[1]));
236 if (is_array($parts)) {
237 foreach ($parts as $key => $val) {
238 $_REQUEST[$key] = $_GET[$key] = sanitize_text_field($val);
239 }
240 }
241 }
242
243 //Instant download link processing
244 if (isset($_GET['wpdmidl'])) {
245 $file = TempStorage::get("__wpdm_instant_download_" . wpdm_query_var('wpdmidl'));
246 if (!$file)
247 Messages::error(__("Download ID not found or expired", "download-manager"), 1);
248 if (!file_exists($file))
249 Messages::error(__("The file is already removed from the server!", "download-manager"), 1);
250
251 FileSystem::downloadFile($file, wpdm_basename($file));
252 die();
253 }
254
255 //Regular download processing
256 if (!isset($wp_query->query_vars['wpdmdl']) && !isset($_GET['wpdmdl'])) return;
257
258
259 $id = isset($_GET['wpdmdl']) ? (int)$_GET['wpdmdl'] : (int)$wp_query->query_vars['wpdmdl'];
260 if ($id <= 0) return;
261
262
263 //Master key validation
264 $masterKey = wpdm_query_var('masterkey');
265 $hasMasterKey = $masterKey !== '' ? true : false;
266 $isMasterKeyValid = WPDM()->package->validateMasterKey($id, $masterKey);
267 $isMaster = $hasMasterKey && $isMasterKeyValid;
268
269 //Temporary download key validation
270 $key = wpdm_query_var('_wpdmkey');
271 $key = $key == '' && array_key_exists('_wpdmkey', $wp_query->query_vars) ? $wp_query->query_vars['_wpdmkey'] : $key;
272 $key = preg_replace("/[^_a-z|A-Z|0-9]/i", "", $key);
273
274 $keyValid = 0;
275
276 if ($key) {
277 $keyValid = is_wpdmkey_valid($id, $key, true);
278
279 if ((int)$keyValid !== 1) {
280 Messages::error(__("&mdash; Invalid download link &mdash;", "download-manager"), 1);
281 }
282 }
283
284
285 if (WPDM()->package->isLocked($id) && !$keyValid && !$isMaster)
286 Messages::error(__("&mdash; You are not allowed to download &mdash;", "download-manager"), 1);
287
288
289 //$package = get_post($id, ARRAY_A);
290 $package = WPDM()->package->init($id);
291 $package = (array)$package;
292 $package['access'] = WPDM()->package->allowedRoles($id);
293
294 $package = apply_filters("wpdm_before_download", $package);
295
296 if ($isMaster || $keyValid) {
297 $package['access'] = array('guest');
298 }
299
300 if(!is_user_logged_in() && get_post_status($id) !== 'publish') {
301 Messages::error( __( '403 - Access Forbidden!', 'download-manager' ), 1 );
302 }
303
304 $matched = (is_array(@maybe_unserialize($package['access'])) && is_user_logged_in()) ? array_intersect($current_user->roles, @maybe_unserialize($package['access'])) : array();
305
306
307 if ((($id != '' && is_user_logged_in() && count($matched) < 1 && !@in_array('guest', $package['access'])) || (!is_user_logged_in() && !@in_array('guest', $package['access']) && $id != ''))) {
308 do_action("wpdm_download_permission_denied", $id);
309 wpdm_download_data("permission-denied.txt", __("You don't have permission to download this file", "download-manager"));
310 die();
311 } else {
312 if ($package['ID'] > 0) {
313
314 if ((int)$package['quota'] == 0 || $package['quota'] > $package['download_count']) {
315 $package['force_download'] = wpdm_query_var('_wpdmkey');
316 include(WPDM_BASE_DIR . "src/wpdm-start-download.php");
317 } else
318 wpdm_download_data("stock-limit-reached.txt", __("Stock Limit Reached", "download-manager"));
319
320 }
321
322 }
323 }
324
325
326 /**
327 * @usage Add with main RSS feed
328 * @param $query
329 * @return mixed
330 */
331 function rssFeed($query)
332 {
333 if (isset($query['feed']) && !isset($query['post_type']) && get_option('__wpdm_rss_feed_main', 0) == 1) {
334 $query['post_type'] = array('post', 'wpdmpro');
335 }
336 return $query;
337 }
338
339 /**
340 * @usage Schedule custom ping
341 * @param $post_id
342 */
343 function customPings($post_id)
344 {
345 wp_schedule_single_event(time() + 5000, 'do_pings', array($post_id));
346 }
347
348 /**
349 * @usage Allow access to server file browser for selected user roles
350 */
351 function sfbAccess()
352 {
353
354 global $wp_roles;
355 if (!is_array($wp_roles->roles)) return;
356 $roleids = array_keys($wp_roles->roles);
357 $roles = get_option('_wpdm_file_browser_access', array('administrator'));
358 $naroles = array_diff($roleids, $roles);
359 foreach ($roles as $role) {
360 $role = get_role($role);
361 if (is_object($role) && !is_wp_error($role))
362 $role->add_cap('access_server_browser');
363 }
364
365 foreach ($naroles as $role) {
366 $role = get_role($role);
367 if (is_object($role) && !is_wp_error($role) && in_array('access_server_browser', $role->capabilities)) {
368 $role->remove_cap('access_server_browser');
369 }
370 }
371
372 }
373
374 /**
375 * @usage Validate individual file password
376 */
377 function checkFilePassword()
378 {
379 if (isset($_POST['actioninddlpvr'], $_POST['wpdmfileid']) && $_POST['actioninddlpvr'] != '') {
380 $limit = get_option('__wpdm_private_link_usage_limit', 3);
381 $fileid = wpdm_query_var('wpdmfileid', 'int');
382 $filepass = wpdm_query_var('filepass', 'escs');
383 $data = get_post_meta(wpdm_query_var('wpdmfileid', 'int'), '__wpdm_fileinfo', true);
384 $data = $data ? $data : array();
385 $package = get_post($fileid);
386 $packagemeta = wpdm_custom_data($fileid);
387 $password = isset($data[$fileid]['password']) && $data[$fileid]['password'] != "" ? $data[$fileid]['password'] : $packagemeta['password'];
388 $pu = isset($packagemeta['password_usage']) && is_array($packagemeta['password_usage']) ? $packagemeta['password_usage'] : array();
389 if ($filepass !== '' && $password == $filepass || substr_count($password, "[{$filepass}]") > 0) {
390 $pul = $packagemeta['password_usage_limit'];
391 if (is_array($pu) && isset($pu[$password]) && $pu[$password] >= $pul && $pul > 0) {
392 $data['error'] = __("Password usages limit exceeded", "download-manager");
393 die('|error|');
394 } else {
395 if (!is_array($pu)) $pu = array();
396 $pu[$password] = isset($pu[$password]) ? $pu[$password] + 1 : 1;
397 update_post_meta($fileid, '__wpdm_password_usage', $pu);
398 }
399
400
401 $_data['error'] = '';
402 $_data['downloadurl'] = WPDM()->package->expirableDownloadLink($fileid);
403 $_data['downloadurl'] .= "&ind=" . wpdm_query_var('wpdmfile');
404 wp_send_json($_data);
405
406 } else
407 wp_send_json(array('error' => __("Invalid password", "download-manager"), 'downloadurl' => ''));
408 }
409 }
410
411 /**
412 * @usage Allow front-end users to access their own files only
413 * @param $query_params
414 * @return string
415 */
416 function usersMediaQuery($query_params)
417 {
418 global $current_user;
419
420 if (current_user_can('edit_posts')) return $query_params;
421
422 if (is_user_logged_in()) {
423 $query_params['author'] = $current_user->ID;
424 }
425 return $query_params;
426 }
427
428 /**
429 * @usage Add packages wth tag query
430 * @param $query
431 * @return mixed
432 */
433 function queryTag($query)
434 {
435
436 if ($query->is_tag() && $query->is_main_query()) {
437 $post_type = get_query_var('post_type');
438 if (!is_array($post_type))
439 $post_type = array('post', 'page', 'wpdmpro', 'nav_menu_item');
440 else
441 $post_type = array_merge($post_type, array('post', 'wpdmpro', 'nav_menu_item'));
442 $query->set('post_type', $post_type);
443 }
444 return $query;
445 }
446
447 /**
448 * Empty cache dir
449 */
450 function clearCache()
451 {
452 __::isAuthentic('ccnonce', WPDM_PRI_NONCE, 'manage_options');
453 FileSystem::deleteFiles(WPDM_CACHE_DIR, false);
454 FileSystem::deleteFiles(WPDM_CACHE_DIR . 'pdfthumbs/', false);
455 global $wpdb;
456 Session::reset();
457 TempStorage::clear();
458 die('ok');
459 }
460
461 /**
462 * Delete all download hostory
463 */
464 function clearStats()
465 {
466 __::isAuthentic('csnonce', WPDM_PRI_NONCE, 'manage_options');
467 global $wpdb;
468 $wpdb->query('truncate table ' . $wpdb->prefix . 'ahm_download_stats');
469 $wpdb->query('truncate table ' . $wpdb->prefix . 'ahm_user_download_counts');
470 $wpdb->query("delete from {$wpdb->prefix}postmeta where meta_key='__wpdmx_user_download_count'");
471 die('ok');
472 }
473
474
475 /**
476 * @usage Add generator tag
477 */
478 function addGenerator()
479 {
480 echo '<meta name="generator" content="WordPress Download Manager ' . WPDM_VERSION . '" />' . "\r\n";
481 }
482
483 function oEmbed($content)
484 {
485 if (get_post_type(get_the_ID()) !== 'wpdmpro') return $content;
486 if (function_exists('wpdmpp_effective_price') && wpdmpp_effective_price(get_the_ID()) > 0)
487 $template = '<table class="table table-bordered"><tbody><tr><td colspan="2">[excerpt_200]</td></tr><tr><td>[txt=Price]</td><td>[currency][effective_price]</td></tr><tr><td>[txt=Version]</td><td>[version]</td></tr><tr><td>[txt=Total Files]</td><td>[file_count]</td></tr><tr><td>[txt=File Size]</td><td>[file_size]</td></tr><tr><td>[txt=Create Date]</td><td>[create_date]</td></tr><tr><td>[txt=Last Updated]</td><td>[update_date]</td><tr><td colspan="2" style="text-align: right;border-bottom: 0"><a class="wpdmdlbtn" href="[page_url]" target="_parent">[txt=Buy Now]</a></td></tr></tbody></table><br/><style> .wpdmdlbtn {-moz-box-shadow:inset 0px 1px 0px 0px #9acc85;-webkit-box-shadow:inset 0px 1px 0px 0px #9acc85;box-shadow:inset 0px 1px 0px 0px #9acc85;background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #74ad5a), color-stop(1, #68a54b));background:-moz-linear-gradient(top, #74ad5a 5%, #68a54b 100%);background:-webkit-linear-gradient(top, #74ad5a 5%, #68a54b 100%);background:-o-linear-gradient(top, #74ad5a 5%, #68a54b 100%);background:-ms-linear-gradient(top, #74ad5a 5%, #68a54b 100%);background:linear-gradient(to bottom, #74ad5a 5%, #68a54b 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#74ad5a\', endColorstr=\'#68a54b\',GradientType=0);background-color:#74ad5a;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;border:1px solid #3b6e22;display:inline-block;cursor:pointer;color:#ffffff !important; font-size:12px;font-weight:bold;padding:10px 20px;text-transform: uppercase;text-decoration:none !important;}.wpdmdlbtn:hover {background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #68a54b), color-stop(1, #74ad5a));background:-moz-linear-gradient(top, #68a54b 5%, #74ad5a 100%);background:-webkit-linear-gradient(top, #68a54b 5%, #74ad5a 100%);background:-o-linear-gradient(top, #68a54b 5%, #74ad5a 100%);background:-ms-linear-gradient(top, #68a54b 5%, #74ad5a 100%);background:linear-gradient(to bottom, #68a54b 5%, #74ad5a 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#68a54b\', endColorstr=\'#74ad5a\',GradientType=0);background-color:#68a54b;}.wpdmdlbtn:active {position:relative;top:1px;} .table{width:100%;border: 1px solid #eeeeee;} .table td{ padding:10px;border-bottom:1px solid #eee;}</style>';
488 else
489 $template = '<table class="table table-bordered"><tbody><tr><td colspan="2">[excerpt_200]</td></tr><tr><td>[txt=Version]</td><td>[version]</td></tr><tr><td>[txt=Total Files]</td><td>[file_count]</td></tr><tr><td>[txt=File Size]</td><td>[file_size]</td></tr><tr><td>[txt=Create Date]</td><td>[create_date]</td></tr><tr><td>[txt=Last Updated]</td><td>[update_date]</td><tr><td colspan="2" style="text-align: right;border-bottom: 0"><a class="wpdmdlbtn" href="[page_url]" target="_parent">[txt=Download]</a></td></tr></tbody></table><br/><style> .wpdmdlbtn {-moz-box-shadow:inset 0px 1px 0px 0px #9acc85;-webkit-box-shadow:inset 0px 1px 0px 0px #9acc85;box-shadow:inset 0px 1px 0px 0px #9acc85;background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #74ad5a), color-stop(1, #68a54b));background:-moz-linear-gradient(top, #74ad5a 5%, #68a54b 100%);background:-webkit-linear-gradient(top, #74ad5a 5%, #68a54b 100%);background:-o-linear-gradient(top, #74ad5a 5%, #68a54b 100%);background:-ms-linear-gradient(top, #74ad5a 5%, #68a54b 100%);background:linear-gradient(to bottom, #74ad5a 5%, #68a54b 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#74ad5a\', endColorstr=\'#68a54b\',GradientType=0);background-color:#74ad5a;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;border:1px solid #3b6e22;display:inline-block;cursor:pointer;color:#ffffff !important; font-size:12px;font-weight:bold;padding:10px 20px;text-transform: uppercase;text-decoration:none !important;}.wpdmdlbtn:hover {background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #68a54b), color-stop(1, #74ad5a));background:-moz-linear-gradient(top, #68a54b 5%, #74ad5a 100%);background:-webkit-linear-gradient(top, #68a54b 5%, #74ad5a 100%);background:-o-linear-gradient(top, #68a54b 5%, #74ad5a 100%);background:-ms-linear-gradient(top, #68a54b 5%, #74ad5a 100%);background:linear-gradient(to bottom, #68a54b 5%, #74ad5a 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#68a54b\', endColorstr=\'#74ad5a\',GradientType=0);background-color:#68a54b;}.wpdmdlbtn:active {position:relative;top:1px;} .table{width:100%; border: 1px solid #eeeeee; } .table td{ padding:10px;border-bottom:1px solid #eee;}</style>';
490 return WPDM()->package->fetchTemplate($template, get_the_ID());
491 }
492
493 function showLockOptions()
494 {
495 if (!isset($_REQUEST['id'])) die('ID Missing!');
496 echo WPDM()->package->downloadLink(wpdm_query_var('id', 'int'), 1);
497 die();
498 }
499
500
501 function verifyEmail($errors, $sanitized_user_login, $user_email)
502 {
503 if (!$errors) $errors = new \WP_Error();
504 if (!wpdm_verify_email($user_email)) {
505 $emsg = get_option('__wpdm_blocked_domain_msg');
506 if (trim($emsg) === '') $emsg = __('Your email address is blocked!', 'download-manager');
507 $errors->add('blocked_email', $emsg);
508 }
509 return $errors;
510 }
511
512 function verifyLoginEmail($user, $user_login, $user_pass)
513 {
514
515 $user_email = null;
516 if(!is_email($user_login) && !$user) {
517 $_user = get_user_by('user_login', $user_login);
518 if($_user)
519 $user_email = $_user->user_email;
520 } else if(is_email($user_login))
521 $user_email = $user_login;
522 else if($user && isset($user->user_email))
523 $user_email = $user->user_email;
524
525 if (is_email($user_email) && !wpdm_verify_email($user_email)) {
526 $user = new \WP_Error();
527 $emsg = get_option('__wpdm_blocked_domain_msg');
528 if (trim($emsg) === '') $emsg = __('Your email address is blocked!', 'download-manager');
529 $user->add('blocked_email', $emsg);
530 }
531 return $user;
532 }
533
534
535 function validateLoginPage($content)
536 {
537 if (is_singular('page')) {
538 $id = get_option('__wpdm_login_url', 0);
539 if ($id > 0 && $id == get_the_ID()) {
540 if (!has_shortcode($content, 'wpdm_login_form') && !has_shortcode($content, 'wpdm_user_dashboard') && !has_shortcode($content, 'wpdm_author_dashboard')) {
541 $content = WPDM()->user->login->form();
542 }
543 }
544 }
545 return $content;
546
547 }
548
549 function removeCommentFeed($feed)
550 {
551 if (get_post_type() == 'wpdmpro' && get_option('__wpdm_has_archive', false) == false)
552 $feed = false;
553 return $feed;
554 }
555
556 function wpHead(){
557
558 self::googleFont();
559
560 }
561
562 static function googleFont()
563 {
564 $wpdmss = maybe_unserialize(get_option('__wpdm_disable_scripts', array()));
565 $uicolors = maybe_unserialize(get_option('__wpdm_ui_colors', array()));
566 //$ltemplates = maybe_unserialize(get_option("_fm_link_templates", true));
567 //$ptemplates = maybe_unserialize(get_option("_fm_page_templates", true));
568 $font = get_option( '__wpdm_google_font', 'Sen' );
569 $font = explode( ":", $font );
570 $font = str_replace("+", " ", $font[0]);
571 $font = $font ? "{$font}" : '';
572 $font = $font ? "{$font}" : '-apple-system';
573
574 $css = WPDM()->packageTemplate->getStyles('link');
575
576 ?>
577 <?php if ((int)get_option('__wpdm_enable_gf', 0) === 1 && get_option('__wpdm_google_font') !== '') { ?>
578 <link href="https://fonts.googleapis.com/css2?family=<?php echo get_option('__wpdm_google_font', 'Sen'); ?>"
579 rel="stylesheet">
580 <style>
581 .w3eden .fetfont,
582 .w3eden .btn,
583 .w3eden .btn.wpdm-front h3.title,
584 .w3eden .wpdm-social-lock-box .IN-widget a span:last-child,
585 .w3eden #xfilelist .panel-heading,
586 .w3eden .wpdm-frontend-tabs a,
587 .w3eden .alert:before,
588 .w3eden .panel .panel-heading,
589 .w3eden .discount-msg,
590 .w3eden .panel.dashboard-panel h3,
591 .w3eden #wpdm-dashboard-sidebar .list-group-item,
592 .w3eden #package-description .wp-switch-editor,
593 .w3eden .w3eden.author-dashbboard .nav.nav-tabs li a,
594 .w3eden .wpdm_cart thead th,
595 .w3eden #csp .list-group-item,
596 .w3eden .modal-title {
597 font-family: "<?php echo __::sanitize_var($font); ?>", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
598 text-transform: uppercase;
599 font-weight: 700;
600 }
601 .w3eden #csp .list-group-item {
602 text-transform: unset;
603 }
604
605
606 </style>
607 <?php } ?>
608 <style>
609 <?php
610 echo '/* WPDM Link Template Styles */';
611 echo wpdm_escs($css);
612 ?>
613 </style>
614 <?php
615 self::uiColors();
616
617 }
618
619 static function uiColors($override_option = true)
620 {
621
622 $wpdmss = maybe_unserialize(get_option('__wpdm_disable_scripts', array()));
623 if (is_array($wpdmss) && in_array('wpdm-front', $wpdmss) && !is_admin()) return;
624
625 $uicolors = maybe_unserialize(get_option('__wpdm_ui_colors', array()));
626 $primary = isset($uicolors['primary']) ? $uicolors['primary'] : '#4a8eff';
627 $secondary = isset($uicolors['secondary']) ? $uicolors['secondary'] : '#4a8eff';
628 $success = isset($uicolors['success']) ? $uicolors['success'] : '#18ce0f';
629 $info = isset($uicolors['info']) ? $uicolors['info'] : '#2CA8FF';
630 $warning = isset($uicolors['warning']) ? $uicolors['warning'] : '#f29e0f';
631 $danger = isset($uicolors['danger']) ? $uicolors['danger'] : '#ff5062';
632 $font = get_option( '__wpdm_google_font', 'Sen' );
633 $font = explode( ":", $font );
634 $font = $font[0];
635 $font = $font ? "{$font}" : '';
636 $font = $font ? "{$font}" : '-apple-system';
637 if (is_singular('wpdmpro'))
638 $ui_button = get_option('__wpdm_ui_download_button');
639 else
640 $ui_button = get_option('__wpdm_ui_download_button_sc');
641 $class = ".btn." . (isset($ui_button['color']) ? $ui_button['color'] : 'btn-primary') . (isset($ui_button['size']) && $ui_button['size'] != '' ? "." . $ui_button['size'] : '');
642
643 ?>
644 <style>
645
646 :root {
647 --color-primary: <?php echo esc_attr($primary); ?>;
648 --color-primary-rgb: <?php echo esc_attr(wpdm_hex2rgb($primary)); ?>;
649 --color-primary-hover: <?php echo esc_attr( isset($uicolors['primary'])?$uicolors['primary_hover']:'#4a8eff' ); ?>;
650 --color-primary-active: <?php echo esc_attr( isset($uicolors['primary'])?$uicolors['primary_active']:'#4a8eff' ); ?>;
651 --clr-sec: <?php echo $secondary; ?>;
652 --clr-sec-rgb: <?php echo wpdm_hex2rgb($secondary); ?>;
653 --clr-sec-hover: <?php echo isset($uicolors['secondary'])?$uicolors['secondary_hover']:'#4a8eff'; ?>;
654 --clr-sec-active: <?php echo isset($uicolors['secondary'])?$uicolors['secondary_active']:'#4a8eff'; ?>;
655 --color-secondary: <?php echo esc_attr( $secondary ); ?>;
656 --color-secondary-rgb: <?php echo esc_attr(wpdm_hex2rgb($secondary)); ?>;
657 --color-secondary-hover: <?php echo esc_attr( isset($uicolors['secondary'])?$uicolors['secondary_hover']:'#4a8eff' ); ?>;
658 --color-secondary-active: <?php echo esc_attr( isset($uicolors['secondary'])?$uicolors['secondary_active']:'#4a8eff' ); ?>;
659 --color-success: <?php echo esc_attr( $success ); ?>;
660 --color-success-rgb: <?php echo esc_attr(wpdm_hex2rgb($success)); ?>;
661 --color-success-hover: <?php echo esc_attr( isset($uicolors['success_hover'])?$uicolors['success_hover']:'#4a8eff' ); ?>;
662 --color-success-active: <?php echo esc_attr( isset($uicolors['success_active'])?$uicolors['success_active']:'#4a8eff' ); ?>;
663 --color-info: <?php echo esc_attr( $info ); ?>;
664 --color-info-rgb: <?php echo esc_attr(wpdm_hex2rgb($info)); ?>;
665 --color-info-hover: <?php echo esc_attr( isset($uicolors['info_hover'])?$uicolors['info_hover']:'#2CA8FF' ); ?>;
666 --color-info-active: <?php echo esc_attr( isset($uicolors['info_active'])?$uicolors['info_active']:'#2CA8FF' ); ?>;
667 --color-warning: <?php echo esc_attr( $warning ); ?>;
668 --color-warning-rgb: <?php echo esc_attr(wpdm_hex2rgb($warning)); ?>;
669 --color-warning-hover: <?php echo esc_attr( isset($uicolors['warning_hover'])?$uicolors['warning_hover']:'orange' ); ?>;
670 --color-warning-active: <?php echo esc_attr( isset($uicolors['warning_active'])?$uicolors['warning_active']:'orange' ); ?>;
671 --color-danger: <?php echo esc_attr( $danger ); ?>;
672 --color-danger-rgb: <?php echo esc_attr(wpdm_hex2rgb($danger)); ?>;
673 --color-danger-hover: <?php echo esc_attr( isset($uicolors['danger_hover'])?$uicolors['danger_hover']:'#ff5062' ); ?>;
674 --color-danger-active: <?php echo esc_attr( isset($uicolors['danger_active'])?$uicolors['danger_active']:'#ff5062' ); ?>;
675 --color-green: <?php echo esc_attr( isset($uicolors['green'])?$uicolors['green']:'#30b570' ); ?>;
676 --color-blue: <?php echo esc_attr( isset($uicolors['blue'])?$uicolors['blue']:'#0073ff' ); ?>;
677 --color-purple: <?php echo esc_attr( isset($uicolors['purple'])?$uicolors['purple']:'#8557D3' ); ?>;
678 --color-red: <?php echo esc_attr( isset($uicolors['red'])?$uicolors['red']:'#ff5062' ); ?>;
679 --color-muted: rgba(69, 89, 122, 0.6);
680 --wpdm-font: "<?php echo esc_attr( $font ); ?>", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
681 }
682
683 .wpdm-download-link<?php echo sanitize_text_field($class); ?> {
684 border-radius: <?php echo (int)( isset($ui_button['borderradius']) ? $ui_button['borderradius'] : 4 ); ?>px;
685 }
686
687
688 </style>
689 <?php
690
691 }
692
693
694
695 /**
696 * @usage Password generator
697 */
698 function generatePassword()
699 {
700 if (!current_user_can(WPDM_MENU_ACCESS_CAP) || !wpdm_is_ajax()) die();
701 include(Template::locate('generate-password.php', __DIR__.'/views'));
702 die();
703
704 }
705
706 /**
707 * Allow <style> tag in wp_kses_post filter.
708 *
709 * @param array $allowed_tags Allowed HTML tags and attributes.
710 * @param string $context The context for which to retrieve tags.
711 * @return array Modified allowed tags.
712 */
713 function allowStyleTagInKses( $allowed_tags, $context ) {
714 if ( 'post' !== $context ) {
715 return $allowed_tags;
716 }
717
718 $allowed_tags['style'] = array(
719 'type' => true,
720 'media' => true,
721 'nonce' => true,
722 'id' => true,
723 'class' => true,
724 );
725
726 return $allowed_tags;
727 }
728
729 /**
730 * @usage Active premium package add-on / shopping cart
731 */
732 function activatePremiumPackage()
733 {
734 __::isAuthentic('wpdmappnonce', WPDM_PRI_NONCE, WPDM_ADMIN_CAP);
735
736 if (current_user_can(WPDM_ADMIN_CAP)) {
737 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
738 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
739 $upgrader = new \Plugin_Upgrader(new \Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api')));
740 $downloadlink = 'https://downloads.wordpress.org/plugin/wpdm-premium-packages.zip';
741 ob_start();
742 echo "<div id='acto'>";
743 if (file_exists(dirname(dirname(__FILE__)) . '/wpdm-premium-packages/'))
744 $upgrader->upgrade($downloadlink);
745 else
746 $upgrader->install($downloadlink);
747 echo '</div><style>#acto .wrap { display: none; }</style>';
748 $data = ob_get_clean();
749 if (file_exists(dirname(WPDM_BASE_DIR) . '/wpdm-premium-packages/wpdm-premium-packages.php')) {
750 activate_plugin('wpdm-premium-packages/wpdm-premium-packages.php');
751 echo "Congratulation! Your Digital Store is Activated. <a href='' class='btn btn-warning'>Refresh The Page!</a>";
752 } else
753 echo "Automatic Installation Failed! Please <a href='".admin_url('plugin-install.php?tab=plugin-information&plugin=wpdm-premium-packages')."' target='_blank' class='btn btn-warning'>Download</a> and install manually";
754 die();
755 } else {
756 die("Only site admin is authorized to install add-on");
757 }
758 }
759
760
761 }
762
763