Ejemplo n.º 1
0
function make_slug($name)
{
    $name = html_entity_decode($name, ENT_QUOTES, 'UTF-8');
    // TODO: prevent escaping of incoming string?
    return formate_slug(remove_accents($name));
}
 public static function handle_img_id_tag($image_id, $align, $legend = '', $images = null, $filter_image_type = true)
 {
     if ($images == null) {
         return '';
     }
     $options = explode(' ', $align);
     $img_class = array();
     $centered = false;
     $inline = false;
     if (in_array('left', $options)) {
         $img_class[] = 'embedded_left';
     } elseif (in_array('right', $options)) {
         $img_class[] = 'embedded_right';
     } elseif (in_array('inline', $options)) {
         $img_class[] = 'embedded_inline';
         $inline = true;
     } elseif (in_array('inline_left', $options)) {
         $img_class[] = 'embedded_inline_left';
     } elseif (in_array('inline_right', $options)) {
         $img_class[] = 'embedded_inline_right';
     } elseif (in_array('center', $options)) {
         $img_class[] = 'embedded_center';
         $centered = true;
     }
     $show_legend = true;
     if (in_array('no_legend', $options)) {
         $show_legend = false;
         $legend = self::do_spaces($legend, false);
     } else {
         $img_class[] = 'img_box';
     }
     if ($show_legend && in_array('no_border', $options)) {
         $img_class[] = 'no_border';
     }
     // big images are not used in mobile version (replaced by medium version)
     if (in_array('big', $options) && !c2cTools::mobileVersion()) {
         $size = 'BI.';
     } elseif (in_array('small', $options)) {
         $size = 'SI.';
     } else {
         $size = 'MI.';
     }
     $image = null;
     foreach ($images as $image_temp) {
         if ($image_temp['id'] == $image_id) {
             $image = $image_temp;
         }
     }
     $error_image = is_null($image);
     // Error image
     if ($error_image) {
         if (!$show_legend) {
             $show_legend = true;
             $img_class[] = 'img_box';
         }
         $img_class[] = 'img_error';
         $path = '/static/images/picto';
         $filename = 'warning';
         $extension = 'png';
         $short_title = __('Image could not be loaded');
         $legend = __('Image could not be loaded long') . '<br />' . link_to(__('View image details'), '@document_by_id?module=images&id=' . $image_id);
     } else {
         if (empty($legend)) {
             $legend = $image['name'];
         }
         $path = '/uploads/images';
         list($filename, $extension) = explode('.', $image['filename']);
         $alt = $filename . '.' . $extension;
         $title = self::do_spaces($legend, false);
         if (!empty($title)) {
             $title = ' title="' . $title . '"';
         }
         // Warning image - TODO to be removed after transition period, use error img instead
         if ($filter_image_type && $image['image_type'] == 2) {
             if (!$show_legend) {
                 $show_legend = true;
                 $img_class[] = 'img_box';
             }
             $img_class[] = 'img_error';
             $img_class[] = 'img_warning';
             $legend = __('Wrong image type');
         }
     }
     $path = sfConfig::get('app_static_url') . $path;
     $img_class = implode(' ', $img_class);
     if (!empty($img_class)) {
         $img_class = ' class="' . $img_class . '"';
     }
     if ($error_image) {
         $image_tag = sprintf('<img src="%s/%s" alt="%s" title="%s" />', $path, $filename . '.' . $extension, $short_title, $short_title);
     } else {
         $image_tag = sprintf('<a data-lightbox="embedded_images" id="lightbox_%s_%s_embedded" class="view_big" href="%s/%s"%s><img%s src="%s/%s" alt="%s" itemprop="image" /></a>', $image['id'], $image['image_type'], $path, $filename . 'BI.' . $extension, strip_tags($title), $show_legend ? '' : $img_class, $path, $filename . $size . $extension, $alt);
         // alt todo use title if available.....
     }
     if ($show_legend) {
         $image_tag = '<figure' . $img_class . '>' . $image_tag;
         if (strpos($img_class, 'img_error') === false) {
             $image_tag = $image_tag . link_to(__('View image details'), '@document_by_id_lang_slug?module=images&id=' . $image['id'] . '&lang=' . $image['culture'] . '&slug=' . formate_slug($image['search_name']), array('class' => 'picto_images view_details', 'title' => __('View image details')));
         }
         // note: it is safe (at least should be :)) to translate \" to " here
         // since we only get them because of e modifier for img pre_replace
         // (elsewhere it is translated to html special chars)
         // FIXME preg_replace with e delimiter is kinda deprecated,we should rather use preg_replace_callback
         $image_tag = $image_tag . '<figcaption>' . stripslashes($legend) . '</figcaption></figure>';
     }
     if ($centered) {
         $image_tag = '<div class="center">' . $image_tag . '</div>';
     } else {
         if (c2cTools::mobileVersion()) {
             $image_tag = '<div class="img_mobile">' . $image_tag . '</div>';
         }
     }
     if (!$inline) {
         $image_tag = '</p>' . $image_tag . '<p>';
     }
     return $image_tag;
 }