public function search(SearchQuery $obj)
 {
     if (AdvancedPathLib::getCurrentOS() == AdvancedPathLib::OS_WINDOWS) {
         return array(0, array());
     }
     $this->results = array();
     // setting the queryString to the variable.
     $searchArray = explode(' ', $obj->getQueryString());
     foreach ($searchArray as $word) {
         $this->searchQuery .= 'filename:' . $word . '* ';
     }
     // setting the queryTokens to the variable.
     $queryTokens = $obj->getQueryTokens();
     // for each valid token, we add the token and its parameters to the $searchQuery variable.
     if ($queryTokens) {
         foreach ($queryTokens as $token => $parameters) {
             if (in_array($token, $this->getValidTokens())) {
                 foreach ($parameters as $count => $value) {
                     $this->searchQuery .= $token . ':' . $value;
                     if ($count < count($parameters) - 1) {
                         $this->searchQuery .= ' OR ';
                     } else {
                         $this->searchQuery .= ' ';
                     }
                 }
                 $this->searchQuery .= 'AND ';
             }
         }
         // searching for an AND at the end of the searchQuery, if it's there we delete it
         // to conform the query to the recoll standards.
         // ( by the way, an AND at the end of a query does not make any sense, do it? :P )
         $pos = strpos($this->searchQuery, 'AND', strlen($this->searchQuery) - 4);
         $this->searchQuery = substr($this->searchQuery, 0, $pos - 1);
     }
     $user = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser()->getName();
     $recollDirPath = UMManager::getEyeosUserDirectory($user) . '/' . USERS_CONF_DIR . '/' . FRAMEWORK_SEARCH_RECOLL_DIR;
     $result = shell_exec(AdvancedPathLib::realpath(FRAMEWORK_SEARCH_UTILS_PATH) . '/XmlBuilder.pl ' . escapeshellarg(AdvancedPathLib::realpath($recollDirPath)) . ' ' . escapeshellarg($this->searchQuery));
     $xmlResult = simplexml_load_string($result);
     if ($xmlResult) {
         $path = realpath(UMManager::getEyeosUserDirectory($user)) . '/files/';
         foreach ($xmlResult as $node => $markup) {
             if ($node == 'file') {
                 $cleanPath = utf8_substr($markup->path, 7);
                 $cleanPath = 'home://~' . $user . '/' . utf8_substr($cleanPath, strlen($path));
                 $tempFile = array('type' => (string) $markup->type, 'path' => (string) $cleanPath, 'name' => (string) $markup->name, 'size' => (string) $markup->size);
                 $this->results[] = $tempFile;
             } else {
                 if ($node == 'files') {
                     $this->totalFiles = $markup;
                 }
             }
         }
     }
     return array($this->totalFiles, $this->results);
 }
Beispiel #2
0
 /**
  * @return string
  */
 public function getPathFromRoot()
 {
     $urlParts = $this->getURLComponents();
     return AdvancedPathLib::realpath($urlParts['path'], false);
 }
 public function testRealpath()
 {
     //localhost
     $this->assertEquals(str_replace('\\', '/', realpath(EYEOS_TESTS_TMP_PATH)), AdvancedPathLib::realpath(EYEOS_TESTS_TMP_PATH, true));
     $this->assertEquals(str_replace('\\', '/', realpath(EYEOS_TESTS_TMP_PATH . '/../../')), AdvancedPathLib::realpath(EYEOS_TESTS_TMP_PATH . '/../../', true));
     //not localhost
     $this->assertEquals('/path/to/myFile.ext', AdvancedPathLib::realpath('/path//to///myFile.ext', false));
     $this->assertEquals('/path/myFile.ext', AdvancedPathLib::realpath('/path/to/../another/../myFile.ext', false));
     $this->assertEquals('/', AdvancedPathLib::realpath('/path/to/../another/../../../', false));
 }