PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/phplist/admin/template.php

https://github.com/radicaldesigns/amp
PHP | 267 lines | 229 code | 26 blank | 12 comment | 42 complexity | 200c0aedade8e74422ebec03ee2cc0c5 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, AGPL-1.0
  1. <script language="Javascript" src="js/jslib.js" type="text/javascript"></script>
  2. <?php
  3. require_once dirname(__FILE__).'/accesscheck.php';
  4. if (is_uploaded_file($_FILES['file_template']['tmp_name'])) {
  5. $content = file_get_contents($_FILES['file_template']['tmp_name']);
  6. } else {
  7. $content = $_POST['content'];
  8. }
  9. if (file_exists("./FCKeditor/fckeditor.php") && USEFCK) {
  10. include("./FCKeditor/fckeditor.php") ;
  11. // Create the editor object here so we can check to see if *it* wants us to use it (this
  12. // does a browser check, etc.
  13. $oFCKeditor = new FCKeditor ;
  14. $usefck = $oFCKeditor->IsCompatible();
  15. unset($oFCKeditor); // This object is *very* short-lived. Thankfully, it's also light-weight
  16. } else {
  17. $usefck = 0;
  18. }
  19. // Verify that TinyMCE is available
  20. $useTinyMCE = 0;
  21. if (USETINYMCETEMPL && file_exists(TINYMCEPATH)) {
  22. $useTinyMCE = 1;
  23. }
  24. if (isset($_REQUEST['id'])) {
  25. $id = sprintf('%d',$_REQUEST['id']);
  26. } else {
  27. $id = 0;
  28. }
  29. function getTemplateImages($content) {
  30. $html_images = array();
  31. $image_types = array(
  32. 'gif' => 'image/gif',
  33. 'jpg' => 'image/jpeg',
  34. 'jpeg' => 'image/jpeg',
  35. 'jpe' => 'image/jpeg',
  36. 'bmp' => 'image/bmp',
  37. 'png' => 'image/png',
  38. 'tif' => 'image/tiff',
  39. 'tiff' => 'image/tiff',
  40. 'swf' => 'application/x-shockwave-flash'
  41. );
  42. // Build the list of image extensions
  43. while(list($key,) = each($image_types))
  44. $extensions[] = $key;
  45. preg_match_all('/"([^"]+\.('.implode('|', $extensions).'))"/Ui', stripslashes($content), $images);
  46. while (list($key,$val) = each ($images[1]))
  47. $html_images[$val]++;
  48. return $html_images;
  49. }
  50. function getTemplateLinks($content) {
  51. preg_match_all('/href="([^"]+)"/Ui', stripslashes($content), $links);
  52. return $links[1];
  53. }
  54. if ($action == "addimages") {
  55. if (!$id)
  56. $msg = $GLOBALS['I18N']->get("No such template");
  57. else {
  58. $content_req = Sql_Fetch_Row_Query("select template from {$tables["template"]} where id = $id");
  59. $images = getTemplateImages($content_req[0]);
  60. if (sizeof($images)) {
  61. include "class.image.inc";
  62. $image = new imageUpload();
  63. while (list($key,$val) = each ($images)) {
  64. # printf('Image name: <b>%s</b> (%d times used)<br />',$key,$val);
  65. $image->uploadImage($key,$id);
  66. }
  67. $msg = $GLOBALS['I18N']->get("Images stored");
  68. } else
  69. $msg = $GLOBALS['I18N']->get("No images found");
  70. }
  71. print '<p class="error">'.$msg.'</p>';
  72. return;
  73. } elseif ($save) {
  74. $templateok = 1;
  75. if ($title && ereg("\[CONTENT\]",$content)) {
  76. $images = getTemplateImages($content);
  77. if (($checkfullimages || $checkimagesexist) && sizeof($images)) {
  78. foreach ($images as $key => $val) {
  79. if (!preg_match("#^https?://#i",$key)) {
  80. if ($checkfullimages) {
  81. print $GLOBALS['I18N']->get("Image")." $key => ".$GLOBALS['I18N']->get("not full URL")."<br/>\n";
  82. $templateok = 0;
  83. }
  84. } else {
  85. if ($checkimagesexist) {
  86. $fp = @fopen($key,"r");
  87. if (!$fp) {
  88. print $GLOBALS['I18N']->get("Image")." $key => ".$GLOBALS['I18N']->get("does not exist")."<br/>\n";
  89. $templateok = 0;
  90. }
  91. @fclose($fp);
  92. }
  93. }
  94. }
  95. }
  96. if ($checkfulllinks) {
  97. $links = getTemplateLinks($content);
  98. foreach ($links as $key => $val) {
  99. if (!preg_match("#^https?://#i",$val) && !preg_match("#^mailto:#i",$val)) {
  100. print $GLOBALS['I18N']->get("Not a full URL:")." $val<br/>\n";
  101. $templateok = 0;
  102. }
  103. }
  104. }
  105. } else {
  106. if (!$title) print $GLOBALS['I18N']->get("No Title")."<br/>";
  107. else print $GLOBALS['I18N']->get("Template does not contain the [CONTENT] placeholder")."<br/>";
  108. $templateok = 0;
  109. }
  110. if ($templateok) {
  111. if (!$id) {
  112. Sql_Query("insert into {$tables["template"]} (title) values(\"Untitled Template\")");
  113. $id = Sql_Insert_id();
  114. }
  115. Sql_Query(sprintf('update %s set title = "%s",template = "%s" where id = %d',
  116. $tables["template"],$title,addslashes($content),$id));
  117. Sql_Query(sprintf('select * from %s where filename = "%s" and template = %d',
  118. $tables["templateimage"],"powerphplist.png",$id));
  119. if (!Sql_Affected_Rows())
  120. Sql_Query(sprintf('insert into %s (template,mimetype,filename,data,width,height)
  121. values(%d,"%s","%s","%s",%d,%d)',
  122. $tables["templateimage"],$id,"image/png","powerphplist.png",
  123. $newpoweredimage,
  124. 70,30));
  125. print '<p class="error">'.$GLOBALS['I18N']->get("Template saved").'</p>';
  126. if (sizeof($images)) {
  127. include $GLOBALS["coderoot"] . "class.image.inc";
  128. $image = new imageUpload();
  129. print "<h3>".$GLOBALS['I18N']->get("Images")."</h3><p>".$GLOBALS['I18N']->get("Below is the list of images used in your template. If an image is currently unavailable, please upload it to the database.")."</p>";
  130. print "<p>".$GLOBALS['I18N']->get("This includes all images, also fully referenced ones, so you may choose not to upload some. If you upload images, they will be included in the emails that use this template.")."</p>";
  131. print formStart('enctype="multipart/form-data"');
  132. print '<input type=hidden name="id" value="'.$id.'">';
  133. ksort($images);
  134. reset($images);
  135. while (list($key,$val) = each ($images)) {
  136. printf($GLOBALS['I18N']->get("Image name:").' <b>%s</b> (%d '.$GLOBALS['I18N']->get("times used").')<br/>',$key,$val);
  137. print $image->showInput($key,$value,$id);
  138. }
  139. //nizar 'value' ci-dessous plusieurs fois
  140. print '<input type=hidden name="id" value="'.$id.'"><input type=hidden name="action" value="addimages"><input type=submit name="addimages" value="'.$GLOBALS['I18N']->get("Save Images").'"></form>';
  141. return;
  142. } else {
  143. print "<p>".$GLOBALS['I18N']->get("Template does not contain local images")."</p>";
  144. return;
  145. }
  146. } else {
  147. print '<p class="error">'.$GLOBALS['I18N']->get("Some errors were found, template NOT saved!").'</p>';
  148. $data["title"] = $title;
  149. $data["template"] = $content;
  150. }
  151. } else {
  152. if ($id) {
  153. $req = Sql_Query("select * from {$tables["template"]} where id = $id");
  154. $data = Sql_Fetch_Array($req);
  155. }
  156. }
  157. ?>
  158. <p class="error"><?php echo $msg?></p>
  159. <?php echo PageLink2("templates",$GLOBALS['I18N']->get("List of Templates"));?>
  160. <p>
  161. <?php echo formStart(' enctype="multipart/form-data"')?>
  162. <input type=hidden name="id" value="<?php echo $id?>">
  163. <table>
  164. <tr>
  165. <td><?php echo $GLOBALS['I18N']->get('Title of this template')?></td>
  166. <td><input type=text name="title" value="<?php echo stripslashes(htmlspecialchars($data["title"]))?>" size=30></td>
  167. </tr>
  168. <tr>
  169. <td colspan=2><?php echo $GLOBALS['I18N']->get('Content of the template.')?><br /><?php echo $GLOBALS['I18N']->get('The content should at least have <b>[CONTENT]</b> somewhere.')?><br/><?php echo $GLOBALS['I18N']->get('You can upload a template file or paste the text in the box below'); ?></td>
  170. </tr>
  171. <tr>
  172. <td><?php echo $GLOBALS['I18N']->get('Template file.')?></td>
  173. <td><input type=file name="file_template" /></td>
  174. </tr>
  175. <tr>
  176. <td colspan=2>
  177. <?php
  178. if ($usefck) {
  179. $oFCKeditor = new FCKeditor('content') ;
  180. $w = 600;
  181. $h = 800;
  182. # version 1.4
  183. //$oFCKeditor->ToolbarSet = 'Accessibility' ;
  184. # $oFCKeditor->ToolbarSet = 'Default' ;
  185. # $oFCKeditor->Value = stripslashes($data["template"]);
  186. # $oFCKeditor->CreateFCKeditor( 'content', $w.'px', $h.'px' ) ;
  187. # version 2.0
  188. $oFCKeditor->BasePath = './FCKeditor/';
  189. $oFCKeditor->ToolbarSet = 'Default' ;
  190. $oFCKeditor->Height = $h;
  191. $oFCKeditor->Width = $w;
  192. $oFCKeditor->Value = stripslashes($data["template"]);
  193. $oFCKeditor->Create() ;
  194. print '</td></tr>';
  195. } elseif ($useTinyMCE) {
  196. $tinyMCE_path = TINYMCEPATH;
  197. $tinyMCE_lang = TINYMCELANG;
  198. $tinyMCE_theme = TINYMCETHEME;
  199. $tinyMCE_opts = TINYMCEOPTS;
  200. ?>
  201. <script language="javascript" type="text/javascript" src="<?php echo $tinyMCE_path;?>"></script>
  202. <script language="javascript" type="text/javascript">
  203. tinyMCE.init({
  204. mode : "exact",
  205. elements : "content",
  206. language : "<?php echo $tinyMCE_lang;?>",
  207. theme : "<?php echo $tinyMCE_theme;?>"
  208. <?php echo $tinyMCE_opts;?>
  209. });
  210. </script>
  211. <textarea name="content" id="content" cols="65" rows="20"><?php echo stripslashes(htmlspecialchars($data["template"]))?></textarea>
  212. <?php
  213. } else {
  214. ?>
  215. <textarea name="content" cols="70" rows="40" wrap="virtual"><?php echo stripslashes(htmlspecialchars($data["template"]))?></textarea>
  216. <?php
  217. }
  218. ?>
  219. </td>
  220. </tr>
  221. <!--tr>
  222. <td>Make sure all images<br/>start with this URL (optional)</td>
  223. <td><input type=text name="baseurl" size=40 value="<?php echo htmlspecialchars($baseurl)?>"></td>
  224. </tr-->
  225. <tr>
  226. <td><?php echo $GLOBALS['I18N']->get('Check that all links have a full URL')?></td>
  227. <td><input type=checkbox name="checkfulllinks" <?php echo $checkfulllinks?"checked":""?>></td>
  228. </tr>
  229. <tr>
  230. <td><?php echo $GLOBALS['I18N']->get('Check that all images have a full URL')?></td>
  231. <td><input type=checkbox name="checkfullimages" <?php echo $checkfullimages?"checked":""?>></td>
  232. </tr>
  233. <tr>
  234. <td><?php echo $GLOBALS['I18N']->get('Check that all external images exist')?></td>
  235. <td><input type=checkbox name="checkimagesexist" <?php echo $checkimagesexist?"checked":""?>></td>
  236. </tr>
  237. <tr>
  238. <td colspan=2><input type=submit name="save" value="<?php echo $GLOBALS['I18N']->get('Save Changes')?>"></td>
  239. </tr>
  240. </table>
  241. </form>