public function folder($folder, $filename = null) { if (!preg_match('/^[0-9]+x[0-9]+$/', $folder)) { // Zijn er geen afmetingen meegegeven? return $this->onFolderNotFound(); } if (!$filename) { // Komt de afbeelding uit een subfolder($recursive)? $url = Url::getCurrentURL(); $path = array('folders' => $url->getFolders(), 'filename' => $url->getFilename()); $subfolders = array_slice($path['folders'], $this->depth + 1); $filename = implode('/', $subfolders) . '/' . $path['filename']; } $source = $this->imagesFolder . $filename; if (!file_exists($source)) { return new HttpError(404, array('warning' => 'Image "' . $filename . '" not found in "' . $this->imagesFolder . '"')); } $target = $this->targetFolder . $folder . '/' . $filename; if (!file_exists($target) || filemtime($source) > filemtime($target)) { $dimensions = explode('x', $folder); \Sledgehammer\mkdirs(dirname($target)); $image = new Image($source); $image->saveThumbnail($target, $dimensions[0], $dimensions[1]); } return new File($target); }
protected function listSeeders() { $dir = new DirectoryIterator(\Sledgehammer\PATH . 'database/seeds'); $seeds = []; $url = Url::getCurrentURL(); foreach ($dir as $entry) { if ($entry->getExtension() === 'php') { $seeds[(string) $url->parameter('class', $entry->getBasename('.php'))] = $entry->getBasename('.php'); } } return new Nav($seeds); }
/** * @param int $count Number of pages * @param int $current Current page * @param array $options [optional] */ public function __construct($count, $current = 1, $options = array()) { $this->count = $count; $this->current = $current; foreach ($options as $key => $value) { $this->{$key} = $value; } if ($this->href === null) { $url = Url::getCurrentURL(); unset($url->query[$this->parameter]); $url->query[$this->parameter] = ''; $this->href = (string) $url; } }
private function getError() { switch ($this->errorCode) { case 400: return array('icon' => 'error', 'title' => 'Bad Request', 'message' => 'Server begreep de aanvraag niet'); case 401: return array('icon' => 'warning', 'title' => 'Niet geauthoriseerd', 'message' => 'U heeft onvoldoende rechten om deze pagina te bekijken.'); case 403: return array('icon' => 'warning', 'title' => 'Verboden toegang', 'message' => substr(Url::getCurrentURL()->path, -1) == '/' ? 'U mag de inhoud van deze map niet bekijken' : 'U mag deze pagina niet bekijken'); case 404: return array('icon' => 'warning', 'title' => 'Bestand niet gevonden', 'message' => 'De opgegeven URL "' . Url::getCurrentURL() . '" kon niet worden gevonden.'); case 500: return array('icon' => 'error', 'title' => 'Interne serverfout', 'message' => 'Er is een interne fout opgetreden, excuses voor het ongemak.'); case 501: return array('icon' => 'error', 'title' => 'Not Implemented', 'message' => 'Dit wordt niet door de server ondersteund'); default: throw new Exception('HTTP errorCode ' . $this->errorCode . ' is not (yet) supported.'); } }
public function testParameter() { $emptyUrl = new Url(''); $this->assertSame('?test=value', (string) $emptyUrl->parameter('test', 'value')); $this->assertSame('?test%5B0%5D=value', (string) $emptyUrl->parameter('test[]', 'value')); $this->assertSame('?test%5B99%5D=value', (string) $emptyUrl->parameter('test[99]', 'value')); $urlWithParam = new Url('?param=1'); $this->assertSame('?param%5B0%5D=1¶m%5B1%5D=value', (string) $urlWithParam->parameter('param[]', 'value')); $urlWithParams = new Url('?param[0]=123¶m[4]=456'); $this->assertSame('?param%5B0%5D=123¶m%5B4%5D=456¶m%5B5%5D=value', (string) $urlWithParams->parameter('param[]', 'value')); $this->assertSame('?param%5B0%5D=123¶m%5B4%5D=value', (string) $urlWithParams->parameter('param[4]', 'value')); $this->assertSame('?param%5B0%5D=123¶m%5B4%5D=value', (string) $urlWithParams->parameter('param', 'value', 4)); $this->assertSame('?param%5B0%5D=123', (string) $urlWithParams->removeParameter('param[4]')); $this->assertSame('?param%5B0%5D=123', (string) $urlWithParams->removeParameter('param', 4)); }
/** * Event/Action voor het afhandelen van niet bestaande (virtuele) mappen. * Geeft deze of een parent van deze virtualfolder de mogenlijkheid om een custom actie uit te voeren. * * @return HttpError */ protected function onFolderNotFound() { if ($this->parent !== null) { return $this->parent->onFolderNotFound(); } $url = Url::getCurrentURL(); $relativePath = substr(rawurldecode($url->path), strlen(\Sledgehammer\WEBPATH) - 1); // Relative path vanaf de WEBROOT $isFolder = substr($relativePath, -1) == '/'; // Gaat de request om een folder? if ($isFolder) { $folder = $relativePath; } else { $folder = dirname($relativePath) . '/'; } // $publicFolder = array(APP_DIR.'/public'.$folder); // $folders = explode('/', substr($folder, 1, -1)); // if (count($folders) != 0) { // $module = $folders[0]; // $modules = Framework::getModules(); // if (isset($modules[$module])) { // $publicFolder[] = $modules[$module]['path'].'public'.substr($folder, strlen($module) + 1); // } // } // Zoek door de public mappen en kijk of de map/bestand bestaat. $foundPublicFolder = false; // foreach ($publicFolder as $folder) { // if (is_dir($folder)) { // $foundPublicFolder = $folder; // if ($isFolder) { // error_log('HTTP[403] Directory listing for "'.$url.'" not allowed'); // // return new HttpError(403); // } // } // $path = $isFolder ? $folder : $folder.basename($relativePath); // if (file_exists($path)) { // if (is_readable($path)) { // return new HttpError(500, array('warning' => 'render_public_folder.php should have renderd the file: "'.$path.'"')); // } else { // return new HttpError(403, array('warning' => 'Permission denied for file "'.basename($path).'" in "'.dirname($path).'/"')); // } // } // } if ($foundPublicFolder) { return new HttpError(404, array('notice' => array('HTTP[404] File "' . basename($relativePath) . '" not found in "' . dirname($relativePath) . '/"', 'VirtualFolder "' . get_class(self::$current) . '" doesn\'t handle the "' . basename(self::$current->getPath(true)) . '" folder'))); } // Gaat om een bestand in een virtualfolder return new HttpError(404, array('notice' => 'HTTP[404] VirtualFolder "' . get_class(self::$current) . '" has no "' . basename(self::$current->getPath(true)) . '" folder')); }
<?php use Sledgehammer\Mvc\Component\Button; use Sledgehammer\Core\Html; use Sledgehammer\Core\Url; echo "<div class=\"modal-dialog\">\n"; echo "\t<div class=\"modal-content\">\n"; echo "\t\t<div class=\"modal-header\">"; echo '<h4 class="modal-title">'; echo Html::escape($title), "</h4></div>\n"; echo "\t\t<div class=\"modal-body\">\n\t\t\t", $body, "\n\t\t</div>\n"; if (count($choices) !== 0) { echo "\t\t<form class=\"modal-footer\" action=\"" . Url::getCurrentURL() . '" method="' . $method . "\">\n"; $indexed = \Sledgehammer\is_indexed($choices); foreach (array_reverse($choices) as $answer => $choice) { if (is_array($choice) === false) { $choice = array('label' => $choice); } $choice['type'] = 'submit'; $choice['name'] = $identifier; if ($indexed) { $choice['value'] = $choice['label']; } else { $choice['value'] = $answer; } $button = new Button($choice); echo "\t\t\t", $button, "\n"; } echo "\t\t</form>\n"; } echo "\t</div>\n";