';
return true;
break;
case 'frontend_image_add_unknown':
case 'frontend_image_add_filenameonly':
case 'frontend_image_selector_submit':
case 'frontend_image_selector_more':
case 'frontend_image_selector_imagecomment':
case 'frontend_image_selector_imagealign':
case 'frontend_image_selector_imagesize':
case 'frontend_image_selector_hiddenfields':
return true;
break;
case 'frontend_image_selector_imagelink':
$this->display_target_selectbox();
return true;
break;
case 'css_backend':
if ($serendipity['version'][0] > '1') {
?>
#quickblog_tablefield {
display: table-cell;
}
#uploadform .quickblog_nugget {
margin-left: 0;
padding: 0;
}
#uploadform .quickblog_form_field {
margin: .375em 0;
}
#uploadform .radio_field label {
padding-left: .5em;
}
display_script();
return true;
break;
default:
return false;
}
} else {
return false;
}
}
/*
* function parse_quickblog_post makes a quickblog post from the picture
* given by $path @string
*/
function parse_quickblog_post($path, &$body) {
global $serendipity;
$file = basename($path);
$dir = dirname($path) . '/';
$t = serendipity_parseFileName($file);
$f = $t[0];
$suf = $t[1];
$infile = $dir . $file;
$outfile = $dir . $f . '.quickblog.' . $suf;
// check for existing image.quickblog thumb (see change in backend_image_addHotlink) else change to default thumbnail name
if (!file_exists($outfile)) $outfile = $dir . $f . '.serendipityThumb.' . $suf;
if (function_exists('exif_read_data') && file_exists($infile) && !serendipity_db_bool($this->get_config('force_jhead'))) {
$exif = @exif_read_data($infile);
$exif_mode = 'internal';
} elseif (file_exists($infile)) {
$exif_mode = 'jhead';
$exif_raw = explode("\n", @`jhead $infile`);
$exif = array();
foreach((array)$exif_raw AS $line) {
preg_match('@^(.+):(.+)$@U', $line, $data);
$key = preg_replace('@[^a-z0-9]@i', '_', trim($data[1]));
if (empty($key)) {
continue;
}
$exif[$key] .= trim($data[2]) . "\n";
}
if (count($exif) < 1) {
$exif = false;
}
} else {
$exif = false;
$exif_mode = 'none';
}
$http_infile = $this->httpize($infile);
$http_outfile = $this->httpize($outfile);
$quickblog = array(
'image' => $http_outfile,
'fullimage' => $http_infile,
'body' => preg_replace('@()@imsU', '', $body),
'exif' => &$exif,
'exif_mode' => $exif_mode
);
$tfile = serendipity_getTemplateFile('quickblog.tpl', 'serendipityPath');
if (!$tfile || $tfile == 'quickblog.tpl') {
$tfile = dirname(__FILE__) . '/quickblog.tpl';
}
$serendipity['smarty']->assign('quickblog', $quickblog);
$content = $this->parseTemplate($tfile);
return $content;
}
/*
* display_target_selectbox()
* displays select box for choosing target of image in the image selector
* depreceated, in new version >0.9 already in admin_image_selector.php
*/
function display_target_selectbox() {
?>
[\S\s]*?)@', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
// parse mediainserts
// (if xml parser is present at php installation
// - SimpleXMLElement in PHP > 5.0, users of older version could have troubles )
// text is splitted into parts
if (class_exists('SimpleXMLElement')) {
for ($i=0, $pcount = count($entry_parts); $i < $pcount; $i++) {
if (!(strpos($entry_parts[$i],"") === false)) {
// There was a problem with wysiwyg-ckeditor: which removes linebreaks and sometimes inserts ending tags
// To not error, we remove at least the ending tags and possibly single-tags missing trailing slashes
$epart = str_replace(array('','','">'), array('','','" />'), $entry_parts[$i]);
$xml = new SimpleXMLElement($epart);
$gallery = $xml->gallery['name'];
$medias = array();
$whole_gallery = false;
foreach ($xml->media as $medium) {
switch((string) $medium['type']) { // Get attributes as element indices
case 'single':
$medias[] = serendipity_db_escape_string($medium['name']);
break;
case 'range':
for ($j=intval($medium['start']);$j<=intval($medium['stop']);$j++) {
$medias[] = serendipity_db_escape_string($medium['prefix']) . $j;
}
break;
case 'gallery':
$whole_gallery = true;
break;
default:
break;
}
}
// here we have desired gallery and desired pictures
// now read available ones from database
if ($whole_gallery) {
$q = "SELECT id,name,extension,thumbnail_name,realname,path,value as comment1,dimensions_width as width, dimensions_height as height
FROM {$serendipity['dbPrefix']}images as i
LEFT JOIN {$serendipity['dbPrefix']}mediaproperties as p ON (p.mediaid = i.id AND p.property='COMMENT1')
WHERE i.path = '" . serendipity_db_escape_string($gallery) . "' ";
} else {
$images_suggestions = "'".implode("','",$medias)."'";
$q = "SELECT id,name,extension,thumbnail_name,realname,path,value as comment1,dimensions_width as width, dimensions_height as height
FROM {$serendipity['dbPrefix']}images as i
LEFT JOIN {$serendipity['dbPrefix']}mediaproperties as p ON (p.mediaid = i.id AND p.property='COMMENT1')
WHERE i.path = '" . serendipity_db_escape_string($gallery) . "' AND i.name IN ($images_suggestions)";
}
$t = serendipity_db_query($q, false, 'assoc');
// here we have to order the results from database to respect
// the order of pictures in xml entry
// and at the same time we calculate thumbs size
$thumb_size = $serendipity['thumbSize'];
$order = array();
if (is_array($t)) {
for ($j=0, $tcount = count($t) ; $j < $tcount ; $j++) {
$h = intval($t[$j]["height"]);
$w = intval($t[$j]["width"]);
$h = $h==0 ? 1 : $h; // avoid 'Division by zero' errors for height
$w = $w==0 ? 1 : $w; // dito for width
if ($w > $h) {
$t[$j]["thumbheight"] = round($thumb_size*$h/$w);
$t[$j]["thumbwidth"] = round($thumb_size);
} else {
$t[$j]["thumbheight"] = round($thumb_size);
$t[$j]["thumbwidth"] = round($thumb_size*$w/$h);
}
if (strlen($t[$j]["comment1"]) == 0) {
#$t[$j][6] = $t[$j]["name"];// add missing new num key if not using assoc select
$t[$j]["comment1"] = $t[$j]["name"];
}
$order[$j] = array_search($t[$j]["name"], $medias);
if (strlen($t[$j]["thumbnail_name"]) == 0) {
array_splice($t,$j,1);
$j--;
$tcount--;
}
}
array_multisort($order, SORT_ASC, SORT_NUMERIC, $t);
// now make an output using template
$tfile = serendipity_getTemplateFile('plugin_mediainsert.tpl', 'serendipityPath');
if (!$tfile || $tfile == 'plugin_mediainsert.tpl') {
$tfile = dirname(__FILE__) . '/plugin_mediainsert.tpl';
}
$serendipity['smarty']->assign('plugin_mediainsert_media', $t);
$serendipity['smarty']->assign('plugin_mediainsert_entry', $eventData);
$content = $this->parseTemplate($tfile);
} else {
// if there are no available images, do no output
$content= "";
}
// fetch the output
$entry_parts[$i] = $content;
}
}
}
return implode("", $entry_parts);
}
//////////////////////////////////////////////////////////////
/// The following methods are used for the auto image resizing
/**
* Substitute img src attributes in $html with auto resize urls
*
* @author Adam Charnock (http://omniwiki.co.uk)
* @param string $html
* @return string The HTML with the transformed images
*/
function substituteImages($html) {
$imgTags = $this->getImageTags($html);
//We need to make sure we substitute the last images first otherwise
//our char offsets will get messed up
$imgTags = array_reverse($imgTags);
foreach ($imgTags as $attrs) {
$newTag = ' $v) {
if (strpos($k, '_') !== 0) {
if ($k == 'src') {
$v = $this->getTransformImg($attrs);
}
$quote = (strpos($v, '"') !== false) ? "'" : '"';
$attrPairs[] = "$k=$quote$v$quote";
}
}
$newTag .= ' ' . implode(' ', $attrPairs) . ' />';
//Now we need to splice the new tag into the HTML
$firstHalf = substr($html, 0, $attrs['_offset']);
$secondHalf = substr($html, $attrs['_offset'] + $attrs['_length']);
$html = $firstHalf . $newTag . $secondHalf;
}
return $html;
}
/**
* Gets an image ID based on the URL
*
* The URL can be in the form:
*
* /uploads/fireworks.jpg
* or
* /templates_c/mediacache/cache_img1_300_300
*
* The first example will cause the database to be queried. In the second
* example the image ID will be extracted directly from the URL
*
* @param string The image URL
* @return mixed An image ID if the URL could be matched, or false if the URL could not be matched
*/
function getImageIdByUrl($url){
global $serendipity;
if (preg_match('#.*templates_c/mediacache/cache_img(\d+)_(\d*)_(\d*)#i', $url, $m)) {
$imageId = $m[1];
} else if (preg_match('#.*uploads(.*/)([^/]+)\.([a-z0-9]+)#i', $url, $m)) {
$name = serendipity_db_escape_string($m[2]);
$extension = serendipity_db_escape_string($m[3]);
$path = serendipity_db_escape_string(ltrim($m[1], '/'));
$sql = "SELECT id FROM {$serendipity['dbPrefix']}images WHERE name = '%s' AND extension = '%s' AND path = '%s'";
$sql = sprintf($sql, $name, $extension, $path);
$row = serendipity_db_query($sql, true);
$imageId = $row['id'];
} else {
//We got an unrecognised url so return false
$imageId = false;
}
return $imageId;
}
/**
* Get the transformed src for an img tag
*
* @author Adam Charnock (http://omniwiki.co.uk)
* @param array $attrs An associative array of the image's attributes. Must conatain src, and either width or height
* @return unknown
*/
function getTransformImg($attrs) {
global $serendipity;
/*
Image URLs can be expected to look like either:
/uploads/fireworks.jpg
or
/templates_c/mediacache/cache_img1_300_300
*/
if (!isset($attrs['src']) || !$attrs['src']) {
trigger_error('The $attrs parameter must contain a "src" key', E_USER_ERROR);
}
if ((!isset($attrs['height']) || !$attrs['height']) && (!isset($attrs['width']) || !$attrs['width'])) {
//Without any height or width values we cannot do anything
return $attrs['src'];
}
$url = $attrs['src'];
$imageId = $this->getImageIdByUrl($url);
if (!$imageId) {
//We got an unrecognised url so don't do anything to it, just send it right back
return $url;
}
//Create the new, transformed URL
$newUrl = rtrim($serendipity['baseURL'], '/') . '/serendipity_admin_image_selector.php?serendipity[image]=%d&serendipity[disposition]=inline&serendipity[step]=showItem';
if (isset($attrs['height']) && $attrs['height']) {
$newUrl .= '&serendipity[resizeHeight]=' . (int)($attrs['height']);
}
if (isset($attrs['width']) && $attrs['width']) {
$newUrl .= '&serendipity[resizeWidth]=' . (int)($attrs['width']);
}
$newUrl = sprintf($newUrl, $imageId);
return $newUrl;
}
/**
* Parses image tags out of a chunk of HTML
*
* @author Adam Charnock (http://omniwiki.co.uk)
* @param string $html
* @return array An array of image tags. Each tag is an associative array of its attributes, plus _offset and _length
*/
function getImageTags($html) {
//Thanks to the following blog post for the inspiration for this regex:
//http://kev.coolcavemen.com/2007/03/ultimate-regular-expression-for-html-tag-parsing-with-php/
preg_match_all("/<\/?(\w+)((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/i", $html, $m, PREG_OFFSET_CAPTURE);
$tags = array('types' => $m[1], 'attrs' => $m[2], 'wholetags' => $m[0]);
//At this stage $tags['attrs'] is just an unparsed string
$imgTags = array();
for ($i=0; $iparseAttrs($tags['attrs'][$i][0]);
if (isset($parsedAttrs['src'])) {
$parsedAttrs['_offset'] = $tags['wholetags'][$i][1];
$parsedAttrs['_length'] = strlen($tags['wholetags'][$i][0]);
$imgTags[] = $parsedAttrs;
}
}
}
return $imgTags;
}
/**
* Parse the attribute portion of an HTML/XHTML/XML tag
*
* The $atts param should (or rather, can) look something like:
* width="400" height="300" border=0 alt="This is an example!"
*
* Which will produce an array as follows:
*
*