diff --git a/e107_plugins/download/download.php b/e107_plugins/download/download.php index c52c749ef..ba92cad1e 100644 --- a/e107_plugins/download/download.php +++ b/e107_plugins/download/download.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/download/download.php,v $ -| $Revision: 1.5 $ -| $Date: 2009-02-11 21:41:54 $ +| $Revision: 1.6 $ +| $Date: 2009-05-03 21:16:15 $ | $Author: bugrain $ | +----------------------------------------------------------------------------+ @@ -78,6 +78,7 @@ else $id = intval($tmp[1]); $errnum = intval(varset($tmp[2],0)); } + switch ($action) { case 'list' : // Category-based listing @@ -122,11 +123,15 @@ else require_once(HEADERF); switch ($errnum) { - case 1 : - $errmsg = LAN_dl_63; // No permissions + case 1 : // No permissions + if (strlen($pref['download_denied']) > 0) { + $errmsg = $tp->toHTML($pref['download_denied'],true); + } else { + $errmsg = LAN_dl_63; + } break; - case 2 : - $errmsg = LAN_dl_62; // Quota exceeded + case 2 : // Quota exceeded + $errmsg = LAN_dl_62; break; default: $errmsg = LAN_dl_61." ".$errnum; // Generic error - shouldn't happen diff --git a/e107_plugins/download/download_admin.php b/e107_plugins/download/download_admin.php index 80170e558..301f0866d 100644 --- a/e107_plugins/download/download_admin.php +++ b/e107_plugins/download/download_admin.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/download/download_admin.php,v $ -| $Revision: 1.8 $ -| $Date: 2009-02-11 22:50:43 $ +| $Revision: 1.9 $ +| $Date: 2009-05-03 21:16:15 $ | $Author: bugrain $ +----------------------------------------------------------------------------+ */ @@ -29,13 +29,16 @@ if (!getperms("P") || !plugInstalled('download')) include_lan(e_PLUGIN.'download/languages/'.e_LANGUAGE.'/lan_download.php'); include_lan(e_PLUGIN.'download/languages/'.e_LANGUAGE.'/lan_download_admin.php'); -require_once(e_PLUGIN.'download/handlers/download_class.php'); -require_once(e_HANDLER."calendar/calendar_class.php"); +require_once(e_PLUGIN.'download/handlers/adminDownload_class.php'); +require_once(e_HANDLER."form_handler.php"); require_once(e_HANDLER."ren_help.php"); +require_once(e_HANDLER."calendar/calendar_class.php"); $cal = new DHTML_Calendar(true); +$gen = new convert(); + function headerjs() { - global $cal; + global $cal; return $cal->load_files(); } @@ -80,7 +83,7 @@ if (e_QUERY) } -if(isset($_POST['delete'])) +if (isset($_POST['delete'])) { $tmp = array_keys($_POST['delete']); list($delete, $del_id) = explode("_", $tmp[0]); @@ -91,7 +94,7 @@ if(isset($_POST['delete'])) $from = ($from ? $from : 0); $amount = 50; -if(isset($_POST)) +if (isset($_POST)) { $e107cache->clear("download_cat"); } @@ -110,7 +113,7 @@ if (isset($_POST['submit_download'])) } -if(isset($_POST['update_catorder'])) +if (isset($_POST['update_catorder'])) { foreach($_POST['catorder'] as $key=>$order) { @@ -153,9 +156,9 @@ if (isset($_POST['updateoptions'])) $targetFields = array('gen_datestamp', 'gen_user_id', 'gen_ip', 'gen_intdata', 'gen_chardata'); // Fields for download limits -if(isset($_POST['addlimit'])) +if (isset($_POST['addlimit'])) { - if($sql->db_Select('generic','gen_id',"gen_type = 'download_limit' AND gen_datestamp = {$_POST['newlimit_class']}")) + if ($sql->db_Select('generic','gen_id',"gen_type = 'download_limit' AND gen_datestamp = {$_POST['newlimit_class']}")) { $message = DOWLAN_116; } @@ -168,7 +171,7 @@ if(isset($_POST['addlimit'])) $vals[$targetFields[$k]] = intval($_POST[$lName]); } $valString = implode(',',$vals); - if($sql->db_Insert('generic',$vals)) + if ($sql->db_Insert('generic',$vals)) { $message = DOWLAN_117; $admin_log->log_event('DOWNL_09',$valString,E_LOG_INFORMATIVE,''); @@ -182,29 +185,29 @@ if(isset($_POST['addlimit'])) } -if(isset($_POST['updatelimits'])) +if (isset($_POST['updatelimits'])) { - if($pref['download_limits'] != $_POST['download_limits']) + if ($pref['download_limits'] != $_POST['download_limits']) { $pref['download_limits'] = ($_POST['download_limits'] == 'on') ? 1 : 0; save_prefs(); - $message .= DOWLAN_126."
"; + $message .= DOWLAN_126."
"; } foreach(array_keys($_POST['count_num']) as $idLim) { $idLim = intval($idLim); - if(!$_POST['count_num'][$idLim] && !$_POST['count_days'][$idLim] && !$_POST['bw_num'][$idLim] && !$_POST['bw_days'][$idLim]) + if (!$_POST['count_num'][$idLim] && !$_POST['count_days'][$idLim] && !$_POST['bw_num'][$idLim] && !$_POST['bw_days'][$idLim]) { //All entries empty - Remove record - if($sql->db_Delete('generic',"gen_id = {$idLim}")) + if ($sql->db_Delete('generic',"gen_id = {$idLim}")) { - $message .= $idLim." - ".DOWLAN_119."
"; + $message .= $idLim." - ".DOWLAN_119."
"; $admin_log->log_event('DOWNL_11','ID: '.$idLim,E_LOG_INFORMATIVE,''); } else { - $message .= $idLim." - ".DOWLAN_120."
"; + $message .= $idLim." - ".DOWLAN_120."
"; } } else @@ -217,22 +220,22 @@ if(isset($_POST['updatelimits'])) $valString = implode(',',$vals); $sql->db_UpdateArray('generic',$vals," WHERE gen_id = {$idLim}"); $admin_log->log_event('DOWNL_10',$idLim.', '.$valString,E_LOG_INFORMATIVE,''); - $message .= $idLim." - ".DOWLAN_121."
"; + $message .= $idLim." - ".DOWLAN_121."
"; unset($vals); } } } -if(isset($_POST['submit_mirror'])) +if (isset($_POST['submit_mirror'])) { $adminDownload->submit_mirror($subAction, $id); } -if($action == "mirror") +if ($action == "mirror") { - $download -> show_existing_mirrors(); + $adminDownload->show_existing_mirrors(); } @@ -268,9 +271,18 @@ if ($action == 'cat') if ($delete == 'main') { - $result = admin_update($sql->db_Delete('download', 'download_id='.$del_id), 'delete', DOWLAN_27." #".$del_id." ".DOWLAN_36); - if($result) + $result = $sql->db_Delete('download', 'download_id='.$del_id); + if ($result) { + // Process triggers before calling admin_update so trigger messages can be shown + $data = array('method'=>'delete', 'table'=>'download', 'id'=>$del_id, 'plugin'=>'download', 'function'=>'delete_download'); + $hooks = $e107->e_event->triggerHook($data); + require_once(e_HANDLER."message_handler.php"); + $emessage = &eMessage::getInstance(); + $emessage->add($hooks, E_MESSAGE_SUCCESS); + + admin_update($result, 'delete', DOWLAN_27." #".$del_id." ".DOWLAN_36); + $admin_log->log_event('DOWNL_07',$del_id,E_LOG_INFORMATIVE,''); admin_purge_related('download', $del_id); $e_event->trigger('dldelete', $del_id); @@ -278,7 +290,6 @@ if ($delete == 'main') unset($subAction, $id); } - if (isset($message)) { $ns->tablerender("", "
".$message."
"); @@ -293,8 +304,9 @@ if ($from === "maint" && isset($_POST['submit_download'])) if (!e_QUERY || $action == "main") { - $adminDownload->show_filter_form($action, $subAction, $id, $from, $amount); - $adminDownload->show_existing_items($action, $subAction, $id, $from, $amount); + $text = $adminDownload->show_filter_form($action, $subAction, $id, $from, $amount); + $text .= $adminDownload->show_existing_items($action, $subAction, $id, $from, $amount); + $ns->tablerender(DOWLAN_7, $text); } @@ -309,8 +321,8 @@ if ($action == "opt")
\n - - + + @@ -318,19 +330,19 @@ if ($action == "opt") $c = $pref['download_php'] ? " checked = 'checked' " : ""; $ssc = ((!isset($pref['download_subsub'])) || ($pref['download_subsub'] == '1')) ? " checked = 'checked' " : ""; $sacc = (varset($pref['download_incinfo'],0) == '1') ? " checked = 'checked' " : ""; - $text .= "".DOWLAN_70." + $text .= "".DOWLAN_70." + + @@ -394,12 +406,12 @@ if ($action == "opt") - + - + @@ -408,7 +420,10 @@ if ($action == "opt") ".DOWLAN_101." @@ -416,13 +431,16 @@ if ($action == "opt") ".DOWLAN_146." @@ -440,16 +458,11 @@ if ($action == 'maint') case 'duplicates': { $title = DOWLAN_166; - //$query = 'SELECT count(download_url), download_id, download_url FROM #download where download_url <> "" group by download_url'; - $query = ' - SELECT count(d1.download_url) AS c, d1.download_id AS d1id, d2.download_id AS d2id, d1.*, dc.download_category_name - FROM `#download` AS d1 - JOIN `#download` AS d2 ON d1.download_url=d2.download_url - LEFT JOIN `#download_category` AS dc ON dc.download_category_id=d1.download_category - WHERE d1.download_url <> "" - AND d1.download_url = d2.download_url - AND d1.download_iddb_Select_gen($query); @@ -469,36 +482,25 @@ if ($action == 'maint') $text .= ''; $foundSome = true; } - $text .= ''; - if ($currentURL != $row['download_url']) { - $text .= ''; - $currentURL = $row['download_url']; - } else { - $text .= ''; - } - $text .= ''; - $text .= "'; - $text .= ''; - $text .= ''; - $text .= ''; $query = "SELECT d.*, dc.* FROM `#download` AS d LEFT JOIN `#download_category` AS dc ON dc.download_category_id=d.download_category - WHERE download_url='".$row['download_url']."' - AND download_id<>".$row['download_id']." + WHERE download_id IN (".$row['gc'].") ORDER BY download_id ASC"; $count = $sql2->db_Select_gen($query); while($row = $sql2->db_Fetch()) { $text .= ''; - $text .= ''; + if ($currentURL != $row['download_url']) { + $text .= ''; + $currentURL = $row['download_url']; + } else { + $text .= ''; + } $text .= ''; $text .= "'; $text .= ''; $text .= ''; $text .= ''; } @@ -528,15 +530,21 @@ if ($action == 'maint') $text .= '
".DOWLAN_69."
".DOWLAN_158." -
".DOWLAN_159." -
".DOWLAN_150."". ($pref['download_email'] ? "" : "")."". ($pref['download_email'] ? "" : "")."
".DOWLAN_100."". ($agree_flag ? "" : "")."". ($agree_flag ? "" : "")."
- + "; + $eform = new e_form(); + $text .= $eform->bbarea('agree_text',$agree_text); + $text .= "
- + "; + $eform = new e_form(); + $text .= $eform->bbarea('download_denied',$pref['download_denied']); + $text .= "
- +
'.$row['download_url'].'*'.$row['download_id'].'".$row['download_name'].''.$row['download_category_name'].' - '.ADMIN_EDIT_ICON.' - toJS(DOWLAN_33.' [ID: '.$row["download_id"].' ]').'") \' /> -
*'.$row['download_url'].'*'.$row['download_id'].'".$row['download_name'].''.$row['download_category_name'].' '.ADMIN_EDIT_ICON.' - toJS(DOWLAN_33.' [ID: '.$row["download_id"].' ]').'") \' /> + toJS(DOWLAN_33.' [ID: '.$row["download_id"].' ]').'") \'/>
'; $text .= ''; $text .= ''; -//TODO $text .= ''; + $text .= ''; + $text .= ''; + $text .= ''; $text .= ''; $foundSome = true; } + $filesize = (is_readable(e_DOWNLOAD.$row['download_url']) ? $e107->parseMemorySize(filesize(e_DOWNLOAD.$file['fname'])) : DOWLAN_181); + $filets = (is_readable(e_DOWNLOAD.$row['download_url']) ? $gen->convert_date(filectime(e_DOWNLOAD.$file['fname']), "long") : DOWLAN_181); $text .= ''; $text .= ''; + $text .= ''; + $text .= ''; //TODO $text .= ''; //TODO $text .= ''; } @@ -579,7 +587,7 @@ if ($action == 'maint') $text .= ''; $text .= ''; $text .= ''; } @@ -631,7 +639,7 @@ if ($action == 'maint') } $text .= ''; $text .= ''; } @@ -680,7 +688,7 @@ if ($action == 'maint') } $text .= ''; $text .= ''; } @@ -729,7 +737,7 @@ if ($action == 'maint') $text .= ''; $text .= ''; $text .= ''; } @@ -761,13 +769,13 @@ if ($action == 'maint') } -if($action == 'limits') +if ($action == 'limits') { - if($sql->db_Select('userclass_classes','userclass_id, userclass_name')) + if ($sql->db_Select('userclass_classes','userclass_id, userclass_name')) { $classList = $sql->db_getList(); } - if($sql->db_Select("generic", "gen_id as limit_id, gen_datestamp as limit_classnum, gen_user_id as limit_bw_num, gen_ip as limit_bw_days, gen_intdata as limit_count_num, gen_chardata as limit_count_days", "gen_type = 'download_limit'")) + if ($sql->db_Select("generic", "gen_id as limit_id, gen_datestamp as limit_classnum, gen_user_id as limit_bw_num, gen_ip as limit_bw_days, gen_intdata as limit_count_num, gen_chardata as limit_count_days", "gen_type = 'download_limit'")) { while($row = $sql->db_Fetch()) { @@ -780,7 +788,7 @@ if($action == 'limits') @@ -808,12 +816,12 @@ if($action == 'limits') "; @@ -822,26 +830,26 @@ if($action == 'limits') $txt .= " - + "; @@ -856,1422 +864,51 @@ if($action == 'limits') require_once(e_ADMIN."footer.php"); exit; - - - -class adminDownload -{ - function show_filter_form($action, $subAction, $id, $from, $amount) - { - global $download, $ns; - $text .= $download->getCategorySelectList($download_category); - $ns->tablerender(DOWLAN_FILTER, $text); - } - function show_existing_items($action, $subAction, $id, $from, $amount) - { - global $sql, $rs, $ns, $tp, $mySQLdefaultdb, $pref; - $text = "
"; - $sortorder = ($pref['download_order']) ? $pref['download_order'] : "download_datestamp"; - $sortdirection = ($pref['download_sort']) ? strtolower($pref['download_sort']) : "desc"; - if ($sortdirection != 'desc') $sortdirection = 'asc'; - if(isset($_POST['searchdisp'])) - { - $pref['admin_download_disp'] = implode("|",$_POST['searchdisp']); - save_prefs(); - } - - if(!$pref['admin_download_disp']) - { - $search_display = array("download_name","download_class"); - } - else - { - $search_display = explode("|",$pref['admin_download_disp']); - } - - $query = "SELECT d.*, dc.* FROM `#download` AS d LEFT JOIN `#download_category` AS dc ON dc. download_category_id = d.download_category"; - - if (isset($_POST['searchquery']) && $_POST['searchquery'] != "") - { - $query .= " WHERE download_url REGEXP('".$_POST['searchquery']."') OR download_author REGEXP('".$_POST['searchquery']."') OR download_description REGEXP('".$_POST['searchquery']."') "; - foreach($search_display as $disp) - { - $query .= " OR $disp REGEXP('".$_POST['searchquery']."') "; - } - $query .= " ORDER BY {$sortorder} {$sortdirection}"; - } - else - { - $query .= " ORDER BY ".($subAction ? $subAction : $sortorder)." ".($id ? $id : $sortdirection)." LIMIT $from, $amount"; - } - - if ($dl_count = $sql->db_Select_gen($query)) - { - $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform")." -
'.DOWLAN_13.''.LAN_OPTIONS.''.DOWLAN_182.''.DOWLAN_170.''.LAN_OPTIONS.'
'.$file['fname'].''.$filets.''.$filesize.' //TODO '.E_16_CREATE.' -//TODO toJS(DOWLAN_173.' [ '.$file["fname"].' ]').'") \' /> +//TODO toJS(DOWLAN_173.' [ '.$file["fname"].' ]').'") \'/> //TODO
'.$row['download_url'].' '.ADMIN_EDIT_ICON.' - toJS(DOWLAN_33.' [ID: '.$row["download_id"].' ]').'") \' /> + toJS(DOWLAN_33.' [ID: '.$row["download_id"].' ]').'") \'/>
'.ADMIN_EDIT_ICON.' - toJS(DOWLAN_33.' [ID: '.$row["download_id"].' ]').'") \' /> + toJS(DOWLAN_33.' [ID: '.$row["download_id"].' ]').'") \'/>
'.ADMIN_EDIT_ICON.' - toJS(DOWLAN_33.' [ID: '.$row["download_id"].' ]').'") \' /> + toJS(DOWLAN_33.' [ID: '.$row["download_id"].' ]').'") \'/>
'.ADMIN_EDIT_ICON.' - toJS(DOWLAN_33.' [ID: '.$row["download_id"].' ]').'") \' /> + toJS(DOWLAN_33.' [ID: '.$row["download_id"].' ]').'") \'/>
"; - if($pref['download_limits'] == 1) + if ($pref['download_limits'] == 1) { $chk = "checked = 'checked'"; } @@ -790,7 +798,7 @@ if($action == 'limits') } $txt .= " - ".DOWLAN_125." + ".DOWLAN_125."
".$row['limit_id']." ".r_userclass_name($row['limit_classnum'])." - ".DOWLAN_109." - ".DOWLAN_110." + ".DOWLAN_109." + ".DOWLAN_110." - ".DOWLAN_111." ".DOWLAN_109." - ".DOWLAN_110." + ".DOWLAN_111." ".DOWLAN_109." + ".DOWLAN_110."
- +




