public function add_link_sid($buffer)
 {
     if (!$this->sid) {
         return $buffer;
     }
     for ($offset = 0, $replace = 'X'; preg_match('!<a ([^>]*?)href=([\'"])(' . KtaiStyle::QUOTED_STRING_REGEX . ')\\2([^>]*?)>!s', $buffer, $l, PREG_OFFSET_CAPTURE, $offset); $offset += strlen($replace)) {
         $orig = $l[0][0];
         $offset = $l[0][1];
         $url = $l[3][0];
         $url = _ks_quoted_remove_query_arg(self::SESSION_NAME, $url);
         $attr1 = $l[1][0];
         $attr2 = $l[4][0];
         $replace = $orig;
         if ($this->is_internal($url)) {
             $replace = sprintf('<a %shref="%s"%s>', $attr1, $this->add_sid($url, KTAI_DO_ECHO), $attr2);
             $buffer = substr_replace($buffer, $replace, $offset, strlen($orig));
             // convert links
         }
     }
     return $buffer;
 }
 public function add_url_inline_image($buffer)
 {
     $value = $this->image_inline ? 'inline' : 'link';
     for ($offset = 0, $replace = 'X'; preg_match('!<a ([^>]*?)href=([\'"])(' . KtaiStyle::QUOTED_STRING_REGEX . ')\\2([^>]*?)>!s', $buffer, $l, PREG_OFFSET_CAPTURE, $offset); $offset += strlen($replace)) {
         $orig = $l[0][0];
         $offset = $l[0][1];
         $url = $l[3][0];
         $url = _ks_quoted_remove_query_arg('img', $url);
         $attr1 = $l[1][0];
         $attr2 = $l[4][0];
         $replace = $orig;
         if (!preg_match($this->self_urls_regex, $url) || preg_match('/id="inline"/', $attr1 . $attr2)) {
             continue;
         }
         $url .= (strpos($url, '?') === false ? '?' : '&amp;') . "img={$value}";
         // can not use add_query_arg()
         $replace = sprintf('<a %shref="%s"%s>', $attr1, $url, $attr2);
         $buffer = substr_replace($buffer, $replace, $offset, strlen($orig));
         // convert links
     }
     return $buffer;
 }
function ks_next_posts_link()
{
    if (is_single()) {
        return;
    }
    $defaults = array('anchor' => __('#.Next', 'ktai_style') . '<img localsrc="8" alt=" &raquo;">', 'accesskey' => '#', 'max_pages' => 0, 'echo' => true);
    $r = _ks_parse_arg(func_get_args(), $defaults);
    if (isset($r['label'])) {
        $r['anchor'] = $r['label'];
    }
    if (!$r['max_pages']) {
        $r['max_pages'] = _ks_get_max_num_pages();
    }
    $paged = intval(get_query_var('paged'));
    $nextpage = intval($paged) + 1;
    $output = '';
    if (empty($paged) || $nextpage <= $r['max_pages']) {
        $output = '<a href="' . KtaiStyle::strip_host(clean_url(_ks_quoted_remove_query_arg('kp', get_next_posts_page_link($r['max_pages'])))) . '"' . ks_accesskey_html($r['accesskey']) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/', '&amp;$1', $r['anchor']) . '</a>';
    }
    if ($r['echo']) {
        echo $output;
    }
    return $output;
}