Beispiel #1
0
 /**
  * @param string|array $route
  * @param array $headers
  * @param array $request_params
  */
 static function load($route = '', $headers = array(), array $request_params = array())
 {
     $controller_route = new self($route, $headers, $request_params);
     $controller = $controller_route->getController();
     if (null === $controller) {
         file_not_found($route);
     }
     $controller->doAction($controller_route->getAction(), $controller_route->getParams());
 }
Beispiel #2
0
 /**
  * @param string $view_file
  * @return View
  */
 public function setFile($view_file = null)
 {
     // normalize slashes
     $view_file = str_replace('\\', '/', $view_file);
     $view_file = trim($view_file, '/');
     // indexes
     if (!is_file(VIEWS_DIR . $view_file . '.php') && is_dir(VIEWS_DIR . $view_file)) {
         $view_file = $view_file . '/index';
     }
     // php extension
     $view_file = VIEWS_DIR . "{$view_file}.php";
     // raise error if file doesn't exist
     if (!is_file($view_file)) {
         file_not_found($view_file);
     }
     $this->viewFile = $view_file;
     return $this;
 }
Beispiel #3
0
/**
 * Return a rooted path to the given URL.
 * If the URL is already a complete URL (prefixed with http:// or
 * https://), then the URL will be returned unmodified.
 * If $url is an array, then the contents will be imploded.
 *
 * @param mixed $url URL or array of URL segments
 * @param bool $version Append the modification time of the file to the URL
 * @return string
 * @author Dan Blaisdell
 */
