Skip to content

Instantly share code, notes, and snippets.

@seedprod
Created March 3, 2011 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save seedprod/852808 to your computer and use it in GitHub Desktop.
Save seedprod/852808 to your computer and use it in GitHub Desktop.
Mobile php buffer method
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<!--#START-ROOT-CODE
<?php
$docRoot = '/var/www/html';
require_once($docRoot .'/scripts/global-pre.php');
?>
#END-ROOT-CODE-->
<head>
<title><system-page-title/> - College of Charleston</title>
<system-page-meta-keywords/>
<system-page-meta-description/>
<meta content="en-us" http-equiv="content-language" name="language"/>
<meta content="text/html;charset=utf-8" http-equiv="content-type"/>
[system-view:internal]
<link href="/styles/common.css" media="screen" rel="stylesheet"/>
<link href="/styles/custom.css" media="screen" rel="stylesheet"/>
[/system-view:internal]
[system-view:external]
<!--#START-CODE <?php if($_GET['print'] == '1'){ ?> #END-CODE-->
<link href="/styles/print.css" media="all" rel="stylesheet"/>
<!--#START-CODE <?php } else { ?> #END-CODE-->
<link href="/styles/common.css" media="screen" rel="stylesheet"/>
<link href="/styles/custom.css" media="screen" rel="stylesheet"/>
<!--#START-CODE <?php } ?> #END-CODE-->
[/system-view:external]
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("jquery", "1.4.2");
</script>
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="[system-asset:id=b82589897f00000101fcc4f8db234586]/styles/IE_low.css[/system-asset]" media="screen" />
<![endif]-->
<script type="text/javascript">
var activeLink = "about";
</script>
[system-view:internal]
<script src="/scripts/primarynav_internal.js" type="text/javascript"></script>
[/system-view:internal]
[system-view:external]
<script src="/scripts/primarynav.js" type="text/javascript"></script>
[/system-view:external]
</head>
<body class="full-banner">
<div class="page-wrapper">
<div class="header small-header">
<a href="/index"><img alt="College of Charleston Home" class="home-link" height="1" src="/images/blank.gif" width="1"/></a>
<div class="audience-nav">
<system-region name="AUDIENCE-NAVIGATION"/>
</div>
<div class="tactical-nav">
<system-region name="TACTICAL-NAVIGATION"/>
</div>
<system-region name="HEADER"/>
<div class="primary-nav">
<system-region name="PRIMARY-NAVIGATION"/>
</div>
</div>
<div class="column-wrapper">
<div class="colA">
<div class="banner">
<system-region name="BANNER"/>
</div>
<div class="left-nav">
<system-region name="LEFT-NAVIGATION"/>
<system-region name="LEFT-CONTENT"/>
<system-region name="EMAIL-A-FRIEND"/>
</div>
<div class="content">
<div class="breadcrumbs">
<system-region name="BREADCRUMBS"/>
</div>
<system-region name="DEFAULT"/>
</div>
<div class="colB">
<system-region name="RIGHT-CONTENT"/>
</div>
</div>
<div class="clearDiv"></div>
</div>
<div class="footer">
<system-region name="FOOTER"/>
</div>
<div class="clear">
</div>
</div>
</body>
</html><?php require_once($docRoot .'/scripts/global-post.php');
?>
<?php
$html = ob_get_contents();
ob_end_clean();
// Output
if($mobile_browser){
$pq = phpQuery::newDocument($html);
phpQuery::selectDocument($pq);
$navHeader = pq('.leftNavSectionHeader');
$nav = pq('.nav');
$content1 = pq('.content');
$content2 = pq('.sr-rightcol');
require_once($docRoot .'/scripts/mobile/header.php');
echo '<div class="left-nav">';
ob_start();
echo $navHeader;
$navHeaderstr = ob_get_contents();
ob_end_clean();
ob_start();
echo $nav;
$navstr = ob_get_contents();
ob_end_clean();
echo convertNavToDropdown($navHeaderstr,$navstr);
echo '</div>';
ob_start();
echo $content1;
$contentstr1 = ob_get_contents();
ob_end_clean();
ob_start();
echo $content2;
$contentstr2 = ob_get_contents();
ob_end_clean();
if(!empty($contentstr1)){
echo $contentstr1;
}else if(!empty($contentstr2)){
echo $contentstr2;
}else{
echo "<h1 style='text-align:center; margin:20px;'>There is no mobile version of this page.</h1>";
}
require_once($docRoot .'/scripts/mobile/footer.php');
}
else {
echo $html;
}
//Zend_Debug::dump($mobile_browser);
//Zend_Debug::dump($navHeaderstr);
//Zend_Debug::dump($content);
//functions
function convertNavToDropdown($navHeaderstr,$nav){
$nav = str_replace(array("\n","\r"),'',$nav);
$navArr = array();
$pq = phpQuery::newDocument($nav);
phpQuery::selectDocument($pq);
$ul = pq('ul.nav');
foreach($ul['> li'] as $li) {
$firstlevel = pq($li )->html();
$firstlevel = str_replace("\n",'',$firstlevel);
if(strpos($firstlevel, '<a') === 0){
$firstlevel = str_replace(array('<a title="','" href="','">','</a>'),array('<option href="','" value="','">- ','</option>'),str_replace("\n",'',$firstlevel));
$firstlevel = str_replace(array('<a href="','" title="'),array('<option value="','" title="'),str_replace("\n",'',$firstlevel));
$navArr[] = $firstlevel;
}else if(strpos($firstlevel, '<span') === 0){
$firstlevel = str_replace(array('<span>','</span>'),array('<option selected="selected">- ','</option>'),str_replace("\n",'',$firstlevel));
$navArr[] = $firstlevel;
}else{
if(strpos($firstlevel, '<div><strong>') === 0){
$firstleveltemp = str_replace(array('<div><strong><span>','</span></strong>'),array('<option selected="selected">- *','*</option>'),str_replace("\n",'',$firstlevel));
}else{
$firstleveltemp = str_replace(array('<a href="index.php"><strong>','</strong></a>'),array('<option>- ','</option>'),str_replace("\n",'',$firstlevel));
}
$patterns = "/\<\/option\>(.)*/";
$firstleveltemp = preg_replace($patterns, '</option>', $firstleveltemp);
$navArr[] = $firstleveltemp;
$pq2 = phpQuery::newDocument($firstlevel);
$ul2 = $pq2['ul.subnav'];
foreach($ul2['> li'] as $li2) {
$secondlevel = pq($li2)->html();
$secondlevel = str_replace("\n",'',$secondlevel);
$secondlevel = str_replace(array('<a title="','" href="','">','</a>'),array('<option title="','" value="','">- - ','</option>'),$secondlevel);
$secondlevel = str_replace(array('<a href="','" title="','">- -','</a>'),array('<option value="','" title="','">- - ','</option>'),$secondlevel);
$secondlevel = str_replace(array('<span>','</span>'),array('<option selected="selected">- - *','*</option>'),$secondlevel);
//Zend_Debug::dump($secondlevel);
$navArr[] = $secondlevel ;
}
}
}
$output = '<select id="nav" onchange="window.location = this.options[this.selectedIndex].value">';
$output .= str_replace(array('<div class="leftNavSectionHeader"><a href="','">','</a></div>'),array('<option value="','" >','</option>'),$navHeaderstr);
foreach($navArr as $val){
$output .= $val;
}
$output .= '</select>';
return $output;
}
?>
<?php
//display error
//ini_set('display_errors', 1);
//error_reporting(E_ALL);
// Global Variables
$docRoot = '/var/www/html';
$mobile_browser = $_COOKIE['mobile'];
// Load Zend
set_include_path('.' . PATH_SEPARATOR . dirname(__FILE__) .PATH_SEPARATOR . '.');
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);
//Load phpQuery
require('phpQuery/phpQuery.php');
//Load Mobile Detect
//require_once($docRoot .'/scripts/mobile-detect.php');
//Library Redirect
try{
$path = $_SERVER['REQUEST_URI'];
$host = $_SERVER['HTTP_HOST'];
$url = $host.$path;
$pattern = '\/library\/';
if ($mobile_browser>0 && preg_match("/($pattern)/", $url)) {
header( 'Location: http://mcat.library.cofc.edu' ) ;
}
} catch (Exception $e) {
}
// Start Buffer
$buffer = ob_start();
?>
<?php
$docRoot = '/var/www/html';
// Check for Mobile Browser
// Redirect to full site
if ($_GET['full']){
setcookie("mobile", "", time()-3600,$path='', '.cofc.edu');
setcookie("full", "1", null,$path='', '.cofc.edu');
header( 'Location: http://www.cofc.edu' ) ;
}
if ($_COOKIE['full']){
setcookie("mobile", '1',null,$path='', '.cofc.edu');
setcookie("full", "", time()-3600,$path='', '.cofc.edu');
}
require_once($docRoot .'/scripts/mobile-detect.php');
if($mobile_browser>0) {
setcookie("mobile", '1',null,$path='', '.cofc.edu');
}
else {
header( 'Location: http://www.cofc.edu' ) ;
}
require_once($docRoot .'/scripts/mobile/header.php');
?>
<ul class="m-nav">
<li><a href="http://www.cofc.edu/about/">About<span class="m-sub-links">History and Traditions, Social Media...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://cofc.edu/academics/">Academic<span class="m-sub-links">Schools, Majors and Minors...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://admissions.cofc.edu/">Admissions<span class="m-sub-links">Applying, Financial Aid...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://www.cofc.edu/campuslife/">Campus Life<span class="m-sub-links">Culture, Housing, Clubs...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://www.cofc.edu/athletics/">Athletics<span class="m-sub-links">News, Schedules, Tickets...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://gradschool.cofc.edu/">Graduate School<span class="m-sub-links">Applying, Degrees...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://www.cofc.edu/library/">Library<span class="m-sub-links">Research, Services...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://giving.cofc.edu/">Giving<span class="m-sub-links">Donors, Foundation...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
</ul>
<ul class="m-nav">
<li><a href="http://www.cofc.edu/visit/">Visit<span class="m-sub-links">Directions, Maps, Weather...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://bookstore.cofc.edu/">Bookstore<span class="m-sub-links">Textbooks, Apparel...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://www.cofc.edu/directory/">Directory<span class="m-sub-links">Students, Faculty, Staff...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://www.cofc.edu/siteindex/">Site Index<span class="m-sub-links">Websites</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
</ul>
<ul class="m-nav">
<li><a href="http://www.cofc.edu/currentstudents/">Current Students<span class="m-sub-links">My Charleston, Webmail...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://www.cofc.edu/parents/">Parents<span class="m-sub-links">eBill, CougarTrail...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://www.cofc.edu/facultystaff/">Faculty &amp; Staff<span class="m-sub-links">My Charleston, Webmail...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
<li><a href="http://alumni.cofc.edu/">Alumni<span class="m-sub-links">Community, Get Involved...</span><img src="http://www.cofc.edu/images/mobile/ql-next.png" /></a></li>
</ul>
<ul class="m-nav">
<li><a href="http://news.cofc.edu/">News</a>
<div class="m-feeds">
<div id="feed-control"><span style="font-size: 11px; margin: 10px; padding: 4px;">Loading...</span></div>
<!-- Google Ajax Api
-->
<script src="http://www.google.com/jsapi?key=notsupplied-wizard" type="text/javascript"></script>
<!-- Dynamic Feed Control and Stylesheet -->
<script src="http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js" type="text/javascript"></script>
<script type="text/javascript">
function LoadDynamicFeedControl() {
var feeds = [
{title: 'College of Charleston News',
url: 'http://news.cofc.edu/feed/'
}];
var options = {
stacked : false,
horizontal : false,
title : ""
}
new GFdynamicFeedControl(feeds, 'feed-control', options);
}
// Load the feeds API and set the onload callback.
google.load('feeds', '1');
google.setOnLoadCallback(LoadDynamicFeedControl);
</script>
<!-- ++End Dynamic Feed Control Wizard Generated Code++ -->
</div>
</li>
<?php
$startdate = date('n/j/Y');
$enddate = date('n/j/Y', time() + 2592000);
$calurl = "http://calendar.cofc.edu/RSSSyndicator.aspx?category=&location=&type=N&starting={$startdate}&ending={$enddate}&binary=Y"
?>
<li><a href="http://calendar.cofc.edu">Events</a>
<div class="m-feeds">
<div id="feed-control-1"><span style="font-size: 11px; margin: 10px; padding: 4px;">Loading...</span></div>
<script type="text/javascript">
function LoadDynamicFeedControl() {
var feeds1 = [
{title: 'College of Charleston Events Calendar',
url: 'http://calendar.cofc.edu/RSSSyndicator.aspx?category=&amp;location=&amp;type=N&amp;starting=3/1/2010&amp;ending=3/31/2010&amp;binary=Y'
}];
var options1 = {
stacked : false,
horizontal : false,
title : ""
}
new GFdynamicFeedControl(feeds1, 'feed-control-1', options1);
}
// Load the feeds API and set the onload callback.
google.load('feeds', '1');
google.setOnLoadCallback(LoadDynamicFeedControl);
</script>
<!-- ++End Dynamic Feed Control Wizard Generated Code++ -->
</div>
</li>
</ul>
<?php
require_once($docRoot .'/scripts/mobile/footer.php');
?>
<?php
$html = ob_get_contents();
ob_end_clean();
// Output
if($mobile_browser){
$pq = phpQuery::newDocument($html);
phpQuery::selectDocument($pq);
$navHeader = pq('.leftNavSectionHeader');
$nav = pq('.nav');
$content1 = pq('.content');
$content2 = pq('.sr-rightcol');
require_once($docRoot .'/scripts/mobile/header.php');
echo '<div class="left-nav">';
ob_start();
echo $navHeader;
$navHeaderstr = ob_get_contents();
ob_end_clean();
ob_start();
echo $nav;
$navstr = ob_get_contents();
ob_end_clean();
echo convertNavToDropdown($navHeaderstr,$navstr);
echo '</div>';
ob_start();
echo $content1;
$contentstr1 = ob_get_contents();
ob_end_clean();
ob_start();
echo $content2;
$contentstr2 = ob_get_contents();
ob_end_clean();
if(!empty($contentstr1)){
echo $contentstr1;
}else if(!empty($contentstr2)){
echo $contentstr2;
}else{
echo "<h1 style='text-align:center; margin:20px;'>There is no mobile version of this page.</h1>";
}
require_once($docRoot .'/scripts/mobile/footer.php');
}
else {
echo $html;
}
//Zend_Debug::dump($mobile_browser);
//Zend_Debug::dump($navHeaderstr);
//Zend_Debug::dump($content);
//functions
function convertNavToDropdown($navHeaderstr,$nav){
$nav = str_replace(array("\n","\r"),'',$nav);
$navArr = array();
$pq = phpQuery::newDocument($nav);
phpQuery::selectDocument($pq);
$ul = pq('ul.nav');
foreach($ul['> li'] as $li) {
$firstlevel = pq($li )->html();
$firstlevel = str_replace("\n",'',$firstlevel);
if(strpos($firstlevel, '<a') === 0){
$firstlevel = str_replace(array('<a title="','" href="','">','</a>'),array('<option href="','" value="','">- ','</option>'),str_replace("\n",'',$firstlevel));
$firstlevel = str_replace(array('<a href="','" title="'),array('<option value="','" title="'),str_replace("\n",'',$firstlevel));
$navArr[] = $firstlevel;
}else if(strpos($firstlevel, '<span') === 0){
$firstlevel = str_replace(array('<span>','</span>'),array('<option selected="selected">- ','</option>'),str_replace("\n",'',$firstlevel));
$navArr[] = $firstlevel;
}else{
if(strpos($firstlevel, '<div><strong>') === 0){
$firstleveltemp = str_replace(array('<div><strong><span>','</span></strong>'),array('<option selected="selected">- *','*</option>'),str_replace("\n",'',$firstlevel));
}else{
$firstleveltemp = str_replace(array('<a href="index.php"><strong>','</strong></a>'),array('<option>- ','</option>'),str_replace("\n",'',$firstlevel));
}
$patterns = "/\<\/option\>(.)*/";
$firstleveltemp = preg_replace($patterns, '</option>', $firstleveltemp);
$navArr[] = $firstleveltemp;
$pq2 = phpQuery::newDocument($firstlevel);
$ul2 = $pq2['ul.subnav'];
foreach($ul2['> li'] as $li2) {
$secondlevel = pq($li2)->html();
$secondlevel = str_replace("\n",'',$secondlevel);
$secondlevel = str_replace(array('<a title="','" href="','">','</a>'),array('<option title="','" value="','">- - ','</option>'),$secondlevel);
$secondlevel = str_replace(array('<a href="','" title="','">- -','</a>'),array('<option value="','" title="','">- - ','</option>'),$secondlevel);
$secondlevel = str_replace(array('<span>','</span>'),array('<option selected="selected">- - *','*</option>'),$secondlevel);
//Zend_Debug::dump($secondlevel);
$navArr[] = $secondlevel ;
}
}
}
$output = '<select id="nav" onchange="window.location = this.options[this.selectedIndex].value">';
$output .= str_replace(array('<div class="leftNavSectionHeader"><a href="','">','</a></div>'),array('<option value="','" >','</option>'),$navHeaderstr);
foreach($navArr as $val){
$output .= $val;
}
$output .= '</select>';
return $output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment