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 / Admin / Menu / Templates.php
download-manager / src / Admin / Menu Last commit date
AddOns.php 5 years ago Categories.php 3 years ago Packages.php 1 week ago Settings.php 5 months ago Stats.php 4 years ago Templates.php 2 years ago Welcome.php 6 months ago
Templates.php
248 lines
1 <?php
2
3 namespace WPDM\Admin\Menu;
4
5
6 use WPDM\__\__;
7 use WPDM\__\Crypt;
8 use WPDM\__\Template;
9
10 class Templates
11 {
12
13 function __construct()
14 {
15 add_filter('init', array($this, 'livePreview'), 99 );
16 add_filter('wdm_before_fetch_template', array($this, 'introduceCustomTags'), 99, 3 );
17 //add_action('admin_init', array($this, 'Save'));
18 add_action('wp_ajax_template_preview', array($this, 'preview'));
19 add_action('wp_ajax_wpdm_save_email_template', array($this, 'saveEmailTemplate'));
20 add_action('wp_ajax_update_template_status', array($this, 'updateTemplateStatus'));
21 add_action('wp_ajax_wpdm_save_email_setting', array($this, 'saveEmailSetting'));
22 add_action('wp_ajax_connect_template_server', array($this, 'templateServer'));
23 add_action('admin_menu', array($this, 'menu'));
24 }
25
26 function livePreview(){
27 if(wpdm_query_var('template_preview') !== '') {
28 __::isAuthentic('_tplnonce', NONCE_KEY, WPDM_ADMIN_CAP);
29 add_filter( 'show_admin_bar', '__return_false' );
30 $page_template = Template::locate('template-preview.php', WPDM_SRC_DIR.'__/views');
31 $type = wpdm_query_var('_type');
32 global $post;
33 if(wpdm_query_var('pid'))
34 $package = get_post(wpdm_query_var('pid'), ARRAY_A);
35 else {
36 $package = get_posts(array('post_type' => 'wpdmpro', 'posts_per_page' => 1, 'post_status' => 'publish'));
37 $package = (array)$package[0];
38 }
39 $template = Crypt::decrypt(wpdm_query_var('template_preview'));
40 $template = stripslashes_deep(str_replace(array("\r", "\n"), "", html_entity_decode(urldecode($template))));
41 $output = wpdm_fetch_template($template, $package, $type);
42 $template = "<div class='w3eden' style='max-width: 900px;margin: 20px auto !important;padding: 40px;'>{$output}</div><script> jQuery(function($) { var body = document.body, html = document.documentElement; var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); window.parent.wpdmifh(height); });</script>";
43 include $page_template;
44 die();
45 }
46 }
47
48 function menu()
49 {
50 add_submenu_page('edit.php?post_type=wpdmpro', __( "Templates &lsaquo; Download Manager" , "download-manager" ), __( "Templates" , "download-manager" ), WPDM_MENU_ACCESS_CAP, 'templates', array($this, 'UI'));
51 }
52
53 function UI(){
54 $ttype = isset($_GET['_type']) ? wpdm_query_var('_type') : 'link';
55
56 if (isset($_GET['task']) && ($_GET['task'] == 'EditTemplate' || $_GET['task'] == 'NewTemplate'))
57 Templates::editor();
58 else if (isset($_GET['task']) && $_GET['task'] == 'EditEmailTemplate')
59 Templates::emailEditor();
60 else
61 Templates::Show();
62 }
63
64
65 public static function editor(){
66 include wpdm_admin_tpl_path("templates/template-editor.php");
67 }
68
69
70 public static function emailEditor(){
71 include wpdm_admin_tpl_path("templates/email-template-editor.php");
72 }
73
74
75 public static function Show(){
76 WPDM()->packageTemplate->covertAll()->covertAll('page');
77 include wpdm_admin_tpl_path('templates/templates.php');
78 }
79
80 function saveEmailTemplate(){
81 if (isset($_POST['email_template'])) {
82 __::isAuthentic('__setnonce', WPDM_PRI_NONCE, WPDM_ADMIN_CAP);
83 $email_template = wpdm_query_var('email_template', array('validate' => array('subject' => '', 'message' => 'escs', 'from_name' => '', 'from_email' => '')));
84 update_option("__wpdm_etpl_".wpdm_query_var('id'), $email_template, false);
85 wp_send_json(array('success' => true, 'message' => 'Email Template Saved!'));
86 //header("location: edit.php?post_type=wpdmpro&page=templates&_type=$ttype");
87 die();
88 }
89 }
90
91 /**
92 * @usage Preview link/page template
93 */
94 function preview()
95 {
96
97 $wposts = array();
98 __::isAuthentic('_tplnonce', WPDM_PUB_NONCE, WPDM_ADMIN_CAP);
99 $template = isset($_REQUEST['template'])?wpdm_query_var('template', 'escs'):'';
100 $type = wpdm_query_var("_type");
101 $css = wpdm_query_var("css","txt");
102
103
104 $args=array(
105 'post_type' => 'wpdmpro',
106 'posts_per_page' => 1
107 );
108
109 $wposts = get_posts( $args );
110 $template = stripslashes($template);
111 $template = urlencode($template);
112 $tplnonce = wp_create_nonce(NONCE_KEY);
113 $template_enc = Crypt::encrypt($template);
114 $preview_link = home_url("/?template_preview={$template_enc}&_type={$type}&_tplnonce={$tplnonce}");
115
116 if(count($wposts)==0) $html = "<div class='w3eden'><div class='col-md-12'><div class='alert alert-info'>".__( "No package found! Please create at least 1 package to see template preview" , "download-manager" )."</div> </div></div>";
117 else
118 $html = "<a class='btn btn-link btn-block' href='{$preview_link}' target='_blank'><i class='fa fa-external-link-alt'></i> Preview in a new window</a><iframe id='templateiframe' src='{$preview_link}' style='border: 0;width: 100%;height: 200px;overflow: hidden'></iframe><script>function wpdmifh( h ){ jQuery('#templateiframe').height(h); }</script>";
119
120 echo $html;
121 die();
122
123 }
124
125 public static function dropdown($params, $activeOnly = false)
126 {
127 extract($params);
128 $type = isset($type) && in_array($type, array('link', 'page', 'email')) ? esc_attr($type) : 'link';
129 $tplstatus = maybe_unserialize(get_option("_fm_{$type}_template_status"));
130
131 $xactivetpls = array();
132 $activetpls = array();
133 if(is_array($tplstatus)) {
134 foreach ($tplstatus as $tpl => $active) {
135 if (!$active)
136 $xactivetpls[] = $tpl;
137 else
138 $activetpls[] = $tpl;
139 }
140 }
141
142 $ttpldir = get_stylesheet_directory() . '/download-manager/' . $type . '-templates/';
143 $ttpls = array();
144 if(file_exists($ttpldir)) {
145 $ttpls = scandir($ttpldir);
146 array_shift($ttpls);
147 array_shift($ttpls);
148 }
149
150 $ltpldir = WPDM()->package->templateDir . $type . '-templates/';
151
152 $ctpls = scandir($ltpldir);
153 array_shift($ctpls);
154 array_shift($ctpls);
155
156 foreach($ctpls as $ind => $tpl){
157 $ctpls[$ind] = $ltpldir.$tpl;
158 }
159
160 foreach($ttpls as $tpl){
161 if(!in_array($ltpldir.$tpl, $ctpls)) {
162 $ctpls[] = $ttpldir . $tpl;
163 }
164 }
165
166 //$custom_templates = maybe_unserialize(get_option("_fm_{$type}_templates", array()));
167 $custom_templates = WPDM()->packageTemplate->getCustomTemplates($type);
168 $custom_templates = array_reverse($custom_templates);
169 $name = isset($name)?$name:$type.'_template';
170 $css = isset($css)?"style='$css'":'';
171 $id = isset($id)?$id:uniqid();
172 $default = $type == 'link'?'link-template-default.php':'page-template-default.php';
173 $xdf = str_replace(".php", "", $default);
174 $html = "";
175 if(is_array($xactivetpls) && count($xactivetpls) > 0)
176 $default = (in_array($xdf, $xactivetpls) || in_array($default, $xactivetpls)) && isset($activetpls[0])?$activetpls[0]:$default;
177
178 $html .= "<select name='$name' id='$id' class='form-control template {$type}_template' {$css}><option value='$default'>Select ".ucfirst($type)." Template</option>";
179 $data = array();
180 if(is_array($custom_templates)) {
181 foreach ($custom_templates as $id => $template) {
182 if(!$activeOnly || ($activeOnly && (!isset($tplstatus[$id]) || $tplstatus[$id] == 1))) {
183 $data[$id] = $template['title'];
184 $eselected = isset($selected) && $selected == $id ? 'selected=selected' : '';
185 $html .= "<option value='{$id}' {$eselected}>{$template['title']}</option>";
186 }
187 }
188 }
189 foreach ($ctpls as $ctpl) {
190 $ind = str_replace(".php", "", basename($ctpl));
191 if(!$activeOnly || ($activeOnly && (!isset($tplstatus[$ind]) || $tplstatus[$ind] == 1))) {
192 $tmpdata = file_get_contents($ctpl);
193 $regx = "/WPDM.*Template[\s]*:([^\-\->]+)/";
194 if (preg_match($regx, $tmpdata, $matches)) {
195 $data[basename($ctpl)] = $matches[1];
196 $eselected = isset($selected) && $selected == basename($ctpl) ? 'selected=selected' : '';
197
198 $html .= "<option value='" . basename($ctpl) . "' {$eselected}>{$matches[1]}</option>";
199 }
200 }
201 }
202 $html .= "</select>";
203
204 return isset($data_type) && $data_type == 'ARRAY'? $data : $html;
205 }
206
207 function saveEmailSetting(){
208 __::isAuthentic('__sesnonce', WPDM_PRI_NONCE, WPDM_ADMIN_CAP, true);
209
210 update_option('__wpdm_email_template', wpdm_query_var('__wpdm_email_template'), false);
211 $email_settings = wpdm_query_var('__wpdm_email_setting', array('validate' => array('logo' => 'url', 'banner' => 'url', 'youtube' => 'url', 'twitter' => 'url', 'facebook' => 'url', 'footer_text' => 'txts')));
212 update_option('__wpdm_email_setting', $email_settings, false);
213 die("Done!");
214 }
215
216 function updateTemplateStatus(){
217 __::isAuthentic('tsnonce', WPDM_PRI_NONCE, WPDM_ADMIN_CAP);
218 $type = wpdm_query_var('type', 'txt');
219 $tpldata = maybe_unserialize(get_option("_fm_{$type}_template_status"));
220 $tpldata[wpdm_query_var('template')] = wpdm_query_var('status', 'int');
221 update_option("_fm_{$type}_template_status", $tpldata, false);
222 echo "OK";
223 die();
224 }
225
226 function introduceCustomTags($vars, $template, $type){
227 $upload_dir = wp_upload_dir();
228 $upload_dir = $upload_dir['basedir'];
229 $tags_dir = $upload_dir.'/wpdm-custom-tags/';
230 if(!file_exists($tags_dir)) mkdir($tags_dir, 0755, true);
231 $custom_tags = scandir($tags_dir);
232 foreach ($custom_tags as $custom_tag) {
233 if (strstr($custom_tag, '.tag')) {
234 $content = file_get_contents($tags_dir . $custom_tag);
235 $custom_tag = str_replace(".tag", "", $custom_tag);
236 $vars[$custom_tag] = stripslashes($content);
237 }
238 }
239 return $vars;
240 }
241
242 function templateServer(){
243 wpdmpro_required();
244 die();
245 }
246
247 }
248