aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/LocalFilesEditor/include/tpl.inc.php
blob: 1063b2238e298d841ba0fca3fd9365d6f3ee8a55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php

if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');

$edited_file = isset($_POST['edited_file']) ? $_POST['edited_file'] : '';
$content_file = '';

if ((isset($_POST['edit'])) and !is_numeric($_POST['file_to_edit']))
{
  $edited_file = $_POST['file_to_edit'];
  if (file_exists($edited_file))
  {
    $content_file = file_get_contents($edited_file);
  }
  else
  {
    $content_file = '';
  }
}

$newfile_page = isset($_GET['newfile']);

// Edit new tpl file
if (isset($_POST['create_tpl']))
{
  $filename = $_POST['tpl_name'];
  if (empty($filename))
  {
    array_push($page['errors'], l10n('locfiledit_empty_filename'));
  }
  if (get_extension($filename) != 'tpl')
  {
    $filename .= '.tpl';
  }
  if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
  {
    array_push($page['errors'], l10n('locfiledit_filename_error'));
  }
  if (is_numeric($_POST['tpl_model']) and $_POST['tpl_model'] != '0')
  {
    array_push($page['errors'], l10n('locfiledit_model_error'));
  }
  if (file_exists($_POST['tpl_parent'] . '/' . $filename))
  {
    array_push($page['errors'], l10n('locfiledit_file_already_exists'));
  }
  if (!empty($page['errors']))
  {
    $newfile_page = true;
  }
  else
  {
    $edited_file = $_POST['tpl_parent'] . '/' . $filename;
    $content_file = ($_POST['tpl_model'] == '0') ? '' : file_get_contents($_POST['tpl_model']);
  }
}

if ($newfile_page)
{
  $filename = isset($_POST['tpl_name']) ? $_POST['tpl_name'] : '';
  $selected['model'] = isset($_POST['tpl_model']) ? $_POST['tpl_model'] : '0';
  $selected['parent'] = isset($_POST['tpl_parent']) ? $_POST['tpl_parent'] : PHPWG_ROOT_PATH . 'template-extension';

  // Parent directories list
  $options['parent'] = array(PHPWG_ROOT_PATH . 'template-extension' => 'template-extension');
  $options['parent'] = array_merge($options['parent'], get_rec_dirs(PHPWG_ROOT_PATH . 'template-extension'));

  $options['model'][] = l10n('locfiledit_empty_page');
  $options['model'][] = '----------------------';
  $i = 0;
  foreach (get_extents() as $pwg_template)
  {
    $value = PHPWG_ROOT_PATH . 'template-extension/' . $pwg_template;
    $options['model'][$value] =  'template-extension / ' . str_replace('/', ' / ', $pwg_template);
    $i++;
  }
  foreach (get_dirs($conf['themes_dir']) as $theme_id)
  {
    if ($i)
    {
      $options['model'][] = '----------------------';
      $i = 0;
    }
    $dir = $conf['themes_dir'] . '/' . $theme_id . '/template/';
    if (is_dir($dir) and $content = opendir($dir))
    {
      while ($node = readdir($content))
      {
        if (is_file($dir.$node) and get_extension($node) == 'tpl')
        {
          $value = $dir . $node;
          $options['model'][$value] = $theme_id . ' / ' . $node;
          $i++;
        }
      }
    }
  }
  if (end($options['model']) == '----------------------')
  {
    array_pop($options['model']);
  }
  // Assign variables to template
  $template->assign('create_tpl', array(
    'NEW_FILE_NAME' => $filename,
    'MODEL_OPTIONS' => $options['model'],
    'MODEL_SELECTED' => $selected['model'],
    'PARENT_OPTIONS' => $options['parent'],
    'PARENT_SELECTED' => $selected['parent']
    )
  );
}
else
{
  // List existing template extensions
  $selected = 0; 
  $options[] = l10n('locfiledit_choose_file');
  $options[] = '----------------------';
  foreach (get_extents() as $pwg_template)
  {
    $value = './template-extension/' . $pwg_template;
    $options[$value] =  str_replace('/', ' / ', $pwg_template);
    if ($edited_file == $value) $selected = $value;
  }
  if ($selected == 0 and !empty($edited_file))
  {
    $options[$edited_file] =  str_replace(array('./template-extension/', '/'), array('', ' / '), $edited_file);
    $selected = $edited_file;
  }
  $template->assign('css_lang_tpl', array(
    'OPTIONS' => $options,
    'SELECTED' => $selected,
    'NEW_FILE_URL' => $my_base_url.'-tpl&amp;newfile',
    'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right'
    )
  );
}

$codemirror_mode = 'text/html';

?>