PageRenderTime 64ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 1ms

/n3u.php

https://github.com/n3u/n3u-Niche-Store
PHP | 1816 lines | 1518 code | 4 blank | 294 comment | 498 complexity | 50adf1b4605091b26fdfc9a209c1bb9e MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. n3u Niche Store - Custom Niche PHP Script
  4. Copyright (C) 2012-2014 n3u.com
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>
  15. **/
  16. if(!defined('n3u')){die('Direct access is not permitted.');} // Is n3u defined?
  17. // Get required files and execute required functions in order
  18. require_once('Prosperent_Api.php'); // The Prosperent Api library
  19. $n3u_ServerVars = $_SERVER;
  20. n3u_Input(); // Gets and filters input data
  21. n3u_Config(); // Gets and filters config data
  22. $n3u_PostVars = $_POST;
  23. n3u_Defaults(); // Checks that defaults are set, if not sets them.
  24. //
  25. session_start(); // Check Sessions
  26. if(isset($_SESSION['username']) && isset($_SESSION['password'])){
  27. if($_SESSION['username'] == md5($n3u_configVars['username']) && $_SESSION['password'] == md5($n3u_configVars['password'])){
  28. define('admin',TRUE);
  29. }else{
  30. session_start();
  31. $_SESSION = array();
  32. session_destroy();
  33. header('Location: index.php?x=login');
  34. exit;
  35. }
  36. }
  37. require_once($n3u_configVars['language_dir'] . 'language.php'); // Get the Language
  38. n3u_ErrorChecker(); // Check for errors
  39. n3u_CheckCache(); // Check for cache cleanup routines
  40. n3u_BlockConfig();
  41. /**
  42. n3u_AdditionalStores() looks for additional stores pointed to the same
  43. installation of n3u Niche Store. This is done by looking for domain
  44. configuration files.
  45. **/
  46. function n3u_AdditionalStores($page_limit = NULL){ // Returns array of Custom pages
  47. $n3u_AdditionalStores = array();
  48. $i = 1;
  49. foreach(glob("*_config.php") as $n3u_additional_store){
  50. if(preg_match('/_block/i', $n3u_additional_store) != TRUE){
  51. $n3u_additional_storename = str_replace('_config.php','',$n3u_additional_store);
  52. $n3u_AdditionalStores[$i]['name'] = $n3u_additional_storename;
  53. $n3u_AdditionalStores[$i]['path'] = $n3u_additional_store;
  54. $n3u_AdditionalStores[$i]['url'] = 'http://'. $n3u_additional_storename;
  55. if($page_limit == NULL){ // limits pages returned if specified
  56. $i++;
  57. }elseif($page_limit > $i){
  58. $i++;
  59. }
  60. }
  61. } // finds all custom pages in templates custom directory, builds array
  62. unset($page_limit,$n3u_additional_store,$n3u_additional_storename,$i);
  63. return $n3u_AdditionalStores;
  64. }
  65. function n3u_AutoLinker($text=NULL){
  66. global $n3u_configVars;
  67. $matches=NULL;
  68. preg_match_all("/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/",$text,$matches);
  69. if(isset($matches) && $matches != NULL){
  70. foreach($matches[0] as $match){
  71. // preprint_r($match);
  72. // $text=str_replace($match,'<a href="' . $match . '" target="_blank" title="External Link"> ' . ($match) . '</a>',$text);
  73. if($n3u_configVars['CleanUrls'] == TRUE){
  74. $text=str_replace($match,'<a class="ExternalLink" href="go/'.base64_encode(urlencode($match)) . '.htm" rel="nofollow" target="_blank" title="External Link"> ' . ($match) . '</a>',$text);
  75. }else{
  76. $text=str_replace($match,'<a class="ExternalLink" href="' . $n3u_configVars['self'] . '?x=go&amp;url=' . base64_encode(urlencode($match)) . '" rel="nofollow" target="_blank" title="External Link"> ' . ($match) . '</a>',$text);
  77. }
  78. }
  79. return $text;
  80. }
  81. }
  82. /**
  83. n3u_Block() is used to restrive individual blocks. If $block_area is
  84. specified, n3u_Block() will only look in that position. If TRUE is
  85. passed as a 2nd option, A list will be returned instead.
  86. **/
  87. function n3u_BlockSort($a,$b){
  88. return $a['SortOrder'] - $b['SortOrder'];
  89. }
  90. function n3u_Block($block_area='*',$list=FALSE){
  91. global $n3u_blockData;
  92. global $n3u_configVars;
  93. global $n3u_inputVars;
  94. global $n3u_lang;
  95. global $n3u_results;
  96. global $n3u_PostVars;
  97. global $n3u_ServerVars;
  98. global $prosperentApi;
  99. // preprint_r($n3u_blockData);
  100. if($list == FALSE){
  101. $Blocks = array();
  102. foreach($n3u_blockData as $BlockNameKey => $BlockArrayValue){
  103. // preprint_r($BlockArrayValue);
  104. $n3u_position = $BlockArrayValue['Position'];
  105. if($n3u_position == $block_area){ // If correct Position
  106. $Blocks[$BlockNameKey] = array('Path' => $BlockArrayValue['Path'],'Position' => $BlockArrayValue['Position'], 'SortOrder' => $BlockArrayValue['SortOrder']);
  107. }
  108. unset($n3u_position);
  109. }
  110. $reverse_blockData = $Blocks;
  111. krsort($reverse_blockData); // Reverse Order by keyname so that usort sorts by correct order
  112. usort($reverse_blockData, 'n3u_BlockSort'); // Call n3u_BlockSort Function to sort by SortOrder
  113. foreach($reverse_blockData as $Block){
  114. $n3u_position = $Block['Position'];
  115. require_once $Block['Path'];
  116. unset($n3u_position);
  117. }
  118. // preprint_r($reverse_blockData);
  119. }elseif($list == TRUE){
  120. $n3u_BlockList = array();
  121. $block_name = '*';
  122. $block_filename = 'block_*.php';
  123. foreach($n3u_blockData as $BlockNameKey => $BlockArrayValue){
  124. list($block_dir,$BlockArrayValue['Position'],$BlockNameKey,$block_filename) = explode('/', $filepath);
  125. $n3u_BlockList[$BlockNameKey]['filename'] = $BlockNameKey;
  126. $n3u_BlockList[$BlockNameKey]['Path'] = $BlockArrayValue['Path'];
  127. $n3u_BlockList[$BlockNameKey]['Position'] = $BlockArrayValue['Position'];
  128. if(is_numeric($block_name[0])){
  129. $n3u_BlockList[$BlockNameKey]['SortOrder'] = $block_name[0];
  130. }else{
  131. $n3u_BlockList[$BlockNameKey]['SortOrder'] = NULL;
  132. }
  133. }
  134. unset($block_area,$block_dir,$block_filename,$block_name);
  135. // preprint_r($blocklist);
  136. return $n3u_BlockList;
  137. }
  138. }
  139. /**
  140. n3u_Block() is used to restrive individual blocks. If $block_area is
  141. specified, n3u_Block() will only look in that position. If TRUE is
  142. passed as a 2nd option, A list will be returned instead.
  143. **/
  144. function n3u_BlockConfig(){
  145. global $n3u_blockData;
  146. global $n3u_configVars;
  147. global $n3u_inputVars;
  148. global $n3u_lang;
  149. global $n3u_results;
  150. global $n3u_PostVars;
  151. global $n3u_ServerVars;
  152. global $prosperentApi;
  153. $url = n3u_HTTP_Host();
  154. // if(file_exists($url['host'].'_config.php')){require_once($url['host'].'_config.php');}
  155. if(file_exists($n3u_configVars['include_dir'] . 'configs/' . $url['host'] . '_block_config.php')){ // Use existing but check for new
  156. require_once($n3u_configVars['include_dir'] . 'configs/' . $url['host'] . '_block_config.php');
  157. foreach($n3u_blockData as $BlockName => $BlockArray){
  158. if(!file_exists($BlockArray['Path'])){ // Check to see if path is no longer valid. If so unset data.
  159. unset($n3u_blockData[$BlockName]);
  160. // preprint_r($BlockArray);
  161. n3u_WriteBlockConfig();
  162. }
  163. }
  164. $folderlist = glob($n3u_configVars['blocks_dir'] . "*",GLOB_ONLYDIR);
  165. foreach($folderlist as $folderpath){
  166. $name = str_replace($n3u_configVars['blocks_dir'],'',$folderpath);
  167. if(!isset($n3u_blockData[$name]) || $n3u_blockData[$name] == NULL){
  168. $n3u_blockData[$name] = array(
  169. 'Path' => $n3u_configVars['blocks_dir'] . $name . '/block_'.strtolower($name).'.php',
  170. 'Position' => '#disabled',
  171. 'SortOrder' => '3',
  172. );
  173. n3u_WriteBlockConfig();
  174. }
  175. }
  176. ksort($n3u_blockData);
  177. // preprint_r($n3u_blockData);
  178. }else{ // Get new Block Data
  179. $n3u_blockData = array();
  180. $folderlist = glob($n3u_configVars['blocks_dir'] . "*",GLOB_ONLYDIR);
  181. foreach($folderlist as $folderpath){
  182. $name = str_replace($n3u_configVars['blocks_dir'],'',$folderpath);
  183. $n3u_blockData[$name] = array(
  184. 'Path' => $n3u_configVars['blocks_dir'] . $name . '/block_'.strtolower($name).'.php',
  185. 'Position' => '#disabled',
  186. 'SortOrder' => '3',
  187. );
  188. }
  189. ksort($n3u_blockData);
  190. }
  191. // preprint_r($n3u_blockData);
  192. // n3u_WriteBlockConfig();
  193. // preprint_r($n3u_BlockListArray);
  194. return $n3u_blockData;
  195. }
  196. function n3u_WriteBlockConfig($domainConfig=NULL){
  197. global $n3u_blockData;
  198. global $n3u_configVars;
  199. global $n3u_inputVars;
  200. global $n3u_lang;
  201. global $n3u_results;
  202. global $n3u_PostVars;
  203. global $n3u_ServerVars;
  204. global $prosperentApi;
  205. $url = n3u_HTTP_Host();
  206. if(!isset($domainConfig) || $domainConfig == NULL){
  207. $domainConfig = $n3u_configVars['include_dir'] . 'configs/' . $url['host'] . '_block_config.php';
  208. }
  209. $configFile = '<?php ' . PHP_EOL
  210. . "\t" . '/**' . PHP_EOL
  211. . n3u_GPL_Credits()
  212. . "\t\t" . 'n3u Niche Store - '.$url['host'].'_block_config.php' . PHP_EOL
  213. . "\t\t\t" . 'This configuration file maintains the data used for blocks.' . PHP_EOL
  214. . "\t\t\t" . 'It\'s best to configure Blocks directly from the Admin Panel' . PHP_EOL
  215. . "\t\t\t" . 'Don\'t use a \' character in any option unless you know how to escape properly.' . PHP_EOL
  216. . "\t\t\t" . 'Again it\'s best to use Admin Panel which is safer.' . PHP_EOL
  217. . "\t" . '**/' . PHP_EOL
  218. . "\t" . 'if(!defined(\'n3u\')){die(\'Direct access is not permitted.\');} // Is n3u defined?' . PHP_EOL
  219. . "\t" . '$n3u_blockData = array( // Visit the Blocks admin section to change settings.' . PHP_EOL;
  220. // $BlockData = n3u_BlockConfig();
  221. // preprint_r($BlockData);
  222. foreach($n3u_blockData as $Blockkey => $Blockvalue){
  223. $configFile .= "\t\t" . var_export($Blockkey,TRUE) . ' => ' . preg_replace(array('\'\s+\'','/\s*(?!<\")\/\*[^\*]+\*\/(?!\")\s*/','(,\),)'),array('','','),'),var_export($Blockvalue,TRUE) . ',') . PHP_EOL;
  224. }
  225. $configFile .= "\t" . '); // n3u Niche Store is brought to you by n3u.com' . PHP_EOL
  226. . '?>';
  227. $fp = fopen($domainConfig, "w");
  228. fwrite($fp, $configFile);
  229. fclose($fp);
  230. unset($configFile,$url);
  231. }
  232. /**
  233. n3u_CacheBegin() is used to start the caching process. If the admin is
  234. logged in, or if caching is disabled, This process does not start. If
  235. caching is enabled appropiate headers are sent to notify the browser to
  236. cache as well.
  237. **/
  238. function n3u_CacheBegin(){
  239. global $n3u_inputVars;
  240. global $n3u_configVars;
  241. global $n3u_cacheFile;
  242. global $n3u_ServerVars;
  243. $url = parse_url($n3u_ServerVars['HTTP_HOST']);
  244. if(!isset($url['host']) || $url['host'] == NULL){
  245. if(isset($url['path']) && $url['path'] != NULL){ // Check to see if host is classified as path
  246. $url['host'] = $url['path'];
  247. }elseif(isset($n3u_ServerVars['HTTP_ZONE_NAME']) && $n3u_ServerVars['HTTP_ZONE_NAME'] != NULL){ // Use HTTP_ZONE)NAME
  248. $url['host'] = $n3u_ServerVars['HTTP_ZONE_NAME'];
  249. }else{ // Use SiteURL
  250. $url['host'] = strtolower(str_replace('http://','',$n3u_configVars['SiteURL']));
  251. }
  252. }
  253. $n3u_cacheFile = $n3u_configVars['cache_dir'] .$url['host']. '/' . $n3u_inputVars['x'] . '_' . (md5(@$n3u_inputVars['m'] . '_' . @$n3u_inputVars['b'] . '_' . @urlencode($n3u_inputVars['q']) . '-' . @$n3u_inputVars['sort'] . '-' . @$n3u_inputVars['p'])) . '.htm';
  254. date_default_timezone_set('GMT'); // Sets the default timezone to use, browser headers require GMT.
  255. // Serve from the cache if it is younger than the current $cachetime
  256. if(defined('admin') || $n3u_configVars['caching'] == FALSE){
  257. // Cache is not generated for admin or if caches are disabled.
  258. }elseif(file_exists($n3u_cacheFile) && time() - $n3u_configVars['lifetime'] < filemtime($n3u_cacheFile)){
  259. // if a fresh file exist and admin is not logged in at this point...
  260. header('Cache-Control: max-age='.$n3u_configVars['lifetime'].', must-revalidate');
  261. header('Expires: ' . date('D, d M Y H:i:s e', filemtime($n3u_cacheFile)+$n3u_configVars['lifetime'])); // Date in the future
  262. header('Last-Modified: ' . date('D, d M Y H:i:s e', filemtime($n3u_cacheFile))); // Cache header only sent if not serving cached copy
  263. header('Pragma: public');
  264. header('X-Powered-By: n3u Niche Store ' . $n3u_configVars['Version']);
  265. include($n3u_cacheFile);
  266. // echo "\t\t" . '<!-- This file was generated on ' . date('F jS,Y \@ g:i:s e', filemtime($n3u_cacheFile)) . ' -->' . PHP_EOL;
  267. exit;
  268. }else{
  269. header('Cache-Control: max-age='.$n3u_configVars['lifetime'].', must-revalidate');
  270. header('Expires: ' . date('D, d M Y H:i:s e', time()+$n3u_configVars['lifetime'])); // Date in the future
  271. header('Last-Modified: ' . date('D, d M Y H:i:s e', time())); // Cache header only sent if not serving cached copy
  272. header('Pragma: public');
  273. header('X-Powered-By: n3u Niche Store ' . $n3u_configVars['Version']);
  274. }
  275. unset($url);
  276. ob_start(); // Start the output buffer. The cache don't exist at this point.
  277. }
  278. /**
  279. n3u_CacheCSS() is used to cache CSS if canching is enabled. If disabled,
  280. or Admin is logged in, each individal style link is returned.
  281. **/
  282. function n3u_CacheCSS(){
  283. global $n3u_configVars;
  284. global $n3u_blockData;
  285. global $n3u_ServerVars;
  286. // Cache the contents to a file
  287. if(defined('admin') || $n3u_configVars['caching'] == FALSE){ // if admin or if caching is disabled
  288. foreach(glob($n3u_configVars['blocks_dir'] . '*/*.css') as $filename){ // get block css files
  289. echo "\t\t" . '<link rel="stylesheet" type="text/css" href="' . $filename . '">' . PHP_EOL;
  290. }
  291. foreach(glob($n3u_configVars['Template_Dir'] . $n3u_configVars['Template_Name'] . '/*.css') as $filename){ // get template css files
  292. echo "\t\t" . '<link rel="stylesheet" type="text/css" href="' . $filename . '">' . PHP_EOL;
  293. }
  294. if((defined('admin') == TRUE) && file_exists($n3u_configVars['Template_Dir'] . 'admin/admin.css')){
  295. echo "\t\t" . '<link rel="stylesheet" type="text/css" href="'.$n3u_configVars['Template_Dir'] . 'admin/admin.css">' . PHP_EOL;
  296. }
  297. if((defined('admin') == TRUE) && file_exists($n3u_configVars['Template_Dir'] . 'admin/style.php')){
  298. echo "\t\t" . '<link rel="stylesheet" type="text/css" href="'.$n3u_configVars['Template_Dir'] . 'admin/style.php">' . PHP_EOL;
  299. }
  300. }else{ // if not admin and caching is enabled and cache is old
  301. $url = parse_url($n3u_ServerVars['HTTP_HOST']);
  302. if(!isset($url['host']) || $url['host'] == NULL){
  303. if(isset($url['path']) && $url['path'] != NULL){ // Check to see if host is classified as path
  304. $url['host'] = $url['path'];
  305. }elseif(isset($n3u_ServerVars['HTTP_ZONE_NAME']) && $n3u_ServerVars['HTTP_ZONE_NAME'] != NULL){ // Use HTTP_ZONE_NAME
  306. $url['host'] = $n3u_ServerVars['HTTP_ZONE_NAME'];
  307. }else{ // Use SiteURL
  308. $url['host'] = strtolower(str_replace('http://','',$n3u_configVars['SiteURL']));
  309. }
  310. }
  311. $n3u_cacheFilePath = $n3u_configVars['cache_dir'] .$url['host']. '/' . 'css.css'; // Set cache file name
  312. if(file_exists($n3u_cacheFilePath) && time() - $n3u_configVars['lifetime'] < filemtime($n3u_cacheFilePath)){ // else if a recent cache file exist
  313. // Already exist and is recent so do nothing.
  314. }else{
  315. $css = array();
  316. foreach(glob($n3u_configVars['blocks_dir'] . '*/*.css') as $filename){ // get block css files
  317. // if(preg_match('/disabled/i', $filename) != TRUE){
  318. $css[] = $filename; // add each filename into css array
  319. // }
  320. }
  321. foreach(glob($n3u_configVars['Template_Dir'] . $n3u_configVars['Template_Name'] . '/*.css') as $filename){ // get template css files
  322. if(preg_match('/admin.css/i', $filename) != TRUE){ // Not admin so strip out admin css
  323. $css[] = $filename; // add each filename into css array
  324. }
  325. }
  326. if(file_exists($n3u_configVars['Template_Dir'] . $n3u_configVars['Template_Name'] . '/style.php')){ // get style.php if exist
  327. $css[] = $n3u_configVars['Template_Dir'] . $n3u_configVars['Template_Name'] . '/style.php';
  328. }
  329. if((defined('admin') == TRUE) && file_exists($n3u_configVars['Template_Dir'] . $n3u_configVars['Template_Name'] . '/style.php')){ // get style.php if exist
  330. $css[] = $n3u_configVars['Template_Dir'] . 'admin/style.php';
  331. }
  332. if((defined('admin') == TRUE) && file_exists($n3u_configVars['Template_Dir'] . $n3u_configVars['Template_Name'] . '/style.php')){ // get style.php if exist
  333. $css[] = $n3u_configVars['Template_Dir'] . 'admin/admin.css';
  334. }
  335. $pattern = array('\'\s+\'','/\s*(?!<\")\/\*[^\*]+\*\/(?!\")\s*/','/images\/' . '/'); // what to find
  336. $replacement = array(' ','','../../' . $n3u_configVars['Template_Dir'] . $n3u_configVars['Template_Name'] . '/images/'); // what to replace
  337. ob_start();
  338. foreach($css as $file){require_once($file);} // require every file from the css array
  339. $n3u_cacheFileDump = str_replace(array(' { ',' } '),array('{','} '),preg_replace($pattern,$replacement,ob_get_contents())); // Dump contents as var & replace from patterns
  340. ob_end_clean(); // Stop & flush buffer
  341. $n3u_cacheFileName = fopen($n3u_cacheFilePath, 'w'); // open as writeable
  342. fwrite($n3u_cacheFileName, $n3u_cacheFileDump); // Write the file from var
  343. fclose($n3u_cacheFileName); // Close file
  344. unset($css,$file,$n3u_cacheFileName,$n3u_cacheFileDump,$pattern,$replacement);
  345. }
  346. echo "\t\t" . '<link rel="stylesheet" type="text/css" href="' . $n3u_cacheFilePath . '">' . PHP_EOL;
  347. unset($n3u_cacheFilePath,$url);
  348. }
  349. }
  350. /**
  351. n3u_CacheEnd() is used to end the caching process and write the results
  352. to a single cache file. Cache has already been minified and combined.
  353. **/
  354. function n3u_CacheEnd(){
  355. global $n3u_inputVars;
  356. global $n3u_configVars;
  357. global $n3u_cacheFile;
  358. // Cache the contents to a file
  359. if(defined('admin') || $n3u_configVars['caching'] == FALSE){
  360. ob_end_flush(); // Send the output to browser & flush buffer
  361. }else{
  362. $n3u_cacheFileName = fopen($n3u_cacheFile, 'w'); // Open file as writeable
  363. $n3u_cacheFileDump = str_replace('> <','><',preg_replace("'\s+'",' ',ob_get_contents())); // Remove extra spaces to minify
  364. fwrite($n3u_cacheFileName, $n3u_cacheFileDump); // Write the file
  365. fclose($n3u_cacheFileName); // Close file
  366. ob_end_flush(); // Send the output to browser & flush buffer
  367. }
  368. }
  369. /**
  370. n3u_CacheImage() is used to cache the images returned by Prosperent if
  371. Image Caching is enabled in the Cache Settings of n3u Niche Store.
  372. Images appear to be from your site instead of from another domain. The
  373. browser also deals with less http request and gains performance from
  374. having the file ready to serve. Images are sorted based on their size.
  375. **/
  376. function n3u_CacheImage($src_img,$val){
  377. global $n3u_configVars;
  378. // global $n3u_inputVars;
  379. if($n3u_configVars['cacheImgs'] == FALSE){return $src_img;} // nothing further to do.
  380. $dst_img = $n3u_configVars['img_dir'] . $n3u_configVars['img_size'] . '/' . $val . '_'.$n3u_configVars['img_size'].'.jpg';
  381. if(!is_dir($n3u_configVars['img_dir'])){
  382. mkdir($n3u_configVars['img_dir']);
  383. fclose(fopen($n3u_configVars['img_dir'] . 'index.php', 'w'));
  384. }elseif(!is_dir($n3u_configVars['img_dir'] . $n3u_configVars['img_size'] . '/')){
  385. mkdir($n3u_configVars['img_dir'] . $n3u_configVars['img_size'] . '/');
  386. fclose(fopen($n3u_configVars['img_dir'] . $n3u_configVars['img_size'] . '/' . 'index.php', 'w'));
  387. }
  388. if(!is_file($dst_img)){ // Check if file exist
  389. @copy($src_img,$dst_img);
  390. usleep(50000); // small delay to minimize timeouts from remote images, increase if needed (microseconds)
  391. }
  392. $dst_size = @filesize($dst_img);
  393. if($dst_size < 225){
  394. @unlink($dst_img); // file is empty or likely invalid, delete file
  395. return $n3u_configVars['Template_Dir'] . $n3u_configVars['Template_Name'] . '/images/NoImg'.$n3u_configVars['img_size'].'.png';
  396. }
  397. return $dst_img;
  398. }
  399. /**
  400. n3u_CacheJS() is used to cache JS in a similar manner to n3u_CacheCSS().
  401. **/
  402. function n3u_CacheJS(){
  403. global $n3u_configVars;
  404. global $n3u_ServerVars;
  405. if(defined('admin') || $n3u_configVars['caching'] == FALSE){ // if admin or if caching is disabled
  406. echo "\t\t" . '<script type="text/javascript">' . PHP_EOL
  407. . "\t\t" . ' var _prosperent = {' . PHP_EOL
  408. . "\t\t" . ' \'campaign_id\': \'4fc3f330cc53edb6b1b672001dd0a607\',' . PHP_EOL
  409. . "\t\t" . ' \'platform\': \'other\'' . PHP_EOL
  410. . "\t\t" . ' };' . PHP_EOL
  411. . "\t\t" . '</script>' . PHP_EOL
  412. . "\t\t" . '<script defer type="text/javascript" src="http://prosperent.com/js/prosperent.js"></script>' . PHP_EOL
  413. . "\t\t" . '<script defer src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js" type="text/javascript"></script>' . PHP_EOL;
  414. foreach(glob($n3u_configVars['Template_Dir'] . $n3u_configVars['Template_Name'] . '/*.js') as $filename){echo "\t\t" . '<script defer src="' . $filename . '"></script>' . PHP_EOL;} // get template js files
  415. foreach(glob($n3u_configVars['blocks_dir'] . '*/*.js') as $filename){if(preg_match('/disabled/i', $filename) != TRUE){echo "\t\t" . '<script defer src="' . $filename . '"></script>' . PHP_EOL;}} // get block js files
  416. if($n3u_configVars['jScroll'] == TRUE){echo "\t\t" . '<script defer src="'.$n3u_configVars['include_dir'].'jquery.jscroll.min.js"></script>' . PHP_EOL;}
  417. }else{ // if not admin and caching is enabled and cache is old
  418. $url = parse_url($n3u_ServerVars['HTTP_HOST']);
  419. if(!isset($url['host']) || $url['host'] == NULL){
  420. if(isset($url['path']) && $url['path'] != NULL){ // Check to see if host is classified as path
  421. $url['host'] = $url['path'];
  422. }elseif(isset($n3u_ServerVars['HTTP_ZONE_NAME']) && $n3u_ServerVars['HTTP_ZONE_NAME'] != NULL){ // Use HTTP_ZONE_NAME
  423. $url['host'] = $n3u_ServerVars['HTTP_ZONE_NAME'];
  424. }else{ // Use SiteURL
  425. $url['host'] = strtolower(str_replace('http://','',$n3u_configVars['SiteURL']));
  426. }
  427. }
  428. $n3u_cacheFilePath = $n3u_configVars['cache_dir'] .$url['host']. '/' . 'js.js'; // Set cache file name
  429. if(file_exists($n3u_cacheFilePath) && time() - $n3u_configVars['lifetime'] < filemtime($n3u_cacheFilePath)){ // else if a recent cache file exist
  430. // Already exist and is recent so do nothing.
  431. }else{
  432. $js = array();
  433. foreach(glob($n3u_configVars['Template_Dir'] . $n3u_configVars['Template_Name'] . '/*.js') as $filename){ // get template js files
  434. $js[] = $filename; // add each filename into js array
  435. }
  436. foreach(glob($n3u_configVars['blocks_dir'] . '*/*.js') as $filename){ // get block js files
  437. if(preg_match('/disabled/i', $filename) != TRUE){$js[] = $filename;} // add each filename into js array but ignore disabled blocks
  438. }
  439. ob_start();
  440. foreach($js as $file){require_once($file);} // require every file from the js array
  441. $n3u_cacheFileDump = preg_replace(array('\'\s+\'','/\s*(?!<\")\/\*[^\*]+\*\/(?!\")\s*/'),array(' ',''),ob_get_contents()); // Dump contents as var & replace from patterns
  442. ob_end_clean(); // Stop & flush buffer
  443. $n3u_cacheFileName = fopen($n3u_cacheFilePath, 'w'); // open as writeable
  444. fwrite($n3u_cacheFileName, $n3u_cacheFileDump); // Write the file from var
  445. fclose($n3u_cacheFileName); // Close file
  446. unset($js,$file,$n3u_cacheFileName,$n3u_cacheFileDump);
  447. }
  448. // echo "\t\t" . '<script type="text/javascript">' . PHP_EOL
  449. // . "\t\t\t" . '<!--' . PHP_EOL
  450. // . "\t\t\t" . 'prosperent_pa_uid = '.$n3u_configVars['Prosperent_UserID'].';' . PHP_EOL
  451. // . "\t\t\t" . 'prosperent_pa_fallback_query = \''.$n3u_configVars['defaultKeyword'].'\';' . PHP_EOL
  452. // . "\t\t\t" . '//-->' . PHP_EOL
  453. // . "\t\t" . '</script>' . PHP_EOL
  454. echo "\t\t" . '<script type="text/javascript">' . PHP_EOL
  455. . "\t\t" . ' var _prosperent = {' . PHP_EOL
  456. . "\t\t" . ' \'campaign_id\': \'4fc3f330cc53edb6b1b672001dd0a607\',' . PHP_EOL
  457. . "\t\t" . ' \'platform\': \'other\'' . PHP_EOL
  458. . "\t\t" . ' };' . PHP_EOL
  459. . "\t\t" . '</script>' . PHP_EOL
  460. . "\t\t" . '<script defer src="http://prosperent.com/js/prosperent.js" type="text/javascript"></script>' . PHP_EOL
  461. . "\t\t" . '<script defer src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js" type="text/javascript"></script>' . PHP_EOL
  462. . "\t\t" . '<script defer src="' . $n3u_cacheFilePath . '" type="text/javascript"></script>' . PHP_EOL;
  463. if($n3u_configVars['jScroll'] == TRUE){echo "\t\t" . '<script defer src="'.$n3u_configVars['include_dir'].'jquery.jscroll.min.js" type="text/javascript"></script>' . PHP_EOL;}
  464. unset($n3u_cacheFilePath,$url);
  465. }
  466. }
  467. /**
  468. n3u_CheckApiKey() is used for the Supporter Feature which is fully
  469. configurable in the Administration Panel. Supporters support the project
  470. by allocating n3u.com's api key instead of theirs for that specific item
  471. For example, if a val of 10 is passed (which is default) that translates
  472. into n3u.com having a 1 out of a 10 chance to have it's API Key applied
  473. instead of the default sites API Key. That site would still then average
  474. it's api key being applied 9 out of 10 times. n3u Niche Store allows you
  475. full control of this in the Admin Panel so rather than disable if you
  476. find 1 out of 10 too many, Please try another allocation. It's up to you
  477. though and n3u.com forces nothing.
  478. **/
  479. function n3u_CheckApiKey($api_key,$val=10){ // Check API Key
  480. global $n3u_configVars;
  481. if($val == 0){
  482. return $api_key; // 0 means disabled, so we just return the users api key and never set n3u Niche Stores :(
  483. }elseif($val < 3){ // val was set for 1 or 2 meaning user attempted to allocate over 50% of page views to n3u Niche Store
  484. $val = 3; // This is overridden to 3 meaning 1 out 3 visits (or 33%), The extra view(s) are given back since 3 is minimum for if statement below. Otherwise lower numbers would never return true.
  485. } // $val was set 3 or higher, Process check as normal.
  486. if(rand(1,$val) == 3){ // 3 is symbolic so if 3 is picked at random, replace with n3u's API Key
  487. $api_key = base64_decode('ODcwM2I1OWJhMWE2NDQ5ZmE3ZjM2MWZhMTM5ODI1MjQ=');
  488. }
  489. return $api_key; // returns either the sites api key, or n3u.com's if conditions are met
  490. }
  491. /**
  492. n3u_CheckCache() is used for cache cleanup. You configure the Frequency
  493. in the Administration Panel. This affects both file and image caches.
  494. Files are emptied at random based on the Frequency. Images are only
  495. emptied if they are found to be older than 45 days. This function also
  496. detects when the administrator empties the cache.
  497. **/
  498. function n3u_CheckCache(){ // Check Cache
  499. global $n3u_inputVars;
  500. global $n3u_configVars;
  501. global $n3u_PostVars;
  502. if(rand(1,$n3u_configVars['ClearCacheFreq']) == 3){ // if 3, empty cache (avg 1 out of ClearCacheFreq visits)
  503. n3u_ClearCache(); // Clear File Caches, Auto cleans cache folder 1 out of ClearCacheFreq visits for older files.
  504. }
  505. if(rand(1,$n3u_configVars['ClearImgCacheFreq']) == 3){ // if 3, empty cache (avg 1 out of ClearImgCacheFreq visits)
  506. n3u_ClearImages(60); // Clear Image Caches, Auto cleans images folders 1 out of ClearImgCacheFreq visits for older images.
  507. }
  508. if(isset($n3u_inputVars['clearcache']) && defined('admin')){ // Check if sent via server via GET (Also make sure is admin)
  509. n3u_ClearCache(); // Delete all file caches (but not images)
  510. }
  511. if(isset($n3u_inputVars['clearimgs']) && defined('admin')){ // Clear Image Caches
  512. if($n3u_inputVars['clearimgs'] == 'accessed'){
  513. n3u_ClearImages(60); // Clear images that were last-accessed 45 days or more ago (cleans stale, keeps recently accessed)
  514. }elseif($n3u_inputVars['clearimgs'] == 'modified'){
  515. n3u_ClearImages(60,TRUE); // Clear images that were last-modified 45 days or more ago (cleans any older than 45 days)
  516. }elseif($n3u_inputVars['clearimgs'] == 'all'){
  517. n3u_ClearImages(); // Clear all images (not recommended, Spiders)
  518. }
  519. }
  520. if(isset($n3u_PostVars['ClearCache']) && $n3u_PostVars['ClearCache'] == 'ClearCacheFiles'){ // Check if sent to server via $n3u_PostVars
  521. n3u_ClearCache(); // Clear cache files (does not include images)
  522. }elseif(isset($n3u_PostVars['ClearCache']) && $n3u_PostVars['ClearCache'] == 'ClearAllImages'){
  523. n3u_ClearImages(); // Clear all images (not recommended, Spiders)
  524. }elseif(isset($n3u_PostVars['ClearCache']) && $n3u_PostVars['ClearCache'] == 'ClearLastAccessedImages'){
  525. n3u_ClearImages(60); // Clear images that were last-accessed 45 days or more ago (cleans stale, keep recently accessed)
  526. }elseif(isset($n3u_PostVars['ClearCache']) && $n3u_PostVars['ClearCache'] == 'ClearLastModifiedImages'){
  527. n3u_ClearImages(60,TRUE); // Clear images that were last-modified 45 days or more ago (cleans any older than 30 days ago)
  528. }
  529. }
  530. /**
  531. n3u_Cleaner() may be redundant and needs to be checked.
  532. function n3u_Cleaner($string){
  533. $id_entities = array('%21','%2A','%27','%28','%29','%3B','%3A','%40','%26','&','%3D','%2B','%24','%2C','%2F','%3F','%25','%23','%5B','%5D');
  534. $id_replacements = array('!','*',"'",'(', ')',';',':','@','&amp;','&amp;','=','+','$',',','/','?','%','#','[',']');
  535. return str_replace($id_entities,$id_replacements,$string);
  536. }**/
  537. /**
  538. n3u_Clean() may be redundant and needs to be checked.
  539. function n3u_Clean($string){
  540. $id_entities = array('\'','.',',','/','&',' ');
  541. $id_replacements = array('',' ','','','and',' ');
  542. return strtolower(urlencode(str_replace($id_entities,$id_replacements,$string)));
  543. }**/
  544. /**
  545. n3u_ClearCache() does the actual job of cleaning file caches. If called
  546. directly, expect that file caches are emptied without condition.
  547. **/
  548. function n3u_ClearCache(){
  549. global $n3u_configVars;
  550. $files = array_filter(glob('{' . $n3u_configVars['cache_dir'] . '*,'. $n3u_configVars['cache_dir'] . '*/*}',GLOB_BRACE), 'is_file');
  551. $folders = glob($n3u_configVars['cache_dir'] . '*',GLOB_ONLYDIR);
  552. array_map("unlink", $files);
  553. array_map("rmdir", $folders);
  554. unset($folders,$files);
  555. }
  556. /**
  557. n3u_ClearImages() does the actual job of cleaning image caches. If
  558. called directly, expect that image caches are emptied without condition.
  559. **/
  560. function n3u_ClearImages($val=null,$val2=FALSE){
  561. global $n3u_configVars;
  562. $files = array_filter(glob('{' . $n3u_configVars['img_dir'] . '*,'. $n3u_configVars['img_dir'] . '*/*,'. $n3u_configVars['img_dir'] . '*/*/*}',GLOB_BRACE), 'is_file');
  563. $folders = array_filter($files, 'is_dir');
  564. if($val == null){ // empty, clear all
  565. array_map("unlink", $files);
  566. array_map("rmdir", $folders);
  567. }elseif(is_int($val)){ // number of days
  568. if($val2 == TRUE){ // last modified
  569. foreach ($files as $file){
  570. if(filemtime($file) < strtotime('-' . $val . ' days')){@unlink($file);} // delete file
  571. }
  572. }elseif($val2 == FALSE){ // last accessed
  573. foreach ($files as $file){
  574. if(fileatime($file) < strtotime('-' . $val . ' days')){@unlink($file);} // delete file
  575. }
  576. }
  577. }
  578. unset($folders,$files);
  579. }
  580. /**
  581. n3u_Config() is used to retrieve and filter the ocnfiguration for
  582. n3u_ConfigVars().
  583. **/
  584. function n3u_Config(){ // Check installation, get data
  585. global $n3u_configArgs; // Make $n3u_configArgs Global
  586. global $n3u_configVars;
  587. global $n3u_lang;
  588. global $n3u_ServerVars;
  589. if(file_exists('config.php')){require_once('config.php');} // Backwards compatibility
  590. $url = parse_url($n3u_ServerVars['HTTP_HOST']);
  591. if(!isset($url['host']) || $url['host'] == NULL){
  592. if(isset($url['path']) && $url['path'] != NULL){ // Check to see if host is classified as path
  593. $url['host'] = $url['path'];
  594. }elseif(isset($n3u_ServerVars['HTTP_ZONE_NAME']) && $n3u_ServerVars['HTTP_ZONE_NAME'] != NULL){ // Use HTTP_ZONE_NAME
  595. $url['host'] = $n3u_ServerVars['HTTP_ZONE_NAME'];
  596. }else{ // Use SiteURL
  597. $url['host'] = strtolower(str_replace('http://','',$n3u_configVars['SiteURL']));
  598. }
  599. }
  600. if(file_exists($url['host'].'_config.php')){require_once($url['host'].'_config.php');} // This should get config for sub domains and overtide main configs array in the process.
  601. $n3u_configArgs = array(
  602. 'accessKey' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  603. 'AdminCategories' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  604. 'AdminCatList' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  605. 'api_key' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  606. 'blocks_dir' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  607. 'cache_dir' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  608. 'cacheBackend' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  609. 'cacheImgs' => FILTER_VALIDATE_BOOLEAN,
  610. 'caching' => FILTER_VALIDATE_BOOLEAN,
  611. 'ClearCacheFreq' => FILTER_VALIDATE_INT,
  612. 'ClearImgCacheFreq' => FILTER_VALIDATE_INT,
  613. 'Categories' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_ENCODE_HIGH),
  614. 'CategoryFilters' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_ENCODE_HIGH),
  615. // 'channel_id' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  616. 'CleanUrls' => FILTER_VALIDATE_BOOLEAN,
  617. 'commissionDateMonths' => FILTER_VALIDATE_INT,
  618. 'commissionDateRange' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  619. 'debug' => FILTER_VALIDATE_BOOLEAN,
  620. 'enableCoupons' => FILTER_VALIDATE_BOOLEAN,
  621. 'enableFacets' => FILTER_VALIDATE_BOOLEAN,
  622. 'enableJsonCompression' => FILTER_VALIDATE_BOOLEAN,
  623. 'enableQuerySuggestion' => FILTER_VALIDATE_BOOLEAN,
  624. 'defaultKeyword' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_ENCODE_HIGH),
  625. 'defaultLanguage' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_ENCODE_HIGH),
  626. 'img_dir' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  627. 'img_size' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH),
  628. 'include_dir' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  629. 'language_dir' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  630. 'lifetime' => FILTER_SANITIZE_NUMBER_INT,
  631. 'limit' => FILTER_SANITIZE_NUMBER_INT,
  632. 'logging' => FILTER_VALIDATE_BOOLEAN,
  633. 'msg_dir' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  634. 'password' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  635. 'Prosperent_Endpoint' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  636. 'Prosperent_UserID' => FILTER_SANITIZE_NUMBER_INT,
  637. 'querySuggestion' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_ENCODE_HIGH),
  638. 'reCaptcha_privKey' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_ENCODE_HIGH),
  639. 'reCaptcha_pubKey' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_ENCODE_HIGH),
  640. 'jScroll' => FILTER_VALIDATE_BOOLEAN,
  641. 'self' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  642. 'sid' => FILTER_SANITIZE_URL,
  643. 'SiteEmail' => FILTER_VALIDATE_EMAIL,
  644. 'SiteIndex' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  645. 'SiteName' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  646. 'SiteURL' => FILTER_SANITIZE_URL,
  647. 'Supporter' => FILTER_SANITIZE_NUMBER_INT,
  648. 'Template_Dir' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  649. 'Template_Name' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  650. 'username' => array('filter' => FILTER_SANITIZE_STRING,'flags' => FILTER_FLAG_STRIP_HIGH),
  651. 'Version' => array('filter' => FILTER_SANITIZE_NUMBER_FLOAT,'flags' => FILTER_FLAG_ALLOW_FRACTION),
  652. );
  653. $n3u_configVars = @filter_var_array($n3u_configData,$n3u_configArgs);
  654. unset($url);
  655. }
  656. /**
  657. n3u_CustomPages() restrieves custom pages and builds and array
  658. **/
  659. function n3u_CustomPages($page_limit = NULL){ // Returns array of Custom pages
  660. global $n3u_configVars;
  661. $n3u_customPages = array();
  662. $i = 1;
  663. $url = n3u_HTTP_Host();
  664. foreach(glob($n3u_configVars['include_dir'] . 'custom/'.$url['host'] . '_' . "*.php") as $n3u_custom_page){
  665. $n3u_custom_pagename = str_replace('.php','',str_replace($n3u_configVars['include_dir'] . 'custom/'.$url['host'] . '_','',$n3u_custom_page));
  666. $n3u_customPages[$i]['name'] = $n3u_custom_pagename;
  667. $n3u_customPages[$i]['path'] = $n3u_custom_page;
  668. if($n3u_configVars['CleanUrls'] == TRUE){
  669. $n3u_customPages[$i]['url'] = './page_'. $n3u_custom_pagename .'.htm';
  670. }else{
  671. $n3u_customPages[$i]['url'] = $n3u_configVars['self'] . '?x=page&amp;page=' . $n3u_custom_pagename;
  672. }
  673. if($page_limit == NULL){ // limits pages returned if specified
  674. $i++;
  675. }elseif($page_limit > $i){
  676. $i++;
  677. }
  678. } // finds all custom pages in templates custom directory, builds array
  679. unset($page_limit,$n3u_custom_page,$n3u_custom_pagename,$i,$url);
  680. return $n3u_customPages;
  681. }
  682. function Boolean2String($boolean = NULL){ // returns string
  683. return($boolean?'True':'False');
  684. }
  685. /**
  686. n3u_date() returns the date in the format requested.
  687. **/
  688. function n3u_date($date, $format){
  689. $n3u_date = date($format, strtotime($date));
  690. return $n3u_date;
  691. }
  692. /**
  693. n3u_Debug() returns debugging information if Debug is enabled.
  694. **/
  695. function n3u_Debug($n3u_val,$info=FALSE){
  696. global $n3u_inputVars;
  697. global $n3u_configVars;
  698. global $n3u_lang;
  699. global $prosperentApi;
  700. global $n3u_results; //$n3u_results
  701. if($info == TRUE){
  702. if($n3u_configVars['debug'] == TRUE){ // Is debug mode enabled?
  703. if(defined('admin')){
  704. // Error & Debug Info
  705. echo "\t\t\t\t" . '<div class="block_footer" id="Debug">' . PHP_EOL
  706. . "\t\t\t\t\t" . '<h3>' . $n3u_lang['Debug'] . '</h3>' . PHP_EOL
  707. . "\t\t\t\t\t" . '<hr />' . PHP_EOL
  708. . "\t\t\t\t\t" . '<form action="' . $n3u_configVars['self'] . '" id="debug_form" method="post">' . PHP_EOL
  709. . "\t\t\t\t\t\t" . '<fieldset>' . PHP_EOL
  710. . "\t\t\t\t\t\t\t" . '<legend>' . $n3u_lang['Debug_Mode'] . '</legend>' . PHP_EOL
  711. . "\t\t\t\t\t\t\t" . '<ul>' . PHP_EOL
  712. . "\t\t\t\t\t\t\t\t" . '<li>' . $n3u_lang['n3u_Niche_Store'] . ': <span>' . $n3u_lang['Debug_Enabled'] . '</span></li>' . PHP_EOL
  713. . "\t\t\t\t\t\t\t\t" . '<li>' . $n3u_lang['n3u_Niche_Store'] . ': <span>' . $n3u_lang['Debug_Explain1'] . '</span></li>' . PHP_EOL;
  714. if(in_array($n3u_inputVars['x'],array('index','item','search'))){
  715. n3u_FetchSearch();
  716. if($prosperentApi->hasWarnings()){
  717. foreach($prosperentApi->getWarnings() as $n3u_Warnings){
  718. echo "\t\t\t\t\t\t\t\t" . '<li>' . $n3u_lang['Prosperent'] . ': <span class="explain">(' . $n3u_Warnings['code'] . ') ' . $n3u_Warnings['msg'] . '</span></li>' . PHP_EOL;
  719. }
  720. }
  721. if($prosperentApi->hasErrors()){
  722. foreach($prosperentApi->getErrors() as $n3u_Errors){
  723. echo "\t\t\t\t\t\t\t\t" . '<li>' . $n3u_lang['Prosperent'] . ': <span class="explain">(' . $n3u_Errors['code'] . ') ' . $n3u_Errors['msg'] . '</span></li>' . PHP_EOL;
  724. }
  725. }
  726. echo "\t\t\t\t\t\t\t" . '</ul>' . PHP_EOL;
  727. if(isset($n3u_results) && $n3u_results != NULL){
  728. echo "\t\t\t\t\t\t\t\t" . '<label>Dump of $n3u_results: </label>' . PHP_EOL;
  729. foreach($n3u_results as $n3u_resultsString){
  730. foreach($n3u_resultsString as $n3u_resultKey => $n3u_resultString){
  731. echo "\t\t\t\t\t\t\t\t" . '<div class="debugvalues"><div class="keyvalue">$n3u_results[\''.$n3u_resultKey.'\']&nbsp;=&nbsp;</div>' . '<div class="stringvalue">'.str_replace('&','&amp;',var_export($n3u_resultString,TRUE)).';</div></div>' . PHP_EOL;
  732. }
  733. echo "\t\t\t\t\t\t\t\t" . '<hr class="hr" />' . PHP_EOL;
  734. }
  735. }
  736. }else{
  737. echo "\t\t\t\t\t\t\t" . '</ul>' . PHP_EOL;
  738. }
  739. echo "\t\t\t\t\t\t\t" . '<label>Dump of $n3u_inputVars: </label>' . PHP_EOL;
  740. foreach($n3u_inputVars as $n3u_inputVarKey => $n3u_inputVarString){
  741. echo "\t\t\t\t\t\t\t" . '<div class="debugvalues"><div class="keyvalue">$n3u_inputVars[\''.$n3u_inputVarKey.'\']&nbsp;=&nbsp;</div>'
  742. . '<div class="stringvalue">'.var_export($n3u_inputVarString,TRUE).';</div></div>' . PHP_EOL;
  743. }
  744. echo "\t\t\t\t\t\t\t\t" . '<hr class="hr" />' . PHP_EOL
  745. . "\t\t\t\t\t\t\t\t" . '<label>Dump of $n3u_configVars: </label>' . PHP_EOL;
  746. foreach($n3u_configVars as $n3u_configVarKey => $n3u_configVarString){
  747. if($n3u_configVarKey == 'password'){
  748. $n3u_configVarString = str_replace($n3u_configVarString,'*******',$n3u_configVarString);
  749. }
  750. echo "\t\t\t\t\t\t\t" . '<div class="debugvalues"><div class="keyvalue">$n3u_configVars[\''.$n3u_configVarKey.'\']&nbsp;=&nbsp;</div>'
  751. . '<div class="stringvalue">'.var_export($n3u_configVarString,TRUE).';</div></div>' . PHP_EOL;
  752. }
  753. echo "\t\t\t\t\t\t" . '</fieldset>' . PHP_EOL
  754. . "\t\t\t\t\t" . '</form>' . PHP_EOL
  755. . "\t\t\t\t" . '</div>' . PHP_EOL; //div debug
  756. }
  757. }
  758. }else{ // Not generating info, instead debug an array
  759. if(isset($n3u_val) && $n3u_val != NULL){
  760. echo "\t\t\t\t\t" . '<pre>' . PHP_EOL;
  761. foreach($n3u_val as $n3u_row){print_r(str_replace('&','&amp;',array_combine(array_keys($n3u_row), array_values($n3u_row))));}
  762. echo "\t\t\t\t\t" . '</pre>' . PHP_EOL;
  763. }
  764. }
  765. }
  766. /**
  767. n3u_Defaults() sets the minimums or defaults for n3u Niche Store.
  768. **/
  769. function n3u_Defaults(){
  770. global $n3u_inputVars;
  771. global $n3u_configVars;
  772. global $n3u_lang;
  773. global $n3u_extendedSort;
  774. global $n3u_ServerVars;
  775. if($n3u_configVars['debug'] == TRUE){
  776. error_reporting(E_ALL ^ E_NOTICE); // Report PHP errors but not notices
  777. }else{
  778. error_reporting(0); // Report no PHP errors
  779. }
  780. // First let's set defaults for $n3u_inputVars
  781. if(!isset($n3u_inputVars['b']) || $n3u_inputVars['b'] == array('Any'||'Unknown')){$n3u_inputVars['b'] = '';}
  782. // if(!isset($n3u_inputVars['compare'])){$n3u_inputVars['compare'] = NULL;}
  783. if(!isset($n3u_inputVars['m']) || $n3u_inputVars['m'] == array('Any'||'Unknown')){$n3u_inputVars['m'] = '';}
  784. if(!isset($n3u_inputVars['url'])){unset($n3u_inputVars['url']);}
  785. // if(!isset($n3u_inputVars['price_max']) || ($n3u_inputVars['price_max'] == NULL)){$n3u_inputVars['price_max'] = '0';}
  786. // if(!isset($n3u_inputVars['price_min']) || ($n3u_inputVars['price_min'] == NULL)){$n3u_inputVars['price_min'] = '0';}
  787. if(!isset($n3u_inputVars['p']) || ($n3u_inputVars['p'] == NULL)){$n3u_inputVars['p'] = '1';}
  788. if(!isset($n3u_inputVars['sort']) || !in_array($n3u_inputVars['sort'],array('ASC','DESC','REL'))){$n3u_inputVars['sort'] = 'REL';}
  789. if(!isset($n3u_inputVars['item'])){$n3u_inputVars['item'] = '';} // implement an error here
  790. if(isset($n3u_inputVars['sort']) && $n3u_inputVars['sort'] == 'ASC'){
  791. $n3u_extendedSort= 'price ASC';
  792. }elseif(isset($n3u_inputVars['sort']) && $n3u_inputVars['sort'] == 'DESC'){
  793. $n3u_extendedSort= 'price DESC';
  794. }elseif(isset($n3u_inputVars['sort']) && $n3u_inputVars['sort'] == 'REL'){
  795. $n3u_extendedSort= '@relevance DESC';
  796. }
  797. // defaults
  798. if(!isset($n3u_ServerVars['HTTP_CF_CONNECTING_IP'])){$n3u_configVars['visitor_ip'] = @$n3u_ServerVars['REMOTE_ADDR'];}else{$n3u_configVars['visitor_ip'] = $n3u_ServerVars['HTTP_CF_CONNECTING_IP'];} // CloudFlare is a reverse proxy, so all ips look like they originate from cloudflare, CloudFlare passes REMOTE_ADDR as HTTP_CF_CONNECTING_IP
  799. if(!isset($n3u_ServerVars['HTTP_REFERER'])){$n3u_configVars['referrer'] = '';$n3u_ServerVars['HTTP_REFERER'] = '';}else{$n3u_configVars['referrer'] = $n3u_ServerVars['HTTP_REFERER'];} // Auto determines Visitors Referrer
  800. if(preg_match("/" . @$n3u_ServerVars['HTTP_HOST'] . "/i",$n3u_ServerVars['HTTP_REFERER'])){$n3u_configVars['referrer'] = '';$n3u_ServerVars['HTTP_REFERER'] = '';} // empties referrer if from site.
  801. if(!isset($n3u_configVars['api_key']) || $n3u_configVars['api_key'] == NULL){$n3u_configVars['api_key'] = '8703b59ba1a6449fa7f361fa13982524'; } // Use n3u's if no other is set (to ensure script functions)
  802. if(!isset($n3u_configVars['blocks_dir']) || $n3u_configVars['blocks_dir'] == NULL){$n3u_configVars['blocks_dir'] = 'blocks/';}
  803. if(!isset($n3u_configVars['cacheBackend']) || $n3u_configVars['cacheBackend'] == NULL){$n3u_configVars['cacheBackend'] = 'File';}
  804. if(!isset($n3u_configVars['cacheImgs']) || $n3u_configVars['cacheImgs'] == NULL){$n3u_configVars['cacheImgs'] = FALSE;}
  805. if(!isset($n3u_configVars['cache_dir']) || $n3u_configVars['cache_dir'] == NULL){$n3u_configVars['cache_dir'] = 'cache/';}
  806. if(!isset($n3u_configVars['caching']) || $n3u_configVars['caching'] == NULL){$n3u_configVars['caching'] = FALSE;}
  807. if(!isset($n3u_configVars['ClearCacheFreq']) || $n3u_configVars['ClearCacheFreq'] == NULL){$n3u_configVars['ClearCacheFreq'] = 100;}
  808. if(!isset($n3u_configVars['ClearImgCacheFreq']) || $n3u_configVars['ClearImgCacheFreq'] == NULL){$n3u_configVars['ClearImgCacheFreq'] = 100;}
  809. if(!is_dir($n3u_configVars['cache_dir'])){mkdir($n3u_configVars['cache_dir']);fclose(fopen($n3u_configVars['cache_dir'] . 'index.php', 'w'));} // Auto creates cache folder & index.php
  810. $url = parse_url($n3u_ServerVars['HTTP_HOST']);
  811. if(!isset($url['host']) || $url['host'] == NULL){
  812. if(isset($url['path']) && $url['path'] != NULL){ // Check to see if host is classified as path
  813. $url['host'] = $url['path'];
  814. }elseif(isset($n3u_ServerVars['HTTP_ZONE_NAME']) && $n3u_ServerVars['HTTP_ZONE_NAME'] != NULL){ // Use HTTP_ZONE_NAME
  815. $url['host'] = $n3u_ServerVars['HTTP_ZONE_NAME'];
  816. }else{ // Use SiteURL
  817. $url['host'] = strtolower(str_replace('http://','',$n3u_configVars['SiteURL']));
  818. }
  819. }
  820. if(!is_dir($n3u_configVars['cache_dir'] . $url['host'] . '/')){mkdir($n3u_configVars['cache_dir'] . $url['host'] . '/');fclose(fopen($n3u_configVars['cache_dir'] . $url['host'] . '/' . 'index.php', 'w'));} // Auto creates cache folder & index.php
  821. unset($url);
  822. if(!isset($n3u_configVars['Categories']) || $n3u_configVars['Categories'] == NULL){$n3u_configVars['Categories'] = '7.2v,9.6v,12v,14.4v,18v,20v';}
  823. if(!isset($n3u_configVars['CategoryFilters']) || $n3u_configVars['CategoryFilters'] == NULL){$n3u_configVars['CategoryFilters'] = 'refurb|refurbished|recondition|reconditioned';}
  824. $n3u_configVars['CategoryFilters'] = str_replace(array(' , ',', ',',',' | ','| ',' '),array('|','|','|','|','|','%20'),$n3u_configVars['CategoryFilters']);
  825. if(!isset($n3u_configVars['CleanUrls']) || $n3u_configVars['CleanUrls'] == NULL){$n3u_configVars['CleanUrls'] = FALSE;}
  826. if(!isset($n3u_configVars['commissionDateMonths']) || $n3u_configVars['commissionDateMonths'] == NULL){$n3u_configVars['commissionDateMonths'] = 3;}
  827. if(!isset($n3u_configVars['commissionDateRange']) || $n3u_configVars['commissionDateRange'] == NULL){$n3u_configVars['commissionDateRange'] = date('Ymd', strtotime('-'.$n3u_configVars['commissionDateMonths'].' months -1 day')).','.date('Ymd', strtotime('yesterday'));}
  828. if(!isset($n3u_configVars['debug']) || $n3u_configVars['debug'] == NULL){$n3u_configVars['debug'] = FALSE;}
  829. if(!isset($n3u_configVars['defaultKeyword']) || $n3u_configVars['defaultKeyword'] == NULL){$n3u_configVars['defaultKeyword'] ='Cordless Drill';}
  830. if(!isset($n3u_inputVars['q']) || $n3u_inputVars['q'] == NULL){$n3u_inputVars['q'] = $n3u_configVars['defaultKeyword'];}
  831. if($n3u_inputVars['q'] != $n3u_configVars['defaultKeyword']){$n3u_inputVars['q'] = $n3u_configVars['defaultKeyword'].' '.str_replace($n3u_configVars['defaultKeyword'] .' ','',$n3u_inputVars['q']);}else{$n3u_inputVars['q'] = $n3u_configVars['defaultKeyword'];}
  832. if($n3u_inputVars['q'] == $n3u_configVars['defaultKeyword'].' '.$n3u_configVars['defaultKeyword']){$n3u_inputVars['q'] = $n3u_configVars['defaultKeyword']; }
  833. if(!isset($n3u_configVars['defaultLanguage']) || $n3u_configVars['defaultLanguage'] == NULL){$n3u_configVars['defaultLanguage'] = 'en-us';}
  834. if(!isset($n3u_configVars['enableCoupons']) || $n3u_configVars['enableCoupons'] == NULL){$n3u_configVars['enableCoupons'] = FALSE;}
  835. if(!isset($n3u_configVars['enableFacets']) || $n3u_configVars['enableFacets'] == NULL){$n3u_configVars['enableFacets'] = TRUE;}
  836. if(!isset($n3u_configVars['enableJsonCompression']) || $n3u_configVars['enableJsonCompression'] == NULL){$n3u_configVars['enableJsonCompression'] = TRUE;}
  837. if(!isset($n3u_configVars['enableQuerySuggestion']) || $n3u_configVars['enableQuerySuggestion'] == NULL){$n3u_configVars['enableQuerySuggestion'] = TRUE;}
  838. if(!isset($n3u_inputVars['lang']) || $n3u_inputVars['lang'] == NULL){$n3u_inputVars['lang'] = $n3u_configVars['defaultLanguage'];} // set default language
  839. if(!isset($n3u_configVars['include_dir']) || $n3u_configVars['include_dir'] == NULL){$n3u_configVars['include_dir'] = 'inc/';}
  840. if(!is_dir($n3u_configVars['include_dir'])){mkdir($n3u_configVars['include_dir']);fclose(fopen($n3u_configVars['include_dir'] . 'index.php', 'w'));} // Auto creates inc folder & index.php
  841. if(!is_dir($n3u_configVars['include_dir'] . 'configs/')){mkdir($n3u_configVars['include_dir'] . 'configs/');fclose(fopen($n3u_configVars['include_dir'] . 'configs/index.php', 'w'));} // Auto creates custom folder & index.php
  842. if(!is_dir($n3u_configVars['include_dir'] . 'custom/')){mkdir($n3u_configVars['include_dir'] . 'custom/');fclose(fopen($n3u_configVars['include_dir'] . 'custom/index.php', 'w'));} // Auto creates custom folder & index.php
  843. if(!is_dir($n3u_configVars['include_dir'] . 'messages/')){mkdir($n3u_configVars['include_dir'] . 'messages/');fclose(fopen($n3u_configVars['include_dir'] . 'messages/index.php', 'w'));} // Auto creates custom folder & index.php
  844. if(!isset($n3u_configVars['img_dir']) || $n3u_configVars['img_dir'] == NULL){$n3u_configVars['img_dir'] = 'images/';}
  845. if(!isset($n3u_configVars['img_size']) || $n3u_configVars['img_size'] == NULL){$n3u_configVars['img_size'] = '125x125';}
  846. if(!isset($n3u_configVars['language_dir']) || $n3u_configVars['language_dir'] == NULL){$n3u_configVars['language_dir'] = 'languages/';}
  847. if(!isset($n3u_configVars['lifetime']) || $n3u_configVars['lifetime'] == NULL){$n3u_configVars['lifetime'] = '86400';}
  848. if(!isset($n3u_configVars['limit']) || $n3u_configVars['limit'] == NULL){$n3u_configVars['limit'] = '10';}
  849. if(!isset($n3u_configVars['username']) || $n3

Large files files are truncated, but you can click here to view the full file