Downloads". If you are upgrading Download Monitor it is a good idea to back-up your database just in case. Version: 2.2.1 Author: Mike Jolley Author URI: http://blue-anvil.com */ /* Copyright 2006 Michael Jolley (email : jolley.small.at.googlemail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ ################################################################################ // Vars and version ################################################################################ $dlm_build="B20081217"; $wp_dlm_root = get_bloginfo('wpurl')."/wp-content/plugins/download-monitor/"; add_option('max_upload_size','10485760','no'); //10mb $max_upload_size = get_option('max_upload_size'); global $table_prefix; $wp_dlm_db = $table_prefix."DLM_DOWNLOADS"; $wp_dlm_db_cats = $table_prefix."DLM_CATS"; $wp_dlm_db_formats = $table_prefix."DLM_FORMATS"; // Get extensions $allowed_e = get_option('wp_dlm_extensions'); if (empty( $allowed_e )) { wp_dlm_init(); $allowed_e = get_option('wp_dlm_extensions'); } $allowed_extentions = explode(",",$allowed_e); include_once('classes/upload.class.php'); load_plugin_textdomain('wp-download_monitor', 'wp-content/plugins/download-monitor/'); ################################################################################ // ADD MEDIA BUTTONS AND FORMS ################################################################################ function wp_dlm_add_media_button() { echo ''.__('Add Download','wp-download_monitor').''; } add_action('media_buttons', 'wp_dlm_add_media_button', 20); ################################################################################ // HANDLE UPDATES ################################################################################ function wp_dlm_update() { global $dlm_build; add_option('wp_dlm_build', $dlm_build, 'Version of DLM plugin', 'no'); if ( get_option('wp_dlm_build') != $dlm_build ) { // Init again wp_dlm_reinstall(); // Show update message echo '
'; _e('

The plugin has recently been updated - You may need to re-save your permalinks settings (Options/settings -> Permalinks) for the changes to occur in your blog.

