Beispiel #1
0
 /**
  * Fetch notices to be displayed
  *
  * @param int $channelid Current Channel ID
  * @param array $ignore_np_notices Ignored non-persistent notice ids
  * @param boolean Whether or not to do the phrase replacement, if false, the client is responsible
  * @return array Notices
  *
  * @see fetch_relevant_notice_ids()
  */
 public function fetch($channelid = 0, $ignore_np_notices = array(), $replace_phrases = false)
 {
     if ($channelid) {
         $channelapi = vB_Api::instanceInternal('content_channel');
         // This is to verify $channelid
         $channelapi->fetchChannelById($channelid);
     }
     $noticecache = vB::getDatastore()->getValue('noticecache');
     $userinfo = vB::getCurrentSession()->fetch_userinfo();
     $vboptions = vB::getDatastore()->getValue('options');
     $display_notices = array();
     foreach ($noticecache as $noticeid => $notice) {
         foreach ($notice as $criteriaid => $conditions) {
             switch ($criteriaid) {
                 case 'persistent':
                     if ($conditions == 0 and is_array($ignore_np_notices) and in_array($noticeid, $ignore_np_notices)) {
                         continue 3;
                     }
                     break;
                 case 'dismissible':
                     if ($conditions == 1 and in_array($noticeid, $this->fetchDismissedNotices())) {
                         continue 3;
                     }
                     break;
                     /*case 'notice_x_not_displayed': // this is now handled differently - see $remove_display_notices below
                     		{
                     			if (in_array(intval($conditions[0]), $display_notices))
                     			{
                     				continue 3;
                     			}
                     			break;
                     		}*/
                 /*case 'notice_x_not_displayed': // this is now handled differently - see $remove_display_notices below
                 		{
                 			if (in_array(intval($conditions[0]), $display_notices))
                 			{
                 				continue 3;
                 			}
                 			break;
                 		}*/
                 case 'in_usergroup_x':
                     if (!is_member_of($userinfo, intval($conditions[0]))) {
                         continue 3;
                     }
                     break;
                 case 'not_in_usergroup_x':
                     if (is_member_of($userinfo, intval($conditions[0]))) {
                         continue 3;
                     }
                     break;
                 case 'browsing_forum_x':
                     if (!$channelid or $channelid != intval($conditions[0])) {
                         continue 3;
                     }
                     break;
                 case 'browsing_forum_x_and_children':
                     if (!$channelid) {
                         continue 3;
                     }
                     $parents = vB_Library::instance('node')->getParents($channelid);
                     $parentids = array();
                     foreach ($parents as $parent) {
                         if ($parent['nodeid'] != 1) {
                             $parentids[] = $parent['nodeid'];
                         }
                     }
                     if (!in_array(intval($conditions[0]), $parentids)) {
                         continue 3;
                     }
                     break;
                 case 'no_visit_in_x_days':
                     if ($userinfo['lastvisit'] > vB::getRequest()->getTimeNow() - $conditions[0] * 86400) {
                         continue 3;
                     }
                     break;
                 case 'has_never_posted':
                     if ($userinfo['posts'] > 0) {
                         continue 3;
                     }
                     break;
                 case 'no_posts_in_x_days':
                     if ($userinfo['lastpost'] == 0 or $userinfo['lastpost'] > vB::getRequest()->getTimeNow() - $conditions[0] * 86400) {
                         continue 3;
                     }
                     break;
                 case 'has_x_postcount':
                     if (!$this->checkNoticeCriteriaBetween($userinfo['posts'], $conditions[0], $conditions[1])) {
                         continue 3;
                     }
                     break;
                 case 'has_x_reputation':
                     if (!$this->checkNoticeCriteriaBetween($userinfo['reputation'], $conditions[0], $conditions[1])) {
                         continue 3;
                     }
                     break;
                 case 'has_x_infraction_points':
                     if (!$this->checkNoticeCriteriaBetween($userinfo['ipoints'], $conditions[0], $conditions[1])) {
                         continue 3;
                     }
                     break;
                 case 'pm_storage_x_percent_full':
                     if ($userinfo['permissions']['pmquota']) {
                         $pmboxpercentage = $userinfo['pmtotal'] / $userinfo['permissions']['pmquota'] * 100;
                         if (!$this->checkNoticeCriteriaBetween($pmboxpercentage, $conditions[0], $conditions[1])) {
                             continue 3;
                         }
                     } else {
                         continue 3;
                     }
                     break;
                 case 'username_is':
                     if (strtolower($userinfo['username']) != strtolower(trim($conditions[0]))) {
                         continue 3;
                     }
                     break;
                 case 'is_birthday':
                     if (substr($userinfo['birthday'], 0, 5) != vbdate('m-d', vB::getRequest()->getTimeNow(), false, false)) {
                         continue 3;
                     }
                     break;
                 case 'came_from_search_engine':
                     if (!is_came_from_search_engine()) {
                         continue 3;
                     }
                     break;
                 case 'style_is_x':
                     if (STYLEID != intval($conditions[0])) {
                         continue 3;
                     }
                     break;
                 case 'in_coventry':
                     if (!in_array($userinfo['userid'], preg_split('#\\s+#', $vboptions['globalignore'], -1, PREG_SPLIT_NO_EMPTY))) {
                         continue 3;
                     }
                     break;
                 case 'is_date':
                     if (empty($conditions[1]) and vbdate('d-m-Y', vB::getRequest()->getTimeNow(), false, false) != $conditions[0]) {
                         continue 3;
                     } else {
                         if ($conditions[1] and gmdate('d-m-Y', vB::getRequest()->getTimeNow()) != $conditions[0]) {
                             continue 3;
                         }
                     }
                     break;
                 case 'is_time':
                     if (preg_match('#^(\\d{1,2}):(\\d{2})$#', $conditions[0], $start_time) and preg_match('#^(\\d{1,2}):(\\d{2})$#', $conditions[1], $end_time)) {
                         if (empty($conditions[2])) {
                             $start = mktime($start_time[1], $start_time[2]) + $vboptions['hourdiff'];
                             $end = mktime($end_time[1], $end_time[2]) + $vboptions['hourdiff'];
                             $now = mktime() + $vboptions['hourdiff'];
                         } else {
                             $start = gmmktime($start_time[1], $start_time[2]);
                             $end = gmmktime($end_time[1], $end_time[2]);
                             $now = gmmktime();
                         }
                         if ($now < $start or $now > $end) {
                             continue 3;
                         }
                     } else {
                         continue 3;
                     }
                     break;
                 default:
                     $abort = false;
                     if ($abort) {
                         continue 3;
                     }
             }
         }
         $display_notices["{$noticeid}"] = $noticeid;
     }
     // now go through removing notices using the 'notice_x_not_displayed' criteria
     $remove_display_notices = array();
     foreach ($noticecache as $noticeid => $notice) {
         if (isset($notice['notice_x_not_displayed']) and isset($display_notices[intval($notice['notice_x_not_displayed'][0])])) {
             $remove_display_notices["{$noticeid}"] = $noticeid;
         }
     }
     foreach ($remove_display_notices as $noticeid) {
         unset($display_notices["{$noticeid}"]);
     }
     $return = array();
     if ($display_notices) {
         if ($replace_phrases) {
             // Prefech phrases
             $phrases = array();
             foreach ($display_notices as $display_notice) {
                 $phrases[] = "notice_{$display_notice}_html";
             }
             $vbphrase = vB_Api::instanceInternal('phrase')->fetch($phrases);
             foreach ($display_notices as $display_notice) {
                 $notice_html = str_replace(array('{musername}', '{username}', '{userid}', '{sessionurl}', '{sessionurl_q}', '{register_page}', '{help_page}'), array($userinfo['musername'], $userinfo['username'], $userinfo['userid'], vB::getCurrentSession()->get('sessionurl'), vB::getCurrentSession()->get('sessionurl_q'), vB5_Route::buildUrl('register|fullurl'), vB5_Route::buildUrl('help|fullurl')), $vbphrase["notice_{$display_notice}_html"]);
                 $return[$display_notice] = $noticecache[$display_notice];
                 $return[$display_notice]['notice_html'] = $notice_html;
             }
         } else {
             foreach ($display_notices as $display_notice) {
                 $return[$display_notice] = $noticecache[$display_notice];
                 $return[$display_notice]['notice_phrase_varname'] = "notice_{$display_notice}_html";
             }
         }
     }
     return $return;
 }
