コード例 #1
0
ファイル: database.php プロジェクト: just-paja/fudjan
 /**
  * @dataProvider database_items_batch
  */
 public function test_raw_data($item)
 {
     $f = BASE_DIR . '/var/cache/test/file.test';
     \System\Directory::check(BASE_DIR . '/var/cache/test');
     file_put_contents($f, 'test');
     $item = new \Test\Model\Mock\Database($item);
     $data = $item->get_data_raw();
     $obj = $item->to_object();
     if ($item->belongs) {
         $this->assertFalse(array_key_exists('belongs', $data));
         $this->assertTrue(array_key_exists('id_belongs', $data));
     }
     if ($item->belongs_def) {
         $this->assertFalse(array_key_exists('belongs', $data));
         $this->assertTrue(array_key_exists('id_belongs_def', $data));
     }
     if ($item->belongs_null) {
         $this->assertFalse(array_key_exists('belongs_null', $data));
         $this->assertTrue(array_key_exists('id_belongs_null', $data));
     }
     if ($item->file) {
         $this->assertTrue(array_key_exists('file', $data));
         $this->assertTrue(is_string($data['file']));
         $file = json_decode($data['file'], true);
         $this->assertTrue(array_key_exists('hash', $file));
         $this->assertEquals($item->file->hash, $file['hash']);
     }
     unlink($f);
 }
コード例 #2
0
ファイル: composer.php プロジェクト: just-paja/fudjan
 public static function find($path, $regexp = null)
 {
     $dirs = self::list_dirs($path);
     $files = array();
     foreach ($dirs as $dir) {
         \System\Directory::find_all_files($dir, $files, $regexp);
     }
     return $files;
 }
コード例 #3
0
ファイル: jade.php プロジェクト: just-paja/fudjan
 public function construct($attrs)
 {
     \System\Directory::check(BASE_DIR . self::DIR_CACHE);
     $cache = \System\Settings::getSafe(array('cache', 'templates'), true);
     if (class_exists('Jade\\Jade')) {
         $this->jade = new \Jade\Jade(array('cache' => $cache ? BASE_DIR . self::DIR_CACHE : null));
     } else {
         throw new \System\Error\MissingDependency('Could not find jade template compiler.', 'Please install ronan-gloo/jadephp');
     }
 }
コード例 #4
0
ファイル: status.php プロジェクト: just-paja/fudjan
 /**
  * Write error into log file
  *
  * @param string $type
  * @param string $msg
  * @return void
  */
 public static function report($type, $report)
 {
     $debug = \System\Settings::getSafe(array('dev', 'debug', 'backend'), false);
     \System\Directory::check(BASE_DIR . self::DIR_LOGS);
     $log_to = fopen(BASE_DIR . self::DIR_LOGS . '/' . $type . '.log', 'a+');
     if (!$debug && $type == 'error') {
         $rcpt = \System\Settings::getSafe(array('dev', 'mailing', 'errors'), null);
         if ($rcpt) {
             \Helper\Offcom\Mail::create('[Fudjan] Server error', $report, $rcpt)->send();
         }
     }
     if (is_resource($log_to)) {
         fwrite($log_to, $report);
     }
 }
コード例 #5
0
ファイル: package.php プロジェクト: just-paja/fudjan
 public function cmd_artifact(array $params = array())
 {
     \System\Directory::check(BASE_DIR . static::DIR_PACKAGES);
     $target = BASE_DIR . static::DIR_PACKAGES . '/artifact.tar';
     $result = $target . '.gz';
     if (isset($params[0])) {
         $target = $params[0];
     }
     if (file_exists($target)) {
         unlink($target);
     }
     if (file_exists($result)) {
         unlink($result);
     }
     $iter = new \RecursiveDirectoryIterator(BASE_DIR);
     $iter->setFlags(\FileSystemIterator::SKIP_DOTS);
     $iter = new ProjectDirectoryRecursiveIterator($iter);
     $iter = new \RecursiveIteratorIterator($iter);
     $archive = new \PharData($target);
     $archive->buildFromIterator($iter, BASE_DIR);
     $archive->compress(\Phar::GZ);
     unlink($target);
 }
