Dotclear

source: plugins/myForms/trunk/index.php @ 798

Revision 798, 3.2 KB checked in by Oaz, 15 years ago (diff)
  • added path to all 'default-templates' folder for form search
  • check presence of theme editor to modify existing forms
Line 
1<?php
2# ***** BEGIN LICENSE BLOCK *****
3# Copyright (c) 2009 Olivier Azeau and contributors. All rights reserved.
4#
5# This is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with DotClear; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18#
19# ***** END LICENSE BLOCK *****
20if (!defined('DC_CONTEXT_ADMIN')) { return; }
21
22dcPage::check('usage,contentadmin');
23
24# Use theme editor
25$core->themes = new dcThemes($core);
26$core->themes->loadModules($core->blog->themes_path,null);
27$themeEditorClass = path::real(dirname(__FILE__).'/../themeEditor/class.themeEditor.php');
28if($themeEditorClass) {
29  require_once($themeEditorClass);
30  class myFormsTplFileFinder extends dcThemeEditor
31  {
32     public function __construct(&$core)
33     {
34      return parent::__construct($core);
35     }
36     protected function getFilesInDir($dir,$ext=null,$prefix='')
37     {
38      return parent::getFilesInDir($dir,'myforms.html',$prefix);
39    }
40  }
41}
42
43try
44{
45?>
46<html>
47<head>
48  <title>myForms</title>
49</head>
50<body>
51<?php
52  if( isset($_POST['myFormId']) ) {
53    $newFormId = $_POST['myFormId'];
54    $newFormFile = path::real($core->blog->themes_path.'/'.$core->blog->settings->theme).'/tpl/'.$newFormId.'.myforms.html';
55    if( file_exists($newFormFile) ) {
56      print '<p class="message">'.__('Form already exists.').'</p>';
57    } else {
58      ob_start();
59?>
60<tpl:myformsInfo name="title">{{tpl:BlogName encode_html="1"}} - <?php print $newFormId; ?></tpl:myformsInfo>
61
62<tpl:myformsOnInit>
63  <p>This is a new form named '<?php print $newFormId; ?>'.</p>
64  <p><tpl:myformsSubmit name="clickme">Click me</tpl:myformsSubmit></p>
65</tpl:myformsOnInit>
66
67<tpl:myformsOnSubmit name="clickme">
68  <p>You got it !</p>
69</tpl:myformsOnSubmit>
70
71<?php
72      if( file_put_contents( $newFormFile, ob_get_clean() ) )
73        print '<p class="message">'.__('Form was successfully created.').'</p>';
74      else
75        print '<p class="message">'.__('An error occured while creating the form.').'</p>';
76    }
77  }
78
79  if($themeEditorClass) {
80    print '<h2>'.__('Click on a form to modify it.').'</h2>';
81    $fileFinder = new myFormsTplFileFinder($core);
82    echo $fileFinder->filesList('tpl','<a href="plugin.php?p=themeEditor&amp;tpl=%2$s" class="tpl-link">%1$s</a>');
83  } else {
84    print '<p class="message">'.__('You need the \'themeEditor\' extension to modify the existing forms.').'</p>';
85  }
86  print '<h2>'.__('Create a new form').'</h2>';
87  print '<form action="'.$p_url.'" method="post">';
88  print '<p>'.__('Form ID').' : <input type="text" name="myFormId" value="" /></p>';
89  print '<p><input type="submit" value="'.__('Create').'" />'.$core->formNonce().'</p>';
90  print '</form>';
91?>
92</body>
93</html>
94<?php
95}
96catch (Exception $e)
97{
98  $core->error->add($e->getMessage());
99}
100?>
Note: See TracBrowser for help on using the repository browser.

Sites map