".r_userclass("newlimit_class", 0, "off", "guest, member, admin, classes, language")." - ".DOWLAN_109." - ".DOWLAN_110." + ".DOWLAN_109." + ".DOWLAN_110." - ".DOWLAN_111." ".DOWLAN_109." - ".DOWLAN_110." + ".DOWLAN_111." ".DOWLAN_109." + ".DOWLAN_110."
- +
- - - "; - - // Search Display Column header.---------- - foreach($search_display as $disp) - { - if($disp == "download_name") - { // Toggle direction - $text .= ""; - } - else - { - $repl = array("download_","_"); - $text .= ""; - } - } - - - $text .=""; - - while ($row = $sql->db_Fetch()) - { - $text .= ""; - - // Display Chosen options - foreach($search_display as $disp) - { - $text .= ""; - } - - - $text .= " - - "; - } - $text .= "
ID".DOWLAN_27."".ucwords(str_replace($repl," ",$disp))."".LAN_OPTIONS."
".$row['download_id'].""; - switch ($disp) - { - case "download_name" : - $text .= "".$row['download_name'].""; - break; - case "download_category" : - $text .= $row['download_category_name']." "; - break; - case "download_datestamp" : - $text .= ($row[$disp]) ? strftime($pref['shortdate'],$row[$disp])." " : " "; - break; - case "download_class" : - case "download_visible" : - $text .= r_userclass_name($row[$disp])." "; - break; - case "download_filesize" : - $text .= ($row[$disp]) ? round(($row[$disp] / 1000))." Kb " : " "; - break; - case "download_thumb" : - $text .= ($row[$disp]) ? "" : ""; - break; - case "download_image" : - $text .= "".$row[$disp]." "; - break; - case "download_description" : - $text .= $tp->toHTML($row[$disp],TRUE)." "; - break; - case "download_active" : - if($row[$disp]== 1) - { - $text .= "\n"; - } - elseif($row[$disp]== 2) - { - $text .= "\n"; - } - else - { - $text .= "\n"; - } - break; - case "download_comment" : - $text .= ($row[$disp]) ? ADMIN_TRUE_ICON : " "; - break; - default : - $text .= $row[$disp]." "; - } - $text .= " - ".ADMIN_EDIT_ICON." - toJS(DOWLAN_33." [ID: ".$row['download_id']." ]")."') \" /> -
"; - } - else - { // 'No downloads yet' - $text .= "
".DOWLAN_6."
"; - } - $text .= ""; - - // Next-Previous. - $downloads = $sql->db_Count("download"); - if ($downloads > $amount && !$_POST['searchquery']) - { - $parms = "{$downloads},{$amount},{$from},".e_SELF."?".(e_QUERY ? "$action.$subAction.$id." : "main.{$sortorder}.{$sortdirection}.")."[FROM]"; - $text .= "
".$tp->parseTemplate("{NEXTPREV={$parms}}"); - } - - - // Search & display options etc. - $text .= "
\n

\n\n\n

