Guest User

Untitled

a guest
Feb 21st, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.53 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by deZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 1.1.3.0
  8. * @ Author : DeZender
  9. * @ Release on : 17.05.2011
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. function trigger_db_error(&$obj) {
  15. global $CFG;
  16.  
  17. $error_arr = debug_backtrace( );
  18. $subject = 'Report bug - Sql error - VAR_SITE_URL';
  19. $content = '<u><b>Url :</b></u>
  20. VAR_CURRENT_URL
  21.  
  22. <u><b>Error File :</b></u>
  23. VAR_FILE
  24.  
  25. <u><b>Error Line No :</b></u>
  26. VAR_LINE
  27.  
  28. <u><b>Error Sql :</b></u>
  29. VAR_SQL
  30.  
  31. <u><b>Error Description:</b></u>
  32. VAR_ERROR';
  33. $frmobj = new FormHandler( );
  34. $frmobj->setEmailTemplateValue( 'CURRENT_URL', $CFG['site']['current_url'] );
  35. $frmobj->setEmailTemplateValue( 'FILE', $error_arr[0]['file'] );
  36. $frmobj->setEmailTemplateValue( 'LINE', $error_arr[0]['line'] );
  37. $frmobj->setEmailTemplateValue( 'SQL', $error_arr[0]['args'][0]->sql );
  38. $frmobj->setEmailTemplateValue( 'ERROR', $error_arr[0]['args'][0]->debug_output );
  39. $frmobj->buildEmailTemplate( $subject, $content, false, true );
  40. sendBugEmail( $frmobj );
  41. trigger_error( 'Error at ' . $error_arr[0]['file'] . ' on line ' . $error_arr[0]['line'] . '<br>' . $obj->ErrorNo( ) . ' ' . $obj->ErrorMsg( ), E_USER_ERROR );
  42. }
  43.  
  44. function setUserConfigVariables() {
  45. global $CFG;
  46.  
  47. if (!isMember( )) {
  48. return false;
  49. }
  50.  
  51. $CFG['user']['user_id'] = $_SESSION['user']['user_id'];
  52. $CFG['user']['user_name'] = $_SESSION['user']['user_name'];
  53. $CFG['user']['time_zone'] = (isset( $_SESSION['user']['time_zone'] ) ? $_SESSION['user']['time_zone'] : '');
  54. $CFG['user']['email'] = (isset( $_SESSION['user']['email'] ) ? $_SESSION['user']['email'] : '');
  55. $CFG['user']['openid_type'] = (isset( $_SESSION['user']['openid_type'] ) ? $_SESSION['user']['openid_type'] : '');
  56. $CFG['user']['name'] = (isset( $_SESSION['user']['name'] ) ? $_SESSION['user']['name'] : '');
  57. $CFG['user']['pref_lang'] = (isset( $_SESSION['user']['pref_lang'] ) ? $_SESSION['user']['pref_lang'] : '');
  58. $CFG['user']['last_logged'] = (isset( $_SESSION['user']['last_logged'] ) ? $_SESSION['user']['last_logged'] : '');
  59. $CFG['user']['num_visits'] = (isset( $_SESSION['user']['num_visits'] ) ? $_SESSION['user']['num_visits'] : '');
  60. $CFG['user']['useragent_hash'] = (isset( $_SESSION['user']['useragent_hash'] ) ? $_SESSION['user']['useragent_hash'] : '');
  61. $CFG['user']['is_upload_background_image'] = (isset( $_SESSION['user']['is_upload_background_image'] ) ? $_SESSION['user']['is_upload_background_image'] : '');
  62. $CFG['user']['is_paid_member'] = (isset( $_SESSION['user']['is_paid_member'] ) ? $_SESSION['user']['is_paid_member'] : '');
  63. $CFG['user']['ip'] = (isset( $_SESSION['user']['ip'] ) ? $_SESSION['user']['ip'] : '');
  64. $CFG['user']['is_logged_in'] = (isset( $_SESSION['user']['is_logged_in'] ) ? $_SESSION['user']['is_logged_in'] : '');
  65. $CFG['user']['adult'] = (isset( $_SESSION['user']['adult'] ) ? $_SESSION['user']['adult'] : '');
  66. $CFG['user']['content_filter'] = (isset( $_SESSION['user']['content_filter'] ) ? $_SESSION['user']['content_filter'] : '');
  67. $CFG['user']['usr_access'] = (isset( $_SESSION['user']['usr_access'] ) ? $_SESSION['user']['usr_access'] : '');
  68. $CFG['user']['user_actions'] = (isset( $_SESSION['user']['user_actions'] ) ? $_SESSION['user']['user_actions'] : '');
  69. return true;
  70. }
  71.  
  72. function sendBugEmail($frmobj) {
  73. global $CFG;
  74.  
  75. $EasySwift = new EasySwift( )( );
  76. $EasySwift->flush( );
  77. $EasySwift->addPart( $frmobj->getEmailContent( true ), 'text/html' );
  78. $from_email = $CFG['site']['noreply_email'];
  79. $EasySwift->send( 'r.senthilvasan@agriya.in', $from_email, $frmobj->getEmailSubject( ) );
  80. }
  81.  
  82. function getCurrentMemberUrl() {
  83. global $CFG;
  84.  
  85. return $CFG['site']['current_url'];
  86. }
  87.  
  88. function getMemberAvatarDetails($user_id) {
  89. global $db;
  90. global $CFG;
  91.  
  92. $details = array( );
  93. $defaultPhotoDetails = true;
  94. $udetails = getUserDetail( 'user_id', $user_id );
  95.  
  96. if (( $udetails && $udetails['image_ext'] )) {
  97. $defaultPhotoDetails = false;
  98. $imgUrl = (!empty( $udetails['image_server_url'] ) ? $udetails['image_server_url'] : $CFG['site']['url']);
  99. $img = $imgUrl . $CFG['admin']['members_profile']['user_profile_folder'] . '/';
  100. $udetails['image_name'] = ($udetails['image_name'] ? $udetails['image_name'] : $user_id);
  101. $details['l_url'] = $img . $udetails['image_name'] . $CFG['image_large_name'] . '.' . $udetails['image_ext'];
  102. $details['t_url'] = $img . $udetails['image_name'] . $CFG['image_thumb_name'] . '.' . $udetails['image_ext'];
  103. $details['s_url'] = $img . $udetails['image_name'] . $CFG['image_small_name'] . '.' . $udetails['image_ext'];
  104. $details['m_url'] = $img . $udetails['image_name'] . $CFG['image_medium_name'] . '.' . $udetails['image_ext'];
  105. $details['s_width'] = $udetails['small_width'];
  106. $details['t_width'] = $udetails['thumb_width'];
  107. $details['l_width'] = $udetails['large_width'];
  108. $details['m_width'] = $udetails['mini_width'];
  109. $details['s_height'] = $udetails['small_height'];
  110. $details['t_height'] = $udetails['thumb_height'];
  111. $details['l_height'] = $udetails['large_height'];
  112. $details['m_height'] = $udetails['mini_height'];
  113. }
  114.  
  115. if ($defaultPhotoDetails) {
  116. $tWidth = $CFG['image_thumb_width'];
  117. $tHeight = $CFG['image_thumb_height'];
  118. $sWidth = $CFG['image_small_width'];
  119. $sHeight = $CFG['image_small_height'];
  120. $lWidth = $CFG['image_thumb_width'];
  121. $lHeight = $CFG['image_thumb_height'];
  122. $mWidth = $CFG['image_medium_width'];
  123. $mHeight = $CFG['image_medium_height'];
  124. $url = $CFG['site']['url'] . 'design/templates/' . $CFG['html']['template']['default'] . '/root/images/' . $CFG['html']['stylesheet']['screen']['default'] . '/no_image';
  125.  
  126. if (( isset( $udetails['sex'] ) && $udetails['sex'] == 'female' )) {
  127. $details['l_url'] = $url . '/no-femaleprofile_L.jpg';
  128. $details['t_url'] = $url . '/no-femaleprofile_T.jpg';
  129. $details['s_url'] = $url . '/no-femaleprofile_S.jpg';
  130. $details['m_url'] = $url . '/no-femaleprofile_M.jpg';
  131. } else {
  132. $details['l_url'] = $url . '/no-maleprofile_L.jpg';
  133. $details['t_url'] = $url . '/no-maleprofile_T.jpg';
  134. $details['s_url'] = $url . '/no-maleprofile_S.jpg';
  135. $details['m_url'] = $url . '/no-maleprofile_M.jpg';
  136. }
  137.  
  138. $details['s_width'] = $sWidth;
  139. $details['t_width'] = $tWidth;
  140. $details['l_width'] = $lWidth;
  141. $details['m_width'] = $lWidth;
  142. $details['s_height'] = $sHeight;
  143. $details['t_height'] = $tHeight;
  144. $details['l_height'] = $lHeight;
  145. $details['m_height'] = $lHeight;
  146. }
  147.  
  148. return $details;
  149. }
  150.  
  151. function setUserDetails($column_name, &$column_value) {
  152. global $CFG;
  153. global $db;
  154.  
  155. if (!$column_value) {
  156. return false;
  157. }
  158.  
  159. if (isset( $CFG['user_details'][$column_value] )) {
  160. return null;
  161. }
  162.  
  163. $condition = ' AND usr_status!=\'Deleted\'';
  164. $sql = ' SELECT * FROM ' . $CFG['db']['tbl']['users'] . ' WHERE' . ' ' . $column_name . ' = ' . $db->Param( 'column_name' ) . $condition;
  165. $stmt = $db->Prepare( $sql );
  166. $rs = $db->Execute( $stmt, array( $column_value ) );
  167.  
  168. if (!$rs) {
  169. trigger_db_error( $db );
  170. }
  171.  
  172. if ($row = $rs->FetchRow( )) {
  173. $row['display_name'] = getUserDisplayName( $row );
  174. $row['profile_url'] = getMemberProfileUrl( $row['user_id'], $row['user_name'] );
  175. $row['user_actions'] = getUserActions( $row['usr_type'] );
  176. $CFG['user_details'][strtolower( $row['user_name'] )] = $row;
  177. $CFG['user_details'][strtolower( $row['user_id'] )] = $row;
  178. $CFG['user_details'][strtolower( $row['email'] )] = $row;
  179. return true;
  180. }
  181.  
  182. $CFG['user_details'][$column_value] = '';
  183. return false;
  184. }
  185.  
  186. function getUserDetail($column_name, $column_value, $return_column_name = '') {
  187. global $CFG;
  188.  
  189. $column_name = strtolower( $column_name );
  190. $column_value = strtolower( $column_value );
  191.  
  192. if (!isset( $CFG['user_details'][$column_value] )) {
  193. setUserDetails( $column_name, $column_value );
  194. }
  195.  
  196. if (isset( $CFG['user_details'][$column_value] )) {
  197. if (!$return_column_name) {
  198. return $CFG['user_details'][$column_value];
  199. }
  200.  
  201. if (isset( $CFG['user_details'][$column_value][$return_column_name] )) {
  202. return $CFG['user_details'][$column_value][$return_column_name];
  203. }
  204. }
  205.  
  206. return false;
  207. }
  208.  
  209. function getUserActions($usr_type) {
  210. global $CFG;
  211. global $db;
  212.  
  213. $field_values = array( );
  214.  
  215. if ($usr_type) {
  216. $sql = 'SELECT type_name, type_actions FROM ' . $CFG['db']['tbl']['user_type_settings'] . ' WHERE type_id = ' . $db->Param( $usr_type ) . ' AND type_status = \'Active\'';
  217. $field_values = array( $usr_type );
  218. } else {
  219. $sql = 'SELECT type_name, type_actions FROM ' . $CFG['db']['tbl']['user_type_settings'] . ' WHERE default_type = \'Yes\' LIMIT 0, 1';
  220. }
  221.  
  222. $stmt = $db->Prepare( $sql );
  223. $rs = $db->Execute( $stmt, $field_values );
  224.  
  225. if (!$rs) {
  226. trigger_db_error( $db );
  227. }
  228.  
  229. $user_actions = array( );
  230.  
  231. if ($row = $rs->FetchRow( )) {
  232. $row['type_actions'] = unserialize( $row['type_actions'] );
  233. $user_actions = $row;
  234. }
  235.  
  236. return $user_actions;
  237. }
  238.  
  239. function checkUserPermission($user_actions, $action, $sub_actions = '') {
  240. if ($sub_actions) {
  241. if (!strpos( $sub_actions, ',' )) {
  242. if (isset( $user_actions['type_actions'][$action][$sub_actions] )) {
  243. return ($user_actions['type_actions'][$action][$sub_actions] != '' ? true : false);
  244. }
  245. } else {
  246. $sub_actions = explode( ', ', $sub_actions );
  247.  
  248. foreach ($sub_actions as $sub_action) {
  249. if (isset( $user_actions['type_actions'][$action][$sub_action] )) {
  250. if ($user_actions['type_actions'][$action][$sub_action] != '') {
  251. return true;
  252. }
  253.  
  254. continue;
  255. }
  256. }
  257.  
  258. return false;
  259. }
  260. }
  261.  
  262. if (( !$sub_actions && isset( $user_actions['type_actions'][$action] ) )) {
  263. return (is_array( $user_actions['type_actions'][$action] ) ? true : $user_actions['type_actions'][$action]);
  264. }
  265.  
  266. return false;
  267. }
  268.  
  269. function postForm($url, $post_value) {
  270. $ch = curl_init( );
  271. curl_setopt( $ch, CURLOPT_URL, $url );
  272. curl_setopt( $ch, CURLOPT_POST, 1 );
  273. curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_value );
  274. $result = curl_exec( $ch );
  275. curl_close( $ch );
  276. }
  277.  
  278. function chkIsSiteUnderMaintenance() {
  279. global $CFG;
  280.  
  281. if (!isAdmin( )) {
  282. $currentPage = strtolower( $CFG['html']['current_script_name'] );
  283.  
  284. if (( $CFG['admin']['module']['site_maintenance'] && $currentPage != 'maintenance' )) {
  285. $_SESSION = array( );
  286.  
  287. if (isset( $_COOKIE[session_name( )] )) {
  288. setcookie( session_name( ), '', time( ) - 42000, '/' );
  289. }
  290.  
  291. session_destroy( );
  292. session_write_close( );
  293. setcookie( $CFG['cookie']['starting_text'] . '_bba', '', time( ) - 42000, '/' );
  294. $murl = getUrl( $CFG['redirect']['maintenance_module_url']['file_name'], $CFG['redirect']['maintenance_module_url']['normal'], $CFG['redirect']['maintenance_module_url']['htaccess'], 'root' );
  295. $CFG['site']['current_url'];
  296.  
  297. if ($CFG['site']['current_url'] != $murl) {
  298. Redirect2Url( $murl );
  299. exit( );
  300. return null;
  301. }
  302. }
  303. } else {
  304. $value_array = explode( '/', $CFG['site']['relative_url'] );
  305.  
  306. if (( !in_array( 'admin', $value_array ) && $CFG['admin']['module']['site_maintenance'] )) {
  307. $admin_url = $CFG['site']['url'] . 'admin/index.php';
  308. Redirect2URL( $admin_url );
  309. }
  310. }
  311.  
  312. }
  313.  
  314. function chkIsAllowedCountry() {
  315. global $CFG;
  316.  
  317. $country_code = apache_note( 'GEOIP_COUNTRY_CODE' );
  318.  
  319. if (in_array( $country_code, $CFG['admin']['geo_country'] )) {
  320. return false;
  321. }
  322.  
  323. return true;
  324. }
  325.  
  326. function findinside($start, $end, $string) {
  327. preg_match_all( '/' . preg_quote( $start, '/' ) . '([^\.)]+)' . preg_quote( $end, '/' ) . '/i', $string, $m );
  328. return $m[1];
  329. }
  330.  
  331. function MatchPattern($PATTERN = '', $CONTENT = '', $KEY = '') {
  332. if (( $PATTERN && $CONTENT )) {
  333. preg_match_all( $PATTERN, $CONTENT, $Match );
  334. }
  335.  
  336. if ($KEY != '') {
  337. return $Match[$KEY];
  338. }
  339.  
  340. return $Match;
  341. }
  342.  
  343. function DISP_IMAGE($cfg_width = 0, $cfg_height = 0, $img_width = 0, $img_height = 0) {
  344. if (( ( ( 0 < $cfg_width && 0 < $cfg_height ) && $cfg_width < $img_width ) && $cfg_height < $img_height )) {
  345. $tmpHeight = $cfg_width / $img_width * $img_height;
  346.  
  347. if ($tmpHeight <= $cfg_height) {
  348. $attr = ' width="' . $cfg_width . '"';
  349. } else {
  350. $height = $tmpHeight - ( $tmpHeight - $cfg_height );
  351. $attr = ' height="' . $height . '"';
  352. }
  353. } else {
  354. if (( 0 < $cfg_width && $cfg_width < $img_width )) {
  355. $attr = ' width="' . $cfg_width . '"';
  356. } else {
  357. if (( 0 < $cfg_height && $cfg_height < $img_height )) {
  358. $attr = ' height="' . $cfg_height . '"';
  359. } else {
  360. $attr = '';
  361. }
  362. }
  363. }
  364.  
  365. return $attr;
  366. }
  367.  
  368. function word_limiter($str, $limit = 100, $end_char = '&#8230;') {
  369. if (trim( $str ) == '') {
  370. return $str;
  371. }
  372.  
  373. preg_match( '/^\s*+(?:\S++\s*+){1,' . (int)$limit . '}/', $str, $matches );
  374.  
  375. if (strlen( $str ) == strlen( $matches[0] )) {
  376. $end_char = '';
  377. }
  378.  
  379. return rtrim( $matches[0] ) . $end_char;
  380. }
  381.  
  382. function character_limiter($str, $n = 500, $end_char = '&#8230;') {
  383. if (strlen( $str ) < $n) {
  384. return $str;
  385. }
  386.  
  387. $str = preg_replace( '/\s+/', ' ', preg_replace( '/(
  388. |
  389. |
  390. )/', ' ', $str ) );
  391.  
  392. if (strlen( $str ) <= $n) {
  393. return $str;
  394. }
  395.  
  396. $out = '';
  397.  
  398. foreach (explode( ' ', trim( $str ) ) as $val) {
  399. $out .= $val . ' ';
  400.  
  401. if ($n <= strlen( $out )) {
  402. return trim( $out ) . $end_char;
  403. }
  404. }
  405.  
  406. }
  407.  
  408. function word_censor($str, $censored, $replacement = '') {
  409. if (!is_array( $censored )) {
  410. return $str;
  411. }
  412.  
  413. $str = ' ' . $str . ' ';
  414.  
  415. foreach ($censored as $badword) {
  416. if ($replacement != '') {
  417. $str = preg_replace( '/\b(' . str_replace( '\*', '\w*?', preg_quote( $badword ) ) . ')\b/i', $replacement, $str );
  418. continue;
  419. }
  420.  
  421. $str = preg_replace( '/\b(' . str_replace( '\*', '\w*?', preg_quote( $badword ) ) . ')\b/ie', 'str_repeat(\'#\', strlen(\'\1\'))', $str );
  422. }
  423.  
  424. return trim( $str );
  425. }
  426.  
  427. function highlight_code(&$str) {
  428. $str = str_replace( array( '&lt;', '&gt;' ), array( '<', '>' ), $str );
  429. $str = str_replace( array( '<?', '?>', '<%', '%>', '\', '</script>' ), array( 'phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose' ), $str );
  430. $str = '<?php tempstart' . '
  431. ' . $str . 'tempend ?>';
  432. $str = highlight_string( $str, TRUE );
  433.  
  434. if (abs( phpversion( ) ) < 5) {
  435. $str = str_replace( array( '<font ', ',', ',', ',', ',', '</font>' ), array( '<span ', ',', ',', ',', ',', '</span>' ), $str );
  436. $str = preg_replace( '#color="(.*?)"#', 'style="color: \1"', $str );
  437. }
  438.  
  439. $str = preg_replace( '#\<code\>.+?tempstart\<br />(?:\</span\>)?#is', '<code>
  440. ', $str );
  441. $str = preg_replace( '#tempend.+#is', '</span>
  442. </code>', $str );
  443. $str = str_replace( array( 'phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose' ), array( '&lt;?', '?&gt;', '&lt;%', '%&gt;', '\', '&lt;/script&gt;' ), $str );
  444. return $str;
  445. }
  446.  
  447. function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>') {
  448. if ($str == '') {
  449. return '';
  450. }
  451.  
  452. if ($phrase != '') {
  453. return preg_replace( '/(' . preg_quote( $phrase, '/' ) . ')/i', $tag_open . '\1' . $tag_close, $str );
  454. }
  455.  
  456. return $str;
  457. }
  458.  
  459. function word_wrap($str, $charlim = '76') {
  460. if (!is_numeric( $charlim )) {
  461. $charlim = 76;
  462. }
  463.  
  464. $str = preg_replace( '| +|', ' ', $str );
  465. $str = preg_replace( '/
  466. |
  467. /', '
  468. ', $str );
  469. $unwrap = array( );
  470.  
  471. if (preg_match_all( '|(\{unwrap\}.+?\{/unwrap\})|s', $str, $matches )) {
  472. $i = 0;
  473.  
  474. while ($i < count( $matches['0'] )) {
  475. $unwrap[] = $matches['1'][$i];
  476. $str = str_replace( $matches['1'][$i], '{{unwrapped' . $i . '}}', $str );
  477. ++$i;
  478. }
  479. }
  480.  
  481. $str = wordwrap( $str, $charlim, '
  482. ', FALSE );
  483. $output = '';
  484.  
  485. foreach (explode( '
  486. ', $str ) as $line) {
  487. if (strlen( $line ) <= $charlim) {
  488. $output .= $line . '
  489. ';
  490. continue;
  491. }
  492.  
  493. $temp = '';
  494.  
  495. while ($charlim < strlen( $line )) {
  496. if (preg_match( '!\[url.+\]|://|wwww.!', $line )) {
  497. break;
  498. }
  499.  
  500. $temp .= substr( $line, 0, $charlim - 1 );
  501. $line = substr( $line, $charlim - 1 );
  502. }
  503.  
  504.  
  505. if ($temp != '') {
  506. $output .= $temp . '
  507. ' . $line;
  508. } else {
  509. $output .= $line;
  510. }
  511.  
  512. $output .= '
  513. ';
  514. }
  515.  
  516.  
  517. if (0 < count( $unwrap )) {
  518. foreach ($unwrap as $key => $val) {
  519. $output = str_replace( '{{unwrapped' . $key . '}}', $val, $output );
  520. }
  521. }
  522.  
  523. $output = str_replace( array( '{unwrap}', '{/unwrap}' ), '', $output );
  524. return $output;
  525. }
  526.  
  527. function stripSpecifiedTag($str, $tags) {
  528. if (!is_array( $tags )) {
  529. $tags = (stripos( $str, '>' ) !== false ? explode( '>', str_ireplace( '<', '', $tags ) ) : array( $tags ));
  530.  
  531. if (end( $tags ) == '') {
  532. array_pop( $tags );
  533. }
  534. }
  535.  
  536.  
  537. foreach ($tags as $tag) {
  538. $str = preg_replace( '#</?' . $tag . '[^>]*>#is', '', $str );
  539. }
  540.  
  541. return $str;
  542. }
  543.  
  544. function directory_map($source_dir, $top_level_only = FALSE) {
  545. if ($fp = @opendir( $source_dir )) {
  546. $filedata = array( );
  547.  
  548. while (FALSE !== $file = readdir( $fp )) {
  549. if (( ( @is_dir( $source_dir . $file ) && substr( $file, 0, 1 ) != '.' ) && $top_level_only == FALSE )) {
  550. $temp_array = array( );
  551. $temp_array = directory_map( $source_dir . $file . '/' );
  552. $filedata[$file] = $temp_array;
  553. continue;
  554. }
  555.  
  556. if (substr( $file, 0, 1 ) != '.') {
  557. $filedata[] = $file;
  558. continue;
  559. }
  560. }
  561.  
  562. return $filedata;
  563. }
  564.  
  565. }
  566.  
  567. function read_file($file) {
  568. if (!file_exists( $file )) {
  569. return FALSE;
  570. }
  571.  
  572. if (function_exists( 'file_get_contents' )) {
  573. return file_get_contents( $file );
  574. }
  575.  
  576. if (!$fp = @fopen( $file, 'rb' )) {
  577. return FALSE;
  578. }
  579.  
  580. flock( $fp, LOCK_SH );
  581. $data = '';
  582.  
  583. if (0 < filesize( $file )) {
  584. $data = &fread( $fp, filesize( $file ) );
  585. }
  586.  
  587. flock( $fp, LOCK_UN );
  588. fclose( $fp );
  589. return $data;
  590. }
  591.  
  592. function write_file($path, $data, $mode = 'w+') {
  593. if (!$fp = @fopen( $path, $mode )) {
  594. return FALSE;
  595. }
  596.  
  597. flock( $fp, LOCK_EX );
  598. fwrite( $fp, $data );
  599. @chmod( $path, 511 );
  600. flock( $fp, LOCK_UN );
  601. fclose( $fp );
  602. return TRUE;
  603. }
  604.  
  605. function readDirectory($dir_path, $return = 'both') {
  606. $return_arr = array( );
  607.  
  608. if (is_dir( $dir_path )) {
  609. if ($handle = opendir( $dir_path )) {
  610. while (false !== $file = readdir( $handle )) {
  611. if (( ( $file != '.' && $file != '..' ) && $file != '.svn' )) {
  612. if (( ( ( is_file( $dir_path . $file ) && $return == 'file' ) || ( is_dir( $dir_path . $file ) && $return == 'dir' ) ) || $return == 'both' )) {
  613. $return_arr[] = $file;
  614. continue;
  615. }
  616.  
  617. continue;
  618. }
  619. }
  620.  
  621. closedir( $handle );
  622. }
  623. }
  624.  
  625. return $return_arr;
  626. }
  627.  
  628. function force_download($filename = '', &$data = '') {
  629. global $CFG;
  630.  
  631. if (( $filename == '' || $data == '' )) {
  632. return FALSE;
  633. }
  634.  
  635. if (FALSE === strpos( $filename, '.' )) {
  636. return FALSE;
  637. }
  638.  
  639. $x = explode( '.', $filename );
  640. $extension = end( $x );
  641. @include( $CFG['site']['project_path'] . 'common/configs/config_mimes.inc..php' );
  642.  
  643. if (!isset( $mimes[$extension] )) {
  644. $mime = 'application/octet-stream';
  645. } else {
  646. $mime = (is_array( $mimes[$extension] ) ? $mimes[$extension][0] : $mimes[$extension]);
  647. }
  648.  
  649.  
  650. if (strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' )) {
  651. header( 'Content-Type: "' . $mime . '"' );
  652. header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
  653. header( 'Expires: 0' );
  654. header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
  655. header( 'Content-Transfer-Encoding: binary' );
  656. header( 'Pragma: public' );
  657. header( 'Content-Length: ' . strlen( $data ) );
  658. } else {
  659. header( 'Content-Type: "' . $mime . '"' );
  660. header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
  661. header( 'Content-Transfer-Encoding: binary' );
  662. header( 'Expires: 0' );
  663. header( 'Pragma: no-cache' );
  664. header( 'Content-Length: ' . strlen( $data ) );
  665. }
  666.  
  667. echo $data;
  668. }
  669.  
  670. function strip_slashes($str) {
  671. if (is_array( $str )) {
  672. foreach ($str as $key => $val) {
  673. $str[$key] = strip_slashes( $val );
  674. }
  675. } else {
  676. $str = stripslashes( $str );
  677. }
  678.  
  679. return $str;
  680. }
  681.  
  682. function isCronRunning($script_name = '') {
  683. global $CFG;
  684.  
  685. if (strstr( $CFG['site']['url'], '/localhost/' )) {
  686. return false;
  687. }
  688.  
  689. $max_cron_allowed = 1;
  690. $cronRunning = false;
  691.  
  692. if ($script_name) {
  693. $command = ' ps -eaf | grep ' . $script_name;
  694. $result = @shell_exec( $command );
  695. $scriptCount = intval( @substr_count( $result, $script_name ) );
  696. $max_cron_allowed = $max_cron_allowed + 3;
  697. $cronRunning = $max_cron_allowed <= $scriptCount;
  698. }
  699.  
  700. return $cronRunning;
  701. }
  702.  
  703. function callMultipleCronCheck() {
  704. global $CFG;
  705.  
  706. $cronUrl = $CFG['site']['current_url'];
  707. $time = date( 'd-m-y H:i:s' );
  708. print ( '' . '
  709. CRON: ' . $cronUrl . ':
  710. TIME:' . $time . '
  711. ' );
  712.  
  713. if (isCronRunning( $cronUrl )) {
  714. print '' . 'CRON : ' . $cronUrl . '
  715. TIME:' . $cronUrl . '
  716. Concurrent Process Detected
  717. So Skipping ' . $cronUrl . ' CRON at ' . date( 'd-M-y H:i:s' ) . '
  718.  
  719. ';
  720. exit( );
  721. }
  722.  
  723. }
  724.  
  725. function getMD5Text($text, $count = 15) {
  726. $text = md5( $text );
  727. return substr( $text, 0, $count - 1 );
  728. }
  729.  
  730. function doEncode($text, $size = 0) {
  731. $text = str_pad( $text, $size, '0', STR_PAD_LEFT );
  732. $text = base64_encode( $text );
  733. $text = urlencode( $text );
  734. return $text;
  735. }
  736.  
  737. function doDecode($text) {
  738. $text = urldecode( $text );
  739. $text = base64_decode( $text );
  740. return $text;
  741. }
  742.  
  743. function getTimeDiffInSeconds($date) {
  744. global $CFG;
  745. global $db;
  746.  
  747. $sql = 'SELECT TIMEDIFF(NOW(), \'' . $date . '\') AS date_added';
  748. $stmt = $db->Prepare( $sql );
  749. $rs = $db->Execute( $stmt );
  750.  
  751. if (!$rs) {
  752. trigger_db_error( $db );
  753. }
  754.  
  755. $row = $rs->FetchRow( );
  756. return $row['date_added'];
  757. }
  758.  
  759. function getDateTimeDiff($date, &$today) {
  760. list( $year, $month, $day, $hrs, $min, $sec ) = split( '[ \:-]', $date );
  761. list( $year1, $month1, $day1, $hrs1, $min1, $sec1 ) = split( '[ \:-]', $today );
  762. $secs = mktime( $hrs1, $min1, $sec1, $month1, $day1, $year1 ) - mktime( $hrs, $min, $sec, $month, $day, $year );
  763. $mins = floor( $secs / 60 );
  764. $hrs = floor( $mins / 60 );
  765. $secs = $secs % 60;
  766. $mins = $mins % 60;
  767. $row['date_added'] = $hrs . ':' . $mins . ':' . $secs;
  768. return ;
  769. }
  770.  
  771. function str_replace_once($needle, $replace, $haystack) {
  772. $pos = strpos( $haystack, $needle );
  773.  
  774. if ($pos === false) {
  775. return $haystack;
  776. }
  777.  
  778. return substr_replace( $haystack, $replace, $pos, strlen( $needle ) );
  779. }
  780.  
  781. function getFullTextSearchString($tags) {
  782. $tags = rawurlencode( $tags );
  783. return $tags = '[[:<:]]' . preg_replace( '/\s+/', '|', addslashes( $tags ) ) . '[[:>:]]';
  784. }
  785.  
  786. function getSearchRegularExpressionQueryForums($tags, $field_name, $extra = '') {
  787. global $CFG;
  788.  
  789. $not_allowed_search_array = $CFG['admin']['not_allowed_chars'];
  790. $tags = replaceCharacter( $not_allowed_search_array, '-', $tags );
  791. $tags = addslashes( $tags );
  792. $additional_query = ' (' . $field_name . ' REGEXP \'' . formatSearchString( $tags ) . '\') ' . $extra . ' ';
  793. return $additional_query;
  794. }
  795.  
  796. function replaceCharacter($search_value, $replace, $text) {
  797. if (is_array( $search_value )) {
  798. foreach ($search_value as $key => $value) {
  799. $text = str_replace( $value, $replace, $text );
  800. }
  801.  
  802. return $text;
  803. }
  804.  
  805. return str_replace( $char, $replace, $text );
  806. }
  807.  
  808. function formatSearchString($tags) {
  809. return $tags = '[[:<:]]' . preg_replace( '/\s+/', '|', $tags ) . '[[:>:]]';
  810. }
  811.  
  812. function getSearchRegularExpressionQuery($tags, $field_name, $extra = '') {
  813. global $CFG;
  814.  
  815. $tags = addslashes( $tags );
  816.  
  817. if ($CFG['admin']['search']['regular_expression']) {
  818. $additional_query = ' (' . $field_name . ' REGEXP \'' . getFullTextSearchString( $tags ) . '\') ' . $extra . ' ';
  819. } else {
  820. $additional_query = ' MATCH(' . $field_name . ') AGAINST (\'' . $tags . '\' IN BOOLEAN MODE) ' . $extra . ' ';
  821. }
  822.  
  823. return $additional_query;
  824. }
  825.  
  826. function createMultiLevelFolder($folderName) {
  827. $folder_arr = explode( '/', $folderName );
  828. $folderName = '';
  829.  
  830. foreach ($folder_arr as $key => $value) {
  831. $folderName .= $value . '/';
  832.  
  833. if (( $value == '..' || $value == '.' )) {
  834. continue;
  835. }
  836.  
  837. if (!is_dir( $folderName )) {
  838. mkdir( $folderName );
  839. @chmod( $folderName, 511 );
  840. continue;
  841. }
  842. }
  843.  
  844. }
  845.  
  846. function removeDirectory($dirname) {
  847. if (is_dir( $dirname )) {
  848. $result = array( );
  849.  
  850. if (substr( $dirname, 0 - 1 ) != '/') {
  851. $dirname .= '/';
  852. }
  853.  
  854. $handle = opendir( $dirname );
  855.  
  856. while (false !== $file = readdir( $handle )) {
  857. if (( $file != '.' && $file != '..' )) {
  858. $path = $dirname . $file;
  859.  
  860. if (is_dir( $path )) {
  861. $result = array_merge( $result, removeDirectory( $path ) );
  862. continue;
  863. }
  864.  
  865. unlink( $path );
  866. $result-> .= $path;
  867. continue;
  868. }
  869. }
  870.  
  871. closedir( $handle );
  872. rmdir( $dirname );
  873. $result-> .= $dirname;
  874. return $result;
  875. }
  876.  
  877. return false;
  878. }
  879.  
  880. function setHeaderStart($check_login = false) {
  881. global $CFG;
  882.  
  883. ob_start( );
  884. header( 'Pragma: no-cache' );
  885. header( 'Cache-Control: no-cache, must-revalidate' );
  886. header( 'Expires: 0' );
  887. header( 'Content-type: text/css; charset="' . $CFG['site']['charset'] . '"' );
  888. }
  889.  
  890. function setHeaderEnd() {
  891. ob_end_flush( );
  892. }
  893.  
  894. function chkIsValidUrlUsingCurl($url) {
  895. if (!strstr( $url, '://' )) {
  896. $url = 'http://' . $url;
  897. }
  898.  
  899. if (function_exists( 'curl_init' )) {
  900. $ch = @curl_init( );
  901.  
  902. if ($ch) {
  903. curl_setopt( $ch, CURLOPT_URL, $url );
  904. curl_setopt( $ch, CURLOPT_HEADER, 0 );
  905. curl_setopt( $ch, CURLOPT_NOBODY, 1 );
  906. curl_setopt( $ch, CURLOPT_RANGE, '0-1' );
  907. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 0 );
  908. curl_setopt( $ch, CURLOPT_TIMEOUT, 10 );
  909. $result = curl_exec( $ch );
  910. $errno = curl_errno( $ch );
  911. curl_close( $ch );
  912.  
  913. if ($errno != 0) {
  914. return false;
  915. }
  916. }
  917. }
  918.  
  919. return true;
  920. }
  921.  
  922. function getContents($url) {
  923. $result = '';
  924.  
  925. if (!strstr( $url, '://' )) {
  926. $url = 'http://' . $url;
  927. }
  928.  
  929. if (function_exists( 'curl_init' )) {
  930. $ch = curl_init( $url );
  931. curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
  932. curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2' );
  933. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  934. $result = curl_exec( $ch );
  935.  
  936. if (!curl_errno( $ch )) {
  937. curl_close( $ch );
  938. } else {
  939. $result = false;
  940. }
  941. } else {
  942. set_time_limit( 180 );
  943. $result = file_get_contents( $url );
  944. }
  945.  
  946. return $result;
  947. }
  948.  
  949. function setFontSizeForTagCloud($tag_array = array( )) {
  950. $formattedArray = $tag_array;
  951. $max_qty = max( array_values( $formattedArray ) );
  952. $min_qty = min( array_values( $formattedArray ) );
  953. $max_font_size = 28;
  954. $min_font_size = 12;
  955. $spread = $max_qty - $min_qty;
  956.  
  957. if (0 == $spread) {
  958. $spread = 1;
  959. }
  960.  
  961. $step = ( $max_font_size - $min_font_size ) / $spread;
  962.  
  963. foreach ($tag_array as $catname => $count) {
  964. $size = $min_font_size + ( $count - $min_qty ) * $step;
  965. $formattedArray[$catname] = ceil( $size );
  966. }
  967.  
  968. return $formattedArray;
  969. }
  970.  
  971. function setTemplateFolder($template_for = '', $module = '') {
  972. global $smartyObj;
  973. global $CFG;
  974.  
  975. $smartyObj->config_dir = $CFG['site']['project_path'] . 'design/templates/' . $CFG['html']['template']['default'] . '/configs/';
  976.  
  977. if ($module) {
  978. if ($template_for == 'admin/') {
  979. $smartyObj->template_dir = $CFG['site']['project_path'] . '/design/templates/default/' . $template_for . $module . '/';
  980. $smartyObj->compile_dir = $CFG['site']['project_path'] . '/design/templates/default/' . getTplFolder( ) . $module . '/templates_c/';
  981. $smartyObj->css_path = $CFG['site']['url'] . '/design/templates/default/' . $template_for . $module . '/css/' . $CFG['html']['stylesheet']['screen']['default'] . '/';
  982. } else {
  983. if (isAdmin( )) {
  984. $smartyObj->template_dir = $CFG['site']['project_path'] . $module . '/design/templates/' . $CFG['html']['template']['default'] . '/' . $template_for;
  985. $smartyObj->compile_dir = $CFG['site']['project_path'] . $module . '/design/templates/' . $CFG['html']['template']['default'] . '/members/templates_c/';
  986. $smartyObj->css_path = $CFG['site']['url'] . $module . '/design/templates/' . $CFG['html']['template']['default'] . '/' . $template_for . 'css/' . $CFG['html']['stylesheet']['screen']['default'] . '/';
  987. } else {
  988. $smartyObj->template_dir = $CFG['site']['project_path'] . $module . '/design/templates/' . $CFG['html']['template']['default'] . '/' . $template_for;
  989. $smartyObj->compile_dir = $CFG['site']['project_path'] . $module . '/design/templates/' . $CFG['html']['template']['default'] . '/' . getTplFolder( ) . 'templates_c/';
  990. $smartyObj->css_path = $CFG['site']['url'] . $module . '/design/templates/' . $CFG['html']['template']['default'] . '/' . $template_for . 'css/' . $CFG['html']['stylesheet']['screen']['default'] . '/';
  991. }
  992.  
  993.  
  994. if (( isAdmin( ) && 0 < strpos( $CFG['site']['relative_url'], 'admin/' ) )) {
  995. $smartyObj->template_dir = $CFG['site']['project_path'] . '/design/templates/default/' . $template_for;
  996. $smartyObj->compile_dir = $CFG['site']['project_path'] . '/design/templates/default' . '/' . getTplFolder( ) . '/templates_c/';
  997. $smartyObj->css_path = $CFG['site']['url'] . '/design/templates/default' . '/' . $template_for . '/css/' . $CFG['html']['stylesheet']['screen']['default'] . '/';
  998. } else {
  999. if (!is_dir( $smartyObj->template_dir )) {
  1000. foreach ($CFG['html']['template']['allowed'] as $available_template) {
  1001. $available_template_dir = $CFG['site']['project_path'] . $module . '/design/templates/' . $available_template . '/' . $template_for;
  1002.  
  1003. if (is_dir( $available_template_dir )) {
  1004. foreach ($CFG['html']['stylesheet'][$available_template]['allowed'] as $available_css) {
  1005. $available_css_path = $CFG['site']['project_path'] . $module . '/design/templates/' . $available_template . '/root/css/' . $available_css . '/';
  1006.  
  1007. if (is_dir( $available_css_path )) {
  1008. $smartyObj->template_dir = $available_template_dir;
  1009. $smartyObj->compile_dir = $CFG['site']['project_path'] . $module . '/design/templates/' . $available_template . '/' . getTplFolder( ) . 'templates_c/';
  1010. $smartyObj->css_path = $CFG['site']['url'] . $module . '/design/templates/' . $available_template . '/' . $template_for . 'css/' . $available_css . '/';
  1011. break;
  1012. }
  1013. }
  1014.  
  1015. continue;
  1016. }
  1017. }
  1018. }
  1019. }
  1020. }
  1021. } else {
  1022. $smartyObj->template_dir = $CFG['site']['project_path'] . 'design/templates/' . $CFG['html']['template']['default'] . '/' . $template_for;
  1023. $smartyObj->compile_dir = $CFG['site']['project_path'] . 'design/templates/' . $CFG['html']['template']['default'] . '/' . getTplFolder( ) . 'templates_c/';
  1024. $smartyObj->css_path = $CFG['site']['url'] . 'design/templates/' . $CFG['html']['template']['default'] . '/' . $template_for . 'css/' . $CFG['html']['stylesheet']['screen']['default'] . '/';
  1025.  
  1026. if ($template_for == 'admin/') {
  1027. $smartyObj->template_dir = $CFG['site']['project_path'] . '/design/templates/default/' . $template_for;
  1028. $smartyObj->compile_dir = $CFG['site']['project_path'] . '/design/templates/default' . '/' . getTplFolder( ) . '/templates_c/';
  1029. $smartyObj->css_path = $CFG['site']['url'] . '/design/templates/default' . '/' . $template_for . '/css/' . $CFG['html']['stylesheet']['screen']['default'] . '/';
  1030. } else {
  1031. if (!empty( $CFG['site']['is_module_page'] )) {
  1032. $template_dir_module = $CFG['site']['project_path'] . $CFG['site']['is_module_page'] . '/design/templates/' . $CFG['html']['template']['default'] . '/' . $template_for;
  1033.  
  1034. if (( isAdmin( ) && 0 < strpos( $CFG['site']['relative_url'], 'admin/' ) )) {
  1035. $smartyObj->template_dir = $CFG['site']['project_path'] . '/design/templates/default/' . $template_for;
  1036. $smartyObj->compile_dir = $CFG['site']['project_path'] . '/design/templates/default' . '/' . getTplFolder( ) . '/templates_c/';
  1037. $smartyObj->css_path = $CFG['site']['url'] . '/design/templates/default' . '/' . $template_for . '/css/' . $CFG['html']['stylesheet']['screen']['default'] . '/';
  1038. } else {
  1039. if (!is_dir( $template_dir_module )) {
  1040. foreach ($CFG['html']['template']['allowed'] as $available_template) {
  1041. $available_template_dir = $CFG['site']['project_path'] . $CFG['site']['is_module_page'] . '/design/templates/' . $available_template . '/' . $template_for;
  1042.  
  1043. if (is_dir( $available_template_dir )) {
  1044. $CFG['html']['template']['default'] = $available_template;
  1045.  
  1046. foreach ($CFG['html']['stylesheet'][$available_template]['allowed'] as $available_css) {
  1047. $available_css_path = $CFG['site']['project_path'] . $CFG['site']['is_module_page'] . '/design/templates/' . $available_template . '/root/css/' . $available_css . '/';
  1048.  
  1049. if (is_dir( $available_css_path )) {
  1050. $CFG['html']['stylesheet']['screen']['default'] = $available_css;
  1051. $smartyObj->template_dir = $CFG['site']['project_path'] . 'design/templates/' . $available_template . '/' . $template_for;
  1052. $smartyObj->compile_dir = $CFG['site']['project_path'] . 'design/templates/' . $available_template . '/' . getTplFolder( ) . 'templates_c/';
  1053. $smartyObj->css_path = $CFG['site']['url'] . 'design/templates/' . $available_template . '/' . $template_for . 'css/' . $available_css . '/';
  1054. break;
  1055. }
  1056. }
  1057.  
  1058. continue;
  1059. }
  1060. }
  1061. }
  1062. }
  1063. }
  1064. }
  1065. }
  1066.  
  1067. $smartyObj->cache_dir = $CFG['site']['project_path'] . 'design/templates/' . $CFG['html']['template']['default'] . '/' . getTplFolder( ) . 'cache/';
  1068. $image_path = $CFG['site']['url'] . 'design/templates/' . $CFG['html']['template']['default'] . '/root/images/' . $CFG['html']['stylesheet']['screen']['default'] . '/';
  1069. $smartyObj->assign( 'html_stylesheet', $smartyObj->css_path . $CFG['html']['stylesheet']['screen']['default_file'] . '.css' );
  1070. $smartyObj->css_defalut_path = $smartyObj->css_path . $CFG['html']['stylesheet']['screen']['default_file'] . '.css';
  1071. $smartyObj->assign( 'images_path', $image_path );
  1072. $smartyObj->assign( 'html_stylesheet_path', $smartyObj->css_path );
  1073. }
  1074.  
  1075. function URL($url) {
  1076. return $url;
  1077. }
  1078.  
  1079. function isAjaxPage() {
  1080. return ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' );
  1081. }
  1082.  
  1083. function ShowHelpTip($tip_key, $tipfor = '') {
  1084. global $LANG;
  1085. global $CFG;
  1086.  
  1087. $tipfor = ($tipfor ? $tipfor : $tip_key);
  1088. $tip = str_replace( '
  1089. ', '&#13;', $LANG['help'][$tip_key] );
  1090. echo '<div class="clsHelpText" id="';
  1091. echo $tipfor;
  1092. echo '_Help" style="visibility:hidden">';
  1093. echo $tip;
  1094. echo '</div>
  1095. ';
  1096. }
  1097.  
  1098. function isAjax() {
  1099. return ( ( isset( $_REQUEST['ajax_page'] ) && $_REQUEST['ajax_page'] == true ) || ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) );
  1100. }
  1101.  
  1102. function FMT_DATE($date) {
  1103. return $date;
  1104. }
  1105.  
  1106. function FMT_AMOUNT($amount) {
  1107. global $CFG;
  1108.  
  1109. $exponent = pow( 10, $CFG['framework']['no_of_decimals'] );
  1110. return floor( $amount * $exponent ) / $exponent;
  1111. }
  1112.  
  1113. function ExposeQuery($msg, $newline = '') {
  1114. global $SQL_QUERIES;
  1115.  
  1116. $SQL_QUERIES .= '
  1117. ' . $msg . '
  1118. ';
  1119. }
  1120.  
  1121. function DEBUG($var_name, $var_desc = '') {
  1122. global $CFG;
  1123. global $DEBUG_TRACE;
  1124.  
  1125. if ($CFG['debug']['is_debug_mode']) {
  1126. $DEBUG_TRACE .= '
  1127. ' . $var_desc . ':';
  1128.  
  1129. if (!is_array( $var_name )) {
  1130. $var_name = htmlspecialchars( $var_name );
  1131. }
  1132.  
  1133. $DEBUG_TRACE .= print_r( $var_name, true );
  1134.  
  1135. if (is_array( $var_name )) {
  1136. reset( $var_name );
  1137. }
  1138.  
  1139. $DEBUG_TRACE .= '
  1140. ';
  1141. }
  1142.  
  1143. }
  1144.  
  1145. function Redirect2URL($url) {
  1146. global $CFG;
  1147.  
  1148. if (( isAjaxPage( ) || $CFG['admin']['session_redirect_light_window_page'] )) {
  1149. if (!isMember( )) {
  1150. unset( $_SESSION[url] );
  1151. $param = '';
  1152. $url = getUrl( 'login' ) . $param;
  1153. }
  1154. }
  1155.  
  1156. if (!headers_sent( )) {
  1157. header( 'Location: ' . URL( $url ) );
  1158.  
  1159. if (stristr( $_SERVER['SERVER_SIGNATURE'], 'IIS' )) {
  1160. header( 'Refresh: 0;url=' . $url );
  1161. }
  1162. } else {
  1163. trigger_error( 'Headers already sent', E_USER_NOTICE );
  1164. echo '<meta http-equiv="refresh" content="0; URL=' . URL( $url ) . '" />' . '
  1165. ';
  1166. echo '<p>Please click this <a href="' . URL( $url ) . '">link</a> to continue...</p>' . '
  1167. ';
  1168. }
  1169.  
  1170. exit( 0 );
  1171. }
  1172.  
  1173. function getAdvertisement($block, &$not_allowed_page_name = array( )) {
  1174. global $CFG;
  1175. global $db;
  1176. global $______ADVERTISEMENT_ID;
  1177.  
  1178. $block_condition = '';
  1179.  
  1180. if (!chkAllowedModule( array( 'banner' ) )) {
  1181. return null;
  1182. }
  1183.  
  1184. $cur_page_name = strtolower( basename( $_SERVER['SCRIPT_NAME'], '.php' ) );
  1185.  
  1186. if (( 0 < sizeof( $not_allowed_page_name ) && in_array( $cur_page_name, $not_allowed_page_name ) )) {
  1187. return false;
  1188. }
  1189.  
  1190. $sql = 'SELECT add_id, source FROM ' . $CFG['db']['tbl']['advertisement'] . ' WHERE' . ' block=\'' . $block . '\'' . ' AND status=\'activate\'';
  1191.  
  1192. if ($CFG['admin']['banner']['impressions_date']) {
  1193. $sql .= ' AND NOW()>=start_date AND (((allowed_impressions!=\'\' AND allowed_impressions!=0) AND' . ' (completed_impressions < allowed_impressions)) OR ((allowed_impressions=\'\'' . ' OR allowed_impressions=0) AND (end_date!=\'0000-00-00 00:00:00\'' . ' AND end_date > NOW())))';
  1194. }
  1195.  
  1196. $stmt = $db->Prepare( $sql );
  1197. $rs = $db->Execute( $stmt, array( ) );
  1198.  
  1199. if (!$rs) {
  1200. trigger_db_error( $db );
  1201. }
  1202.  
  1203. $total_count = $rs->PO_RecordCount( );
  1204.  
  1205. if (!$total_count) {
  1206. $sql = 'SELECT add_id, source FROM ' . $CFG['db']['tbl']['advertisement'] . ' WHERE' . ' block LIKE \'%' . $block . '\'' . ' AND status=\'activate\'';
  1207.  
  1208. if ($CFG['admin']['banner']['impressions_date']) {
  1209. $sql .= ' AND NOW()>=start_date AND (((allowed_impressions!=\'\' AND allowed_impressions!=0) AND' . ' (completed_impressions < allowed_impressions)) OR ((allowed_impressions=\'\'' . ' OR allowed_impressions=0) AND (end_date!=\'0000-00-00 00:00:00\'' . ' AND end_date > NOW())))';
  1210. }
  1211.  
  1212. $stmt = $db->Prepare( $sql );
  1213. $rs = $db->Execute( $stmt );
  1214.  
  1215. if (!$rs) {
  1216. trigger_db_error( $db );
  1217. }
  1218.  
  1219. $total_count = $rs->PO_RecordCount( );
  1220. }
  1221.  
  1222. if (!$total_count) {
  1223. return false;
  1224. }
  1225. ...............................
  1226. ...................
  1227. ........
Add Comment
Please, Sign In to add comment