Exemplo n.º 1
0
/**
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     modifier
 * Name:     cal_date_format
 * Purpose:  format datestamps via strftime, (timezone adjusted to calendar specified timezone)
 * Input:    string: input date string
 *           format: strftime format for output
 *           default_date: default date if $string is empty
 * -------------------------------------------------------------
 */
function smarty_modifier_cal_date_format($string, $format = "%b %e, %Y", $default_date = null, $tra_format = null)
{
    $mDate = new BitDate(0);
    if ($mDate->get_display_offset()) {
        $format = preg_replace("/ ?%Z/", "", $format);
    } else {
        $format = preg_replace("/%Z/", "UTC", $format);
    }
    $disptime = $mDate->getTimestampFromISO($string);
    global $gBitSystem, $gBitLanguage;
    //$gBitLanguage->mLanguage= $gBitSystem->getConfig("language", "en");
    if ($gBitSystem->getConfig("language", "en") != $gBitLanguage->mLanguage && $tra_format) {
        $format = $tra_format;
    }
    return $mDate->strftime($format, $disptime, true);
}
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
 /**
  * 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.º 4
0
/**
 * Smarty {html_select_date} plugin
 *
 * Type:     function<br>
 * Name:     html_select_date<br>
 * Purpose:  Prints the dropdowns for date selection.
 *
 * ChangeLog:<br>
 *           - 1.0 initial release
 *           - 1.1 added support for +/- N syntax for begin
 *                and end year values. (Monte)
 *           - 1.2 added support for yyyy-mm-dd syntax for
 *                time value. (Jan Rosier)
 *           - 1.3 added support for choosing format for
 *                month values (Gary Loescher)
 *           - 1.3.1 added support for choosing format for
 *                day values (Marcus Bointon)
 * @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date}
 *      (Smarty online manual)
 * @version 1.3
 * @author   Andrei Zmievski
 * @param array
 * @param Smarty
 * @return string
 */
