Esempio n. 1
0
 /**
  * Standard modular run function for preview hooks.
  *
  * @return array			A pair: The preview, the updated post Comcode
  */
 function run()
 {
     require_lang('ocf');
     require_css('ocf');
     $original_comcode = post_param('post');
     $posting_ref_id = post_param_integer('posting_ref_id', mt_rand(0, 100000));
     $post_bits = do_comcode_attachments($original_comcode, 'seedy_post', strval(-$posting_ref_id), true, $GLOBALS['SITE_DB']);
     $post_comcode = $post_bits['comcode'];
     $post_html = $post_bits['tempcode'];
     return array($post_html, $post_comcode);
 }
Esempio n. 2
0
 /**
  * Standard modular run function for preview hooks.
  *
  * @return array			A pair: The preview, the updated post Comcode
  */
 function run()
 {
     $original_comcode = post_param('post');
     $posting_ref_id = post_param_integer('posting_ref_id', mt_rand(0, 100000));
     $post_bits = do_comcode_attachments($original_comcode, 'news', strval(-$posting_ref_id), true, $GLOBALS['SITE_DB']);
     $post_comcode = $post_bits['comcode'];
     $post_html = $post_bits['tempcode'];
     $view_space_map = array();
     $view_space_map[post_param('label_for__title')] = escape_html(post_param('title'));
     $view_space_map[post_param('label_for__post')] = $post_html;
     $view_space_map[post_param('label_for__news')] = comcode_to_tempcode(post_param('news', ''));
     require_code('templates_view_space');
     $view_space_fields = new ocp_tempcode();
     foreach ($view_space_map as $key => $val) {
         $view_space_fields->attach(view_space_field($key, $val, true));
     }
     $output = do_template('VIEW_SPACE', array('WIDTH' => '170', 'FIELDS' => $view_space_fields));
     return array($output, $post_comcode);
 }
Esempio n. 3
0
/**
 * Update a language code, in such a way that new attachments are created if they were specified.
 *
 * @param  integer		The language id
 * @param  LONG_TEXT		The new text
 * @param  ID_TEXT		The arbitrary type that the attached is for (e.g. download)
 * @param  ID_TEXT		The id in the set of the arbitrary types that the attached is for
 * @param  ?object		The database connection to use (NULL: standard site connection)
 * @param  boolean		Whether to backup the language string before changing it
 * @param  ?MEMBER		The member to use for ownership permissions (NULL: current member)
 * @return integer		The language id
 */