コード例 #6
0
ファイル: json.php プロジェクト: just-paja/fudjan
 /** Read all JSON files in dir and return content
  * @param string $dir_dist   Path to directory
  * @param &array $temp       Variable to write in
  * @param bool   $assoc_keys Associate file names (without postifx) to data read
  * @param &array $files      Files that have been read during dist search
  * @return array
  */
 public static function read_dist($dir_dist, &$temp = array(), $assoc_keys = false, &$files = array())
 {
     if (\System\Directory::check($dir_dist, false)) {
         $dir = opendir($dir_dist);
         while ($f = readdir($dir)) {
             if (strpos($f, ".") !== 0 && strpos($f, ".json")) {
                 list($mod) = explode(".", $f);
                 $json = (array) self::read($dir_dist . '/' . $f);
                 $files[] = $dir_dist . '/' . $f;
                 if ($assoc_keys) {
                     if (isset($temp[$mod])) {
                         if (isset($json['overwrite']) && $json['overwrite']) {
                             unset($json['overwrite']);
                             $temp[$mod] = $json;
                         } else {
                             $temp[$mod] = array_replace_recursive($temp[$mod], $json);
                         }
                     } else {
                         unset($json['overwrite']);
                         $temp[$mod] = $json;
                     }
                 } else {
                     if (isset($json['overwrite']) && $json['overwrite']) {
                         unset($json['overwrite']);
                         $temp = $json;
                     } else {
                         $temp = array_merge_recursive($temp, $json);
                     }
                 }
             }
         }
         closedir($dir);
         return $temp;
     } else {
         throw new \System\Error\File(sprintf('Directory "%s" either does not exist or is not accessible.', $dir_dist));
     }
 }
コード例 #7
0
ファイル: settings.php プロジェクト: just-paja/fudjan
 /** Does config environment exist
  * @param string $env Environment name
  * @return bool
  */
 public static function env_create($env)
 {
     return \System\Directory::check(BASE_DIR . self::DIR_CONF_DIST . '/' . $env);
 }
コード例 #8
0
ファイル: text.php プロジェクト: just-paja/fudjan
 /** Get list of available files from user input
  * @param string $type
  * @param list   $modules
  * @return array
  */
 public function get_file_list($modules)
 {
     $found = array();
     $missing = array();
     try {
         $use_cache = \System\Settings::get('cache', 'resources');
     } catch (\System\Error\Config $e) {
         $use_cache = false;
     }
     if ($use_cache) {
         $dirs = array(BASE_DIR . $this::DIR_CACHE);
     } else {
         if ($this->src == 'static') {
             $src = $this::DIR_STATIC;
         } else {
             $src = $this::DIR_MEDIA;
         }
         $dirs = \System\Composer::list_dirs($src);
     }
     foreach ($modules as $module) {
         $mod_found = false;
         foreach ($dirs as $dir) {
             foreach ($this::$postfixes as $postfix) {
                 $path = $dir . DIRECTORY_SEPARATOR . $module;
                 if (file_exists($p = $path . '.list')) {
                     $list = $this->get_file_list(array_map('trim', array_filter(explode("\n", \System\File::read($p)))));
                     $found = array_merge($found, $list[self::KEY_FOUND]);
                     $missing = array_merge($missing, $list[self::KEY_MISSING]);
                     $mod_found = true;
                     break;
                 } else {
                     if (is_file($p = $path) || is_file($p = $path . '.' . $postfix)) {
                         $found[] = $p;
                         $mod_found = true;
                     }
                 }
                 if (is_dir($path)) {
                     $json = null;
                     $meta = self::get_meta($path, 'bower.json');
                     if (!$meta) {
                         $meta = self::get_meta($path, 'package.json');
                     }
                     if ($meta) {
                         $files = array();
                         foreach ($meta as $file) {
                             $files[] = str_replace($dir . '/', '', $path . '/' . $file);
                         }
                         $list = $this->get_file_list($files);
                         $found = array_merge($found, $list[self::KEY_FOUND]);
                         $mod_found = true;
                         break;
                     } else {
                         $files = \System\Directory::find_all_files($path);
                         foreach ($files as $key => $tmp_file) {
                             $files[$key] = str_replace($dir . '/', '', $files[$key]);
                         }
                         $list = $this->get_file_list($files);
                         $found = array_merge($found, $list[self::KEY_FOUND]);
                         $missing = array_merge($missing, $list[self::KEY_MISSING]);
                         $mod_found = true;
                         break;
                     }
                 }
             }
             if ($mod_found) {
                 break;
             }
         }
         if (!$mod_found) {
             $missing[] = $module;
         }
     }
     $this->sum = self::get_module_sum_from_list($modules);
     return array(self::KEY_FOUND => array_unique(array_filter($found)), self::KEY_MISSING => array_unique(array_filter($missing)), self::KEY_SUM => $this->sum);
 }
