\r\n";
/** @public string Information to be displayed at start of main page */
public $preamble = '';
/** @public string Default Licence for downloads */
public $Default_Licence = '';
/** @public string Custom field control - serialized array */
public $customizer = '';
/** @public string Custom field names and titles */
public $custom_names='';
/** @public int unix timestamp for automatic timed triggering */
public $Cron_Timer=0;
/** @public bool Do files have ID number when stored in file system? */
public $Real_With_ID=1;
public function __construct () {
$repnum = max(1, remositoryRepository::getParam($_REQUEST, 'repnum', 1));
$interface = remositoryInterface::getInstance();
$database = $interface->getDB();
if (true OR $type=='GLOBAL') {
$mosConfig_live_site = $interface->getCfg('live_site');
$database->setQuery("SELECT * FROM #__downloads_repository ORDER BY id LIMIT 1");
$repositories = $database->loadObjectList();
// Change for multiple repositories
// if ($repositories) foreach ($repositories as $repository) if ($repnum == $repository->id) break;
if (!empty($repositories)) $repository = $repositories[0];
if (isset($repository)) {
if ($repnum != $repository->id) {
$repository = $repositories[0];
$_REQUEST['repnum'] = $repository->id;
}
$this->setValues($repository);
}
else {
$this->headerpic = $interface->getCfg('live_site').$this->headerpic;
$this->saveValues();
}
}
foreach (get_class_vars(get_class($this)) as $k=>$v) {
$this->$k = str_replace ('{live_site}', $mosConfig_live_site, $this->$k);
}
}
public static function getInstance () {
static $instance;
if (!is_object($instance)) $instance = new remositoryRepository();
return $instance;
}
protected function tableName () {
return '#__downloads_repository';
}
protected function getVarText() {
$txt = '';
$this->Time_Stamp = time();
foreach (get_class_vars(get_class($this)) as $k=>$v) {
if (substr($k,0,1) != '_') {
if (is_numeric($this->$k)){
$txt .= "\$$k = ".intval($this->$k).";\n";
} elseif (strlen($k) > 0) $txt .= "\$$k = \"".addslashes( $this->$k )."\";\n";
}
}
return $txt;
}
public function saveValues ($makenew=false) {
$interface = remositoryInterface::getInstance();
$database = $interface->getDB();
$this->forceBools();
if (!$makenew) {
$repnum = max(1, remositoryRepository::getParam($_REQUEST, 'repnum', 1));
// Change for multiple repositories
// $sql = "SELECT COUNT(*) FROM #__downloads_repository WHERE id = $repnum";
$sql = "SELECT COUNT(*) FROM #__downloads_repository";
$database->setQuery($sql);
if (!$database->loadResult()) $makenew = true;
}
if ($makenew) {
$abspath = $interface->getCfg('absolute_path');
$this->Down_Path = $abspath.'/remos_downloads/';
$this->Up_Path = $this->Down_Path.'uploads/';
$sql = $this->insertSQL();
}
else {
$this->id = $repnum;
$sql = $this->updateSQL();
}
remositoryRepository::doSQL ($sql);
}
public function searchRepository($search_text, $seek_fields, $user, $pagecontrol, $containers, $countOnly=false) {
if (!$search_text) return $countOnly ? 0 : array();
if ($countOnly) {
$sql = remositoryFile::searchFilesSQL($search_text, $seek_fields, $user, true, $containers);
$interface = remositoryInterface::getInstance();
$database = $interface->getDB();
$database->setQuery($sql);
return $database->loadResult();
}
$sql = remositoryFile::searchFilesSQL($search_text, $seek_fields, $user, false, $containers, $pagecontrol->startItem(), $pagecontrol->itemsperpage);
return remositoryRepository::doSQLget($sql,'remositoryFile');
}
// May be redundant
function getUploadLimit () {
return $this->maxUploads;
}
// May be redundant
function canUserSubmit () {
return $this->userSubmit;
}
public function getTableClasses () {
return explode(",",$this->tabclass);
}
public function isExtensionOK ($file) {
if ('*' == trim($this->ExtsOk)) return true;
$extsok = explode(",",strtolower($this->ExtsOk));
foreach ($extsok as $ok) if (0 == strcasecmp($ok, substr($file, -strlen($ok)))) return true;
return false;
}
public function getSelectList ($allowTop, $default, $type, $parm, &$user, $usable=false) {
if ($allowTop) $selector[] = $this->makeOption(0,_DOWN_NO_PARENT);
else $selector = array();
$manager = remositoryContainerManager::getInstance();
foreach ($manager->getCategories() as $category) $category->addSelectList('', $selector, null, $user, $usable);
if (count($selector)) return $this->selectList( $selector, $type, $parm, $default );
else return '';
}
public static function getIcons ($location) {
$interface = remositoryInterface::getInstance();
$mosConfig_live_site = $interface->getCfg('live_site');
$iconList='';
$handle=@opendir($interface->getCfg('absolute_path').'/components/com_remository/images/'.$location);
if ($handle) {
$ss = 0;
while (($file = readdir($handle))!==false) {
if ($file != "." && $file != "..") {
$iconList.="\n\t\t\t\t
";
/*
$ss++;
if ($ss>=10) {
$ss = 0;
$iconList.="
\n";
}
*/
}
}
closedir($handle);
if ($iconList=='') $iconList="_DOWN_NOT_AUTH";
}
return $iconList;
}
public function resetCounts ($chain=null) {
$manager = remositoryContainerManager::getInstance();
$categories = $manager->getCategories();
// if (is_array($chain)) remositoryRepository::doSQL('TRUNCATE TABLE #__downloads_structure');
foreach ($categories as $category) $category->setFileCount($chain);
}
// May be redundant
function getFiles ($search='', $limitstart=0, $limit=0) {
$sql = remositoryFile::getFilesSQL(true, false, 0, true, 2, $search, $limitstart, $limit);
return remositoryRepository::doSQLget($sql,'remositoryFile');
}
// May be redundant
function getFilesCount ($search) {
$interface = remositoryInterface::getInstance();
$database = $interface->getDB();
$sql = remositoryFile::getFilesSQL(true, true, 0, true, 2, $search);
$database->setQuery( $sql );
return $database->loadResult();
}
public function getTempFiles () {
$repnum = max(1, remositoryRepository::getParam($_REQUEST, 'repnum', 1));
// Change for multiple repositories
// $sql = "SELECT * FROM #__downloads_files WHERE metatype > 0 AND repnum = $repnum ORDER BY id";
$sql = "SELECT * FROM #__downloads_files WHERE metatype > 0 ORDER BY id";
$results = remositoryRepository::doSQLget($sql,'remositoryTempFile');
foreach ($results as $key=>$result) $results[$key]->containerid = -$result->containerid;
return $results;
}
public function RemositoryFunctionURL ($func=null, $idparm=null, $os=null, $orderby=null, $item=null) {
return '';
}
public function RemositoryRawFunctionURL ($func=null, $idparm=null, $os=null, $orderby=null, $item=null, $fname=null ) {
$interface = remositoryInterface::getInstance();
$database = $interface->getDB();
$repnum = max(1, remositoryRepository::getParam($_REQUEST, 'repnum', 1));
if (!defined('_ALIRO_IS_PRESENT')) {
// Change for multiple repositories
// $url = "index.php?option=com_remository&repnum=$repnum&Itemid=";
$url = "index.php?option=com_remository&Itemid=";
$url .= $item ? $item : $this->getItemid();
}
// Change for multiple repositories
// elseif (1 < $repnum) $url = 'index.php?option=com_remository&repnum='.$repnum;
else $url = 'index.php?option=com_remository';
if ($func) $url .= '&func='.$func;
if ($idparm) $url .= '&id='.$idparm;
if (!$os) $os = remositoryRepository::getParam($_REQUEST,'os',null);
if (!in_array($os,array('win','mac','linux','all'))) $os = null;
if ($os AND $os != 'All') $url .= '&os='.$os;
if ($orderby) $url .= '&orderby='.$orderby;
if ($func == 'download') $url .= '&chk='.$this->makeCheck($idparm,$func).'&no_html=1';
elseif ($func == 'rss') $url .= '&no_html=1';
// if ($fname) $url .= '&fname='.urlencode($fname);
$thisfunc = remositoryRepository::getParam($_REQUEST, 'func');
if ('direct' == substr($thisfunc,0,6)) {
if (!$func) $url .= '&func=directlist';
$url .= '&indextype=2';
}
return $url;
}
public function getItemid ($component='com_remository') {
if (isset($GLOBALS['remosef_itemids'][$component])) $Itemid = $GLOBALS['remosef_itemids'][$component];
else {
$database = remositoryInterface::getInstance()->getDB();
$database->setQuery("SELECT id, (CASE menutype WHEN 'mainmenu' THEN 1 WHEN 'topmenu' THEN 2 WHEN 'othermenu' THEN 3 ELSE 99 END) menorder"
." FROM #__menu WHERE link LIKE 'index.php?option=$component%' AND published=1 ORDER BY menorder");
$GLOBALS['remosef_itemids'][$component] = $Itemid = $database->loadResult();
}
return $Itemid;
}
public function RemositoryBasicFunctionURL ($func=null, $idparm=null, $os=null, $orderby=null, $item=null, $fname=null ) {
$interface = remositoryInterface::getInstance();
$url = $this->RemositoryRawFunctionURL($func, $idparm, $os, $orderby, $item, $fname);
if (!defined('REMOSITORY_ADMIN_SIDE')) $url = $interface->sefRelToAbs($url);
$ampencode = '/(&(?!(#[0-9]{1,5};))(?!([0-9a-zA-Z]{1,10};)))/';
return preg_replace($ampencode, '&', $url);
return $url;
}
function wrongCheck ($chk, $id, $func) {
if ($chk == $this->makeCheck($id, $func)) return false;
return true;
}
function makeCheck ($id, $func) {
$interface = remositoryInterface::getInstance();
return md5($this->Time_Stamp.$interface->getCfg('absolute_path').date('md').$id.$func);
}
// Containerid may be needed for notification by email of intererested people
public function sendAdminMail ($user_full, $filetitles, $containerid, $published=true) {
$interface = remositoryInterface::getInstance();
$subject = $interface->getCfg('sitename').':'._DOWN_MAIL_SUB;
$message = $published ? _DOWN_MAIL_MSG_APP : _DOWN_MAIL_MSG;
$message .= "\n"._DOWN_FILE_TITLE."\n". $filetitles;
$message = sprintf($message, $user_full, $interface->getCfg('sitename'));
eval ("\$message = \"$message\";");
$interface->sendMail (($this->Sub_Mail_Alt_Addr ? $this->Sub_Mail_Alt_Addr : remositoryUser::superAdminMail()), $subject, $message);
}
public function RemositoryImageURL($imageName, $width=32, $height=32, $title='') {
$interface = remositoryInterface::getInstance();
$imageurl = $interface->getCfg('live_site').'/components/com_remository/images/'.$imageName;
$titlehtml = $title ? "title=\"$title\"" : '';
return <<
REMOS_IMAGE;
}
public static function doSQL ($sql) {
if ($sql) {
$interface = remositoryInterface::getInstance();
$database = $interface->getDB();
$database->setQuery($sql);
if (!$database->query()) {
echo "\n";
exit();
}
}
}
public static function doSQLget ($sql, $classname) {
if ($sql) {
$interface = remositoryInterface::getInstance();
$database = $interface->getDB();
$database->setQuery($sql);
$rows = $database->loadObjectList();
}
else $rows = null;
$target = get_class_vars($classname);
if ($rows) {
foreach ($rows as $row) {
$next = new $classname(0);
foreach (get_object_vars($row) as $field=>$value) {
if (isset($target[$field])) $next->$field = $value;
}
$result[] = $next;
}
}
else $result = (array());
return $result;
}
public function makeOption($value, $text='', $value_name='value', $text_name='text') {
$obj = new stdClass;
$obj->$value_name = $value;
$obj->$text_name = trim($text) ? $text : $value;
return $obj;
}
public function selectList (&$arr, $tag_name, $tag_attribs='', $selected=NULL, $key='value', $text='text' ) {
$html = "\n\t\t\n";
return $html;
}
public static function getParam (&$array, $name, $default='') {
$interface = remositoryInterface::getInstance();
if (!empty($array[$name])) {
if (is_numeric($default)) return intval($array[$name]);
else return $interface->purify($array[$name]);
}
else return $default;
}
}