Example #1
0
 /**
  * Standard modular run function for CRON hooks. Searches for tasks to perform.
  */
 function run()
 {
     //if (!addon_installed('bank')) return;
     $to_be_restored = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'bank WHERE add_time<' . strval(time() - 30 * 24 * 60 * 60), NULL, NULL, true);
     if (is_null($to_be_restored)) {
         return;
     }
     $bank_dividend = intval(get_option('bank_divident'));
     foreach ($to_be_restored as $deposit) {
         if ($deposit['amount'] > 0) {
             require_code('points2');
             require_lang('bank');
             $restore_amount = round(floatval($deposit['amount']) * (1.0 + floatval($bank_dividend) / 100.0));
             system_gift_transfer(do_lang('RESTORED_DEPOSIT'), intval($restore_amount), $deposit['user_id']);
             $GLOBALS['SITE_DB']->query_delete('bank', array('id' => $deposit['id']), '', 1);
         }
     }
 }
Example #2
0
 function run($ob, $query, $max, $start, $fail_ok, $get_insert_id, $ret)
 {
     if (strpos($query, 'INTO ' . get_table_prefix() . 'banner_clicks') !== false) {
         load_user_stuff();
         if (method_exists($GLOBALS['FORUM_DRIVER'], 'forum_layer_initialise')) {
             $GLOBALS['FORUM_DRIVER']->forum_layer_initialise();
         }
         global $FORCE_INVISIBLE_GUEST, $MEMBER_CACHED;
         $FORCE_INVISIBLE_GUEST = false;
         $MEMBER_CACHED = NULL;
         if (!is_guest()) {
             require_code('comcode');
             require_code('permissions');
             $member_id = get_member();
             $dest = get_param('dest', '');
             $cnt = $GLOBALS['SITE_DB']->query_value('banner_clicks', 'COUNT(*)', array('c_member_id' => $member_id, 'c_banner_id' => $dest));
             if ($cnt == 0) {
                 require_code('points');
                 require_code('points2');
                 system_gift_transfer('Clicking a banner', 1, $member_id);
             }
         }
     }
 }
Example #3
0
 /**
  * Standard modular run function for CRON hooks. Searches for tasks to perform.
  */
 function run()
 {
     require_code('points');
     $time = time();
     $last_time = intval(get_value('last_group_points'));
     if ($last_time > time() - 24 * 60 * 60 * 27) {
         return;
     }
     // Only once within a month
     if (date('j') != '1') {
         return;
     }
     // Only on first day
     require_code('points');
     require_code('points2');
     $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true, true);
     $group_points = get_group_points();
     $fields = new ocp_tempcode();
     foreach ($groups as $group_id => $group_name) {
         if (isset($group_points[$group_id])) {
             $points = $group_points[$group_id];
             if ($points['p_points_per_month'] != 0) {
                 $start = 0;
                 do {
                     $members = $GLOBALS['FORUM_DRIVER']->member_group_query(array($group_id), 100, $start);
                     foreach ($members as $member_row) {
                         $member_id = $GLOBALS['FORUM_DRIVER']->pname_id($member_row);
                         system_gift_transfer('Being in the ' . $group_name . ' usergroup', $points['p_points_per_month'], $member_id);
                     }
                     $start += 100;
                 } while (count($members) > 0);
             }
         }
     }
     set_value('last_group_points', strval($time));
 }
/**
 * Add a member.
 *
 * @param  SHORT_TEXT		The username.
 * @param  SHORT_TEXT		The password.
 * @param  SHORT_TEXT		The e-mail address.
 * @param  ?array				A list of usergroups (NULL: default/current usergroups).
 * @param  ?integer			Day of date of birth (NULL: unknown).
 * @param  ?integer			Month of date of birth (NULL: unknown).
 * @param  ?integer			Year of date of birth (NULL: unknown).
 * @param  array				A map of custom field values (field-id=>value).
 * @param  ?ID_TEXT			The member timezone (NULL: auto-detect).
 * @param  ?GROUP				The member's primary (NULL: default).
 * @param  BINARY				Whether the profile has been validated.
 * @param  ?TIME				When the member joined (NULL: now).
 * @param  ?TIME				When the member last visited (NULL: now).
 * @param  ID_TEXT			The member's default theme.
 * @param  ?URLPATH			The URL to the member's avatar (blank: none) (NULL: choose one automatically).
 * @param  LONG_TEXT			The member's signature (blank: none).
 * @param  BINARY				Whether the member is permanently banned.
 * @param  BINARY				Whether posts are previewed before they are made.
 * @param  BINARY				Whether the member's age may be shown.
 * @param  SHORT_TEXT		The member's title (blank: get from primary).
 * @param  URLPATH			The URL to the member's photo (blank: none).
 * @param  URLPATH			The URL to the member's photo thumbnail (blank: none).
 * @param  BINARY				Whether the member sees signatures in posts.
 * @param  ?BINARY			Whether the member automatically is enabled for notifications for content they contribute to (NULL: get default from config).
 * @param  ?LANGUAGE_NAME	The member's language (NULL: auto detect).
 * @param  BINARY				Whether the member allows e-mails via the site.
 * @param  BINARY				Whether the member allows e-mails from staff via the site.
 * @param  LONG_TEXT			Personal notes of the member.
 * @param  ?IP					The member's IP address (NULL: IP address of current user).
 * @param  SHORT_TEXT		The code required before the account becomes active (blank: already entered).
 * @param  boolean			Whether to check details for correctness.
 * @param  ?ID_TEXT			The compatibility scheme that the password operates in (blank: none) (NULL: none [meaning normal ocPortal salted style] or plain, depending on whether passwords are encrypted).
 * @param  SHORT_TEXT		The password salt (blank: password compatibility scheme does not use a salt / auto-generate).
 * @param  BINARY				Whether the member likes to view zones without menus, when a choice is available.
 * @param  ?TIME				The time the member last made a submission (NULL: set to now).
 * @param  ?AUTO_LINK		Force an ID (NULL: don't force an ID)
 * @param  BINARY				Whether the member username will be highlighted.
 * @param  SHORT_TEXT		Usergroups that may PT the member.
 * @param  LONG_TEXT			Rules that other members must agree to before they may start a PT with the member.
 * @return AUTO_LINK			The ID of the new member.
 */
