Beispiel #1
0
/**
 * Add a buddy.
 *
 * @param  MEMBER			The member befriending
 * @param  MEMBER			The member being befriended
 * @param  ?TIME			The logged time of the friendship (NULL: now)
 */
function buddy_add($likes, $liked, $time = NULL)
{
    if (is_null($time)) {
        $time = time();
    }
    $GLOBALS['SITE_DB']->query_delete('chat_buddies', array('member_likes' => $likes, 'member_liked' => $liked), '', 1);
    // Just in case page refreshed
    $GLOBALS['SITE_DB']->query_insert('chat_buddies', array('member_likes' => $likes, 'member_liked' => $liked, 'date_and_time' => $time));
    // Send a notification
    if (is_null($GLOBALS['SITE_DB']->query_value_null_ok('chat_buddies', 'date_and_time', array('member_likes' => $liked, 'member_liked' => $likes)))) {
        require_lang('chat');
        require_code('notifications');
        $to_name = $GLOBALS['FORUM_DRIVER']->get_username($liked);
        $from_name = $GLOBALS['FORUM_DRIVER']->get_username($likes);
        $subject_tag = do_lang('YOURE_MY_BUDDY_SUBJECT', $from_name, get_site_name(), NULL, get_lang($liked));
        $befriend_url = build_url(array('page' => 'chat', 'type' => 'buddy_add', 'member_id' => $likes), get_module_zone('chat'), NULL, false, false, true);
        $message_raw = do_lang('YOURE_MY_BUDDY_BODY', comcode_escape($to_name), comcode_escape(get_site_name()), array($befriend_url->evaluate(), comcode_escape($from_name)), get_lang($liked));
        dispatch_notification('new_buddy', NULL, $subject_tag, $message_raw, array($liked), $likes);
        // Log the action
        log_it('MAKE_BUDDY', strval($likes), strval($liked));
        syndicate_described_activity('chat:PEOPLE_NOW_FRIENDS', $to_name, '', '', '_SEARCH:members:view:' . strval($liked), '_SEARCH:members:view:' . strval($likes), '', 'chat', 1, $likes);
        syndicate_described_activity('chat:PEOPLE_NOW_FRIENDS', $to_name, '', '', '_SEARCH:members:view:' . strval($liked), '_SEARCH:members:view:' . strval($likes), '', 'chat', 1, $liked);
    }
}
Beispiel #2
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));
 }
