Example #1
0
 public function fetchData()
 {
     $files = $this->getTransformedFiles();
     $baseDir = ClassLoader::getBaseDir();
     $query = $this->getOption('query');
     $found = array();
     foreach ($files as $file) {
         if (strpos(file_get_contents($file['path']), $query) !== false) {
             $found[] = array('id' => $file['id'], 'name' => basename($file['path']));
         }
     }
     $count = count($found);
     $ret = array();
     $ret['records'] = array();
     // $found;
     $ret['count'] = $count;
     $offset = $this->getOption('offset');
     // pp($offset);
     $ret['from'] = $offset;
     if ($ret['from'] == '' || $ret['from'] < 0) {
         $ret['from'] = 0;
     }
     $ret['to'] = $this->getOption('limit') + $offset;
     // $ret['from'];
     for ($i = $offset; $i < $ret['to'] && $i < $ret['count']; $i++) {
         $ret['records'][] = $found[$i];
     }
     $diff = $ret['to'] - $ret['from'];
     $c = count($ret['records']);
     if ($diff != $c) {
         $ret['to'] = $ret['from'] + $c;
     }
     $ret['from']++;
     $ret['meta'] = array();
     return $ret;
 }
Example #2
0
 public function export()
 {
     require_once ClassLoader::getRealPath('library.pclzip') . '/pclzip.lib.php';
     $id = $this->getRequest()->get('id');
     $files = $this->getThemeFiles($id);
     if ($files === null) {
         return new ActionRedirectResponse('backend.theme', 'index');
     }
     do {
         $path = ClassLoader::getRealPath('cache.tmp.theme_export_' . rand(1, 10000000));
     } while (file_exists($path));
     $zipFilePath = $path . '_archive.zip';
     $confFilePath = $path . DIRECTORY_SEPARATOR . 'theme.conf';
     foreach (array($zipFilePath, $confFilePath) as $fp) {
         if (!is_dir(dirname($fp))) {
             mkdir(dirname($fp), 0777, true);
         }
     }
     file_put_contents($confFilePath, sprintf('[Theme]' . "\n" . 'name = %s', $id));
     $archive = new PclZip($zipFilePath);
     chdir(ClassLoader::getBaseDir());
     $files[] = $confFilePath;
     $archive->add($files, PCLZIP_OPT_REMOVE_PATH, $path);
     $this->application->rmdir_recurse($path);
     $response = new ObjectFileResponse(ObjectFile::getNewInstance('ObjectFile', $zipFilePath, $id . '.zip'));
     $response->deleteFileOnComplete();
     return $response;
 }