Exemplo n.º 1
0
 protected function process_data(&$signal)
 {
     if (!parent::process_data($signal)) {
         return false;
     }
     $title = $signal->data_title($this->default_data_key);
     if (is_null($title)) {
         return false;
     }
     $namespace = $this->core->info->title_namespace($title);
     if (empty($namespace)) {
         $title = $this->core->info->namespace_name('File') . ':' . $title;
     }
     $params = array('title' => $title, 'properties' => array('imageinfo' => array()));
     $paramnames = $this->core->info->param_querymodule_parameters_names('imageinfo');
     foreach ($paramnames as $paramname) {
         if (isset($this->{$paramname}) && !is_null($this->{$paramname})) {
             $params['properties']['imageinfo'][$paramname] = $this->{$paramname};
         }
     }
     if (empty($params['properties']['imageinfo']['prop'])) {
         $params['properties']['imageinfo']['prop'] = $this->core->info->param_querymodule_parameter_type('prop', 'imageinfo');
     }
     require_once dirname(__FILE__) . '/../../../../core/tasks/fetch_filename.php';
     $task = new Task_FetchFilename($this->core);
     $file = $task->go($params);
     if ($file !== false && $this->fetch_body) {
         if (isset($this->body_file)) {
             if ($this->body_file == "") {
                 $this->core->browser->write_into_file = sha1($title);
             } else {
                 $this->core->browser->write_into_file = $this->body_file;
             }
         }
         $browser_max_retries = $this->core->browser->max_retries;
         $this->core->browser->max_retries = 50;
         try {
             $result = $this->core->browser->xfer($file->url);
         } catch (Exception $e) {
             $result = false;
         }
         if ($result) {
             if (!isset($this->body_file)) {
                 $file->body = $this->core->browser->content;
                 $filesize = strlen($file->body);
             } else {
                 $file->body_link = $this->core->browser->write_into_file;
                 $file->body_link_is_tempfile = true;
                 $filesize = filesize($file->body_link);
             }
             $this->log("Fetched also the file body - {$filesize} bytes", LL_DEBUG);
         } else {
             $this->log("Tried, but could not fetch the file body!", LL_WARNING);
         }
         $this->core->browser->max_retries = $browser_max_retries;
         unset($this->core->browser->write_into_file);
     }
     $result = $this->set_fetched_data($signal, $file);
     $this->set_jobdata($result, array_merge(array('title' => $title, 'fetch_body' => $this->fetch_body), $params['properties']['imageinfo']));
     return $result;
 }
Exemplo n.º 2
0
 public function fetch_filename($filename, $properties = NULL, $log_fetch = NULL)
 {
     $params = array('title' => $filename, 'properties' => $properties, 'log_result' => $log_fetch);
     require_once dirname(__FILE__) . '/../../core/tasks/fetch_filename.php';
     $task = new Task_FetchFilename($this->core);
     return $task->go($params);
 }