1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 12:20:44 +02:00

Tidy up formatting a bit

This commit is contained in:
e107steved
2008-12-30 16:51:07 +00:00
parent bb450cb261
commit bc5dab5ecd
2 changed files with 177 additions and 91 deletions

View File

@@ -10,6 +10,11 @@
| |
| Released under the terms and conditions of the | Released under the terms and conditions of the
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/pref_class.php,v $
| $Revision: 1.2 $
| $Date: 2008-12-30 16:51:07 $
| $Author: e107steved $
+---------------------------------------------------------------+ +---------------------------------------------------------------+
*/ */
@@ -30,14 +35,21 @@ if (!defined('e107_INIT')) { exit; }
// Just to be safe I have changed a number of menu_pref edits to use setArray(). // Just to be safe I have changed a number of menu_pref edits to use setArray().
// //
class prefs { class prefs
{
var $prefVals; var $prefVals;
var $prefArrays; var $prefArrays;
// List of rows that shouldn't be automatically extracted (delimeted by '|') // Default prefs to load
var $DefaultRows = "e107_name='e107' OR e107_name='menu_pref' OR e107_name='notify_prefs'"; var $DefaultRows = "e107_name='e107' OR e107_name='menu_pref' OR e107_name='notify_prefs'";
function ExtractPrefs($RowList = "", $use_default = FALSE) { // Read prefs from DB - get as many rows as are required with a single query.
// $RowList is an array of pref entries to retrieve.
// If $use_default is TRUE, $RowList entries are added to the default array. Otherwise only $RowList is used.
// Returns TRUE on success (measured as getting at least one row of data); false on error.
// Any data read is buffered (in serialised form) here - retrieve using get()
function ExtractPrefs($RowList = "", $use_default = FALSE)
{
global $sql; global $sql;
$Args = ''; $Args = '';
if($use_default) if($use_default)
@@ -51,36 +63,50 @@ class prefs {
$Args .= ($Args ? " OR e107_name='{$v}'" : "e107_name='{$v}'"); $Args .= ($Args ? " OR e107_name='{$v}'" : "e107_name='{$v}'");
} }
} }
$sql->db_Select('core', '*', $Args, 'default'); if (!$sql->db_Select('core', '*', $Args, 'default'))
{
return FALSE;
}
while ($row = $sql->db_Fetch()) while ($row = $sql->db_Fetch())
{ {
$this->prefVals['core'][$row['e107_name']] = $row['e107_value']; $this->prefVals['core'][$row['e107_name']] = $row['e107_value'];
} }
return TRUE;
} }
/** /**
* Return current pref string $name from $table (only core for now) * Return current pref string $name from $table (only core for now)
* *
* - @param string $name -- name of pref row * - @param string $name -- name of pref row
* - @param string $table -- "core" * - @param string $table -- "core"
* - @return string pref value, slashes already stripped * - @return string pref value, slashes already stripped. FALSE on error
* - @access public * - @access public
*/ */
function get($Name) { function get($Name)
if(isset($this->prefVals['core'][$Name])){ {
if($this->prefVals['core'][$Name] != '### ROW CACHE FALSE ###'){ if(isset($this->prefVals['core'][$Name]))
return $this->prefVals['core'][$Name]; {
} else { if($this->prefVals['core'][$Name] != '### ROW CACHE FALSE ###')
{
return $this->prefVals['core'][$Name]; // Dava from cache
}
else
{
return false; return false;
} }
} }
// Data not in cache - retrieve from DB
$get_sql = new db; // required so sql loops don't break using $tp->toHTML(). $get_sql = new db; // required so sql loops don't break using $tp->toHTML().
if($get_sql->db_Select('core', '*', "`e107_name` = '{$Name}'", 'default')) { if($get_sql->db_Select('core', '*', "`e107_name` = '{$Name}'", 'default'))
{
$row = $get_sql->db_Fetch(); $row = $get_sql->db_Fetch();
$this->prefVals['core'][$Name] = $row['e107_value']; $this->prefVals['core'][$Name] = $row['e107_value'];
return $this->prefVals['core'][$Name]; return $this->prefVals['core'][$Name];
} else { }
else
{ // Data not in DB - put a 'doesn't exist' entry in cache to save another DB access
$this->prefVals['core'][$Name] = '### ROW CACHE FALSE ###'; $this->prefVals['core'][$Name] = '### ROW CACHE FALSE ###';
return false; return false;
} }

View File

@@ -12,57 +12,73 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/request.php,v $ | $Source: /cvs_backup/e107_0.8/request.php,v $
| $Revision: 1.5 $ | $Revision: 1.6 $
| $Date: 2008-07-04 20:23:13 $ | $Date: 2008-12-30 16:51:07 $
| $Author: e107steved $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
// ********************************** SEE HIGHLIGHTED AND NUMBERED QUERIES *****************************
require_once("class2.php"); require_once("class2.php");
include_lan(e_LANGUAGEDIR.e_LANGUAGE."/lan_download.php"); include_lan(e_LANGUAGEDIR.e_LANGUAGE."/lan_download.php");
if (!e_QUERY || isset($_POST['userlogin'])) { if (!e_QUERY || isset($_POST['userlogin']))
{
header("location: {$e107->base_path}"); header("location: {$e107->base_path}");
exit(); exit();
} }
$id = FALSE; $id = FALSE;
if (!is_numeric(e_QUERY)) { if (!is_numeric(e_QUERY))
if ($sql->db_Select("download", "download_id", "download_url='".$tp -> toDB(e_QUERY)."'")) { {
if ($sql->db_Select('download', 'download_id', "download_url='".$tp -> toDB(e_QUERY)."'"))
{
$row = $sql->db_Fetch(); $row = $sql->db_Fetch();
$type = "file"; $type = 'file';
$id = $row['download_id']; $id = $row['download_id'];
} else if(strstr(e_QUERY, "http://") || strstr(e_QUERY, "ftp://" || strstr(e_QUERY, "https://"))) { }
elseif((strpos(e_QUERY, "http://") === 0) || (strpos(e_QUERY, "ftp://") === 0) || (strpos(e_QUERY, "https://") === 0))
{
header("location: ".e_QUERY); header("location: ".e_QUERY);
exit(); exit();
} else if(file_exists($DOWNLOADS_DIRECTORY.e_QUERY)) { }
elseif(file_exists($DOWNLOADS_DIRECTORY.e_QUERY)) // 1 - should we allow this?
{
send_file($DOWNLOADS_DIRECTORY.e_QUERY); send_file($DOWNLOADS_DIRECTORY.e_QUERY);
exit(); exit();
} }
} }
if(strstr(e_QUERY, "mirror")) {
if(strstr(e_QUERY, "mirror"))
{ // Download from mirror
list($action, $download_id, $mirror_id) = explode(".", e_QUERY); list($action, $download_id, $mirror_id) = explode(".", e_QUERY);
$download_id = intval($download_id); $download_id = intval($download_id);
$mirror_id = intval($mirror_id); $mirror_id = intval($mirror_id);
$qry = "SELECT d.*, dc.download_category_class FROM #download as d LEFT JOIN #download_category AS dc ON dc.download_category_id = d.download_category WHERE d.download_id = {$download_id}"; $qry = "SELECT d.*, dc.download_category_class FROM #download as d LEFT JOIN #download_category AS dc ON dc.download_category_id = d.download_category WHERE d.download_id = {$download_id}";
if ($sql->db_Select_gen($qry)) { if ($sql->db_Select_gen($qry))
{
$row = $sql->db_Fetch(); $row = $sql->db_Fetch();
extract($row); extract($row);
if (check_class($download_category_class) && check_class($download_class)) if (check_class($download_category_class) && check_class($download_class))
{ {
if($pref['download_limits'] && $download_active == 1) { if($pref['download_limits'] && $download_active == 1)
{
check_download_limits(); check_download_limits();
} }
$mirrorList = explode(chr(1), $download_mirror); $mirrorList = explode(chr(1), $download_mirror);
$mstr = ""; $mstr = "";
foreach($mirrorList as $mirror) { foreach($mirrorList as $mirror)
if($mirror) { {
if($mirror)
{
$tmp = explode(",", $mirror); $tmp = explode(",", $mirror);
$mid = intval($tmp[0]); $mid = intval($tmp[0]);
$address = $tmp[1]; $address = $tmp[1];
$requests = $tmp[2]; $requests = $tmp[2];
if($tmp[0] == $mirror_id) { if($tmp[0] == $mirror_id)
{
$gaddress = trim($address); $gaddress = trim($address);
$requests ++; $requests ++;
} }
@@ -80,16 +96,21 @@ if(strstr(e_QUERY, "mirror")) {
} }
$tmp = explode(".", e_QUERY); $tmp = explode(".", e_QUERY);
if (!$tmp[1] || strstr(e_QUERY, "pub_")) { if (!$tmp[1] || strstr(e_QUERY, "pub_"))
{
$id = intval($tmp[0]); $id = intval($tmp[0]);
$type = "file"; $type = "file";
} else { }
else
{
$table = preg_replace("#\W#", "", $tp -> toDB($tmp[0], true)); $table = preg_replace("#\W#", "", $tp -> toDB($tmp[0], true));
$id = intval($tmp[1]); $id = intval($tmp[1]);
$type = "image"; $type = "image";
} }
if (preg_match("#.*\.[a-z,A-Z]{3,4}#", e_QUERY)) {
if (preg_match("#.*\.[a-z,A-Z]{3,4}#", e_QUERY))
{
if(strstr(e_QUERY, "pub_")) if(strstr(e_QUERY, "pub_"))
{ {
$bid = str_replace("pub_", "", e_QUERY); $bid = str_replace("pub_", "", e_QUERY);
@@ -99,7 +120,8 @@ if (preg_match("#.*\.[a-z,A-Z]{3,4}#", e_QUERY)) {
exit(); exit();
} }
} }
if (file_exists($DOWNLOADS_DIRECTORY.e_QUERY)) { if (file_exists($DOWNLOADS_DIRECTORY.e_QUERY))
{
send_file($DOWNLOADS_DIRECTORY.e_QUERY); send_file($DOWNLOADS_DIRECTORY.e_QUERY);
exit(); exit();
} }
@@ -125,14 +147,17 @@ if ($type == "file")
exit(); exit();
} }
if($pref['download_limits'] && $row['download_active'] == 1) { if($pref['download_limits'] && $row['download_active'] == 1)
{
check_download_limits(); check_download_limits();
} }
extract($row); extract($row);
if($download_mirror) { if($download_mirror)
{
$array = explode(chr(1), $download_mirror); $array = explode(chr(1), $download_mirror);
$c = (count($array)-1); $c = (count($array)-1);
for ($i=1; $i < $c; $i++) { for ($i=1; $i < $c; $i++)
{
$d = mt_rand(0, $i); $d = mt_rand(0, $i);
$tmp = $array[$i]; $tmp = $array[$i];
$array[$i] = $array[$d]; $array[$i] = $array[$d];
@@ -141,8 +166,10 @@ if ($type == "file")
$tmp = explode(",", $array[0]); $tmp = explode(",", $array[0]);
$mirror_id = $tmp[0]; $mirror_id = $tmp[0];
$mstr = ""; $mstr = "";
foreach($array as $mirror) { foreach($array as $mirror)
if($mirror) { {
if($mirror)
{
$tmp = explode(",", $mirror); $tmp = explode(",", $mirror);
$mid = $tmp[0]; $mid = $tmp[0];
$address = $tmp[1]; $address = $tmp[1];
@@ -169,7 +196,8 @@ if ($type == "file")
$request_data = "'0', '{$user_id}', '{$ip}', '{$id}', '".time()."'"; $request_data = "'0', '{$user_id}', '{$ip}', '{$id}', '".time()."'";
//add request info to db //add request info to db
$sql->db_Insert("download_requests", $request_data, FALSE); $sql->db_Insert("download_requests", $request_data, FALSE);
if (preg_match("/Binary\s(.*?)\/.*/", $download_url, $result)) { if (preg_match("/Binary\s(.*?)\/.*/", $download_url, $result))
{
$bid = $result[1]; $bid = $result[1];
$result = @mysql_query("SELECT * FROM ".MPREFIX."rbinary WHERE binary_id = '{$bid}'"); $result = @mysql_query("SELECT * FROM ".MPREFIX."rbinary WHERE binary_id = '{$bid}'");
$binary_data = @mysql_result($result, 0, "binary_data"); $binary_data = @mysql_result($result, 0, "binary_data");
@@ -185,11 +213,16 @@ if ($type == "file")
if (strstr($download_url, "http://") || strstr($download_url, "ftp://") || strstr($download_url, "https://")) { if (strstr($download_url, "http://") || strstr($download_url, "ftp://") || strstr($download_url, "https://")) {
header("Location: {$download_url}"); header("Location: {$download_url}");
exit(); exit();
} else { }
if (file_exists($DOWNLOADS_DIRECTORY.$download_url)) { else
{
if (file_exists($DOWNLOADS_DIRECTORY.$download_url))
{
send_file($DOWNLOADS_DIRECTORY.$download_url); send_file($DOWNLOADS_DIRECTORY.$download_url);
exit(); exit();
} else if(file_exists(e_FILE."public/{$download_url}")) { }
elseif(file_exists(e_FILE."public/{$download_url}"))
{
send_file(e_FILE."public/{$download_url}"); send_file(e_FILE."public/{$download_url}");
exit(); exit();
} }
@@ -205,17 +238,12 @@ if ($type == "file")
)) ))
{ {
header("Location: ".e_BASE."download.php?error.{$id}.1"); header("Location: ".e_BASE."download.php?error.{$id}.1");
exit; exit();
/* require_once(HEADERF);
$denied_message = ($pref['download_denied'] && !strpos($pref['download_denied'],"signup.php")) ? $tp->toHTML($pref['download_denied'],"","defs") : LAN_dl_63;
$ns -> tablerender(LAN_dl_61, $denied_message);
require_once(FOOTERF);
exit(); */
} }
else else
{ {
header("Location: ".trim($pref['download_denied'])); header("Location: ".trim($pref['download_denied']));
exit; exit();
} }
} }
} }
@@ -247,7 +275,8 @@ $sql->db_Select($table, "*", "{$table}_id = '{$id}'");
$row = $sql->db_Fetch(); $row = $sql->db_Fetch();
extract($row); extract($row);
$image = ($table == "upload" ? $upload_ss : $download_image); $image = ($table == "upload" ? $upload_ss : $download_image);
if (preg_match("/Binary\s(.*?)\/.*/", $image, $result)) { if (preg_match("/Binary\s(.*?)\/.*/", $image, $result))
{
$bid = $result[1]; $bid = $result[1];
$result = @mysql_query("SELECT * FROM ".MPREFIX."rbinary WHERE binary_id = '{$bid}'"); $result = @mysql_query("SELECT * FROM ".MPREFIX."rbinary WHERE binary_id = '{$bid}'");
$binary_data = @mysql_result($result, 0, "binary_data"); $binary_data = @mysql_result($result, 0, "binary_data");
@@ -259,32 +288,47 @@ if (preg_match("/Binary\s(.*?)\/.*/", $image, $result)) {
exit(); exit();
} }
$image = ($table == "upload" ? $upload_ss : $download_image); $image = ($table == "upload" ? $upload_ss : $download_image);
if (strpos($image, "http") !== FALSE) { if (strpos($image, "http") !== FALSE)
{
header("Location: {$image}"); header("Location: {$image}");
exit(); exit();
} else { }
if ($table == "download") { else
{
if ($table == "download")
{
require_once(HEADERF); require_once(HEADERF);
if (file_exists(e_FILE."download/{$image}")) { if (file_exists(e_FILE."download/{$image}"))
{
$disp = "<div style='text-align:center'><img src='".e_FILE."download/{$image}' alt='' /></div>"; $disp = "<div style='text-align:center'><img src='".e_FILE."download/{$image}' alt='' /></div>";
} }
else if(file_exists(e_FILE."downloadimages/{$image}")) { else if(file_exists(e_FILE."downloadimages/{$image}"))
{
$disp = "<div style='text-align:center'><img src='".e_FILE."downloadimages/{$image}' alt='' /></div>"; $disp = "<div style='text-align:center'><img src='".e_FILE."downloadimages/{$image}' alt='' /></div>";
} else { }
else
{
$disp = "<div style='text-align:center'><img src='".e_FILE."public/{$image}' alt='' /></div>"; $disp = "<div style='text-align:center'><img src='".e_FILE."public/{$image}' alt='' /></div>";
} }
$disp .= "<br /><div style='text-align:center'><a href='javascript:history.back(1)'>".LAN_dl_64."</a></div>"; $disp .= "<br /><div style='text-align:center'><a href='javascript:history.back(1)'>".LAN_dl_64."</a></div>";
$ns->tablerender($image, $disp); $ns->tablerender($image, $disp);
require_once(FOOTERF); require_once(FOOTERF);
} else { } else
if (is_file(e_FILE."public/{$image}")) { {
if (is_file(e_FILE."public/{$image}"))
{
echo "<img src='".e_FILE."public/{$image}' alt='' />"; echo "<img src='".e_FILE."public/{$image}' alt='' />";
} elseif(is_file(e_FILE."downloadimages/{$image}")) { }
elseif(is_file(e_FILE."downloadimages/{$image}"))
{
echo "<img src='".e_FILE."downloadimages/{$image}' alt='' />"; echo "<img src='".e_FILE."downloadimages/{$image}' alt='' />";
} else { }
else
{
require_once(HEADERF); require_once(HEADERF);
$ns -> tablerender(LAN_dl_61, "<div style='text-align:center'>".LAN_dl_65."<br /><br /><a href='javascript:history.back(1)'>".LAN_dl_64."</a></div>"); $ns -> tablerender(LAN_dl_61, "<div style='text-align:center'>".LAN_dl_65."<br /><br /><a href='javascript:history.back(1)'>".LAN_dl_64."</a></div>");
require_once(FOOTERF); require_once(FOOTERF);
@@ -294,8 +338,11 @@ if (strpos($image, "http") !== FALSE) {
} }
} }
// File retrieval function. by Cam. // File retrieval function. by Cam.
function send_file($file) { function send_file($file)
{
global $pref, $DOWNLOADS_DIRECTORY,$FILES_DIRECTORY, $e107; global $pref, $DOWNLOADS_DIRECTORY,$FILES_DIRECTORY, $e107;
if (!$pref['download_php']) if (!$pref['download_php'])
{ {
@@ -310,17 +357,24 @@ function send_file($file) {
$path = realpath($filename); $path = realpath($filename);
$path_downloads = realpath($DOWNLOADS_DIRECTORY); $path_downloads = realpath($DOWNLOADS_DIRECTORY);
$path_public = realpath($FILES_DIRECTORY."public/"); $path_public = realpath($FILES_DIRECTORY."public/");
if(!strstr($path, $path_downloads) && !strstr($path,$path_public)) { if(!strstr($path, $path_downloads) && !strstr($path,$path_public))
if(E107_DEBUG_LEVEL > 0 && ADMIN){ {
if(E107_DEBUG_LEVEL > 0 && ADMIN)
{
echo "Failed to Download <b>".$file."</b><br />"; echo "Failed to Download <b>".$file."</b><br />";
echo "The file-path <b>".$path."<b> didn't match with either <b>{$path_downloads}</b> or <b>{$path_public}</b><br />"; echo "The file-path <b>".$path."<b> didn't match with either <b>{$path_downloads}</b> or <b>{$path_public}</b><br />";
exit(); exit();
}else{ }
else
{
header("location: {$e107->base_path}"); header("location: {$e107->base_path}");
exit(); exit();
} }
} else { }
if (is_file($filename) && is_readable($filename) && connection_status() == 0) { else
{
if (is_file($filename) && is_readable($filename) && connection_status() == 0)
{
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
{ {
$file = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1); $file = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1);
@@ -359,19 +413,25 @@ function send_file($file) {
$data_len -= $bufsize; $data_len -= $bufsize;
} }
fclose($res); fclose($res);
} else { }
else
if(E107_DEBUG_LEVEL > 0 && ADMIN){ {
if(E107_DEBUG_LEVEL > 0 && ADMIN)
{
echo "file failed =".$file."<br />"; echo "file failed =".$file."<br />";
echo "path =".$path."<br />"; echo "path =".$path."<br />";
exit(); exit();
}else{ }
else
{
header("location: ".e_BASE."index.php"); header("location: ".e_BASE."index.php");
exit(); exit();
} }
} }
} }
} }
function check_download_limits() function check_download_limits()
{ {
global $pref, $sql, $ns, $HEADER, $e107, $tp; global $pref, $sql, $ns, $HEADER, $e107, $tp;