コード例 #9
0
ファイル: module.php プロジェクト: just-paja/fudjan
 /**
  * Get all available modules
  *
  * @param bool $with_perms
  * @return array
  */
 public static function get_all($with_perms = false)
 {
     $mods = array();
     $path = ROOT . self::DIR;
     \System\Directory::find_all_files($path, $mods, '/\\.php$/');
     sort($mods);
     foreach ($mods as &$mod) {
         $mod = array("path" => preg_replace('/\\.php$/', '', substr($mod, strlen($path) + 1)));
         if ($with_perms) {
             $mod['perms'] = \System\User\Perm::get_all()->where(array("type" => 'module', "trigger" => $mod['path']))->fetch();
         }
     }
     return $mods;
 }
コード例 #10
0
ファイル: thumb.php プロジェクト: just-paja/fudjan
 /** Generate thumb using GD library
  * @param self $obj         Instance of image
  * @return bool
  */
 public static function gen_gd(self $obj)
 {
     $obj->image->refresh_info();
     $coords = array('w_new' => $obj->width, 'h_new' => $obj->height, 'w_org' => intval($obj->image->width()), 'h_org' => intval($obj->image->height()));
     $tpth = BASE_DIR . $obj->get_path();
     \System\Directory::check(dirname($tpth));
     if ($coords['w_new'] < $coords['w_org'] || $coords['h_new'] < $coords['h_org']) {
         $coords = self::calc_thumb_coords($coords, $obj->crop);
         $im = \System\Image::get_gd_resource($obj->image);
         $th = imagecreatetruecolor($coords['w_new'], $coords['h_new']);
         $trans = $obj->image->format() == 3;
         if ($trans) {
             $transparent = imagecolorallocatealpha($th, 0, 0, 0, 127);
             imagefill($th, 0, 0, $transparent);
         } else {
             $wh = imagecolorallocate($th, 255, 255, 255);
             imagefill($th, 0, 0, $wh);
         }
         imagecopyresampled($th, $im, intval($coords['dst_x']), intval($coords['dst_y']), 0, 0, intval($coords['xw']), intval($coords['xh']), $coords['w_org'], $coords['h_org']);
         if (file_exists($tpth)) {
             unlink($tpth);
         }
         if ($trans) {
             imagealphablending($th, false);
             imagesavealpha($th, true);
             imagepng($th, $tpth);
         } else {
             imagejpeg($th, $tpth, 99);
         }
         imagedestroy($th);
     } else {
         $obj->image->copy($tpth);
     }
     return $obj;
 }
コード例 #11
0
ファイル: loader.php プロジェクト: just-paja/fudjan
 /** Load all classes inside directory
  * @param string $dir
  * @return void
  */
 public static function load_dir($dir)
 {
     $files = \System\Directory::find_all_files($dir);
     foreach ($files as $file) {
         $fname = str_replace($dir . '/', '', $file);
         $cname = self::get_class_from_file($fname);
         if (!class_exists($cname, false) && !interface_exists($cname, false)) {
             require_once $file;
         }
     }
 }
コード例 #12
0
ファイル: file.php プロジェクト: just-paja/fudjan
 /** Read file data
  * @param string $path
  * @param bool   $silent
  * @throws System\Error\File
  * @throws System\Error\Permissions
  * @return string
  */
 public static function read($path, $silent = false)
 {
     if (\System\Directory::check(dirname($path), false) && file_exists($path)) {
         if (is_readable($path)) {
             return file_get_contents($path);
         } else {
             if (!$silent) {
                 throw new \System\Error\Permissions(sprintf('Failed to read file "%s". It is not readable.', $path));
             }
         }
     } else {
         if (!$silent) {
             throw new \System\Error\File(sprintf('Failed to read file "%s". It does not exist.', $path));
         }
     }
     return false;
 }
コード例 #13
0
ファイル: cache.php プロジェクト: just-paja/fudjan
 public static function clear($all = false)
 {
     $base = BASE_DIR . self::DIR_CACHE;
     $files = glob($base . '/*');
     foreach ($files as $file) {
         $name = str_replace($base . '/', '', $file);
         if (!$all && in_array($name, static::$persistent)) {
             continue;
         }
         if (is_file($file)) {
             unlink($file);
         } else {
             if (is_dir($file)) {
                 \System\Directory::remove($file);
             }
         }
     }
 }