',"wp-download_monitor"); // Update the build update_option('wp_dlm_build', $dlm_build); } } ################################################################################ // Set up menus within the wordpress admin sections ################################################################################ function wp_dlm_menu() { // Add submenus to the manage menu: add_management_page(__('Downloads','wp-download_monitor'), __('Downloads','wp-download_monitor'), 6,'Downloads', 'wp_dlm_admin'); } add_action('admin_menu', 'wp_dlm_menu'); ################################################################################ // ADMIN HEADER ################################################################################ function wp_dlm_head() { global $wp_db_version; // Provide css based on wordpress version. if ($wp_db_version <= 6124) { // Version 2.3.3 and below echo ''; //wp_enqueue_script('jquery'); // Include JQUERY where needed if( strpos($_SERVER['REQUEST_URI'], 'post.php') || strstr($_SERVER['PHP_SELF'], 'page-new.php') || $_GET['page']=="Downloads" || strstr($_SERVER['PHP_SELF'], 'post-new.php') || strstr($_SERVER['PHP_SELF'], 'page.php') ) { echo ''; } } elseif ($wp_db_version > 6124 && $wp_db_version < 9872) { // 2.5 + 2.6 with new interface echo ''; } else { // 2.7 echo ''; } if ($_GET['activate'] && $_GET['activate']==true) { wp_dlm_init(); } } add_action('admin_head', 'wp_dlm_head'); ################################################################################ // Set up database ################################################################################ function wp_dlm_init() { add_option('wp_dlm_url', '', 'URL for download', 'no'); add_option('wp_dlm_type', 'ID', 'wp_dlm_type', 'no'); add_option('wp_dlm_default_format', '0', 'wp_dlm_default_format', 'no'); add_option('wp_dlm_does_not_exist','','no'); add_option('wp_dlm_image_url',get_bloginfo('wpurl')."/wp-content/plugins/download-monitor/img/download.gif",'no'); add_option('wp_dlm_extensions', '.zip,.pdf,.mp3,.rar', '', 'no'); global $wp_dlm_db,$wp_dlm_db_cats,$wp_dlm_db_formats,$wpdb; $sql = "CREATE TABLE IF NOT EXISTS ".$wp_dlm_db." ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `title` VARCHAR (200) NOT NULL , `filename` LONGTEXT NOT NULL , `file_description` LONGTEXT NULL , `dlversion` VARCHAR (200) NOT NULL , `postDate` DATETIME NOT NULL , `hits` INT (12) UNSIGNED NOT NULL , `user` VARCHAR (200) NOT NULL , `category_id` INT (12) NULL, `members` INT (1) NULL, `mirrors` LONGTEXT NULL, PRIMARY KEY ( `id` ) )"; $result = $wpdb->query($sql); $sql = "CREATE TABLE IF NOT EXISTS ".$wp_dlm_db_cats." ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `name` LONGTEXT NOT NULL , `parent` INT (12) UNSIGNED NOT NULL, PRIMARY KEY ( `id` ) )"; $result = $wpdb->query($sql); $sql = "CREATE TABLE IF NOT EXISTS ".$wp_dlm_db_formats." ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR (250) NOT NULL , `format` LONGTEXT NOT NULL, PRIMARY KEY ( `id` ) )"; $result = $wpdb->query($sql); $q = $wpdb->get_results("select * from $wp_dlm_db;"); if ( empty( $q ) ) { $wpdb->query("TRUNCATE table $wp_dlm_db"); } return; } function wp_dlm_reinstall() { global $wpdb, $wp_dlm_db, $wp_dlm_db_cats; // GET OLD DATA $wpdb->show_errors; $query = sprintf("SELECT * from %s;", $wpdb->escape( $wp_dlm_db )); $result_d = $wpdb->get_results($query); if($result_d && $wpdb->num_rows>0) { $values=""; foreach($result_d as $d) { $id=$d->id; $title=$d->title; $filename=$d->filename; $dlversion=$d->dlversion; $postDate=$d->postDate; $hits=$d->hits; $user=$d->user; $members=$d->members; $category_id=$d->category_id; $mirrors=$d->mirrors; $file_description=$d->file_description; $values.='("'.$id.'","'.$title.'","'.$filename.'","'.$dlversion.'","'.$postDate.'","'.$hits.'","'.$user.'","'.$members.'","'.$category_id.'","'.$mirrors.'","'.$file_description.'"),'; } $values = substr_replace($values,"",-1); } $query = sprintf("SELECT * from %s;", $wpdb->escape( $wp_dlm_db_cats )); $result_cats = $wpdb->get_results($query); if($result_cats && $wpdb->num_rows>0) { $values2=""; foreach($result_cats as $d) { $id=$d->id; $name=$d->name; $parent=$d->parent; $values2.='("'.$id.'","'.$name.'","'.$parent.'"),'; } $values2 = substr_replace($values2,"",-1); } // DROP TABLES $sql = 'DROP TABLE IF EXISTS `'.$wp_dlm_db.'`'; $wpdb->query($sql); $sql = 'DROP TABLE IF EXISTS `'.$wp_dlm_db_cats.'`'; $wpdb->query($sql); wp_dlm_init(); // ADD OLD DATA if (!empty($values)) { $query_ins = sprintf("INSERT INTO %s (id, title, filename, dlversion, postDate, hits, user, members, category_id, mirrors, file_description) VALUES %s;", $wpdb->escape( $wp_dlm_db ), $values); $wpdb->query($query_ins); } if (!empty($values2)) { $query_ins = sprintf("INSERT INTO %s (id, name, parent) VALUES %s;", $wpdb->escape( $wp_dlm_db_cats ), $values2); $wpdb->query($query_ins); } } ################################################################################ // MAGIC QUOTES - checks if magic quotes enabled, disables the add_slashes on // inputs, so ensure add_slashes before interacting with the database ################################################################################ function wp_dlm_magic() { function stripit($in) { if (!is_array($in)) $out = stripslashes($in); else $out = $in; return $out; } if (get_magic_quotes_gpc()){ $_GET = array_map('stripit', $_GET); $_POST = array_map('stripit', $_POST); } return; } ################################################################################ // INSERT BUTTON ON POST SCREEN ################################################################################ function wp_dlm_ins_button() { //set globals global $table_prefix,$wpdb,$wp_dlm_db,$wp_dlm_db_cats; if( strpos($_SERVER['REQUEST_URI'], 'post.php') || strstr($_SERVER['PHP_SELF'], 'page-new.php') || strstr($_SERVER['PHP_SELF'], 'page.php') || strstr($_SERVER['PHP_SELF'], 'post-new.php') ) { $wp_dlm_db_exists = false; // Check table exists $tables = $wpdb->get_results("show tables;"); foreach ( $tables as $table ) { foreach ( $table as $value ) { if ( strtolower($value) == strtolower($wp_dlm_db) ) $wp_dlm_db_exists = true; } } if ($wp_dlm_db_exists==true) { // select all downloads $query_select = sprintf("SELECT * FROM %s ORDER BY id;", $wpdb->escape($wp_dlm_db)); $downloads = $wpdb->get_results($query_select); $js .= ''; $js .= ''; $js .= ''; $js .= ''; if (!empty($downloads)) { $js .= ''; foreach( $downloads as $d ) { $js .= ''; } $js .= ''; // select all cats $query_select_cats = sprintf("SELECT * FROM %s WHERE parent=0 ORDER BY id;", $wpdb->escape( $wp_dlm_db_cats )); $cats = $wpdb->get_results($query_select_cats); if (!empty($cats)) { $js .= ''; foreach ( $cats as $c ) { $js .= ''; $js .= addslashes(get_option_children_cats($c->id, "$c->name — ", 0)); } $js .= ''; } ?> escape($wp_dlm_db_formats), $wpdb->escape($id)); $format = $wpdb->get_row($query_select); return $format->format; } ################################################################################ // INSERT LINK INTO POSTS ################################################################################ function wp_dlm_parse_downloads($data) { if (substr_count($data,"[download#")) { global $wpdb,$wp_dlm_root,$allowed_extentions,$max_upload_size,$wp_dlm_db,$wp_dlm_db_formats,$wp_dlm_db_cats; $wp_dlm_db_exists = false; $def_format = get_option('wp_dlm_default_format'); // Check table exists $tables = $wpdb->get_results("show tables;"); foreach ( $tables as $table ) { foreach ( $table as $value ) { if ( strtolower($value) == strtolower($wp_dlm_db) ) $wp_dlm_db_exists = true; } } if ($wp_dlm_db_exists==true) { //echo "-Table exists-"; $url = get_option('wp_dlm_url'); $downloadurl = get_bloginfo('wpurl').'/'.$url; if (empty($url)) $downloadurl = $wp_dlm_root.'download.php?id='; $downloadtype = get_option('wp_dlm_type'); // Handle Custom Formats (format=...) if (substr_count($data,"#format=")) { preg_match_all("/\[download#([0-9]+)#format=([0-9]+)\]/", $data, $matches, PREG_SET_ORDER); foreach ($matches as $val) { // Get format $format = wp_dlm_get_custom_format($val[2]); if ($format) { // Get download info + insert $query_select = sprintf("SELECT * FROM %s WHERE id = '%s';", $wpdb->escape($wp_dlm_db), $wpdb->escape($val[1])); $d = $wpdb->get_row($query_select); switch ($downloadtype) { case ("Title") : $downloadlink = urlencode($d->title); break; case ("Filename") : $downloadlink = $d->filename; $links = explode("/",$downloadlink); $downloadlink = end($links); break; default : $downloadlink = $d->id; break; } $fpatts = array(); $fsubs = array(); $fpatts[] = '{url}'; $fsubs[] = $downloadurl.$downloadlink; $fpatts[] = '{version}'; $fsubs[] = $d->dlversion; $fpatts[] = '{title}'; $fsubs[] = $d->title; $fpatts[] = '{size}'; $fsubs[] = wp_dlm_get_size($d->filename); $fpatts[] = '{hits}'; $fsubs[] = $d->hits; $fpatts[] = '{image_url}'; $fsubs[] = get_option('wp_dlm_image_url'); if ($d->category_id>0) { $fpatts[] = '{category}'; $c = $wpdb->get_row("SELECT name FROM $wp_dlm_db_cats where id=".$d->category_id." LIMIT 1;"); $fsubs[] = $c->name; preg_match("/{category,([^,{}]*),([^,{}]*)}/", $format, $match); $fpatts[] = $match[0]; $fsubs[] = $match[1].$c->name.$match[2]; } else { $fpatts[] = '{category}'; $fsubs[] = ""; preg_match("/{category,([^,{}]*),([^,{}]*)}/", $format, $match); $fpatts[] = $match[0]; $fsubs[] = ""; } $fpatts[] = '{description}'; $fsubs[] = $d->file_description; $fpatts[] = '{description-autop}'; $fsubs[] = wpautop($d->file_description); preg_match("/{description,([^,{}]*),([^,{}]*)}/", $format, $match); $fpatts[] = $match[0]; if ($d->file_description) $fsubs[] = $match[1].$d->file_description.$match[2]; else $fsubs[] = ""; preg_match("/{description-autop,([^,{}]*),([^,{}]*)}/", $format, $match); $fpatts[] = $match[0]; if ($d->file_description) $fsubs[] = $match[1].wpautop($d->file_description).$match[2]; else $fsubs[] = ""; $code = str_replace($fpatts, $fsubs, $format); $data = str_replace($val[0],$code,$data); } } } // select all downloads $query_select = sprintf("SELECT * FROM %s ORDER BY id;", $wpdb->escape($wp_dlm_db)); $downloads = $wpdb->get_results($query_select); if (!empty($downloads)) { //echo "-Downloads found-"; $patts = array(); $subs = array(); foreach($downloads as $d) { switch ($downloadtype) { case ("Title") : $downloadlink = urlencode($d->title); break; case ("Filename") : $downloadlink = $d->filename; $links = explode("/",$downloadlink); $downloadlink = end($links); break; default : $downloadlink = $d->id; break; } ################################################################################ // Define Patterns ################################################################################ // Regular download link - NOW USES DEFAULT FORMAT if ($def_format==0) { if (!empty($d->dlversion)) $link = 'dlversion.' '.__("downloaded","wp-download_monitor").' '.$d->hits.' '.__("times","wp-download_monitor").'" >'.$d->title.' ('.$d->hits.')'; else $link = 'hits.' '.__("times","wp-download_monitor").'" >'.$d->title.' ('.$d->hits.')'; } else { // Get Custom formatted version $format = wp_dlm_get_custom_format($def_format); $fpatts = array(); $fsubs = array(); $fpatts[] = '{url}'; $fsubs[] = $downloadurl.$downloadlink; $fpatts[] = '{version}'; $fsubs[] = $d->dlversion; $fpatts[] = '{title}'; $fsubs[] = $d->title; $fpatts[] = '{size}'; $fsubs[] = wp_dlm_get_size($d->filename); $fpatts[] = '{hits}'; $fsubs[] = $d->hits; $fpatts[] = '{image_url}'; $fsubs[] = get_option('wp_dlm_image_url'); if ($d->category_id>0) { $fpatts[] = '{category}'; $c = $wpdb->get_row("SELECT name FROM $wp_dlm_db_cats where id=".$d->category_id." LIMIT 1;"); $fsubs[] = $c->name; preg_match("/{category,([^,{}]*),([^,{}]*)}/", $format, $match); $fpatts[] = $match[0]; $fsubs[] = $match[1].$c->name.$match[2]; } else { $fpatts[] = '{category}'; $fsubs[] = ""; preg_match("/{category,([^,{}]*),([^,{}]*)}/", $format, $match); $fpatts[] = $match[0]; $fsubs[] = ""; } $fpatts[] = '{description}'; $fsubs[] = $d->file_description; $fpatts[] = '{description-autop}'; $fsubs[] = wpautop($d->file_description); preg_match("/{description,([^,{}]*),([^,{}]*)}/", $format, $match); $fpatts[] = $match[0]; if ($d->file_description) $fsubs[] = $match[1].$d->file_description.$match[2]; else $fsubs[] = ""; preg_match("/{description-autop,([^,{}]*),([^,{}]*)}/", $format, $match); $fpatts[] = $match[0]; if ($d->file_description) $fsubs[] = $match[1].wpautop($d->file_description).$match[2]; else $fsubs[] = ""; $link = str_replace($fpatts, $fsubs, $format); } $patts[] = "[download#" . $d->id . "]"; $subs[] = $link; // No hit counter if (!empty($d->dlversion)) $link = 'dlversion.' '.__("downloaded","wp-download_monitor").' '.$d->hits.' '.__("times","wp-download_monitor").'" >'.$d->title.''; else $link = 'hits.' '.__("times","wp-download_monitor").'" >'.$d->title.''; $patts[] = "[download#" . $d->id . "#nohits]"; $subs[] = $link; // URL only $link = $downloadurl.$downloadlink; $patts[] = "[download#" . $d->id . "#url]"; $subs[] = $link; // Description only $link = $d->file_description; $patts[] = "[download#" . $d->id . "#description]"; $subs[] = $link; // Description (autop) only $link = wpautop($d->file_description); $patts[] = "[download#" . $d->id . "#description_autop]"; $subs[] = $link; // Hits only $link = $d->hits; $patts[] = "[download#" . $d->id . "#hits]"; $subs[] = $link; // Image link if (!empty($d->dlversion)) $link = 'title.' '.__("Version","wp-download_monitor").' '.$d->dlversion.'">'.__(title.' '.__("Version","wp-download_monitor").' '.$d->dlversion.'" />

'.__("Downloaded a total of","wp-download_monitor").' '.$d->hits.' '.__("times","wp-download_monitor").'

'; else $link = 'title.'">'.__(title.'" />

'.__("Downloaded a total of","wp-download_monitor").' '.$d->hits.' '.__("times","wp-download_monitor").'

'; $patts[] = "[download#" . $d->id . "#image]"; $subs[] = $link; // Regular download link WITH filesize if (!empty($d->dlversion)) $link = 'dlversion.' '.__("downloaded","wp-download_monitor").' '.$d->hits.' '.__("times","wp-download_monitor").'" >'.$d->title.' ('.$d->hits.') - '.wp_dlm_get_size($d->filename).''; else $link = 'hits.' '.__("times","wp-download_monitor").'" >'.$d->title.' ('.$d->hits.') - '.wp_dlm_get_size($d->filename).''; $patts[] = "[download#" . $d->id . "#size]"; $subs[] = $link; // No hit counter + filesize if (!empty($d->dlversion)) $link = 'dlversion.' '.__("downloaded","wp-download_monitor").' '.$d->hits.' '.__("times","wp-download_monitor").'" >'.$d->title.' ('.wp_dlm_get_size($d->filename).')'; else $link = 'hits.' '.__("times","wp-download_monitor").'" >'.$d->title.' ('.wp_dlm_get_size($d->filename).')'; $patts[] = "[download#" . $d->id . "#size#nohits]"; $subs[] = $link; } return str_replace($patts, $subs, $data); } else return $data; } else return $data; } else return $data; } add_filter('the_content', 'wp_dlm_parse_downloads',1,1); add_filter('the_excerpt', 'wp_dlm_parse_downloads',1,1); add_filter('the_meta_key', 'wp_dlm_parse_downloads',1,1); add_filter('widget_text', 'wp_dlm_parse_downloads',1,1); add_filter('widget_title', 'wp_dlm_parse_downloads',1,1); ################################################################################ // CATEGORIES - INSERT LINK INTO POSTS ################################################################################ function wp_dlm_parse_downloads_cats($data) { if (substr_count($data,"[download_cat#")) { global $wpdb,$wp_dlm_root,$allowed_extentions,$max_upload_size,$wp_dlm_db,$wp_dlm_db_cats; $wp_dlm_db_exists = false; // Check table exists $tables = $wpdb->get_results("show tables;"); foreach ( $tables as $table ) { foreach ( $table as $value ) { if ( strtolower($value) == strtolower($wp_dlm_db) ) $wp_dlm_db_exists = true; } } if ($wp_dlm_db_exists==true) { $url = get_option('wp_dlm_url'); $downloadurl = get_bloginfo('wpurl').'/'.$url; if (empty($url)) $downloadurl = $wp_dlm_root.'download.php?id='; $downloadtype = get_option('wp_dlm_type'); // select all cats $query_select = sprintf("SELECT * FROM %s ORDER BY id;", $wpdb->escape($wp_dlm_db_cats)); $cats = $wpdb->get_results($query_select); if (!empty($cats)) { $patts = array(); $subs = array(); foreach($cats as $c) { // Get downloads for cat and put in ul $links = ''; $patts[] = "[download_cat#" . $c->id . "]"; $subs[] = $links; } return str_replace($patts, $subs, $data); }else return $data; } else return $data; } else return $data; } add_filter('the_content', 'wp_dlm_parse_downloads_cats',1,1); add_filter('the_excerpt', 'wp_dlm_parse_downloads_cats',1,1); add_filter('the_meta_key', 'wp_dlm_parse_downloads_cats',1,1); add_filter('widget_text', 'wp_dlm_parse_downloads_cats',1,1); add_filter('widget_title', 'wp_dlm_parse_downloads_cats',1,1); // Formats file size function wp_dlm_get_size($path) { $path = str_replace(get_bloginfo('wpurl'),"./",$path); if (file_exists($path)) { $size = filesize($path); if ($size) { $bytes = array('bytes','KB','MB','GB','TB'); foreach($bytes as $val) { if($size > 1024){ $size = $size / 1024; }else{ break; } } return round($size, 2)." ".$val; } } } // Function used later to output categories function get_option_children_cats($parent,$chain,$current,$showid=1) { global $wp_dlm_db_cats,$wpdb; $sql = sprintf("SELECT * FROM %s WHERE parent=%s ORDER BY id;", $wpdb->escape( $wp_dlm_db_cats ), $wpdb->escape( $parent )); $scats = $wpdb->get_results($sql); if (!empty($scats)) { foreach ( $scats as $c ) { $string.= ''; $string.= get_option_children_cats($c->id, "$chain$c->name — ",$current); } } return $string; } ################################################################################ // ADMIN PAGE ################################################################################ function wp_dlm_admin() { //set globals global $wpdb,$wp_dlm_root,$allowed_extentions,$max_upload_size,$wp_dlm_db,$wp_dlm_db_cats,$wp_dlm_db_formats; // turn off magic quotes wp_dlm_magic(); wp_dlm_update(); // DEFINE QUERIES // select all downloads if (empty( $_POST['dlhits'] )) $_POST['dlhits'] = 0; // select a downloads $query_select_1 = sprintf("SELECT * FROM %s WHERE id=%s;", $wpdb->escape( $wp_dlm_db ), $wpdb->escape( $_GET['id'] )); $action = $_GET['action']; if (!empty($action)) { switch ($action) { case "add" : $method = $_REQUEST['method']; if (!empty($method)) { //SAVE if ( $_POST['sub'] ) { //get postdata $title = htmlspecialchars(trim($_POST['title'])); $filename = htmlspecialchars(trim($_POST['filename'])); $dlversion = htmlspecialchars(trim($_POST['dlversion'])); $dlhits = htmlspecialchars(trim($_POST['dlhits'])); $postDate = $_POST['postDate']; $user = $_POST['user']; $members = (isset($_POST['memberonly'])) ? 1 : 0; $download_cat = $_POST['download_cat']; $mirrors = htmlspecialchars(trim($_POST['mirrors'])); $file_description = trim($_POST['file_description']); //validate fields if (empty( $_POST['title'] )) $errors.=__('
Required field: Title omitted
',"wp-download_monitor"); if (empty( $_POST['dlhits'] )) $_POST['dlhits'] = 0; if (!is_numeric($_POST['dlhits'] )) $errors.=__('
Invalid hits entered
',"wp-download_monitor"); if ($method=="upload") { //attempt to upload file if ( empty($errors ) ) { global $max_upload_size; $max_size = $max_upload_size; // the max. size for uploading $my_upload = new wp_dlm_file_upload; $my_upload->upload_dir = "../wp-content/uploads/"; // the folder for the uploaded files (you may have to create this folder) $my_upload->extensions = $allowed_extentions; // specify the allowed extensions here $my_upload->max_length_filename = 100; // change this value to fit your field length in your database (standard 100) $my_upload->rename_file = false; //upload it $my_upload->the_temp_file = $_FILES['upload']['tmp_name']; $my_upload->the_file = $_FILES['upload']['name']; $my_upload->http_error = $_FILES['upload']['error']; $my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; $my_upload->do_filename_check = "n"; if ($my_upload->upload()) { $full_path = $my_upload->upload_dir.$my_upload->file_copy; $info = $my_upload->show_error_string(); } else $errors = '
'.$my_upload->show_error_string().'
'; $filename = get_bloginfo('wpurl')."/wp-content/uploads/".$my_upload->file_copy; } } elseif ($method=="url") { if ( empty( $_POST['filename']) ) $errors.=__('
No file selected
',"wp-download_monitor"); } else $errors.=__('
Error
',"wp-download_monitor"); //save to db if ( empty($errors ) ) { if ($my_upload->replace=="y") { $query_del = sprintf("DELETE FROM %s WHERE filename='%s';", $wpdb->escape( $wp_dlm_db ), $wpdb->escape( $filename )); $wpdb->query($query_del); } $query_add = sprintf("INSERT INTO %s (title, filename, dlversion, postDate, hits, user, members,category_id, mirrors, file_description) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", $wpdb->escape( $wp_dlm_db ), $wpdb->escape( $_POST['title'] ), $wpdb->escape( $filename ), mysql_real_escape_string( $_POST['dlversion'] ), $wpdb->escape( $_POST['postDate'] ), mysql_real_escape_string( $_POST['dlhits'] ), $wpdb->escape( $_POST['user'] ), $wpdb->escape( $members ), $wpdb->escape($download_cat), $wpdb->escape($mirrors), $wpdb->escape($file_description) ); $result = $wpdb->query($query_add); if ($result) { if (empty($info)) echo '

'.__("Download added Successfully","wp-download_monitor").'

'; else echo '

'.__("Download added Successfully","wp-download_monitor").' - '.$info.'

'; $_POST['add_n']=""; $_POST['add_e']=""; $show=true; } else _e('
Error saving to database
',"wp-download_monitor"); break; } else echo $errors; } } if (!empty( $_POST['add_n'] )) { //ADD DOWNLOAD FORM global $max_upload_size; $max_size = $max_upload_size; // the max. size for uploading ?>

:
:
:
:

.

delete all current stats for the currently uploaded file. If you wish to keep existing stats, go to the files Edit page instead and re-upload there.',"wp-download_monitor"); ?>

/>

" />

" /> user_login.'" />'; ?>

:
:
:
:
:

/>

" />

" /> user_login.'" />'; ?>
Invalid Add method, go back.

',"wp-download_monitor"); break; case "delete" : $d = $wpdb->get_row($query_select_1); global $wp_db_version; if ($wp_db_version>=9872) { $adminpage = 'tools.php'; } else { $adminpage = 'edit.php'; } ?>

"title; ?>"

'.__('Required field: Title omitted',"wp-download_monitor").''; if (empty( $_POST['dlfilename'] )) $errors.='
'.__('Required field: File URL omitted',"wp-download_monitor").'
'; if (empty( $_POST['dlhits'] )) $_POST['dlhits'] = 0; if (!is_numeric($_POST['dlhits'] )) $errors.='
'.__('Invalid hits entered',"wp-download_monitor").'
'; $members = (isset($_POST['memberonly'])) ? 1 : 0; if (empty($errors)) { if (!empty($_FILES['upload']['tmp_name'])) { //user is replacing the file global $max_upload_size; $max_size = $max_upload_size; // the max. size for uploading $my_upload = new wp_dlm_file_upload; $my_upload->upload_dir = "../wp-content/uploads/"; // "files" is the folder for the uploaded files (you have to create this folder) $my_upload->extensions = $allowed_extentions; // specify the allowed extensions here $my_upload->max_length_filename = 100; // change this value to fit your field length in your database (standard 100) $my_upload->rename_file = false; //upload it $my_upload->the_temp_file = $_FILES['upload']['tmp_name']; $my_upload->the_file = $_FILES['upload']['name']; $my_upload->http_error = $_FILES['upload']['error']; $my_upload->replace = "y"; $my_upload->do_filename_check = "n"; if ($my_upload->upload()) { $full_path = $my_upload->upload_dir.$my_upload->file_copy; $info = $my_upload->show_error_string(); } else $errors.= '
'.$my_upload->show_error_string().'
'; $filename = get_bloginfo('wpurl')."/wp-content/uploads/".$my_upload->file_copy; // update download & file $query_update_file = sprintf("UPDATE %s SET title='%s', dlversion='%s', hits='%s', filename='%s', postDate='%s', user='%s',members='%s',category_id='%s', mirrors='%s', file_description='%s' WHERE id=%s;", $wpdb->escape( $wp_dlm_db ), $wpdb->escape( $_POST['title'] ), mysql_real_escape_string( $_POST['dlversion'] ), mysql_real_escape_string( $_POST['dlhits'] ), $wpdb->escape( $filename ), $wpdb->escape( $_POST['postDate'] ), $wpdb->escape( $_POST['user'] ), $wpdb->escape( $members ), $wpdb->escape( $_POST['download_cat'] ), $wpdb->escape( trim($_POST['mirrors']) ) , $wpdb->escape( trim($_POST['file_description']) ) , $wpdb->escape( $_GET['id'] )); //replacing file $d = $wpdb->get_row($query_update_file); $show=true; echo '

'.__('Download edited Successfully',"wp-download_monitor").' - '.$info.'

'; } else { //not replacing file $query_update = sprintf("UPDATE %s SET title='%s', dlversion='%s', hits='%s', filename='%s',members='%s',category_id='%s', mirrors='%s', file_description='%s' WHERE id=%s;", $wpdb->escape( $wp_dlm_db ), $wpdb->escape( $_POST['title'] ), mysql_real_escape_string( $_POST['dlversion'] ), mysql_real_escape_string( $_POST['dlhits'] ), $wpdb->escape( $_POST['dlfilename'] ), $wpdb->escape( $members ), $wpdb->escape( $_POST['download_cat'] ), $wpdb->escape( trim($_POST['mirrors']) ) , $wpdb->escape( trim($_POST['file_description']) ) , $wpdb->escape( $_GET['id'] )); $d = $wpdb->get_row($query_update); $show=true; echo '

'.__('Download edited Successfully',"wp-download_monitor").'

'; } } if (!empty($errors)) { echo $errors; $title = $_POST['title']; $dlversion = $_POST['dlversion']; $dlhits = $_POST['dlhits']; $dlfilename =$_POST['dlfilename']; $members = (isset($_POST['memberonly'])) ? 1 : 0; $download_cat = $_POST['download_cat']; $mirrors = $_POST['mirrors']; $file_description = $_POST['file_description']; } } else { //load values $d = $wpdb->get_row($query_select_1); $title = $d->title; $dlversion = $d->dlversion; $dlhits = $d->hits; $dlfilename = $d->filename; if (empty( $dlhits )) $dlhits = 0; $members = $d->members; $download_cat = $d->category_id; $mirrors = $d->mirrors; $file_description = $d->file_description; } if ($show==false) { ?>

:
:
:
:

/>
:

Here you can upload/re-upload the file from your computer. This will Overwrite any existing files with the same name, but will keep stats in-tact.

',"wp-download_monitor"); ?>

.
" /> user_login.'" />'; ?>

" />

get_row($query_select_1); $file = $d->filename; if ( strstr ( $d->filename, "/wp-content/uploads/" ) ) { $path = get_bloginfo('wpurl')."/wp-content/uploads/"; $file = str_replace( $path , "" , $d->filename); if(is_file('../wp-content/uploads/'.$file)){ chmod('../wp-content/uploads/'.$file, 0777); unlink('../wp-content/uploads/'.$file); } } $query_delete = sprintf("DELETE FROM %s WHERE id=%s;", $wpdb->escape( $wp_dlm_db ), $wpdb->escape( $_GET['id'] )); $wpdb->query($query_delete); echo '

'.__('Download deleted Successfully',"wp-download_monitor").'

'; // Truncate table if empty global $wp_dlm_db; $q=$wpdb->get_results("select * from $wp_dlm_db;"); if ( empty( $q ) ) { $wpdb->query("TRUNCATE table $wp_dlm_db"); } $show=true; break; case "cancelled" : $show=true; break; case "saveurl" : $url = $_POST['url']; update_option('wp_dlm_url', trim($url)); update_option('wp_dlm_type', $_POST['type']); if (!empty($url)) { echo '
'; _e('

Download URL updated - You need to re-save your permalinks settings (Options/settings -> Permalinks) for the changes to occur in your blog.

If your .htaccess file cannot be written to by WordPress, add the following to your .htaccess file above the "# BEGIN WordPress" line:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^download/(.*) wp-content/plugins/download-monitor/download.php?id=$1 [L]

replacing "download/" with your custom url.

',"wp-download_monitor"); echo '
'; } else { echo '
'; _e('

Download URL updated - You need to re-save your permalinks settings (Options/settings -> Permalinks) for the changes to occur in your blog.

If your .htaccess file cannot be written to by WordPress, remove the following from your .htaccess file if it exists above the "# BEGIN WordPress" line:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^download/(.*) wp-content/plugins/download-monitor/download.php?id=$1 [L]

replacing "download/" with your previous custom url.

',"wp-download_monitor"); echo '
'; } $save_url = true; $show=true; break; case "saveoptions" : update_option('wp_dlm_image_url', $_POST['wp_dlm_image_url']); update_option('wp_dlm_default_format', $_POST['wp_dlm_default_format']); update_option('wp_dlm_does_not_exist', $_POST['wp_dlm_does_not_exist']); update_option('wp_dlm_member_only', $_POST['wp_dlm_member_only']); $allowed = $_POST['extensions']; $allowed_a=array(); $allow = array(); $allowed_a=explode(",",$allowed); foreach ($allowed_a as $a) { $a = trim($a); $allow[] = $a; } $allowed = implode(",",$allow); update_option('wp_dlm_extensions', $allowed); // Get extensions $allowed_e = get_option('wp_dlm_extensions'); $allowed_extentions = explode(",",$allowed_e); $save_opt=true; echo '
'; _e('

Options updated

',"wp-download_monitor"); echo '
'; $show=true; break; case "categories" : $name = $_POST['cat_name']; if (!empty($name)) { $parent = $_POST['cat_parent']; if (!$parent) $parent=0; $query_ins = sprintf("INSERT INTO %s (name, parent) VALUES ('%s','%s')", $wpdb->escape( $wp_dlm_db_cats ), $wpdb->escape( $name ), $wpdb->escape( $parent )); $wpdb->query($query_ins); echo '

'.__('Category added',"wp-download_monitor").'

'; $ins_cat=true; } $show=true; break; case "deletecat" : $id = $_GET['id']; // Get 'em $delete_cats=array(); $delete_cats[]=$id; // Sub cats function dlm_get_cats($delete_cats) { global $wpdb, $wp_dlm_db_cats; $query = sprintf("SELECT id from %s WHERE parent IN (%s);", $wpdb->escape( $wp_dlm_db_cats ), $wpdb->escape( implode(",",$delete_cats) )); $res = $wpdb->get_results($query); $b=sizeof($delete_cats); if ($res) { foreach($res as $r) { if (!in_array($r->id,$delete_cats)) $delete_cats[]=$r->id; } } $a=sizeof($delete_cats); while ($b!=$a) { $query = sprintf("SELECT id from %s WHERE parent IN (%s);", $wpdb->escape( $wp_dlm_db_cats ), $wpdb->escape( implode(",",$delete_cats) )); $res = $wpdb->get_results($query); $b=sizeof($delete_cats); if ($res) { foreach($res as $r) { if (!in_array($r->id,$delete_cats)) $delete_cats[]=$r->id; } } $a=sizeof($delete_cats); } return $delete_cats; } $delete_cats = dlm_get_cats($delete_cats); // Delete $query_delete = sprintf("DELETE FROM %s WHERE id IN (%s);", $wpdb->escape( $wp_dlm_db_cats ), $wpdb->escape( implode(",",$delete_cats) )); $wpdb->query($query_delete); // Remove from downloads $query_update = sprintf("UPDATE %s SET category_id='N/A' WHERE category_id IN (%s);", $wpdb->escape( $wp_dlm_db ), $wpdb->escape( implode(",",$delete_cats) )); $d = $wpdb->get_row($query_update); echo '

'.__('Category deleted Successfully',"wp-download_monitor").'

'; $ins_cat=true; $show=true; break; case "reinstall" : wp_dlm_reinstall(); echo '

'.__('Database recreated',"wp-download_monitor").'

'; $show=true; break; case "formats" : if ($_POST['savef']) { $loop = 0; if (is_array($_POST['formatfieldid'])) { foreach($_POST['formatfieldid'] as $formatid) { if ($_POST['formatfield'][$loop]) { $query_update = sprintf("UPDATE %s SET `format`='%s' WHERE id = %s;", $wpdb->escape( $wp_dlm_db_formats ), $wpdb->escape( $_POST['formatfield'][$loop] ), $wpdb->escape( $formatid )); $wpdb->query($query_update); } $loop++; } echo '

'.__('Formats updated',"wp-download_monitor").'

'; $ins_format=true; } } else { $name = $_POST['format_name']; $format = $_POST['format']; if (!empty($name) && !empty($format)) { $query_ins = sprintf("INSERT INTO %s (name, format) VALUES ('%s','%s')", $wpdb->escape( $wp_dlm_db_formats ), $wpdb->escape( $name ), $wpdb->escape( $format )); $wpdb->query($query_ins); echo '

'.__('Format added',"wp-download_monitor").'

'; $ins_format=true; } } $show=true; break; case "deleteformat" : $id = $_GET['id']; // Delete $query_delete = sprintf("DELETE FROM %s WHERE id=%s;", $wpdb->escape( $wp_dlm_db_formats ), $wpdb->escape( $id )); $wpdb->query($query_delete); echo '

'.__('Format deleted Successfully',"wp-download_monitor").'

'; $ins_format=true; $show=true; break; } } //show downloads page if ( ($show==true) || ( empty($action) ) ) { $downloadurl = get_option('wp_dlm_url'); $downloadtype = get_option('wp_dlm_type'); ?>


" /> " />


escape($wp_dlm_db)); // Figure out the limit for the query based on the current page number. $from = (($page * 10) - 10); $paged_select = sprintf("SELECT * FROM %s ORDER BY %s LIMIT %s,10;", $wpdb->escape( $wp_dlm_db ), $wpdb->escape( $sort ), $wpdb->escape( $from )); $download = $wpdb->get_results($paged_select); $total = $wpdb->get_var($total_results); // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total / 10); if (!empty($download)) { echo ''; foreach ( $download as $d ) { $date = date("jS M Y", strtotime($d->postDate)); $path = get_bloginfo('wpurl')."/wp-content/uploads/"; $file = str_replace($path, "", $d->filename); $links = explode("/",$file); $file = end($links); echo (''); echo ''; if (strlen($d->file_description) > 50) $file_description = substr(htmlspecialchars($d->file_description), 0, strrpos(substr(htmlspecialchars($d->file_description), 0, 50), ' ')) . ' [...]'; else $file_description = htmlspecialchars($d->file_description); echo ''; } echo ''; } else echo ''; // FIXED: 1.6 - Colspan changed ?>
'.$d->id.' '.$d->title.' '.$file.' '; if ($d->category_id=="" || $d->category_id==0) echo "N/A"; else { $c = $wpdb->get_row("SELECT * FROM $wp_dlm_db_cats where id=".$d->category_id." LIMIT 1;"); $chain = $c->name; while ($c->parent>0) { $c = $wpdb->get_row("SELECT * FROM $wp_dlm_db_cats where id=".$c->parent." LIMIT 1;"); $chain = $c->name.' — '.$chain; } echo $d->category_id." - ".$chain; } echo ' '.$d->dlversion.''.nl2br($file_description).' '; if ($d->members) echo __('Yes',"wp-download_monitor"); else echo __('No',"wp-download_monitor"); echo ' '.$date.' by '.$d->user.' '.$d->hits.' Edit Delete
'.__('No downloads added yet.',"wp-download_monitor").'
1) { // FIXED: 1.6 - Stops it displaying when un-needed // Build Page Number Hyperlinks if($page > 1){ $prev = ($page - 1); echo "« ".__('Previous',"wp-download_monitor")." "; } else echo "« ".__('Previous',"wp-download_monitor").""; for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo " $i "; } else { echo " $i "; } } // Build Next Link if($page < $total_pages){ $next = ($page + 1); echo "".__('Next',"wp-download_monitor")." »"; } else echo "".__('Next',"wp-download_monitor")." »"; } ?>

You can categorise downloads using these categories. You can then show groups of downloads using the category tags or a dedicated download page (see documentation). Please note, deleting a category also deletes it\'s child categories.

',"wp-download_monitor"); ?>
escape( $wp_dlm_db_cats ), $wpdb->escape( $parent )); $scats = $wpdb->get_results($sql); if (!empty($scats)) { foreach ( $scats as $c ) { echo ''; get_children_cats($c->id, "$chain$c->name — "); } } return; } $query_select_cats = sprintf("SELECT * FROM %s WHERE parent=0 ORDER BY id;", $wpdb->escape( $wp_dlm_db_cats )); $cats = $wpdb->get_results($query_select_cats); if (!empty($cats)) { foreach ( $cats as $c ) { echo ''; get_children_cats($c->id, "$c->name — "); } } else { echo ''; } ?>
'.$c->id.''.$chain.''.$c->name.'Delete
'.$c->id.''.$c->name.'Delete
'.__('No categories exist',"wp-download_monitor").'

