/** * Locates the $file in $__paths, searches recursively. * * @param string $file full file name * @param boolean $recursive search $__paths recursively * @return mixed boolean on fail, $file directory path on success * @access private */ private static function __find($file, $recursive = true) { if (empty(self::$search)) { return null; } elseif (is_string(self::$search)) { self::$search = array(self::$search); } if (empty(self::$__paths)) { self::$__paths = Cache::read('dir_map', '_cake_core_'); } foreach (self::$search as $path) { $path = rtrim($path, DS); if ($path === rtrim(APP, DS)) { $recursive = false; } if ($recursive === false) { if (self::__load($path . DS . $file)) { return $path . DS; } continue; } if (!isset(self::$__paths[$path])) { if (!class_exists('Folder')) { require LIBS . 'folder.php'; } $Folder = new Folder(); $directories = $Folder->tree($path, array('.svn', 'tests', 'templates'), 'dir'); sort($directories); self::$__paths[$path] = $directories; } foreach (self::$__paths[$path] as $directory) { if (self::__load($directory . DS . $file)) { return $directory . DS; } } } return null; }
<?php /** * Provides the search interface. */ namespace saasy; // Authorize user if (!App::authorize($page, $tpl)) { return; } $page->title = __('Search'); echo App::search();
<meta property="og:title" content="When Great Minds Don’t Think Alike" /> <meta property="og:description" content="How much does culture influence creative thinking?" /> <meta property="og:image" content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg" />'; }); $app->get('/categories', function () { $cats = App::getCategories(); $r = []; foreach ($cats as $c) { $r[] = ["id" => $c->getID(), "name" => $c->getName(), "count" => $c->countPosts()]; } echo json_encode($r); }); $app->get('/search', function () use($app) { $q = $app->request()->get("q"); if ($q) { $result = App::search($q); echo json_encode($result); } else { echo json_encode(array()); } }); $app->post('/users/', function () use($app) { $body = $app->request->getBody(); $nu = json_decode($body); if ($uid = User::create($nu->firstName, $nu->lastName, $nu->email)) { $app->response()->status("201"); $token = App::generateToken($uid); echo json_encode(array('token' => "{$token}")); } else { $app->response()->status("401"); }
/** * Finds classes based on $name or specific file(s) to search. Calling App::import() will * not construct any classes contained in the files. It will only find and require() the file. * * @link http://book.cakephp.org/view/934/Using-App-import * @param mixed $type The type of Class if passed as a string, or all params can be passed as * an single array to $type, * @param string $name Name of the Class or a unique name for the file * @param mixed $parent boolean true if Class Parent should be searched, accepts key => value * array('parent' => $parent ,'file' => $file, 'search' => $search, 'ext' => '$ext'); * $ext allows setting the extension of the file name * based on Inflector::underscore($name) . ".$ext"; * @param array $search paths to search for files, array('path 1', 'path 2', 'path 3'); * @param string $file full name of the file to search for including extension * @param boolean $return, return the loaded file, the file must have a return * statement in it to work: return $variable; * @return boolean true if Class is already in memory or if file is found and loaded, false if not */ public static function import($type = null, $name = null, $parent = true, $search = array(), $file = null, $return = false) { $plugin = $directory = null; if (is_array($type)) { extract($type, EXTR_OVERWRITE); } if (is_array($parent)) { extract($parent, EXTR_OVERWRITE); } if ($name === null && $file === null) { $name = $type; $type = 'Core'; } elseif ($name === null) { $type = 'File'; } if (is_array($name)) { foreach ($name as $class) { $tempType = $type; $plugin = null; if (strpos($class, '.') !== false) { $value = explode('.', $class); $count = count($value); if ($count > 2) { $tempType = $value[0]; $plugin = $value[1] . '.'; $class = $value[2]; } elseif ($count === 2 && ($type === 'Core' || $type === 'File')) { $tempType = $value[0]; $class = $value[1]; } else { $plugin = $value[0] . '.'; $class = $value[1]; } } if (!App::import($tempType, $plugin . $class, $parent)) { return false; } } return true; } if ($name != null && strpos($name, '.') !== false) { list($plugin, $name) = explode('.', $name); $plugin = Inflector::camelize($plugin); } self::$return = $return; if (isset($ext)) { $file = Inflector::underscore($name) . ".{$ext}"; } $ext = self::__settings($type, $plugin, $parent); $className = $name; if (strpos($className, '/') !== false) { $className = substr($className, strrpos($className, '/') + 1); } if ($name != null && !class_exists($className . $ext['class'])) { if ($load = self::__mapped($name . $ext['class'], $type, $plugin)) { if (self::__load($load)) { if (self::$return) { return include $load; } return true; } else { self::__remove($name . $ext['class'], $type, $plugin); self::$__cache = true; } } if (!empty($search)) { self::$search = $search; } elseif ($plugin) { self::$search = self::__paths('plugin'); } else { self::$search = self::__paths($type); } $find = $file; if ($find === null) { $find = Inflector::underscore($name . $ext['suffix']) . '.php'; if ($plugin) { $paths = self::$search; foreach ($paths as $key => $value) { self::$search[$key] = $value . $ext['path']; } } } if (strtolower($type) !== 'vendor' && empty($search) && self::__load($file)) { $directory = false; } else { $file = $find; $directory = self::__find($find, true); } if ($directory !== null) { self::$__cache = true; self::__map($directory . $file, $name . $ext['class'], $type, $plugin); if (self::$return) { return include $directory . $file; } return true; } return false; } return true; }