Exemplo n.º 1
0
 /**
  * Make sure the data is safe to store
  *
  * @param array pParams reference to hash of values that will be used to store the page, they will be modified where necessary
  * @return bool TRUE on success, FALSE if verify failed. If FALSE, $this->mErrors will have reason why
  * @access private
  **/
 function verify(&$pParamHash)
 {
     global $gBitUser, $gBitSystem;
     if ($gBitUser->isRegistered() && $this->isValid()) {
         $this->load();
         $timeout = $gBitSystem->getUTCTime() - $gBitSystem->getConfig('recommends_recommend_period', 15) * RECOMMENDS_PERIOD_SCALE;
         $timeout_change = $gBitSystem->getUTCTime() - $gBitSystem->getConfig('recommends_change_timeout', 1) * RECOMMENDS_TIMEOUT_CHANGE_SCALE;
         if ((!$gBitSystem->isFeatureActive('recommends_recommend_period') || $this->mInfo['created'] > $timeout) && (empty($this->mInfo['recommends_time']) || $this->mInfo['recommends_time'] > $timeout_change)) {
             if (empty($this->mInfo['recommends_changes']) || $this->mInfo['recommends_changes'] < $gBitSystem->getConfig('recommends_max_changes', 1)) {
                 $pParamHash['content_id'] = $this->mContentId;
                 $pParamHash['recommending'] = $pParamHash['recommends_recommending'];
                 if (($pParamHash['recommending'] == 1 || $pParamHash['recommending'] == -1 || $pParamHash['recommending'] == 0) && $this->isValid()) {
                     // recommends table
                     $pParamHash['recommends_store']['content_id'] = $pParamHash['recommends_store']['content_id'] = (int) $this->mContentId;
                     $pParamHash['recommends_store']['recommending'] = (int) $pParamHash['recommending'];
                     $pParamHash['recommends_store']['recommending_time'] = (int) BitDate::getUTCTime();
                     $pParamHash['recommends_store']['user_id'] = (int) $gBitUser->mUserId;
                     $pParamHash['recommends_store']['changes'] = !isset($this->mInfo['recommends_changes']) ? 0 : $this->mInfo['recommends_changes'] + 1;
                 } else {
                     $this->mErrors['recommending_bad'] = tra("Invalid recommendation.");
                 }
             } else {
                 $this->mErrors['recommending_changes'] = tra('Maximum number of changes already made.');
             }
         } else {
             $this->mErrors['recommending_timeout'] = tra("Recommendation period has expired");
         }
     } else {
         $this->mErrors['unregistered'] = tra("You have to be registered to recommend content.");
     }
     return count($this->mErrors) == 0;
 }
Exemplo n.º 2
0
 function calculateUserWeight($pUserId = NULL)
 {
     global $gBitUser, $gBitSystem;
     if ($gBitSystem->isFeatureActive('stars_user_weight')) {
         // allow overriding of currently loaded user
         if (@BitBase::verifyId($pUserId)) {
             $tmpUser = new BitPermUser($pUserId);
             $tmpUser->load(TRUE);
         } else {
             $tmpUser =& $gBitUser;
         }
         // age relative to site age
         $query = "SELECT MIN( `registration_date` ) FROM `" . BIT_DB_PREFIX . "users_users`";
         $age['site'] = BitDate::getUTCTime() - $this->mDb->getOne($query);
         $age['user'] = BitDate::getUTCTime() - $tmpUser->getField('registration_date');
         $userWeight['age'] = $age['user'] / $age['site'];
         // permissioning relative to full number of permissions
         $query = "SELECT COUNT( `perm_name` ) FROM `" . BIT_DB_PREFIX . "users_permissions`";
         if ($tmpUser->isAdmin()) {
             $userWeight['permission'] = 1;
         } else {
             $userWeight['permission'] = count($tmpUser->mPerms) / $this->mDb->getOne($query);
         }
         // activity - we could to the same using the history as well.
         $query = "SELECT COUNT( `content_id` ) FROM `" . BIT_DB_PREFIX . "liberty_content` WHERE `user_id`=?";
         $activity['user'] = $this->mDb->getOne($query, array($tmpUser->getField('user_id')));
         $query = "SELECT COUNT( `content_id` ) FROM `" . BIT_DB_PREFIX . "liberty_content`";
         $activity['site'] = $this->mDb->getOne($query);
         $userWeight['activity'] = $activity['user'] / $activity['site'];
         // here we can add some weight to various areas
         $custom['age'] = $gBitSystem->getConfig('stars_weight_age');
         $custom['permission'] = $gBitSystem->getConfig('stars_weight_permission');
         $custom['activity'] = $gBitSystem->getConfig('stars_weight_activity');
         foreach ($userWeight as $type => $value) {
             ${$type} = 10 * $value * $custom[$type];
             if (empty(${$type})) {
                 ${$type} = 1;
             }
         }
         // TODO: run some tests to see if this is a good way of evaluating power of a user
         // ensure that we always have a positive number here to avoid chaos - this also makes sure new users have at least a bit of a say
         if (($ret = round(log($age * $permission * $activity, 2))) < 1) {
             $ret = 1;
         }
     } else {
         $ret = 1;
     }
     return $ret;
 }