function ocf_make_member($username, $password, $email_address, $secondary_groups, $dob_day, $dob_month, $dob_year, $custom_fields, $timezone = NULL, $primary_group = NULL, $validated = 1, $join_time = NULL, $last_visit_time = NULL, $theme = '', $avatar_url = NULL, $signature = '', $is_perm_banned = 0, $preview_posts = 0, $reveal_age = 1, $title = '', $photo_url = '', $photo_thumb_url = '', $views_signatures = 1, $auto_monitor_contrib_content = NULL, $language = NULL, $allow_emails = 1, $allow_emails_from_staff = 1, $personal_notes = '', $ip_address = NULL, $validated_email_confirm_code = '', $check_correctness = true, $password_compatibility_scheme = NULL, $salt = '', $zone_wide = 1, $last_submit_time = NULL, $id = NULL, $highlighted_name = 0, $pt_allow = '*', $pt_rules_text = '')
{
    if (is_null($auto_monitor_contrib_content)) {
        $auto_monitor_contrib_content = get_value('no_auto_notifications') === '1' ? 0 : 1;
    }
    if (is_null($password_compatibility_scheme)) {
        if (get_value('no_password_hashing') === '1') {
            $password_compatibility_scheme = 'plain';
        } else {
            $password_compatibility_scheme = '';
        }
    }
    if (is_null($language)) {
        $language = '';
    }
    if (is_null($signature)) {
        $signature = '';
    }
    if (is_null($title)) {
        $title = '';
    }
    if (is_null($timezone)) {
        $timezone = get_site_timezone();
    }
    if (is_null($allow_emails)) {
        $allow_emails = 1;
    }
    if (is_null($allow_emails_from_staff)) {
        $allow_emails_from_staff = 1;
    }
    if (is_null($personal_notes)) {
        $personal_notes = '';
    }
    if (is_null($avatar_url)) {
        if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 1 || !addon_installed('ocf_member_avatars')) {
            $avatar_url = '';
        } else {
            if (get_option('random_avatars') == '1' && !running_script('stress_test_loader')) {
                require_code('themes2');
                $codes = get_all_image_ids_type('ocf_default_avatars/default_set', false, $GLOBALS['FORUM_DB']);
                shuffle($codes);
                $results = array();
                foreach ($codes as $code) {
                    if (strpos($code, 'ocp_fanatic') !== false) {
                        continue;
                    }
                    $count = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(m_cache_num_posts) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE ' . db_string_equal_to('m_avatar_url', find_theme_image($code, false, true)));
                    if (is_null($count)) {
                        $count = 0;
                    }
                    $results[$code] = $count;
                }
                @asort($results);
                // @'d as type checker fails for some odd reason
                $found_avatars = array_keys($results);
                $avatar_url = find_theme_image(array_shift($found_avatars), true, true);
            }
            if (is_null($avatar_url)) {
                $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'ocf_default_avatars/default', 'path' => ''));
                // In case failure cached, gets very confusing
                $avatar_url = find_theme_image('ocf_default_avatars/default', true, true);
                if (is_null($avatar_url)) {
                    $avatar_url = '';
                }
            }
        }
    }
    if ($check_correctness) {
        if (!in_array($password_compatibility_scheme, array('ldap', 'httpauth'))) {
            ocf_check_name_valid($username, NULL, $password_compatibility_scheme == '' ? $password : NULL);
        }
        if (!function_exists('has_actual_page_access') || !has_actual_page_access(get_member(), 'admin_ocf_join')) {
            require_code('type_validation');
            if (!is_valid_email_address($email_address) && $email_address != '') {
                warn_exit(do_lang_tempcode('_INVALID_EMAIL_ADDRESS', escape_html($email_address)));
            }
        }
    }
    require_code('ocf_members');
    require_code('ocf_groups');
    if (is_null($last_submit_time)) {
        $last_submit_time = time();
    }
    if (is_null($join_time)) {
        $join_time = time();
    }
    if (is_null($last_visit_time)) {
        $last_visit_time = time();
    }
    if (is_null($primary_group)) {
        $primary_group = get_first_default_group();
        // This is members
    }
    if (is_null($secondary_groups)) {
        $secondary_groups = ocf_get_all_default_groups(false);
    }
    foreach ($secondary_groups as $_g_id => $g_id) {
        if ($g_id == $primary_group) {
            unset($secondary_groups[$_g_id]);
        }
    }
    if (is_null($ip_address)) {
        $ip_address = get_ip_address();
    }
    if ($password_compatibility_scheme == '' && get_value('no_password_hashing') === '1') {
        $password_compatibility_scheme = 'plain';
        $salt = '';
    }
    if ($salt == '' && $password_compatibility_scheme == '') {
        $salt = produce_salt();
        $password_salted = md5($salt . md5($password));
    } else {
        $password_salted = $password;
    }
    // Supplement custom field values given with defaults, and check constraints
    $all_fields = list_to_map('id', ocf_get_all_custom_fields_match($secondary_groups));
    require_code('fields');
    foreach ($all_fields as $field) {
        $field_id = $field['id'];
        if (array_key_exists($field_id, $custom_fields)) {
            if ($check_correctness && $field[array_key_exists('cf_show_on_join_form', $field) ? 'cf_show_on_join_form' : 'cf_required'] == 0 && $field['cf_owner_set'] == 0 && !has_actual_page_access(get_member(), 'admin_ocf_join')) {
                access_denied('I_ERROR');
            }
        } else {
            $custom_fields[$field_id] = '';
        }
    }
    if (!addon_installed('unvalidated')) {
        $validated = 1;
    }
    $map = array('m_username' => $username, 'm_pass_hash_salted' => $password_salted, 'm_pass_salt' => $salt, 'm_theme' => $theme, 'm_avatar_url' => $avatar_url, 'm_validated' => $validated, 'm_validated_email_confirm_code' => $validated_email_confirm_code, 'm_cache_num_posts' => 0, 'm_cache_warnings' => 0, 'm_max_email_attach_size_mb' => 5, 'm_join_time' => $join_time, 'm_timezone_offset' => $timezone, 'm_primary_group' => $primary_group, 'm_last_visit_time' => $last_visit_time, 'm_last_submit_time' => $last_submit_time, 'm_signature' => insert_lang_comcode($signature, 4, $GLOBALS['FORUM_DB']), 'm_is_perm_banned' => $is_perm_banned, 'm_preview_posts' => $preview_posts, 'm_notes' => $personal_notes, 'm_dob_day' => $dob_day, 'm_dob_month' => $dob_month, 'm_dob_year' => $dob_year, 'm_reveal_age' => $reveal_age, 'm_email_address' => $email_address, 'm_title' => $title, 'm_photo_url' => $photo_url, 'm_photo_thumb_url' => $photo_thumb_url, 'm_views_signatures' => $views_signatures, 'm_auto_monitor_contrib_content' => $auto_monitor_contrib_content, 'm_highlighted_name' => $highlighted_name, 'm_pt_allow' => $pt_allow, 'm_pt_rules_text' => insert_lang_comcode($pt_rules_text, 4, $GLOBALS['FORUM_DB']), 'm_language' => $language, 'm_ip_address' => $ip_address, 'm_zone_wide' => $zone_wide, 'm_allow_emails' => $allow_emails, 'm_allow_emails_from_staff' => $allow_emails_from_staff, 'm_password_change_code' => '', 'm_password_compat_scheme' => $password_compatibility_scheme, 'm_on_probation_until' => NULL);
    if (!is_null($id)) {
        $map['id'] = $id;
    }
    $member_id = $GLOBALS['FORUM_DB']->query_insert('f_members', $map, true);
    if ($check_correctness) {
        // If it was an invite/recommendation, award the referrer
        if (addon_installed('recommend')) {
            $inviter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_invites', 'i_inviter', array('i_email_address' => $email_address), 'ORDER BY i_time');
            if (!is_null($inviter)) {
                if (addon_installed('points')) {
                    require_code('points2');
                    require_lang('recommend');
                    system_gift_transfer(do_lang('RECOMMEND_SITE_TO', $username, get_site_name()), intval(get_option('points_RECOMMEND_SITE')), $inviter);
                }
                if (addon_installed('chat')) {
                    require_code('chat2');
                    buddy_add($inviter, $member_id);
                    buddy_add($member_id, $inviter);
                }
            }
        }
    }
    $value = mixed();
    // Store custom fields
    $row = array('mf_member_id' => $member_id);
    $all_fields_types = collapse_2d_complexity('id', 'cf_type', $all_fields);
    foreach ($custom_fields as $field_num => $value) {
        if (!array_key_exists($field_num, $all_fields_types)) {
            continue;
        }
        // Trying to set a field we're not allowed to (doesn't apply to our group)
        $ob = get_fields_hook($all_fields_types[$field_num]);
        list(, , $storage_type) = $ob->get_field_value_row_bits($all_fields[$field_num]);
        if (strpos($storage_type, '_trans') !== false) {
            $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
        }
        $row['field_' . strval($field_num)] = $value;
    }
    // Set custom field row
    $all_fields_regardless = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_type'));
    foreach ($all_fields_regardless as $field) {
        if (!array_key_exists('field_' . strval($field['id']), $row)) {
            $ob = get_fields_hook($field['cf_type']);
            list(, , $storage_type) = $ob->get_field_value_row_bits($field);
            $value = '';
            if (strpos($storage_type, '_trans') !== false) {
                $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
            }
            $row['field_' . strval($field['id'])] = $value;
        }
    }
    $GLOBALS['FORUM_DB']->query_insert('f_member_custom_fields', $row);
    // Any secondary work
    foreach ($secondary_groups as $g) {
        if ($g != $primary_group) {
            $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_member_id' => $member_id, 'gm_group_id' => $g), '', 1);
            $GLOBALS['FORUM_DB']->query_insert('f_group_members', array('gm_group_id' => $g, 'gm_member_id' => $member_id, 'gm_validated' => 1));
        }
    }
    if ($check_correctness) {
        if (function_exists('decache')) {
            decache('side_stats');
        }
    }
    return $member_id;
}
Example #5
0
/**
 * Implement a rating at the quantum level.
 *
 * @param  ?integer		Rating given (NULL: unrate)
 * @range 1 10
 * @param  ID_TEXT		The page name the rating is on
 * @param  MEMBER			The member doing the rating
 * @param  ID_TEXT		The type (download, etc) that this rating is for
 * @param  ID_TEXT		The second level type (probably blank)
 * @param  ID_TEXT		The ID of the type that this rating is for
 * @param  ?string		The title to where the commenting will pass back to (to put into the comment topic header) (NULL: don't know)
 * @param  mixed			The URL to where the commenting will pass back to (to put into the comment topic header) (URLPATH or Tempcode)
 */