function update_lang_comcode_attachments($lang_id, $text, $type, $id, $connection = NULL, $backup_string = false, $for_member = NULL)
{
    if ($lang_id == 0) {
        return insert_lang_comcode_attachments(3, $text, $type, $id, $connection, false, $for_member);
    }
    if ($text === STRING_MAGIC_NULL) {
        return $lang_id;
    }
    if (is_null($connection)) {
        $connection = $GLOBALS['SITE_DB'];
    }
    require_lang('comcode');
    _check_attachment_count();
    $test = $connection->query_value_null_ok('translate', 'text_original', array('id' => $id, 'language' => user_lang()));
    if ($backup_string) {
        $current = $connection->query_select('translate', array('*'), array('id' => $lang_id, 'language' => user_lang()));
        if (!array_key_exists(0, $current)) {
            $current = $connection->query_select('translate', array('*'), array('id' => $lang_id));
        }
        $connection->query_insert('translate_history', array('lang_id' => $lang_id, 'language' => $current[0]['language'], 'text_original' => $current[0]['text_original'], 'broken' => $current[0]['broken'], 'action_member' => get_member(), 'action_time' => time()));
    }
    $member = function_exists('get_member') ? get_member() : $GLOBALS['FORUM_DRIVER']->get_guest_id();
    $_info = do_comcode_attachments($text, $type, $id, false, $connection, NULL, $for_member);
    $text2 = '';
    //Actually we'll let it regenerate with the correct permissions ($member, not $for_member) $_info['tempcode']->to_assembly();
    $remap = array('text_original' => $_info['comcode'], 'text_parsed' => $text2);
    if (ocp_admirecookie('use_wysiwyg', '1') == '0' && get_value('edit_with_my_comcode_perms') === '1' || !has_specific_permission($member, 'allow_html') || !has_specific_permission($member, 'use_very_dangerous_comcode')) {
        $remap['source_user'] = $member;
    }
    if (!is_null($test)) {
        $connection->query_update('translate', $remap, array('id' => $lang_id, 'language' => user_lang()));
    } else {
        $connection->query_update('translate', $remap, array('id' => $lang_id));
    }
    return $lang_id;
}
Esempio n. 4
0
 /**
  * Standard modular run function for preview hooks.
  *
  * @return array			A pair: The preview, the updated post Comcode
  */
 function run()
 {
     require_lang('ocf');
     require_css('ocf');
     $original_comcode = post_param('post');
     require_code('ocf_posts_action');
     require_code('ocf_posts_action2');
     ocf_check_post($original_comcode, post_param_integer('topic_id', NULL), get_member());
     $posting_ref_id = post_param_integer('posting_ref_id', mt_rand(0, 100000));
     if ($posting_ref_id < 0) {
         fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     $post_bits = do_comcode_attachments($original_comcode, 'ocf_post', strval(-$posting_ref_id), true, $GLOBALS['FORUM_DB']);
     $post_comcode = $post_bits['comcode'];
     $post_html = $post_bits['tempcode'];
     // Put quote in
     $parent_id = post_param_integer('parent_id', NULL);
     if (!is_null($parent_id) && strpos($post_comcode, '[quote') === false) {
         $_p = $GLOBALS['FORUM_DB']->query_select('f_posts', array('*'), array('id' => $parent_id), '', 1);
         if (array_key_exists(0, $_p)) {
             $p = $_p[0];
             $p['message'] = get_translated_tempcode($p['p_post'], $GLOBALS['FORUM_DB']);
             $temp = $post_html;
             $post_html = new ocp_tempcode();
             $post_html = do_template('COMCODE_QUOTE_BY', array('SAIDLESS' => false, 'BY' => $p['p_poster_name_if_guest'], 'CONTENT' => $p['message']));
             $post_html->attach($temp);
         }
     }
     $post_owner = get_member();
     $_post_date = time();
     $post_id = post_param_integer('post_id', NULL);
     if (!is_null($post_id)) {
         $post_owner = $GLOBALS['FORUM_DB']->query_value_null_ok('f_posts', 'p_poster', array('id' => $post_id));
         if (is_null($post_owner)) {
             $post_owner = get_member();
         }
         $_post_date = $GLOBALS['FORUM_DB']->query_value_null_ok('f_posts', 'p_time', array('id' => $post_id));
         if (is_null($_post_date)) {
             $_post_date = time();
         }
     }
     $post_date = get_timezoned_date($_post_date);
     $post_title = post_param('title', '');
     if (strlen($post_title) > 120) {
         warn_exit(do_lang_tempcode('TITLE_TOO_LONG'));
     }
     $unvalidated = post_param_integer('validated', 0) == 0 && get_param('page', '') == 'topics' ? do_lang_tempcode('UNVALIDATED') : new ocp_tempcode();
     $emphasis = new ocp_tempcode();
     $intended_solely_for = post_param('intended_solely_for', NULL);
     if ($intended_solely_for == '') {
         $intended_solely_for = NULL;
     }
     $is_emphasised = post_param_integer('is_emphasised', 0) == 1;
     if ($is_emphasised) {
         $emphasis = do_lang_tempcode('IMPORTANT');
     } elseif (!is_null($intended_solely_for)) {
         if (is_numeric($intended_solely_for)) {
             $_intended_solely_for = $GLOBALS['FORUM_DRIVER']->get_username(intval($intended_solely_for));
             if (!is_null($_intended_solely_for)) {
                 $intended_solely_for = $_intended_solely_for;
             }
         }
         $emphasis = do_lang_tempcode('PP_TO', escape_html($intended_solely_for));
     }
     $class = $is_emphasised ? 'ocf_post_emphasis' : (!is_null($intended_solely_for) ? 'ocf_post_personal' : '');
     // Member details
     $signature = get_translated_tempcode($GLOBALS['FORUM_DRIVER']->get_member_row_field($post_owner, 'm_signature'), $GLOBALS['FORUM_DB']);
     $_postdetails_avatar = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($post_owner);
     if ($_postdetails_avatar != '') {
         $post_avatar = do_template('OCF_TOPIC_POST_AVATAR', array('_GUID' => '2683c09eabd7a9f1fdc57a20117483ef', 'AVATAR' => $_postdetails_avatar));
     } else {
         $post_avatar = new ocp_tempcode();
     }
     require_code('ocf_groups');
     require_code('ocf_members');
     $poster_title = addon_installed('ocf_member_titles') ? $GLOBALS['FORUM_DRIVER']->get_member_row_field($post_owner, 'm_title') : '';
     $primary_group = $GLOBALS['FORUM_DRIVER']->get_member_row_field($post_owner, 'm_primary_group');
     if ($poster_title == '') {
         $poster_title = get_translated_text(ocf_get_group_property($primary_group, 'title'), $GLOBALS['FORUM_DB']);
     }
     // Poster box
     if (!is_guest($post_owner)) {
         require_code('ocf_members2');
         $poster_details = ocf_show_member_box($post_owner, false, NULL, NULL, false);
         $poster_username = $GLOBALS['FORUM_DRIVER']->get_username($post_owner);
         if (is_null($poster_username)) {
             $poster_username = do_lang('UNKNOWN');
         }
         $poster = do_template('OCF_POSTER_MEMBER', array('_GUID' => '976a6ceb631bbdcdd950b723cb5d2487', 'ONLINE' => true, 'ID' => strval($post_owner), 'POSTER_DETAILS' => $poster_details, 'PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($post_owner, false, true), 'POSTER_USERNAME' => $poster_username));
     } else {
         $poster_details = new ocp_tempcode();
         $custom_fields = do_template('OCF_TOPIC_POST_CUSTOM_FIELD', array('NAME' => do_lang_tempcode('IP_ADDRESS'), 'VALUE' => get_ip_address()));
         $poster_details = do_template('OCF_GUEST_DETAILS', array('_GUID' => '2db48e17db9f060c04386843f2d0f105', 'CUSTOM_FIELDS' => $custom_fields));
         $poster_username = post_param('poster_name_if_guest', do_lang('GUEST'));
         $ip_link = has_actual_page_access(get_member(), 'admin_lookup') ? build_url(array('page' => 'admin_lookup', 'param' => get_ip_address()), get_module_zone('admin_lookup')) : new ocp_tempcode();
         $poster = do_template('OCF_POSTER_GUEST', array('_GUID' => '9c0ba6198663de96facc7399a08e8281', 'IP_LINK' => $ip_link, 'POSTER_DETAILS' => $poster_details, 'POSTER_USERNAME' => $poster_username));
     }
     // Rank images
     $rank_images = new ocp_tempcode();
     $posters_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($post_owner, 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);
         if ($rank_image != '') {
             $rank_images->attach(do_template('OCF_RANK_IMAGE', array('_GUID' => 'a6a413fc07e05b28ab995b072718b755', 'GROUP_NAME' => $group_name, 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username(get_member()), 'IMG' => $rank_image, 'IS_LEADER' => $group_leader == get_member())));
         }
     }
     if (get_param('type') == 'edit_post') {
         $last_edited = do_template('OCF_TOPIC_POST_LAST_EDITED', array('LAST_EDIT_DATE_RAW' => strval(time()), 'LAST_EDIT_DATE' => get_timezoned_date(time(), true), 'LAST_EDIT_PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url(get_member(), false, true), 'LAST_EDIT_USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username(get_member())));
     } else {
         $last_edited = new ocp_tempcode();
     }
     $post = do_template('OCF_TOPIC_POST', array('_GUID' => '354473f96b4f7324d2a9c476ff78f0d7', 'POST_ID' => '', 'TOPIC_FIRST_POST_ID' => '', 'TOPIC_FIRST_POSTER' => strval(get_member()), 'POST_TITLE' => $post_title, 'CLASS' => $class, 'EMPHASIS' => $emphasis, 'FIRST_UNREAD' => '', 'TOPIC_ID' => '', 'ID' => '', 'POST_DATE_RAW' => strval($_post_date), 'POST_DATE' => $post_date, 'UNVALIDATED' => $unvalidated, 'URL' => '', 'POSTER' => $poster, 'POST_AVATAR' => $post_avatar, 'POSTER_TITLE' => $poster_title, 'RANK_IMAGES' => $rank_images, 'POST' => $post_html, 'LAST_EDITED' => $last_edited, 'SIGNATURE' => $signature, 'BUTTONS' => '', 'POSTER_ID' => strval($post_owner)));
     $out = do_template('OCF_TOPIC_POST_CLEAN_WRAP', array('_GUID' => '62bbfabfa5c16c2aa6724a0b79839626', 'POST' => $post));
     return array($out, $post_comcode);
 }
Esempio n. 5
0
/**
 * Insert some comcode content that may contain attachments, and return the language id.
 *
 * @param  integer		The level of importance this language string holds
 * @set    1 2 3 4
 * @param  LONG_TEXT		The comcode content
 * @param  ID_TEXT		The arbitrary type that the attached is for (e.g. download)
 * @param  ID_TEXT		The id in the set of the arbitrary types that the attached is for
 * @param  ?object		The database connection to use (NULL: standard site connection)
 * @param  boolean		Whether to insert it as an admin (any comcode parsing will be carried out with admin privileges)
 * @param  ?MEMBER		The member to use for ownership permissions (NULL: current member)
 * @return integer		The language id
 */
function insert_lang_comcode_attachments($level, $text, $type, $id, $connection = NULL, $insert_as_admin = false, $for_member = NULL)
{
    if (is_null($connection)) {
        $connection = $GLOBALS['SITE_DB'];
    }
    require_lang('comcode');
    _check_attachment_count();
    $_info = do_comcode_attachments($text, $type, $id, false, $connection, $insert_as_admin, $for_member);
    $text2 = $_info['tempcode']->to_assembly();
    $member = function_exists('get_member') ? get_member() : $GLOBALS['FORUM_DRIVER']->get_guest_id();
    $lang_id = NULL;
    if (user_lang() == 'Gibb') {
        $lang_id = $connection->query_insert('translate', array('source_user' => $member, 'broken' => 0, 'importance_level' => $level, 'text_original' => 'EnglishEnglishWarningWrongLanguageWantGibberishLang', 'text_parsed' => '', 'language' => 'EN'), true);
    }
    if (is_null($lang_id)) {
        $lang_id = $connection->query_insert('translate', array('source_user' => $member, 'broken' => 0, 'importance_level' => $level, 'text_original' => $_info['comcode'], 'text_parsed' => $text2, 'language' => user_lang()), true);
    } else {
        $connection->query_insert('translate', array('id' => $lang_id, 'source_user' => $member, 'broken' => 0, 'importance_level' => $level, 'text_original' => $_info['comcode'], 'text_parsed' => $text2, 'language' => user_lang()));
    }
    final_attachments_from_preview($id, $connection);
    return $lang_id;
}
Esempio n. 6
0
 /**
  * The actualiser to edit a comcode page.
  *
  * @return tempcode		The UI
  */
 function __ed()
 {
     $simple_add = get_param_integer('simple_add', 0) == 1;
     $title = get_page_title($simple_add ? 'COMCODE_PAGE_ADD' : 'COMCODE_PAGE_EDIT');
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/comcode_page_edit';
     $file = filter_naughty(post_param('file'));
     $lang = filter_naughty(post_param('lang'));
     $zone = filter_naughty(post_param('zone'));
     if (addon_installed('page_management')) {
         $new_file = filter_naughty(has_actual_page_access(get_member(), 'admin_sitetree') ? post_param('title', $file) : $file);
     } else {
         $new_file = filter_naughty($file);
     }
     if ($file == '') {
         $file = $new_file;
     }
     require_code('type_validation');
     if (!is_alphanumeric($file, true)) {
         warn_exit(do_lang_tempcode('BAD_CODENAME'));
     }
     $fullpath = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang . '/' . $file . '.txt');
     $renaming_page = $new_file != $file;
     if ($renaming_page) {
         if (!is_alphanumeric($new_file, true)) {
             warn_exit(do_lang_tempcode('BAD_CODENAME'));
         }
         $langs = find_all_langs(true);
         $rename_map = array();
         $afm_needed = false;
         // Actually will stay false as we don't allow renaming original-pages at the moment
         foreach (array_keys($langs) as $lang) {
             $path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/comcode_custom/' . $lang . '/' . $file . '.txt', true);
             if (is_file(get_file_base() . '/' . $path)) {
                 $new_path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/comcode_custom/' . $lang . '/' . $new_file . '.txt', true);
                 if (is_file($new_path)) {
                     warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($zone . ':' . $new_file)));
                 }
                 $rename_map[$path] = $new_path;
             }
             if (is_file(get_file_base() . '/' . str_replace('/comcode_custom/', '/comcode/', $path))) {
                 $completion_text = do_lang_tempcode('ORIGINAL_PAGE_NO_RENAME');
             }
         }
         if ($afm_needed) {
             require_code('abstract_file_manager');
             force_have_afm_details();
         }
     }
     $validated = post_param_integer('validated', 0);
     if (!has_specific_permission(get_member(), 'bypass_validation_highrange_content')) {
         $validated = 0;
     }
     $parent_page = post_param('parent_page', '');
     $show_as_edit = post_param_integer('show_as_edit', 0);
     $resource_owner = $GLOBALS['SITE_DB']->query_value_null_ok('comcode_pages', 'p_submitter', array('the_zone' => $zone, 'the_page' => $file));
     check_edit_permission('high', $resource_owner);
     if ($GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) {
         $_owner = post_param('owner', $GLOBALS['FORUM_DRIVER']->get_username(get_member()));
         $owner = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_owner);
         if (is_null($owner)) {
             $owner = get_member();
         }
     } else {
         $owner = get_member();
     }
     if (is_null($resource_owner)) {
         check_submit_permission('high');
         require_code('submit');
         give_submit_points('COMCODE_PAGE_ADD');
         if (!addon_installed('unvalidated')) {
             $validated = 1;
         }
         $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => $zone, 'the_page' => $file, 'p_parent_page' => $parent_page, 'p_validated' => $validated, 'p_edit_date' => NULL, 'p_add_date' => time(), 'p_submitter' => $owner, 'p_show_as_edit' => 0));
     } else {
         if (!has_actual_page_access(get_member(), $file, $zone)) {
             access_denied('PAGE_ACCESS');
         }
         require_code('submit');
         $just_validated = !content_validated('comcode_page', $zone . ':' . $file) && $validated == 1;
         if ($just_validated) {
             send_content_validated_notification('comcode_page', $zone . ':' . $file);
         }
         if (!addon_installed('unvalidated')) {
             $validated = 1;
         }
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('p_parent_page' => $parent_page, 'p_validated' => $validated, 'p_edit_date' => time(), 'p_submitter' => $owner, 'p_show_as_edit' => $show_as_edit), array('the_zone' => $zone, 'the_page' => $file), '', 1);
     }
     if ($validated == 0) {
         require_code('submit');
         $edit_url = build_url(array('page' => '_SELF', 'type' => '_ed', 'page_link' => $zone . ':' . $new_file), '_SELF', NULL, false, false, true);
         if (addon_installed('unvalidated')) {
             send_validation_request('COMCODE_PAGE_EDIT', 'comcode_pages', true, $zone . ':' . $new_file, $edit_url);
         }
     }
     $new = post_param('post');
     require_code('attachments2');
     $_new = do_comcode_attachments($new, 'comcode_page', $zone . ':' . $file);
     $new = $_new['comcode'];
     if (!file_exists($fullpath) || $new != file_get_contents($fullpath, FILE_TEXT)) {
         $myfile = @fopen($fullpath, 'wt');
         if ($myfile === false) {
             intelligent_write_error($fullpath);
         }
         final_attachments_from_preview($zone . ':' . $file);
         if (fwrite($myfile, $new) < strlen($new)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         sync_file($fullpath);
         $file_changed = true;
     } else {
         $file_changed = false;
     }
     require_code('seo2');
     $new_keywords = post_param('meta_keywords', '');
     $new_description = post_param('meta_description', '');
     if ($new_keywords == '' && $new_description == '') {
         seo_meta_set_for_implicit('comcode_page', $zone . ':' . $file, array($new), $new);
     } else {
         seo_meta_set_for_explicit('comcode_page', $zone . ':' . $file, $new_keywords, $new_description);
     }
     $completion_text = $validated == 0 ? do_lang_tempcode('SUBMIT_UNVALIDATED') : do_lang_tempcode('SUCCESS');
     // Update cache  NO WE CAN'T - THEY'RE MULTI-THEME NOW
     /*	$string_index=$GLOBALS['SITE_DB']->query_value_null_ok('cached_comcode_pages','string_index',array('the_zone'=>$zone,'the_page'=>$file));
     		if (!is_null($string_index))
     		{
     			lang_remap_comcode($string_index,$new);
     		} else
     		{
     			$string_index=insert_lang_comcode($new,1,NULL,false,NULL,NULL,false,NULL,NULL,60,true,true);
     			$GLOBALS['SITE_DB']->query_insert('cached_comcode_pages',array('the_zone'=>$zone,'the_page'=>$file,'string_index'=>$string_index));
     		}*/
     require_code('permissions2');
     set_page_permissions_from_environment($zone, $file);
     $caches = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => $zone, 'the_page' => $file));
     $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => $zone, 'the_page' => $file));
     foreach ($caches as $cache) {
         delete_lang($cache['string_index']);
     }
     persistant_cache_empty();
     persistant_cache_delete(array('PAGE_INFO'));
     decache('main_comcode_page_children');
     fix_permissions($fullpath);
     if (is_file($fullpath) && get_option('store_revisions') == '1' && $file_changed) {
         $time = time();
         @copy($fullpath, $fullpath . '.' . strval($time)) or intelligent_write_error($fullpath . '.' . strval($time));
         fix_permissions($fullpath . '.' . strval($time));
         sync_file($fullpath . '.' . strval($time));
     }
     log_it('COMCODE_PAGE_EDIT', $file, $zone);
     require_code('autosave');
     clear_ocp_autosave();
     if ($renaming_page) {
         $GLOBALS['SITE_DB']->query_delete('comcode_pages', array('the_zone' => $zone, 'the_page' => $new_file), '', 1);
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('the_page' => $new_file), array('the_zone' => $zone, 'the_page' => $file), '', 1);
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('p_parent_page' => $new_file), array('the_zone' => $zone, 'p_parent_page' => $file));
         foreach ($rename_map as $path => $new_path) {
             if ($afm_needed) {
                 afm_move($path, $new_path);
             } else {
                 rename(get_custom_file_base() . '/' . $path, get_custom_file_base() . '/' . $new_path);
             }
         }
         if (addon_installed('awards')) {
             $types = $GLOBALS['SITE_DB']->query_select('award_types', array('id'), array('a_content_type' => 'comcode_page'));
             foreach ($types as $type) {
                 $GLOBALS['SITE_DB']->query_update('award_archive', array('content_id' => $new_file), array('content_id' => $file, 'a_type_id' => $type['id']));
             }
         }
         $file = $new_file;
     }
     if (post_param_integer('delete', 0) == 1) {
         unlink(get_custom_file_base() . '/' . $path);
     }
     if (addon_installed('awards')) {
         require_code('awards');
         handle_award_setting('comcode_page', $zone . ':' . $file);
     }
     decache('main_sitemap');
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     // Look for bad title semantics
     $_new['html'] = $_new['tempcode']->evaluate();
     if (substr($file, 0, 1) != '_' && substr($file, 0, 6) != 'panel_' && trim($_new['html']) != '') {
         if (strpos($_new['html'], '<h1') === false && strpos($_new['comcode'], '[title]') === false && strpos($_new['comcode'], '[title="1"]') === false) {
             attach_message(do_lang_tempcode('NO_LEVEL_1_HEADERS'), 'notice');
         }
         $matches = array();
         if (strpos($_new['html'], '<h2') === false && preg_match_all('#\\n\\[(b|font|size)\\][^\\.]+\\[/(b|font|size)\\]\\n#', $_new['comcode'], $matches) >= 2) {
             attach_message(do_lang_tempcode('NO_LEVEL_2_HEADERS'), 'inform');
         }
     }
     // Show it worked / Refresh
     $url = post_param('redirect', '');
     if ($url != '') {
         return redirect_screen($title, $url, $completion_text);
     }
     return $this->do_next_manager($title, $file, $zone, $completion_text);
 }
