Beispiel #1
0
 /**
  * @constructor
  *
  * @param {array}  $rules Redirect rules
  * @param {callable|string} $rules[][source] Regex, plain string startsWith() or callback matcher func,
  * @param {string} $rules[][target] String for redirection, can use backreference on regex,
  * @param {?int}   $rules[][options] Redirection $options, or internal by default,
  * @param {?string} $options[source] Base path to match against requests, defaults to root.
  * @param {string|callable} $options[target] Redirects to a static target, or function($request) returns a string;
  */
 public function __construct($rules)
 {
     // rewrite all URLs
     if (is_string($rules)) {
         $rules = array('*' => $rules);
     }
     $rules = util::wrapAssoc($rules);
     $this->rules = array_reduce($rules, function ($result, $rule) {
         $rule = array_select($rule, array('source', 'target', 'options'));
         // note: make sure source is callback
         if (is_string($rule['source'])) {
             // regex
             if (@preg_match($rule['source'], null) !== false) {
                 $rule['source'] = matches($rule['source']);
                 if (is_string($rule['target'])) {
                     $rule['target'] = compose(invokes('uri', array('path')), replaces($rule['source'], $rule['target']));
                 }
             } else {
                 if (!is_callable($rule['source'])) {
                     $rule['source'] = startsWith($rule['source']);
                     if (is_string($rule['target'])) {
                         $rule['target'] = compose(invokes('uri', array('path')), replaces('/^' . preg_quote($rule['source']) . '/', $rule['target']));
                     }
                 }
             }
         }
         if (!is_callable($rule['source'])) {
             throw new InvalidArgumentException('Source must be string, regex or callable.');
         }
         $result[] = $rule;
         return $result;
     }, array());
 }
Beispiel #2
0
        //Puts the default template in a variable, so we can use the real template later
        $this->newsplate = $temp->template;
        //Gets the user information for each post
        $resultUser = mysql_query("SELECT user, email, avatar, userLevel, alias FROM an_user WHERE user='******'");
        $nUser = mysql_fetch_object($resultUser);
        //Selects all the categories, and adds them to the news
        $selectCats = mysql_query("SELECT * FROM an_cats WHERE id='{$show->cat}'") or die(mysql_error());
        $obCats = mysql_fetch_object($selectCats) or print "CAT OBJECT ERROR";
        //These are where the templates are replaced with MySQL info
        $show->news = str_replace($emotes, $images, $show->news);
        $this->newsplate = eregi_replace("<#SUBJECT#>", $show->subject, $this->newsplate);
        $this->newsplate = eregi_replace("<#ADDCOM#>", "/argonnews/news.php?comments=add&post={$show->id}", $this->newsplate);
        $this->newsplate = eregi_replace("<#SEECOM#>", "/argonnews/news.php?comments=see&post={$show->id}", $this->newsplate);
        $this->newsplate = eregi_replace("<#ALIAS#>", $nUser->alias, $this->newsplate);
        $this->newsplate = eregi_replace("<#NAME#>", $show->user, $this->newsplate);
        $this->newsplate = eregi_replace("<#EMAIL#>", $nUser->email, $this->newsplate);
        $this->newsplate = eregi_replace("<#TIME#>", $show->time, $this->newsplate);
        $this->newsplate = eregi_replace("<#CATEGORY#>", $obCats->catName, $this->newsplate);
        $this->newsplate = eregi_replace("<#CATICON#>", "<img src=\"/argonnews/caticon/{$obCats->catImage}\" alt=\"\"/>", $this->newsplate);
        $this->newsplate = eregi_replace("<#AVATAR#>", $nUser->avatar, $this->newsplate);
        $this->newsplate = eregi_replace("<#NEWS#>", $show->news, $this->newsplate);
        $this->newsplate = eregi_replace("<#PRINT#>", "/argonnews/print.php?post={$show->id}", $this->newsplate);
        $this->newsplate = eregi_replace("<#SEND#>", "/argonnews/send.php?post={$show->id}", $this->newsplate);
        //Prints the news
        print $this->newsplate;
        //Restores the original template so we can use it for the next post
        $this->newsplate = $temp->template;
    }
}
replaces();
Beispiel #3
0
 /**
  * Parameters starts with metaPrefix will not be returned from param() and
  * must be retrieved from this function.
  */
 public function meta($name = null)
 {
     $value =& $this->meta;
     if (!$value) {
         $value = $this->_param();
         $value = array_filter_keys($value, startsWith($this->metaPrefix));
         $value = array_combine(array_map(replaces('/^' . preg_quote($this->metaPrefix) . '/', ''), array_keys($value)), array_values($value));
     }
     if ($name === null) {
         return $value;
     } else {
         return @$value[$name];
     }
 }