*/ $ci_query_resource = $vbulletin->db->query("\n SELECT imagequeueid, url, contentid, contenttypeid, attempts\n FROM " . TABLE_PREFIX . "rcd_imagequeue\n WHERE status = 'PROCESSING'\n AND nextcheck < " . TIMENOW . "\n"); // Queue URLs to check $ci_urls = array(); // Full URL data (to update message) $ci_urls_data = array(); // Next check timestamp $ci_next_check = TIMENOW + CI_CHECK_INTERVAL * 60; // Fetch queued URL info while ($ci_data = $vbulletin->db->fetch_array($ci_query_resource)) { $ci_urls_data[$ci_data['imagequeueid']] = $ci_data; $ci_urls[$ci_data['imagequeueid']] = $ci_data['url']; } $vbulletin->db->free_result($ci_query_resource); // Check URLs (get status and content size) $ci_urls_status = ci_check_urls($ci_urls); if (is_array($ci_urls_status)) { // Now we have status and content size on every url foreach ($ci_urls_status as $key => $url_data) { $ci_url_check_attempts = $ci_urls_data[$key]['attempts'] + 1; // If the status PROCESSING, but the number of attempts is over - set FAILED $ci_url_queue_status = 'PROCESSING' === $ci_url_queue_status && $ci_url_check_attempts >= CI_CHECK_COUNT ? 'FAILED' : $url_data['status']; if ($ci_url_queue_status == 'REPLACE' || $ci_url_queue_status == 'FAILED') { // Get classname from contenttypeid $ci_content_type = $ci_content_types->getContentTypeClass($ci_urls_data[$key]['contenttypeid']); // Replace IMG tag to URL switch ($ci_content_type) { case 'Post': case 'Thread': $ci_content = fetch_postinfo($ci_urls_data[$key]['contentid']); $ci_manager =& datamanager_init($ci_content_type, $vbulletin, ERRTYPE_STANDARD, 'threadpost');
/** * Find all IMG tags in message and check size. If size exceed the limit or this is not a image replace them to URL tag. * If URL is inaccessible it appended to $ci_image_queue global array ('key' => 'url') because we cannot save it now - lack of contentid. * * @param string &$message Message where need to check & replace. * @return array $ci_postponed_urls URLs which need to check later. */ function ci_fix_images_in_msg(&$message) { $ci_postponed_urls = array(); // If message contains IMG tags if (preg_match_all('#\\[img\\]\\s*(https?://([^*\\r\\n]+|[a-z0-9/\\._\\- !]+))\\[/img\\]#iUe', $message, $ci_img_tags)) { // Filter ut ll data-uris foreach ($ci_img_tags[1] as $idx => $url) { if (preg_match('/;base64,[A-Za-z0-9+/]{2}[A-Za-z0-9+/=]{2,}$/', $url)) { // got data uri - remove whole string $message = str_ireplace($ci_img_tags[0][$idx], '', $message); // and remove it from matching groups foreach ($ci_img_tags as $i => $arr) { unset($ci_img_tags[$i][$idx]); } } } // Get status of each url $ci_urls_status = ci_check_urls($ci_img_tags[1]); foreach ($ci_urls_status as $key => $url_data) { switch ($url_data['status']) { case 'REPLACE': $message = ci_replace_img_tag($message, $ci_img_tags[1][$key], $url_data['size']); break; case 'PROCESSING': // Now we cannot save URL because lack of contentid, // it will be inserted in table via _postsave hook $ci_postponed_urls[] = $ci_img_tags[1][$key]; break; } } } return $ci_postponed_urls; }