Exemplo n.º 3
0
function data_calendar($data, $params)
{
    global $gBitSmarty, $gBitSystem;
    if ($gBitSystem->isPackageActive('calendar')) {
        $offset = $gBitSystem->get_display_offset();
        $bitDate = new BitDate($offset);
        $time = $bitDate->getUTCTime();
        $date = $bitDate->getDate($time, true);
        $month = $date['mon'];
        $year = $date['year'];
        $month_day = $date['mday'];
        $month_name = $date['month'];
        // reset time so we can make today look different in template with compare
        $time = $bitDate->mktime(0, 0, 0, $month, $month_day, $year);
        $last_time = $bitDate->mktime(0, 0, 0, $month, 0, $year);
        $next_time = $bitDate->mktime(0, 0, 0, $month + 1, 1, $year);
        $last = $bitDate->getDate($last_time);
        $next = $bitDate->getDate($next_time);
        $days = array();
        for ($i = 2; $i < 9; $i++) {
            // Start from known sunday.
            $timestamp = $bitDate->mktime(0, 0, 0, 1, $i, 2000);
            $days[] = $bitDate->strftime('%a', $timestamp);
        }
        // Build a two-dimensional array of UNIX timestamps.
        $calendar = array();
        // Start with last days of previous month.
        $week = array();
        $month_begin = $bitDate->mktime(0, 0, 0, $month, 1, $year);
        $month_begin_dow = strftime('%w', $month_begin);
        $days_last_month = $bitDate->daysInMonth($last['month'], $last['year']);
        for ($dow = 0; $dow < $month_begin_dow; $dow++) {
            $day = $days_last_month - $month_begin_dow + $dow;
            $d['time'] = $bitDate->mktime(0, 0, 0, $month - 1, $day, $year);
            $d['dim'] = true;
            $week[] = $d;
        }
        // Do this month
        $days_in_month = $bitDate->daysInMonth($month, $year);
        for ($i = 1; $i <= $days_in_month; $i++) {
            if ($dow == 7) {
                $calendar[] = $week;
                // Done with row
                $dow = 0;
                unset($week);
                $week = array();
            }
            $d['time'] = $bitDate->mktime(0, 0, 0, $month, $i, $year);
            $d['dim'] = false;
            // Flag today
            if ($i == $month_day) {
                $d['today'] = true;
            }
            $week[] = $d;
            unset($d['today']);
            $dow++;
        }
        // Do the last month.
        for ($i = 1; $dow < 7; $i++, $dow++) {
            $d['time'] = $bitDate->mktime(0, 0, 0, $month + 1, $i, $year);
            $d['dim'] = true;
            $week[] = $d;
        }
        $calendar[] = $week;
        $gBitSmarty->assign('minical', true);
        $gBitSmarty->assign('month_name', $month_name);
        $gBitSmarty->assign('month', $month);
        $gBitSmarty->assign('year', $year);
        $gBitSmarty->assign('last_month', $last_time);
        $gBitSmarty->assign('next_month', $next_time);
        $gBitSmarty->assign('dow_abbrevs', $days);
        $gBitSmarty->assign('calendar', $calendar);
        $gBitSmarty->assign('today', $time);
        // Assign a base url
        if (empty($params['events'])) {
            $pBaseUrl = CALENDAR_PKG_URL . 'index.php';
        } else {
            $pBaseUrl = EVENTS_PKG_URL . 'calendar.php';
        }
        $gBitSmarty->assign('baseCalendarUrl', $pBaseUrl);
        return $gBitSmarty->fetch('bitpackage:calendar/minical.tpl');
    }
    return '<div class="error">Calendar Package Not Active</div>';
}