Example #1
0
/**
 * Removes suffix from end of string
 *
 * @param string $input
 * @param string $suffix
 *
 * @return string
 *
 * @author Lucantis Swann <*****@*****.**>
 */
function string_chomp_right($input, $suffix)
{
    if (string_ends_with($input, $suffix)) {
        return mb_substr($input, 0, mb_strlen($input) - mb_strlen($suffix));
    }
    return $input;
}
Example #2
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $WikiTheme;
     $args = $this->getArgs($argstr, $request);
     extract($args);
     if (!$url && !$file) {
         return $this->error(_("Both 'url' or 'file' parameters missing."));
     } elseif ($url && $file) {
         return $this->error(_("Choose only one of 'url' or 'file' parameters."));
     } elseif ($file) {
         // $url = SERVER_URL . getUploadDataPath() . '/' . $file;
         $url = getUploadDataPath() . '/' . $file;
     }
     if (string_ends_with($url, ".ogg")) {
         return HTML::video(array('autoplay' => 'true', 'controls' => 'true', 'src' => $url), _("Your browser does not understand the HTML 5 video tag."));
     }
     $html = HTML();
     if (isBrowserIE()) {
         $object = HTML::object(array('id' => 'flowplayer', 'classid' => 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000', 'width' => $width, 'height' => $height));
         $param = HTML::param(array('name' => 'movie', 'value' => SERVER_URL . $WikiTheme->_findData('flowplayer-3.2.4.swf')));
         $object->pushContent($param);
         $param = HTML::param(array('name' => "allowfullscreen", 'value' => "true"));
         $object->pushContent($param);
         $param = HTML::param(array('name' => "allowscriptaccess", 'value' => "false"));
         $object->pushContent($param);
         $flashvars = "config={'clip':{'url':'" . $url . "','autoPlay':" . $autoplay . "}}";
         $param = HTML::param(array('name' => 'flashvars', 'value' => $flashvars));
         $object->pushContent($param);
         $embed = HTML::embed(array('type' => 'application/x-shockwave-flash', 'width' => $width, 'height' => $height, 'src' => SERVER_URL . $WikiTheme->_findData('flowplayer-3.2.4.swf'), 'flashvars' => $flashvars));
         $object->pushContent($embed);
         $html->pushContent($object);
     } else {
         $object = HTML::object(array('data' => SERVER_URL . $WikiTheme->_findData('flowplayer-3.2.4.swf'), 'type' => "application/x-shockwave-flash", 'width' => $width, 'height' => $height));
         $param = HTML::param(array('name' => "allowfullscreen", 'value' => "true"));
         $object->pushContent($param);
         $param = HTML::param(array('name' => "allowscriptaccess", 'value' => "false"));
         $object->pushContent($param);
         $value = "config={'clip':{'url':'" . $url . "','autoPlay':" . $autoplay . "}}";
         $param = HTML::param(array('name' => "flashvars", 'value' => $value));
         $object->pushContent($param);
         $html->pushContent($object);
     }
     return $html;
 }
Example #3
0
 function _parseMap($text)
 {
     if (!preg_match_all("/^\\s*(\\S+)\\s+(.+)\$/m", $text, $matches, PREG_SET_ORDER)) {
         return false;
     }
     foreach ($matches as $m) {
         $map[$m[1]] = $m[2];
     }
     // Add virtual monikers Upload: Talk: User:
     // and expand special variables %u, %b, %d
     // Upload: Should be expanded later to user-specific upload dirs.
     // In the Upload plugin, not here: Upload:ReiniUrban/uploaded-file.png
     if (empty($map['Upload'])) {
         $map['Upload'] = getUploadDataPath();
     }
     // User:ReiniUrban => ReiniUrban or Users/ReiniUrban
     // Can be easily overriden by a customized InterWikiMap:
     //   User Users/%s
     if (empty($map["User"])) {
         $map["User"] = "******";
     }
     // Talk:PageName => PageName/Discussion as default, which might be overridden
     if (empty($map["Talk"])) {
         $pagename = $GLOBALS['request']->getArg('pagename');
         // against PageName/Discussion/Discussion
         if (string_ends_with($pagename, SUBPAGE_SEPARATOR . _("Discussion"))) {
             $map["Talk"] = "%s";
         } else {
             $map["Talk"] = "%s" . SUBPAGE_SEPARATOR . _("Discussion");
         }
     }
     foreach (array('Upload', 'User', 'Talk') as $special) {
         // Expand special variables:
         //   %u => username
         //   %b => wikibaseurl
         //   %d => iso8601 DateTime
         // %s is expanded later to the pagename
         if (strstr($map[$special], '%u')) {
             $map[$special] = str_replace($map[$special], '%u', $GLOBALS['request']->_user->_userid);
         }
         if (strstr($map[$special], '%b')) {
             $map[$special] = str_replace($map[$special], '%b', PHPWIKI_BASE_URL);
         }
         if (strstr($map[$special], '%d')) {
             $map[$special] = str_replace($map[$special], '%d', Iso8601DateTime());
         }
     }
     // Maybe add other monikers also - SemanticWeb link predicates
     // Should they be defined in a RDF? (strict mode)
     // Or should the SemanticWeb lib add it by itself?
     // (adding only a subset dependent on the context = model)
     return $map;
 }
Example #4
0
function make_record($zone, $input)
{
    global $defaults;
    $name = isset($input['name']) ? $input['name'] : '';
    if ('' == $name) {
        $name = $zone['name'];
    } elseif (string_ends_with($name, '.')) {
        # "absolute" name, shouldn't append zone[name] - but check.
        $name = substr($name, 0, -1);
        if (!string_ends_with($name, $zone['name'])) {
            jtable_respond(null, 'error', "Name {$name} not in zone " . $zone['name']);
        }
    } else {
        if (!string_ends_with($name, $zone['name'])) {
            $name = $name . '.' . $zone['name'];
        }
    }
    $ttl = (int) (isset($input['ttl']) && $input['ttl'] ? $input['ttl'] : $defaults['ttl']);
    $type = isset($input['type']) ? $input['type'] : '';
    $disabled = (bool) (isset($input['disabled']) && $input['disabled']);
    $content = isset($input['content']) ? $input['content'] : '';
    if ($type === 'TXT') {
        # empty TXT records are ok, otherwise require surrounding quotes: "..."
        if (strlen($content) == 1 || substr($content, 0, 1) !== '"' || substr($content, -1) !== '"') {
            # fix quoting: first escape all \, then all ", then surround with quotes.
            $content = '"' . str_replace('"', '\\"', str_replace('\\', '\\\\', $content)) . '"';
        }
    }
    if (!_valid_label($name)) {
        jtable_respond(null, 'error', "Please only use [a-z0-9_/.-]");
    }
    if (!$type) {
        jtable_respond(null, 'error', "Require a type");
    }
    if (!is_ascii($content)) {
        jtable_respond(null, 'error', "Please only use ASCII-characters in your fields");
    }
    return array('disabled' => $disabled, 'type' => $type, 'name' => $name, 'ttl' => $ttl, 'content' => $content);
}
Example #5
0
/**
 * Returns true if the filename ends with an video suffix.
 * Currently only FLV and OGG
 */
function is_video($filename)
{
    return string_ends_with(strtolower($filename), ".flv") or string_ends_with(strtolower($filename), ".ogg");
}
 protected function format_record_property(&$name, &$value)
 {
     if (is_array($value)) {
         $value = $this->format_record($value);
         return;
     }
     //this is used so that the _ends_with "able" rule is not applied to commentable field, since commentable is 'yes', 'no', 'dissabled'
     if (strpos($name, "commentable") !== false) {
         return;
     }
     if (strpos($name, "author_image_url") !== false) {
         $value = $this->get_avatar_url($value);
         return;
     }
     if (string_ends_with($name, "able")) {
         $value = (bool) $value;
         return;
     }
     if (strpos($name, "allowed") !== false) {
         $value = (bool) $value;
         return;
     }
     if (strpos($name, "approved") !== false) {
         $value = (bool) $value;
         return;
     }
     if (string_ends_with($name, "latitude") || string_ends_with($name, "longitude")) {
         $value = (double) $value;
         return;
     }
     if (string_ends_with($name, "_ids")) {
         $ids = explode(",", $value);
         $value = array();
         foreach ($ids as $i => $id) {
             $value[] = (int) $id;
         }
         return;
     }
     if (string_ends_with($name, "_at") || string_ends_with($name, "time")) {
         $value = date(DATE_RSS, strtotime($value));
         return;
     }
     if (is_numeric($value)) {
         $value = (int) $value;
         return;
     } else {
         if (is_string($value)) {
             //$value = html_entity_decode($value, ENT_QUOTES, 'UTF-8'); //why was this added
         }
     }
 }
 function retrieve(&$ds, $url)
 {
     if (isset($ds->_data[$url])) {
         return $ds->_data[$url];
     } else {
         if (string_ends_with($url, '!random')) {
             return $ds->_data[array_rand($ds->_data)];
         } else {
             return NULL;
         }
     }
 }
Example #8
0
 /**
  * fromFile - read pictures & descriptions (separated by ;)
  *            from $src and return it in array $photos
  *
  * @param string $src path to dir or textfile (local or remote)
  * @param array $photos
  * @return string Error when bad url or file couldn't be opened
  */
 function fromFile($src, &$photos, $webpath = '')
 {
     $src_bak = $src;
     if (preg_match("/^Upload:(.*)\$/", $src, $m)) {
         $src = getUploadFilePath() . $m[1];
         $webpath = getUploadDataPath() . $m[1];
     }
     //there has a big security hole... as loading config/config.ini !
     if (!preg_match('/(\\.csv|\\.jpg|\\.jpeg|\\.png|\\.gif|\\/)$/', $src)) {
         return $this->error(_("File extension for csv file has to be '.csv'"));
     }
     if (!IsSafeURL($src)) {
         return $this->error(_("Bad url in src: remove all of <, >, \""));
     }
     if (preg_match('/^(http|ftp|https):\\/\\//i', $src)) {
         $contents = url_get_contents($src);
         $web_location = 1;
     } else {
         $web_location = 0;
         if (string_ends_with($src, "/")) {
             $src = substr($src, 0, -1);
         }
     }
     if (!file_exists($src) and @file_exists(PHPWIKI_DIR . "/{$src}")) {
         $src = PHPWIKI_DIR . "/{$src}";
     }
     // check if src is a directory
     if (file_exists($src) and filetype($src) == 'dir') {
         //all images
         $list = array();
         foreach (array('jpeg', 'jpg', 'png', 'gif') as $ext) {
             $fileset = new fileSet($src, "*.{$ext}");
             $list = array_merge($list, $fileset->getFiles());
         }
         // convert dirname($src) (local fs path) to web path
         natcasesort($list);
         if (!$webpath) {
             // assume relative src. default: "themes/Hawaiian/images/pictures"
             $webpath = DATA_PATH . '/' . $src_bak;
         }
         foreach ($list as $file) {
             // convert local path to webpath
             $photos[] = array("src" => $file, "name" => $webpath . "/{$file}", "name_tile" => $src . "/{$file}", "src" => $src . "/{$file}", "desc" => "");
         }
         return;
     }
     // check if $src is an image
     foreach (array('jpeg', 'jpg', 'png', 'gif') as $ext) {
         if (preg_match("/\\.{$ext}\$/", $src)) {
             if (!file_exists($src) and @file_exists(PHPWIKI_DIR . "/{$src}")) {
                 $src = PHPWIKI_DIR . "/{$src}";
             }
             if ($web_location == 1 and !empty($contents)) {
                 $photos[] = array("src" => $src, "name" => $src, "name_tile" => $src, "src" => $src, "desc" => "");
                 return;
             }
             if (!file_exists($src)) {
                 return $this->error(fmt("Unable to find src='%s'", $src));
             }
             $photos[] = array("src" => $src, "name" => "../" . $src, "name_tile" => $src, "src" => $src, "desc" => "");
             return;
         }
     }
     if ($web_location == 0) {
         $fp = @fopen($src, "r");
         if (!$fp) {
             return $this->error(fmt("Unable to read src='%s'", $src));
         }
         while ($data = fgetcsv($fp, 1024, ';')) {
             if (count($data) == 0 || empty($data[0]) || preg_match('/^#/', $data[0]) || preg_match('/^[[:space:]]*$/', $data[0])) {
                 continue;
             }
             if (empty($data[1])) {
                 $data[1] = '';
             }
             $photos[] = array("name" => dirname($src) . "/" . trim($data[0]), "location" => "../" . dirname($src) . "/" . trim($data[0]), "desc" => trim($data[1]), "name_tile" => dirname($src) . "/" . trim($data[0]));
         }
         fclose($fp);
     } elseif ($web_location == 1) {
         //TODO: check if the file is an image
         $contents = preg_split('/\\n/', $contents);
         while (list($key, $value) = each($contents)) {
             $data = preg_split('/\\;/', $value);
             if (count($data) == 0 || empty($data[0]) || preg_match('/^#/', $data[0]) || preg_match('/^[[:space:]]*$/', $data[0])) {
                 continue;
             }
             if (empty($data[1])) {
                 $data[1] = '';
             }
             $photos[] = array("name" => dirname($src) . "/" . trim($data[0]), "src" => dirname($src) . "/" . trim($data[0]), "desc" => trim($data[1]), "name_tile" => dirname($src) . "/" . trim($data[0]));
         }
     }
 }
Example #9
0
function getUploadDataPath()
{
    if (defined('UPLOAD_DATA_PATH')) {
        return string_ends_with(UPLOAD_DATA_PATH, "/") ? UPLOAD_DATA_PATH : UPLOAD_DATA_PATH . "/";
    }
    return SERVER_URL . (string_ends_with(DATA_PATH, "/") ? '' : "/") . DATA_PATH . '/uploads/';
}
Example #10
0
 function test_string_ends_with()
 {
     $string = 'abcdefghijklmnopqrstuvwxyz';
     $this->assertTrue(string_ends_with($string, $string));
     $this->assertTrue(string_ends_with($string, 'opqrstuvwxyz'));
     $this->assertTrue(string_ends_with($string, 'z'));
     $this->assertFalse(string_ends_with($string, 'a'));
 }
function path_info()
{
    if (string_ends_with($_SERVER['PHP_SELF'], 'diagnostics.php')) {
        return fail('Unable to test?  Try visiting <a href="' . $_SERVER['PHP_SELF'] . '/test">this</a>');
    } else {
        if (isset($_SERVER['PATH_INFO'])) {
            return pass($_SERVER['PATH_INFO']);
        } else {
            return fail("PATH INFO not exposed");
        }
    }
}
Example #12
0
 function get_word($accept = TSQ_ALLWORDS)
 {
     // Performance shortcut for ( and ). This is always false
     if (!empty($this->lexer->tokens[$this->lexer->pos])) {
         list($type, $val) = $this->lexer->tokens[$this->lexer->pos];
         if ($type == TSQ_TOK_LPAREN or $type == TSQ_TOK_RPAREN) {
             return false;
         }
     }
     foreach (array("WORD", "STARTS_WITH", "ENDS_WITH", "EXACT", "REGEX", "REGEX_GLOB", "REGEX_PCRE", "ALL") as $tok) {
         $const = constant("TSQ_TOK_" . $tok);
         // Bug#1791564: allow word '0'
         if ($accept & $const and ($word = $this->lexer->get($const)) !== false) {
             // phrase or word level?
             if ($tok == 'STARTS_WITH' and $this->lexer->query_str[0] == '^') {
                 $classname = "TextSearchQuery_phrase_" . strtolower($tok);
             } elseif ($tok == 'ENDS_WITH' and string_ends_with($this->lexer->query_str, '$')) {
                 $classname = "TextSearchQuery_phrase_" . strtolower($tok);
             } else {
                 $classname = "TextSearchQuery_node_" . strtolower($tok);
             }
             return new $classname($word);
         }
     }
     return false;
 }
 function get_timestamp($from_qs_key = NULL)
 {
     $dates = $this->value;
     if (is_null($dates)) {
         $dates = $this->default;
     }
     if (is_null($dates)) {
         $dates = $this->range;
     }
     $index = 0;
     if (!is_null($from_qs_key)) {
         if (is_integer($from_qs_key)) {
             $index = $from_qs_key;
         } else {
             if (string_ends_with($from_qs_key, QC_DATE_RANGE_QS_POSTFIX_END)) {
                 $index = 1;
             }
         }
     }
     $elements = split('-', $dates[$index]);
     $defaults = array(0, 0, 0, 0, 0, 0);
     $elements = array_merge_or($elements, array(0, 0, 0, 0, 0, 0));
     return mktime($elements[3], $elements[4], $elements[5], $elements[1], $elements[2], $elements[0]);
 }