Пример #1
0
 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);
 }
Пример #2
0
 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);
 }
Пример #3
0
 /**
  * @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;
     }
 }
Пример #4
0
 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.');
     }
 }
Пример #5
0
 /**
  * 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'));
 }
Пример #6
0
<?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";