예제 #1
1
 /**
  * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX.
  *
  * @return tempcode  The snippet
  */
 function run()
 {
     $type = get_param('type');
     if (!has_zone_access(get_member(), 'adminzone')) {
         return new ocp_tempcode();
     }
     decache('main_staff_checklist');
     require_lang('staff_checklist');
     switch ($type) {
         case 'add':
             $recurinterval = get_param_integer('recurinterval', 0);
             $task_title = get_param('tasktitle', false, true);
             $id = $GLOBALS['SITE_DB']->query_insert('customtasks', array('tasktitle' => $task_title, 'datetimeadded' => time(), 'recurinterval' => $recurinterval, 'recurevery' => get_param('recurevery'), 'taskisdone' => NULL), true);
             require_code('notifications');
             $subject = do_lang('CT_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $task_title);
             $mail = do_lang('CT_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($task_title));
             dispatch_notification('checklist_task', NULL, $subject, $mail);
             return do_template('BLOCK_MAIN_STAFF_CHECKLIST_CUSTOM_TASK', array('TASKTITLE' => comcode_to_tempcode(get_param('tasktitle', false, true)), 'DATETIMEADDED' => display_time_period(time()), 'RECURINTERVAL' => $recurinterval == 0 ? '' : integer_format($recurinterval), 'RECUREVERY' => get_param('recurevery'), 'TASKDONE' => 'not_completed', 'ID' => strval($id)));
         case 'delete':
             $GLOBALS['SITE_DB']->query_delete('customtasks', array('id' => get_param_integer('id')), '', 1);
             break;
         case 'mark_done':
             $GLOBALS['SITE_DB']->query_update('customtasks', array('taskisdone' => time()), array('id' => get_param_integer('id')), '', 1);
             break;
         case 'mark_undone':
             $GLOBALS['SITE_DB']->query_update('customtasks', array('taskisdone' => NULL), array('id' => get_param_integer('id')), '', 1);
             break;
     }
     return new ocp_tempcode();
 }
예제 #2
0
/**
 * Add a banner to the database, and return the new ID of that banner in the database.
 *
 * @param  ID_TEXT			The name of the banner
 * @param  URLPATH			The URL to the banner image
 * @param  SHORT_TEXT		The title text for the banner (only used for text banners, and functions as the 'trigger text' if the banner type is shown inline)
 * @param  SHORT_TEXT		The caption of the banner
 * @param  ?integer			The number of hits the banner may have (NULL: not applicable for this banner type)
 * @range  0 max
 * @param  URLPATH			The URL to the site the banner leads to
 * @param  integer			The banners "importance modulus"
 * @range  1 max
 * @param  LONG_TEXT			Any notes associated with the banner
 * @param  SHORT_INTEGER	The type of banner (0=permanent, 1=campaign, 2=default)
 * @set    0 1 2
 * @param  ?TIME				The banner expiry date (NULL: never)
 * @param  ?MEMBER			The banners submitter (NULL: current member)
 * @param  BINARY				Whether the banner has been validated
 * @param  ID_TEXT			The banner type (can be anything, where blank means 'normal')
 * @param  ?TIME				The time the banner was added (NULL: now)
 * @param  integer			The number of return hits from this banners site
 * @param  integer			The number of banner hits to this banners site
 * @param  integer			The number of return views from this banners site
 * @param  integer			The number of banner views to this banners site
 * @param  ?TIME				The banner edit date  (NULL: never)
 */
function add_banner_quiet($name, $imgurl, $title_text, $caption, $campaignremaining, $site_url, $importance_modulus, $notes, $the_type, $expiry_date, $submitter, $validated = 0, $b_type = '', $time = NULL, $hits_from = 0, $hits_to = 0, $views_from = 0, $views_to = 0, $edit_date = NULL)
{
    if (!is_numeric($importance_modulus)) {
        $importance_modulus = 3;
    }
    if (!is_numeric($campaignremaining)) {
        $campaignremaining = NULL;
    }
    if (is_null($time)) {
        $time = time();
    }
    if (is_null($submitter)) {
        $submitter = get_member();
    }
    $test = $GLOBALS['SITE_DB']->query_value_null_ok('banners', 'name', array('name' => $name));
    if (is_null($test)) {
        if (!addon_installed('unvalidated')) {
            $validated = 1;
        }
        $GLOBALS['SITE_DB']->query_insert('banners', array('b_title_text' => $title_text, 'b_type' => $b_type, 'edit_date' => $edit_date, 'add_date' => $time, 'expiry_date' => $expiry_date, 'the_type' => $the_type, 'submitter' => $submitter, 'name' => $name, 'img_url' => $imgurl, 'caption' => insert_lang_comcode($caption, 2), 'campaign_remaining' => $campaignremaining, 'site_url' => $site_url, 'importance_modulus' => $importance_modulus, 'notes' => '', 'validated' => $validated, 'hits_from' => $hits_from, 'hits_to' => $hits_to, 'views_from' => $views_from, 'views_to' => $views_to));
        if (function_exists('decache')) {
            decache('main_banner_wave');
            decache('main_topsites');
        }
        log_it('ADD_BANNER', $name, $caption);
    }
}
예제 #3
0
/**
 * Add a topic.
 *
 * @param  ?AUTO_LINK	The ID of the forum the topic will be in (NULL: Private Topic).
 * @param  SHORT_TEXT	Description of the topic.
 * @param  SHORT_TEXT	The theme image code of the emoticon for the topic.
 * @param  ?BINARY		Whether the topic is validated (NULL: detect whether it should be).
 * @param  BINARY			Whether the topic is open.
 * @param  BINARY			Whether the topic is pinned.
 * @param  BINARY			Whether the topic is sunk.
 * @param  BINARY			Whether the topic is cascading.
 * @param  ?MEMBER		If it is a Private Topic, who is it 'from' (NULL: not a Private Topic).
 * @param  ?MEMBER		If it is a Private Topic, who is it 'to' (NULL: not a Private Topic).
 * @param  boolean		Whether to check the poster has permissions for the given topic settings.
 * @param  integer		The number of times the topic has been viewed.
 * @param  ?AUTO_LINK	Force an ID (NULL: don't force an ID)
 * @param  SHORT_TEXT	Link related to the topic (e.g. link to view a ticket).
 * @return AUTO_LINK		The ID of the newly created topic.
 */
function ocf_make_topic($forum_id, $description = '', $emoticon = '', $validated = NULL, $open = 1, $pinned = 0, $sunk = 0, $cascading = 0, $pt_from = NULL, $pt_to = NULL, $check_perms = true, $num_views = 0, $id = NULL, $description_link = '')
{
    if (is_null($pinned)) {
        $pinned = 0;
    }
    if (is_null($sunk)) {
        $sunk = 0;
    }
    if (is_null($description)) {
        $description = '';
    }
    if (is_null($num_views)) {
        $num_views = 0;
    }
    if ($check_perms) {
        require_code('ocf_topics');
        if (!ocf_may_post_topic($forum_id, get_member())) {
            access_denied('I_ERROR');
        }
        if (!is_null($pt_to)) {
            decache('side_ocf_personal_topics', array($pt_to));
            decache('_new_pp', array($pt_to));
        }
        if (!is_null($forum_id)) {
            require_code('ocf_posts_action');
            ocf_decache_ocp_blocks($forum_id);
        }
        require_code('ocf_forums');
        if (!ocf_may_moderate_forum($forum_id)) {
            $pinned = 0;
            $sunk = 0;
            $open = 1;
            $cascading = 0;
        }
    }
    if (is_null($validated) || $check_perms && $validated == 1) {
        if (!is_null($forum_id) && !has_specific_permission(get_member(), 'bypass_validation_midrange_content', 'topics', array('forums', $forum_id))) {
            $validated = 0;
        } else {
            $validated = 1;
        }
    }
    if (!addon_installed('unvalidated')) {
        $validated = 1;
    }
    $map = array('t_pinned' => $pinned, 't_sunk' => $sunk, 't_cascading' => $cascading, 't_forum_id' => $forum_id, 't_pt_from' => $pt_from, 't_pt_to' => $pt_to, 't_description' => substr($description, 0, 255), 't_description_link' => substr($description_link, 0, 255), 't_emoticon' => $emoticon, 't_num_views' => $num_views, 't_validated' => $validated, 't_is_open' => $open, 't_poll_id' => NULL, 't_cache_first_post_id' => NULL, 't_cache_first_post' => NULL, 't_cache_first_time' => NULL, 't_cache_first_title' => '', 't_cache_first_username' => '', 't_cache_first_member_id' => NULL, 't_cache_last_post_id' => NULL, 't_cache_last_time' => NULL, 't_cache_last_title' => '', 't_cache_last_username' => '', 't_cache_last_member_id' => NULL, 't_cache_num_posts' => 0, 't_pt_from_category' => '', 't_pt_to_category' => '');
    if (!is_null($id)) {
        $map['id'] = $id;
    }
    return $GLOBALS['FORUM_DB']->query_insert('f_topics', $map, true);
}
예제 #4
0
 /**
  * Standard modular run function for CRON hooks. Searches for tasks to perform.
  */
 function run()
 {
     if (!addon_installed('catalogues')) {
         return;
     }
     $last = get_value('last_classified_refresh');
     $time = time();
     if (!is_null($last) && intval($last) > $time - 60 * 60) {
         return;
     }
     // Don't do more than once per hour
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     $start = 0;
     do {
         $entries = $GLOBALS['SITE_DB']->query_select('catalogue_entries e JOIN ' . get_table_prefix() . 'classifieds_prices p ON p.c_catalogue_name=e.c_name', array('e.*'), array('ce_validated' => 1), '', 1000, $start);
         foreach ($entries as $entry) {
             if ($entry['ce_last_moved'] == $entry['ce_add_date']) {
                 require_code('classifieds');
                 initialise_classified_listing($entry);
             }
             // Expiring
             if ($entry['ce_last_moved'] < $time) {
                 $GLOBALS['SITE_DB']->query_update('catalogue_entries', array('ce_validated' => 0), array('id' => $entry['id']), '', 1);
                 decache('main_cc_embed');
                 decache('main_recent_cc_entries');
                 require_code('catalogues2');
                 calculate_category_child_count_cache($entry['cc_id']);
             } elseif ($entry['ce_last_moved'] < $time + 60 * 60 * 24 && $entry['ce_last_moved'] > $time + 60 * 60 * 23) {
                 // Expiring in 24 hours
                 require_code('notifications');
                 require_lang('classifieds');
                 $member_id = $entry['ce_submitter'];
                 $renew_url = build_url(array('page' => 'classifieds', 'type' => 'adverts', 'id' => $member_id), get_module_zone('classifieds'));
                 require_code('catalogues');
                 $data_map = get_catalogue_entry_map($entry, NULL, 'CATEGORY', 'DEFAULT', NULL, NULL, array(0));
                 $ad_title = $data_map['FIELD_0_PLAIN'];
                 if (is_object($ad_title)) {
                     $ad_title = $ad_title->evaluate();
                 }
                 $subject_tag = do_lang('SUBJECT_CLASSIFIED_ADVERT_EXPIRING', $ad_title, get_site_name(), NULL, get_lang($member_id), false);
                 $mail = do_lang('MAIL_CLASSIFIED_ADVERT_EXPIRING', $ad_title, comcode_escape(get_site_name()), comcode_escape($renew_url->evaluate()), get_lang($member_id), false);
                 // Send actual notification
                 dispatch_notification('classifieds__' . $entry['c_name'], '', $subject_tag, $mail, array($member_id), A_FROM_SYSTEM_PRIVILEGED);
             }
         }
     } while (count($entries) == 1000);
     set_value('last_classified_refresh', strval($time));
 }
예제 #5
0
 /**
  * Standard modular run function for CRON hooks. Searches for tasks to perform.
  */
 function run()
 {
     if (!addon_installed('backup')) {
         return;
     }
     $backup_schedule_time = intval(get_value('backup_schedule_time'));
     if ($backup_schedule_time != 0) {
         $backup_recurrance_days = intval(get_value('backup_recurrance_days'));
         $time = time();
         $last_time = intval(get_value('last_backup'));
         if ($time >= $backup_schedule_time) {
             decache('main_staff_checklist');
             require_lang('backups');
             require_code('backup');
             $max_size = get_value('backup_max_size');
             $b_type = get_value('backup_b_type');
             global $MB2_FILE, $MB2_B_TYPE, $MB2_MAX_SIZE;
             $end = get_option('backup_overwrite') != '1' || $b_type == 'incremental' ? uniqid('', true) : 'scheduled';
             if ($b_type == 'full') {
                 $file = 'restore_' . $end;
             } elseif ($b_type == 'incremental') {
                 $file = 'dif_' . $end;
             } elseif ($b_type == 'sql') {
                 $file = 'database_' . $end;
             }
             $MB2_FILE = $file;
             $MB2_B_TYPE = $b_type;
             $MB2_MAX_SIZE = $max_size;
             register_shutdown_function('make_backup_2');
             if ($backup_recurrance_days == 0) {
                 delete_value('backup_schedule_time');
             } else {
                 set_value('backup_schedule_time', strval($backup_schedule_time + $backup_recurrance_days * 60 * 60 * 24));
             }
         }
     }
 }
예제 #6
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     if (!array_key_exists('param', $map)) {
         $map['param'] = 'main';
     }
     if (!array_key_exists('page', $map)) {
         $map['page'] = get_page_name();
     }
     if (array_key_exists('extra_param_from', $map)) {
         $extra = '_' . $map['extra_param_from'];
     } else {
         $extra = '';
     }
     require_code('feedback');
     $self_url = get_self_url();
     $self_title = $map['page'];
     $id = $map['page'] . '_' . $map['param'] . $extra;
     $test_changed = post_param('rating_' . $id, '');
     if ($test_changed != '') {
         decache('main_rating');
     }
     actualise_rating(true, 'block_main_rating', $id, $self_url, $self_title);
     return get_rating_box($self_url, $self_title, 'block_main_rating', $id, true);
 }
예제 #7
0
 /**
  * The UI to show a gallery.
  *
  * @return tempcode		The UI
  */
 function do_gallery()
 {
     require_code('images');
     $cat = get_param('id', 'root');
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=galleries&filter=' . $cat;
     $root = get_param('root', 'root');
     if (!has_category_access(get_member(), 'galleries', $cat)) {
         access_denied('CATEGORY_ACCESS');
     }
     // Info on our gallery
     $gallery_rows = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('name' => $cat), '', 1);
     $implied_existence = false;
     if (!array_key_exists(0, $gallery_rows)) {
         // Possibly we will 'imply' it's existence if this is a member gallery; allows normal rendering to finish, with add links
         $matches = array();
         if (preg_match('#^member\\_(\\d+)\\_(.*)$#', $cat, $matches) != 0) {
             $username = $GLOBALS['FORUM_DRIVER']->get_username(intval($matches[1]));
             if (!is_null($username)) {
                 $gallery_rows = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('name' => $matches[2]), '', 1);
             }
         }
         if (!array_key_exists(0, $gallery_rows)) {
             return warn_screen(get_page_title('ERROR_OCCURRED'), do_lang_tempcode('MISSING_RESOURCE'));
         }
         $myrow = $gallery_rows[0];
         $myrow['is_member_synched'] = 0;
         $fullname = do_lang('PERSONAL_GALLERY_OF', $username, get_translated_text($myrow['fullname']));
         $myrow['parent_id'] = $matches[2];
         $implied_existence = true;
     } else {
         $myrow = $gallery_rows[0];
         $fullname = get_translated_text($myrow['fullname']);
     }
     if ($fullname == '') {
         $fullname = $cat;
     }
     $description = get_translated_tempcode($myrow['description']);
     if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_galleries', array('galleries', $cat))) {
         $submit_cat = $myrow['is_member_synched'] == 1 ? 'member_' . strval(get_member()) . '_' . $cat : $cat;
         $submit_image_url = $myrow['accept_images'] == 0 ? new ocp_tempcode() : build_url(array('page' => 'cms_galleries', 'type' => 'ad', 'cat' => $submit_cat), get_module_zone('cms_galleries'));
         $submit_video_url = $myrow['accept_videos'] == 0 ? new ocp_tempcode() : build_url(array('page' => 'cms_galleries', 'type' => 'av', 'cat' => $submit_cat), get_module_zone('cms_galleries'));
     } else {
         $submit_image_url = new ocp_tempcode();
         $submit_video_url = new ocp_tempcode();
     }
     if (!$implied_existence && has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_edit_permission('cat_mid', get_member(), get_member_id_from_gallery_name($cat), 'cms_galleries', array('galleries', $cat))) {
         $edit_url = build_url(array('page' => 'cms_galleries', 'type' => '_ec', 'id' => $cat), get_module_zone('cms_galleries'));
     } else {
         $edit_url = new ocp_tempcode();
     }
     if (!$implied_existence && has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_submit_permission('cat_mid', get_member(), get_ip_address(), 'cms_galleries')) {
         $add_gallery_url = build_url(array('page' => 'cms_galleries', 'type' => 'ac', 'cat' => $cat), get_module_zone('cms_galleries'));
     } else {
         $add_gallery_url = new ocp_tempcode();
     }
     $may_download_gallery = has_specific_permission(get_member(), 'may_download_gallery', 'galleries', array('galleries', $cat));
     $tree = gallery_breadcrumbs($cat, $root, true, get_module_zone('galleries'));
     if (!$tree->is_empty()) {
         $tree->attach(do_template('BREADCRUMB_ESCAPED'));
     }
     if (has_specific_permission(get_member(), 'open_virtual_roots')) {
         $url = get_self_url(false, false, array('root' => $cat));
         $tree->attach(hyperlink($url, escape_html($fullname), false, false, do_lang_tempcode('VIRTUAL_ROOT')));
     } else {
         $tree->attach('<span>' . escape_html($fullname) . '</span>');
     }
     $myrow['flow_mode_interface'] = get_param_integer('flow_mode_interface', $myrow['flow_mode_interface']);
     // Allow override via URL
     // Flow mode puts emphasis on subgalleries, rather than entries; it is subgalleries that there are a lot of, rather than entries
     if ($myrow['flow_mode_interface'] == 1) {
         $max = get_param_integer('max', get_default_gallery_max());
         if ($max < 1) {
             $max = 1;
         }
         $start = get_param_integer('start', 0);
     } else {
         $max = NULL;
         $start = NULL;
     }
     // Subgalleries
     $order = 'add_date DESC';
     if (get_option('gallery_name_order') == '1') {
         $order = 'name ASC';
     }
     $rows_children = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('parent_id' => $cat), 'ORDER BY ' . $order, 200);
     $children = new ocp_tempcode();
     $num_galleries = 0;
     if (count($rows_children) == 200) {
         $rows_children = array();
     }
     // Lots of personal galleries. Will need to be reached via member profiles
     foreach ($rows_children as $child) {
         if (substr($child['name'], 0, 9) == 'download_') {
             continue;
         }
         if (!has_category_access(get_member(), 'galleries', $child['name'])) {
             continue;
         }
         if (get_option('show_empty_galleries') == '1' || gallery_has_content($child['name'])) {
             if (is_null($max) || $num_galleries >= $start && $num_galleries < $start + $max) {
                 $content = show_gallery_box($child, $root, true, get_zone_name(), get_option('show_empty_galleries') != '1');
                 if (!$content->is_empty()) {
                     $children->attach(do_template('GALLERY_SUBGALLERY_WRAP', array('CONTENT' => $content)));
                 }
             }
             $num_galleries++;
         }
     }
     // Views
     if (get_db_type() != 'xml') {
         $myrow['gallery_views']++;
         $GLOBALS['SITE_DB']->query_update('galleries', array('gallery_views' => $myrow['gallery_views']), array('name' => $cat), '', 1, NULL, false, true);
     }
     // Page title
     if (addon_installed('awards')) {
         require_code('awards');
         $awards = find_awards_for('gallery', $cat);
     } else {
         $awards = array();
     }
     $title_to_use = do_lang_tempcode('_GALLERY', escape_html($fullname));
     $title_to_use_2 = do_lang('_GALLERY', $fullname);
     $title = get_page_title($title_to_use, false, NULL, NULL, $awards);
     seo_meta_load_for('gallery', $cat, $title_to_use_2);
     $rep_image = $myrow['rep_image'];
     if (post_param_integer('rating_' . $cat, -1) != -1) {
         decache('main_top_galleries');
     }
     list($rating_details, $comment_details, $trackback_details) = embed_feedback_systems(get_page_name(), $cat, $myrow['allow_rating'], $myrow['allow_comments'], 0, 1, NULL, build_url(array('page' => '_SELF'), '_SELF', NULL, true, false, true), $title_to_use_2, get_value('comment_forum__galleries'));
     breadcrumb_add_segment($tree);
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $myrow['add_date']), 'creator' => is_null($myrow['g_owner']) ? '' : $GLOBALS['FORUM_DRIVER']->get_username($myrow['g_owner']), 'publisher' => '', 'modified' => '', 'type' => 'Gallery', 'title' => $fullname, 'identifier' => '_SEARCH:galleries:misc:' . $cat, 'description' => get_translated_text($myrow['description']));
     if ($rep_image != '') {
         $GLOBALS['META_DATA'] += array('image' => (url_is_local($rep_image) ? get_custom_base_url() . '/' : '') . $rep_image);
     }
     // Sorting
     list($sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos) = $this->get_sort_order();
     if (get_option('is_on_rating') == '1') {
         $_selectors['compound_rating DESC'] = 'POPULARITY';
     }
     $_selectors = array_merge($_selectors, array('url ASC' => 'FILENAME', 'add_date ASC' => 'OLDEST_FIRST', 'add_date DESC' => 'NEWEST_FIRST', 'title ASC' => 'TITLE'));
     $selectors = new ocp_tempcode();
     foreach ($_selectors as $selector_value => $selector_name) {
         $selected = $sort == $selector_value;
         $selectors->attach(do_template('RESULTS_BROWSER_SORTER', array('SELECTED' => $selected, 'NAME' => do_lang_tempcode($selector_name), 'VALUE' => $selector_value)));
     }
     $sort_url = get_self_url(false, false, array('sort' => NULL), false, true);
     $sorting = do_template('RESULTS_BROWSER_SORT', array('SORT' => 'sort', 'RAND' => uniqid(''), 'URL' => $sort_url, 'SELECTORS' => $selectors));
     if ($myrow['flow_mode_interface'] == 1) {
         return $this->do_gallery_flow_mode($rating_details, $comment_details, $cat, $root, $description, $children, $may_download_gallery, $edit_url, $add_gallery_url, $submit_image_url, $submit_video_url, $title, $rep_image, $start, $max, $num_galleries, $fullname, $sorting);
     } else {
         return $this->do_gallery_regular_mode($rating_details, $comment_details, $cat, $root, $description, $children, $may_download_gallery, $edit_url, $add_gallery_url, $submit_image_url, $submit_video_url, $title, $fullname, $sorting);
     }
 }