"; - - $text .= "
".LAN_DISPLAYOPT."
"; - $text .= " -
\n - "; - $ns->tablerender(DOWLAN_7, $text); - } - - function show_options($action) { - if ($action == "") { - $action = "main"; - } - $var['main']['text'] = DOWLAN_29; - $var['main']['link'] = e_SELF; - $var['create']['text'] = DOWLAN_30; - $var['create']['link'] = e_SELF."?create"; - $var['cat']['text'] = DOWLAN_31; - $var['cat']['link'] = e_SELF."?cat"; - $var['cat']['perm'] = "Q"; - $var['opt']['text'] = LAN_OPTIONS; - $var['opt']['link'] = e_SELF."?opt"; - $var['maint']['text'] = DOWLAN_165; - $var['maint']['link'] = e_SELF."?maint"; - $var['limits']['text'] = DOWLAN_112; - $var['limits']['link'] = e_SELF."?limits"; - $var['mirror']['text'] = DOWLAN_128; - $var['mirror']['link'] = e_SELF."?mirror"; - show_admin_menu(DOWLAN_32, $action, $var); - - } - - function show_maint_options($action,$subAction) { - if ($action != "maint") { - return; - } - $var['duplicates']['text'] = DOWLAN_166; - $var['duplicates']['link'] = e_SELF."?maint.duplicates"; - $var['orphans']['text'] = DOWLAN_167; - $var['orphans']['link'] = e_SELF."?maint.orphans"; - $var['missing']['text'] = DOWLAN_168; - $var['missing']['link'] = e_SELF."?maint.missing"; - $var['inactive']['text'] = DOWLAN_169; - $var['inactive']['link'] = e_SELF."?maint.inactive"; - $var['nocategory']['text'] = DOWLAN_178; - $var['nocategory']['link'] = e_SELF."?maint.nocategory"; - $var['filesize']['text'] = DOWLAN_170; - $var['filesize']['link'] = e_SELF."?maint.filesize"; - $var['log']['text'] = DOWLAN_171; - $var['log']['link'] = e_SELF."?maint.log"; - show_admin_menu(DOWLAN_177, $subAction, $var); - } - -// --------------------------------------------------------------------------- - - - // Given the string which is stored in the DB, turns it into an array of mirror entries - // If $byID is true, the array index is the mirror ID. Otherwise its a simple array - function makeMirrorArray($source, $byID = FALSE) - { - $ret = array(); - if($source) - { - $mirrorTArray = explode(chr(1), $source); - - $count = 0; - foreach($mirrorTArray as $mirror) - { - if ($mirror) - { - list($mid, $murl, $mreq, $msize) = explode(",", $mirror); - $ret[$byID ? $mid : $count] = array('id' => $mid, 'url' => $murl, 'requests' => $mreq, 'filesize' => $msize); - $count++; - } - } - } - return $ret; - } - - - // Turn the array into a string which can be stored in the DB - function compressMirrorArray($source) - { - if (!is_array($source) || !count($source)) return ''; - $inter = array(); - foreach ($source as $s) - { - $inter[] = $s['id'].','.$s['url'].','.$s['requests'].','.$s['filesize']; - } - return implode(chr(1),$inter); - } - - - - function create_download($subAction, $id) - { - global $download, $cal, $tp, $sql, $fl, $rs, $ns, $file_array, $image_array, $thumb_array, $pst; - require_once(e_PLUGIN.'download/download_shortcodes.php'); - require_once(e_HANDLER."form_handler.php"); - - if($file_array = $fl->get_files(e_DOWNLOAD, "","standard",5)) - { - sort($file_array); - } - if($public_array = $fl->get_files(e_FILE."public/")) - { - foreach($public_array as $key=>$val) - { - $file_array[] = str_replace(e_FILE."public/","",$val); - } - } - if ($sql->db_Select("rbinary")) - { - while ($row = $sql->db_Fetch()) - { - extract($row); - $file_array[] = "Binary ".$binary_id."/".$binary_name; - } - } - if($image_array = $fl->get_files(e_FILE.'downloadimages/', '\.gif$|\.jpg$|\.png$|\.GIF$|\.JPG$|\.PNG$','standard',2)) - { - sort($image_array); - } - if($thumb_array = $fl->get_files(e_FILE.'downloadthumbs/', '\.gif$|\.jpg$|\.png$|\.GIF$|\.JPG$|\.PNG$','standard',2)) - { - sort($thumb_array); - } - - $eform = new e_form(); - $mirrorArray = array(); - - $download_status[0] = DOWLAN_122; - $download_status[1] = DOWLAN_123; - $download_status[2] = DOWLAN_124; - $preset = $pst->read_preset("admin_downloads"); // read preset values into array - extract($preset); - - if (!$sql->db_Select("download_category")) - { - $ns->tablerender(ADLAN_24, "
".DOWLAN_5."
"); - return; - } - $download_active = 1; - if ($subAction == "edit" && !$_POST['submit']) - { - if ($sql->db_Select("download", "*", "download_id=".$id)) - { - $row = $sql->db_Fetch(); - extract($row); - - $mirrorArray = $this->makeMirrorArray($row['download_mirror']); - } - } - - if ($subAction == "dlm" && !$_POST['submit']) - { - require_once(e_PLUGIN.'download/download_shortcodes.php'); - if ($sql->db_Select("upload", "*", "upload_id=".$id)) - { - $row = $sql->db_Fetch(); - - $download_category = $row['upload_category']; - $download_name = $row['upload_name'].($row['upload_version'] ? " v" . $row['upload_version'] : ""); - $download_url = $row['upload_file']; - $download_author_email = $row['upload_email']; - $download_author_website = $row['upload_website']; - $download_description = $row['upload_description']; - $download_image = $row['upload_ss']; - $download_filesize = $row['upload_filesize']; - $image_array[] = array("path" => "", "fname" => $row['upload_ss']); - $download_author = substr($row['upload_poster'], (strpos($row['upload_poster'], ".")+1)); - } - } - - - $text = " -
- -
-
-
- - - - - -
".DOWLAN_13." -
".DOWLAN_131."   - -
-
-
-
- - - - - - - - - -
".DOWLAN_149." - -
".DOWLAN_66." - -
-
-
- - - - "; - } - else - { - $text .= DOWLAN_132."
"; - $mirrorList = $sql -> db_getList(); // Get the list of possible mirrors - $m_count = (count($mirrorArray) ? count($mirrorArray) : 1); // Count of mirrors actually in use (or count of 1 if none defined yet) - for($count = 1; $count <= $m_count; $count++) - { - $opt = ($count==1) ? "id='mirror'" : ""; - $text .=" -
- - - "; - if (DOWNLOAD_DEBUG) - { - if ($id) - { - $text .= '('.$mirrorArray[($count-1)]['requests'].')'; - } - else - { - $text .= ""; - } - } - $text .= "
"; - } - $text .="
- - - - - - - "; - } // End of mirror-related stuff - - $download_author = $subAction != "edit" && $download_author == "" ? USERNAME : $download_author;//TODO what if editing an no author specified - $download_author_email = $subAction != "edit" && $download_author_email == "" ? USEREMAIL : $download_author_email; - $text .= " -
".DOWLAN_128.""; - - // See if any mirrors to display - if(!$sql -> db_Select("download_mirror")) - { // No mirrors defined here - $text .= DOWLAN_144."
".DOWLAN_155." - ".DOWLAN_156."
- ".DOWLAN_157." -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "; - if ($subAction == "dlm") { - $text .= " - - - - - - - - "; - } - - $text .= " - - - -
".DOWLAN_11.""; - $text .= $download->getCategorySelectList($download_category); - $text .= "
".DOWLAN_12." - toForm($download_name)."\" maxlength='200' /> -
".DOWLAN_15." - -
".DOWLAN_16." - -
".DOWLAN_17." - -
".DOWLAN_18." - "; - $text .= $eform->bbarea('download_description',$download_description); - $text .= "
".DOWLAN_19." - "; - if($subAction == "dlm" && $download_image) - { - $text .= " - \n"; - } - $text .= "
".DOWLAN_20." - -
".LAN_DATESTAMP.""; - if(!$download_datestamp){ - $download_datestamp = time(); - } - $cal_options['showsTime'] = false; - $cal_options['showOthers'] = false; - $cal_options['weekNumbers'] = false; - $cal_options['ifFormat'] = "%d/%m/%Y %H:%M:%S"; - $cal_options['timeFormat'] = "24"; - $cal_attrib['class'] = "tbox"; - $cal_attrib['size'] = "22"; - $cal_attrib['name'] = "download_datestamp"; - $cal_attrib['value'] = date("d/m/Y H:i:s", $download_datestamp); - $text .= $cal->make_input_field($cal_options, $cal_attrib); - $update_checked = ($_POST['update_datestamp']) ? "checked='checked'" : ""; - $text .= "   ".DOWLAN_148." -
".DOWLAN_21." - -
".DOWLAN_102.""; - if ($download_comment == "0") { - $text .= LAN_YES.": - ".LAN_NO.": "; - } else { - $text .= LAN_YES.": - ".LAN_NO.": "; - } - $text .= "
".DOWLAN_145."".r_userclass('download_visible', $download_visible, 'off', 'public, nobody, member, admin, classes, language')."
".DOWLAN_106."".r_userclass('download_class', $download_class, 'off', 'public, nobody, member, admin, classes, language')."
".DOWLAN_153." - -
".DOWLAN_103." - - -
"; - if ($id && $subAction == "edit") { - $text .= " "; - } else { - $text .= ""; - } - - $text .= " -
-
-
-
-
"; - $ns->tablerender(ADLAN_24, $text); - } - - -// ----------------------------------------------------------------------------- - - function show_message($message) { - global $ns; - $ns->tablerender("", "
".$message."
"); - } - -// ----------------------------------------------------------------------------- - - - // Actually save a new or edited download to the DB - function submit_download($subAction, $id) - { - global $tp, $sql, $DOWNLOADS_DIRECTORY, $e_event; - - $dlInfo = array(); - $dlMirrors = array(); - - if($subAction == 'edit') - { - if($_POST['download_url_external'] == '') - { - $_POST['download_filesize_external'] = FALSE; - } - } - - if ($_POST['download_url_external'] && $_POST['download_url'] == '') - { - $dlInfo['download_url'] = $tp->toDB($_POST['download_url_external']); - $filesize = intval($_POST['download_filesize_external']); - } - else - { - $dlInfo['download_url'] = $tp->toDB($_POST['download_url']); - if($_POST['download_filesize_external']) - { - $filesize = intval($_POST['download_filesize_external']); - } - else - { - if (strpos($DOWNLOADS_DIRECTORY, "/") === 0 || strpos($DOWNLOADS_DIRECTORY, ":") >= 1) - { - $filesize = filesize($DOWNLOADS_DIRECTORY.$dlInfo['download_url']); - } - else - { - $filesize = filesize(e_BASE.$DOWNLOADS_DIRECTORY.$dlInfo['download_url']); - } - } - } - - if (!$filesize) - { - if($sql->db_Select("upload", "upload_filesize", "upload_file='{$dlInfo['download_url']}'")) - { - $row = $sql->db_Fetch(); - $filesize = $row['upload_filesize']; - } - } - $dlInfo['download_filesize'] = $filesize; - - - // ---- Move Images and Files ------------ - if($_POST['move_image']) - { - if($_POST['download_thumb']) - { - $oldname = e_FILE."public/".$_POST['download_thumb']; - $newname = e_FILE."downloadthumbs/".$_POST['download_thumb']; - if(!$this -> move_file($oldname,$newname)) - { - return; - } - } - if($_POST['download_image']) - { - $oldname = e_FILE."public/".$_POST['download_image']; - $newname = e_FILE."downloadimages/".$_POST['download_image']; - if(!$this -> move_file($oldname,$newname)) - { - return; - } - } - } - - if($_POST['move_file'] && $_POST['download_url']) - { - $oldname = e_FILE."public/".$_POST['download_url']; - $newname = $_POST['move_file'].$_POST['download_url']; - if(!$this -> move_file($oldname,$newname)) - { - return; - } - $dlInfo['download_url'] = str_replace(e_DOWNLOAD,"",$newname); - } - - - // ------------------------------------------ - - - $dlInfo['download_description'] = $tp->toDB($_POST['download_description']); - $dlInfo['download_name'] = $tp->toDB($_POST['download_name']); - $dlInfo['download_author'] = $tp->toDB($_POST['download_author']); - $dlInfo['download_author_email'] = $tp->toDB($_POST['download_author_email']); - $dlInfo['download_author_website'] = $tp->toDB($_POST['download_author_website']); - $dlInfo['download_category'] = intval($_POST['download_category']); - $dlInfo['download_active'] = intval($_POST['download_active']); - $dlInfo['download_thumb'] = $tp->toDB($_POST['download_thumb']); - $dlInfo['download_image'] = $tp->toDB($_POST['download_image']); - $dlInfo['download_comment'] = $tp->toDB($_POST['download_comment']); - $dlInfo['download_class'] = intval($_POST['download_class']); - $dlInfo['download_visible'] =intval($_POST['download_visible']); - - if (preg_match("#(.*?)/(.*?)/(.*?) (.*?):(.*?):(.*?)$#", $_POST['download_datestamp'], $matches)) - { - $dlInfo['download_datestamp'] = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]); - } - else - { - $dlInfo['download_datestamp'] = time(); - } - - if($_POST['update_datestamp']) - { - $dlInfo['download_datestamp'] = time(); - } - - $mirrorStr = ""; - $mirrorFlag = FALSE; - - // See if any mirrors defined - // Need to check all the possible mirror names - might have deleted the first one if we're in edit mode - foreach ($_POST['download_mirror_name'] as $mn) - { - if ($mn) - { - $mirrorFlag = TRUE; - break; - } - } - if($mirrorFlag) - { - $mirrors = count($_POST['download_mirror_name']); - $mirrorArray = array(); - $newMirrorArray = array(); - if ($id && $sql->db_Select('download','download_mirror', 'download_id = '.$id)) // Get existing download stats - { - if ($row = $sql->db_Fetch()) - { - $mirrorArray = $this->makeMirrorArray($row['download_mirror'], TRUE); - } - } - for($a=0; $a<$mirrors; $a++) - { - $mid = trim($_POST['download_mirror_name'][$a]); - $murl = trim($_POST['download_mirror'][$a]); - $msize = trim($_POST['download_mirror_size'][$a]); - if ($mid && $murl) - { - $newMirrorArray[$mid] = array('id' => $mid, 'url' => $murl, 'requests' => 0, 'filesize' => $msize); - if (DOWNLOAD_DEBUG && !$id) - { - $newMirrorArray[$mid]['requests'] = intval($_POST['download_mirror_requests'][$a]); - } - } - } - // Now copy across any existing usage figures - foreach ($newMirrorArray as $k => $m) - { - if (isset($mirrorArray[$k])) - { - $newMirrorArray[$k]['requests'] = $mirrorArray[$k]['requests']; - } - } - $mirrorStr = $this->compressMirrorArray($newMirrorArray); - } - - $dlMirrors['download_mirror']=$mirrorStr; - $dlMirrors['download_mirror_type']=intval($_POST['download_mirror_type']); - - if ($id) - { // Its an edit - admin_update($sql->db_UpdateArray('download',array_merge($dlInfo,$dlMirrors),'WHERE download_id='.intval($id)), 'update', DOWLAN_2." (".$_POST['download_name'].")"); - $dlInfo['download_id'] = $id; - $this->downloadLog('DOWNL_06',$dlInfo,$dlMirrors); - $dlInfo['download_datestamp'] = $time; // This is what 0.7 did, regardless of settings - unset($dlInfo['download_class']); // Also replicating 0.7 - $e_event->trigger('dlupdate', $dlInfo); - } - else - { - if (admin_update($download_id = $sql->db_Insert('download',array_merge($dlInfo,$dlMirrors)), 'insert', DOWLAN_1." (".$_POST['download_name'].")")) - { - $dlInfo['download_id'] = $download_id; - $this->downloadLog('DOWNL_05',$dlInfo,$dlMirrors); - $dlInfo['download_datestamp'] = $time; // This is what 0.7 did, regardless of settings - unset($dlInfo['download_class']); // Also replicating 0.7 - $e_event->trigger("dlpost", $dlInfo); - - if ($_POST['remove_upload']) - { - $sql->db_Update("upload", "upload_active='1' WHERE upload_id='".$_POST['remove_id']."'"); - $mes = "
".$_POST['download_name']." ".DOWLAN_104; - $mes .= "

