PageRenderTime 81ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/system/cp/cp.templates.php

https://github.com/danboy/Croissierd
PHP | 4143 lines | 2890 code | 979 blank | 274 comment | 591 complexity | 51ea15fb5788f46a56557681b0221451 MD5 | raw file
  1. <?php
  2. /*
  3. =====================================================
  4. ExpressionEngine - by EllisLab
  5. -----------------------------------------------------
  6. http://expressionengine.com/
  7. -----------------------------------------------------
  8. Copyright (c) 2003 - 2010 EllisLab, Inc.
  9. =====================================================
  10. THIS IS COPYRIGHTED SOFTWARE
  11. PLEASE READ THE LICENSE AGREEMENT
  12. http://expressionengine.com/docs/license.html
  13. =====================================================
  14. File: cp.templates.php
  15. -----------------------------------------------------
  16. Purpose: The template management functions
  17. =====================================================
  18. */
  19. if ( ! defined('EXT'))
  20. {
  21. exit('Invalid file request');
  22. }
  23. class Templates {
  24. var $template_map = array();
  25. // Reserved Template names
  26. var $reserved_names = array('act', 'css', 'trackback');
  27. // Reserved Global Variable names
  28. var $reserved_vars = array(
  29. 'lang',
  30. 'charset',
  31. 'homepage',
  32. 'debug_mode',
  33. 'gzip_mode',
  34. 'version',
  35. 'elapsed_time',
  36. 'hits',
  37. 'total_queries',
  38. 'XID_HASH'
  39. );
  40. function Templates()
  41. {
  42. global $IN, $DSP, $PREFS;
  43. if ($PREFS->ini("use_category_name") == 'y' AND $PREFS->ini("reserved_category_word") != '')
  44. {
  45. $this->reserved_names[] = $PREFS->ini("reserved_category_word");
  46. }
  47. if ($PREFS->ini("forum_is_installed") == 'y' AND $PREFS->ini("forum_trigger") != '')
  48. {
  49. $this->reserved_names[] = $PREFS->ini("forum_trigger");
  50. }
  51. if ($PREFS->ini("profile_trigger") != '')
  52. {
  53. $this->reserved_names[] = $PREFS->ini("profile_trigger");
  54. }
  55. if ($IN->GBL('tgpref', 'GP') AND $IN->GBL('M') != '')
  56. {
  57. $DSP->url_append = AMP.'tgpref='.$IN->GBL('tgpref', 'GP');
  58. }
  59. switch($IN->GBL('M'))
  60. {
  61. case 'global_variables' : $this->global_variables();
  62. break;
  63. case 'edit_global_var' : $this->edit_global_variable();
  64. break;
  65. case 'update_global_var' : $this->update_global_variable();
  66. break;
  67. case 'delete_global_var' : $this->global_variable_delete_conf();
  68. break;
  69. case 'do_delete_global_var' : $this->delete_global_variable();
  70. break;
  71. case 'new_tg_form' : $this->edit_template_group_form();
  72. break;
  73. case 'edit_tg_form' : $this->edit_template_group_form();
  74. break;
  75. case 'update_tg' : $this->update_template_group();
  76. break;
  77. case 'edit_tg_order' : $this->edit_template_group_order_form();
  78. break;
  79. case 'update_tg_order' : $this->update_template_group_order();
  80. break;
  81. case 'tg_del_conf' : $this->template_group_del_conf();
  82. break;
  83. case 'delete_tg' : $this->template_group_delete();
  84. break;
  85. case 'new_templ_form' : $this->new_template_form();
  86. break;
  87. case 'new_template' : $this->create_new_template();
  88. break;
  89. case 'tmpl_del_conf' : $this->template_del_conf();
  90. break;
  91. case 'delete_template' : $this->delete_template();
  92. break;
  93. case 'edit_template' : $this->edit_template();
  94. break;
  95. case 'update_template' : $this->update_template();
  96. break;
  97. case 'edit_preferences' : $this->edit_preferences();
  98. break;
  99. case 'update_template_prefs' : $this->update_template_prefs();
  100. break;
  101. case 'template_access' : $this->template_access();
  102. break;
  103. case 'update_template_access' : $this->update_template_access();
  104. break;
  105. case 'revision_history' : $this->view_template_revision();
  106. break;
  107. case 'clear_revisions' : $this->clear_revision_history();
  108. break;
  109. case 'export_tmpl' : $this->export_templates_form();
  110. break;
  111. case 'export' : $this->export_templates();
  112. break;
  113. case 'export_template' : $this->export_template();
  114. break;
  115. case 'template_prefs_manager': $this->template_prefs_manager();
  116. break;
  117. case 'update_manager_prefs' : $this->update_manager_prefs();
  118. break;
  119. default : $this->template_manager();
  120. break;
  121. }
  122. }
  123. /* END */
  124. /** -----------------------------
  125. /** Template Preferences Manager
  126. /** -----------------------------*/
  127. function template_prefs_manager($message = '', $group_id = '')
  128. {
  129. global $IN, $DSP, $DB, $SESS, $LANG, $REGX, $PREFS;
  130. if ( ! $DSP->allowed_group('can_admin_templates'))
  131. {
  132. return $DSP->no_access_message();
  133. }
  134. if ($IN->GBL('id') !== FALSE)
  135. {
  136. $group_id = $IN->GBL('id');
  137. }
  138. $user_blog = FALSE;
  139. $DSP->crumbline = TRUE;
  140. if ($SESS->userdata['tmpl_group_id'] != 0)
  141. {
  142. $user_blog = TRUE;
  143. }
  144. /** -------------------------------------
  145. /** Opening Remarks
  146. /** -------------------------------------*/
  147. $DSP->title = $LANG->line('template_preferences_manager');
  148. $DSP->crumb = $LANG->line('template_preferences_manager');
  149. $r = $DSP->qdiv('tableHeading', $LANG->line('template_preferences_manager'));
  150. ob_start();
  151. ?>
  152. <script type="text/javascript">
  153. function showHideTemplate(htmlObj)
  154. {
  155. if (isNaN(htmlObj.value) || htmlObj.value == '') return;
  156. for (var g = 0; g < htmlObj.options.length; g++)
  157. {
  158. if (document.getElementById('template_group_div_' + htmlObj.options[g].value))
  159. {
  160. extTextDiv = document.getElementById('template_group_div_' + htmlObj.options[g].value);
  161. if (htmlObj.options[g].selected == true)
  162. {
  163. if (extTextDiv.style.display != 'block')
  164. {
  165. extTextDiv.style.display = "block";
  166. }
  167. }
  168. else if(extTextDiv.style.display != 'none')
  169. {
  170. extTextDiv.style.display = "none";
  171. }
  172. }
  173. }
  174. }
  175. </script>
  176. <?php
  177. $r .= ob_get_contents();
  178. ob_end_clean();
  179. /** -------------------------------------
  180. /** Retrieve Valid Template Groups and Templates
  181. /** -------------------------------------*/
  182. if ($SESS->userdata['group_id'] != 1 && (sizeof($SESS->userdata['assigned_template_groups']) == 0 OR $DSP->allowed_group('can_admin_templates') == FALSE))
  183. {
  184. $r .= $DSP->qdiv('', $LANG->line('no_templates_assigned'));
  185. return $DSP->body = $r;
  186. }
  187. $sql = "SELECT tg.group_id, tg.group_name, t.template_id, t.template_name
  188. FROM exp_template_groups tg , exp_templates t
  189. WHERE tg.group_id = t.group_id
  190. AND tg.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'";
  191. if ($user_blog === TRUE)
  192. {
  193. $sql .= " AND t.group_id = '".$SESS->userdata['tmpl_group_id']."'";
  194. }
  195. else
  196. {
  197. $sql .= " AND is_user_blog = 'n'";
  198. }
  199. if ($SESS->userdata['group_id'] != 1)
  200. {
  201. $sql .= " AND t.group_id IN (";
  202. foreach ($SESS->userdata['assigned_template_groups'] as $key => $val)
  203. {
  204. $sql .= "'$key',";
  205. }
  206. $sql = substr($sql, 0, -1).")";
  207. }
  208. $sql .= " ORDER BY tg.group_order, t.group_id, t.template_name";
  209. $query = $DB->query($sql);
  210. /** -------------------------------------
  211. /** Nothing?
  212. /** -------------------------------------*/
  213. if ($query->num_rows == 0)
  214. {
  215. $DSP->body .= $DSP->qdiv('alert', $LANG->line('no_templates_available'));
  216. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=templates', $LANG->line('back')));
  217. return;
  218. }
  219. /** -------------------------------------
  220. /** Create Our MultiSelect Lists
  221. /** -------------------------------------*/
  222. $current_group = 0;
  223. $groups = "<select onchange='showHideTemplate(this);' name='template_groups' class='multiselect' size='10' multiple='multiple' style='width:160px'>";
  224. $templates = $DSP->div('default', '', 'template_group_div_'.$query->row['group_id'], '', ($group_id == $query->row['group_id']) ? '' : 'style="display: none; padding:0;"').
  225. $DSP->input_select_header('template_group_'.$query->row['group_id'].'[]', 'y', 8);
  226. foreach ($query->result as $row)
  227. {
  228. if ($row['group_id'] != $current_group)
  229. {
  230. $groups .= $DSP->input_select_option($row['group_id'], $REGX->form_prep($row['group_name']), ($group_id == $row['group_id']) ? 'y' : '');
  231. if ($current_group != 0)
  232. {
  233. $templates .= $DSP->input_select_footer().
  234. $DSP->div_c().
  235. $DSP->div('default', '', 'template_group_div_'.$row['group_id'], '', ($group_id == $row['group_id']) ? '' : 'style="display: none; padding:0;"').
  236. $DSP->input_select_header('template_group_'.$row['group_id'].'[]', 'y', 8);
  237. }
  238. }
  239. $templates .= $DSP->input_select_option($row['template_id'], $REGX->form_prep($row['template_name']), '');
  240. $current_group = $row['group_id'];
  241. }
  242. $groups .= $DSP->input_select_footer();
  243. $templates .= $DSP->input_select_footer().$DSP->div_c();
  244. /** -------------------------------------
  245. /** Templates and Form
  246. /** -------------------------------------*/
  247. $r .= $DSP->form_open(array('action' => 'C=templates'.AMP.'M=update_manager_prefs', 'name' => 'templateManagement', 'id' => 'templateManagement'));
  248. if ($message != '')
  249. {
  250. $r .= $DSP->table('tableBorder', '0', '', '100%')
  251. . $DSP->tr()
  252. . $DSP->table_qcell('tableCellOne', $DSP->qspan('success', $LANG->line('preferences_updated')))
  253. . $DSP->tr_c()
  254. .$DSP->table_c();
  255. }
  256. $r .= $DSP->table('tableBorder', '0', '', '100%')
  257. .$DSP->tr()
  258. .$DSP->table_qcell('tableHeadingAlt', $LANG->line('template_groups'))
  259. .$DSP->table_qcell('tableHeadingAlt', $LANG->line('selected_templates'))
  260. .$DSP->td_c()
  261. .$DSP->tr_c()
  262. .$DSP->tr()
  263. .$DSP->table_qcell('tableCellOne', $groups, '400px', 'top')
  264. .$DSP->table_qcell('tableCellOne', $templates, '400px', 'top')
  265. .$DSP->tr_c()
  266. .$DSP->table_c();
  267. /** -------------------------------------
  268. /** Preferences
  269. /** -------------------------------------*/
  270. $r .= BR.$DSP->table('tableBorder', '0', '', '100%')
  271. .$DSP->tr()
  272. .$DSP->table_qcell('tableHeadingAlt', $LANG->line('type'));
  273. $r .= $DSP->td('tableHeadingAlt', '', '1').$LANG->line('cache_enable').$DSP->td_c();
  274. $r .= $DSP->table_qcell('tableHeadingAlt', $LANG->line('refresh_interval'));
  275. if ($SESS->userdata['group_id'] == 1)
  276. {
  277. $r .= $DSP->td('tableHeadingAlt').$LANG->line('enable_php').$DSP->td_c();
  278. $r .= $DSP->td('tableHeadingAlt').$LANG->line('parse_stage').$DSP->td_c();
  279. }
  280. if ($PREFS->ini('save_tmpl_files') == 'y' AND $PREFS->ini('tmpl_file_basepath') != '')
  281. {
  282. $r .= $DSP->table_qcell('tableHeadingAlt', $LANG->line('save_template_file'));
  283. }
  284. $r .= $DSP->table_qcell('tableHeadingAlt', $LANG->line('hit_counter'));
  285. $r .= $DSP->tr_c();
  286. $r .= $DSP->tr();
  287. $r .= $DSP->td('tableCellOne', '', '1').NBS.$DSP->td_c()
  288. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', ''))
  289. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('refresh_in_minutes')));
  290. if ($SESS->userdata['group_id'] == 1)
  291. {
  292. $r .= $DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', ''))
  293. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', ''));
  294. }
  295. if ($PREFS->ini('save_tmpl_files') == 'y' AND $PREFS->ini('tmpl_file_basepath') != '')
  296. {
  297. $r .= $DSP->td('tableCellOne', '', '1').NBS.$DSP->td_c();
  298. }
  299. $r .= $DSP->td('tableCellOne', '', '1').NBS.$DSP->td_c();
  300. $r .= $DSP->tr_c();
  301. $style = 'tableCellOne';
  302. $r .= $DSP->tr();
  303. $t = $DSP->input_select_header('template_type');
  304. $t .= $DSP->input_select_option('null', $LANG->line('do_not_change'), 1);
  305. $t .= $DSP->input_select_option('css', $LANG->line('css_stylesheet'));
  306. $t .= $DSP->input_select_option('js', $LANG->line('js'));
  307. $t .= $DSP->input_select_option('rss', $LANG->line('rss'));
  308. $t .= $DSP->input_select_option('static', $LANG->line('static'));
  309. $t .= $DSP->input_select_option('webpage', $LANG->line('webpage'));
  310. $t .= $DSP->input_select_option('xml', $LANG->line('xml'));
  311. $t .= $DSP->input_select_footer();
  312. $r .= $DSP->table_qcell($style, $t);
  313. $t = $DSP->input_select_header('cache');
  314. $t .= $DSP->input_select_option('null', $LANG->line('do_not_change'),'');
  315. $t .= $DSP->input_select_option('y', $LANG->line('yes'));
  316. $t .= $DSP->input_select_option('n', $LANG->line('no'));
  317. $t .= $DSP->input_select_footer();
  318. $r .= $DSP->table_qcell($style, $t);
  319. $r .= $DSP->table_qcell($style, $DSP->input_text('refresh', '0', '8', '6', 'input', '50px'));
  320. if ($SESS->userdata['group_id'] == 1)
  321. {
  322. $t = $DSP->input_select_header('allow_php');
  323. $t .= $DSP->input_select_option('null', $LANG->line('do_not_change'),'');
  324. $t .= $DSP->input_select_option('y', $LANG->line('yes'));
  325. $t .= $DSP->input_select_option('n', $LANG->line('no'));
  326. $t .= $DSP->input_select_footer();
  327. $r .= $DSP->table_qcell($style, $t);
  328. $t = $DSP->input_select_header('php_parse_location');
  329. $t .= $DSP->input_select_option('null', $LANG->line('do_not_change'),'');
  330. $t .= $DSP->input_select_option('i', $LANG->line('input'));
  331. $t .= $DSP->input_select_option('o', $LANG->line('output'));
  332. $t .= $DSP->input_select_footer();
  333. $r .= $DSP->table_qcell($style, $t);
  334. }
  335. if ($PREFS->ini('save_tmpl_files') == 'y' AND $PREFS->ini('tmpl_file_basepath') != '')
  336. {
  337. $t = $DSP->input_select_header('save_template_file');
  338. $t .= $DSP->input_select_option('null', $LANG->line('do_not_change'),'');
  339. $t .= $DSP->input_select_option('y', $LANG->line('yes'));
  340. $t .= $DSP->input_select_option('n', $LANG->line('no'));
  341. $t .= $DSP->input_select_footer();
  342. $r .= $DSP->table_qcell($style, $t);
  343. }
  344. $r .= $DSP->table_qcell($style, $DSP->input_text('hits', '', '6', '13', 'input', '50px'));
  345. $r .=$DSP->tr_c();
  346. $r .= $DSP->table_c();
  347. if ($SESS->userdata['group_id'] == 1)
  348. {
  349. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('security_warning')));
  350. }
  351. /** -------------------------------------
  352. /** Access
  353. /** -------------------------------------*/
  354. $r .= BR.$DSP->table('tableBorder', '0', '', '100%').
  355. $DSP->tr().
  356. $DSP->td('tableHeadingAlt', '', 2).
  357. $LANG->line('template_access').
  358. $DSP->tr_c().
  359. $DSP->tr().
  360. $DSP->td('tableCellOne', '', '').
  361. $DSP->qdiv('defaultBold', $LANG->line('member_group')).
  362. $DSP->td_c().
  363. $DSP->td('tableCellOne', '', '').
  364. $DSP->qdiv('defaultBold', $LANG->line('can_view_template')).
  365. $DSP->td_c().
  366. $DSP->tr_c();
  367. $i = 0;
  368. $query = $DB->query("SELECT group_id, group_title FROM exp_member_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND group_id != '1' ORDER BY group_title");
  369. $access_e = array();
  370. foreach ($query->result as $row)
  371. {
  372. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  373. $r .= $DSP->tr().
  374. $DSP->td($style, '40%').
  375. $row['group_title'].
  376. $DSP->td_c().
  377. $DSP->td($style, '60%');
  378. $r .= $LANG->line('yes').NBS.
  379. $DSP->input_radio('access_'.$row['group_id'], 'y', '').$DSP->nbs(3);
  380. $r .= $LANG->line('no').NBS.
  381. $DSP->input_radio('access_'.$row['group_id'], 'n', '').$DSP->nbs(3);
  382. $r .= $LANG->line('do_not_change').NBS.
  383. $DSP->input_radio('access_'.$row['group_id'], 'null', 1).$DSP->nbs(3);
  384. $r .= $DSP->td_c()
  385. .$DSP->tr_c();
  386. $access_e[] = "access_{$row['group_id']}";
  387. }
  388. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  389. $r .= $this->template_access_toggle($access_e);
  390. $r .= $DSP->tr().
  391. $DSP->td($style, '40%').
  392. $DSP->qdiv('defaultBold', $LANG->line('select_all')).
  393. $DSP->td_c().
  394. $DSP->td($style, '60%');
  395. $r .= $LANG->line('yes').NBS.
  396. $DSP->input_radio('can_view', 'y', '', "onclick=\"toggle_access(this);\"").$DSP->nbs(3).
  397. $LANG->line('no').NBS.
  398. $DSP->input_radio('can_view', 'n', '', "onclick=\"toggle_access(this);\"").$DSP->nbs(3).
  399. $LANG->line('do_not_change').NBS.
  400. $DSP->input_radio('can_view', 'null', '', "onclick=\"toggle_access(this);\"").$DSP->nbs(3);
  401. $r .= $DSP->td_c().
  402. $DSP->tr_c();
  403. $r .= $DSP->table_c();
  404. $r .= $DSP->div('box');
  405. $r .= $DSP->heading($LANG->line('no_access_select_blurb'), 5);
  406. $r .= $DSP->qdiv('itemWrapper', $LANG->line('no_access_instructions'));
  407. $sql = "SELECT exp_template_groups.group_name, exp_templates.template_name, exp_templates.template_id
  408. FROM exp_template_groups, exp_templates
  409. WHERE exp_template_groups.group_id = exp_templates.group_id
  410. AND exp_template_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'";
  411. if (USER_BLOG !== FALSE)
  412. {
  413. $sql .= " AND exp_template_groups.group_id = '".$DB->escape_str(UB_TMP_GRP)."'";
  414. }
  415. else
  416. {
  417. $sql .= " AND exp_template_groups.is_user_blog = 'n'";
  418. }
  419. $sql .= " ORDER BY exp_template_groups.group_name, exp_templates.template_name";
  420. $query = $DB->query($sql);
  421. $r .= $DSP->div()
  422. .$DSP->input_select_header('no_auth_bounce')
  423. .$DSP->input_select_option('null', $LANG->line('do_not_change'), '1');
  424. foreach ($query->result as $row)
  425. {
  426. $r .= $DSP->input_select_option($row['template_id'], $row['group_name'].'/'.$row['template_name'], '');
  427. }
  428. $r .= $DSP->input_select_footer().BR.BR;
  429. $t = $DSP->input_select_header('enable_http_auth');
  430. $t .= $DSP->input_select_option('null', $LANG->line('do_not_change'), 1);
  431. $t .= $DSP->input_select_option('y', $LANG->line('yes'));
  432. $t .= $DSP->input_select_option('n', $LANG->line('no'));
  433. $t .= $DSP->input_select_footer();
  434. $r .= $DSP->div('paddedTop');
  435. $r .= $DSP->heading($LANG->line('enable_http_authentication'), 5);
  436. $r .= $DSP->qdiv('itemWrapper', $t);
  437. $r .= $DSP->div_c();
  438. $r .= $DSP->div_c();
  439. $r .= $DSP->div_c().BR;
  440. $r .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('update')))
  441. .$DSP->form_close();
  442. $DSP->body = $r;
  443. }
  444. /* END */
  445. /** -----------------------------
  446. /** Template Preferences Manager - UPDATE
  447. /** -----------------------------*/
  448. function update_manager_prefs()
  449. {
  450. global $IN, $DSP, $DB, $SESS, $LANG, $REGX, $OUT, $PREFS;
  451. if ( ! $DSP->allowed_group('can_admin_templates'))
  452. {
  453. return $DSP->no_access_message();
  454. }
  455. $user_blog = ($SESS->userdata['tmpl_group_id'] != 0) ? TRUE : FALSE;
  456. /** -------------------------------------
  457. /** Determine Valid Template Groups and Templates
  458. /** -------------------------------------*/
  459. if ($SESS->userdata['group_id'] != 1 && (sizeof($SESS->userdata['assigned_template_groups']) == 0 OR $DSP->allowed_group('can_admin_templates') == FALSE))
  460. {
  461. return $DSP->no_access_message();
  462. }
  463. $sql = "SELECT t.template_id, t.group_id
  464. FROM exp_template_groups tg , exp_templates t
  465. WHERE tg.group_id = t.group_id
  466. AND tg.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'";
  467. if ($user_blog === TRUE)
  468. {
  469. $sql .= " AND t.group_id = '".$SESS->userdata['tmpl_group_id']."'";
  470. }
  471. else
  472. {
  473. $sql .= " AND is_user_blog = 'n'";
  474. }
  475. if ($SESS->userdata['group_id'] != 1)
  476. {
  477. $sql .= " AND t.group_id IN (";
  478. foreach ($SESS->userdata['assigned_template_groups'] as $key => $val)
  479. {
  480. $sql .= "'$key',";
  481. }
  482. $sql = substr($sql, 0, -1).")";
  483. }
  484. $query = $DB->query($sql);
  485. if ($query->num_rows == 0)
  486. {
  487. return $DSP->no_access_message();
  488. }
  489. $templates = array();
  490. foreach($_POST as $key => $value)
  491. {
  492. if (substr($key, 0, strlen('template_group_')) == 'template_group_' && is_array($value))
  493. {
  494. foreach($value as $template)
  495. {
  496. $templates[] = $DB->escape_str($template);
  497. }
  498. }
  499. }
  500. if (sizeof($templates) == 0)
  501. {
  502. $OUT->show_user_error('submission', $LANG->line('no_templates_selected'));
  503. }
  504. /** -------------------------------------
  505. /** Template Preferences
  506. /** -------------------------------------*/
  507. $data = array();
  508. if (in_array($_POST['template_type'], array('css', 'js', 'rss', 'static', 'webpage', 'xml')))
  509. {
  510. $data['template_type'] = $_POST['template_type'];
  511. }
  512. if ($_POST['cache'] == 'y' OR $_POST['cache'] == 'n')
  513. {
  514. $data['cache'] = $_POST['cache'];
  515. if ($_POST['refresh'] != '' && is_numeric($_POST['refresh']))
  516. {
  517. $data['refresh'] = $_POST['refresh'];
  518. }
  519. }
  520. if ($SESS->userdata['group_id'] == 1)
  521. {
  522. if ($_POST['allow_php'] == 'y' OR $_POST['allow_php'] == 'n')
  523. {
  524. $data['allow_php'] = $_POST['allow_php'];
  525. if ($_POST['php_parse_location'] == 'i' OR $_POST['php_parse_location'] == 'o')
  526. {
  527. $data['php_parse_location'] = $_POST['php_parse_location'];
  528. }
  529. }
  530. }
  531. if ($_POST['hits'] != '' && is_numeric($_POST['hits']))
  532. {
  533. $data['hits'] = $_POST['hits'];
  534. }
  535. if ($_POST['enable_http_auth'] == 'y' OR $_POST['enable_http_auth'] == 'n')
  536. {
  537. $data['enable_http_auth'] = $_POST['enable_http_auth'];
  538. }
  539. if ($_POST['no_auth_bounce'] != 'null')
  540. {
  541. $data['no_auth_bounce'] = $_POST['no_auth_bounce'];
  542. }
  543. if ($PREFS->ini('save_tmpl_files') == 'y' AND $PREFS->ini('tmpl_file_basepath') != '')
  544. {
  545. if ($_POST['save_template_file'] != 'null')
  546. {
  547. $data['save_template_file'] = $_POST['save_template_file'];
  548. }
  549. }
  550. if (sizeof($data) > 0)
  551. {
  552. $DB->query($DB->update_string('exp_templates', $data, "template_id IN ('".implode("','", $templates)."')"));
  553. }
  554. /** -------------------------------------
  555. /** Template Access
  556. /** -------------------------------------*/
  557. $yes = array();
  558. $no = array();
  559. $query = $DB->query("SELECT group_id FROM exp_member_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND group_id != '1' ORDER BY group_title");
  560. if ($query->num_rows > 0)
  561. {
  562. foreach($query->result as $row)
  563. {
  564. if ( isset($_POST['access_'.$row['group_id']]))
  565. {
  566. if ($_POST['access_'.$row['group_id']] == 'y')
  567. {
  568. $yes[] = $row['group_id'];
  569. }
  570. elseif($_POST['access_'.$row['group_id']] == 'n')
  571. {
  572. $no[] = $row['group_id'];
  573. }
  574. }
  575. }
  576. }
  577. if ( ! empty($yes) OR ! empty($no))
  578. {
  579. $access = array();
  580. if (sizeof($no) > 0)
  581. {
  582. foreach($templates as $template)
  583. {
  584. $access[$template] = $no;
  585. }
  586. }
  587. $query = $DB->query("SELECT * FROM exp_template_no_access WHERE template_id IN ('".implode("','", $templates)."')");
  588. if ($query->num_rows > 0)
  589. {
  590. foreach($query->result as $row)
  591. {
  592. if ( ! in_array($row['member_group'], $yes) && ! in_array($row['member_group'], $no))
  593. {
  594. $access[$row['template_id']][] = $row['member_group'];
  595. }
  596. }
  597. }
  598. $query = $DB->query("DELETE FROM exp_template_no_access WHERE template_id IN ('".implode("','", $templates)."')");
  599. foreach($access as $template => $groups)
  600. {
  601. if ( empty($groups)) continue;
  602. foreach($groups as $group)
  603. {
  604. $DB->query($DB->insert_string('exp_template_no_access', array('template_id' => $template, 'member_group' => $group)));
  605. }
  606. }
  607. }
  608. $this->template_prefs_manager('y');
  609. }
  610. /* END */
  611. /** -----------------------------
  612. /** Verify access privileges
  613. /** -----------------------------*/
  614. function template_access_privs($data = '')
  615. {
  616. global $SESS, $DB;
  617. // If the user is a Super Admin, return true
  618. if ($SESS->userdata['group_id'] == 1)
  619. {
  620. return TRUE;
  621. }
  622. $template_id = '';
  623. $group_id = '';
  624. if (is_array($data))
  625. {
  626. if (isset($data['template_id']))
  627. {
  628. $template_id = $data['template_id'];
  629. }
  630. if (isset($data['group_id']))
  631. {
  632. $group_id = $data['group_id'];
  633. }
  634. }
  635. if ($group_id == '')
  636. {
  637. if ($template_id == '')
  638. {
  639. return FALSE;
  640. }
  641. else
  642. {
  643. $query = $DB->query("SELECT group_id, template_name FROM exp_templates WHERE template_id = '".$DB->escape_str($template_id)."'");
  644. $group_id = $query->row['group_id'];
  645. }
  646. }
  647. if ($SESS->userdata['tmpl_group_id'] == 0)
  648. {
  649. $access = FALSE;
  650. foreach ($SESS->userdata['assigned_template_groups'] as $key => $val)
  651. {
  652. if ($group_id == $key)
  653. {
  654. $access = TRUE;
  655. break;
  656. }
  657. }
  658. if ($access == FALSE)
  659. {
  660. return FALSE;
  661. }
  662. }
  663. else
  664. {
  665. if ($group_id != $SESS->userdata['tmpl_group_id'] )
  666. {
  667. return FALSE;
  668. }
  669. }
  670. return TRUE;
  671. }
  672. /* END */
  673. /** -----------------------------
  674. /** Template Preferences
  675. /** -----------------------------*/
  676. function edit_preferences($group_id = '')
  677. {
  678. global $IN, $DSP, $DB, $SESS, $LANG, $PREFS;
  679. if ( ! $DSP->allowed_group('can_admin_templates'))
  680. {
  681. return $DSP->no_access_message();
  682. }
  683. if ($group_id == '')
  684. {
  685. if ( ! $group_id = $IN->GBL('id'))
  686. {
  687. return false;
  688. }
  689. $message = '';
  690. }
  691. else
  692. {
  693. $message = $DSP->qdiv('success', $LANG->line('preferences_updated'));
  694. }
  695. if ( ! is_numeric($group_id))
  696. {
  697. return FALSE;
  698. }
  699. $query = $DB->query("SELECT group_name FROM exp_template_groups WHERE group_id = '$group_id'");
  700. if ($query->num_rows == 0)
  701. {
  702. return FALSE;
  703. }
  704. $DSP->title = $LANG->line('template_preferences');
  705. $DSP->crumb = $LANG->line('template_preferences');
  706. $r = $DSP->form_open(array('action' => 'C=templates'.AMP.'M=update_template_prefs'))
  707. .$DSP->input_hidden('group_id', $group_id);
  708. $r .= $DSP->qdiv('tableHeading', $LANG->line('template_preferences').NBS.NBS.'('.$query->row['group_name'].')');
  709. if ($message != '')
  710. {
  711. $r .= $DSP->table('tableBorder', '0', '', '100%')
  712. . $DSP->tr()
  713. . $DSP->table_qcell('tableCellOne', $message)
  714. . $DSP->tr_c()
  715. .$DSP->table_c();
  716. }
  717. $r .= $DSP->table('tableBorder', '0', '', '100%')
  718. .$DSP->tr()
  719. .$DSP->table_qcell('tableHeadingAlt', $LANG->line('name_of_template'))
  720. .$DSP->table_qcell('tableHeadingAlt', $LANG->line('type'));
  721. $r .= $DSP->td('tableHeadingAlt', '', '2').$LANG->line('cache_enable').$DSP->td_c();
  722. $r .= $DSP->table_qcell('tableHeadingAlt', $LANG->line('refresh_interval'));
  723. if ($SESS->userdata['group_id'] == 1)
  724. {
  725. $r .= $DSP->td('tableHeadingAlt', '', '2').$LANG->line('enable_php').$DSP->td_c();
  726. $r .= $DSP->td('tableHeadingAlt', '', '2').$LANG->line('parse_stage').$DSP->td_c();
  727. }
  728. if ($PREFS->ini('save_tmpl_files') == 'y' AND $PREFS->ini('tmpl_file_basepath') != '')
  729. {
  730. $r .= $DSP->td('tableHeadingAlt', '', '2').$LANG->line('save_template_file').$DSP->td_c();
  731. }
  732. $r .= $DSP->table_qcell('tableHeadingAlt', $LANG->line('hit_counter'));
  733. $r .= $DSP->tr_c();
  734. $r .= $DSP->tr();
  735. $r .= $DSP->td('tableCellOne', '', '2').NBS.$DSP->td_c()
  736. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('yes')))
  737. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('no')))
  738. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('refresh_in_minutes')));
  739. if ($SESS->userdata['group_id'] == 1)
  740. {
  741. $r .= $DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('yes')))
  742. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('no')))
  743. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('input')))
  744. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('output')));
  745. }
  746. if ($PREFS->ini('save_tmpl_files') == 'y' AND $PREFS->ini('tmpl_file_basepath') != '')
  747. {
  748. $r .= $DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('yes')))
  749. .
  750. $DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('no')));
  751. }
  752. $r .= $DSP->td('tableCellOne', '', '1').NBS.$DSP->td_c();
  753. $r .= $DSP->tr_c();
  754. $i = 0;
  755. // Fetch template preferences
  756. $query = $DB->query("SELECT template_id, template_name, template_type, group_id, save_template_file, allow_php, php_parse_location, no_auth_bounce, cache, refresh, hits FROM exp_templates WHERE group_id = '$group_id' ORDER BY template_name");
  757. foreach ($query->result as $row)
  758. {
  759. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  760. $id = $row['template_id'].'__';
  761. $r .= $DSP->tr();
  762. $old = $DSP->input_hidden($id.'old_name', $row['template_name']);
  763. if ($row['template_name'] == 'index')
  764. {
  765. $r .= $DSP->table_qcell($style, $DSP->qdiv('defaultBold', $row['template_name']).$old);
  766. }
  767. else
  768. {
  769. $r .= $DSP->table_qcell($style, $DSP->input_text($id.'template_name', $row['template_name'], '15', '50', 'input', '110px').$old);
  770. }
  771. $t = $DSP->input_select_header($id.'template_type');
  772. $t .= $DSP->input_select_option('css', $LANG->line('css_stylesheet'), ($row['template_type'] == 'css') ? 1 : '');
  773. $t .= $DSP->input_select_option('js', $LANG->line('js'), ($row['template_type'] == 'js') ? 1 : '');
  774. $t .= $DSP->input_select_option('rss', $LANG->line('rss'), ($row['template_type'] == 'rss') ? 1 : '');
  775. $t .= $DSP->input_select_option('static', $LANG->line('static'), ($row['template_type'] == 'static') ? 1 : '');
  776. $t .= $DSP->input_select_option('webpage', $LANG->line('webpage'), ($row['template_type'] == 'webpage') ? 1 : '');
  777. $t .= $DSP->input_select_option('xml', $LANG->line('xml'), ($row['template_type'] == 'xml') ? 1 : '');
  778. $t .= $DSP->input_select_footer();
  779. $r .= $DSP->table_qcell($style, $t);
  780. $r .= $DSP->table_qcell($style, $DSP->input_radio($id.'cache', 'y', ($row['cache'] == 'y') ? 1 : ''));
  781. $r .= $DSP->table_qcell($style, $DSP->input_radio($id.'cache', 'n', ($row['cache'] == 'n') ? 1 : ''));
  782. $r .= $DSP->table_qcell($style, $DSP->input_text($id.'refresh', $row['refresh'], '8', '6', 'input', '50px'));
  783. if ($SESS->userdata['group_id'] == 1)
  784. {
  785. $r .= $DSP->table_qcell($style, $DSP->input_radio($id.'allow_php', 'y', ($row['allow_php'] == 'y') ? 1 : ''));
  786. $r .= $DSP->table_qcell($style, $DSP->input_radio($id.'allow_php', 'n', ($row['allow_php'] == 'n') ? 1 : ''));
  787. $r .= $DSP->table_qcell($style, $DSP->input_radio($id.'php_parse_location', 'i', ($row['php_parse_location'] == 'i') ? 1 : ''));
  788. $r .= $DSP->table_qcell($style, $DSP->input_radio($id.'php_parse_location', 'o', ($row['php_parse_location'] == 'o') ? 1 : ''));
  789. }
  790. if ($PREFS->ini('save_tmpl_files') == 'y' AND $PREFS->ini('tmpl_file_basepath') != '')
  791. {
  792. $r .= $DSP->table_qcell($style, $DSP->input_radio($id.'save_template_file', 'y', ($row['save_template_file'] == 'y') ? 1 : ''));
  793. $r .= $DSP->table_qcell($style, $DSP->input_radio($id.'save_template_file', 'n', ($row['save_template_file'] == 'n') ? 1 : ''));
  794. }
  795. $r .= $DSP->table_qcell($style, $DSP->input_text($id.'hits', $row['hits'], '6', '13', 'input', '50px'));
  796. $r .=$DSP->tr_c();
  797. }
  798. $r .= $DSP->table_c();
  799. if ($SESS->userdata['group_id'] == 1)
  800. {
  801. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('security_warning')));
  802. }
  803. $r .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('update')))
  804. .$DSP->form_close();
  805. $DSP->body = $r;
  806. }
  807. /* END */
  808. /** -------------------------------
  809. /** Update Template Preferences
  810. /** -------------------------------*/
  811. function update_template_prefs()
  812. {
  813. global $IN, $DSP, $DB, $SESS, $LANG, $PREFS;
  814. if ( ! $group_id = $IN->GBL('group_id', 'POST'))
  815. {
  816. return false;
  817. }
  818. if ($SESS->userdata['tmpl_group_id'] == 0)
  819. {
  820. if ( ! $DSP->allowed_group('can_admin_templates'))
  821. {
  822. return $DSP->no_access_message();
  823. }
  824. }
  825. else
  826. {
  827. if ($group_id != $SESS->userdata['tmpl_group_id'] )
  828. {
  829. return $DSP->no_access_message();
  830. }
  831. }
  832. $idx = array();
  833. foreach ($_POST as $k => $val)
  834. {
  835. if ( ! stristr($k, "__"))
  836. continue;
  837. $temp = explode("__", $k);
  838. $id = $temp['0'];
  839. $idx[] = $temp['0'];
  840. if (isset($_POST[$id.'__template_name']))
  841. {
  842. if ($_POST[$id.'__template_name'] == '')
  843. {
  844. return $DSP->error_message($LANG->line('missing_name'));
  845. }
  846. if ( ! preg_match("#^[a-zA-Z0-9_\.-]+$#i", $_POST[$id.'__template_name']))
  847. {
  848. return $DSP->error_message($LANG->line('illegal_characters'));
  849. }
  850. if (in_array($_POST[$id.'__template_name'], $this->reserved_names))
  851. {
  852. return $DSP->error_message($LANG->line('reserved_name'));
  853. }
  854. if ($_POST[$id.'__template_name'] != $_POST[$id.'__old_name'])
  855. {
  856. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_templates WHERE template_name='".$DB->escape_str($_POST[$id.'__template_name'])."' AND group_id = '$group_id'");
  857. if ($query->row['count'] > 0)
  858. {
  859. return $DSP->error_message($LANG->line('template_name_taken'));
  860. }
  861. }
  862. }
  863. }
  864. foreach ($idx as $id)
  865. {
  866. $data = array();
  867. if (isset($_POST[$id.'__template_name']))
  868. {
  869. $data['template_name'] = $_POST[$id.'__template_name'];
  870. }
  871. $data['cache'] = $_POST[$id.'__cache'];
  872. $data['refresh'] = ( ! is_numeric($_POST[$id.'__refresh'])) ? '1' : $_POST[$id.'__refresh'];
  873. $data['hits'] = ( ! is_numeric($_POST[$id.'__hits'])) ? '0' : $_POST[$id.'__hits'];
  874. $data['template_type'] = $_POST[$id.'__template_type'];
  875. if ($PREFS->ini('save_tmpl_files') == 'y' AND $PREFS->ini('tmpl_file_basepath') != '')
  876. {
  877. $data['save_template_file'] = $_POST[$id.'__save_template_file'];
  878. }
  879. if ($SESS->userdata['group_id'] == 1)
  880. {
  881. $data['php_parse_location'] = $_POST[$id.'__php_parse_location'];
  882. $data['allow_php'] = (isset($_POST[$id.'__allow_php']) AND $_POST[$id.'__allow_php'] == 'y' AND $SESS->userdata['group_id'] == 1) ? 'y' : 'n';
  883. }
  884. $DB->query($DB->update_string('exp_templates', $data, "template_id = '$id'"));
  885. }
  886. return $this->edit_preferences($group_id);
  887. }
  888. /* END */
  889. /** -----------------------------
  890. /** Template default page
  891. /** -----------------------------*/
  892. function template_manager()
  893. {
  894. global $IN, $DSP, $DB, $PREFS, $FNS, $SESS, $LANG, $REGX, $EXT;
  895. // -------------------------------------------
  896. // 'template_manager_start' hook.
  897. // - Allows complete rewrite of Templates page.
  898. //
  899. $edata = $EXT->call_extension('template_manager_start');
  900. if ($EXT->end_script === TRUE) return;
  901. //
  902. // -------------------------------------------
  903. $user_blog = FALSE;
  904. $DSP->crumbline = TRUE;
  905. if ($SESS->userdata['tmpl_group_id'] != 0)
  906. {
  907. $user_blog = TRUE;
  908. }
  909. switch ($IN->GBL('MSG'))
  910. {
  911. case '01' : $message = $LANG->line('template_group_created');
  912. break;
  913. case '02' : $message = $LANG->line('template_group_updated');
  914. break;
  915. case '03' : $message = $LANG->line('template_group_deleted');
  916. break;
  917. case '04' : $message = $LANG->line('template_created');
  918. break;
  919. case '05' : $message = $LANG->line('template_deleted');
  920. break;
  921. default : $message = "";
  922. break;
  923. }
  924. $DSP->title = $LANG->line('design');
  925. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=templates', $LANG->line('design')).$DSP->crumb_item($LANG->line('template_management'));
  926. if ($user_blog === FALSE AND $DSP->allowed_group('can_admin_templates'))
  927. {
  928. $DSP->right_crumb($LANG->line('create_new_template_group'), BASE.AMP.'C=templates'.AMP.'M=new_tg_form');
  929. }
  930. ob_start();
  931. ?>
  932. <script type="text/javascript">
  933. function showHideTemplate(htmlObj)
  934. {
  935. if (isNaN(htmlObj.value) || htmlObj.value == '') return;
  936. for (var g = 0; g < htmlObj.options.length; g++)
  937. {
  938. if (document.getElementById('extText' + htmlObj.options[g].value))
  939. {
  940. extTextDiv = document.getElementById('extText' + htmlObj.options[g].value);
  941. if (htmlObj.options[g].selected == true)
  942. {
  943. if (extTextDiv.style.display != 'block')
  944. {
  945. extTextDiv.style.display = "block";
  946. }
  947. }
  948. else if(extTextDiv.style.display != 'none')
  949. {
  950. extTextDiv.style.display = "none";
  951. }
  952. }
  953. }
  954. }
  955. </script>
  956. <?php
  957. $r = ob_get_contents();
  958. ob_end_clean();
  959. $r .= $DSP->table('', '', '', '97%')
  960. .$DSP->tr()
  961. .$DSP->td('', '', '', '', 'top')
  962. .$DSP->heading($LANG->line('template_management'));
  963. if ($message != '')
  964. {
  965. $r .= $DSP->qdiv('success', $message);
  966. }
  967. if ($IN->GBL('keywords', 'POST') !== FALSE && trim($IN->GBL('keywords', 'POST')) != '')
  968. {
  969. $r .= $DSP->qspan('defaultBold', $LANG->line('search_terms')).NBS.NBS.$DSP->qspan('success', stripslashes($IN->GBL('keywords', 'POST')));
  970. }
  971. $r .= $DSP->td_c()
  972. .$DSP->td('', '', '', '', 'top');
  973. $r .= $DSP->div('defaultRight');
  974. if ($DSP->allowed_group('can_admin_templates') || $user_blog !== FALSE)
  975. {
  976. $r .= $DSP->anchor(BASE.AMP.'C=templates'.AMP.'M=global_variables', '<b>'.$LANG->line('global_variables').'</b>');
  977. }
  978. if ($user_blog === FALSE AND $DSP->allowed_group('can_admin_templates'))
  979. {
  980. $r .= NBS.NBS.'|'.NBS.NBS.$DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=config_mgr'.AMP.'P=template_cfg'.AMP.'class_override=templates', '<b>'.$LANG->line('global_template_preferences').'</b>');
  981. $r .= NBS.NBS.'|'.NBS.NBS.$DSP->anchor(BASE.AMP.'C=templates'.AMP.'M=edit_tg_order', '<b>'.$LANG->line('edit_template_group_order').'</b>');
  982. $r .= NBS.NBS.'|'.NBS.NBS.$DSP->anchor(BASE.AMP.'C=templates'.AMP.'M=template_prefs_manager', '<b>'.$LANG->line('template_preferences_manager').'</b>');
  983. }
  984. $r .= $DSP->div_c();
  985. $r .= $DSP->td_c()
  986. .$DSP->tr_c()
  987. .$DSP->table_c();
  988. $qs = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  989. $sitepath = $FNS->fetch_site_index(0, 0).$qs.'URL='.$FNS->fetch_site_index();
  990. $sitepath = rtrim($sitepath, '/').'/';
  991. if ($SESS->userdata['group_id'] != 1 && (sizeof($SESS->userdata['assigned_template_groups']) == 0 OR $DSP->allowed_group('can_admin_templates') == FALSE))
  992. {
  993. $r .= $DSP->qdiv('', $LANG->line('no_templates_assigned'));
  994. return $DSP->body = $r;
  995. }
  996. else
  997. {
  998. $sql = "SELECT tg.group_id, tg.group_name, tg.is_site_default,
  999. t.template_id, t.template_name, t.template_type, t.hits, t.enable_http_auth
  1000. FROM exp_template_groups tg , exp_templates t
  1001. WHERE tg.group_id = t.group_id
  1002. AND tg.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'";
  1003. if ($user_blog === TRUE)
  1004. {
  1005. $sql .= " AND t.group_id = '".$SESS->userdata['tmpl_group_id']."'";
  1006. }
  1007. else
  1008. {
  1009. $sql .= " AND is_user_blog = 'n'";
  1010. }
  1011. if ($SESS->userdata['group_id'] != 1)
  1012. {
  1013. $sql .= " AND t.group_id IN (";
  1014. foreach ($SESS->userdata['assigned_template_groups'] as $key => $val)
  1015. {
  1016. $sql .= "'$key',";
  1017. }
  1018. $sql = substr($sql, 0, -1).")";
  1019. }
  1020. if ($IN->GBL('keywords', 'POST') !== FALSE && trim($IN->GBL('keywords', 'POST')) != '')
  1021. {
  1022. $keywords = $REGX->keyword_clean(stripslashes($IN->GBL('keywords', 'POST')));
  1023. if (trim($keywords) == '')
  1024. {
  1025. $DSP->body .= $DSP->qdiv('alert', $LANG->line('no_results'));
  1026. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=templates', $LANG->line('back')));
  1027. return;
  1028. }
  1029. $terms = array();
  1030. if (preg_match_all("/\-*\"(.*?)\"/", $keywords, $matches))
  1031. {
  1032. for($m=0; $m < sizeof($matches['1']); $m++)
  1033. {
  1034. $terms[] = trim(str_replace('"','',$matches['0'][$m]));
  1035. $keywords = str_replace($matches['0'][$m],'', $keywords);
  1036. }
  1037. }
  1038. if (trim($keywords) != '')
  1039. {
  1040. $terms = array_merge($terms, preg_split("/\s+/", trim($keywords)));
  1041. }
  1042. rsort($terms);
  1043. $not_and = (sizeof($terms) > 2) ? ') AND (' : 'AND';
  1044. $criteria = 'AND';
  1045. $mysql_function = (substr($terms['0'], 0,1) == '-') ? 'NOT LIKE' : 'LIKE';
  1046. $search_term = (substr($terms['0'], 0,1) == '-') ? substr($terms['0'], 1) : $terms['0'];
  1047. // We have two parentheses in the beginning in case
  1048. // there are any NOT LIKE's being used
  1049. $sql .= "\nAND (t.template_data $mysql_function '%".$DB->escape_like_str($search_term)."%' ";
  1050. for ($i=1; $i < sizeof($terms); $i++)
  1051. {
  1052. if (trim($terms[$i]) == '') continue;
  1053. $mysql_criteria = ($mysql_function == 'NOT LIKE' OR substr($terms[$i], 0,1) == '-') ? $not_and : $criteria;
  1054. $mysql_function = (substr($terms[$i], 0,1) == '-') ? 'NOT LIKE' : 'LIKE';
  1055. $search_term = (substr($terms[$i], 0,1) == '-') ? substr($terms[$i], 1) : $terms[$i];
  1056. $sql .= "$mysql_criteria t.template_data $mysql_function '%".$DB->escape_like_str($search_term)."%' ";
  1057. }
  1058. $sql .= ") \n";
  1059. }
  1060. $sql .= " ORDER BY tg.group_order, t.group_id, t.template_name";
  1061. $query = $DB->query($sql);
  1062. if ($query->num_rows == 0)
  1063. {
  1064. if (isset($keywords))
  1065. {
  1066. $DSP->body .= $DSP->qdiv('alert', $LANG->line(isset($keywords) ? 'no_results' : 'no_templates_available'));
  1067. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=templates', $LANG->line('back')));
  1068. }
  1069. else
  1070. {
  1071. $DSP->body .= $DSP->qdiv('alert', $LANG->line('no_templates_available'));
  1072. }
  1073. return;
  1074. }
  1075. $r .= $DSP->table_open(array('width' => '99%', 'cellpadding' => '1'))
  1076. .$DSP->tr()
  1077. ."<td valign='top' style='width:180px; padding-top:1px'>"
  1078. .$DSP->div('itemWrapper')
  1079. .$DSP->div('templateEditBox')
  1080. .$DSP->qdiv('tableHeadingAlt', $LANG->line('choose_group'))
  1081. .$DSP->div('templatePrefBox')
  1082. .$DSP->div('defaultCenter')
  1083. ."<select onchange='showHideTemplate(this);' name='template_groups' class='multiselect' size='15' multiple='multiple' style='width:160px'>";
  1084. $current_group = 0;
  1085. foreach($query->result as $e => $row)
  1086. {
  1087. if ($row['group_id'] == $current_group) continue;
  1088. $current_group = $row['group_id'];
  1089. if (isset($_GET['tgpref']) && is_numeric($_GET['tgpref']) && $_GET['tgpref'] == $row['group_id'])
  1090. {
  1091. if ($row['is_site_default'] == 'y')
  1092. {
  1093. $r .= $DSP->input_select_option($row['group_id'], '* '.$REGX->form_prep($row['group_name']), 'y', "class='highlight_alt2'");
  1094. }
  1095. else
  1096. {
  1097. $r .= $DSP->input_select_option($row['group_id'], $REGX->form_prep($row['group_name']), 'y');
  1098. }
  1099. }
  1100. else
  1101. {
  1102. if ($row['is_site_default'] == 'y')
  1103. {
  1104. $r .= $DSP->input_select_option($row['group_id'], '* '.$REGX->form_prep($row['group_name']), ($e > 0 OR isset($_GET['tgpref'])) ? '' : 'y', "class='highlight_alt2'");
  1105. }
  1106. else
  1107. {
  1108. $r .= $DSP->input_select_option($row['group_id'], $REGX->form_prep($row['group_name']), ($e > 0 OR isset($_GET['tgpref'])) ? '' : 'y');
  1109. }
  1110. }
  1111. if ($row['is_site_default'] == 'y')
  1112. {
  1113. $default_group = $row['group_name'];
  1114. }
  1115. }
  1116. $default_text = '';
  1117. if (isset($default_group))
  1118. {
  1119. $default_text = $DSP->div('defaultCenter').
  1120. $DSP->qspan('defaultBold', $LANG->line('default_template_group')).NBS.
  1121. $default_group.
  1122. $DSP->div_c();
  1123. }
  1124. $r .= $DSP->input_select_footer().
  1125. $default_text.
  1126. $DSP->div_c().
  1127. $DSP->div_c().
  1128. $DSP->div_c().
  1129. $DSP->div_c().
  1130. $DSP->qdiv('tableHeadingAlt', $LANG->line('search'))
  1131. .$DSP->div('profileMenuInner')
  1132. . $DSP->form_open(array('action' => 'C=templates'))
  1133. . $DSP->input_text('keywords', '', '20', '120', 'input', '100%')
  1134. . $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultRight', $DSP->input_submit($LANG->line('search'))))
  1135. . $DSP->form_close()
  1136. .$DSP->div_c().
  1137. $DSP->td_c().
  1138. $DSP->table_qcell('', '', '8px').
  1139. $DSP->td('', '', '', '', 'top');
  1140. $x = 1;
  1141. $j = 1;
  1142. $out = '';
  1143. $current_group = 0;
  1144. $t = '';
  1145. foreach ($query->result as $row)
  1146. {
  1147. if ($row['group_id'] != $current_group)
  1148. {
  1149. if ($current_group != 0)
  1150. {
  1151. $t .= $DSP->table_c();
  1152. $t .= $DSP->td_c()
  1153. .$DSP->tr_c()
  1154. .$DSP->table_c();
  1155. if ($user_blog === FALSE AND $reqflag == TRUE)
  1156. {
  1157. $t .= $DSP->qdiv('itemWrapper', $DSP->required($LANG->line('default_site_page')));
  1158. }
  1159. if (isset($_GET['tgpref']) && is_numeric($_GET['tgpref']) && $_GET['tgpref'] == $current_group)
  1160. {
  1161. $r .= '<div id="extText'.$current_group.'"><div class="itemWrapper">'.$t.'</div></div>'.NL.NL;
  1162. }
  1163. elseif ( ! isset($_GET['tgpref']) && $query->row['group_id'] == $current_group)
  1164. {
  1165. $r .= '<div id="extText'.$current_group.'"><div class="itemWrapper">'.$t.'</div></div>'.NL.NL;
  1166. }
  1167. else
  1168. {
  1169. $r .= '<div id="extText'.$current_group.'" style="display: none; padding:0;"><div class="itemWrapper">'.$t.'</div></div>'.NL.NL;
  1170. }
  1171. $t = '';
  1172. $x++;
  1173. }
  1174. $template_group = $row['group_name'];
  1175. $is_site_default = $row['is_site_default'];
  1176. $t .= $DSP->table('', '', '', '100%')
  1177. .$DSP->tr()
  1178. .$DSP->td('templateEditBox', '20%', '', '', 'top');
  1179. $t .= "<div class='tableHeadingAlt'>".NBS.'<b>'.$template_group."</b></div>";
  1180. $t .= $DSP->table('', '', '', '100%')
  1181. .$DSP->tr()
  1182. .$DSP->td('templatePrefBox', '', '', '', 'top');
  1183. $t .= $DSP->div('templateprefpad');
  1184. $t .= $DSP->div('leftPad');
  1185. if ($DSP->allowed_group('can_admin_templates'))
  1186. {
  1187. $t .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=templates'.AMP.'M=edit_preferences'.AMP.'id='.$row['group_id'].AMP.'tgpref='.$row['group_id'], $LANG->line('preferences')));
  1188. }
  1189. $t .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=templates'.AMP.'M=new_templ_form'.AMP.'id='.$row['group_id'].AMP.'tgpref='.$row['group_id'], $LANG->line('create_new_template')));
  1190. if ($user_blog === FALSE AND $DSP->allowed_group('can_admin_templates'))
  1191. {
  1192. $t .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=templates'.AMP.'M=edit_tg_form'.AMP.'id='.$row['group_id'].AMP.'tgpref='.$row['group_id'], $LANG->line('edit_template_group')))
  1193. .$DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=templates'.AMP.'M=tg_del_conf'.AMP.'id='.$row['group_id'].AMP.'tgpref='.$row['group_id'], $LANG->line('delete_template_group')));
  1194. }
  1195. // TEMPLATE EXPORT LINK
  1196. $t .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=templates'.AMP.'M=export_tmpl'.AMP.'id='.$row['group_id'].AMP.'tgpref='.$row['group_id'], $LANG->line('export_templates')));
  1197. $t .= $DSP->div_c();
  1198. $t .= $DSP->div_c();
  1199. $t .= $DSP->td_c()
  1200. .$DSP->tr_c()
  1201. .$DSP->table_c();
  1202. $t .= $DSP->td_c()
  1203. .$DSP->td('defaultSmall', '1%').NBS;
  1204. $t .= $DSP->td_c()
  1205. .$DSP->td('templateEditBox', '79%', '', '', 'top');
  1206. $t .= $DSP->table('', '0', '', '100%')
  1207. .$DSP->tr()
  1208. .$DSP->table_qcell('tableHeading', $LANG->line('template_name').' / '.$LANG->line('edit'), '40%')
  1209. .$DSP->table_qcell('tableHeading', $LANG->line('hits'), '15%')
  1210. .$DSP->table_qcell('tableHeading', $LANG->line('view'), '15%')
  1211. .$DSP->table_qcell('tableHeading', $LANG->line('access'), '15%')
  1212. .$DSP->table_qcell('tableHeading', $LANG->line('delete'), '15%')
  1213. .$DSP->tr_c();
  1214. $i = 0;
  1215. $reqflag = FALSE;
  1216. }
  1217. $current_group = $row['group_id'];
  1218. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  1219. $t .= $DSP->tr();
  1220. $default = ($is_site_default == 'y' AND $row['template_name'] == 'index') ? $DSP->required() : '';
  1221. $viewurl = $sitepath;
  1222. if ($row['template_type'] == 'css')
  1223. {
  1224. $viewurl = substr($viewurl, 0, -1);
  1225. $viewurl .= $qs.$template_group.'/'.$row['template_name'].'/';
  1226. }
  1227. else
  1228. {
  1229. $viewurl .= $template_group.'/'.$row['template_name'].'/';
  1230. }
  1231. $img_type = ($row['template_name'] == 'index') ? 'index' : $row['template_type'];
  1232. /* -------------------------------------------
  1233. /* Hidden Configuration Variable
  1234. /* - hidden_template_indicator => '.'
  1235. The character(s) used to designate a template as "hidden"
  1236. /* -------------------------------------------*/
  1237. $hidden_indicator = ($PREFS->ini('hidden_template_indicator') === FALSE) ? '.' : $PREFS->ini('hidden_template_indicator');
  1238. $hidden = (substr($row['template_name'], 0, 1) == $hidden_indicator) ? '_hidden' : '';
  1239. $edit_img = "<img src='".PATH_CP_IMG."{$img_type}_icon{$hidden}.png' border='0' width='16' height='16' alt='".$LANG->line('view')."' />";
  1240. $edit_url = BASE.AMP.'C=templates'.AMP.'M=edit_template'.AMP.'id='.$row['template_id'].AMP.'tgpref='.$row['group_id'];
  1241. $protected = ($row['enable_http_auth'] == 'y') ? '&nbsp;&nbsp;<img src="'.PATH_CP_IMG.'key.gif" border="0" width="12" height="12" alt="'.$LANG->line('http_auth_protected').'" title="'.$LANG->line('http_auth_protected').'" />' : '';
  1242. $t .= $DSP->table_qcell($style, $DSP->anchor($edit_url, $edit_img).NBS.NBS.NBS.$DSP->anchor($edit_url, $default.'<b>'.$row['template_name'].'</b>').$protected);
  1243. $t .= $DSP->table_qcell($style, $row['hits']);
  1244. $t .= $DSP->table_qcell($style, $DSP->pagepop($viewurl, $LANG->line('view')));
  1245. $key_url = BASE.AMP.'C=templates'.AMP.'M=template_access'.AMP.'id='.$row['template_id'].AMP.'tgpref='.$row['group_id'];
  1246. $t .= $DSP->table_qcell($style, $DSP->anchor($key_url, $LANG->line('access')));
  1247. $del_url = BASE.AMP.'C=templates'.AMP.'M=tmpl_del_conf'.AMP.'id='.$row['template_id'].AMP.'tgpref='.$row['group_id'];
  1248. $delete = ($row['template_name'] == 'index') ? '--' : $DSP->anchor($del_url, $LANG->line('delete'));
  1249. $t .= $DSP->table_qcell($style, $delete)
  1250. .$DSP->tr_c();
  1251. if ($default != '' AND $reqflag == FALSE)
  1252. $reqflag = TRUE;
  1253. }
  1254. }
  1255. $t .= $DSP->table_c();
  1256. $t .= $DSP->td_c()
  1257. .$DSP->tr_c()
  1258. .$DSP->table_c();
  1259. if ($user_blog === FALSE AND $reqflag == TRUE)
  1260. {
  1261. $t .= $DSP->qdiv('itemWrapper', $DSP->required($LANG->line('default_site_page')));
  1262. }
  1263. if (isset($_GET['tgpref']) && is_numeric($_GET['tgpref']) && $_GET['tgpref'] == $row['group_id'])
  1264. {
  1265. $r .= '<div id="extText'.$row['group_id'].'"><div class="itemWrapper">'.$t.'</div></div>'.NL.NL;
  1266. }
  1267. elseif ( ! isset($_GET['tgpref']) && $query->row['group_id'] == $row['group_id'])
  1268. {
  1269. $r .= '<div id="extText'.$row['group_id'].'"><div class="itemWrapper">'.$t.'</div></div>'.NL.NL;
  1270. }
  1271. else
  1272. {
  1273. $r .= '<div id="extText'.$row['group_id'].'" style="display: none; padding:0;"><div class="itemWrapper">'.$t.'</div></div>'.NL.NL;
  1274. }
  1275. $x++;
  1276. $r .= $DSP->td_c().
  1277. $DSP->tr_c().
  1278. $DSP->table_close();
  1279. $DSP->body = $r;
  1280. }
  1281. /* END */
  1282. /** ---------------------------------
  1283. /** New/Edit Template Group Form
  1284. /** ---------------------------------*/
  1285. function edit_template_group_form()
  1286. {
  1287. global $DSP, $IN, $DB, $LANG, $PREFS;
  1288. if ( ! $DSP->allowed_group('can_admin_templates'))
  1289. {
  1290. return $DSP->no_access_message();
  1291. }
  1292. $edit = FALSE;
  1293. $group_id = '';
  1294. $group_name = '';
  1295. $group_order = '';
  1296. $is_site_default = '';
  1297. if ($group_id = $IN->GBL('id'))
  1298. {
  1299. $edit = TRUE;
  1300. if ( ! is_numeric($group_id))
  1301. {
  1302. return false;
  1303. }
  1304. $query = $DB->query("SELECT group_id, group_name, is_site_default FROM exp_template_groups WHERE group_id = '$group_id'");
  1305. foreach ($query->row as $key => $val)
  1306. {
  1307. $$key = $val;
  1308. }
  1309. }
  1310. $title = ($edit == FALSE) ? $LANG->line('new_template_group_form') : $LANG->line('edit_template_group_form');
  1311. // Build the output
  1312. $DSP->title = $title;
  1313. $DSP->crumb = $title;
  1314. $DSP->body = $DSP->form_open(array('action' => 'C=templates'.AMP.'M=update_tg'));
  1315. if ($edit == TRUE)
  1316. {
  1317. $DSP->body .= $DSP->input_hidden('group_id', $group_id);
  1318. $DSP->body .= $DSP->input_hidden('old_name', $group_name);
  1319. }
  1320. $DSP->body .= $DSP->qdiv('tableHeading', $title);
  1321. $DSP->body .= $DSP->div('box').$DSP->div('paddedWrapper')
  1322. .$DSP->qdiv('itemWrapper', '<b>'.$LANG->line('name_of_template_group', 'group_name').'</b>')
  1323. .$DSP->qdiv('itemWrapper', $LANG->line('template_group_instructions'))
  1324. .$DSP->qdiv('itemWrapper', $LANG->line('undersores_allowed'))
  1325. .$DSP->qdiv('itemWrapper', $DSP->input_text('group_name', $group_name, '20', '50', 'input', '300px'))
  1326. .$DSP->div_c();
  1327. if ($edit == FALSE)
  1328. {
  1329. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('duplicate_existing_group').BR));
  1330. $sql = "SELECT group_name, group_id, site_label
  1331. FROM exp_template_groups, exp_sites
  1332. WHERE exp_sites.site_id = exp_template_groups.site_id ";
  1333. if ($PREFS->ini('multiple_sites_enabled') !== 'y')
  1334. {
  1335. $sql .= "AND exp_template_groups.site_id = '1' ";
  1336. }
  1337. if (USER_BLOG == TRUE)
  1338. {
  1339. $sql .= "AND exp_template_groups.group_id = '".$SESS->userdata['tmpl_group_id']."' ";
  1340. }
  1341. else
  1342. {
  1343. $sql .= "AND exp_template_groups.is_user_blog = 'n' ";
  1344. }
  1345. $sql .= " ORDER BY group_name";
  1346. $query = $DB->query($sql);
  1347. $DSP->body .= $DSP->input_select_header('duplicate_group');
  1348. $DSP->body .= $DSP->input_select_option('false', $LANG->line('do_not_duplicate_group'));
  1349. foreach ($query->result as $row)
  1350. {
  1351. $DSP->body .= $DSP->input_select_option($row['group_id'], ($PREFS->ini('multiple_sites_enabled') == 'y') ? $row['site_label'].' - '.$row['group_name'] : $row['group_name']);
  1352. }
  1353. $DSP->body .= $DSP->input_select_footer();
  1354. }
  1355. $selected = ($is_site_default == 'y') ? 1 : '';
  1356. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->input_checkbox('is_site_default', 'y', $selected).NBS.$LANG->line('is_site_default').BR.BR);
  1357. $DSP->body .= $DSP->div_c();
  1358. if ($edit == FALSE)
  1359. $DSP->body .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('submit')));
  1360. else
  1361. $DSP->body .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('update')));
  1362. $DSP->body .= $DSP->form_close();
  1363. }
  1364. /* END */
  1365. /** -------------------------------------
  1366. /** Create/Update Template Group
  1367. /** -------------------------------------*/
  1368. function update_template_group()
  1369. {
  1370. global $DSP, $IN, $DB, $FNS, $LANG, $SESS, $LOC, $PREFS;
  1371. $group_id = $IN->GBL('group_id');
  1372. if ( ! $DSP->allowed_group('can_admin_templates'))
  1373. {
  1374. return $DSP->no_access_message();
  1375. }
  1376. if ( ! $group_name = $IN->GBL('group_name', 'POST'))
  1377. {
  1378. return $DSP->error_message($LANG->line('form_is_empty'));
  1379. }
  1380. if ( ! preg_match("#^[a-zA-Z0-9_\-/]+$#i", $group_name))
  1381. {
  1382. return $DSP->error_message($LANG->line('illegal_characters'));
  1383. }
  1384. if (in_array($group_name, $this->reserved_names))
  1385. {
  1386. return $DSP->error_message($LANG->line('reserved_name'));
  1387. }
  1388. $query = $DB->query("SELECT count(*) AS count FROM exp_template_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND group_name = '".$DB->escape_str($group_name)."'");
  1389. if (($IN->GBL('old_name', 'POST') != $group_name) AND $query->row['count'] > 0)
  1390. {
  1391. return $DSP->error_message($LANG->line('template_group_taken'));
  1392. }
  1393. elseif ($query->row['count'] > 1)
  1394. {
  1395. return $DSP->error_message($LANG->line('template_group_taken'));
  1396. }
  1397. $is_site_default = ($IN->GBL('is_site_default', 'POST') == 'y' ) ? 'y' : 'n';
  1398. if ($is_site_default == 'y')
  1399. {
  1400. $DB->query("UPDATE exp_template_groups SET is_site_default = 'n' WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ");
  1401. }
  1402. if ( ! $group_id)
  1403. {
  1404. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_template_groups WHERE is_user_blog = 'n'");
  1405. $group_order = $query->row['count'] +1;
  1406. $DB->query(
  1407. $DB->insert_string(
  1408. 'exp_template_groups',
  1409. array(
  1410. 'group_id' => '',
  1411. 'group_name' => $group_name,
  1412. 'group_order' => $group_order,
  1413. 'is_site_default' => $is_site_default,
  1414. 'site_id' => $PREFS->ini('site_id')
  1415. )
  1416. )
  1417. );
  1418. $group_id = $DB->insert_id;
  1419. $duplicate = FALSE;
  1420. if (is_numeric($_POST['duplicate_group']))
  1421. {
  1422. $query = $DB->query("SELECT template_name, template_data, template_type, template_notes, cache, refresh, no_auth_bounce, allow_php, php_parse_location FROM exp_templates WHERE group_id = '".$DB->escape_str($_POST['duplicate_group'])."'");
  1423. if ($query->num_rows > 0)
  1424. {
  1425. $duplicate = TRUE;
  1426. }
  1427. }
  1428. if ( ! $duplicate)
  1429. {
  1430. $DB->query(
  1431. $DB->insert_string(
  1432. 'exp_templates',
  1433. array(
  1434. 'template_id' => '',
  1435. 'group_id' => $group_id,
  1436. 'template_name' => 'index',
  1437. 'edit_date' => $LOC->now,
  1438. 'site_id' => $PREFS->ini('site_id')
  1439. )
  1440. )
  1441. );
  1442. }
  1443. else
  1444. {
  1445. foreach ($query->result as $row)
  1446. {
  1447. $data = array(
  1448. 'template_id' => '',
  1449. 'group_id' => $group_id,
  1450. 'template_name' => $row['template_name'],
  1451. 'template_notes' => $row['template_notes'],
  1452. 'cache' => $row['cache'],
  1453. 'refresh' => $row['refresh'],
  1454. 'no_auth_bounce' => $row['no_auth_bounce'],
  1455. 'php_parse_location' => $row['php_parse_location'],
  1456. 'allow_php' => ($SESS->userdata['group_id'] == 1) ? $row['allow_php'] : 'n',
  1457. 'template_type' => $row['template_type'],
  1458. 'template_data' => $row['template_data'],
  1459. 'edit_date' => $LOC->now,
  1460. 'site_id' => $PREFS->ini('site_id')
  1461. );
  1462. $DB->query($DB->insert_string('exp_templates', $data, TRUE));
  1463. }
  1464. }
  1465. $message = '01';
  1466. }
  1467. else
  1468. {
  1469. $DB->query(
  1470. $DB->update_string(
  1471. 'exp_template_groups',
  1472. array('group_name' => $group_name, 'is_site_default' => $is_site_default),
  1473. array('group_id' => $group_id)
  1474. )
  1475. );
  1476. $message = '02';
  1477. }
  1478. $append = ($IN->GBL('tgpref', 'GP')) ? AMP.'tgpref='.$IN->GBL('tgpref', 'GP') : '';
  1479. $FNS->redirect(BASE.AMP.'C=templates'.AMP.'MSG='.$message.$append);
  1480. exit;
  1481. }
  1482. /* END */
  1483. /** -------------------------------
  1484. /** Template Group Delete Confirm
  1485. /** -------------------------------*/
  1486. function template_group_del_conf()
  1487. {
  1488. global $DSP, $DB, $IN, $LANG;
  1489. if ( ! $DSP->allowed_group('can_admin_templates'))
  1490. {
  1491. return $DSP->no_access_message();
  1492. }
  1493. $DSP->title = $LANG->line('template_group_del_conf');
  1494. $DSP->crumb = $LANG->line('template_group_del_conf');
  1495. if ( ! $group_id = $IN->GBL('id'))
  1496. {
  1497. return false;
  1498. }
  1499. $query = $DB->query("SELECT group_name FROM exp_template_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  1500. $DSP->body = $DSP->delete_confirmation(
  1501. array(
  1502. 'url' => 'C=templates'.AMP.'M=delete_tg',
  1503. 'heading' => 'delete_template_group',
  1504. 'message' => 'delete_this_group',
  1505. 'item' => $query->row['group_name'],
  1506. 'extra' => 'all_templates_will_be_nuked',
  1507. 'hidden' => array('group_id' => $group_id)
  1508. )
  1509. );
  1510. }
  1511. /* END */
  1512. /** -------------------------------
  1513. /** Delete Template Group
  1514. /** -------------------------------*/
  1515. function template_group_delete()
  1516. {
  1517. global $DSP, $DB, $IN, $FNS, $LANG;
  1518. if ( ! $DSP->allowed_group('can_admin_templates'))
  1519. {
  1520. return $DSP->no_access_message();
  1521. }
  1522. if ( ! $group_id = $IN->GBL('group_id', 'POST'))
  1523. {
  1524. return false;
  1525. }
  1526. if ( ! is_numeric($group_id))
  1527. {
  1528. return false;
  1529. }
  1530. // We need to delete all the saved template data in the versioning table
  1531. $query = $DB->query("SELECT template_id FROM exp_templates WHERE group_id = '$group_id'");
  1532. if ($query->num_rows > 0)
  1533. {
  1534. $sql = "DELETE FROM exp_revision_tracker WHERE ";
  1535. $sqlb = '';
  1536. foreach ($query->result as $row)
  1537. {
  1538. $sqlb .= " item_id = '".$row['template_id']."' OR";
  1539. }
  1540. $sqlb = substr($sqlb, 0, -2);
  1541. $DB->query($sql.$sqlb);
  1542. $DB->query("DELETE FROM exp_template_no_access WHERE ".str_replace('item_id', 'template_id', $sqlb));
  1543. $DB->query("DELETE FROM exp_templates WHERE group_id = '$group_id'");
  1544. }
  1545. $DB->query("DELETE FROM exp_template_groups WHERE group_id = '$group_id'");
  1546. $FNS->redirect(BASE.AMP.'C=templates'.AMP.'MSG=03');
  1547. exit;
  1548. }
  1549. /* END */
  1550. /** -------------------------------
  1551. /** Edit template group order
  1552. /** -------------------------------*/
  1553. function edit_template_group_order_form()
  1554. {
  1555. global $DSP, $DB, $LANG, $PREFS;
  1556. if ( ! $DSP->allowed_group('can_admin_templates'))
  1557. {
  1558. return $DSP->no_access_message();
  1559. }
  1560. $r = $DSP->form_open(array('action' => 'C=templates'.AMP.'M=update_tg_order'));
  1561. $r .= $DSP->table('tableBorder', '0', '0', '100%').
  1562. $DSP->tr().
  1563. $DSP->table_qcell('tableHeading', $LANG->line('edit_group_order')).
  1564. $DSP->table_qcell('tableHeading', $LANG->line('order')).
  1565. $DSP->tr_c();
  1566. $query = $DB->query("SELECT group_id, group_order, group_name FROM exp_template_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND is_user_blog = 'n' ORDER BY group_order asc");
  1567. $i = 0;
  1568. $templates = array();
  1569. foreach ($query->result as $row)
  1570. {
  1571. $templates[$row['group_id']] = $row['group_name'];
  1572. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  1573. $r .= $DSP->tr()
  1574. .$DSP->table_qcell($style, '<b>'.$row['group_name'].'</b>')
  1575. .$DSP->table_qcell($style, $DSP->input_text($row['group_id'], $row['group_order'], '4', '3', 'input', '30px'))
  1576. .$DSP->tr_c();
  1577. }
  1578. natcasesort($templates);
  1579. $r .= $DSP->table_c();
  1580. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('update')));
  1581. $r .= $DSP->form_close();
  1582. $DSP->title = $LANG->line('edit_group_order');
  1583. $DSP->crumb = $LANG->line('edit_group_order');
  1584. $js = "<script>\n<!--\n\n\tfunction alphabetize_order()\n\t{\n";
  1585. $i = 1;
  1586. foreach($templates as $key => $template)
  1587. {
  1588. $js .= "\t\tdocument.getElementById('".$key."').value = '{$i}'\n";
  1589. $i++;
  1590. }
  1591. $js .= "\t}\n\n//-->\n</script>\n";
  1592. $DSP->right_crumb($LANG->line('alphabetize_group_order'), '', 'onclick="alphabetize_order();return false;"');
  1593. $DSP->body = $js.$r;
  1594. }
  1595. /* END */
  1596. /** -------------------------------
  1597. /** Update Template Group Order
  1598. /** -------------------------------*/
  1599. function update_template_group_order()
  1600. {
  1601. global $DSP, $IN, $DB, $FNS, $LANG;
  1602. if ( ! $DSP->allowed_group('can_admin_templates'))
  1603. {
  1604. return $DSP->no_access_message();
  1605. }
  1606. foreach ($_POST as $key => $val)
  1607. {
  1608. $DB->query("UPDATE exp_template_groups SET group_order = '$val' WHERE group_id = '$key'");
  1609. }
  1610. $append = ($IN->GBL('tgpref', 'GP')) ? AMP.'tgpref='.$IN->GBL('tgpref', 'GP') : '';
  1611. $FNS->redirect(BASE.AMP.'C=templates'.$append);
  1612. exit;
  1613. }
  1614. /* END */
  1615. /** -----------------------------
  1616. /** New Template Form
  1617. /** -----------------------------*/
  1618. function new_template_form()
  1619. {
  1620. global $DSP, $IN, $FNS, $DB, $SESS, $LANG, $PREFS;
  1621. if ( ! $group_id = $IN->GBL('id'))
  1622. {
  1623. return false;
  1624. }
  1625. if ( ! $this->template_access_privs(array('group_id' => $group_id)))
  1626. {
  1627. return $DSP->no_access_message();
  1628. }
  1629. $user_blog = ($SESS->userdata['tmpl_group_id'] == 0) ? FALSE : TRUE;
  1630. // Build the output
  1631. $DSP->title = $LANG->line('new_template_form');
  1632. $DSP->crumb = $LANG->line('new_template_form');
  1633. $r = $DSP->form_open(array('action' => 'C=templates'.AMP.'M=new_template'));
  1634. $r .= $DSP->input_hidden('group_id', $group_id);
  1635. $r .= $DSP->qdiv('tableHeading', $LANG->line('new_template_form'));
  1636. $r .= $DSP->div('box');
  1637. $r .= $DSP->qdiv('itemWrapper', '<b>'.$LANG->line('name_of_template', 'template_name').'</b>')
  1638. .$DSP->qdiv('itemWrapper', $LANG->line('template_group_instructions'))
  1639. .$DSP->qdiv('itemWrapper', $LANG->line('undersores_allowed'))
  1640. .$DSP->qdiv('', $DSP->input_text('template_name', '', '20', '50', 'input', '240px'));
  1641. $r .= $DSP->div('itemWrapper').'<b>'.$LANG->line('template_type').'</b>';
  1642. $r .= $DSP->input_select_header('template_type');
  1643. $r .= $DSP->input_select_option('webpage', $LANG->line('webpage'), 1);
  1644. $r .= $DSP->input_select_option('rss', $LANG->line('rss'), '');
  1645. $r .= $DSP->input_select_option('css', $LANG->line('css_stylesheet'), '');
  1646. $r .= $DSP->input_select_option('js', $LANG->line('js'), '');
  1647. $r .= $DSP->input_select_option('static', $LANG->line('static'), '');
  1648. $r .= $DSP->input_select_option('xml', $LANG->line('xml'), '');
  1649. $r .= $DSP->input_select_footer();
  1650. $r .= $DSP->div_c();
  1651. $r .= $DSP->div_c();
  1652. $r .= $DSP->table('tableBorder', '0', '', '100%')
  1653. .$DSP->tr()
  1654. .$DSP->td('tableHeadingAlt', '', '3').$LANG->line('choose_default_data').$DSP->td_c()
  1655. .$DSP->tr_c();
  1656. $r .= $DSP->tr()
  1657. .$DSP->table_qcell('tableCellOne', $DSP->input_radio('data', 'none', 1))
  1658. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('blank_template')))
  1659. .$DSP->table_qcell('tableCellOne', NBS)
  1660. .$DSP->tr_c();
  1661. $data = $FNS->create_directory_map(PATH_TMPL);
  1662. $d = '';
  1663. if (count($data) > 0)
  1664. {
  1665. $d = $DSP->input_select_header('library');
  1666. $this->render_map_as_select_options($data);
  1667. foreach ($this->template_map as $val)
  1668. {
  1669. $d .= $DSP->input_select_option($val, substr($val, 0, -4));
  1670. }
  1671. $d .= $DSP->input_select_footer();
  1672. }
  1673. $r .= $DSP->tr()
  1674. .$DSP->table_qcell('tableCellOne', $DSP->input_radio('data', 'library', ''))
  1675. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('template_from_library')))
  1676. .$DSP->table_qcell('tableCellOne', $d)
  1677. .$DSP->tr_c();
  1678. $sql = "SELECT exp_template_groups.group_name, exp_templates.template_name, exp_templates.template_id, exp_sites.site_label
  1679. FROM exp_template_groups, exp_templates, exp_sites
  1680. WHERE exp_template_groups.group_id = exp_templates.group_id
  1681. AND exp_template_groups.site_id = exp_sites.site_id";
  1682. if ($user_blog == TRUE)
  1683. {
  1684. $sql .= " AND exp_template_groups.group_id = '".$SESS->userdata['tmpl_group_id']."'";
  1685. }
  1686. else
  1687. {
  1688. $sql .= " AND exp_template_groups.is_user_blog = 'n'";
  1689. }
  1690. if ($PREFS->ini('multiple_sites_enabled') !== 'y')
  1691. {
  1692. $sql .= "AND exp_template_groups.site_id = '1' ";
  1693. }
  1694. $sql .= " ORDER BY exp_sites.site_label, exp_template_groups.group_order, exp_templates.template_name";
  1695. $query = $DB->query($sql);
  1696. $d = $DSP->input_select_header('template');
  1697. foreach ($query->result as $row)
  1698. {
  1699. $d .= $DSP->input_select_option($row['template_id'], (($PREFS->ini('multiple_sites_enabled') === 'y') ? $row['site_label'].NBS.'-'.NBS : '').$row['group_name'].'/'.$row['template_name']);
  1700. }
  1701. $d .= $DSP->input_select_footer();
  1702. $r .= $DSP->tr()
  1703. .$DSP->table_qcell('tableCellOne', $DSP->input_radio('data', 'template', ''))
  1704. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('an_existing_template')))
  1705. .$DSP->table_qcell('tableCellOne', $d)
  1706. .$DSP->tr_c()
  1707. .$DSP->table_c();
  1708. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('submit')))
  1709. .$DSP->form_close();
  1710. $DSP->body = $r;
  1711. }
  1712. /* END */
  1713. /** -------------------------------------------
  1714. /** Create pull-down optios from dirctory map
  1715. /** -------------------------------------------*/
  1716. function render_map_as_select_options($zarray, $array_name = '')
  1717. {
  1718. foreach ($zarray as $key => $val)
  1719. {
  1720. if ( is_array($val))
  1721. {
  1722. if ($array_name != "")
  1723. $key = $array_name.'/'.$key;
  1724. $this->render_map_as_select_options($val, $key);
  1725. }
  1726. else
  1727. {
  1728. if ($array_name != '')
  1729. {
  1730. $val = $array_name.'/'.$val;
  1731. }
  1732. if (preg_match("#\.(tpl|css|js)$#", $val))
  1733. {
  1734. $this->template_map[] = $val;
  1735. }
  1736. }
  1737. }
  1738. }
  1739. /* END */
  1740. /** -------------------------------
  1741. /** Create new template
  1742. /** -------------------------------*/
  1743. function create_new_template()
  1744. {
  1745. global $DSP, $IN, $DB, $LOC, $FNS, $SESS, $LANG, $PREFS;
  1746. if ( ! $template_name = $IN->GBL('template_name', 'POST'))
  1747. {
  1748. return $DSP->error_message($LANG->line('you_must_submit_a_name'));
  1749. }
  1750. if ( ! $group_id = $IN->GBL('group_id', 'POST'))
  1751. {
  1752. return $DSP->no_access_message();
  1753. }
  1754. if ( ! $this->template_access_privs(array('group_id' => $group_id)))
  1755. {
  1756. return $DSP->no_access_message();
  1757. }
  1758. $user_blog = ($SESS->userdata['tmpl_group_id'] == 0) ? FALSE : TRUE;
  1759. if ($user_blog == TRUE && $group_id != $SESS->userdata['tmpl_group_id'])
  1760. {
  1761. return $DSP->no_access_message();
  1762. }
  1763. if ( ! preg_match("#^[a-zA-Z0-9_\.-]+$#i", $template_name))
  1764. {
  1765. return $DSP->error_message($LANG->line('illegal_characters'));
  1766. }
  1767. if (in_array($template_name, $this->reserved_names))
  1768. {
  1769. return $DSP->error_message($LANG->line('reserved_name'));
  1770. }
  1771. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_templates WHERE group_id = '".$DB->escape_str($_POST['group_id'])."' AND template_name = '".$DB->escape_str($_POST['template_name'])."'");
  1772. if ($query->row['count'])
  1773. {
  1774. return $DSP->error_message($LANG->line('template_name_taken'));
  1775. }
  1776. $template_data = '';
  1777. $template_type = $_POST['template_type'];
  1778. if ($_POST['data'] == 'library' && isset($_POST['library']))
  1779. {
  1780. $parts = explode('/', $_POST['library']);
  1781. if (sizeof($parts) == 1)
  1782. {
  1783. $_POST['library'] = $FNS->filename_security($parts[0]);
  1784. }
  1785. else
  1786. {
  1787. $_POST['library'] = '';
  1788. foreach($parts as $part)
  1789. {
  1790. $_POST['library'] .= $FNS->filename_security($part).'/';
  1791. }
  1792. }
  1793. $_POST['library'] = rtrim($_POST['library'], '/');
  1794. if ($fp = @fopen(PATH_TMPL.$_POST['library'], 'r'))
  1795. {
  1796. $size = filesize(PATH_TMPL.$_POST['library']);
  1797. $template_data = ($size > 0) ? fread($fp, $size) : '';
  1798. fclose($fp);
  1799. }
  1800. $data = array(
  1801. 'template_id' => '',
  1802. 'group_id' => $_POST['group_id'],
  1803. 'template_name' => $_POST['template_name'],
  1804. 'template_type' => $template_type,
  1805. 'template_data' => $template_data,
  1806. 'edit_date' => $LOC->now,
  1807. 'site_id' => $PREFS->ini('site_id')
  1808. );
  1809. $DB->query($DB->insert_string('exp_templates', $data));
  1810. }
  1811. elseif ($_POST['data'] == 'template')
  1812. {
  1813. $query = $DB->query("SELECT tg.group_name, template_name, template_data, template_type, template_notes, cache, refresh, no_auth_bounce, allow_php, php_parse_location, save_template_file
  1814. FROM exp_templates t, exp_template_groups tg
  1815. WHERE t.template_id = '".$DB->escape_str($_POST['template'])."'
  1816. AND tg.group_id = t.group_id");
  1817. if ($PREFS->ini('save_tmpl_files') == 'y' && $PREFS->ini('tmpl_file_basepath') != '' && $query->row['save_template_file'] == 'y')
  1818. {
  1819. $basepath = rtrim($PREFS->ini('tmpl_file_basepath'), '/').'/';
  1820. $basepath .= $query->row['group_name'].'/'.$query->row['template_name'].'.php';
  1821. if ($fp = @fopen($basepath, 'rb'))
  1822. {
  1823. flock($fp, LOCK_SH);
  1824. $query->row['template_data'] = (filesize($basepath) == 0) ? '' : fread($fp, filesize($basepath));
  1825. flock($fp, LOCK_UN);
  1826. fclose($fp);
  1827. }
  1828. }
  1829. $template_data = $query->row['template_data'];
  1830. if ($template_type != $query->row['template_type'])
  1831. $template_type = $query->row['template_type'];
  1832. $data = array(
  1833. 'template_id' => '',
  1834. 'group_id' => $_POST['group_id'],
  1835. 'template_name' => $_POST['template_name'],
  1836. 'template_notes' => $query->row['template_notes'],
  1837. 'cache' => $query->row['cache'],
  1838. 'refresh' => $query->row['refresh'],
  1839. 'no_auth_bounce' => $query->row['no_auth_bounce'],
  1840. 'php_parse_location' => $query->row['php_parse_location'],
  1841. 'allow_php' => ($SESS->userdata['group_id'] == 1) ? $query->row['allow_php'] : 'n',
  1842. 'template_type' => $template_type,
  1843. 'template_data' => $template_data,
  1844. 'edit_date' => $LOC->now,
  1845. 'site_id' => $PREFS->ini('site_id')
  1846. );
  1847. $DB->query($DB->insert_string('exp_templates', $data, TRUE));
  1848. }
  1849. else
  1850. {
  1851. $data = array(
  1852. 'template_id' => '',
  1853. 'group_id' => $_POST['group_id'],
  1854. 'template_name' => $_POST['template_name'],
  1855. 'template_type' => $template_type,
  1856. 'template_data' => '',
  1857. 'edit_date' => $LOC->now,
  1858. 'site_id' => $PREFS->ini('site_id')
  1859. );
  1860. $DB->query($DB->insert_string('exp_templates', $data));
  1861. }
  1862. $append = ($IN->GBL('tgpref', 'GP')) ? AMP.'tgpref='.$IN->GBL('tgpref', 'GP') : '';
  1863. $FNS->redirect(BASE.AMP.'C=templates'.AMP.'MSG=04'.$append);
  1864. exit;
  1865. }
  1866. /* END */
  1867. /** -------------------------------
  1868. /** Template Delete Confirm
  1869. /** -------------------------------*/
  1870. function template_del_conf()
  1871. {
  1872. global $DSP, $DB, $IN, $SESS, $LANG;
  1873. if ( ! $id = $IN->GBL('id'))
  1874. {
  1875. return false;
  1876. }
  1877. if ( ! is_numeric($id))
  1878. {
  1879. return false;
  1880. }
  1881. $query = $DB->query("SELECT group_id, template_name FROM exp_templates WHERE template_id = '$id'");
  1882. $group_id = $query->row['group_id'];
  1883. $name = $query->row['template_name'];
  1884. if ($SESS->userdata['tmpl_group_id'] == 0)
  1885. {
  1886. if ( ! $DSP->allowed_group('can_admin_templates'))
  1887. {
  1888. if ( ! $this->template_access_privs(array('group_id' => $group_id)))
  1889. {
  1890. return $DSP->no_access_message();
  1891. }
  1892. }
  1893. }
  1894. else
  1895. {
  1896. if ($group_id != $SESS->userdata['tmpl_group_id'] )
  1897. {
  1898. return $DSP->no_access_message();
  1899. }
  1900. }
  1901. $DSP->title = $LANG->line('template_del_conf');
  1902. $DSP->crumb = $LANG->line('template_del_conf');
  1903. $DSP->body = $DSP->delete_confirmation(
  1904. array(
  1905. 'url' => 'C=templates'.AMP.'M=delete_template',
  1906. 'heading' => 'delete_template',
  1907. 'message' => 'delete_this_template',
  1908. 'item' => $name,
  1909. 'extra' => '',
  1910. 'hidden' => array('template_id' => $id)
  1911. )
  1912. );
  1913. }
  1914. /* END */
  1915. /** -------------------------------
  1916. /** Delete Template
  1917. /** -------------------------------*/
  1918. function delete_template()
  1919. {
  1920. global $DSP, $IN, $LANG, $FNS, $SESS, $DB;
  1921. if ( ! $id = $IN->GBL('template_id', 'POST'))
  1922. {
  1923. return false;
  1924. }
  1925. if ( ! is_numeric($id))
  1926. {
  1927. return false;
  1928. }
  1929. $query = $DB->query("SELECT group_id FROM exp_templates WHERE template_id = '$id'");
  1930. $group_id = $query->row['group_id'];
  1931. if ($SESS->userdata['tmpl_group_id'] == 0)
  1932. {
  1933. if ( ! $DSP->allowed_group('can_admin_templates'))
  1934. {
  1935. if ( ! $this->template_access_privs(array('group_id' => $group_id)))
  1936. {
  1937. return $DSP->no_access_message();
  1938. }
  1939. }
  1940. }
  1941. else
  1942. {
  1943. if ($group_id != $SESS->userdata['tmpl_group_id'] )
  1944. {
  1945. return $DSP->no_access_message();
  1946. }
  1947. }
  1948. $DB->query("DELETE FROM exp_revision_tracker WHERE item_id = '$id' AND item_table = 'exp_templates' and item_field = 'template_data' ");
  1949. $DB->query("DELETE FROM exp_template_no_access WHERE template_id = '$id'");
  1950. $DB->query("DELETE FROM exp_templates WHERE template_id = '$id'");
  1951. $append = ($IN->GBL('tgpref', 'GP')) ? AMP.'tgpref='.$IN->GBL('tgpref', 'GP') : '';
  1952. $FNS->redirect(BASE.AMP.'C=templates'.AMP.'MSG=05'.$append);
  1953. exit;
  1954. }
  1955. /* END */
  1956. /** -----------------------------
  1957. /** Template Member Access
  1958. /** -----------------------------*/
  1959. function template_access($template_id = '')
  1960. {
  1961. global $IN, $DSP, $DB, $SESS, $LANG, $PREFS;
  1962. if ( ! $DSP->allowed_group('can_admin_templates'))
  1963. {
  1964. return $DSP->no_access_message();
  1965. }
  1966. if ($template_id == '')
  1967. {
  1968. if ( ! $template_id = $IN->GBL('id'))
  1969. {
  1970. return false;
  1971. }
  1972. $message = '';
  1973. }
  1974. else
  1975. {
  1976. $message = $DSP->qdiv('success', $LANG->line('preferences_updated'));
  1977. }
  1978. if (defined('UB_TMP_GRP'))
  1979. {
  1980. $query = $DB->query("SELECT group_id FROM exp_templates WHERE template_id = '".$DB->escape_str($template_id)."'");
  1981. if ($query->num_rows != 1)
  1982. {
  1983. return $DSP->no_access_message();
  1984. }
  1985. if ($query->row['group_id'] != UB_TMP_GRP)
  1986. {
  1987. return $DSP->no_access_message();
  1988. }
  1989. }
  1990. $query = $DB->query("SELECT template_name, enable_http_auth, group_id, no_auth_bounce FROM exp_templates WHERE template_id = '".$DB->escape_str($template_id)."'");
  1991. foreach ($query->row as $key => $val)
  1992. {
  1993. $$key = $val;
  1994. }
  1995. $DSP->title = $LANG->line('template_access');
  1996. $DSP->crumb = $LANG->line('template_access');
  1997. $r = $DSP->form_open(array('action' => 'C=templates'.AMP.'M=update_template_access', 'name' => 'templateManagement', 'id' => 'templateManagement'))
  1998. .$DSP->input_hidden('template_id', $template_id)
  1999. .$DSP->input_hidden('group_id', $group_id)
  2000. .$DSP->qdiv('tableHeading', $LANG->line('template_access').NBS.'('.$template_name.')')
  2001. .$message;
  2002. $r .= $DSP->qdiv('box', $DSP->qdiv('highlight_alt', $LANG->line('group_restriction')));
  2003. $r .= $DSP->table('tableBorder', '0', '', '100%').
  2004. $DSP->tr().
  2005. $DSP->td('tableHeading', '', '').
  2006. $LANG->line('member_group').
  2007. $DSP->td_c().
  2008. $DSP->td('tableHeading', '', '').
  2009. $LANG->line('can_view_template').
  2010. $DSP->td_c().
  2011. $DSP->tr_c();
  2012. $i = 0;
  2013. $group = array();
  2014. $result = $DB->query("SELECT member_group FROM exp_template_no_access WHERE template_id = '".$DB->escape_str($template_id)."'");
  2015. if ($result->num_rows != 0)
  2016. {
  2017. foreach($result->result as $row)
  2018. {
  2019. $group[$row['member_group']] = TRUE;
  2020. }
  2021. }
  2022. $query = $DB->query("SELECT group_id, group_title FROM exp_member_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND group_id != '1' ORDER BY group_title");
  2023. $access_e = array();
  2024. $r2 = '';
  2025. foreach ($query->result as $row)
  2026. {
  2027. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2028. $r2 .= $DSP->tr().
  2029. $DSP->td($style, '40%').
  2030. $row['group_title'].
  2031. $DSP->td_c().
  2032. $DSP->td($style, '60%');
  2033. $selected = ( ! isset($group[$row['group_id']])) ? 1 : '';
  2034. $r2 .= $LANG->line('yes').NBS.
  2035. $DSP->input_radio('access_'.$row['group_id'], 'y', $selected).$DSP->nbs(3);
  2036. $selected = (isset($group[$row['group_id']])) ? 1 : '';
  2037. $r2 .= $LANG->line('no').NBS.
  2038. $DSP->input_radio('access_'.$row['group_id'], 'n', $selected).$DSP->nbs(3);
  2039. $r2 .= $DSP->td_c()
  2040. .$DSP->tr_c();
  2041. $access_e[] = "access_{$row['group_id']}";
  2042. }
  2043. $access_e[] = 'can_view';
  2044. $access_e[] = 'can_view2';
  2045. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2046. $r3 = $this->template_access_toggle($access_e).
  2047. $DSP->tr().
  2048. $DSP->td('tableCellOne', '40%').
  2049. $DSP->qdiv('defaultBold', $LANG->line('select_all')).
  2050. $DSP->td_c().
  2051. $DSP->td('tableCellOne', '60%').
  2052. $LANG->line('yes').NBS.
  2053. $DSP->input_radio('can_view', 'y', '', "onclick=\"toggle_access(this);\"").$DSP->nbs(3).
  2054. $LANG->line('no').NBS.
  2055. $DSP->input_radio('can_view', 'n', '', "onclick=\"toggle_access(this);\"").$DSP->nbs(3).
  2056. $DSP->td_c().
  2057. $DSP->tr_c();
  2058. $r4 = $this->template_access_toggle($access_e).
  2059. $DSP->tr().
  2060. $DSP->td($style, '40%').
  2061. $DSP->qdiv('defaultBold', $LANG->line('select_all')).
  2062. $DSP->td_c().
  2063. $DSP->td($style, '60%').
  2064. $LANG->line('yes').NBS.
  2065. $DSP->input_radio('can_view2', 'y', '', "onclick=\"toggle_access(this);\"").$DSP->nbs(3).
  2066. $LANG->line('no').NBS.
  2067. $DSP->input_radio('can_view2', 'n', '', "onclick=\"toggle_access(this);\"").$DSP->nbs(3).
  2068. $DSP->td_c().
  2069. $DSP->tr_c();
  2070. $r .= $r3.$r2.$r4.$DSP->table_c();
  2071. $r .= $DSP->div('box');
  2072. $r .= $DSP->heading($LANG->line('no_access_select_blurb'), 5);
  2073. $r .= $DSP->qdiv('itemWrapper', $LANG->line('no_access_instructions'));
  2074. $sql = "SELECT exp_template_groups.group_name, exp_templates.template_name, exp_templates.template_id
  2075. FROM exp_template_groups, exp_templates
  2076. WHERE exp_template_groups.group_id = exp_templates.group_id
  2077. AND exp_template_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'";
  2078. if (USER_BLOG !== FALSE)
  2079. {
  2080. $sql .= " AND exp_template_groups.group_id = '".$DB->escape_str(UB_TMP_GRP)."'";
  2081. }
  2082. else
  2083. {
  2084. $sql .= " AND exp_template_groups.is_user_blog = 'n'";
  2085. }
  2086. $sql .= " ORDER BY exp_template_groups.group_name, exp_templates.template_name";
  2087. $query = $DB->query($sql);
  2088. $r .= $DSP->div()
  2089. .$DSP->input_select_header('no_auth_bounce');
  2090. foreach ($query->result as $row)
  2091. {
  2092. $selected = ($row['template_id'] == $no_auth_bounce) ? 1 : '';
  2093. $r .= $DSP->input_select_option($row['template_id'], $row['group_name'].'/'.$row['template_name'], $selected);
  2094. }
  2095. $r .= $DSP->input_select_footer().BR.BR;
  2096. $r .= $DSP->div('paddedTop');
  2097. $r .= $DSP->heading($LANG->line('enable_http_authentication'), 5);
  2098. $r .= $DSP->qdiv('itemWrapper', $LANG->line('enable_http_authentication_subtext'));
  2099. $r .= $DSP->qdiv('itemWrapper', $DSP->qspan('alert', $LANG->line('enable_http_authentication_note')));
  2100. $r .= $DSP->qdiv('itemWrapper', $DSP->input_checkbox('enable_http_auth', 'y', ($enable_http_auth == 'y') ? 'y' : '')
  2101. .NBS.NBS.$LANG->line('enable_http_authentication'));
  2102. $r .= $DSP->div_c();
  2103. $r .= $DSP->div_c();
  2104. $r .= $DSP->div_c();
  2105. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('submit')))
  2106. .$DSP->form_close();
  2107. $DSP->body = $r;
  2108. }
  2109. /* END */
  2110. /** -------------------------------
  2111. /** Update Template Access
  2112. /** -------------------------------*/
  2113. function update_template_access()
  2114. {
  2115. global $IN, $DSP, $DB, $SESS, $LANG;
  2116. if ( ! $template_id = $IN->GBL('template_id', 'POST'))
  2117. {
  2118. return false;
  2119. }
  2120. if ( ! is_numeric($template_id))
  2121. {
  2122. return false;
  2123. }
  2124. if ( ! $group_id = $IN->GBL('group_id', 'POST'))
  2125. {
  2126. return false;
  2127. }
  2128. $query = $DB->query("SELECT group_id, template_name FROM exp_templates WHERE template_id = '".$DB->escape_str($template_id)."'");
  2129. if ($SESS->userdata['tmpl_group_id'] == 0)
  2130. {
  2131. if ( ! $DSP->allowed_group('can_admin_templates'))
  2132. {
  2133. return $DSP->no_access_message();
  2134. }
  2135. }
  2136. else
  2137. {
  2138. if ($query->row['group_id'] != $SESS->userdata['tmpl_group_id'] )
  2139. {
  2140. return $DSP->no_access_message();
  2141. }
  2142. }
  2143. $DB->query("DELETE FROM exp_template_no_access WHERE template_id = '".$DB->escape_str($template_id)."'");
  2144. $no_auth = FALSE;
  2145. foreach ($_POST as $key => $val)
  2146. {
  2147. if (substr($key, 0, 7) == 'access_' AND $val == 'n')
  2148. {
  2149. $no_auth = TRUE;
  2150. $DB->query("INSERT INTO exp_template_no_access (template_id, member_group) VALUES ('$template_id', '".substr($key, 7)."')");
  2151. }
  2152. }
  2153. $data['no_auth_bounce'] = ($no_auth == TRUE) ? $_POST['no_auth_bounce'] : '';
  2154. $data['enable_http_auth'] = (isset($_POST['enable_http_auth'])) ? 'y' : 'n';
  2155. $DB->query($DB->update_string('exp_templates', $data, "template_id = '$template_id'"));
  2156. return $this->template_access($template_id);
  2157. }
  2158. /* END */
  2159. /** ----------------------------------------
  2160. /** JavaScript Toggle Code for Permissions
  2161. /** ----------------------------------------*/
  2162. function template_access_toggle($elements)
  2163. {
  2164. ob_start();
  2165. ?>
  2166. <script type="text/javascript">
  2167. <!--
  2168. function toggle_access(thebutton)
  2169. {
  2170. var val = thebutton.value;
  2171. <?php
  2172. foreach($elements as $element)
  2173. {
  2174. ?>
  2175. var len = document.getElementById('templateManagement').<?php echo $element; ?>.length;
  2176. for (var i = 0; i < len; i++)
  2177. {
  2178. if (document.getElementById('templateManagement').<?php echo $element; ?>[i].value == val)
  2179. {
  2180. document.getElementById('templateManagement').<?php echo $element; ?>[i].checked = true;
  2181. }
  2182. }
  2183. <?php } ?>
  2184. }
  2185. //-->
  2186. </script>
  2187. <?php
  2188. $out = ob_get_contents();
  2189. ob_end_clean();
  2190. return $out;
  2191. }
  2192. /* END */
  2193. /** -------------------------------
  2194. /** Edit Template
  2195. /** -------------------------------*/
  2196. function edit_template($template_id = '', $message = '')
  2197. {
  2198. global $DSP, $IN, $DB, $EXT, $PREFS, $SESS, $FNS, $LOC, $LANG;
  2199. if ($template_id == '')
  2200. {
  2201. if ( ! $template_id = $IN->GBL('id'))
  2202. {
  2203. return false;
  2204. }
  2205. }
  2206. if ( ! is_numeric($template_id))
  2207. {
  2208. return false;
  2209. }
  2210. $user_blog = ($SESS->userdata['tmpl_group_id'] == 0) ? FALSE : TRUE;
  2211. $query = $DB->query("SELECT group_id, template_name, save_template_file, template_data, template_notes, template_type, edit_date, last_author_id FROM exp_templates WHERE template_id = '$template_id'");
  2212. $group_id = $query->row['group_id'];
  2213. $template_type = $query->row['template_type'];
  2214. $result = $DB->query("SELECT group_name FROM exp_template_groups WHERE group_id = '".$group_id."'");
  2215. $template_group = $result->row['group_name'];
  2216. if ( ! $this->template_access_privs(array('group_id' => $group_id)))
  2217. {
  2218. return $DSP->no_access_message();
  2219. }
  2220. $template_data = $query->row['template_data'];
  2221. $template_name = $query->row['template_name'];
  2222. $template_notes = $query->row['template_notes'];
  2223. $save_template_file = $query->row['save_template_file'];
  2224. $date_fmt = ($SESS->userdata['time_format'] != '') ? $SESS->userdata['time_format'] : $PREFS->ini('time_format');
  2225. if ($date_fmt == 'us')
  2226. {
  2227. $datestr = '%m/%d/%y %h:%i %a';
  2228. }
  2229. else
  2230. {
  2231. $datestr = '%Y-%m-%d %H:%i';
  2232. }
  2233. $edit_date = $LOC->decode_date($datestr, $query->row['edit_date'], TRUE);
  2234. $mquery = $DB->query("SELECT screen_name FROM exp_members WHERE member_id = ".$query->row['last_author_id']);
  2235. if ($mquery->num_rows == 0)
  2236. {
  2237. // this feature was added in 1.6.5, so existing templates following that update will have a member_id of '0'
  2238. // and will not have a known value until the template is edited again.
  2239. $last_author = '';
  2240. }
  2241. else
  2242. {
  2243. $last_author = $mquery->row['screen_name'];
  2244. }
  2245. /* -------------------------------------
  2246. /* 'edit_template_start' hook.
  2247. /* - Allows complete takeover of the template editor
  2248. /* - Added 1.6.0
  2249. */
  2250. $edata = $EXT->call_extension('edit_template_start', $query, $template_id, $message);
  2251. if ($EXT->end_script === TRUE) return;
  2252. /*
  2253. /* -------------------------------------*/
  2254. // Clear old revisions
  2255. if ($PREFS->ini('save_tmpl_revisions') == 'y')
  2256. {
  2257. $maxrev = $PREFS->ini('max_tmpl_revisions');
  2258. if ($maxrev != '' AND is_numeric($maxrev) AND $maxrev > 0)
  2259. {
  2260. $res = $DB->query("SELECT tracker_id FROM exp_revision_tracker WHERE item_id = '$template_id' AND item_table = 'exp_templates' AND item_field ='template_data' ORDER BY tracker_id DESC");
  2261. if ($res->num_rows > 0 AND $res->num_rows > $maxrev)
  2262. {
  2263. $flag = '';
  2264. $ct = 1;
  2265. foreach ($res->result as $row)
  2266. {
  2267. if ($ct >= $maxrev)
  2268. {
  2269. $flag = $row['tracker_id'];
  2270. break;
  2271. }
  2272. $ct++;
  2273. }
  2274. if ($flag != '')
  2275. {
  2276. $DB->query("DELETE FROM exp_revision_tracker WHERE tracker_id < $flag AND item_id = '".$DB->escape_str($template_id)."' AND item_table = 'exp_templates' AND item_field ='template_data'");
  2277. }
  2278. }
  2279. }
  2280. }
  2281. if ($PREFS->ini('save_tmpl_files') == 'y' AND $PREFS->ini('tmpl_file_basepath') != '' AND $save_template_file == 'y')
  2282. {
  2283. $basepath = rtrim($PREFS->ini('tmpl_file_basepath'), '/').'/';
  2284. $basepath .= $template_group.'/'.$template_name.'.php';
  2285. if ($file = $DSP->file_open($basepath))
  2286. {
  2287. $template_data = $file;
  2288. }
  2289. }
  2290. $qs = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  2291. $sitepath = $FNS->fetch_site_index(0, 0).$qs.'URL='.$FNS->fetch_site_index();
  2292. $sitepath = rtrim($sitepath, '/').'/';
  2293. if ($template_type == 'css')
  2294. {
  2295. $sitepath = substr($sitepath, 0, -1);
  2296. $sitepath .= $qs.'css='.$template_group.'/'.$template_name.'/';
  2297. }
  2298. else
  2299. {
  2300. $sitepath .= $template_group.(($template_name == 'index') ? '/' : '/'.$template_name.'/');
  2301. }
  2302. $DSP->title = $LANG->line('edit_template').' | '.$template_name;
  2303. $DSP->crumb = $LANG->line('edit_template');
  2304. $DSP->right_crumb($LANG->line('view_rendered_template'), $sitepath, '', TRUE);
  2305. ob_start();
  2306. ?>
  2307. <script type="text/javascript">
  2308. <!--
  2309. function viewRevision()
  2310. {
  2311. var id = document.forms.revisions.revision_history.value;
  2312. if (id == "")
  2313. {
  2314. return false;
  2315. }
  2316. else if (id == "clear")
  2317. {
  2318. var items = document.forms.revisions.revision_history;
  2319. for (i = items.length -1; i >= 1; i--)
  2320. {
  2321. items.options[i] = null;
  2322. }
  2323. document.forms.revisions.revision_history.options[0].selected = true;
  2324. flipButtonText(1);
  2325. window.open ("<?php echo BASE.'&C=templates&M=clear_revisions&id='.$template_id.'&Z=1'; ?>" ,"Revision", "width=500, height=260, location=0, menubar=0, resizable=0, scrollbars=0, status=0, titlebar=0, toolbar=0, screenX=60, left=60, screenY=60, top=60");
  2326. return false;
  2327. }
  2328. else
  2329. {
  2330. window.open ("<?php echo BASE.'&C=templates&M=revision_history&Z=1'; ?>&id="+id ,"Revision");
  2331. return false;
  2332. }
  2333. return false;
  2334. }
  2335. function flipButtonText(which)
  2336. {
  2337. if (which == "clear")
  2338. {
  2339. document.forms.revisions.submit.value = '<?php echo $LANG->line('clear'); ?>';
  2340. }
  2341. else
  2342. {
  2343. document.forms.revisions.submit.value = '<?php echo $LANG->line('view'); ?>';
  2344. }
  2345. }
  2346. function showhide_notes()
  2347. {
  2348. if (document.getElementById('notes').style.display == "block")
  2349. {
  2350. document.getElementById('notes').style.display = "none";
  2351. document.getElementById('noteslink').style.display = "block";
  2352. }
  2353. else
  2354. {
  2355. document.getElementById('notes').style.display = "block";
  2356. document.getElementById('noteslink').style.display = "none";
  2357. }
  2358. }
  2359. //-->
  2360. </script>
  2361. <?php
  2362. $buffer = ob_get_contents();
  2363. ob_end_clean();
  2364. $r = $buffer;
  2365. $r .= $DSP->form_open(
  2366. array(
  2367. 'action' => '',
  2368. 'name' => 'revisions',
  2369. 'id' => 'revisions'
  2370. ),
  2371. array(
  2372. 'template_id' => $template_id
  2373. )
  2374. );
  2375. $r .= $DSP->table('', '', '', '100%')
  2376. .$DSP->tr()
  2377. .$DSP->td('tableHeading')
  2378. .$LANG->line('template_name').NBS.NBS.$template_group.'/'.$template_name.NBS.NBS
  2379. .'('.$LANG->line('last_edit').NBS.$edit_date
  2380. .(($last_author != '') ? NBS.$LANG->line('by').NBS.$last_author : '').')'
  2381. .$DSP->td_c();
  2382. $r .= $DSP->td('tableHeading')
  2383. .$DSP->div('defaultRight');
  2384. if ($user_blog == FALSE)
  2385. {
  2386. $r .= "<select name='revision_history' class='select' onchange='flipButtonText(this.options[this.selectedIndex].value);'>"
  2387. .NL
  2388. .$DSP->input_select_option('', $LANG->line('revision_history'));
  2389. $rquery = $DB->query("SELECT tracker_id, item_date, screen_name FROM exp_revision_tracker LEFT JOIN exp_members ON exp_members.member_id = exp_revision_tracker.item_author_id WHERE item_table = 'exp_templates' AND item_field = 'template_data' AND item_id = '".$DB->escape_str($template_id)."' ORDER BY tracker_id DESC");
  2390. if ($rquery->num_rows > 0)
  2391. {
  2392. foreach ($rquery->result as $row)
  2393. {
  2394. $r .= $DSP->input_select_option($row['tracker_id'], $LOC->set_human_time($row['item_date']).' ('.$row['screen_name'].')');
  2395. }
  2396. $r .= $DSP->input_select_option('clear', $LANG->line('clear_revision_history'));
  2397. }
  2398. $r .= $DSP->input_select_footer()
  2399. .$DSP->input_submit($LANG->line('view'), 'submit', "onclick='return viewRevision();'");
  2400. }
  2401. else
  2402. {
  2403. $r .= NBS;
  2404. }
  2405. $r .= $DSP->div_c()
  2406. .$DSP->td_c()
  2407. .$DSP->tr_c()
  2408. .$DSP->table_c()
  2409. .$DSP->form_close();
  2410. $r .= $message;
  2411. $r .= $DSP->form_open(array('action' => 'C=templates'.AMP.'M=update_template'))
  2412. .$DSP->input_hidden('template_id', $template_id);
  2413. $r .= $DSP->qdiv('templatepad', $DSP->input_textarea('template_data', $template_data, $SESS->userdata['template_size'], 'textarea', '100%'));
  2414. $notelink = ' <a href="javascript:void(0);" onclick="showhide_notes();return false;"><b>'.$LANG->line('template_notes').'</b></a>';
  2415. $expand = '<img src="'.PATH_CP_IMG.'expand.gif" border="0" width="10" height="10" alt="Expand" />';
  2416. $collapse = '<img src="'.PATH_CP_IMG.'collapse.gif" border="0" width="10" height="10" alt="Collapse" />';
  2417. $js = ' onclick="showhide_notes();return false;" onmouseover="navTabOn(\'noteopen\', \'tableHeadingAlt\', \'tableHeadingAltHover\');" onmouseout="navTabOff(\'noteopen\', \'tableHeadingAlt\', \'tableHeadingAltHover\');" ';
  2418. $r .= '<div id="noteslink" style="display: block; padding:0; margin: 0;">';
  2419. $r .= "<div class='tableHeadingAlt' id='noteopen' ".$js.">";
  2420. $r .= $expand.' '.$LANG->line('template_notes');
  2421. $r .= $DSP->div_c();
  2422. $r .= $DSP->div_c();
  2423. $js = ' onclick="showhide_notes();return false;" onmouseover="navTabOn(\'noteclose\', \'tableHeadingAlt\', \'tableHeadingAltHover\');" onmouseout="navTabOff(\'noteclose\', \'tableHeadingAlt\', \'tableHeadingAltHover\');" ';
  2424. $r .= '<div id="notes" style="display: none; padding:0; margin: 0;">';
  2425. $r .= "<div class='tableHeadingAlt' id='noteclose' ".$js.">";
  2426. $r .= $collapse.' '.$LANG->line('template_notes');
  2427. $r .= $DSP->div_c();
  2428. $r .= $DSP->div('templatebox');
  2429. $r .= $DSP->qdiv('itemWrapper', $LANG->line('template_notes_desc'));
  2430. $r .= $DSP->input_textarea('template_notes', $template_notes, '24', 'textarea', '100%');
  2431. $r .= $DSP->div_c();
  2432. $r .= $DSP->div_c();
  2433. $r .= $DSP->div('templatebox');
  2434. $r .= $DSP->table('', '', '6', '100%')
  2435. .$DSP->tr()
  2436. .$DSP->td('', '25%', '', '', 'top')
  2437. .$DSP->div('bigPad');
  2438. if ($user_blog == FALSE AND $PREFS->ini('save_tmpl_revisions') == 'y')
  2439. {
  2440. $selected = ($PREFS->ini('save_tmpl_revisions') == 'y') ? 1 : '';
  2441. $r .= $DSP->qdiv('itemWrapper', $DSP->input_checkbox('save_history', 'y', $selected).NBS.NBS.$LANG->line('save_history'));
  2442. }
  2443. if ($PREFS->ini('save_tmpl_files') == 'y' AND $PREFS->ini('tmpl_file_basepath') != '')
  2444. {
  2445. $selected = ($save_template_file == 'y') ? 1 : '';
  2446. $r .= $DSP->qdiv('itemWrapper', $DSP->input_checkbox('save_template_file', 'y', $selected).NBS.NBS.$LANG->line('save_template_file'));
  2447. }
  2448. $r .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('update')).NBS.$DSP->input_submit($LANG->line('update_and_return'),'return'));
  2449. $r .= $DSP->td_c()
  2450. .$DSP->td('', '25%', '', '', 'top')
  2451. .$DSP->div('bigPad')
  2452. .$DSP->qdiv('itemWrapper', $DSP->input_text('columns', $SESS->userdata['template_size'], '4', '2', 'input', '30px').NBS.NBS.$LANG->line('template_size'))
  2453. .$DSP->div_c()
  2454. .$DSP->td_c()
  2455. .$DSP->tr_c()
  2456. .$DSP->table_c()
  2457. .$DSP->div_c();
  2458. $r .= $DSP->form_close();
  2459. // TEMPLATE EXPORT LINK
  2460. $r .= <<<EOT
  2461. <script type="text/javascript">
  2462. <!--
  2463. function export_template()
  2464. {
  2465. document.forms['export_template_form'].export_data.value = document.getElementById('template_data').value;
  2466. document.forms['export_template_form'].submit();
  2467. }
  2468. //-->
  2469. </script>
  2470. EOT;
  2471. $r .= $DSP->form_open(array('action' => 'C=templates'.AMP.'M=export_template'.AMP.'id='.$group_id.AMP.'tid='.$template_id,
  2472. 'id' => "export_template_form"),
  2473. array('export_data' => ''));
  2474. $r .= $DSP->qdiv('itemWrapper', $DSP->anchor('javascript:nullo();', $LANG->line('export_template'), 'onclick="export_template();return false;"'));
  2475. $r .= $DSP->form_close();
  2476. /* -------------------------------------
  2477. /* 'edit_template_end' hook.
  2478. /* - Allows content to be added to the output
  2479. /* - Added 1.6.0
  2480. */
  2481. if ($EXT->active_hook('edit_template_end') === TRUE)
  2482. {
  2483. $r .= $EXT->call_extension('edit_template_end', $query, $template_id);
  2484. if ($EXT->end_script === TRUE) return;
  2485. }
  2486. /*
  2487. /* -------------------------------------*/
  2488. $DSP->body = $r;
  2489. }
  2490. /* END */
  2491. /** -------------------------------
  2492. /** Update Template
  2493. /** -------------------------------*/
  2494. function update_template()
  2495. {
  2496. global $PREFS, $DSP, $IN, $DB, $EXT, $LOC, $SESS, $FNS, $LANG;
  2497. if ( ! $template_id = $IN->GBL('template_id', 'POST'))
  2498. {
  2499. return false;
  2500. }
  2501. if ( ! is_numeric($template_id))
  2502. {
  2503. return false;
  2504. }
  2505. if ( ! $this->template_access_privs(array('template_id' => $template_id)))
  2506. {
  2507. return $DSP->no_access_message();
  2508. }
  2509. $save_result = FALSE;
  2510. $save_template_file = ($IN->GBL('save_template_file', 'POST') == 'y') ? 'y' : 'n';
  2511. /** -------------------------------
  2512. /** Save template as file
  2513. /** -------------------------------*/
  2514. // Depending on how things are set up we might save the template data in a text file
  2515. if ($PREFS->ini('tmpl_file_basepath') != '' AND $PREFS->ini('save_tmpl_files') == 'y')
  2516. {
  2517. $query = $DB->query("SELECT exp_templates.template_name, exp_templates.save_template_file, exp_template_groups.group_name
  2518. FROM exp_templates
  2519. LEFT JOIN exp_template_groups ON exp_templates.group_id = exp_template_groups.group_id
  2520. WHERE template_id = '".$DB->escape_str($template_id)."'");
  2521. if ($save_template_file == 'y')
  2522. {
  2523. $tdata = array(
  2524. 'template_id' => $template_id,
  2525. 'template_group' => $query->row['group_name'],
  2526. 'template_name' => $query->row['template_name'],
  2527. 'template_data' => $_POST['template_data'],
  2528. 'edit_date' => $LOC->now,
  2529. 'last_author_id' => $SESS->userdata['member_id']
  2530. );
  2531. $save_result = $this->update_template_file($tdata);
  2532. }
  2533. else
  2534. {
  2535. // If the template was previously saved as a text file,
  2536. // but the checkbox was not selected this time we'll
  2537. // delete the file
  2538. if ($query->row['save_template_file'] == 'y')
  2539. {
  2540. $basepath = rtrim($PREFS->ini('tmpl_file_basepath'), '/').'/';
  2541. $basepath .= $query->row['group_name'].'/'.$query->row['template_name'].'.php';
  2542. @unlink($basepath);
  2543. }
  2544. }
  2545. }
  2546. /** -------------------------------
  2547. /** Save revision cache
  2548. /** -------------------------------*/
  2549. if ($IN->GBL('save_history', 'POST') == 'y')
  2550. {
  2551. $data = array(
  2552. 'tracker_id' => '',
  2553. 'item_id' => $template_id,
  2554. 'item_table' => 'exp_templates',
  2555. 'item_field' => 'template_data',
  2556. 'item_data' => $_POST['template_data'],
  2557. 'item_date' => $LOC->now,
  2558. 'item_author_id' => $SESS->userdata['member_id']
  2559. );
  2560. $DB->query($DB->insert_string('exp_revision_tracker', $data));
  2561. }
  2562. /** -------------------------------
  2563. /** Save Template
  2564. /** -------------------------------*/
  2565. $DB->query($DB->update_string('exp_templates', array('template_data' => $_POST['template_data'], 'edit_date' => $LOC->now, 'last_author_id' => $SESS->userdata['member_id'], 'save_template_file' => $save_template_file, 'template_notes' => $_POST['template_notes']), "template_id = '$template_id'"));
  2566. if (is_numeric($_POST['columns']))
  2567. {
  2568. if ($SESS->userdata['template_size'] != $_POST['columns'])
  2569. {
  2570. $DB->query("UPDATE exp_members SET template_size = '".$DB->escape_str($_POST['columns'])."' WHERE member_id = '".$SESS->userdata('member_id')."'");
  2571. $SESS->userdata['template_size'] = $_POST['columns'];
  2572. }
  2573. }
  2574. // Clear cache files
  2575. $FNS->clear_caching('all');
  2576. $message = $DSP->qdiv('success', $LANG->line('template_updated'));
  2577. if ($save_template_file == 'y' AND $save_result == FALSE)
  2578. {
  2579. $message .= $DSP->qdiv('alert', $LANG->line('template_not_saved'));
  2580. }
  2581. /* -------------------------------------
  2582. /* 'update_template_end' hook.
  2583. /* - Add more things to do for template
  2584. /* - Added 1.6.0
  2585. */
  2586. $edata = $EXT->call_extension('update_template_end', $template_id, $message);
  2587. if ($EXT->end_script === TRUE) return;
  2588. /*
  2589. /* -------------------------------------*/
  2590. if (($tgpref = $IN->GBL('tgpref')) AND is_numeric($tgpref) AND isset($_POST['return']))
  2591. {
  2592. $FNS->redirect(BASE.AMP.'C=templates'.AMP.'tgpref='.$tgpref);
  2593. exit;
  2594. }
  2595. else
  2596. {
  2597. return $this->edit_template($template_id, $message);
  2598. }
  2599. }
  2600. /* END */
  2601. /** -----------------------------
  2602. /** Update Template File
  2603. /** -----------------------------*/
  2604. function update_template_file($data)
  2605. {
  2606. global $PREFS, $DB;
  2607. if ( ! $this->template_access_privs(array('template_id' => $data['template_id'])))
  2608. {
  2609. return FALSE;
  2610. }
  2611. if ($PREFS->ini('save_tmpl_files') == 'n' OR $PREFS->ini('tmpl_file_basepath') == '')
  2612. {
  2613. return FALSE;
  2614. }
  2615. $basepath = $PREFS->ini('tmpl_file_basepath', TRUE);
  2616. if ( ! @is_dir($basepath) OR ! is_writable($basepath))
  2617. {
  2618. return FALSE;
  2619. }
  2620. $basepath .= $data['template_group'];
  2621. if ( ! @is_dir($basepath))
  2622. {
  2623. if ( ! @mkdir($basepath, 0777))
  2624. {
  2625. return FALSE;
  2626. }
  2627. @chmod($basepath, 0777);
  2628. }
  2629. if ( ! $fp = @fopen($basepath.'/'.$data['template_name'].'.php', 'wb'))
  2630. {
  2631. return FALSE;
  2632. }
  2633. else
  2634. {
  2635. flock($fp, LOCK_EX);
  2636. fwrite($fp, stripslashes($data['template_data']));
  2637. flock($fp, LOCK_UN);
  2638. fclose($fp);
  2639. @chmod($basepath.'/'.$data['template_name'].'.php', 0777);
  2640. }
  2641. return TRUE;
  2642. }
  2643. /* END */
  2644. /** -----------------------------
  2645. /** View Revision History
  2646. /** -----------------------------*/
  2647. function view_template_revision()
  2648. {
  2649. global $DSP, $REGX, $IN, $DB, $LANG;
  2650. if ( ! $id = $IN->GBL('id'))
  2651. {
  2652. return false;
  2653. }
  2654. $query = $DB->query("SELECT item_id FROM exp_revision_tracker WHERE tracker_id = '".$DB->escape_str($id)."' AND item_table = 'exp_templates' AND item_field = 'template_data'");
  2655. if ($query->num_rows == 0)
  2656. {
  2657. return false;
  2658. }
  2659. if ( ! $this->template_access_privs(array('template_id' => $query->row['item_id'])))
  2660. {
  2661. return $DSP->no_access_message();
  2662. }
  2663. $DSP->title = $LANG->line('revision_history');
  2664. $DSP->crumb = $LANG->line('revision_history');
  2665. $query = $DB->query("SELECT item_data FROM exp_revision_tracker WHERE tracker_id = '".$DB->escape_str($id)."' ");
  2666. $DSP->body = $DSP->input_textarea('template_data', $query->row['item_data'], 26, 'textarea', '100%');
  2667. $DSP->body .= $DSP->qdiv('itemWrapper', BR.'<div align="center"><a href="JavaScript:window.close();"><b>'.$LANG->line('close_window').'</b></a></div>');
  2668. }
  2669. /* END */
  2670. /** -----------------------------
  2671. /** Clear Revision History
  2672. /** -----------------------------*/
  2673. function clear_revision_history()
  2674. {
  2675. global $DSP, $DB, $IN, $LANG;
  2676. if ( ! $DSP->allowed_group('can_admin_templates'))
  2677. {
  2678. return $DSP->no_access_message();
  2679. }
  2680. if ( ! $id = $IN->GBL('id'))
  2681. {
  2682. return false;
  2683. }
  2684. $DSP->title = $LANG->line('revision_history');
  2685. $DSP->crumb = $LANG->line('revision_history');
  2686. $query = $DB->query("DELETE FROM exp_revision_tracker WHERE item_id = '".$DB->escape_str($id)."' AND item_table = 'exp_templates' AND item_field ='template_data'");
  2687. $DSP->body = $DSP->qdiv('defaultCenter', BR.BR.'<b>'.$LANG->line('history_cleared').'</b>'.BR.BR.BR);
  2688. $DSP->body .= $DSP->qdiv('defaultCenter', "<a href='javascript:window.close();'>".$LANG->line('close_window')."</a>".BR.BR.BR);
  2689. }
  2690. /* END */
  2691. /** -----------------------------
  2692. /** Export template form
  2693. /** -----------------------------*/
  2694. function export_templates_form($group_id = '')
  2695. {
  2696. global $IN, $SESS, $DSP, $DB, $LANG;
  2697. if ($group_id == '')
  2698. {
  2699. if ( ! $group_id = $IN->GBL('id'))
  2700. {
  2701. return false;
  2702. }
  2703. }
  2704. if ($SESS->userdata['tmpl_group_id'] != 0)
  2705. {
  2706. $group_id = $SESS->userdata['tmpl_group_id'];
  2707. }
  2708. if ( ! $this->template_access_privs(array('group_id' => $group_id)))
  2709. {
  2710. return $DSP->no_access_message();
  2711. }
  2712. $LANG->fetch_language_file('admin');
  2713. $sql = "SELECT group_name FROM exp_template_groups WHERE group_id = '".$DB->escape_str($group_id)."'";
  2714. $query = $DB->query($sql);
  2715. if ($query->num_rows == 0)
  2716. {
  2717. return false;
  2718. }
  2719. $r = $this->toggle_code();
  2720. $r .= $DSP->qdiv('tableHeading', $LANG->line('export_templates'));
  2721. $r .= $DSP->qdiv('box', $DSP->qdiv('highlight_alt', $LANG->line('choose_templates')));
  2722. $r .= $DSP->form_open(
  2723. array(
  2724. 'action' => 'C=templates'.AMP.'M=export'.AMP.'id='.$group_id,
  2725. 'name' => 'templates',
  2726. 'id' => 'templates'
  2727. )
  2728. );
  2729. $template_group = $query->row['group_name'];
  2730. $r .= $DSP->table('tableBorder', '0', '', '100%')
  2731. .$DSP->tr()
  2732. .$DSP->table_qcell('tableHeadingAlt', $LANG->line('template_name'), '32%')
  2733. .$DSP->table_qcell('tableHeadingAlt', $DSP->input_checkbox('toggleflag', '', '', "onclick=\"toggle(this);\"").NBS.NBS.$LANG->line('select_all'), '17%')
  2734. .$DSP->td_c()
  2735. .$DSP->tr_c();
  2736. $i = 0;
  2737. $res = $DB->query("SELECT template_id, template_name, hits FROM exp_templates WHERE group_id = '".$DB->escape_str($group_id)."' ORDER BY template_name");
  2738. foreach ($res->result as $val)
  2739. {
  2740. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2741. $r .= $DSP->tr();
  2742. $r .= $DSP->table_qcell($style, $DSP->qdiv('defaultBold', $val['template_name']));
  2743. $r .= $DSP->table_qcell($style, "<input type='checkbox' name=\"template[".$val['template_id']."]\" value='y' />")
  2744. .$DSP->tr_c();
  2745. }
  2746. $r .= $DSP->table_c();
  2747. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('export_will_be_zip')));
  2748. $r .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('export')));
  2749. $r .= $DSP->form_close();
  2750. $DSP->title = $LANG->line('export_templates');
  2751. $DSP->crumb = $LANG->line('export_templates');
  2752. $DSP->body = $r;
  2753. }
  2754. /* END */
  2755. /** -------------------------------------------
  2756. /** JavaScript toggle code
  2757. /** -------------------------------------------*/
  2758. function toggle_code()
  2759. {
  2760. ob_start();
  2761. ?>
  2762. <script type="text/javascript">
  2763. <!--
  2764. function toggle(thebutton)
  2765. {
  2766. if (thebutton.checked)
  2767. {
  2768. val = true;
  2769. }
  2770. else
  2771. {
  2772. val = false;
  2773. }
  2774. var len = document.templates.elements.length;
  2775. for (var i = 0; i < len; i++)
  2776. {
  2777. var button = document.templates.elements[i];
  2778. var name_array = button.name.split("[");
  2779. if (name_array[0] == "template")
  2780. {
  2781. button.checked = val;
  2782. }
  2783. }
  2784. document.templates.toggleflag.checked = val;
  2785. }
  2786. //-->
  2787. </script>
  2788. <?php
  2789. $buffer = ob_get_contents();
  2790. ob_end_clean();
  2791. return $buffer;
  2792. }
  2793. /* END */
  2794. /** -----------------------------
  2795. /** Export single template
  2796. /** -----------------------------*/
  2797. function export_template()
  2798. {
  2799. global $IN;
  2800. if ( ! is_numeric($IN->GBL('tid')))
  2801. {
  2802. return FALSE;
  2803. }
  2804. $_POST['template'][$IN->GBL('tid')] = $IN->GBL('tid');
  2805. $this->export_templates('default');
  2806. }
  2807. /* END */
  2808. /** -----------------------------
  2809. /** Export templates
  2810. /** -----------------------------*/
  2811. function export_templates($type='zip')
  2812. {
  2813. global $IN, $SESS, $DSP, $DB, $LOC, $FNS, $LANG;
  2814. if ( ! $group_id = $IN->GBL('id'))
  2815. {
  2816. return false;
  2817. }
  2818. /** --------------------------------------
  2819. /** Is the user allowed to export?
  2820. /** --------------------------------------*/
  2821. if ($SESS->userdata['tmpl_group_id'] != 0)
  2822. {
  2823. $group_id = $SESS->userdata['tmpl_group_id'];
  2824. }
  2825. if ( ! $this->template_access_privs(array('group_id' => $group_id)))
  2826. {
  2827. return $DSP->no_access_message();
  2828. }
  2829. /** --------------------------------------
  2830. /** No templates? Bounce them back
  2831. /** --------------------------------------*/
  2832. if ( ! isset($_POST['template']))
  2833. {
  2834. return $this->export_templates_form($group_id);
  2835. }
  2836. /** --------------------------------------
  2837. /** Is the selected compression supported?
  2838. /** --------------------------------------*/
  2839. if ( ! @function_exists('gzcompress') && $type == 'zip')
  2840. {
  2841. return $DSP->error_message($LANG->line('unsupported_compression'));
  2842. }
  2843. /** --------------------------------------
  2844. /** Assign the name of the of the folder
  2845. /** --------------------------------------*/
  2846. $query = $DB->query("SELECT group_name, is_site_default FROM exp_template_groups WHERE group_id = '$group_id'");
  2847. $directory = $query->row['group_name'].'_tmpl';
  2848. /** --------------------------------------
  2849. /** Fetch the template data and zip it
  2850. /** --------------------------------------*/
  2851. if ($type == 'default' && sizeof($_POST['template']) == 1)
  2852. {
  2853. $directory = $query->row['group_name'].'_';
  2854. $query = $DB->query("SELECT template_data, template_name, template_type FROM exp_templates WHERE template_id = '".$DB->escape_str(array_pop(array_keys($_POST['template'])))."'");
  2855. $output = ( ! isset($_POST['export_data']) OR $_POST['export_data'] == '') ? $query->row['template_data'] : stripslashes($_POST['export_data']);
  2856. $directory .= $query->row['template_name'];
  2857. switch($query->row['template_type'])
  2858. {
  2859. case 'css' :
  2860. $suffix = 'css';
  2861. $content_type = 'application/force-download';
  2862. break;
  2863. case 'js' :
  2864. $suffix = 'js';
  2865. $content_type = 'application/force-download';
  2866. break;
  2867. case 'rss' :
  2868. $suffix = 'xml';
  2869. $content_type = 'application/force-download';
  2870. break;
  2871. case 'static' :
  2872. $suffix = 'txt';
  2873. $content_type = 'application/force-download';
  2874. break;
  2875. case 'webpage' :
  2876. $suffix = 'html';
  2877. $content_type = 'application/force-download';
  2878. break;
  2879. case 'xml' :
  2880. $suffix = 'xml';
  2881. $content_type = 'application/force-download';
  2882. break;
  2883. default :
  2884. $suffix = 'txt';
  2885. $content_type = 'application/force-download';
  2886. break;
  2887. }
  2888. }
  2889. else
  2890. {
  2891. require PATH_CP.'cp.utilities'.EXT;
  2892. $zip = new Zipper;
  2893. $temp_data = array();
  2894. // $zip->add_dir($directory.'/');
  2895. foreach ($_POST['template'] as $key => $val)
  2896. {
  2897. $query = $DB->query("SELECT template_data, template_name FROM exp_templates WHERE template_id = '".$DB->escape_str($key)."'");
  2898. $zip->add_file($query->row['template_data'], $directory.'/'.$query->row['template_name'].'.txt');
  2899. }
  2900. $suffix = 'zip';
  2901. $content_type = 'application/x-zip';
  2902. }
  2903. /** -------------------------------------------
  2904. /** Write out the headers
  2905. /** -------------------------------------------*/
  2906. ob_start();
  2907. if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
  2908. {
  2909. header('Content-Type: '.$content_type);
  2910. header('Content-Disposition: inline; filename="'.$directory.'.'.$suffix.'"');
  2911. header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
  2912. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  2913. header('Pragma: public');
  2914. }
  2915. else
  2916. {
  2917. header('Content-Type: '.$content_type);
  2918. header('Content-Disposition: attachment; filename="'.$directory.'.'.$suffix.'"');
  2919. header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
  2920. header('Pragma: no-cache');
  2921. }
  2922. if (isset($output))
  2923. {
  2924. echo $output;
  2925. }
  2926. else
  2927. {
  2928. echo $zip->output_zipfile();
  2929. }
  2930. $buffer = ob_get_contents();
  2931. ob_end_clean();
  2932. echo $buffer;
  2933. exit;
  2934. }
  2935. /* END */
  2936. /** -----------------------------
  2937. /** Global Variables
  2938. /** -----------------------------*/
  2939. function global_variables($message = '')
  2940. {
  2941. global $DSP, $DB, $LANG, $SESS, $PREFS;
  2942. if ($SESS->userdata['tmpl_group_id'] == 0)
  2943. {
  2944. if ( ! $DSP->allowed_group('can_admin_templates'))
  2945. {
  2946. return $DSP->no_access_message();
  2947. }
  2948. }
  2949. $DSP->title = $LANG->line('global_variables');
  2950. $DSP->crumb = $LANG->line('global_variables');
  2951. $DSP->right_crumb($LANG->line('create_new_global_variable'), BASE.AMP.'C=templates'.AMP.'M=edit_global_var');
  2952. if ($message != '')
  2953. {
  2954. $DSP->body .= $DSP->qdiv('successBox', $DSP->qdiv('success', $message));
  2955. }
  2956. $i = 0;
  2957. $s1 = 'tableCellOne';
  2958. $s2 = 'tableCellTwo';
  2959. $id = ( ! defined('UB_BLOG_ID')) ? 0 : UB_BLOG_ID;
  2960. $query = $DB->query("SELECT variable_id, variable_name, variable_data FROM exp_global_variables WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND user_blog_id = '".$DB->escape_str($id)."' ORDER BY variable_name ASC");
  2961. /** -----------------------------
  2962. /** Table Header
  2963. /** -----------------------------*/
  2964. $DSP->body .= $DSP->table('tableBorder', '0', '0', '100%').
  2965. $DSP->tr().
  2966. $DSP->table_qcell('tableHeading',
  2967. ($query->num_rows == 0) ?
  2968. array($LANG->line('global_variables')) :
  2969. array($LANG->line('global_variables'),
  2970. $LANG->line('global_variable_syntax'),
  2971. $LANG->line('delete')
  2972. )
  2973. ).
  2974. $DSP->tr_c();
  2975. /** -----------------------------
  2976. /** Table Rows
  2977. /** -----------------------------*/
  2978. if ($query->num_rows == 0)
  2979. {
  2980. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  2981. array(
  2982. $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('no_global_variables')))
  2983. )
  2984. );
  2985. }
  2986. else
  2987. {
  2988. foreach ($query->result as $row)
  2989. {
  2990. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  2991. array(
  2992. $DSP->qspan('defaultBold', $DSP->anchor(BASE.AMP.'C=templates'.AMP.'M=edit_global_var'.AMP.'id='.$row['variable_id'], $row['variable_name'])),
  2993. $DSP->qspan('defaultBold', '{'.$row['variable_name'].'}'),
  2994. $DSP->qspan('defaultBold', $DSP->anchor(BASE.AMP.'C=templates'.AMP.'M=delete_global_var'.AMP.'id='.$row['variable_id'], $LANG->line('delete'))),
  2995. )
  2996. );
  2997. }
  2998. }
  2999. $DSP->body .= $DSP->table_c();
  3000. }
  3001. /* END */
  3002. /** -----------------------------
  3003. /** Create/Edit Global Variables
  3004. /** -----------------------------*/
  3005. function edit_global_variable()
  3006. {
  3007. global $IN, $DSP, $DB, $LANG, $SESS, $PREFS;
  3008. if ($SESS->userdata['tmpl_group_id'] == 0)
  3009. {
  3010. if ( ! $DSP->allowed_group('can_admin_templates'))
  3011. {
  3012. return $DSP->no_access_message();
  3013. }
  3014. }
  3015. $DSP->title = $LANG->line('global_variables');
  3016. $DSP->crumb = $LANG->line('global_variables');
  3017. $DSP->body = $DSP->qdiv('tableHeading', $LANG->line('global_variables'));
  3018. $DSP->body .= $DSP->form_open(array('action' => 'C=templates'.AMP.'M=update_global_var'));
  3019. $variable_name = '';
  3020. $variable_data = '';
  3021. $id = $IN->GBL('id');
  3022. $ub_id = ( ! defined('UB_BLOG_ID')) ? 0 : UB_BLOG_ID;
  3023. if ($id != FALSE)
  3024. {
  3025. $query = $DB->query("SELECT variable_name, variable_data, user_blog_id FROM exp_global_variables WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND variable_id = '".$DB->escape_str($id)."' ");
  3026. if ($query->num_rows == 1)
  3027. {
  3028. if ($query->row['user_blog_id'] == $ub_id)
  3029. {
  3030. $DSP->body .= $DSP->input_hidden('id', $id);
  3031. $variable_name = $query->row['variable_name'];
  3032. $variable_data = $query->row['variable_data'];
  3033. }
  3034. }
  3035. }
  3036. $DSP->body .= $DSP->div('box')
  3037. .$DSP->heading(BR.$LANG->line('variable_name', 'variable_name'), 5)
  3038. .$DSP->qdiv('itemWrapper', $LANG->line('template_group_instructions'))
  3039. .$DSP->qdiv('itemWrapper', $LANG->line('undersores_allowed'))
  3040. .$DSP->qdiv('itemWrapper', $DSP->input_text('variable_name', $variable_name, '20', '50', 'input', '240px'))
  3041. .$DSP->heading(BR.$LANG->line('variable_data'), 5)
  3042. .$DSP->input_textarea('variable_data', $variable_data, '15', 'textarea', '100%')
  3043. .$DSP->div_c();
  3044. $DSP->body .= $DSP->div('itemWrapperTop');
  3045. if ($id == FALSE)
  3046. $DSP->body .= $DSP->input_submit($LANG->line('submit'));
  3047. else
  3048. $DSP->body .= $DSP->input_submit($LANG->line('update'));
  3049. $DSP->body .= $DSP->div_c();
  3050. $DSP->body .= $DSP->form_close();
  3051. }
  3052. /* END */
  3053. /** -----------------------------
  3054. /** Insert/Update a Global Var
  3055. /** -----------------------------*/
  3056. function update_global_variable()
  3057. {
  3058. global $IN, $DSP, $DB, $LANG, $SESS, $PREFS;
  3059. if ($SESS->userdata['tmpl_group_id'] == 0)
  3060. {
  3061. if ( ! $DSP->allowed_group('can_admin_templates'))
  3062. {
  3063. return $DSP->no_access_message();
  3064. }
  3065. }
  3066. if ($_POST['variable_name'] == '' || $_POST['variable_data'] == '')
  3067. {
  3068. return $DSP->error_message($LANG->line('all_fields_required'));
  3069. }
  3070. if ( ! preg_match("#^[a-zA-Z0-9_\-/]+$#i", $_POST['variable_name']))
  3071. {
  3072. return $DSP->error_message($LANG->line('illegal_characters'));
  3073. }
  3074. if (in_array($_POST['variable_name'], $this->reserved_vars))
  3075. {
  3076. return $DSP->error_message($LANG->line('reserved_name'));
  3077. }
  3078. $id = $IN->GBL('id');
  3079. $ub_id = ( ! defined('UB_BLOG_ID')) ? 0 : UB_BLOG_ID;
  3080. if ($id != FALSE)
  3081. {
  3082. $DB->query("UPDATE exp_global_variables SET variable_name = '".$DB->escape_str($_POST['variable_name'])."', variable_data = '".$DB->escape_str($_POST['variable_data'])."' WHERE variable_id = '$id' AND user_blog_id = '$ub_id'");
  3083. $msg = $LANG->line('global_var_updated');
  3084. }
  3085. else
  3086. {
  3087. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_global_variables WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND variable_name = '".$DB->escape_str($_POST['variable_name'])."'");
  3088. if ($query->row['count'] > 0)
  3089. {
  3090. return $DSP->error_message($LANG->line('duplicate_var_name'));
  3091. }
  3092. $DB->query("INSERT INTO exp_global_variables (variable_id, site_id, variable_name, variable_data, user_blog_id) VALUES ('', '".$DB->escape_str($PREFS->ini('site_id'))."', '".$DB->escape_str($_POST['variable_name'])."', '".$DB->escape_str($_POST['variable_data'])."', '$ub_id')");
  3093. $msg = $LANG->line('global_var_created');
  3094. }
  3095. return $this->global_variables($msg);
  3096. }
  3097. /* END */
  3098. /** -----------------------------
  3099. /** Global Var Delete Conf
  3100. /** -----------------------------*/
  3101. function global_variable_delete_conf()
  3102. {
  3103. global $DSP, $DB, $IN, $LANG, $SESS;
  3104. if ($SESS->userdata['tmpl_group_id'] == 0)
  3105. {
  3106. if ( ! $DSP->allowed_group('can_admin_templates'))
  3107. {
  3108. return $DSP->no_access_message();
  3109. }
  3110. }
  3111. $DSP->title = $LANG->line('delete_global_variable');
  3112. $DSP->crumb = $LANG->line('delete_global_variable');
  3113. if ( ! $id = $IN->GBL('id'))
  3114. {
  3115. return false;
  3116. }
  3117. $ub_id = ( ! defined('UB_BLOG_ID')) ? 0 : UB_BLOG_ID;
  3118. $query = $DB->query("SELECT variable_name FROM exp_global_variables WHERE variable_id = '".$DB->escape_str($id)."' AND user_blog_id = '".$DB->escape_str($ub_id)."' ");
  3119. if ($query->num_rows == 0)
  3120. {
  3121. return false;
  3122. }
  3123. $DSP->body = $DSP->delete_confirmation(
  3124. array(
  3125. 'url' => 'C=templates'.AMP.'M=do_delete_global_var',
  3126. 'heading' => 'delete_global_variable',
  3127. 'message' => 'delete_this_variable',
  3128. 'item' => $query->row['variable_name'],
  3129. 'extra' => '',
  3130. 'hidden' => array('id' => $id)
  3131. )
  3132. );
  3133. }
  3134. /* END */
  3135. /** -----------------------------
  3136. /** Delete Global Variable
  3137. /** -----------------------------*/
  3138. function delete_global_variable()
  3139. {
  3140. global $DSP, $DB, $IN, $LANG, $SESS;
  3141. if ($SESS->userdata['tmpl_group_id'] == 0)
  3142. {
  3143. if ( ! $DSP->allowed_group('can_admin_templates'))
  3144. {
  3145. return $DSP->no_access_message();
  3146. }
  3147. }
  3148. if ( ! $id = $IN->GBL('id', 'POST'))
  3149. {
  3150. return false;
  3151. }
  3152. $ub_id = ( ! defined('UB_BLOG_ID')) ? 0 : UB_BLOG_ID;
  3153. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_global_variables WHERE variable_id = '".$DB->escape_str($id)."' AND user_blog_id = '".$DB->escape_str($ub_id)."' ");
  3154. if ($query->row['count'] == 0)
  3155. {
  3156. return false;
  3157. }
  3158. $DB->query("DELETE FROM exp_global_variables WHERE variable_id = '".$DB->escape_str($id)."' AND user_blog_id = '".$DB->escape_str($ub_id)."' ");
  3159. return $this->global_variables($LANG->line('variable_deleted'));
  3160. }
  3161. /* END */
  3162. }
  3163. // END CLASS
  3164. ?>