Пример #1
0
 function testFetch()
 {
     $fetch = new NetworkFetch('http://example.com/');
     $this->assertTrue($fetch->fetch());
     $tmpFile = $fetch->getTmpFile();
     $this->assertTrue(file_exists($tmpFile));
     unset($fetch);
     $this->assertFalse(file_exists($tmpFile));
 }
Пример #2
0
 public function setFile($file)
 {
     if (substr(strtolower($file), 0, 7) == 'http://') {
         $fetch = new NetworkFetch($file);
         $fetch->fetch();
         $this->cacheFile = $fetch->getTmpFile();
         if (!file_exists($this->cacheFile)) {
             return null;
         }
         $file = $this->cacheFile;
     }
     // keep original image as well for future resizing, etc
     $path = $this->getPath('original');
     copy($file, $path);
     return $this->resizeImage(new ImageManipulator($file));
 }
Пример #3
0
 public function queue()
 {
     ini_set('memory_limit', '512M');
     if ($this->request->get('password') != $this->config->get('CLONE_STORE_API_KEY')) {
         return new RawResponse('Wrong password: '******'password');
     }
     $fetch = new NetworkFetch($this->request->get('url') . '?file=' . urlencode($this->request->get('fileName')) . '&id=' . $this->request->get('id') . '&password='******'CLONE_STORE_API_KEY')));
     $fetch->setAuth('admin', 'Cloning123!');
     $fetch->fetch();
     // validate hash
     $hashFetch = new NetworkFetch($this->request->get('hashUrl') . '?file=' . urlencode($this->request->get('fileName')) . '&id=' . $this->request->get('id') . '&password='******'CLONE_STORE_API_KEY')));
     $hashFetch->setAuth('admin', 'Cloning123!');
     $hashFetch->fetch();
     if (md5_file($fetch->getTmpFile()) == file_get_contents($hashFetch->getTmpFile())) {
         rename($fetch->getTmpFile(), $this->getFileDir() . $this->request->get('fileName'));
         return new RawResponse('OK');
     } else {
         return new RawResponse('MD5 mismatch ' . file_get_contents($hashFetch->getTmpFile()) . ' ' . substr(file_get_contents($fetch->getTmpFile()) . ' ' . filesize($fetch->getTmpFile()), -200));
     }
 }
Пример #4
0
 public function getResponse($query, $params = array(), $raw = false)
 {
     if (!empty($params['package'])) {
         $module = $params['package'];
         if (substr($module, 0, 7) == 'module.') {
             $module = substr($module, 7);
         } else {
             if ('.' == $module) {
                 $module = 'livecart';
             }
         }
         $params['package'] = $module;
     }
     $params['handshake'] = $this->handshake;
     $url = $this->url . '/' . $query . '?domain=' . $this->domain;
     foreach ($params as $key => $value) {
         $url .= '&' . $key . '=' . $value;
     }
     $fetch = new NetworkFetch($url);
     $fetch->fetch();
     return $raw ? file_get_contents($fetch->getTmpFile()) : json_decode(file_get_contents($fetch->getTmpFile()), true);
 }
Пример #5
0
 private function importImage(ProductImage $image, $path)
 {
     if (!$path) {
         return false;
     }
     if (@parse_url($path, PHP_URL_SCHEME)) {
         $fetch = new NetworkFetch($path);
         $path = $fetch->fetch() ? $fetch->getTmpFile() : '';
     } else {
         if (!file_exists($path)) {
             foreach (array('/tmp/import/', ClassLoader::getRealPath('public.import.')) as $loc) {
                 $p = $loc . $path;
                 if (file_exists($p)) {
                     $path = $p;
                     break;
                 }
             }
         }
         if (!file_exists($path)) {
             $path = '';
         }
     }
     if ($path) {
         $man = new ImageManipulator($path);
         if ($man->isValidImage()) {
             $image->save();
             $image->resizeImage($man);
             $image->save();
         }
     }
 }
Пример #6
0
 public function status()
 {
     $status = array();
     foreach (ActiveRecord::getRecordSet('ClonedStore', select()) as $store) {
         $f = new NetworkFetch('http://' . $store->domain->get() . '/storeSync/status');
         $f->fetch();
         $status[$store->getID()] = file_get_contents($f->getTmpFile()) == 'true';
     }
     $status['ready'] = count($status) == count(array_filter($status));
     return new JSONResponse($status);
 }
Пример #7
0
 public function repoDescription()
 {
     $repo = $this->request->get('repo');
     if (!preg_match('/^http[s]{0,1}\\:\\/\\//', $repo)) {
         return new RawResponse('Invalid URL');
     }
     $fetch = new NetworkFetch($repo);
     $fetch->fetch();
     return new RawResponse(file_get_contents($fetch->getTmpFile()));
 }