Beispiel #1
0
 /**
  * Get information about a theme.
  * @param string $theme Theme name.
  * @return ThemeInfo|null Theme information or null if theme not found or
  * invalid. Will produce a warning if the JSON file is invalid.
  */
 public function getInfo($theme)
 {
     if (!isset($this->info[$theme])) {
         $dir = $this->p('themes', $theme);
         $library = null;
         if (!file_exists($dir . '/theme.json')) {
             foreach ($this->libraries as $key) {
                 $dir = $this->p($key, 'themes/' . $theme);
                 if (file_exists($dir . '/theme.json')) {
                     $library = $key;
                 }
             }
             if (!isset($library)) {
                 return null;
             }
         }
         $info = Json::decodeFile($dir . '/theme.json');
         if (!$info) {
             $this->logger->warning(tr('The theme "%1" has an invalid json file.', $theme));
             return null;
         }
         $this->info[$theme] = new ThemeInfo($theme, $info, array(), $library);
     }
     return $this->info[$theme];
 }
Beispiel #2
0
 /**
  * Get information about a database driver.
  *
  * The returned information array is of the format:
  * <code>
  * array(
  *   'driver' => ..., // Driver name (string)
  *   'name' => ..., // Formal name, e.g. 'MySQL' instead of 'MySql' (string)
  *   'requiredOptions' => array(...), // List of required options (string[])
  *   'optionalOptions' => array(...), // List of optional options (string[])
  *   'isAvailable' => ..., // Whether or not driver is available (bool)
  *   'missingExtensions => array(...) // List of missing extensions (string[])
  * )
  * </code>
  * @param string $driver Driver name
  * @return array Driver information as an associative array.
  * @throws InvalidDriverException If driver is missing or invalid.
  */
 public function checkDriver($driver)
 {
     if (!file_exists($this->p('Jivoo/Databases/Drivers/' . $driver . '/' . $driver . 'Database.php'))) {
         throw new InvalidDriverException(tr('Driver class not found: %1', $driver));
     }
     if (!file_exists($this->p('Jivoo/Databases/Drivers/' . $driver . '/driver.json'))) {
         throw new InvalidDriverException(tr('Driver manifest not found: %1', $driver));
     }
     try {
         $info = Json::decodeFile($this->p('Jivoo/Databases/Drivers/' . $driver . '/driver.json'));
     } catch (JsonException $e) {
         throw new InvalidDriverException(tr('Invalid driver manifest: %1 (%2)', $driver, $e->getMessage()), 0, $e);
     }
     if (!isset($info['required'])) {
         $info['required'] = array();
     }
     if (!isset($info['optional'])) {
         $info['optional'] = array();
     }
     if (!isset($info['phpExtensions'])) {
         $info['phpExtensions'] = array();
     }
     $missing = array();
     foreach ($info['phpExtensions'] as $dependency) {
         if (!extension_loaded($dependency)) {
             $missing[] = $dependency;
         }
     }
     return array('driver' => $driver, 'name' => $info['name'], 'requiredOptions' => $info['required'], 'optionalOptions' => $info['optional'], 'isAvailable' => count($missing) < 1, 'missingExtensions' => $missing);
 }
Beispiel #3
0
 /**
  * Installer step: Configure application manifest, create directories, and
  * copy files.
  * @param array $data POST data.
  * @return \Jivoo\Routing\Response|string Response.
  */
 public function configure($data = null)
 {
     if (isset($data)) {
         $this->configForm->addData($data['Configure']);
         $manifest = array('name' => $this->configForm->name, 'version' => $this->configForm->version, 'modules' => array_merge(array('Assets', 'Helpers', 'Models', 'Routing', 'View'), array_values($this->configForm->modules)), 'install' => 'Jivoo\\Setup\\DefaultInstaller', 'update' => 'Jivoo\\Setup\\DefaultUpdater');
         mkdir($this->p('app', ''));
         mkdir($this->p('app', 'config'));
         mkdir($this->p('app', 'config/environments'));
         $this->installFile('Core', 'config/environments/development.php');
         $this->installFile('Core', 'config/environments/production.php');
         mkdir($this->p('user', ''));
         mkdir($this->p('log', ''));
         mkdir($this->p('state', ''));
         $file = fopen($this->p('app', 'app.json'), 'w');
         if ($file) {
             fwrite($file, Json::prettyPrint($manifest));
             fclose($file);
             return $this->next();
         }
     } else {
         $this->configForm->name = $this->app->name;
         $this->configForm->version = $this->app->version;
         $this->configForm->modules = array('Controllers', 'Snippets', 'Databases', 'Migrations', 'ActiveModels', 'Extensions', 'Themes', 'AccessControl', 'Setup', 'Jtk', 'Console', 'Generators', 'Content');
     }
     return $this->render();
 }
