PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/mailz/lists/admin/template.php

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