Esempio n. 7
0
/**
 * Build up a preview based on what was submitted.
 *
 * @param  boolean	Whether to return additional data
 * @return mixed		Either tempcode for the preview, or a tuple of details
 */
function build_preview($multi_return = false)
{
    // Check CAPTCHA if it is passed
    if (addon_installed('captcha')) {
        if (array_key_exists('post', $_POST) && $_POST['post'] != '' && array_key_exists('security_image', $_POST)) {
            require_code('captcha');
            enforce_captcha(false);
        }
    }
    require_code('attachments2');
    $hooks = find_all_hooks('systems', 'preview');
    $output = NULL;
    $new_post_value = NULL;
    $attachment_type = NULL;
    $forum_db = false;
    $limit_to = NULL;
    foreach (array_keys($hooks) as $hook) {
        require_code('hooks/systems/preview/' . $hook);
        $object = object_factory('Hook_Preview_' . $hook, true);
        if (is_null($object)) {
            continue;
        }
        $apply_bits = $object->applies();
        $applies = $apply_bits[0];
        if ($applies) {
            $attachment_type = $apply_bits[1];
            $forum_db = array_key_exists(2, $apply_bits) ? $apply_bits[2] : false;
            $limit_to = array_key_exists(3, $apply_bits) ? $apply_bits[3] : NULL;
            if (method_exists($object, 'run')) {
                list($output, $new_post_value) = $object->run();
            }
            break;
        }
    }
    $validation = new ocp_tempcode();
    $keyword_density = new ocp_tempcode();
    $spelling = new ocp_tempcode();
    $meta_keywords = post_param('meta_keywords', '');
    $spellcheck = post_param_integer('perform_spellcheck', 0) == 1;
    $keywordcheck = post_param_integer('perform_keywordcheck', 0) == 1 && $meta_keywords != '';
    if (post_param_integer('perform_validation', 0) != 0) {
        foreach ($_POST as $key => $val) {
            if (!is_string($val)) {
                continue;
            }
            $val = post_param($key, '');
            // stripslashes, and wysiwyg output handling
            $tempcodecss = post_param_integer('tempcodecss__' . $key, 0) == 1;
            $supports_comcode = post_param_integer('comcode__' . $key, 0) == 1;
            if ($supports_comcode) {
                $temp = $_FILES;
                $_FILES = array();
                $valt = comcode_to_tempcode($val);
                $_FILES = $temp;
                require_code('view_modes');
                require_code('obfuscate');
                require_code('validation');
                $validation->attach(do_xhtml_validation($valt->evaluate(), false, post_param_integer('perform_validation', 0), true));
            } elseif ($tempcodecss) {
                $i = 0;
                $color = post_param(strval($i), '');
                while ($color != '') {
                    $val = str_replace('<color-' . strval($i) . '>', '#' . $color, $val);
                    $i++;
                    $color = post_param(strval($i), '');
                }
                $_val_orig = $val;
                require_lang('validation');
                require_css('adminzone');
                require_code('view_modes');
                require_code('obfuscate');
                require_code('validation');
                require_code('validation2');
                $error = check_css($_val_orig);
                $show = count($error['errors']) != 0;
                if ($show) {
                    $validation->attach(display_validation_results($_val_orig, $error, true, true));
                }
            }
        }
    }
    if ($spellcheck) {
        if (addon_installed('wordfilter')) {
            $words_skip = collapse_1d_complexity('w_replacement', $GLOBALS['SITE_DB']->query_select('wordfilter', array('w_replacement')));
        } else {
            $words_skip = array();
        }
        require_once get_file_base() . '/data/areaedit/plugins/SpellChecker/spell-check-logic.php';
    }
    $db = $forum_db ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
    $view_space_map = array();
    require_code('templates_view_space');
    foreach ($_POST as $key => $val) {
        if (!is_string($val)) {
            continue;
        }
        if (!is_null($limit_to) && !in_array($key, $limit_to)) {
            continue;
        }
        $val = post_param($key, '');
        // stripslashes, and wysiwyg output handling
        if ($val == '0') {
            $val = do_lang('NO');
        }
        if ($val == '1') {
            $val = do_lang('YES');
        }
        if (substr($key, 0, 14) == 'review_rating' || substr($key, 0, 7) == 'rating') {
            $val .= '/10';
        }
        $is_hidden = in_array($key, array('from_url', 'password', 'confirm_password', 'edit_password', 'MAX_FILE_SIZE', 'perform_validation', '_validated', 'id', 'posting_ref_id', 'f_face', 'f_colour', 'f_size', 'http_referer')) || strpos($key, 'hour') !== false || strpos($key, 'access_') !== false || strpos($key, 'minute') !== false || strpos($key, 'confirm') !== false || strpos($key, 'pre_f_') !== false || strpos($key, 'label_for__') !== false || strpos($key, 'wysiwyg_version_of_') !== false || strpos($key, 'is_wysiwyg') !== false || strpos($key, 'require__') !== false || strpos($key, 'tempcodecss__') !== false || strpos($key, 'comcode__') !== false || strpos($key, '_parsed') !== false || preg_match('#^caption\\d+$#', $key) != 0 || preg_match('#^attachmenttype\\d+$#', $key) != 0 || substr($key, 0, 1) == '_' || substr($key, 0, 9) == 'hidFileID' || substr($key, 0, 11) == 'hidFileName';
        if (substr($key, 0, 14) == 'tick_on_form__') {
            if (post_param_integer(substr($key, 14), 0) == 1) {
                $is_hidden = true;
            } else {
                $key = substr($key, 14);
            }
        }
        if (substr($key, -4) == '_day') {
            $key = substr($key, 0, strlen($key) - 4);
            $timestamp = get_input_date($key);
            if (is_null($timestamp)) {
                $is_hidden = true;
            } else {
                $val = get_timezoned_date($timestamp, false, true, false, true);
            }
        } elseif (substr($key, -6) == '_month' || substr($key, -5) == '_year') {
            $is_hidden = true;
        }
        $key_nice = post_param('label_for__' . $key, ucwords(str_replace('_', ' ', $key)));
        if ($key_nice == '') {
            $is_hidden = true;
        }
        if (!$is_hidden) {
            if ($spellcheck) {
                require_code('comcode_from_html');
                $mispellings = spellchecklogic('check', strip_comcode(semihtml_to_comcode($val, true)), $words_skip, true);
                $_misspellings = array();
                foreach ($mispellings as $misspelling) {
                    list($word_bad, $words_good) = $misspelling;
                    $_misspellings[] = array('WORD' => $word_bad, 'CORRECTIONS' => implode(', ', $words_good));
                }
                if (count($_misspellings) != 0) {
                    $spelling->attach(do_template('PREVIEW_SCRIPT_SPELLING', array('_GUID' => '9649572982c01995a8f47c58d16fda39', 'FIELD' => $key_nice, 'MISSPELLINGS' => $_misspellings)));
                }
            }
            if ($keywordcheck && (strpos($val, ' ') !== false || $key == 'title')) {
                $keyword_explode = explode(',', $meta_keywords);
                $keywords = array();
                $word_count = str_word_count($val);
                if ($word_count != 0) {
                    foreach ($keyword_explode as $meta_keyword) {
                        $meta_keyword = trim($meta_keyword);
                        if ($meta_keyword != '') {
                            $density = substr_count($val, $meta_keyword) / $word_count;
                            $ideal_density = 1.0 / (9.0 * count($keyword_explode));
                            // Pretty rough -- common sense is needed
                            $keywords[] = array('sort' => $ideal_density, 'KEYWORD' => $meta_keyword, 'IDEAL_DENSITY' => strval(intval(round($ideal_density * 100))), 'DENSITY' => strval(intval(round($density * 100))));
                        }
                    }
                    global $M_SORT_KEY;
                    $M_SORT_KEY = 'sort';
                    usort($keywords, 'multi_sort');
                    foreach ($keywords as $ti => $meta_keyword) {
                        unset($keywords[$ti]['sort']);
                    }
                    if (count($keywords) != 0) {
                        $keyword_density->attach(do_template('PREVIEW_SCRIPT_KEYWORD_DENSITY', array('_GUID' => '4fa05e9f52023958a3594d1610b00747', 'FIELD' => $key_nice, 'KEYWORDS' => $keywords)));
                    }
                }
            }
        }
        if (is_null($output)) {
            if (is_null($attachment_type) || $key != 'post') {
                $tempcodecss = post_param_integer('tempcodecss__' . $key, 0) == 1;
                $supports_comcode = post_param_integer('comcode__' . $key, 0) == 1;
                $preformatted = post_param_integer('pre_f_' . $key, 0) == 1;
                if ($is_hidden) {
                    continue;
                }
                if ($preformatted) {
                    $valt = with_whitespace($val);
                } elseif ($supports_comcode) {
                    $valt = comcode_to_tempcode($val);
                } elseif ($tempcodecss) {
                    $i = 0;
                    $color = post_param(strval($i), '');
                    while ($color != '') {
                        $val = str_replace('<color-' . strval($i) . '>', '#' . $color, $val);
                        $i++;
                        $color = post_param(strval($i), '');
                    }
                    $_val_orig = $val;
                    $valt = comcode_to_tempcode("[code=\"CSS\"]" . $val . "[/code]");
                } else {
                    $valt = make_string_tempcode(escape_html($val));
                }
                $view_space_map[$key_nice] = $valt;
            } else {
                $tempcodecss = false;
                $posting_ref_id = post_param_integer('posting_ref_id');
                if ($posting_ref_id < 0) {
                    fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
                }
                $post_bits = do_comcode_attachments($val, $attachment_type, strval(-$posting_ref_id), true, $db);
                $new_post_value = $post_bits['comcode'];
                $view_space_map[$key_nice] = $post_bits['tempcode'];
                $val = $post_bits['tempcode'];
                $supports_comcode = true;
            }
        }
    }
    // Make attachments temporarily readable without any permission context
    global $COMCODE_ATTACHMENTS;
    $posting_ref_id = post_param_integer('posting_ref_id', NULL);
    if (!is_null($posting_ref_id)) {
        if (array_key_exists(strval(-$posting_ref_id), $COMCODE_ATTACHMENTS)) {
            foreach ($COMCODE_ATTACHMENTS[strval(-$posting_ref_id)] as $attachment) {
                $db->query_delete('attachment_refs', array('r_referer_type' => 'null', 'r_referer_id' => strval(-$posting_ref_id), 'a_id' => $attachment['id']), '', 1);
                $db->query_insert('attachment_refs', array('r_referer_type' => 'null', 'r_referer_id' => strval(-$posting_ref_id), 'a_id' => $attachment['id']));
            }
        }
    }
    if (is_null($output)) {
        if (count($view_space_map) == 1) {
            $output = array_pop($view_space_map);
        } else {
            $view_space_fields = new ocp_tempcode();
            foreach ($view_space_map as $key => $val) {
                $view_space_fields->attach(view_space_field($key, $val, true));
            }
            $output = do_template('VIEW_SPACE', array('_GUID' => '3f548883b9eb37054c500d1088d9efa3', 'WIDTH' => '170', 'FIELDS' => $view_space_fields));
        }
    }
    // This is to get the Comcode attachments updated to the new IDs
    if (!is_null($new_post_value)) {
        $new_post_value_html = comcode_to_tempcode($new_post_value, NULL, false, 60, NULL, $db, true);
        if (strpos($new_post_value_html->evaluate(), '<!-- CC-error -->') === false) {
            $output->attach(do_template('PREVIEW_SCRIPT_CODE', array('_GUID' => 'bc7432af91e1eaf212dc210f3bf2f756', 'NEW_POST_VALUE_HTML' => $new_post_value_html, 'NEW_POST_VALUE' => $new_post_value)));
        }
    }
    $output->handle_symbol_preprocessing();
    if ($multi_return) {
        return array($output, $validation, $keyword_density, $spelling);
    }
    return $output;
}
Esempio n. 8
0
/**
 * Load Comcode page from disk.
 *
 * @param  PATH			The relative (to ocPortal's base directory) path to the page (e.g. pages/comcode/EN/start.txt)
 * @param  ID_TEXT		The zone the page is being loaded from
 * @param  ID_TEXT		The codename of the page
 * @param  PATH			The file base to load from
 * @param  array			New row for database, used if nesessary (holds submitter etc)
 * @param  boolean		Whether the page is being included from another
 * @return array			A tuple: The page, New Comcode page row, Title
 */