function actualise_specific_rating($rating, $page_name, $member_id, $content_type, $type, $content_id, $content_url, $content_title)
{
    if (!is_null($rating)) {
        if ($rating > 10 || $rating < 1) {
            log_hack_attack_and_exit('VOTE_CHEAT');
        }
    }
    $rating_for_type = $content_type . ($type == '' ? '' : '_' . $type);
    if (!has_specific_permission($member_id, 'rate', $page_name)) {
        return;
    }
    $already_rated = already_rated(array($rating_for_type), $content_id);
    if (!is_null($rating)) {
        if ($already_rated) {
            // Delete, in preparation for re-rating
            $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => $rating_for_type, 'rating_for_id' => $content_id, 'rating_member' => $member_id, 'rating_ip' => get_ip_address()));
        }
    }
    list($_content_title, $submitter, , $safe_content_url, $cma_info) = get_details_behind_feedback_code($content_type, $content_id);
    if (is_null($content_title)) {
        $content_title = $_content_title;
    }
    if ($member_id === $submitter && !is_guest($member_id)) {
        return;
    }
    if (!is_null($rating)) {
        $GLOBALS['SITE_DB']->query_insert('rating', array('rating_for_type' => $rating_for_type, 'rating_for_id' => $content_id, 'rating_member' => $member_id, 'rating_ip' => get_ip_address(), 'rating_time' => time(), 'rating' => $rating));
    } else {
        $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => $rating_for_type, 'rating_for_id' => $content_id, 'rating_member' => $member_id, 'rating_ip' => get_ip_address()));
    }
    // Top rating / liked
    if ($rating === 10 && $type == '') {
        $content_type_title = $content_type;
        if (!is_null($cma_info) && isset($cma_info['content_type_label'])) {
            $content_type_title = do_lang($cma_info['content_type_label']);
        }
        // Special case. Would prefer not to hard-code, but important for usability
        if ($content_type == 'post' && $content_title == '' && get_forum_type() == 'ocf') {
            $content_title = do_lang('POST_IN', $GLOBALS['FORUM_DB']->query_value('f_topics', 't_cache_first_title', array('id' => $GLOBALS['FORUM_DB']->query_value('f_posts', 'p_topic_id', array('id' => intval($content_id))))));
        }
        if (!is_null($submitter) && !is_guest($submitter)) {
            // Give points
            if ($member_id != $submitter) {
                if (addon_installed('points') && !$already_rated) {
                    require_code('points2');
                    require_lang('points');
                    system_gift_transfer(do_lang('CONTENT_LIKED'), intval(get_option('points_if_liked')), $submitter);
                }
            }
            // Notification
            require_code('notifications');
            $subject = do_lang('CONTENT_LIKED_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title);
            $rendered_award = '';
            $award_hook = convert_ocportal_type_codes('feedback_type_code', $content_type, 'award_hook');
            if ($award_hook != '') {
                require_code('hooks/systems/awards/' . $award_hook);
                $award_ob = object_factory('Hook_awards_' . $award_hook);
                $award_content_row = content_get_row($content_id, $award_ob->info());
                if (!is_null($award_content_row)) {
                    $rendered_award = preg_replace('#&amp;keep_\\w+=[^&]*#', '', static_evaluate_tempcode($award_ob->run($award_content_row, '_SEARCH')));
                }
            }
            $mail = do_lang('CONTENT_LIKED_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title), array(comcode_escape(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), $rendered_award, comcode_escape($GLOBALS['FORUM_DRIVER']->get_username(get_member()))));
            dispatch_notification('like', NULL, $subject, $mail, array($submitter));
        }
        // Put on activity wall / whatever
        $real_content_type = convert_ocportal_type_codes('feedback_type_code', $content_type, 'cma_hook');
        if (may_view_content_behind_feedback_code($GLOBALS['FORUM_DRIVER']->get_guest_id(), $real_content_type, $content_id)) {
            if (is_null($submitter)) {
                $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id();
            }
            $activity_type = is_null($submitter) || is_guest($submitter) ? '_ACTIVITY_LIKES' : 'ACTIVITY_LIKES';
            if ($content_title == '') {
                syndicate_described_activity($activity_type . '_UNTITLED', ocp_mb_strtolower($content_type_title), $content_type_title, '', url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter);
            } else {
                syndicate_described_activity($activity_type, $content_title, ocp_mb_strtolower($content_type_title), $content_type_title, url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter);
            }
        }
    }
    // Enter them for a prize draw to win a free jet
    // NOT IMPLEMENTED- Anyone want to donate the jet?
}
Example #6
0
/**
 * Farm out the files for downloads.
 */
function dload_script()
{
    // Closed site
    $site_closed = get_option('site_closed');
    if ($site_closed == '1' && !has_specific_permission(get_member(), 'access_closed_site') && !$GLOBALS['IS_ACTUALLY_ADMIN']) {
        header('Content-Type: text/plain');
        @exit(get_option('closed'));
    }
    global $SITE_INFO;
    if (!is_guest() || !isset($SITE_INFO['any_guest_cached_too']) || $SITE_INFO['any_guest_cached_too'] == '0') {
        if (get_param('for_session', '-1') != md5(strval(get_session_id())) && get_option('anti_leech') == '1' && ocp_srv('HTTP_REFERER') != '') {
            warn_exit(do_lang_tempcode('LEECH_BLOCK'));
        }
    }
    require_lang('downloads');
    $id = get_param_integer('id', 0);
    // Lookup
    $rows = $GLOBALS['SITE_DB']->query_select('download_downloads', array('*'), array('id' => $id), '', 1);
    if (!array_key_exists(0, $rows)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $myrow = $rows[0];
    // Permission
    if (!has_category_access(get_member(), 'downloads', strval($myrow['category_id']))) {
        access_denied('CATEGORY_ACCESS');
    }
    // Cost?
    $got_before = $GLOBALS['SITE_DB']->query_value_null_ok('download_logging', 'the_user', array('the_user' => get_member(), 'id' => $id));
    if (addon_installed('points')) {
        if ($myrow['download_cost'] > 0) {
            require_code('points2');
            $member = get_member();
            if (is_guest($member)) {
                access_denied('NOT_AS_GUEST');
            }
            // Check they haven't downloaded this before (they only get charged once - maybe they are resuming)
            if (is_null($got_before)) {
                $cost = $myrow['download_cost'];
                $member = get_member();
                if (is_guest($member)) {
                    access_denied('NOT_AS_GUEST');
                }
                $dif = $cost - available_points($member);
                if ($dif > 0 && !has_specific_permission(get_member(), 'have_negative_gift_points')) {
                    warn_exit(do_lang_tempcode('LACKING_POINTS', integer_format($dif)));
                }
                require_code('points2');
                charge_member($member, $cost, do_lang('DOWNLOADED_THIS', get_translated_text($myrow['name'])));
                if ($myrow['download_submitter_gets_points'] == 1) {
                    system_gift_transfer(do_lang('THEY_DOWNLOADED_THIS', get_translated_text($myrow['name'])), $cost, $myrow['submitter']);
                }
            }
        }
    }
    // Filename
    $full = $myrow['url'];
    $breakdown = @pathinfo($full) or warn_exit(do_lang_tempcode('HTTP_DOWNLOAD_NO_SERVER', $full));
    //	$filename=$breakdown['basename'];
    if (!array_key_exists('extension', $breakdown)) {
        $extension = '';
    } else {
        $extension = strtolower($breakdown['extension']);
    }
    if (url_is_local($full)) {
        $_full = get_custom_file_base() . '/' . rawurldecode($full);
    } else {
        $_full = rawurldecode($full);
    }
    // Is it non-local? If so, redirect
    if (!url_is_local($full) || !file_exists(get_file_base() . '/' . rawurldecode(filter_naughty($full)))) {
        if (url_is_local($full)) {
            $full = get_custom_base_url() . '/' . $full;
        }
        if (strpos($full, chr(10)) !== false || strpos($full, chr(13)) !== false) {
            log_hack_attack_and_exit('HEADER_SPLIT_HACK');
        }
        header('Location: ' . $full);
        log_download($id, 0, !is_null($got_before));
        // Bandwidth used is 0 for an external download
        return;
    }
    // Some basic security: don't fopen php files
    if ($extension == 'php') {
        log_hack_attack_and_exit('PHP_DOWNLOAD_INNOCENT', integer_format($id));
    }
    // Size, bandwidth, logging
    $size = filesize($_full);
    if (is_null($got_before)) {
        $bandwidth = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT SUM(file_size) AS answer FROM ' . get_table_prefix() . 'download_logging l LEFT JOIN ' . get_table_prefix() . 'download_downloads d ON l.id=d.id WHERE date_and_time>' . strval(time() - 24 * 60 * 60 * 32));
        if ($bandwidth + floatval($size) > floatval(get_option('maximum_download')) * 1024 * 1024 * 1024 && !has_specific_permission(get_member(), 'bypass_bandwidth_restriction')) {
            warn_exit(do_lang_tempcode('TOO_MUCH_DOWNLOAD'));
        }
        require_code('files2');
        check_shared_bandwidth_usage($size);
    }
    log_download($id, $size, !is_null($got_before));
    // Send header
    if (strpos($myrow['original_filename'], chr(10)) !== false || strpos($myrow['original_filename'], chr(13)) !== false) {
        log_hack_attack_and_exit('HEADER_SPLIT_HACK');
    }
    header('Content-Type: application/octet-stream' . '; authoritative=true;');
    if (get_option('immediate_downloads') == '1') {
        require_code('mime_types');
        header('Content-Type: ' . get_mime_type(get_file_extension($myrow['original_filename'])) . '; authoritative=true;');
        header('Content-Disposition: filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($myrow['original_filename']))) . '"');
    } else {
        if (strstr(ocp_srv('HTTP_USER_AGENT'), 'MSIE') !== false) {
            header('Content-Disposition: filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($myrow['original_filename']))) . '"');
        } else {
            header('Content-Disposition: attachment; filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($myrow['original_filename']))) . '"');
        }
    }
    header('Accept-Ranges: bytes');
    // Caching
    header("Pragma: private");
    header("Cache-Control: private");
    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 60 * 60 * 24 * 365) . ' GMT');
    $time = is_null($myrow['edit_date']) ? $myrow['add_date'] : $myrow['edit_date'];
    $time = max($time, filemtime($_full));
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $time) . ' GMT');
    // Default to no resume
    $from = 0;
    $new_length = $size;
    @ini_set('zlib.output_compression', 'Off');
    // They're trying to resume (so update our range)
    $httprange = ocp_srv('HTTP_RANGE');
    if (strlen($httprange) > 0) {
        $_range = explode('=', ocp_srv('HTTP_RANGE'));
        if (count($_range) == 2) {
            if (strpos($_range[0], '-') === false) {
                $_range = array_reverse($_range);
            }
            $range = $_range[0];
            if (substr($range, 0, 1) == '-') {
                $range = strval($size - intval(substr($range, 1)) - 1) . $range;
            }
            if (substr($range, -1, 1) == '-') {
                $range .= strval($size - 1);
            }
            $bits = explode('-', $range);
            if (count($bits) == 2) {
                list($from, $to) = array_map('intval', $bits);
                if ($to - $from != 0 || $from == 0) {
                    $new_length = $to - $from + 1;
                    header('HTTP/1.1 206 Partial Content');
                    header('Content-Range: bytes ' . $range . '/' . strval($size));
                } else {
                    $from = 0;
                }
            }
        }
    }
    header('Content-Length: ' . strval($new_length));
    if (function_exists('set_time_limit')) {
        @set_time_limit(0);
    }
    error_reporting(0);
    // Send actual data
    $myfile = fopen($_full, 'rb');
    fseek($myfile, $from);
    $i = 0;
    flush();
    // Works around weird PHP bug that sends data before headers, on some PHP versions
    while ($i < $new_length) {
        $content = fread($myfile, min($new_length - $i, 1048576));
        echo $content;
        $len = strlen($content);
        if ($len == 0) {
            break;
        }
        $i += $len;
    }
    fclose($myfile);
    /*
    Security note... at the download adding/editing stage, we ensured that
    	only files accessible to the web server (in raw form) could end up in
    	our database.
    	Therefore we did not check here that our file was accessible in raw
    	form.
    */
}
Example #7
0
 /**
  * Actualiser: process quiz results.
  *
  * @return tempcode	The result of execution.
  */
 function _do_quiz()
 {
     $id = get_param_integer('id');
     $quizzes = $GLOBALS['SITE_DB']->query_select('quizzes', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $quizzes)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $quiz = $quizzes[0];
     $this->enforcement_checks($quiz);
     $last_visit_time = $GLOBALS['SITE_DB']->query_value_null_ok('quiz_member_last_visit', 'v_time', array('v_quiz_id' => $id, 'v_member_id' => get_member()), 'ORDER BY v_time DESC');
     if (is_null($last_visit_time)) {
         warn_exit(do_lang_tempcode('QUIZ_TWICE'));
     }
     if (!is_null($quiz['q_timeout'])) {
         if (time() - $last_visit_time > $quiz['q_timeout'] * 60 + 10) {
             warn_exit(do_lang_tempcode('TOO_LONG_ON_SCREEN'));
         }
         // +10 is for page load time, worst case scenario to be fair
     }
     // Our entry
     $entry_id = $GLOBALS['SITE_DB']->query_insert('quiz_entries', array('q_time' => time(), 'q_member' => get_member(), 'q_quiz' => $id, 'q_results' => 0), true);
     $GLOBALS['SITE_DB']->query_update('quiz_member_last_visit', array('v_time' => time() - (is_null($quiz['q_timeout']) ? 0 : $quiz['q_timeout']) * 60), array('v_member_id' => get_member(), 'v_quiz_id' => $id), '', 1);
     // Calculate results and store
     $questions = $GLOBALS['SITE_DB']->query_select('quiz_questions', array('*'), array('q_quiz' => $id));
     foreach ($questions as $i => $question) {
         $answers = $GLOBALS['SITE_DB']->query_select('quiz_question_answers', array('*'), array('q_question' => $question['id']));
         $questions[$i]['answers'] = $answers;
     }
     $marks = 0.0;
     $potential_extra_marks = 0;
     $out_of = count($questions);
     if ($out_of == 0) {
         $out_of = 1;
     }
     $results = array();
     $corrections = array();
     $unknowns = array();
     foreach ($questions as $i => $question) {
         $name = 'q_' . strval($question['id']);
         if ($question['q_num_choosable_answers'] == 0) {
             if (count($question['answers']) == 0) {
                 $potential_extra_marks++;
                 $unknowns[] = array(get_translated_text($question['q_question_text']), post_param($name));
             } else {
                 $was_right = false;
                 $correct_answer = new ocp_tempcode();
                 $correct_explanation = NULL;
                 foreach ($question['answers'] as $a) {
                     if ($a['q_is_correct'] == 1) {
                         $correct_answer = make_string_tempcode(escape_html(get_translated_text($a['q_answer_text'])));
                     }
                     if ($a['q_is_correct'] == 1 && get_translated_text($a['q_answer_text']) == post_param($name)) {
                         $marks++;
                         $was_right = true;
                         break;
                     }
                     if (get_translated_text($a['q_answer_text']) == post_param($name)) {
                         $correct_explanation = $a['q_explanation'];
                     }
                 }
                 if (!$was_right) {
                     $correction = array($question['id'], get_translated_text($question['q_question_text']), $correct_answer, post_param($name));
                     if (!is_null($correct_explanation)) {
                         $explanation = get_translated_text($correct_explanation);
                         if ($explanation != '') {
                             $correction[] = $explanation;
                         }
                     }
                     $corrections[] = $correction;
                 }
             }
             $results[$i] = post_param($name);
             $GLOBALS['SITE_DB']->query_insert('quiz_entry_answer', array('q_entry' => $entry_id, 'q_question' => $question['id'], 'q_answer' => $results[$i]));
         } elseif ($question['q_num_choosable_answers'] > 1) {
             // Vector distance
             $wrongness = 0.0;
             $accum = new ocp_tempcode();
             $correct_answer = new ocp_tempcode();
             $correct_explanation = NULL;
             foreach ($question['answers'] as $a) {
                 $for_this = post_param_integer($name . '_' . strval($a['id']), 0);
                 $should_be_this = $a['q_is_correct'];
                 $dist = $for_this - $should_be_this;
                 $wrongness += $dist * $dist;
                 if ($should_be_this == 1) {
                     if (!$correct_answer->is_empty()) {
                         $correct_answer->attach(do_lang_tempcode('LIST_SEP'));
                     }
                     $correct_answer->attach(escape_html(get_translated_text($a['q_answer_text'])));
                     $correct_explanation = $a['q_explanation'];
                 }
                 if ($for_this == 1) {
                     if (!$accum->is_empty()) {
                         $accum->attach(do_lang_tempcode('LIST_SEP'));
                     }
                     $accum->attach(escape_html(get_translated_text($a['q_answer_text'])));
                     $GLOBALS['SITE_DB']->query_insert('quiz_entry_answer', array('q_entry' => $entry_id, 'q_question' => $question['id'], 'q_answer' => strval($a['id'])));
                 }
             }
             $wrongness = sqrt($wrongness);
             // Normalise it
             $wrongness /= count($question['answers']);
             // And get our complement
             $correctness = 1.0 - $wrongness;
             $marks += $correctness;
             if ($correctness != 1.0) {
                 $correction = array($question['id'], get_translated_text($question['q_question_text']), $correct_answer, $accum);
                 if (!is_null($correct_explanation)) {
                     $explanation = get_translated_text($correct_explanation);
                     if ($explanation != '') {
                         $correction[] = $explanation;
                     }
                 }
                 $corrections[] = $correction;
             }
             $results[$i] = $accum->evaluate();
         } else {
             $was_right = false;
             $correct_answer = new ocp_tempcode();
             $correct_explanation = NULL;
             foreach ($question['answers'] as $a) {
                 if ($a['q_is_correct'] == 1) {
                     $correct_answer = make_string_tempcode(escape_html(get_translated_text($a['q_answer_text'])));
                 }
                 if (post_param_integer($name, -1) == $a['id']) {
                     $results[$i] = get_translated_text($a['q_answer_text']);
                     if ($a['q_is_correct'] == 1) {
                         $was_right = true;
                         $marks++;
                         break;
                     }
                     $correct_explanation = $a['q_explanation'];
                 }
             }
             $GLOBALS['SITE_DB']->query_insert('quiz_entry_answer', array('q_entry' => $entry_id, 'q_question' => $question['id'], 'q_answer' => post_param($name, '')));
             if (!array_key_exists($i, $results)) {
                 $results[$i] = '/';
             }
             if (!$was_right) {
                 $correction = array($question['id'], get_translated_text($question['q_question_text']), $correct_answer, $results[$i]);
                 if (!is_null($correct_explanation)) {
                     $explanation = get_translated_text($correct_explanation);
                     if ($explanation != '') {
                         $correction[] = $explanation;
                     }
                 }
                 $corrections[] = $correction;
             }
         }
     }
     $mail_title = do_lang('EMAIL_TITLE', do_lang($quiz['q_type']), $GLOBALS['FORUM_DRIVER']->get_username(get_member()), strval($entry_id), get_site_default_lang());
     $_corrections = new ocp_tempcode();
     $_corrections_to_show = new ocp_tempcode();
     foreach ($corrections as $correction) {
         $this_correction = new ocp_tempcode();
         $this_correction->attach(do_lang('QUIZ_MISTAKE', is_object($correction[1]) ? $correction[1]->evaluate() : $correction[1], is_object($correction[3]) ? $correction[3]->evaluate() : $correction[3], array(is_object($correction[2]) ? $correction[2]->evaluate() : $correction[2], array_key_exists(4, $correction) ? $correction[4] : '')));
         if (array_key_exists(4, $correction)) {
             $_corrections_to_show->attach($this_correction);
         }
         $_corrections->attach($this_correction);
     }
     $_answers = new ocp_tempcode();
     foreach ($results as $i => $result) {
         $_answers->attach(do_lang('QUIZ_RESULT', get_translated_text($questions[$i]['q_question_text']), is_null($result) ? '' : $result));
     }
     $_unknowns = new ocp_tempcode();
     foreach ($unknowns as $unknown) {
         $_unknowns->attach(do_lang('QUIZ_UNKNOWN', $unknown[0], $unknown[1]));
     }
     require_code('notifications');
     // Award points?
     if ($out_of == 0) {
         $out_of = 1;
     }
     $minimum_percentage = intval(round(100.0 * $marks / $out_of));
     $maximum_percentage = intval(round(100.0 * ($marks + $potential_extra_marks) / $out_of));
     if (addon_installed('points') && $quiz['q_points_for_passing'] != 0 && ($quiz['q_type'] != 'TEST' || $minimum_percentage >= $quiz['q_percentage'])) {
         require_code('points2');
         $points_difference = $quiz['q_points_for_passing'];
         system_gift_transfer(do_lang('POINTS_COMPLETED_QUIZ', get_translated_text($quiz['q_name'])), $points_difference, get_member());
     } else {
         $points_difference = 0;
     }
     // Give them their result if it is a test.
     if ($quiz['q_type'] == 'TEST') {
         $result = new ocp_tempcode();
         $result->attach(paragraph(do_lang_tempcode('MARKS_OUT_OF', float_format($marks) . ($potential_extra_marks == 0 ? '' : '-' . float_format($marks + $potential_extra_marks)), integer_format($out_of), strval($minimum_percentage) . ($potential_extra_marks == 0 ? '' : '-' . strval($maximum_percentage))), 'trete9r0itre'));
         $result2 = do_lang_tempcode('MAIL_MARKS_OUT_OF', float_format($marks) . ($potential_extra_marks == 0 ? '' : '-' . float_format($marks + $potential_extra_marks)), integer_format($out_of), strval($minimum_percentage) . ($potential_extra_marks == 0 ? '' : '-' . strval($maximum_percentage)));
         if ($minimum_percentage >= $quiz['q_percentage']) {
             $result->attach(paragraph(do_lang_tempcode('TEST_PASS'), '4tfdhdhghh'));
             $result2->attach(do_lang_tempcode('MAIL_TEST_PASS'));
             syndicate_described_activity('quiz:ACTIVITY_PASSED_TEST', get_translated_text($quiz['q_name']), '', '', '_SEARCH:quiz:do:' . strval($id), '', '', 'quizzes');
         } elseif ($maximum_percentage < $quiz['q_percentage']) {
             $result->attach(paragraph(do_lang_tempcode('TEST_FAIL'), '5yrgdgsdg'));
             $result2->attach(do_lang_tempcode('MAIL_TEST_FAIL'));
         } else {
             $result->attach(paragraph(do_lang_tempcode('TEST_UNKNOWN'), 'yteyrthrt'));
             $result2->attach(do_lang_tempcode('MAIL_TEST_UNKNOWN'));
         }
         // Send mail about the result to the staff: include result and corrections, and unknowns
         $mail = do_template('QUIZ_TEST_ANSWERS_MAIL', array('_GUID' => 'a0f8f47cdc1ef83b59c93135ebb5c114', 'UNKNOWNS' => $_unknowns, 'CORRECTIONS' => $_corrections, 'RESULT' => $result2, 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username(get_member())));
         dispatch_notification('quiz_results', strval($id), $mail_title, $mail->evaluate(get_site_default_lang()));
     } elseif ($quiz['q_type'] == 'COMPETITION') {
         $result = comcode_to_tempcode($_corrections->evaluate());
         syndicate_described_activity('quiz:ACTIVITY_ENTERED_COMPETITION', get_translated_text($quiz['q_name']), '', '', '_SEARCH:quiz:do:' . strval($id), '', '', 'quizzes');
     } else {
         $result = paragraph(do_lang_tempcode('SURVEY_THANKYOU'), '4rtyrthgf');
         $_answers = do_template('QUIZ_ANSWERS_MAIL', array('_GUID' => '381f392c8e491b6e078bcae34adc45e8', 'ANSWERS' => $_answers, 'MEMBER_PROFILE_URL' => is_guest() ? '' : $GLOBALS['FORUM_DRIVER']->member_profile_url(get_member(), false, true), 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username(get_member())));
         // Send mail of answers to the staff
         dispatch_notification('quiz_results', strval($id), $mail_title, $_answers->evaluate(get_site_default_lang()));
         syndicate_described_activity('quiz:ACTIVITY_FILLED_SURVEY', get_translated_text($quiz['q_name']), '', '', '_SEARCH:quiz:do:' . strval($id), '', '', 'quizzes');
     }
     // Store results for entry
     $GLOBALS['SITE_DB']->query_update('quiz_entries', array('q_results' => intval(round($marks))), array('id' => $entry_id), '', 1);
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', make_string_tempcode(escape_html(get_translated_text($quiz['q_name']))))));
     // Show end text
     $title = get_page_title(do_lang_tempcode('THIS_WITH', do_lang_tempcode($quiz['q_type']), make_string_tempcode(escape_html(get_translated_text($quiz['q_name'])))), false);
     $fail_text = get_translated_tempcode($quiz['q_end_text_fail']);
     $message = $quiz['q_type'] != 'TEST' || $minimum_percentage >= $quiz['q_percentage'] || $fail_text->is_empty() ? get_translated_tempcode($quiz['q_end_text']) : get_translated_tempcode($quiz['q_end_text_fail']);
     return do_template('QUIZ_DONE_SCREEN', array('_GUID' => 'fa783f087eca7f8f577b134ec0bdc4ce', 'CORRECTIONS_TO_SHOW' => comcode_to_tempcode($_corrections_to_show->evaluate()), 'POINTS_DIFFERENCE' => strval($points_difference), 'RESULT' => $result, 'TITLE' => $title, 'TYPE' => $quiz['q_type'], 'MESSAGE' => $message));
 }
Example #8
0
/**
 * Set the poll.
 *
 * @param  AUTO_LINK		The poll ID to set
 */
function set_poll($id)
{
    persistant_cache_delete('POLL');
    $rows = $GLOBALS['SITE_DB']->query_select('poll', array('question', 'submitter'), array('id' => $id));
    $question = $rows[0]['question'];
    $submitter = $rows[0]['submitter'];
    log_it('CHOOSE_POLL', strval($id), get_translated_text($question));
    if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'polls')) {
        syndicate_described_activity('polls:ACTIVITY_CHOOSE_POLL', get_translated_text($question), '', '', '_SEARCH:polls:view:' . strval($id), '', '', 'polls');
    }
    if (!is_guest($submitter) && addon_installed('points')) {
        require_code('points2');
        $_points_chosen = get_option('points_CHOOSE_POLL');
        if (is_null($_points_chosen)) {
            $points_chosen = 35;
        } else {
            $points_chosen = intval($_points_chosen);
        }
        if ($points_chosen != 0) {
            system_gift_transfer(do_lang('POLL'), $points_chosen, $submitter);
        }
    }
    $GLOBALS['SITE_DB']->query_update('poll', array('is_current' => 0), array('is_current' => 1));
    $GLOBALS['SITE_DB']->query_update('poll', array('is_current' => 1, 'date_and_time' => time()), array('id' => $id), '', 1);
    decache('main_poll');
    require_lang('polls');
    require_code('notifications');
    $subject = do_lang('POLL_CHOSEN_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $question);
    $poll_url = build_url(array('page' => 'polls', 'type' => 'view', 'id' => $id), get_module_zone('polls'), NULL, false, false, true);
    $mail = do_lang('POLL_CHOSEN_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape(get_translated_text($question)), $poll_url->evaluate());
    dispatch_notification('poll_chosen', NULL, $subject, $mail);
}
Example #9
0
/**
 * Set the IOTD.
 *
 * @param  AUTO_LINK		The IOTD ID to set
 */
function set_iotd($id)
{
    $rows = $GLOBALS['SITE_DB']->query_select('iotd', array('*'), array('id' => $id), '', 1);
    $title = get_translated_text($rows[0]['i_title']);
    $submitter = $rows[0]['submitter'];
    log_it('CHOOSE_IOTD', strval($id), $title);
    if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'iotds')) {
        syndicate_described_activity('iotds:ACTIVITY_CHOOSE_IOTD', $title, '', '', '_SEARCH:iotds:view:' . strval($id), '', '', 'iotds');
    }
    if (!is_guest($submitter) && addon_installed('points')) {
        require_code('points2');
        $_points_chosen = get_option('points_CHOOSE_IOTD');
        if (is_null($_points_chosen)) {
            $points_chosen = 35;
        } else {
            $points_chosen = intval($_points_chosen);
        }
        if ($points_chosen != 0) {
            system_gift_transfer(do_lang('IOTD'), $points_chosen, $submitter);
        }
    }
    // Turn all others off
    $GLOBALS['SITE_DB']->query_update('iotd', array('is_current' => 0), array('is_current' => 1));
    // Turn ours on
    $GLOBALS['SITE_DB']->query_update('iotd', array('is_current' => 1, 'used' => 1, 'date_and_time' => time()), array('id' => $id), '', 1);
    require_lang('iotds');
    require_code('notifications');
    $view_url = build_url(array('page' => 'iotds', 'type' => 'view', 'id' => $id), get_module_zone('iotds'), NULL, false, false, true);
    $thumb_url = $rows[0]['thumb_url'];
    if (url_is_local($thumb_url)) {
        $thumb_url = get_custom_base_url() . '/' . $thumb_url;
    }
    $subject = do_lang('IOTD_CHOSEN_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $title);
    $mail = do_lang('IOTD_CHOSEN_NOTIFICATION_MAIL', comcode_escape(get_site_name()), $title, array($view_url->evaluate(), $thumb_url));
    dispatch_notification('iotd_chosen', NULL, $subject, $mail);
    decache('main_iotd');
}
Example #10
0
 /**
  * Standard modular run function for CRON hooks. Searches for tasks to perform.
  */
 function run()
 {
     //if (!addon_installed('octhief')) return;
     require_code('ocf_topics_action2');
     require_code('points');
     require_lang('octhief');
     // ensure it is done once per week
     $time = time();
     $last_time = intval(get_value('last_thieving_time'));
     if ($last_time > time() - 24 * 60 * 60 * 7) {
         return;
     }
     set_value('last_thieving_time', strval($time));
     $octhief_type = get_option('octhief_type', true);
     $octhief_type = isset($octhief_type) && strlen($octhief_type) > 0 ? $octhief_type : 'Members that are inactive, but has lots points';
     $_octhief_number = get_option('octhief_number', true);
     $octhief_number = isset($_octhief_number) && is_numeric($_octhief_number) ? intval($_octhief_number) : 1;
     $_octhief_points = get_option('octhief_points', true);
     $octhief_points = isset($_octhief_points) && is_numeric($_octhief_points) ? intval($_octhief_points) : 10;
     $octhief_group = get_option('octhief_group', true);
     $octhief_group = isset($octhief_group) && strlen($octhief_group) > 0 ? $octhief_group : 'Member';
     // start determining the various cases
     if ($octhief_type == "Members that are inactive, but has lots points") {
         $all_members = $GLOBALS['FORUM_DRIVER']->get_top_posters(1000);
         $points = array();
         foreach ($all_members as $member) {
             $id = $GLOBALS['FORUM_DRIVER']->pname_id($member);
             $signin_time = $member['m_last_visit_time'];
             $points[$signin_time] = array('points' => available_points($id), 'id' => $id);
         }
         ksort($points);
         //print_r($points);
         $octhief_number = count($points) > $octhief_number ? $octhief_number : count($points);
         $theft_count = 0;
         foreach ($points as $member) {
             $theft_count++;
             if ($theft_count > $octhief_number) {
                 break;
             }
             // start stealing
             require_code('points2');
             require_lang('octhief');
             $total_points = $member['points'];
             $octhief_points = $octhief_points < $total_points ? $octhief_points : $total_points;
             $give_to_member = $GLOBALS['FORUM_DB']->query('SELECT id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE  id <> ' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . ' AND id <> ' . strval($member['id']) . ' ORDER BY RAND( ) ', 1, NULL, true);
             $give_to_member = isset($give_to_member[0]['id']) && $give_to_member[0]['id'] > 0 ? $give_to_member[0]['id'] : 0;
             // get THIEF points
             charge_member($member['id'], $octhief_points, do_lang('THIEF_GET') . ' ' . strval($octhief_points) . ' point(-s) from you.');
             if ($give_to_member > 0) {
                 system_gift_transfer(do_lang('THIEF_GAVE_YOU') . ' ' . strval($octhief_points) . ' point(-s)', $octhief_points, $give_to_member);
                 require_code('ocf_topic_action');
                 require_code('ocf_posts_action');
                 $subject = do_lang('THIEF_PT_TOPIC', strval($octhief_points), $GLOBALS['FORUM_DRIVER']->get_username($member['id']), $GLOBALS['FORUM_DRIVER']->get_username($give_to_member));
                 $topic_id = ocf_make_topic(NULL, $subject, '', 1, 1, 0, 0, 0, $member['id'], $give_to_member, false, 0, NULL, '');
                 $post_id = ocf_make_post($topic_id, $subject, do_lang('THIEF_PT_TOPIC_POST'), 0, true, 1, 0, NULL, NULL, NULL, $give_to_member, NULL, NULL, NULL, false, true, NULL, true, $subject, 0, NULL, true, true, true);
                 send_pt_notification($post_id, $subject, $topic_id, $give_to_member, $GLOBALS['FORUM_DRIVER']->pname_id($member));
                 send_pt_notification($post_id, $subject, $topic_id, $GLOBALS['FORUM_DRIVER']->pname_id($member), $give_to_member);
             }
         }
     } elseif ($octhief_type == "Members that are rich") {
         $all_members = $GLOBALS['FORUM_DRIVER']->get_top_posters(100);
         $points = array();
         foreach ($all_members as $member) {
             $id = $GLOBALS['FORUM_DRIVER']->pname_id($member);
             $points[$id] = available_points($id);
         }
         arsort($points);
         $octhief_number = count($points) > $octhief_number ? $octhief_number : count($points);
         $theft_count = 0;
         foreach ($points as $member_id => $av_points) {
             $theft_count++;
             if ($theft_count > $octhief_number) {
                 break;
             }
             // start stealing
             require_code('points2');
             require_lang('octhief');
             $total_points = $av_points;
             $octhief_points = $octhief_points < $total_points ? $octhief_points : $total_points;
             $give_to_member = $GLOBALS['FORUM_DB']->query('SELECT id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE  id <> ' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . ' AND id <> ' . strval($member_id) . ' ORDER BY RAND( ) ', 1, NULL, true);
             $give_to_member = isset($give_to_member[0]['id']) && $give_to_member[0]['id'] > 0 ? $give_to_member[0]['id'] : 0;
             // get THIEF points
             charge_member($member_id, $octhief_points, do_lang('THIEF_GET') . ' ' . strval($octhief_points) . ' point(-s) from you.');
             if ($give_to_member > 0) {
                 system_gift_transfer(do_lang('THIEF_GAVE_YOU') . ' ' . strval($octhief_points) . ' point(-s)', $octhief_points, $give_to_member);
                 require_code('ocf_topic_action');
                 require_code('ocf_posts_action');
                 $subject = do_lang('THIEF_PT_TOPIC', strval($octhief_points));
                 $topic_id = ocf_make_topic(NULL, $subject, '', 1, 1, 0, 0, 0, $member_id, $give_to_member, false, 0, NULL, '');
                 $post_id = ocf_make_post($topic_id, $subject, do_lang('THIEF_PT_TOPIC_POST'), 0, true, 1, 0, NULL, NULL, NULL, $give_to_member, NULL, NULL, NULL, false, true, NULL, true, $subject, 0, NULL, true, true, true);
                 send_pt_notification($post_id, $subject, $topic_id, $give_to_member, $member);
                 send_pt_notification($post_id, $subject, $topic_id, $member, $give_to_member);
             }
         }
     } elseif ($octhief_type == "Members that are random") {
         $random_members = $GLOBALS['FORUM_DB']->query('SELECT id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE  id <> ' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . ' ORDER BY RAND( ) ', $octhief_number, NULL, true);
         $octhief_number = count($random_members) > $octhief_number ? $octhief_number : count($random_members);
         foreach ($random_members as $member) {
             // start stealing
             require_code('points2');
             require_lang('octhief');
             $total_points = available_points($member['id']);
             $octhief_points = $octhief_points < $total_points ? $octhief_points : $total_points;
             $give_to_member = $GLOBALS['FORUM_DB']->query('SELECT id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE  id <> ' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . ' AND id <> ' . strval($member['id']) . ' ORDER BY RAND( ) ', 1, NULL, true);
             $give_to_member = isset($give_to_member[0]['id']) && $give_to_member[0]['id'] > 0 ? $give_to_member[0]['id'] : 0;
             // get THIEF points
             charge_member($member['id'], $octhief_points, do_lang('THIEF_GET') . ' ' . strval($octhief_points) . ' point(-s) from you.');
             if ($give_to_member != 0) {
                 system_gift_transfer(do_lang('THIEF_GAVE_YOU') . ' ' . strval($octhief_points) . ' point(-s)', $octhief_points, $give_to_member);
                 require_code('ocf_topic_action');
                 require_code('ocf_posts_action');
                 $subject = do_lang('THIEF_PT_TOPIC', strval($octhief_points));
                 $topic_id = ocf_make_topic(NULL, $subject, '', 1, 1, 0, 0, 0, $member['id'], $give_to_member, false, 0, NULL, '');
                 $post_id = ocf_make_post($topic_id, $subject, do_lang('THIEF_PT_TOPIC_POST'), 0, true, 1, 0, NULL, NULL, NULL, $give_to_member, NULL, NULL, NULL, false, true, NULL, true, $subject, 0, NULL, true, true, true);
                 send_pt_notification($post_id, $subject, $topic_id, $give_to_member, $member);
                 send_pt_notification($post_id, $subject, $topic_id, $member, $give_to_member);
             }
         }
     } elseif ($octhief_type == "Members that are in a certain usergroup") {
         $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list();
         $group_id = 0;
         foreach ($groups as $id => $group) {
             if ($octhief_group == $group) {
                 $group_id = $id;
             }
         }
         require_code('ocf_groups2');
         $members = ocf_get_group_members_raw($group_id);
         $octhief_number = count($members) > $octhief_number ? $octhief_number : count($members);
         $members_to_steal_ids = array_rand($members, $octhief_number);
         if ($octhief_number == 1) {
             $members_to_steal_ids = array('0' => $members_to_steal_ids);
         }
         foreach ($members_to_steal_ids as $member_rand_key) {
             // start stealing
             require_code('points2');
             require_lang('octhief');
             //echo $members[$member_rand_key];
             $total_points = available_points($members[$member_rand_key]);
             $octhief_points = $octhief_points < $total_points ? $octhief_points : $total_points;
             $give_to_member = $GLOBALS['FORUM_DB']->query('SELECT id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE  id <> ' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . ' AND id <> ' . strval($members[$member_rand_key]) . ' ORDER BY RAND( ) ', 1, NULL, true);
             $give_to_member = isset($give_to_member[0]['id']) && $give_to_member[0]['id'] > 0 ? $give_to_member[0]['id'] : 0;
             // get THIEF points
             charge_member($members[$member_rand_key], $octhief_points, do_lang('THIEF_GET') . ' ' . strval($octhief_points) . ' point(-s) from you.');
             if ($give_to_member != 0) {
                 system_gift_transfer(do_lang('THIEF_GAVE_YOU') . ' ' . strval($octhief_points) . ' point(-s)', $octhief_points, $give_to_member);
                 require_code('ocf_topics_action');
                 $subject = do_lang('THIEF_PT_TOPIC', strval($octhief_points));
                 $topic_id = ocf_make_topic(NULL, $subject, '', 1, 1, 0, 0, 0, $members[$member_rand_key], $give_to_member, false, 0, NULL, '');
                 require_code('ocf_posts_action');
                 $post_id = ocf_make_post($topic_id, $subject, do_lang('THIEF_PT_TOPIC_POST'), 0, true, 1, 0, NULL, NULL, NULL, $give_to_member, NULL, NULL, NULL, false, true, NULL, true, $subject, 0, NULL, true, true, true);
                 require_code('ocf_topics_action2');
                 send_pt_notification($post_id, $subject, $topic_id, $give_to_member, $octhief_number);
                 send_pt_notification($post_id, $subject, $topic_id, $octhief_number, $give_to_member);
             }
         }
     }
 }
