/postsbyimage-options.php

https://github.com/freerobby/postsbyimage · PHP · 177 lines · 153 code · 9 blank · 15 comment · 8 complexity · c56d68b1a82789da3ada6a45900093c0 MD5 · raw file

  1. <?php
  2. // If the form was just submitted, ...
  3. if ( isset ( $_POST [ 'submitted' ] ) ) {
  4. // Update the local path of the cache folder.
  5. update_option ( 'ds_pbi_cachepath', htmlspecialchars ( $_POST [ 'cachepath' ], ENT_QUOTES ) );
  6. // Update the URL of the cache folder.
  7. update_option ( 'ds_pbi_cacheurl', htmlspecialchars ( $_POST [ 'cacheurl' ], ENT_QUOTES ) );
  8. // Update the number of default columns to use for a display table.
  9. update_option ( 'ds_pbi_defaultcols', htmlspecialchars ( $_POST [ 'defaultcols' ], ENT_QUOTES ) );
  10. // Update the maximum width of a thumbnail
  11. update_option ( 'ds_pbi_thumbnailmaxwidth', htmlspecialchars ( $_POST [ 'thumbnailmaxwidth' ], ENT_QUOTES ) );
  12. // Update the maximum height of a thumbnail
  13. update_option ( 'ds_pbi_thumbnailmaxheight', htmlspecialchars ( $_POST [ 'thumbnailmaxheight' ], ENT_QUOTES ) );
  14. ?>
  15. <div id="message" class="updated fade">
  16. <p>
  17. <strong>
  18. Options saved!
  19. </strong>
  20. </p>
  21. </div>
  22. <?php
  23. }
  24. // If the user requested that we run autoconfigure, ...
  25. if ( isset ( $_POST [ 'autoconfigure' ] ) ) {
  26. ?>
  27. <div id="message" class="updated fade">
  28. <p>
  29. <strong>
  30. Running Autoconfigure... <br />
  31. <?php
  32. // Use default location
  33. echo 'Creating cache folder... ';
  34. $default_cachepath = ABSPATH . get_option ( 'upload_path' ) . '/postsbyimage_cache';
  35. // Try to make the directory, and add perms 777.
  36. // (Not the most secure way but oh well).
  37. mkdir ( $default_cachepath, 0777 );
  38. $success = is_dir ( $default_cachepath );
  39. // If the folder was not created, ...
  40. $success = true;
  41. if ( ! $success ) {
  42. echo 'FAIL <br />';
  43. }
  44. else {
  45. echo '<br />';
  46. // Create Options
  47. echo 'Configuring plugin... <br />';
  48. update_option ( 'ds_pbi_cachepath', htmlspecialchars ( $default_cachepath ), ENT_QUOTES );
  49. update_option ( 'ds_pbi_cacheurl', htmlspecialchars ( get_option ( 'siteurl' ) . '/' . get_option ( 'upload_path' ) . '/postsbyimage_cache' ), ENT_QUOTES );
  50. // Generate cache
  51. ds_pbi_regenerateimagecache ();
  52. echo 'Autoconfigure complete!';
  53. }
  54. ?>
  55. </strong>
  56. </p>
  57. </div>
  58. <?php
  59. }
  60. // If the cache was just regenerated
  61. // Eventually, this should be made the official trigger.
  62. if ( isset ( $_POST [ 'regenerateimagecache' ] ) ) {
  63. ?>
  64. <div id="message" class="updated fade">
  65. <p>
  66. <strong>
  67. Cache regeneration request received! <br />
  68. <?php ds_pbi_regenerateimagecache (); ?>
  69. </strong>
  70. </p>
  71. </div>
  72. <?php
  73. }
  74. ?>
  75. <!-- Beginning of Options Page -->
  76. <div class="wrap">
  77. <h2>
  78. Automatic Configuration
  79. </h2>
  80. <form action="<?php echo $_SERVER ['REQUEST_URI']; ?>" method="post">
  81. <!-- End of Beginning of Options Page -->
  82. <h3>
  83. Auto-Configure
  84. </h3>
  85. <p>
  86. Autoconfigure is the method of setup recommended for most users. It works on most shared hosting providers. Autoconfigure will do the following, in order:
  87. <ol>
  88. <li>
  89. Create a cache directory in your uploads folder.
  90. </li>
  91. <li>
  92. Configure PostsByImage to use the newly-created cache directory.
  93. </li>
  94. <li>
  95. Generate the image cache for your existing posts and pages.
  96. </li>
  97. </ol>
  98. <input type="submit" name="autoconfigure" value="Run Autoconfigure" />
  99. </p>
  100. <h2>
  101. Image Cache
  102. </h2>
  103. <h3>
  104. Image Cache Generation
  105. </h3>
  106. <p>
  107. Clicking the button below will regenerate your image cache. You should only have to do this once (immediately after installing the PostsByImage plugin). Please note that this process can take a lot of time--if your server is slow or if you have a lot of posts it may take several minutes!
  108. <br />
  109. <input type="submit" name="regenerateimagecache" value="Regenerate Image Cache" />
  110. </p>
  111. <h3>
  112. Image Cache Storage
  113. </h3>
  114. <p>
  115. Generated images will be stored on your server in the directory below.
  116. <br />
  117. <input type="text" name="cachepath" value="<?php echo stripslashes ( get_option ( 'ds_pbi_cachepath' ) ); ?>" size="<?php echo strlen ( stripslashes ( get_option ( 'ds_pbi_cachepath' ) ) ); ?>" />
  118. <br />
  119. </p>
  120. <h3>
  121. Image Cache Accessibility
  122. </h3>
  123. <p>
  124. Images stored in your cache are accessible in the URL specified below.
  125. <br />
  126. <input type="text" name="cacheurl" value="<?php echo stripslashes ( get_option ( 'ds_pbi_cacheurl' ) ); ?>" size="<?php echo strlen ( stripslashes ( get_option ( 'ds_pbi_cacheurl' ) ) ); ?>" />
  127. </p>
  128. <h2>
  129. Display Settings
  130. </h2>
  131. <h3>
  132. Columns per Table
  133. </h3>
  134. <p>
  135. Number of columns in your display table:
  136. <input type="text" name="defaultcols" value="<?php echo stripslashes ( get_option ( 'ds_pbi_defaultcols' ) ); ?>" size="3" />
  137. </p>
  138. <h3>
  139. Thumbnail Dimensions
  140. </h3>
  141. <p>
  142. <em>
  143. Note: Changing these values will only affect newly-generated thumbnails.
  144. <br />
  145. To change the size of existing thumbnails, regenerate your image cache after modifying these settings.
  146. </em>
  147. <table border="0">
  148. <tr>
  149. <td>
  150. Max width of a generated wide thumbnail:
  151. </td>
  152. <td>
  153. <input type="text" name="thumbnailmaxwidth" value="<?php echo stripslashes ( get_option ( 'ds_pbi_thumbnailmaxwidth' ) ); ?>" size="3" />
  154. </td>
  155. </tr>
  156. <tr>
  157. <td>
  158. Max height of a generated tall thumbnail:
  159. </td>
  160. <td>
  161. <input type="text" name="thumbnailmaxheight" value="<?php echo stripslashes ( get_option ( 'ds_pbi_thumbnailmaxheight' ) ); ?>" size="3" />
  162. </td>
  163. </tr>
  164. </table>
  165. </p>
  166. <input type="submit" name="submitted" value="Update Options &raquo;" />
  167. </form>
  168. </div>