PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/adduserplugin.php

https://github.com/tedkulp/cmsmadesimple-2-0
PHP | 182 lines | 138 code | 21 blank | 23 comment | 27 complexity | 0dd6528c16a1621b4e8b71da32aa3d4c MD5 | raw file
  1. <?php
  2. #CMS - CMS Made Simple
  3. #(c)2004 by Ted Kulp (wishy@users.sf.net)
  4. #This project's homepage is: http://cmsmadesimple.sf.net
  5. #
  6. #This program is free software; you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation; either version 2 of the License, or
  9. #(at your option) any later version.
  10. #
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. #GNU General Public License for more details.
  15. #You should have received a copy of the GNU General Public License
  16. #along with this program; if not, write to the Free Software
  17. #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. #
  19. #$Id$
  20. $CMS_ADMIN_PAGE=1;
  21. require_once(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'cmsms.api.php');
  22. $urlext='?'.CMS_SECURE_PARAM_NAME.'='.$_SESSION[CMS_USER_KEY];
  23. check_login();
  24. $error = array();
  25. $plugin_name= "";
  26. if (isset($_POST["plugin_name"])) $plugin_name = $_POST["plugin_name"];
  27. $code= "";
  28. if (isset($_POST["code"])) $code = $_POST["code"];
  29. if (isset($_POST["cancel"])) {
  30. redirect("listusertags.php".$urlext);
  31. return;
  32. }
  33. $userid = get_userid();
  34. $access = check_permission($userid, 'Modify User-defined Tags');
  35. $use_javasyntax = false;
  36. if (get_preference($userid, 'use_javasyntax') == "1") $use_javasyntax = true;
  37. $smarty = new CmsSmarty($gCms->config);
  38. load_plugins($smarty);
  39. global $gCms;
  40. $db =& $gCms->GetDb();
  41. if ($access) {
  42. if (isset($_POST["addplugin"])) {
  43. $validinfo = true;
  44. if ($plugin_name == "") {
  45. $error[] = lang('nofieldgiven',array(lang('name')));
  46. $validinfo = false;
  47. }
  48. elseif(preg_match('<^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$>', $plugin_name) == 0)
  49. {
  50. $error[] = lang('error_udt_name_chars');
  51. $validinfo = false;
  52. }
  53. else
  54. {
  55. if (in_array($plugin_name, $gCms->cmsplugins))
  56. {
  57. $error[] = lang('usertagexists');
  58. $validinfo = false;
  59. }
  60. }
  61. // Make sure no spaces are put into plugin name.
  62. $without_spaces = str_replace(' ', '', $plugin_name);
  63. if ($plugin_name != $without_spaces)
  64. {
  65. $error[] = lang('error_udt_name_whitespace');
  66. $validinfo = false;
  67. }
  68. if ($code == "") {
  69. $error[] = lang('nofieldgiven',array(lang('code')));
  70. $validinfo = false;
  71. }
  72. else if (strrpos($code, '{') !== FALSE)
  73. {
  74. $lastopenbrace = strrpos($code, '{');
  75. $lastclosebrace = strrpos($code, '}');
  76. if ($lastopenbrace > $lastclosebrace)
  77. {
  78. $error[] = lang('invalidcode');
  79. $validinfo = false;
  80. }
  81. }
  82. if ($validinfo)
  83. {
  84. srand();
  85. ob_start();
  86. if (eval('function testfunction'.rand().'() {'.$code.'}') === FALSE)
  87. {
  88. $error[] = lang('invalidcode');
  89. //catch the error
  90. //eval('function testfunction'.rand().'() {'.$code.'}');
  91. $buffer = ob_get_clean();
  92. //add error
  93. $error[] = preg_replace('/<br \/>/', '', $buffer );
  94. $validinfo = false;
  95. }
  96. else
  97. {
  98. ob_end_clean();
  99. }
  100. }
  101. if ($validinfo) {
  102. $new_usertag_id = $db->GenID(cms_db_prefix()."userplugins_seq");
  103. Events::SendEvent('Core', 'AddUserDefinedTagPre', array('id' => $new_usertag_id, 'name' => &$plugin_name, 'code' => &$code));
  104. $query = "INSERT INTO ".cms_db_prefix()."userplugins (userplugin_id, userplugin_name, code, create_date, modified_date) VALUES ($new_usertag_id, ".$db->qstr($plugin_name).", ".$db->qstr($code).", ".$db->DBTimeStamp(time()).", ".$db->DBTimeStamp(time()).")";
  105. $result = $db->Execute($query);
  106. if ($result) {
  107. Events::SendEvent('Core', 'AddUserDefinedTagPost', array('id' => $new_usertag_id, 'name' => &$plugin_name, 'code' => &$code));
  108. audit($new_usertag_id, $plugin_name, 'Added User Defined Tag');
  109. redirect("listusertags.php".$urlext."&message=usertagadded");
  110. return;
  111. }
  112. else {
  113. $error .= lang('errorinsertingtag');
  114. }
  115. }
  116. }
  117. }
  118. include_once("header.php");
  119. if (!$access) {
  120. echo '<div class=\"pageerrorcontainer\"><p class="pageerror">'.lang('noaccessto', array(lang('addusertag'))).'</p></div>';
  121. }
  122. else {
  123. if (FALSE == empty($error)) {
  124. echo $themeObject->ShowErrors($error);
  125. }
  126. ?>
  127. <div class="pagecontainer">
  128. <?php echo $themeObject->ShowHeader('addusertag'); ?>
  129. <form enctype="multipart/form-data" action="adduserplugin.php" method="post">
  130. <div>
  131. <input type="hidden" name="<?php echo CMS_SECURE_PARAM_NAME ?>" value="<?php echo $_SESSION[CMS_USER_KEY] ?>" />
  132. </div>
  133. <div class="pageoverflow">
  134. <p class="pagetext">*<?php echo lang('name')?>:</p>
  135. <p class="pageinput">
  136. <input type="text" name="plugin_name" maxlength="255" value="<?php echo $plugin_name?>" />
  137. </p>
  138. </div>
  139. <div class="pageoverflow">
  140. <p class="pagetext">*<?php echo lang('code')?></p>
  141. <p class="pageinput">
  142. <?php echo create_textarea(false, $code, 'code', 'pagebigtextarea', 'code', '', '', '80', '15','','php')?>
  143. <!-- <textarea class="pagetextarea" name="code" rows="" cols=""><_?php echo $code ?></textarea>-->
  144. </p>
  145. </div>
  146. <div class="pageoverflow">
  147. <p class="pagetext">&nbsp;</p>
  148. <p class="pageinput">
  149. <input type="hidden" name="addplugin" value="true" />
  150. <input type="submit" accesskey="s" value="<?php echo lang('submit')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
  151. <input type="submit" accesskey="c" name="cancel" value="<?php echo lang('cancel')?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
  152. </p>
  153. </div>
  154. </form>
  155. </div>
  156. <?php
  157. }
  158. echo '<p class="pageback"><a class="pageback" href="'.$themeObject->BackUrl().'">&#171; '.lang('back').'</a></p>';
  159. include_once("footer.php");
  160. # vim:ts=4 sw=4 noet
  161. ?>