source: trunk/plugins/LocalFilesEditor/include/tpl.inc.php @ 11654

Last change on this file since 11654 was 11654, checked in by patdenice, 13 years ago

merge r11653 from branch 2.2 to trunk
No warning with new empty tpl file

File size: 3.9 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5$edited_file = isset($_POST['edited_file']) ? $_POST['edited_file'] : '';
6$content_file = '';
7
8if ((isset($_POST['edit'])) and !is_numeric($_POST['file_to_edit']))
9{
10  $edited_file = $_POST['file_to_edit'];
11  if (file_exists($edited_file))
12  {
13    $content_file = file_get_contents($edited_file);
14  }
15  else
16  {
17    $content_file = '';
18  }
19}
20
21$newfile_page = isset($_GET['newfile']);
22
23// Edit new tpl file
24if (isset($_POST['create_tpl']))
25{
26  $filename = $_POST['tpl_name'];
27  if (empty($filename))
28  {
29    array_push($page['errors'], l10n('locfiledit_empty_filename'));
30  }
31  if (get_extension($filename) != 'tpl')
32  {
33    $filename .= '.tpl';
34  }
35  if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
36  {
37    array_push($page['errors'], l10n('locfiledit_filename_error'));
38  }
39  if (is_numeric($_POST['tpl_model']) and $_POST['tpl_model'] != '0')
40  {
41    array_push($page['errors'], l10n('locfiledit_model_error'));
42  }
43  if (file_exists($_POST['tpl_parent'] . '/' . $filename))
44  {
45    array_push($page['errors'], l10n('locfiledit_file_already_exists'));
46  }
47  if (!empty($page['errors']))
48  {
49    $newfile_page = true;
50  }
51  else
52  {
53    $edited_file = $_POST['tpl_parent'] . '/' . $filename;
54    $content_file = ($_POST['tpl_model'] == '0') ? '' : file_get_contents($_POST['tpl_model']);
55  }
56}
57
58if ($newfile_page)
59{
60  $filename = isset($_POST['tpl_name']) ? $_POST['tpl_name'] : '';
61  $selected['model'] = isset($_POST['tpl_model']) ? $_POST['tpl_model'] : '0';
62  $selected['parent'] = isset($_POST['tpl_parent']) ? $_POST['tpl_parent'] : PHPWG_ROOT_PATH . 'template-extension';
63
64  // Parent directories list
65  $options['parent'] = array(PHPWG_ROOT_PATH . 'template-extension' => 'template-extension');
66  $options['parent'] = array_merge($options['parent'], get_rec_dirs(PHPWG_ROOT_PATH . 'template-extension'));
67
68  $options['model'][] = l10n('locfiledit_empty_page');
69  $options['model'][] = '----------------------';
70  $i = 0;
71  foreach (get_extents() as $pwg_template)
72  {
73    $value = PHPWG_ROOT_PATH . 'template-extension/' . $pwg_template;
74    $options['model'][$value] =  'template-extension / ' . str_replace('/', ' / ', $pwg_template);
75    $i++;
76  }
77  foreach (get_dirs($conf['themes_dir']) as $theme_id)
78  {
79    if ($i)
80    {
81      $options['model'][] = '----------------------';
82      $i = 0;
83    }
84    $dir = $conf['themes_dir'] . '/' . $theme_id . '/template/';
85    if (is_dir($dir) and $content = opendir($dir))
86    {
87      while ($node = readdir($content))
88      {
89        if (is_file($dir.$node) and get_extension($node) == 'tpl')
90        {
91          $value = $dir . $node;
92          $options['model'][$value] = $theme_id . ' / ' . $node;
93          $i++;
94        }
95      }
96    }
97  }
98  if (end($options['model']) == '----------------------')
99  {
100    array_pop($options['model']);
101  }
102  // Assign variables to template
103  $template->assign('create_tpl', array(
104    'NEW_FILE_NAME' => $filename,
105    'MODEL_OPTIONS' => $options['model'],
106    'MODEL_SELECTED' => $selected['model'],
107    'PARENT_OPTIONS' => $options['parent'],
108    'PARENT_SELECTED' => $selected['parent']
109    )
110  );
111}
112else
113{
114  // List existing template extensions
115  $selected = 0; 
116  $options[] = l10n('locfiledit_choose_file');
117  $options[] = '----------------------';
118  foreach (get_extents() as $pwg_template)
119  {
120    $value = './template-extension/' . $pwg_template;
121    $options[$value] =  str_replace('/', ' / ', $pwg_template);
122    if ($edited_file == $value) $selected = $value;
123  }
124  if ($selected == 0 and !empty($edited_file))
125  {
126    $options[$edited_file] =  str_replace(array('./template-extension/', '/'), array('', ' / '), $edited_file);
127    $selected = $edited_file;
128  }
129  $template->assign('css_lang_tpl', array(
130    'OPTIONS' => $options,
131    'SELECTED' => $selected,
132    'NEW_FILE_URL' => $my_base_url.'-tpl&amp;newfile',
133    'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right'
134    )
135  );
136}
137
138$codemirror_mode = 'text/html';
139
140?>
Note: See TracBrowser for help on using the repository browser.