:
:

" />

This allows you to define formats in which to output your downloads however you want.

',"wp-download_monitor"); ?>
escape( $wp_dlm_db_formats )); $formats = $wpdb->get_results($query_select_formats); if (!empty($formats)) { foreach ( $formats as $f ) { echo ''; } } else { echo ''; } ?>
'.$f->id.''.$f->name.' Delete
'.__('No formats exist',"wp-download_monitor").'

" />

Use the following tags in your custom format:

  • {url} - Url of download (does not include hyperlink)
  • {version} - Version of download
  • {title} - Title of download
  • {size} - Filesize of download
  • {category,before,after} or {category} - Download Category. Replace "before" with preceding text/html and "after" with succeeding text/html.
  • {hits} - Current hit count
  • {image_url} - URL of the download image
  • {description,before,after} or {description} - Description you gave download. Not outputted if none set. Replace "before" with preceding text/html and "after" with succeeding text/html.
  • {description-autop,before,after} or {description-autop} - Description formatted with autop (converts double line breaks to paragraphs)
',"wp-download_monitor"); ?>
:
:

" />

Set the url of the downloads, e.g. download/. In this example a download link would look like this: http://yoursite.com/download/2.

Leave this option blank to use the default download path (wp-content/plugins/download-monitor/download.php?id=)

