function keitaiFilter($s) { if ($s === '') { return false; } $head = $header = $body = $footer = $pagetitle = ''; $header_template = $body_template = $footer_template = ''; $encode = ''; $rebuilds = $this->k_tai_conf['rebuilds']; if (isset($rebuilds['redirectMessage'])) { // check "redirectMessage" at last. $_redirectMessage = $rebuilds['redirectMessage']; unset($rebuilds['redirectMessage']); $rebuilds['redirectMessage'] = $_redirectMessage; } // テンプレート読み込み if ($rebuilds && $this->k_tai_conf['template']) { $templates_dir = dirname(dirname(__FILE__)) . '/ktairender/templates/' . $this->k_tai_conf['template'] . '/'; foreach (array('header', 'body', 'footer') as $_name) { if (is_file($templates_dir . $_name . '.html')) { $var_name = $_name . '_template'; ${$var_name} = file_get_contents($templates_dir . $_name . '.html'); } } } $r =& $this->HypKTaiRender; // use jquery mobile? $use_jquery = $r->Config_jquery; $is_rss = false; // Is RSS? if (preg_match('/<(?:feed.+?<entry|(?:rss|rdf).+?<channel)/isS', substr($s, 0, 1000))) { HypCommonFunc::loadClass('HypRss2Html'); $rh = new HypRss2Html($s); $rh->detect_order = $this->detect_order; $s = $rh->getHtml(); //$s = mb_convert_encoding($s, $this->encode, $r->encoding); $encode = $rh->encoding; $header = '<h1>RSS of ' . $rh->base['TITLE'] . '</h1><a href="' . $rh->base['LINK'] . '" data-icon="home" data-iconpos="notext">Home</a>'; $s = str_replace('<head>', '<head><link href="' . $_SERVER['REQUEST_URI'] . '" title="RSS of ' . $rh->base['TITLE'] . '" type="application/rss+xml" rel="alternate" />', $s); $is_rss = true; //$use_jquery = false; } // preg_match では、サイズが大きいページで正常処理できないことがあるので。 $s = str_replace(array('</BODY>', '</HEAD>', '<BODY', '<HEAD'), array('</body>', '</head>', '<body', '<head'), $s); $arr1 = explode('<head', $s, 2); if (isset($arr1[1]) && strpos($arr1[1], '</head>') !== FALSE) { $arr2 = explode('</head>', $arr1[1], 2); $head = substr($arr2[0], strpos($arr2[0], '>') + 1); } $arr1 = explode('<body', $s, 2); if (isset($arr1[1]) && strpos($arr1[1], '</body>') !== FALSE) { $arr2 = explode('</body>', $arr1[1], 2); $body = substr($arr2[0], strpos($arr2[0], '>') + 1); } if ($head && !$encode) { $encode = HypCommonFunc::get_encoding_by_meta($head, TRUE); } if (!$encode) { $encode = $this->encode; } if ($body) { // 最適化済みパートをエスケープ while (strpos($body, '<!--HypKTaiOptimized-->') !== FALSE) { $arr1 = explode('<!--HypKTaiOptimized-->', $body, 2); $arr2 = array_pad(explode('<!--/HypKTaiOptimized-->', $arr1[1], 2), 2, ''); $body = $arr1[0] . str_replace(array('<', '>'), array("", ""), $arr2[0]) . $arr2[1]; } // 携帯のみ有効にする部分 $body = str_replace('<!--HypKTaiOnly', '', $body); $body = str_replace('HypKTaiOnly-->', '', $body); // 無視する部分(<!--HypKTaiIgnore-->...<!--/HypKTaiIgnore-->)を削除 while (strpos($body, '<!--HypKTaiIgnore-->') !== FALSE) { $arr1 = explode('<!--HypKTaiIgnore-->', $body, 2); $arr2 = array_pad(explode('<!--/HypKTaiIgnore-->', $arr1[1], 2), 2, ''); $body = $arr1[0] . $arr2[1]; } // Block を処理 $bid = isset($_GET[$this->k_tai_conf['getKeys']['block']]) ? intval($_GET[$this->k_tai_conf['getKeys']['block']]) : 0; $_showblocks = $showblocks = $blocks = $submenu = $blockmenu = array(); $base = '?'; $querys = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; if ($querys) { $base .= str_replace('&', '&', $querys); } while (strpos($body, '<!--KTaiBlock_') !== FALSE) { $arr1 = explode('<!--KTaiBlock_', $body, 2); $arr2 = array_pad(explode('<!--/KTaiBlock-->', $arr1[1], 2), 2, ''); list($id, $bcontent) = explode('-->', $arr2[0], 2); $title = preg_replace('#^.*?<!--KTaiTitle-->(.+?)<!--/KTaiTitle-->.*?$#s', '$1', $bcontent); $no_title = false; if ($title === $bcontent || !$title) { $title = 'Block No.' . $id; $no_title = true; } if ($use_jquery) { $bcontent = preg_replace('#<h[1-6].*?<!--KTaiTitle-->(.+?)<!--/KTaiTitle-->.*?/h[1-6]>#s', '', $bcontent); if ($no_title) { $body = $arr1[0] . '<div id="ktaiblock' . $id . '">' . $bcontent . '</div>' . $arr2[1]; } else { if (in_array($id, $this->k_tai_conf['showBlockIds'])) { $body = $arr1[0] . '<div id="ktaiblock' . $id . '" data-role="collapsible" data-theme="' . $this->k_tai_conf['jquery_theme_block'] . '" data-content-theme="' . $this->k_tai_conf['jquery_theme_block'] . '" data-collapsed="false"><h3>' . $title . '</h3>' . $bcontent . '</div>' . $arr2[1]; } else { $body = $arr1[0] . '<div id="ktaiblock' . $id . '" data-role="collapsible" data-theme="' . $this->k_tai_conf['jquery_theme_block'] . '" data-content-theme="' . $this->k_tai_conf['jquery_theme_block'] . '" data-collapsed="true"><h3>' . $title . '</h3>' . $bcontent . '</div>' . $arr2[1]; } $blockmenu[$id] = '<a href="#ktaiblock' . $id . '" data-ajax="false">' . $title . '</a>'; } } else { if ($no_title || in_array($id, $this->k_tai_conf['showBlockIds'])) { $body = $arr1[0] . '<div id="ktaiblock' . $id . '">' . $bcontent . '</div>' . $arr2[1]; if (!$no_title) { $showblocks['ktaiblock' . $id] = $title; } } else { $blocks[$id]['content'] = $bcontent; if ($bid != $id) { $submenu[$id] = '<a href="' . $base . '&' . $this->k_tai_conf['getKeys']['block'] . '=' . $id . '">' . $title . '</a>'; } else { $submenu[$id] = '<span style="' . $this->k_tai_conf['style']['highlight'] . '">' . $title . '</span>'; } $body = $arr1[0] . $arr2[1]; } } } if (!empty($_showblocks)) { $showblocks += $_showblocks; } if ($submenu) { $body .= '<!--subMenu--><ul>'; foreach ($submenu as $sub) { $body .= '<li>' . $sub . '</li>'; } $body .= '</ul><!--/subMenu-->'; $showblocks['submenu'] = $this->k_tai_conf['msg']['subMenu']; } if ($showblocks) { $block_menu = array(); foreach ($showblocks as $id => $title) { $block_menu[] = '<a href="#' . $id . '">' . $title . '</a>'; } $body .= '<!--blockMenu-->' . join(' / ', $block_menu) . '<!--/blockMenu-->'; } if ($blockmenu) { $_url = XOOPS_URL . '/'; $blockmenu = join('</li><li>', $blockmenu); if (is_file(XOOPS_THEME_PATH . '/' . $this->k_tai_conf['themeSet'] . '/menubar_jqm.html')) { $body .= str_replace(array('<_JQUERY_THEME_>', '<_BLOCK_MENU_>', '<_TOP_URL_>'), array($this->k_tai_conf['jquery_theme'], $blockmenu, XOOPS_URL . '/'), file_get_contents(XOOPS_THEME_PATH . '/' . $this->k_tai_conf['themeSet'] . '/menubar_jqm.html')); } else { if (isset($rebuilds['blockMenuBar'])) { $body .= <<<EOD <!--blockMenu--> <div id="keitaiblockmenu" data-role="header" data-theme="{$this->k_tai_conf['jquery_theme']}"> <div data-role="navbar"> <ul><li>{$blockmenu}</li></ul> </div> </div> <!--/blockMenu--> <!--blockMenuBar--> <div data-role="header" data-theme="{$this->k_tai_conf['jquery_theme']}"> <a href="{$_url}" data-ajax="false" data-icon="home" data-iconpos="notext">Home</a> <h4> <a id="keitaifixedbar_main" href="#keitaiMainContents" data-ajax="false" style="display:inline;text-decoration:none;"><pagetitle></a> </h4> <a id="keitaifixedbar_block" href="#" data-ajax="false" data-icon="grid" data-iconpos="notext">block</a> </div> <!--/blockMenuBar--> EOD; } else { // old way $body .= <<<EOD <!--blockMenu--> <div id="keitaiblockmenu" data-role="header"> <div data-role="navbar"> <ul><li>{$blockmenu}</li></ul> </div> </div> <div data-role="header"> <a href="{$_url}" data-ajax="false" data-icon="home" data-iconpos="notext">Home</a> <h4> <a id="keitaifixedbar_main" href="#keitaiMainContents" data-ajax="false" style="display:inline;text-decoration:none;"><pagetitle></a> </h4> <a id="keitaifixedbar_block" href="#" data-ajax="false" data-icon="grid" data-iconpos="notext">block</a> </div> <!--/blockMenu--> EOD; } } } if ($rebuilds) { $parts = array(); $rebuild_found = FALSE; if (!empty($_SESSION['hyp_redirect_message'])) { $body = '<!--redirectMessage-->' . $_SESSION['hyp_redirect_message'] . '<!--/redirectMessage-->' . $body; unset($_SESSION['hyp_redirect_message']); } if (isset($_GET[$this->k_tai_conf['getKeys']['block']]) && isset($blocks[$_GET[$this->k_tai_conf['getKeys']['block']]])) { $body .= '<!--toMain-->' . $this->k_tai_conf['icon']['toMain'] . '<a href="' . $base . '">' . $this->k_tai_conf['msg']['toMain'] . '</a><!--/toMain-->'; $body .= '<!--blockContent--><ns>' . $blocks[$_GET[$this->k_tai_conf['getKeys']['block']]]['content'] . '</ns><!--/blockContent-->'; } foreach ($rebuilds as $id => $var) { $qid = preg_quote($id, '#'); $parts[$id] = ''; // preg_match では、サイズが大きいページで正常処理できないことがあるので。 $arr1 = explode('<!--' . $id . '-->', $body, 2); if (isset($arr1[1]) && strpos($arr1[1], '<!--/' . $id . '-->') !== FALSE) { $arr2 = explode('<!--/' . $id . '-->', $arr1[1], 2); $target = $arr2[0]; //$target = trim(preg_replace('/<!--.+?-->/sS', '', $target)); if (!$use_jquery) { $target = trim(preg_replace('/<!--.+?-->/sS', '', $target)); } if (trim(preg_replace('/<\\/?(?:div|span|ns|p)[^>]*?>/S', '', $target))) { $parts[$id] = $var['above'] . $target . $var['below']; if ($id !== 'redirectMessage') { $rebuild_found = TRUE; } else { if ($rebuild_found) { $target = strip_tags($target); } } $parts[$id] = $var['above'] . $target . $var['below']; } } } if ($rebuild_found) { if (isset($_GET[$this->k_tai_conf['getKeys']['block']]) && isset($blocks[$_GET[$this->k_tai_conf['getKeys']['block']]])) { if (empty($parts['content'])) { $parts['toMain'] = ''; } //$parts['content'] = $blocks[$_GET[$this->k_tai_conf['getKeys']['block']]]['content']; $parts['content'] = ''; } if ($use_jquery && !empty($parts['content'])) { $parts['content'] = '<div id="keitaiMainContents" data-role="collapsible" data-theme="' . $this->k_tai_conf['jquery_theme_content'] . '" data-content-theme="' . $this->k_tai_conf['jquery_theme_content'] . '" data-collapsed="false">' . $parts['content'] . '</div>'; } // Easy login & to PC $easylogin = ''; $to_pc = '<li><a href="#" onclick="return jQuery.keitaiSwitchToPc();">PC</a></li>'; if (!empty($this->k_tai_conf['easyLogin'])) { if (!empty($r->vars['ua']['isGuest'])) { $add = '_EASYLOGIN'; if ($r->vars['ua']['carrier'] === 'docomo') { $add .= '&guid=on'; } //$url = $r->myRoot . $r->removeSID($r->SERVER['REQUEST_URI']); $url = $r->myRoot . $r->removeQueryFromUrl($r->SERVER['REQUEST_URI'], array('guid', $r->session_name)); $url .= (strpos($url, '?') === FALSE ? '?' : '&') . $add; $url = str_replace('&', '&', $url); if ($use_jquery) { $easylogin = '******' . $url . '">' . $this->k_tai_conf['msg']['easylogin'] . '</a></li>' . $to_pc . '</ul>'; } else { $easylogin = '******' . $url . '">' . $this->k_tai_conf['msg']['easylogin'] . '</a>'; } } else { $uname = ''; if (empty($_SESSION['hyp_redirect_uname'])) { $member_handler =& xoops_gethandler('member'); $xoopsUser =& $member_handler->getUser($this->HypKTaiRender->vars['ua']['xoopsUid']); $uname = $xoopsUser->getVar('uname'); } else { $uname = $_SESSION['hyp_redirect_uname']; unset($_SESSION['hyp_redirect_uname']); } if ($uname) { $uname = htmlspecialchars($uname, ENT_COMPAT, _CHARSET); $guid = $r->vars['ua']['carrier'] === 'docomo' ? '&guid=on' : ''; $uname = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $this->HypKTaiRender->vars['ua']['xoopsUid'] . $guid . '">' . $uname . '</a>'; } if ($use_jquery) { $easylogin = '******' . $uname . '</li><li><a href="' . XOOPS_URL . '/user.php?op=logout">' . $this->k_tai_conf['msg']['logout'] . '</a></li>' . $to_pc . '</ul>'; } else { $easylogin = $uname . ' <a href="' . XOOPS_URL . '/user.php?op=logout">' . $this->k_tai_conf['msg']['logout'] . '</a>'; } // 簡単ログイン:設定 or 解除 if (isset($this->k_tai_conf['easyLoginConfPath']) && isset($this->k_tai_conf['easyLoginConfuid'])) { $purl = parse_url(XOOPS_URL); $nowpath = $r->SERVER['PHP_SELF']; if (isset($purl['path'])) { $nowpath = preg_replace('#^' . $purl['path'] . '#', '', $nowpath); } if (strpos($nowpath, $this->k_tai_conf['easyLoginConfPath']) === 0 && $this->HypKTaiRender->vars['ua']['xoopsUid'] == @$_GET[$this->k_tai_conf['easyLoginConfuid']]) { $uaUid = md5($r->vars['ua']['uid'] . XOOPS_DB_PASS); // Read easy login data file $myroot = str_replace('/', '_', preg_replace('#https?://#i', '', XOOPS_URL)); $datfile = XOOPS_TRUST_PATH . '/uploads/hyp_common/' . $myroot . '_easylogin.dat'; if (is_file($datfile)) { $uids = unserialize(HypCommonFunc::flock_get_contents($datfile)); } else { $uids = array(); } if (isset($uids[$uaUid])) { $add = '_EASYLOGINUNSET'; $msg = 'easyloginUnset'; } else { $add = '_EASYLOGINSET'; $msg = 'easyloginSet'; } if ($r->vars['ua']['carrier'] === 'docomo') { $add .= '&guid=on'; } $url = $r->myRoot . $r->removeQueryFromUrl($r->SERVER['REQUEST_URI'], array('guid', '_EASYLOGINUNSET', '_EASYLOGINSET')); $url .= (strpos($url, '?') === FALSE ? '?' : '&') . $add; $url = str_replace('&', '&', $url); $parts[$this->k_tai_conf['easyLoginConfInsert']] = '<hr /><div style="text-align:center">[<a href="' . $url . '">' . $this->k_tai_conf['msg'][$msg] . '</a>]</div>' . @$parts[$this->k_tai_conf['easyLoginConfInsert']]; } } } } else { if (!empty($r->vars['ua']['isGuest'])) { if ($use_jquery) { $easylogin = '******' . $to_pc . '</ul>'; } } else { if ($use_jquery) { $easylogin = '******' . $uname . '</li><li><a href="' . XOOPS_URL . '/user.php?op=logout">' . $this->k_tai_conf['msg']['logout'] . '</a></li>' . $to_pc . '</ul>'; } else { $easylogin = $uname . ' <a href="' . XOOPS_URL . '/user.php?op=logout">' . $this->k_tai_conf['msg']['logout'] . '</a>'; } } } if ($easylogin) { $parts['easylogin'] = $rebuilds['easylogin']['above'] . $easylogin . $rebuilds['easylogin']['below']; } foreach (array_keys($rebuilds) as $id) { $header_template = str_replace('<' . $id . '>', $parts[$id], $header_template); $body_template = str_replace('<' . $id . '>', $parts[$id], $body_template); $footer_template = str_replace('<' . $id . '>', $parts[$id], $footer_template); } if ($header_template) { $header = $header_template; } if ($body_template) { $body = $body_template; } if ($footer_template) { $footer = $footer_template; } } elseif ($use_jquery && !$is_rss && strpos($head, '<!--jqm_theme') === false) { return false; } } } else { return $s; } if ($head) { // Redirect if (preg_match('#<meta[^>]+http-equiv=("|\')Refresh\\1[^>]+content=("|\')[\\d]+;\\s*url=(.+)\\2[^>]*>#iUS', $head, $match)) { //$url = str_replace('&', '&', $match[3]); $url = strtr(str_replace('&', '&', $match[3]), "\r\n", " "); if ($body) { $body = preg_replace('#<p>.*?<a[^>]*?href="' . preg_quote($match[3], '#') . '.*?</p>#', '', $body); $_SESSION['hyp_redirect_message'] = strip_tags($body); } $url = $r->getRealUrl($url); $url = $r->addSID($url, XOOPS_URL); $this->_locationRedirect($url, false); return ''; } // <head> $_head = '<head>'; if (preg_match('#<title[^>]*>(.*)</title>#isUS', $head, $match)) { $pagetitle = $match[1]; $_head .= mb_convert_encoding($match[0], $use_jquery ? $encode : 'SJIS-win', $encode); } if (isset($r->vars['ua']['meta'])) { $_head .= $r->vars['ua']['meta']; } // Check RSS & CSS $_css_type = $use_jquery && $this->k_tai_conf['jquery_no_reduce'] ? 'all|screen|handheld' : 'handheld'; $rss = array(); $jquery_script = array(); if ($use_jquery) { // remove jquery-ui css $head = preg_replace('#<link[^>]+?href=[^>]*?jquery-ui(?:\\.min)?\\.css[^>]*?>\\r?\\n?#i', '', $head); } if (preg_match_all('#<link([^>]+?)>#iS', $head, $match)) { foreach ($match[1] as $key => $attrs) { if (preg_match('#type=("|\')application/(?:atom|rss)\\+xml\\1#iS', $attrs)) { if (preg_match('#href=("|\')([^ <>"\']+)\\1#is', $attrs, $match2)) { $title = 'RSS'; $url = $match2[2]; if (preg_match('#title=("|\')([^<>"\']+)\\1#isS', $attrs, $match3)) { $title = $match3[2]; } if (!$is_rss) { $rss[] = '<a href="' . $url . '" data-ajax="true">' . $title . '</a>'; } if ($use_jquery) { $_head .= $match[0][$key]; } } } else { if (preg_match('#rel=("|\')stylesheet\\1#iS', $attrs)) { if (strpos($_css_type, 'all') !== false && strpos($attrs, 'media=') === false) { $_head .= '<link' . $attrs . '>'; } else { if (preg_match('# media=("|\')[a-z, ]*\\b(?:' . $_css_type . '|' . $r->vars['ua']['carrier'] . ')\\b[a-z, ]*\\1#iS', $attrs)) { $_head .= '<link' . preg_replace('# media=("|\')[^"\']*?\\1#iS', '', $attrs) . '>'; } } } } } } /* if (preg_match_all('#<script(.+?)/script>\r?\n?#isS', $head, $match)) { foreach($match[1] as $i => $attrs) { if (preg_match('#jquery#iS', $attrs)) { $jquery_script[] = $match[0][$i]; $head = str_replace($match[0][$i], '', $head); } } } */ if ($rss) { if ($use_jquery && count($rss) > 1) { $rss = '<div data-role="collapsible" data-theme="' . $this->k_tai_conf['jquery_theme_block'] . '" data-content-theme="' . $this->k_tai_conf['jquery_theme_block'] . '" data-collapsed="true"><h4>RSS Links</h4>' . $r->Config_icons['RSS'] . join('<br />' . $r->Config_icons['RSS'], $rss) . '</div>'; } else { $rss = '<div style="font-size:0.9em">' . $r->Config_icons['RSS'] . join('<br />' . $r->Config_icons['RSS'], $rss) . '</div>'; } } else { $rss = ''; } $header = str_replace('<rssLink>', $rss, $header); $body = str_replace('<rssLink>', $rss, $body); $footer = str_replace('<rssLink>', $rss, $footer); if ($use_jquery) { // remove empty script tag from <head> $head = preg_replace('#<script[^>]*?>\\s*?<!--\\s*?//-->\\s*?</script>\\r?\\n?#is', '', $head); // remove jquery tag from <head> $head = preg_replace('#google\\.load\\("jqueryui",\\s*"[^"]+?"\\);\\r?\\n?#', '', $head); $head = preg_replace('#<script[^>]+?src=[^>]*?jquery-?ui(?:\\.min)?\\.js[^>]*?></script>\\r?\\n?#i', '', $head); $_head .= '<link href="' . XOOPS_THEME_URL . '/' . $this->k_tai_conf['themeSet'] . '/jquery.mobile.min.css" rel="stylesheet" type="text/css" />'; if ($this->k_tai_conf['jqm_css']) { $_head .= '<link href="' . $this->k_tai_conf['jqm_css'] . '" rel="stylesheet" type="text/css" />'; } if (!$rebuild_found) { $_head .= '<link href="' . XOOPS_THEME_URL . '/' . $this->k_tai_conf['themeSet'] . '/smart.css" rel="stylesheet" type="text/css" />'; } if ($this->k_tai_conf['jquery_no_reduce']) { $_head .= preg_replace('#<link([^>]+?)>\\r?\\n?|<title.+?/title>\\r?\\n?#iS', '', $head); } $_head .= '<script type="text/javascript" src="' . XOOPS_THEME_URL . '/' . $this->k_tai_conf['themeSet'] . '/jquery.min.js"></script>'; $_head .= '<script type="text/javascript" src="' . XOOPS_THEME_URL . '/' . $this->k_tai_conf['themeSet'] . '/jquery.mobile-config.js"></script>'; $_head .= '<script type="text/javascript" src="' . XOOPS_THEME_URL . '/' . $this->k_tai_conf['themeSet'] . '/jquery.mobile.min.js"></script>'; //$_head .= join('', $jquery_script); $_head .= '<script type="text/javascript" src="' . XOOPS_THEME_URL . '/' . $this->k_tai_conf['themeSet'] . '/jquery.extra.js"></script>'; if (preg_match('/<!--jqm_theme_([a-z])/', $head, $_match)) { $this->k_tai_conf['jquery_theme'] = $_match[1]; $this->k_tai_conf['rebuilds']['header']['above'] = preg_replace('/data-theme="[a-z]"/', 'data-theme="' . $this->k_tai_conf['jquery_theme'] . '"', $this->k_tai_conf['rebuilds']['header']['above']); $this->k_tai_conf['rebuilds']['body']['above'] = preg_replace('/data-theme="[a-z]"/', 'data-theme="' . $this->k_tai_conf['jquery_theme'] . '"', $this->k_tai_conf['rebuilds']['body']['above']); $this->k_tai_conf['rebuilds']['footer']['above'] = preg_replace('/data-theme="[a-z]"/', 'data-theme="' . $this->k_tai_conf['jquery_theme'] . '"', $this->k_tai_conf['rebuilds']['footer']['above']); } } $_head .= '</head>'; $head = $_head; } // Remove xoopsCode buttons & Smilies buttons. if (strpos($body, '<div id="message_bbcode_buttons_pre"') !== FALSE) { $body = preg_replace('#<div id="message_bbcode_buttons_pre".+?/div>#sS', '', $body); $body = preg_replace('#<div id="message_bbcode_buttons_post".+?/div>#sS', '', $body); $body = preg_replace('#<input type="checkbox" id="message_bbcode_onoff".+?<br />#sS', '', $body); $body = preg_replace('#<input type="checkbox" id="d3f_post_advanced_options_onoff".+?>#sS', '', $body); } if (strpos($body, '<a name=\'moresmiley\'>') !== FALSE) { $body = preg_replace('#<a name=\'moresmiley\'>.+?<textarea#sS', '<textarea', $body); $body = preg_replace('#(?:<img |<a href="\\#" )onclick=\'xoopsCodeSmilie\\(.+?</a>\\]#sS', '', $body); } if ($r->vars['ua']['carrier'] === 'docomo') { $body = preg_replace('/<form[^>]+?user\\.php[^>]+?>/isS', '$0<input type="hidden" name="guid" value="ON">', $body); } if ($this->k_tai_conf['googleAnalyticsId']) { $header .= $r->googleAnalyticsGetImgTag($this->k_tai_conf['googleAnalyticsId'], $pagetitle); } $header = $this->k_tai_conf['rebuilds']['header']['above'] . $header . $this->k_tai_conf['rebuilds']['header']['below']; $body = $this->k_tai_conf['rebuilds']['body']['above'] . $body . $this->k_tai_conf['rebuilds']['body']['below']; $footer = $this->k_tai_conf['rebuilds']['footer']['above'] . $footer . $this->k_tai_conf['rebuilds']['footer']['below']; if ($use_jquery) { $header .= '<separator>'; $body .= '<separator>'; if ($this->k_tai_conf['jquery_no_reduce']) { $r->Config_no_diet = true; } } $r->contents['header'] = $header; $r->contents['body'] = $body; $r->contents['footer'] = $footer; $r->inputEncode = $encode; $r->outputEncode = $use_jquery ? $encode : 'SJIS'; $r->outputMode = $use_jquery ? 'html5' : 'xhtml'; $r->langcode = _LANGCODE; $r->doOptimize(); $charset = strtoupper($r->outputEncode) === 'SJIS' ? 'Shift_JIS' : $encode; // Set <body> attribute $bodyAttr = $this->k_tai_conf['bodyAttribute'] ? ' ' . trim($this->k_tai_conf['bodyAttribute']) : ''; if (!empty($r->vars['ua']['bodyAttribute'])) { $bodyAttr = ' ' . trim($r->vars['ua']['bodyAttribute']); } $outBody = $r->outputBody; $outBody = str_replace('<pagetitle>', $pagetitle, $outBody); if ($use_jquery) { $_array = explode('<separator>', $outBody); $outBody = '<div data-role="page" data-theme="' . $this->k_tai_conf['jquery_theme'] . '">'; $outBody .= $_array[0]; $outBody .= $_array[1]; $outBody .= $_array[2]; $outBody .= '</div>'; } $s = $r->getHtmlDeclaration() . $head . '<body' . $bodyAttr . '>' . $outBody . '</body></html>'; $ctype = $r->getOutputContentType(); $r = NULL; unset($r); header('Content-Type: ' . $ctype . '; charset=' . $charset); if (!$use_jquery) { header('Cache-Control: no-cache'); if (function_exists('headers_list')) { header('Content-Length: ' . strlen($s)); } } $this->changeContentLength = true; return $s; }
function plugin_rss_action() { $version = isset($this->root->vars['ver']) ? strtolower($this->root->vars['ver']) : ''; $base = isset($this->root->vars['p']) ? $this->root->vars['p'] : ''; $s_base = $base ? '/' . $base : ''; $uid = !empty($this->root->vars['u']) ? strval(intval($this->root->vars['u'])) : ''; $cache_clear = isset($this->root->vars['cc']); switch ($version) { case '': $version = '1.0'; break; // Default // Default case '1': $version = '1.0'; break; // Sugar // Sugar case '2': $version = '2.0'; break; // Sugar // Sugar case 'atom': /* FALLTHROUGH */ /* FALLTHROUGH */ case '0.91': /* FALLTHROUGH */ /* FALLTHROUGH */ case '1.0': /* FALLTHROUGH */ /* FALLTHROUGH */ case '2.0': break; default: die('Invalid RSS version!!'); } $count = empty($this->root->vars['count']) ? $this->root->rss_max : (int) $this->root->vars['count']; $count = max($count, 1); $count = min($count, $this->maxcount); // キャッシュファイル名 $c_file = $this->cont['CACHE_DIR'] . 'plugin/' . md5($version . $base . $count . $uid . $this->cont['ROOT_URL']) . $this->cont['UI_LANG'] . '.rss'; if (!$cache_clear && is_file($c_file)) { $filetime = filemtime($c_file); $etag = md5($c_file . $filetime); if ($etag === @$_SERVER["HTTP_IF_NONE_MATCH"] && $this->cont['UA_PROFILE'] !== 'keitai') { // バッファをクリア $this->func->clear_output_buffer(); header("HTTP/1.1 304 Not Modified"); header("Etag: " . $etag); header('Cache-Control: private'); header('Pragma:'); //header('Expires:'); exit; } $out = file_get_contents($c_file); } else { // バッファリング ob_start(); $lang = $this->cont['LANG']; $page_title = $this->func->htmlspecialchars($this->root->siteinfo['sitename'] . '::' . $this->root->module_title . $s_base); $self = $this->func->get_script_uri(); $maketime = $date = substr_replace($this->func->get_date('Y-m-d\\TH:i:sO'), ':', -2, 0); $buildtime = $this->func->get_date('r'); $pubtime = 0; $rss_css = $this->cont['LOADER_URL'] . '?src=rss.' . $this->cont['UI_LANG'] . '.xml'; // Creating <item> $items = $rdf_li = ''; // ゲスト扱いで一覧を取得 $nolisting = !$base || $base[0] !== ':'; $where = $uid ? '`uid`="' . $uid . '"' : ''; $lines = $this->func->get_existpages(FALSE, $base ? $base . '/' : '', array('limit' => $count, 'order' => ' ORDER BY editedtime DESC', 'nolisting' => $nolisting, 'withtime' => TRUE, 'asguest' => TRUE, 'where' => $where)); foreach ($lines as $line) { list($time, $page) = explode("\t", rtrim($line)); $r_page = rawurlencode($page); $link = $this->func->get_page_uri($page, true, 'keitai'); $title = $this->func->htmlspecialchars($this->root->pagename_num2str ? preg_replace('/\\/(?:[0-9\\-]+|[B0-9][A-Z0-9]{9})$/', '/' . $this->func->strip_emoji(htmlspecialchars_decode($this->func->get_heading($page))), $page) : $page); if ($base) { $title = substr($title, strlen($base) + 1); } if (!$pubtime) { $pubtime = $this->func->get_date('r', $time); } switch ($version) { case '0.91': $date = $this->func->get_date('r', $time); $items .= <<<EOD <item> <title>{$title}</title> <link>{$link}</link> <description>{$date}</description> </item> EOD; break; case '2.0': list($description, $html, $pginfo) = $this->get_content($page); $author = $this->func->htmlspecialchars($pginfo['uname']); $date = $this->func->get_date('r', $time); $items .= <<<EOD <item> <title>{$title}</title> <link>{$link}</link> <guid>{$link}</guid> <pubDate>{$date}</pubDate> <description>{$description}</description> <content:encoded><![CDATA[ {$html} ]]></content:encoded> </item> EOD; break; case '1.0': // Add <item> into <items> list($description, $html, $pginfo, $tags) = $this->get_content($page); $author = $this->func->htmlspecialchars($pginfo['uname']); $tag = ''; if ($tags) { $tags = array_map('$this->func->htmlspecialchars', array_map('rtrim', $tags)); $tag = '<dc:subject>' . join("</dc:subject>\n <dc:subject>", $tags) . '</dc:subject>'; } $rdf_li .= ' <rdf:li rdf:resource="' . $link . '" />' . "\n"; $date = substr_replace($this->func->get_date('Y-m-d\\TH:i:sO', $time), ':', -2, 0); $trackback_ping = ''; /* if ($this->root->trackback) { $tb_id = md5($r_page); $trackback_ping = ' <trackback:ping>' . $self . '?tb_id=' . $tb_id . '</trackback:ping>'; } */ $items .= <<<EOD <item rdf:about="{$self}?{$r_page}"> <title>{$title}</title> <link>{$link}</link> <dc:date>{$date}</dc:date> <dc:creator>{$author}</dc:creator> {$tag} <description>{$description}</description> <content:encoded><![CDATA[ {$html} ]]></content:encoded> <dc:identifier>{$self}?{$r_page}</dc:identifier> {$trackback_ping} </item> EOD; break; case 'atom': list($description, $html, $pginfo, $tags) = $this->get_content($page); $author = $this->func->htmlspecialchars($pginfo['uname']); $tag = ''; if ($tags) { $tags = array_map('$this->func->htmlspecialchars', array_map('rtrim', $tags)); foreach ($tags as $_tag) { $tag .= '<category term="' . str_replace('"', '\\"', $_tag) . '"/>' . "\n"; } } $date = substr_replace($this->func->get_date('Y-m-d\\TH:i:sO', $time), ':', -2, 0); $id = $link; $items .= <<<EOD <entry> <title type="html">{$title}</title> <link rel="alternate" type="text/html" href="{$link}" /> <id>{$id}</id> <updated>{$date}</updated> <published>{$date}</published> {$tag} <author> <name>{$author}</name> </author> <summary type="html">{$description}</summary> <content type="html"><![CDATA[ {$html} ]]></content> </entry> EOD; break; } } // Feeding start print '<?xml version="1.0" encoding="UTF-8"?>' . "\n\n"; //$r_whatsnew = rawurlencode($this->root->whatsnew); $link = $base ? $this->func->get_page_uri($base, true) : $self; switch ($version) { case '0.91': print <<<EOD <!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd"> <rss version="{$version}"> <channel> <title>{$page_title}</title> <link>{$link}</link> <description>xpWiki RecentChanges</description> <language>{$lang}</language> {$items} </channel> </rss> EOD; break; case '2.0': print <<<EOD <rss version="{$version}" xmlns:content="http://purl.org/rss/1.0/modules/content/"> <channel> <title>{$page_title}</title> <link>{$link}</link> <description>xpWiki RecentChanges</description> <language>{$lang}</language> <image> <url>{$self}module_icon.php</url> <title>{$page_title}</title> <link>{$link}</link> <description>{$page_title}</description> </image> <pubDate>{$pubtime}</pubDate> <lastBuildDate>{$buildtime}</lastBuildDate> <generator>xpWiki</generator> {$items} </channel> </rss> EOD; break; case '1.0': $xmlns_trackback = $this->root->trackback ? ' xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"' : ''; print <<<EOD <?xml-stylesheet type="text/xsl" media="screen" href="{$rss_css}" ?> <rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" {$xmlns_trackback} xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xml:lang="{$lang}"> <channel rdf:about="{$link}"> <title>{$page_title}</title> <link>{$link}</link> <description>xpWiki RecentChanges</description> <dc:date>{$maketime}</dc:date> <image rdf:resource="{$self}module_icon.php" /> <items> <rdf:Seq> {$rdf_li} </rdf:Seq> </items> </channel> <image rdf:about="{$self}module_icon.php"> <title>{$page_title}</title> <link>{$link}</link> <url>{$self}module_icon.php</url> </image> {$items} </rdf:RDF> EOD; break; case 'atom': $rpage = $base ? '&p=' . rawurlencode($base) : ''; $feedurl = $this->cont['HOME_URL'] . '?cmd=rss' . $rpage . '&ver=atom'; $rpage = $base ? '&p=' . rawurlencode($base) : ''; $modifier = $this->func->htmlspecialchars($this->root->modifier); print <<<EOD <feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{$lang}"> <title>{$page_title}</title> <link rel="alternate" type="text/html" href="{$link}" /> <link rel="self" type="application/atom+xml" href="{$feedurl}" /> <id>{$self}</id> <updated>{$maketime}</updated> <subtitle>xpWiki RecentChanges</subtitle> <generator uri="http://hypweb.net/">xpWiki</generator> <rights>hypweb.net</rights> <author> <name>{$modifier}</name> <uri>{$this->root->modifierlink}</uri> </author> {$items} </feed> EOD; break; } $out = mb_convert_encoding(ob_get_contents(), 'UTF-8', $this->cont['CONTENT_CHARSET']); ob_end_clean(); // NULLバイト除去 $out = $this->func->input_filter($out); if ($this->cont['UA_PROFILE'] === 'default') { //キャッシュ書き込み if ($fp = @fopen($c_file, "wb")) { fputs($fp, $out); fclose($fp); } $filetime = filemtime($c_file); } else { $filetime = time(); } $etag = md5($c_file . $filetime); } if ($this->cont['UA_PROFILE'] === 'keitai' || defined('HYP_K_TAI_RENDER') && HYP_K_TAI_RENDER === 1) { HypCommonFunc::loadClass('HypRss2Html'); $r = new HypRss2Html($out); $out = $r->getHtml(); $out = mb_convert_encoding($out, 'SJIS', $r->encoding); HypCommonFunc::loadClass('HypKTaiRender'); if (HypCommonFunc::get_version() < '20080925') { $r = new HypKTaiRender(); } else { $r =& HypKTaiRender::getSingleton(); } $r->set_myRoot($this->root->siteinfo['host']); $r->Config_hypCommonURL = $this->cont['ROOT_URL'] . 'class/hyp_common'; $r->Config_redirect = $this->root->k_tai_conf['redirect']; $r->Config_emojiDir = $this->cont['ROOT_URL'] . 'images/emoji'; if (!empty($this->root->k_tai_conf['showImgHosts'])) { $r->Config_showImgHosts = $this->root->k_tai_conf['showImgHosts']; } if (!empty($this->root->k_tai_conf['directLinkHosts'])) { $r->Config_directLinkHosts = $this->root->k_tai_conf['directLinkHosts']; } if ($this->cont['PKWK_ENCODING_HINT']) { $r->Config_encodeHintWord = $this->cont['PKWK_ENCODING_HINT']; } if (!empty($this->root->k_tai_conf['googleAdsense']['config'])) { $r->Config_googleAdSenseConfig = $this->root->k_tai_conf['googleAdsense']['config']; $r->Config_googleAdSenseBelow = $this->root->k_tai_conf['googleAdsense']['below']; } $r->inputEncode = 'SHIFT_JIS'; $r->outputEncode = 'SJIS'; $r->outputMode = 'xhtml'; $r->langcode = $this->cont['LANG']; $r->inputHtml = $out; $r->doOptimize(); $out = $r->outputBody; // バッファをクリア $this->func->clear_output_buffer(); header('Content-Type: text/html; charset=Shift_JIS'); header('Content-Length: ' . strlen($out)); header('Cache-Control: no-cache'); } else { header('Content-Type: application/xml; charset=utf-8'); header('Content-Length: ' . strlen($out)); header('Cache-Control: private'); header('Pragma:'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $filetime) . ' GMT'); header('Etag: ' . $etag); } echo $out; exit; }