Example #11
0
 function run($ob, $query, $max, $start, $fail_ok, $get_insert_id, $ret)
 {
     if (!isset($GLOBALS['FORUM_DB'])) {
         return;
     }
     if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 1) {
         return;
     }
     if ($GLOBALS['BOOTSTRAPPING'] == 1) {
         return;
     }
     //if (strpos($query,$GLOBALS['FORUM_DB']->get_table_prefix().'f_members')!==false && strpos($query,'BY RAND')==false) // to test without registration
     if (strpos($query, 'INTO ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts') !== false) {
         require_code('permissions');
         load_user_stuff();
         if (method_exists($GLOBALS['FORUM_DRIVER'], 'forum_layer_initialise')) {
             $GLOBALS['FORUM_DRIVER']->forum_layer_initialise();
         }
         global $FORCE_INVISIBLE_GUEST, $MEMBER_CACHED;
         $FORCE_INVISIBLE_GUEST = false;
         $MEMBER_CACHED = NULL;
         $poster_id = get_member();
         $post = post_param('post', '');
         $posted_data = $GLOBALS['FORUM_DB']->query('SELECT * FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE id= ' . strval($ret) . ' ', 1, NULL, true);
         $topic_id = isset($posted_data[0]['p_topic_id']) && $posted_data[0]['p_topic_id'] > 0 ? $posted_data[0]['p_topic_id'] : 0;
         $first_post_data = $GLOBALS['FORUM_DB']->query('SELECT * FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE p_topic_id= ' . strval($topic_id) . ' ORDER BY p_time,id', 1, NULL, true);
         $first_post = $first_post_data[0]['p_post'];
         $first_post = get_translated_text($first_post);
         $_insult = explode('[b]', $first_post);
         $insult = isset($_insult[1]) && strlen($_insult[1]) > 0 ? $_insult[1] : '';
         $_insult = explode('[/b]', $insult);
         $insult = isset($_insult[0]) && strlen($_insult[0]) > 0 ? $_insult[0] : '';
         //old code that uses quotes
         //$insult=explode('"',$first_post);
         //$insult=(isset($insult[1]) && strlen($insult[1])>0)?$insult[1]:'';
         if ($insult != '') {
             $get_reply = '';
             if (is_file(get_file_base() . '/text_custom/' . user_lang() . '/insults.txt')) {
                 $insults = file(get_file_base() . '/text_custom/' . user_lang() . '/insults.txt');
                 $insults_array = array();
                 foreach ($insults as $insult_item) {
                     $x = explode('=', $insult_item);
                     if (isset($x[0]) && strlen($x[0]) > 0 && isset($x[1]) && strlen($x[1]) > 0) {
                         $insults_array[trim($x[0])] = trim($x[1]);
                     }
                 }
                 $get_reply = isset($insults_array[$insult]) ? $insults_array[$insult] : '';
             }
             if ($get_reply != '') {
                 //get PT
                 $pt = $GLOBALS['FORUM_DB']->query('SELECT * FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE id= ' . strval($topic_id) . ' ', 1, NULL, true);
                 $to_member = isset($pt[0]['t_pt_to']) && $pt[0]['t_pt_to'] > 0 ? $pt[0]['t_pt_to'] : 0;
                 if ($to_member == $poster_id) {
                     //start comparing insult reply and the post
                     if (levenshtein(trim(strtolower($post)), trim(strtolower($get_reply))) < intval(0.1 * strlen($get_reply))) {
                         $_insult_points = get_option('insult_points', true);
                         $insult_points = isset($_insult_points) && intval($_insult_points) > 0 ? intval($_insult_points) : 10;
                         // give points
                         require_code('points2');
                         require_lang('insults');
                         $rows = $GLOBALS['FORUM_DB']->query('SELECT g.id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'gifts g LEFT JOIN ' . get_table_prefix() . 'translate t ON t.id=g.reason WHERE t.text_original LIKE "' . db_encode_like('%' . $insult . '%') . '" AND g.gift_to=' . strval($poster_id), 1, NULL, true);
                         //if the member doesn't get reward yet, give him/her his award
                         if (!isset($rows[0]['id'])) {
                             system_gift_transfer(do_lang('SUCCESSFULLY_SUGGESTED_COMEBACK') . ' (' . $insult . ')', intval($insult_points), $poster_id);
                             require_code('ocf_posts_action');
                             $congratulations_post = do_lang('CONGRATULATIONS_WON');
                             //Congratulations that is the correct response
                             ocf_make_post($topic_id, '', $congratulations_post, 0, true, 1, 0, do_lang('SYSTEM'), NULL, NULL, $GLOBALS['FORUM_DRIVER']->get_guest_id(), $poster_id, NULL, NULL, false, true, NULL, true, '', 0, NULL, false, true, true);
                         }
                     }
                 }
             }
         }
     }
 }
