Changeset 414 for plugins/metaImage
- Timestamp:
- 04/20/08 14:25:40 (15 years ago)
- Location:
- plugins/metaImage
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/metaImage/_admin.php
r349 r414 1 1 <?php 2 3 $_menu['Plugins']->addItem(__('Meta Image'),'plugin.php?p=metaImage','index.php?pf=metaImage/icon.png', 4 preg_match('/plugin.php\?p=metaImage/',$_SERVER['REQUEST_URI']), 5 $core->auth->isSuperAdmin()); 6 7 $core->addBehavior('adminPostFormSidebar',array('metaImageBehaviors','imageField')); 2 $_menu['Plugins']->addItem(__('Meta Image'),'plugin.php?p=metaImage', 3 'index.php?pf=metaImage/icon.png', 4 preg_match('/plugin.php\?p=metaImage(&.*)?$/',$_SERVER['REQUEST_URI']), 5 $core->auth->isSuperAdmin() 6 ); 7 8 $core->addBehavior('adminPostFormSidebar',array('metaImageBehaviors','adminPostFormSidebar')); 8 9 9 10 $core->addBehavior('adminAfterPostCreate',array('metaImageBehaviors','setImage')); … … 13 14 class metaImageBehaviors 14 15 { 15 16 public static function imageField(&$post) 17 { 18 $core = $GLOBALS['core']; 19 $bMustHaveImage = $core->blog->settings->must_have_image; 20 $min_width = $core->blog->settings->min_width; 21 $min_height = $core->blog->settings->min_height; 22 23 # Tentative de récupération de l'image associée 24 $objMeta = new dcMeta($GLOBALS['core']); 25 $imageName = ($post) ? $objMeta->getMetaStr($post->post_meta,'image') : ''; 26 27 # Initialise la variable à "true" si une image associée à été trouvée 28 $imageAttached = !empty($imageName); 29 30 $width = 0; 31 $height = 0; 32 if ($imageAttached) { 33 # Calcul des dimensions de l'image pour les écrire dans le code HTML 34 $imgPath = $GLOBALS['core']->blog->public_path."/illustration-articles/".$imageName; 35 if (file_exists($imgPath)) 36 list($width, $height) = getimagesize($imgPath); 37 38 $imageSrc = $GLOBALS['core']->blog->settings->public_url."/illustration-articles/".$imageName; 39 } 40 41 $required = $bMustHaveImage ? 'required' : ''; 42 43 # Ajout du formulaire d'upload 16 public static function adminPostFormSidebar(&$post) 17 { 18 global $core; 19 20 $bMustHaveImage = $core->blog->settings->mi_force; 21 $min_width = $core->blog->settings->mi_min_width; 22 $min_height = $core->blog->settings->mi_min_height; 23 24 # Tentative de récupération de l'image associée 25 $objMeta = new dcMeta($core); 26 $imageName = $post 27 ? $objMeta->getMetaStr($post->post_meta,'image') 28 : ''; 29 30 # Initialise la variable à "true" si une image associée à été trouvée 31 $imageAttached = !empty($imageName); 32 33 $width = 0; 34 $height = 0; 35 if ($imageAttached) { 36 # Calcul des dimensions de l'image pour les écrire dans le code HTML 37 $imgPath = $GLOBALS['core']->blog->public_path."/illustration-articles/".$imageName; 38 if (file_exists($imgPath)) { 39 list($width, $height) = getimagesize($imgPath); 40 } 41 $imageSrc = $GLOBALS['core']->blog->settings->public_url."/illustration-articles/".$imageName; 42 } 43 44 $required = $bMustHaveImage ? 'required' : ''; 45 46 # Ajout du formulaire d'upload 47 ?> 48 <h3><label class="<?php echo $required?>" for="upfileimage"><?php echo __('Image')?></label></h3> 49 <?php if ($imageAttached) { ?> 50 <img src="<?php echo $imageSrc?>" width="<?php echo $width?>" height="<?php echo $height?>" /> 51 <?php } else { ?> 52 <?php } ?> 53 <script type="text/javascript"> 54 formulaire = document.getElementById("entry-form"); 55 if (formulaire) { 56 formulaire.setAttribute("enctype","multipart/form-data"); 57 formulaire.setAttribute("encoding","multipart/form-data"); 58 } 59 </script> 60 <div class="p" id="meta-edit-image"> 61 <label for="upfileimage"><?php echo __('Choose an image:')?></label> 62 <input type="file" id="upfileimage" name="upfileimage" size="22" /> 63 </div> 64 <?php 65 if ($min_width > 0 || $min_height > 0) 66 { 67 echo '<p class="form-note warn">'; 68 if ($min_width > 0) { 69 echo sprintf (__('min width is %d pixels'), $min_width); 70 } 71 if ($min_height > 0) { 72 if ($min_width > 0) { 73 echo '<br />'; 74 } 75 echo sprintf (__('min height is %d pixels'), $min_height); 76 } 77 echo '</p>'; 78 } 79 } 80 81 public static function removeImage ($post_id) 82 { 83 $core = $GLOBALS['core']; 84 $objMeta = new dcMeta($core); 85 $post = $core->blog->getPosts(array('post_id' => $post_id)); 86 $oldImageName = ($post) ? $objMeta->getMetaStr($post->post_meta,'image') : ''; 87 $haveImage = !empty($oldImageName); 88 89 # S'il y avait précédement une image, tenter de la supprimer 90 if ($haveImage) { 91 try { 92 $core->media = new dcMedia($GLOBALS['core'], 'image'); 93 $core->media->chdir("illustration-articles"); 94 $core->media->removeFile($oldImageName); 95 } catch (Exception $e) {;} 96 } 97 } 98 99 public static function setImage(&$cur,&$post_id) 100 { 101 $upfileimage = null; 102 $core = $GLOBALS['core']; 103 104 $bMustHaveImage = $core->blog->settings->mi_force; 105 106 $objMeta = new dcMeta($core); 107 $post = $core->blog->getPosts(array('post_id' => $post_id)); 108 $oldImageName = ($post) ? $objMeta->getMetaStr($post->post_meta,'image') : ''; 109 $haveImage = !empty($oldImageName); 110 111 # S'il y a un fichier à associer au billet 112 if (!empty($_FILES['upfileimage']) && (strlen($_FILES['upfileimage']['name']) > 0)) 113 { 114 # Préparation de la structure pour l'upload de l'image 115 $imageName = 'tmp-article'.$post_id.'-'.$_FILES['upfileimage']['name']; 116 $upfileimage = array( 117 'name' => $imageName, 118 'type' => $_FILES['upfileimage']['type'], 119 'tmp_name' => $_FILES['upfileimage']['tmp_name'], 120 'error' => $_FILES['upfileimage']['error'], 121 'size' => $_FILES['upfileimage']['size'], 122 123 'title' => __('metaimage-title').$imageName, 124 'private' => true 125 ); 126 127 # Vérif du format de l'image 128 if ($upfileimage['type'] != 'image/gif' 129 && $upfileimage['type'] != 'image/jpeg' 130 && $upfileimage['type'] != 'image/png' 131 && $upfileimage['type'] != 'image/pjpeg' 132 && $upfileimage['type'] != 'image/pjpg') { 133 throw new Exception ($upfileimage['type'].__('error-bad-file')); 134 } 135 136 # Upload de l'image via le gestionnaire de média 137 $core->media = new dcMedia($GLOBALS['core'], 'image'); 138 $core->media->makeDir("illustration-articles"); 139 $core->media->chdir("illustration-articles"); 140 files::uploadStatus($upfileimage); 141 $file_id = $core->media->uploadFile($upfileimage['tmp_name'],$upfileimage['name'],$upfileimage['title'],$upfileimage['private']); 142 $file = $core->media->getFile($file_id); 143 $imgPath = $core->blog->public_path."/illustration-articles/".$imageName; 144 145 # Chargement en mémoire de l'image 146 $imgTool = new imageTools(); 147 try { 148 $imgTool->loadImage($imgPath); 149 } 150 catch (Exception $e) { 151 throw new Exception (__('error-missed-upload')); 152 } 153 154 # définintion des largeurs et hauteurs maximales 155 # FIXME : à rendre paramétrable 156 $min_width = $core->blog->settings->mi_min_width; 157 $min_height = $core->blog->settings->mi_min_height; 158 $max_width = $core->blog->settings->mi_max_width; 159 $max_height = $core->blog->settings->mi_max_height; 160 161 # Récupération des dimensions originales 162 $width = $imgTool->getW(); 163 $height = $imgTool->getH(); 164 165 $err_msg = ''; 166 if ($width < $min_width) { 167 throw new Exception(sprintf (__('Warning: Image must have a min width of %d pixels'), $min_width)); 168 } 169 170 if ($width < $min_width || $height < $min_height) { 171 if ($width < $min_width) { 172 echo sprintf (__('Image must have a min width of %d pixels'), $min_width); 173 } 174 175 if ($height < $min_height) 176 if ($width < $min_width) { 177 echo '<br />'; 178 } 179 echo sprintf (__('Image must have a min height of %d pixels'), $min_height); 180 181 throw new Exception($err_msg); 182 } 183 184 # Calcul des ratios 185 $x_ratio = $max_width / $width; 186 $y_ratio = $max_height / $height; 187 188 # Calcul des nouvelles dimentions 189 if (($width <= $max_width) && ($height <= $max_height)) { 190 $tn_width = $width; 191 $tn_height = $height; 192 } 193 elseif (($x_ratio * $height) < $max_height) { 194 $tn_height = ceil($x_ratio * $height); 195 $tn_width = $max_width; 196 } 197 else { 198 $tn_width = ceil($y_ratio * $width); 199 $tn_height = $max_height; 200 } 201 202 # Redimentionnement de l'image 203 $imgTool->resize($tn_width, $tn_height); 204 205 # S'il y avait précédement une image, tenter de la supprimer 206 if ($haveImage) { 207 try { 208 $core->media->removeFile($oldImageName); 209 } 210 catch (Exception $e) 211 {;} 212 } 213 214 # Enregistrement de la nouvelle image dans un format dépendant du format d'origine 215 switch($upfileimage['type']) { 216 case 'image/gif': 217 case 'image/png': 218 $ext = 'png'; 219 break; 220 default: 221 $ext = 'jpg'; 222 } 223 $newImageName = 'billet'.$post_id.'.'.$ext; 224 $newImagePathName = $core->blog->public_path."/illustration-articles/".$newImageName; 225 $imgTool->output($ext, $newImagePathName); 226 227 # Effacement de l'image temporaire ET ajout de l'image redimentionnée dans le gestionnaire de media 228 $core->media->removeFile($imageName); 229 $core->media->createFile($newImageName, __('metaimage-title').$post_id, true); 230 231 # Ajout de l'info dans 'post_meta' pour associer l'image au billet 232 $post_id = (integer) $post_id; 233 $objMeta = new dcMeta($core); 234 $objMeta->delPostMeta($post_id,'image'); 235 $objMeta->setPostMeta($post_id,'image', $newImageName); 236 } 237 else { 238 # Si aucune image n'est associée à ce billet et qu'une image associée est requise, refuse la validation 239 if (!$haveImage && $bMustHaveImage) { 240 throw new Exception (sprintf (__('error-missed-image'), __('Image:'))); 241 } 242 } 243 } 244 } 44 245 ?> 45 <h3><label class="<?php echo $required?>" for="upfileimage"><?php echo __('Image')?></label></h3>46 <?php if ($imageAttached) { ?>47 <img src="<?php echo $imageSrc?>" width="<?php echo $width?>" height="<?php echo $height?>" />48 <?php } else { ?>49 <?php } ?>50 <script type="text/javascript">51 formulaire = document.getElementById("entry-form");52 if (formulaire) {53 formulaire.setAttribute("enctype","multipart/form-data");54 formulaire.setAttribute("encoding","multipart/form-data");55 }56 </script>57 <div class="p" id="meta-edit-image">58 <label for="upfileimage"><?php echo __('Choose an image:')?></label>59 <input type="file" id="upfileimage" name="upfileimage" size="22" />60 </div>61 <?php if ($min_width > 0 || $min_height > 0)62 {63 echo '<p class="form-note warn">';64 if ($min_width > 0) {65 echo sprintf (__('min width is %d pixels'), $min_width);66 }67 if ($min_height > 0) {68 if ($min_width > 0)69 echo '<br />';70 echo sprintf (__('min height is %d pixels'), $min_height);71 }72 echo '</p>';73 }74 }75 76 public static function removeImage ($post_id)77 {78 $core = $GLOBALS['core'];79 $objMeta = new dcMeta($core);80 $post = $core->blog->getPosts(array('post_id' => $post_id));81 $oldImageName = ($post) ? $objMeta->getMetaStr($post->post_meta,'image') : '';82 $haveImage = !empty($oldImageName);83 84 # S'il y avait précédement une image, tenter de la supprimer85 if ($haveImage) {86 try {87 $core->media = new dcMedia($GLOBALS['core'], 'image');88 $core->media->chdir("illustration-articles");89 $core->media->removeFile($oldImageName);90 } catch (Exception $e) {;}91 }92 }93 94 public static function setImage(&$cur,&$post_id)95 {96 $upfileimage = null;97 $core = $GLOBALS['core'];98 99 $bMustHaveImage = $core->blog->settings->must_have_image;100 101 $objMeta = new dcMeta($core);102 $post = $core->blog->getPosts(array('post_id' => $post_id));103 $oldImageName = ($post) ? $objMeta->getMetaStr($post->post_meta,'image') : '';104 $haveImage = !empty($oldImageName);105 106 # S'il y a un fichier à associer au billet107 if (!empty($_FILES['upfileimage']) && (strlen($_FILES['upfileimage']['name']) > 0))108 {109 # Préparation de la structure pour l'upload de l'image110 $imageName = 'tmp-article'.$post_id.'-'.$_FILES['upfileimage']['name'];111 $upfileimage = array(112 'name' => $imageName,113 'type' => $_FILES['upfileimage']['type'],114 'tmp_name' => $_FILES['upfileimage']['tmp_name'],115 'error' => $_FILES['upfileimage']['error'],116 'size' => $_FILES['upfileimage']['size'],117 118 'title' => __('metaimage-title').$imageName,119 'private' => true120 );121 122 # Vérif du format de l'image123 if (($upfileimage['type']) != 'image/gif' &&124 ($upfileimage['type']) != 'image/jpeg' &&125 ($upfileimage['type']) != 'image/png' &&126 ($upfileimage['type']) != 'image/pjpeg' &&127 ($upfileimage['type']) != 'image/pjpg')128 {129 throw new Exception ($upfileimage['type'].__('error-bad-file'));130 }131 132 # Upload de l'image via le gestionnaire de média133 $core->media = new dcMedia($GLOBALS['core'], 'image');134 $core->media->makeDir("illustration-articles");135 $core->media->chdir("illustration-articles");136 files::uploadStatus($upfileimage);137 $file_id = $core->media->uploadFile($upfileimage['tmp_name'],$upfileimage['name'],$upfileimage['title'],$upfileimage['private']);138 $file = $core->media->getFile($file_id);139 $imgPath = $core->blog->public_path."/illustration-articles/".$imageName;140 141 # Chargement en mémoire de l'image142 $imgTool = new imageTools();143 try {144 $imgTool->loadImage($imgPath);145 } catch (Exception $e) {146 throw new Exception (__('error-missed-upload'));147 }148 149 # définintion des largeurs et hauteurs maximales, TODO : à rendre paramétrable150 $min_width = $core->blog->settings->min_width;151 $min_height = $core->blog->settings->min_height;152 $max_width = $core->blog->settings->max_width;153 $max_height = $core->blog->settings->max_height;154 155 # Récupération des dimensions originales156 $width = $imgTool->getW();157 $height = $imgTool->getH();158 159 $err_msg = '';160 if ($width < $min_width)161 throw new Exception(sprintf (__('Warning: Image must have a min width of %d pixels'), $min_width));162 163 if ($width < $min_width || $height < $min_height)164 {165 if ($width < $min_width)166 echo sprintf (__('Image must have a min width of %d pixels'), $min_width);167 168 if ($height < $min_height)169 if ($width < $min_width)170 echo '<br />';171 echo sprintf (__('Image must have a min height of %d pixels'), $min_height);172 173 throw new Exception($err_msg);174 }175 176 # Calcul des ratios177 $x_ratio = $max_width / $width;178 $y_ratio = $max_height / $height;179 180 # Calcul des nouvelles dimentions181 if( ($width <= $max_width) && ($height <= $max_height) )182 {183 $tn_width = $width;184 $tn_height = $height;185 }186 elseif (($x_ratio * $height) < $max_height)187 {188 $tn_height = ceil($x_ratio * $height);189 $tn_width = $max_width;190 }191 else192 {193 $tn_width = ceil($y_ratio * $width);194 $tn_height = $max_height;195 }196 197 # Redimentionnement de l'image198 $imgTool->resize($tn_width, $tn_height);199 200 # S'il y avait précédement une image, tenter de la supprimer201 if ($haveImage) {202 try {203 $core->media->removeFile($oldImageName);204 } catch (Exception $e) {;}205 }206 207 # Enregistrement de la nouvelle image dans un format dépendant du format d'origine208 switch($upfileimage['type']){209 case 'image/gif':210 case 'image/png':211 $ext = 'png';212 break;213 default:214 $ext = 'jpg';215 }216 $newImageName = 'billet'.$post_id.'.'.$ext;217 $newImagePathName = $core->blog->public_path."/illustration-articles/".$newImageName;218 $imgTool->output($ext, $newImagePathName);219 220 # Effacement de l'image temporaire ET ajout de l'image redimentionnée dans le gestionnaire de media221 $core->media->removeFile($imageName);222 $core->media->createFile($newImageName, __('metaimage-title').$post_id, true);223 224 # Ajout de l'info dans 'post_meta' pour associer l'image au billet225 $post_id = (integer) $post_id;226 $objMeta = new dcMeta($core);227 $objMeta->delPostMeta($post_id,'image');228 $objMeta->setPostMeta($post_id,'image', $newImageName);229 }230 else {231 # Si aucune image n'est associée à ce billet et qu'une image associée est requise, refuse la validation232 if (!$haveImage && $bMustHaveImage)233 throw new Exception (sprintf (__('error-missed-image'), __('Image:')));234 }235 }236 }237 238 ?> -
plugins/metaImage/_define.php
r349 r414 1 1 <?php 2 2 $this->registerModule( 3 /* Name */ "Meta Image",4 /* Description*/ "Permet - voir oblige - l'association d'une image à chaque billet créé",5 /* Author */ "Marc Claustre / arald.org",6 /* Version */ 7 /* Permissions */ 3 /* Name */ 'Meta Image', 4 /* Description*/ 'Allows users attach an image to each entry', 5 /* Author */ 'Marc Claustre - http://arald.org', 6 /* Version */ '0.3', 7 /* Permissions */ 'usage,contentadmin' 8 8 ); 9 9 ?> -
plugins/metaImage/_install.php
r349 r414 1 1 <?php 2 $m_version = $core->plugins->moduleInfo('Meta Image','version'); 3 4 $i_version = $core->getVersion('metaimage'); 5 2 if (!defined('DC_CONTEXT_ADMIN')) { exit; } 3 4 $label = 'metaImage'; 5 $m_version = $core->plugins->moduleInfo($label,'version'); 6 $i_version = $core->getVersion($label); 7 6 8 if (version_compare($i_version,$m_version,'>=')) { 7 9 return; 8 10 } 9 11 10 # Cr éation du setting (s'il existe, il ne sera pas écrasé)11 $settings = new dcSettings($core,null);12 $settings->setNamespace( 'metaimage');13 $settings->put('m ust_have_image',false,'boolean','Force usage of image',false,true);14 $settings->put('mi n_width',150,'integer','Min width',false,true);15 $settings->put('mi n_height',50,'integer','Min height',false,true);16 $settings->put('m ax_width',150,'integer','Max width',false,true);17 $settings->put('m ax_height',450,'integer','Max height',false,true);12 # Creating / updating settings 13 $settings = &$core->blog->settings; 14 $settings->setNamespace(strtolower($label)); 15 $settings->put('mi_force',false,'boolean','Force usage of image',false,true); 16 $settings->put('mi_min_width',150,'integer','Min width',false,true); 17 $settings->put('mi_min_height',50,'integer','Min height',false,true); 18 $settings->put('mi_max_width',150,'integer','Max width',false,true); 19 $settings->put('mi_max_height',450,'integer','Max height',false,true); 18 20 19 $core->setVersion('metaimage',$m_version); 21 $core->setVersion($label,$m_version); 22 unset($label,$m_version,$i_version); 20 23 return true; 21 24 ?> -
plugins/metaImage/_public.php
r349 r414 1 1 <?php 2 global $core;3 2 $core->tpl->addValue('MetaImage',array('tplMetaImageTpl','MetaImage')); 4 3 5 4 class tplMetaImageTpl 6 5 { 7 8 6 public static function MetaImage($attr) 9 7 { -
plugins/metaImage/index.php
r349 r414 1 1 <?php 2 $page_name = __('Meta Image'); 2 3 $label = 'metaImage'; 4 $p_name = __('Meta Image'); 5 6 if ($core->blog->settings->mi_force === null) { 7 $res = require dirname(__FILE__).'/_install.php'; 8 9 # If installation failed, redirect to index.php 10 if ($res !== true) { 11 http::redirect('index.php'); 12 } 13 } 14 15 $settings = &$core->blog->settings; 16 17 $force = $settings->mi_force; 18 $min_width = $settings->mi_min_width; 19 $min_height = $settings->mi_min_height; 20 $max_width = $settings->mi_max_width; 21 $max_height = $settings->mi_max_height; 22 23 if (isset($_POST['act_save'])) { 24 $force = !empty($_POST['force']); 25 $min_width = (integer) $_POST['min_width']; 26 $min_height = (integer) $_POST['min_height']; 27 $max_width = (integer) $_POST['max_width']; 28 $max_height = (integer) $_POST['max_height']; 29 } 30 31 if (isset($_POST['act_save'])) { 32 try { 33 if ($min_width > $max_width) { 34 throw new Exception(__('Minimal width greater than maximal width.')); 35 } elseif ($min_height > $max_height) { 36 throw new Exception(__('Minimal height greater than maximal height.')); 37 } 38 39 $settings->setNameSpace(strtolower($label)); 40 $settings->put('mi_force',$force); 41 $settings->put('mi_min_width',$min_width); 42 $settings->put('mi_min_height',$min_height); 43 $settings->put('mi_max_width',$max_width); 44 $settings->put('mi_max_height',$max_height); 45 46 http::redirect($p_url.'&up=1'); 47 } catch (Exception $e) { 48 $core->error->add($e->getMessage()); 49 } 50 } 51 52 $msg = ''; 53 54 if (isset($_REQUEST['up'])) { 55 $msg = __('Configuration successfully updated'); 56 } 57 58 if (!empty($msg)) { 59 $msg = '<p class="message">'.$msg.'</p>'; 60 } 61 62 echo 63 '<html><head> 64 <title>'.$p_name.'</title> 65 </head><body> 66 <h2>'.html::escapeHTML($core->blog->name).' > '.html::escapeHTML($p_name).'</h2> 67 '.$msg.' 68 <h3>'.__('Usage').'</h3> 69 <p>'. 70 __('In your post.html template, add {{tpl:MetaImage}} where you want to print the meta image.'). 71 '</p> 72 73 <h3>'.__('Config').'</h3> 74 <form action="'.$p_url.'" method="post"> 75 76 <p><label class="classic">'.form::checkbox('force',1,$force).' '. 77 __('Posts must have an image').'</label></p> 78 79 <fieldset><legend>'.__('Images size').'</legend> 80 <h3>'.__('Min size').'</h3> 81 <p>'.__('Message, min size').'</p> 82 <p>'.sprintf(__('%sWidth%s x %sheight%s:'), 83 '<label for="min_width" class="classic">','</label>', 84 '<label for="min_height" class="classic">','</label>').' '. 85 form::field('min_width',4,4,$min_width).' x '. 86 form::field('min_height',4,4,$min_height).' 87 </p> 3 88 4 # Si les propriétés n'ont pas encore été fixées 5 if ($core->blog->settings->must_have_image === null) 6 { 7 $core->blog->settings->setNameSpace('metaimage'); 8 $core->blog->settings->put('must_have_image',0,'boolean','Force usage of image',false,true); 9 $core->blog->settings->put('min_width',150,'integer','Min width',false,true); 10 $core->blog->settings->put('min_height',50,'integer','Min height',false,true); 11 $core->blog->settings->put('max_width',150,'integer','Max width',false,true); 12 $core->blog->settings->put('max_height',450,'integer','Max height',false,true); 13 http::redirect($p_url); 14 } 15 16 # Si l'on vient de la validation du formulaire 17 if (isset($_POST['fromform'])) { 18 19 $core->blog->settings->setNameSpace('metaimage'); 20 $valueChanged = false; 21 22 # Si la valeur reçue est différente de la valeur enregistrée en base de données 23 if (isset($_POST['must_have_image']) != $core->blog->settings->must_have_image) { 24 $core->blog->settings->put('must_have_image',isset($_POST['must_have_image']),'boolean','Force usage of image',true,true); 25 $valueChanged = true; 26 } 27 if ($_POST['max_width'] != $core->blog->settings->max_width) { 28 $core->blog->settings->put('min_width',$_POST['min_width'],'integer','Min width',true,true); 29 $valueChanged = true; 30 } 31 if ($_POST['min_height'] != $core->blog->settings->min_height) { 32 $core->blog->settings->put('min_height',$_POST['min_height'],'integer','Min height',true,true); 33 $valueChanged = true; 34 } 35 if ($_POST['max_width'] != $core->blog->settings->max_width) { 36 $core->blog->settings->put('max_width',$_POST['max_width'],'integer','Max width',true,true); 37 $valueChanged = true; 38 } 39 if ($_POST['max_height'] != $core->blog->settings->max_height) { 40 $core->blog->settings->put('max_height',$_POST['max_height'],'integer','Max height',true,true); 41 $valueChanged = true; 42 } 43 44 # Si au moins une valeur a été modifiée, recharger pour mettre à jour cette (ou ces) valeur(s) 45 if ($valueChanged) 46 http::redirect($p_url.'&up=1'); 47 } 89 <h3 style="padding-top: 1.5em;">'.__('Max size').'</h3> 90 <p>'.__('Message, max size').'</p> 91 <p>'.sprintf(__('%sWidth%s x %sheight%s:'), 92 '<label for="max_width" class="classic">','</label>', 93 '<label for="max_height" class="classic">','</label>').' '. 94 form::field('max_width',4,4,$max_width).' x '. 95 form::field('max_height',4,4,$max_height).' 96 </p> 97 </fieldset> 48 98 99 <p><input type="submit" name="act_save" value="'.__('save').'" />'. 100 $core->formNonce().'</p> 101 </form> 102 </body></html> 103 '; 49 104 ?> 50 <html>51 <head>52 <title><?php echo $page_name; ?></title>53 </head>54 55 <body>56 <h2><?php echo html::escapeHTML($core->blog->name).' > '.$page_name; ?></h2>57 58 <h3><?php echo __('Usage'); ?></h3>59 <p><?php echo __('In your post.html template, add {{tpl:MetaImage}} where you want to print the meta image.') ?></p>60 61 <h3><?php echo __('Config'); ?></h3>62 <form action="<?php echo $p_url; ?>" method="post">63 <input type="hidden" id="fromform" name="fromform" value="1" />64 <?php echo $core->formNonce(); ?>65 <p>66 <?php echo form::checkbox('must_have_image',1,$core->blog->settings->must_have_image); ?>67 <label for="must_have_image" class="classic"><?php echo __('Posts must have an image'); ?></label>68 </p>69 70 <fieldset><legend><?php echo __('Images size'); ?></legend>71 <h3><?php echo __('Min size'); ?></h3>72 <p><?php echo __('Message, min size'); ?></p>73 <label for="min_width" class="classic"><?php echo __('Width'); ?></label> x74 <label for="min_height" class="classic"><?php echo __('height'); ?></label> :75 <input type="text" id="min_width" name="min_width" size="4" value="<?php echo $core->blog->settings->min_width ?>"/> x76 <input type="text" id="min_height" name="min_height" size="4" value="<?php echo $core->blog->settings->min_height ?>" />77 78 <h3 style="padding-top: 1.5em;"><?php echo __('Max size'); ?></h3>79 <p><?php echo __('Message, max size'); ?></p>80 <label for="max_width" class="classic"><?php echo __('Width'); ?></label> x81 <label for="max_height" class="classic"><?php echo __('height'); ?></label> :82 <input type="text" id="max_width" name="max_width" size="4" value="<?php echo $core->blog->settings->max_width ?>" /> x83 <input type="text" id="max_height" name="max_height" size="4" value="<?php echo $core->blog->settings->max_height ?>" />84 </fieldset>85 86 <input type="submit" value="<?php echo __('save')?>" />87 </form>88 89 </body>90 </html>
Note: See TracChangeset
for help on using the changeset viewer.