open-social-media-toolkit /core/classes/pageMobile.class.php

Language PHP Lines 333
MD5 Hash 52aa85ce93062bea9ecf850c0c6c0ace Estimated Cost $6,912 (why?)
Repository git://github.com/newscloud/open-social-media-toolkit.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php

class MobilePage extends XHTMLpage {
	var $header = '';
	var $sidebar = '';
	var $content = '';
	var $footer = '';
	var $agent;
	var $googleAnalytics;
	var $keywordDescription;
	var $keywordList;
	var $isIE=false;
	
	function MobilePage($title='NewsCloud.com')
	{			
		// Construct the parent
		parent::XHTMLPage($title);	
		// main layout file
		$this->agent=$_SERVER['HTTP_USER_AGENT'];
		$this->isIE=(eregi("msie",$this->agent) && !eregi("opera",$this->agent));
		$this->googleAnalytics='<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));</script><script type="text/javascript"> var pageTracker = _gat._getTracker("'.$init[analytics].'"); pageTracker._initData(); pageTracker._trackPageview(); </script>';
		$this->keywordDescription='';
		$this->keywordList='';		
	}
	
	function display()
	{
		$this->add( $this->_genMain() );
		echo $this->getPage();
	}
	
	function addToHeader($string)
	{
		$this->header .= $string;
	}
	function addToContent($string)
	{
		$this->content .= $string;
	}
	function addToFooter($string)
	{
		$this->footer .= $string;
	}
		
	function _genMain()
	{
		$ret = '<div id="main"><!-- main -->';
		$ret .= $this->_genHeader();
		$ret .= $this->_genContent();
		$ret .= $this->_genFooter();		
		$ret .= '<!-- /main --></div>';
		return $ret;
	}

	function _genHeader()
	{
		return '<div id="header"><!-- header -->' . $this->header . '</div><!-- /header -->';
	}

	function _genContent()
	{
		return '<div id="content"><!-- content -->' . $this->content . '</div><!-- /content -->';
	}

	function _genFooter()
	{
		return '<div id="footer"><!-- footer -->'.$this->footer.'</div><!-- /footer -->';
	}
}

class XHTMLpage {
	
	var $title = '';
	var $description = '';
	var $siteTagline='Must read stories from around the Web';
	var $html = '';
	
	var $doctype_tag = '';
	var $onload = '';
	
	var $keywords    = array();
	var $stylesheets = array();
	var $scripts     = array();
	var $miscHead	 = array();
	var $rssfeeds	 = array();
	var $atomfeeds	 = array();
		
	var $page_time_start;
	
	function XHTMLPage($title = '')
	{
		$this->page_time_start = microtime();
		
		$this->setTitle($title);
		$this->doctype_tag = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
	}
	
	function getPage()
	{
		$page = $this->doctype_tag;
		$page .= '<html>';
		$page .= $this->_genHead();
		$page .= $this->_genBody();		
		return $page . '</html><!-- Page built in ' . $this->getCurrentExecTime() . ' seconds. --> ';
	}
	
	function display()
	{
		echo $this->getPage();
	}
	
	function add($HTML)
	{
		$this->html .= $HTML;
	}
	
	function addStyle($stylesheet_path)
	{
		$this->stylesheets[] = trim($stylesheet_path);
	}
	
	function addHead($miscStr)
	{
		$this->miscHead[] = trim($miscStr);
	}
	
	function addScript($script_path)
	{
		$this->scripts[] = trim($script_path);		
	}
	
	function pkgScripts($page='default',$scripts) {		
		$this->scripts[]=URL_CACHE."&cf=".$page."_".$this->fetchPkgVersion($page,$scripts,'js',true).".js";
	}

	function pkgStyles($page='default',$sheets) {
		$this->stylesheets[]=URL_CACHE."&cf=".$page."_".$this->fetchPkgVersion($page,$sheets,'css',false).".css";
	}

	function fetchPkgVersion($page,$files,$mode='js',$jsCompress=false) {
	   $sDocRoot = $_SERVER['DOCUMENT_ROOT'];
	   define('JSMIN_COMMENTS', ''); // any comments to append to the top of the compressed output
	   define('JSMIN_AS_LIB', true); 
	  // get file last modified dates
	  $aLastModifieds = array();
	  foreach ($files as $sFile) {
	     $aLastModifieds[] = filemtime("$sDocRoot/$sFile");
	  }
	  // sort dates, newest first
	  rsort($aLastModifieds);
 	 $iETag=$aLastModifieds[0];	
       // create a directory for storing current and archive versions
      if (!is_dir("$sDocRoot/".ARCHIVE_FOLDER)) {
         mkdir("$sDocRoot/".ARCHIVE_FOLDER);
      }
      
      $sMergedFilename = "$sDocRoot/".ARCHIVE_FOLDER."/".$page."_".$iETag.".".$mode;
      // if it does not exist, we need to create a new merged package
      if (!file_exists($sMergedFilename)) {
         // get and merge code
         $sCode = '';
         $aLastModifieds = array();
         foreach ($files as $sFile) {
            $aLastModifieds[] = filemtime("$sDocRoot/$sFile");
            $sCode .= file_get_contents("$sDocRoot/$sFile");
         }
         // sort dates, newest first
         rsort($aLastModifieds);
         // reset iETag incase of late breaking file update
	 	 $iETag=$aLastModifieds[0];         
	      $sMergedFilename = "$sDocRoot/".ARCHIVE_FOLDER."/".$page."_".$iETag.".".$mode;
           $this->pkgWrite($sMergedFilename, $sCode);
           if ($jsCompress) {
			  require_once("$sDocRoot/".JSMIN_PATH."/jsmin.php");
              if (JSMIN_COMMENTS != '') {
                 $jsMin = new JSMin(file_get_contents($sMergedFilename), false, JSMIN_COMMENTS);
              } else {
                 $jsMin = new JSMin(file_get_contents($sMergedFilename), false);
              }
              $sCode = $jsMin->minify();              
              $this->pkgWrite($sMergedFilename, $sCode);
           }
      }
	  // return latest timestamp
	 return $iETag;
	}	
	