Beispiel #3
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);
}
Beispiel #4
0
 /**
  * Standard aed_module edit actualiser.
  *
  * @param  ID_TEXT		The entry being edited
  */
 function edit_actualisation($_id)
 {
     $id = intval($_id);
     $validated = post_param_integer('validated', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $news_article = post_param('post', STRING_MAGIC_NULL);
     if (post_param('main_news_category') != 'personal') {
         $main_news_category = post_param_integer('main_news_category', INTEGER_MAGIC_NULL);
     } else {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     $news_category = array();
     if (array_key_exists('news_category', $_POST)) {
         foreach ($_POST['news_category'] as $val) {
             $news_category[] = intval($val);
         }
     }
     $allow_rating = post_param_integer('allow_rating', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $allow_comments = post_param_integer('allow_comments', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $allow_trackbacks = post_param_integer('allow_trackbacks', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $notes = post_param('notes', STRING_MAGIC_NULL);
     $this->donext_type = $main_news_category;
     if (!fractional_edit()) {
         $urls = get_url('', 'file', 'uploads/grepimages', 0, OCP_UPLOAD_IMAGE);
         $url = $urls[0];
         if ($url != '' && function_exists('imagecreatefromstring')) {
             convert_image(get_base_url() . '/' . $url, get_file_base() . '/uploads/grepimages/' . basename(rawurldecode($url)), -1, -1, intval(get_option('thumb_width')), true, NULL, false, true);
         }
         if ($url == '' && post_param_integer('file_unlink', 0) != 1) {
             $url = NULL;
         }
     } else {
         $url = STRING_MAGIC_NULL;
     }
     $owner = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'nc_owner', array('id' => $main_news_category));
     // null_ok in case somehow category setting corrupted
     if (!is_null($owner) && $owner != get_member()) {
         check_specific_permission('can_submit_to_others_categories', array('news', $main_news_category), NULL, 'cms_news');
     }
     $schedule = get_input_date('schedule');
     $add_time = is_null($schedule) ? mixed() : $schedule;
     if (addon_installed('calendar') && has_specific_permission(get_member(), 'scheduled_publication_times')) {
         require_code('calendar2');
         $schedule_code = ':$GLOBALS[\'SITE_DB\']->query_update(\'news\',array(\'date_and_time\'=>$GLOBALS[\'event_timestamp\'],\'validated\'=>1),array(\'id\'=>' . strval($id) . '),\'\',1);';
         $past_event = $GLOBALS['SITE_DB']->query_value_null_ok('calendar_events e LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON e.e_content=t.id', 'e.id', array('text_original' => $schedule_code));
         require_code('calendar');
         if (!is_null($past_event)) {
             delete_calendar_event($past_event);
         }
         if (!is_null($schedule) && $schedule > time()) {
             $validated = 0;
             $start_year = post_param_integer('schedule_year');
             $start_month = post_param_integer('schedule_month');
             $start_day = post_param_integer('schedule_day');
             $start_hour = post_param_integer('schedule_hour');
             $start_minute = post_param_integer('schedule_minute');
             $event_id = add_calendar_event(db_get_first_id(), 'none', NULL, 0, do_lang('PUBLISH_NEWS', 0, post_param('title')), $schedule_code, 3, 0, $start_year, $start_month, $start_day, $start_hour, $start_minute);
             regenerate_event_reminder_jobs($event_id, true);
         }
     }
     $title = post_param('title', STRING_MAGIC_NULL);
     if ($validated == 1 && $main_news_category != INTEGER_MAGIC_NULL && $GLOBALS['SITE_DB']->query_value('news', 'validated', array('id' => intval($id))) == 0) {
         $is_blog = true;
         $submitter = $GLOBALS['SITE_DB']->query_value('news', 'submitter', array('id' => $id));
         $activity_title = $is_blog ? 'news:ACTIVITY_ADD_NEWS_BLOG' : 'news:ACTIVITY_ADD_NEWS';
         $activity_title_validate = $is_blog ? 'news:ACTIVITY_VALIDATE_NEWS_BLOG' : 'news:ACTIVITY_VALIDATE_NEWS';
         if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'news')) {
             // NB: no category permission check, as syndication choice was explicit, and news categorisation is a bit more complex
             syndicate_described_activity($submitter != get_member() ? $activity_title_validate : $activity_title, $title, '', '', '_SEARCH:news:view:' . strval($id), '', '', 'news', 1, NULL, true);
         }
     }
     edit_news(intval($id), $title, post_param('news', STRING_MAGIC_NULL), post_param('author', STRING_MAGIC_NULL), $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $news_article, $main_news_category, $news_category, post_param('meta_keywords', STRING_MAGIC_NULL), post_param('meta_description', STRING_MAGIC_NULL), $url, $add_time);
 }
Beispiel #5
0
 /**
  * Subscribe for reminders to an event.
  *
  * @return tempcode		The UI
  */
 function _subscribe_event()
 {
     $title = get_page_title('SUBSCRIBE_EVENT');
     $seconds_before = intval(floatval(post_param('hours_before')) * 3600.0);
     $id = get_param_integer('id');
     // The event ID
     $events = $GLOBALS['SITE_DB']->query_select('calendar_events', array('*'), array('id' => get_param_integer('id')), '', 1);
     $event = $events[0];
     $rem_id = $GLOBALS['SITE_DB']->query_insert('calendar_reminders', array('e_id' => $id, 'n_member_id' => get_member(), 'n_seconds_before' => $seconds_before), true);
     if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'calendar') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'calendar', strval($event['e_type']))) {
         $_from = cal_get_start_utctime_for_event($event['e_timezone'], $event['e_start_year'], $event['e_start_month'], $event['e_start_day'], $event['e_start_hour'], $event['e_start_minute'], $event['e_do_timezone_conv'] == 1);
         $from = cal_utctime_to_usertime($_from, $event['e_timezone'], $event['e_do_timezone_conv'] == 1);
         $to = mixed();
         if (!is_null($event['e_end_year']) && !is_null($event['e_end_month']) && !is_null($event['e_end_day'])) {
             $_to = cal_get_end_utctime_for_event($event['e_timezone'], $event['e_end_year'], $event['e_end_month'], $event['e_end_day'], $event['e_end_hour'], $event['e_end_minute'], $event['e_do_timezone_conv'] == 1);
             $to = cal_utctime_to_usertime($_to, $event['e_timezone'], $event['e_do_timezone_conv'] == 1);
         }
         syndicate_described_activity('calendar:ACTIVITY_SUBSCRIBED_EVENT', get_translated_text($event['e_title']), date_range($from, $to, !is_null($event['e_start_hour'])), '', '_SEARCH:calendar:view:' . strval($id), '', '', 'calendar', 1, NULL, true);
     }
     // Add next reminder to job system
     $recurrences = find_periods_recurrence($event['e_timezone'], 1, $event['e_start_year'], $event['e_start_month'], $event['e_start_day'], is_null($event['e_start_hour']) ? 0 : $event['e_start_hour'], is_null($event['e_start_minute']) ? 0 : $event['e_start_minute'], $event['e_end_year'], $event['e_end_month'], $event['e_end_day'], is_null($event['e_end_hour']) ? 0 : $event['e_end_hour'], is_null($event['e_end_minute']) ? 0 : $event['e_end_minute'], $event['e_recurrence'], min(1, $event['e_recurrences']));
     if (array_key_exists(0, $recurrences)) {
         $GLOBALS['SITE_DB']->query_insert('calendar_jobs', array('j_time' => usertime_to_utctime($recurrences[0][0]) - $seconds_before, 'j_reminder_id' => $rem_id, 'j_member_id' => get_member(), 'j_event_id' => get_param_integer('id')));
     }
     $url = build_url(array('page' => '_SELF', 'type' => 'view', 'id' => get_param_integer('id')), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
Beispiel #6
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');
}
Beispiel #7
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');
}
Beispiel #8
0
 /**
  * The actualiser for uploading a file.
  *
  * @return tempcode	The UI.
  */
 function module_do_upload()
 {
     if (!has_specific_permission(get_member(), 'upload_filedump')) {
         access_denied('I_ERROR');
     }
     $title = get_page_title('FILEDUMP_UPLOAD');
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     // Slowly uploading a file can trigger time limit, on some servers
     $place = filter_naughty(post_param('place'));
     require_code('uploads');
     if (!is_swf_upload(true) && (!array_key_exists('file', $_FILES) || !is_uploaded_file($_FILES['file']['tmp_name']))) {
         $attach_name = 'file';
         $max_size = get_max_file_size();
         if (isset($_FILES[$attach_name]) && ($_FILES[$attach_name]['error'] == 1 || $_FILES[$attach_name]['error'] == 2)) {
             warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format($max_size)));
         } elseif (isset($_FILES[$attach_name]) && ($_FILES[$attach_name]['error'] == 3 || $_FILES[$attach_name]['error'] == 6 || $_FILES[$attach_name]['error'] == 7)) {
             warn_exit(do_lang_tempcode('ERROR_UPLOADING_' . strval($_FILES[$attach_name]['error'])));
         } else {
             warn_exit(do_lang_tempcode('ERROR_UPLOADING'));
         }
     }
     $file = $_FILES['file']['name'];
     if (get_magic_quotes_gpc()) {
         $file = stripslashes($file);
     }
     if (!has_specific_permission(get_member(), 'upload_anything_filedump') || get_file_base() != get_custom_file_base()) {
         check_extension($file);
     }
     $file = str_replace('.', '-', basename($file, '.' . get_file_extension($file))) . '.' . get_file_extension($file);
     if (!file_exists(get_custom_file_base() . '/uploads/filedump' . $place . $file)) {
         $max_size = get_max_file_size();
         if ($_FILES['file']['size'] > $max_size) {
             warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format(intval($max_size))));
         }
         $full = get_custom_file_base() . '/uploads/filedump' . $place . $file;
         if (is_swf_upload(true)) {
             @rename($_FILES['file']['tmp_name'], $full) or warn_exit(do_lang_tempcode('FILE_MOVE_ERROR', escape_html($file), escape_html('uploads/filedump' . $place)));
         } else {
             @move_uploaded_file($_FILES['file']['tmp_name'], $full) or warn_exit(do_lang_tempcode('FILE_MOVE_ERROR', escape_html($file), escape_html('uploads/filedump' . $place)));
         }
         fix_permissions($full);
         sync_file($full);
         $return_url = build_url(array('page' => '_SELF', 'place' => $place), '_SELF');
         $test = $GLOBALS['SITE_DB']->query_value_null_ok('filedump', 'description', array('name' => $file, 'path' => $place));
         if (!is_null($test)) {
             delete_lang($test);
         }
         $GLOBALS['SITE_DB']->query_delete('filedump', array('name' => $file, 'path' => $place), '', 1);
         $description = post_param('description');
         $GLOBALS['SITE_DB']->query_insert('filedump', array('name' => $file, 'path' => $place, 'the_member' => get_member(), 'description' => insert_lang_comcode($description, 3)));
         require_code('notifications');
         $subject = do_lang('FILEDUMP_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $file, $place);
         $mail = do_lang('FILEDUMP_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($file), array(comcode_escape($place), comcode_escape($description)));
         dispatch_notification('filedump', $place, $subject, $mail);
         log_it('FILEDUMP_UPLOAD', $file, $place);
         if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), get_page_name(), get_zone_name())) {
             syndicate_described_activity('filedump:ACTIVITY_FILEDUMP_UPLOAD', $place . '/' . $file, '', '', '', '', '', 'filedump');
         }
         return redirect_screen($title, $return_url, do_lang_tempcode('SUCCESS'));
     } else {
         warn_exit(do_lang_tempcode('OVERWRITE_ERROR'));
     }
     return new ocp_tempcode();
 }
Beispiel #9
0
 /**
  * Standard aed_module edit actualiser.
  *
  * @param  ID_TEXT		The entry being edited
  */
 function edit_actualisation($_id)
 {
     $id = intval($_id);
     $open_time = get_input_date('open_time');
     $close_time = get_input_date('close_time');
     $_tied_newsletter = post_param('tied_newsletter', '');
     $tied_newsletter = $_tied_newsletter == '' ? NULL : intval($_tied_newsletter);
     $name = post_param('name');
     $validated = post_param_integer('validated', 0);
     if ($validated == 1 && $GLOBALS['SITE_DB']->query_value('quizzes', 'q_validated', array('id' => $id)) == 0) {
         $submitter = $GLOBALS['SITE_DB']->query_value('quizzes', 'q_submitter', array('id' => $id));
         if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'quiz')) {
             syndicate_described_activity($submitter != get_member() ? 'quiz:ACTIVITY_VALIDATE_QUIZ' : 'quiz:ACTIVITY_ADD_QUIZ', $name, '', '', '_SEARCH:quiz:do:' . strval($id), '', '', 'quizzes', 1, NULL);
         }
     }
     edit_quiz($id, $name, post_param_integer('timeout', NULL), post_param('start_text'), post_param('end_text'), post_param('end_text_fail'), post_param('notes', ''), post_param_integer('percentage', 0), $open_time, $close_time, post_param_integer('num_winners', 0), post_param_integer('redo_time', NULL), post_param('type'), $validated, post_param('text'), post_param('meta_keywords', ''), post_param('meta_description', ''), post_param_integer('points_for_passing', 0), $tied_newsletter);
 }