function _load_comcode_page_cache_off($string, $zone, $codename, $file_base, $new_comcode_page_row, $being_included = false)
{
    global $COMCODE_PARSE_TITLE;
    if (is_null($new_comcode_page_row['p_submitter'])) {
        $as_admin = true;
        $members = $GLOBALS['FORUM_DRIVER']->member_group_query($GLOBALS['FORUM_DRIVER']->get_super_admin_groups(), 1);
        if (count($members) != 0) {
            $new_comcode_page_row['p_submitter'] = $GLOBALS['FORUM_DRIVER']->pname_id($members[key($members)]);
        } else {
            $new_comcode_page_row['p_submitter'] = db_get_first_id() + 1;
            // On OCF and most forums, this is the first admin member
        }
    }
    $_comcode_page_row = $GLOBALS['SITE_DB']->query_select('comcode_pages', array('*'), array('the_zone' => $zone, 'the_page' => $codename), '', 1);
    global $LAX_COMCODE;
    $temp = $LAX_COMCODE;
    $LAX_COMCODE = true;
    require_code('attachments2');
    $_new = do_comcode_attachments(file_get_contents($file_base . '/' . $string, FILE_TEXT), 'comcode_page', $zone . ':' . $codename, false, NULL, !array_key_exists(0, $_comcode_page_row) || is_guest($_comcode_page_row[0]['p_submitter']), array_key_exists(0, $_comcode_page_row) ? $_comcode_page_row[0]['p_submitter'] : get_member());
    $html = $_new['tempcode'];
    $LAX_COMCODE = $temp;
    $title_to_use = is_null($COMCODE_PARSE_TITLE) ? NULL : clean_html_title($COMCODE_PARSE_TITLE);
    // Try and insert corresponding page; will silently fail if already exists. This is only going to add a row for a page that was not created in-system
    if (array_key_exists(0, $_comcode_page_row)) {
        $comcode_page_row = $_comcode_page_row[0];
    } else {
        $comcode_page_row = $new_comcode_page_row;
        $GLOBALS['SITE_DB']->query_insert('comcode_pages', $comcode_page_row, false, true);
    }
    return array($html, $comcode_page_row, $title_to_use);
}