Example #1
0
 function UpdateMemBar()
 {
     if ($this->mem_bar) {
         $ms = self::GetMemStats();
         $pu = round($ms['usage'] / $ms['limit'] * 100);
         if ($this->memprof && $pu > 90) {
             memprof_dump_callgrind(fopen("/tmp/callgrind_mem.out", "w"));
             die("memprof @{$pu}% written to /tmp/callgrind_mem.out");
         }
         if ($this->memprof) {
             self::DEcho("Mem Usage: {$pu} %<br />");
             //sleep(1);
         }
         $this->mem_bar->set($ms['usage']);
     }
 }
Example #2
0
 static function Sync($hash_sync = false, $output = false)
 {
     self::PrintDebugTrace();
     wpfb_loadclass('File', 'Category');
     $sync_data = new WPFB_SyncData(true);
     $sync_data->hash_sync = $hash_sync;
     self::PreSync($sync_data);
     self::SyncPase1($sync_data, $output);
     if ($output && $sync_data->num_files_to_add > 0) {
         echo "<p>";
         printf(__('%d Files found, %d new.', WPFB), $sync_data->num_all_files, $sync_data->num_files_to_add);
         echo "</p>";
         if (!class_exists('progressbar')) {
             include_once WPFB_PLUGIN_ROOT . 'extras/progressbar.class.php';
         }
         $progress_bar = new progressbar(0, $sync_data->num_files_to_add);
         $progress_bar->print_code();
     } else {
         $progress_bar = null;
         if ($output) {
             self::DEcho('done!</p>');
         }
     }
     self::PrintDebugTrace("pre_add_files");
     self::AddNewFiles($sync_data, $progress_bar);
     self::PostSync($sync_data, $output);
     return $sync_data->log;
 }
Example #3
0
 public function progressbar()
 {
     session_write_close();
     // unlock session !important!
     $dbprg = new progressbar($this->_prepare_registry(), $this);
     $this->response->addJSONHeader();
     switch ($this->request->get["work"]) {
         case "max":
             echo AJson::encode(array('total' => $dbprg->get_max()));
             break;
         case "do":
             $result = $dbprg->do_work();
             if (!$result) {
                 $result = array('status' => 406, 'errorText' => $result);
             } else {
                 $result = array('status' => 100);
             }
             echo AJson::encode($result);
             break;
         case "progress":
             echo AJson::encode(array('prc' => (int) $dbprg->get_progress()));
             break;
     }
 }
Example #4
0
 /**
  *
  * @param type $steps
  *
  * @return \progressbar
  */
 private static function NewProgressBar($steps)
 {
     if (!class_exists('progressbar')) {
         include_once WPFB_PLUGIN_ROOT . 'extras/progressbar.class.php';
     }
     $progress_bar = new progressbar(0, $steps);
     $progress_bar->print_code();
     return $progress_bar;
 }
Example #5
0
 public static function SideloadFile($url, $dest_file = null, $size_for_progress = 0)
 {
     //WARNING: The file is not automatically deleted, The script must unlink() the file.
     @ini_set('max_execution_time', '0');
     @set_time_limit(0);
     require_once ABSPATH . 'wp-admin/includes/file.php';
     if (!$url) {
         return array('error' => __('Invalid URL Provided.'));
     }
     if (empty($dest_file)) {
         // if no dest file set, create temp file
         $fi = self::GetRemoteFileInfo($url);
         if (empty($fi)) {
             return array('error' => sprintf(__('Could not get file information from %s!', WPFB), $url));
         }
         if (!($dest_file = self::GetTmpFile($fi['name']))) {
             return array('error' => __('Could not create Temporary file.'));
         }
     }
     if ($size_for_progress >= self::$MIN_SIZE_FOR_PROGRESSBAR) {
         if (!class_exists('progressbar')) {
             include_once WPFB_PLUGIN_ROOT . 'extras/progressbar.class.php';
         }
         $progress_bar = new progressbar(0, $size_for_progress, 300, 30, '#aaa');
         echo "<p><code>" . esc_html($url) . "</code> ...</p>";
         $progress_bar->print_code();
     } else {
         $progress_bar = null;
     }
     wpfb_loadclass('Download');
     $result = WPFB_Download::SideloadFile($url, $dest_file, $progress_bar);
     if (is_array($result) && !empty($result['error'])) {
         return $result;
     }
     return array('error' => false, 'file' => $dest_file);
 }