예제 #8
0
/**
 * Delete a specified gallery.
 *
 * @param  ID_TEXT		The gallery codename
 */
function delete_gallery($name)
{
    if ($name == '') {
        warn_exit(do_lang_tempcode('NO_DELETE_ROOT'));
    }
    $rows = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('name' => $name), '', 1);
    if (!array_key_exists(0, $rows)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    require_code('files2');
    delete_upload('uploads/grepimages', 'galleries', 'rep_image', 'name', $name);
    delete_upload('uploads/watermarks', 'galleries', 'watermark_top_left', 'name', $name);
    delete_upload('uploads/watermarks', 'galleries', 'watermark_top_right', 'name', $name);
    delete_upload('uploads/watermarks', 'galleries', 'watermark_bottom_left', 'name', $name);
    delete_upload('uploads/watermarks', 'galleries', 'watermark_bottom_right', 'name', $name);
    log_it('DELETE_GALLERY', $name, get_translated_text($rows[0]['fullname']));
    delete_lang($rows[0]['fullname']);
    delete_lang($rows[0]['description']);
    delete_lang($rows[0]['teaser']);
    // Images and videos are deleted, because we are deleting the _gallery_, not just a category (nobody is going to be deleting galleries with the expectation of moving the image to a different one in bulk - unlike download categories, for example).
    if (function_exists('set_time_limit')) {
        @set_time_limit(0);
    }
    do {
        $images = $GLOBALS['SITE_DB']->query_select('images', array('id'), array('cat' => $name), '', 200);
        foreach ($images as $image) {
            delete_image($image['id'], false);
        }
    } while ($images != array());
    do {
        $videos = $GLOBALS['SITE_DB']->query_select('videos', array('id'), array('cat' => $name), '', 200);
        foreach ($videos as $video) {
            delete_video($video['id'], false);
        }
    } while ($images != array());
    //... but the subgalleries remain
    $GLOBALS['SITE_DB']->query_update('galleries', array('parent_id' => $rows[0]['parent_id']), array('parent_id' => $name));
    $GLOBALS['SITE_DB']->query_delete('galleries', array('name' => $name), '', 1);
    $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => 'images', 'rating_for_id' => $name));
    $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => 'videos', 'rating_for_id' => $name));
    require_code('seo2');
    seo_meta_erase_storage('gallery', $name);
    $GLOBALS['SITE_DB']->query_delete('group_category_access', array('module_the_name' => 'galleries', 'category_name' => $name));
    $GLOBALS['SITE_DB']->query_delete('gsp', array('module_the_name' => 'galleries', 'category_name' => $name));
    decache('main_top_galleries');
    decache('main_recent_galleries');
    decache('main_root_galleries');
    decache('side_root_galleries');
}
예제 #9
0
파일: news.php 프로젝트: erico-deh/ocPortal
/**
 * Delete a news entry.
 *
 * @param  AUTO_LINK		The ID of the news to edit
 */
function delete_news($id)
{
    $rows = $GLOBALS['SITE_DB']->query_select('news', array('title', 'news', 'news_article'), array('id' => $id), '', 1);
    if (!array_key_exists(0, $rows)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $title = $rows[0]['title'];
    $news = $rows[0]['news'];
    $news_article = $rows[0]['news_article'];
    $_title = get_translated_text($title);
    log_it('DELETE_NEWS', strval($id), $_title);
    require_code('files2');
    delete_upload('uploads/grepimages', 'news', 'news_image', 'id', $id);
    $GLOBALS['SITE_DB']->query_delete('news', array('id' => $id), '', 1);
    $GLOBALS['SITE_DB']->query_delete('news_category_entries', array('news_entry' => $id));
    $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => 'news', 'rating_for_id' => $id));
    $GLOBALS['SITE_DB']->query_delete('trackbacks', array('trackback_for_type' => 'news', 'trackback_for_id' => $id));
    delete_lang($title);
    delete_lang($news);
    require_code('attachments2');
    require_code('attachments3');
    if (!is_null($news_article)) {
        delete_lang_comcode_attachments($news_article, 'news', strval($id));
    }
    require_code('seo2');
    seo_meta_erase_storage('news', strval($id));
    decache('main_news');
    decache('side_news');
    decache('side_news_archive');
    decache('bottom_news');
}
예제 #10
0
 /**
  * The actualiser to move a page.
  *
  * @return tempcode		The UI
  */
 function _move()
 {
     $title = get_page_title('MOVE_PAGES');
     if (get_file_base() != get_custom_file_base()) {
         warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
     }
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/move';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_structure';
     $zone = post_param('zone', NULL);
     if (is_null($zone)) {
         $post_url = build_url(array('page' => '_SELF', 'type' => get_param('type')), '_SELF', NULL, true);
         $hidden = build_keep_form_fields('', true);
         return do_template('YESNO_SCREEN', array('_GUID' => 'c6e872cc62bdc7cf1c5157fbfdb2dfd6', 'TITLE' => $title, 'TEXT' => do_lang_tempcode('Q_SURE'), 'URL' => $post_url, 'HIDDEN' => $hidden));
     }
     $new_zone = post_param('destination_zone', '');
     if (substr($new_zone, -1) == ':') {
         $new_zone = substr($new_zone, 0, strlen($new_zone) - 1);
     }
     //$pages=find_all_pages_wrap($zone);
     $pages = array();
     require_code('site');
     foreach ($_POST as $key => $val) {
         if (substr($key, 0, 6) == 'page__' && $val === '1') {
             $page = substr($key, 6);
             $page_details = _request_page($page, $zone, NULL, NULL, true);
             if ($page_details === false) {
                 warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
             }
             $pages[$page] = strtolower($page_details[0]);
             if (array_key_exists(3, $page_details)) {
                 $pages[$page] .= '/' . $page_details[3];
             }
         }
     }
     $afm_needed = false;
     foreach ($pages as $page => $type) {
         if (post_param_integer('page__' . $page, 0) == 1) {
             if ($type != 'comcode_custom') {
                 $afm_needed = true;
             }
         }
     }
     if ($afm_needed) {
         require_code('abstract_file_manager');
         force_have_afm_details();
     }
     $cannot_move = new ocp_tempcode();
     foreach ($pages as $page => $type) {
         if (!is_string($page)) {
             $page = strval($page);
         }
         if (post_param_integer('page__' . $page, 0) == 1) {
             if (substr($type, 0, 7) == 'modules') {
                 $_page = $page . '.php';
             } elseif (substr($type, 0, 7) == 'comcode') {
                 $_page = $page . '.txt';
             } elseif (substr($type, 0, 4) == 'html') {
                 $_page = $page . '.htm';
             }
             if (file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page))) {
                 if (!$cannot_move->is_empty()) {
                     $cannot_move->attach(do_lang_tempcode('LIST_SEP'));
                 }
                 $cannot_move->attach(do_lang_tempcode('PAGE_WRITE', escape_html($page)));
                 continue;
             }
         }
     }
     $moved_something = NULL;
     foreach ($pages as $page => $type) {
         if (!is_string($page)) {
             $page = strval($page);
         }
         if (post_param_integer('page__' . $page, 0) == 1) {
             $moved_something = $page;
             if (substr($type, 0, 7) == 'modules') {
                 $_page = $page . '.php';
             } elseif (substr($type, 0, 7) == 'comcode') {
                 $_page = $page . '.txt';
             } elseif (substr($type, 0, 4) == 'html') {
                 $_page = $page . '.htm';
             }
             if (file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page))) {
                 continue;
             }
             if (file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page))) {
                 if ($afm_needed) {
                     afm_move(zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page, true), zone_black_magic_filterer(filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page, true));
                 } else {
                     rename(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page), zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page));
                 }
             }
             // If a non-overridden one is there too, need to move that too
             if (strpos($type, '_custom') !== false && file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page)) && !file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page))) {
                 if ($afm_needed) {
                     afm_move(zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page, true), zone_black_magic_filterer(filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page, true));
                 } else {
                     rename(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page), zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page));
                 }
             }
             log_it('MOVE_PAGES', $page);
         }
     }
     if (is_null($moved_something)) {
         warn_exit(do_lang_tempcode('NOTHING_SELECTED'));
     }
     persistant_cache_empty();
     require_lang('addons');
     if ($cannot_move->is_empty()) {
         $message = do_lang_tempcode('SUCCESS');
     } else {
         $message = do_lang_tempcode('WOULD_NOT_OVERWRITE_BUT_SUCCESS', $cannot_move);
     }
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('PAGES')), array('_SELF:_SELF:move', do_lang_tempcode('MOVE_PAGES'))));
     decache('main_sitemap');
     if (has_js()) {
         return inform_screen($title, $message);
         // Came from site-tree editor, so want to just close this window when done
     }
     return $this->do_next_manager($title, $moved_something, $new_zone, new ocp_tempcode());
 }
예제 #11
0
 /**
  * Standard modular UI/actualiser to edit an entry.
  *
  * @return tempcode	The UI
  */
 function __ed()
 {
     $id = mixed();
     // Define type as mixed
     $id = $this->non_integer_id ? get_param('id', false, true) : strval(get_param_integer('id'));
     $doing = 'EDIT_' . $this->lang_type;
     if ($this->catalogue && get_param('catalogue_name', '') != '') {
         $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => get_param('catalogue_name'))));
         if ($this->type_code == 'd') {
             $doing = do_lang('CATALOGUE_GENERIC_EDIT', escape_html($catalogue_title));
         } elseif ($this->type_code == 'c') {
             $doing = do_lang('CATALOGUE_GENERIC_EDIT_CATEGORY', escape_html($catalogue_title));
         }
     }
     $title = get_page_title($doing);
     if ($this->second_stage_preview && get_param_integer('preview', 0) == 1) {
         return $this->preview_intercept($title);
     }
     if (method_exists($this, 'get_submitter')) {
         list($submitter, $date_and_time) = $this->get_submitter($id);
         if (!is_null($date_and_time) && addon_installed('points')) {
             $reverse = post_param_integer('reverse_point_transaction', 0);
             if ($reverse == 1) {
                 $points_test = $GLOBALS['SITE_DB']->query_select('gifts', array('*'), array('date_and_time' => $date_and_time, 'gift_to' => $submitter, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id()));
                 if (array_key_exists(0, $points_test)) {
                     $amount = $points_test[0]['amount'];
                     $sender_id = $points_test[0]['gift_from'];
                     $recipient_id = $points_test[0]['gift_to'];
                     $GLOBALS['SITE_DB']->query_delete('gifts', array('id' => $points_test[0]['id']), '', 1);
                     if (!is_guest($sender_id)) {
                         $_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));
                     }
                     require_code('points');
                     $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));
                 }
             }
         }
     } else {
         $submitter = NULL;
     }
     breadcrumb_set_parents(array_merge($GLOBALS['BREADCRUMB_SET_PARENTS'], array(array('_SELF:_SELF:_e' . $this->type_code . ':' . $id, strpos($doing, ' ') !== false ? protect_from_escaping($doing) : do_lang_tempcode($doing)))));
     $delete = post_param_integer('delete', 0);
     if ($delete == 1 || $delete == 2) {
         if (!is_null($this->permissions_require)) {
             check_delete_permission($this->permissions_require, $submitter, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id)), $this->permission_page_name);
         }
         $doing = 'DELETE_' . $this->lang_type;
         if ($this->catalogue && get_param('catalogue_name', '') != '') {
             $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => get_param('catalogue_name'))));
             if ($this->type_code == 'd') {
                 $doing = do_lang('CATALOGUE_GENERIC_DELETE', escape_html($catalogue_title));
             } elseif ($this->type_code == 'c') {
                 $doing = do_lang('CATALOGUE_GENERIC_DELETE_CATEGORY', escape_html($catalogue_title));
             }
         }
         $title = get_page_title($doing);
         $test = $this->handle_confirmations($title);
         if (!is_null($test)) {
             return $test;
         }
         $this->delete_actualisation($id);
         // Delete custom fields
         if ($this->has_tied_catalogue()) {
             require_code('fields');
             delete_form_custom_fields($this->award_type, $id);
         }
         /*if ((!is_null($this->redirect_type)) || ((!is_null(get_param('redirect',NULL)))))		No - resource is gone now, and redirect would almost certainly try to take us back there
         		{
         			$url=(($this->redirect_type=='!') || (is_null($this->redirect_type)))?get_param('redirect'):build_url(array('page'=>'_SELF','type'=>$this->redirect_type),'_SELF');
         			return redirect_screen($title,$url,do_lang_tempcode('SUCCESS'));
         		}*/
         clear_ocp_autosave();
         $description = is_null($this->do_next_description) ? do_lang_tempcode('SUCCESS') : $this->do_next_description;
         return $this->do_next_manager($title, $description, NULL);
     } else {
         if (!is_null($this->permissions_require)) {
             check_edit_permission($this->permissions_require, $submitter, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id)), $this->permission_page_name);
         }
         $test = $this->handle_confirmations($title);
         if (!is_null($test)) {
             return $test;
         }
         if ($this->user_facing && !is_null($this->permissions_require) && array_key_exists('validated', $_POST)) {
             if (!has_specific_permission(get_member(), 'bypass_validation_' . $this->permissions_require . 'range_content', $this->permission_page_name, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? '' : post_param($this->permissions_cat_name), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? '' : post_param($this->permissions_cat_name_b)))) {
                 $_POST['validated'] = '0';
             }
         }
         if (!is_null($this->upload)) {
             require_code('uploads');
         }
         $description = $this->edit_actualisation($id);
         if (!is_null($this->new_id)) {
             $id = $this->new_id;
         }
         // Save custom fields
         if ($this->has_tied_catalogue()) {
             require_code('fields');
             save_form_custom_fields($this->award_type, $id);
         }
         if ($this->output_of_action_is_confirmation && !is_null($description)) {
             return $description;
         }
         if (is_null($description)) {
             $description = do_lang_tempcode('SUCCESS');
         }
         if (addon_installed('awards')) {
             if (!is_null($this->award_type)) {
                 require_code('awards');
                 handle_award_setting($this->award_type, $id);
             }
         }
         if ($this->user_facing) {
             if ($this->check_validation && post_param_integer('validated', 0) == 0) {
                 require_code('submit');
                 if ($this->send_validation_request) {
                     $edit_url = build_url(array('page' => '_SELF', 'type' => '_e' . $this->type_code, 'id' => $id, 'validated' => 1), '_SELF', NULL, false, false, true);
                     if (addon_installed('unvalidated')) {
                         send_validation_request($doing, $this->table, $this->non_integer_id, $id, $edit_url);
                     }
                 }
                 $description->attach(paragraph(do_lang_tempcode('SUBMIT_UNVALIDATED')));
             }
         }
     }
     if (!is_null($this->redirect_type) || !is_null(get_param('redirect', NULL))) {
         $url = $this->redirect_type == '!' || is_null($this->redirect_type) ? make_string_tempcode(get_param('redirect')) : build_url(array('page' => '_SELF', 'type' => $this->redirect_type), '_SELF');
         return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
     }
     clear_ocp_autosave();
     decache('main_awards');
     return $this->do_next_manager($title, $description, $id);
 }