Example #12
0
 /**
  * Standard aed_module add actualiser.
  *
  * @return ID_TEXT		The ID of the entry added
  */
 function add_actualisation()
 {
     require_code('catalogues2');
     $category_id = post_param_integer('category_id');
     $validated = post_param_integer('validated', 0);
     $notes = post_param('notes', '');
     $allow_rating = post_param_integer('allow_rating', 0);
     $allow_comments = post_param_integer('allow_comments', 0);
     $allow_trackbacks = post_param_integer('allow_trackbacks', 0);
     $catalogue_name = $GLOBALS['SITE_DB']->query_value_null_ok('catalogue_categories', 'c_name', array('id' => $category_id));
     if (is_null($catalogue_name)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $map = $this->get_set_field_map($catalogue_name);
     if (!is_guest() && addon_installed('points')) {
         $points = $GLOBALS['SITE_DB']->query_value('catalogues', 'c_submit_points', array('c_name' => $catalogue_name));
         require_code('points2');
         system_gift_transfer(do_lang('ADD_CATALOGUE_ENTRY'), intval($points), get_member());
     }
     $id = actual_add_catalogue_entry($category_id, $validated, $notes, $allow_rating, $allow_comments, $allow_trackbacks, $map);
     if ($validated == 1 || !addon_installed('unvalidated')) {
         if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'catalogues') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'catalogues_catalogue', $catalogue_name) && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'catalogues_category', strval($category_id))) {
             $map_copy = $map;
             $title = array_shift($map_copy);
             $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => $catalogue_name)));
             syndicate_described_activity('catalogues:ACTIVITY_CATALOGUE_GENERIC_ADD', $catalogue_title, $title, '', '_SEARCH:catalogues:entry:' . strval($id), '', '', 'catalogues');
         }
     }
     $this->donext_category_id = $category_id;
     $this->donext_catalogue_name = $catalogue_name;
     return strval($id);
 }
