[Comoblog-commit] comoblog/modules/mod_markup/include mod_markup.inc.php,1.2,1.3
Status: Inactive
Brought to you by:
markwallis
|
From: Mark W. \(a. serialmonkey\) <mar...@us...> - 2005-10-09 06:46:17
|
Update of /cvsroot/comoblog/comoblog/modules/mod_markup/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3672/modules/mod_markup/include Modified Files: mod_markup.inc.php Log Message: RFE: 1280308 - Finished image markup function. Images can now be downloaded locally before references Index: mod_markup.inc.php =================================================================== RCS file: /cvsroot/comoblog/comoblog/modules/mod_markup/include/mod_markup.inc.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- mod_markup.inc.php 9 Oct 2005 01:44:15 -0000 1.2 +++ mod_markup.inc.php 9 Oct 2005 06:46:08 -0000 1.3 @@ -22,10 +22,69 @@ return $post; } +function process_images_local($post) +{ + $pos = 0; + $body = $post['post_mail_body']; + $pos = strpos( $body, "[[Image:"); + + while ($pos != FALSE) + { + $start = $pos; + $end = strpos( $body, "]]", $start + 1); + $url = substr($body, $start+8, $end-$start-8); + $now = str_replace(' ', '', microtime()).rand(); + $cid = $now; + + $html = "<img hspace=0 src='cid:".$cid."' align=baseline border=0>"; + $body = substr($body, 0, $start).$html.substr($body, $end+2); + + $ch = curl_init($url); + $fp = fopen (CFG_BASE_PATH.'/img/tmp/'.$now, 'wb'); + curl_setopt($ch, CURLOPT_FILE, $fp); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_exec($ch); + curl_close($ch); + fclose($fp); + + $imgsize = @getimagesize(CFG_BASE_PATH.'/img/tmp/'.$now); + + if ($imgsize) { + if ($imgsize[2] == 1) $ctype = 'image/gif'; + elseif($imgsize[2] == 2) $ctype = 'image/jpg'; + elseif($imgsize[2] == 3) $ctype = 'image/png'; + + if ($ctype != '') { + array_push ($post['images_mime'], $ctype); + array_push ($post['images_tmp'], CFG_BASE_PATH.'/img/tmp/'.$now); + array_push ($post['images_cid'], $cid); + array_push ($post['images'], ""); + } + else + @unlink(CFG_BASE_PATH.'/img/tmp/'.$now); + } + + $pos = strpos( $body, "[[Image:"); + } + + $post['post_mail_body'] = $body; + return $post; +} + function markup ($post) { - if (CFG_MOD_MARKUP_DOWNLOAD_IMAGES == "N") + $extensions = get_loaded_extensions(); + + // check if curl support is enabled + if (in_array('curl', $extensions)) + $has_curl = TRUE; + else + $has_curl = FALSE; + + if (!$has_curl || CFG_MOD_MARKUP_DOWNLOAD_IMAGES == "N") $post = process_images_remote( $post ); + else + $post = process_images_local( $post ); $post['post_mail_body'] = nl2br($post['post_mail_body']); $post['post_ctype'] = "text/html"; |