Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Example of a PHP script communicating between the server and the OFP LoadMod.sqs script
- // Compliant with the standard described here:
- // http://ofp-faguss.com/files/OFPAD_metadatastandard.pdf
- echo "_version=0.5;";
- // ====================================================================================
- // Evaluate request type and return data
- // ====================================================================================
- // Return address list for other addon databases --------------------------------------
- if (isset($_GET[othersites]))
- {
- // Array with urls
- // This is an example. You could store this in a database instead.
- $list = array
- (
- // "http://www.address.example/for/ofp/download", //CUSTOMIZE
- );
- // Format it to an OFP array and return
- echo "_url=[";
- sort($list);
- foreach ($list as $item) echo "]+[".formatString($item);
- echo "];true";
- }
- // Search database --------------------------------------------------------------------
- else if (isset($_GET[search]))
- {
- // Assign input variables
- $search = $_GET[search];
- $page = $_GET[page];
- $calcTotalPages = !isset($_GET[page]);
- // Check input validity
- if ($calcTotalPages || $page<1) $page=1;
- if (get_magic_quotes_gpc()) $search=stripslashes($search);
- if ($search==NULL||ctype_space($search)) die("_errorMSG=\"Search subject is empty\";false");
- // Determine starting record based on page number
- $rowLimit = 10; //CUSTOMIZE
- $startRow = --$page * $rowLimit;
- // Connect to the database
- $link = mysqli_connect("", "", "", ""); //CUSTOMIZE
- if (!$link) die("_errorMSG=\"Couldn't connect to the database\";false");
- $table = "ofpaddon";
- mysqli_select_db($link, $table);
- $search = mysqli_real_escape_string($link, $search);
- // Build query string
- // In this example file size (in KB) is stored in the database
- // but you could measure it on the fly
- $query = "SELECT ";
- if ($calcTotalPages) $query.="SQL_CALC_FOUND_ROWS ";
- $query .= //CUSTOMIZE
- "
- DISTINCT(filename), url, filesize
- FROM {$table}
- WHERE
- pboname LIKE '%{$search}%'
- OR
- filename LIKE '%{$search}%'
- LIMIT {$startRow}, {$rowLimit}
- ";
- // Send query
- // If page number was not specified then send 2nd query for total number of results
- $result = mysqli_query($link, $query);
- $result2 = true;
- if ($calcTotalPages) $result2=mysqli_query($link, "SELECT FOUND_ROWS()");
- if (!$result || !$result2)
- die("_errorMSG=\"Invalid query:\\n".str_replace("\"","\"\"",mysqli_error($link))."\";false");
- // If page number was not specified then calculate total number of pages
- if ($calcTotalPages)
- {
- $temp = mysqli_fetch_row($result2);
- $total_records = $temp[0];
- $total_pages = ceil($total_records / $rowLimit);
- echo "_pages=$total_pages;_results=$total_records;";
- };
- // Put query results to an OFP array and then return it
- echo "_files=[";
- while($row = mysqli_fetch_assoc($result))
- {
- echo "]+[[" //CUSTOMIZE
- . formatTitle($row["filename"]) . ","
- . formatFileSize($row["filesize"]) . ","
- . formatString($row["url"]) . "]";
- };
- echo "];true";
- // Free memory
- mysqli_free_result($result);
- mysqli_close($link);
- }
- // Predetermined list of files --------------------------------------------------------
- else if (isset($_GET[quickaccess]))
- {
- // Array with file info
- // This is an example. You could store this in a database instead.
- $list = array
- (
- // array("Editor Addon 1.11","63","kegetys.net/ofp/KegetysEditorAddon111.zip"), //CUSTOMIZE
- );
- // Associate keys in the array
- function renameKeys($subarray)
- {
- return array('filename'=>$subarray[0], 'filesize'=>$subarray[1], 'url'=>$subarray[2]);
- };
- $list = array_map("renameKeys", $list);
- // Put array contents to an OFP array and then return it
- echo "_files=[";
- foreach($list as $row)
- {
- echo "]+[["
- . formatTitle($row["filename"]) . ","
- . formatFileSize($row["filesize"]) . ","
- . formatString($row["url"]) . "]";
- };
- echo "];true";
- }
- // Unknown request --------------------------------------------------------------------
- else echo "_errorMSG=\"Request not supported\";false";
- // ====================================================================================
- // Function inventory
- // ====================================================================================
- // Format file size number
- function formatFileSize($size) //CUSTOMIZE
- {
- if (ctype_space($size)) return "\"\"";
- if ($size > 1024)
- {$size=intval($size/1024); $size.=" MB";}
- else
- $size.=" KB";
- return "\"".$size."\"";
- };
- // Split string if it's too long - don't modify this function
- function formatString($string)
- {
- if (strlen($string)<=122)
- return "\"" . str_replace("\"","\"\"",$string) . "\"";
- $array = str_split($string, 122);
- $string = "[";
- foreach ($array as $part)
- $string .= "]+[\"" . str_replace("\"","\"\"",$part) . "\"";
- return $string."]";
- };
- // Double quot marks
- function formatTitle($string)
- {
- return "\"" . str_replace("\"", "\"\"", $string) . "\"";
- };
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement