Ejemplo n.º 1
0
	/**
	 * Returns the best language version of given page for current user.
	 *
	 * @author   Jan Tvrdík
	 * @param    string
	 * @return   string|FALSE      language code or FALSE (no suitable version available)
	 */
	private function getPreferredLanguageVersion($page)
	{
		$available = $this->getPageManager()->getAvailableLanguages($page);
		$detected = $this->httpRequest->detectLanguage($available);
		if ($detected === NULL) {
			if (in_array($this->defaultLanguage, $available)) {
				return $this->defaultLanguage;
			} else {
				return FALSE;
			}

		} else {
			return $detected;
		}
	}
Ejemplo n.º 2
0
<?php

use Nette\String, Nette\Web\HttpRequest;
require_once dirname(__FILE__) . "/../../libs/nette.php";
require_once dirname(__FILE__) . '/paths.php';
$httpRequest = new HttpRequest();
$folder = $httpRequest->getQuery("folder", "");
$root = realpath(FILES_BASE_PATH);
$dir = realpath($root . "/" . $folder);
// check directory
if ($root === false || $dir === false || !String::startsWith($dir, $root) || !is_dir($dir)) {
    echo json_encode(array("error" => "Problem with directory."));
    exit;
}
$directories = array();
$files = array();
// up
if ($root !== $dir) {
    $dirPieces = explode("/", $folder);
    array_pop($dirPieces);
    $directories[] = array("type" => "up", "name" => "..", "key" => implode("/", $dirPieces));
}
foreach (new DirectoryIterator($dir) as $fileInfo) {
    $filename = $fileInfo->getFileName();
    // skip hidden files, . and ..
    if (String::startsWith($filename, ".")) {
        continue;
    }
    if ($fileInfo->isDir()) {
        $directories[] = array("type" => "folder", "name" => $filename, "key" => ($folder ? "{$folder}/" : "") . $filename);
    } else {
Ejemplo n.º 3
0
<?php

use Nette\Web\HttpRequest, Nette\String;
require_once dirname(__FILE__) . "/../../libs/nette.php";
require_once dirname(__FILE__) . '/paths.php';
$httpRequest = new HttpRequest();
$file = $httpRequest->getFile("file");
$folder = $httpRequest->getPost("folder", "");
$state = array();
$root = realpath(FILES_BASE_PATH);
$dir = realpath(FILES_BASE_PATH . "/" . $folder);
// security check
//if (!$allowed) {
//	$state["error"] = "You are not allowed to upload files.";
//}
if (empty($file)) {
    $state["error"] = "No file was uploaded";
}
// check directory
if ($root === false || $dir === false || !String::startsWith($dir, $root) || !is_dir($dir) || !is_writable($dir)) {
    $state["error"] = "Problem with directory to upload.";
}
if (!empty($state["error"])) {
    die(json_encode($state));
}
if ($file->isOk()) {
    $filename = String::webalize($file->getName(), ".");
    $success = @$file->move("{$dir}/{$filename}");
    if ($success) {
        // nastavit typ - je to obrázek?
        $type = @$file->getImageSize() ? "image" : "file";