".DOWLAN_105.""; - $this->show_message($mes); - } - } - } - } - - - function downloadLog($aText, &$dlInfo, &$mirrorInfo=NULL) - { - global $admin_log; - $logString = DOWLAN_9; - foreach ($dlInfo as $k => $v) - { - $logString .= '[!br!]'.$k.'=>'.$v; - } - if ($mirrorInfo != NULL) - { - foreach ($mirrorInfo as $k => $v) - { - $logString .= '[!br!]'.$k.'=>'.$v; - } - } - $admin_log->log_event($aText,$logString,E_LOG_INFORMATIVE,''); - } - -// ----------------------------------------------------------------------------- - - function show_categories($subAction, $id) - { - global $download, $sql, $sql2, $rs, $ns, $tp, $pst; - - require_once(e_HANDLER."form_handler.php"); - $eform = new e_form(); - - $text = $rs->form_open("post", e_SELF."?".e_QUERY, "myform"); - $text .= "
"; - - $qry = " - SELECT dc.*, COUNT(d.download_id) AS filecount FROM #download_category AS dc - LEFT JOIN #download AS d ON d.download_category = dc.download_category_id - GROUP BY dc.download_category_id - ORDER BY dc.download_category_order - "; - if($sql->db_Select_gen($qry)) - { - $categories = $sql->db_getList(); - foreach($categories as $cat) - { - $cat_array[$cat['download_category_parent']][] = $cat; - } - $text .= " - - - - - - - - - - - - - - "; - - - //Start displaying parent categories - foreach($cat_array[0] as $parent) - { - if(strstr($parent['download_category_icon'], chr(1))) - { - list($parent['download_category_icon'], $parent['download_category_icon_empty']) = explode(chr(1), $parent['download_category_icon']); - } - - $text .= " - - - - - - - "; - - //Show sub categories - if(is_array($cat_array[$parent['download_category_id']])) - { - foreach($cat_array[$parent['download_category_id']] as $subcat) - { - - if(strstr($subcat['download_category_icon'], chr(1))) - { - list($subcat['download_category_icon'], $subcat['download_category_icon_empty']) = explode(chr(1), $subcat['download_category_icon']); - } - $text .= " - - - - - - - "; - - //Show sub-sub categories - if(is_array($cat_array[$subcat['download_category_id']])) - { - foreach($cat_array[$subcat['download_category_id']] as $subsubcat) - { - - if(strstr($subsubcat['download_category_icon'], chr(1))) - { - list($subsubcat['download_category_icon'], $subsubcat['download_category_icon_empty']) = explode(chr(1), $subsubcat['download_category_icon']); - } - $text .= " - - - - - - "; - } - } - } - } - - } - - $text .= "
".DOWLAN_11."".DOWLAN_52."".LAN_ORDER."".LAN_OPTIONS."
".($parent['download_category_icon'] ? "" : " ")." - "; - $text .= $tp->toHTML($parent['download_category_name']); - $text .= "
- "; - $text .= $tp->toHTML($parent['download_category_description']); - $text .= " -
- - - - ".ADMIN_EDIT_ICON." - "; - if(!is_array($cat_array[$parent['download_category_id']])) - { - $text .= "toJS(DOWLAN_34." [ID: {$parent['download_category_id']} ]")."') \"/>"; - } - $text .= " -
".($subcat['download_category_icon'] ? "" : " ")." - "; - $text .= $tp->toHTML($subcat['download_category_name']); - $text .= " -
- "; - $text .= $tp->toHTML($subcat['download_category_description']); - $text .= " -
{$subcat['filecount']} - - - ".ADMIN_EDIT_ICON.""; - if(!is_array($cat_array[$subcat['download_category_id']]) && !$subcat['filecount']) - { - $text .= "toJS(DOWLAN_34." [ID: {$subcat['download_category_id']} ]")."') \"/>"; - } - $text .= " -
".($subsubcat['download_category_icon'] ? "" : " ")." -     "; - $text .= $tp->toHTML($subsubcat['download_category_name']); - $text .= " -
-     "; - $text .= $tp->toHTML($subsubcat['download_category_description']); - $text .= " -
{$subsubcat['filecount']} - - - ".ADMIN_EDIT_ICON." - "; - if(!$subsubcat['filecount']) - { - $text .= "toJS(DOWLAN_34." [ID: {$subsubcat['download_category_id']} ]")."') \"/>"; - } - $text .= " -
"; - $text .= "
- -
"; - } - else - { - $text .= "
".DOWLAN_38."
"; - } - $text .= ""; - $ns->tablerender(DOWLAN_37, $text); - - unset($download_category_id, $download_category_name, $download_category_description, $download_category_parent, $download_category_icon, $download_category_class); - - $handle = opendir(e_IMAGE."icons"); - while ($file = readdir($handle)) { - if ($file != "." && $file != ".." && $file != "/" && $file != "CVS") { - $iconlist[] = $file; - } - } - closedir($handle); - - if ($subAction == "edit" && !$_POST['add_category']) { - if ($sql->db_Select("download_category", "*", "download_category_id=$id")) { - $row = $sql->db_Fetch(); - extract($row); - $main_category_parent = $download_category_parent; - if(strstr($download_category_icon, chr(1))) - { - list($download_category_icon, $download_category_icon_empty) = explode(chr(1), $download_category_icon); - } - else - { - $download_category_icon_empty = ""; - } - } - } - - $preset = $pst->read_preset("admin_dl_cat"); // read preset values into array - extract($preset); - - $frm_action = (isset($_POST['add_category'])) ? e_SELF."?cat" : e_SELF."?".e_QUERY; - $text = "
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "; - - $text .= " - - - - -
".DOWLAN_37.": "; - - $text .= $download->getCategorySelectList($main_category_parent, DOWLAN_40, false, false); - $text .= "
".DOWLAN_12.": - -
".DOWLAN_18.": "; - $text .= $eform->bbarea('download_category_description',$download_category_description); - $text .= "
".DOWLAN_41.": - - -
".DOWLAN_147.": - - -
".DOWLAN_43.":
(".DOWLAN_44.")
".r_userclass("download_category_class", $download_category_class, 'off', 'public, nobody, member, admin, classes, language')." -
"; - if ($id && $subAction == "edit" && !isset($_POST['add_category'])) { - $text .= " "; - } else { - $text .= ""; - } - $text .= "
-
-
"; - $ns->tablerender(DOWLAN_39, $text); - } - - function create_category($subAction, $id) - { - global $sql, $tp, $admin_log; - $download_category_name = $tp->toDB($_POST['download_category_name']); - $download_category_description = $tp->toDB($_POST['download_category_description']); - $download_category_icon = $tp->toDB($_POST['download_category_icon']); - $download_category_class = $tp->toDB($_POST['download_category_class']); - $download_categoory_parent = intval($_POST['download_category_parent']); - - if(isset($_POST['download_category_icon_empty']) && $_POST['download_category_icon_empty'] != "") - { - $download_category_icon .= trim(chr(1).$tp->toDB($_POST['download_category_icon_empty'])); - } - - if ($id) - { - admin_update($sql->db_Update("download_category", "download_category_name='{$download_category_name}', download_category_description='{$download_category_description}', download_category_icon ='{$download_category_icon}', download_category_parent= '{$download_categoory_parent}', download_category_class='{$download_category_class}' WHERE download_category_id='{$id}'"), 'update', DOWLAN_48); - $admin_log->log_event('DOWNL_03',$download_category_name.'[!br!]'.$download_category_description,E_LOG_INFORMATIVE,''); - } - else - { - admin_update($sql->db_Insert("download_category", "0, '{$download_category_name}', '{$download_category_description}', '{$download_category_icon}', '{$download_categoory_parent}', '{$download_category_class}', 0 "), 'insert', DOWLAN_47); - $admin_log->log_event('DOWNL_02',$download_category_name.'[!br!]'.$download_category_description,E_LOG_INFORMATIVE,''); - } - if ($subAction == "sn") - { - $sql->db_Delete("tmp", "tmp_time='{$id}' "); - } - } - - function show_existing_mirrors() - { - global $sql, $ns, $tp, $subAction, $id, $delete, $del_id, $admin_log; - - require_once(e_HANDLER."form_handler.php"); - $eform = new e_form(); - if($delete == "mirror") - { - admin_update($sql -> db_Delete("download_mirror", "mirror_id=".$del_id), delete, DOWLAN_135); - $admin_log->log_event('DOWNL_14','ID: '.$del_id,E_LOG_INFORMATIVE,''); - } - - - if(!$sql -> db_Select("download_mirror")) - { - $text = "
".DOWLAN_144."
"; // No mirrors defined yet - } - else - { - - $text = "
-
- - - - - - - - "; - - $mirrorList = $sql -> db_getList(); - - foreach($mirrorList as $mirror) - { - extract($mirror); - $text .= " - - - - - - - - "; - } - $text .= "
ID".DOWLAN_12."".DOWLAN_136."".LAN_OPTIONS."
$mirror_id".$tp -> toHTML($mirror_name)."".($mirror_image ? "" : DOWLAN_28)." - ".ADMIN_EDIT_ICON." - -
"; - - } - - $ns -> tablerender(DOWLAN_138, $text); - - require_once(e_HANDLER."file_class.php"); - $fl = new e_file; - $imagelist = $fl->get_files(e_FILE.'downloadimages/'); - - if($subAction == "edit" && !defined("SUBMITTED")) - { - $sql -> db_Select("download_mirror", "*", "mirror_id='".intval($id)."' "); - $mirror = $sql -> db_Fetch(); - extract($mirror); - $edit = TRUE; - } - else - { - unset($mirror_name, $mirror_url, $mirror_image, $mirror_location, $mirror_description); - $edit = FALSE; - } - - $text = "
-
\n - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
".DOWLAN_12." - -
".DOWLAN_139." - -
".DOWLAN_136." - - - -
- -
".DOWLAN_141." - -
".DOWLAN_18.""; - $text .= $eform->bbarea('mirror_description',$mirror_description); - $text .= "
- ".($edit ? "" : "")." -
-
-
"; - - $caption = ($edit ? DOWLAN_142 : DOWLAN_143); - - $ns -> tablerender($caption, $text); - } - - function submit_mirror() - { - global $tp, $sql, $admin_log; - define("SUBMITTED", TRUE); - if(isset($_POST['mirror_name']) && isset($_POST['mirror_url'])) - { - $name = $tp -> toDB($_POST['mirror_name']); - $url = $tp -> toDB($_POST['mirror_url']); - $location = $tp -> toDB($_POST['mirror_location']); - $description = $tp -> toDB($_POST['mirror_description']); - - $logString = $name.'[!br!]'.$url.'[!br!]'.$location.'[!br!]'.$description; - - if (isset($_POST['id'])) - { - admin_update($sql -> db_Update("download_mirror", "mirror_name='{$name}', mirror_url='{$url}', mirror_image='".$tp->toDB($_POST['mirror_image'])."', mirror_location='{$location}', mirror_description='{$description}' WHERE mirror_id=".intval($_POST['id'])), 'update', DOWLAN_133); - $admin_log->log_event('DOWNL_13','ID: '.intval($_POST['id']).'[!br!]'.$logString,E_LOG_INFORMATIVE,''); - } - else - { - admin_update($sql -> db_Insert("download_mirror", "0, '{$name}', '{$url}', '".$tp->toDB($_POST['mirror_image'])."', '{$location}', '{$description}', 0"), 'insert', DOWLAN_134); - $admin_log->log_event('DOWNL_12',$logString,E_LOG_INFORMATIVE,''); - } - } - } - - // --------------------------------------------------------------------------- - - function move_file($oldname,$newname) - { - global $ns; - if(file_exists($newname)) - { - return TRUE; - } - - if(!file_exists($oldname) || is_dir($oldname)) - { - $ns -> tablerender(LAN_ERROR,DOWLAN_68 . " : ".$oldname); - return FALSE; - } - - $directory = dirname($newname); - if(is_writable($directory)) - { - if(!rename($oldname,$newname)) - { - $ns -> tablerender(LAN_ERROR,DOWLAN_152." ".$oldname ." -> ".$newname); - return FALSE; - } - else - { - return TRUE; - } - } - else - { - $ns -> tablerender(LAN_ERROR,$directory ." ".LAN_NOTWRITABLE); - return FALSE; - } - } - -// ------------------------------------------------------------------------- - - -} // end class. - - function download_admin_adminmenu($parms) { - global $adminDownload,$action,$subAction; - $adminDownload->show_options($action); - if ('maint' == $action) - { - $adminDownload->show_maint_options($action,$subAction); + global $action,$subAction; + if ($action == "") { + $action = "main"; + } + $var['main']['text'] = DOWLAN_29; + $var['main']['link'] = e_SELF; + $var['create']['text'] = DOWLAN_30; + $var['create']['link'] = e_SELF."?create"; + $var['cat']['text'] = DOWLAN_31; + $var['cat']['link'] = e_SELF."?cat"; + $var['cat']['perm'] = "Q"; + $var['opt']['text'] = LAN_OPTIONS; + $var['opt']['link'] = e_SELF."?opt"; + $var['maint']['text'] = DOWLAN_165; + $var['maint']['link'] = e_SELF."?maint"; + $var['limits']['text'] = DOWLAN_112; + $var['limits']['link'] = e_SELF."?limits"; + $var['mirror']['text'] = DOWLAN_128; + $var['mirror']['link'] = e_SELF."?mirror"; + e_admin_menu(DOWLAN_32, $action, $var); + + unset($var); + if ($action == "" || $action == "main") { + $var['1']['text'] = "//TODO"; + $var['1']['link'] = ""; + e_admin_menu(DOWLAN_184, $subAction, $var); + } + if ($action == "maint") { + $var['duplicates']['text'] = DOWLAN_166; + $var['duplicates']['link'] = e_SELF."?maint.duplicates"; + $var['orphans']['text'] = DOWLAN_167; + $var['orphans']['link'] = e_SELF."?maint.orphans"; + $var['missing']['text'] = DOWLAN_168; + $var['missing']['link'] = e_SELF."?maint.missing"; + $var['inactive']['text'] = DOWLAN_169; + $var['inactive']['link'] = e_SELF."?maint.inactive"; + $var['nocategory']['text'] = DOWLAN_178; + $var['nocategory']['link'] = e_SELF."?maint.nocategory"; + $var['filesize']['text'] = DOWLAN_170; + $var['filesize']['link'] = e_SELF."?maint.filesize"; + $var['log']['text'] = DOWLAN_171; + $var['log']['link'] = e_SELF."?maint.log"; + e_admin_menu(DOWLAN_177, $subAction, $var); } } ?> \ No newline at end of file diff --git a/e107_plugins/download/download_shortcodes.php b/e107_plugins/download/download_shortcodes.php index 060bd29c9..7401c4650 100644 --- a/e107_plugins/download/download_shortcodes.php +++ b/e107_plugins/download/download_shortcodes.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/download/download_shortcodes.php,v $ -| $Revision: 1.3 $ -| $Date: 2009-02-11 21:41:54 $ +| $Revision: 1.4 $ +| $Date: 2009-05-03 21:16:15 $ | $Author: bugrain $ +----------------------------------------------------------------------------+ */ @@ -279,7 +279,7 @@ class download_shortcodes { global $pref,$dl,$tp; if ($pref['agree_flag'] == 1) { - return "toJS($tp->toHTML($pref['agree_text'],FALSE,'DESCRIPTION'))."');\" title='".LAN_dl_46."'>".$dl['download_name'].""; + return "xxxtoJS($tp->toHTML($pref['agree_text'],FALSE,'DESCRIPTION'))."');\" title='".LAN_dl_46."'>".$dl['download_name'].""; } else { return "".$dl['download_name'].""; } @@ -352,7 +352,7 @@ class download_shortcodes global $pref,$dlrow,$tp; $click = ""; if ($pref['agree_flag'] == 1) { - $click = " onclick='return confirm(\"".$tp->toJS($tp->toHTML($pref['agree_text'],FALSE,'DESCRIPTION'))."\")'"; + $click = " onclick='return confirm(\"".$tp->toJS($tp->toHTML($pref['agree_text'],true,'emotes, no_tags'))."\")'"; } $dnld_link = ""; if ($dlrow['download_mirror']) @@ -368,7 +368,7 @@ class download_shortcodes } else { - return $dnld_link." *"; + return $dnld_link." xxx*"; } } function get_download_view_filesize() diff --git a/e107_plugins/download/e_tagwords.php b/e107_plugins/download/e_tagwords.php new file mode 100644 index 000000000..f90837a57 --- /dev/null +++ b/e107_plugins/download/e_tagwords.php @@ -0,0 +1,45 @@ +e107 = e107::getInstance(); + + $this->settings = array(); + + $this->settings['plugin'] = ""; + $this->settings['table'] = "download"; + $this->settings['db_id'] = "download_id"; + $this->settings['caption'] = "download"; + } + + function getLink($id) + { + if($this->row=='') + { + $this->row = $this->getRecord($id); + } + $url = e_BASE."download.php?view.".$this->row['download_id']; + return "".$this->e107->tp->toHTML($this->row['download_name'], TRUE, '').""; + } + + function getRecord($id) + { + $this->row = ''; + + $qry = "SELECT d.* + FROM #download as d + WHERE d.download_id='{$id}' AND d.download_class REGEXP '".e_CLASS_REGEXP."' "; + + if($this->e107->sql->db_Select_gen($qry)) + { + $this->row=$this->e107->sql->db_Fetch(); + } + return $this->row; + } +} + +?> \ No newline at end of file diff --git a/e107_plugins/download/handlers/adminDownload_class.php b/e107_plugins/download/handlers/adminDownload_class.php new file mode 100644 index 000000000..4365148d5 --- /dev/null +++ b/e107_plugins/download/handlers/adminDownload_class.php @@ -0,0 +1,1598 @@ +userclassOptions = 'blank,nobody,guest,public,main,admin,member,classes'; + $this->filterCookieName = $pref['cookie_name']."_download_filter_admin"; + if (isset($_COOKIE[$this->filterCookieName])) { + $this->filterFields = unserialize($_COOKIE[$this->filterCookieName]); + } + + // Delete filter selection + if (isset($_POST['download_filter_delete'])) + { + $this->filterFields = array(); + } + + // Save filter selection + if (isset($_POST['download_filter_submit'])) + { + // Store filter fields in a cookie + $this->filterFields = $_POST['download_filter']; + // Convert date if input + //TODO need a core way of doing this - e_form validation? convert class? + $tmp = split("/", $this->filterFields['date']); + $this->filterFields['date'] = mktime(0,0,0,$tmp[1],$tmp[0],$tmp[2]); + cookie($this->filterCookieName, serialize($this->filterFields), 0); // Use session cookie + + // Columns to display saved in prefs + $pref['admin_download_disp'] = implode("|",$_POST['filter_columns']); + save_prefs(); + } + } + function show_filter_form($action, $subAction, $id, $from, $amount) + { + global $mySQLdefaultdb, $pref; + $eform = new e_form(); + + $filterColumns = ($pref['admin_download_disp'] ? explode("|",$pref['admin_download_disp']) : array("download_name","download_class")); + + // Filter fields + $text .= '
'.DOWLAN_183.''; + $text .= "
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameCategory + "; + $text .= $this->getCategorySelectList($this->filterFields['category'], true, false, ' ', 'download_filter[category]'); + $text .= "Filesize + "; + $text .= $this->_getConditionList('download_filter[filesize_condition]', $this->filterFields['filesize_condition']); + $text .= " + + +
Date + "; + $text .= $this->_getConditionList('download_filter[date_condition]', $this->filterFields['date_condition']); + $text .= $eform->datepicker('download_filter[date]', $this->filterFields['date']); + $text .= " + Status + + Requested + "; + $text .= $this->_getConditionList('download_filter[requested_condition]', $this->filterFields['requested_condition']); + $text .= " times +
Visibility + "; + $text .= $eform->uc_select('download_filter[visible]', $this->filterFields['visible'], $this->userclassOptions); + $text .= " + URLAuthor
Class + "; + $text .= $eform->uc_select('download_filter[class]', $this->filterFields['class'], $this->userclassOptions); + $text .= " + Description  
+

