PageRenderTime 37ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/lists/admin/template.php

https://github.com/radicaldesigns/amp
PHP | 175 lines | 166 code | 7 blank | 2 comment | 31 complexity | f3bbc28906b1b16a04c9407c95603794 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. <?
  3. require_once "accesscheck.php";
  4. function getTemplateImages($content) {
  5. $html_images = array();
  6. $image_types = array(
  7. 'gif' => 'image/gif',
  8. 'jpg' => 'image/jpeg',
  9. 'jpeg' => 'image/jpeg',
  10. 'jpe' => 'image/jpeg',
  11. 'bmp' => 'image/bmp',
  12. 'png' => 'image/png',
  13. 'tif' => 'image/tiff',
  14. 'tiff' => 'image/tiff',
  15. 'swf' => 'application/x-shockwave-flash'
  16. );
  17. // Build the list of image extensions
  18. while(list($key,) = each($image_types))
  19. $extensions[] = $key;
  20. preg_match_all('/"([^"]+\.('.implode('|', $extensions).'))"/Ui', stripslashes($content), $images);
  21. while (list($key,$val) = each ($images[1]))
  22. $html_images[$val]++;
  23. return $html_images;
  24. }
  25. function getTemplateLinks($content) {
  26. preg_match_all('/href="([^"]+)"/Ui', stripslashes($content), $links);
  27. return $links[1];
  28. }
  29. if ($action == "addimages") {
  30. if (!$id)
  31. $msg = "No such template";
  32. else {
  33. $content_req = Sql_Fetch_Row_Query("select template from {$tables["template"]} where id = $id");
  34. $images = getTemplateImages($content_req[0]);
  35. if (sizeof($images)) {
  36. include "class.image.inc";
  37. $image = new imageUpload();
  38. while (list($key,$val) = each ($images)) {
  39. # printf('Image name: <b>%s</b> (%d times used)<br />',$key,$val);
  40. $image->uploadImage($key,$id);
  41. }
  42. $msg = 'Images stored';
  43. } else
  44. $msg = 'No images found';
  45. }
  46. print '<p class="error">'.$msg.'</p>';
  47. return;
  48. } elseif ($save) {
  49. $templateok = 1;
  50. if ($title && ereg("\[CONTENT\]",$content)) {
  51. $images = getTemplateImages($content);
  52. if (($checkfullimages || $checkimagesexist) && sizeof($images)) {
  53. foreach ($images as $key => $val) {
  54. if (!preg_match("#^https?://#i",$key)) {
  55. if ($checkfullimages) {
  56. print "Image $key => not full URL<br/>\n";
  57. $templateok = 0;
  58. }
  59. } else {
  60. if ($checkimagesexist) {
  61. $fp = @fopen($key,"r");
  62. if (!$fp) {
  63. print "Image $key => does not exist<br/>\n";
  64. $templateok = 0;
  65. }
  66. @fclose($fp);
  67. }
  68. }
  69. }
  70. }
  71. if ($checkfulllinks) {
  72. $links = getTemplateLinks($content);
  73. foreach ($links as $key => $val) {
  74. if (!preg_match("#^https?://#i",$val)) {
  75. print "Not a full URL: $val<br/>\n";
  76. $templateok = 0;
  77. }
  78. }
  79. }
  80. } else {
  81. if (!$title) print "No Title<br/>";
  82. else print "Template does not contain the [CONTENT] placeholder<br/>";
  83. $templateok = 0;
  84. }
  85. if ($templateok) {
  86. if (!$id) {
  87. Sql_Query("insert into {$tables["template"]} (title) values(\"Untitled Template\")");
  88. $id = Sql_Insert_id();
  89. }
  90. Sql_Query(sprintf('update %s set title = "%s",template = "%s" where id = %d',
  91. $tables["template"],$title,addslashes($content),$id));
  92. Sql_Query(sprintf('select * from %s where filename = "%s" and template = %d',
  93. $tables["templateimage"],"powerphplist.png",$id));
  94. if (!Sql_Affected_Rows())
  95. Sql_Query(sprintf('insert into %s (template,mimetype,filename,data,width,height)
  96. values(%d,"%s","%s","%s",%d,%d)',
  97. $tables["templateimage"],$id,"image/png","powerphplist.png",
  98. $newpoweredimage,
  99. 70,30));
  100. print '<p class="error">Template saved</p>';
  101. if (sizeof($images)) {
  102. include $GLOBALS["coderoot"] . "class.image.inc";
  103. $image = new imageUpload();
  104. print "<h3>Images</h3><p>Below is the list of images used in your template. If an image is currently unavailable, please upload it to the database.</p>";
  105. print "<p>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>";
  106. print formStart('enctype="multipart/form-data"');
  107. print '<input type=hidden name="id" value="'.$id.'">';
  108. ksort($images);
  109. reset($images);
  110. while (list($key,$val) = each ($images)) {
  111. printf('Image name: <b>%s</b> (%d times used)<br/>',$key,$val);
  112. print $image->showInput($key,$value,$id);
  113. }
  114. print '<input type=hidden name="id" value="'.$id.'"><input type=hidden name="action" value="addimages"><input type=submit name="addimages" value="Save Images"></form>';
  115. return;
  116. } else {
  117. print "<p>Template does not contain local images</p>";
  118. return;
  119. }
  120. } else {
  121. print '<p class="error">Some errors were found, template NOT saved!</p>';
  122. $data["title"] = $title;
  123. $data["template"] = $content;
  124. }
  125. } else {
  126. if ($id) {
  127. $req = Sql_Query("select * from {$tables["template"]} where id = $id");
  128. $data = Sql_Fetch_Array($req);
  129. }
  130. }
  131. ?>
  132. <p class="error"><?=$msg?></p>
  133. <?=PageLink2("templates","List of Templates");?>
  134. <p>
  135. <?=formStart()?>
  136. <input type=hidden name="id" value="<?=$id?>">
  137. <table>
  138. <tr>
  139. <td>Title of this template</td>
  140. <td><input type=text name="title" value="<?=stripslashes(htmlspecialchars($data["title"]))?>" size=30></td>
  141. </tr>
  142. <tr>
  143. <td colspan=2>Content of the template.<br />The content should at least have <b>[CONTENT]</b> somewhere.</td>
  144. </tr>
  145. <tr>
  146. <td colspan=2><textarea name="content" cols="70" rows="40" wrap="virtual"><?=stripslashes(htmlspecialchars($data["template"]))?></textarea></td>
  147. </tr>
  148. <!--tr>
  149. <td>Make sure all images<br/>start with this URL (optional)</td>
  150. <td><input type=text name="baseurl" size=40 value="<?=htmlspecialchars($baseurl)?>"></td>
  151. </tr-->
  152. <tr>
  153. <td>Check that all links have a full URL</td>
  154. <td><input type=checkbox name="checkfulllinks" <?=$checkfulllinks?"checked":""?>></td>
  155. </tr>
  156. <tr>
  157. <td>Check that all images have a full URL</td>
  158. <td><input type=checkbox name="checkfullimages" <?=$checkfullimages?"checked":""?>></td>
  159. </tr>
  160. <tr>
  161. <td>Check that all external images exist</td>
  162. <td><input type=checkbox name="checkimagesexist" <?=$checkimagesexist?"checked":""?>></td>
  163. </tr>
  164. <tr>
  165. <td colspan=2><input type=submit name="save" value="Save Changes"></td>
  166. </tr>
  167. </table>
  168. </form>