root/ip/tags/release_1_3_0_53/includes/functions.php

111163
564
	// Defined here to correctly assign the Language Variables and be able to change the variables within code.
564
	// Defined here to correctly assign the Language Variables and be able to change the variables within code.
565
	$nav_links['top'] = array (
565
	$nav_links['top'] = array (
566
		'url' => append_sid(PORTAL_MG),
566
		'url' => append_sid(PORTAL_MG),
567
		'title' => $board_config['sitename']
567
		'title' => ip_stripslashes($board_config['sitename'])
568
	);
568
	);
569
	$nav_links['forum'] = array (
569
	$nav_links['forum'] = array (
570
		'url' => append_sid(FORUM_MG),
570
		'url' => append_sid(FORUM_MG),
571
		'title' => sprintf($lang['Forum_Index'], $board_config['sitename'])
571
		'title' => sprintf($lang['Forum_Index'], ip_stripslashes($board_config['sitename']))
572
	);
572
	);
573
	$nav_links['search'] = array (
573
	$nav_links['search'] = array (
574
		'url' => append_sid(SEARCH_MG),
574
		'url' => append_sid(SEARCH_MG),
...
...
755
755
756
	if ($userdata['user_level'] == ADMIN)
756
	if ($userdata['user_level'] == ADMIN)
757
	{
757
	{
758
		if ($level_required == AUTH_ADMIN)
759
		{
760
			return true;
761
		}
758
		if ($level_required == AUTH_FOUNDER)
762
		if ($level_required == AUTH_FOUNDER)
759
		{
763
		{
760
			$founder_id = (defined('FOUNDER_ID') ? FOUNDER_ID : get_founder_id());
764
			$founder_id = (defined('FOUNDER_ID') ? FOUNDER_ID : get_founder_id());
761
			if ($userdata['user_id'] == $founder_id)
765
			return ($userdata['user_id'] == $founder_id) ? true : false;
762
			{
763
				return true;
764
			}
765
		}
766
		}
766
		elseif ($level_required == AUTH_MAIN_ADMIN)
767
		elseif ($level_required == AUTH_MAIN_ADMIN)
767
		{
768
		{
768
			if (defined('MAIN_ADMINS_ID'))
769
			if (defined('MAIN_ADMINS_ID'))
769
			{
770
			{
770
				$allowed_admins = explode(',', MAIN_ADMINS_ID);
771
				$allowed_admins = explode(',', MAIN_ADMINS_ID);
771
				if (in_array($userdata['user_id'], $allowed_admins))
772
				return (in_array($userdata['user_id'], $allowed_admins)) ? true : false;
772
				{
773
					return true;
774
				}
773
				}
775
			}
774
			}
776
			else
777
			{
778
				// Force to AUTH_ADMIN just in case the user have removed MAIN_ADMINS_ID from constants.php
779
				$level_required == AUTH_ADMIN;
780
			}
781
		}
782
783
		if ($level_required == AUTH_ADMIN)
784
		{
785
			return true;
786
		}
787
	}
775
	}
788
776
777
	// Force to AUTH_ADMIN since we already checked all cases for founder or main admins
789
	if (($level_required == AUTH_FOUNDER) || ($level_required == AUTH_MAIN_ADMIN))
778
	if (($level_required == AUTH_FOUNDER) || ($level_required == AUTH_MAIN_ADMIN))
790
	{
779
	{
791
		// Force to AUTH_ADMIN since we already checked all cases for founder or main admins
792
		$level_required = AUTH_ADMIN;
780
		$level_required = AUTH_ADMIN;
793
	}
781
	}
794
782
...
...
798
	// Check if the user is REG or a BOT
786
	// Check if the user is REG or a BOT
799
	$is_reg = ((($board_config['bots_reg_auth'] == true) && ($userdata['bot_id'] !== false)) || $userdata['session_logged_in']) ? true : false;
787
	$is_reg = ((($board_config['bots_reg_auth'] == true) && ($userdata['bot_id'] !== false)) || $userdata['session_logged_in']) ? true : false;
800
	$not_auth = (!$not_auth && ($level_required == AUTH_REG) && !$is_reg) ? true : $not_auth;
788
	$not_auth = (!$not_auth && ($level_required == AUTH_REG) && !$is_reg) ? true : $not_auth;
801
	$not_auth = (!$not_auth && ($level_required == AUTH_MOD) && ($userdata['user_level'] != MOD)) ? true : $not_auth;
789
	$not_auth = (!$not_auth && ($level_required == AUTH_MOD) && ($userdata['user_level'] != MOD) && ($userdata['user_level'] != ADMIN)) ? true : $not_auth;
802
	$not_auth = (!$not_auth && ($level_required == AUTH_ADMIN)) ? true : $not_auth;
790
	$not_auth = (!$not_auth && ($level_required == AUTH_ADMIN)) ? true : $not_auth;
803
	if ($not_auth)
791
	if ($not_auth)
804
	{
792
	{
...
...
1567
function cal_date($gmepoch, $tz)
1555
function cal_date($gmepoch, $tz)
1568
{
1556
{
1569
	global $board_config;
1557
	global $board_config;
1570
	return (strtotime(gmdate('M d Y H:i:s', $gmepoch + (3600 * $tz))));
1558
	return (@strtotime(gmdate('M d Y H:i:s', $gmepoch + (3600 * $tz))));
1571
}
1559
}
1572
1560
1573
/*
1561
/*
...
...
1578
{
1566
{
1579
	$org_tz = date_default_timezone_get();
1567
	$org_tz = date_default_timezone_get();
1580
	date_default_timezone_set($timezone);
1568
	date_default_timezone_set($timezone);
1581
	$date_serial = mktime($hour, $minute, 0, $month, $day, $year);
1569
	$date_serial = gmmktime($hour, $minute, 0, $month, $day, $year);
1582
	date_default_timezone_set($org_tz);
1570
	date_default_timezone_set($org_tz);
1583
	return $date_serial;
1571
	return $date_serial;
1584
}
1572
}
1585
*/
1573
*/
1586
1574
1587
// Get DST
1575
// Get DST
1588
function get_dst($gmepoch)
1576
function get_dst($gmepoch, $tz = 0)
1589
{
1577
{
1590
	global $board_config, $userdata;
1578
	global $board_config, $userdata;
1591
1579
1580
	$tz = empty($tz) ? $board_config['board_timezone'] : $tz;
1592
	if (!empty($userdata) && !$userdata['session_logged_in'])
1581
	if (!empty($userdata) && !$userdata['session_logged_in'])
1593
	{
1582
	{
1594
		$userdata['user_time_mode'] = $board_config['default_time_mode'];
1583
		$userdata['user_time_mode'] = $board_config['default_time_mode'];
...
...
1608
			$dst_sec = $dst_time_lag * 60;
1597
			$dst_sec = $dst_time_lag * 60;
1609
			break;
1598
			break;
1610
		case SERVER_SWITCH:
1599
		case SERVER_SWITCH:
1611
			$dst_sec = date('I', $gmepoch) * $dst_time_lag * 60;
1600
			//$dst_sec = gmdate('I', $gmepoch + (3600 * $tz)) * $dst_time_lag * 60;
1601
			$dst_sec = @date('I', $gmepoch) * $dst_time_lag * 60;
1612
			break;
1602
			break;
1613
		default:
1603
		default:
1614
			$dst_sec = 0;
1604
			$dst_sec = 0;
...
...
1618
}
1608
}
1619
1609
1620
// Create date/time from format and timezone
1610
// Create date/time from format and timezone
1621
function create_date($format, $gmepoch, $tz)
1611
function create_date($format, $gmepoch, $tz = 0)
1622
{
1612
{
1623
	global $board_config, $lang, $userdata;
1613
	global $board_config, $lang, $userdata;
1624
	static $translate;
1614
	static $translate;
1625
1615
1616
	$tz = empty($tz) ? $board_config['board_timezone'] : $tz;
1626
	// We need to force this ==> isset($lang['datetime']) <== otherwise we may have $lang initialized and we don't want that...
1617
	// We need to force this ==> isset($lang['datetime']) <== otherwise we may have $lang initialized and we don't want that...
1627
	if (empty($translate) && ($board_config['default_lang'] != 'english') && isset($lang['datetime']))
1618
	if (empty($translate) && ($board_config['default_lang'] != 'english') && isset($lang['datetime']))
1628
	{
1619
	{
...
...
1633
		}
1624
		}
1634
	}
1625
	}
1635
1626
1636
	$dst_sec = get_dst($gmepoch);
1627
	$dst_sec = get_dst($gmepoch, $tz);
1637
	$date = (!empty($translate) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz) + $dst_sec), $translate) : @gmdate($format, $gmepoch + (3600 * $tz) + $dst_sec));
1628
	$date = @gmdate($format, $gmepoch + (3600 * $tz) + $dst_sec);
1629
	$date = (!empty($translate) ? strtr($date, $translate) : $date);
1638
	return $date;
1630
	return $date;
1639
}
1631
}
1640
1632
1641
function create_date_ip($format, $gmepoch, $tz, $day_only = false)
1633
function create_date_ip($format, $gmepoch, $tz = 0, $day_only = false)
1642
{
1634
{
1643
	global $board_config, $lang;
1635
	global $board_config, $lang;
1644
	if (empty($board_config['time_today']) || empty($board_config['time_yesterday']))
1636
1645
	{
1637
	$tz = empty($tz) ? $board_config['board_timezone'] : $tz;
1646
		$today_ary = explode('|', create_date('m|d|Y', time(), $board_config['board_timezone']));
1638
	$dst_sec = get_dst($gmepoch, $tz);
1647
		$dst_sec = get_dst($gmepoch);
1639
	$zone_offset = (3600 * $tz) + $dst_sec;
1648
		$board_config['time_today'] = gmmktime(0, 0, 0, $today_ary[0], $today_ary[1], $today_ary[2]) - (3600 * $tz) - $dst_sec;
1640
	list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset));
1649
		$board_config['time_yesterday'] = $board_config['time_today'] - 86400;
1641
	$midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset;
1650
		unset($today_ary);
1642
1651
	}
1652
	$output_date = '';
1643
	$output_date = '';
1653
	$format_hour = 'H:i';
1644
	$format_hour = 'H:i';
1654
	if ($board_config['time_today'] < $gmepoch)
1645
	if ($gmepoch > $midnight)
1655
	{
1646
	{
1656
		$format = ($day_only) ? $format : $format_hour;
1647
		$format = ($day_only) ? $format : $format_hour;
1657
		$output_date = ($day_only) ? $lang['TODAY'] : ($lang['Today_at'] . ' ');
1648
		$output_date = ($day_only) ? $lang['TODAY'] : ($lang['Today_at'] . ' ');
1658
	}
1649
	}
1659
	elseif ($board_config['time_yesterday'] < $gmepoch)
1650
	elseif ($gmepoch > ($midnight - 86400))
1660
	{
1651
	{
1661
		$format = ($day_only) ? $format : $format_hour;
1652
		$format = ($day_only) ? $format : $format_hour;
1662
		$output_date = ($day_only) ? $lang['YESTERDAY'] : ($lang['Yesterday_at'] . ' ');
1653
		$output_date = ($day_only) ? $lang['YESTERDAY'] : ($lang['Yesterday_at'] . ' ');
...
...
1760
// Birthday - END
1751
// Birthday - END
1761
1752
1762
/*
1753
/*
1763
* Pagination routine, generates page number sequence
1754
* Pagination get the page
1764
*/
1755
*/
1765
function get_page($num_items, $per_page, $start_item)
1756
function get_page($num_items, $per_page, $start_item)
1766
{
1757
{
...
...
1785
	return $page_string;
1776
	return $page_string;
1786
}
1777
}
1787
1778
1779
/*
1780
* Pagination routine, generates page number sequence
1781
*/
1788
function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = true, $start = 'start')
1782
function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = true, $start = 'start')
1789
{
1783
{
1790
	global $lang;
1784
	global $lang;
...
...
1878
	return $page_string;
1872
	return $page_string;
1879
}
1873
}
1880
1874
1875
/**
1876
* Return current page (pagination)
1877
*/
1878
function on_page($num_items, $per_page, $start)
1879
{
1880
	global $lang;
1881
1882
	// Make sure $per_page is a valid value
1883
	$per_page = ($per_page <= 0) ? 1 : $per_page;
1884
1885
	$on_page = floor($start / $per_page) + 1;
1886
	$total_pages = ceil($num_items / $per_page);
1887
1888
	$page_number = sprintf($lang['Page_of'], $on_page, max($total_pages, 1));
1889
1890
	return $page_number;
1891
}
1892
1881
//
1893
//
1882
// This does exactly what preg_quote() does in PHP 4-ish
1894
// This does exactly what preg_quote() does in PHP 4-ish
1883
// If you just need the 1-parameter preg_quote call, then don't bother using this.
1895
// If you just need the 1-parameter preg_quote call, then don't bother using this.