Fields to show

+ "; + + // Fields to display list - these are just columns form the download table + $fields = mysql_list_fields($mySQLdefaultdb, MPREFIX."download"); + $columns = mysql_num_fields($fields); + for ($i = 0; $i < $columns; $i++) { + $fname[] = mysql_field_name($fields, $i); + } + $replacechar = array("download_","_"); + $text .= "
"; + foreach($fname as $fcol) + { + $checked = (in_array($fcol,$filterColumns)) ? "checked='checked'" : ""; + $text .= "
"; + $text .= ""; + $text .= "
\n"; + } + + $text .= " +
+ + +
+
"; + return $text; + } + + function show_existing_items($action, $subAction, $id, $from, $amount) + { + global $sql, $rs, $ns, $tp, $mySQLdefaultdb, $pref; + $sortorder = ($pref['download_order']) ? $pref['download_order'] : "download_datestamp"; + $sortdirection = ($pref['download_sort']) ? strtolower($pref['download_sort']) : "desc"; + if ($sortdirection != 'desc') $sortdirection = 'asc'; + + if (!$pref['admin_download_disp']) + { + $filterColumns = array("download_name","download_class"); + } + else + { + $filterColumns = explode("|",$pref['admin_download_disp']); + } + $query = "SELECT d.*, dc.* FROM `#download` AS d LEFT JOIN `#download_category` AS dc ON dc. download_category_id=d.download_category"; + if ($this->filterFields) { + $where = array(); + if (strlen($this->filterFields['name']) > 0) { + array_push($where, "download_name REGEXP('".$this->filterFields['name']."')"); + } + if (strlen($this->filterFields['url']) > 0) { + array_push($where, "download_url REGEXP('".$this->filterFields['url']."')"); + } + if (strlen($this->filterFields['author']) > 0) { + array_push($where, "download_author REGEXP('".$this->filterFields['author']."')"); + } + if (strlen($this->filterFields['description']) > 0) { + array_push($where, "download_description REGEXP('".$this->filterFields['description']."')"); + } + if (strlen($this->filterFields['category']) != 0) { + array_push($where, "download_category=".$this->filterFields['category']); + } + if (strlen($this->filterFields['filesize']) > 0) { + array_push($where, "download_filesize".$this->filterFields['filesize_condition'].($this->filterFields['filesize']*$this->filterFields['filesize_units'])); + } + if ($this->filterFields['status'] != 99) { + array_push($where, "download_active=".$this->filterFields['status']); + } + if (strlen($this->filterFields['date']) > 0) { + switch ($this->filterFields['date_condition']) { + case "<=" : + { + array_push($where, "download_datestamp".$this->filterFields['date_condition'].($this->filterFields['date']+86400)); + break; + } + case "=" : + { + array_push($where, "(download_datestamp>=".$this->filterFields['date']." AND download_datestamp<=".($this->filterFields['date']+86399).")"); + break; + } + case ">=" : + { + array_push($where, "download_datestamp".$this->filterFields['date_condition'].$this->filterFields['date']); + break; + } + } + } + if (strlen($this->filterFields['requested']) > 0) { + array_push($where, "download_requested".$this->filterFields['requested_condition'].$this->filterFields['requested']); + } + if ($this->filterFields['visible']) { + array_push($where, "download_visible=".$this->filterFields['visible']); + } + if ($this->filterFields['class']) { + array_push($where, "download_class=".$this->filterFields['class']); + } + $where = (count($where) > 0 ? " WHERE ".implode(" AND ", $where) : ""); + + $query .= "$where ORDER BY {$sortorder} {$sortdirection}"; + } + else + { + $query .= " ORDER BY ".($subAction ? $subAction : $sortorder)." ".($id ? $id : $sortdirection)." LIMIT $from, $amount"; + } + + $text .= '
+ '.DOWLAN_7.''; + $text .= "
"; + if ($dl_count = $sql->db_Select_gen($query)) + { + $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform")." + + + + "; + + // Search Display Column header.---------- + foreach($filterColumns as $disp) + { + if ($disp == "download_name") + { // Toggle direction + $text .= ""; + } + else + { + $repl = array("download_","_"); + $text .= ""; + } + } + + $text .=""; + + while ($row = $sql->db_Fetch()) + { + $text .= ""; + + // Display Chosen options + foreach($filterColumns as $disp) + { + $text .= ""; + } + + $text .= " + + "; + } + $text .= "
".DOWLAN_67."".DOWLAN_12."".ucwords(str_replace($repl," ",$disp))."".LAN_OPTIONS."
".$row['download_id'].""; + switch ($disp) + { + case "download_name" : + $text .= "".$tp->toHTML($row['download_name']).""; + break; + case "download_category" : + $text .= $tp->toHTML($row['download_category_name']); + break; + case "download_datestamp" : + global $gen; + $text .= ($row[$disp]) ? $gen->convert_date($row[$disp],'short') : ""; + break; + case "download_class" : + case "download_visible" : + $text .= r_userclass_name($row[$disp])." "; + break; + case "download_filesize" : + $text .= ($row[$disp]) ? $this->e107->parseMemorySize(($row[$disp])) : ""; + break; + case "download_thumb" : + $text .= ($row[$disp]) ? "" : ""; + break; + case "download_image" : + $text .= "".$row[$disp].""; + break; + case "download_description" : + $text .= $tp->toHTML($row[$disp],TRUE); + break; + case "download_active" : + if ($row[$disp]== 1) + { + $text .= ""; + } + elseif ($row[$disp]== 2) + { + $text .= ""; + } + else + { + $text .= ""; + } + break; + case "download_comment" : + $text .= ($row[$disp]) ? ADMIN_TRUE_ICON : ""; + break; + default : + $text .= $tp->toHTML($row[$disp]); + } + $text .= " + ".ADMIN_EDIT_ICON." + toJS(DOWLAN_33." [ID: ".$row['download_id']." ]")."') \"/> +
"; + } + else + { // 'No downloads yet' + $text .= "
".DOWLAN_6."
"; + } + $text .= "
"; + + // Next-Previous. + $downloads = $sql->db_Count("download"); + if ($downloads > $amount && !$_POST['searchquery']) + { + $parms = "{$downloads},{$amount},{$from},".e_SELF."?".(e_QUERY ? "$action.$subAction.$id." : "main.{$sortorder}.{$sortdirection}.")."[FROM]"; + $text .= "
".$tp->parseTemplate("{NEXTPREV={$parms}}"); + } + + $text .= "
+
"; + return $text; + } + +// --------------------------------------------------------------------------- + + + // Given the string which is stored in the DB, turns it into an array of mirror entries + // If $byID is true, the array index is the mirror ID. Otherwise its a simple array + function makeMirrorArray($source, $byID = FALSE) + { + $ret = array(); + if ($source) + { + $mirrorTArray = explode(chr(1), $source); + + $count = 0; + foreach($mirrorTArray as $mirror) + { + if ($mirror) + { + list($mid, $murl, $mreq, $msize) = explode(",", $mirror); + $ret[$byID ? $mid : $count] = array('id' => $mid, 'url' => $murl, 'requests' => $mreq, 'filesize' => $msize); + $count++; + } + } + } + return $ret; + } + + + // Turn the array into a string which can be stored in the DB + function compressMirrorArray($source) + { + if (!is_array($source) || !count($source)) return ''; + $inter = array(); + foreach ($source as $s) + { + $inter[] = $s['id'].','.$s['url'].','.$s['requests'].','.$s['filesize']; + } + return implode(chr(1),$inter); + } + + + + function create_download($subAction, $id) + { + global $download, $e107, $cal, $tp, $sql, $fl, $rs, $ns, $file_array, $image_array, $thumb_array, $pst; + require_once(e_PLUGIN.'download/download_shortcodes.php'); + require_once(e_HANDLER."form_handler.php"); + + if ($file_array = $fl->get_files(e_DOWNLOAD, "","standard",5)) + { + sort($file_array); + } + if ($public_array = $fl->get_files(e_FILE."public/")) + { + foreach($public_array as $key=>$val) + { + $file_array[] = str_replace(e_FILE."public/","",$val); + } + } + if ($sql->db_Select("rbinary")) + { + while ($row = $sql->db_Fetch()) + { + extract($row); + $file_array[] = "Binary ".$binary_id."/".$binary_name; + } + } + if ($image_array = $fl->get_files(e_FILE.'downloadimages/', '\.gif$|\.jpg$|\.png$|\.GIF$|\.JPG$|\.PNG$','standard',2)) + { + sort($image_array); + } + if ($thumb_array = $fl->get_files(e_FILE.'downloadthumbs/', '\.gif$|\.jpg$|\.png$|\.GIF$|\.JPG$|\.PNG$','standard',2)) + { + sort($thumb_array); + } + + $eform = new e_form(); + $mirrorArray = array(); + + $download_status[0] = DOWLAN_122; + $download_status[1] = DOWLAN_123; + $download_status[2] = DOWLAN_124; + $preset = $pst->read_preset("admin_downloads"); // read preset values into array + extract($preset); + + if (!$sql->db_Select("download_category")) + { + $ns->tablerender(ADLAN_24, "
".DOWLAN_5."
"); + return; + } + $download_active = 1; + if ($subAction == "edit" && !$_POST['submit']) + { + if ($sql->db_Select("download", "*", "download_id=".$id)) + { + $row = $sql->db_Fetch(); + extract($row); + + $mirrorArray = $this->makeMirrorArray($row['download_mirror']); + } + } + + if ($subAction == "dlm" && !$_POST['submit']) + { + require_once(e_PLUGIN.'download/download_shortcodes.php'); + if ($sql->db_Select("upload", "*", "upload_id=".$id)) + { + $row = $sql->db_Fetch(); + + $download_category = $row['upload_category']; + $download_name = $row['upload_name'].($row['upload_version'] ? " v" . $row['upload_version'] : ""); + $download_url = $row['upload_file']; + $download_author_email = $row['upload_email']; + $download_author_website = $row['upload_website']; + $download_description = $row['upload_description']; + $download_image = $row['upload_ss']; + $download_filesize = $row['upload_filesize']; + $image_array[] = array("path" => "", "fname" => $row['upload_ss']); + $download_author = substr($row['upload_poster'], (strpos($row['upload_poster'], ".")+1)); + } + } + + + $text = " +
+ +
+
+
+ + + + + +
".DOWLAN_13." +
".DOWLAN_131."   + +
+
+
+
+ + + + + + + + + +
".DOWLAN_149." + +
".DOWLAN_66." + +
+
+
+ + + + "; + } + else + { + $text .= DOWLAN_132."
"; + $mirrorList = $sql -> db_getList(); // Get the list of possible mirrors + $m_count = (count($mirrorArray) ? count($mirrorArray) : 1); // Count of mirrors actually in use (or count of 1 if none defined yet) + for($count = 1; $count <= $m_count; $count++) + { + $opt = ($count==1) ? "id='mirror'" : ""; + $text .=" +
+ + + "; + if (DOWNLOAD_DEBUG) + { + if ($id) + { + $text .= '('.$mirrorArray[($count-1)]['requests'].')'; + } + else + { + $text .= ""; + } + } + $text .= "
"; + } + $text .="
+ + + + + + + "; + } // End of mirror-related stuff + + $download_author = $subAction != "edit" && $download_author == "" ? USERNAME : $download_author;//TODO what if editing an no author specified + $download_author_email = $subAction != "edit" && $download_author_email == "" ? USEREMAIL : $download_author_email; + $text .= " +
".DOWLAN_128.""; + + // See if any mirrors to display + if (!$sql -> db_Select("download_mirror")) + { // No mirrors defined here + $text .= DOWLAN_144."
".DOWLAN_155." + ".DOWLAN_156."
+ ".DOWLAN_157." +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "; + if ($subAction == "dlm") { + $text .= " + + + + + + + + "; + } + + //triggerHook + $data = array('method'=>'form', 'table'=>'download', 'id'=>$id, 'plugin'=>'download', 'function'=>'create_download'); + $hooks = $e107->e_event->triggerHook($data); + if(!empty($hooks)) + { + $text .= " + + + "; + foreach($hooks as $hook) + { + if(!empty($hook)) + { + $text .= " + + + "; + } + } + } + + $text .= " + + +
".DOWLAN_11.""; + $text .= $this->getCategorySelectList($download_category); + $text .= "
".DOWLAN_12." + toForm($download_name)."\" maxlength='200'/> +
".DOWLAN_15." + +
".DOWLAN_16." + +
".DOWLAN_17." + +
".DOWLAN_18." + "; + $text .= $eform->bbarea('download_description',$download_description); + $text .= "
".DOWLAN_19." + "; + if ($subAction == "dlm" && $download_image) + { + $text .= " + \n"; + } + $text .= "
".DOWLAN_20." + +
".LAN_DATESTAMP.""; + if (!$download_datestamp){ + $download_datestamp = time(); + } + $cal_options['showsTime'] = false; + $cal_options['showOthers'] = false; + $cal_options['weekNumbers'] = false; + $cal_options['ifFormat'] = "%d/%m/%Y %H:%M:%S"; + $cal_options['timeFormat'] = "24"; + $cal_attrib['class'] = "tbox"; + $cal_attrib['size'] = "22"; + $cal_attrib['name'] = "download_datestamp"; + $cal_attrib['value'] = date("d/m/Y H:i:s", $download_datestamp); + $text .= $cal->make_input_field($cal_options, $cal_attrib); + $update_checked = ($_POST['update_datestamp']) ? "checked='checked'" : ""; + $text .= "   ".DOWLAN_148." +
".DOWLAN_21." + +
".DOWLAN_102.""; + if ($download_comment == "0") { + $text .= LAN_YES.": + ".LAN_NO.": "; + } else { + $text .= LAN_YES.": + ".LAN_NO.": "; + } + $text .= "
".DOWLAN_145."".r_userclass('download_visible', $download_visible, 'off', 'public, nobody, member, admin, classes, language')."
".DOWLAN_106."".r_userclass('download_class', $download_class, 'off', 'public, nobody, member, admin, classes, language')."
".DOWLAN_153." + +
".DOWLAN_103." + + +
".LAN_HOOKS."
".$hook['caption']."".$hook['text']."
"; + if ($id && $subAction == "edit") { + $text .= " "; + } else { + $text .= ""; + } + + $text .= " +
+
+
+
+
"; + $ns->tablerender(ADLAN_24, $text); + } + + +// ----------------------------------------------------------------------------- + + function show_message($message) { + global $ns; + $ns->tablerender("", "
".$message."
"); + } + +// ----------------------------------------------------------------------------- + + + // Actually save a new or edited download to the DB + function submit_download($subAction, $id) + { + global $e107, $tp, $sql, $DOWNLOADS_DIRECTORY, $e_event; + + $dlInfo = array(); + $dlMirrors = array(); + + if ($subAction == 'edit') + { + if ($_POST['download_url_external'] == '') + { + $_POST['download_filesize_external'] = FALSE; + } + } + + if ($_POST['download_url_external'] && $_POST['download_url'] == '') + { + $dlInfo['download_url'] = $tp->toDB($_POST['download_url_external']); + $filesize = intval($_POST['download_filesize_external']); + } + else + { + $dlInfo['download_url'] = $tp->toDB($_POST['download_url']); + if ($_POST['download_filesize_external']) + { + $filesize = intval($_POST['download_filesize_external']); + } + else + { + if (strpos($DOWNLOADS_DIRECTORY, "/") === 0 || strpos($DOWNLOADS_DIRECTORY, ":") >= 1) + { + $filesize = filesize($DOWNLOADS_DIRECTORY.$dlInfo['download_url']); + } + else + { + $filesize = filesize(e_BASE.$DOWNLOADS_DIRECTORY.$dlInfo['download_url']); + } + } + } + + if (!$filesize) + { + if ($sql->db_Select("upload", "upload_filesize", "upload_file='{$dlInfo['download_url']}'")) + { + $row = $sql->db_Fetch(); + $filesize = $row['upload_filesize']; + } + } + $dlInfo['download_filesize'] = $filesize; + + + // ---- Move Images and Files ------------ + if ($_POST['move_image']) + { + if ($_POST['download_thumb']) + { + $oldname = e_FILE."public/".$_POST['download_thumb']; + $newname = e_FILE."downloadthumbs/".$_POST['download_thumb']; + if (!$this -> move_file($oldname,$newname)) + { + return; + } + } + if ($_POST['download_image']) + { + $oldname = e_FILE."public/".$_POST['download_image']; + $newname = e_FILE."downloadimages/".$_POST['download_image']; + if (!$this -> move_file($oldname,$newname)) + { + return; + } + } + } + + if ($_POST['move_file'] && $_POST['download_url']) + { + $oldname = e_FILE."public/".$_POST['download_url']; + $newname = $_POST['move_file'].$_POST['download_url']; + if (!$this -> move_file($oldname,$newname)) + { + return; + } + $dlInfo['download_url'] = str_replace(e_DOWNLOAD,"",$newname); + } + + + // ------------------------------------------ + + + $dlInfo['download_description'] = $tp->toDB($_POST['download_description']); + $dlInfo['download_name'] = $tp->toDB($_POST['download_name']); + $dlInfo['download_author'] = $tp->toDB($_POST['download_author']); + $dlInfo['download_author_email'] = $tp->toDB($_POST['download_author_email']); + $dlInfo['download_author_website'] = $tp->toDB($_POST['download_author_website']); + $dlInfo['download_category'] = intval($_POST['download_category']); + $dlInfo['download_active'] = intval($_POST['download_active']); + $dlInfo['download_thumb'] = $tp->toDB($_POST['download_thumb']); + $dlInfo['download_image'] = $tp->toDB($_POST['download_image']); + $dlInfo['download_comment'] = $tp->toDB($_POST['download_comment']); + $dlInfo['download_class'] = intval($_POST['download_class']); + $dlInfo['download_visible'] =intval($_POST['download_visible']); + + if (preg_match("#(.*?)/(.*?)/(.*?) (.*?):(.*?):(.*?)$#", $_POST['download_datestamp'], $matches)) + { + $dlInfo['download_datestamp'] = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]); + } + else + { + $dlInfo['download_datestamp'] = time(); + } + + if ($_POST['update_datestamp']) + { + $dlInfo['download_datestamp'] = time(); + } + + $mirrorStr = ""; + $mirrorFlag = FALSE; + + // See if any mirrors defined + // Need to check all the possible mirror names - might have deleted the first one if we're in edit mode + foreach ($_POST['download_mirror_name'] as $mn) + { + if ($mn) + { + $mirrorFlag = TRUE; + break; + } + } + if ($mirrorFlag) + { + $mirrors = count($_POST['download_mirror_name']); + $mirrorArray = array(); + $newMirrorArray = array(); + if ($id && $sql->db_Select('download','download_mirror', 'download_id = '.$id)) // Get existing download stats + { + if ($row = $sql->db_Fetch()) + { + $mirrorArray = $this->makeMirrorArray($row['download_mirror'], TRUE); + } + } + for($a=0; $a<$mirrors; $a++) + { + $mid = trim($_POST['download_mirror_name'][$a]); + $murl = trim($_POST['download_mirror'][$a]); + $msize = trim($_POST['download_mirror_size'][$a]); + if ($mid && $murl) + { + $newMirrorArray[$mid] = array('id' => $mid, 'url' => $murl, 'requests' => 0, 'filesize' => $msize); + if (DOWNLOAD_DEBUG && !$id) + { + $newMirrorArray[$mid]['requests'] = intval($_POST['download_mirror_requests'][$a]); + } + } + } + // Now copy across any existing usage figures + foreach ($newMirrorArray as $k => $m) + { + if (isset($mirrorArray[$k])) + { + $newMirrorArray[$k]['requests'] = $mirrorArray[$k]['requests']; + } + } + $mirrorStr = $this->compressMirrorArray($newMirrorArray); + } + + $dlMirrors['download_mirror']=$mirrorStr; + $dlMirrors['download_mirror_type']=intval($_POST['download_mirror_type']); + + if ($id) + { // Its an edit + // Process triggers before calling admin_update so trigger messages can be shown + $data = array('method'=>'update', 'table'=>'download', 'id'=>$id, 'plugin'=>'download', 'function'=>'update_download'); + $hooks = $e107->e_event->triggerHook($data); + require_once(e_HANDLER."message_handler.php"); + $emessage = &eMessage::getInstance(); + $emessage->add($hooks, E_MESSAGE_SUCCESS); + + admin_update($sql->db_UpdateArray('download',array_merge($dlInfo,$dlMirrors),'WHERE download_id='.intval($id)), 'update', DOWLAN_2." (".$_POST['download_name'].")"); + $dlInfo['download_id'] = $id; + $this->downloadLog('DOWNL_06',$dlInfo,$dlMirrors); + $dlInfo['download_datestamp'] = $time; // This is what 0.7 did, regardless of settings + unset($dlInfo['download_class']); // Also replicating 0.7 + $e_event->trigger('dlupdate', $dlInfo); + } + else + { + if ($download_id = $sql->db_Insert('download',array_merge($dlInfo,$dlMirrors))) + { + // Process triggers before calling admin_update so trigger messages can be shown + $data = array('method'=>'create', 'table'=>'download', 'id'=>$download_id, 'plugin'=>'download', 'function'=>'create_download'); + $hooks = $e107->e_event->triggerHook($data); + require_once(e_HANDLER."message_handler.php"); + $emessage = &eMessage::getInstance(); + $emessage->add($hooks, E_MESSAGE_SUCCESS); + + admin_update($download_id, 'insert', DOWLAN_1." (".$_POST['download_name'].")"); + + $dlInfo['download_id'] = $download_id; + $this->downloadLog('DOWNL_05',$dlInfo,$dlMirrors); + $dlInfo['download_datestamp'] = $time; // This is what 0.7 did, regardless of settings + unset($dlInfo['download_class']); // Also replicating 0.7 + $e_event->trigger("dlpost", $dlInfo); + + if ($_POST['remove_upload']) + { + $sql->db_Update("upload", "upload_active='1' WHERE upload_id='".$_POST['remove_id']."'"); + $mes = "
".$_POST['download_name']." ".DOWLAN_104; + $mes .= "

