Smarty3
This commit is contained in:
parent
23e5de77b7
commit
2749dc54ad
@ -4,6 +4,8 @@
|
||||
Version 1.7 ()
|
||||
------------------------------------------------------------------------
|
||||
|
||||
* EXPERIMENTAL: Smarty3 support (ophian)
|
||||
|
||||
* Added new serendipity['defaultBaseURL'] variable that makes sure
|
||||
that the baseURL is not overriden when configuring serendipity
|
||||
with a possibly autodetected currentl URL. Patch by Manko10.
|
||||
|
@ -430,7 +430,7 @@ function serendipity_printComments($comments, $parentid = 0, $depth = 0, $trace
|
||||
return true;
|
||||
}
|
||||
|
||||
$serendipity['smarty']->assign_by_ref($smarty_block == 'COMMENTS'?'comments':'trackbacks', $_smartyComments);
|
||||
$serendipity['smarty']->assignByRef($smarty_block == 'COMMENTS'?'comments':'trackbacks', $_smartyComments);
|
||||
unset($_smartyComments);
|
||||
|
||||
return serendipity_smarty_fetch($smarty_block, $smarty_file);
|
||||
@ -487,7 +487,7 @@ function serendipity_printCommentsByAuthor() {
|
||||
$entry_comments[$entry_id]['tpl_comments'] =& serendipity_printComments($_data['comments'], VIEWMODE_LINEAR, 0, null, 'COMMENTS', 'comments.tpl');
|
||||
}
|
||||
|
||||
$serendipity['smarty']->assign_by_ref('comments_by_authors', $entry_comments);
|
||||
$serendipity['smarty']->assignByRef('comments_by_authors', $entry_comments);
|
||||
|
||||
if (!empty($id)) {
|
||||
$and .= " AND co.entry_id = '" . (int)$id ."'";
|
||||
|
@ -834,7 +834,7 @@ function serendipity_iframe(&$entry, $mode = null, $use_smarty = true) {
|
||||
if ($use_smarty) {
|
||||
$preview = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$serendipity['smarty']->assign_by_ref('preview', $preview);
|
||||
$serendipity['smarty']->assignByRef('preview', $preview);
|
||||
$serendipity['smarty']->display(serendipity_getTemplateFile('preview_iframe.tpl', 'serendipityPath'));
|
||||
}
|
||||
|
||||
@ -2172,7 +2172,7 @@ function serendipity_loadGlobalThemeOptions(&$template_config, &$template_loaded
|
||||
);
|
||||
}
|
||||
|
||||
$serendipity['smarty']->assign_by_ref('navlinks', $navlinks);
|
||||
$serendipity['smarty']->assignByRef('navlinks', $navlinks);
|
||||
}
|
||||
|
||||
// Forward thinking. ;-)
|
||||
|
@ -1200,7 +1200,7 @@ function serendipity_printEntries($entries, $extended = 0, $preview = false, $sm
|
||||
return $dategroup;
|
||||
}
|
||||
|
||||
$serendipity['smarty']->assign_by_ref('entries', $dategroup);
|
||||
$serendipity['smarty']->assignByRef('entries', $dategroup);
|
||||
unset($entries, $dategroup);
|
||||
|
||||
if (isset($serendipity['short_archives']) && $serendipity['short_archives']) {
|
||||
@ -1658,8 +1658,8 @@ function serendipity_printArchives() {
|
||||
}
|
||||
}
|
||||
|
||||
$serendipity['smarty']->assign_by_ref('archives', $output);
|
||||
$serendipity['smarty']->assign_by_ref('max_entries', $max);
|
||||
$serendipity['smarty']->assignByRef('archives', $output);
|
||||
$serendipity['smarty']->assignByRef('max_entries', $max);
|
||||
|
||||
serendipity_smarty_fetch('ARCHIVES', 'entries_archives.tpl', true);
|
||||
}
|
||||
|
@ -176,10 +176,10 @@ function serendipity_printEntryForm($targetURL, $hiddens = array(), $entry = arr
|
||||
|
||||
$template_vars['entry_template'] = serendipity_getTemplateFile('admin/entries.tpl', 'serendipityPath');
|
||||
|
||||
$serendipity['smarty']->register_modifier('emit_htmlarea_code', 'serendipity_emit_htmlarea_code');
|
||||
$serendipity['smarty']->registerPlugin('modifier', 'emit_htmlarea_code', 'serendipity_emit_htmlarea_code');
|
||||
$serendipity['smarty']->assign('admin_view', 'entryform');
|
||||
serendipity_plugin_api::hook_event('backend_entryform_smarty', $template_vars);
|
||||
$serendipity['smarty']->assign_by_ref('entry_vars', $template_vars);
|
||||
$serendipity['smarty']->assignByRef('entry_vars', $template_vars);
|
||||
$serendipity['smarty']->display($template_vars['entry_template']);
|
||||
return true;
|
||||
}
|
||||
|
@ -2864,7 +2864,7 @@ function serendipity_showMedia(&$file, &$paths, $url = '', $manage = false, $lin
|
||||
$media['paths'] =& serendipity_getMediaPaths();
|
||||
}
|
||||
|
||||
$serendipity['smarty']->assign_by_ref('media', $media);
|
||||
$serendipity['smarty']->assignByRef('media', $media);
|
||||
|
||||
if ($enclose) {
|
||||
serendipity_smarty_fetch('MEDIA_ITEMS', 'admin/media_items.tpl');
|
||||
@ -2895,7 +2895,7 @@ function serendipity_metaFieldConvert(&$item, $type) {
|
||||
switch($type) {
|
||||
case 'math':
|
||||
$parts = explode('/', $item);
|
||||
return ($parts[0] / $parts[1]);
|
||||
return ($parts[1] > 0) ? ($parts[0] / $parts[1]) : 0;
|
||||
break;
|
||||
|
||||
case 'or':
|
||||
|
@ -1,450 +1,450 @@
|
||||
<?php
|
||||
/**************************************************
|
||||
* imgedit.inc.php
|
||||
* 2003-10-17
|
||||
* www.sonnd.com / www.supergarv.de
|
||||
*
|
||||
* COPYRIGHT (C) BY sonnd / Garvin Hicking
|
||||
* Published as LGPL. Copyright notice has to stay in effect.
|
||||
**************************************************/
|
||||
|
||||
class imgedit {
|
||||
// Needed variables.
|
||||
var $orientation_available;
|
||||
var $real_img_name, $real_img_info, $real_img_width, $real_img_height, $http_img_name;
|
||||
var $img_width, $img_height, $img_name;
|
||||
var $zoombox_width;
|
||||
var $area_border, $area_width, $area_height, $inner_area_x, $inner_area_y;
|
||||
var $harea_width, $harea_height, $harea_img_name, $harea_visibility;
|
||||
var $varea_width, $varea_height, $varea_img_name, $varea_visibility;
|
||||
var $ratio;
|
||||
var $overlay_clip_top, $overlay_clip_bottom, $overlay_clip_left, $overlay_clip_right;
|
||||
var $slice_from_x, $slice_from_y, $slice_to_x, $slice_to_y;
|
||||
var $output_template = '';
|
||||
var $imgedit_smarty = array();
|
||||
|
||||
// Helper function to cycle through an array. Strips of "_x" and "_y" coordinates if an 'input type="image"'
|
||||
// variable has been submitted.
|
||||
function makeImgComp(&$array) {
|
||||
foreach($array AS $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$this->makeImgComp($array[$key]);
|
||||
} elseif (preg_match('@^.*_(x|y)$@', $key)) {
|
||||
$array[preg_replace('@^(.*)_(x|y)$@', '\1', $key)] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Constructor.
|
||||
function imgedit($img_name, $http_img_name) {
|
||||
global $serendipity;
|
||||
$this->makeImgComp($_REQUEST);
|
||||
|
||||
// Store the given variables
|
||||
$this->real_img_name = $this->img_name = $img_name;
|
||||
$this->real_img_info = getimagesize($this->real_img_name);
|
||||
$this->real_img_width = $this->real_img_info[0];
|
||||
$this->real_img_height = $this->real_img_info[1];
|
||||
|
||||
$this->http_img_name = $http_img_name;
|
||||
|
||||
// Set even more variables
|
||||
$this->setDefaults();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// The main logic
|
||||
function main() {
|
||||
|
||||
// 1. Parse the $_REQUEST vars.
|
||||
$this->parseRequest();
|
||||
|
||||
// 2. Get the current size of the cropping area
|
||||
$this->getCurrentArea();
|
||||
|
||||
// 3. Parse any actions
|
||||
$this->parseRequestActions();
|
||||
|
||||
// 4. Valide the results of any actions
|
||||
$this->validateCoordinates();
|
||||
|
||||
// 5. Populate the template
|
||||
$this->setVars();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sets default vars.
|
||||
function setDefaults() {
|
||||
$this->orientation_available = true;
|
||||
|
||||
$this->img_width = $this->real_img_width;
|
||||
$this->img_height = $this->real_img_height;
|
||||
$this->img_name = $this->real_img_name;
|
||||
|
||||
$this->zoombox_width = 100;
|
||||
$this->area_border = 6;
|
||||
|
||||
// Set values if they haven't been submitted yet.
|
||||
if (!isset($_REQUEST['area_orientation']) || ($_REQUEST['area_orientation'] != 'h' && $_REQUEST['area_orientation'] != 'v')) {
|
||||
$_REQUEST['area_orientation'] = 'h';
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['autoguess_clicked'])) {
|
||||
$_REQUEST['autoguess_clicked'] = 'false';
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['zoombox_x'])) {
|
||||
$_REQUEST['zoombox_x'] = -$this->area_border;
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['zoombox_y'])) {
|
||||
$_REQUEST['zoombox_y'] = -$this->area_border;
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['move_increase'])) {
|
||||
$_REQUEST['move_increase'] = 8;
|
||||
} else {
|
||||
$_REQUEST['move_increase'] = intval($_REQUEST['move_increase']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Parse the $_REQUEST vars
|
||||
function parseRequest() {
|
||||
if (isset($_REQUEST['toggle_area_orientation'])) {
|
||||
if ($_REQUEST['area_orientation'] == 'h') {
|
||||
$_REQUEST['area_orientation'] = 'v';
|
||||
} else {
|
||||
$_REQUEST['area_orientation'] = 'h';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['zoombox_factor'])) {
|
||||
$_REQUEST['zoombox_factor'] = floatval($_REQUEST['zoombox_factor']);
|
||||
} else {
|
||||
$_REQUEST['zoombox_factor'] = 1;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['action']['enlarge'])) {
|
||||
$_REQUEST['zoombox_factor'] += 0.1;
|
||||
} elseif (isset($_REQUEST['action']['reduce'])) {
|
||||
$_REQUEST['zoombox_factor'] -= 0.1;
|
||||
}
|
||||
|
||||
if ($_REQUEST['zoombox_factor'] > 3) {
|
||||
$_REQUEST['zoombox_factor'] = 3;
|
||||
} elseif ($_REQUEST['zoombox_factor'] < 0.1) {
|
||||
$_REQUEST['zoombox_factor'] = 0.1;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['action']['moveup'])) {
|
||||
$_REQUEST['zoombox_y'] -= $_REQUEST['move_increase'];
|
||||
} elseif (isset($_REQUEST['action']['movedown'])) {
|
||||
$_REQUEST['zoombox_y'] += $_REQUEST['move_increase'];
|
||||
} elseif (isset($_REQUEST['action']['moveleft'])) {
|
||||
$_REQUEST['zoombox_x'] -= $_REQUEST['move_increase'];
|
||||
} elseif (isset($_REQUEST['action']['moveright'])) {
|
||||
$_REQUEST['zoombox_x'] += $_REQUEST['move_increase'];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fit an image inside the cropping area.
|
||||
function imgFit($orientation) {
|
||||
if ($orientation == 'height') {
|
||||
$this->imgFitHeight();
|
||||
} else {
|
||||
$this->imgFitWidth();
|
||||
}
|
||||
|
||||
$_REQUEST['zoombox_factor'] = $this->ratio;
|
||||
$_REQUEST['autoguess_clicked'] = 'true';
|
||||
$_REQUEST['zoombox_x'] = -$this->area_border;
|
||||
$_REQUEST['zoombox_y'] = -$this->area_border;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fit an image, using height as fixed value
|
||||
function imgFitHeight() {
|
||||
$this->img_height = $this->inner_area_y - $this->area_border;
|
||||
$this->ratio = round($this->img_height / $this->real_img_height, 3);
|
||||
$this->img_width = intval(round($this->real_img_width * $this->ratio));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fit an image, using width as fixed value
|
||||
function imgFitWidth() {
|
||||
$this->img_width = $this->inner_area_x - $this->area_border;
|
||||
$this->ratio = round($this->img_width / $this->real_img_width, 3);
|
||||
$this->img_height = intval(round($this->real_img_height * $this->ratio));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Parse actions that were submitted
|
||||
function parseRequestActions() {
|
||||
global $serendipity;
|
||||
|
||||
if (isset($_REQUEST['autoscale'])) {
|
||||
|
||||
if ($this->real_img_width > $this->real_img_height) {
|
||||
// The image is a horizontal one. Resize height to fit.
|
||||
$this->imgFit('height');
|
||||
} else {
|
||||
// The image is a vertical one. Resize width to fit.
|
||||
$this->imgFit('width');
|
||||
}
|
||||
|
||||
|
||||
} elseif (isset($_REQUEST['scale'])) {
|
||||
|
||||
|
||||
if ($this->real_img_width > $this->real_img_height) {
|
||||
// The image is a horizontal one. Resize width to fit.
|
||||
$this->imgFit('width');
|
||||
} else {
|
||||
// The image is a vertical one. Resize height to fit.
|
||||
$this->imgFit('height');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$this->img_width = intval(round($this->real_img_width * $_REQUEST['zoombox_factor']));
|
||||
$this->img_height = intval(round($this->real_img_height * $_REQUEST['zoombox_factor']));
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Check which template to use
|
||||
if (isset($_REQUEST['crop'])) {
|
||||
$this->output_template = 'admin/media_imgedit_done.tpl';
|
||||
} else {
|
||||
$this->output_template = 'admin/media_imgedit.tpl';
|
||||
if ($this->orientation_available) {
|
||||
$this->imgedit_smarty['orientation_available'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// The final action. Cropping will take place.
|
||||
if (isset($_REQUEST['crop'])) {
|
||||
$new_img_name = $this->img_name . '.tmp';
|
||||
|
||||
if ($this->img_width <= $this->area_width && $this->img_height <= $this->area_height) {
|
||||
$this->imgedit_smarty['image_no_cut'] = true;
|
||||
|
||||
$new_img_width = $this->img_width;
|
||||
$new_img_height = $this->img_height;
|
||||
} else {
|
||||
$this->imgedit_smarty['image_cut'] = true;
|
||||
|
||||
$new_img_width = $this->area_width - $this->area_border - $this->area_border;
|
||||
$new_img_height = $this->area_height - $this->area_border - $this->area_border;
|
||||
}
|
||||
|
||||
$this->slice_from_x = ($this->area_border + $_REQUEST['zoombox_x']) / $_REQUEST['zoombox_factor'];
|
||||
$this->slice_from_y = ($this->area_border + $_REQUEST['zoombox_y']) / $_REQUEST['zoombox_factor'];
|
||||
|
||||
$slice_width = $new_img_width / $_REQUEST['zoombox_factor'];
|
||||
$slice_height = $new_img_height / $_REQUEST['zoombox_factor'];
|
||||
|
||||
$this->slice_to_x = $this->slice_from_x + $this->slice_width;
|
||||
$this->slice_to_y = $this->slice_from_y + $this->slice_height;
|
||||
|
||||
// TODO:
|
||||
// - Operate also on PNG, TIFF etc.
|
||||
// - Support image magick
|
||||
// - Save file as new image!
|
||||
// - Optionally ask whether to only make a thumbnail from the extracted portion
|
||||
|
||||
// PHP: int imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
|
||||
// Open the user's image.
|
||||
$img_res = imagecreatefromjpeg($this->img_name);
|
||||
|
||||
// Init a blank picture to save the cropped image in.
|
||||
$new_img_res = imagecreatetruecolor($new_img_width, $new_img_height);
|
||||
|
||||
// Crop the image based on user input, save the resulting image. If either action fails, report an error.
|
||||
if (!imagecopyresampled($new_img_res, $img_res, 0, 0, $this->slice_from_x, $this->slice_from_y, $new_img_width, $new_img_height, $slice_width, $slice_height) ||
|
||||
!imageJpeg($new_img_res, $new_img_name, 90)) {
|
||||
|
||||
$this->imgedit_smarty['image_error'] = true;
|
||||
}
|
||||
|
||||
$backup = $this->increment($this->img_name);
|
||||
rename($this->img_name, $backup . '.backup');
|
||||
rename($new_img_name, $this->img_name);
|
||||
$http_new_file = preg_replace('@^' . preg_quote($serendipity['serendipityPath'] . $serendipity['uploadPath']) . '@', '', $this->img_name);
|
||||
serendipity_makeThumbnail(basename($http_new_file), dirname($http_new_file) . '/');
|
||||
|
||||
$this->img_name = $new_img_name;
|
||||
$this->img_width = $new_img_width;
|
||||
$this->img_height = $new_img_height;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function increment($fullfile) {
|
||||
$d = dirname($fullfile) . '/';
|
||||
$f = basename($fullfile);
|
||||
|
||||
$f = time() . '.' . $f;
|
||||
|
||||
return $d . $f;
|
||||
}
|
||||
|
||||
// Checks if any coordinates are out of allowed range
|
||||
function validateCoordinates() {
|
||||
if ($this->img_width > $this->area_width) {
|
||||
$c_img_width = $this->img_width;
|
||||
$ca_img_width = $this->area_width;
|
||||
$x_area_border = $this->area_border;
|
||||
} else {
|
||||
$c_img_width = $this->area_width;
|
||||
$ca_img_width = $this->img_width;
|
||||
$x_area_border = -$this->area_border;
|
||||
}
|
||||
|
||||
if ($this->img_height > $this->area_height) {
|
||||
$c_img_height = $this->img_height;
|
||||
$ca_img_height = $this->area_height;
|
||||
$y_area_border = $this->area_border;
|
||||
} else {
|
||||
$c_img_height = $this->area_height;
|
||||
$ca_img_height = $this->img_height;
|
||||
$y_area_border = -$this->area_border;
|
||||
}
|
||||
|
||||
if ($_REQUEST['zoombox_x'] < (0 - $this->area_border)) {
|
||||
$_REQUEST['zoombox_x'] = 0 - $this->area_border;
|
||||
} elseif ($_REQUEST['zoombox_x'] > ($this->img_width - $ca_img_width + $x_area_border)) {
|
||||
$_REQUEST['zoombox_x'] = $this->img_width - $ca_img_width + $x_area_border;
|
||||
}
|
||||
|
||||
if ($_REQUEST['zoombox_y'] < (0 - $this->area_border)) {
|
||||
$_REQUEST['zoombox_y'] = 0 - $this->area_border;
|
||||
} elseif ($_REQUEST['zoombox_y'] > ($this->img_height - $ca_img_height + $y_area_border)) {
|
||||
$_REQUEST['zoombox_y'] = $this->img_height - $ca_img_height + $y_area_border;
|
||||
}
|
||||
|
||||
$this->overlay_clip_top += $_REQUEST['zoombox_y'];
|
||||
$this->overlay_clip_bottom += $_REQUEST['zoombox_y'];
|
||||
$this->overlay_clip_left += $_REQUEST['zoombox_x'];
|
||||
$this->overlay_clip_right += $_REQUEST['zoombox_x'];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sets the sizes of the cropping area
|
||||
function setArea($img_name, $orientation = 'h') {
|
||||
global $serendipity;
|
||||
|
||||
$fimg = serendipity_getTemplateFile('admin/img/' . $img_name, 'serendipityPath');
|
||||
$hfimg = serendipity_getTemplateFile('admin/img/' . $img_name, 'serendipityHTTPPath');
|
||||
$img_info = getImageSize($fimg);
|
||||
|
||||
if ($orientation == 'h') {
|
||||
$this->harea_width = $img_info[0];
|
||||
$this->harea_height = $img_info[1];
|
||||
$this->harea_img_name = $hfimg;
|
||||
} else {
|
||||
$this->varea_width = $img_info[0];
|
||||
$this->varea_height = $img_info[1];
|
||||
$this->varea_img_name = $hfimg;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the size of the selected cropping area
|
||||
function getCurrentArea() {
|
||||
if ($_REQUEST['area_orientation'] == 'h') {
|
||||
$this->area_width = $this->harea_width;
|
||||
$this->area_height = $this->harea_height;
|
||||
$this->varea_visibility = 'hidden';
|
||||
$this->harea_visibility = 'visible';
|
||||
} else {
|
||||
$this->area_width = $this->varea_width;
|
||||
$this->area_height = $this->varea_height;
|
||||
$this->varea_visibility = 'visible';
|
||||
$this->harea_visibility = 'hidden';
|
||||
}
|
||||
|
||||
$this->inner_area_x = $this->area_width - $this->area_border;
|
||||
$this->inner_area_y = $this->area_height - $this->area_border;
|
||||
|
||||
$this->overlay_clip_top = $this->area_border;
|
||||
$this->overlay_clip_right = $this->area_width - $this->area_border;
|
||||
$this->overlay_clip_bottom = $this->area_height - $this->area_border;
|
||||
$this->overlay_clip_left = $this->area_border;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Set the template variables
|
||||
function setVars() {
|
||||
|
||||
$this->imgedit_smarty['zoombox_width'] = $this->zoombox_width;
|
||||
$this->imgedit_smarty['zoombox_padding'] = $this->zoombox_width + 20;
|
||||
$this->imgedit_smarty['area_width'] = $this->area_width;
|
||||
$this->imgedit_smarty['area_height'] = $this->area_height;
|
||||
$this->imgedit_smarty['varea_width'] = $this->varea_width;
|
||||
$this->imgedit_smarty['varea_height'] = $this->varea_height;
|
||||
$this->imgedit_smarty['varea_img_name'] = $this->varea_img_name;
|
||||
$this->imgedit_smarty['varea_visibility'] = $this->varea_visibility;
|
||||
$this->imgedit_smarty['harea_width'] = $this->harea_width;
|
||||
$this->imgedit_smarty['harea_height'] = $this->harea_height;
|
||||
$this->imgedit_smarty['harea_img_name'] = $this->harea_img_name;
|
||||
$this->imgedit_smarty['harea_visibility'] = $this->harea_visibility;
|
||||
$this->imgedit_smarty['area_border'] = $this->area_border;
|
||||
$this->imgedit_smarty['refresh_line'] = time();
|
||||
|
||||
$this->imgedit_smarty['real_img_width'] = $this->real_img_width;
|
||||
$this->imgedit_smarty['real_img_height'] = $this->real_img_height;
|
||||
$this->imgedit_smarty['real_img_name'] = $this->real_img_name;
|
||||
$this->imgedit_smarty['http_img_name'] = $this->http_img_name;
|
||||
|
||||
$this->imgedit_smarty['img_width'] = $this->img_width;
|
||||
$this->imgedit_smarty['img_height'] = $this->img_height;
|
||||
$this->imgedit_smarty['zoom_img_width'] = $this->img_width;
|
||||
$this->imgedit_smarty['zoom_img_height'] = $this->img_height;
|
||||
$this->imgedit_smarty['img_name'] = $this->img_name;
|
||||
|
||||
$this->imgedit_smarty['overlay_clip_top'] = $this->overlay_clip_top;
|
||||
$this->imgedit_smarty['overlay_clip_bottom'] = $this->overlay_clip_bottom;
|
||||
$this->imgedit_smarty['overlay_clip_left'] = $this->overlay_clip_left;
|
||||
$this->imgedit_smarty['overlay_clip_right'] = $this->overlay_clip_right;
|
||||
|
||||
$this->imgedit_smarty['slice_from_x'] = $this->slice_from_x;
|
||||
$this->imgedit_smarty['slice_from_y'] = $this->slice_from_y;
|
||||
$this->imgedit_smarty['slice_to_x'] = $this->slice_to_x;
|
||||
$this->imgedit_smarty['slice_to_y'] = $this->slice_to_y;
|
||||
|
||||
$this->imgedit_smarty['zoombox_x'] = $_REQUEST['zoombox_x'];
|
||||
$this->imgedit_smarty['zoombox_y'] = $_REQUEST['zoombox_y'];
|
||||
$this->imgedit_smarty['zoombox_factor'] = $_REQUEST['zoombox_factor'];
|
||||
|
||||
$this->imgedit_smarty['php_self'] = $_SERVER['PHP_SELF'];
|
||||
$this->imgedit_smarty['area_orientation'] = $_REQUEST['area_orientation'];
|
||||
$this->imgedit_smarty['move_increase'] = $_REQUEST['move_increase'];
|
||||
$this->imgedit_smarty['autoguess_clicked'] = $_REQUEST['autoguess_clicked'];
|
||||
|
||||
$this->imgedit_smarty['my_url'] = htmlspecialchars($_SERVER['REQUEST_URI']);
|
||||
|
||||
if ($_REQUEST['autoguess_clicked'] == 'true') {
|
||||
$this->imgedit_smarty['scale_visibility'] = 'visible';
|
||||
} else {
|
||||
$this->imgedit_smarty['scale_visibility'] = 'hidden';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**************************************************
|
||||
* imgedit.inc.php
|
||||
* 2003-10-17
|
||||
* www.sonnd.com / www.supergarv.de
|
||||
*
|
||||
* COPYRIGHT (C) BY sonnd / Garvin Hicking
|
||||
* Published as LGPL. Copyright notice has to stay in effect.
|
||||
**************************************************/
|
||||
|
||||
class imgedit {
|
||||
// Needed variables.
|
||||
var $orientation_available;
|
||||
var $real_img_name, $real_img_info, $real_img_width, $real_img_height, $http_img_name;
|
||||
var $img_width, $img_height, $img_name;
|
||||
var $zoombox_width;
|
||||
var $area_border, $area_width, $area_height, $inner_area_x, $inner_area_y;
|
||||
var $harea_width, $harea_height, $harea_img_name, $harea_visibility;
|
||||
var $varea_width, $varea_height, $varea_img_name, $varea_visibility;
|
||||
var $ratio;
|
||||
var $overlay_clip_top, $overlay_clip_bottom, $overlay_clip_left, $overlay_clip_right;
|
||||
var $slice_from_x, $slice_from_y, $slice_to_x, $slice_to_y;
|
||||
var $output_template = '';
|
||||
var $imgedit_smarty = array();
|
||||
|
||||
// Helper function to cycle through an array. Strips of "_x" and "_y" coordinates if an 'input type="image"'
|
||||
// variable has been submitted.
|
||||
function makeImgComp(&$array) {
|
||||
foreach($array AS $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$this->makeImgComp($array[$key]);
|
||||
} elseif (preg_match('@^.*_(x|y)$@', $key)) {
|
||||
$array[preg_replace('@^(.*)_(x|y)$@', '\1', $key)] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Constructor.
|
||||
function imgedit($img_name, $http_img_name) {
|
||||
global $serendipity;
|
||||
$this->makeImgComp($_REQUEST);
|
||||
|
||||
// Store the given variables
|
||||
$this->real_img_name = $this->img_name = $img_name;
|
||||
$this->real_img_info = getimagesize($this->real_img_name);
|
||||
$this->real_img_width = $this->real_img_info[0];
|
||||
$this->real_img_height = $this->real_img_info[1];
|
||||
|
||||
$this->http_img_name = $http_img_name;
|
||||
|
||||
// Set even more variables
|
||||
$this->setDefaults();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// The main logic
|
||||
function main() {
|
||||
|
||||
// 1. Parse the $_REQUEST vars.
|
||||
$this->parseRequest();
|
||||
|
||||
// 2. Get the current size of the cropping area
|
||||
$this->getCurrentArea();
|
||||
|
||||
// 3. Parse any actions
|
||||
$this->parseRequestActions();
|
||||
|
||||
// 4. Valide the results of any actions
|
||||
$this->validateCoordinates();
|
||||
|
||||
// 5. Populate the template
|
||||
$this->setVars();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sets default vars.
|
||||
function setDefaults() {
|
||||
$this->orientation_available = true;
|
||||
|
||||
$this->img_width = $this->real_img_width;
|
||||
$this->img_height = $this->real_img_height;
|
||||
$this->img_name = $this->real_img_name;
|
||||
|
||||
$this->zoombox_width = 100;
|
||||
$this->area_border = 6;
|
||||
|
||||
// Set values if they haven't been submitted yet.
|
||||
if (!isset($_REQUEST['area_orientation']) || ($_REQUEST['area_orientation'] != 'h' && $_REQUEST['area_orientation'] != 'v')) {
|
||||
$_REQUEST['area_orientation'] = 'h';
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['autoguess_clicked'])) {
|
||||
$_REQUEST['autoguess_clicked'] = 'false';
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['zoombox_x'])) {
|
||||
$_REQUEST['zoombox_x'] = -$this->area_border;
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['zoombox_y'])) {
|
||||
$_REQUEST['zoombox_y'] = -$this->area_border;
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['move_increase'])) {
|
||||
$_REQUEST['move_increase'] = 8;
|
||||
} else {
|
||||
$_REQUEST['move_increase'] = intval($_REQUEST['move_increase']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Parse the $_REQUEST vars
|
||||
function parseRequest() {
|
||||
if (isset($_REQUEST['toggle_area_orientation'])) {
|
||||
if ($_REQUEST['area_orientation'] == 'h') {
|
||||
$_REQUEST['area_orientation'] = 'v';
|
||||
} else {
|
||||
$_REQUEST['area_orientation'] = 'h';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['zoombox_factor'])) {
|
||||
$_REQUEST['zoombox_factor'] = floatval($_REQUEST['zoombox_factor']);
|
||||
} else {
|
||||
$_REQUEST['zoombox_factor'] = 1;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['action']['enlarge'])) {
|
||||
$_REQUEST['zoombox_factor'] += 0.1;
|
||||
} elseif (isset($_REQUEST['action']['reduce'])) {
|
||||
$_REQUEST['zoombox_factor'] -= 0.1;
|
||||
}
|
||||
|
||||
if ($_REQUEST['zoombox_factor'] > 3) {
|
||||
$_REQUEST['zoombox_factor'] = 3;
|
||||
} elseif ($_REQUEST['zoombox_factor'] < 0.1) {
|
||||
$_REQUEST['zoombox_factor'] = 0.1;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['action']['moveup'])) {
|
||||
$_REQUEST['zoombox_y'] -= $_REQUEST['move_increase'];
|
||||
} elseif (isset($_REQUEST['action']['movedown'])) {
|
||||
$_REQUEST['zoombox_y'] += $_REQUEST['move_increase'];
|
||||
} elseif (isset($_REQUEST['action']['moveleft'])) {
|
||||
$_REQUEST['zoombox_x'] -= $_REQUEST['move_increase'];
|
||||
} elseif (isset($_REQUEST['action']['moveright'])) {
|
||||
$_REQUEST['zoombox_x'] += $_REQUEST['move_increase'];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fit an image inside the cropping area.
|
||||
function imgFit($orientation) {
|
||||
if ($orientation == 'height') {
|
||||
$this->imgFitHeight();
|
||||
} else {
|
||||
$this->imgFitWidth();
|
||||
}
|
||||
|
||||
$_REQUEST['zoombox_factor'] = $this->ratio;
|
||||
$_REQUEST['autoguess_clicked'] = 'true';
|
||||
$_REQUEST['zoombox_x'] = -$this->area_border;
|
||||
$_REQUEST['zoombox_y'] = -$this->area_border;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fit an image, using height as fixed value
|
||||
function imgFitHeight() {
|
||||
$this->img_height = $this->inner_area_y - $this->area_border;
|
||||
$this->ratio = round($this->img_height / $this->real_img_height, 3);
|
||||
$this->img_width = intval(round($this->real_img_width * $this->ratio));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fit an image, using width as fixed value
|
||||
function imgFitWidth() {
|
||||
$this->img_width = $this->inner_area_x - $this->area_border;
|
||||
$this->ratio = round($this->img_width / $this->real_img_width, 3);
|
||||
$this->img_height = intval(round($this->real_img_height * $this->ratio));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Parse actions that were submitted
|
||||
function parseRequestActions() {
|
||||
global $serendipity;
|
||||
|
||||
if (isset($_REQUEST['autoscale'])) {
|
||||
|
||||
if ($this->real_img_width > $this->real_img_height) {
|
||||
// The image is a horizontal one. Resize height to fit.
|
||||
$this->imgFit('height');
|
||||
} else {
|
||||
// The image is a vertical one. Resize width to fit.
|
||||
$this->imgFit('width');
|
||||
}
|
||||
|
||||
|
||||
} elseif (isset($_REQUEST['scale'])) {
|
||||
|
||||
|
||||
if ($this->real_img_width > $this->real_img_height) {
|
||||
// The image is a horizontal one. Resize width to fit.
|
||||
$this->imgFit('width');
|
||||
} else {
|
||||
// The image is a vertical one. Resize height to fit.
|
||||
$this->imgFit('height');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$this->img_width = intval(round($this->real_img_width * $_REQUEST['zoombox_factor']));
|
||||
$this->img_height = intval(round($this->real_img_height * $_REQUEST['zoombox_factor']));
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Check which template to use
|
||||
if (isset($_REQUEST['crop'])) {
|
||||
$this->output_template = 'admin/media_imgedit_done.tpl';
|
||||
} else {
|
||||
$this->output_template = 'admin/media_imgedit.tpl';
|
||||
if ($this->orientation_available) {
|
||||
$this->imgedit_smarty['orientation_available'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// The final action. Cropping will take place.
|
||||
if (isset($_REQUEST['crop'])) {
|
||||
$new_img_name = $this->img_name . '.tmp';
|
||||
|
||||
if ($this->img_width <= $this->area_width && $this->img_height <= $this->area_height) {
|
||||
$this->imgedit_smarty['image_no_cut'] = true;
|
||||
|
||||
$new_img_width = $this->img_width;
|
||||
$new_img_height = $this->img_height;
|
||||
} else {
|
||||
$this->imgedit_smarty['image_cut'] = true;
|
||||
|
||||
$new_img_width = $this->area_width - $this->area_border - $this->area_border;
|
||||
$new_img_height = $this->area_height - $this->area_border - $this->area_border;
|
||||
}
|
||||
|
||||
$this->slice_from_x = ($this->area_border + $_REQUEST['zoombox_x']) / $_REQUEST['zoombox_factor'];
|
||||
$this->slice_from_y = ($this->area_border + $_REQUEST['zoombox_y']) / $_REQUEST['zoombox_factor'];
|
||||
|
||||
$slice_width = $new_img_width / $_REQUEST['zoombox_factor'];
|
||||
$slice_height = $new_img_height / $_REQUEST['zoombox_factor'];
|
||||
|
||||
$this->slice_to_x = $this->slice_from_x + $this->slice_width;
|
||||
$this->slice_to_y = $this->slice_from_y + $this->slice_height;
|
||||
|
||||
// TODO:
|
||||
// - Operate also on PNG, TIFF etc.
|
||||
// - Support image magick
|
||||
// - Save file as new image!
|
||||
// - Optionally ask whether to only make a thumbnail from the extracted portion
|
||||
|
||||
// PHP: int imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
|
||||
// Open the user's image.
|
||||
$img_res = imagecreatefromjpeg($this->img_name);
|
||||
|
||||
// Init a blank picture to save the cropped image in.
|
||||
$new_img_res = imagecreatetruecolor($new_img_width, $new_img_height);
|
||||
|
||||
// Crop the image based on user input, save the resulting image. If either action fails, report an error.
|
||||
if (!imagecopyresampled($new_img_res, $img_res, 0, 0, $this->slice_from_x, $this->slice_from_y, $new_img_width, $new_img_height, $slice_width, $slice_height) ||
|
||||
!imageJpeg($new_img_res, $new_img_name, 90)) {
|
||||
|
||||
$this->imgedit_smarty['image_error'] = true;
|
||||
}
|
||||
|
||||
$backup = $this->increment($this->img_name);
|
||||
rename($this->img_name, $backup . '.backup');
|
||||
rename($new_img_name, $this->img_name);
|
||||
$http_new_file = preg_replace('@^' . preg_quote($serendipity['serendipityPath'] . $serendipity['uploadPath']) . '@', '', $this->img_name);
|
||||
serendipity_makeThumbnail(basename($http_new_file), dirname($http_new_file) . '/');
|
||||
|
||||
$this->img_name = $new_img_name;
|
||||
$this->img_width = $new_img_width;
|
||||
$this->img_height = $new_img_height;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function increment($fullfile) {
|
||||
$d = dirname($fullfile) . '/';
|
||||
$f = basename($fullfile);
|
||||
|
||||
$f = time() . '.' . $f;
|
||||
|
||||
return $d . $f;
|
||||
}
|
||||
|
||||
// Checks if any coordinates are out of allowed range
|
||||
function validateCoordinates() {
|
||||
if ($this->img_width > $this->area_width) {
|
||||
$c_img_width = $this->img_width;
|
||||
$ca_img_width = $this->area_width;
|
||||
$x_area_border = $this->area_border;
|
||||
} else {
|
||||
$c_img_width = $this->area_width;
|
||||
$ca_img_width = $this->img_width;
|
||||
$x_area_border = -$this->area_border;
|
||||
}
|
||||
|
||||
if ($this->img_height > $this->area_height) {
|
||||
$c_img_height = $this->img_height;
|
||||
$ca_img_height = $this->area_height;
|
||||
$y_area_border = $this->area_border;
|
||||
} else {
|
||||
$c_img_height = $this->area_height;
|
||||
$ca_img_height = $this->img_height;
|
||||
$y_area_border = -$this->area_border;
|
||||
}
|
||||
|
||||
if ($_REQUEST['zoombox_x'] < (0 - $this->area_border)) {
|
||||
$_REQUEST['zoombox_x'] = 0 - $this->area_border;
|
||||
} elseif ($_REQUEST['zoombox_x'] > ($this->img_width - $ca_img_width + $x_area_border)) {
|
||||
$_REQUEST['zoombox_x'] = $this->img_width - $ca_img_width + $x_area_border;
|
||||
}
|
||||
|
||||
if ($_REQUEST['zoombox_y'] < (0 - $this->area_border)) {
|
||||
$_REQUEST['zoombox_y'] = 0 - $this->area_border;
|
||||
} elseif ($_REQUEST['zoombox_y'] > ($this->img_height - $ca_img_height + $y_area_border)) {
|
||||
$_REQUEST['zoombox_y'] = $this->img_height - $ca_img_height + $y_area_border;
|
||||
}
|
||||
|
||||
$this->overlay_clip_top += $_REQUEST['zoombox_y'];
|
||||
$this->overlay_clip_bottom += $_REQUEST['zoombox_y'];
|
||||
$this->overlay_clip_left += $_REQUEST['zoombox_x'];
|
||||
$this->overlay_clip_right += $_REQUEST['zoombox_x'];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sets the sizes of the cropping area
|
||||
function setArea($img_name, $orientation = 'h') {
|
||||
global $serendipity;
|
||||
|
||||
$fimg = serendipity_getTemplateFile('admin/img/' . $img_name, 'serendipityPath');
|
||||
$hfimg = serendipity_getTemplateFile('admin/img/' . $img_name, 'serendipityHTTPPath');
|
||||
$img_info = getImageSize($fimg);
|
||||
|
||||
if ($orientation == 'h') {
|
||||
$this->harea_width = $img_info[0];
|
||||
$this->harea_height = $img_info[1];
|
||||
$this->harea_img_name = $hfimg;
|
||||
} else {
|
||||
$this->varea_width = $img_info[0];
|
||||
$this->varea_height = $img_info[1];
|
||||
$this->varea_img_name = $hfimg;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the size of the selected cropping area
|
||||
function getCurrentArea() {
|
||||
if ($_REQUEST['area_orientation'] == 'h') {
|
||||
$this->area_width = $this->harea_width;
|
||||
$this->area_height = $this->harea_height;
|
||||
$this->varea_visibility = 'hidden';
|
||||
$this->harea_visibility = 'visible';
|
||||
} else {
|
||||
$this->area_width = $this->varea_width;
|
||||
$this->area_height = $this->varea_height;
|
||||
$this->varea_visibility = 'visible';
|
||||
$this->harea_visibility = 'hidden';
|
||||
}
|
||||
|
||||
$this->inner_area_x = $this->area_width - $this->area_border;
|
||||
$this->inner_area_y = $this->area_height - $this->area_border;
|
||||
|
||||
$this->overlay_clip_top = $this->area_border;
|
||||
$this->overlay_clip_right = $this->area_width - $this->area_border;
|
||||
$this->overlay_clip_bottom = $this->area_height - $this->area_border;
|
||||
$this->overlay_clip_left = $this->area_border;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Set the template variables
|
||||
function setVars() {
|
||||
|
||||
$this->imgedit_smarty['zoombox_width'] = $this->zoombox_width;
|
||||
$this->imgedit_smarty['zoombox_padding'] = $this->zoombox_width + 20;
|
||||
$this->imgedit_smarty['area_width'] = $this->area_width;
|
||||
$this->imgedit_smarty['area_height'] = $this->area_height;
|
||||
$this->imgedit_smarty['varea_width'] = $this->varea_width;
|
||||
$this->imgedit_smarty['varea_height'] = $this->varea_height;
|
||||
$this->imgedit_smarty['varea_img_name'] = $this->varea_img_name;
|
||||
$this->imgedit_smarty['varea_visibility'] = $this->varea_visibility;
|
||||
$this->imgedit_smarty['harea_width'] = $this->harea_width;
|
||||
$this->imgedit_smarty['harea_height'] = $this->harea_height;
|
||||
$this->imgedit_smarty['harea_img_name'] = $this->harea_img_name;
|
||||
$this->imgedit_smarty['harea_visibility'] = $this->harea_visibility;
|
||||
$this->imgedit_smarty['area_border'] = $this->area_border;
|
||||
$this->imgedit_smarty['refresh_line'] = time();
|
||||
|
||||
$this->imgedit_smarty['real_img_width'] = $this->real_img_width;
|
||||
$this->imgedit_smarty['real_img_height'] = $this->real_img_height;
|
||||
$this->imgedit_smarty['real_img_name'] = $this->real_img_name;
|
||||
$this->imgedit_smarty['http_img_name'] = $this->http_img_name;
|
||||
|
||||
$this->imgedit_smarty['img_width'] = $this->img_width;
|
||||
$this->imgedit_smarty['img_height'] = $this->img_height;
|
||||
$this->imgedit_smarty['zoom_img_width'] = $this->img_width;
|
||||
$this->imgedit_smarty['zoom_img_height'] = $this->img_height;
|
||||
$this->imgedit_smarty['img_name'] = $this->img_name;
|
||||
|
||||
$this->imgedit_smarty['overlay_clip_top'] = $this->overlay_clip_top;
|
||||
$this->imgedit_smarty['overlay_clip_bottom'] = $this->overlay_clip_bottom;
|
||||
$this->imgedit_smarty['overlay_clip_left'] = $this->overlay_clip_left;
|
||||
$this->imgedit_smarty['overlay_clip_right'] = $this->overlay_clip_right;
|
||||
|
||||
$this->imgedit_smarty['slice_from_x'] = $this->slice_from_x;
|
||||
$this->imgedit_smarty['slice_from_y'] = $this->slice_from_y;
|
||||
$this->imgedit_smarty['slice_to_x'] = $this->slice_to_x;
|
||||
$this->imgedit_smarty['slice_to_y'] = $this->slice_to_y;
|
||||
|
||||
$this->imgedit_smarty['zoombox_x'] = $_REQUEST['zoombox_x'];
|
||||
$this->imgedit_smarty['zoombox_y'] = $_REQUEST['zoombox_y'];
|
||||
$this->imgedit_smarty['zoombox_factor'] = $_REQUEST['zoombox_factor'];
|
||||
|
||||
$this->imgedit_smarty['php_self'] = $_SERVER['PHP_SELF'];
|
||||
$this->imgedit_smarty['area_orientation'] = $_REQUEST['area_orientation'];
|
||||
$this->imgedit_smarty['move_increase'] = $_REQUEST['move_increase'];
|
||||
$this->imgedit_smarty['autoguess_clicked'] = $_REQUEST['autoguess_clicked'];
|
||||
|
||||
$this->imgedit_smarty['my_url'] = htmlspecialchars($_SERVER['REQUEST_URI']);
|
||||
|
||||
if ($_REQUEST['autoguess_clicked'] == 'true') {
|
||||
$this->imgedit_smarty['scale_visibility'] = 'visible';
|
||||
} else {
|
||||
$this->imgedit_smarty['scale_visibility'] = 'hidden';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -53,13 +53,13 @@ function &serendipity_fetchTrackbacks($id, $limit = null, $showAll = false) {
|
||||
function &serendipity_printTrackbacks(&$trackbacks) {
|
||||
global $serendipity;
|
||||
|
||||
$serendipity['smarty']->assign_by_ref('trackbacks', $trackbacks);
|
||||
$serendipity['smarty']->assignByRef('trackbacks', $trackbacks);
|
||||
|
||||
return serendipity_smarty_fetch('TRACKBACKS', 'trackbacks.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty: Fetch a smarty block and pass it on to Serendipity Templates
|
||||
* Smarty: Fetch a smarty block and pass it on to Serendipity Templates - use with Smarty > 3.0 only
|
||||
*
|
||||
* @access public
|
||||
* @param string The name of the block to parse data into ("COMMENTS" - virtual variable like {$COMMENTS})
|
||||
@ -70,13 +70,9 @@ function &serendipity_printTrackbacks(&$trackbacks) {
|
||||
function &serendipity_smarty_fetch($block, $file, $echo = false) {
|
||||
global $serendipity;
|
||||
|
||||
if (strpos($serendipity['smarty']->_version, '2', 1)) {
|
||||
$output =& $serendipity['smarty']->fetch('file:'. serendipity_getTemplateFile($file, 'serendipityPath'), null, null, ($echo === true && $serendipity['smarty_raw_mode']));
|
||||
} else {
|
||||
$output =& $serendipity['smarty']->fetch('file:'. serendipity_getTemplateFile($file, 'serendipityPath'), null, null, null, ($echo === true && $serendipity['smarty_raw_mode']));
|
||||
}
|
||||
$output =& $serendipity['smarty']->fetch('file:'. serendipity_getTemplateFile($file, 'serendipityPath'), null, null, null, ($echo === true && $serendipity['smarty_raw_mode']));
|
||||
|
||||
$serendipity['smarty']->assign_by_ref($block, $output);
|
||||
$serendipity['smarty']->assignByRef($block, $output);
|
||||
|
||||
return $output;
|
||||
}
|
||||
@ -887,72 +883,61 @@ function serendipity_smarty_init($vars = array()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$serendipity['smarty'] = new Smarty;
|
||||
if ($serendipity['production'] === 'debug') {
|
||||
$serendipity['smarty']->force_compile = true;
|
||||
$serendipity['smarty']->debugging = true;
|
||||
// Load serendipity smarty class loading class
|
||||
if (!class_exists('Serendipity_Smarty')) {
|
||||
include 'serendipity_smarty_class.inc.php';
|
||||
}
|
||||
|
||||
$serendipity['smarty']->template_dir = array($template_dir);
|
||||
$p = explode(',', $serendipity['template_engine']);
|
||||
foreach($p AS $te) {
|
||||
$serendipity['smarty']->template_dir[] = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $te;
|
||||
}
|
||||
|
||||
$serendipity['smarty']->template_dir[] = $serendipity['serendipityPath'] . $serendipity['templatePath'] . 'default';
|
||||
$serendipity['smarty']->compile_dir = $serendipity['serendipityPath'] . PATH_SMARTY_COMPILE;
|
||||
|
||||
if (!is_dir($serendipity['smarty']->compile_dir) || !is_writable($serendipity['smarty']->compile_dir)) {
|
||||
printf(DIRECTORY_WRITE_ERROR, $serendipity['smarty']->compile_dir);
|
||||
|
||||
if (!class_exists('Serendipity_Smarty')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// set smarty instance
|
||||
$serendipity['smarty'] = new Serendipity_Smarty;
|
||||
// debug moved to class
|
||||
|
||||
// Hooray for Smarty:
|
||||
$_SESSION['no_smarty'] = $prev_smarty;
|
||||
|
||||
$serendipity['smarty']->config_dir = $template_dir;
|
||||
$serendipity['smarty']->secure_dir = array($serendipity['serendipityPath'] . $serendipity['templatePath']);
|
||||
$serendipity['smarty']->security_settings['MODIFIER_FUNCS'] = array('sprintf', 'sizeof', 'count', 'rand', 'print_r', 'str_repeat');
|
||||
$serendipity['smarty']->security_settings['ALLOW_CONSTANTS'] = true;
|
||||
$serendipity['smarty']->security = true;
|
||||
$serendipity['smarty']->use_sub_dirs = false;
|
||||
$serendipity['smarty']->compile_check = true;
|
||||
$serendipity['smarty']->compile_id = &$serendipity['template'];
|
||||
// enable security policy by instance of the Smarty_Security class
|
||||
$serendipity['smarty']->enableSecurity('Serendipity_Smarty_Security_Policy');
|
||||
|
||||
if (!strpos($serendipity['smarty']->_version, '2', 1)) {
|
||||
$serendipity['smarty']->setDeprecationNotices(false); // set $smarty->deprecation_notices
|
||||
#$serendipity['smarty']->setCaching(true); // set $smarty->caching to not being regenerated
|
||||
#$serendipity['smarty']->force_compile = false; // override compile_check (default:false)
|
||||
#$serendipity['smarty']->error_reporting = E_ALL & ~E_NOTICE;
|
||||
#$serendipity['smarty']->auto_literal = false;
|
||||
}
|
||||
// debugging...
|
||||
#echo '<pre>';print_r($serendipity['smarty']);echo '</pre>';#exit;
|
||||
#$serendipity['smarty']->testInstall();exit;
|
||||
|
||||
/**
|
||||
* prüfe auf eventuelle API Änderungen in 3.2 [smarty_modifier_foobar, --> [smarty_modifier_foobar, smarty_function_foobar, smarty_block_foobar] (siehe class) ]
|
||||
* smarty_modifier_foobar(Smarty $smarty, $string, …) vs. smarty_modifier_foobar($string, …)
|
||||
**/
|
||||
$serendipity['smarty']->registerPlugin('modifier', 'makeFilename', 'serendipity_makeFilename');
|
||||
$serendipity['smarty']->registerPlugin('modifier', 'xhtml_target', 'serendipity_xhtml_target');
|
||||
$serendipity['smarty']->registerPlugin('modifier', 'emptyPrefix', 'serendipity_emptyPrefix');
|
||||
$serendipity['smarty']->registerPlugin('modifier', 'formatTime', 'serendipity_smarty_formatTime');
|
||||
$serendipity['smarty']->registerPlugin('modifier', 'serendipity_utf8_encode', 'serendipity_utf8_encode');
|
||||
$serendipity['smarty']->registerPlugin('modifier', 'ifRemember', 'serendipity_ifRemember');
|
||||
$serendipity['smarty']->registerPlugin('modifier', 'checkPermission', 'serendipity_checkPermission');
|
||||
$serendipity['smarty']->registerPlugin('modifier', 'serendipity_refhookPlugin', 'serendipity_smarty_refhookPlugin');
|
||||
|
||||
$serendipity['smarty']->registerPlugin('function', 'serendipity_printSidebar', 'serendipity_smarty_printSidebar');
|
||||
$serendipity['smarty']->registerPlugin('function', 'serendipity_hookPlugin', 'serendipity_smarty_hookPlugin');
|
||||
$serendipity['smarty']->registerPlugin('function', 'serendipity_showPlugin', 'serendipity_smarty_showPlugin');
|
||||
$serendipity['smarty']->registerPlugin('function', 'serendipity_getFile', 'serendipity_smarty_getFile');
|
||||
$serendipity['smarty']->registerPlugin('function', 'serendipity_printComments', 'serendipity_smarty_printComments');
|
||||
$serendipity['smarty']->registerPlugin('function', 'serendipity_printTrackbacks', 'serendipity_smarty_printTrackbacks');
|
||||
$serendipity['smarty']->registerPlugin('function', 'serendipity_rss_getguid', 'serendipity_smarty_rss_getguid');
|
||||
$serendipity['smarty']->registerPlugin('function', 'serendipity_fetchPrintEntries', 'serendipity_smarty_fetchPrintEntries');
|
||||
$serendipity['smarty']->registerPlugin('function', 'serendipity_getTotalCount', 'serendipity_smarty_getTotalCount');
|
||||
$serendipity['smarty']->registerPlugin('function', 'pickKey', 'serendipity_smarty_pickKey');
|
||||
$serendipity['smarty']->registerPlugin('function', 'serendipity_showCommentForm', 'serendipity_smarty_showCommentForm');
|
||||
$serendipity['smarty']->registerPlugin('function', 'serendipity_getImageSize', 'serendipity_smarty_getImageSize');
|
||||
|
||||
$serendipity['smarty']->registerFilter('pre', 'serendipity_replaceSmartyVars');
|
||||
|
||||
$serendipity['smarty']->register_modifier('makeFilename', 'serendipity_makeFilename');
|
||||
$serendipity['smarty']->register_modifier('xhtml_target', 'serendipity_xhtml_target');
|
||||
$serendipity['smarty']->register_modifier('emptyPrefix', 'serendipity_emptyPrefix');
|
||||
$serendipity['smarty']->register_modifier('formatTime', 'serendipity_smarty_formatTime');
|
||||
$serendipity['smarty']->register_modifier('serendipity_utf8_encode', 'serendipity_utf8_encode');
|
||||
$serendipity['smarty']->register_modifier('ifRemember', 'serendipity_ifRemember');
|
||||
$serendipity['smarty']->register_modifier('checkPermission', 'serendipity_checkPermission');
|
||||
$serendipity['smarty']->register_modifier('serendipity_refhookPlugin', 'serendipity_smarty_refhookPlugin');
|
||||
|
||||
$serendipity['smarty']->register_function('serendipity_printSidebar', 'serendipity_smarty_printSidebar');
|
||||
$serendipity['smarty']->register_function('serendipity_hookPlugin', 'serendipity_smarty_hookPlugin');
|
||||
$serendipity['smarty']->register_function('serendipity_showPlugin', 'serendipity_smarty_showPlugin');
|
||||
$serendipity['smarty']->register_function('serendipity_getFile', 'serendipity_smarty_getFile');
|
||||
$serendipity['smarty']->register_function('serendipity_printComments', 'serendipity_smarty_printComments');
|
||||
$serendipity['smarty']->register_function('serendipity_printTrackbacks', 'serendipity_smarty_printTrackbacks');
|
||||
$serendipity['smarty']->register_function('serendipity_rss_getguid', 'serendipity_smarty_rss_getguid');
|
||||
$serendipity['smarty']->register_function('serendipity_fetchPrintEntries', 'serendipity_smarty_fetchPrintEntries');
|
||||
$serendipity['smarty']->register_function('serendipity_getTotalCount', 'serendipity_smarty_getTotalCount');
|
||||
$serendipity['smarty']->register_function('pickKey', 'serendipity_smarty_pickKey');
|
||||
$serendipity['smarty']->register_function('serendipity_showCommentForm', 'serendipity_smarty_showCommentForm');
|
||||
$serendipity['smarty']->register_function('serendipity_getImageSize', 'serendipity_smarty_getImageSize');
|
||||
$serendipity['smarty']->register_prefilter('serendipity_replaceSmartyVars');
|
||||
}
|
||||
|
||||
if (!isset($serendipity['smarty_raw_mode'])) {
|
||||
if (file_exists($serendipity['smarty']->config_dir . '/layout.php') && $serendipity['template'] != 'default') {
|
||||
if (file_exists($serendipity['smarty']->getConfigDir(0) . '/layout.php') && $serendipity['template'] != 'default') {
|
||||
$serendipity['smarty_raw_mode'] = true;
|
||||
} else {
|
||||
$serendipity['smarty_raw_mode'] = false;
|
||||
@ -1021,14 +1006,14 @@ function serendipity_smarty_init($vars = array()) {
|
||||
|
||||
// For advanced usage, we allow template authors to create a file 'config.inc.php' where they can
|
||||
// setup custom smarty variables, modifiers etc. to use in their templates.
|
||||
@include_once $serendipity['smarty']->config_dir . '/config.inc.php';
|
||||
@include_once $serendipity['smarty']->getConfigDir(0) . '/config.inc.php';
|
||||
|
||||
if (is_array($template_loaded_config)) {
|
||||
$template_vars =& $template_loaded_config;
|
||||
$serendipity['smarty']->assign_by_ref('template_option', $template_vars);
|
||||
$serendipity['smarty']->assignByRef('template_option', $template_vars);
|
||||
} elseif (is_array($template_config)) {
|
||||
$template_vars =& serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option']);
|
||||
$serendipity['smarty']->assign_by_ref('template_option', $template_vars);
|
||||
$serendipity['smarty']->assignByRef('template_option', $template_vars);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1047,14 +1032,14 @@ function serendipity_smarty_purge() {
|
||||
/* Attempt to init Smarty, brrr */
|
||||
serendipity_smarty_init();
|
||||
|
||||
$files = serendipity_traversePath($serendipity['smarty']->compile_dir, '', false, '/.+\.tpl\.php$/');
|
||||
$files = serendipity_traversePath($serendipity['smarty']->getCompileDir() . DIRECTORY_SEPARATOR, '', false, '/.+\.tpl\.php$/');
|
||||
|
||||
if ( !is_array($files) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( $files as $file ) {
|
||||
@unlink($serendipity['smarty']->compile_dir . DIRECTORY_SEPARATOR . $file['name']);
|
||||
@unlink($serendipity['smarty']->getCompileDir() . DIRECTORY_SEPARATOR . $file['name']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1076,7 +1061,7 @@ global $serendipity;
|
||||
chdir($serendipity_directory);
|
||||
$raw_data = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$serendipity['smarty']->assign_by_ref('content_message', $raw_data);
|
||||
$serendipity['smarty']->assignByRef('content_message', $raw_data);
|
||||
|
||||
serendipity_smarty_fetch('CONTENT', 'content.tpl');
|
||||
$serendipity['smarty']->assign('ENTRIES', '');
|
||||
|
@ -34,8 +34,8 @@ serendipity_smarty_init($serendipity['plugindata']['smartyvars']);
|
||||
|
||||
$leftSidebarElements = serendipity_plugin_api::count_plugins('left');
|
||||
$rightSidebarElements = serendipity_plugin_api::count_plugins('right');
|
||||
$serendipity['smarty']->assign_by_ref('leftSidebarElements', $leftSidebarElements);
|
||||
$serendipity['smarty']->assign_by_ref('rightSidebarElements', $rightSidebarElements);
|
||||
$serendipity['smarty']->assignByRef('leftSidebarElements', $leftSidebarElements);
|
||||
$serendipity['smarty']->assignByRef('rightSidebarElements', $rightSidebarElements);
|
||||
|
||||
if ($serendipity['smarty_raw_mode']) {
|
||||
/* For BC reasons, we have to ask for layout.php */
|
||||
|
@ -901,7 +901,7 @@ class serendipity_plugin_api
|
||||
|
||||
serendipity_plugin_api::hook_event('frontend_sidebar_plugins', $pluginData, $addData);
|
||||
|
||||
$serendipity['smarty']->assign_by_ref('plugindata', $pluginData);
|
||||
$serendipity['smarty']->assignByRef('plugindata', $pluginData);
|
||||
$serendipity['smarty']->assign('pluginside', ucfirst($side));
|
||||
|
||||
return serendipity_smarty_fetch('sidebar_'. $side, $tpl, true);
|
||||
@ -1576,10 +1576,7 @@ class serendipity_plugin
|
||||
if (!$tfile || $tfile == $filename) {
|
||||
$tfile = dirname($this->pluginFile) . '/' . $filename;
|
||||
}
|
||||
$inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY];
|
||||
$serendipity['smarty']->security_settings[INCLUDE_ANY] = true;
|
||||
$content = $serendipity['smarty']->fetch('file:'. $tfile);
|
||||
$serendipity['smarty']->security_settings[INCLUDE_ANY] = $inclusion;
|
||||
$content = $serendipity['smarty']->display('file:'. $tfile);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
@ -339,13 +339,13 @@ class serendipity_calendar_plugin extends serendipity_plugin {
|
||||
} // end for
|
||||
} // end for
|
||||
|
||||
$serendipity['smarty']->assign_by_ref('plugin_calendar_weeks', $smartyRows);
|
||||
$serendipity['smarty']->assignByRef('plugin_calendar_weeks', $smartyRows);
|
||||
|
||||
$dow = array();
|
||||
for ($i = 1; $i <= 7; $i++) {
|
||||
$dow[] = array('date' => mktime(0, 0, 0, 3, $bow + $i - 1, 2004));
|
||||
}
|
||||
$serendipity['smarty']->assign_by_ref('plugin_calendar_dow', $dow);
|
||||
$serendipity['smarty']->assignByRef('plugin_calendar_dow', $dow);
|
||||
|
||||
$plugin_calendar_data = array('month_date' => $ts,
|
||||
'uri_previous' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $previousYear, $previousMonth). $add_query),
|
||||
@ -353,7 +353,7 @@ class serendipity_calendar_plugin extends serendipity_plugin {
|
||||
'uri_next' => serendipity_archiveDateUrl(sprintf('%04d/%02d',$nextYear, $nextMonth) . $add_query),
|
||||
'minScroll' => $minmax[0]['min'],
|
||||
'maxScroll' => $minmax[0]['max']);
|
||||
$serendipity['smarty']->assign_by_ref('plugin_calendar_head', $plugin_calendar_data);
|
||||
$serendipity['smarty']->assignByRef('plugin_calendar_head', $plugin_calendar_data);
|
||||
echo serendipity_smarty_fetch('CALENDAR', 'plugin_calendar.tpl');
|
||||
|
||||
} // end function
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php // (experimental) serendipity_smarty_class.inc.php 2011-11-03 10:29 Ian
|
||||
|
||||
// This is the only way I found to get this into Serendipity_Smarty_Security_Policy class as secure_dir and trusted_dir.
|
||||
// Does this somehow has any negativ effects on building template paths in serendipity and/or smarty, partitially builded somehow dynamic?
|
||||
// Does this somehow have any negativ effects on building template paths in serendipity and/or smarty, partitially builded somehow dynamic?
|
||||
@define('S9Y_TEMPLATE_FALLBACK', $serendipity['serendipityPath'] . $serendipity['templatePath'] . 'default');
|
||||
@define('S9Y_TEMPLATE_DEFAULT', $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template']);
|
||||
@define('S9Y_TEMPLATE_SECUREDIR', $serendipity['serendipityPath'] . $serendipity['templatePath']);
|
||||
@ -36,22 +36,10 @@ class Serendipity_Smarty_Security_Policy extends Smarty_Security
|
||||
// actually no need, as template dirs are explicit defined as trusted_dirs (unproofed)
|
||||
public $trusted_dir = array(S9Y_TEMPLATE_DEFAULT, S9Y_TEMPLATE_FALLBACK); // do i need this then?
|
||||
|
||||
#public $modifiers = array(); // kann weg, wenn alles erlaubt
|
||||
// guter test - überschreibt Serendipity_Smarty::default_modifiers und Serendipity_Smarty_Security_Policy::php_modifiers - modifier 'escape' not allowed by security setting
|
||||
#public $modifiers = array(); // can be omitted when all allowed
|
||||
// to test this - overwrites Serendipity_Smarty::default_modifiers and Serendipity_Smarty_Security_Policy::php_modifiers - modifier 'escape' not allowed by security setting
|
||||
#public $allowed_modifiers = array('escape:"htmlall"');
|
||||
|
||||
/* I could have used this, but actually there is no real need as staying with properties only, right?
|
||||
Which construction is recommended, using CONSTANTS or __construct() with global $serendipity for trusted and secure_dir ??
|
||||
STILL LEARNING OOP:
|
||||
Does this has to be renamed to public function __construct(Serendipity_Smarty $serendipity['smarty'])
|
||||
as my class is Serendipity_Smarty and my object is $serendipity['smarty'] ???
|
||||
public function __construct(Smarty $smarty)
|
||||
{
|
||||
parent::__construct($smarty);
|
||||
// whatever you need to do to setup…
|
||||
}
|
||||
*/
|
||||
|
||||
static public function test()
|
||||
{
|
||||
var_dump(get_called_class());
|
||||
@ -138,7 +126,7 @@ class Serendipity_Smarty extends Smarty
|
||||
if (!is_dir($this->getCompileDir()) || !is_writable($this->getCompileDir())) {
|
||||
die(printf(DIRECTORY_WRITE_ERROR, $this->getCompileDir()));
|
||||
}
|
||||
#cache# $this->setCacheDir($serendipity['serendipityPath'] . 'cache'); // uncomment if not using cache
|
||||
#cache# $this->setCacheDir($serendipity['serendipityPath'] . 'cache'); // uncomment if not using cache
|
||||
|
||||
/**
|
||||
* here we go with our other Smarty class properties, which can all be called by their property name (recommended)
|
||||
@ -151,15 +139,16 @@ class Serendipity_Smarty extends Smarty
|
||||
***********************************/
|
||||
// WIE GEHT das genau?
|
||||
// 3.1.4 test 2011-10-20
|
||||
// cache_modified, caching, cache_lifetime und cache_id müssen gesetzt sein, sonst funktioniert caching nur nach Ablauf lifetime!
|
||||
// cache_id($id) gab Fehler und musste deshalb auf md5($_SERVER['REQUEST_URI']) gesetzt sein, damit jede einzelne url auch wirklich gecached wird.
|
||||
// Wie ist das mit fallbacks auf index (zb mit fehlermeldungen)???
|
||||
// cache_modified, caching, cache_lifetime and cache_id need to be set, or caching is only running after lifetime
|
||||
// cache_id($id) returned errors and needed to be set to md5($_SERVER['REQUEST_URI']) so that every single URL is cached
|
||||
// (note garvin: that might not be unique enough, what about POST variables influencing output?)
|
||||
// what about fallbacks to index (i.e. error messages)
|
||||
//
|
||||
// cache_modified_check, cache_lifetime, setCaching arbeiten zwar mit cache, reagieren aber nicht auf unterschiedliche urls, sondern erst auf ende lifetime - WARUM???
|
||||
// cache_modified_check, cache_lifetime, setCaching do work with cache, but do not react to different urls, but only to lifetime ending
|
||||
// If cache_modified_check is enabled Smarty tries to make use of the client browser cache. Maybe you got some garbage in your browser cache. Have you tried to clear the browser cache first?
|
||||
|
||||
#cache# $this->cache_modified_check = true; // must be true to enable 304 headers
|
||||
// Muss ich cache noch auf true setzen?
|
||||
#cache# $this->cache_modified_check = true; // must be true to enable 304 headers
|
||||
// does cache need to be set to true?
|
||||
|
||||
// some documentary from the smarty forum
|
||||
/*********************************************************
|
||||
@ -169,12 +158,12 @@ class Serendipity_Smarty extends Smarty
|
||||
* it cannot be altered except for clearing and regenerating said cache file
|
||||
**/
|
||||
|
||||
#cache# $this->caching = Smarty::CACHING_LIFETIME_CURRENT; // $this->setCaching(2); // 1 will change the end of lifetime immediately.
|
||||
#cache# $this->caching = Smarty::CACHING_LIFETIME_CURRENT; // $this->setCaching(2); // 1 will change the end of lifetime immediately.
|
||||
// $this->caching = Smarty::CACHING_LIFETIME_SAVED; // $this->setCaching(Smarty::CACHING_LIFETIME_SAVED);
|
||||
// #$this->setCaching(Smarty::CACHING_OFF) // stop caching >= 3.1.4
|
||||
// set the cache_lifetime for index.tpl to 5 minutes
|
||||
|
||||
#cache# $this->cache_lifetime = 300; // $this->setCacheLifetime(120);
|
||||
#cache# $this->cache_lifetime = 300; // $this->setCacheLifetime(120);
|
||||
// some documentary from the smarty forum
|
||||
/*********************************************************
|
||||
* Smarty caching is based purely on the fetch() or display() call. So:
|
||||
@ -184,9 +173,9 @@ class Serendipity_Smarty extends Smarty
|
||||
* $smarty->fetch('application.tpl',$cache_id);
|
||||
* It is entirely up to you what is taken into account for the cache_id (URL, etc.)
|
||||
**/
|
||||
//
|
||||
// does this mean $this->setCacheId($id); is useless here and has to be set where the actual templates are called? or does ist work as something default?
|
||||
//
|
||||
//
|
||||
// does this mean $this->setCacheId($id); is useless here and has to be set where the actual templates are called? or does ist work as something default?
|
||||
//
|
||||
// some documentary from the smarty forum
|
||||
/*********************************************************
|
||||
* Smarty will use the cache_id for distributing the cache files into sub_dirs
|
||||
@ -195,13 +184,13 @@ class Serendipity_Smarty extends Smarty
|
||||
* $this->cache_id($id); // $this->setCacheId($id);
|
||||
**/
|
||||
|
||||
#cache# $this->cache_id = md5($_SERVER['REQUEST_URI']); // this isn't a good idea either, better have it disabled or use a special id (where of?)
|
||||
#cache# $this->cache_id = md5($_SERVER['REQUEST_URI']); // this isn't a good idea either, better have it disabled or use a special id (where of?)
|
||||
|
||||
/************************************************
|
||||
* Set all other needed Smarty class properties
|
||||
***********************************************/
|
||||
// welche gehören noch in die security klasse?
|
||||
#???# $this->merge_compiled_includes = true; // $this->setMergeCompiledIncludes(true);
|
||||
// which do also belong to security class?
|
||||
#???# $this->merge_compiled_includes = true; // $this->setMergeCompiledIncludes(true);
|
||||
|
||||
$this->debugging = false; // $this->setDebugging(false); // default here to be overwritten by $serendipity['production'] == 'debug'!
|
||||
// Smarty will create subdirectories under the compiled templates and cache directories if $use_sub_dirs is set to TRUE, default is FALSE.
|
||||
@ -213,10 +202,6 @@ class Serendipity_Smarty extends Smarty
|
||||
#$this->compile_check = COMPILECHECK_CACHEMISS - template files will be checked if caching is enabled and there is no existing cache file or it has expired
|
||||
$this->compile_id = &$serendipity['template']; // $this->setCompileId(&$serendipity['template'])
|
||||
$this->config_overwrite = true; // $this->setConfigOverwrite(true);
|
||||
// guter test - modifier 'escape' wird zwar by security setting generell erlaubt, hiermit aber beschränkt - also keine exeption und doch keine < >
|
||||
#$this->default_modifiers = array('escape:"htmlall"');
|
||||
//default_modifiers gehört zu smarty klasse, wird mit allowed bzw php modifiers in security Klasse überschrieben....?!
|
||||
#$this->default_modifiers = array('sprintf', 'sizeof', 'count', 'rand', 'print_r', 'str_repeat');
|
||||
|
||||
// production == debug extends from s9y version information (alpha|beta|cvs) is always debug | USE ===
|
||||
if ($serendipity['production'] === 'debug') {
|
||||
@ -303,4 +288,3 @@ class Serendipity_Smarty extends Smarty
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -85,6 +85,20 @@ class serendipity_smarty_emulator {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign one or multiple template variable by reference - Smarty API Change > 3.0
|
||||
*
|
||||
* @param string Variable name
|
||||
* @param mixed Referenced variable
|
||||
* @access public
|
||||
* @return null
|
||||
*/
|
||||
function assignByRef($tpl_var, &$value) {
|
||||
$GLOBALS['tpl'][$tpl_var] =& $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign one or multiple template variable by reference
|
||||
*
|
||||
@ -252,6 +266,26 @@ class serendipity_smarty_emulator_xml extends serendipity_smarty_emulator {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign one or multiple template variable by reference - Smarty API Change > 3.0
|
||||
*
|
||||
* @param string Variable name
|
||||
* @param mixed Referenced variable
|
||||
* @access public
|
||||
* @return null
|
||||
*/
|
||||
function assignByRef($tpl_var, &$value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $key => $val) {
|
||||
$this->createXML($level, $key, $val);
|
||||
}
|
||||
} else {
|
||||
$this->createXML($level, $tpl_var, $value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign one or multiple template variable by reference
|
||||
*
|
||||
|
@ -627,7 +627,7 @@ if ($track_referer) {
|
||||
if (!defined('NO_EXIT')) {
|
||||
$raw_data = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$serendipity['smarty']->assign_by_ref('raw_data', $raw_data);
|
||||
$serendipity['smarty']->assignByRef('raw_data', $raw_data);
|
||||
if (empty($serendipity['smarty_file'])) {
|
||||
$serendipity['smarty_file'] = '404.tpl';
|
||||
$serendipity['viewtype'] = '404_5';
|
||||
|
10
rss.php
10
rss.php
@ -250,11 +250,11 @@ $namespace_display_dat = $entries['display_dat'];
|
||||
$channel_display_dat = $entries['channel_dat'];
|
||||
unset($entries['display_dat']);
|
||||
unset($entries['channel_dat']);
|
||||
$serendipity['smarty']->assign_by_ref('metadata', $metadata);
|
||||
$serendipity['smarty']->assign_by_ref('entries', $entries);
|
||||
$serendipity['smarty']->assign_by_ref('namespace_display_dat', $namespace_display_dat);
|
||||
$serendipity['smarty']->assign_by_ref('channel_display_dat', $channel_display_dat);
|
||||
$serendipity['smarty']->assign_by_ref('once_display_dat', $once_display_dat);
|
||||
$serendipity['smarty']->assignByRef('metadata', $metadata);
|
||||
$serendipity['smarty']->assignByRef('entries', $entries);
|
||||
$serendipity['smarty']->assignByRef('namespace_display_dat', $namespace_display_dat);
|
||||
$serendipity['smarty']->assignByRef('channel_display_dat', $channel_display_dat);
|
||||
$serendipity['smarty']->assignByRef('once_display_dat', $once_display_dat);
|
||||
|
||||
$serendipity['smarty']->assign(
|
||||
array(
|
||||
|
@ -275,7 +275,7 @@ if (!$use_installer && !$_SESSION['no_smarty'] && serendipity_smarty_init()) {
|
||||
$admin_vars['version_info'] = sprintf(ADMIN_FOOTER_POWERED_BY, '', '');
|
||||
}
|
||||
|
||||
$serendipity['smarty']->assign_by_ref('admin_vars', $admin_vars);
|
||||
$serendipity['smarty']->assignByRef('admin_vars', $admin_vars);
|
||||
$serendipity['smarty']->display(serendipity_getTemplateFile('admin/index.tpl', 'serendipityPath'));
|
||||
} else {
|
||||
?>
|
||||
|
@ -32,7 +32,7 @@ if (empty($serendipity['GET']['step']) && $serendipity['GET']['page'] < 1) {
|
||||
'GET_STRING' => serendipity_build_query($_GET),
|
||||
'frameset' => true
|
||||
);
|
||||
$serendipity['smarty']->assign_by_ref('media', $media);
|
||||
$serendipity['smarty']->assignByRef('media', $media);
|
||||
$serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_choose.tpl', 'serendipityPath'));
|
||||
return;
|
||||
}
|
||||
@ -304,7 +304,7 @@ switch ($serendipity['GET']['step']) {
|
||||
}
|
||||
|
||||
$media = array_merge($serendipity['GET'], $media);
|
||||
$serendipity['smarty']->assign_by_ref('media', $media);
|
||||
$serendipity['smarty']->assignByRef('media', $media);
|
||||
$serendipity['smarty']->display(serendipity_getTemplateFile($showFile, 'serendipityPath'));
|
||||
|
||||
/* vim: set sts=4 ts=4 expandtab : */
|
Loading…
x
Reference in New Issue
Block a user