apps.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <?php
  2. //
  3. // change this to whatever the correct connection parameters are
  4. //
  5. mysql_connect("localhost","nobody","");
  6. mysql_select_db("gtk");
  7. //
  8. // Change this to whomever you want the administrator emails to go to.
  9. //
  10. $mailto = 'andrei@gravitonic.com';
  11. //$mailto = 'php-gtk-webmaster@lists.php.net';
  12. //$mailto = 'philip+gtk-webmaster@eilio.com';
  13. //
  14. // this directory must exist and must be writable by the user the webserver runs as
  15. //
  16. define("APP_SCREENSHOT_DIR", "screenshots");
  17. //
  18. // this is the structure that defines the categories. Just be sure that all of the id numbers are unique
  19. // and you can do whatever you want. note that you can only have two levels.. you can't nest forever.
  20. //
  21. $appCats[100]->name = "Code Snippets";
  22. $appCats[200]->name = "Database";
  23. $appCats[300]->name = "Games/Entertainment";
  24. $appCats[400]->name = "Internet";
  25. $appCats[400]->sub[410]->name = "Email";
  26. $appCats[400]->sub[420]->name = "WWW";
  27. $appCats[500]->name = "Multimedia";
  28. $appCats[500]->sub[510]->name = "MP3";
  29. $appCats[600]->name = "Other";
  30. $appCats[700]->name = "Security";
  31. $appCats[800]->name = "Software Development";
  32. $appCats[900]->name = "Utilities";
  33. //
  34. // This function buils a select menu containing the categories. It's used in a
  35. // couple of different forms
  36. //
  37. function makeAppSelectMenuOptions($selected_id = "") {
  38. global $appCats;
  39. foreach( $appCats as $cat_id => $catObj ) {
  40. if( $cat_id == $selected_id ) {
  41. $str .= "<option value='$cat_id' selected>$catObj->name";
  42. }else {
  43. $str .= "<option value='$cat_id'>$catObj->name";
  44. }
  45. if( is_array($catObj->sub) ) {
  46. foreach( $catObj->sub as $subcat_id => $subcatObj ) {
  47. if( $subcat_id == $selected_id ) {
  48. $str .= "<option value='$subcat_id' selected> &nbsp; &nbsp; &nbsp; - $subcatObj->name";
  49. }else {
  50. $str .= "<option value='$subcat_id'> &nbsp; &nbsp; &nbsp; - $subcatObj->name";
  51. }
  52. }
  53. }
  54. }
  55. return($str);
  56. }
  57. //
  58. // This is a local "header" function that well, spits out the header code
  59. //
  60. function appHeader($the_cat = false, $the_subcat = false) {
  61. global $appCats, $MAGIC_COOKIE;
  62. if( $_SERVER['SCRIPT_NAME'] == "/apps/admin-apps.php" ) {
  63. $script = "/apps/admin-apps.php";
  64. }else {
  65. $script = "/apps/";
  66. }
  67. if( !empty($the_cat) ) {
  68. $this_cat = $the_cat;
  69. if( !empty($the_subcat) ) {
  70. $this_cat = $the_subcat;
  71. }
  72. }
  73. ?>
  74. <table cellpadding="0" cellspacing="0" border="0">
  75. <tr valign="top">
  76. <td bgcolor="#f0f0f0">
  77. <table width="170" cellpadding="4" cellspacing="0">
  78. <tr valign="top">
  79. <td class="sidebar">
  80. <table border="0" cellpadding="4" cellspacing="0" width="160">
  81. <tr valign="top">
  82. <td><a href="./"><img src="/gifs/caret-t.gif" border="0" width="11" height="7" alt="Applications"/>Applications</a><br/></td>
  83. </tr>
  84. <tr valign="top">
  85. <td style="white-space: nowrap"><small>
  86. <?php if( isset($MAGIC_COOKIE) ) { ?>
  87. &nbsp; &nbsp; &nbsp; <a href="admin-apps.php?key=modified"><img src="/gifs/box-0.gif" border="0" width="11" height="7" alt="">Modified Applications</a><br/>
  88. &nbsp; &nbsp; &nbsp; <a href="admin-apps.php"><img src="/gifs/box-0.gif" border="0" width="11" height="7" alt="">Pending Applications</a><br/>
  89. <br/>
  90. <?php } ?>
  91. &nbsp; &nbsp; &nbsp; <a href="add.php?cat_id=<?php print($this_cat) ?>"><img src="/gifs/box-0.gif" border="0" width="11" height="7" alt=""/>Add Application</a><br/>
  92. &nbsp; &nbsp; &nbsp; <a href="edit.php"><img src="/gifs/box-0.gif" border="0" width="11" height="7" alt=""/>Edit Your Application</a><br/>
  93. <br/>
  94. &nbsp; &nbsp; &nbsp; <a href="<?php print($script) ?>?key=new"><img src="/gifs/box-0.gif" border="0" width="11" height="7" alt=""/>Newest Applications</a><br/>
  95. &nbsp; &nbsp; &nbsp; <a href="<?php print($script) ?>?key=rating"><img src="/gifs/box-0.gif" border="0" width="11" height="7" alt=""/>Highest Rated Applications</a><br/>
  96. </small></td>
  97. </tr>
  98. <tr bgcolor="#cccccc"><td></td></tr>
  99. <?php
  100. //
  101. // loop through the categories and display the left hand navigation
  102. //
  103. foreach( $appCats as $cat_id => $catObj ) {
  104. print("<tr valign=\"top\">");
  105. if( $_GET['the_cat'] == $cat_id ) {
  106. $img = "/gifs/box-1.gif";
  107. }else {
  108. $img = "/gifs/box-0.gif";
  109. }
  110. print("<td style='white-space: nowrap'><a href=\"$script?the_cat=$cat_id\"><img src=\"$img\" border=\"0\" width=\"11\" height=\"7\" alt=\"$catObj->name\" />$catObj->name</a><br/></td>");
  111. print("</tr>");
  112. if( $_GET['the_cat'] == $cat_id && is_array($catObj->sub) ) {
  113. print("<tr valign=\"top\">");
  114. print("<td style='white-space: nowrap'><small>");
  115. foreach( $catObj->sub as $subcat_id => $subcatObj ) {
  116. if( $_GET['the_subcat'] == $subcat_id ) {
  117. $img = "/gifs/box-1.gif";
  118. }else {
  119. $img = "/gifs/box-0.gif";
  120. }
  121. print("&nbsp; &nbsp; &nbsp; <a href=\"$script?the_cat=$cat_id&the_subcat=$subcat_id\"><img src=\"$img\" border=\"0\" width=\"11\" height=\"7\" alt=\"$subcatObj->name\" />$subcatObj->name</a><br/>");
  122. }
  123. print("</small></td>");
  124. print("</tr>");
  125. }
  126. }
  127. ?>
  128. </table>
  129. </td>
  130. </tr>
  131. </table>
  132. </td>
  133. <td bgcolor="#cccccc" style="background-image: url(/gifs/checkerboard.gif)"><img src="/gifs/spacer.gif" width="1" height="1" border="0" alt="" /><br/></td>
  134. <td>
  135. <table width="600" cellpadding="10" cellspacing="0">
  136. <tr>
  137. <td valign="top">
  138. <?php
  139. }
  140. //
  141. // This is the corresponding "footer" function
  142. //
  143. function appFooter() {
  144. ?>
  145. <br/>
  146. </td>
  147. </tr>
  148. </table>
  149. </td>
  150. </tr>
  151. </table>
  152. <?php
  153. }
  154. //
  155. // This function displays exactly one application and depending on $user_edit_mode and $MAGIC_COOKIE
  156. // will display slightly different things such as administration options, etc.
  157. //
  158. function displayApp($app, $the_cat, $the_subcat, $offset, $user_edit_mode = false) {
  159. global $appCats, $MAGIC_COOKIE;
  160. if( $app->rating <= 0 ) {
  161. $rating = "n/a";
  162. }else {
  163. $rating = sprintf("%.1f", $app->rating);
  164. }
  165. if( $app->has_screenshot == 'Y' ) {
  166. $screenshot = "<a href='screenshot.php/$app->id.jpg' target='apppop'><img src='screenshot.php/$app->id-thumb.jpg' alt='' align='right' border='0'/></a>";
  167. }else {
  168. $screenshot = "";
  169. }
  170. print("
  171. <tr valign=top bgcolor='#e0e0e0'>
  172. <td><b>$app->name</b></td>
  173. <td align='right' style='white-space: nowrap'>
  174. ");
  175. if( isset($MAGIC_COOKIE) ) {
  176. if( $app->status == 'P' || $app->status == "M" ) {
  177. print("<a href='admin-apps.php?action=approve&app_id=$app->id' title='Approve'><img src='/gifs/notes-add.gif' width=13 height=13 border=0 alt='Approve'/></a> ");
  178. }
  179. print("<a href='admin-apps.php?action=edit&app_id=$app->id' title='Edit'><img src='/gifs/notes-edit.gif' width=13 height=13 border=0 alt='Edit'/></a> ");
  180. if( $app->status == 'P' || $app->status == "M" ) {
  181. print("<a href='admin-apps.php?action=reject&app_id=$app->id' title='Reject' onclick=\"return confirm('Are you sure you want to reject this app?')\"><img src='/gifs/notes-reject.gif' width='13' height='13' border='0' alt='Reject'/></a> ");
  182. }
  183. print("<a href='admin-apps.php?action=delete&app_id=$app->id' title='Delete' onclick=\"return confirm('Are you sure you want to delete this app?')\"><img src='/gifs/notes-delete.gif' width='13' height=13 border='0' alt='Delete'/></a> ");
  184. }else if( $user_edit_mode == true ) {
  185. print("<a href='edit.php?action=edit&app_id=$app->id'>edit this application</a>");
  186. }else {
  187. print("
  188. <small>
  189. rating: <b>$rating</b> |
  190. rate:
  191. <a href='rate.php?app_id=$app->id&amp;rate=1&amp;the_cat={$_GET['the_cat']}&amp;the_subcat={$_GET['the_subcat']}&amp;offset=$offset'>1</a>
  192. <font color='#999999'>|</font>
  193. <a href='rate.php?app_id=$app->id&amp;rate=2&amp;the_cat={$_GET['the_cat']}&amp;the_subcat={$_GET['the_subcat']}&amp;offset=$offset'>2</a>
  194. <font color='#999999'>|</font>
  195. <a href='rate.php?app_id=$app->id&amp;rate=3&amp;the_cat={$_GET['the_cat']}&amp;the_subcat={$_GET['the_subcat']}&amp;offset=$offset'>3</a>
  196. <font color='#999999'>|</font>
  197. <a href='rate.php?app_id=$app->id&amp;rate=4&amp;the_cat={$_GET['the_cat']}&amp;the_subcat={$_GET['the_subcat']}&amp;offset=$offset'>4</a>
  198. <font color='#999999'>|</font>
  199. <a href='rate.php?app_id=$app->id&amp;rate=5&amp;the_cat={$_GET['the_cat']}&amp;the_subcat={$_GET['the_subcat']}&amp;offset=$offset'>5</a>
  200. </small>
  201. ");
  202. }
  203. print("
  204. </td>
  205. </tr>
  206. <tr valign=top bgcolor='#e0e0e0'>
  207. <td><small><a href='$app->homepage_url' target='apppop'>$app->homepage_url</a></small></td>
  208. <td align=right><small>$app->date_added</small></td>
  209. </tr>
  210. ");
  211. if( isset($MAGIC_COOKIE) ) {
  212. print("
  213. <tr valign=top bgcolor='#e0e0e0'>
  214. <td><small><a href='mailto:$app->submitter'>$app->submitter</a></small></td>
  215. <td align=right><small>" . $appCats[$app->cat_id]->name . "</small></td>
  216. </tr>
  217. ");
  218. }
  219. print("
  220. <tr valign=top>
  221. <td colspan=2>
  222. $screenshot
  223. $app->blurb
  224. </td>
  225. </tr>
  226. <tr><td colspan=2><br/></td></tr>
  227. ");
  228. }
  229. //
  230. // This function handles everything necessary to create the thumbnail of the screenshot,
  231. // resize the screenshot if necessary, and save the files to APP_SCREENSHOT_DIR
  232. //
  233. function handleAppImage($filename, $app_id) {
  234. $imgInfo = getimagesize($filename);
  235. switch($imgInfo[2]) {
  236. case 1:
  237. $src = ImageCreateFromGif($filename);
  238. break;
  239. case 2:
  240. $src = ImageCreateFromJpeg($filename);
  241. break;
  242. case 3:
  243. $src = ImageCreateFromPng($filename);
  244. break;
  245. }
  246. $srcWidth = ImageSX($src);
  247. $srcHeight = ImageSY($src);
  248. $dstWidth = $srcWidth;
  249. $dstHeight = $srcHeight;
  250. if( $srcWidth > 800 ) {
  251. $dstWidth = 800;
  252. $dstHeight = floor($srcHeight * $dstWidth/$srcWidth + .5);
  253. }
  254. $dst = ImageCreateTrueColor($dstWidth, $dstHeight);
  255. ImageCopyResampled($dst, $src, 0, 0, 0, 0, $dstWidth, $dstHeight, $srcWidth, $srcHeight);
  256. ImageJPEG($dst, APP_SCREENSHOT_DIR."/$app_id.jpg", 75);
  257. $thumbWidth = 120;
  258. $thumbHeight = floor($dstHeight * $thumbWidth/$dstWidth + .5);
  259. $thumb = ImageCreateTrueColor($thumbWidth, $thumbHeight);
  260. ImageCopyResampled($thumb, $dst, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $dstWidth, $dstHeight);
  261. ImageJPEG($thumb, APP_SCREENSHOT_DIR."/$app_id-thumb.jpg", 75);
  262. }
  263. ?>