/** * Add a calendar event. * * @param AUTO_LINK The event type * @param SHORT_TEXT The recurrence code (set to 'none' for no recurrences: blank means infinite and will basically time-out ocPortal) * @param ?integer The number of recurrences (NULL: none/infinite) * @param BINARY Whether to segregate the comment-topics/rating/trackbacks per-recurrence * @param SHORT_TEXT The title of the event * @param LONG_TEXT The full text describing the event * @param integer The priority * @range 1 5 * @param BINARY Whether it is a public event * @param ?integer The year the event starts at (NULL: default) * @param ?integer The month the event starts at (NULL: default) * @param ?integer The day the event starts at (NULL: default) * @param ?integer The hour the event starts at (NULL: default) * @param ?integer The minute the event starts at (NULL: default) * @param ?integer The year the event ends at (NULL: not a multi day event) * @param ?integer The month the event ends at (NULL: not a multi day event) * @param ?integer The day the event ends at (NULL: not a multi day event) * @param ?integer The hour the event ends at (NULL: not a multi day event) * @param ?integer The minute the event ends at (NULL: not a multi day event) * @param ?ID_TEXT The timezone for the event (NULL: current user's timezone) * @param BINARY Whether the time should be presented in the viewer's own timezone * @param BINARY Whether the event has been validated * @param BINARY Whether the event may be rated * @param SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) * @param BINARY Whether the event may be trackbacked * @param LONG_TEXT Hidden notes pertaining to the download * @param ?MEMBER The event submitter (NULL: current member) * @param integer The number of views so far * @param ?TIME The add time (NULL: now) * @param ?TIME The edit time (NULL: never) * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @return AUTO_LINK The ID of the event */ function add_calendar_event($type, $recurrence, $recurrences, $seg_recurrences, $title, $content, $priority, $is_public, $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year = NULL, $end_month = NULL, $end_day = NULL, $end_hour = NULL, $end_minute = NULL, $timezone = NULL, $do_timezone_conv = 1, $validated = 1, $allow_rating = 1, $allow_comments = 1, $allow_trackbacks = 1, $notes = '', $submitter = NULL, $views = 0, $add_date = NULL, $edit_date = NULL, $id = NULL) { if (is_null($submitter)) { $submitter = get_member(); } if (is_null($add_date)) { $add_date = time(); } if (is_null($timezone)) { $timezone = get_users_timezone(); } require_code('comcode_check'); check_comcode($content, NULL, false, NULL, true); if (!addon_installed('unvalidated')) { $validated = 1; } $map = array('e_submitter' => $submitter, 'e_views' => $views, 'e_title' => insert_lang($title, 2), 'e_content' => 0, 'e_add_date' => $add_date, 'e_edit_date' => $edit_date, 'e_recurrence' => $recurrence, 'e_recurrences' => $recurrences, 'e_seg_recurrences' => $seg_recurrences, 'e_start_year' => $start_year, 'e_start_month' => $start_month, 'e_start_day' => $start_day, 'e_start_hour' => $start_hour, 'e_start_minute' => $start_minute, 'e_end_year' => $end_year, 'e_end_month' => $end_month, 'e_end_day' => $end_day, 'e_end_hour' => $end_hour, 'e_end_minute' => $end_minute, 'e_timezone' => $timezone, 'e_do_timezone_conv' => $do_timezone_conv, 'e_is_public' => $is_public, 'e_priority' => $priority, 'e_type' => $type, 'validated' => $validated, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'allow_trackbacks' => $allow_trackbacks, 'notes' => $notes); if (!is_null($id)) { $map['id'] = $id; } $id = $GLOBALS['SITE_DB']->query_insert('calendar_events', $map, true); require_code('attachments2'); $GLOBALS['SITE_DB']->query_update('calendar_events', array('e_content' => insert_lang_comcode_attachments(3, $content, 'calendar', strval($id))), array('id' => $id), '', 1); require_code('seo2'); seo_meta_set_for_implicit('event', strval($id), array($title, $content), $content); decache('side_calendar'); if ($validated == 1) { require_lang('calendar'); require_code('notifications'); $subject = do_lang('CALENDAR_EVENT_NOTIFICATION_MAIL_SUBJECT', get_site_name(), strip_comcode($title)); $self_url = build_url(array('page' => 'calendar', 'type' => 'view', 'id' => $id), get_module_zone('calendar'), NULL, false, false, true); $mail = do_lang('CALENDAR_EVENT_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($title), array($self_url->evaluate())); dispatch_notification('calendar_event', strval($type), $subject, $mail); } log_it('ADD_CALENDAR_EVENT', strval($id), $title); return $id; }
/** * Add a gallery with the specified parameters. * * @param ID_TEXT The gallery codename * @param SHORT_TEXT The full human-readeable name of the gallery * @param LONG_TEXT The description of the gallery * @param SHORT_TEXT Teaser text for the gallery * @param LONG_TEXT Hidden notes associated with the gallery * @param ID_TEXT The parent gallery (blank: no parent) * @param BINARY Whether images may be put in this gallery * @param BINARY Whether videos may be put in this gallery * @param BINARY Whether the gallery serves as a container for automatically created member galleries * @param BINARY Whether the gallery uses the flow mode interface * @param URLPATH The representative image of the gallery (blank: none) * @param URLPATH Watermark (blank: none) * @param URLPATH Watermark (blank: none) * @param URLPATH Watermark (blank: none) * @param URLPATH Watermark (blank: none) * @param BINARY Whether rating are allowed * @param BINARY Whether comments are allowed * @param boolean Whether to skip the check for whether the gallery exists (useful for importers) * @param ?TIME The add time (NULL: now) * @param ?MEMBER The gallery owner (NULL: nobody) */ function add_gallery($name, $fullname, $description, $teaser, $notes, $parent_id, $accept_images = 1, $accept_videos = 1, $is_member_synched = 0, $flow_mode_interface = 0, $rep_image = '', $watermark_top_left = '', $watermark_top_right = '', $watermark_bottom_left = '', $watermark_bottom_right = '', $allow_rating = 1, $allow_comments = 1, $skip_exists_check = false, $add_date = NULL, $g_owner = NULL) { if (is_null($add_date)) { $add_date = time(); } require_code('type_validation'); if (!is_alphanumeric($name, true)) { warn_exit(do_lang_tempcode('BAD_CODENAME')); } if (!$skip_exists_check) { $test = $GLOBALS['SITE_DB']->query_value_null_ok('galleries', 'name', array('name' => $name)); if (!is_null($test)) { warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($name))); } } $GLOBALS['SITE_DB']->query_insert('galleries', array('name' => $name, 'add_date' => $add_date, 'description' => insert_lang_comcode($description, 2), 'teaser' => insert_lang_comcode($teaser, 2), 'notes' => $notes, 'fullname' => insert_lang($fullname, 1), 'watermark_top_left' => $watermark_top_left, 'watermark_top_right' => $watermark_top_right, 'watermark_bottom_left' => $watermark_bottom_left, 'watermark_bottom_right' => $watermark_bottom_right, 'parent_id' => $parent_id, 'accept_images' => $accept_images, 'rep_image' => $rep_image, 'accept_videos' => $accept_videos, 'is_member_synched' => $is_member_synched, 'flow_mode_interface' => $flow_mode_interface, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'g_owner' => $g_owner, 'gallery_views' => 0)); log_it('ADD_GALLERY', $name, $fullname); require_code('seo2'); seo_meta_set_for_implicit('gallery', $name, array($fullname, $description), $description); if (function_exists('decache')) { decache('main_top_galleries'); decache('main_recent_galleries'); decache('main_root_galleries'); decache('side_root_galleries'); } }
/** * Add a download. * * @param AUTO_LINK The ID of the category the download is to be in * @param SHORT_TEXT The name of the download * @param URLPATH The URL to the download * @param LONG_TEXT The description of the download * @param ID_TEXT The author of the download (not necessarily same as the submitter) * @param LONG_TEXT The comments for the download * @param ?AUTO_LINK The out-mode-id (the ID of a download that this download is an old version of). Often people wonder why this is specified with the old version, and not the opposite with the new version - it is because statistically, we perceive more chance of downloads merging than splitting (NULL: none) * @param BINARY Whether the download has been validated * @param BINARY Whether the download may be rated * @param SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) * @param BINARY Whether the download may be trackbacked * @param LONG_TEXT Hidden notes pertaining to the download * @param SHORT_TEXT The downloads original filename (the URL may be obfuscated) * @param integer The file size of the download (we can't really detect this in real-time for remote URLs) * @param integer The cost of the download that members will have to pay to get it * @param BINARY Whether the submitter gets the points for the download (they are selling it) (otherwise they are just thrown out, which is an alternative model - one of enforcing community point building) * @param ?AUTO_LINK The licence to use (NULL: none) * @param ?TIME The add date for the download (NULL: now) * @param integer The number of downloads that this download has had * @param integer The number of views that this download has had * @param ?MEMBER The submitter (NULL: current user) * @param ?TIME The edit date (NULL: never) * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @return AUTO_LINK The ID of the newly added download */ function add_download($category_id, $name, $url, $description, $author, $comments, $out_mode_id, $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $original_filename, $file_size, $cost, $submitter_gets_points, $licence = NULL, $add_date = NULL, $num_downloads = 0, $views = 0, $submitter = NULL, $edit_date = NULL, $id = NULL) { if (is_null($add_date)) { $add_date = time(); } if (is_null($submitter)) { $submitter = get_member(); } if ($file_size == 0 || url_is_local($url)) { if (url_is_local($url)) { $file_size = @filesize(get_custom_file_base() . '/' . rawurldecode($url)) or $file_size = NULL; } else { $file_size = @filesize($url) or $file_size = NULL; } } $met = @ini_get('max_execution_time'); $data_mash = $url == '' ? '' : create_data_mash($url, NULL, get_file_extension($original_filename)); if (function_exists('set_time_limit')) { @set_time_limit($met); } if (!addon_installed('unvalidated')) { $validated = 1; } $map = array('download_data_mash' => $data_mash, 'download_licence' => $licence, 'rep_image' => '', 'edit_date' => $edit_date, 'download_submitter_gets_points' => $submitter_gets_points, 'download_cost' => $cost, 'original_filename' => $original_filename, 'download_views' => $views, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'allow_trackbacks' => $allow_trackbacks, 'notes' => $notes, 'submitter' => $submitter, 'default_pic' => 1, 'num_downloads' => $num_downloads, 'out_mode_id' => $out_mode_id, 'category_id' => $category_id, 'name' => insert_lang($name, 2), 'url' => $url, 'description' => insert_lang_comcode($description, 3), 'author' => $author, 'comments' => insert_lang_comcode($comments, 3), 'validated' => $validated, 'add_date' => $add_date, 'file_size' => $file_size); if (!is_null($id)) { $map['id'] = $id; } $id = $GLOBALS['SITE_DB']->query_insert('download_downloads', $map, true); require_code('seo2'); seo_meta_set_for_implicit('downloads_download', strval($id), array($name, $description, $comments), $description); // Make its gallery if (addon_installed('galleries') && !running_script('stress_test_loader')) { $test = $GLOBALS['SITE_DB']->query_value_null_ok('galleries', 'name', array('name' => 'download_' . strval($id))); if (is_null($test)) { require_code('galleries2'); $download_gallery_root = get_option('download_gallery_root'); if (is_null($download_gallery_root)) { $download_gallery_root = 'root'; } add_gallery('download_' . strval($id), do_lang('GALLERY_FOR_DOWNLOAD', $name), '', '', '', $download_gallery_root); } } // Stat update_stat('num_archive_downloads', 1); if ($file_size > 0) { update_stat('archive_size', $file_size); } if ($validated == 1) { require_lang('downloads'); require_code('notifications'); $subject = do_lang('DOWNLOAD_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $name); $self_url = build_url(array('page' => 'downloads', 'type' => 'entry', 'id' => $id), get_module_zone('downloads'), NULL, false, false, true); $mail = do_lang('DOWNLOAD_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($name), array(comcode_escape($self_url->evaluate()))); dispatch_notification('download', strval($category_id), $subject, $mail); } log_it('ADD_DOWNLOAD', strval($id), $name); decache('main_recent_downloads'); decache('main_top_downloads'); decache('main_download_category'); decache('main_download_tease'); return $id; }
/** * Add a CEDI page * * @param SHORT_TEXT The page title * @param LONG_TEXT The page description * @param LONG_TEXT Hidden notes pertaining to the page * @param BINARY Whether to hide the posts on the page by default * @param ?MEMBER The member doing the action (NULL: current member) * @return AUTO_LINK The page ID */ function cedi_add_page($title, $description, $notes, $hide_posts, $member = NULL) { if (is_null($member)) { $member = get_member(); } require_code('comcode_check'); check_comcode($description, NULL, false, NULL, true); if ($description != '') { $id = $GLOBALS['SITE_DB']->query_insert('seedy_pages', array('submitter' => $member, 'hide_posts' => $hide_posts, 'seedy_views' => 0, 'notes' => $notes, 'description' => 0, 'title' => insert_lang($title, 2), 'add_date' => time()), true); require_code('attachments2'); $GLOBALS['SITE_DB']->query_update('seedy_pages', array('description' => insert_lang_comcode_attachments(2, $description, 'cedi_page', strval($id), NULL, false, $member)), array('id' => $id), '', 1); } else { $id = $GLOBALS['SITE_DB']->query_insert('seedy_pages', array('submitter' => $member, 'hide_posts' => $hide_posts, 'seedy_views' => 0, 'notes' => $notes, 'description' => insert_lang($description, 2), 'title' => insert_lang($title, 2), 'add_date' => time()), true); } update_stat('num_seedy_pages', 1); $GLOBALS['SITE_DB']->query_insert('seedy_changes', array('the_action' => 'CEDI_ADD_PAGE', 'the_page' => $id, 'date_and_time' => time(), 'ip' => get_ip_address(), 'the_user' => $member)); require_code('seo2'); seo_meta_set_for_implicit('seedy_page', strval($id), array($title, $description), $description); dispatch_cedi_page_notification($id, 'ADD'); return $id; }
/** * Adds a news entry to the database, and send out the news to any RSS cloud listeners. * * @param SHORT_TEXT The news title * @param LONG_TEXT The news summary (or if not an article, the full news) * @param ?ID_TEXT The news author (possibly, a link to an existing author in the system, but does not need to be) (NULL: current username) * @param BINARY Whether the news has been validated * @param BINARY Whether the news may be rated * @param SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) * @param BINARY Whether the news may have trackbacks * @param LONG_TEXT Notes for the news * @param LONG_TEXT The news entry (blank means no entry) * @param ?AUTO_LINK The primary news category (NULL: personal) * @param ?array The IDs of the news categories that this is in (NULL: none) * @param ?TIME The time of submission (NULL: now) * @param ?MEMBER The news submitter (NULL: current member) * @param integer The number of views the article has had * @param ?TIME The edit date (NULL: never) * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @param URLPATH URL to the image for the news entry (blank: use cat image) * @return AUTO_LINK The ID of the news just added */ function add_news($title, $news, $author = NULL, $validated = 1, $allow_rating = 1, $allow_comments = 1, $allow_trackbacks = 1, $notes = '', $news_article = '', $main_news_category = NULL, $news_category = NULL, $time = NULL, $submitter = NULL, $views = 0, $edit_date = NULL, $id = NULL, $image = '') { if (is_null($author)) { $author = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); } if (is_null($news_category)) { $news_category = array(); } if (is_null($time)) { $time = time(); } if (is_null($submitter)) { $submitter = get_member(); } $already_created_personal_category = false; require_code('comcode_check'); check_comcode($news_article, NULL, false, NULL, true); if (is_null($main_news_category)) { $main_news_category_id = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'id', array('nc_owner' => $submitter)); if (is_null($main_news_category_id)) { if (!has_specific_permission(get_member(), 'have_personal_category', 'cms_news')) { fatal_exit(do_lang_tempcode('INTERNAL_ERROR')); } $p_nc_title = insert_lang(do_lang('MEMBER_CATEGORY', $GLOBALS['FORUM_DRIVER']->get_username($submitter)), 2); $main_news_category_id = $GLOBALS['SITE_DB']->query_insert('news_categories', array('nc_title' => $p_nc_title, 'nc_img' => 'newscats/community', 'notes' => '', 'nc_owner' => $submitter), true); $already_created_personal_category = true; $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'news', 'category_name' => strval($main_news_category_id), 'group_id' => $group_id)); } } } else { $main_news_category_id = $main_news_category; } if (!addon_installed('unvalidated')) { $validated = 1; } $map = array('news_image' => $image, 'edit_date' => $edit_date, 'news_category' => $main_news_category_id, 'news_views' => $views, 'news_article' => 0, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'allow_trackbacks' => $allow_trackbacks, 'notes' => $notes, 'submitter' => $submitter, 'validated' => $validated, 'date_and_time' => $time, 'title' => insert_lang_comcode($title, 1), 'news' => insert_lang_comcode($news, 1), 'author' => $author); if (!is_null($id)) { $map['id'] = $id; } $id = $GLOBALS['SITE_DB']->query_insert('news', $map, true); if (!is_null($news_category)) { $news_category = array_unique($news_category); foreach ($news_category as $value) { if (is_null($value) && !$already_created_personal_category) { $p_nc_title = insert_lang(do_lang('MEMBER_CATEGORY', $GLOBALS['FORUM_DRIVER']->get_username($submitter)), 2); $news_category_id = $GLOBALS['SITE_DB']->query_insert('news_categories', array('nc_title' => $p_nc_title, 'nc_img' => 'newscats/community', 'notes' => '', 'nc_owner' => $submitter), true); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'news', 'category_name' => strval($news_category_id), 'group_id' => $group_id)); } } else { $news_category_id = $value; } if (is_null($news_category_id)) { continue; } // Double selected $GLOBALS['SITE_DB']->query_insert('news_category_entries', array('news_entry' => $id, 'news_entry_category' => $news_category_id)); } } require_code('attachments2'); $map = array('news_article' => insert_lang_comcode_attachments(2, $news_article, 'news', strval($id))); $GLOBALS['SITE_DB']->query_update('news', $map, array('id' => $id), '', 1); log_it('ADD_NEWS', strval($id), $title); if (function_exists('xmlrpc_encode')) { if (function_exists('set_time_limit')) { @set_time_limit(0); } // Send out on RSS cloud $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'news_rss_cloud WHERE register_time<' . strval(time() - 25 * 60 * 60)); $start = 0; do { $listeners = $GLOBALS['SITE_DB']->query_select('news_rss_cloud', array('*'), NULL, '', 100, $start); foreach ($listeners as $listener) { $data = $listener['watching_channel']; if ($listener['rem_protocol'] == 'xml-rpc') { $request = xmlrpc_encode_request($listener['rem_procedure'], $data); $length = strlen($request); $_length = strval($length); $packet = <<<END POST /{$listener['rem_path']} HTTP/1.0 Host: {$listener['rem_ip']} Content-Type: text/xml Content-length: {$_length} {$request} END; } $errno = 0; $errstr = ''; $mysock = @fsockopen($listener['rem_ip'], $listener['rem_port'], $errno, $errstr, 6.0); if ($mysock !== false) { @fwrite($mysock, $packet); @fclose($mysock); } $start += 100; } } while (array_key_exists(0, $listeners)); } require_code('seo2'); seo_meta_set_for_implicit('news', strval($id), array($title, $news == '' ? $news_article : $news), $news == '' ? $news_article : $news); // News article could be used, but it's probably better to go for the summary only to avoid crap if ($validated == 1) { decache('main_news'); decache('side_news'); decache('side_news_archive'); decache('bottom_news'); dispatch_news_notification($id, $title, $main_news_category_id); } if ($validated == 1 && get_option('site_closed') == '0' && ocp_srv('HTTP_HOST') != '127.0.0.1' && ocp_srv('HTTP_HOST') != 'localhost' && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'news', strval($main_news_category_id))) { $_ping_url = str_replace('{url}', urlencode(get_base_url()), str_replace('{rss}', urlencode(find_script('backend') . '?type=rss&mode=news'), str_replace('{title}', urlencode(get_site_name()), get_option('ping_url')))); $ping_urls = explode(chr(10), $_ping_url); foreach ($ping_urls as $ping_url) { $ping_url = trim($ping_url); if ($ping_url != '') { http_download_file($ping_url, NULL, false); } } } return $id; }
/** * 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); }
/** * Adds an author (re-creating them if they already exist - thus it also serves to edit; the reason for this is the fluidity of authors - members are automatically authors even before an author profile is made) * * @param ID_TEXT The name of an author * @param URLPATH The URL to the authors home page * @param ?MEMBER The member ID of the author (NULL: no forum profile) * @param LONG_TEXT A description of the author * @param LONG_TEXT A terse string showing author skills * @param ?SHORT_TEXT Meta keywords for this resource (NULL: do not edit) (blank: implicit) * @param ?LONG_TEXT Meta description for this resource (NULL: do not edit) (blank: implicit) */ function add_author($author, $url, $forum_handle, $description, $skills, $meta_keywords = '', $meta_description = '') { log_it('DEFINE_AUTHOR', $author, is_null($forum_handle) ? '' : strval($forum_handle)); $rows = $GLOBALS['SITE_DB']->query_select('authors', array('description', 'skills'), array('author' => $author), '', 1); if (array_key_exists(0, $rows)) { delete_lang($rows[0]['description']); delete_lang($rows[0]['skills']); $GLOBALS['SITE_DB']->query_delete('authors', array('author' => $author), '', 1); } require_code('seo2'); if ($meta_keywords == '' && $meta_description == '') { seo_meta_set_for_implicit('authors', $author, array($author, $description, $skills), $description); } else { seo_meta_set_for_explicit('authors', $author, $meta_keywords, $meta_description); } $GLOBALS['SITE_DB']->query_insert('authors', array('author' => $author, 'url' => $url, 'forum_handle' => $forum_handle, 'description' => insert_lang_comcode($description, 3), 'skills' => insert_lang_comcode($skills, 3))); }
/** * Add a quiz. * * @param SHORT_TEXT The name of the quiz * @param ?integer The number of minutes allowed for completion (NULL: NA) * @param LONG_TEXT The text shown at the start of the quiz * @param LONG_TEXT The text shown at the end of the quiz * @param LONG_TEXT The text shown at the end of the quiz on failure * @param LONG_TEXT Notes * @param integer Percentage correctness required for competition * @param ?TIME The time the quiz is opened (NULL: now) * @param ?TIME The time the quiz is closed (NULL: never) * @param integer The number of winners for this if it is a competition * @param integer The minimum number of hours between attempts * @param ID_TEXT The type * @set SURVEY COMPETITION TEST * @param BINARY Whether this is validated * @param string Text for questions * @param ?MEMBER The member adding it (NULL: current member) * @param integer The number of points awarded for completing/passing the quiz/test * @param ?AUTO_LINK Newsletter for which a member must be on to enter (NULL: none) * @return AUTO_LINK The ID */ function add_quiz($name, $timeout, $start_text, $end_text, $end_text_fail, $notes, $percentage, $open_time, $close_time, $num_winners, $redo_time, $type, $validated, $text, $submitter = NULL, $points_for_passing = 0, $tied_newsletter = NULL) { if (is_null($submitter)) { $submitter = get_member(); } if (!addon_installed('unvalidated')) { $validated = 1; } $id = $GLOBALS['SITE_DB']->query_insert('quizzes', array('q_name' => insert_lang($name, 2), 'q_timeout' => $timeout, 'q_start_text' => insert_lang($start_text, 2), 'q_end_text' => insert_lang($end_text, 2), 'q_end_text_fail' => insert_lang($end_text_fail, 2), 'q_notes' => $notes, 'q_percentage' => $percentage, 'q_open_time' => $open_time, 'q_close_time' => $close_time, 'q_num_winners' => $num_winners, 'q_redo_time' => $redo_time, 'q_type' => $type, 'q_validated' => $validated, 'q_submitter' => $submitter, 'q_add_date' => time(), 'q_points_for_passing' => $points_for_passing, 'q_tied_newsletter' => $tied_newsletter), true); handle_quiz_answers($id, $text, $type); require_code('seo2'); seo_meta_set_for_implicit('quiz', strval($id), array($name, $start_text), $start_text); log_it('ADD_QUIZ', strval($id), $name); return $id; }
/** * Adds an entry to the specified catalogue. * * @param AUTO_LINK The ID of the category that the entry is in * @param BINARY Whether the entry has been validated * @param LONG_TEXT Hidden notes pertaining to the entry * @param BINARY Whether the entry may be rated * @param SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) * @param BINARY Whether the entry may be trackbacked * @param array A map of field IDs, to values, that defines the entries settings * @param ?TIME The time the entry was added (NULL: now) * @param ?MEMBER The entries submitter (NULL: current user) * @param ?TIME The edit time (NULL: never) * @param integer The number of views * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @return AUTO_LINK The ID of the newly added entry */ function actual_add_catalogue_entry($category_id, $validated, $notes, $allow_rating, $allow_comments, $allow_trackbacks, $map, $time = NULL, $submitter = NULL, $edit_date = NULL, $views = 0, $id = NULL) { if (is_null($time)) { $time = time(); } if (is_null($submitter)) { $submitter = get_member(); } $catalogue_name = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'c_name', array('id' => $category_id)); $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => $catalogue_name))); $_fields = list_to_map('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id', 'cf_type'), array('c_name' => $catalogue_name))); $fields = collapse_2d_complexity('id', 'cf_type', $_fields); require_code('comcode_check'); require_code('fields'); if (!addon_installed('unvalidated')) { $validated = 1; } $imap = array('c_name' => $catalogue_name, 'ce_edit_date' => $edit_date, 'cc_id' => $category_id, 'ce_last_moved' => time(), 'ce_submitter' => $submitter, 'ce_add_date' => $time, 'ce_views' => $views, 'ce_views_prior' => $views, 'ce_validated' => $validated, 'notes' => $notes, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'allow_trackbacks' => $allow_trackbacks); if (!is_null($id)) { $imap['id'] = $id; } $val = mixed(); foreach ($map as $field_id => $val) { $type = $fields[$field_id]; $ob = get_fields_hook($type); list($raw_type) = $ob->get_field_value_row_bits($_fields[$field_id]); if (strpos($raw_type, '_trans') !== false) { check_comcode($val); } } $id = $GLOBALS['SITE_DB']->query_insert('catalogue_entries', $imap, true); $title = NULL; foreach ($map as $field_id => $val) { if ($val == STRING_MAGIC_NULL) { $val = ''; } if (is_null($title)) { $title = $val; } $type = $fields[$field_id]; $ob = get_fields_hook($type); list($raw_type, , $sup_table_name) = $ob->get_field_value_row_bits($_fields[$field_id]); if (strpos($raw_type, '_trans') !== false) { if ($type == 'posting_field') { require_code('attachments2'); $val = insert_lang_comcode_attachments(3, $val, 'catalogue_entry', strval($id)); } else { $val = insert_lang_comcode($val, 3); } } if ($sup_table_name == 'short') { $val = substr($val, 0, 255); } if ($sup_table_name == 'float') { $smap = array('cf_id' => $field_id, 'ce_id' => $id, 'cv_value' => is_null($val) || $val == '' ? NULL : floatval($val)); } elseif ($sup_table_name == 'integer') { $smap = array('cf_id' => $field_id, 'ce_id' => $id, 'cv_value' => is_null($val) || $val == '' ? NULL : intval($val)); } elseif ($sup_table_name == 'short') { $smap = array('cf_id' => $field_id, 'ce_id' => $id, 'cv_value' => substr($val, 0, 255)); } else { $smap = array('cf_id' => $field_id, 'ce_id' => $id, 'cv_value' => $val); } $GLOBALS['SITE_DB']->query_insert('catalogue_efv_' . $sup_table_name, $smap); } require_code('seo2'); seo_meta_set_for_implicit('catalogue_entry', strval($id), $map, ''); calculate_category_child_count_cache($category_id); if ($catalogue_name[0] != '_') { if ($validated == 1) { require_lang('catalogues'); require_code('notifications'); $subject = do_lang('CATALOGUE_ENTRY_NOTIFICATION_MAIL_SUBJECT', get_site_name(), strip_comcode($title), array($catalogue_title)); $self_url = build_url(array('page' => 'catalogues', 'type' => 'entry', 'id' => $id), get_module_zone('catalogues'), NULL, false, false, true); $mail = do_lang('CATALOGUE_ENTRY_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape(strip_comcode($title)), array(comcode_escape($self_url->evaluate()), comcode_escape($catalogue_title))); dispatch_notification('catalogue_entry__' . $catalogue_name, strval($id), $subject, $mail); } log_it('ADD_CATALOGUE_ENTRY', strval($id), $title); } decache('main_cc_embed'); decache('main_recent_cc_entries'); return $id; }