You can also choose how to link to the download in it\'s url, e.g. selecting "filename" would make the link appear as http://yoursite.com/download/filename.zip.

',"wp-download_monitor"); ?>
: /

" />

: " name="extensions" />
: Leave blank for no redirect.
: Leave blank for no redirect.
: #image download tag and the {image_url} tag on this page. Please use an absolute url (e.g. http://yoursite.com/image.gif).',"wp-download_monitor"); ?>
:

" />

This will delete the old download monitor tables and recreate them. You should only do this as a last resort if experiencing database errors after updating the plugin. Download monitor will attempt to re-add any downloads currently in the database.

',"wp-download_monitor"); ?> WARNING: THIS MAY DELETE DOWNLOAD DATA IN THE DATABASE; BACKUP YOUR DATABASE FIRST!

',"wp-download_monitor"); ?>

" />

Need help? FAQ, Usage instructions and other notes can be found on the plugin page here.

',"wp-download_monitor"); ?> The Wordpress Download monitor plugin was created by Mike Jolley. The development of this plugin took a lot of time and effort, sp please don\'t forget to donate if you found this plugin useful to ensure continued development.

',"wp-download_monitor"); ?>
escape( $wp_dlm_db ), $wpdb->escape( $no )); break; case (2) : $query = sprintf("SELECT * FROM %s ORDER BY postDate DESC LIMIT %s;", $wpdb->escape( $wp_dlm_db ), $wpdb->escape( $no )); break; case (3) : $query = sprintf("SELECT * FROM %s ORDER BY rand() LIMIT %s;", $wpdb->escape( $wp_dlm_db ), $wpdb->escape( $no )); break; } if (!empty($query)) { $url = get_option('wp_dlm_url'); $downloadurl = get_bloginfo('wpurl').'/'.$url; if (empty($url)) $downloadurl = $wp_dlm_root.'download.php?id='; $dl = $wpdb->get_results($query); $downloadtype = get_option('wp_dlm_type'); if (!empty($dl)) { echo ''; } } return; } function wp_dlm_all($format = 0) { global $wpdb,$wp_dlm_root,$allowed_extentions,$max_upload_size,$wp_dlm_db; $query = sprintf("SELECT * FROM %s ORDER BY postDate DESC;", $wpdb->escape( $wp_dlm_db )); if (!empty($query)) { $url = get_option('wp_dlm_url'); $downloadurl = get_bloginfo('wpurl').'/'.$url; if (empty($url)) $downloadurl = $wp_dlm_root.'download.php?id='; $dl = $wpdb->get_results($query); $downloadtype = get_option('wp_dlm_type'); if (!empty($dl)) { $retval = ''; } } return $retval; } // Shows Top downloads by default // Dropdown to select a category of downloads or view all function wp_dlm_advanced($format = 0) { global $wpdb,$wp_dlm_root,$allowed_extentions,$max_upload_size,$wp_dlm_db,$wp_dlm_db_cats; // Get post data $showing = (int) $_POST['show_downloads']; if ($showing==0 || $showing=="") { // Most popular by default $query = sprintf("SELECT * FROM %s ORDER BY hits DESC LIMIT 10;", $wpdb->escape( $wp_dlm_db )); } else { // Get list of cats and sub cats $the_cats = array(); $the_cats[] = $showing; $query = sprintf("SELECT id from %s WHERE parent IN (%s);", $wpdb->escape( $wp_dlm_db_cats ), $wpdb->escape( implode(",",$the_cats) )); $res = $wpdb->get_results($query); $b=sizeof($the_cats); if ($res) { foreach($res as $r) { if (!in_array($r->id,$the_cats)) $the_cats[]=$r->id; } } $a=sizeof($the_cats); while ($b!=$a) { $query = sprintf("SELECT id from %s WHERE parent IN (%s);", $wpdb->escape( $wp_dlm_db_cats ), $wpdb->escape( implode(",",$the_cats) )); $res = $wpdb->get_results($query); $b=sizeof($the_cats); if ($res) { foreach($res as $r) { if (!in_array($r->id,$the_cats)) $the_cats[]=$r->id; } } $a=sizeof($the_cats); } $query = sprintf("SELECT * FROM %s WHERE `category_id` IN (%s) ORDER BY `title`;", $wpdb->escape( $wp_dlm_db ), $wpdb->escape( implode(",",$the_cats) )); } // Output selector box $retval = '
'; if (!empty($query)) { $url = get_option('wp_dlm_url'); $downloadurl = get_bloginfo('wpurl').'/'.$url; if (empty($url)) $downloadurl = $wp_dlm_root.'download.php?id='; $dl = $wpdb->get_results($query); $downloadtype = get_option('wp_dlm_type'); if (!empty($dl)) { $retval .= ''; } else $retval .='