Beispiel #10
0
 /**
  * Standard aed_module edit actualiser.
  *
  * @param  ID_TEXT		The entry being edited
  */
 function edit_actualisation($_id)
 {
     require_code('catalogues2');
     $id = intval($_id);
     $category_id = post_param_integer('category_id', INTEGER_MAGIC_NULL);
     $validated = post_param_integer('validated', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $notes = post_param('notes', STRING_MAGIC_NULL);
     $allow_rating = post_param_integer('allow_rating', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $allow_comments = post_param_integer('allow_comments', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $allow_trackbacks = post_param_integer('allow_trackbacks', fractional_edit() ? INTEGER_MAGIC_NULL : 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, $id);
     if ($validated == 1 && $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'ce_validated', array('id' => $id)) == 0) {
         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))) {
             $submitter = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'ce_submitter', array('id' => $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($submitter != get_member() ? 'calendar:ACTIVITY_VALIDATE_CATALOGUE_GENERIC' : 'catalogues:ACTIVITY_CATALOGUE_GENERIC_ADD', $catalogue_title, $title, '', '_SEARCH:catalogues:entry:' . strval($id), '', '', 'catalogues', 1, NULL);
         }
     }
     actual_edit_catalogue_entry($id, $category_id, $validated, $notes, $allow_rating, $allow_comments, $allow_trackbacks, $map, post_param('meta_keywords', STRING_MAGIC_NULL), post_param('meta_description', STRING_MAGIC_NULL));
     $this->donext_category_id = $category_id;
     $this->donext_catalogue_name = $catalogue_name;
 }
Beispiel #11
0
 /**
  * Standard aed_module edit actualiser.
  *
  * @param  ID_TEXT		The entry being edited
  */
 function edit_actualisation($_id)
 {
     $id = intval($_id);
     $cat = post_param('cat');
     if (can_submit_to_gallery($cat) === false) {
         access_denied('SUBMIT_HERE');
     }
     make_member_gallery_if_needed($cat);
     $this->check_videos_allowed($cat);
     $validated = post_param_integer('validated', 0);
     $title = post_param('title');
     $urls = get_url('url', 'file', 'uploads/galleries' . (get_value('use_gallery_subdirs') == '1' ? '/' . $cat : ''), 0, OCP_UPLOAD_VIDEO, true, 'thumb_url', 'file2');
     if ($urls[0] == '') {
         warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD'));
     }
     $url = $urls[0];
     if (!array_key_exists(1, $urls) || $urls[1] == '') {
         $thumb_url = '';
     } else {
         $thumb_url = $urls[1];
     }
     if (substr($url, 0, 8) != 'uploads/' && $url != '' && is_null(http_download_file($url, 0, false)) && !is_null($GLOBALS['HTTP_MESSAGE_B'])) {
         attach_message($GLOBALS['HTTP_MESSAGE_B'], 'warn');
     }
     if ($thumb_url == '' && $url != '') {
         $thumb_url = create_video_thumb($url);
     }
     if ($thumb_url == '') {
         $rows = $GLOBALS['SITE_DB']->query_select('videos', array('url', 'thumb_url'), array('id' => $id), '', 1);
         $thumb_url = $rows[0]['thumb_url'];
     }
     if ($url == '' || $thumb_url == '') {
         warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD'));
     }
     $comments = post_param('comments');
     $allow_rating = post_param_integer('allow_rating', 0);
     $allow_comments = post_param_integer('allow_comments', 0);
     $notes = post_param('notes', '');
     $allow_trackbacks = post_param_integer('allow_trackbacks', 0);
     list($video_width, $video_height, $video_length) = $this->get_special_video_info();
     $this->donext_type = $cat;
     if ($validated == 1 && $GLOBALS['SITE_DB']->query_value('videos', 'validated', array('id' => $id)) == 0) {
         $submitter = $GLOBALS['SITE_DB']->query_value('videos', 'submitter', array('id' => $id));
         if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries', $cat)) {
             syndicate_described_activity($submitter != get_member() ? 'galleries:ACTIVITY_VALIDATE_VIDEO' : 'galleries:ACTIVITY_ADD_VIDEO', $title == '' ? $urls[2] : $title, '', '', '_SEARCH:galleries:video:' . strval($id), '', '', 'galleries', 1, NULL);
         }
     }
     edit_video($id, $title, $cat, $comments, $url, $thumb_url, $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $video_length, $video_width, $video_height, post_param('meta_keywords', ''), post_param('meta_description', ''));
 }
