diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index 905f88e35..d6f72f838 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -110,6 +110,8 @@ class news_admin extends e_admin_dispatcher } + + } @@ -810,6 +812,42 @@ class news_admin_ui extends e_admin_ui } + function handleListImageBbcodeBatch($selected, $field, $value) + { + $sql = e107::getDb(); + + $status = array(); + + $ids = implode(",", e107::getParser()->filter($selected,'int')); + + if($data = $sql->retrieve("news","news_id,news_body","news_id IN (".$ids.") ",true)) + { + foreach($data as $row) + { + $id = $row['news_id']; + $update = array( + 'news_body' => e107::getBB()->imgToBBcode($row['news_body'], true), + 'WHERE' => 'news_id = '.$row['news_id'] + ); + + $status[$id] = $sql->update('news',$update) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; + } + + } + + $mes = e107::getMessage(); + + foreach($status as $k=>$v) + { + $mes->add(LAN_UPDATED.": ".$k, $v); + } + + return true; + } + + + + function init() { @@ -846,6 +884,13 @@ class news_admin_ui extends e_admin_ui } + + if(deftrue('e_DEBUG')) + { + $this->batchOptions['Modify News body'] = array('image_bbcode'=>"Convert all images in news-body to [img] bbcodes."); + } + + if(deftrue("ADMINUI_NEWS_VISIBILITY_MULTIPLE")) // bc workaround for those who need it. Add to e107_config.php . { $this->fields['news_class']['type'] = 'userclasses'; diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index 1670b36a0..e20c9450d 100644 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -3458,6 +3458,8 @@ class e_admin_controller_ui extends e_admin_controller //something like handleListUrlTypeBatch(); for custom handling of 'url_type' field name $method = 'handle'.$actionName.$this->getRequest()->camelize($field).'Batch'; + + e107::getDebug()->log("Checking for batch method: ".$method); if(method_exists($this, $method)) // callback handling { $this->$method($selected, $value); @@ -3467,6 +3469,7 @@ class e_admin_controller_ui extends e_admin_controller //handleListBatch(); for custom handling of all field names if(empty($selected)) return $this; $method = 'handle'.$actionName.'Batch'; + e107::getDebug()->log("Checking for batch method: ".$method); if(method_exists($this, $method)) { $this->$method($selected, $field, $value); @@ -4787,6 +4790,19 @@ class e_admin_ui extends e_admin_controller_ui parent::manageColumns(); } + + /** + * Detect if a batch function has been fired. + * @param $batchKey + * @return bool + */ + public function batchTriggered($batchKey) + { + return (!empty($_POST['e__execute_batch']) && (varset($_POST['etrigger_batch']) == $batchKey)); + } + + + /** * Catch batch submit * @param string $batch_trigger diff --git a/e107_handlers/bbcode_handler.php b/e107_handlers/bbcode_handler.php index 3cb9ac4a0..ea84f98a2 100644 --- a/e107_handlers/bbcode_handler.php +++ b/e107_handlers/bbcode_handler.php @@ -654,8 +654,104 @@ class e_bbcode return str_replace(array("",""),"",$html); } - - + + + /** + * Replace all instances of tags with [img] bbcodes - allowing image tags and their 'src' values to remain dynamic. + * @param string $html + * @param bool $fromDB if html source is directly from the database, set to true to handle '"' etc. + * @return string html with tags replaced by [img] bbcodes. + */ + function imgToBBcode($html, $fromDB = false) + { + + $tp = e107::getParser(); + + if($fromDB === true) + { + $html = str_replace('"','"', $html); + } + + $arr = $tp->getTags($html,'img'); + + $srch = array("?","&"); + $repl = array("\?","&"); + + if(defined('TINYMCE_DEBUG')) + { + print_a($arr); + } + + foreach($arr['img'] as $img) + { + if(substr($img['src'],0,4) == 'http' || strpos($img['src'], e_IMAGE_ABS.'emotes/')!==false) // dont resize external images or emoticons. + { + continue; + } + + $regexp = '#(]*src="'.str_replace($srch, $repl, $img['src']).'"[^>]*>)#'; + + $qr = $tp->thumbUrlDecode($img['src']); // extract width/height and src from thumb URLs. + + if(substr($qr['src'],0,4)!=='http' && empty($qr['w']) && empty($qr['aw'])) + { + $qr['w'] = $img['width']; + $qr['h'] = $img['height']; + } + + $qr['ebase'] = true; + + unset($img['src'],$img['srcset'],$img['@value'], $img['caption'], $img['alt']); + + if(!empty($img['class'])) + { + $tmp = explode(" ",$img['class']); + $cls = array(); + foreach($tmp as $v) + { + if($v === 'img-rounded' || $v === 'rounded' || $v === 'bbcode' || $v === 'bbcode-img-news' || $v === 'bbcode-img') + { + continue; + } + + $cls[] = $v; + + } + + if(empty($cls)) + { + unset($img['class']); + } + else + { + $img['class'] = implode(" ",$cls); + } + + } + + $parms = !empty($img) ? ' '.str_replace('+', ' ', http_build_query($img,null, '&')) : ""; + + $code_text = str_replace($tp->getUrlConstants('raw'), $tp->getUrlConstants('sc'), $qr['src']); + + $replacement = '[img'.$parms.']'.$code_text.'[/img]'; + + $html = preg_replace($regexp, $replacement, $html); + + } + + if($fromDB === true) + { + $html = str_replace('"', '"', $html); + } + + return $html; + + + } + + + + /** * Convert HTML to bbcode. diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 950cf207c..fbdcbf967 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -2836,6 +2836,56 @@ class e_parse extends e_parser + /** + * 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] + ); + } + elseif(preg_match('/theme\/img\/(a)?([\d]*)x(a)?([\d]*)\/(.*)/', $url, $match)) // Theme-image SEF Urls + { + $wKey = $match[1].'w'; + $hKey = $match[3].'h'; + + $ret = array( + 'src'=> 'e_THEME/'.$match[5], + $wKey => $match[2], + $hKey => $match[4] + ); + + } + elseif(defined('TINYMCE_DEBUG')) + { + print_a("thumbUrlDecode: No Matches"); + + } + + + return $ret; + } + + /** * Experimental: Generate a Thumb URL for use in the img srcset attribute. diff --git a/e107_plugins/tinymce4/plugins/e107/parser.php b/e107_plugins/tinymce4/plugins/e107/parser.php index 123ed6bd4..97394937e 100644 --- a/e107_plugins/tinymce4/plugins/e107/parser.php +++ b/e107_plugins/tinymce4/plugins/e107/parser.php @@ -194,7 +194,8 @@ TEMPL; { $content = trim($content); - $content = $this->updateImg($content); + // $content = $this->updateImg($content); + $content = e107::getBB()->imgToBBcode($content); // $content = $tp->parseBBTags($content,true); // replace html with bbcode equivalent if(strip_tags($content, '') == ' ') // Avoid this: [html]

 

