PageRenderTime 63ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/www/plugins/system/nonumberelements/helper.php

https://github.com/amet17/webstar
PHP | 281 lines | 235 code | 28 blank | 18 comment | 31 complexity | ad22cf1914d4163a8052ab02fd00bfe3 MD5 | raw file
  1. <?php
  2. /**
  3. * Plugin Helper File
  4. *
  5. * @package NoNumber! Elements
  6. * @version 2.9.1
  7. *
  8. * @author Peter van Westen <peter@nonumber.nl>
  9. * @link http://www.nonumber.nl
  10. * @copyright Copyright © 2011 NoNumber! All Rights Reserved
  11. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
  12. */
  13. // No direct access
  14. defined( '_JEXEC' ) or die();
  15. /**
  16. * ...
  17. */
  18. class plgSystemNoNumberElementsHelper
  19. {
  20. function __construct()
  21. {
  22. $mainframe =& JFactory::getApplication();
  23. $url = JRequest::getVar( 'url' );
  24. $options = JRequest::getVar( 'url_options', array(), 'post', 'array' );
  25. $func = new plgSystemNoNumberElementsHelperFunctions;
  26. if ( $url ) {
  27. echo $func->getByUrl( $url, $options );
  28. exit();
  29. }
  30. $file = JRequest::getVar( 'file' );
  31. // only allow files that have .inc.php in the file name
  32. if ( !$file || ( strpos( $file, '.inc.php' ) === false ) ) {
  33. echo JText::_( 'Access Denied' );
  34. exit();
  35. }
  36. $folder = JRequest::getVar( 'folder' );
  37. jimport( 'joomla.filesystem.file' );
  38. if ( $mainframe->isSite() && !JRequest::getCmd( 'usetemplate' ) ) {
  39. $mainframe->setTemplate( 'system' );
  40. }
  41. $_REQUEST['tmpl'] = 'component';
  42. JRequest::setVar( 'option', '1' );
  43. $mainframe->set( '_messageQueue', '' );
  44. $path = JPATH_SITE;
  45. if ( $folder ) {
  46. $path .= DS.implode( DS, explode( '.', $folder ) );
  47. }
  48. $file = $path.DS.$file;
  49. $html = '';
  50. if ( JFile::exists( $file ) ) {
  51. ob_start();
  52. include $file;
  53. $html = ob_get_contents();
  54. ob_end_clean();
  55. }
  56. $document =& JFactory::getDocument();
  57. $document->setBuffer( $html, 'component' );
  58. $document->addStyleSheet( JURI::root( true ).'/templates/system/css/system.css' );
  59. $document->addStyleSheet( JURI::root( true ).'/plugins/system/nonumberelements/css/default.css' );
  60. $document->addScript( JURI::root(true).'/includes/js/joomla.javascript.js' );
  61. $mainframe->render();
  62. echo JResponse::toString( $mainframe->getCfg( 'gzip' ) );
  63. exit();
  64. }
  65. }
  66. class plgSystemNoNumberElementsHelperFunctions
  67. {
  68. function getByUrl( $url, $options = array() ) {
  69. if ( substr( $url, 0, 4 ) != 'http' ) {
  70. $url = 'http://'.$url;
  71. }
  72. $html = '';
  73. if ( function_exists( 'curl_init' ) ) {
  74. $html = $this->curl( $url, $options );
  75. } else {
  76. $file = @fopen( $url, 'r' );
  77. if ( $file ) {
  78. $html = array();
  79. while ( !feof( $file ) ) {
  80. $html[] = fgets( $file, 1024 );
  81. }
  82. $html = implode( '', $html );
  83. }
  84. }
  85. return $html;
  86. }
  87. function curl( $url, $options = array() )
  88. {
  89. $ch = curl_init( $url );
  90. $ch_options = array (
  91. CURLOPT_URL => $url,
  92. CURLOPT_HEADER => false,
  93. CURLOPT_RETURNTRANSFER => true,
  94. CURLOPT_TIMEOUT => 3,
  95. CURLOPT_USERAGENT => 'some crazy browser'
  96. );
  97. if ( !empty( $options ) ) {
  98. $curl_opts = $this->getCurlOpts();
  99. foreach ( $options as $key => $option ) {
  100. if ( is_numeric( $key ) ) {
  101. $ch_options[$key] = $option;
  102. } else if ( isset( $curl_opts[$key] ) ) {
  103. $ch_options[$curl_opts[$key]] = $option;
  104. }
  105. }
  106. }
  107. curl_setopt_array( $ch, $ch_options );
  108. //follow on location problems
  109. if ( ini_get( 'open_basedir' ) == '' && ini_get( 'safe_mode' ) != 'On' ) {
  110. curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
  111. $html = curl_exec( $ch );
  112. }else{
  113. $html = $this->curl_redir_exec( $ch );
  114. }
  115. curl_close( $ch );
  116. return $html;
  117. }
  118. function curl_redir_exec( $ch )
  119. {
  120. static $curl_loops = 0;
  121. static $curl_max_loops = 20;
  122. if ( $curl_loops++ >= $curl_max_loops ) {
  123. $curl_loops = 0;
  124. return false;
  125. }
  126. curl_setopt( $ch, CURLOPT_HEADER, true );
  127. $data = curl_exec( $ch );
  128. list( $header, $data ) = explode( "\n\n", str_replace( "\r", '', $data ), 2 );
  129. $http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
  130. if ( $http_code == 301 || $http_code == 302 ) {
  131. $matches = array();
  132. preg_match( '/Location:(.*?)\n/', $header, $matches );
  133. $url = @parse_url( trim( array_pop( $matches ) ) );
  134. if (!$url) {
  135. //couldn't process the url to redirect to
  136. $curl_loops = 0;
  137. return $data;
  138. }
  139. $last_url = parse_url( curl_getinfo( $ch, CURLINFO_EFFECTIVE_URL ) );
  140. if ( !$url['scheme'] ) {
  141. $url['scheme'] = $last_url['scheme'];
  142. }
  143. if ( !$url['host'] ) {
  144. $url['host'] = $last_url['host'];
  145. }
  146. if ( !$url['path'] ) {
  147. $url['path'] = $last_url['path'];
  148. }
  149. $new_url = $url['scheme'].'://'.$url['host'].$url['path'].( $url['query'] ? '?'.$url['query'] : '' );
  150. curl_setopt( $ch, CURLOPT_URL, $new_url );
  151. return $this->curl_redir_exec( $ch );
  152. } else {
  153. $curl_loops = 0;
  154. return $data;
  155. }
  156. }
  157. function getCurlOpts() {
  158. return array(
  159. 'CURLOPT_AUTOREFERER' => 58,
  160. 'CURLOPT_BINARYTRANSFER' => 19914,
  161. 'CURLOPT_BUFFERSIZE' => 98,
  162. 'CURLOPT_CAINFO' => 10065,
  163. 'CURLOPT_CAPATH' => 10097,
  164. 'CURLOPT_CLOSEPOLICY' => 72,
  165. 'CURLOPT_CONNECTTIMEOUT' => 78,
  166. 'CURLOPT_CONNECTTIMEOUT_MS' => 156,
  167. 'CURLOPT_COOKIE' => 10022,
  168. 'CURLOPT_COOKIEFILE' => 10031,
  169. 'CURLOPT_COOKIEJAR' => 10082,
  170. 'CURLOPT_COOKIESESSION' => 96,
  171. 'CURLOPT_CRLF' => 27,
  172. 'CURLOPT_CUSTOMREQUEST' => 10036,
  173. 'CURLOPT_DNS_CACHE_TIMEOUT' => 92,
  174. 'CURLOPT_EGDSOCKET' => 10077,
  175. 'CURLOPT_ENCODING' => 10102,
  176. 'CURLOPT_FAILONERROR' => 45,
  177. 'CURLOPT_FILE' => 10001,
  178. 'CURLOPT_FILETIME' => 69,
  179. 'CURLOPT_FOLLOWLOCATION' => 52,
  180. 'CURLOPT_FORBID_REUSE' => 75,
  181. 'CURLOPT_FRESH_CONNECT' => 74,
  182. 'CURLOPT_FTPAPPEND' => 50,
  183. 'CURLOPT_FTPLISTONLY' => 48,
  184. 'CURLOPT_FTPPORT' => 10017,
  185. 'CURLOPT_FTP_USE_EPRT' => 106,
  186. 'CURLOPT_FTP_USE_EPSV' => 85,
  187. 'CURLOPT_HEADER' => 42,
  188. 'CURLOPT_HEADERFUNCTION' => 20079,
  189. 'CURLOPT_HTTP200ALIASES' => 10104,
  190. 'CURLOPT_HTTPGET' => 80,
  191. 'CURLOPT_HTTPHEADER' => 10023,
  192. 'CURLOPT_HTTPPROXYTUNNEL' => 61,
  193. 'CURLOPT_HTTP_VERSION' => 84,
  194. 'CURLOPT_INFILE' => 10009,
  195. 'CURLOPT_INFILESIZE' => 14,
  196. 'CURLOPT_INTERFACE' => 10062,
  197. 'CURLOPT_KRB4LEVEL' => 10063,
  198. 'CURLOPT_LOW_SPEED_LIMIT' => 19,
  199. 'CURLOPT_LOW_SPEED_TIME' => 20,
  200. 'CURLOPT_MAXCONNECTS' => 71,
  201. 'CURLOPT_MAXREDIRS' => 68,
  202. 'CURLOPT_NETRC' => 51,
  203. 'CURLOPT_NOBODY' => 44,
  204. 'CURLOPT_NOPROGRESS' => 43,
  205. 'CURLOPT_NOSIGNAL' => 99,
  206. 'CURLOPT_PORT' => 3,
  207. 'CURLOPT_POST' => 47,
  208. 'CURLOPT_POSTFIELDS' => 10015,
  209. 'CURLOPT_POSTQUOTE' => 10039,
  210. 'CURLOPT_PROXY' => 10004,
  211. 'CURLOPT_PROXYPORT' => 59,
  212. 'CURLOPT_PROXYTYPE' => 101,
  213. 'CURLOPT_PROXYUSERPWD' => 10006,
  214. 'CURLOPT_PUT' => 54,
  215. 'CURLOPT_QUOTE' => 10028,
  216. 'CURLOPT_RANDOM_FILE' => 10076,
  217. 'CURLOPT_RANGE' => 10007,
  218. 'CURLOPT_READDATA' => 10009,
  219. 'CURLOPT_READFUNCTION' => 20012,
  220. 'CURLOPT_REFERER' => 10016,
  221. 'CURLOPT_RESUME_FROM' => 21,
  222. 'CURLOPT_RETURNTRANSFER' => 19913,
  223. 'CURLOPT_SSLCERT' => 10025,
  224. 'CURLOPT_SSLCERTPASSWD' => 10026,
  225. 'CURLOPT_SSLCERTTYPE' => 10086,
  226. 'CURLOPT_SSLENGINE' => 10089,
  227. 'CURLOPT_SSLENGINE_DEFAULT' => 90,
  228. 'CURLOPT_SSLKEY' => 10087,
  229. 'CURLOPT_SSLKEYPASSWD' => 10026,
  230. 'CURLOPT_SSLKEYTYPE' => 10088,
  231. 'CURLOPT_SSLVERSION' => 32,
  232. 'CURLOPT_SSL_CIPHER_LIST' => 10083,
  233. 'CURLOPT_SSL_VERIFYHOST' => 81,
  234. 'CURLOPT_SSL_VERIFYPEER' => 64,
  235. 'CURLOPT_STDERR' => 10037,
  236. 'CURLOPT_TCP_NODELAY' => 121,
  237. 'CURLOPT_TIMECONDITION' => 33,
  238. 'CURLOPT_TIMEOUT' => 13,
  239. 'CURLOPT_TIMEOUT_MS' => 155,
  240. 'CURLOPT_TIMEVALUE' => 34,
  241. 'CURLOPT_TRANSFERTEXT' => 53,
  242. 'CURLOPT_UNRESTRICTED_AUTH' => 105,
  243. 'CURLOPT_UPLOAD' => 46,
  244. 'CURLOPT_URL' => 10002,
  245. 'CURLOPT_USERAGENT' => 10018,
  246. 'CURLOPT_USERPWD' => 10005,
  247. 'CURLOPT_VERBOSE' => 41,
  248. 'CURLOPT_WRITEFUNCTION' => 20011,
  249. 'CURLOPT_WRITEHEADER' => 10029,
  250. 'CURLOPT_DNS_USE_GLOBAL_CACHE' => 91,
  251. );
  252. }
  253. }