Beispiel #12
0
 /**
  * Standard aed_module edit actualiser.
  *
  * @param  ID_TEXT		The entry being edited
  * @return tempcode		Description shown after editing
  */
 function edit_actualisation($_id)
 {
     $id = intval($_id);
     $rows = $GLOBALS['SITE_DB']->query_select('calendar_events', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $rows)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $event = $rows[0];
     check_edit_permission($event['e_is_public'] == 1 ? 'mid' : 'low', $event['e_submitter']);
     $delete_status = post_param('delete', '0');
     list($type, $recurrence, $_recurrences, $title, $content, $priority, $is_public, $_start_year, $_start_month, $_start_day, $_start_hour, $_start_minute, $_end_year, $_end_month, $_end_day, $_end_hour, $_end_minute, $timezone, $do_timezone_conv) = $this->get_event_parameters();
     $allow_trackbacks = post_param_integer('allow_trackbacks', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $allow_rating = post_param_integer('allow_rating', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $allow_comments = post_param_integer('allow_comments', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $notes = post_param('notes', STRING_MAGIC_NULL);
     $validated = post_param_integer('validated', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $seg_recurrences = post_param_integer('seg_recurrences', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $fixed_past = false;
     if ($delete_status == '3' && !fractional_edit()) {
         // Fix past occurences
         $past_times = find_periods_recurrence($event['e_timezone'], 1, $event['e_start_year'], $event['e_start_month'], $event['e_start_day'], $event['e_start_hour'], $event['e_start_minute'], $event['e_end_year'], $event['e_end_month'], $event['e_end_day'], $event['e_end_hour'], $event['e_end_minute'], $event['e_recurrence'], $event['e_recurrences'], utctime_to_usertime(mktime($event['e_start_hour'], $event['e_start_minute'], 0, $event['e_start_month'], $event['e_start_day'], $event['e_start_year'])), utctime_to_usertime(time()));
         if (count($past_times) > 0) {
             foreach ($past_times as $past_time) {
                 list($start_year, $start_month, $start_day, $start_hour, $start_minute) = explode('-', date('Y-m-d-h-i', usertime_to_utctime($past_time[0])));
                 if (is_null($past_time[1])) {
                     list($end_year, $end_month, $end_day, $end_hour, $end_minute) = array(NULL, NULL, NULL, NULL, NULL);
                 } else {
                     $explode = explode('-', date('Y-m-d-h-i', usertime_to_utctime($past_time[1])));
                     $end_year = intval($explode[0]);
                     $end_month = intval($explode[1]);
                     $end_day = intval($explode[2]);
                     $end_hour = intval($explode[3]);
                     $end_minute = intval($explode[4]);
                 }
                 add_calendar_event($event['e_type'], 'none', NULL, 0, get_translated_text($event['e_title']), get_translated_text($event['e_content']), $event['e_priority'], $event['e_is_public'], intval($start_year), intval($start_month), intval($start_day), intval($start_hour), intval($start_minute), $end_year, $end_month, $end_day, $end_hour, $end_minute, $timezone, $do_timezone_conv, $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes);
             }
             if (is_null($_recurrences)) {
                 $recurrences = NULL;
             } else {
                 $recurrences = max(0, $_recurrences - count($past_times));
             }
             // Find next occurence in future
             if (count($past_times) == 0) {
                 $start_year = $_start_year;
                 $start_month = $_start_month;
                 $start_day = $_start_day;
                 $start_hour = $_start_hour;
                 $start_minute = $_start_minute;
                 $end_year = $_end_year;
                 $end_month = $_end_month;
                 $end_day = $_end_day;
                 $end_hour = $_end_hour;
                 $end_minute = $_end_minute;
             }
             $past_times = find_periods_recurrence($event['e_timezone'], 1, $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year, $end_month, $end_day, $end_hour, $end_minute, $event['e_recurrence'], 1, time());
             if (array_key_exists(0, $past_times)) {
                 $past_time = $past_times[0];
                 $explode = explode('-', date('Y-m-d-h-i', $past_time[0]));
                 $start_year = intval($explode[0]);
                 $start_month = intval($explode[1]);
                 $start_day = intval($explode[2]);
                 $start_hour = intval($explode[3]);
                 $start_minute = intval($explode[4]);
                 if (is_null($past_time[1])) {
                     list($end_year, $end_month, $end_day, $end_hour, $end_minute) = array(NULL, NULL, NULL, NULL, NULL);
                 } else {
                     $explode = explode('-', date('Y-m-d-h-i', $past_time[1]));
                     $end_year = intval($explode[0]);
                     $end_month = intval($explode[1]);
                     $end_day = intval($explode[2]);
                     $end_hour = intval($explode[3]);
                     $end_minute = intval($explode[4]);
                 }
             } else {
                 $recurrences = 0;
             }
             $fixed_past = true;
         }
     }
     if (!$fixed_past) {
         $start_year = $_start_year;
         $start_month = $_start_month;
         $start_day = $_start_day;
         $start_hour = $_start_hour;
         $start_minute = $_start_minute;
         $end_year = $_end_year;
         $end_month = $_end_month;
         $end_day = $_end_day;
         $end_hour = $_end_hour;
         $end_minute = $_end_minute;
         $recurrences = $_recurrences;
     }
     if ($validated == 1 && $GLOBALS['SITE_DB']->query_value('calendar_events', 'validated', array('id' => $id)) == 0) {
         if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'calendar') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'calendar', strval($type))) {
             $_from = cal_get_start_utctime_for_event($timezone, $start_year, $start_month, $start_day, $start_hour, $start_minute, true);
             $from = cal_utctime_to_usertime($_from, $timezone, false);
             $to = mixed();
             if (!is_null($end_year) && !is_null($end_month) && !is_null($end_day)) {
                 $_to = cal_get_end_utctime_for_event($timezone, $end_year, $end_month, $end_day, $end_hour, $end_minute, true);
                 $to = cal_utctime_to_usertime($_to, $timezone, false);
             }
             $submitter = $GLOBALS['SITE_DB']->query_value('calendar_events', 'e_submitter', array('id' => $id));
             syndicate_described_activity($submitter != get_member() ? 'calendar:ACTIVITY_VALIDATE_CALENDAR_EVENT' : 'calendar:ACTIVITY_CALENDAR_EVENT', $title, date_range($from, $to, !is_null($start_hour)), '', '_SEARCH:calendar:view:' . strval($id), '', '', 'calendar', 1, NULL, true);
         }
     }
     edit_calendar_event($id, $type, $recurrence, $recurrences, $seg_recurrences, $title, $content, $priority, $is_public, $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year, $end_month, $end_day, $end_hour, $end_minute, $timezone, $do_timezone_conv, post_param('meta_keywords', STRING_MAGIC_NULL), post_param('meta_description', STRING_MAGIC_NULL), $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes);
     if (!fractional_edit()) {
         $conflicts = detect_conflicts(get_member(), $id, $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year, $end_month, $end_day, $end_hour, $end_minute, $recurrence, $recurrences);
         $_description = is_null($conflicts) ? paragraph(do_lang_tempcode('SUCCESS')) : $conflicts;
         regenerate_event_reminder_jobs($id);
     } else {
         $_description = do_lang_tempcode('SUCCESS');
     }
     $this->donext_type = $type;
     $this->donext_date = strval($start_year) . '-' . strval($start_month) . '-' . strval($start_day);
     return $_description;
 }
Beispiel #13
0
 /**
  * Standard aed_module add actualiser.
  *
  * @return ID_TEXT		The entry added
  */
 function add_actualisation()
 {
     require_code('ocf_forums_action2');
     $parent_forum = post_param_integer('parent_forum', -1);
     $name = post_param('name');
     $id = strval(ocf_make_forum($name, post_param('description'), post_param_integer('category_id'), NULL, $parent_forum, post_param_integer('position'), post_param_integer('post_count_increment', 0), post_param_integer('order_sub_alpha', 0), post_param('intro_question'), post_param('intro_answer'), post_param('redirection'), post_param('order'), post_param_integer('is_threaded', 0)));
     // Warning if there is full access to this forum, but not to the parent
     $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
     $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, true);
     $full_access = true;
     foreach (array_keys($groups) as $gid) {
         if (!in_array($gid, $admin_groups)) {
             if (post_param_integer('access_' . strval($gid), 0) == 0) {
                 $full_access = false;
                 break;
             }
         }
     }
     if ($full_access) {
         $parent_has_full_access = true;
         $access_rows = $GLOBALS['FORUM_DB']->query_select('group_category_access', array('group_id'), array('module_the_name' => 'forums', 'category_name' => strval($parent_forum)));
         $access = array();
         foreach ($access_rows as $row) {
             $access[$row['group_id']] = 1;
         }
         foreach (array_keys($groups) as $gid) {
             if (!in_array($gid, $admin_groups)) {
                 if (!array_key_exists($gid, $access)) {
                     $parent_has_full_access = false;
                     break;
                 }
             }
         }
         if (!$parent_has_full_access) {
             attach_message(do_lang_tempcode('ANOMALOUS_FORUM_ACCESS'), 'notice');
         }
     }
     $this->set_permissions($id);
     if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'forumview') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'forums', $id)) {
         syndicate_described_activity('ocf:ACTIVITY_ADD_FORUM', $name, '', '', '_SEARCH:forumview:misc:' . $id, '', '', 'ocf_forum');
     }
     return $id;
 }
