/** * @return string */ function make_link($Link) { $Link = encodeUri($Link); if (eregi("^[a-z0-9\\._-]+@+[a-z0-9\\._-]+\\.+[a-z]{2,4}\$", $Link)) { return "mailto:{$Link}\" class=\"link_email"; } else { if (substr($Link, 0, 4) == 'http') { return "{$Link}\" class=\"link_extern"; } } // TODO: load the title of the page into the link title and set an other css-class if the page does not exists return "index.php?page={$Link}\" class=\"link_intern"; }
function MakeImage($Image) { #[size] {[int_x]X[int_y],[int_maxsize], w[int_maxwidth], thumb=>w180, original=>[orig_x]X[orig_y], big=>800} #[format] {box, box_only, picture} #[Url]|[Title] => [Url]|box|thumb|[Title] #[Url]|[size]|[Title] = [Url]|box|[size]|[Title] #[Url]|[display]|[size]|[Title] // TODO: get the connection throug the parameters, not as a global global $sqlConnection; // Defaults $ImageAlign = IMG_ALIGN_NORMAL; $imageDisplay = IMG_DISPLAY_BOX; $imageSize = 'w180'; $imageWidth = 180; $imageHeight = 180; $imageTitle = ''; $imageUrl = ''; $leftSpace = false; $rightSpace = false; if (substr($Image, 0, 1) == ' ') { $leftSpace = true; } if (substr($Image, -1, 1) == ' ') { $rightSpace = true; } if ($leftSpace && $rightSpace) { $ImageAlign = IMG_ALIGN_CENTER; } else { if ($leftSpace) { $ImageAlign = IMG_ALIGN_LEFT; } else { if ($rightSpace) { $ImageAlign = IMG_ALIGN_RIGHT; } } } // remove spaces at the begin and end of the string $Image = preg_replace("~^\\ *(.+?)\\ *\$~", '$1', $Image); // Split into all Parameters $parameters = explode('|', $Image); // set the path to the local media dir $imageUrl = preg_replace("~^\\media:\\ *(.+?)\$~", 'data/upload/' . '$1', $parameters[0]); $imageTitle = $parameters[0]; //remove first entry (we don't have to check it) unset($parameters[0]); // go through each parameter foreach ($parameters as $key => $value) { // extract the image layout if (preg_match('~^(' . IMG_DISPLAY_BOX_ONLY . '|' . IMG_DISPLAY_BOX . '|' . IMG_DISPLAY_PICTURE . ')$~', $value)) { $imageDisplay = $value; } else { if (preg_match('~^(thumb|original|big|[0-9]+[Xx][0-9]+|[0-9]+|\\w[0-9]+)$~', $value)) { $imageSize = $value; } else { // its the Title of the picture (it is the last unused parameter) $imageTitle = $value; } } } // TODO: // check if the image isn't saved "local", if it is, download it! // extern_{$filename}_timestamp.png // if the file doesn't exists under the given path, try to find it in the database if (!file_exists($imageUrl)) { $sql = "SELECT file_path\n\t\t\t\t\t\tFROM " . DB_PREFIX . "files\n\t\t\t\t\t\tWHERE LOWER(file_path) = '" . strtolower($imageUrl) . "'\n\t\t\t\t\t\t\tOR LOWER(file_name) = '" . strtolower(basename($imageUrl)) . "'\n\t\t\t\t\t\tLIMIT 1"; $result = $sqlConnection->SqlQuery($sql); if ($fileData = mysql_fetch_object($result)) { $imageUrl = $fileData->file_path; } // check if the file from the database really exists if (!file_exists($imageUrl)) { return "<strong>Bild ("<em>{$imageUrl}</em>") nicht gefunden.</strong>"; } } // Resize the image $image = new ImageConverter($imageUrl); // convert the 'name-sizes' to 'pixel-sizes' if ($imageSize == 'thumb') { $imageSize = 'w180'; } else { if ($imageSize == 'big') { $imageSize = '800'; } else { if ($imageSize == 'original') { // took the original sizes $imageWidth = $image->Size[0]; $imageHeight = $image->Size[1]; } } } // 'width-format'' if (preg_match('~^w[0-9]+$~', $imageSize)) { $imageWidth = substr($imageSize, 1); // calculate the proporitonal height $imageHeight = round($image->Size[1] / $image->Size[0] * $imageWidth, 0); } else { if (preg_match('~^[0-9]+$~', $imageSize)) { // look for the longer side and resize it to te given size, // short the other side proportional to the longer side $imageWidth = $image->Size[0] > $image->Size[1] ? round($imageSize, 0) : round($image->Size[0] / ($image->Size[1] / $imageSize), 0); $imageHeight = $image->Size[1] > $image->Size[0] ? round($imageSize, 0) : round($image->Size[1] / ($image->Size[0] / $imageSize), 0); } else { if (preg_match('~^([0-9]+)[Xx]([0-9]+)$~', $imageSize, $maches)) { // took the given sizes $imageWidth = $maches[1] < $image->Size[0] ? $maches[1] : $image->Size[0]; $imageHeight = $maches[2] < $image->Size[1] ? $maches[2] : $image->Size[1]; } } } $originalUrl = encodeUri($imageUrl); // str_replace(' ', '%20', basename($imageUrl)); // TODO: don't use the global global $config; // check if the image exists already $thumbnailfolder = $config->Get('thumbnailfolder', 'data/thumbnails/'); if (file_exists($thumbnailfolder . '/' . $imageWidth . 'x' . $imageHeight . '_' . basename($imageUrl))) { $imageUrl = $thumbnailfolder . '/' . $imageWidth . 'x' . $imageHeight . '_' . basename($imageUrl); } else { if ($image->Size[0] >= $imageWidth && $image->Size[1] > $imageHeight || $image->Size[0] > $imageWidth && $image->Size[1] >= $imageHeight) { $imageUrl = $image->SaveResizedTo($imageWidth, $imageHeight, $thumbnailfolder, $imageWidth . 'x' . $imageHeight . '_'); if ($imageUrl === false) { return "Not enough memory available!(resize your image!)"; } } else { $imageWidth = $image->Size[0]; $imageHeight = $image->Size[1]; } } if ($imageDisplay == IMG_DISPLAY_BOX) { $imageString = "</p>\n\n<div class=\"thumb t" . $ImageAlign . "\">\n\t\t\t\t\t\t<div style=\"width:" . ($imageWidth + 4) . "px\">\n\t\t\t\t\t\t\t<img width=\"{$imageWidth}\" height=\"{$imageHeight}\" src=\"{$imageUrl}\" title=\"{$imageTitle}\" alt=\"{$imageTitle}\" />\n\t\t\t\t\t\t\t<div class=\"description\" title=\"{$imageTitle}\"><div class=\"magnify\"><a href=\"special.php?page=image&file={$originalUrl}\" title=\"vergrößern\"><img src=\"img/magnify.png\" title=\"vergrößern\" alt=\"vergrößern\"/></a></div>{$imageTitle}</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div><p>\n"; } else { if ($imageDisplay == IMG_DISPLAY_BOX_ONLY) { $imageString = "</p>\n\n<div class=\"thumb tbox t" . $ImageAlign . "\">\n\t\t\t\t\t\t<div style=\"width:" . ($imageWidth + 4) . "px\">\n\t\t\t\t\t\t\t<img width=\"{$imageWidth}\" height=\"{$imageHeight}\" src=\"{$imageUrl}\" title=\"{$imageTitle}\" alt=\"{$imageTitle}\" />\n\t\t\t\t\t\t\t<div class=\"magnify\"><a href=\"special.php?page=image&file={$originalUrl}\" title=\"vergrößern\"><img src=\"img/magnify.png\" title=\"vergrößern\" alt=\"vergrößern\"/></a></div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n<p>"; } else { if ($imageDisplay == IMG_DISPLAY_PICTURE) { $imageString = "</p>\n\n<div class=\"thumb tbox t" . $ImageAlign . "\">\n\t\t\t\t\t<img width=\"{$imageWidth}\" height=\"{$imageHeight}\" src=\"{$imageUrl}\" title=\"{$imageTitle}\" alt=\"{$imageTitle}\" />\n\t\t\t\t\t</div><p>"; } } } return "{$imageString}"; }