[/html] @@ -219,65 +220,18 @@ 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] - ); - } - elseif(preg_match('/theme\/img\/(a)?([\d]*)x(a)?([\d]*)\/(.*)/', $url, $match)) // Theme-image SEF Urls - { - $wKey = $match[1].'w'; - $hKey = $match[3].'h'; - - $ret = array( - 'src'=> 'e_THEME/'.$match[5], - $wKey => $match[2], - $hKey => $match[4] - ); - - } - elseif(defined('TINYMCE_DEBUG')) - { - print_a("thumbUrlDecode: No Matches"); - - } - - - return $ret; - } /** * Rebuld tags with modified thumbnail size. + * @deprecated @see e107::getBB()->imgToBBcode(); * @param $text * @return mixed */ - function updateImg($text) +/* function updateImg($text) { - - $arr = e107::getParser()->getTags($text,'img'); + $tp = e107::getParser(); + $arr = $tp->getTags($text,'img'); $srch = array("?","&"); $repl = array("\?","&"); @@ -296,18 +250,19 @@ TEMPL; $regexp = '#(]*src="'.str_replace($srch, $repl, $img['src']).'"[^>]*>)#'; -/* - $width = vartrue($img['width']) ? ' width="'.$img['width'].'"' : ''; - $height = vartrue($img['height']) ? ' height="'.$img['height'].'"' : ''; - $style = vartrue($img['style']) ? ' style="'.$img['style'].'"' : ''; - $class = vartrue($img['class']) ? ' class="'.$img['class'].'"' : ''; - $alt = vartrue($img['alt']) ? ' alt="'.$img['alt'].'"' : ''; - $title = vartrue($img['title']) ? ' title="'.$img['title'].'"' : ''; - $srcset = vartrue($img['srcset']) ? 'srcset="'.$img['srcset'].'"' : ''; - */ + + // $width = vartrue($img['width']) ? ' width="'.$img['width'].'"' : ''; + // $height = vartrue($img['height']) ? ' height="'.$img['height'].'"' : ''; + // $style = vartrue($img['style']) ? ' style="'.$img['style'].'"' : ''; + // $class = vartrue($img['class']) ? ' class="'.$img['class'].'"' : ''; + // $alt = vartrue($img['alt']) ? ' alt="'.$img['alt'].'"' : ''; + // $title = vartrue($img['title']) ? ' title="'.$img['title'].'"' : ''; + // $srcset = vartrue($img['srcset']) ? 'srcset="'.$img['srcset'].'"' : ''; - $qr = $this->thumbUrlDecode($img['src']); + + + $qr = $tp->thumbUrlDecode($img['src']); if(substr($qr['src'],0,4)!=='http' && empty($qr['w']) && empty($qr['aw'])) { @@ -351,7 +306,7 @@ TEMPL; $parms = !empty($img) ? ' '.str_replace('+', ' ', http_build_query($img,null, '&')) : ""; - $code_text = str_replace(e107::getParser()->getUrlConstants('raw'), e107::getParser()->getUrlConstants('sc'), $qr['src']); + $code_text = str_replace($tp->getUrlConstants('raw'), $tp->getUrlConstants('sc'), $qr['src']); $replacement = '[img'.$parms.']'.$code_text.'[/img]'; @@ -360,7 +315,7 @@ TEMPL; } return $text; - } + }*/ }