Esempio n. 1
0
 private function chdir($ftp, $splitPaths)
 {
     $passedPaths = [];
     foreach ($splitPaths as $splitPath) {
         $passedPaths[] = $splitPath;
         $ok = @ftp_chdir($ftp, $splitPath);
         if (!$ok) {
             throw new FolderNotFoundException(Path::join($passedPaths));
         }
     }
 }
Esempio n. 2
0
 public function __toString()
 {
     $filename = Path::join(array($path, 'images', 'famfamfam', $this->name));
     if (substr($filename, -4) != '.png') {
         $filename .= '.png';
     }
     if (is_readable($filename)) {
         return file_get_contents($filename);
     } else {
         return '';
     }
 }
Esempio n. 3
0
 public function __construct($argv = array())
 {
     $filename = empty($argv[0]) ? 'redirect' : $argv[0];
     $filename = Path::join(array($path, 'html', $filename));
     if (substr($filename, -5) != '.html') {
         $filename .= '.html';
     }
     if (is_readable($filename)) {
         $this->filename = $filename;
     }
     //-->
     if (isset($_GET['compress'])) {
         $this->options['compress'] = $_GET['compress'];
     }
 }
Esempio n. 4
0
 public function __construct($argv = array())
 {
     if (!empty($argv[0])) {
         $className = $this->name($argv[0]);
         $fileName = Path::join(array('api', $className));
         if (substr($fileName, -4) != '.php') {
             $fileName .= '.php';
         }
         if (is_readable($fileName)) {
             $this->filename = $fileName;
             $this->className = $className;
             $this->dispatch();
         }
     }
 }
Esempio n. 5
0
 public static function real($path)
 {
     $path = Path::split($path);
     $newpath = array();
     while (list(, $v) = each($path)) {
         switch ($v) {
             case '.':
                 continue;
             case '..':
                 array_pop($newpath);
                 continue;
             default:
                 $newpath[] = $v;
         }
     }
     return Path::join($newpath);
 }
Esempio n. 6
0
 public function __construct($argv = array())
 {
     $filename = Path::join(array('css', $argv[0]));
     if (substr($filename, -4) != '.css') {
         $filename .= '.css';
     }
     if (is_readable($filename)) {
         $this->filename = $filename;
     }
     //-->
     if (isset($_GET['compress'])) {
         $this->options['compress'] = $_GET['compress'];
     }
     //-->
     if (empty($this->filename)) {
         $this->parseAll();
     } elseif (is_readable($this->filename)) {
         $this->css[$this->filename] = $this->parse(file_get_contents($this->filename));
     }
 }
Esempio n. 7
0
 /**
  * Save image to given file.
  *
  * @param string $fname      filename
  * @param string $format     possible values in self::$formats
  * @param integer $quality   quality of output jpeg
  * @param boolean $overwrite if true, it overwrite file if it exists
  *
  * @throws CEFilesystemError ({@link CEFileSystemError description})
  *
  * @access public
  */
 public function saveToFile($fname, $format = null, $quality = null, $overwrite = false)
 {
     $this->isInitialized();
     $pathinfo = pathinfo($fname);
     if (is_null($format)) {
         $format = $pathinfo['extension'];
     }
     $format = $this->checkFormat(strtolower($format));
     if ('' == $pathinfo['dirname']) {
         $pathinfo['dirname'] = '.';
     }
     $pathinfo['dirname'] = realpath($pathinfo['dirname']);
     $fullpath = Path::join($pathinfo['dirname'], $pathinfo['basename']);
     if (!is_writeable($pathinfo['dirname'])) {
         throw new CEFileSystemError(sprintf('Cannot write to "%s" directory.', $pathinfo['dirname']), 300);
     }
     if (file_exists($fullpath)) {
         if ($overwrite) {
             unlink($fullpath);
         } else {
             throw new CEFileSystemError(sprintf('File "%s" already exists.', $fullpath), 301);
         }
     }
     if (is_null($quality)) {
         $quality = self::QUALITY;
     }
     $fun = self::$formats[$format];
     $fun($this->body, $fname, $quality);
 }
