Annotation of /trunk/ionfiles.php
Parent Directory
|
Revision Log
Revision 6 - (view) (download)
| 1 : | andphe | 2 | <?php |
| 2 : | sabiertas | 6 | // defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); |
| 3 : | andphe | 2 | ////////////////////////////////////////////// |
| 4 : | // FileName: ionFile.php | ||
| 5 : | // Date: 05/03/2006 | ||
| 6 : | // License: GNU General Public License | ||
| 7 : | // Script Version #: 1.3 | ||
| 8 : | // MOS Version #: 4.5 and 4.5.1+ | ||
| 9 : | // | ||
| 10 : | ////////////////////////////////////////////// | ||
| 11 : | |||
| 12 : | |||
| 13 : | /*************************************************************** | ||
| 14 : | // Disable errors | ||
| 15 : | ***************************************************************/ | ||
| 16 : | error_reporting ( 0 ); | ||
| 17 : | |||
| 18 : | /*************************************************************** | ||
| 19 : | // Enable magic quotes | ||
| 20 : | ***************************************************************/ | ||
| 21 : | if (get_magic_quotes_gpc ()) { | ||
| 22 : | // Yes? Strip the added slashes | ||
| 23 : | $_REQUEST = remove_magic_quotes ( $_REQUEST ); | ||
| 24 : | $_GET = remove_magic_quotes ( $_GET ); | ||
| 25 : | $_POST = remove_magic_quotes ( $_POST ); | ||
| 26 : | } | ||
| 27 : | set_magic_quotes_runtime ( 0 ); | ||
| 28 : | |||
| 29 : | /*************************************************************** | ||
| 30 : | // Globals | ||
| 31 : | ***************************************************************/ | ||
| 32 : | global $mosConfig_lang, $database; | ||
| 33 : | |||
| 34 : | /*************************************************************** | ||
| 35 : | // 1.5 DB | ||
| 36 : | ***************************************************************/ | ||
| 37 : | $database = get_db (); | ||
| 38 : | |||
| 39 : | /*************************************************************** | ||
| 40 : | // Basic Language | ||
| 41 : | ***************************************************************/ | ||
| 42 : | if (file_exists ( 'components/com_ionfiles/language/' . $mosConfig_lang . '.php' )) { | ||
| 43 : | include_once ('components/com_ionfiles/language/' . $mosConfig_lang . '.php'); | ||
| 44 : | } else { | ||
| 45 : | include_once ('components/com_ionfiles/language/english.php'); | ||
| 46 : | } | ||
| 47 : | |||
| 48 : | /*************************************************************** | ||
| 49 : | // Select our configuration | ||
| 50 : | ***************************************************************/ | ||
| 51 : | $query = "SELECT * FROM `#__ionfile_conf`"; | ||
| 52 : | $database->setQuery ( $query ); | ||
| 53 : | $rows = $database->loadObjectList (); | ||
| 54 : | if (count ( $rows ) < 1) { | ||
| 55 : | $query = "INSERT INTO `#__ionfile_conf` | ||
| 56 : | (hdr_text,show_size,show_ver,show_lic,show_icon,show_dl, | ||
| 57 : | show_desc,show_hdr,show_totals,show_hdr_desc,hdr_desc_text,allow_direct) | ||
| 58 : | VALUES ('Downloads',1,0,0,0,1,0,1,0,1,'Description',0);"; //<- May need to be changed in future versions, stores the default config. | ||
| 59 : | |||
| 60 : | |||
| 61 : | $database->setQuery ( $query ); | ||
| 62 : | $rows = $database->loadObjectList (); | ||
| 63 : | } | ||
| 64 : | |||
| 65 : | /*************************************************************** | ||
| 66 : | // variables | ||
| 67 : | ***************************************************************/ | ||
| 68 : | $func = GetParams ( "POST", 'func' ); | ||
| 69 : | $fileid = GetParams ( "POST", 'fileid' ); | ||
| 70 : | $categoryid = GetParams ( "POST", 'categoryid' ); | ||
| 71 : | $svalue = GetParams ( "POST", 'svalue' ); | ||
| 72 : | |||
| 73 : | /*************************************************************** | ||
| 74 : | // Determine our function | ||
| 75 : | // @params: func (user defined function) | ||
| 76 : | ***************************************************************/ | ||
| 77 : | switch ( $func) { | ||
| 78 : | case 'download' : | ||
| 79 : | downloadFile ( $fileid ); | ||
| 80 : | break; | ||
| 81 : | |||
| 82 : | case 'showarchive' : | ||
| 83 : | disp ( 1 ); | ||
| 84 : | break; | ||
| 85 : | |||
| 86 : | case 'showcategory' : | ||
| 87 : | disp ( 0, $categoryid ); | ||
| 88 : | break; | ||
| 89 : | |||
| 90 : | case 'search' : | ||
| 91 : | disp ( 0, 0, $svalue ); | ||
| 92 : | break; | ||
| 93 : | |||
| 94 : | default : | ||
| 95 : | disp (); | ||
| 96 : | break; | ||
| 97 : | } | ||
| 98 : | |||
| 99 : | /*************************************************************** | ||
| 100 : | // Display all of the files for th user | ||
| 101 : | // in order for download | ||
| 102 : | // @params onlyArchive (values 0 or 1) displays the archive files | ||
| 103 : | // @params categoryID - Displays a category id only | ||
| 104 : | ***************************************************************/ | ||
| 105 : | function disp($onlyArchive = 0, $categoryID = 0, $searchTerm = "") { | ||
| 106 : | |||
| 107 : | /*************************************************************** | ||
| 108 : | // ensure this file is being included by a parent file | ||
| 109 : | ***************************************************************/ | ||
| 110 : | if (! defined ( '_JEXEC' ) && ! defined ( '_VALID_MOS' )) | ||
| 111 : | die ( 'Restricted access' ); | ||
| 112 : | |||
| 113 : | // Globals | ||
| 114 : | global $my; | ||
| 115 : | $database = get_db (); | ||
| 116 : | |||
| 117 : | // Variables | ||
| 118 : | $hdrText = _IONFILE_HDR; | ||
| 119 : | $showSize = 1; | ||
| 120 : | $showVer = 1; | ||
| 121 : | $showLic = 1; | ||
| 122 : | $showIcon = 0; | ||
| 123 : | $showDl = 0; | ||
| 124 : | $showDesc = 1; | ||
| 125 : | $showTotals = 0; | ||
| 126 : | $showCats = 0; | ||
| 127 : | $hdrDescription = _IONFILE_HDR_DESCRIPTION; | ||
| 128 : | $showHdr = 1; | ||
| 129 : | $allow_direct = 1; | ||
| 130 : | $showHdr_Desc = 1; | ||
| 131 : | $showCats = 1; | ||
| 132 : | |||
| 133 : | // Select the config | ||
| 134 : | $query = "SELECT * FROM #__ionfile_conf" . "\n LIMIT 1"; | ||
| 135 : | |||
| 136 : | // Get our settings from the database | ||
| 137 : | $database->setQuery ( $query ); | ||
| 138 : | $rows = $database->loadObjectList (); | ||
| 139 : | if ($rows) { | ||
| 140 : | $myConfig = $rows [0]; | ||
| 141 : | // Assign our Variables | ||
| 142 : | $hdrText = $myConfig->hdr_text; | ||
| 143 : | $showSize = $myConfig->show_size; | ||
| 144 : | $showVer = $myConfig->show_ver; | ||
| 145 : | $showLic = $myConfig->show_lic; | ||
| 146 : | $showIcon = $myConfig->show_icon; | ||
| 147 : | $showDl = $myConfig->show_dl; | ||
| 148 : | $showDesc = $myConfig->show_desc; | ||
| 149 : | $showHdr = $myConfig->show_hdr; | ||
| 150 : | $showTotals = $myConfig->show_totals; | ||
| 151 : | $allow_direct = $myConfig->allow_direct; | ||
| 152 : | $showHdr_Desc = $myConfig->show_hdr_desc; | ||
| 153 : | $hdrDescription = $myConfig->hdr_desc_text; | ||
| 154 : | $showDate = $myConfig->show_date; | ||
| 155 : | $showSearch = $myConfig->show_search; | ||
| 156 : | $showArchive = $myConfig->show_archive; | ||
| 157 : | $allowCat = $myConfig->allow_category; | ||
| 158 : | $searchpos = $myConfig->search_pos; | ||
| 159 : | $disablesearch = $myConfig->disable_search; | ||
| 160 : | } | ||
| 161 : | |||
| 162 : | if (defined ( '_JEXEC' )) { | ||
| 163 : | $user = & JFactory::getUser (); | ||
| 164 : | $my->gid = $user->get ( 'aid', 0 ); | ||
| 165 : | } | ||
| 166 : | |||
| 167 : | // show only one category | ||
| 168 : | $catQuery = ''; | ||
| 169 : | if ($categoryID != 0 && $allowCat == 1) { | ||
| 170 : | $catQuery = "\n AND id=$categoryID"; | ||
| 171 : | } | ||
| 172 : | |||
| 173 : | $query = "SELECT * FROM #__ionfile_categories" . "\n WHERE published = '1'" . "\n AND access <= " . ( int ) $my->gid . $catQuery . "\n ORDER BY ordering ASC"; | ||
| 174 : | |||
| 175 : | // Select all Categories | ||
| 176 : | $database->setQuery ( $query ); | ||
| 177 : | $rows = $database->loadObjectList (); | ||
| 178 : | |||
| 179 : | ?> | ||
| 180 : | <script type="text/javascript"> | ||
| 181 : | <!-- | ||
| 182 : | function toggle_all(selectBox) { | ||
| 183 : | var id, i, a; | ||
| 184 : | id = 'iftr' + selectBox.options[selectBox.selectedIndex].innerHTML | ||
| 185 : | + selectBox.options[selectBox.selectedIndex].value; | ||
| 186 : | |||
| 187 : | // Remove spaces for XHTML | ||
| 188 : | id = removeSpaces(id); | ||
| 189 : | |||
| 190 : | for(i=0; ( a = document.getElementsByTagName('tr')[i]); i++) | ||
| 191 : | { | ||
| 192 : | // Grab our ID | ||
| 193 : | var s = a.id; | ||
| 194 : | |||
| 195 : | if (id != "iftrAll0") { | ||
| 196 : | if (s.substr(0, 4) == 'iftr') { | ||
| 197 : | |||
| 198 : | // Find the first period (used to make | ||
| 199 : | // unique ids) | ||
| 200 : | var posPeriod = s.indexOf("."); | ||
| 201 : | |||
| 202 : | // If posPeriod is > 0 then we are at | ||
| 203 : | // a file and need to remove the .xxxx | ||
| 204 : | if (posPeriod > 0) { | ||
| 205 : | s = s.substr(0, posPeriod); | ||
| 206 : | } | ||
| 207 : | |||
| 208 : | // Remove spaces for XHTML | ||
| 209 : | s = removeSpaces(s); | ||
| 210 : | |||
| 211 : | // Test to see if we have a match | ||
| 212 : | if (s == id) { | ||
| 213 : | a.style.display = ''; | ||
| 214 : | } | ||
| 215 : | else { | ||
| 216 : | a.style.display = 'none'; | ||
| 217 : | } | ||
| 218 : | } | ||
| 219 : | } | ||
| 220 : | else { | ||
| 221 : | a.style.display = ''; | ||
| 222 : | } | ||
| 223 : | |||
| 224 : | } | ||
| 225 : | } | ||
| 226 : | |||
| 227 : | function toggle_visibility(id) { | ||
| 228 : | var e = document.getElementById(id); | ||
| 229 : | if(e.style.display == 'none') | ||
| 230 : | e.style.display = 'block'; | ||
| 231 : | else | ||
| 232 : | e.style.display = 'none'; | ||
| 233 : | } | ||
| 234 : | |||
| 235 : | // Remove spaces of ids for XHTML | ||
| 236 : | function removeSpaces(string) { | ||
| 237 : | var tstring = ""; | ||
| 238 : | string = '' + string; | ||
| 239 : | splitstring = string.split(" "); | ||
| 240 : | for(i = 0; i < splitstring.length; i++) | ||
| 241 : | tstring += splitstring[i]; | ||
| 242 : | return tstring; | ||
| 243 : | } | ||
| 244 : | |||
| 245 : | //--> | ||
| 246 : | </script> | ||
| 247 : | |||
| 248 : | <script language="javascript" type="text/javascript"> | ||
| 249 : | <!-- // --><![CDATA[ | ||
| 250 : | function flip(img, flipto) { | ||
| 251 : | if(!img.old) { | ||
| 252 : | img.old = img.src; | ||
| 253 : | img.src = flipto; | ||
| 254 : | } | ||
| 255 : | else { | ||
| 256 : | var src = img.src; | ||
| 257 : | img.src = img.old; | ||
| 258 : | img.old = src; | ||
| 259 : | } | ||
| 260 : | } | ||
| 261 : | // ]]></script> | ||
| 262 : | |||
| 263 : | <?php | ||
| 264 : | |||
| 265 : | // CSS for Hiding Description | ||
| 266 : | print '<div style =".demo{ visibility:hidden;}">'; | ||
| 267 : | |||
| 268 : | // Print our header information | ||
| 269 : | if ($showHdr == 1) { | ||
| 270 : | print "<div class=\"componentheading\">"; | ||
| 271 : | print stripslashes ( $hdrText ); | ||
| 272 : | print "</div></div>"; | ||
| 273 : | } else | ||
| 274 : | |||
| 275 : | if ($showHdr == 0) { | ||
| 276 : | print "<div class=\"componentheading\">"; | ||
| 277 : | print "</div></div>"; | ||
| 278 : | } | ||
| 279 : | |||
| 280 : | // Display our header description | ||
| 281 : | if ($showHdr_Desc == 1) { | ||
| 282 : | print "<br />"; | ||
| 283 : | print stripslashes ( $hdrDescription ); | ||
| 284 : | print "<br /><br />"; | ||
| 285 : | } | ||
| 286 : | |||
| 287 : | // Check if there are any categories. If not, | ||
| 288 : | // display an error. | ||
| 289 : | if (count ( $rows ) < 1) { | ||
| 290 : | print "<b>" . _IONFILE_ERROR_NO_FILES_TO_DISPLAY . "</b>"; | ||
| 291 : | } else { | ||
| 292 : | |||
| 293 : | // Create our table | ||
| 294 : | print "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\">"; | ||
| 295 : | |||
| 296 : | // We need to count how many | ||
| 297 : | // colums there are to be displayed | ||
| 298 : | $colCount = 1; | ||
| 299 : | |||
| 300 : | // Print Icon | ||
| 301 : | if ($showIcon == 1) | ||
| 302 : | $colCount ++; | ||
| 303 : | |||
| 304 : | // File Name/Title | ||
| 305 : | // Version | ||
| 306 : | if ($showVer == 1) | ||
| 307 : | $colCount ++; | ||
| 308 : | |||
| 309 : | // File Size | ||
| 310 : | if ($showSize == 1) | ||
| 311 : | $colCount ++; | ||
| 312 : | |||
| 313 : | // Type/License | ||
| 314 : | if ($showLic == 1) | ||
| 315 : | $colCount ++; | ||
| 316 : | |||
| 317 : | // Downloads | ||
| 318 : | if ($showDl == 1) | ||
| 319 : | $colCount ++; | ||
| 320 : | |||
| 321 : | // Show Date | ||
| 322 : | if ($showDate == 1) | ||
| 323 : | $colCount ++; | ||
| 324 : | |||
| 325 : | // Show the search bar if admin wants | ||
| 326 : | if (! ($disablesearch == 1 && $categoryID > 0)) { | ||
| 327 : | if ($searchpos == 0 || $searchpos == 2) { | ||
| 328 : | buildSearchBar ( $allowCat, $showSearch, $showArchive, $colCount ); | ||
| 329 : | } | ||
| 330 : | } | ||
| 331 : | |||
| 332 : | // Our Header | ||
| 333 : | print "<tr>"; | ||
| 334 : | |||
| 335 : | // Print Icon | ||
| 336 : | if ($showIcon == 1) { | ||
| 337 : | print "<td></td>"; | ||
| 338 : | } | ||
| 339 : | // File Name/Title | ||
| 340 : | print "<td><div class=\"contentheading\">" . _IONFILE_PRODUCT . "</div></td>"; | ||
| 341 : | // Version | ||
| 342 : | if ($showVer == 1) { | ||
| 343 : | print "<td><div class=\"contentheading\">" . _IONFILE_VERSION . "</div></td>"; | ||
| 344 : | } | ||
| 345 : | // File Size | ||
| 346 : | if ($showSize == 1) { | ||
| 347 : | print "<td><div class=\"contentheading\">" . _IONFILE_SIZE . "</div></td>"; | ||
| 348 : | } | ||
| 349 : | // Type/License | ||
| 350 : | if ($showLic == 1) { | ||
| 351 : | print "<td><div class=\"contentheading\">" . _IONFILE_TYPE . "</div></td>"; | ||
| 352 : | } | ||
| 353 : | // Downloads | ||
| 354 : | if ($showDl == 1) { | ||
| 355 : | print "<td><div class=\"contentheading\">" . _IONFILE_DOWNLOADS . "</div></td>"; | ||
| 356 : | } | ||
| 357 : | // Show Date | ||
| 358 : | if ($showDate == 1) { | ||
| 359 : | print "<td><div class=\"contentheading\">" . _IONFILE_DATE . "</div></td>"; | ||
| 360 : | } | ||
| 361 : | |||
| 362 : | // End of Header | ||
| 363 : | print "</tr>"; | ||
| 364 : | |||
| 365 : | // Cycle through categories drawing the Cat Header and listing files | ||
| 366 : | foreach ( $rows as $row ) { | ||
| 367 : | // Set our archive string | ||
| 368 : | if ($onlyArchive == 1 && $showArchive == 1) { | ||
| 369 : | $archString = "AND archived ='1'"; | ||
| 370 : | } else { | ||
| 371 : | $archString = "AND archived !='1'"; | ||
| 372 : | } | ||
| 373 : | |||
| 374 : | // If the user is searching.... | ||
| 375 : | if ($showSearch && $searchTerm != "") { | ||
| 376 : | $archString = "AND (title like '%$searchTerm%' OR description like '%$searchTerm%')"; | ||
| 377 : | } | ||
| 378 : | |||
| 379 : | $query = "SELECT * FROM #__ionfile" . "\n WHERE published = '1' " . "\n AND cat_id ='$row->id'" . "\n AND access <= " . ( int ) $my->gid . "\n $archString" . "\n ORDER BY ordering"; | ||
| 380 : | // Select all files from the DB in current category | ||
| 381 : | $database->setQuery ( $query ); | ||
| 382 : | $file_rows = $database->loadObjectList (); | ||
| 383 : | |||
| 384 : | // Create unique ID for hiding row on cat select | ||
| 385 : | $rowId = 'iftr' . stripslashes ( $row->title ) . $row->id; | ||
| 386 : | |||
| 387 : | // Remove spaces | ||
| 388 : | $rowId = str_replace ( " ", "", $rowId ); | ||
| 389 : | |||
| 390 : | if (count ( $file_rows ) > 0) { | ||
| 391 : | // Display the category header | ||
| 392 : | if ($showCats) { | ||
| 393 : | print "<tr id=\"$rowId\"><td width=\"100%\" colspan=\"$colCount\" class=\"sectiontableheader\">"; | ||
| 394 : | |||
| 395 : | if ($row->link == 1 && $row->linkURL != "") { | ||
| 396 : | print "<a href=\"$row->linkURL\">"; | ||
| 397 : | print stripslashes ( $row->title ); | ||
| 398 : | print "</a>"; | ||
| 399 : | } else { | ||
| 400 : | print stripslashes ( $row->title ); | ||
| 401 : | } | ||
| 402 : | |||
| 403 : | print "</td></tr>"; | ||
| 404 : | } | ||
| 405 : | |||
| 406 : | // Setup our counter | ||
| 407 : | $counter = 1; | ||
| 408 : | $totalFileSize = 0; | ||
| 409 : | $totalFileDownloads = 0; | ||
| 410 : | |||
| 411 : | // Cycle through and list every download in the category | ||
| 412 : | foreach ( $file_rows as $dl_row ) { | ||
| 413 : | |||
| 414 : | // Find our grey class | ||
| 415 : | $class = ($counter % 2) ? "sectiontableentry1" : "sectiontableentry2"; | ||
| 416 : | |||
| 417 : | // Our Header | ||
| 418 : | print "<tr class=\"$class\" id=\"$rowId.$counter\">"; | ||
| 419 : | |||
| 420 : | // Print Icon | ||
| 421 : | if ($showIcon == 1) { | ||
| 422 : | print "<td valign=\"top\" class=\"$class\"><img src=\"$dl_row->icon_url\" width=\"16\" height=\"16\" alt=\"Icon\" /></td>"; | ||
| 423 : | } | ||
| 424 : | // File Name/Title | ||
| 425 : | print "<td valign=\"top\"><a href=\"index.php?option=com_ionfiles&func=download&fileid=$dl_row->id\">" . stripslashes ( $dl_row->title ) . "</a>"; | ||
| 426 : | |||
| 427 : | // Description | ||
| 428 : | if ($showDesc == 1 && $dl_row->description != "") { | ||
| 429 : | print " <img src=\"components/com_ionfiles/images/dropdown.gif\" alt=\"details\" align=\"top\" onclick=\"flip(this, 'components/com_ionfiles/images/up.gif'); toggle_visibility('ion$dl_row->id'); return false\" />"; | ||
| 430 : | |||
| 431 : | } | ||
| 432 : | // End of colum. | ||
| 433 : | print "</td>"; | ||
| 434 : | |||
| 435 : | // Version | ||
| 436 : | if ($showVer == 1) { | ||
| 437 : | print "<td valign=\"top\" >$dl_row->file_version</td>"; | ||
| 438 : | } | ||
| 439 : | |||
| 440 : | // File Size | ||
| 441 : | if ($showSize == 1) { | ||
| 442 : | print "<td valign=\"top\" >$dl_row->size</td>"; | ||
| 443 : | } | ||
| 444 : | $totalFileSize += str_replace ( "kb", "", strtolower ( $dl_row->size ) ); //Assumes no alpha symbols. Assumes all kb values. | ||
| 445 : | |||
| 446 : | |||
| 447 : | // Type/License | ||
| 448 : | if ($showLic == 1) { | ||
| 449 : | print "<td valign=\"top\" >$dl_row->license</td>"; | ||
| 450 : | } | ||
| 451 : | // Downloads | ||
| 452 : | if ($showDl == 1) { | ||
| 453 : | print "<td valign=\"top\" align=\"center\" >$dl_row->file_dl</td>"; | ||
| 454 : | } | ||
| 455 : | $totalFileDownloads += $dl_row->file_dl; | ||
| 456 : | // Date | ||
| 457 : | if ($showDate == 1) { | ||
| 458 : | print "<td valign=\"top\" align=\"center\" >$dl_row->date</td>"; | ||
| 459 : | } | ||
| 460 : | |||
| 461 : | // Increase our counter | ||
| 462 : | $counter = $counter + 1; | ||
| 463 : | print "</tr><tr><td width=\"100%\" colspan=\"$colCount\">"; | ||
| 464 : | |||
| 465 : | print "<div id=\"ion$dl_row->id\" style=\"display:none;\">" . stripslashes ( $dl_row->description ); | ||
| 466 : | print "<br />"; | ||
| 467 : | |||
| 468 : | // Print extra info | ||
| 469 : | if ($dl_row->info_url != "") { | ||
| 470 : | print "<a href=\"$dl_row->info_url\">[" . _IONFILE_MORE . "]</a> | "; | ||
| 471 : | } | ||
| 472 : | if ($dl_row->screenshot != "") { | ||
| 473 : | print "<a href=\"$dl_row->screenshot\">[" . _IONFILE_SCREENSHOTS . "]</a> | "; | ||
| 474 : | } | ||
| 475 : | if (($dl_row->homepage != "") && ($dl_row->author != "")) { | ||
| 476 : | print "<a href=\"$dl_row->homepage\">[$dl_row->author]</a> "; | ||
| 477 : | } | ||
| 478 : | if (($dl_row->homepage != "") && ($dl_row->author == "")) { | ||
| 479 : | print "<a href=\"$dl_row->homepage\">[" . _IONFILE_AUTHOR . "]</a> "; | ||
| 480 : | } | ||
| 481 : | if (($dl_row->homepage == "") && ($dl_row->author != "")) { | ||
| 482 : | print "[$dl_row->author] "; | ||
| 483 : | } | ||
| 484 : | |||
| 485 : | print "</div></td></tr>"; | ||
| 486 : | } // End $file_rows for | ||
| 487 : | } // End 0 or more check. | ||
| 488 : | if ($showSize && $showTotals) { | ||
| 489 : | print "<tr><td>" . _IONFILE_TOTAL . " " . _IONFILE_SIZE . ": " . ($totalFileSize / 1024) . "Mb</td></tr>"; | ||
| 490 : | } | ||
| 491 : | if ($showDl && $showTotals) { | ||
| 492 : | print "<tr><td>" . _IONFILE_TOTAL . " " . _IONFILE_DOWNLOADS . ": " . $totalFileDownloads . "</td></tr>"; | ||
| 493 : | } | ||
| 494 : | // Give a space | ||
| 495 : | if ($showCats && count ( $file_rows ) > 0) { | ||
| 496 : | print "<tr id=\"$rowId.x\"><td colspan=\"$colCount\"><br /></td></tr>"; | ||
| 497 : | } | ||
| 498 : | } // Category foreach | ||
| 499 : | |||
| 500 : | |||
| 501 : | // Show the search bar if admin wants | ||
| 502 : | if (! ($disablesearch == 1 && $categoryID > 0)) { | ||
| 503 : | if ($searchpos == 1 || $searchpos == 2) { | ||
| 504 : | buildSearchBar ( $allowCat, $showSearch, $showArchive, $colCount ); | ||
| 505 : | } | ||
| 506 : | } | ||
| 507 : | |||
| 508 : | // End our Tables | ||
| 509 : | print "</table>"; | ||
| 510 : | |||
| 511 : | // CodeCall Link | ||
| 512 : | /*print "<br />"; | ||
| 513 : | print "<center><a href=\"http://forum.codecall.net/community-projects/1321-project-ionfiles-joomla-simple-file-download.html\" target=\"_blank\">ionFiles</a> by"; | ||
| 514 : | print " <a href=\"http://www.codecall.net/\" target=\"_blank\">CodeCall Programming</a>"; | ||
| 515 : | print "</center>"; | ||
| 516 : | print "<br /><br />";*/ | ||
| 517 : | |||
| 518 : | } // End else check for 0 files | ||
| 519 : | |||
| 520 : | |||
| 521 : | } // End function disp | ||
| 522 : | |||
| 523 : | |||
| 524 : | /*************************************************************** | ||
| 525 : | // Creates/builds the search bar which houses the archive, | ||
| 526 : | // category select and search bar. Needed in multiple places | ||
| 527 : | // And has no return value (just prints directly), for now... | ||
| 528 : | ***************************************************************/ | ||
| 529 : | function buildSearchBar($allowCat, $showSearch, $showArchive, $colCount) { | ||
| 530 : | // Archive link, Search Bar and Category selection | ||
| 531 : | if ($allowCat || $showSearch || $showArchive) { | ||
| 532 : | print "<tr><td width=\"100%\" colspan=\"$colCount\" class=\"sectiontableheader\" style=\"text-align: center;\">"; | ||
| 533 : | |||
| 534 : | // Start a new table | ||
| 535 : | print '<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td>'; | ||
| 536 : | |||
| 537 : | // Display the archive link | ||
| 538 : | // That will allow the user to see archived files | ||
| 539 : | if ($showArchive && $onlyArchive == 0) { | ||
| 540 : | print "<a href=\"index.php?option=com_ionfiles&func=showarchive\">" . _IONFILE_ARCHIVE . "</a>"; | ||
| 541 : | print "</td>"; | ||
| 542 : | } else if ($showArchive && $onlyArchive == 1) { | ||
| 543 : | print "<a href=\"index.php?option=com_ionfiles\">" . _IONFILE_FULL . "</a>"; | ||
| 544 : | print "</td>"; | ||
| 545 : | } | ||
| 546 : | |||
| 547 : | // Display the category drop-box | ||
| 548 : | if ($allowCat) { | ||
| 549 : | print "<td>"; | ||
| 550 : | print build_cat_html (); | ||
| 551 : | print "</td>"; | ||
| 552 : | } | ||
| 553 : | |||
| 554 : | // Display the search | ||
| 555 : | if ($showSearch) { | ||
| 556 : | print "<td>"; | ||
| 557 : | print "<form action=\"index.php\"><input type=\"text\" name=\"svalue\" | ||
| 558 : | onblur=\"if(this.value=='') this.value='" . _IONFILE_SEARCH . "';\" | ||
| 559 : | onfocus=\"if(this.value=='" . _IONFILE_SEARCH . "') this.value='';\" value=\"" . _IONFILE_SEARCH . "\" />"; | ||
| 560 : | print "<input type=\"hidden\" name=\"option\" value=\"com_ionfiles\" />"; | ||
| 561 : | print "<input type=\"hidden\" name=\"func\" value=\"search\" />"; | ||
| 562 : | print "</form>"; | ||
| 563 : | print "</td>"; | ||
| 564 : | } | ||
| 565 : | |||
| 566 : | print "</tr></table>"; | ||
| 567 : | print "</td></tr>"; | ||
| 568 : | } | ||
| 569 : | |||
| 570 : | } | ||
| 571 : | |||
| 572 : | /*************************************************************** | ||
| 573 : | // Download Function | ||
| 574 : | ***************************************************************/ | ||
| 575 : | function downloadFile($uid) { | ||
| 576 : | # If a download has already been selected, | ||
| 577 : | #----------------------------------------- | ||
| 578 : | If ($uid) { | ||
| 579 : | # Define Globals | ||
| 580 : | #------------------------------- | ||
| 581 : | global $mosConfig_live_site, $mainframe; | ||
| 582 : | $database = get_db (); | ||
| 583 : | |||
| 584 : | # SQL Query | ||
| 585 : | $query = "SELECT file_url, download FROM #__ionfile" . "\n WHERE published = '1' AND id = '$uid'" . "\n LIMIT 1"; | ||
| 586 : | |||
| 587 : | // Select the file location from the db | ||
| 588 : | $database->setQuery ( $query ); | ||
| 589 : | $file_dl = $database->loadObjectList (); | ||
| 590 : | $myFile = $file_dl [0]; | ||
| 591 : | |||
| 592 : | # Get the filename to be downloaded | ||
| 593 : | #---------------------------------- | ||
| 594 : | $file = $myFile->file_url; | ||
| 595 : | $file = stripslashes ( $file ); | ||
| 596 : | $file = htmlspecialchars ( $file ); | ||
| 597 : | $download = $myFile->download; | ||
| 598 : | |||
| 599 : | # if the file prefix is to a local folder, append livesite data by Ed | ||
| 600 : | # ------------------------------------------------------------- | ||
| 601 : | if (strtolower ( substr ( $file, 0, 7 ) ) != 'http://' && strtolower ( substr ( $file, 0, 6 ) ) != "ftp://") { | ||
| 602 : | if (defined ( '_JEXEC' )) { | ||
| 603 : | $file = JPATH_ROOT . '/' . $file; | ||
| 604 : | } else { | ||
| 605 : | global $mosConfig_absolute_path; | ||
| 606 : | $file = $mosConfig_absolute_path . '/' . $file; | ||
| 607 : | } | ||
| 608 : | } | ||
| 609 : | |||
| 610 : | # Increment download count | ||
| 611 : | #------------------------------------------ | ||
| 612 : | $query = "UPDATE #__ionfile" . "\n SET file_dl=file_dl+1" . "\n WHERE id='$uid'"; | ||
| 613 : | $database->setQuery ( $query ); | ||
| 614 : | |||
| 615 : | if (! $database->query ()) { | ||
| 616 : | echo "$database->getErrorMsg()"; | ||
| 617 : | exit (); | ||
| 618 : | } | ||
| 619 : | |||
| 620 : | |||
| 621 : | # Begin the file download | ||
| 622 : | #------------------------------------------- | ||
| 623 : | startDownload($file, $download); | ||
| 624 : | |||
| 625 : | } else { | ||
| 626 : | print _IONFILE_ERROR_NO_FILE_SELECTED; | ||
| 627 : | die (); | ||
| 628 : | } | ||
| 629 : | } | ||
| 630 : | |||
| 631 : | /*************************************************************** | ||
| 632 : | // Joomla 1.5/1.0 DB switch for get Params | ||
| 633 : | ***************************************************************/ | ||
| 634 : | function GetParams($method = "POST", $field, $default = "", $params = "", $type = "") { | ||
| 635 : | if (defined ( '_JEXEC' )) { | ||
| 636 : | // Change the type from old to new | ||
| 637 : | if ($params == "_MOS_ALLOWHTML") { | ||
| 638 : | $params = JREQUEST_ALLOWHTML; | ||
| 639 : | } | ||
| 640 : | |||
| 641 : | if ($params) { | ||
| 642 : | $variable = JRequest::getVar ( $field, $default, $method, $type, $params ); | ||
| 643 : | } else { | ||
| 644 : | $variable = JRequest::getVar ( $field ); | ||
| 645 : | } | ||
| 646 : | } else { | ||
| 647 : | if ($method == "POST") { | ||
| 648 : | $variable = mosGetParam ( $_REQUEST, $field, $default, $params ); | ||
| 649 : | } else { | ||
| 650 : | $variable = mosGetParam ( $_REQUEST, $field, $default, $params ); | ||
| 651 : | } | ||
| 652 : | } | ||
| 653 : | |||
| 654 : | return $variable; | ||
| 655 : | |||
| 656 : | } | ||
| 657 : | |||
| 658 : | /*************************************************************** | ||
| 659 : | // Misc Functions | ||
| 660 : | ***************************************************************/ | ||
| 661 : | function remove_magic_quotes($array) { | ||
| 662 : | foreach ( $array as $k => $v ) { | ||
| 663 : | if (is_array ( $v )) | ||
| 664 : | $array [$k] = remove_magic_quotes ( $v ); else | ||
| 665 : | $array [$k] = stripslashes ( $v ); | ||
| 666 : | } | ||
| 667 : | return $array; | ||
| 668 : | } | ||
| 669 : | |||
| 670 : | /*************************************************************** | ||
| 671 : | // Error Messages | ||
| 672 : | ***************************************************************/ | ||
| 673 : | function error_msg($message) { | ||
| 674 : | echo "<script> alert('" . $message . "'); window.history.go(-1); </script>\n"; | ||
| 675 : | |||
| 676 : | } | ||
| 677 : | |||
| 678 : | /*************************************************************** | ||
| 679 : | // Joomla 1.5/1.0 DB switch | ||
| 680 : | ***************************************************************/ | ||
| 681 : | function get_db() { | ||
| 682 : | if (defined ( '_JEXEC' )) { // 1.5 | ||
| 683 : | // This gets the database object using the JFactory class | ||
| 684 : | $database = &JFactory::getDBO (); | ||
| 685 : | } else { | ||
| 686 : | // Use the Joomla 1.0 database | ||
| 687 : | global $database; | ||
| 688 : | } | ||
| 689 : | |||
| 690 : | return $database; | ||
| 691 : | } | ||
| 692 : | |||
| 693 : | /**************************************************************** | ||
| 694 : | // Build Category list | ||
| 695 : | ***************************************************************/ | ||
| 696 : | function build_cat_html() { | ||
| 697 : | global $my; | ||
| 698 : | |||
| 699 : | $database = get_db (); | ||
| 700 : | $categoryid = GetParams ( "POST", 'categoryid' ); | ||
| 701 : | |||
| 702 : | $query = "SELECT * FROM #__ionfile_categories" . "\n WHERE published = '1'" . "\n AND access <= " . ( int ) $my->gid . "\n ORDER BY ordering ASC"; | ||
| 703 : | |||
| 704 : | // Select all Categories | ||
| 705 : | $database->setQuery ( $query ); | ||
| 706 : | $rows = $database->loadObjectList (); | ||
| 707 : | |||
| 708 : | // Build our form | ||
| 709 : | $html = "<form action=\"index.php\" method=\"get\">"; | ||
| 710 : | $html = $html . "<input type=\"hidden\" name=\"option\" value=\"com_ionfiles\" />"; | ||
| 711 : | $html = $html . "<input type=\"hidden\" name=\"func\" value=\"showcategory\" />"; | ||
| 712 : | |||
| 713 : | // Build the select form | ||
| 714 : | $html = $html . ' <select name="categoryid" onchange="javascript:toggle_all(this);" style="width: 150px;"><option value="0">All</option>'; | ||
| 715 : | |||
| 716 : | // Cycle through categories drawing the Cat Header and listing files | ||
| 717 : | foreach ( $rows as $row ) { | ||
| 718 : | if ($row->id == $categoryid) { | ||
| 719 : | $html = $html . '<option SELECTED value="' . $row->id . '">' . $row->title . '</option>'; | ||
| 720 : | } else { | ||
| 721 : | $html = $html . '<option value="' . $row->id . '">' . $row->title . '</option>'; | ||
| 722 : | } | ||
| 723 : | } | ||
| 724 : | |||
| 725 : | $html = $html . '</select></form>'; | ||
| 726 : | |||
| 727 : | return $html; | ||
| 728 : | } | ||
| 729 : | |||
| 730 : | |||
| 731 : | /********************************************** | ||
| 732 : | // Code imported from download.php | ||
| 733 : | * v2.4.3 - Initial import - (TkTech) | ||
| 734 : | **********************************************/ | ||
| 735 : | |||
| 736 : | function startDownload($file, $download) { | ||
| 737 : | |||
| 738 : | # Make sure program execution doesn't time out | ||
| 739 : | #------------------------------- | ||
| 740 : | set_time_limit(0); | ||
| 741 : | |||
| 742 : | # Get the filename to be downloaded | ||
| 743 : | #---------------------------------- | ||
| 744 : | #$file = stripslashes($file); | ||
| 745 : | #$file = htmlspecialchars($file); | ||
| 746 : | |||
| 747 : | # file extension | ||
| 748 : | #----------------------------------- | ||
| 749 : | $fext = strtolower(substr(strrchr($file,"."),1)); | ||
| 750 : | |||
| 751 : | # Get the File Size | ||
| 752 : | #----------------------------------- | ||
| 753 : | //$fsize = remotefsize($file); | ||
| 754 : | |||
| 755 : | # Get the mime type | ||
| 756 : | #------------------------------------ | ||
| 757 : | $mtype = getmtype($fext); | ||
| 758 : | |||
| 759 : | # Check to see if the file is a link or download | ||
| 760 : | #------------------------------------------------- | ||
| 761 : | if ($download == 1) { | ||
| 762 : | header("Pragma:no-cache"); | ||
| 763 : | header("Expires: 0"); | ||
| 764 : | header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | ||
| 765 : | header("Cache-Control: public"); | ||
| 766 : | header("Content-Description: File Transfer"); | ||
| 767 : | header("Content-type: $mtype"); | ||
| 768 : | header("Content-Transfer-Encoding: binary"); | ||
| 769 : | header("Content-Disposition: attachment; filename=\"".basename($file)."\""); | ||
| 770 : | |||
| 771 : | |||
| 772 : | if (ini_get('allow_url_fopen')) { | ||
| 773 : | if (extension_loaded('curl')) { | ||
| 774 : | header("Content-Length: " . remotefsize($file)); | ||
| 775 : | } | ||
| 776 : | } | ||
| 777 : | |||
| 778 : | header("Accept-Ranges: bytes"); | ||
| 779 : | @readfile("$file"); | ||
| 780 : | |||
| 781 : | // Exit so that Joomla headers do not | ||
| 782 : | // corrupt the download. | ||
| 783 : | exit(); | ||
| 784 : | |||
| 785 : | } | ||
| 786 : | else { | ||
| 787 : | # Forward the user to the file | ||
| 788 : | #-------------------------------------------------- | ||
| 789 : | header("Location: " .$file); | ||
| 790 : | } | ||
| 791 : | |||
| 792 : | } | ||
| 793 : | //////////////////////////////////////////////////////////// | ||
| 794 : | // Get the mtype | ||
| 795 : | //////////////////////////////////////////////////////////// | ||
| 796 : | function getmtype($fext) { | ||
| 797 : | |||
| 798 : | # Mime Types | ||
| 799 : | #------------------------------- | ||
| 800 : | $mine_types = array ( | ||
| 801 : | |||
| 802 : | # archives | ||
| 803 : | #------------------------------- | ||
| 804 : | 'zip' => 'application/zip', | ||
| 805 : | |||
| 806 : | # documents | ||
| 807 : | #------------------------------- | ||
| 808 : | 'pdf' => 'application/pdf', | ||
| 809 : | 'doc' => 'application/msword', | ||
| 810 : | 'xls' => 'application/vnd.ms-excel', | ||
| 811 : | 'ppt' => 'application/vnd.ms-powerpoint', | ||
| 812 : | |||
| 813 : | # executables | ||
| 814 : | #------------------------------- | ||
| 815 : | 'exe' => 'application/octet-stream', | ||
| 816 : | |||
| 817 : | # images | ||
| 818 : | #------------------------------- | ||
| 819 : | 'gif' => 'image/gif', | ||
| 820 : | 'png' => 'image/png', | ||
| 821 : | 'jpg' => 'image/jpeg', | ||
| 822 : | 'jpeg' => 'image/jpeg', | ||
| 823 : | |||
| 824 : | # audio | ||
| 825 : | #------------------------------- | ||
| 826 : | 'mp3' => 'audio/mpeg', | ||
| 827 : | 'wav' => 'audio/x-wav', | ||
| 828 : | |||
| 829 : | # video | ||
| 830 : | #------------------------------- | ||
| 831 : | 'mpeg' => 'video/mpeg', | ||
| 832 : | 'mpg' => 'video/mpeg', | ||
| 833 : | 'mpe' => 'video/mpeg', | ||
| 834 : | 'mov' => 'video/quicktime', | ||
| 835 : | 'avi' => 'video/x-msvideo' | ||
| 836 : | |||
| 837 : | ); | ||
| 838 : | |||
| 839 : | # Find the Mime Type | ||
| 840 : | #------------------------------- | ||
| 841 : | if ($mine_types[$fext] == '') { | ||
| 842 : | $mtype = ''; | ||
| 843 : | |||
| 844 : | # mime type is not set, get from server settings | ||
| 845 : | #------------------------------- | ||
| 846 : | if (function_exists('mime_content_type')) { | ||
| 847 : | $mtype = mime_content_type($file); | ||
| 848 : | } | ||
| 849 : | else | ||
| 850 : | { | ||
| 851 : | $mtype = "application/force-download"; | ||
| 852 : | } | ||
| 853 : | |||
| 854 : | } | ||
| 855 : | else | ||
| 856 : | { | ||
| 857 : | # get mime type defined by admin | ||
| 858 : | #------------------------------- | ||
| 859 : | $mtype = $mine_types[$fext]; | ||
| 860 : | } | ||
| 861 : | |||
| 862 : | # Return our Type | ||
| 863 : | #------------------------------- | ||
| 864 : | return $mtype; | ||
| 865 : | } | ||
| 866 : | |||
| 867 : | //////////////////////////////////////////////////////////// | ||
| 868 : | // Filesize of remote file | ||
| 869 : | // Grab the filesize of a file hosted on another server | ||
| 870 : | //////////////////////////////////////////////////////////// | ||
| 871 : | function remotefsize($url, $user = "", $pw = ""){ | ||
| 872 : | ob_start(); | ||
| 873 : | $ch = curl_init($url); | ||
| 874 : | curl_setopt($ch, CURLOPT_HEADER, 1); | ||
| 875 : | curl_setopt($ch, CURLOPT_NOBODY, 1); | ||
| 876 : | |||
| 877 : | if(!empty($user) && !empty($pw)) | ||
| 878 : | |||
| 879 : | { | ||
| 880 : | $headers = array('Authorization: Basic ' . base64_encode("$user:$pw")); | ||
| 881 : | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | ||
| 882 : | } | ||
| 883 : | |||
| 884 : | |||
| 885 : | $ok = curl_exec($ch); | ||
| 886 : | curl_close($ch); | ||
| 887 : | $head = ob_get_contents(); | ||
| 888 : | ob_end_clean(); | ||
| 889 : | |||
| 890 : | $regex = '/Content-Length:\s([0-9].+?)\s/'; | ||
| 891 : | $count = preg_match($regex, $head, $matches); | ||
| 892 : | |||
| 893 : | return isset($matches[1]) ? $matches[1] : "unknown"; | ||
| 894 : | } | ||
| 895 : | |||
| 896 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

