Ejemplo n.º 1
0
 function upgrade_from_1()
 {
     global $wpdb;
     // Add columns to drainhole_access: version_id, user_id
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_access` ADD `user_id` int UNSIGNED NOT NULL;");
     // Add columns to drainhole_files: name, description, created_at
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` ADD `name` varchar(150) NOT NULL default '';");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` ADD `description` TEXT default NULL;");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` ADD\t`version_id` int(11) unsigned NOT NULL;");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` ADD `options` mediumtext DEFAULT NULL ;");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` ADD `svn` varchar(150) DEFAULT NULL ;");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_access` ADD `version_id` int UNSIGNED NOT NULL DEFAULT '0';");
     // Change columns in drainhole_files for: file
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` CHANGE `file` `file` varchar(150) NOT NULL default '';");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` CHANGE `downloads` `hits` int(10) UNSIGNED NOT NULL DEFAULT '0';");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_holes` CHANGE `role_error_id` `role_error_url` varchar(100) DEFAULT NULL;");
     $files = DH_File::get_all();
     // Remove columns
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` DROP `version`;");
     $wpdb->query("ALTER TABLE `{$wpdb->prefix}drainhole_files` DROP `force_download`;");
     // Create the first version for each file and link it back to the file
     // Also link all access stats to the latest version
     if (count($files) > 0) {
         foreach ($files as $file) {
             $version = DH_Version::create($file, $file->version, $file->hits, $file->updated_at, __('First version', 'drain-hole'));
             $options = $wpdb->escape(serialize(array('force_download' => $file->force_download)));
             $wpdb->query("UPDATE {$wpdb->prefix}drainhole_files SET version_id='{$version}',options='{$options}' WHERE id='{$file->id}'");
             $wpdb->query("UPDATE {$wpdb->prefix}drainhole_access SET version_id='{$version}' WHERE file_id='{$file->id}'");
         }
     }
 }
Ejemplo n.º 2
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') {
         $items = DH_Version::get_hits_per_year(intval($_GET['hole']), 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) {
                 $chart['chart_type'] = 'line';
Ejemplo n.º 3
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']);
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 function delete_version($id)
 {
     if (check_ajax_referer('drainhole-delete_items')) {
         foreach ($_POST['checkall'] as $fileid) {
             $version = DH_Version::get($id);
             $version->delete();
         }
     }
 }
Ejemplo n.º 5
0
Archivo: file.php Proyecto: Jintha/cama
 function create_new_version($version, $branch, $reason, $dontbranch = false, $svnupdate = false)
 {
     global $wpdb;
     $hole = DH_Hole::get($this->hole_id);
     // Branch our copy
     if ($dontbranch === false && $branch) {
         if ($hole && $this->exists($hole)) {
             $target = $this->file($hole, $this->version_id);
             @wp_mkdir_p(dirname($target));
             @copy($this->file($hole), $target);
         }
     }
     // Sort out any SVN business
     if ($this->svn && $svnupdate) {
         $options = get_option('drainhole_options');
         if ($options && isset($options['svn']) && $options['svn']) {
             include dirname(__FILE__) . '/svn.php';
             $svn = new DH_SVN($this->svn, $options['svn']);
             $svn->update($this->file($hole));
             if ($svn->version()) {
                 $version = $svn->version();
             }
         }
     }
     // Store details in a version branch
     if ($dontbranch === false) {
         $version = DH_Version::create($this, $version, $this->hits - DH_Version::total_hits($this->id), '', $reason);
         // Update our details
         $wpdb->query("UPDATE {$wpdb->prefix}drainhole_files SET updated_at=NOW(), version_id='{$version}' WHERE id={$this->id}");
     } else {
         $wpdb->query("UPDATE {$wpdb->prefix}drainhole_version SET version='{$version}', created_at=NOW() WHERE id={$this->version_id}");
     }
     return true;
 }