Esempio n. 8
0
 function searchFiles($path, $name, $content)
 {
     if ($name === '' && $content === '') {
         throw new NameException();
     }
     $parent = $this->rootFolder;
     if ($parent->isProxy) {
         if ($parent->canSearch) {
             return $parent->searchFiles($path, $name, $content);
         }
         return [];
     }
     $splitPaths = Path::split($path);
     $passedFolders = [];
     while ($splitPaths) {
         $folderName = array_shift($splitPaths);
         $passedFolders[] = $folderName;
         $item = $parent->get($folderName);
         if (!$item) {
             throw new FolderNotFoundException(Path::join($passedFolders));
         } else {
             if ($item instanceof File) {
                 throw new NotAFolderException($path);
             } elseif ($item->isProxy) {
                 if ($item->canSearch) {
                     $files = $item->searchFiles(Path::join($splitPaths), $name, $content);
                     foreach ($files as &$file) {
                         $file['path'] = Path::join([$path, $file['path']]);
                     }
                     return $files;
                 }
                 throw new NotAFolderException(Path::join($passedFolders));
             }
         }
         $parent = $item;
     }
     $files = $parent->searchFiles($name, $content);
     foreach ($files as &$file) {
         $file['path'] = Path::join([$path, $file['path']]);
     }
     return $files;
 }
Esempio n. 9
0
        return;
    }
    $fname = strtolower($classname);
    $fname = str_replace('_', '', $fname);
    $fname1 = sprintf(ROOT . '%sinc%sclass_%s.php', DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $fname);
    if (is_file($fname1)) {
        require_once $fname1;
        return;
    }
    $fname2 = sprintf(ROOT . '%sinc%sns_%s.php', DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $fname);
    if (is_file($fname2)) {
        require_once $fname2;
        return;
    }
    echo $fname1 . '<br />';
    echo $fname2 . '<br />';
}
require_once sprintf('..%sconfig.php', DIRECTORY_SEPARATOR);
$config = new CoreConfig();
/*
new CoreInit(
    $config->enc_from,
    $config->enc_to,
    $config->comp_level,
    $config->email
);
*/
define('OPT_DIR', Path::join(ROOT, 'inc', 'opt') . DIRECTORY_SEPARATOR);
require_once Path::join(ROOT, 'inc', 'opt', 'opt.class.php');
$auth = new Auth();
echo $auth->authenticate('mysz', sha1('jsDhzc1'));
Esempio n. 10
0
 /**
  * Recursive walk into directory and return it's content.
  *
  * @param string  $dir directory to scan
  * @param boolean $assoc return associative or normal array
  * @param integer $maxLevel how deep scan $dir
  *
  * @return array
  * @throws CENotFound ({@link CENotFound description})
  *
  * @access public
  */
 public static function walk($dir, $assoc = false, $maxLevel = false, $curLevel = 1)
 {
     $dir = Path::real($dir);
     $ret = array();
     $data = Path::listdir($dir, self::SORT_ASC, true);
     if ($assoc) {
         $ret[$dir] = array('dirs' => $data['dirs'], 'files' => $data['files']);
     } else {
         $ret[] = array($dir, $data['dirs'], $data['files']);
     }
     if (false === $maxLevel || $maxLevel > $curLevel) {
         foreach ($data['dirs'] as $d) {
             $path = Path::join($dir, $d);
             $ret = array_merge($ret, Path::walk($path, $assoc, $maxLevel, $curLevel + 1));
         }
     }
     return $ret;
 }
Esempio n. 11
0
 /**
  * Constructor
  *
  * Checks for valid parameters, and initializes proper options.
  *
  * @param string  $enc_from   character set of files (present)
  * @param string  $enc_to     output character set
  * @param integer $comp_level
  * @param array   $incpath    elements of include path
  *
  * @access public
  */
 public function __construct(&$enc_from = null, &$enc_to = null, &$comp_level = null, &$email = null, &$incPath = null)
 {
     if (is_null($incPath)) {
         $this->_incPath = array(ROOT, Path::join(ROOT, 'inc'));
     } else {
         $this->_incPath = $incPath;
     }
     if (!is_null($email) && Validate::email($email)) {
         $this->_email = $email;
     }
     if (is_null($comp_level)) {
         $comp_level = self::COMP_LEVEL;
     }
     if (is_null($enc_from)) {
         $enc_from = self::ENC_FROM;
     }
     if (is_null($enc_to)) {
         $enc_to = self::ENC_TO;
     }
     if (defined('DEBUG') && DEBUG) {
         $this->_debug = true;
     }
     $ob_start_opts = array();
     if ($comp_level > 0) {
         $comp = $this->_initCompress($comp_level);
         if ($comp !== false) {
             $ob_start_opts[] = $comp;
         }
     }
     if ($enc_from !== $enc_to) {
         $enc = $this->_initEncoding($enc_from, $enc_to);
         if ($enc !== false) {
             $ob_start_opts[] = $enc;
         }
     }
     if (count($ob_start_opts) > 0) {
         ob_start($ob_start_opts);
         $this->_initialized = true;
     } else {
         $this->_initialized = false;
     }
     $this->_initPhpSettings();
 }
