public function retrieve($folder, $object_id) { global $err; if (STORAGE_TYPE == 'ES_JSON') { if (SQL_FS) { return eatStaticFakeFS::retrieve($folder, $object_id); } else { if (eatStaticStorage::recordExists($folder, $object_id)) { $json = eatStatic::read_file(DATA_ROOT . '/' . $folder . '/' . $object_id . '.json'); return json_decode($json); } else { $err->add('STORAGE', 'specified file does not exist'); } } } }
/** * @desc search all posts and return array of post slugs */ public function search($term) { $matches = array(); $dir = DATA_ROOT . '/posts/'; //echo $dir; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { //echo "filename: $file : filetype: " . filetype($dir . $file) . "\n"; if (filetype($dir . $file) == 'file' && substr($file, -4) == '.txt') { // for each post found $content = eatStatic::read_file($dir . $file); $match_count = substr_count($content, $term); if ($match_count > 0) { $matches[] = array('count' => $match_count, 'file' => $file); } //$matches[] = array('1', $file); } } closedir($dh); } } // see http://php.net/manual/en/function.array-multisort.php // sort the array by matches // Obtain a list of columns foreach ($matches as $key => $row) { $count[$key] = $row['count']; $file[$key] = $row['file']; } // Sort the data with volume descending, edition ascending // Add $data as the last parameter, to sort by the common key array_multisort($count, SORT_DESC, $file, SORT_ASC, $matches); return $matches; }