From 0c3125a11eb1b086d34edff8bc39eeebd9d2616f Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 4 Feb 2016 11:40:15 -0800 Subject: [PATCH] Issue #1257 More work on SEF Thumb URLs. --- e107_admin/image.php | 8 +-- e107_core/bbcodes/bb_img.php | 17 ++--- e107_plugins/tinymce4/plugins/e107/parser.php | 64 +++++++++++++++---- 3 files changed, 62 insertions(+), 27 deletions(-) diff --git a/e107_admin/image.php b/e107_admin/image.php index 9a5fc2d8a..e11158df1 100644 --- a/e107_admin/image.php +++ b/e107_admin/image.php @@ -1310,10 +1310,10 @@ class media_admin_ui extends e_admin_ui $br = (E107_DEBUG_LEVEL > 0) ? "
" : ""; $text .= " - ".$br." - ".$br." - ".$br." - ".$br." + ".$br." + ".$br." + ".$br." + ".$br." "; return $text; diff --git a/e107_core/bbcodes/bb_img.php b/e107_core/bbcodes/bb_img.php index c9c86e1d3..0c1f9441f 100644 --- a/e107_core/bbcodes/bb_img.php +++ b/e107_core/bbcodes/bb_img.php @@ -42,8 +42,8 @@ class bb_img extends e_bb_base // Replace the bbcode path with a real one. $code_text = str_replace('{e_MEDIA}images/','{e_MEDIA_IMAGE}',$code_text); //BC 0.8 fix. - $code_text = str_replace('{e_MEDIA_IMAGE}', e_HTTP."thumb.php?src=e_MEDIA_IMAGE/", $code_text); - $code_text = str_replace('{e_THEME}', e_HTTP."thumb.php?src=e_THEME/", $code_text); + // $code_text = str_replace('{e_MEDIA_IMAGE}', e_HTTP."thumb.php?src=e_MEDIA_IMAGE/", $code_text); + // $code_text = str_replace('{e_THEME}', e_HTTP."thumb.php?src=e_THEME/", $code_text); $imgParms = $this->processParm($code_text, $parm); $figcaption = false; @@ -60,25 +60,22 @@ class bb_img extends e_bb_base // $parmStr .= " ".$k.'="'.$v.'"'; $p[] = $tp->toAttribute($k).'="'.$tp->toAttribute($v).'"'; } - - - // $w = e107::getBB()->resizeWidth(); // varies depending on the class set by external script. see admin->media-manager->prefs - - + $w = vartrue($imgParms['width']) ? intval($imgParms['width']) : vartrue(e107::getBB()->resizeWidth(),0); // $h = vartrue($imgParms['height']) ? intval($imgParms['height']) : e107::getBB()->resizeHeight(); $resize = "&w=".$w; // Always resize - otherwise the thumbnailer returns nothing. $parmStr = implode(" ",$p); - + // print_a($imgParms); // print_a($parmStr); + $url = e107::getParser()->thumbUrl($code_text, $resize); if(!empty($figcaption)) { $html = "
\n"; - $html .= "\n"; + $html .= ""; $html .= "
".e107::getParser()->filter($figcaption,'str')."
\n"; $html .= "
"; @@ -86,7 +83,7 @@ class bb_img extends e_bb_base } else { - return ""; + return ""; } } diff --git a/e107_plugins/tinymce4/plugins/e107/parser.php b/e107_plugins/tinymce4/plugins/e107/parser.php index b26a372b4..634ef2978 100644 --- a/e107_plugins/tinymce4/plugins/e107/parser.php +++ b/e107_plugins/tinymce4/plugins/e107/parser.php @@ -8,7 +8,7 @@ */ -if(empty($_POST['content']) && empty($_GET['debug'])) +if(empty($_POST['content']) && empty($_GET['debug']) && !defined('TINYMCE_DEBUG')) { header('Content-Length: 0'); exit; @@ -17,7 +17,11 @@ if(empty($_POST['content']) && empty($_GET['debug'])) $_E107['no_online'] = true; $_E107['no_menus'] = true; $_E107['no_forceuserupdate'] = true; -require_once("../../../../class2.php"); + +if(!defined('TINYMCE_DEBUG')) +{ + require_once("../../../../class2.php"); +} /** * Two Modes supported below going to and from the Tinymce wysiwyg editor. @@ -29,7 +33,7 @@ require_once("../../../../class2.php"); class e107TinyMceParser { - protected $gzipCompression = true; + protected $gzipCompression = false; /** * @@ -38,6 +42,11 @@ class e107TinyMceParser { $html = ''; + if(defined('TINYMCE_DEBUG')) + { + $this->gzipCompression = false; + } + if(!empty($_GET['debug']) && getperms('0')) { $debug = true; // For future use. @@ -213,8 +222,42 @@ TEMPL; } + /** + * Split a thumb.php url into an array which can be parsed back into the thumbUrl method. . + * @param $src + * @return array + */ + function thumbUrlDecode($src) + { + list($url,$qry) = explode("?",$src); + + $ret = array(); + + if(strstr($url,"thumb.php") && !empty($qry)) // Regular + { + parse_str($qry,$val); + $ret = $val; + } + elseif(preg_match('/media\/img\/(a)?([\d]*)x(a)?([\d]*)\/(.*)/',$url,$match)) // SEF + { + $wKey = $match[1].'w'; + $hKey = $match[3].'h'; + + $ret = array( + 'src'=> 'e_MEDIA_IMAGE/'.$match[5], + $wKey => $match[2], + $hKey => $match[4] + ); + } + + return $ret; + } + + /** * Rebuld tags with modified thumbnail size. + * @param $text + * @return mixed */ function updateImg($text) { @@ -235,34 +278,29 @@ TEMPL; $alt = vartrue($img['alt']) ? ' alt="'.$img['alt'].'"' : ''; $title = vartrue($img['title']) ? ' title="'.$img['title'].'"' : ''; - list($url,$qry) = explode("?",$img['src']); + $qr = $this->thumbUrlDecode($img['src']); - parse_str($qry,$qr); - - if(substr($url,0,4)!=='http' && empty($qr['w']) && empty($qr['aw'])) + if(substr($qr['src'],0,4)!=='http' && empty($qr['w']) && empty($qr['aw'])) { $qr['w'] = $img['width']; $qr['h'] = $img['height']; } - $src = $url."?".urldecode(http_build_query($qr)); + $src = e107::getParser()->thumbUrl($qr['src'],$qr); - $replacement = ''; + $replacement = ''; $text = preg_replace($regexp, $replacement, $text); - } return $text; - - } } -new e107TinyMceParser(); +$mce = new e107TinyMceParser(); ?> \ No newline at end of file