Пример #1
0
 /**
  * Returns the URL of the first image found in a WYSIWYG section
  *
  * @param INT $page_id
  * @return STR URL oder BOOL FALSE
  */
 public static function getFirstImageFromContent($page_id, $exec_droplets = true)
 {
     $self = self::getInstance();
     $img = array();
     $__CAT_Helper_Droplets_content = '';
     $section = CAT_Sections::getSectionsByType($page_id);
     if (count($section)) {
         $SQL = "SELECT `content` FROM `:prefix:mod_wysiwyg` WHERE `section_id`=:id";
         $params = array('id' => $section[0]['section_id']);
         $result = $self->db()->query($SQL, $params)->fetchColumn();
         if ($self->db()->isError()) {
             return false;
         }
         if (is_string($result)) {
             $__CAT_Helper_Droplets_content = self::unsanitizeText($result);
         }
     }
     if (!empty($__CAT_Helper_Droplets_content)) {
         // scan content for images
         if ($exec_droplets && file_exists(CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/droplets/droplets.php'))) {
             // we must process the droplets to get the real output content
             $_SESSION['DROPLET_EXECUTED_BY_DROPLETS_EXTENSION'] = true;
             ob_start();
             include_once CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/droplets/droplets.php');
             if (function_exists('evalDroplets')) {
                 try {
                     $__CAT_Helper_Droplets_content = evalDroplets($__CAT_Helper_Droplets_content);
                 } catch (Exception $e) {
                     trigger_error(sprintf('[%s - %s] %s', __FUNCTION__, __LINE__, $e->getMessage()), E_USER_ERROR);
                 }
             }
             ob_end_clean();
             unset($_SESSION['DROPLET_EXECUTED_BY_DROPLETS_EXTENSION']);
         }
         if (preg_match('/<img[^>]*>/', $__CAT_Helper_Droplets_content, $matches)) {
             preg_match_all('/([a-zA-Z]*[a-zA-Z])\\s{0,3}[=]\\s{0,3}("[^"\\r\\n]*)"/', $matches[0], $attr);
             foreach ($attr as $attributes) {
                 foreach ($attributes as $attribut) {
                     if (strpos($attribut, "=") !== false) {
                         list($key, $value) = explode("=", $attribut);
                         $value = trim($value);
                         $value = substr($value, 1, strlen($value) - 2);
                         $img[strtolower(trim($key))] = trim($value);
                     }
                 }
             }
         }
     }
     if (isset($img['src'])) {
         $image = $img['src'];
         if (strpos($image, '..') !== false) {
             $image = substr($image, strpos($image, MEDIA_DIRECTORY . '/'));
             $image = CAT_URL . $image;
         }
         return $image;
     } else {
         return false;
     }
 }