Beispiel #14
0
    /**
     * The actualiser to add a reply.
     *
     * @return tempcode		The UI
     */
    function _add_reply()
    {
        if (addon_installed('captcha')) {
            require_code('captcha');
            enforce_captcha();
        }
        require_code('attachments2');
        require_code('ocf_posts_action');
        require_code('ocf_posts_action2');
        $invited_members = array();
        $topic_id = either_param_integer('topic_id', -1);
        // Posting into an existing topic?
        $forum_id = post_param_integer('forum_id', -1);
        // New topic in existing forum? (NB: -2 represents reported posts forum)
        $member_id = post_param_integer('member_id', -1);
        // Send TOPIC to specific member? Could be Private Topic (topic_id==-1, forum_id==-1), or personal post (topic_id!=-1, forum_id==-1)
        $parent_id = either_param_integer('parent_id', NULL);
        if ($member_id == -1) {
            $member_username = post_param('to_member_id_0', '');
            if ($member_username != '') {
                $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username($member_username);
                if (is_null($member_id)) {
                    warn_exit(do_lang_tempcode('_USER_NO_EXIST', $member_username));
                }
            }
            foreach ($_POST as $key => $_invited_member) {
                if (substr($key, 0, 13) != 'to_member_id_') {
                    continue;
                }
                if ($key == 'to_member_id_0') {
                    continue;
                }
                if ($_invited_member == '') {
                    continue;
                }
                if (get_magic_quotes_gpc()) {
                    $_invited_member = stripslashes($_invited_member);
                }
                $invited_member = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_invited_member);
                if (is_null($invited_member)) {
                    attach_message(do_lang_tempcode('_USER_NO_EXIST', $_invited_member), 'warn');
                } else {
                    $invited_members[] = intval($invited_member);
                }
            }
        }
        $validated = post_param_integer('validated', post_param_integer('_validated', 0));
        $is_emphasised = post_param_integer('is_emphasised', 0);
        $skip_sig = post_param_integer('skip_sig', 0);
        $post = post_param('post');
        $title = post_param('title', NULL);
        if (is_null($title)) {
            $title = '';
        }
        $check_permissions = true;
        $add_poll = post_param_integer('add_poll', 0);
        $topic_validated = $validated;
        if ($validated == 1) {
            $topic_validated = 1 - $add_poll;
        }
        // If a topic is gonna have a poll added, it starts unvalidated. Adding the poll will validate it.
        $anonymous = post_param_integer('anonymous', 0);
        $poster_name_if_guest = post_param('poster_name_if_guest', NULL);
        if ($poster_name_if_guest == '') {
            $poster_name_if_guest = NULL;
        }
        if (!is_null($poster_name_if_guest)) {
            $poster_name_if_guest = trim($poster_name_if_guest);
            $restricted_usernames = explode(',', get_option('restricted_usernames'));
            $restricted_usernames[] = do_lang('UNKNOWN');
            $restricted_usernames[] = do_lang('SYSTEM');
            if (!is_null($GLOBALS['FORUM_DRIVER']->get_member_from_username($poster_name_if_guest))) {
                $restricted_usernames[] = $poster_name_if_guest;
            }
            foreach ($restricted_usernames as $_restricted_username) {
                $restricted_username = trim($_restricted_username);
                if ($restricted_username == '') {
                    continue;
                }
                if ($poster_name_if_guest == $restricted_username) {
                    $poster_name_if_guest = $poster_name_if_guest . ' (' . do_lang('GUEST') . ')';
                    break;
                }
            }
        }
        $new_topic = $topic_id == -1;
        if (!$new_topic) {
            $_intended_solely_for = post_param('intended_solely_for', '');
            if ($_intended_solely_for == '') {
                $intended_solely_for = NULL;
            } else {
                $intended_solely_for = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_intended_solely_for);
                if (is_null($intended_solely_for)) {
                    warn_exit(do_lang_tempcode('_USER_NO_EXIST', $_intended_solely_for));
                }
            }
        } else {
            $intended_solely_for = NULL;
        }
        require_code('ocf_topics_action');
        require_code('ocf_topics_action2');
        if ($new_topic) {
            ocf_check_post($post);
            if ($title == '') {
                warn_exit(do_lang_tempcode('NO_PARAMETER_SENT', 'title'));
            }
            $sunk = post_param_integer('sunk', 0);
            $topic_title = $title;
            if ($forum_id == -1) {
                require_code('ocf_members2');
                if (!ocf_may_whisper($member_id)) {
                    warn_exit(do_lang_tempcode('NO_PT_FROM_ALLOW'));
                }
                check_specific_permission('use_pt');
                $topic_id = ocf_make_topic(NULL, post_param('description', ''), post_param('emoticon', ''), $topic_validated, post_param_integer('open', 0), post_param_integer('pinned', 0), $sunk, post_param_integer('cascading', 0), get_member(), $member_id);
                $_title = get_page_title('ADD_PERSONAL_TOPIC');
            } elseif ($forum_id == -2) {
                $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name(get_option('reported_posts_forum'));
                if (is_null($forum_id)) {
                    warn_exit(do_lang_tempcode('NO_REPORTED_POST_FORUM'));
                }
                // See if post already reported...
                $topic_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_topics t LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts p ON p.id=t.t_cache_first_post_id', 't.id', array('p.p_title' => $title, 't.t_forum_id' => $forum_id));
                if (!is_null($topic_id)) {
                    // Already a topic
                } else {
                    $topic_id = ocf_make_topic($forum_id, '', '', 1, 1, 0, 0, 0, NULL, NULL, false);
                }
                $_title = get_page_title('REPORT_POST');
                $check_permissions = false;
                decache('main_staff_checklist');
            } else {
                $topic_id = ocf_make_topic($forum_id, post_param('description', ''), post_param('emoticon', ''), $topic_validated, post_param_integer('open', 0), post_param_integer('pinned', 0), $sunk, post_param_integer('cascading', 0));
                $_title = get_page_title('ADD_TOPIC');
                if (addon_installed('awards')) {
                    require_code('awards');
                    handle_award_setting('topic', strval($topic_id));
                }
            }
            $first_post = true;
            require_code('fields');
            if (has_tied_catalogue('topic')) {
                save_form_custom_fields('topic', strval($topic_id));
            }
        } else {
            $_title = get_page_title('ADD_POST');
            $first_post = false;
            $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_cache_first_title', 't_sunk', 't_forum_id', 't_is_open', 't_description'), array('id' => $topic_id), '', 1);
            if (!array_key_exists(0, $topic_info)) {
                warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
            }
            $forum_id = $topic_info[0]['t_forum_id'];
            $topic_title = $topic_info[0]['t_cache_first_title'];
            $sunk = $topic_info[0]['t_sunk'];
            if ($topic_info[0]['t_is_open'] == 0) {
                $may_moderate_forum = ocf_may_moderate_forum($forum_id);
                if (!$may_moderate_forum) {
                    warn_exit(do_lang_tempcode('TOPIC_IS_CLOSED'));
                }
            }
            // Moderator reply
            $new_title = post_param('new_title', NULL);
            if (!is_null($new_title) && !is_null($forum_id) && ocf_may_moderate_forum($forum_id, get_member())) {
                $cascading = post_param_integer('cascading', 0);
                $pinned = post_param_integer('pinned', 0);
                $sunk = post_param_integer('sunk', 0);
                $open = post_param_integer('open', 0);
                $topic_validated = post_param_integer('topic_validated', 0);
                $to = post_param_integer('to', NULL);
                $schedule = get_input_date('schedule');
                if (!is_null($schedule) && addon_installed('calendar')) {
                    $_intended_solely_for = is_null($intended_solely_for) ? 'NULL' : strval($intended_solely_for);
                    $_postdetailser_name_if_guest = is_null($poster_name_if_guest) ? 'NULL' : '\'' . addslashes($poster_name_if_guest) . '\'';
                    $_first_post = $first_post ? 'true' : 'false';
                    $__title = is_null($title) ? 'NULL' : '\'' . str_replace(chr(10), '\'.chr(10).\'', addslashes($title)) . '\'';
                    $_postdetails = is_null($post) ? 'NULL' : '\'' . str_replace(chr(10), '\'.chr(10).\'', addslashes($post)) . '\'';
                    $_new_title = is_null($new_title) ? 'NULL' : '\'' . str_replace(chr(10), '\'.chr(10).\'', addslashes($new_title)) . '\'';
                    $schedule_code = <<<END
:require_code('ocf_topics_action2'); require_code('ocf_topics_action'); ocf_edit_topic({$topic_id},NULL,NULL,{$validated},{$open},{$pinned},{$sunk},{$cascading},'',{$_new_title}); if (({$to}!={$forum_id}) && (!is_null({$to}))) ocf_move_topics({$forum_id},{$to},array({$topic_id})); \$post_id=ocf_make_post({$topic_id},{$__title},{$_postdetails},{$skip_sig},{$_first_post},{$validated},{$is_emphasised},{$_postdetailser_name_if_guest},NULL,NULL,NULL,{$_intended_solely_for},NULL,NULL,false,true,NULL,true,{$topic_title},{$sunk},NULL,{$anonymous}==1); if (addon_installed('awards')) { require_code('awards'); handle_award_setting('post',strval(\$post_id)); }
END;
                    require_code('calendar');
                    $start_year = post_param_integer('schedule_year');
                    $start_month = post_param_integer('schedule_month');
                    $start_day = post_param_integer('schedule_day');
                    $start_hour = post_param_integer('schedule_hour');
                    $start_minute = post_param_integer('schedule_minute');
                    require_code('calendar2');
                    $event_id = add_calendar_event(db_get_first_id(), '', NULL, 0, do_lang('ADD_POST'), $schedule_code, 3, 0, $start_year, $start_month, $start_day, $start_hour, $start_minute);
                    regenerate_event_reminder_jobs($event_id);
                    $text = do_lang_tempcode('SUCCESS');
                    $map = array('page' => 'topicview', 'id' => $topic_id, 'type' => 'first_unread');
                    $test = get_param_integer('kfs' . (is_null($forum_id) ? '' : strval($forum_id)), -1);
                    if ($test != -1 && $test != 0) {
                        $map['kfs' . (is_null($forum_id) ? '' : strval($forum_id))] = $test;
                    }
                    $test = get_param_integer('threaded', -1);
                    if ($test != -1) {
                        $map['threaded'] = $test;
                    }
                    $_url = build_url($map, get_module_zone('topicview'));
                    $url = $_url->evaluate();
                    $url .= '#first_unread';
                    $url = get_param('redirect', $url);
                    return redirect_screen($_title, $url, $text);
                }
                ocf_edit_topic($topic_id, NULL, NULL, $topic_validated, $open, $pinned, $sunk, $cascading, '', $new_title == '' ? NULL : $new_title);
                if ($to != $forum_id && !is_null($to)) {
                    ocf_move_topics($forum_id, $to, array($topic_id));
                }
            }
        }
        $post_id = ocf_make_post($topic_id, $title, $post, $skip_sig, $first_post, $validated, $is_emphasised, $poster_name_if_guest, NULL, NULL, NULL, $intended_solely_for, NULL, NULL, $check_permissions, true, NULL, true, $topic_title, $sunk, NULL, $anonymous == 1, $forum_id == -1 || is_null($forum_id), $forum_id == -1 || is_null($forum_id), false, $parent_id);
        if (addon_installed('awards')) {
            require_code('awards');
            handle_award_setting('post', strval($post_id));
        }
        if (!is_null($forum_id) && $anonymous == 0 && $intended_solely_for === NULL) {
            if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'forumview') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'forums', strval($forum_id))) {
                syndicate_described_activity($first_post ? 'ocf:ACTIVITY_ADD_TOPIC' : 'ocf:ACTIVITY_ADD_POST_IN', $first_post ? $title : $topic_title, '', '', '_SEARCH:topicview:misc:' . strval($topic_id) . '#post_' . strval($post_id), '', '', 'ocf_forum');
            }
        }
        require_code('fields');
        if (has_tied_catalogue('post')) {
            save_form_custom_fields('post', strval($post_id));
        }
        $validated = $GLOBALS['FORUM_DB']->query_value('f_posts', 'p_validated', array('id' => $post_id));
        $rep_post_id = post_param_integer('o_post_id', -1);
        if ($rep_post_id != -1) {
            $map = array('page' => 'topicview', 'id' => $rep_post_id, 'type' => 'findpost');
            $_url = build_url($map, get_module_zone('topicview'));
            $url = $_url->evaluate();
            $url .= '#post_' . strval($rep_post_id);
        } else {
            $map = array('page' => 'topicview', 'id' => $post_id, 'type' => 'findpost');
            $test = get_param_integer('kfs' . (is_null($forum_id) ? '' : strval($forum_id)), -1);
            if ($test != -1 && $test != 0) {
                $map['kfs' . (is_null($forum_id) ? '' : strval($forum_id))] = $test;
            }
            $test = get_param_integer('threaded', -1);
            if ($test != -1) {
                $map['threaded'] = $test;
            }
            $_url = build_url($map, get_module_zone('topicview'));
            $url = $_url->evaluate();
            if ($validated != 0) {
                $url .= '#post_' . strval($post_id);
            }
        }
        if ($forum_id >= 0) {
            $topic_validated = $GLOBALS['FORUM_DB']->query_value('f_topics', 't_validated', array('id' => $topic_id));
            if ($topic_validated == 0 && !has_specific_permission(get_member(), 'jump_to_unvalidated')) {
                $map = array('page' => 'forumview', 'id' => $forum_id);
                $test = get_param_integer('kfs' . (is_null($forum_id) ? '' : strval($forum_id)), -1);
                if ($test != -1 && $test != 0) {
                    $map['kfs' . (is_null($forum_id) ? '' : strval($forum_id))] = $test;
                }
                $test = get_param_integer('threaded', -1);
                if ($test != -1) {
                    $map['threaded'] = $test;
                }
                $_url = build_url($map, get_module_zone('forumview'));
                $url = $_url->evaluate();
            }
        }
        if ($new_topic && $forum_id == -1) {
            require_code('notifications');
            enable_notifications('ocf_topic', strval($topic_id), get_member());
            // from
            enable_notifications('ocf_topic', strval($topic_id), $member_id);
            // to
            foreach ($invited_members as $invited_member) {
                enable_notifications('ocf_topic', strval($topic_id), $invited_member);
                ocf_invite_to_pt($invited_member, $topic_id);
            }
        }
        if ($anonymous == 1) {
            log_it('MAKE_ANONYMOUS_POST', strval($post_id), $title);
        }
        if (addon_installed('awards')) {
            require_code('awards');
            handle_award_setting('post', strval($post_id));
        }
        if ($forum_id == -1 && $member_id != -1) {
            send_pt_notification($post_id, $title, $topic_id, $member_id, NULL, $post);
        }
        if ($add_poll == 1) {
            if (post_param_integer('add_poll', 0) == 1) {
                // Show it worked / Refresh
                $_url = build_url(array('page' => '_SELF', 'type' => 'add_poll', 'id' => $topic_id, 'try_validate' => 1), '_SELF');
                return redirect_screen($_title, $_url, do_lang_tempcode('SUCCESS'));
            }
        }
        if (!$new_topic && $forum_id != -1 && $member_id == -1) {
            handle_topic_ticket_reply($forum_id, $topic_id, $topic_title, $post);
        }
        $text = $validated == 1 ? do_lang_tempcode('SUCCESS') : do_lang_tempcode('SUBMIT_UNVALIDATED');
        require_code('autosave');
        clear_ocp_autosave();
        // Show it worked / Refresh
        $url = get_param('redirect', $url);
        return redirect_screen($_title, $url, $text);
    }
