/** * Get tempcode for a Comcode rich-media attachment. * * @param ID_TEXT The attachment tag * @set attachment attachment_safe attachment2 * @param array A map of the attributes (name=>val) for the tag * @param array A map of the attachment properties (name=>val) for the attachment * @param string A special identifier to mark where the resultant tempcode is going to end up (e.g. the ID of a post) * @param MEMBER The member who is responsible for this Comcode * @param boolean Whether to check as arbitrary admin * @param object The database connection to use * @param ?array A list of words to highlight (NULL: none) * @param ?MEMBER The member we are running on behalf of, with respect to how attachments are handled; we may use this members attachments that are already within this post, and our new attachments will be handed to this member (NULL: member evaluating) * @param boolean Whether to parse so as to create something that would fit inside a semihtml tag. It means we generate HTML, with Comcode written into it where the tag could never be reverse-converted (e.g. a block). * @return tempcode The tempcode for the attachment */ function render_attachment($tag, $attributes, $attachment, $pass_id, $source_member, $as_admin, $connection, $highlight_bits = NULL, $on_behalf_of_member = NULL, $semiparse_mode = false) { require_code('comcode_renderer'); $extension = get_file_extension($attachment['a_original_filename']); require_code('mime_types'); $mime_type = get_mime_type($extension); $attachment['CLEAN_SIZE'] = clean_file_size($attachment['a_file_size']); $attachment['MIME_TYPE'] = $mime_type; $attachment['PASS_ID'] = intval($pass_id) < 0 ? strval(mt_rand(0, 10000)) : $pass_id; $attachment['SCRIPT'] = find_script('attachment'); $attachment['RAND'] = strval(mt_rand(0, 32000)); if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) { $attachment['SUP_PARAMS'] = '&forum_db=1'; $attachment['FORUM_DB_BIN'] = '1'; } else { $attachment['SUP_PARAMS'] = ''; $attachment['FORUM_DB_BIN'] = ''; } $type = trim(array_key_exists('type', $attributes) ? $attributes['type'] : 'auto'); $attachment['id'] = strval($attachment['id']); $attachment['a_member_id'] = strval($attachment['a_member_id']); $attachment['a_file_size'] = strval($attachment['a_file_size']); $attachment['a_last_downloaded_time'] = is_null($attachment['a_last_downloaded_time']) ? '' : strval($attachment['a_last_downloaded_time']); $attachment['a_add_time'] = strval($attachment['a_add_time']); $attachment['a_num_downloads'] = integer_format($attachment['a_num_downloads']); require_code('images'); $attachment['a_width'] = array_key_exists('width', $attributes) ? strval(intval($attributes['width'])) : ''; $attachment['a_height'] = array_key_exists('height', $attributes) ? strval(intval($attributes['height'])) : ''; if ($attachment['a_width'] == '' || $attachment['a_height'] == '') { if (addon_installed('galleries') && is_video($attachment['a_original_filename']) && url_is_local($attachment['a_url'])) { require_code('galleries2'); $vid_details = get_video_details(get_custom_file_base() . '/' . rawurldecode($attachment['a_url']), $attachment['a_original_filename'], true); if ($vid_details !== false) { list($_width, $_height, ) = $vid_details; if ($attachment['a_width'] == '') { $attachment['a_width'] = strval($_width); } if ($attachment['a_height'] == '') { $attachment['a_height'] = strval($_height); } } } if ($attachment['a_width'] == '' || $attachment['a_height'] == '') { if ($attachment['a_width'] == '') { $attachment['a_width'] = '240'; } if ($attachment['a_height'] == '') { $attachment['a_height'] = '216'; } } } $attachment['a_align'] = array_key_exists('align', $attributes) ? $attributes['align'] : 'left'; if (!array_key_exists('a_description', $attachment)) { if (array_key_exists('description', $attributes)) { $attachment['description'] = $attributes['description']; } if (!array_key_exists('description', $attachment)) { $attachment['description'] = ''; } $attachment['a_description'] = is_object($attachment['description']) ? $attachment['description'] : comcode_to_tempcode($attachment['description'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, NULL, $on_behalf_of_member); } else { $attachment['a_description'] = comcode_to_tempcode($attachment['a_description'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, NULL, $on_behalf_of_member); } $attachment['a_type'] = $type; $attachment['a_thumb'] = array_key_exists('thumb', $attributes) ? $attributes['thumb'] : '1'; if ($attachment['a_thumb'] != '0') { $attachment['a_thumb'] = '1'; } $attachment['a_thumb_url'] = array_key_exists('thumb_url', $attributes) ? $attributes['thumb_url'] : $attachment['a_thumb_url']; switch ($type) { case 'email': require_code('mail'); global $EMAIL_ATTACHMENTS; if (url_is_local($attachment['a_url'])) { $attachment['a_url'] = get_custom_base_url() . '/' . $attachment['a_url']; } $EMAIL_ATTACHMENTS[$attachment['a_url']] = $attachment['a_original_filename']; $temp_tpl = new ocp_tempcode(); break; case 'code': $url = $attachment['a_url']; if (url_is_local($url)) { $url = get_custom_base_url() . '/' . $url; } $file_contents = http_download_file($url, 1024 * 1024 * 20); list($_embed, $title) = do_code_box($extension, make_string_tempcode($file_contents)); if ($attachment['a_original_filename'] != '') { $title = escape_html($attachment['a_original_filename']); } $temp_tpl = do_template('COMCODE_CODE', array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true, 'STYLE' => '', 'TYPE' => $extension, 'CONTENT' => $_embed, 'TITLE' => $title)); break; case 'hyperlink': if ($tag == 'attachment') { $keep = symbol_tempcode('KEEP'); $_url = new ocp_tempcode(); $_url->attach(find_script('attachment') . '?id=' . urlencode($attachment['id']) . $keep->evaluate()); if (get_option('anti_leech') == '1') { $_url->attach('&for_session='); $_url->attach(symbol_tempcode('SESSION_HASHED')); } } else { $url = $attachment['a_url']; if (url_is_local($url)) { $url = get_custom_base_url() . '/' . $url; } $_url = make_string_tempcode($url); } $temp_tpl = hyperlink($_url, is_object($attachment['a_description']) ? $attachment['a_description']->evaluate() : $attachment['a_description'] != '' ? $attachment['a_description'] : $attachment['a_original_filename'], true); break; default: if (is_image($attachment['a_original_filename'])) { if ($type == 'inline' || $type == 'left_inline' || $type == 'right_inline') { $attachment['mini'] = '1'; } require_code('images'); ensure_thumbnail($attachment['a_url'], $attachment['a_thumb_url'], 'attachments', 'attachments', intval($attachment['id']), 'a_thumb_url'); $temp_tpl = do_template('ATTACHMENT_IMG' . (array_key_exists('mini', $attachment) && $attachment['mini'] == '1' ? '_MINI' : ''), map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true)); if ($type == 'left' || $type == 'left_inline') { $temp_tpl = do_template('ATTACHMENT_LEFT', array('_GUID' => 'aee2a6842d369c8dae212c3478a3a3e9', 'WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true, 'CONTENT' => $temp_tpl)); } if ($type == 'right' || $type == 'right_inline') { $temp_tpl = do_template('ATTACHMENT_RIGHT', array('_GUID' => '1a7209d67d91db740c86e7a331720195', 'WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true, 'CONTENT' => $temp_tpl)); } break; } elseif ($extension == 'swf') { $temp_tpl = do_template('ATTACHMENT_SWF', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true)); break; } elseif (addon_installed('jwplayer') && ($mime_type == 'video/x-flv' || $mime_type == 'video/mp4' || $mime_type == 'video/webm')) { $temp_tpl = do_template('ATTACHMENT_FLV', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true)); break; } elseif ($mime_type == 'video/quicktime') { $temp_tpl = do_template('ATTACHMENT_QT', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true)); break; } elseif ($mime_type == 'audio/x-pn-realaudio') { $temp_tpl = do_template('ATTACHMENT_RM', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true)); break; } elseif (substr($mime_type, 0, 5) == 'video' || substr($mime_type, 0, 5) == 'audio') { $temp_tpl = do_template('ATTACHMENT_MEDIA', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true)); break; } // Continues on, as it's not a media type... // Continues on, as it's not a media type... case 'download': if (is_null($attachment['a_file_size'])) { $temp_tpl = do_template('ATTACHMENT_DOWNLOAD_REMOTE', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true)); } else { $temp_tpl = do_template('ATTACHMENT_DOWNLOAD', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true)); } break; } return $temp_tpl; }
/** * Run through tests. * * @return tempcode The result of execution. */ function go() { require_code('comcode_renderer'); $title = get_page_title('RUN_THROUGH_TESTS'); $show_for_all = get_param_integer('show_for_all', 0); $show_successful = get_param_integer('show_successful', 0); $tester = get_member(); if ($GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) { $tester = get_param_integer('tester', get_member()); } if ($show_for_all == 0) { $where = '(t.t_assigned_to=' . strval((int) $tester) . ' OR (t.t_assigned_to IS NULL AND s.s_assigned_to=' . strval((int) $tester) . '))'; } else { $where = 's.id IS NOT NULL'; } if ($show_successful == 0) { $where .= ' AND t.t_status<>1'; } $where .= ' AND s.s_inheritable=0'; $sections = new ocp_tempcode(); $query = 'SELECT *,t.id AS id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'tests t LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'test_sections s ON t.t_section=s.id WHERE ' . $where . ' ORDER BY s.s_section,t.id'; $_tests = $GLOBALS['SITE_DB']->query($query); $current = NULL; $current_2 = NULL; $current_3 = NULL; $tests = new ocp_tempcode(); foreach ($_tests as $test) { if (!is_null($current) && $current != $test['t_section']) { $edit_test_section_url = new ocp_tempcode(); if (has_specific_permission(get_member(), 'edit_own_tests') && ($test['s_assigned_to'] == get_member() || $GLOBALS['FORUM_DRIVER']->is_staff(get_member()))) { $edit_test_section_url = build_url(array('page' => '_SELF', 'type' => '_ed', 'id' => $current), '_SELF'); } $sections->attach(do_template('TESTER_GO_SECTION', array('_GUID' => '5ac788f72b881e403f75f76815706032', 'ID' => strval($current), 'EDIT_TEST_SECTION_URL' => $edit_test_section_url, 'NOTES' => $current_3, 'SECTION' => $current_2, 'TESTS' => $tests))); $tests = new ocp_tempcode(); } $current = $test['t_section']; $current_2 = $test['s_section']; $current_3 = $test['s_notes']; $a_test = make_string_tempcode(escape_html($test['t_test'])); if (!is_null($test['t_inherit_section'])) { $_tests_2 = $GLOBALS['SITE_DB']->query_select('tests', array('*'), array('t_section' => $test['t_inherit_section'])); if (count($_tests_2) != 0) { $section_notes = $GLOBALS['SITE_DB']->query_value('test_sections', 's_notes', array('id' => $test['t_inherit_section'])); if ($section_notes != '') { $a_test->attach(paragraph(escape_html($section_notes))); } $a_test->attach(do_template('TESTER_TEST_SET', array('TESTS' => map_keys_to_upper($_tests_2)))); } } $bug_report_url = build_url(array('page' => '_SELF', 'type' => 'report', 'id' => $test['id']), '_SELF'); $tests->attach(do_template('TESTER_GO_TEST', array('_GUID' => '1e719a51201d27eff7aed58b7f730251', 'BUG_REPORT_URL' => $bug_report_url, 'TEST' => $a_test, 'ID' => strval($test['id']), 'VALUE' => strval($test['t_status'])))); } if ($tests->is_empty() && $sections->is_empty()) { $sections = paragraph(do_lang_tempcode('NO_ENTRIES'), '4tregerg344'); } else { $edit_test_section_url = new ocp_tempcode(); if (has_specific_permission(get_member(), 'edit_own_tests') && ($test['s_assigned_to'] == get_member() || $GLOBALS['FORUM_DRIVER']->is_staff(get_member()))) { $edit_test_section_url = build_url(array('page' => '_SELF', 'type' => '_ed', 'id' => $test['t_section']), '_SELF'); } $sections->attach(do_template('TESTER_GO_SECTION', array('_GUID' => '9bd53d8b0f0aab1a683660fac2b6ad85', 'ID' => strval($test['t_section']), 'EDIT_TEST_SECTION_URL' => $edit_test_section_url, 'NOTES' => $test['s_notes'], 'SECTION' => $test['s_section'], 'TESTS' => $tests))); } $add_test_section_url = new ocp_tempcode(); if (has_specific_permission(get_member(), 'add_tests')) { $add_test_section_url = build_url(array('page' => '_SELF', 'type' => 'ad'), '_SELF'); } $post_url = build_url(array('page' => '_SELF', 'type' => '_go'), '_SELF'); return do_template('TESTER_GO_SCREEN', array('_GUID' => '22b3b626cb510e64a795d95acc0ad8a2', 'ADD_TEST_SECTION_URL' => $add_test_section_url, 'SHOW_SUCCESSFUL' => strval($show_successful), 'SHOW_FOR_ALL' => strval($show_for_all), 'TITLE' => $title, 'SECTIONS' => $sections, 'URL' => $post_url)); }