PageRenderTime 66ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/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

Large files files are truncated, but you can click here to view the full 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 =

Large files files are truncated, but you can click here to view the full file