function smarty_function_html_select_date($params, &$pSmarty)
{
    global $gBitSystem;
    $pSmarty->loadPlugin('smarty_shared_make_timestamp');
    $pSmarty->loadPlugin('smarty_function_html_options');
    /* Default values. */
    $prefix = "Date_";
    $start_year = strftime("%Y");
    $end_year = $start_year;
    $display_days = true;
    $display_months = true;
    $display_years = true;
    $month_format = "%B";
    /* Write months as numbers by default  GL */
    $month_value_format = "%m";
    $day_format = "%02d";
    /* Write day values using this format MB */
    $day_value_format = "%d";
    $year_as_text = false;
    /* Display years in reverse order? Ie. 2000,1999,.... */
    $reverse_years = false;
    /* Should the select boxes be part of an array when returned from PHP?
       e.g. setting it to "birthday", would create "birthday[Day]",
       "birthday[Month]" & "birthday[Year]". Can be combined with prefix */
    $field_array = null;
    /* <select size>'s of the different <select> tags.
       If not set, uses default dropdown. */
    $day_size = null;
    $month_size = null;
    $year_size = null;
    /* Unparsed attributes common to *ALL* the <select>/<input> tags.
       An example might be in the template: all_extra ='class ="foo"'. */
    $all_extra = null;
    /* Separate attributes for the tags. */
    $day_extra = null;
    $month_extra = null;
    $year_extra = null;
    /* Order in which to display the fields.
       "D" -> day, "M" -> month, "Y" -> year. */
    $field_order = 'MDY';
    /* String printed between the different fields. */
    $field_separator = "\n";
    $time = time();
    extract($params);
    // If $time is not in format yyyy-mm-dd
    if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $time)) {
        // then $time is empty or unix timestamp or mysql timestamp
        // strftime to make yyyy-mm-dd
        // Just in case the offset moves us into another day.
        $date = new BitDate(0);
        // sets the offset for the user - necessary because BitDate is a bitwack
        $offset = $date->get_display_offset();
        $time = $date->getDisplayDateFromUTC($time);
        $time = $gBitSystem->mServerTimestamp->strftime('%Y-%m-%d', $time, TRUE);
    }
    // Now split this in pieces, which later can be used to set the select
    $time = explode("-", $time);
    // make syntax "+N" or "-N" work with start_year and end_year
    if (preg_match('!^(\\+|\\-)\\s*(\\d+)$!', $end_year, $match)) {
        if ($match[1] == '+') {
            $end_year = strftime('%Y') + $match[2];
        } else {
            $end_year = strftime('%Y') - $match[2];
        }
    }
    if (preg_match('!^(\\+|\\-)\\s*(\\d+)$!', $start_year, $match)) {
        if ($match[1] == '+') {
            $start_year = strftime('%Y') + $match[2];
        } else {
            $start_year = strftime('%Y') - $match[2];
        }
    }
    $field_order = strtoupper($field_order);
    $html_result = $month_result = $day_result = $year_result = "";
    if ($display_months) {
        $month_names = array();
        $month_values = array();
        for ($i = 1; $i <= 12; $i++) {
            // date: 2003/03/20 22:54:34;  author: ohertel;  state: Exp;  lines: +1 -1
            // added many missing translation blocks and german translations for user admin page, newsreader, notepad and bookmarks, month from html_select_date is being translated now
            // -            $month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));
            // +            $month_names[] = tra(strftime($month_format, mktime(0, 0, 0, $i, 1, 2000)));
            $month_names[] = tra(strftime($month_format, mktime(0, 0, 0, $i, 1, 2000)));
            $month_values[] = strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000));
        }
        $month_result .= '<select name=';
        if (null !== $field_array) {
            $month_result .= '"' . $field_array . '[' . $prefix . 'Month]"';
        } else {
            $month_result .= '"' . $prefix . 'Month"';
        }
        if (null !== $month_size) {
            $month_result .= ' size="' . $month_size . '"';
        }
        if (null !== $month_extra) {
            $month_result .= ' ' . $month_extra;
        }
        if (null !== $all_extra) {
            $month_result .= ' ' . $all_extra;
        }
        $month_result .= '>' . "\n";
        $month_result .= smarty_function_html_options(array('output' => $month_names, 'values' => $month_values, 'selected' => $month_values[$time[1] - 1], 'print_result' => false), $pSmarty);
        $month_result .= '</select>';
    }
    if ($display_days) {
        $days = array();
        for ($i = 1; $i <= 31; $i++) {
            $days[] = sprintf($day_format, $i);
            $day_values[] = sprintf($day_value_format, $i);
        }
        $day_result .= '<select name=';
        if (null !== $field_array) {
            $day_result .= '"' . $field_array . '[' . $prefix . 'Day]"';
        } else {
            $day_result .= '"' . $prefix . 'Day"';
        }
        if (null !== $day_size) {
            $day_result .= ' size="' . $day_size . '"';
        }
        if (null !== $all_extra) {
            $day_result .= ' ' . $all_extra;
        }
        if (null !== $day_extra) {
            $day_result .= ' ' . $day_extra;
        }
        $day_result .= '>' . "\n";
        $day_result .= smarty_function_html_options(array('output' => $days, 'values' => $day_values, 'selected' => $time[2], 'print_result' => false), $pSmarty);
        $day_result .= '</select>';
    }
    if ($display_years) {
        if (null !== $field_array) {
            $year_name = $field_array . '[' . $prefix . 'Year]';
        } else {
            $year_name = $prefix . 'Year';
        }
        if ($year_as_text) {
            $year_result .= '<input type="text" name="' . $year_name . '" value="' . $time[0] . '" size="4" maxlength="4"';
            if (null !== $all_extra) {
                $year_result .= ' ' . $all_extra;
            }
            if (null !== $year_extra) {
                $year_result .= ' ' . $year_extra;
            }
            $year_result .= '>';
        } else {
            $years = range((int) $start_year, (int) $end_year);
            if ($reverse_years) {
                rsort($years, SORT_NUMERIC);
            }
            $year_result .= '<select name="' . $year_name . '"';
            if (null !== $year_size) {
                $year_result .= ' size="' . $year_size . '"';
            }
            if (null !== $all_extra) {
                $year_result .= ' ' . $all_extra;
            }
            if (null !== $year_extra) {
                $year_result .= ' ' . $year_extra;
            }
            $year_result .= '>' . "\n";
            $year_result .= smarty_function_html_options(array('output' => $years, 'values' => $years, 'selected' => $time[0], 'print_result' => false), $pSmarty);
            $year_result .= '</select>';
        }
    }
    // Loop thru the field_order field
    for ($i = 0; $i <= 2; $i++) {
        $c = substr($field_order, $i, 1);
        switch ($c) {
            case 'D':
                $html_result .= $day_result;
                break;
            case 'M':
                $html_result .= $month_result;
                break;
            case 'Y':
                $html_result .= $year_result;
                break;
        }
        // Add the field seperator
        if ($i != 2) {
            $html_result .= $field_separator;
        }
    }
    return $html_result;
}
Exemplo n.º 5
0
/**
 * Smarty {html_select_time} function plugin
 *
 * Type:     function<br>
 * Name:     html_select_time<br>
 * Purpose:  Prints the dropdowns for time selection
 * @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time}
 *          (Smarty online manual)
 * @param array
 * @param Smarty
 * @return string
 */
