PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/include/cssjs.php

https://gitlab.com/protoneutron/xbtbb3cker
PHP | 196 lines | 157 code | 28 blank | 11 comment | 33 complexity | 4477780803ab1739d970b32a335ad633 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * @package xbtBB3cker
  5. * @copyright (c) 2015 PPK
  6. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
  7. *
  8. */
  9. error_reporting(0);
  10. @ini_set('register_globals', 0);
  11. @ini_set('magic_quotes_runtime', 0);
  12. @ini_set('magic_quotes_sybase', 0);
  13. function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get') ? date_default_timezone_set(@date_default_timezone_get()) : '';
  14. define('IN_PHPBB', true);
  15. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../../../../';
  16. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  17. require($phpbb_root_path . 'config.'.$phpEx);
  18. if (!defined('PHPBB_ENVIRONMENT'))
  19. {
  20. @define('PHPBB_ENVIRONMENT', 'production');
  21. }
  22. unset($dbpasswd);
  23. $css_set=isset($_GET['css_set']) ? intval($_GET['css_set']) : 0;
  24. $js_set=isset($_GET['js_set']) ? intval($_GET['js_set']) : 0;
  25. $no_cache=isset($_GET['no_cache']) && $_GET['no_cache'] ? true : false;
  26. $type=isset($_GET['type']) ? $_GET['type'] : '';
  27. $ppkbb3cker_addons="{$phpbb_root_path}ext/ppk/xbtbb3cker/";
  28. $data['css'][0]=array(
  29. $ppkbb3cker_addons.'css/ppkbb3cker.css',
  30. );
  31. $data['css'][1]=array(
  32. $ppkbb3cker_addons.'css/ppkbb3cker.css',
  33. $ppkbb3cker_addons.'css/admin.css',
  34. );
  35. $data['js'][0]=array(
  36. $ppkbb3cker_addons.'js/ppkbb3cker.js',
  37. );
  38. $data['js'][1]=array(
  39. $ppkbb3cker_addons.'js/ppkbb3cker.js',
  40. );
  41. if(!in_array($type, array('css', 'js')) || ($css_set && !isset($data[$type][$css_set])) || ($js_set && !isset($data[$type][$js_set])))
  42. {
  43. exit();
  44. }
  45. $addit=isset($_GET['addit']) ? $_GET['addit'] : '';
  46. if($addit)
  47. {
  48. $addit=explode('|', $addit);
  49. if(count($addit))
  50. {
  51. foreach($addit as $cssjs)
  52. {
  53. $cssjs=explode(',', $cssjs);
  54. if(isset($cssjs[0]))
  55. {
  56. if(count($cssjs)==1)
  57. {
  58. isset($addit_cssjs[$type][$cssjs[0]]) ? $data[$type][0]=array_merge($data[$type][0], $addit_cssjs[$type][$cssjs[0]]) : '';
  59. }
  60. else
  61. {
  62. foreach($cssjs as $k=>$v)
  63. {
  64. $k && isset($addit_cssjs[$type][$cssjs[0]][$v]) ? $data[$type][0]=array_merge($data[$type][0], array($addit_cssjs[$type][$cssjs[0]][$v])) : '';
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }
  71. echo header("Content-Type: ".($type=='css' ? "text/{$type}" : 'application/x-javascript')."; charset=UTF-8");
  72. echo get_tracker_cssjs($data[$type][$type=='css' ? $css_set : $js_set], $type, $no_cache);
  73. ################################################################################
  74. function get_tracker_cssjs($flist, $type, $no_cache=false)
  75. {
  76. global $phpbb_root_path, $phpEx;
  77. if(is_array($flist) && count($flist) && in_array($type, array('css', 'js')))
  78. {
  79. $md5_flist=md5(implode('|', $flist));
  80. $cssjs_file="{$phpbb_root_path}cache/".PHPBB_ENVIRONMENT."/data_ppkbb3cker_{$type}_{$md5_flist}.{$phpEx}";
  81. if(!@file_exists($cssjs_file) || !$no_cache)
  82. {
  83. return write_tracker_cssjs($cssjs_file, $flist, $type, $no_cache);
  84. }
  85. else
  86. {
  87. $last_modified=@filemtime($cssjs_file);
  88. if($last_modified)
  89. {
  90. //$etag=dechex(@fileinode($cssjs_file)).'-'.dechex(@filesize($cssjs_file)).'-'.dechex($last_modified);
  91. $last_modified=gmdate('D, d M Y H:i:s', $last_modified).' GMT';
  92. if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
  93. {
  94. $if_modified_since=preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
  95. if($if_modified_since==$last_modified)
  96. {
  97. header('HTTP/1.0 304 Not Modified');
  98. header('Cache-Control: max-age=86400, must-revalidate');
  99. exit;
  100. }
  101. }
  102. header('Last-Modified: '.$last_modified);
  103. header('Cache-Control: max-age=86400, must-revalidate');
  104. }
  105. $cssjs=@file($cssjs_file);
  106. if(count($cssjs) > 2)
  107. {
  108. unset($cssjs[0]);
  109. }
  110. return implode('', $cssjs);
  111. }
  112. }
  113. return '';
  114. }
  115. function write_tracker_cssjs($cssjs_file, $flist, $type, $no_cache=false)
  116. {
  117. global $phpbb_root_path, $phpEx;
  118. if($cssjs_file)
  119. {
  120. $cssjs_text='';
  121. foreach($flist as $fname)
  122. {
  123. if(@file_exists($fname))
  124. {
  125. $cssjs=@file($fname);
  126. $cssjs ? $cssjs_text.=implode('', $cssjs)."\n" : '';
  127. }
  128. }
  129. if(is_writable($phpbb_root_path.'cache/'.PHPBB_ENVIRONMENT.'/') && !$no_cache)
  130. {
  131. $fo=@fopen($cssjs_file, 'wb');
  132. if($fo)
  133. {
  134. @flock($fo, LOCK_EX);
  135. @fwrite($fo, "<?php if (!defined('IN_PHPBB')) exit;?>\n{$cssjs_text}\n");
  136. //@fflush($fo);
  137. @flock($fo, LOCK_UN);
  138. @fclose($fo);
  139. if(!function_exists('phpbb_chmod'))
  140. {
  141. include("{$phpbb_root_path}ext/ppk/xbtbb3cker/include/file_functions.{$phpEx}");
  142. }
  143. phpbb_chmod($cssjs_file, CHMOD_READ | CHMOD_WRITE);
  144. }
  145. $last_modified=@filemtime($cssjs_file);
  146. if($last_modified && !$no_cache)
  147. {
  148. //$etag=dechex(@fileinode($cssjs_file)).'-'.dechex(@filesize($cssjs_file)).'-'.dechex($last_modified);
  149. $last_modified=gmdate('D, d M Y H:i:s', $last_modified).' GMT';
  150. if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
  151. {
  152. $if_modified_since=preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
  153. if($if_modified_since==$last_modified)
  154. {
  155. header('HTTP/1.0 304 Not Modified');
  156. header('Cache-Control: max-age=86400, must-revalidate');
  157. exit;
  158. }
  159. }
  160. header('Last-Modified: '.$last_modified);
  161. header('Cache-Control: max-age=86400, must-revalidate');
  162. }
  163. }
  164. return $cssjs_text;
  165. }
  166. return '';
  167. }
  168. ?>