'.__('No Downloads Found',"wp-download_monitor").'

'; } $retval .= "
"; return $retval; } ################################################################################ // SHOW ALL DOWNLOADS TAG ################################################################################ function wp_dlm_parse_downloads_all($data) { if (substr_count($data,"[#show_downloads]")) { $data = str_replace("[#show_downloads]",wp_dlm_all(), $data); } if (substr_count($data,"[#advanced_downloads]")) { $data = str_replace("[#advanced_downloads]",wp_dlm_advanced(), $data); } return $data; } add_filter('the_content', 'wp_dlm_parse_downloads_all',1,1); ################################################################################ // Dashboard widget - Based on "Dashboard: Draft Posts" by http://www.viper007bond.com/ ################################################################################ // Only for wordpress 2.5 and above! if ($wp_db_version > 6124) { class wp_dlm_dash { // Class initialization function wp_dlm_dash() { // Add to dashboard add_action( 'wp_dashboard_setup', array(&$this, 'register_widget') ); add_filter( 'wp_dashboard_widgets', array(&$this, 'add_widget') ); } // Register the widget for dashboard use function register_widget() { global $wp_db_version; if ($wp_db_version>=9872) { $adminpage = 'tools.php'; } else { $adminpage = 'edit.php'; } wp_register_sidebar_widget( 'download_monitor_dash', __( 'Downloads', 'wp-download_monitor' ), array(&$this, 'widget'), array( 'all_link' => $adminpage.'?page=Downloads' ) ); } // Insert into dashboard function add_widget( $widgets ) { global $wp_registered_widgets; if ( !isset($wp_registered_widgets['download_monitor_dash']) ) return $widgets; array_splice( $widgets, 2, 0, 'download_monitor_dash' ); return $widgets; } // Output the widget function widget( $args ) { if (is_array($args)) extract( $args, EXTR_SKIP ); echo $before_widget; echo $before_title; echo $widget_name; echo $after_title; global $wp_dlm_db,$wpdb; echo "

".__('Most Recent',"wp-download_monitor")."

"; $query = sprintf("SELECT * FROM %s ORDER BY postDate DESC LIMIT 3;", $wpdb->escape( $wp_dlm_db )); if (!empty($query)) { $dl = $wpdb->get_results($query); echo ''; } echo "

".__('Most Popular',"wp-download_monitor")."

"; $query = sprintf("SELECT * FROM %s ORDER BY hits DESC LIMIT 3;", $wpdb->escape( $wp_dlm_db )); if (!empty($query)) { $dl = $wpdb->get_results($query); echo ''; } echo $after_widget; } } add_action( 'plugins_loaded', create_function( '', 'global $wp_dlm_dash; $wp_dlm_dash = new wp_dlm_dash();' ) ); } ?>