Example #1
0
function strim($s, $l = 50)
{
    if (strlen($s) < $l) {
        return $s;
    }
    $h = intval(($l - 3) / 2);
    $t = strlen($s) - $h + 3;
    return htmlspecialchars(mysubstr($s, 0, $h) . _TB_LEADER . mysubstr($s, $t));
}
/**
* Smarty truncate modifier plugin
*
* Type:     modifier<br>
* Name:     truncate<br>
* Purpose: Truncate a string to a certain length if necessary,
*           optionally splitting in the middle of a word, and
*           appending the $etc string or inserting $etc into the middle.
* @link http://smarty.php.net/manual/en/language.modifier.truncate.php
*          truncate (Smarty online manual)
* @author   Monte Ohrt <monte at ohrt dot com>
* @param string
* @param integer
* @param string
* @param boolean
* @param boolean
* @return string
*/
function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
{
    if ($length == 0) {
        return '';
    }
    if (mystrlen($string) > $length) {
        $length -= min($length, mystrlen($etc));
        if (!$break_words && !$middle) {
            $string = preg_replace('//s+?(/S+)?$/', '', mysubstr($string, 0, $length + 1));
        }
        if (!$middle) {
            return mysubstr($string, 0, $length) . $etc;
        } else {
            return mysubstr($string, 0, $length / 2) . $etc . mysubstr($string, -$length / 2);
        }
    } else {
        return $string;
    }
}
Example #3
0
function refpage_get_details($ref, $uri)
{
    global $trackConfig;
    $linked = 0;
    $checked = 0;
    $title = '';
    $ctext = '';
    // includes Snoopy class for remote file access
    require_once XOOPS_ROOT_PATH . "/class/snoopy.php";
    $snoopy = new Snoopy();
    //TIMEOUT
    $snoopy->read_timeout = 10;
    //URL
    $snoopy->fetch($ref);
    //GET DATA
    $page = $snoopy->results;
    if ($snoopy->error) {
        $page = "";
    }
    if ($page) {
        if (XOOPS_USE_MULTIBYTES && function_exists("mb_convert_encoding")) {
            $page = mb_convert_encoding($page, _CHARSET, "ISO-2022-JP,JIS,EUC-JP,UTF-8,Shift_JIS");
        }
        $pat = "/<title[^>]*>(.*)<\\/title>/i";
        if (preg_match($pat, $page, $d)) {
            $title = $d[1];
            $len = 255;
            if (strlen($title) > $len) {
                $title = mysubstr($title, 0, $len - 2) . "..";
            }
            $page = preg_replace($pat, "", $page);
        }
        $anc = "/<a\\s+href=([\"'])?" . preg_quote(XOOPS_URL . $uri, "/") . "\\1(>|\\s[^>]*>)/i";
        $root = "/<a\\s+href=([\"']?)" . preg_quote(XOOPS_URL . "/", "/") . "\\1(>|\\s[^>]*>)/i";
        if (preg_match($anc, $page)) {
            $F = preg_split($anc, $page, 2);
            $linked = 1;
        } elseif (preg_match($root, $page)) {
            $F = preg_split($root, $page, 2);
            $linked = 1;
        }
        if ($linked) {
            // cut out text from orign page
            function strip_string($s)
            {
                return preg_replace('/\\s+/', ' ', urldecode(strip_tags($s)));
            }
            $l = min($trackConfig['ctext_len'], 255);
            $pre = ltrim(strip_string($F[0]));
            list($a, $post) = preg_split('/<\\/a>/i', $F[1], 2);
            $post = rtrim(strip_string($post));
            $m = intval($l / 2);
            $ctext = mysubstr($pre, max(strlen($pre) - $m + 1, 0), $m) . "<u>" . strip_tags($a) . "</u>";
            $m = $l - strlen($ctext);
            $ctext .= mysubstr($post, 0, min(strlen($post), $m));
            $ctext = mysubstr($ctext, 0, $l);
            if (preg_match('/<u>/', $ctext) && !preg_match('/<\\/u>/', $ctext)) {
                $ctext = mysubstr($ctext, 0, $l - 4) . "</u>";
            }
        }
        if ($linked == 1 || strip_tags($page) != "") {
            $checked = 1;
        }
    }
    return array($title, $ctext, $linked, $checked);
}
Example #4
0
function make_track_item($data, $add = "", $attr = "target='_blank'")
{
    global $xoopsModuleConfig;
    $cdate = formatTimestamp($data['since'], "m");
    $mdate = $data['mtime'] > 10 ? formatTimestamp($data['mtime'], "m") : _TB_WAIT_UPDATE;
    $url = $data['ref_url'];
    $nref = $data['nref'];
    $nurl = "";
    if (isset($data['refs'])) {
        $nurl = _TB_REF_NURL . ": " . $data['n'];
        $refn = $data["refn"];
        foreach ($data["refs"] as $ref) {
            $nurl .= " <a href='{$ref}'>[" . array_shift($refn) . "]</a>";
        }
        $nurl = "<div class='trinfo'>{$nurl}</div>";
    }
    $title = $data['title'];
    $len = max($xoopsModuleConfig['title_len'], 255);
    $alt = "";
    if ($title == '') {
        $title = strim(myurldecode($url), $len);
    } elseif (strlen($title) > $len) {
        $alt = " title='{$title}'";
        $title = mysubstr($title, 0, $len - 2) . "..";
    }
    if ($data['context'] != '') {
        $ctext = _TB_LEADER . preg_replace(array('/&lt;u&gt;/', '/&lt;\\/u&gt;/'), array("<u class='anc'>", "</u>"), htmlspecialchars($data['context'])) . _TB_LEADER;
    } else {
        $ctext = "";
    }
    return "<a href='{$url}'{$alt} {$attr} class='trtitle'>{$title}</a>{$add}" . "<div class='trtext'>{$ctext}</div>" . "<div class='trinfo'>" . _TB_REF_COUNT . ":{$nref} [" . _TB_REF_CDATE . " {$cdate}] [" . _TB_REF_MDATE . " {$mdate}]<br/>" . _TB_REF_URL . " <a href='{$url}'>" . myurldecode($url) . "</a></div>" . $nurl;
}