function site_url($url = '', $version = false)
{
    if (is_array($url)) {
        $url = implode('/', $url);
    }
    if (false !== strpos($url, ':') || 0 === strpos($url, '#') || 0 === strpos($url, '//')) {
        return $url;
    }
    if ($version) {
        $path = PUBLIC_DIR . $url;
        if (!is_file($path)) {
            file_not_found($url);
        }
        $char = strpos($url, '?') === false ? '?' : '&';
        $url .= $char . 'v=' . filemtime($path);
    }
    $url = trim($url, '/');
    return BASE_URL . $url;
}
function diff()
{
    global $argc, $argv;
    if ($argc != 3) {
        usage();
    }
    $file = $argv[2];
    if (file_exists($file)) {
        $xml = @simplexml_load_file($file);
    } else {
        file_not_found($file);
    }
    if ($xml === false) {
        bad_xml($file);
    }
    echo "Analysing {$file}...\n";
    // Go through nodes and mark ways that have changed (we can easiky keep it in memory)
    // rq: use floats or strings but not ints, since PHP_INT_MAX is too small on 32 bits systems
    $impacted_ways = array();
    $nodes = $xml->node;
    foreach ($nodes as $node) {
        $nodeid = (string) $node->attributes()->id;
        $nodeaction = (string) $node->attributes()->action;
        if ((double) $nodeid < 0 || $nodeaction === 'modify') {
            $results = $xml->xpath("//way[count(nd[@ref='{$nodeid}'])>0]");
            if (count($results)) {
                foreach ($results as $way) {
                    $wayid = (string) $way->attributes()->id;
                    if (!isset($impacted_ways[$wayid])) {
                        $impacted_ways[$wayid] = 1;
                    }
                }
            }
        }
    }
    // we go through ways, but only the ones that have a c2c:id attached
    // (other are part of a relation)
    $impacted_relations = array();
    $ways = $xml->way;
    foreach ($ways as $way) {
        // If only the nodes of a way have been modified or deleted, the way itself is not marked
        // as changed in josm. Let's check that.
        $wayid = (string) $way->attributes()->id;
        $propaged_modification = array_key_exists($wayid, $impacted_ways);
        $state = state($way);
        if ($propaged_modification && $state === 'NOCHANGE') {
            $state = 'MODIFY';
        }
        // check if it has a c2c:id attached
        // other ways are handled via their parent relation
        $c2cid = c2cid($way);
        if ($c2cid) {
            for ($i = 0; $i < count($c2cid); $i++) {
                $changes[$c2cid[$i]][$state][] = $wayid;
                if (!isset($changes[$c2cid[$i]]['name'])) {
                    $changes[$c2cid[$i]]['name'] = c2cname($way, $i);
                }
            }
        } else {
            // determine if way has changed (either directly or via its nodes)
            // if so, keep track of the related relations that will be considered modified
            if ($state === 'MODIFY') {
                $results = $xml->xpath("//relation[count(member[@ref='{$wayid}'])>0]");
                if (count($results)) {
                    foreach ($results as $relation) {
                        $relationid = (string) $relation->attributes()->id;
                        if (!isset($impacted_relations[$relationid])) {
                            $impacted_relations[$relationid] = 1;
                        }
                    }
                }
            }
        }
    }
    // we go through the relations
    $relations = $xml->relation;
    foreach ($relations as $relation) {
        $relationid = (string) $relation->attributes()->id;
        $propaged_modification = array_key_exists($relationid, $impacted_relations);
        $state = state($relation);
        if ($propaged_modification && $state === 'NOCHANGE') {
            $state = 'MODIFY';
        }
        $c2cid = c2cid($relation);
        if ($c2cid) {
            for ($i = 0; $i < count($c2cid); $i++) {
                $changes[$c2cid[$i]][$state][] = $relationid;
                if (!isset($changes[$c2cid[$i]]['name'])) {
                    $changes[$c2cid[$i]]['name'] = c2cname($relation, $i);
                }
            }
        } else {
            die("Found a relation without c2c:id. Aborting...\n");
        }
    }
    // display the changes in a human readable way
    echo "\n";
    foreach ($changes as $id => $change) {
        $modifycount = isset($change['MODIFY']) ? count($change['MODIFY']) : 0;
        $deletecount = isset($change['DELETE']) ? count($change['DELETE']) : 0;
        $newcount = isset($change['NEW']) ? count($change['NEW']) : 0;
        $nochangecount = isset($change['NOCHANGE']) ? count($change['NOCHANGE']) : 0;
        // an area has been completely deleted
        if ($deletecount > 0 && $modifycount == 0 && $newcount == 0 && $nochangecount == 0) {
            echo $change['name'] . " ({$id}) has been deleted\n";
            continue;
        }
        // a new area has been created
        if ($newcount > 0 && $modifycount == 0 && $deletecount == 0 && $nochangecount == 0) {
            echo $change['name'] . " ({$id}) has been created with {$newcount} polygon(s)\n";
            continue;
        }
        // modified in various ways
        if ($newcount > 0 || $modifycount > 0 || $deletecount > 0) {
            echo $change['name'] . " ({$id}) has been changed\n";
            continue;
        }
    }
}
Beispiel #5
0
 function display_from_archive($content_map = array())
 {
     // Set default values
     $this->params = array_merge(array('pattern' => '@^[/]([^/]+)[/](.*)$@', 'vpath' => $_SERVER["PATH_INFO"], 'archive_subdir' => true, 'zipfile' => true, 'fix_dir' => false, 'archive_dir' => ARCHIVE_DIR, 'archive_file_prefix' => ARCHIVE_FILE_PREFIX, 'use_http_expire_date' => false, 'override_extractor' => null, 'title' => NULL, 'charset' => NULL, 'content' => NULL, 'error' => false), $this->params);
     $this->get_archive_location();
     // Only use a permanent redirect for releases (beta or full).
     $redirect_status_code = $this->params['version'] && $this->params['version']->is_numbered_release() ? 301 : 302;
     // Calculate expiry date if requested.
     $expires = null;
     if ($this->params['use_http_expire_date']) {
         if (!$this->params['version']) {
             $expires = "+1 week";
         } else {
             $compare_version = BoostVersion::from($this->params['version'])->compare(BoostVersion::current());
             $expires = $compare_version === -1 ? "+1 year" : ($compare_version === 0 ? "+1 week" : "+1 day");
         }
     }
     // Check file exists.
     if ($this->params['zipfile']) {
         $check_file = $this->params['archive'];
         if (!is_readable($check_file)) {
             file_not_found($this->params, 'Unable to find zipfile.');
             return;
         }
     } else {
         $check_file = $this->params['file'];
         if (is_dir($check_file)) {
             if (substr($check_file, -1) != '/') {
                 $redirect = resolve_url(basename($check_file) . '/');
                 header("Location: {$redirect}", TRUE, $redirect_status_code);
                 return;
             }
             $found_file = NULL;
             if (is_readable("{$check_file}/index.html")) {
                 $found_file = 'index.html';
             } else {
                 if (is_readable("{$check_file}/index.htm")) {
                     $found_file = 'index.htm';
                 }
             }
             if ($found_file) {
                 $this->params['file'] = $check_file = $check_file . $found_file;
                 $this->params['key'] = $this->params['key'] . $found_file;
             } else {
                 if (!http_headers('text/html', filemtime($check_file), $expires)) {
                     return;
                 }
                 $display_dir = new BoostDisplayDir($this->params);
                 return $display_dir->display($check_file);
             }
         } else {
             if (!is_readable($check_file)) {
                 file_not_found($this->params, 'Unable to find file.');
                 return;
             }
         }
     }
     // Choose filter to use
     $info_map = array_merge($content_map, array(array('', '@[.](txt|py|rst|jam|v2|bat|sh|xml|xsl|toyxml)$@i', 'text', 'text/plain'), array('', '@[.](qbk|quickbook)$@i', 'qbk', 'text/plain'), array('', '@[.](c|h|cpp|hpp)$@i', 'cpp', 'text/plain'), array('', '@[.]png$@i', 'raw', 'image/png'), array('', '@[.]gif$@i', 'raw', 'image/gif'), array('', '@[.](jpg|jpeg|jpe)$@i', 'raw', 'image/jpeg'), array('', '@[.]svg$@i', 'raw', 'image/svg+xml'), array('', '@[.]css$@i', 'raw', 'text/css'), array('', '@[.]js$@i', 'raw', 'application/x-javascript'), array('', '@[.]pdf$@i', 'raw', 'application/pdf'), array('', '@[.](html|htm)$@i', 'raw', 'text/html'), array('', '@(/|^)(Jamroot|Jamfile|ChangeLog|configure)$@i', 'text', 'text/plain'), array('', '@[.]dtd$@i', 'raw', 'application/xml-dtd')));
     $preprocess = null;
     $extractor = null;
     $type = null;
     foreach ($info_map as $i) {
         if (preg_match($i[1], $this->params['key'])) {
             if ($i[0]) {
                 $version = BoostVersion::from($i[0]);
                 if ($version->compare(BoostVersion::page()) > 0) {
                     // This is after the current version.
                     continue;
                 }
             }
             $extractor = $i[2];
             $type = $i[3];
             $preprocess = isset($i[4]) ? $i[4] : NULL;
             break;
         }
     }
     if ($this->params['override_extractor']) {
         $extractor = $this->params['override_extractor'];
     }
     if (!$extractor) {
         if (strpos($_SERVER['HTTP_HOST'], 'www.boost.org') === false) {
             file_not_found($this->params, "No extractor found for filename.");
         } else {
             file_not_found($this->params);
         }
         return;
     }
     // Handle ETags and Last-Modified HTTP headers.
     // Output raw files.
     if ($extractor == 'raw') {
         if (!http_headers($type, filemtime($check_file), $expires)) {
             return;
         }
         if ($_SERVER['REQUEST_METHOD'] != 'HEAD') {
             display_raw_file($this->params, $type);
         }
     } else {
         // Read file from hard drive or zipfile
         // Note: this sets $this->params['content'] with either the content or an error
         // message:
         if (!extract_file($this->params, $this->params['content'])) {
             file_not_found($this->params, $this->params['content']);
             return;
         }
         // Check if the file contains a redirect.
         if ($type == 'text/html') {
             if ($redirect = detect_redirect($this->params['content'])) {
                 http_headers('text/html', null, "+1 day");
                 header("Location: {$redirect}", TRUE, $redirect_status_code);
                 if ($_SERVER['REQUEST_METHOD'] != 'HEAD') {
                     echo $this->params['content'];
                 }
                 return;
             }
         }
         if (!http_headers('text/html', filemtime($check_file), $expires)) {
             return;
         }
         // Finally process the file and display it.
         if ($_SERVER['REQUEST_METHOD'] != 'HEAD') {
             if ($preprocess) {
                 $this->params['content'] = call_user_func($preprocess, $this->params['content']);
             }
             echo_filtered($extractor, $this->params);
         }
     }
 }