Beispiel #15
0
 /**
  * Standard aed_module add actualiser.
  *
  * @return ID_TEXT		The entry added
  */
 function add_actualisation()
 {
     require_code('ocf_forums_action2');
     $_group_leader = post_param('group_leader');
     if ($_group_leader != '') {
         $group_leader = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_group_leader);
         if (is_null($group_leader)) {
             warn_exit(do_lang_tempcode('_USER_NO_EXIST', $_group_leader));
         }
     } else {
         $group_leader = NULL;
     }
     $name = post_param('name');
     $id = ocf_make_group($name, 0, 0, 0, '', '', NULL, NULL, $group_leader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000, 0, post_param_integer('open_membership', 0), 1);
     // Create forum
     $mods = $GLOBALS['FORUM_DRIVER']->get_moderator_groups();
     $access_mapping = array();
     foreach ($mods as $m_id) {
         $access_mapping[$m_id] = 5;
     }
     $_cat = get_option('club_forum_parent_category');
     if (is_numeric($_cat)) {
         $cat = intval($_cat);
     } else {
         $cat = $GLOBALS['FORUM_DB']->query_value_null_ok('f_categories', 'id', array('c_title' => $_cat));
         if (is_null($cat)) {
             $cat = $GLOBALS['FORUM_DB']->query_value('f_categories', 'MIN(id)');
         }
     }
     $_forum = get_option('club_forum_parent_forum');
     if (is_numeric($_forum)) {
         $forum = intval($_forum);
     } else {
         $forum = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'id', array('f_name' => $_forum));
         if (is_null($forum)) {
             $forum = $GLOBALS['FORUM_DB']->query_value('f_forums', 'MIN(id)');
         }
     }
     $is_threaded = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_is_threaded', array('id' => $forum));
     $forum_id = ocf_make_forum($name, do_lang('FORUM_FOR_CLUB', $name), $cat, $access_mapping, $forum, 1, 1, 0, '', '', '', 'last_post', $is_threaded);
     $this->_set_permissions($id, $forum_id);
     require_code('ocf_groups_action2');
     ocf_add_member_to_group(get_member(), $id);
     if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'groups')) {
         syndicate_described_activity('ocf:ACTIVITY_ADD_CLUB', $name, '', '', '_SEARCH:groups:view:' . strval($id), '', '', 'ocf_clubs');
     }
     return strval($id);
 }
Beispiel #16
0
/**
 * Add comments to the specified resource.
 *
 * @param  boolean		Whether this resource allows comments (if not, this function does nothing - but it's nice to move out this common logic into the shared function)
 * @param  ID_TEXT		The type (download, etc) that this commenting is for
 * @param  ID_TEXT		The ID of the type that this commenting is for
 * @param  mixed			The URL to where the commenting will pass back to (to put into the comment topic header) (URLPATH or Tempcode)
 * @param  ?string		The title to where the commenting will pass back to (to put into the comment topic header) (NULL: don't know, but not first post so not important)
 * @param  ?string		The name of the forum to use (NULL: default comment forum)
 * @param  boolean		Whether to not require a captcha
 * @param  ?BINARY		Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver (hence is the last parameter).
 * @param  boolean		Whether to force allowance
 * @param  boolean		Whether to skip a success message
 * @param  boolean		Whether posts made should not be shared
 * @return boolean		Whether a hidden post has been made
 */