".DOWLAN_105.""; + $this->show_message($mes); + } + } + } + } + + + function downloadLog($aText, &$dlInfo, &$mirrorInfo=NULL) + { + global $admin_log; + $logString = DOWLAN_9; + foreach ($dlInfo as $k => $v) + { + $logString .= '[!br!]'.$k.'=>'.$v; + } + if ($mirrorInfo != NULL) + { + foreach ($mirrorInfo as $k => $v) + { + $logString .= '[!br!]'.$k.'=>'.$v; + } + } + $admin_log->log_event($aText,$logString,E_LOG_INFORMATIVE,''); + } + +// ----------------------------------------------------------------------------- + + function show_categories($subAction, $id) + { + global $download, $sql, $sql2, $rs, $ns, $tp, $pst; + + require_once(e_HANDLER."form_handler.php"); + $eform = new e_form(); + + $text = $rs->form_open("post", e_SELF."?".e_QUERY, "myform"); + $text .= "
"; + + $qry = " + SELECT dc.*, COUNT(d.download_id) AS filecount FROM #download_category AS dc + LEFT JOIN #download AS d ON d.download_category = dc.download_category_id + GROUP BY dc.download_category_id + ORDER BY dc.download_category_order + "; + if ($sql->db_Select_gen($qry)) + { + $categories = $sql->db_getList(); + foreach($categories as $cat) + { + $cat_array[$cat['download_category_parent']][] = $cat; + } + $text .= " + + + + + + + + + + + + + + "; + + + //Start displaying parent categories + foreach($cat_array[0] as $parent) + { + if (strstr($parent['download_category_icon'], chr(1))) + { + list($parent['download_category_icon'], $parent['download_category_icon_empty']) = explode(chr(1), $parent['download_category_icon']); + } + + $text .= " + + + + + + + "; + + //Show sub categories + if (is_array($cat_array[$parent['download_category_id']])) + { + foreach($cat_array[$parent['download_category_id']] as $subcat) + { + + if (strstr($subcat['download_category_icon'], chr(1))) + { + list($subcat['download_category_icon'], $subcat['download_category_icon_empty']) = explode(chr(1), $subcat['download_category_icon']); + } + $text .= " + + + + + + + "; + + //Show sub-sub categories + if (is_array($cat_array[$subcat['download_category_id']])) + { + foreach($cat_array[$subcat['download_category_id']] as $subsubcat) + { + + if (strstr($subsubcat['download_category_icon'], chr(1))) + { + list($subsubcat['download_category_icon'], $subsubcat['download_category_icon_empty']) = explode(chr(1), $subsubcat['download_category_icon']); + } + $text .= " + + + + + + "; + } + } + } + } + + } + + $text .= "
".DOWLAN_11."".DOWLAN_52."".LAN_ORDER."".LAN_OPTIONS."
".($parent['download_category_icon'] ? "" : " ")." + "; + $text .= $tp->toHTML($parent['download_category_name']); + $text .= "
+ "; + $text .= $tp->toHTML($parent['download_category_description']); + $text .= " +
+ + + + ".ADMIN_EDIT_ICON." + "; + if (!is_array($cat_array[$parent['download_category_id']])) + { + $text .= "toJS(DOWLAN_34." [ID: {$parent['download_category_id']} ]")."') \"/>"; + } + $text .= " +
".($subcat['download_category_icon'] ? "" : " ")." + "; + $text .= $tp->toHTML($subcat['download_category_name']); + $text .= " +
+ "; + $text .= $tp->toHTML($subcat['download_category_description']); + $text .= " +
{$subcat['filecount']} + + + ".ADMIN_EDIT_ICON.""; + if (!is_array($cat_array[$subcat['download_category_id']]) && !$subcat['filecount']) + { + $text .= "toJS(DOWLAN_34." [ID: {$subcat['download_category_id']} ]")."') \"/>"; + } + $text .= " +
".($subsubcat['download_category_icon'] ? "" : " ")." +     "; + $text .= $tp->toHTML($subsubcat['download_category_name']); + $text .= " +
+     "; + $text .= $tp->toHTML($subsubcat['download_category_description']); + $text .= " +
{$subsubcat['filecount']} + + + ".ADMIN_EDIT_ICON." + "; + if (!$subsubcat['filecount']) + { + $text .= "toJS(DOWLAN_34." [ID: {$subsubcat['download_category_id']} ]")."') \"/>"; + } + $text .= " +
"; + $text .= "
+ +
"; + } + else + { + $text .= "
".DOWLAN_38."
"; + } + $text .= ""; + $ns->tablerender(DOWLAN_37, $text); + + unset($download_category_id, $download_category_name, $download_category_description, $download_category_parent, $download_category_icon, $download_category_class); + + $handle = opendir(e_IMAGE."icons"); + while ($file = readdir($handle)) { + if ($file != "." && $file != ".." && $file != "/" && $file != "CVS") { + $iconlist[] = $file; + } + } + closedir($handle); + + if ($subAction == "edit" && !$_POST['add_category']) { + if ($sql->db_Select("download_category", "*", "download_category_id=$id")) { + $row = $sql->db_Fetch(); + extract($row); + $main_category_parent = $download_category_parent; + if (strstr($download_category_icon, chr(1))) + { + list($download_category_icon, $download_category_icon_empty) = explode(chr(1), $download_category_icon); + } + else + { + $download_category_icon_empty = ""; + } + } + } + + $preset = $pst->read_preset("admin_dl_cat"); // read preset values into array + extract($preset); + + $frm_action = (isset($_POST['add_category'])) ? e_SELF."?cat" : e_SELF."?".e_QUERY; + $text = "
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "; + + $text .= " + + + + +
".DOWLAN_37.": "; + + $text .= $this->getCategorySelectList($main_category_parent, false, false, DOWLAN_40); + $text .= "
".DOWLAN_12.": + +
".DOWLAN_18.": "; + $text .= $eform->bbarea('download_category_description',$download_category_description); + $text .= "
".DOWLAN_41.": + + +
".DOWLAN_147.": + + +
".DOWLAN_43.":
(".DOWLAN_44.")
".r_userclass("download_category_class", $download_category_class, 'off', 'public, nobody, member, admin, classes, language')." +
"; + if ($id && $subAction == "edit" && !isset($_POST['add_category'])) { + $text .= " "; + } else { + $text .= ""; + } + $text .= "
+
+
"; + $ns->tablerender(DOWLAN_39, $text); + } + + function create_category($subAction, $id) + { + global $sql, $tp, $admin_log; + $download_category_name = $tp->toDB($_POST['download_category_name']); + $download_category_description = $tp->toDB($_POST['download_category_description']); + $download_category_icon = $tp->toDB($_POST['download_category_icon']); + $download_category_class = $tp->toDB($_POST['download_category_class']); + $download_categoory_parent = intval($_POST['download_category_parent']); + + if (isset($_POST['download_category_icon_empty']) && $_POST['download_category_icon_empty'] != "") + { + $download_category_icon .= trim(chr(1).$tp->toDB($_POST['download_category_icon_empty'])); + } + + if ($id) + { + admin_update($sql->db_Update("download_category", "download_category_name='{$download_category_name}', download_category_description='{$download_category_description}', download_category_icon ='{$download_category_icon}', download_category_parent= '{$download_categoory_parent}', download_category_class='{$download_category_class}' WHERE download_category_id='{$id}'"), 'update', DOWLAN_48); + $admin_log->log_event('DOWNL_03',$download_category_name.'[!br!]'.$download_category_description,E_LOG_INFORMATIVE,''); + } + else + { + admin_update($sql->db_Insert("download_category", "0, '{$download_category_name}', '{$download_category_description}', '{$download_category_icon}', '{$download_categoory_parent}', '{$download_category_class}', 0 "), 'insert', DOWLAN_47); + $admin_log->log_event('DOWNL_02',$download_category_name.'[!br!]'.$download_category_description,E_LOG_INFORMATIVE,''); + } + if ($subAction == "sn") + { + $sql->db_Delete("tmp", "tmp_time='{$id}' "); + } + } + + function show_existing_mirrors() + { + global $sql, $ns, $tp, $subAction, $id, $delete, $del_id, $admin_log; + + require_once(e_HANDLER."form_handler.php"); + $eform = new e_form(); + if ($delete == "mirror") + { + admin_update($sql -> db_Delete("download_mirror", "mirror_id=".$del_id), delete, DOWLAN_135); + $admin_log->log_event('DOWNL_14','ID: '.$del_id,E_LOG_INFORMATIVE,''); + } + + + if (!$sql -> db_Select("download_mirror")) + { + $text = "
".DOWLAN_144."
"; // No mirrors defined yet + } + else + { + + $text = "
+
+ + + + + + + + "; + + $mirrorList = $sql -> db_getList(); + + foreach($mirrorList as $mirror) + { + extract($mirror); + $text .= " + + + + + + + + "; + } + $text .= "
ID".DOWLAN_12."".DOWLAN_136."".LAN_OPTIONS."
$mirror_id".$tp -> toHTML($mirror_name)."".($mirror_image ? "" : DOWLAN_28)." + ".ADMIN_EDIT_ICON." + +
"; + + } + + $ns -> tablerender(DOWLAN_138, $text); + + require_once(e_HANDLER."file_class.php"); + $fl = new e_file; + $imagelist = $fl->get_files(e_FILE.'downloadimages/'); + + if ($subAction == "edit" && !defined("SUBMITTED")) + { + $sql -> db_Select("download_mirror", "*", "mirror_id='".intval($id)."' "); + $mirror = $sql -> db_Fetch(); + extract($mirror); + $edit = TRUE; + } + else + { + unset($mirror_name, $mirror_url, $mirror_image, $mirror_location, $mirror_description); + $edit = FALSE; + } + + $text = "
+
\n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
".DOWLAN_12." + +
".DOWLAN_139." + +
".DOWLAN_136." + + + +
+ +
".DOWLAN_141." + +
".DOWLAN_18.""; + $text .= $eform->bbarea('mirror_description',$mirror_description); + $text .= "
+ ".($edit ? "" : "")." +
+
+
"; + + $caption = ($edit ? DOWLAN_142 : DOWLAN_143); + + $ns -> tablerender($caption, $text); + } + + function submit_mirror() + { + global $tp, $sql, $admin_log; + define("SUBMITTED", TRUE); + if (isset($_POST['mirror_name']) && isset($_POST['mirror_url'])) + { + $name = $tp -> toDB($_POST['mirror_name']); + $url = $tp -> toDB($_POST['mirror_url']); + $location = $tp -> toDB($_POST['mirror_location']); + $description = $tp -> toDB($_POST['mirror_description']); + + $logString = $name.'[!br!]'.$url.'[!br!]'.$location.'[!br!]'.$description; + + if (isset($_POST['id'])) + { + admin_update($sql -> db_Update("download_mirror", "mirror_name='{$name}', mirror_url='{$url}', mirror_image='".$tp->toDB($_POST['mirror_image'])."', mirror_location='{$location}', mirror_description='{$description}' WHERE mirror_id=".intval($_POST['id'])), 'update', DOWLAN_133); + $admin_log->log_event('DOWNL_13','ID: '.intval($_POST['id']).'[!br!]'.$logString,E_LOG_INFORMATIVE,''); + } + else + { + admin_update($sql -> db_Insert("download_mirror", "0, '{$name}', '{$url}', '".$tp->toDB($_POST['mirror_image'])."', '{$location}', '{$description}', 0"), 'insert', DOWLAN_134); + $admin_log->log_event('DOWNL_12',$logString,E_LOG_INFORMATIVE,''); + } + } + } + + // --------------------------------------------------------------------------- + + function move_file($oldname,$newname) + { + global $ns; + if (file_exists($newname)) + { + return TRUE; + } + + if (!file_exists($oldname) || is_dir($oldname)) + { + $ns -> tablerender(LAN_ERROR,DOWLAN_68 . " : ".$oldname); + return FALSE; + } + + $directory = dirname($newname); + if (is_writable($directory)) + { + if (!rename($oldname,$newname)) + { + $ns -> tablerender(LAN_ERROR,DOWLAN_152." ".$oldname ." -> ".$newname); + return FALSE; + } + else + { + return TRUE; + } + } + else + { + $ns -> tablerender(LAN_ERROR,$directory ." ".LAN_NOTWRITABLE); + return FALSE; + } + } + /** + * + * @private + */ + function _getConditionList($name, $value) { + $text .= " + + "; + return $text; + } + /** + * + * @private + */ + function _getStatusList($name, $value) { + $download_status[99]= ' '; + $download_status[0] = DOWLAN_122; + $download_status[1] = DOWLAN_123; + $download_status[2] = DOWLAN_124; + $text = ""; + foreach($download_status as $key=>$val){ + $sel = ($value == $key && $value != null) ? " selected='selected'" : ""; + $text .= "\n"; + } + return $text; + } +} +?> \ No newline at end of file diff --git a/e107_plugins/download/handlers/download_class.php b/e107_plugins/download/handlers/download_class.php index 7fc4cb984..4b68f1491 100644 --- a/e107_plugins/download/handlers/download_class.php +++ b/e107_plugins/download/handlers/download_class.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/download/handlers/download_class.php,v $ -| $Revision: 1.1 $ -| $Date: 2009-02-11 21:41:54 $ +| $Revision: 1.2 $ +| $Date: 2009-05-03 21:16:15 $ | $Author: bugrain $ | +----------------------------------------------------------------------------+ @@ -22,8 +22,10 @@ if (!plugInstalled('download')) { exit(); } class download { + var $e107; function download() { + $this->e107 = e107::getInstance(); } function displayCategoryList() { } @@ -46,7 +48,7 @@ class download $dlbreadcrumb['fieldlist'] = implode(",", array_keys($dlbreadcrumb)); return $dlbreadcrumb; } - function getCategorySelectList($currentID=0, $blankText="", $incSubSub=true, $groupOnMain=true) + function getCategorySelectList($currentID=0, $incSubSub=true, $groupOnMain=true, $blankText=" ", $name="download_category") { global $sql,$parm; $boxinfo = "\n"; @@ -63,7 +65,7 @@ class download return "Error reading categories
"; exit; } - $boxinfo .= " \n"; // Its a structured display option - need a 2-step process to create a tree $catlist = array(); diff --git a/e107_plugins/download/languages/English/lan_download_admin.php b/e107_plugins/download/languages/English/lan_download_admin.php index fff7da3cc..c4122fe59 100644 --- a/e107_plugins/download/languages/English/lan_download_admin.php +++ b/e107_plugins/download/languages/English/lan_download_admin.php @@ -4,8 +4,8 @@ | e107 website system - Language File. | | $Source: /cvs_backup/e107_0.8/e107_plugins/download/languages/English/lan_download_admin.php,v $ -| $Revision: 1.5 $ -| $Date: 2009-02-11 21:41:54 $ +| $Revision: 1.6 $ +| $Date: 2009-05-03 21:16:15 $ | $Author: bugrain $ +----------------------------------------------------------------------------+ */ @@ -36,7 +36,7 @@ define("DOWLAN_25", "Submit Download"); define("DOWLAN_27", "Download"); define("DOWLAN_28", "None"); -define("DOWLAN_29", "Downloads Front Page"); +define("DOWLAN_29", "Downloads"); define("DOWLAN_30", "Create Download"); define("DOWLAN_31", "Categories"); define("DOWLAN_32", "Downloads Options"); @@ -64,6 +64,7 @@ define("DOWLAN_53", "Subcategory"); define("DOWLAN_54", "Download Options"); define("DOWLAN_55", "Number of downloads to display per page"); define("DOWLAN_56", "Sort by "); +define("DOWLAN_57", "Clear filters"); define("DOWLAN_59", "Filename"); @@ -169,6 +170,10 @@ define("DOWLAN_177", "Maintenance options"); define("DOWLAN_178", "No category"); define("DOWLAN_179", "Select an option from the Maintenance Options menu"); define("DOWLAN_180", "File size (database/disk)"); +define("DOWLAN_181", "Not readable"); +define("DOWLAN_182", "Timestamp"); +define("DOWLAN_183", "Filter options"); +define("DOWLAN_184", "Batch options"); define("DOWLAN_HELP_1", "Download Help"); define("DOWLAN_HELP_2", "

Create/edit a download.

Enter only one of: File, URL or Mirror.

Ensure you select a category, otherwise your download will not be visible on the downloads page.

");