public static function cgsi_getimages($params, $content, &$smarty, $repeat)
 {
     if (!$content) {
         return;
     }
     $mod = cms_utils::get_module('CGSmartImage');
     $old_errorval = libxml_use_internal_errors(true);
     $dom = new CGDomDocument();
     $dom->strictErrorChecking = FALSE;
     $dom->validateOnParse = FALSE;
     if (function_exists('mb_convert_encoding')) {
         $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
     }
     $dom->loadHTML($content);
     $imgs = $dom->GetElementsByTagName('img');
     if (is_object($imgs) && $imgs->length) {
         $out = array();
         for ($i = 0; $i < $imgs->length; $i++) {
             $node = $imgs->item($i);
             $sxe = simplexml_import_dom($node);
             $rec = array();
             $rec['tag'] = $sxe->asXML();
             foreach ($sxe->attributes() as $name => $value) {
                 $value = (string) $value;
                 if ($value == '') {
                     continue;
                 }
                 $rec[$name] = $value;
             }
             $out[] = $rec;
         }
         if (isset($params['assign'])) {
             $smarty->assign($params['assign'], $out);
         }
     }
     $imagesonly = cms_to_bool(get_parameter_value($params, 'imagesonly'));
     $nocontent = cms_to_bool(get_parameter_value($params, 'nocontent'));
     if (!$nocontent) {
         if ($imagesonly) {
             $content = '';
             foreach ($out as $rec) {
                 $content .= $rec['tag'];
             }
         }
         return $content;
     }
 }
 public static function cgsi_convert($params, $content, &$smarty, $repeat)
 {
     if (!$content) {
         return;
     }
     $max_width = -1;
     $max_height = -1;
     if (isset($params['max_height'])) {
         $max_height = max(0, (int) $params['max_height']);
     }
     if (isset($params['max_width'])) {
         $max_width = max(0, (int) $params['max_width']);
     }
     $did_modify = FALSE;
     $mod = cms_utils::get_module('CGSmartImage');
     $old_errorval = libxml_use_internal_errors(true);
     $dom = new CGDomDocument();
     $dom->strictErrorChecking = FALSE;
     $dom->validateOnParse = FALSE;
     if (function_exists('mb_convert_encoding')) {
         $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
     }
     $dom->loadHTML($content);
     $imgs = $dom->GetElementsByTagName('img');
     if (is_object($imgs) && $imgs->length) {
         for ($i = 0; $i < $imgs->length; $i++) {
             $node = $imgs->item($i);
             $sxe = simplexml_import_dom($node);
             $parms = $params;
             $process = true;
             foreach ($sxe->attributes() as $name => $value) {
                 $value = (string) $value;
                 if ($value == '') {
                     continue;
                 }
                 switch ($name) {
                     case 'width':
                         if ($max_width > 0) {
                             $value = min($max_width, (int) $value);
                         }
                         break;
                     case 'height':
                         if ($max_height > 0) {
                             $value = min($max_height, (int) $value);
                         }
                         break;
                     case 'class':
                         $words = explode(' ', $value);
                         if (in_array('nocgsi', $words)) {
                             $process = false;
                         }
                         break;
                 }
                 $parms[$name] = $value;
             }
             if (!$process) {
                 continue;
             }
             // found a reason not do to anything with this image.
             if (!isset($parms['src'])) {
                 continue;
             }
             if (startswith($parms['src'], 'data:')) {
                 continue;
             }
             // already embedded, can't do anything.
             $parms['notag'] = 1;
             $outp = self::process_image($parms);
             foreach ($outp as $key => $value) {
                 $did_modify = TRUE;
                 switch ($key) {
                     case 'width':
                     case 'height':
                         $sxe[$key] = (int) $value;
                         break;
                     case 'src':
                         $value = trim($value);
                         if ($value) {
                             $sxe[$key] = trim($value);
                         }
                         break;
                     default:
                         break;
                 }
             }
         }
         // for each image
     }
     // get the contents.
     if ($did_modify) {
         $node = $dom->documentElement;
         $content = $node->innerHTML;
         $content = str_replace(chr(13), '', $content);
         $content = str_replace('&#13;', '', $content);
         if (startswith($content, '<html>')) {
             $content = str_replace('<html>', '', $content);
             $content = str_replace('</html>', '', $content);
         }
         if (startswith($content, '<body>')) {
             $content = str_replace('<body>', '', $content);
             $content = str_replace('</body>', '', $content);
         }
     }
     return $content;
 }