Esempio n. 12
0
 function searchFiles($path, $name, $content)
 {
     $splitPaths = Path::split($path);
     $this->chdir($splitPaths);
     $files = $this->searchFilesRecursive($name, $content, []);
     foreach ($files as &$file) {
         $file['path'] = Path::join([$path, $file['path']]);
     }
     return $files;
 }
Esempio n. 13
0
    }
    $fname = strtolower($classname);
    $fname = str_replace('_', '', $fname);
    $fname1 = sprintf('inc%sclass_%s.php', DIRECTORY_SEPARATOR, $fname);
    if (is_file($fname1)) {
        require_once $fname1;
        return;
    }
    $fname2 = sprintf('inc%sns_%s.php', DIRECTORY_SEPARATOR, $fname);
    if (is_file($fname2)) {
        require_once $fname2;
        return;
    }
}
require_once 'config.php';
$config = new CoreConfig();
new CoreInit($config->enc_from, $config->enc_to, $config->comp_level, $config->email);
define('OPT_DIR', Path::join(ROOT, 'inc/opt') . DIRECTORY_SEPARATOR);
require_once Path::join(ROOT, 'inc/opt/opt.class.php');
$id_post = 1;
try {
    $post = new Post($id_post);
    $post->title = 'asd';
    $post->show();
} catch (CENotFound $e) {
    echo '<pre>';
    echo $e;
    echo '</pre>';
    exit;
}
//$post->setFromDB(1);
Esempio n. 14
0
 /**
  * Save uploaded file in destionation directory
  *
  * Use addtional methods, {@link Upload::preSave()} and {@link Upload::postSave()}
  * for other operations, needed on uploaded file (like check for proper
  * size etc).
  *
  * @param string  $dest destination directory (if other then {@link Upload::$saveDir})
  * @param boolean $genName use original filename to store, or generated
  * @param boolean $overwrite overwrite file if destination file already exists?
  *
  * @return boolean
  * @throws CEFileSystemError {@link CEFileSystemError description}
  * @throws CEUploadError {@link CEUploadError description}
  *
  * @access public
  */
 public function save($dest = null, $genFname = false, $overwrite = false)
 {
     if (is_null($dest)) {
         $dest = $this->saveDir;
     }
     $dest = realpath($dest);
     if ('' == $dest || !is_writeable($dest)) {
         throw new CEFileSystemError(sprintf('Cannot write to "%s" ' . 'directory.', $dest), 301);
     }
     if ($genFname) {
         $fname = $this->generateFname();
     } else {
         $fname = $this->name;
     }
     $path = Path::join($dest, $fname);
     if (is_file($path)) {
         if ($overwrite) {
             unlink($path);
         } else {
             throw new CEFileSystemError(sprintf('File "%s" already ' . 'exists.', $path), 302);
         }
     }
     $preSave = $this->preSave();
     if (!is_null($preSave)) {
         throw new CEUploadError($preSave[0], $preSave[1]);
     }
     if (isset($_SESSION[$this->sessionName][$this->fieldName])) {
         unset($_SESSION[$this->sessionName][$this->fieldName]);
     }
     $ret = rename($this->tmpName, $path);
     $postSave = $this->postSave();
     if (!is_null($postSave)) {
         throw new CEUploadError($postSave[0], $postSave[1]);
     }
     return $ret;
 }
Esempio n. 15
0
 function searchFiles($name, $content)
 {
     $folders = [];
     $foundFiles = [];
     foreach ($this->getItemArray() as $item) {
         if ($item instanceof Folder) {
             $folders[] = $item;
         } elseif ($item instanceof File) {
             $nameMatched = true;
             if ($name) {
                 $nameMatched = false;
                 if (strpos($item->name, $name) !== false) {
                     $nameMatched = true;
                 }
             }
             $contentMatched = true;
             if ($content) {
                 $contentMatched = false;
                 $contentJson = $item->getContent();
                 $fileContent = $contentJson['content'];
                 if (strpos($fileContent, $content) !== false) {
                     $contentMatched = true;
                 }
             }
             if ($nameMatched && $contentMatched) {
                 $file = $item->toClientJson();
                 $file['path'] = $file['name'];
                 $foundFiles[] = $file;
             }
         }
     }
     // find files in subfolders
     foreach ($folders as $folder) {
         $subfiles = $folder->searchFiles($name, $content);
         foreach ($subfiles as &$subfile) {
             $subfile['path'] = Path::join([$folder->name, $subfile['path']]);
         }
         $foundFiles = array_merge($foundFiles, $subfiles);
     }
     return $foundFiles;
 }