Exemplo n.º 1
0
 /**
  * TODO.
  *
  * @param string $directory
  *
  * @throws Exception
  */
 public function readConfigDir($directory)
 {
     $environment = Ajde_Environment::current();
     $searchDirs = [CORE_DIR . $directory, CORE_DIR . $directory . $environment . DS, APP_DIR . $directory, APP_DIR . $directory . $environment . DS];
     foreach ($searchDirs as $searchDir) {
         foreach (Ajde_Fs_Find::findFiles($searchDir, '*.json') as $configFile) {
             if (!($configData = json_decode(file_get_contents($configFile), true))) {
                 throw new Exception('Config file ' . $configFile . ' contains invalid JSON');
             }
             $this->merge(pathinfo($configFile, PATHINFO_FILENAME), $configData);
         }
     }
 }
Exemplo n.º 2
0
Arquivo: Meta.php Projeto: nabble/ajde
 /**
  * @return Ajde_Crud_Cms_Meta_Type[]
  */
 public function getTypes()
 {
     if (!$this->_types) {
         $ds = DIRECTORY_SEPARATOR;
         $files = Ajde_Fs_Find::findFiles(LIB_DIR . 'Ajde' . $ds . 'Crud' . $ds . 'Cms' . $ds . 'Meta' . $ds . 'Type' . $ds, '*.php');
         foreach ($files as $file) {
             $filename = pathinfo($file, PATHINFO_FILENAME);
             $className = 'Ajde_Crud_Cms_Meta_Type_' . ucfirst($filename);
             $this->_types[strtolower($filename)] = new $className();
         }
         ksort($this->_types);
     }
     return $this->_types;
 }
Exemplo n.º 3
0
 public function afterDelete()
 {
     // Delete main file
     $clean = Ajde_Fs_Find::findFiles($this->uploadDirectory, $this->pointer);
     // Delete thumbnail file
     $clean = array_merge($clean, Ajde_Fs_Find::findFiles($this->uploadDirectory, $this->thumbnail));
     // Delete thumbs of main file
     $clean = array_merge($clean, Ajde_Fs_Find::findFiles($this->uploadDirectory . Ajde_Resource_Image::$_thumbDir . DS, pathinfo($this->pointer, PATHINFO_FILENAME) . '_*x*.' . pathinfo($this->pointer, PATHINFO_EXTENSION)));
     // Delete thumbs of thumbnail file
     $clean = array_merge($clean, Ajde_Fs_Find::findFiles($this->uploadDirectory . Ajde_Resource_Image::$_thumbDir . DS, pathinfo($this->thumbnail, PATHINFO_FILENAME) . '_*x*.' . pathinfo($this->thumbnail, PATHINFO_EXTENSION)));
     foreach (array_unique($clean) as $path) {
         unlink($path);
     }
 }
Exemplo n.º 4
0
Arquivo: Db.php Projeto: nabble/ajde
 private function installFromVersion($version = 'v0')
 {
     $sqlFiles = Ajde_Fs_Find::findFiles(DEV_DIR . 'db' . DIRECTORY_SEPARATOR, 'v*.sql');
     usort($sqlFiles, [$this, 'versionSort']);
     foreach ($sqlFiles as $sqlFile) {
         $sqlFileVersion = pathinfo($sqlFile, PATHINFO_FILENAME);
         if (version_compare($sqlFileVersion, $version) > 0) {
             $this->executeFile($sqlFile);
         }
     }
 }
Exemplo n.º 5
0
Arquivo: Lang.php Projeto: nabble/ajde
 public function getAvailableNiceNames()
 {
     $langs = Ajde_Fs_Find::findFiles(LANG_DIR, '*');
     $return = [];
     foreach ($langs as $lang) {
         $lang = basename($lang);
         $return[$lang] = $this->getNiceName($lang);
     }
     return $return;
 }
Exemplo n.º 6
0
 public function chromeAppDownload()
 {
     // Temp dir
     $appdir = TMP_DIR . 'app' . DIRECTORY_SEPARATOR;
     mkdir($appdir);
     // manifest.json
     $url = config('i18n.rootUrl') . 'admin/?chromeapp=1';
     $manifest = (object) ['manifest_version' => 2, 'name' => config('app.title'), 'description' => config('app.description'), 'version' => '1.0', 'icons' => (object) ['128' => 'app.png'], 'app' => (object) ['urls' => [$url], 'launch' => (object) ['web_url' => $url]], 'permissions' => ['unlimitedStorage', 'notifications']];
     $json = json_encode($manifest);
     // Clean temp dir
     Ajde_Fs_Directory::truncate($appdir);
     // Put files
     file_put_contents($appdir . 'manifest.json', $json);
     copy(MEDIA_DIR . 'app.png', $appdir . 'app.png');
     // All files to zip
     $appfiles = Ajde_Fs_Find::findFiles($appdir, '*');
     // Make the zip file
     $zipfile = TMP_DIR . 'app.zip';
     $zip = new ZipArchive();
     $zip->open($zipfile, ZIPARCHIVE::OVERWRITE);
     foreach ($appfiles as $file) {
         $zip->addFile($file, basename($file));
     }
     $zip->close();
     // Get contents
     $zipcontents = file_get_contents($zipfile);
     // Path to crx file
     $crxfile = TMP_DIR . 'app.crx';
     // Path to pem file
     $pemfile = DEV_DIR . 'app.pem';
     $pemcontents = file_get_contents($pemfile);
     // Fetch private key from file and ready it
     $privkey = openssl_get_privatekey($pemcontents);
     // Get public key
     $pubkey = openssl_pkey_get_details($privkey);
     $pubkey = $pubkey['key'];
     // geting rid of -----BEGIN/END PUBLIC KEY-----
     $pubkey = explode('-----', $pubkey);
     $pubkey = trim($pubkey[2]);
     // decode the public key
     $pubkey = base64_decode($pubkey);
     // make a SHA1 signature using our private key
     openssl_sign($zipcontents, $signature, $privkey, OPENSSL_ALGO_SHA1);
     openssl_free_key($privkey);
     // .crx package format:
     //
     //   magic number               char(4)
     //   crx format ver             byte(4)
     //   pub key lenth              byte(4)
     //   signature length           byte(4)
     //   public key                 string
     //   signature                  string
     //   package contents, zipped   string
     //
     // see http://code.google.com/chrome/extensions/crx.html
     //
     $fh = fopen($crxfile, 'wb');
     fwrite($fh, 'Cr24');
     // extension file magic number
     fwrite($fh, pack('V', 2));
     // crx format version
     fwrite($fh, pack('V', strlen($pubkey)));
     // public key length
     fwrite($fh, pack('V', strlen($signature)));
     // signature length
     fwrite($fh, $pubkey);
     // public key
     fwrite($fh, $signature);
     // signature
     fwrite($fh, $zipcontents);
     // package contents, zipped
     fclose($fh);
     // We'll be outputting a chrome extension
     header('Content-type: application/x-chrome-extension');
     // It will be called app.crx
     header('Content-Disposition: attachment; filename="app.crx"');
     // Output the crx file
     readfile($crxfile);
     // Clean up
     unlink($zipfile);
     unlink($crxfile);
     Ajde_Fs_Directory::delete($appdir);
     exit;
 }