   function pkgWrite($sFilename, $sCode) {
      $oFile = fopen($sFilename, 'w');
      if (flock($oFile, LOCK_EX)) {
         fwrite($oFile, $sCode);
         flock($oFile, LOCK_UN);
      }
      fclose($oFile);
   }

	function addRSSFeed($rssfeed_path)
	{
		$this->rssfeeds[] = trim($rssfeed_path);
	}

	function addATOMFeed($atomfeed_path)
	{
		$this->atomfeeds[] = trim($atomfeed_path);
	}
	
	function setTitle($title='NewsCloud.com')
	{
		if ($title=='NewsCloud.com') {
			$title.=' - '.$this->siteTagline;
		}
		$this->title = $title;
	}
	
	function setDescription($description)
	{
		$this->description = strip_tags($description);
	}
	
	function setOnload($string)
	{
		$this->onload = $string;
	}

	function addKeywords($keywords)
	/**
	 * Takes either an array or a comma/whitespace seperated list of keywords
	 * and appends them to the local keywords array property
	 */
	{
		if ( is_array($keywords) ) {
			$new_array = $keywords;
		} else {
			$new_array = preg_split("([[:space:]]|,|;)", $keywords, -1, PREG_SPLIT_NO_EMPTY);
		}
		$this->keywords = array_unique(array_merge( $new_array,$this->keywords));
	}
	
	function _genHead()
	{
		$head = '<head><meta name="viewport" content="width=320"><meta HTTP-EQUIV="Refresh" CONTENT="1800"><meta HTTP-EQUIV="Expires" CONTENT="now"><meta http-equiv="Content-type" content="text/html;charset=UTF-8" />';
		$head .= $this->_genTitle();
		$head .= $this->_genDescription();
		$head .= $this->_genKeywords();
		$head .= $this->_genStylesheets();
		$head .= $this->_genFeeds();
		$head .= $this->_genMiscHead();
		$head .= $this->_genScripts();		
		return $head . '</head>';
	}
	
	function _genBody()
	{
		$body = '<body onload="' . $this->onload . '">';
		if (!strpos($_SERVER['HTTP_HOST'],'local'))
			$body.=$this->googleAnalytics;
		$body .= $this->html;
		return $body.'</body>';
	}
	
	function _genTitle()
	{
		$title = '<title>' . $this->title . '</title>';
		return $title;
	}
	
	function _genDescription()
	{
		return '<meta name="description" content="' . trim($this->description) . '" />';
	}
	
	function _genKeywords()
	{
		$words = '';
		foreach ($this->keywords as $key => $val) {
			$words .= $val . ", ";
		}
		$tag = '<meta name="keywords" content="' . substr($words, 0, -2) . '" />';
		return $tag;
	}

	function _genStylesheets()
	{
		$ret = '';
		foreach (array_unique($this->stylesheets) as $key => $val) {
			$ret .= '<link rel="stylesheet" href="' . $val . '" type="text/css" charset="utf-8" />';
		}
		$ret.='<link rel="Shortcut Icon" href="http://www.newscloud.com/images/favicon.ico" type="image/x-icon" />';
		return $ret;
	}

	function _genMiscHead()
	{
		$ret = '';
		foreach (array_unique($this->miscHead) as $key => $val) {
			$ret .= $val;
		}
		return $ret;
	}
	
	function _genFeeds() {
		$ret = '';
		foreach (array_unique($this->rssfeeds) as $key => $val) {
			$ret .= '<link rel="alternate" title="RSS" href="' . $val . '" type="application/rss+xml">';
		}
		foreach (array_unique($this->atomfeeds) as $key => $val) {
			$ret .= '<link rel="alternate" title="ATOM" href="' . $val . '" type="application/atom+xml">';
		}
		return $ret;		
	}
	
	function _genScripts()
	{
		$ret = '';
		foreach (array_unique($this->scripts) as $key => $val) {
			$ret .= '<script src="' . $val . '" type="text/javascript" language="javascript" charset="utf-8"></script>';			
		}

		return $ret;
	}
	
	function getCurrentExecTime()
	{
	    $page_time_end = microtime();
		return $page_time_end - $this->page_time_start;
	}
	
	function isRobot() {
		return (eregi("googlebot",$this->agent) || eregi("yahooseeker",$this->agent) || eregi("msnbot",$this->agent));		
	}
}
?>
Back to Top