Esempio n. 1
0
 function upgrade_from_0()
 {
     // Copy old tables
     $old = $wpdb->get_results("SELECT * FROM drainhole_files");
     if (count($old) > 0) {
         DH_Hole::create(array('url' => get_option('drainhole_store'), 'directory' => realpath(ABSPATH) . '/' . get_option('drainhole_store')));
         $hole = DH_Hole::get($wpdb->insert_id);
         foreach ($old as $row) {
             $version = $wpdb->escape($row->version);
             $file = $wpdb->escape($row->file);
             $wpdb->query("INSERT INTO {$wpdb->prefix}drainhole_files (file,hole_id,version,downloads,updated_at) VALUES ('{$file}',{$hole->id},'{$version}','{$row->downloads}',NOW())");
             $file = DH_File::get($wpdb->insert_id);
             $file->sync_modified_time($hole);
         }
     }
     // Delete old tables
     $wpdb->query("DROP TABLE drainhole_files");
     $wpdb->query("DROP TABLE drainhole_access");
 }
Esempio n. 2
0
$id = intval($_GET['id']);
$type = $_GET['type'];
header("Content-Type: application/vnd.ms-excel");
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
/**
 * Escape CSV values
 *
 * @param string $value Original value to escape
 * @return string Escaped value
 **/
global $drainhole;
if ($type == 'stats') {
    $file = DH_File::get($id);
    header('Content-Disposition: attachment; filename="' . basename($file->file) . '.csv"');
    $stats = DH_Access::get_all($id);
    if (count($stats) > 0) {
        foreach ($stats as $stat) {
            $csv = array();
            $csv[] = $drainhole->csv_escape(date('Y-m-d', $stat->created_at));
            $csv[] = $drainhole->csv_escape(date('H:i', $stat->created_at));
            $csv[] = $drainhole->csv_escape($stat->ip);
            $csv[] = $drainhole->csv_escape($stat->speed);
            $csv[] = $drainhole->csv_escape($stat->time_taken);
            echo implode(',', $csv) . "\r\n";
        }
    }
} else {
    if ($type == 'files') {
Esempio n. 3
0
 function show_version($id)
 {
     $version = DH_Version::get($id);
     $file = DH_File::get($version->file_id);
     $hole = DH_Hole::get($file->hole_id);
     $this->render_admin('versions_item', array('version' => $version, 'hole' => $hole, 'file' => $file));
 }
Esempio n. 4
0
 function delete()
 {
     global $wpdb;
     $wpdb->query("DELETE FROM {$wpdb->prefix}drainhole_version WHERE id='{$this->id}'");
     $file = DH_File::get($this->file_id);
     $hole = DH_Hole::get($file->hole_id);
     $file->delete_version($this->id, $hole);
 }
Esempio n. 5
0
 /**
  * Replaces matched regular expressions with appropriate data
  * 
  * @param array $matches An array of matches from preg_replace.  $matches[1]=type, $matches[2]=ID, $matches[3]=command, $matches[4]=arguments
  * @return string New text with replaced tags
  **/
 function tags($matches)
 {
     $type = $matches[1];
     $id = intval($matches[2]);
     $cmd = $matches[3];
     $args = $matches[4];
     $options = $this->get_options();
     if ($type == 'hole') {
         $hole = DH_Hole::get($id);
         if ($hole) {
             if ($cmd == 'hits') {
                 return number_format($hole->hits);
             } else {
                 if ($cmd == 'recent') {
                     if ($args == 0) {
                         $args = 1;
                     }
                     $files = DH_File::get_recent($hole->id, $args);
                     return $this->capture('show_hole', array('files' => $files, 'hole' => $hole));
                 } else {
                     if ($cmd == 'show' && !$this->excerpt) {
                         if ($args == '') {
                             $args = 'show_hole';
                         }
                         $files = DH_File::get_all($hole->id);
                         return $this->capture($args, array('files' => $files, 'hole' => $hole));
                     }
                 }
             }
         }
     } else {
         if ($type == 'file') {
             $file = DH_File::get($id);
             if ($file) {
                 $hole = DH_Hole::get($file->hole_id);
                 if ($cmd == 'show' && !$this->excerpt) {
                     if ($args == '') {
                         $args = 'default_show';
                     }
                     return $this->tags_inline($this->capture($args, array('file' => $file, 'hole' => $hole)), $hole, $file);
                 } else {
                     if ($cmd == 'versions') {
                         $limit = 5;
                         if ($args) {
                             $limit = intval($args);
                         }
                         $versions = DH_Version::get_history($file->id, $file->version_id, $limit);
                         if (count($versions) > 0 && $options['tracker']) {
                             foreach ($versions as $pos => $version) {
                                 $versions[$pos]->reason = preg_replace('@\\#(\\d*)@', '<a href="' . $options['tracker'] . '$1">#$1</a>', $version->reason);
                             }
                         }
                         return $this->capture('versions', array('versions' => $versions, 'file' => $file, 'hole' => $hole));
                     } else {
                         if ($cmd == 'version') {
                             return $file->version;
                         } else {
                             if ($cmd == 'hits') {
                                 return number_format($file->hits);
                             } else {
                                 if ($cmd == 'name') {
                                     return $file->name();
                                 } else {
                                     if ($cmd == 'md5') {
                                         return md5($file->file($hole));
                                     } else {
                                         if ($cmd == 'url') {
                                             return $file->url($hole, $args == '' ? basename($file->file) : $args, $options['google']);
                                         } else {
                                             if ($cmd == 'href') {
                                                 return $file->url_ref($hole);
                                             } else {
                                                 if ($cmd == 'svn') {
                                                     return $file->svn();
                                                 } else {
                                                     if ($cmd == 'updated') {
                                                         return date(get_option('date_format'), $file->updated_at);
                                                     } else {
                                                         if ($cmd == 'size') {
                                                             return $file->bytes($file->filesize($hole));
                                                         } else {
                                                             if ($cmd == 'icon') {
                                                                 return $file->icon($hole, $this->url(), $options['google']);
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 6
0
         $min = min(array_slice($data, 1));
         $max = $max + (10 - $max % 10);
         $min = $min - $min % 10;
         $chart['chart_data'] = array($axis, $data);
         $chart['axis_value'] = array('min' => 0, 'max' => $max, 'size' => 14, 'show_min' => true, 'steps' => 10);
         $chart['axis_category'] = array('size' => 14, 'orientation' => 'horizontal', 'skip' => count($data) > 5 ? 2 : 0);
         if (count($data) > 4) {
             $chart['chart_type'] = 'line';
         } else {
             $chart['chart_type'] = 'column';
         }
         $text = sprintf(__('Daily downloads over time (%1s %2s)', 'drain-hole'), $wp_locale->get_month(intval($_GET['month'])), intval($_GET['year']));
     }
 } else {
     if ($_GET['display'] == 'monthly') {
         $file = DH_File::get(intval($_GET['file']));
         $items = DH_Access::get_file_hits_per_year(intval($_GET['file']), intval($_GET['year']));
         if (count($items) > 0) {
             foreach ($items as $month => $hits) {
                 $axis[] = sprintf('%1s %2s', $wp_locale->get_month_abbrev($wp_locale->get_month($month)), $day);
                 $data[] = $hits;
             }
             // Work out the max and min values
             $max = max(array_slice($data, 1));
             $min = min(array_slice($data, 1));
             $max = $max + (10 - $max % 10);
             $min = $min - $min % 10;
             $chart['chart_data'] = array($axis, $data);
             $chart['axis_value'] = array('min' => 0, 'max' => $max, 'size' => 14, 'show_min' => true, 'steps' => 10);
             $chart['axis_category'] = array('size' => 14, 'orientation' => 'horizontal', 'skip' => count($data) > 5 ? 2 : 0);
             if (count($data) > 4) {
Esempio n. 7
0
File: file.php Progetto: Jintha/cama
 /**
  * Create a new file entry in the database
  *
  * @static
  * @param DH_Hole $hole The DrainHole in which to put the file
  * @param string $file The file's name
  * @return boolean true if successfully created, false if the file already exists
  **/
 function create($hole, $file)
 {
     global $wpdb;
     $count = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}drainhole_files WHERE file='{$file}' AND hole_id={$hole}");
     if ($count == 0 && $count !== false) {
         $options = get_option('drainhole_options');
         $version = '0.1';
         $name = $file;
         if (isset($options['default_version']) && $options['default_version'] != '') {
             $version = $options['default_version'];
         }
         if (isset($options['default_name']) && $options['default_name'] != '') {
             $name = $options['default_name'];
             $parts = pathinfo(basename($file));
             if (!isset($parts['filename'])) {
                 $parts['filename'] = substr($parts['basename'], 0, strpos($parts['basename'], '.'));
             }
             $name = str_replace('$FILENAME$', $parts['filename'], $name);
             $name = str_replace('$EXTENSION$', $parts['extension'], $name);
             $name = $wpdb->escape($name);
         }
         // Now create the file
         $file = $wpdb->escape(DH_Hole::sanitize_dir(ltrim($file, '/')));
         $wpdb->query("INSERT INTO {$wpdb->prefix}drainhole_files (hole_id,file,updated_at,name) VALUES ({$hole},'{$file}',NOW(),'{$name}')");
         // Create version information
         $file = DH_File::get($wpdb->insert_id);
         $version = DH_Version::create($file, $version);
         $wpdb->query("UPDATE {$wpdb->prefix}drainhole_files SET version_id='{$version}' WHERE id='{$file->id}'");
         return true;
     }
     return false;
 }