Beispiel #2
0
/**
* Fetches the IDs of the notices to display on a particular page.
*
* @return	array	Array of IDs to display
*/
function fetch_relevant_notice_ids()
{
	global $vbulletin, $vbphrase, $foruminfo, $threadinfo, $postinfo;


	$forum_pages = array('poll', 'editpost', 'threadrate', 'postings', 'showthread', 'newthread', 'forumdisplay', 'newreply', 'threadtag', 'inlinemod', 'announcement', 'showpost');

	$ignore_np_notices = isset($_COOKIE[COOKIE_PREFIX . 'np_notices_displayed']) ? explode(',', $_COOKIE[COOKIE_PREFIX . 'np_notices_displayed']) : array();
	$display_notices = array();
	$vbulletin->np_notices_displayed = array();

	($hook = vBulletinHook::fetch_hook('notices_check_start')) ? eval($hook) : false;

	foreach ($vbulletin->noticecache AS $noticeid => $notice)
	{
		foreach ($notice AS $criteriaid => $conditions)
		{
			switch ($criteriaid)
			{
				case 'persistent':
				{
					if ($conditions == 0 AND in_array($noticeid, $ignore_np_notices)) // session cookie set in print_output()
					{
						continue 3;
					}
					break;
				}
				case 'dismissible':
				{
					if (in_array($noticeid, fetch_dismissed_notices()))
					{
						continue 3;
					}
					break;
				}
				/*case 'notice_x_not_displayed': // this is now handled differently - see $remove_display_notices below
				{
					if (in_array(intval($conditions[0]), $display_notices))
					{
						continue 3;
					}
					break;
				}*/
				case 'in_usergroup_x':
				{
					if (!is_member_of($vbulletin->userinfo, intval($conditions[0])))
					{
						continue 3;
					}
					break;
				}
				case 'not_in_usergroup_x':
				{
					if (is_member_of($vbulletin->userinfo, intval($conditions[0])))
					{
						continue 3;
					}
					break;
				}
				case 'browsing_forum_x':
				{
					if ($foruminfo['forumid'] != intval($conditions[0]) OR !in_array(THIS_SCRIPT, $forum_pages))
					{
						continue 3;
					}
					break;
				}
				case 'browsing_forum_x_and_children':
				{
					if (!in_array(THIS_SCRIPT, $forum_pages) OR !in_array(intval($conditions[0]), explode(',', $foruminfo['parentlist'])))
					{
						continue 3;
					}
					break;
				}
				case 'no_visit_in_x_days':
				{
					if ($vbulletin->userinfo['lastvisit'] > TIMENOW - $conditions[0] * 86400)
					{
						continue 3;
					}
					break;
				}
				case 'has_never_posted':
				{
					if ($vbulletin->userinfo['lastpost'] > 0)
					{
						continue 3;
					}
					break;
				}
				case 'no_posts_in_x_days':
				{
					if ($vbulletin->userinfo['lastpost'] == 0 OR $vbulletin->userinfo['lastpost'] > TIMENOW - $conditions[0] * 86400)
					{
						continue 3;
					}
					break;
				}
				case 'has_x_postcount':
				{
					if (!check_notice_criteria_between($vbulletin->userinfo['posts'], $conditions[0], $conditions[1]))
					{
						continue 3;
					}
					break;
				}
				case 'has_x_reputation':
				{
					if (!check_notice_criteria_between($vbulletin->userinfo['reputation'], $conditions[0], $conditions[1]))
					{
						continue 3;
					}
					break;
				}
				case 'has_x_infraction_points':
				{
					if (!check_notice_criteria_between($vbulletin->userinfo['ipoints'], $conditions[0], $conditions[1]))
					{
						continue 3;
					}
					break;
				}
				case 'pm_storage_x_percent_full':
				{
					if ($vbulletin->userinfo['permissions']['pmquota'])
					{
						$pmboxpercentage = $vbulletin->userinfo['pmtotal'] / $vbulletin->userinfo['permissions']['pmquota'] * 100;
						if (!check_notice_criteria_between($pmboxpercentage, $conditions[0], $conditions[1]))
						{
							continue 3;
						}
					}
					else
					{
						continue 3;
					}
					break;
				}
				case 'username_is':
				{
					if (strtolower($vbulletin->userinfo['username']) != strtolower(trim($conditions[0])))
					{
						continue 3;
					}
					break;
				}
				case 'is_birthday':
				{
					if (substr($vbulletin->userinfo['birthday'], 0, 5) != vbdate('m-d', TIMENOW, false, false))
					{
						continue 3;
					}
					break;
				}
				case 'came_from_search_engine':
					if (!is_came_from_search_engine())
					{
						continue 3;
					}
					break;
				case 'style_is_x':
				{
					if (STYLEID != intval($conditions[0]))
					{
						continue 3;
					}
					break;
				}
				case 'in_coventry':
				{
					if (!in_array($vbulletin->userinfo['userid'], preg_split('#\s+#', $vbulletin->options['globalignore'], -1, PREG_SPLIT_NO_EMPTY)))
					{
						continue 3;
					}
					break;
				}
				case 'is_date':
				{
					if (empty($conditions[1]) AND vbdate('d-m-Y', TIMENOW, false, false) != $conditions[0]) // user timezone
					{
						continue 3;
					}
					else if ($conditions[1] AND gmdate('d-m-Y', TIMENOW) != $conditions[0]) // utc
					{
						continue 3;
					}
					break;
				}
				case 'is_time':
				{
					if (preg_match('#^(\d{1,2}):(\d{2})$#', $conditions[0], $start_time) AND preg_match('#^(\d{1,2}):(\d{2})$#', $conditions[1], $end_time))
					{
						if (empty($conditions[2])) // user timezone
						{
							$start = mktime($start_time[1], $start_time[2]) + $vbulletin->options['hourdiff'];
							$end   = mktime($end_time[1], $end_time[2]) + $vbulletin->options['hourdiff'];
							$now   = mktime() + $vbulletin->options['hourdiff'];
						}
						else // utc
						{
							$start = gmmktime($start_time[1], $start_time[2]);
							$end   = gmmktime($end_time[1], $end_time[2]);
							$now   = gmmktime();
						}

						if ($now < $start OR $now > $end)
						{
							continue 3;
						}
					}
					else
					{
						continue 3;
					}
					break;
				}
				default:
				{
					$abort = false;

					($hook = vBulletinHook::fetch_hook('notices_check_criteria')) ? eval($hook) : false;

					if ($abort)
					{
						continue 3;
					}
				}
			}
		}

		$display_notices["$noticeid"] = $noticeid;

		if ($notice['persistent'] == 0)
		{
			$vbulletin->np_notices_displayed["$noticeid"] = $noticeid;
		}
	}

	// now go through removing notices using the 'notice_x_not_displayed' criteria
	$remove_display_notices = array();
	foreach ($vbulletin->noticecache AS $noticeid => $notice)
	{
		if (isset($notice['notice_x_not_displayed']) AND isset($display_notices[intval($notice['notice_x_not_displayed'][0])]))
		{
			$remove_display_notices["$noticeid"] = $noticeid;
		}
	}
	foreach ($remove_display_notices AS $noticeid)
	{
		unset($display_notices["$noticeid"], $vbulletin->np_notices_displayed["$noticeid"]);
	}

	return $display_notices;
}