function actualise_post_comment($allow_comments, $content_type, $content_id, $content_url, $content_title, $forum = NULL, $avoid_captcha = false, $validated = NULL, $explicit_allow = false, $no_success_message = false, $private = false)
{
    if (!$explicit_allow) {
        if (get_option('is_on_comments') == '0' || !$allow_comments) {
            return false;
        }
        if (!has_specific_permission(get_member(), 'comment', get_page_name())) {
            return false;
        }
    }
    if (running_script('preview')) {
        return false;
    }
    $forum_tie = get_option('is_on_strong_forum_tie') == '1';
    if (addon_installed('captcha')) {
        if (array_key_exists('post', $_POST) && $_POST['post'] != '' && !$avoid_captcha) {
            require_code('captcha');
            enforce_captcha();
        }
    }
    $post_title = post_param('title', NULL);
    if (is_null($post_title) && !$forum_tie) {
        return false;
    }
    $post = post_param('post', NULL);
    if ($post == do_lang('POST_WARNING')) {
        $post = '';
    }
    if ($post == do_lang('THREADED_REPLY_NOTICE', do_lang('POST_WARNING'))) {
        $post = '';
    }
    if ($post == '' && $post_title !== '') {
        $post = $post_title;
        $post_title = '';
    }
    if ($post === '') {
        warn_exit(do_lang_tempcode('NO_PARAMETER_SENT', 'post'));
    }
    if (is_null($post)) {
        $post = '';
    }
    $email = trim(post_param('email', ''));
    if ($email != '') {
        $body = '> ' . str_replace(chr(10), chr(10) . '> ', $post);
        if (substr($body, -2) == '> ') {
            $body = substr($body, 0, strlen($body) - 2);
        }
        if (get_page_name() != 'tickets') {
            $post .= '[staff_note]';
        }
        $post .= "\n\n" . '[email subject="Re: ' . comcode_escape($post_title) . ' [' . get_site_name() . ']" body="' . comcode_escape($body) . '"]' . $email . '[/email]' . "\n\n";
        if (get_page_name() != 'tickets') {
            $post .= '[/staff_note]';
        }
    }
    $content_title = strip_comcode($content_title);
    if (is_null($forum)) {
        $forum = get_option('comments_forum_name');
    }
    $content_url_flat = is_object($content_url) ? $content_url->evaluate() : $content_url;
    $_parent_id = post_param('parent_id', '');
    $parent_id = $_parent_id == '' ? NULL : intval($_parent_id);
    $poster_name_if_guest = post_param('poster_name_if_guest', '');
    list($topic_id, $is_hidden) = $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum, $content_type . '_' . $content_id, get_member(), $post_title, $post, $content_title, do_lang('COMMENT'), $content_url_flat, NULL, NULL, $validated, $explicit_allow ? 1 : NULL, $explicit_allow, $poster_name_if_guest, $parent_id, false, !$private && $post != '' ? 'comment_posted' : NULL, !$private && $post != '' ? $content_type . '_' . $content_id : NULL);
    if (!is_null($topic_id)) {
        if (!is_integer($forum)) {
            $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum);
        } else {
            $forum_id = (int) $forum;
        }
        if (get_forum_type() == 'ocf' && !is_null($GLOBALS['LAST_POST_ID'])) {
            $extra_review_ratings = array();
            global $REVIEWS_STRUCTURE;
            if (array_key_exists($content_type, $REVIEWS_STRUCTURE)) {
                $reviews_rating_criteria = $REVIEWS_STRUCTURE[$content_type];
            } else {
                $reviews_rating_criteria[] = '';
            }
            foreach ($reviews_rating_criteria as $rating_type) {
                // Has there actually been any rating?
                $rating = post_param_integer('review_rating__' . fix_id($rating_type), NULL);
                if (!is_null($rating)) {
                    if ($rating > 10 || $rating < 1) {
                        log_hack_attack_and_exit('VOTE_CHEAT');
                    }
                    $GLOBALS['SITE_DB']->query_insert('review_supplement', array('r_topic_id' => $GLOBALS['LAST_TOPIC_ID'], 'r_post_id' => $GLOBALS['LAST_POST_ID'], 'r_rating_type' => $rating_type, 'r_rating_for_type' => $content_type, 'r_rating_for_id' => $content_id, 'r_rating' => $rating));
                }
            }
        }
    }
    if (!$private && $post != '') {
        list(, $submitter, , $safe_content_url, $cma_info) = get_details_behind_feedback_code($content_type, $content_id);
        $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']);
        }
        // Notification
        require_code('notifications');
        $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $subject = do_lang('NEW_COMMENT_SUBJECT', get_site_name(), $content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title, array($post_title, $username), get_site_default_lang());
        $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $message_raw = do_lang('NEW_COMMENT_BODY', comcode_escape(get_site_name()), comcode_escape($content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title), array($post_title == '' ? do_lang('NO_SUBJECT') : $post_title, post_param('post'), comcode_escape($content_url_flat), comcode_escape($username)), get_site_default_lang());
        dispatch_notification('comment_posted', $content_type . '_' . $content_id, $subject, $message_raw);
        // Is the user gonna automatically enable notifications for this?
        if (get_forum_type() == 'ocf') {
            $auto_monitor_contrib_content = $GLOBALS['OCF_DRIVER']->get_member_row_field(get_member(), 'm_auto_monitor_contrib_content');
            if ($auto_monitor_contrib_content == 1) {
                enable_notifications('comment_posted', $content_type . '_' . $content_id);
            }
        }
        // Activity
        $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) ? '_ADDED_COMMENT_ON' : 'ADDED_COMMENT_ON';
            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);
            }
        }
    }
    if ($post != '' && $forum_tie && !$no_success_message) {
        require_code('site2');
        assign_refresh($GLOBALS['FORUM_DRIVER']->topic_url($GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier($forum, $content_type . '_' . $content_id), $forum), 0.0);
    }
    if ($post != '' && !$no_success_message) {
        attach_message(do_lang_tempcode('SUCCESS'));
    }
    return $is_hidden;
}
Beispiel #17
0
 /**
  * Standard aed_module edit actualiser.
  *
  * @param  ID_TEXT		The entry being edited
  */
 function edit_actualisation($_id)
 {
     $id = intval($_id);
     $rows = $GLOBALS['SITE_DB']->query_select('iotd', array('is_current', 'submitter'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $rows)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $is_current = $rows[0]['is_current'];
     $submitter = $rows[0]['submitter'];
     require_code('uploads');
     check_edit_permission($is_current == 1 ? 'high' : 'mid', $submitter);
     $urls = get_url('url', 'file', 'uploads/iotds', 0, OCP_UPLOAD_IMAGE, true, 'thumb_url', 'file2');
     if ($urls[0] == '' || $urls[1] == '') {
         warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD'));
     }
     $url = $urls[0];
     $thumb_url = $urls[1];
     if (substr($urls[0], 0, 8) != 'uploads/' && $urls[0] != '' && is_null(http_download_file($urls[0], 0, false)) && !is_null($GLOBALS['HTTP_MESSAGE_B'])) {
         attach_message($GLOBALS['HTTP_MESSAGE_B'], 'warn');
     }
     $allow_rating = post_param_integer('allow_rating', 0);
     $allow_comments = post_param_integer('allow_comments', 0);
     $notes = post_param('notes', '');
     $allow_trackbacks = post_param_integer('allow_trackbacks', 0);
     $current = post_param_integer('validated', 0);
     $title = post_param('title');
     if ($current == 1 && $GLOBALS['SITE_DB']->query_value('iotd', 'is_current', array('id' => $id)) == 0) {
         $submitter = $GLOBALS['SITE_DB']->query_value('iotd', 'submitter', array('id' => $id));
         if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'iotds')) {
             syndicate_described_activity('iotds:ACTIVITY_ADD_IOTD', $title, '', '', '_SEARCH:iotds:view:' . strval($id), '', '', 'iotds', 1, NULL);
         }
     }
     edit_iotd($id, $title, post_param('caption'), $thumb_url, $url, $allow_rating, $allow_comments, $allow_trackbacks, $notes);
     if ($current == 1) {
         if ($is_current == 0) {
             if (!has_specific_permission(get_member(), 'choose_iotd')) {
                 log_hack_attack_and_exit('BYPASS_VALIDATION_HACK');
             }
             set_iotd($id);
         }
     }
 }