Beispiel #4
0
 protected function update()
 {
     $messages = $this->Message->where('id > %i', $this->lastMessage)->orderBy('id');
     foreach ($messages as $message) {
         $this->trigger(Json::encode(array('id' => $message->id, 'author' => $message->author, 'message' => $message->message)));
         $this->lastMessage = $message->id;
     }
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 protected function decode($content)
 {
     try {
         return Json::decode($content);
     } catch (JsonException $e) {
         throw new AccessException('Invalid JSON file: ' . $e->getMessage(), 0, $e);
     }
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 protected function update()
 {
     $this->session->open();
     if (isset($this->session['jtk-notifications'])) {
         $notifications = $this->session['jtk-notifications'];
         if (is_array($notifications) and count($notifications) > 0) {
             unset($this->session['jtk-notifications']);
             $this->session->close();
             return Json::encodeResponse($notifications);
         }
     }
     $this->session->close();
     return null;
 }
Beispiel #7
0
 /**
  * {@inheritdoc}
  */
 public function read($name, $path)
 {
     $file = $path . '/' . $this->getFileName();
     if (!file_exists($file)) {
         return null;
     }
     try {
         $manifest = Json::decodeFile($file);
     } catch (JsonException $e) {
         return null;
     }
     if (!isset($manifest['name'])) {
         $manifest['name'] = $name;
     }
     return $this->getPackage($manifest, $path);
 }
Beispiel #8
0
 public function post($data)
 {
     if (!$this->request->accepts('json')) {
         return $this->invalid();
     }
     $message = $this->Message->create($data, array('message'));
     if (preg_match('/^\\/name (.+)/i', $message->message, $matches) === 1) {
         $this->session['name'] = trim($matches[1]);
         return Json::encodeResponse('success');
     }
     if (isset($this->session['name'])) {
         $message->author = $this->session['name'];
     }
     if ($message->save()) {
         return Json::encodeResponse('success');
     }
     return Json::encodeResponse($message->getErors());
 }
Beispiel #9
0
 protected function update()
 {
     if (isset($this->request->query['lastMessage'])) {
         $messages = $this->Message->where('id > %i', $this->request->query['lastMessage'])->orderBy('id');
         $response = array();
         foreach ($messages as $message) {
             $response[] = array('id' => $message->id, 'author' => $message->author, 'message' => $message->message);
         }
         if (count($response) > 0) {
             return Json::encodeResponse($response);
         }
     } else {
         $messages = $this->Message->orderByDescending('id')->limit(10);
         $response = array();
         foreach ($messages as $message) {
             $response[] = array('id' => $message->id, 'author' => $message->author, 'message' => $message->message);
         }
         $response = array_reverse($response);
         return Json::encodeResponse($response);
     }
     return null;
 }
Beispiel #10
0
 /**
  * {@inheritdoc}
  */
 public function decode(DataType $type, $value)
 {
     if (!isset($value)) {
         return null;
     }
     switch ($type->type) {
         case DataType::BOOLEAN:
             return $value != 0;
         case DataType::DATE:
         case DataType::DATETIME:
             return strtotime($value . ' UTC');
         case DataType::INTEGER:
             return intval($value);
         case DataType::FLOAT:
             return floatval($value);
         case DataType::STRING:
         case DataType::TEXT:
         case DataType::BINARY:
         case DataType::ENUM:
             return strval($value);
         case DataType::OBJECT:
             return Json::decode($value);
     }
 }
Beispiel #11
0
 /**
  * Run build script.
  * @param string $root Package root.
  * @throws InstallException on failure.
  */
 public function run($root)
 {
     $this->buildPath = $this->p('tmp/build/' . $this->name);
     if (!Utilities::dirExists($this->buildPath, true, true)) {
         throw new InstallException('Could not create build directory: ' . $this->buildPath);
     }
     $this->installPath = Paths::combinePaths($root, $this->name);
     if (!Utilities::dirExists($this->installPath, true, true)) {
         throw new InstallException('Could not create install directory: ' . $this->installPath);
     }
     if (isset($this->prepare)) {
         $this->info(tr('Preparing...'));
         call_user_func($this->prepare, $this);
     }
     $this->fetchSources();
     if (isset($this->build)) {
         $this->info(tr('Building...'));
         call_user_func($this->build, $this);
     }
     if (isset($this->install)) {
         $this->info(tr('Installing...'));
         call_user_func($this->install, $this);
     }
     $this->manifest['name'] = $this->name;
     $this->manifest['version'] = $this->version;
     if (isset($this->manifestFile) and isset($this->manifest)) {
         $this->info(tr('Creating manifest...'));
         $manifestFile = $this->installPath . '/' . $this->manifestFile;
         file_put_contents($manifestFile, Json::prettyPrint($this->manifest));
     }
 }
Beispiel #12
0
 /**
  * Create application.
  * @param string $appPath Path to app-directory containing at least an
  * 'app.json' configuration file.
  * @param string $userPath Path to user-directory.
  * @param string $entryScript Name of entry script, e.g. 'index.php'.
  */
 public function __construct($appPath, $userPath, $entryScript = 'index.php')
 {
     parent::__construct();
     $this->logger = ErrorHandler::getInstance()->getLogger();
     $appPath = Utilities::convertPath($appPath);
     $userPath = Utilities::convertPath($userPath);
     $manifestFile = $appPath . '/app.json';
     if (file_exists($manifestFile)) {
         $manifest = Json::decodeFile($manifestFile);
         $manifest = array_merge($this->defaultManifest, $manifest);
     } else {
         $this->logger->error('Invalid application. "app.json" not found. Configuring default application.');
         $this->noManifest = true;
         $manifest = $this->defaultManifest;
     }
     $this->manifest = $manifest;
     $this->m = new ModuleLoader();
     $this->paths = new Paths(Paths::convertPath(getcwd()), $userPath);
     $this->paths->app = $appPath;
     $this->paths->user = $userPath;
     //     $this->basePath = dirname($_SERVER['SCRIPT_NAME']);
     $this->entryScript = $entryScript;
     // Temporary work-around for weird SCRIPT_NAME.
     // When url contains a trailing dot such as
     // /app/index.php/admin./something
     // SCRIPT_NAME returns /app/index.php/admin./something instead of expected
     // /app/index.php
     $script = explode('/', $_SERVER['SCRIPT_NAME']);
     while (count($script) > 0) {
         if ($script[count($script) - 1] == $entryScript) {
             break;
         }
         array_pop($script);
     }
     $this->basePath = dirname(implode('/', $script));
     // END work-around
     $this->name = $manifest['name'];
     $this->version = $manifest['version'];
     $this->namespace = $manifest['namespace'];
     Autoloader::getInstance()->addPath($this->namespace, $this->p('app'));
     $this->paths->Jivoo = \Jivoo\PATH;
     $this->paths->Core = \Jivoo\PATH . '/Core';
     $file = new PhpStore($this->p('user/config.php'));
     $this->config = new Document();
     $this->config['user'] = new Config($file);
 }
Beispiel #13
0
 /**
  * Output tool creation JavaScript.
  * @return string JavaScript.
  */
 public function outputTools()
 {
     $output = 'if (typeof JIVOO !== "object") {';
     $output .= 'console.error("Jivoo module not found!");';
     $output .= '} else if (typeof JIVOO.devbar !== "object") {';
     $output .= 'console.error("Jivoo Devbar module not found!");';
     $output .= '} else {';
     foreach ($this->tools as $id => $tool) {
         if ($tool['ajax']) {
             $output .= 'JIVOO.devbar.addAjaxTool(';
         } else {
             $output .= 'JIVOO.devbar.addLinkTool(';
         }
         $output .= Json::encode($id) . ', ';
         $output .= Json::encode($tool['name']) . ', ';
         $link = $this->m->Routing->getLink($tool['route']);
         $output .= Json::encode($link);
         if ($tool['ajax'] and $tool['ajaxOnly']) {
             $output .= ', true';
         }
         $output .= ');';
     }
     $output .= '}';
     return $output;
 }
Beispiel #14
0
 /**
  * Get extension information.
  * @param string $extension Extension name.
  * @param string $kind Extension kind.
  * @return ExtensionInfo|null Extension information or null if not found or
  * invalid.
  */
 public function getInfo($extension, $kind = 'extensions')
 {
     if (!isset($this->info[$extension])) {
         $dir = $this->p($kind, $extension);
         $manifest = $this->kinds[$kind]['manifest'] . '.json';
         $library = null;
         if (!file_exists($dir . '/' . $manifest)) {
             foreach ($this->libraries as $key) {
                 $dir = $this->p($key, $kind . '/' . $extension);
                 if (file_exists($dir . '/' . $manifest)) {
                     $library = $key;
                 }
             }
             if (!isset($library)) {
                 return null;
             }
         }
         try {
             $info = Json::decodeFile($dir . '/' . $manifest);
         } catch (JsonException $e) {
             $this->logger->error(tr('Error decoding JSON: %1', $dir . '/' . $manifest));
             return null;
         }
         $this->info[$extension] = new ExtensionInfo($extension, $info, $library, $this->isEnabled($extension));
     }
     return $this->info[$extension];
 }
Beispiel #15
0
 /**
  * Create a JSON response.
  * @param mixed Data.
  * @return TextResponse Response.
  */
 public function respond($response)
 {
     return new TextResponse(Http::OK, 'json', Json::encode($response));
 }