+if(!$a->theme['stylesheet'])
+ $stylesheet = current_theme_url();
+else
+ $stylesheet = $a->theme['stylesheet'];
+
+$a->page['htmlhead'] = str_replace('{{$stylesheet}}',$stylesheet,$a->page['htmlhead']);
+//$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => $stylesheet));
+
+if (isset($_GET["mode"]) AND (($_GET["mode"] == "raw") OR ($_GET["mode"] == "minimal"))) {
+ $doc = new DOMDocument();
+
+ $target = new DOMDocument();
+ $target->loadXML("<root></root>");
+
+ $content = mb_convert_encoding($a->page["content"], 'HTML-ENTITIES', "UTF-8");
+
+ @$doc->loadHTML($content);
+
+ $xpath = new DomXPath($doc);
+
+ $list = $xpath->query("//*[contains(@id,'tread-wrapper-')]"); /* */
+
+ foreach ($list as $item) {
+
+ $item = $target->importNode($item, true);
+
+ // And then append it to the target
+ $target->documentElement->appendChild($item);
+ }
+}
+
+if (isset($_GET["mode"]) AND ($_GET["mode"] == "raw")) {
+
+ header("Content-type: text/html; charset=utf-8");
+
+ echo substr($target->saveHTML(), 6, -8);
+
+ session_write_close();
+ exit;
+
+} elseif (get_pconfig(local_user(),'system','infinite_scroll')
+ AND ($a->module == "network") AND ($_GET["mode"] != "minimal")) {
+ if (is_string($_GET["page"]))
+ $pageno = $_GET["page"];
+ else
+ $pageno = 1;
+
+ $reload_uri = "";
+
+ foreach ($_GET AS $param => $value)
+ if (($param != "page") AND ($param != "q"))
+ $reload_uri .= "&".$param."=".urlencode($value);
+
+ if (($a->page_offset != "") AND !strstr($reload_uri, "&offset="))
+ $reload_uri .= "&offset=".urlencode($a->page_offset);
+
+
+$a->page['htmlhead'] .= <<< EOT
+<script type="text/javascript">
+
+$(document).ready(function() {
+ num = $pageno;
+});
+
+function loadcontent() {
+ //$("div.loader").show();
+
+ num+=1;
+
+ console.log('Loading page ' + num);
+
+ $.get('/network?mode=raw$reload_uri&page=' + num, function(data) {
+ $(data).insertBefore('#conversation-end');
+ });
+
+ //$("div.loader").fadeOut('normal');
+}
+
+var num = $pageno;
+
+$(window).scroll(function(e){
+
+ if ($(document).height() != $(window).height()) {
+ // First method that is expected to work - but has problems with Chrome
+ if ($(window).scrollTop() == $(document).height() - $(window).height())
+ loadcontent();
+ } else {
+ // This method works with Chrome - but seems to be much slower in Firefox
+ if ($(window).scrollTop() > (($("section").height() + $("header").height() + $("footer").height()) - $(window).height()))
+ loadcontent();
+ }
+});
+</script>
+
+EOT;
+
+}