Beispiel #18
0
/**
 * Give a member some points, from another member.
 *
 * @param  integer		The amount being given
 * @param  MEMBER			The member receiving the points
 * @param  MEMBER			The member sending the points
 * @param  SHORT_TEXT	The reason for the gift
 * @param  boolean		Does the sender want to remain anonymous?
 * @param  boolean		Whether to send out an email about it
 */
function give_points($amount, $recipient_id, $sender_id, $reason, $anonymous = false, $send_email = true)
{
    require_lang('points');
    require_code('points');
    $your_username = $GLOBALS['FORUM_DRIVER']->get_username($sender_id);
    $GLOBALS['SITE_DB']->query_insert('gifts', array('date_and_time' => time(), 'amount' => $amount, 'gift_from' => $sender_id, 'gift_to' => $recipient_id, 'reason' => insert_lang_comcode($reason, 4), 'anonymous' => $anonymous ? 1 : 0));
    $sender_gift_points_used = point_info($sender_id);
    $sender_gift_points_used = array_key_exists('gift_points_used', $sender_gift_points_used) ? $sender_gift_points_used['gift_points_used'] : 0;
    $GLOBALS['FORUM_DRIVER']->set_custom_field($sender_id, 'gift_points_used', strval($sender_gift_points_used + $amount));
    $temp_points = point_info($recipient_id);
    $GLOBALS['FORUM_DRIVER']->set_custom_field($recipient_id, 'points_gained_given', strval((array_key_exists('points_gained_given', $temp_points) ? $temp_points['points_gained_given'] : 0) + $amount));
    $their_username = $GLOBALS['FORUM_DRIVER']->get_username($recipient_id);
    if (is_null($their_username)) {
        warn_exit(do_lang_tempcode('_USER_NO_EXIST', $recipient_id));
    }
    $yes = $GLOBALS['FORUM_DRIVER']->get_member_email_allowed($recipient_id);
    if ($yes && $send_email) {
        $_url = build_url(array('page' => 'points', 'type' => 'member', 'id' => $recipient_id), get_module_zone('points'), NULL, false, false, true);
        $url = $_url->evaluate();
        require_code('notifications');
        if ($anonymous) {
            $message_raw = do_lang('GIVEN_POINTS_FOR_ANON', comcode_escape(get_site_name()), comcode_escape(integer_format($amount)), array(comcode_escape($reason), comcode_escape($url)), get_lang($recipient_id));
            dispatch_notification('received_points', NULL, do_lang('YOU_GIVEN_POINTS', integer_format($amount), NULL, NULL, get_lang($recipient_id)), $message_raw, array($recipient_id), A_FROM_SYSTEM_UNPRIVILEGED);
        } else {
            $message_raw = do_lang('GIVEN_POINTS_FOR', comcode_escape(get_site_name()), comcode_escape(integer_format($amount)), array(comcode_escape($reason), comcode_escape($url), comcode_escape($your_username)), get_lang($recipient_id));
            dispatch_notification('received_points', NULL, do_lang('YOU_GIVEN_POINTS', integer_format($amount), NULL, NULL, get_lang($recipient_id)), $message_raw, array($recipient_id), $sender_id);
        }
        $message_raw = do_lang('USER_GIVEN_POINTS_FOR', comcode_escape($their_username), comcode_escape(integer_format($amount)), array(comcode_escape($reason), comcode_escape($url), comcode_escape($your_username)), get_site_default_lang());
        dispatch_notification('receive_points_staff', NULL, do_lang('USER_GIVEN_POINTS', integer_format($amount), NULL, NULL, get_site_default_lang()), $message_raw, NULL, $sender_id);
    }
    global $TOTAL_POINTS_CACHE, $POINT_INFO_CACHE;
    if (array_key_exists($recipient_id, $TOTAL_POINTS_CACHE)) {
        $TOTAL_POINTS_CACHE[$recipient_id] += $amount;
    }
    if (array_key_exists($recipient_id, $POINT_INFO_CACHE) && array_key_exists('points_gained_given', $POINT_INFO_CACHE[$recipient_id])) {
        $POINT_INFO_CACHE[$recipient_id]['points_gained_given'] += $amount;
    }
    if (array_key_exists($sender_id, $POINT_INFO_CACHE) && array_key_exists('gift_points_used', $POINT_INFO_CACHE[$sender_id])) {
        $POINT_INFO_CACHE[$sender_id]['gift_points_used'] += $amount;
    }
    if (get_forum_type() == 'ocf') {
        require_code('ocf_posts_action');
        require_code('ocf_posts_action2');
        ocf_member_handle_promotion($recipient_id);
    }
    if (!$anonymous) {
        if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'points')) {
            syndicate_described_activity(is_null($recipient_id) || is_guest($recipient_id) ? 'points:_ACTIVITY_GIVE_POINTS' : 'points:ACTIVITY_GIVE_POINTS', $reason, integer_format($amount), '', '_SEARCH:points:member:' . strval($recipient_id), '', '', 'points', 1, NULL, false, $recipient_id);
        }
    }
}
Beispiel #19
0
 /**
  * Standard aed_module edit actualiser.
  *
  * @param  ID_TEXT		The entry being edited
  */
 function edit_actualisation($id)
 {
     $rows = $GLOBALS['SITE_DB']->query_select('poll', array('is_current', 'submitter', 'num_options'), array('id' => intval($id)), '', 1);
     if (!array_key_exists(0, $rows)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $is_current = $rows[0]['is_current'];
     $submitter = $rows[0]['submitter'];
     check_edit_permission($is_current == 1 ? 'high' : 'mid', $submitter);
     $question = post_param('question', STRING_MAGIC_NULL);
     $option1 = post_param('option1', STRING_MAGIC_NULL);
     $option2 = post_param('option2', STRING_MAGIC_NULL);
     $option3 = post_param('option3', STRING_MAGIC_NULL);
     $option4 = post_param('option4', STRING_MAGIC_NULL);
     $option5 = post_param('option5', STRING_MAGIC_NULL);
     $option6 = post_param('option6', STRING_MAGIC_NULL);
     $option7 = post_param('option7', STRING_MAGIC_NULL);
     $option8 = post_param('option8', STRING_MAGIC_NULL);
     $option9 = post_param('option9', STRING_MAGIC_NULL);
     $option10 = post_param('option10', STRING_MAGIC_NULL);
     $allow_rating = post_param_integer('allow_rating', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $allow_comments = post_param_integer('allow_comments', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $allow_trackbacks = post_param_integer('allow_trackbacks', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $notes = post_param('notes', STRING_MAGIC_NULL);
     if (fractional_edit()) {
         $num_options = $rows[0]['num_options'];
     } else {
         $num_options = 10;
         if ($option10 == '') {
             $num_options = 9;
         }
         if ($option9 == '') {
             $num_options = 8;
         }
         if ($option8 == '') {
             $num_options = 7;
         }
         if ($option7 == '') {
             $num_options = 6;
         }
         if ($option6 == '') {
             $num_options = 5;
         }
         if ($option5 == '') {
             $num_options = 4;
         }
         if ($option4 == '') {
             $num_options = 3;
         }
         if ($option3 == '') {
             $num_options = 2;
         }
         if ($option2 == '') {
             $num_options = 1;
         }
     }
     $current = post_param_integer('validated', 0);
     if ($current == 1 && $GLOBALS['SITE_DB']->query_value('poll', 'is_current', array('id' => $id)) == 0) {
         $submitter = $GLOBALS['SITE_DB']->query_value('poll', 'submitter', array('id' => $id));
         if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'polls')) {
             syndicate_described_activity('polls:ACTIVITY_ADD_POLL', $question, '', '', '_SEARCH:polls:view:' . strval($id), '', '', 'polls', 1, NULL);
         }
     }
     edit_poll(intval($id), $question, $option1, $option2, $option3, $option4, $option5, $option6, $option7, $option8, $option9, $option10, $num_options, $allow_rating, $allow_comments, $allow_trackbacks, $notes);
     if (!fractional_edit()) {
         if ($current == 1) {
             if ($is_current == 0) {
                 if (!has_specific_permission(get_member(), 'choose_poll')) {
                     log_hack_attack_and_exit('BYPASS_VALIDATION_HACK');
                 }
                 set_poll(intval($id));
             }
         }
     }
 }