예제 #12
0
 /**
  * The actualiser to set privileges.
  *
  * @return tempcode		The UI
  */
 function set_specific_permissions()
 {
     require_all_lang();
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/privileges';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_permissions';
     if (count($_POST) == 0 && strtolower(ocp_srv('REQUEST_METHOD')) != 'post') {
         warn_exit(do_lang_tempcode('PERMISSION_TRAGEDY_PREVENTED'));
     }
     $title = get_page_title('SPECIFIC_PERMISSIONS');
     $p_section = get_param('id');
     $_sections = $this->_get_ordered_sections();
     $array_keys = array_keys($_sections);
     $next_section = $array_keys[0];
     $counter = 0;
     foreach ($_sections as $s) {
         if (is_null($s)) {
             continue;
         }
         if ($counter > array_search($p_section, $array_keys)) {
             $next_section = $s['p_section'];
             break;
         }
         $counter++;
     }
     $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
     $permissions = collapse_1d_complexity('the_name', $GLOBALS['SITE_DB']->query_select('sp_list', array('the_name'), array('p_section' => $p_section)));
     $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
     foreach ($permissions as $permission) {
         foreach (array_keys($groups) as $id) {
             if (in_array($id, $admin_groups)) {
                 continue;
             }
             $val = post_param_integer($permission . '__' . strval($id), 0);
             // Delete to cleanup
             $GLOBALS['SITE_DB']->query_delete('gsp', array('specific_permission' => $permission, 'group_id' => $id, 'the_page' => '', 'module_the_name' => '', 'category_name' => ''), '', 1);
             if ($val == 1) {
                 $GLOBALS['SITE_DB']->query_insert('gsp', array('specific_permission' => $permission, 'group_id' => $id, 'the_page' => '', 'module_the_name' => '', 'category_name' => '', 'the_value' => 1));
             }
         }
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF:specific', do_lang_tempcode('CHOOSE'))));
     decache('main_sitemap');
     $GLOBALS['SITE_DB']->query_delete('cache');
     if (function_exists('persistant_cache_empty')) {
         persistant_cache_empty();
     }
     // Show it worked / Refresh
     $url = build_url(array('page' => '_SELF', 'type' => 'specific', 'id' => $next_section), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS_NOW_NEXT_SCREEN'));
 }
예제 #13
0
/**
 * Log an action
 *
 * @param  ID_TEXT		The type of activity just carried out (a lang string)
 * @param  ?SHORT_TEXT	The most important parameter of the activity (e.g. id) (NULL: none)
 * @param  ?SHORT_TEXT	A secondary (perhaps, human readable) parameter of the activity (e.g. caption) (NULL: none)
 */
function _log_it($type, $a = NULL, $b = NULL)
{
    if (!function_exists('get_member')) {
        return;
    }
    // If this is during installation
    if (get_option('site_closed') == '1' && get_option('no_stats_when_closed', true) === '1') {
        return;
    }
    // Run hooks, if any exist
    $hooks = find_all_hooks('systems', 'upon_action_logging');
    foreach (array_keys($hooks) as $hook) {
        require_code('hooks/systems/upon_action_logging/' . filter_naughty($hook));
        $ob = object_factory('upon_action_logging' . filter_naughty($hook), true);
        if (is_null($ob)) {
            continue;
        }
        $ob->run($type, $a, $b);
    }
    $ip = get_ip_address();
    $GLOBALS['SITE_DB']->query_insert('adminlogs', array('the_type' => $type, 'param_a' => is_null($a) ? '' : substr($a, 0, 80), 'param_b' => is_null($b) ? '' : substr($b, 0, 80), 'date_and_time' => time(), 'the_user' => get_member(), 'ip' => $ip));
    decache('side_tag_cloud');
    decache('main_staff_actions');
    decache('main_staff_checklist');
    decache('main_awards');
    decache('main_multi_content');
    decache('side_stored_menu');
    // Due to the content counts in the CMS/Admin Zones
    if (get_page_name() != 'admin_themewizard' && get_page_name() != 'admin_import') {
        require_all_lang();
        static $logged = 0;
        $logged++;
        if ($logged < 10) {
            require_all_lang();
            if (is_null($a)) {
                $a = do_lang('NA');
            }
            if (is_null($a)) {
                $a = do_lang('NA');
            }
            require_code('notifications');
            $subject = do_lang('ACTIONLOG_NOTIFICATION_MAIL_SUBJECT', get_site_name(), do_lang($type), array($a, $b));
            $mail = do_lang('ACTIONLOG_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape(do_lang($type)), array(is_null($a) ? '' : comcode_escape($a), is_null($b) ? '' : comcode_escape($b)));
            if (addon_installed('actionlog')) {
                dispatch_notification('actionlog', $type, $subject, $mail);
            }
        }
    }
}
예제 #14
0
 /**
  * Set zone access permissions from info in the POST request.
  *
  * @param  ID_TEXT		The zone that we're setting permissions for
  */
 function set_permissions($zone)
 {
     $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
     $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
     foreach (array_keys($groups) as $id) {
         if (in_array($id, $admin_groups)) {
             continue;
         }
         $value = post_param_integer('access_' . strval($id), 0);
         $GLOBALS['SITE_DB']->query_delete('group_zone_access', array('zone_name' => $zone, 'group_id' => $id), '', 1);
         if ($value == 1) {
             $GLOBALS['SITE_DB']->query_insert('group_zone_access', array('zone_name' => $zone, 'group_id' => $id));
         }
     }
     decache('main_sitemap');
     $GLOBALS['SITE_DB']->query_delete('cache');
     if (function_exists('persistant_cache_empty')) {
         persistant_cache_empty();
     }
 }
예제 #15
0
/**
 * AJAX script for dynamically extended sitetree.
 */
function site_tree_script()
{
    header("Cache-Control: no-cache, must-revalidate");
    // HTTP/1.1
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    // Date in the past
    $root_perms = array('submit_cat_highrange_content' => 0, 'edit_cat_highrange_content' => 0, 'edit_own_cat_highrange_content' => 0, 'delete_cat_highrange_content' => 0, 'delete_own_cat_highrange_content' => 0, 'submit_highrange_content' => 1, 'bypass_validation_highrange_content' => 1, 'edit_own_highrange_content' => 1, 'edit_highrange_content' => 1, 'delete_own_highrange_content' => 1, 'delete_highrange_content' => 1, 'submit_cat_midrange_content' => 0, 'edit_cat_midrange_content' => 0, 'edit_own_cat_midrange_content' => 0, 'delete_cat_midrange_content' => 0, 'delete_own_cat_midrange_content' => 0, 'submit_midrange_content' => 1, 'bypass_validation_midrange_content' => 1, 'edit_own_midrange_content' => 1, 'edit_midrange_content' => 1, 'delete_own_midrange_content' => 1, 'delete_midrange_content' => 1, 'submit_cat_lowrange_content' => 0, 'edit_cat_lowrange_content' => 0, 'edit_own_cat_lowrange_content' => 0, 'delete_cat_lowrange_content' => 0, 'delete_own_cat_lowrange_content' => 0, 'submit_lowrange_content' => 1, 'bypass_validation_lowrange_content' => 1, 'edit_own_lowrange_content' => 1, 'edit_lowrange_content' => 1, 'delete_own_lowrange_content' => 1, 'delete_lowrange_content' => 1);
    require_code('zones2');
    require_code('zones3');
    // Usergroups we have
    $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
    $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
    if (!has_actual_page_access(get_member(), 'admin_site_tree', 'adminzone')) {
        exit;
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(30);
    }
    disable_php_memory_limit();
    // Needed for loading large amount of permissions (potentially)
    // ======
    // Saving
    // ======
    if (get_param_integer('set_perms', 0) == 1) {
        if (!has_actual_page_access(get_member(), 'admin_permissions', 'adminzone')) {
            exit;
        }
        // Build a map of every page link we are setting permissions for
        $map = array();
        foreach (array_merge($_GET, $_POST) as $i => $page_link) {
            if (get_magic_quotes_gpc()) {
                $page_link = stripslashes($page_link);
            }
            if (substr($i, 0, 4) == 'map_') {
                $map[intval(substr($i, 4))] = $page_link;
            }
        }
        // Read it all in
        foreach ($map as $i => $page_link) {
            // Decode page link
            $matches = array();
            $type = '';
            if ($page_link == '_root') {
                $type = 'root';
            } elseif (preg_match('#^([^:]*):([^:]+):.+$#', $page_link, $matches) != 0) {
                $type = 'cat';
            } elseif (preg_match('#^([^:]*):([^:]+)$#', $page_link, $matches) != 0) {
                $type = 'page';
            } elseif (preg_match('#^([^:]*):?$#', $page_link, $matches) != 0) {
                $type = 'zone';
            } else {
                $type = 'root';
            }
            // Working out what we're doing with privilege overrides
            if ($type == 'page' || $type == 'cat') {
                $zone = $matches[1];
                $page = $matches[2];
                list($overridables, $sp_page) = get_module_overridables($zone, $page);
            }
            if ($type == 'root') {
                // Insertion
                foreach ($groups as $group => $group_name) {
                    if (!in_array($group, $admin_groups)) {
                        // SP's
                        foreach (array_keys($root_perms) as $overide) {
                            $val = post_param_integer(strval($i) . 'gsp_' . $overide . '_' . strval($group), -2);
                            if ($val != -2) {
                                $GLOBALS['SITE_DB']->query_delete('gsp', array('specific_permission' => $overide, 'group_id' => $group, 'the_page' => '', 'module_the_name' => '', 'category_name' => ''));
                                if ($val != -1) {
                                    $GLOBALS['SITE_DB']->query_insert('gsp', array('specific_permission' => $overide, 'group_id' => $group, 'module_the_name' => '', 'category_name' => '', 'the_page' => '', 'the_value' => $val));
                                }
                            }
                        }
                    }
                }
            } elseif ($type == 'zone') {
                $zone = $matches[1];
                // Insertion
                foreach ($groups as $group => $group_name) {
                    if (!in_array($group, $admin_groups)) {
                        // View access
                        $view = post_param_integer(strval($i) . 'g_view_' . strval($group), -1);
                        if ($view != -1) {
                            $GLOBALS['SITE_DB']->query_delete('group_zone_access', array('zone_name' => $zone, 'group_id' => $group));
                            if ($view == 1) {
                                $GLOBALS['SITE_DB']->query_insert('group_zone_access', array('zone_name' => $zone, 'group_id' => $group));
                            }
                        }
                    }
                }
            } elseif ($type == 'page') {
                // Insertion
                foreach ($groups as $group => $group_name) {
                    if (!in_array($group, $admin_groups)) {
                        // View access
                        $view = post_param_integer(strval($i) . 'g_view_' . strval($group), -1);
                        if ($view != -1) {
                            $GLOBALS['SITE_DB']->query_delete('group_page_access', array('zone_name' => $zone, 'page_name' => $page, 'group_id' => $group));
                            if ($view == 0) {
                                // Pages have access by row non-presence, for good reason
                                $GLOBALS['SITE_DB']->query_insert('group_page_access', array('zone_name' => $zone, 'page_name' => $page, 'group_id' => $group));
                            }
                        }
                        // SP's
                        foreach (array_keys($overridables) as $overide) {
                            $val = post_param_integer(strval($i) . 'gsp_' . $overide . '_' . strval($group), -2);
                            if ($val != -2) {
                                $GLOBALS['SITE_DB']->query_delete('gsp', array('specific_permission' => $overide, 'group_id' => $group, 'the_page' => $sp_page));
                                if ($val != -1) {
                                    $GLOBALS['SITE_DB']->query_insert('gsp', array('specific_permission' => $overide, 'group_id' => $group, 'module_the_name' => '', 'category_name' => '', 'the_page' => $sp_page, 'the_value' => $val));
                                }
                            }
                        }
                    }
                }
            } elseif ($type == 'cat') {
                $_pagelinks = extract_module_functions_page($zone, $page, array('extract_page_link_permissions'), array($page_link));
                list($category, $module) = is_array($_pagelinks[0]) ? call_user_func_array($_pagelinks[0][0], $_pagelinks[0][1]) : eval($_pagelinks[0]);
                // If $_pagelinks[0] is NULL then it's an error: extract_page_link_permissions is always there when there are cat permissions
                // Insertion
                foreach ($groups as $group => $group_name) {
                    if (!in_array($group, $admin_groups)) {
                        // View access
                        $view = post_param_integer(strval($i) . 'g_view_' . strval($group), -1);
                        if ($view != -1) {
                            $GLOBALS['SITE_DB']->query_delete('group_category_access', array('module_the_name' => $module, 'category_name' => $category, 'group_id' => $group));
                            if ($view == 1) {
                                $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => $module, 'category_name' => $category, 'group_id' => $group));
                            }
                        }
                        // SP's
                        foreach ($overridables as $overide => $cat_support) {
                            if (is_array($cat_support)) {
                                $cat_support = $cat_support[0];
                            }
                            if ($cat_support == 0) {
                                continue;
                            }
                            $val = post_param_integer(strval($i) . 'gsp_' . $overide . '_' . strval($group), -2);
                            if ($val != -2) {
                                $GLOBALS['SITE_DB']->query_delete('gsp', array('specific_permission' => $overide, 'group_id' => $group, 'module_the_name' => $module, 'category_name' => $category, 'the_page' => ''));
                                if ($val != -1) {
                                    $new_settings = array('specific_permission' => $overide, 'group_id' => $group, 'module_the_name' => $module, 'category_name' => $category, 'the_page' => '', 'the_value' => $val);
                                    $GLOBALS['SITE_DB']->query_insert('gsp', $new_settings);
                                }
                            }
                        }
                    }
                }
            }
        }
        decache('main_sitemap');
        $GLOBALS['SITE_DB']->query_delete('cache');
        if (function_exists('persistant_cache_empty')) {
            persistant_cache_empty();
        }
        // Tra la la tada
        return;
    }
    // =======
    // Loading
    // =======
    $default = get_param('default', NULL, true);
    header('Content-Type: text/xml');
    $permissions_needed = get_param_integer('get_perms', 0) == 1;
    // Whether we are limiting our tree to permission-supporting
    @ini_set('ocproducts.xss_detect', '0');
    echo '<' . '?xml version="1.0" encoding="' . get_charset() . '"?' . '>';
    echo '<request><result>';
    require_lang('permissions');
    require_lang('zones');
    $page_link = get_param('id', NULL, true);
    $_sp_access = $GLOBALS['SITE_DB']->query_select('gsp', array('*'));
    $sp_access = array();
    foreach ($_sp_access as $a) {
        if (!isset($sp_access[$a['group_id']])) {
            $sp_access[$a['group_id']] = array();
        }
        $sp_access[$a['group_id']][] = $a;
    }
    if (!is_null($page_link) && $page_link != '' && (strpos($page_link, ':') === false || strpos($page_link, ':') === strlen($page_link) - 1)) {
        if (strpos($page_link, ':') === strlen($page_link) - 1) {
            $page_link = substr($page_link, 0, strlen($page_link) - 1);
        }
        // Pages in the zone
        $zone = $page_link;
        $page_type = get_param('page_type', NULL);
        $pages = find_all_pages_wrap($zone, false, true, FIND_ALL_PAGES__NEWEST, $page_type);
        ksort($pages);
        if ($permissions_needed) {
            $zone_access = $GLOBALS['SITE_DB']->query_select('group_zone_access', array('*'), array('zone_name' => $zone));
            $page_access = $GLOBALS['SITE_DB']->query_select('group_page_access', array('*'), array('zone_name' => $zone));
        }
        foreach ($pages as $page => $page_type) {
            if (!is_string($page)) {
                $page = strval($page);
            }
            $full_page_type = $page_type;
            $description = '';
            if (strpos($full_page_type, '/') !== false) {
                $full_page_type = substr($full_page_type, 0, strpos($full_page_type, '/'));
            }
            if (strpos($full_page_type, ':') !== false) {
                $full_page_type = substr($full_page_type, 0, strpos($full_page_type, ':'));
            }
            switch ($full_page_type) {
                case 'redirect':
                    list(, $redir_zone, $redir_page) = explode(':', $page_type);
                    $page_title = html_entity_decode(strip_tags(str_replace(array('<kbd>', '</kbd>'), array('"', '"'), do_lang('REDIRECT_PAGE_TO', xmlentities($redir_zone), xmlentities($redir_page)))), ENT_QUOTES) . ': ' . (is_string($page) ? $page : strval($page));
                    break;
                case 'comcode':
                case 'comcode_custom':
                    $page_title = do_lang('COMCODE_PAGE') . ': ' . (is_string($page) ? $page : strval($page));
                    break;
                case 'html':
                case 'html_custom':
                    $page_title = 'HTML: ' . $page;
                    break;
                case 'modules':
                case 'modules_custom':
                    $page_title = do_lang('MODULE') . ': ' . $page;
                    $matches = array();
                    if (preg_match('#@package\\s+(\\w+)#', file_get_contents(zone_black_magic_filterer(get_file_base() . '/' . $zone . '/pages/' . $page_type . '/' . $page . '.php')), $matches) != 0) {
                        $package = $matches[1];
                        $path = get_file_base() . '/sources_custom/hooks/systems/addon_registry/' . $package . '.php';
                        if (!file_exists($path)) {
                            $path = get_file_base() . '/sources/hooks/systems/addon_registry/' . $package . '.php';
                        }
                        if (file_exists($path)) {
                            require_lang('zones');
                            require_code('zones2');
                            $functions = extract_module_functions($path, array('get_description'));
                            $description = is_array($functions[0]) ? call_user_func_array($functions[0][0], $functions[0][1]) : eval($functions[0]);
                            $description = do_lang('FROM_ADDON', $package, $description);
                        }
                    }
                    break;
                case 'minimodules':
                case 'minimodules_custom':
                    $page_title = do_lang('MINIMODULE') . ': ' . $page;
                    break;
                default:
                    $page_title = do_lang('PAGE') . ': ' . $page;
                    break;
            }
            if ($permissions_needed) {
                $view_perms = '';
                foreach ($groups as $group => $group_name) {
                    if (!in_array($group, $admin_groups)) {
                        $view_perms .= 'g_view_' . strval($group) . '="' . (!in_array(array('zone_name' => $zone, 'page_name' => is_string($page) ? $page : strval($page), 'group_id' => $group), $page_access) ? 'true' : 'false') . '" ';
                    }
                }
                $pagelinks = NULL;
                if (substr($page_type, 0, 7) != 'modules') {
                    $overridables = array();
                } else {
                    list($overridables, $sp_page) = get_module_overridables($zone, $page);
                }
                $sp_perms = '';
                foreach ($overridables as $overridable => $cat_support) {
                    $lang_string = do_lang('PT_' . $overridable);
                    if (is_array($cat_support)) {
                        $lang_string = do_lang($cat_support[1]);
                    }
                    if (strlen($lang_string) > 20 && strpos($lang_string, '(') !== false) {
                        $lang_string = preg_replace('# \\([^\\)]*\\)#', '', $lang_string);
                    }
                    $sp_perms .= 'sp_' . $overridable . '="' . xmlentities($lang_string) . '" ';
                    foreach ($groups as $group => $group_name) {
                        if (!in_array($group, $admin_groups)) {
                            $override_value = -1;
                            foreach ($sp_access[$group] as $test) {
                                if ($test['specific_permission'] == $overridable && $test['the_page'] == $sp_page) {
                                    $override_value = $test['the_value'];
                                }
                            }
                            if ($override_value != -1) {
                                $sp_perms .= 'gsp_' . $overridable . '_' . strval($group) . '="' . strval($override_value) . '" ';
                            }
                        }
                    }
                }
                if (count($overridables) == 0) {
                    $sp_perms = 'no_sps="1" ';
                }
                $has_children = $sp_perms != '';
                if (count(array_diff(array_keys($overridables), array('submit_highrange_content', 'submit_midrange_content', 'submit_lowrange_content'))) != 0) {
                    $sp_perms .= 'inherits_something="1" ';
                }
                $serverid = $zone . ':' . (is_string($page) ? $page : strval($page));
                echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'description="' . xmlentities($description) . '" img_func_1="permissions_img_func_1" img_func_2="permissions_img_func_2" highlighted="true" ' . $view_perms . $sp_perms . ' id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities($page_title) . '" has_children="' . ($has_children ? 'true' : 'false') . '" selectable="true">';
            } else {
                $extra = '';
                if (strpos($page_type, 'modules') === 0) {
                    $info = extract_module_info(zone_black_magic_filterer(get_file_base() . '/' . $zone . ($zone == '' ? '' : '/') . 'pages/' . $page_type . '/' . $page . '.php'));
                    if (!is_null($info) && array_key_exists('author', $info)) {
                        $extra = 'author="' . xmlentities($info['author']) . '" organisation="' . xmlentities($info['organisation']) . '" version="' . xmlentities(integer_format($info['version'])) . '" ';
                    }
                }
                $has_children = false;
                // For a normal tree, we have children if we have entry points. We have children if we have categories also - but where there are categories there are also entry points
                if (strpos($page_type, 'modules') === 0) {
                    $_entrypoints = extract_module_functions_page($zone, $page, array('get_entry_points'));
                    if (!is_null($_entrypoints[0])) {
                        $entrypoints = is_string($_entrypoints[0]) && strpos($_entrypoints[0], '::') !== false ? array('whatever' => 1) : (is_array($_entrypoints[0]) ? call_user_func_array($_entrypoints[0][0], $_entrypoints[0][1]) : eval($_entrypoints[0]));
                        // The strpos thing is a little hack that allows it to work for base-class derived modules
                        if (!is_array($entrypoints)) {
                            $entrypoints = array('whatever' => 1);
                        }
                        $has_children = array_keys($entrypoints) != array('!');
                    }
                }
                global $MODULES_ZONES;
                $not_draggable = array_key_exists($page, $MODULES_ZONES) || $zone == 'adminzone' && substr($page, 0, 6) == 'admin_' && substr($page_type, 0, 6) == 'module';
                $serverid = $zone . ':' . $page;
                echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . '' . $extra . 'type="' . xmlentities($page_type) . '" description="' . xmlentities($description) . '" draggable="' . ($not_draggable ? 'false' : 'page') . '" droppable="' . ($page_type == 'zone' ? 'page' : 'false') . '" id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities($page_title) . '" has_children="' . ($has_children ? 'true' : 'false') . '" selectable="true">';
            }
            echo '</category>';
        }
    } elseif (!is_null($page_link) && $page_link != '') {
        $matches = array();
        preg_match('#^([^:]*):([^:]*)#', $page_link, $matches);
        $zone = $matches[1];
        $page = $matches[2];
        if ($permissions_needed) {
            $category_access = $GLOBALS['SITE_DB']->query_select('group_category_access', array('*'));
        }
        $_pagelinks = extract_module_functions_page($zone, $page, array('get_page_links'), array(1, true, $page_link));
        if (!is_null($_pagelinks[0])) {
            $pagelinks = is_array($_pagelinks[0]) ? call_user_func_array($_pagelinks[0][0], $_pagelinks[0][1]) : eval($_pagelinks[0]);
            if (!is_null($pagelinks[0]) && !is_null($pagelinks[1])) {
                $_overridables = extract_module_functions_page(get_module_zone($pagelinks[1]), $pagelinks[1], array('get_sp_overrides'));
                if (!is_null($_overridables[0])) {
                    $overridables = is_array($_overridables[0]) ? call_user_func_array($_overridables[0][0], $_overridables[0][1]) : eval($_overridables[0]);
                } else {
                    $overridables = array();
                }
            } else {
                $overridables = array();
            }
        } else {
            $pagelinks = NULL;
        }
        $_pagelinks = extract_module_functions_page($zone, $page, array('extract_page_link_permissions'), array($page_link));
        list($category, $module) = is_null($_pagelinks[0]) || strlen($matches[0]) == strlen($page_link) ? array('!', '') : (is_array($_pagelinks[0]) ? call_user_func_array($_pagelinks[0][0], $_pagelinks[0][1]) : eval($_pagelinks[0]));
        // If $_pagelinks[0] is NULL then it's an error: extract_page_link_permissions is always there when there are cat permissions
        // Entry points under here
        if (!$permissions_needed && $zone . ':' . $page == $page_link) {
            $path = zone_black_magic_filterer(filter_naughty($zone) . ($zone == '' ? '' : '/') . 'pages/modules_custom/' . filter_naughty($page) . '.php', true);
            if (!file_exists(get_file_base() . '/' . $path)) {
                $path = zone_black_magic_filterer(filter_naughty($zone) . '/pages/modules/' . filter_naughty($page) . '.php', true);
            }
            require_code($path);
            if (class_exists('Mx_' . filter_naughty_harsh($page))) {
                $object = object_factory('Mx_' . filter_naughty_harsh($page));
            } else {
                $object = object_factory('Module_' . filter_naughty_harsh($page));
            }
            require_all_lang();
            $entrypoints = $object->get_entry_points();
            foreach ($entrypoints as $entry_point => $lang_string) {
                $serverid = $zone . ':' . $page;
                echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'type="entry_point" id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . ':type=' . $entry_point . '" title="' . xmlentities(do_lang('ENTRY_POINT') . ': ' . do_lang($lang_string)) . '" has_children="false" selectable="true">';
                echo '</category>';
            }
        }
        // Categories under here
        if (!is_null($pagelinks)) {
            foreach ($pagelinks[0] as $pagelink) {
                $keys = array_keys($pagelink);
                if (is_string($keys[0])) {
                    $module_the_name = array_key_exists(3, $pagelinks) ? $pagelinks[3] : NULL;
                    $category_name = is_string($pagelink['id']) ? $pagelink['id'] : strval($pagelink['id']);
                    $actual_page_link = str_replace('!', $category_name, $pagelinks[2]);
                    $title = $pagelink['title'];
                    $has_children = $pagelink['child_count'] != 0;
                } else {
                    $cms_module_name = NULL;
                    $module_the_name = $pagelink[1];
                    $category_name = is_null($pagelink[2]) ? '' : (is_string($pagelink[2]) ? $pagelink[2] : strval($pagelink[2]));
                    $actual_page_link = $pagelink[0];
                    $title = $pagelink[3];
                    $has_children = array_key_exists(7, $pagelink) ? $pagelink[7] : NULL;
                }
                $cms_module_name = $pagelinks[1];
                if ($category_name == $category) {
                    continue;
                }
                if ($module_the_name == 'catalogues_category' && $category_name == '') {
                    continue;
                }
                if (!is_null($cms_module_name)) {
                    $edit_type = '_ec';
                    if ($module_the_name == 'catalogues_catalogue') {
                        $edit_type = '_ev';
                    }
                    $actual_edit_link = preg_replace('#^[\\w\\_]+:[\\w\\_]+:type=[\\w\\_]+:(id|catalogue\\_name)=#', get_module_zone($cms_module_name) . ':' . $cms_module_name . ':' . $edit_type . ':', $actual_page_link);
                } else {
                    $actual_edit_link = '';
                }
                $actual_page_link = str_replace('_SELF:_SELF', $zone . ':' . $page, $actual_page_link);
                // Support for lazy notation
                if ($permissions_needed) {
                    $highlight = $module_the_name == 'catalogues_catalogue' ? 'true' : 'false';
                    $view_perms = '';
                    $sp_perms = '';
                    if (!is_null($module_the_name)) {
                        foreach ($groups as $group => $group_name) {
                            if (!in_array($group, $admin_groups)) {
                                $view_perms .= 'g_view_' . strval($group) . '="' . (in_array(array('module_the_name' => $module_the_name, 'category_name' => $category_name, 'group_id' => $group), $category_access) ? 'true' : 'false') . '" ';
                            }
                        }
                        foreach ($overridables as $overridable => $cat_support) {
                            $lang_string = do_lang('PT_' . $overridable);
                            if (is_array($cat_support)) {
                                $lang_string = do_lang($cat_support[1]);
                            }
                            if (strlen($lang_string) > 20 && strpos($lang_string, '(') !== false) {
                                $lang_string = preg_replace('# \\([^\\)]*\\)#', '', $lang_string);
                            }
                            if (is_array($cat_support)) {
                                $cat_support = $cat_support[0];
                            }
                            if ($cat_support == 0) {
                                continue;
                            }
                            $sp_perms .= 'sp_' . $overridable . '="' . xmlentities($lang_string) . '" ';
                            foreach ($groups as $group => $group_name) {
                                if (!in_array($group, $admin_groups)) {
                                    $override_value = -1;
                                    foreach ($sp_access[$group] as $test) {
                                        if ($test['specific_permission'] == $overridable && $test['the_page'] == '' && $test['category_name'] == $category_name && $test['module_the_name'] == $module_the_name) {
                                            $override_value = $test['the_value'];
                                        }
                                    }
                                    if ($override_value != -1) {
                                        $sp_perms .= 'gsp_' . $overridable . '_' . strval($group) . '="' . strval($override_value) . '" ';
                                    }
                                }
                            }
                        }
                    }
                    if (count(array_diff(array_keys($overridables), array('submit_highrange_content', 'submit_midrange_content', 'submit_lowrange_content'))) != 0) {
                        $sp_perms .= 'inherits_something="1" ';
                    }
                    $serverid = $actual_page_link;
                    echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'img_func_1="permissions_img_func_1" img_func_2="permissions_img_func_2" highlighted="' . $highlight . '" ' . $view_perms . $sp_perms . ' id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities($title) . '" has_children="' . ($has_children ? 'true' : 'false') . '" selectable="' . (!is_null($module_the_name) ? 'true' : 'false') . '">';
                } else {
                    $serverid = $actual_page_link;
                    echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'type="category" id="' . uniqid('', true) . '" edit="' . xmlentities($actual_edit_link) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities($title) . '" has_children="' . ($has_children ? 'true' : 'false') . '" selectable="true">';
                }
                echo '</category>';
            }
        }
    } else {
        // Start of tree
        if ($permissions_needed) {
            $view_perms = '';
            foreach ($groups as $group => $group_name) {
                if (!in_array($group, $admin_groups)) {
                    $view_perms .= 'g_view_' . strval($group) . '="true" ';
                }
                // This isn't actually displayed in the editor
            }
            $sp_perms = '';
            $sp_perms_opera_hack = '';
            foreach (array_keys($root_perms) as $overridable) {
                $sp_perms .= 'sp_' . $overridable . '="' . xmlentities(do_lang('PT_' . $overridable)) . '" ';
                $sp_perms_opera_hack .= '<attribute key="' . 'sp_' . $overridable . '" value="' . xmlentities(do_lang('PT_' . $overridable)) . '" />';
                foreach ($groups as $group => $group_name) {
                    if (!in_array($group, $admin_groups)) {
                        $override_value = 0;
                        foreach ($sp_access[$group] as $test) {
                            if ($test['specific_permission'] == $overridable && $test['the_page'] == '' && $test['module_the_name'] == '' && $test['category_name'] == '') {
                                $override_value = $test['the_value'];
                            }
                        }
                        $sp_perms .= 'gsp_' . $overridable . '_' . strval($group) . '="' . strval($override_value) . '" ';
                        $sp_perms_opera_hack .= '<attribute key="' . 'gsp_' . $overridable . '_' . strval($group) . '" value="' . strval($override_value) . '" />';
                    }
                }
            }
            echo '<category serverid="_root" expanded="true" title="' . do_lang('ROOT') . '" has_children="true" selectable="true" img_func_1="permissions_img_func_1" img_func_2="permissions_img_func_2" id="' . uniqid('', true) . '" ' . $view_perms . '>';
            echo $sp_perms_opera_hack;
        } else {
            echo '<category serverid="_root" expanded="true" title="' . do_lang('ROOT') . '" has_children="true" selectable="false" type="root" id="' . uniqid('', true) . '">';
        }
        // Zones
        $zones = $GLOBALS['SITE_DB']->query_select('zones', array('zone_title', 'zone_name', 'zone_default_page'), NULL, 'ORDER BY zone_title', 50);
        if ($permissions_needed) {
            $zone_access = $GLOBALS['SITE_DB']->query_select('group_zone_access', array('*'));
            $page_access = $GLOBALS['SITE_DB']->query_select('group_page_access', array('*'));
        }
        $start_links = get_param_integer('start_links', 0) == 1;
        foreach ($zones as $_zone) {
            if (get_option('collapse_user_zones') == '1' && $_zone['zone_name'] == 'site') {
                continue;
            }
            $_zone['text_original'] = get_translated_text($_zone['zone_title']);
            $zone = $_zone['zone_name'];
            $zone_title = $_zone['text_original'];
            $serverid = $zone;
            if ($start_links) {
                $serverid = $zone . ':';
            }
            $pages = find_all_pages_wrap($zone, false, true, FIND_ALL_PAGES__NEWEST);
            if ($permissions_needed) {
                $view_perms = '';
                foreach ($groups as $group => $group_name) {
                    if (!in_array($group, $admin_groups)) {
                        $view_perms .= 'g_view_' . strval($group) . '="' . (in_array(array('zone_name' => $zone, 'group_id' => $group), $zone_access) ? 'true' : 'false') . '" ';
                    }
                }
                echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'img_func_1="permissions_img_func_1" img_func_2="permissions_img_func_2" no_sps="1" highlighted="true" ' . $view_perms . ' id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities(do_lang('ZONE') . ': ' . $zone_title) . '" has_children="' . (count($pages) != 0 ? 'true' : 'false') . '" selectable="true">';
            } else {
                echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'type="zone" droppable="page" id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities(do_lang('ZONE') . ': ' . $zone_title) . '" has_children="' . (count($pages) != 0 ? 'true' : 'false') . '" selectable="true">';
            }
            echo '</category>';
        }
        echo '</category>';
    }
    // Mark parent cats for pre-expansion
    if (!is_null($default) && $default != '' && strpos($default, ':') !== false) {
        list($zone, $page) = explode(':', $default, 2);
        echo "\n" . '<expand>' . $zone . '</expand>';
        echo "\n" . '<expand>' . $zone . ':</expand>';
        echo "\n" . '<expand>' . $zone . ':' . $page . '</expand>';
    }
    echo '</result></request>';
}
예제 #16
0
/**
 * Assuming that permission details are POSTed, set the permissions for the specified category, in the current page
 *
 * @param  ID_TEXT		The ID code for the zone
 * @param  ID_TEXT		The ID code for the page
 */
function set_page_permissions_from_environment($zone, $page)
{
    if (is_null($page)) {
        $page = get_page_name();
    }
    $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
    $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
    $GLOBALS['SITE_DB']->query_delete('group_page_access', array('zone_name' => $zone, 'page_name' => $page));
    foreach (array_keys($groups) as $group_id) {
        if (in_array($group_id, $admin_groups)) {
            continue;
        }
        $value = post_param_integer('access_' . strval($group_id), 0);
        if ($value == 0) {
            $GLOBALS['SITE_DB']->query_insert('group_page_access', array('zone_name' => $zone, 'page_name' => $page, 'group_id' => $group_id), false, true);
            // Race/corruption condition
        }
    }
    decache('main_sitemap');
    $GLOBALS['SITE_DB']->query_delete('cache');
    if (function_exists('persistant_cache_empty')) {
        persistant_cache_empty();
    }
}
예제 #17
0
파일: msn.php 프로젝트: erico-deh/ocPortal
 /**
  * Standard modular run function. See if we have to decache based on the passed filename.
  *
  * @param PATH		Filename.
  */
 function run($file)
 {
     if (strpos($file, '/netlink') !== false || $file == 'netlink') {
         decache('side_network');
     }
 }
예제 #18
0
 /**
  * The actualiser to mark a topic as unread.
  *
  * @return tempcode		The UI
  */
 function mark_unread_topic()
 {
     $topic_id = get_param_integer('id');
     $forum_id = $GLOBALS['FORUM_DB']->query_value('f_topics', 't_forum_id', array('id' => $topic_id));
     if (is_null($forum_id)) {
         decache('side_ocf_personal_topics', array(get_member()));
         decache('_new_pp', array(get_member()));
     }
     $this->ocf_ping_topic_unread($topic_id);
     return $this->redirect_to_forum('MARK_UNREAD', $forum_id, do_lang_tempcode('TOPIC_MARKED_UNREAD'));
 }
예제 #19
0
 /**
  * The actualiser to translate code (called from this module).
  *
  * @return tempcode		The UI
  */
 function set_lang_code()
 {
     decache('side_language');
     require_code('view_modes');
     erase_tempcode_cache();
     $lang = get_param('lang');
     $lang_file = get_param('lang_file');
     $for_base_lang = get_lang_file_map(fallback_lang(), $lang_file, true);
     $for_base_lang_2 = get_lang_file_map($lang, $lang_file, false);
     $descriptions = get_lang_file_descriptions(fallback_lang(), $lang_file);
     // Just to make sure the posted data is at least partially there, before we wipe out the old file
     foreach (array_unique(array_merge(array_keys($for_base_lang), array_keys($for_base_lang_2))) as $key) {
         $val = post_param($key);
     }
     $path = get_custom_file_base() . '/lang_custom/' . filter_naughty($lang) . '/' . filter_naughty($lang_file) . '.ini';
     $path_backup = $path . '.' . strval(time());
     if (file_exists($path)) {
         @copy($path, $path_backup) or intelligent_write_error($path_backup);
         sync_file($path_backup);
     }
     $myfile = @fopen($path, 'wt');
     if ($myfile === false) {
         intelligent_write_error($path);
     }
     fwrite($myfile, "[descriptions]\n");
     foreach ($descriptions as $key => $description) {
         fwrite($myfile, $key . '=' . $description . "\n");
     }
     fwrite($myfile, "\n");
     // Weird bug with IIS 'wt' writing needs this to be on a separate line
     fwrite($myfile, "[strings]\n");
     foreach (array_unique(array_merge(array_keys($for_base_lang), array_keys($for_base_lang_2))) as $key) {
         $val = post_param($key);
         if ($val != '' && (!array_key_exists($key, $for_base_lang) || str_replace(chr(10), '\\n', $val) != $for_base_lang[$key])) {
             if (fwrite($myfile, $key . '=' . str_replace(chr(10), '\\n', $val) . "\n") == 0) {
                 warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
             }
         }
     }
     fclose($myfile);
     fix_permissions($path);
     sync_file($path);
     $path_backup2 = $path . '.latest_in_ocp_edit';
     @copy($path, $path_backup2) or intelligent_write_error($path_backup2);
     sync_file($path_backup2);
     $title = get_page_title('TRANSLATE_CODE');
     log_it('TRANSLATE_CODE');
     require_code('view_modes');
     erase_cached_language();
     erase_cached_templates();
     // Show it worked / Refresh
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
예제 #20
0
 /**
  * The actualiser for deleting all the ticked messages in a room.
  *
  * @return tempcode	The UI.
  */
 function _chat_delete_many_messages()
 {
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     $title = get_page_title('DELETE_SOME_MESSAGES');
     $room_id = get_param_integer('room_id');
     check_chatroom_access($room_id);
     $room_details = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('id' => $room_id), '', 1);
     if (!array_key_exists(0, $room_details)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $row = $room_details[0];
     $has_mod_access = has_specific_permission(get_member(), 'edit_lowrange_content', 'cms_chat', array('chat', $room_id)) || $row['room_owner'] == get_member() && has_specific_permission(get_member(), 'moderate_my_private_rooms');
     if (!$has_mod_access) {
         access_denied('SPECIFIC_PERMISSION', 'edit_lowrange_content');
     }
     // Actualiser
     $count = 0;
     foreach (array_keys($_REQUEST) as $key) {
         if (substr($key, 0, 4) == 'del_') {
             delete_chat_messages(array('room_id' => $room_id, 'id' => intval(substr($key, 4))));
             $count++;
         }
     }
     if ($count == 0) {
         warn_exit(do_lang_tempcode('NOTHING_SELECTED'));
     }
     decache('side_shoutbox');
     $num_remaining = $GLOBALS['SITE_DB']->query_value('chat_messages', 'COUNT(*)', array('room_id' => $room_id));
     if ($num_remaining == 0) {
         $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     } else {
         $url = build_url(array('page' => '_SELF', 'type' => 'room', 'id' => $room_id, 'start' => get_param_integer('start'), 'max' => get_param_integer('max')), '_SELF');
     }
     // Redirect
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
예제 #21
0
/**
 * 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;
}
예제 #22
0
 /**
  * The actualiser for toggling invisible mode.
  *
  * @return tempcode	The UI.
  */
 function invisible()
 {
     if (get_option('is_on_invisibility') == '1') {
         $visible = array_key_exists(get_session_id(), $GLOBALS['SESSION_CACHE']) && $GLOBALS['SESSION_CACHE'][get_session_id()]['session_invisible'] == 0;
     } else {
         $visible = false;
         // Small fudge: always say thay are not visible now, so this will make them visible -- because they don't have permission to be invisible
     }
     $title = get_page_title($visible ? 'INVISIBLE' : 'BE_VISIBLE');
     $GLOBALS['SITE_DB']->query_update('sessions', array('session_invisible' => $visible ? 1 : 0), array('the_user' => get_member(), 'the_session' => get_session_id()), '', 1);
     global $SESSION_CACHE;
     if ($SESSION_CACHE[get_session_id()]['the_user'] == get_member()) {
         $SESSION_CACHE[get_session_id()]['session_invisible'] = $visible ? 1 : 0;
         if (get_value('session_prudence') !== '1') {
             persistant_cache_set('SESSION_CACHE', $SESSION_CACHE);
         }
     }
     decache('side_users_online');
     // Store in cookie, if we have login cookies around
     if (array_key_exists(get_member_cookie(), $_COOKIE)) {
         require_code('users_active_actions');
         ocp_setcookie(get_member_cookie() . '_invisible', strval($visible ? 1 : 0));
         $_COOKIE[get_member_cookie() . '_invisible'] = strval($visible ? 1 : 0);
     }
     $url = get_param('redirect', NULL);
     if (is_null($url)) {
         $_url = build_url(array('page' => ''), '');
         $url = $_url->evaluate();
     }
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
예제 #23
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     if (!array_key_exists('param', $map)) {
         $map['param'] = 'main';
     }
     if (!array_key_exists('page', $map)) {
         $map['page'] = str_replace('-', '_', get_page_name());
     }
     if (array_key_exists('extra_param_from', $map)) {
         $extra = '_' . $map['extra_param_from'];
     } else {
         $extra = '';
     }
     require_code('feedback');
     $submitted = post_param_integer('_comment_form_post', 0) == 1;
     $self_url = build_url(array('page' => '_SELF'), '_SELF', NULL, true, false, true);
     $self_title = $map['page'];
     $test_changed = post_param('title', NULL);
     if (!is_null($test_changed)) {
         decache('main_comments');
     }
     $hidden = $submitted ? actualise_post_comment(true, 'block_main_comments', $map['page'] . '_' . $map['param'] . $extra, $self_url, $self_title, array_key_exists('forum', $map) ? $map['forum'] : NULL, false, NULL, get_page_name() == 'guestbook') : false;
     $out = new ocp_tempcode();
     if (array_key_exists('title', $_POST) && $hidden && $submitted) {
         $out->attach(paragraph(do_lang_tempcode('MESSAGE_POSTED'), 'dsgdgdfl;gkd09'));
         if (get_forum_type() == 'ocf') {
             if (addon_installed('unvalidated')) {
                 require_code('submit');
                 $validate_url = get_self_url(true, false, array('keep_session' => NULL));
                 $_validate_url = build_url(array('page' => 'topics', 'type' => 'validate_post', 'id' => $GLOBALS['LAST_POST_ID'], 'redirect' => $validate_url), get_module_zone('topics'), NULL, false, false, true);
                 $validate_url = $_validate_url->evaluate();
                 send_validation_request('MAKE_POST', 'f_posts', false, $GLOBALS['LAST_POST_ID'], $validate_url);
             }
         }
     }
     $invisible_if_no_comments = array_key_exists('invisible_if_no_comments', $map) && $map['invisible_if_no_comments'] == '1';
     $reverse = array_key_exists('reverse', $map) && $map['reverse'] == '1';
     $allow_reviews = !array_key_exists('reviews', $map) || $map['reviews'] == '1';
     $out->attach(get_comments('block_main_comments', true, $map['page'] . '_' . $map['param'] . $extra, $invisible_if_no_comments, array_key_exists('forum', $map) ? $map['forum'] : NULL, NULL, NULL, get_page_name() == 'guestbook', $reverse, NULL, $allow_reviews));
     return $out;
 }
예제 #24
0
/**
 * Decache cached OCF elements depending on a certain forum, and optionally a certain member.
 *
 * @param  AUTO_LINK The ID of the forum.
 * @param  ?string	The name of the forum (NULL: find it from the DB).
 * @param  ?MEMBER	The member (NULL: do no member decacheing).
 */
function ocf_decache_ocp_blocks($updated_forum_id, $forum_name = NULL, $member = NULL)
{
    if (is_null($forum_name)) {
        $forum_name = $GLOBALS['FORUM_DB']->query_value('f_forums', 'f_name', array('id' => $updated_forum_id));
    }
    decache('main_forum_news');
    decache('main_forum_topics');
    decache('side_forum_news');
    decache('bottom_news', array($forum_name));
    if (!is_null($member)) {
        decache('side_ocf_personal_topics', array($member));
        decache('_new_pp', array($member));
    }
}
예제 #25
0
 /**
  * Render posts.
  *
  * @param  integer		Maximum to load if non-threaded
  * @param  array			Tree structure of posts
  * @param  boolean		Whether the current user may reply to the topic (influences what buttons show)
  * @param  ?AUTO_LINK	Only show posts under here (NULL: show posts from root)
  * @param  array			Review ratings rows
  * @param  AUTO_LINK		ID of forum this topic in in
  * @return tempcode		Rendered tree structure
  */
 function _render_post_tree($num_to_show_limit, $tree, $may_reply, $highlight_by_user, $all_individual_review_ratings, $forum_id)
 {
     list($rendered, ) = $tree;
     $sequence = new ocp_tempcode();
     foreach ($rendered as $post) {
         if (get_forum_type() == 'ocf') {
             require_code('ocf_topicview');
             require_code('ocf_posts');
             $post += ocf_get_details_to_show_post($post);
         }
         // Misc details
         $datetime_raw = $post['date'];
         $datetime = get_timezoned_date($post['date']);
         $poster_url = is_guest($post['user']) ? new ocp_tempcode() : $GLOBALS['FORUM_DRIVER']->member_profile_url($post['user'], false, true);
         $poster_name = array_key_exists('username', $post) ? $post['username'] : $GLOBALS['FORUM_DRIVER']->get_username($post['user']);
         if (is_null($poster_name)) {
             $poster_name = do_lang('UNKNOWN');
         }
         $highlight = $highlight_by_user === $post['user'];
         // Find review, if there is one
         $individual_review_ratings = array();
         foreach ($all_individual_review_ratings as $potential_individual_review_rating) {
             if ($potential_individual_review_rating['r_post_id'] == $post['id']) {
                 $individual_review_ratings[$potential_individual_review_rating['r_rating_type']] = array('REVIEW_TITLE' => $potential_individual_review_rating['r_rating_type'], 'REVIEW_RATING' => float_to_raw_string($potential_individual_review_rating['r_rating']));
             }
         }
         // Edit URL
         $emphasis = new ocp_tempcode();
         $buttons = new ocp_tempcode();
         $last_edited = new ocp_tempcode();
         $last_edited_raw = '';
         $unvalidated = new ocp_tempcode();
         $poster = mixed();
         $poster_details = new ocp_tempcode();
         $is_spacer_post = false;
         if (get_forum_type() == 'ocf') {
             // Spacer post fiddling
             if (!is_null($this->first_post_id) && !is_null($this->topic_title) && !is_null($this->topic_description) && !is_null($this->topic_description_link)) {
                 $is_spacer_post = $post['id'] == $this->first_post_id && substr($post['message_comcode'], 0, strlen('[semihtml]' . do_lang('SPACER_POST_MATCHER'))) == '[semihtml]' . do_lang('SPACER_POST_MATCHER');
                 if ($is_spacer_post) {
                     $c_prefix = do_lang('COMMENT') . ': #';
                     if (substr($this->topic_description, 0, strlen($c_prefix)) == $c_prefix && $this->topic_description_link != '') {
                         list($linked_type, $linked_id) = explode('_', substr($this->topic_description, strlen($c_prefix)), 2);
                         $linked_url = $this->topic_description_link;
                         require_code('ocf_posts');
                         list($new_description, $new_post) = ocf_display_spacer_post($linked_type, $linked_id);
                         //if (!is_null($new_description)) $this->topic_description=$new_description;	Actually, it's a bit redundant
                         if (!is_null($new_post)) {
                             $post['message'] = $new_post;
                         }
                         $highlight = false;
                         $this->topic_title = do_lang('SPACER_TOPIC_TITLE_WRAP', $this->topic_title);
                         $post['title'] = do_lang('SPACER_TOPIC_TITLE_WRAP', $post['title']);
                         $this->topic_description = '';
                     }
                 }
             }
             // Misc meta details for post
             $emphasis = ocf_get_post_emphasis($post);
             $unvalidated = $post['validated'] == 0 ? do_lang_tempcode('UNVALIDATED') : new ocp_tempcode();
             if (array_key_exists('last_edit_time', $post)) {
                 $last_edited = do_template('OCF_TOPIC_POST_LAST_EDITED', array('LAST_EDIT_DATE_RAW' => is_null($post['last_edit_time']) ? '' : strval($post['last_edit_time']), 'LAST_EDIT_DATE' => $post['last_edit_time_string'], 'LAST_EDIT_PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($post['last_edit_by'], false, true), 'LAST_EDIT_USERNAME' => $post['last_edit_by_username']));
                 $last_edited_raw = is_null($post['last_edit_time']) ? '' : strval($post['last_edit_time']);
             }
             // Post buttons
             if (!$is_spacer_post) {
                 if (!is_null($this->topic_id)) {
                     if (is_null($this->topic_info)) {
                         $this->topic_info = ocf_read_in_topic($this->topic_id, 0, 0, false, false);
                     }
                     require_lang('ocf');
                     $buttons = ocf_render_post_buttons($this->topic_info, $post, $may_reply);
                 }
             }
             // OCF renderings of poster
             static $hooks = NULL;
             if (is_null($hooks)) {
                 $hooks = find_all_hooks('modules', 'topicview');
             }
             static $hook_objects = NULL;
             if (is_null($hook_objects)) {
                 $hook_objects = array();
                 foreach (array_keys($hooks) as $hook) {
                     require_code('hooks/modules/topicview/' . filter_naughty_harsh($hook));
                     $object = object_factory('Hook_' . filter_naughty_harsh($hook), true);
                     if (is_null($object)) {
                         continue;
                     }
                     $hook_objects[$hook] = $object;
                 }
             }
             if (!$is_spacer_post) {
                 if (!is_guest($post['poster'])) {
                     require_code('ocf_members2');
                     $poster_details = ocf_show_member_box($post, false, $hooks, $hook_objects, false);
                 } else {
                     $custom_fields = new ocp_tempcode();
                     if (array_key_exists('ip_address', $post) && addon_installed('ocf_forum')) {
                         $custom_fields->attach(do_template('OCF_TOPIC_POST_CUSTOM_FIELD', array('NAME' => do_lang_tempcode('IP_ADDRESS'), 'VALUE' => $post['ip_address'])));
                         $poster_details = do_template('OCF_GUEST_DETAILS', array('CUSTOM_FIELDS' => $custom_fields));
                     } else {
                         $poster_details = new ocp_tempcode();
                     }
                 }
             }
             if (addon_installed('ocf_forum')) {
                 if (!is_guest($post['poster'])) {
                     $poster = do_template('OCF_POSTER_MEMBER', array('ONLINE' => member_is_online($post['poster']), 'ID' => strval($post['poster']), 'POSTER_DETAILS' => $poster_details, 'PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($post['poster'], false, true), 'POSTER_USERNAME' => $post['poster_username']));
                 } else {
                     $ip_link = array_key_exists('ip_address', $post) && has_actual_page_access(get_member(), 'admin_lookup') ? build_url(array('page' => 'admin_lookup', 'param' => $post['ip_address']), get_module_zone('admin_lookup')) : new ocp_tempcode();
                     $poster = do_template('OCF_POSTER_GUEST', array('IP_LINK' => $ip_link, 'POSTER_DETAILS' => $poster_details, 'POSTER_USERNAME' => $post['poster_username']));
                 }
             } else {
                 $poster = make_string_tempcode(escape_html($post['poster_username']));
             }
         }
         // Child posts
         $children = mixed();
         // NULL
         $other_ids = array();
         if (array_key_exists('children', $post)) {
             foreach ($post['children'][1] as $u) {
                 $other_ids[] = strval($u['id']);
             }
             if ($this->is_threaded) {
                 $children = $this->_render_post_tree($num_to_show_limit, $post['children'], $may_reply, $highlight_by_user, $all_individual_review_ratings, $forum_id);
             }
         }
         if (get_forum_type() == 'ocf') {
             require_code('feedback');
             actualise_rating(true, 'post', strval($post['id']), get_self_url(), $post['title']);
             $rating = display_rating(get_self_url(), $post['title'], 'post', strval($post['id']), 'RATING_INLINE_DYNAMIC', $post['user']);
         } else {
             $rating = new ocp_tempcode();
         }
         if (array_key_exists('intended_solely_for', $post)) {
             decache('side_ocf_personal_topics', array(get_member()));
             decache('_new_pp', array(get_member()));
         }
         // Render
         $sequence->attach(static_evaluate_tempcode(do_template('POST', array('_GUID' => 'eb7df038959885414e32f58e9f0f9f39', 'INDIVIDUAL_REVIEW_RATINGS' => $individual_review_ratings, 'HIGHLIGHT' => $highlight, 'TITLE' => $post['title'], 'TIME_RAW' => strval($datetime_raw), 'TIME' => $datetime, 'POSTER_ID' => strval($post['user']), 'POSTER_URL' => $poster_url, 'POSTER_NAME' => $poster_name, 'POSTER' => $poster, 'POSTER_DETAILS' => $poster_details, 'ID' => strval($post['id']), 'POST' => $post['message'], 'POST_COMCODE' => isset($post['message_comcode']) ? $post['message_comcode'] : NULL, 'CHILDREN' => $children, 'OTHER_IDS' => count($other_ids) == 0 ? NULL : $other_ids, 'RATING' => $rating, 'EMPHASIS' => $emphasis, 'BUTTONS' => $buttons, 'LAST_EDITED_RAW' => $last_edited_raw, 'LAST_EDITED' => $last_edited, 'TOPIC_ID' => is_null($this->topic_id) ? '' : strval($this->topic_id), 'UNVALIDATED' => $unvalidated, 'IS_SPACER_POST' => $is_spacer_post, 'NUM_TO_SHOW_LIMIT' => strval($num_to_show_limit)))));
     }
     return $sequence;
 }
예제 #26
0
/**
 * Delete a download.
 *
 * @param  AUTO_LINK		The ID of the download to delete
 * @param  boolean		Whether to leave the actual file behind
 */
function delete_download($id, $leave = false)
{
    $myrows = $GLOBALS['SITE_DB']->query_select('download_downloads', array('name', 'description', 'comments'), array('id' => $id), '', 1);
    if (!array_key_exists(0, $myrows)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $myrow = $myrows[0];
    log_it('DELETE_DOWNLOAD', strval($id), get_translated_text($myrow['name']));
    delete_lang($myrow['name']);
    delete_lang($myrow['description']);
    delete_lang($myrow['comments']);
    require_code('seo2');
    seo_meta_erase_storage('downloads_download', strval($id));
    if (!$leave) {
        require_code('files2');
        delete_upload('uploads/downloads', 'download_downloads', 'url', 'id', $id);
    }
    // Delete from database
    $GLOBALS['SITE_DB']->query_delete('download_downloads', array('id' => $id), '', 1);
    $GLOBALS['SITE_DB']->query_delete('download_logging', array('id' => $id));
    $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => 'downloads', 'rating_for_id' => $id));
    $GLOBALS['SITE_DB']->query_delete('trackbacks', array('trackback_for_type' => 'downloads', 'trackback_for_id' => $id));
    $GLOBALS['SITE_DB']->query_update('download_downloads', array('out_mode_id' => NULL), array('out_mode_id' => $id), '', 1);
    if (addon_installed('galleries')) {
        // Delete gallery
        $name = 'download_' . strval($id);
        require_code('galleries2');
        $test = $GLOBALS['SITE_DB']->query_value_null_ok('galleries', 'parent_id', array('name' => 'download_' . strval($id)));
        if (!is_null($test)) {
            delete_gallery($name);
        }
    }
    decache('main_recent_downloads');
    decache('main_top_downloads');
    decache('main_download_category');
    decache('main_download_tease');
}
예제 #27
0
/**
 * Move some topics.
 *
 * @param  AUTO_LINK		The forum the topics are currently in.
 * @param  AUTO_LINK		The forum the topics are being moved to.
 * @param  ?array 		A list of the topic IDs to move (NULL: move all topics from source forum).
 */
function ocf_move_topics($from, $to, $topics = NULL)
{
    if ($from == $to) {
        return;
    }
    // That would be nuts, and interfere with our logic
    require_code('notifications');
    require_code('ocf_topics');
    require_code('ocf_forums_action2');
    $forum_name = ocf_ensure_forum_exists($to);
    if (!ocf_may_moderate_forum($from)) {
        access_denied('I_ERROR');
    }
    $topic_count = 0;
    if (is_null($topics)) {
        if (is_null($from)) {
            access_denied('I_ERROR');
        }
        $all_topics = $GLOBALS['FORUM_DB']->query_select('f_topics', array('id', 't_cache_num_posts', 't_validated'), array('t_forum_id' => $from));
        $or_list = '';
        $post_count = 0;
        $topics = array();
        foreach ($all_topics as $topic_info) {
            $topics[] = $topic_info['id'];
            if ($or_list != '') {
                $or_list .= ' OR ';
            }
            $or_list .= 'id=' . strval((int) $topic_info['id']);
            $post_count += $topic_info['t_cache_num_posts'];
            if ($topic_info['t_validated'] == 1) {
                $topic_count++;
            }
        }
        $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_forum_id' => $to), array('t_forum_id' => $from));
        // Update forum IDs' for posts
        $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_cache_forum_id' => $to), array('p_cache_forum_id' => $from));
        $or_list_2 = str_replace('id', 'p_topic_id', $or_list);
        if ($or_list_2 == '') {
            return;
        }
    } elseif (count($topics) == 1) {
        $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id', 't_pt_from', 't_pt_to', 't_cache_first_title', 't_cache_num_posts', 't_validated'), array('id' => $topics[0]));
        if (!array_key_exists(0, $topic_info)) {
            warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
        }
        if ($topic_info[0]['t_forum_id'] != $from || $topic_info[0]['t_pt_from'] != get_member() && $topic_info[0]['t_pt_to'] != get_member() && !ocf_has_special_pt_access($topics[0]) && !has_specific_permission(get_member(), 'view_other_pt') && is_null($topic_info[0]['t_forum_id'])) {
            access_denied('I_ERROR');
        }
        if ($topic_info[0]['t_validated'] == 1) {
            $topic_count++;
        }
        $topic_title = $topic_info[0]['t_cache_first_title'];
        $post_count = $topic_info[0]['t_cache_num_posts'];
        $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_pt_from' => NULL, 't_pt_to' => NULL, 't_forum_id' => $to), array('t_forum_id' => $from, 'id' => $topics[0]), '', 1);
        // Extra where constraint for added security
        log_it('MOVE_TOPICS', $topic_title, strval($topics[0]));
        $or_list = 'id=' . strval($topics[0]);
        $or_list_2 = 'p_topic_id=' . strval($topics[0]);
        // Update forum IDs' for posts
        $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_cache_forum_id' => $to), array('p_topic_id' => $topics[0]));
    } else {
        if (count($topics) == 0) {
            return;
        }
        // Nuts, lol
        $or_list = '';
        foreach ($topics as $topic_id) {
            if ($or_list != '') {
                $or_list .= ' OR ';
            }
            $or_list .= 'id=' . strval((int) $topic_id);
            if (is_null($from)) {
                $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id', 't_pt_from', 't_pt_to'), array('id' => $topic_id));
                if (array_key_exists(0, $topic_info)) {
                    if ($topic_info[0]['t_validated'] == 1) {
                        $topic_count++;
                    }
                    if ($topic_info[0]['t_forum_id'] != $from || $topic_info[0]['t_pt_from'] != get_member() && $topic_info[0]['t_pt_to'] != get_member() && !ocf_has_special_pt_access($topic_id) && !has_specific_permission(get_member(), 'view_other_pt')) {
                        access_denied('I_ERROR');
                    }
                }
            } else {
                $topic_count++;
                // Might not be validated, which means technically we shouldn't do this, but it's low chance, low impact, and the indicator is only a cache thing anyway
            }
        }
        $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics SET t_forum_id=' . strval((int) $to) . ',t_pt_from=NULL,t_pt_to=NULL WHERE t_forum_id' . (is_null($from) ? ' IS NULL' : '=' . strval((int) $from)) . ' AND (' . $or_list . ')');
        log_it('MOVE_TOPICS', do_lang('MULTIPLE'));
        $post_count = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(t_cache_num_posts) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE ' . $or_list);
        // Update forum IDs' for posts
        $or_list_2 = str_replace('id', 'p_topic_id', $or_list);
        $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts SET p_cache_forum_id=' . strval((int) $to) . ' WHERE ' . $or_list_2);
    }
    require_code('ocf_posts_action2');
    // Update source forum cache view
    if (!is_null($from)) {
        ocf_force_update_forum_cacheing($from, -$topic_count, -$post_count);
    }
    // Update dest forum cache view
    ocf_force_update_forum_cacheing($to, $topic_count, $post_count);
    if (!is_null($from)) {
        // Update member post counts if we've switched between post-count countable forums
        $post_count_info = $GLOBALS['FORUM_DB']->query('SELECT id,f_post_count_increment FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE id=' . strval((int) $from) . ' OR id=' . strval((int) $to), 2);
        if ($post_count_info[0]['id'] == $from) {
            $from_cnt = $post_count_info[0]['f_post_count_increment'];
            $to_cnt = $post_count_info[1]['f_post_count_increment'];
        } else {
            $from_cnt = $post_count_info[1]['f_post_count_increment'];
            $to_cnt = $post_count_info[0]['f_post_count_increment'];
        }
        require_code('ocf_posts_action');
        if ($from_cnt != $to_cnt) {
            $sql = 'SELECT p_poster FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE (' . $or_list_2 . ')';
            if (addon_installed('unvalidated')) {
                $sql .= ' AND p_validated=1';
            }
            $_member_post_counts = collapse_1d_complexity('p_poster', $GLOBALS['FORUM_DB']->query($sql));
            $member_post_counts = array_count_values($_member_post_counts);
            foreach ($member_post_counts as $member_id => $member_post_count) {
                if ($to == 0) {
                    $member_post_count = -$member_post_count;
                }
                ocf_force_update_member_post_count($member_id, $member_post_count);
            }
        }
    }
    require_code('ocf_posts_action');
    if (!is_null($from)) {
        ocf_decache_ocp_blocks($from);
    } else {
        decache('side_ocf_personal_topics');
        decache('_new_pp');
    }
    ocf_decache_ocp_blocks($to, $forum_name);
    if (function_exists('set_time_limit')) {
        @set_time_limit(0);
    }
    $start = 0;
    do {
        $topics2 = $GLOBALS['FORUM_DB']->query('SELECT id,t_cache_first_title,t_cache_last_time FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE ' . $or_list, 100, $start);
        require_code('urls2');
        foreach ($topics2 as $_topic) {
            if ($_topic['t_cache_last_time'] < time() - 60 * 60 * 24 * 14) {
                continue;
            }
            $topic_id = $_topic['id'];
            $topic_title = $_topic['t_cache_first_title'];
            suggest_new_idmoniker_for('topicview', 'misc', strval($topic_id), $topic_title);
            // Now lets inform people tracking the topic that it has moved
            $subject = do_lang('TOPIC_MOVE_MAIL_SUBJECT', get_site_name(), $topic_title);
            $mail = do_lang('TOPIC_MOVE_MAIL', comcode_escape(get_site_name()), comcode_escape($topic_title), array(comcode_escape($forum_name)));
            dispatch_notification('ocf_topic', strval($topic_id), $subject, $mail);
        }
    } while (count($topics2) == 100);
}
예제 #28
0
 /**
  * Standard modular run function.
  *
  * @return tempcode	The result of execution.
  */
 function run()
 {
     if (get_forum_type() != 'ocf') {
         warn_exit(do_lang_tempcode('NO_OCF'));
     } else {
         ocf_require_all_forum_stuff();
     }
     require_code('ocf_topicview');
     require_css('ocf');
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'max';
     $NON_CANONICAL_PARAMS[] = 'start';
     $NON_CANONICAL_PARAMS[] = 'threaded';
     $start = get_param_integer('start', 0);
     $default_max = intval(get_option('forum_posts_per_page'));
     $max = get_param_integer('max', $default_max);
     if ($max == 0) {
         $max = $default_max;
     }
     if ($max == 0) {
         $max = 1;
     }
     if ($max > 30 && !has_specific_permission(get_member(), 'remove_page_split')) {
         $max = $default_max;
     }
     $first_unread_id = -1;
     global $NON_CANONICAL_PARAMS;
     foreach (array_keys($_GET) as $key) {
         if (substr($key, 0, 3) == 'kfs') {
             $NON_CANONICAL_PARAMS[] = $key;
         }
     }
     $type = get_param('type', 'misc');
     $id = get_param_integer('id', NULL);
     if (is_guest() && is_null($id)) {
         access_denied('NOT_AS_GUEST');
     }
     if ($type == 'findpost') {
         $post_id = get_param_integer('id');
         $redirect = find_post_id_url($post_id);
         require_code('site2');
         assign_refresh($redirect, 0.0);
         return do_template('REDIRECT_SCREEN', array('_GUID' => '76e6d34c20a4f5284119827e41c7752f', 'URL' => $redirect, 'TITLE' => get_page_title('VIEW_TOPIC'), 'TEXT' => do_lang_tempcode('REDIRECTING')));
     } else {
         if ($type == 'first_unread') {
             $redirect = find_first_unread_url($id);
             require_code('site2');
             assign_refresh($redirect, 0.0);
             return do_template('REDIRECT_SCREEN', array('_GUID' => '12c5d16f60e8c4df03536d9a7a932528', 'URL' => $redirect, 'TITLE' => get_page_title('VIEW_TOPIC'), 'TEXT' => do_lang_tempcode('REDIRECTING')));
         }
     }
     if (!is_null($id)) {
         $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=ocf_topicview&filter=' . strval($id);
     }
     $view_poll_results = get_param_integer('view_poll_results', 0);
     // Mark as read
     if (!is_null($id)) {
         if (!is_guest()) {
             $GLOBALS['FORUM_DB']->query_delete('f_read_logs', array('l_member_id' => get_member(), 'l_topic_id' => $id), '', 1);
             $GLOBALS['FORUM_DB']->query_insert('f_read_logs', array('l_member_id' => get_member(), 'l_topic_id' => $id, 'l_time' => time()), false, true);
             // race condition
         }
         $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics SET t_num_views=(t_num_views+1) WHERE id=' . strval((int) $id), 1, NULL, true);
     }
     // Load up topic info
     $topic_info = ocf_read_in_topic($id, $start, $max, $view_poll_results == 1);
     $GLOBALS['META_DATA'] += $topic_info['meta_data'];
     global $SEO_TITLE;
     $SEO_TITLE = do_lang('_VIEW_TOPIC', $topic_info['title']);
     // Render posts according to whether threaded or not
     $threaded = $topic_info['is_threaded'] == 1;
     $may_reply = array_key_exists('may_reply', $topic_info) && ($topic_info['is_open'] || array_key_exists('may_post_closed', $topic_info));
     if (!$threaded) {
         $GLOBALS['META_DATA']['description'] = $topic_info['description'];
         // Poster detail hooks
         $hooks = find_all_hooks('modules', 'topicview');
         $hook_objects = array();
         foreach (array_keys($hooks) as $hook) {
             require_code('hooks/modules/topicview/' . filter_naughty_harsh($hook));
             $object = object_factory('Hook_' . filter_naughty_harsh($hook), true);
             if (is_null($object)) {
                 continue;
             }
             $hook_objects[$hook] = $object;
         }
         // Render non-threaded
         $posts = new ocp_tempcode();
         $replied = false;
         if (is_null($topic_info['forum_id'])) {
             decache('side_ocf_personal_topics', array(get_member()));
             decache('_new_pp', array(get_member()));
         }
         $second_poster = $topic_info['first_poster'];
         foreach ($topic_info['posts'] as $array_id => $_postdetails) {
             if ($array_id == 0) {
                 $description = $topic_info['description'];
             } else {
                 $description = NULL;
             }
             if ($_postdetails['poster'] == get_member()) {
                 $replied = true;
             }
             if ($array_id == 1 && $start == 0 || $array_id == 0 && $start != 0) {
                 $second_poster = $_postdetails['poster'];
             }
             if (array_key_exists('last_edit_time', $_postdetails)) {
                 $last_edited = do_template('OCF_TOPIC_POST_LAST_EDITED', array('_GUID' => '77a28e8bc3cf2ec2211aafdb5ba192bf', 'LAST_EDIT_DATE_RAW' => is_null($_postdetails['last_edit_time']) ? '' : strval($_postdetails['last_edit_time']), 'LAST_EDIT_DATE' => $_postdetails['last_edit_time_string'], 'LAST_EDIT_PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($_postdetails['last_edit_by'], false, true), 'LAST_EDIT_USERNAME' => $_postdetails['last_edit_by_username']));
             } else {
                 $last_edited = new ocp_tempcode();
             }
             $last_edited_raw = array_key_exists('last_edit_time', $_postdetails) ? is_null($_postdetails['last_edit_time']) ? '' : strval($_postdetails['last_edit_time']) : '0';
             $is_spacer_post = $_postdetails['is_spacer_post'];
             // Post buttons
             $buttons = new ocp_tempcode();
             if (!$is_spacer_post) {
                 $buttons = ocf_render_post_buttons($topic_info, $_postdetails, $may_reply);
             }
             // Avatar
             if (array_key_exists('poster_avatar', $_postdetails) && $_postdetails['poster_avatar'] != '') {
                 $post_avatar = do_template('OCF_TOPIC_POST_AVATAR', array('_GUID' => 'd647ada9c11d56eedc0ff7894d33e83c', 'AVATAR' => $_postdetails['poster_avatar']));
             } else {
                 $post_avatar = new ocp_tempcode();
             }
             // Rank images
             $rank_images = new ocp_tempcode();
             if (!$is_spacer_post) {
                 $posters_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($_postdetails['poster'], true);
                 foreach ($posters_groups as $group) {
                     $rank_image = ocf_get_group_property($group, 'rank_image');
                     $group_leader = ocf_get_group_property($group, 'group_leader');
                     $group_name = ocf_get_group_name($group);
                     $rank_image_pri_only = ocf_get_group_property($group, 'rank_image_pri_only');
                     if ($rank_image != '' && ($rank_image_pri_only == 0 || $group == $GLOBALS['FORUM_DRIVER']->get_member_row_field($_postdetails['poster'], 'm_primary_group'))) {
                         $rank_images->attach(do_template('OCF_RANK_IMAGE', array('_GUID' => '0ff7855482b901be95591964d4212c44', 'GROUP_NAME' => $group_name, 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($_postdetails['poster']), 'IMG' => $rank_image, 'IS_LEADER' => $group_leader == $_postdetails['poster'])));
                     }
                 }
             }
             // Poster details
             if (!$is_spacer_post) {
                 if (!is_guest($_postdetails['poster'])) {
                     require_code('ocf_members2');
                     $poster_details = ocf_show_member_box($_postdetails, false, $hooks, $hook_objects, false);
                 } else {
                     $custom_fields = new ocp_tempcode();
                     if (array_key_exists('ip_address', $_postdetails)) {
                         $custom_fields->attach(do_template('OCF_TOPIC_POST_CUSTOM_FIELD', array('_GUID' => 'd85be094dff0d039a64120d6f8f381bb', 'NAME' => do_lang_tempcode('IP_ADDRESS'), 'VALUE' => $_postdetails['ip_address'])));
                         $poster_details = do_template('OCF_GUEST_DETAILS', array('_GUID' => 'e43534acaf598008602e8da8f9725f38', 'CUSTOM_FIELDS' => $custom_fields));
                     } else {
                         $poster_details = new ocp_tempcode();
                     }
                 }
             } else {
                 $poster_details = new ocp_tempcode();
             }
             if (!is_guest($_postdetails['poster'])) {
                 $poster = do_template('OCF_POSTER_MEMBER', array('_GUID' => 'dbbed1850b6c01a6c9601d85c6aee43f', 'ONLINE' => member_is_online($_postdetails['poster']), 'ID' => strval($_postdetails['poster']), 'POSTER_DETAILS' => $poster_details, 'PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($_postdetails['poster'], false, true), 'POSTER_USERNAME' => $_postdetails['poster_username'], 'HIGHLIGHT_NAME' => array_key_exists('poster_highlighted_name', $_postdetails) ? strval($_postdetails['poster_highlighted_name']) : NULL));
             } else {
                 $ip_link = array_key_exists('ip_address', $_postdetails) && has_actual_page_access(get_member(), 'admin_lookup') ? build_url(array('page' => 'admin_lookup', 'param' => $_postdetails['ip_address']), get_module_zone('admin_lookup')) : new ocp_tempcode();
                 $poster = do_template('OCF_POSTER_GUEST', array('_GUID' => '36a8e550222cdac5165ef8f722be3def', 'IP_LINK' => $ip_link, 'POSTER_DETAILS' => $poster_details, 'POSTER_USERNAME' => $_postdetails['poster_username']));
             }
             // Signature
             $signature = new ocp_tempcode();
             if (array_key_exists('signature', $_postdetails) && !$_postdetails['signature']->is_empty()) {
                 $signature = $_postdetails['signature'];
             }
             $post_title = $_postdetails['title'];
             $first_unread = $_postdetails['id'] == $first_unread_id || $first_unread_id < 0 && $array_id == count($topic_info['posts']) - 1 ? do_template('OCF_TOPIC_FIRST_UNREAD') : new ocp_tempcode();
             $unvalidated = $_postdetails['validated'] == 0 ? do_lang_tempcode('UNVALIDATED') : new ocp_tempcode();
             $post_url = $GLOBALS['FORUM_DRIVER']->post_url($_postdetails['id'], is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']), true);
             if (array_key_exists('intended_solely_for', $_postdetails) && $_postdetails['intended_solely_for'] == get_member()) {
                 decache('side_ocf_personal_topics', array(get_member()));
                 decache('_new_pp', array(get_member()));
             }
             $emphasis = ocf_get_post_emphasis($_postdetails);
             require_code('feedback');
             if (!array_key_exists('intended_solely_for', $_postdetails)) {
                 actualise_rating(true, 'post', strval($_postdetails['id']), get_self_url(), $_postdetails['title']);
                 $rating = display_rating(get_self_url(), $_postdetails['title'], 'post', strval($_postdetails['id']), 'RATING_INLINE_DYNAMIC', $_postdetails['poster']);
             } else {
                 $rating = new ocp_tempcode();
             }
             $rendered_post = do_template('OCF_TOPIC_POST', array('_GUID' => 'sacd09wekfofpw2f', 'ID' => $is_spacer_post ? '' : strval($_postdetails['id']), 'TOPIC_FIRST_POST_ID' => is_null($topic_info['first_post_id']) ? '' : strval($topic_info['first_post_id']), 'TOPIC_FIRST_POSTER' => is_null($topic_info['first_poster']) ? '' : strval($topic_info['first_poster']), 'POST_ID' => $is_spacer_post ? '' : (get_value('seq_post_ids') === '1' ? strval($start + $array_id + 1) : strval($_postdetails['id'])), 'URL' => $post_url, 'CLASS' => $_postdetails['is_emphasised'] ? 'ocf_post_emphasis' : (array_key_exists('intended_solely_for', $_postdetails) ? 'ocf_post_personal' : ''), 'EMPHASIS' => $emphasis, 'FIRST_UNREAD' => $first_unread, 'POSTER_TITLE' => $is_spacer_post ? '' : $_postdetails['poster_title'], 'POST_TITLE' => $post_title, 'POST_DATE_RAW' => strval($_postdetails['time']), 'POST_DATE' => $_postdetails['time_string'], 'POST' => $_postdetails['post'], 'TOPIC_ID' => is_null($id) ? '' : strval($id), 'LAST_EDITED_RAW' => $last_edited_raw, 'LAST_EDITED' => $last_edited, 'POSTER_ID' => strval($_postdetails['poster']), 'POSTER' => $is_spacer_post ? '' : $poster, 'POSTER_DETAILS' => $poster_details, 'POST_AVATAR' => $post_avatar, 'RANK_IMAGES' => $rank_images, 'BUTTONS' => $buttons, 'SIGNATURE' => $signature, 'UNVALIDATED' => $unvalidated, 'DESCRIPTION' => $description, 'RATING' => $rating));
             $posts->attach($rendered_post);
         }
         $serialized_options = mixed();
         $hash = mixed();
     } else {
         require_code('topics');
         $threaded_topic_ob = new OCP_Topic();
         // Load some settings into the renderer
         $threaded_topic_ob->first_post_id = $topic_info['first_post_id'];
         $threaded_topic_ob->topic_description = $topic_info['description'];
         $threaded_topic_ob->topic_description_link = $topic_info['description_link'];
         $threaded_topic_ob->topic_title = $topic_info['title'];
         $threaded_topic_ob->topic_info = $topic_info;
         // Other settings we need
         $max_thread_depth = intval(get_option('max_thread_depth'));
         $num_to_show_limit = get_param_integer('max_comments', intval(get_option('comments_to_show_in_thread')));
         // Load posts
         $threaded_topic_ob->load_from_topic($id, $num_to_show_limit, $start, false, NULL, true);
         $threaded_topic_ob->is_threaded = true;
         // Render posts
         list($posts, $serialized_options, $hash) = $threaded_topic_ob->render_posts($num_to_show_limit, $max_thread_depth, $may_reply, $topic_info['first_poster'], array(), $topic_info['forum_id'], NULL, false);
         $GLOBALS['META_DATA']['description'] = $threaded_topic_ob->topic_description;
         // Get other gathered details
         $replied = $threaded_topic_ob->replied;
         if (!is_null($threaded_topic_ob->topic_title)) {
             // Updated topic title
             $topic_info['title'] = $threaded_topic_ob->topic_title;
         }
         $topic_info['max_rows'] = $threaded_topic_ob->total_posts;
         $second_poster = $GLOBALS['FORUM_DRIVER']->get_guest_id();
         // No definitive post orders
     }
     // Buttons for topic as whole
     $button_array = array();
     if (!is_null($id)) {
         if (get_value('no_threaded_buttons') !== '1') {
             if ($threaded) {
                 $view_as_linear_url = get_self_url(false, false, array('threaded' => 0));
                 $button_array[] = array('immediate' => true, 'title' => do_lang_tempcode('VIEW_AS_LINEAR'), 'url' => $view_as_linear_url, 'img' => 'linear');
             } else {
                 $view_as_threaded_url = get_self_url(false, false, array('threaded' => 1));
                 $button_array[] = array('immediate' => true, 'title' => do_lang_tempcode('VIEW_AS_THREADED'), 'url' => $view_as_threaded_url, 'img' => 'threaded');
             }
         }
         if (!is_guest()) {
             $too_old = $topic_info['last_time'] < time() - 60 * 60 * 24 * intval(get_option('post_history_days'));
             if (get_value('disable_mark_topic_unread') !== '1' && !$too_old) {
                 $map = array('page' => 'topics', 'type' => 'mark_unread_topic', 'id' => $id);
                 $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
                 if ($test != -1 && $test != 0) {
                     $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
                 }
                 $test = get_param_integer('threaded', -1);
                 if ($test != -1) {
                     $map['threaded'] = $test;
                 }
                 $mark_unread_url = build_url($map, get_module_zone('topics'));
                 $button_array[] = array('immediate' => true, 'title' => do_lang_tempcode('MARK_UNREAD'), 'url' => $mark_unread_url, 'img' => 'mark_unread');
             }
         }
         if ($may_reply && is_null(get_bot_type())) {
             $reply_prevented = false;
             // "Staff-only" reply for support tickets
             if ($GLOBALS['FORUM_DRIVER']->is_staff(get_member()) && addon_installed('tickets')) {
                 require_code('tickets');
                 if (is_ticket_forum($topic_info['forum_id'])) {
                     if (is_guest($second_poster)) {
                         $reply_prevented = true;
                     }
                     require_lang('tickets');
                     $map = array('page' => 'topics', 'type' => 'new_post', 'id' => $id, 'intended_solely_for' => $GLOBALS['FORUM_DRIVER']->get_guest_id());
                     $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
                     if ($test != -1 && $test != 0) {
                         $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
                     }
                     $test = get_param_integer('threaded', -1);
                     if ($test != -1) {
                         $map['threaded'] = $test;
                     }
                     $new_post_url = build_url($map, get_module_zone('topics'));
                     $button_array[] = array('immediate' => false, 'rel' => 'add', 'title' => do_lang_tempcode('TICKET_STAFF_ONLY_REPLY'), 'url' => $new_post_url, 'img' => 'staff_only_reply');
                 }
             }
             if (!$reply_prevented) {
                 if ($topic_info['is_threaded'] == 0) {
                     $map = array('page' => 'topics', 'type' => 'new_post', 'id' => $id);
                     $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
                     if ($test != -1 && $test != 0) {
                         $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
                     }
                     $test = get_param_integer('threaded', -1);
                     if ($test != -1) {
                         $map['threaded'] = $test;
                     }
                     $new_post_url = build_url($map, get_module_zone('topics'));
                     $button_array[] = array('immediate' => false, 'rel' => 'add', 'title' => do_lang_tempcode($topic_info['is_open'] ? 'REPLY' : 'CLOSED'), 'url' => $new_post_url, 'img' => $topic_info['is_open'] ? 'reply' : 'closed');
                 }
             } else {
                 unset($topic_info['may_use_quick_reply']);
             }
         } elseif ((is_null($topic_info['forum_id']) || has_specific_permission(get_member(), 'submit_lowrange_content', 'topics', array('forums', $topic_info['forum_id']))) && $topic_info['last_poster'] == get_member() && !is_guest() && ocf_may_edit_post_by(get_member(), $topic_info['forum_id'])) {
             $map = array('page' => 'topics', 'type' => 'edit_post', 'id' => $topic_info['last_post_id']);
             $test = get_param_integer('kfs' . strval($topic_info['forum_id']), -1);
             if ($test != -1 && $test != 0) {
                 $map['kfs' . strval($topic_info['forum_id'])] = $test;
             }
             $test = get_param_integer('threaded', -1);
             if ($test != -1) {
                 $map['threaded'] = $test;
             }
             $new_post_url = build_url($map, get_module_zone('topics'));
             $button_array[] = array('immediate' => false, 'rel' => 'edit', 'title' => do_lang_tempcode('LAST_POST'), 'url' => $new_post_url, 'img' => 'amend');
         }
         if (!is_null($topic_info['forum_id'])) {
             if (get_value('disable_add_topic_btn_in_topic') !== '1') {
                 if (ocf_may_post_topic($topic_info['forum_id'], get_member())) {
                     $new_topic_url = build_url(array('page' => 'topics', 'type' => 'new_topic', 'id' => $topic_info['forum_id']), get_module_zone('topics'));
                     $button_array[] = array('immediate' => false, 'rel' => 'add', 'title' => do_lang_tempcode('ADD_TOPIC'), 'url' => $new_topic_url, 'img' => 'new_topic');
                 }
             }
         } else {
             $invite_url = build_url(array('page' => 'topics', 'type' => 'invite_member', 'id' => $id), get_module_zone('topics'));
             $button_array[] = array('immediate' => false, 'title' => do_lang_tempcode('INVITE_MEMBER_TO_PT'), 'url' => $invite_url, 'img' => 'invite_member');
         }
     }
     $buttons = ocf_screen_button_wrap($button_array);
     // Poll
     if (array_key_exists('poll', $topic_info)) {
         $_poll = $topic_info['poll'];
         $voted_already = $_poll['voted_already'];
         $poll_results = array_key_exists(0, $_poll['answers']) && array_key_exists('num_votes', $_poll['answers'][0]);
         $answers = new ocp_tempcode();
         $real_button = false;
         if ($_poll['is_open']) {
             if ($poll_results) {
                 $button = new ocp_tempcode();
             } elseif ($_poll['requires_reply'] && !$replied) {
                 $button = do_lang_tempcode('POLL_REQUIRES_REPLY');
             } else {
                 if (!has_specific_permission(get_member(), 'vote_in_polls') || is_guest()) {
                     $button = do_lang_tempcode('VOTE_DENIED');
                 } else {
                     if (!is_null($voted_already)) {
                         $button = do_lang_tempcode('NOVOTE');
                     } else {
                         require_lang('polls');
                         $map = array('page' => 'topicview', 'id' => $id, 'view_poll_results' => 1, 'start' => $start == 0 ? NULL : $start, 'max' => $max == $default_max ? NULL : $max);
                         $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
                         if ($test != -1 && $test != 0) {
                             $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
                         }
                         $test = get_param_integer('threaded', -1);
                         if ($test != -1) {
                             $map['threaded'] = $test;
                         }
                         $results_url = build_url($map, get_module_zone('topics'));
                         $button = do_template('OCF_TOPIC_POLL_BUTTON', array('_GUID' => '94b932fd01028df8f67bb5864d9235f9', 'RESULTS_URL' => $results_url));
                         $real_button = true;
                     }
                 }
             }
         } else {
             $button = do_lang_tempcode('TOPIC_POLL_CLOSED');
         }
         foreach ($_poll['answers'] as $answer) {
             if ($poll_results && ($_poll['requires_reply'] == 0 || $replied)) {
                 $num_votes = $answer['num_votes'];
                 $total_votes = $_poll['total_votes'];
                 if ($total_votes != 0) {
                     $width = intval(round(70.0 * floatval($num_votes) / floatval($total_votes)));
                 } else {
                     $width = 0;
                 }
                 $answer_tpl = do_template('OCF_TOPIC_POLL_ANSWER_RESULTS', array('_GUID' => 'b32f4c526e147abf20ca0d668e40d515', 'ID' => strval($_poll['id']), 'NUM_VOTES' => integer_format($num_votes), 'WIDTH' => strval($width), 'ANSWER' => $answer['answer'], 'I' => strval($answer['id'])));
             } else {
                 $answer_tpl = do_template('OCF_TOPIC_POLL_ANSWER' . ($_poll['maximum_selections'] == 1 ? '_RADIO' : ''), array('REAL_BUTTON' => $real_button, 'ID' => strval($_poll['id']), 'ANSWER' => $answer['answer'], 'I' => strval($answer['id'])));
             }
             $answers->attach($answer_tpl);
         }
         $map = array('page' => 'topics', 'type' => 'vote_poll', 'id' => $id, 'start' => $start == 0 ? NULL : $start, 'max' => $max == $default_max ? NULL : $max);
         $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
         if ($test != -1 && $test != 0) {
             $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
         }
         $test = get_param_integer('threaded', -1);
         if ($test != -1) {
             $map['threaded'] = $test;
         }
         $vote_url = build_url($map, get_module_zone('topics'));
         if ($_poll['is_private']) {
             $private = paragraph(do_lang_tempcode('TOPIC_POLL_IS_PRIVATE'), 'dfgsdgdsgs');
         } else {
             $private = new ocp_tempcode();
         }
         if ($_poll['maximum_selections'] > 1) {
             $num_choices = paragraph($_poll['minimum_selections'] == $_poll['maximum_selections'] ? do_lang_tempcode('POLL_NOT_ENOUGH_ERROR_2', integer_format($_poll['minimum_selections'])) : do_lang_tempcode('POLL_NOT_ENOUGH_ERROR', integer_format($_poll['minimum_selections']), integer_format($_poll['maximum_selections'])), 'dsfsdfsdfs');
         } else {
             $num_choices = new ocp_tempcode();
         }
         $poll = do_template('OCF_TOPIC_POLL' . ($poll_results ? '_VIEW_RESULTS' : ''), array('ID' => strval($_poll['id']), 'NUM_CHOICES' => $num_choices, 'PRIVATE' => $private, 'QUESTION' => $_poll['question'], 'ANSWERS' => $answers, 'REAL_BUTTON' => $real_button, 'BUTTON' => $button, 'VOTE_URL' => $vote_url, 'MINIMUM_SELECTIONS' => integer_format($_poll['minimum_selections']), 'MAXIMUM_SELECTIONS' => integer_format($_poll['maximum_selections'])));
     } else {
         $poll = new ocp_tempcode();
     }
     // Forum nav tree
     if (!is_null($topic_info['forum_id'])) {
         $tree = ocf_forum_breadcrumbs($topic_info['forum_id'], NULL, NULL, false);
     } else {
         $tree = new ocp_tempcode();
         $tree->attach(hyperlink(build_url(array('page' => 'members'), get_module_zone('members')), do_lang_tempcode('MEMBERS'), false, false, do_lang_tempcode('GO_BACKWARDS_TO', do_lang_tempcode('MEMBERS')), NULL, NULL, 'up'));
         $tree->attach(do_template('BREADCRUMB_ESCAPED'));
         if (has_specific_permission(get_member(), 'view_other_pt')) {
             $of_member = $topic_info['pt_from'] == get_member() ? $topic_info['pt_from'] : $topic_info['pt_to'];
         } else {
             $of_member = get_member();
         }
         $of_username = $GLOBALS['FORUM_DRIVER']->get_username($of_member);
         if (is_null($of_username)) {
             $of_username = do_lang('UNKNOWN');
         }
         $personal_topic_url = build_url(array('page' => 'members', 'type' => 'view', 'id' => $of_member), get_module_zone('members'), NULL, true, false, false, 'tab__pts');
         $tree->attach(hyperlink($personal_topic_url, do_lang_tempcode('MEMBER_PROFILE', escape_html($of_username)), false, false, do_lang_tempcode('GO_BACKWARDS_TO', do_lang_tempcode('MEMBERS')), NULL, NULL, 'up'));
     }
     // Quick reply
     if (array_key_exists('may_use_quick_reply', $topic_info) && $may_reply && !is_null($id)) {
         $map = array('page' => 'topics', 'type' => '_add_reply', 'topic_id' => $id);
         $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
         if ($test != -1 && $test != 0) {
             $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
         }
         $test = get_param_integer('threaded', -1);
         if ($test != -1) {
             $map['threaded'] = $test;
         }
         $_post_url = build_url($map, get_module_zone('topics'));
         $post_url = $_post_url->evaluate();
         $map = array('page' => 'topics', 'type' => 'new_post', 'id' => $id);
         if ($test != -1 && $test != 0) {
             $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
         }
         $more_url = build_url($map, get_module_zone('topics'));
         $_postdetails = array_key_exists('first_post', $topic_info) ? get_translated_tempcode($topic_info['first_post'], $GLOBALS['FORUM_DB']) : new ocp_tempcode();
         $first_post = $_postdetails;
         $first_post_url = $GLOBALS['FORUM_DRIVER']->post_url($topic_info['first_post_id'], is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']), true);
         $display = 'block';
         $expand_type = 'contract';
         if ($topic_info['max_rows'] > $start + $max) {
             $display = 'none';
             $expand_type = 'expand';
         }
         $em = $GLOBALS['FORUM_DRIVER']->get_emoticon_chooser();
         require_javascript('javascript_editing');
         require_javascript('javascript_validation');
         if (addon_installed('captcha')) {
             require_code('captcha');
             $use_captcha = use_captcha();
             if ($use_captcha) {
                 generate_captcha();
             }
         } else {
             $use_captcha = false;
         }
         $post_warning = '';
         if ($topic_info['is_really_threaded'] == 1) {
             $post_warning = do_lang('THREADED_REPLY_NOTICE', $post_warning);
         }
         $quick_reply = do_template('COMMENTS_POSTING_FORM', array('_GUID' => '4c532620f3eb68d9cc820b18265792d7', 'JOIN_BITS' => '', 'USE_CAPTCHA' => $use_captcha, 'GET_EMAIL' => false, 'EMAIL_OPTIONAL' => true, 'GET_TITLE' => false, 'POST_WARNING' => $post_warning, 'COMMENT_TEXT' => '', 'EM' => $em, 'EXPAND_TYPE' => $expand_type, 'DISPLAY' => $display, 'FIRST_POST_URL' => $first_post_url, 'FIRST_POST' => $first_post, 'MORE_URL' => $more_url, 'COMMENT_URL' => $post_url, 'TITLE' => do_lang_tempcode('QUICK_REPLY'), 'SUBMIT_NAME' => do_lang_tempcode('MAKE_POST')));
     } else {
         $quick_reply = new ocp_tempcode();
     }
     $action_url = build_url(array('page' => 'topics', 'id' => $id), get_module_zone('topics'));
     if (!is_null($id)) {
         // Moderation options
         $moderator_actions = '';
         if (is_null($topic_info['forum_id'])) {
             $moderator_actions .= '<option value="categorise_pts">' . do_lang('_CATEGORISE_PTS') . '</option>';
         }
         if (array_key_exists('may_multi_moderate', $topic_info) && array_key_exists('forum_id', $topic_info)) {
             $multi_moderations = ocf_list_multi_moderations($topic_info['forum_id']);
             if (count($multi_moderations) != 0) {
                 $moderator_actions .= '<optgroup label="' . do_lang('MULTI_MODERATIONS') . '">';
                 foreach ($multi_moderations as $mm_id => $mm_name) {
                     $moderator_actions .= '<option value="mm_' . strval($mm_id) . '">' . $mm_name . '</option>';
                 }
                 $moderator_actions .= '</optgroup>';
             }
         }
         if (array_key_exists('may_move_topic', $topic_info)) {
             $moderator_actions .= '<option value="move_topic">' . do_lang('MOVE_TOPIC') . '</option>';
         }
         if (array_key_exists('may_edit_topic', $topic_info)) {
             $moderator_actions .= '<option value="edit_topic">' . do_lang('EDIT_TOPIC') . '</option>';
         }
         if (array_key_exists('may_delete_topic', $topic_info)) {
             $moderator_actions .= '<option value="delete_topic">' . do_lang('DELETE_TOPIC') . '</option>';
         }
         if (array_key_exists('may_pin_topic', $topic_info)) {
             $moderator_actions .= '<option value="pin_topic">' . do_lang('PIN_TOPIC') . '</option>';
         }
         if (array_key_exists('may_unpin_topic', $topic_info)) {
             $moderator_actions .= '<option value="unpin_topic">' . do_lang('UNPIN_TOPIC') . '</option>';
         }
         if (array_key_exists('may_sink_topic', $topic_info)) {
             $moderator_actions .= '<option value="sink_topic">' . do_lang('SINK_TOPIC') . '</option>';
         }
         if (array_key_exists('may_unsink_topic', $topic_info)) {
             $moderator_actions .= '<option value="unsink_topic">' . do_lang('UNSINK_TOPIC') . '</option>';
         }
         if (array_key_exists('may_cascade_topic', $topic_info)) {
             $moderator_actions .= '<option value="cascade_topic">' . do_lang('CASCADE_TOPIC') . '</option>';
         }
         if (array_key_exists('may_uncascade_topic', $topic_info)) {
             $moderator_actions .= '<option value="uncascade_topic">' . do_lang('UNCASCADE_TOPIC') . '</option>';
         }
         if (array_key_exists('may_open_topic', $topic_info)) {
             $moderator_actions .= '<option value="open_topic">' . do_lang('OPEN_TOPIC') . '</option>';
         }
         if (array_key_exists('may_close_topic', $topic_info)) {
             $moderator_actions .= '<option value="close_topic">' . do_lang('CLOSE_TOPIC') . '</option>';
         }
         if (array_key_exists('may_edit_poll', $topic_info)) {
             $moderator_actions .= '<option value="edit_poll">' . do_lang('EDIT_TOPIC_POLL') . '</option>';
         }
         if (array_key_exists('may_delete_poll', $topic_info)) {
             $moderator_actions .= '<option value="delete_poll">' . do_lang('DELETE_TOPIC_POLL') . '</option>';
         }
         if (array_key_exists('may_attach_poll', $topic_info)) {
             $moderator_actions .= '<option value="add_poll">' . do_lang('ADD_TOPIC_POLL') . '</option>';
         }
         if (has_specific_permission(get_member(), 'view_content_history') && $GLOBALS['FORUM_DB']->query_value('f_post_history', 'COUNT(*)', array('h_topic_id' => $id)) != 0) {
             $moderator_actions .= '<option value="topic_history">' . do_lang('POST_HISTORY') . '</option>';
         }
         if (array_key_exists('may_make_personal', $topic_info) && !is_null($topic_info['forum_id'])) {
             $moderator_actions .= '<option value="make_personal">' . do_lang('MAKE_PERSONAL') . '</option>';
         }
         if ($GLOBALS['XSS_DETECT']) {
             ocp_mark_as_escaped($moderator_actions);
         }
         // Marked post actions
         $map = array('page' => 'topics', 'id' => $id);
         $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
         if ($test != -1 && $test != 0) {
             $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
         }
         $test = get_param_integer('threaded', -1);
         if ($test != -1) {
             $map['threaded'] = $test;
         }
         $action_url = build_url($map, get_module_zone('topics'), NULL, false, true);
         $marked_post_actions = '';
         if (array_key_exists('may_move_posts', $topic_info)) {
             $marked_post_actions .= '<option value="move_posts_a">' . do_lang('MERGE_POSTS') . '</option>';
             $marked_post_actions .= '<option value="move_posts_b">' . do_lang('SPLIT_POSTS') . '</option>';
         }
         if (array_key_exists('may_delete_posts', $topic_info)) {
             $marked_post_actions .= '<option value="delete_posts">' . do_lang('DELETE_POSTS') . '</option>';
         }
         if (array_key_exists('may_validate_posts', $topic_info)) {
             $marked_post_actions .= '<option value="validate_posts">' . do_lang('VALIDATE_POSTS') . '</option>';
         }
         if (get_value('disable_multi_quote') !== '1') {
             if ($may_reply) {
                 $marked_post_actions .= '<option value="new_post">' . do_lang('QUOTE_POSTS') . '</option>';
             }
         }
         if ($GLOBALS['XSS_DETECT']) {
             ocp_mark_as_escaped($marked_post_actions);
         }
     } else {
         $moderator_actions = '';
         $marked_post_actions = '';
     }
     $max_rows = $topic_info['max_rows'];
     if ($max_rows > $max && !$threaded) {
         require_code('templates_results_browser');
         $results_browser = results_browser(do_lang_tempcode('FORUM_POSTS'), $id, $start, 'start', $max, 'max', $max_rows, NULL, 'misc', true, false, 7, array(10, 20, 30));
     } else {
         $results_browser = new ocp_tempcode();
     }
     // Members viewing this topic
     $members = is_null($id) ? array() : get_members_viewing('topicview', '', strval($id), true);
     $num_guests = 0;
     $num_members = 0;
     if (is_null($members)) {
         $members_viewing = new ocp_tempcode();
     } else {
         $members_viewing = new ocp_tempcode();
         foreach ($members as $member_id => $at_details) {
             $username = $at_details['mt_cache_username'];
             if (is_guest($member_id)) {
                 $num_guests++;
             } else {
                 $num_members++;
                 $profile_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($member_id, false, true);
                 $map = array('PROFILE_URL' => $profile_url, 'USERNAME' => $username);
                 if (has_specific_permission(get_member(), 'show_user_browsing') || in_array($at_details['the_page'], array('topics', 'topicview')) && $at_details['the_id'] == strval($id)) {
                     $map['AT'] = escape_html($at_details['the_title']);
                 }
                 $map['COLOUR'] = get_group_colour(ocf_get_member_primary_group($member_id));
                 $members_viewing->attach(do_template('OCF_USER_MEMBER', $map));
             }
         }
         if ($members_viewing->is_empty()) {
             $members_viewing = do_lang_tempcode('NONE_EM');
         }
     }
     if (!is_null($id)) {
         breadcrumb_add_segment($tree, do_lang_tempcode(is_null($topic_info['forum_id']) ? 'VIEW_PERSONAL_TOPIC' : 'VIEW_TOPIC'));
     }
     if (is_null($id)) {
         $root_forum_name = $GLOBALS['FORUM_DB']->query_value('f_forums', 'f_name', array('id' => db_get_first_id()));
         $tree = hyperlink(build_url(array('page' => 'forumview', 'id' => db_get_first_id()), get_module_zone('forumview')), escape_html($root_forum_name), false, false, do_lang('GO_BACKWARDS_TO'));
         breadcrumb_add_segment($tree, do_lang('INLINE_PERSONAL_POSTS'));
     }
     if ($topic_info['validated'] == 0) {
         $warning_details = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode(get_param_integer('redirected', 0) == 1 ? 'UNVALIDATED_TEXT_NON_DIRECT' : 'UNVALIDATED_TEXT')));
     } else {
         $warning_details = new ocp_tempcode();
     }
     $topic_tpl = do_template('OCF_TOPIC_WRAP', array('_GUID' => 'bb201d5d59559e5e2bd60e7cf2e6f7e9', 'SERIALIZED_OPTIONS' => $serialized_options, 'HASH' => $hash, 'ID' => strval($id), 'TITLE' => $topic_info['title'], 'MAY_DOUBLE_POST' => has_specific_permission(get_member(), 'double_post'), 'LAST_POSTER' => array_key_exists('last_poster', $topic_info) ? is_null($topic_info['last_poster']) ? '' : strval($topic_info['last_poster']) : '', 'WARNING_DETAILS' => $warning_details, 'MAX' => strval($max), 'MAY_CHANGE_MAX' => array_key_exists('may_change_max', $topic_info), 'ACTION_URL' => $action_url, 'NUM_GUESTS' => integer_format($num_guests), 'NUM_MEMBERS' => integer_format($num_members), 'MEMBERS_VIEWING' => $members_viewing, 'RESULTS_BROWSER' => $results_browser, 'MODERATOR_ACTIONS' => $moderator_actions, 'MARKED_POST_ACTIONS' => $marked_post_actions, 'QUICK_REPLY' => $quick_reply, 'TREE' => $tree, 'POLL' => $poll, 'SCREEN_BUTTONS' => $buttons, 'POSTS' => $posts, 'THREADED' => $threaded));
     if (is_null($id)) {
         $title = get_page_title('INLINE_PERSONAL_POSTS');
     } else {
         if (is_null($topic_info['forum_id'])) {
             $title = get_page_title(do_lang_tempcode('NAMED_PERSONAL_TOPIC', escape_html($topic_info['title'])), false, NULL, do_lang_tempcode('READING_PERSONAL_TOPIC'));
         } else {
             if (addon_installed('awards')) {
                 require_code('awards');
                 $awards = find_awards_for('topic', strval($id));
             } else {
                 $awards = array();
             }
             $title = get_page_title(do_lang_tempcode('NAMED_TOPIC', escape_html($topic_info['title'])), false, NULL, NULL, $awards);
         }
     }
     return ocf_wrapper($title, $topic_tpl, true, false, $topic_info['forum_id']);
 }
예제 #29
0
파일: cedi.php 프로젝트: erico-deh/ocPortal
/**
 * Edit a CEDI post
 *
 * @param  AUTO_LINK		The page ID
 * @param  string			The new post
 * @param  BINARY			Whether the post will be validated
 * @param  ?MEMBER		The member doing the action (NULL: current member)
 * @param  boolean		Whether to send out a staff e-mail about the new CEDI post
 * @return AUTO_LINK		The post ID
 */
function cedi_add_post($page_id, $message, $validated = 1, $member = NULL, $send_mail = true)
{
    if (is_null($member)) {
        $member = get_member();
    }
    require_code('comcode_check');
    check_comcode($message, NULL, false, NULL, true);
    if (!addon_installed('unvalidated')) {
        $validated = 1;
    }
    $id = $GLOBALS['SITE_DB']->query_insert('seedy_posts', array('validated' => $validated, 'edit_date' => NULL, 'the_message' => 0, 'the_user' => $member, 'date_and_time' => time(), 'page_id' => $page_id, 'seedy_views' => 0), true);
    require_code('attachments2');
    $the_message = insert_lang_comcode_attachments(2, $message, 'cedi_post', strval($id));
    $GLOBALS['SITE_DB']->query_update('seedy_posts', array('the_message' => $the_message), array('id' => $id), '', 1);
    // Log
    $GLOBALS['SITE_DB']->query_insert('seedy_changes', array('the_action' => 'CEDI_MAKE_POST', 'the_page' => $page_id, 'ip' => get_ip_address(), 'the_user' => $member, 'date_and_time' => time()));
    // Update post count
    if (addon_installed('points')) {
        require_code('points');
        $_count = point_info($member);
        $count = array_key_exists('points_gained_seedy', $_count) ? $_count['points_gained_seedy'] : 0;
        $GLOBALS['FORUM_DRIVER']->set_custom_field($member, 'points_gained_seedy', $count + 1);
    }
    // Stat
    update_stat('num_seedy_posts', 1);
    //update_stat('num_seedy_files',count($_FILES));
    // Send e-mail to the staff. These exist because CEDI exists in the 'space' between a forum, and a website- usually there is no validation, but the content does need moderation (and unlike a forum, staff are unlikely to 'lurk')
    if ($send_mail) {
        dispatch_cedi_post_notification($id, 'ADD');
    }
    if (get_option('show_post_validation') == '1') {
        decache('main_staff_checklist');
    }
    return $id;
}
예제 #30
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);
}