Example #13
0
/**
 * Give points to a member for submitting something, then returns the XHTML page to say so.
 *
 * @param  ID_TEXT		One of this type has been submitted. By convention it is the language code of what was done, e.g. ADD_DOWNLOAD
 * @param  ?MEMBER		The member to give the points to (NULL: give to current member)
 * @return ?string		A message about the member being given these submit points (NULL: no message)
 */
function give_submit_points($type, $member = NULL)
{
    if (is_null($member)) {
        $member = get_member();
    }
    if (!is_guest($member) && addon_installed('points')) {
        $points = get_option('points_' . $type, true);
        if (is_null($points)) {
            return '';
        }
        require_code('points2');
        system_gift_transfer(do_lang($type), intval($points), get_member());
        return do_lang('SUBMIT_AWARD', integer_format(intval($points)));
    }
    return NULL;
}
Example #14
0
/**
 * Give an award.
 *
 * @param  AUTO_LINK			The award ID
 * @param  ID_TEXT			The content ID
 * @param  ?TIME				Time the award was given (NULL: now)
 */
function give_award($award_id, $content_id, $time = NULL)
{
    require_lang('awards');
    if (is_null($time)) {
        $time = time();
    }
    $awards = $GLOBALS['SITE_DB']->query_select('award_types', array('*'), array('id' => $award_id), '', 1);
    if (!array_key_exists(0, $awards)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $award_title = get_translated_text($awards[0]['a_title']);
    log_it('GIVE_AWARD', strval($award_id), $award_title);
    require_code('hooks/systems/awards/' . filter_naughty_harsh($awards[0]['a_content_type']));
    $object = object_factory('Hook_awards_' . $awards[0]['a_content_type']);
    $info = $object->info();
    if (is_null($info)) {
        fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
    }
    if (array_key_exists('submitter_field', $info) && $awards[0]['a_content_type'] != 'author' && !is_null($info['submitter_field'])) {
        require_code('content');
        list($content_title, $member_id, , $content) = content_get_details($awards[0]['a_content_type'], $content_id);
        if (is_null($content)) {
            warn_exit(do_lang_tempcode('_MISSING_RESOURCE', escape_html($awards[0]['a_content_type'] . ':' . $content_id)));
        }
        // Lots of fiddling around to work out how to check permissions for this
        $permission_type_code = convert_ocportal_type_codes('award_hook', $awards[0]['a_content_type'], 'permissions_type_code');
        $module = convert_ocportal_type_codes('module', $awards[0]['a_content_type'], 'permissions_type_code');
        if ($module == '') {
            $module = $content_id;
        }
        $category_id = mixed();
        if (isset($info['category_field'])) {
            if (is_array($info['category_field'])) {
                $category_id = $content[$info['category_field'][1]];
            } else {
                $category_id = $content[$info['category_field']];
            }
        }
        if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'awards') && has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), $module) && ($permission_type_code == '' || is_null($category_id) || has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), $permission_type_code, is_integer($category_id) ? strval($category_id) : $category_id))) {
            syndicate_described_activity(is_null($member_id) || is_guest($member_id) ? 'awards:_ACTIVITY_GIVE_AWARD' : 'awards:ACTIVITY_GIVE_AWARD', $award_title, $content_title, '', '_SEARCH:awards:award:' . strval($award_id), '', '', 'awards', 1, NULL, false, $member_id);
        }
    } else {
        $member_id = NULL;
    }
    if (is_null($member_id)) {
        $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id();
    }
    if (!is_guest($member_id) && addon_installed('points')) {
        require_code('points2');
        system_gift_transfer(do_lang('_AWARD', get_translated_text($awards[0]['a_title'])), $awards[0]['a_points'], $member_id);
    }
    $GLOBALS['SITE_DB']->query_insert('award_archive', array('a_type_id' => $award_id, 'member_id' => $member_id, 'content_id' => $content_id, 'date_and_time' => $time));
    decache('main_awards');
    decache('main_multi_content');
}