pluginglobs(); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_TITLE); $propbag->add('description', PLUGIN_DOWNLOADMANAGER_DESC); $propbag->add('requirements', array( 'serendipity' => '1.6', 'smarty' => '2.6.7', 'php' => '5.3.0' )); $propbag->add('version', '0.38'); $propbag->add('author', 'Alexander \'dma147\' Mieland, Grischa Brockhaus, Ian'); $propbag->add('stackable', false); $propbag->add('event_hooks', array( 'entries_header' => true, 'entry_display' => true, 'genpage' => true, 'external_plugin' => true, 'css' => true, 'css_backend' => true, 'backend_sidebar_entries' => true, 'backend_sidebar_admin_appearance' => true, 'backend_sidebar_entries_event_display_downloadmanager' => true ) ); $propbag->add('configuration', array( 'pagetitle', 'headline', 'intro', 'pageurl', 'permalink', 'separator', 'absincomingpath', 'absdownloadspath', 'httppath', 'add_existing_file', 'iconwidth', 'iconheight', 'dateformat', 'showhidden_registered', 'registered_only', 'showfilename', 'showdownloads', 'showfilesize', 'showdate', 'showdesc_inlist', 'directdl_inlist', 'filename_field', 'filesize_field', 'filedate_field', 'dls_field' ) ); $propbag->add('groups', array('FRONTEND_FULL_MODS')); $this->dependencies = array('serendipity_event_entryproperties' => 'keep'); } /** * introspect_config_item API */ function introspect_config_item($name, &$propbag) { global $serendipity; switch($name) { case 'pagetitle' : $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_PAGETITLE); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_PAGETITLE_BLAHBLAH); $propbag->add('default', 'My downloads'); break; case 'headline' : $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_HEADLINE); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_HEADLINE_BLAHBLAH); $propbag->add('default', 'Here you can find some useful downloads'); break; case 'intro': $propbag->add('type', ($serendipity['wysiwyg'] === true ? 'html' : 'text')); $propbag->add('rows', 3); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_INTRO); $propbag->add('description',''); $propbag->add('default', ''); break; case 'pageurl' : $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_PAGEURL); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_PAGEURL_BLAHBLAH); $propbag->add('default', 'downloadmanager'); break; case 'permalink': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_PERMALINK); $propbag->add('description',sprintf(PLUGIN_DOWNLOADMANAGER_PERMALINK_BLAHBLAH, $serendipity['serendipityHTTPPath'] . 'downloads.html')); $propbag->add('default', $serendipity['rewrite'] != 'none' ? $serendipity['serendipityHTTPPath'] . 'downloads.html' : $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/downloads.html'); break; case 'separator': $propbag->add('type', 'separator'); break; // Remember, the chg2archivespath variable was here to indicate the upgrade to DLM Version 0.24+ had run through // and files got merged to the new location, which should not be configurable any more, so be a 'content' information! case 'absincomingpath': $propbag->add('type', 'content'); $propbag->add('default', ''.PLUGIN_DOWNLOADMANAGER_ABSINCOMINGPATH . ': ' . $serendipity['serendipityPath'] . 'archives/.dlm/ftpin' . '
' . PLUGIN_DOWNLOADMANAGER_ABSINCOMINGPATH_BLAHBLAH); break; case 'absdownloadspath': $propbag->add('type', 'content'); $propbag->add('default', ''.PLUGIN_DOWNLOADMANAGER_ABSDOWNLOADPATH . ': ' . $serendipity['serendipityPath'] . 'archives/.dlm/files' . '
' . PLUGIN_DOWNLOADMANAGER_ABSDOWNLOADPATH_BLAHBLAH); break; case 'httppath': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_HTTPPATH); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_HTTPPATH_BLAHBLAH); $propbag->add('default', $serendipity['serendipityHTTPPath'] . 'plugins/serendipity_event_downloadmanager/'); break; case 'iconwidth': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_ICONWIDTH); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_ICONWIDTHBLAH); $propbag->add('default', '18'); break; case 'iconheight': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_ICONHEIGHT); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_ICONHEIGHT_BLAHBLAH); $propbag->add('default', '20'); break; case 'dateformat': $propbag->add('type', 'string'); $propbag->add('name', GENERAL_PLUGIN_DATEFORMAT); $propbag->add('description',sprintf(PLUGIN_DOWNLOADMANAGER_DATEFORMAT, 'Y/m/d, h:ia')); $propbag->add('default', 'Y/m/d, h:ia'); break; case 'showhidden_registered': $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_SHOWHIDDEN_REGISTERED); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_SHOWHIDDEN_REGISTERED_BLAHBLAH); $propbag->add('default', 'false'); break; case 'registered_only': $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_REGISTERED_ONLY); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_REGISTERED_ONLY_BLAHBLAH); $propbag->add('default', 'false'); break; case 'showfilename': $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_SHOWFILENAME); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_SHOWFILENAME_BLAHBLAH); $propbag->add('default', 'true'); break; case 'showdownloads': $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_SHOWDOWNLOADS); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_SHOWDOWNLOADS_BLAHBLAH); $propbag->add('default', 'true'); break; case 'showfilesize': $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_SHOWFILESIZE); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_SHOWFILESIZE_BLAHBLAH); $propbag->add('default', 'true'); break; case 'showdate': $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_SHOWFILEDATE); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_SHOWFILEDATE_BLAHBLAH); $propbag->add('default', 'false'); break; case 'showdesc_inlist': $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_SHOWDESC_INLIST); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_SHOWDESC_INLIST_DESC); $propbag->add('default', 'false'); break; case 'directdl_inlist': $listdl_types = array( 'no' => PLUGIN_DOWNLOADMANAGER_DOWNLOAD_INLIST_NO, 'icon' => PLUGIN_DOWNLOADMANAGER_DOWNLOAD_INLIST_ICON, 'name' => PLUGIN_DOWNLOADMANAGER_DOWNLOAD_INLIST_NAME, 'both' => PLUGIN_DOWNLOADMANAGER_DOWNLOAD_INLIST_BOTH, ); $propbag->add('type', 'select'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_DOWNLOAD_INLIST); $propbag->add('description', PLUGIN_DOWNLOADMANAGER_DOWNLOAD_INLIST_DESC); $propbag->add('default', 'no'); $propbag->add('select_values', $listdl_types); break; case 'add_existing_file': $existing_types = array( 'insert' => PLUGIN_DOWNLOADMANAGER_ADD_EXISTING_INSERT, 'update' => PLUGIN_DOWNLOADMANAGER_ADD_EXISTING_UPDATE, ); $propbag->add('type', 'select'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_ADD_EXISTING); $propbag->add('description', PLUGIN_DOWNLOADMANAGER_ADD_EXISTING_DESC); $propbag->add('default', 'insert'); $propbag->add('select_values', $existing_types); break; case 'filename_field' : $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_FILENAME_FIELD); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_FILENAME_FIELD_BLAHBLAH); $propbag->add('default', PLUGIN_DOWNLOADMANAGER_FILENAME); break; case 'filesize_field' : $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_FILESIZE_FIELD); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_FILESIZE_FIELD_BLAHBLAH); $propbag->add('default', PLUGIN_DOWNLOADMANAGER_FILESIZE); break; case 'filedate_field' : $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_FILEDATE_FIELD); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_FILEDATE_FIELD_BLAHBLAH); $propbag->add('default', PLUGIN_DOWNLOADMANAGER_FILEDATE); break; case 'dls_field' : $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DOWNLOADMANAGER_DLS_FIELD); $propbag->add('description',PLUGIN_DOWNLOADMANAGER_DLS_FIELD_BLAHBLAH); $propbag->add('default', PLUGIN_DOWNLOADMANAGER_NUM_DOWNLOADS); break; default: return false; } return true; } /** * show */ function show() { global $serendipity; if ($this->selected()) { if (!headers_sent()) { header('HTTP/1.0 200'); header('Status: 200 OK'); } if (!is_object($serendipity['smarty'])) { serendipity_smarty_init(); } $_ENV['staticpage_pagetitle'] = preg_replace('@[^a-z0-9]@i', '_',$this->get_config('pagetitle')); $serendipity['smarty']->assign('staticpage_pagetitle', $_ENV['staticpage_pagetitle']); $this->showShoutPage(); } } /** * This method is a plugin API standard starter */ function selected() { global $serendipity; if (!empty($serendipity['POST']['subpage'])) { $serendipity['GET']['subpage'] = $serendipity['POST']['subpage']; } if ($serendipity['GET']['subpage'] == $this->get_config('pageurl') || preg_match('@^' . preg_quote($this->get_config('permalink')) . '@i', $serendipity['GET']['subpage'])) { return true; } return false; } /** * setup database */ function setupDB() { global $serendipity; $built = $this->get_config('dl_db_built', null); if (empty($built) && !defined('DLMANAGER_UPGRADE_DONE')) { $q = "CREATE TABLE {$serendipity['dbPrefix']}dma_downloadmanager_files ( id {AUTOINCREMENT} {PRIMARY}, catid int(10) NOT NULL default '0', timestamp int(10) NOT NULL default '0', systemfilename varchar(32), realfilename varchar(150), description text, filesize int(10) NOT NULL default '0', dlcount int(10) NOT NULL default '0' )"; $sql = serendipity_db_schema_import($q); $q = "CREATE TABLE {$serendipity['dbPrefix']}dma_downloadmanager_categories ( node_id {AUTOINCREMENT} {PRIMARY}, root_id int(10) NOT NULL default '0', payload varchar(64), lft int(10) NOT NULL default '0', rgt int(10) NOT NULL default '0' )"; $sql = serendipity_db_schema_import($q); $sql = "SELECT * FROM {$serendipity['dbPrefix']}dma_downloadmanager_categories WHERE payload = 'root'"; $root = serendipity_db_query($sql); if (intval($root[0]['node_id']) != 1) { serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}dma_downloadmanager_categories (payload, lft, rgt ) VALUES ('root', 1, 2 )"); $last_insert_id = serendipity_db_insert_id('dma_downloadmanager_categories', 'node_id'); serendipity_db_query("UPDATE {$serendipity['dbPrefix']}dma_downloadmanager_categories SET root_id = $last_insert_id WHERE node_id = $last_insert_id"); } $this->set_config('dl_db_built', '1'); @define('DLMANAGER_UPGRADE_DONE', true); // No further static pages may be called! } switch($built){ case 1: $q = "CREATE TABLE {$serendipity['dbPrefix']}dma_downloadmanager_categories_tmp ( node_id {AUTOINCREMENT} {PRIMARY}, root_id int(10) NOT NULL default '0', payload varchar(64), lft int(10) NOT NULL default '0', rgt int(10) NOT NULL default '0' )"; $sql = serendipity_db_schema_import($q); $q = "INSERT INTO {$serendipity['dbPrefix']}dma_downloadmanager_categories_tmp (node_id, root_id, payload, lft, rgt) SELECT node_id, root_id, payload, lft, rgt FROM {$serendipity['dbPrefix']}dma_downloadmanager_categories;"; $sql = serendipity_db_schema_import($q); $q = "DROP TABLE {$serendipity['dbPrefix']}dma_downloadmanager_categories;"; $sql = serendipity_db_schema_import($q); $q = "CREATE TABLE {$serendipity['dbPrefix']}dma_downloadmanager_categories ( node_id {AUTOINCREMENT} {PRIMARY}, root_id int(10) NOT NULL default '0', payload varchar(64), lft int(10) NOT NULL default '0', rgt int(10) NOT NULL default '0', hidden int(2) NOT NULL default '0' )"; $sql = serendipity_db_schema_import($q); $q = "INSERT INTO {$serendipity['dbPrefix']}dma_downloadmanager_categories (node_id, root_id, payload, lft, rgt) SELECT node_id, root_id, payload, lft, rgt FROM {$serendipity['dbPrefix']}dma_downloadmanager_categories_tmp;"; $sql = serendipity_db_schema_import($q); $q = "DROP TABLE {$serendipity['dbPrefix']}dma_downloadmanager_categories_tmp;"; $sql = serendipity_db_schema_import($q); $this->set_config('dl_db_built', '2'); break; } } /** * uninstall API */ function uninstall(&$propbag) { global $serendipity; serendipity_db_query("DROP TABLE {$serendipity['dbPrefix']}dma_downloadmanager_files"); serendipity_db_query("DROP TABLE {$serendipity['dbPrefix']}dma_downloadmanager_categories"); } /** * dlm sql db function set * * @param type string and db vars * @return result * * serendipity_db_query [ sql, single(true, false), arrtype(both, assoc, num), dberror(true, false), string(array key name), string(array field name) ... ] */ function dlm_sql_db($type=NULL, $whe=NULL) { global $serendipity; switch($type) { case 'DLM_BE_UPDATE': // approve events $sql = "UPDATE {$serendipity['dbPrefix']}dma_downloadmanager_files SET $whe"; $result = serendipity_db_query($sql, true, 'both', true); break; case 'DLM_BE_DELETE_FILE': // delete events $sql = "DELETE FROM {$serendipity['dbPrefix']}dma_downloadmanager_files WHERE $whe"; $result = serendipity_db_query($sql, true, 'both', true); break; case 'DLM_BE_DELETE_CAT': // delete events $sql = "DELETE FROM {$serendipity['dbPrefix']}dma_downloadmanager_categories WHERE $whe"; $result = serendipity_db_query($sql, true, 'both', true); break; case 'DLM_SUBCATS': // mysql_fetch_array :: result is a single array select (TRUE) $sql = "SELECT node1.*, round((node1.rgt-node1.lft-1)/2,0) AS subcats FROM {$serendipity['dbPrefix']}dma_downloadmanager_categories AS node1 WHERE $whe"; $result = serendipity_db_query($sql, true, 'assoc', true); break; case 'DLM_COUNT': // count mysql_num_rows :: result is a single array select (TRUE) $sql = "SELECT COUNT(*) AS num FROM {$serendipity['dbPrefix']}dma_downloadmanager_files WHERE $whe"; $result = serendipity_db_query($sql, true, 'assoc', false); break; case 'DLM_SELECT': // mysql_fetch_array :: result is a single array select (TRUE) $sql = "SELECT * FROM {$serendipity['dbPrefix']}dma_downloadmanager_files WHERE $whe"; $result = serendipity_db_query($sql, true, 'assoc', true); break; case 'DLM_SELECT_ARRAY': // mysql_fetch_array :: result is a multiple array select (FALSE) $sql = "SELECT * FROM {$serendipity['dbPrefix']}dma_downloadmanager_files WHERE $whe"; $result = serendipity_db_query($sql, false, 'assoc', true); break; } return $result; } /** * create plugins global array * * @access private */ function pluginglobs() { global $serendipity; $this->globs = array( 'dateformat' => $this->get_config('dateformat', 'Y-m-d H:i'), 'ftppath' => (!$this->get_config('absincomingpath') ? $serendipity['serendipityPath'] . 'archives/.dlm/ftpin' : $this->get_config('absincomingpath')), 'dlmpath' => (!$this->get_config('absdownloadspath') ? $serendipity['serendipityPath'] . 'archives/.dlm/files' : $this->get_config('absdownloadspath')), 'attention' => (($serendipity['version'][0] < 2) ? '' : ' ') ); } /** * Avoids "bug" on 64-bit PHP systems cutting off utf8 encoded first chars * @see https://bugs.php.net/bug.php?id=62119 * @see https://evertpot.com/271/ * Thanks to: http://php.net/manual/de/function.basename.php#85369 */ function mb_basename($file) { return end(explode('/',$file)); } /** * get relative path */ function getRelPath() { global $serendipity; $c_path = dirname(__FILE__); $b_path = $serendipity['serendipityPath']; if ($b_path[(strlen($b_path)-1)] == '/') { $b_path = substr($b_path, 0, strlen($b_path)-1); } $r_path = '.' . str_replace($b_path, '', $c_path); return $r_path; } /** * error message redirector and Smarty assigning */ function ERRMSG($msg, $type='error') { global $serendipity; if (!is_object($serendipity['smarty'])) { serendipity_smarty_init(); } if ($serendipity['version'][0] < 2) { $serendipity['smarty']->assign(array('div' => 'div', 'tag' => 'p')); } if ($type == 'error') { // assign files of category to smarty $serendipity['smarty']->assign('dlmerr', array('thiserror' => true, 'errormsg' => $msg)); } elseif ( $type == 'success') { // assign files of category to smarty $serendipity['smarty']->assign('dlmerr', array('thiserror' => true, 'successmsg' => $msg)); } elseif ( $type == 'status') { // assign files of category to smarty $serendipity['smarty']->assign('dlmerr', array('thiserror' => true, 'statusmsg' => $msg)); } } /** * Fetch all Categories in Frontend and Backend inclusive root level * * @param Boolean BackEndCall (default false) * @return array **/ function GetAllCats($bec=false) { global $serendipity; $sql = " SELECT node1.node_id AS node_id, node1.root_id AS root_id, node1.payload AS payload, node1.lft AS lft, node1.rgt AS rgt, node1.hidden AS hidden, round((node1.rgt-node1.lft-1)/2,0) AS subcats, ((min(node2.rgt)-node1.rgt-(node1.lft>1))/2) > 0 AS lower, (( (node1.lft-max(node2.lft)>1) )) AS upper, COUNT(*) AS level FROM {$serendipity['dbPrefix']}dma_downloadmanager_categories AS node1, {$serendipity['dbPrefix']}dma_downloadmanager_categories AS node2 WHERE node1.lft BETWEEN node2.lft AND node2.rgt AND (node2.root_id = node1.root_id) AND (node2.node_id != node1.node_id OR node1.lft = 1) AND (node2.root_id = 1)"; $sql .= ($bec === false) ? ((serendipity_db_bool($this->get_config('showhidden_registered', 'false')) && serendipity_userLoggedIn()) ? '' : " AND (node1.hidden != 1) AND (node2.hidden != 1) ") : ''; $sql .= " GROUP BY node1.lft, node1.rgt, node1.node_id, node1.root_id, node1.payload"; $cats = serendipity_db_query($sql, false, 'assoc', true); if (!is_array($cats)) { $cats = array(); } return $cats; } /** * get sub categories */ function GetSubCats($node_id, $user=0) { global $serendipity; $node_id = intval($node_id); $sql = "SELECT node1.node_id AS node_id, node1.payload AS payload, node1.lft AS lft, node1.rgt AS rgt, node1.hidden AS hidden, round((node1.rgt-node1.lft-1)/2,0) AS subcats, COUNT(*) AS level FROM {$serendipity['dbPrefix']}dma_downloadmanager_categories AS node1, {$serendipity['dbPrefix']}dma_downloadmanager_categories AS node2, {$serendipity['dbPrefix']}dma_downloadmanager_categories AS node3 WHERE node1.lft BETWEEN node2.lft AND node2.rgt AND node1.lft BETWEEN node3.lft AND node3.rgt AND node2.root_id = 1 AND node3.node_id = $node_id"; if ($user == 1) { if (serendipity_db_bool($this->get_config('showhidden_registered', 'false')) && serendipity_userLoggedIn()) $sql .= ""; else $sql .= " AND (node1.hidden != 1) "; } $sql .= " GROUP BY node1.lft, node1.rgt, node1.node_id, node1.root_id, node1.payload"; $cats = serendipity_db_query($sql); return $cats; } /** * calculate file size */ function calcFilesize($filesize) { $array = array( 'YB' => 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'ZB' => 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'EB' => 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'PB' => 1024 * 1024 * 1024 * 1024 * 1024, 'TB' => 1024 * 1024 * 1024 * 1024, 'GB' => 1024 * 1024 * 1024, 'MB' => 1024 * 1024, 'KB' => 1024, ); if ($filesize <= 1024) { $filesize = $filesize . ' Bytes'; } foreach($array AS $name => $size) { if ($filesize > $size || $filesize == $size) { $filesize = round((round($filesize / $size * 100) / 100), 2) . ' ' . $name; } } return $filesize; } /** * get mime application */ function getMime($filename) { static $mimetypes = array( "ez" => "application/andrew-inset", "hqx" => "application/mac-binhex40", "cpt" => "application/mac-compactpro", "doc" => "application/msword", "bin" => "application/octet-stream", "dms" => "application/octet-stream", "lha" => "application/octet-stream", "lzh" => "application/octet-stream", "exe" => "application/octet-stream", "class" => "application/octet-stream", "so" => "application/octet-stream", "dll" => "application/octet-stream", "oda" => "application/oda", "pdf" => "application/pdf", "ai" => "application/postscript", "eps" => "application/postscript", "ps" => "application/postscript", "smi" => "application/smil", "smil" => "application/smil", "wbxml" => "application/vnd.wap.wbxml", "wmlc" => "application/vnd.wap.wmlc", "wmlsc" => "application/vnd.wap.wmlscriptc", "bcpio" => "application/x-bcpio", "vcd" => "application/x-cdlink", "pgn" => "application/x-chess-pgn", "cpio" => "application/x-cpio", "csh" => "application/x-csh", "dcr" => "application/x-director", "dir" => "application/x-director", "dxr" => "application/x-director", "dvi" => "application/x-dvi", "spl" => "application/x-futuresplash", "gtar" => "application/x-gtar", "hdf" => "application/x-hdf", "js" => "application/x-javascript", "skp" => "application/x-koan", "skd" => "application/x-koan", "skt" => "application/x-koan", "skm" => "application/x-koan", "latex" => "application/x-latex", "nc" => "application/x-netcdf", "cdf" => "application/x-netcdf", "sh" => "application/x-sh", "shar" => "application/x-shar", "swf" => "application/x-shockwave-flash", "sit" => "application/x-stuffit", "sv4cpio" => "application/x-sv4cpio", "sv4crc" => "application/x-sv4crc", "tar" => "application/x-tar", "tcl" => "application/x-tcl", "tex" => "application/x-tex", "texinfo" => "application/x-texinfo", "texi" => "application/x-texinfo", "t" => "application/x-troff", "tr" => "application/x-troff", "roff" => "application/x-troff", "man" => "application/x-troff-man", "me" => "application/x-troff-me", "ms" => "application/x-troff-ms", "ustar" => "application/x-ustar", "src" => "application/x-wais-source", "xhtml" => "application/xhtml+xml", "xht" => "application/xhtml+xml", "zip" => "application/zip", "au" => "audio/basic", "snd" => "audio/basic", "mid" => "audio/midi", "midi" => "audio/midi", "kar" => "audio/midi", "mpga" => "audio/mpeg", "mp2" => "audio/mpeg", "mp3" => "audio/mpeg", "aif" => "audio/x-aiff", "aiff" => "audio/x-aiff", "aifc" => "audio/x-aiff", "m3u" => "audio/x-mpegurl", "ram" => "audio/x-pn-realaudio", "rm" => "audio/x-pn-realaudio", "rpm" => "audio/x-pn-realaudio-plugin", "ra" => "audio/x-realaudio", "wav" => "audio/x-wav", "pdb" => "chemical/x-pdb", "xyz" => "chemical/x-xyz", "bmp" => "image/bmp", "gif" => "image/gif", "ief" => "image/ief", "jpeg" => "image/jpeg", "jpg" => "image/jpeg", "jpe" => "image/jpeg", "png" => "image/png", "tiff" => "image/tiff", "tif" => "image/tif", "djvu" => "image/vnd.djvu", "djv" => "image/vnd.djvu", "wbmp" => "image/vnd.wap.wbmp", "ras" => "image/x-cmu-raster", "pnm" => "image/x-portable-anymap", "pbm" => "image/x-portable-bitmap", "pgm" => "image/x-portable-graymap", "ppm" => "image/x-portable-pixmap", "prc" => "application/x-pilot", "pdb" => " application/x-pilot-pdb", "rgb" => "image/x-rgb", "xbm" => "image/x-xbitmap", "xpm" => "image/x-xpixmap", "xwd" => "image/x-windowdump", "igs" => "model/iges", "iges" => "model/iges", "msh" => "model/mesh", "mesh" => "model/mesh", "silo" => "model/mesh", "wrl" => "model/vrml", "vrml" => "model/vrml", "css" => "text/css", "html" => "text/html", "htm" => "text/html", "asc" => "text/plain", "txt" => "text/plain", "rtx" => "text/richtext", "rtf" => "text/rtf", "sgml" => "text/sgml", "sgm" => "text/sgml", "tsv" => "text/tab-seperated-values", "wml" => "text/vnd.wap.wml", "wmls" => "text/vnd.wap.wmlscript", "etx" => "text/x-setext", "xml" => "text/xml", "xsl" => "text/xml", "mpeg" => "video/mpeg", "mpg" => "video/mpeg", "mpe" => "video/mpeg", "qt" => "video/quicktime", "mov" => "video/quicktime", "mxu" => "video/vnd.mpegurl", "avi" => "video/x-msvideo", "wmv" => "video/x-msvideo", "movie" => "video/x-sgi-movie", "ice" => "x-conference-xcooltalk", "ics" => "text/calendar" ); $MIMETYPE = array(); $filename = $this->mb_basename($filename); $fileparts = explode(".", $filename); $EXTENSION = $fileparts[(count($fileparts) - 1)]; if (file_exists(dirname(__FILE__) . "/img/dlicons/".$EXTENSION.".png")) { $MIMETYPE['ICON'] = $this->get_config('httppath')."img/dlicons/".$EXTENSION.".png"; } else { $MIMETYPE['ICON'] = $this->get_config('httppath')."img/dlicons/unknown_small.png"; } if (!empty($mimetypes[$EXTENSION]) && trim($mimetypes[$EXTENSION]) != '') { $MIMETYPE['TYPE'] = $mimetypes[$EXTENSION]; } else { $MIMETYPE['TYPE'] = "application/octet-stream"; } return $MIMETYPE; } /** * showShoutPage */ function showShoutPage() { global $serendipity; if (!headers_sent()) { header('HTTP/1.0 200'); header('Status: 200 OK'); } if (!is_object($serendipity['smarty'])) { serendipity_smarty_init(); } if (!serendipity_db_bool($this->get_config('unhideroot'))) { // with DLM version 0.25 we set payload.root to be unhidden.0, to get the expected results in frontend $result = $this->dlm_sql_db('DLM_UPDATE', "hidden = '0' WHERE payload = 'root' AND node_id = '1'"); if ($result) $this->set_config('unhideroot', 'true'); } // assign to smarty and all 3 frontend pages $serendipity['smarty']->assign( array( 'httppath' => $this->get_config('httppath'), 'pagetitle' => $this->get_config('pagetitle'), 'headline' => $this->get_config('headline'), 'dlm_intro' => $this->get_config('intro'), 'dlm_is_registered' => serendipity_db_bool($this->get_config('registered_only', 'false')) ) ); if (isset($_GET['file']) && intval($_GET['file']) >= 1) { // FRONTEND PAGE 3: FILEDETAILS SINGLE FILE if (empty($filename) || $filename == 'none.html') { $filename = 'dlmanager.filedetails.tpl'; } $id = intval($_GET['file']); $catid = intval($_GET['thiscat']); $sqlfe = (serendipity_db_bool($this->get_config('showhidden_registered', 'false')) && serendipity_userLoggedIn()) ? '' : " AND hidden != 1 "; $cat = $this->dlm_sql_db('DLM_SUBCATS', "node_id = $catid" . $sqlfe); if (is_array($cat) && !empty($cat)) { $serendipity['smarty']->assign('showfile', true); // get subcats of cat $ret1 = $this->dlm_sql_db('DLM_COUNT', "catid = $catid"); $serendipity['smarty']->assign( array( 'catname' => $cat['payload'], 'pageurl' => $this->get_config('pageurl'), 'catid' => $catid, 'num_subcats' => intval($cat['subcats']), 'num_files' => intval($ret1['num']), 'basepage' => $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] ) ); // get single file content as a simple linear array, smarty tpl needs no loop, but has no proper $var|print_r output // else take DLM_SELECT_ARRAY and add $file[0] here - remember smarty switches arrays back -1 level in templates! $file = $this->dlm_sql_db('DLM_SELECT', "id = $id"); $mime = $this->getMime($file['realfilename']); if (is_array($file) && !empty($file)) { $temp_array = array('comment' => stripslashes($file['description'])); serendipity_plugin_api::hook_event('frontend_display', $temp_array); // push the file array to hold everything needed $file['id'] = ''; // obfuscated $file['systemfilename'] = ''; // obfuscated $file['iconfile'] = $mime['ICON']; $file['icontype'] = $mime['TYPE']; $file['iconwidth'] = $this->get_config('iconwidth'); $file['iconheight'] = $this->get_config('iconheight'); $file['filesize_field'] = $this->get_config('filesize_field'); $file['filedate_field'] = $this->get_config('filedate_field'); $file['filename'] = stripslashes($file['realfilename']); $file['dlcount'] = intval($file['dlcount']); $file['filesize'] = $this->calcFilesize($file['filesize']); $file['filedate'] = date($this->globs['dateformat'], $file['timestamp']); $file['description'] = $temp_array['comment']; $file['dlurl'] = $serendipity['baseURL'] . ($serendipity['rewrite'] == "none" ? $serendipity['indexFile'] . '?/' : '') . 'plugin/dlfile_'.$id; $serendipity['smarty']->assign('thisfile', $file); } unset($cat); unset($file); } } elseif (isset($_GET['thiscat']) && intval($_GET['thiscat']) > 0) { // FRONTEND PAGE 2: FILELIST OF CATEGORY if (empty($filename) || $filename == 'none.html') $filename = 'dlmanager.filelist.tpl'; $id = intval($_GET['thiscat']); $level = intval($_GET['level']); $sqlfe = (serendipity_db_bool($this->get_config('showhidden_registered', 'false')) && serendipity_userLoggedIn()) ? '' : " AND hidden != 1 "; $cat = $this->dlm_sql_db('DLM_SUBCATS', "node_id = $id" . $sqlfe); if (is_array($cat)) { $ret1 = $this->dlm_sql_db('DLM_COUNT', "catid = $id"); $num_dls = intval($ret1['num']); $serendipity['smarty']->assign( array( 'catname' => $cat['payload'], 'numsubcats' => $cat['subcats'], 'pageurl' => $this->get_config('pageurl'), 'numdls' => intval($num_dls), 'basepage' => $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] ) ); $files = $this->dlm_sql_db('DLM_SELECT_ARRAY', "catid = $id ORDER BY timestamp DESC"); $subcats = $this->GetSubCats($id, 1); if (is_array($subcats) && count($subcats) >= 2) { $serendipity['smarty']->assign('has_subcats', true); foreach($subcats AS $subcat) { if ($level == 1) { $sublvl = 2; } else { $sublvl = 2; } if ($subcat['level'] == ($level + $sublvl)) { $ret = $this->dlm_sql_db('DLM_COUNT', "catid = ".$subcat['node_id']); $num_dls = intval($ret['num']); $nodetb = array('f' => $this->get_config('httppath').'img/f.gif', 'e' => $this->get_config('httppath').'img/e.gif', 'path' => $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . "?serendipity[subpage]=".$this->get_config('pageurl')."&level=".($subcat['level']-1)."&thiscat=".$subcat['node_id'] ); // construct the smarty template array $sctable[] = array('subcat' => $subcat, 'node' => $nodetb, 'num' => $num_dls); } } // assign subcategeories to smarty $serendipity['smarty']->assign('sclist', $sctable); } if (is_array($files)) { if (serendipity_db_bool($this->get_config('showfilename', 'true'))) $serendipity['smarty']->assign('filename_field', $this->get_config('filename_field')); if (serendipity_db_bool($this->get_config('showdownloads', 'true'))) $serendipity['smarty']->assign('dls_field', $this->get_config('dls_field')); if (serendipity_db_bool($this->get_config('showfilesize', 'true'))) $serendipity['smarty']->assign('filesize_field', $this->get_config('filesize_field')); if (serendipity_db_bool($this->get_config('showdate', 'false'))) $serendipity['smarty']->assign('filedate_field', $this->get_config('filedate_field')); $nis = array(); $colspan = 0; if (serendipity_db_bool($this->get_config('showfilename', 'true'))) { ++$colspan; $nis['showfilename'] = true; } if (serendipity_db_bool($this->get_config('showdownloads', 'true'))) { ++$colspan; $nis['showdownloads'] = true; } if (serendipity_db_bool($this->get_config('showfilesize', 'true'))) { ++$colspan; $nis['showfilesize'] = true; } if (serendipity_db_bool($this->get_config('showdate', 'false'))) { ++$colspan; $nis['showdate'] = true; } if (serendipity_db_bool($this->get_config('showdesc_inlist', 'false'))) { $nis['showdesc_inlist'] = true; } foreach($files AS $file) { $infourl = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . "?serendipity[subpage]=".$this->get_config('pageurl')."&thiscat=".$id."&file=".$file['id']; $dlurl = $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/dlfile_' . $file['id']; $mime = $this->getMime($file['realfilename']); $fileinfo = array('file_desc' => str_replace(array("\r\n","\n","\r"),array("
","
","
"), $file['description']), 'filedate' => date($this->globs['dateformat'], $file['timestamp']), 'filesize' => $this->calcFilesize($file['filesize']), 'iconfile' => $mime['ICON'], 'iconwidth' => $this->get_config('iconwidth'), 'iconheight' => $this->get_config('iconheight'), 'icontype' => $mime['TYPE'], 'iconurl' => ($this->get_config('directdl_inlist','no') == 'icon' || $this->get_config('directdl_inlist','no') == 'both') ? $dlurl : $infourl, 'nameurl' => ($this->get_config('directdl_inlist','no') == 'name' || $this->get_config('directdl_inlist','no') == 'both') ? $dlurl : $infourl ); // construct the smarty template array $fltable[] = array('file' => $file, 'info' => $fileinfo, 'is' => $nis, 'col' => $colspan); } // assign files of categeory to smarty $serendipity['smarty']->assign('fltable', $fltable); } } unset($cat); unset($files); } else { // FRONTEND PAGE 1: SUBCATLIST OF ROOT CATEGORY if (empty($filename) || $filename == 'none.html') $filename = 'dlmanager.catlist.tpl'; // build the frontend category array list (in backend = false and as call array (default: false) * @return array */ function buildCategoriesList($admin=false, $seca=false) { $cats = array(); $cats = $this->GetAllCats($admin); foreach($cats AS $cat) { if (($cat['level'] == 1)) { $parent = array(); } if ( ($cat['level'] >= $last['level'])) $parent[$last['level']] = $last; if ($seca === false) { // the frontend and backend category call if ($cat['payload'] != 'root') { $clt[] = $this->buildCat($cat, $parent); } } else { // the backend call (default: false) * @return array */ function buildCat($cat, $parent, $seca=false) { global $serendipity; if ($seca === false) { $ret = $this->dlm_sql_db('DLM_COUNT', "catid = ".$cat['node_id']); $fnum = intval($ret['num']); } else $fnum = NULL; // backend call list => true $catlist = $this->buildCategoriesList(true, true); // assign the backend addcat vars to smarty template page section 'addcat' $serendipity['smarty']->assign('dlmact', array( 'addcat' => true, 'selcatlist' => $catlist ) ); unset($catlist); return; } /** * build the dlm backend categories table content * * @param array A referenced array of categories * @param boolean Default value foldable divs (permanently open = true) * @param string The configs absincomepath * @param int The category id number * @param int The div number (standard=3) * @param int The page number * * @return string */ function backend_dlm_build_categories($cats, $ddiv=false, $absinth='', $cn=1, $dn=0, $pn=0) { global $serendipity; if (is_array($cats) && sizeof($cats) >= 1) { $cc = is_array($cats) ? count($cats)-1 : 0; // else root level would be counted too // build the category list in backend => true and as call list => true $catlist = $this->buildCategoriesList(true, true); // assign the backend editfile vars to smarty template page section 'editfile' $serendipity['smarty']->assign('dlmefe', array( 'thistype' => 'editfile', 'description' => $file['description'], 'realfilename' => $file['realfilename'], 'fileid' => $id, 'mime' => $mime, 'catid' => $catid, 'selcatlist' => $catlist ) ); unset($catlist); return; } } /* vim: set sts=4 ts=4 expandtab : */ ?>