예제 #1
0
/**
 * Frontendausgabe CMS:tag image
 *
 * @Args: int type_container -> id von cms:tag <cms:lay type="container" id="XX" />
 *        int type_number  -> Entspricht der Verdopplungsid eines Containers
 *        int type_typenumber -> Eindeutige Id des Contents
 *        array $type_config -> Attribute und deren Werte des cms:tags
 * @Return String Content
 * @Access public
 */
function type_output_image($type_container, $type_number, $type_typenumber, $type_config)
{
    global $sess, $DB_cms, $cms_db, $cfg_cms, $cfg_client, $idcatside, $mod_lang, $content, $cms_side;
    global $client, $cms_edittype, $cms_mod, $con_side;
    //catch vars and arrays from the tag attributes
    eval(_type_get_dynamic_val_string($type_config));
    // URL formatieren
    $mod_content = is_array($content[$type_container][$type_number]) ? $content[$type_container][$type_number]['4'][$type_typenumber]['1'] : '';
    $match = array();
    if (preg_match_all('#^cms://(idfile|idfilethumb)=(\\d+)$#', $mod_content, $match)) {
        $is_thumb = $match['1']['0'] == 'idfilethumb';
        $id = $match['2']['0'];
        $sql = "SELECT \n\t\t\t\t\tA.*, B.filetype, C.dirname \n\t\t\t\tFROM \n\t\t\t\t\t" . $cms_db['upl'] . " A \n\t\t\t\t\tLEFT JOIN " . $cms_db['filetype'] . " B USING(idfiletype) \n\t\t\t\t\tLEFT JOIN " . $cms_db['directory'] . " C ON A.iddirectory=C.iddirectory \n\t\t\t\tWHERE \n\t\t\t\t\tA.idclient='{$client}' \n\t\t\t\t\tAND idupl='" . $id . "'";
        $db = new DB_cms();
        $db->query($sql);
        if ($db->next_record()) {
            $mod_url = $cfg_client['upl_htmlpath'] . $db->f('dirname') . $db->f('filename');
            $mod_path = $cfg_client['upl_path'] . $db->f('dirname') . $db->f('filename');
            $fileid = $db->f('idupl');
            $original_x = $db->f('pictwidth');
            $original_y = $db->f('pictheight');
            $pic_filetype = $db->f('filetype');
            $pic_dirname = $db->f('dirname');
            $pic_filename = $db->f('filename');
            $pic_idfiletype = $db->f('idfiletype');
            $pic_iddirectory = $db->f('iddirectory');
            $thumb_x = $db->f('pictthumbwidth');
            $thumb_y = $db->f('pictthumbheight');
            $pic_db_desc = $db->f('description');
            $pic_db_titel = $db->f('titel');
            $file_size = $db->f('filesize');
            if (in_array($type_config['mode'], array('thumb', 'thumbamplitude', 'thumbwidth', 'thumbheight', 'thumburl', 'thumbpath')) && $pic_filetype != 'gif' && ($thumb_x != 0 || $thumb_y != 0) || $is_thumb) {
                $original_x = $thumb_x;
                $original_y = $thumb_y;
                $name_length = strlen($pic_filename);
                $extension_length = strlen($pic_filetype);
                $new_name = substr($pic_filename, 0, $name_length - $extension_length - 1);
                $new_name .= $cfg_client['thumbext'] . '.' . $pic_filetype;
                $mod_url = $cfg_client['upl_htmlpath'] . $db->f('dirname') . $new_name;
                $mod_path = $cfg_client['upl_path'] . $db->f('dirname') . $new_name;
                $pic_filename = $new_name;
            }
        }
    }
    if ($type_config['autoresize'] == 'true' && !empty($mod_url)) {
        // Extract needed data
        $is_aspectratio = $type_config['aspectratio'] != 'false' ? true : false;
        $extracted_size = _type_calculate_new_image_size($original_x, $original_y, $type_config['width'], $type_config['height'], $is_aspectratio);
        $new_x = $extracted_size['width'];
        $new_y = $extracted_size['height'];
        // Skip transform if new image have the same properties as the original image,
        if ($new_x == $original_x && $new_y == $original_y) {
            $skip_transform = true;
        }
        // If _type_calculate_new_image_size(..) throwed an error, new_x and new_y are not set, skip transform
        if (!empty($new_x) && !empty($new_y)) {
            $name_length = strlen($pic_filename);
            $extension_length = strlen($pic_filetype);
            // New filename for image
            $new_name = substr($pic_filename, 0, $name_length - $extension_length - 1);
            $new_name .= '_' . $new_x . 'X' . $new_y . '.' . $pic_filetype;
            if (file_exists($cfg_client['upl_path'] . $pic_dirname . $new_name)) {
                // manipulate current CMS:tag values with new transform values
                $mod_url = $cfg_client['upl_htmlpath'] . $pic_dirname . $new_name;
                $mod_path = $cfg_client['upl_path'] . $pic_dirname . $new_name;
                $type_config['width'] = $original_x = $new_x;
                $type_config['height'] = $original_y = $new_y;
            } else {
                if ($skip_transform || $cfg_cms['image_mode'] == 'gd' && $pic_filetype == 'gif') {
                    $type_config['width'] = $original_x = $new_x;
                    $type_config['height'] = $original_y = $new_y;
                } else {
                    // Create image only if file doesn't exist, isn't GD with filetype gif
                    // and imagedriver isn't empty
                    if (!($cfg_cms['image_mode'] == 'gd' && $pic_filetype == 'gif') && !empty($cfg_cms['image_mode'])) {
                        // IMAGE TRANSFORM
                        global $cms_image;
                        require_once 'Image/Transform.php';
                        $cms_image = is_object($cms_image) ? $cms_image : Image_Transform::factory($cfg_cms['image_mode']);
                        $cms_image->load($mod_path);
                        $cms_image->resize($new_x, $new_y);
                        $cms_image->save($cfg_client['upl_path'] . $pic_dirname . $new_name);
                        $cms_image->free();
                        global $fm;
                        $fm->insert_file((int) $client, $new_name, (int) $pic_iddirectory, (int) $pic_idfiletype);
                        //manipulate current CMS:tag values with new transform values
                        $mod_url = $cfg_client['upl_htmlpath'] . $pic_dirname . $new_name;
                        $mod_path = $cfg_client['upl_path'] . $pic_dirname . $new_name;
                        $type_config['width'] = $original_x = $new_x;
                        $type_config['height'] = $original_y = $new_y;
                    }
                }
            }
        }
    }
    // Wenn amplitude angefordert - Ausgabe FRONTEND + BACKEND
    if ($type_config['mode'] == 'amplitude' || $type_config['mode'] == 'thumbamplitude') {
        return 'width="' . $original_x . '" height="' . $original_y . '"';
    }
    // Wenn nur filesize gefordert, Ausgabe - FRONTEND und BACKEND
    if ($type_config['mode'] == 'filesize') {
        return $file_size;
    }
    // Wenn nur id der Datei gefordert, Ausgabe - FRONTEND und BACKEND
    if ($type_config['mode'] == 'id') {
        return $fileid;
    }
    // Wenn dateimanager titel angefordert - Ausgabe FRONTEND + BACKEND
    if ($type_config['mode'] == 'fmtitle') {
        return $pic_db_titel;
    }
    // Wenn dateimanager beschreibung angefordert - Ausgabe FRONTEND + BACKEND
    if ($type_config['mode'] == 'fmdesc') {
        return $pic_db_desc;
    }
    // Wenn Filetype angefordert - Ausgabe FRONTEND + BACKEND
    if ($type_config['mode'] == 'filetype') {
        return $pic_filetype;
    }
    // Wenn Bildhöhe angefordert - Ausgabe FRONTEND + BACKEND
    if ($type_config['mode'] == 'width' || $type_config['mode'] == 'thumbwidth') {
        return $original_x;
    }
    // Wenn Bildweite angefordert - Ausgabe FRONTEND + BACKEND
    if ($type_config['mode'] == 'height' || $type_config['mode'] == 'thumbheight') {
        return $original_y;
    }
    // Wenn nur url gefordert - Ausgabe FRONTEND + BACKEND
    if ($type_config['mode'] == 'url' || $type_config['mode'] == 'thumburl') {
        return $mod_url;
    }
    // Wenn nur pfad gefordert - Ausgabe FRONTEND + BACKEND
    if ($type_config['mode'] == 'path' || $type_config['mode'] == 'thumbpath') {
        return $mod_path;
    }
    // Beschreibung raussuchen
    $mod_descr = is_array($content[$type_container][$type_number]) ? htmlspecialchars($content[$type_container][$type_number]['5'][$type_typenumber]['1'], ENT_COMPAT, 'UTF-8') : '';
    // Wenn nur Beschreibung gefordert - Ausgabe FRONTEND + BACKEND
    if ($type_config['mode'] == 'desc') {
        return $mod_descr;
    }
    // Bildgroesse ermitteln
    // Wenn defaultimage
    if (empty($mod_url)) {
        $pic_width = !empty($type_config['defaultwidth']) ? $type_config['defaultwidth'] : $type_config['width'];
        $pic_height = !empty($type_config['defaultheight']) ? $type_config['defaultheight'] : $type_config['height'];
        // wenn schon ausgewaehltes Bild
    } else {
        $pic_width = empty($type_config['width']) ? '' : $type_config['width'];
        $pic_height = empty($type_config['height']) ? '' : $type_config['height'];
        // Bildgroesse soll automatisch ermittelt werden
    }
    if ((empty($type_config['width']) || $type_config['width'] == 'true' || empty($type_config['height']) || $type_config['height'] == 'true') && !empty($mod_url)) {
        //Bildweite aus der DB
        if ($type_config['width'] == 'true' || empty($type_config['width'])) {
            $pic_width = $original_x;
        }
        //Bildhoehe aus der DB
        if ($type_config['height'] == 'true' || empty($type_config['height'])) {
            $pic_height = $original_y;
        }
    }
    // defaultimage, wenn nicht gesetzt dann transparentes bild einsetzen
    if ($type_config['defaultimage']) {
        $mod_def = $type_config['defaultimage'];
    } else {
        $mod_def = $cfg_client['space'];
    }
    if (!$mod_url) {
        $mod_url = $mod_def;
    }
    // make global edit_all url
    if (_type_check_editall($cms_side, $type_config)) {
        $cms_edittype[$type_container][$type_number][] = '4-' . $type_typenumber . ',5-' . $type_typenumber;
    }
    // CSS ausfindig machen
    $css = _type_get_style($type_config['styleclass'], $type_config['styleid'], $type_config['styledb']);
    // Wenn style angefordert oder default
    if ($type_config['mode'] == 'style') {
        return $css['style'];
    }
    // Wenn styletype angefordert oder default
    if ($type_config['mode'] == 'styletype') {
        return $css['type'];
    }
    // Wenn fullstyle angefordert oder default
    if ($type_config['mode'] == 'fullstyle') {
        return $css['fullstyle'];
    }
    // Bild generieren
    if (_type_check_editable($cms_side['edit'], $type_config['editable'], $cms_side['view'], isset($cms_side['edit_all']))) {
        // Bearbeitungsbutton / layer erzeugen
        if ($type_config['menuoptions'] != 'false') {
            $title = empty($type_config['title']) ? $mod_lang['type_image'] : $type_config['title'];
            // advanced Modus
            if ($type_config['menuoptions'] == 'advanced') {
                $new = false;
                $delete = false;
                $up = false;
                $down = false;
                // neu anlegen & loeschen
                if ($type_number != '1' || $mod_url != $mod_def) {
                    $new = true;
                    $delete = true;
                }
                // nach oben verschieben
                if ($type_number != '1') {
                    $up = true;
                }
                // nach unten verschieben
                if ($mod_url != $mod_def && $cms_mod['modul']['lastentry'] != 'true') {
                    $down = true;
                }
            }
            $ids = array(4, 5);
            $infos = array('container_number' => $type_container, 'cmstag_id' => $type_typenumber, 'mod_repeat_id' => $type_number, 'title' => $title, 'base_url' => $con_side[$idcatside]['link'], 'mode' => $type_config['menuoptions']);
            //menu erstellen
            $editbutton_image = _type_get_layer_menu($ids, $infos, $delete, $new, $up, $down);
            //Wenn nur editbutton gefordert - Ausgabe BACKEND
            if ($type_config['mode'] == 'editbutton') {
                return $editbutton_image;
            }
        }
        //
        if ($type_config['menuoptions'] != 'false') {
            $mod_content = sprintf("<img src=\"{$mod_url}\"%s%s%s " . $css['fullstyle'] . " />", $mod_descr != '' ? ' alt="' . $mod_descr . '" title="' . $mod_descr . '"' : " alt=\"\"", $pic_width ? ' width="' . ($pic_width - 29) . '"' : '', $pic_height ? ' height="' . ($pic_height - 8) . '"' : '');
            $mod = '<span style="background-color: #DBE3EF; border: 1px solid black; padding: 3px;">' . $mod_content . '<span style="padding-left: 3px;">' . $editbutton_image . '</span></span>';
            $mod = $editbutton . $mod;
        } else {
            if ($type_config['mode'] == 'editbutton') {
                return;
            }
            return sprintf("<img src=\"{$mod_url}\"%s%s%s " . $css['fullstyle'] . " />", $mod_descr != '' ? ' alt="' . $mod_descr . '" title="' . $mod_descr . '"' : " alt=\"\"", $pic_width ? ' width="' . $pic_width . '"' : '', $pic_height ? ' height="' . $pic_height . '"' : '');
        }
    } else {
        // Wenn nur editbutton gefordert - keine Ausgabe Frontend
        if ($type_config['mode'] == 'editbutton') {
            return;
        }
        // Ausgabe image - Frontend
        $mod = sprintf("<img src=\"{$mod_url}\"%s%s%s " . $css['fullstyle'] . " />", $mod_descr != '' ? ' alt="' . $mod_descr . '" title="' . $mod_descr . '"' : " alt=\"\"", $pic_width ? ' width="' . $pic_width . '"' : '', $pic_height ? ' height="' . $pic_height . '"' : '');
    }
    return $mod;
}
예제 #2
0
/**
* Returns complete formatted Image-field
* 
* @Args : formname -> name of the inputfield
*         content -> value of textfield
*         type_config -> array with values from the CMS:tag
*         cms_side['view'] -> the current view of the user, 'edit' or 'preview'
*                  ['edit'] -> 'true' if user set the mod in templateconfig as active
*                              if user set inactiv var is not set
* @Return String HTML field
* @Access public 
*/
function type_form_img($formname, $content, $type_config, $cms_side)
{
    global $db, $cms_db, $cms_lang, $client, $cfg_client;
    // Standardfiletypes laden, wenn keine anderen angegeben, defaults laden
    $ft = strtolower(trim($type_config['filetypes']));
    $filetypes = empty($ft) || $ft == 'true' ? 'jpg,jpeg,gif,png' : $ft;
    $match = array();
    $pathway_string = '';
    if (preg_match_all('#^cms://(idfile|idfilethumb)=(\\d+)$#', $content, $match)) {
        $content = type_form_cmslinks_to_templinks($content);
        $is_thumb = $match['1']['0'] == 'idfilethumb';
        $id = $match['2']['0'];
        $sql = "SELECT\n\t\t\t\tU.idupl, U.filename, U.pictheight, U.pictwidth, U.pictthumbwidth, U.pictthumbheight, F.filetype, D.dirname\n\t\t\tFROM\n\t\t\t\t" . $cms_db['upl'] . " U\n\t\t\t\tLEFT JOIN " . $cms_db['filetype'] . " F USING(idfiletype)\n\t\t\t\tLEFT JOIN " . $cms_db['directory'] . " D ON U.iddirectory=D.iddirectory\n\t\t\tWHERE\n\t\t\t\tU.idclient= '{$client}'\n\t\t\t\tAND D.dirname NOT LIKE('cms/%')\n\t\t\t\tAND U.idupl = '" . $id . "'";
        $db->query($sql);
        if ($db->next_record()) {
            $pic_filename = $db->f('filename');
            $pic_filetype = $db->f('filetype');
            $pic_height = $db->f('pictheight');
            $pic_width = $db->f('pictwidth');
            $pic_thumb_height = $db->f('pictthumbheight');
            $pic_thumb_width = $db->f('pictthumbwidth');
            $name_length = strlen($pic_filename);
            $extension_length = strlen($pic_filetype);
            $t_name = substr($pic_filename, 0, $name_length - $extension_length - 1);
            $t_name .= $cfg_client['thumbext'] . '.' . $pic_filetype;
            $thumb_url = $db->f('dirname') . $t_name;
            if ($is_thumb) {
                $pathway_string = $thumb_url;
            } else {
                $pathway_string = $db->f('dirname') . $db->f('filename');
            }
        }
    }
    $rb =& $GLOBALS['sf_factory']->getObjectForced('GUI', 'RessourceBrowser');
    $res_file =& $GLOBALS['sf_factory']->getObjectForced('GUI/RESSOURCES', 'FileManager');
    $res_file->setFiletypes(type_config_string_to_array($filetypes));
    $res_file->setFolderIds(type_config_string_to_array($type_config['folders']));
    $res_file->setWithSubfoders($type_config['subfolders'] != 'false');
    $res_file->setReturnValueMode('sefrengolink');
    $rb->addRessource($res_file);
    $rb->setJSCallbackFunction('sf_getImage' . $formname, array('picked_name', 'picked_value'));
    $rb_url = $rb->exportConfigURL();
    if (is_file($cfg_client['upl_path'] . $thumb_url)) {
        $img_src = $cfg_client['upl_htmlpath'] . $thumb_url;
        $img_thumb_x = $pic_thumb_width;
        $img_thumb_y = $pic_thumb_height;
    } else {
        if ($pic_height > 0 && $pic_width > 0) {
            $img_src = $cfg_client['upl_htmlpath'] . $pathway_string;
            $extracted_size = _type_calculate_new_image_size($pic_width, $pic_height, $cfg_client['thumb_size'], $cfg_client['thumb_size'], true);
            $img_thumb_x = $extracted_size['width'];
            $img_thumb_y = $extracted_size['height'];
        } else {
            $img_src = $cfg_client['space'];
            $img_thumb_x = $cfg_client['thumb_size'];
            $img_thumb_y = $cfg_client['thumb_size'];
        }
    }
    $out .= '<td width="640" nowrap> <table style="height:' . ($cfg_client['thumb_size'] + 20) . 'px"><tr>
<td style="background-color:#efefef;border:1px solid black;text-align:center;vertical-align:middle;width:' . ($cfg_client['thumb_size'] + 20) . 'px;">
<img id="' . $formname . '" src="' . $img_src . '"  border="0" width="' . $img_thumb_x . '" height="' . $img_thumb_y . '" />
</td><td valign="bottom">';
    $out .= "<input type=\"hidden\" name=\"{$formname}\" value=\"{$content}\"><input type=\"text\" name=\"" . $formname . "display\" readonly=\"readonly\" value=\"" . $pathway_string . "\" style=\"width:560px\" >\n";
    $out .= "<input type='button' value='DEL' onclick=\"sf_getImage" . $formname . "('', '');\" />";
    $out .= "&nbsp;<input type='button' value='...' onclick=\"new_window('{$rb_url}', 'rb', '', screen.width * 0.7, screen.height * 0.7, 'true')\" />";
    $out .= '</td></tr></table></td>' . "\n";
    $out .= '<script type="text/javascript">
	<!--
	function sf_getImage' . $formname . '(name, value) {
		editcontent.' . $formname . '.value= value;
		editcontent.' . $formname . 'display.value= name;
		sf_loadPreviewPic("' . $cfg_client['upl_htmlpath'] . '"+name, "' . $cfg_client['thumbext'] . '", "' . $formname . '");
		//changeImage("media/"+name, value, "' . $formname . '");
		//alert(name + " XXX " +value);
	}
	-->
	</script>';
    return $out;
}