function smarty_function_html_select_time($params, &$gBitSmarty)
{
    global $gBitSystem;
    $gBitSmarty->loadPlugin('smarty_shared_make_timestamp');
    $gBitSmarty->loadPlugin('smarty_function_html_options');
    /* Default values. */
    $prefix = "Time_";
    $time = time();
    $display_hours = true;
    $display_minutes = true;
    $display_seconds = true;
    $display_meridian = true;
    $use_24_hours = true;
    $minute_interval = 1;
    $second_interval = 1;
    /* Should the select boxes be part of an array when returned from PHP?
       e.g. setting it to "birthday", would create "birthday[Hour]",
       "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]".
       Can be combined with prefix. */
    $field_array = null;
    $all_extra = null;
    $hour_extra = null;
    $minute_extra = null;
    $second_extra = null;
    $meridian_extra = null;
    extract($params);
    $date = new BitDate(0);
    // sets the offset for the user - necessary because BitDate is a bitwack
    $offset = $date->get_display_offset();
    $disptime = $date->getDisplayDateFromUTC($time);
    $html_result = '';
    if ($display_hours) {
        $hours = $use_24_hours ? range(0, 23) : range(1, 12);
        $hour_fmt = $use_24_hours ? '%H' : '%I';
        $selected = $gBitSystem->mServerTimestamp->strftime($hour_fmt, $disptime, TRUE);
        for ($i = 0, $for_max = count($hours); $i < $for_max; $i++) {
            $hours[$i] = sprintf('%02d', $hours[$i]);
        }
        $html_result .= '<select name=';
        if (null !== $field_array) {
            $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';
        } else {
            $html_result .= '"' . $prefix . 'Hour"';
        }
        if (null !== $hour_extra) {
            $html_result .= ' ' . $hour_extra;
        }
        if (null !== $all_extra) {
            $html_result .= ' ' . $all_extra;
        }
        $html_result .= '>' . "\n";
        $html_result .= smarty_function_html_options(array('output' => $hours, 'values' => $hours, 'selected' => $selected, 'print_result' => false), $gBitSmarty);
        $html_result .= "</select>\n";
    }
    if ($display_minutes) {
        $all_minutes = range(0, 59);
        for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i += $minute_interval) {
            $minutes[] = sprintf('%02d', $all_minutes[$i]);
        }
        $selected = intval(floor($gBitSystem->mServerTimestamp->strftime('%M', $disptime, TRUE) / $minute_interval) * $minute_interval);
        $html_result .= '<select name=';
        if (null !== $field_array) {
            $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"';
        } else {
            $html_result .= '"' . $prefix . 'Minute"';
        }
        if (null !== $minute_extra) {
            $html_result .= ' ' . $minute_extra;
        }
        if (null !== $all_extra) {
            $html_result .= ' ' . $all_extra;
        }
        $html_result .= '>' . "\n";
        $html_result .= smarty_function_html_options(array('output' => $minutes, 'values' => $minutes, 'selected' => $selected, 'print_result' => false), $gBitSmarty);
        $html_result .= "</select>\n";
    }
    if ($display_seconds) {
        $all_seconds = range(0, 59);
        for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i += $second_interval) {
            $seconds[] = sprintf('%02d', $all_seconds[$i]);
        }
        $selected = intval(floor($gBitSystem->mServerTimestamp->strftime('%S', $disptime, TRUE) / $second_interval) * $second_interval);
        $html_result .= '<select name=';
        if (null !== $field_array) {
            $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"';
        } else {
            $html_result .= '"' . $prefix . 'Second"';
        }
        if (null !== $second_extra) {
            $html_result .= ' ' . $second_extra;
        }
        if (null !== $all_extra) {
            $html_result .= ' ' . $all_extra;
        }
        $html_result .= '>' . "\n";
        $html_result .= smarty_function_html_options(array('output' => $seconds, 'values' => $seconds, 'selected' => $selected, 'print_result' => false), $gBitSmarty);
        $html_result .= "</select>\n";
    }
    if ($display_meridian && !$use_24_hours) {
        $html_result .= '<select name=';
        $selected = strtolower($gBitSystem->mServerTimestamp->strftime('%p', $disptime, TRUE));
        if (null !== $field_array) {
            $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"';
        } else {
            $html_result .= '"' . $prefix . 'Meridian"';
        }
        if (null !== $meridian_extra) {
            $html_result .= ' ' . $meridian_extra;
        }
        if (null !== $all_extra) {
            $html_result .= ' ' . $all_extra;
        }
        $html_result .= '>' . "\n";
        $html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'), 'values' => array('am', 'pm'), 'selected' => $selected, 'print_result' => false), $gBitSmarty);
        $html_result .= "</select>\n";
    }
    // date: 2003/02/12 21:23:52;  author: gilshwartz;  state: Exp;  lines: +1 -1
    // Enforce LTR direction of time entry regardless of overall directionality.
    // -    print $html_result;
    // +    print '<span dir="ltr">'.$html_result.'</span>';
    $html_result = '<span dir="ltr">' . $html_result . '</span>';
    return $html_result;
}
Exemplo n.º 6
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>';
}