Beispiel #6
0
 /**
  * @param string $action_name
  * @param array $args
  */
 function doAction($action_name = null, $args = array())
 {
     // todo: this probably belongs somewhere else
     if ($this->isRestful()) {
         $has_id = false;
         if ((string) (int) $action_name === (string) $action_name) {
             array_unshift($args, $action_name);
             $action_name = null;
             $has_id = true;
         }
         if (!$action_name) {
             switch ($this->route->getHttpVerb()) {
                 case 'POST':
                 case 'PUT':
                     $action_name = 'save';
                     break;
                 case 'GET':
                     if ($has_id) {
                         $action_name = 'show';
                     }
                     break;
                 case 'DELETE':
                     if ($has_id) {
                         $action_name = 'delete';
                     }
                     break;
             }
         }
     }
     if (!$action_name) {
         $action_name = DEFAULT_CONTROLLER;
     }
     $method_name = str_replace(array('-', '_', ' '), '', $action_name);
     $view = $this->getView($action_name);
     if (!is_array($args) && !$args instanceof ArrayObject) {
         $args = array($args);
     }
     if (!method_exists($this, $method_name) && !method_exists($this, '__call') || strpos($action_name, '_') === 0) {
         file_not_found($view);
     }
     $result = call_user_func_array(array($this, $method_name), $args);
     if (!$this->loadView) {
         return;
     }
     if ($this->isRestful()) {
         $this->loadView($view, $result);
     } else {
         $this->loadView($view);
     }
 }