表示モード切替(印刷用)paraedit

  • ページ: Develop/Modification1
  • 投稿者: ぃぉぃぉ
  • 優先順位: 普通
  • 状態: 完了
  • カテゴリー: プラグイン
  • 投稿日: 2010-02-10 (水) 18:25:04
  • バージョン: 0.0.16

メッセージparaedit

主な目的 ... 印刷時にresizeimage無効化

仕様paraedit

パラメータにmedia=printを追加するとresizeimageを無効にする。cssのパラメータに合わせてみた。*1

実装paraedit

plugin/ref.inc.phpparaedit

もともとresizeimageを使用するかどうかdefineしていたので、その部分に条件追加。

  • function plugin_ref_body
    	$params['_align'] = PLUGIN_REF_DEFAULT_ALIGN;
    	foreach (array('right', 'left', 'center') as $align) {
    		if ($params[$align])  {
    			$params['_align'] = $align;
    			break;
    		}
    	}
    	if ($is_url) {
    		if ($is_image) {
    			$params['_body'] = "<img src=\"$url\" alt=\"$title\" title=\"$title\" $info/>";
    			if (! $params['nolink']) {
    				$params['_body'] = "<a href=\"$linkurl\" title=\"$title\">{$params['_body']}</a>";
    			}
    		} else {
    		$icon = $params['noicon'] ? '' : FILE_ICON;
    		$params['_body'] = "<a href=\"$linkurl\" title=\"$info\">$icon$title</a>";
    		}
    +		$media   = isset($vars['media'])   ? $vars['media']    : '';
    		if (PLUGIN_REF_DIRECT_ACCESS) {
    			$params['_body'] = "<img src=\"$file\" alt=\"$title\" title=\"$title\" $info/>";
    !		} else if(PLUGIN_REF_USE_RESIZEIMAGE && ($media !== 'print')) {
    			$params['_body'] = '<img src="' . get_wiki_uri(array_merge($thumbnailurlparam, $thumbnailinfoparam)) . "\" alt=\"$title\" title=\"$title\" />";
    		} else {
    			$params['_body'] = '<img src="' . get_wiki_uri($refurlparam) . "\" alt=\"$title\" title=\"$title\" $info/>";
    		}
    		if (! $params['nolink'] && isset($attachurlparam))
    			$params['_body'] = '<a href="' . get_wiki_uri($attachurlparam) . "\" title=\"$title\">{$params['_body']}</a>";
    	} else {
    		$icon = $params['noicon'] ? '' : FILE_ICON;
    		$params['_body'] = '<a href="' . get_wiki_uri($attachurlparam) . "\" title=\"$info\">$icon$title</a>";
    	}

plugin/resizeimage.inc.phpparaedit

  • function plugin_resizeimage_inline()

media=printであれば、refを使用する。ただし、サイズ指定でwidthかheightいずれかのみ指定されている場合にはresizeimageを使用する。(refに渡すとサイズが幅か高さが0になって画像が表示できないため。)

{
	global $vars;
	if(isset($vars['page'])) {
		$page = $vars['page'];
	} else {
		return PLUGIN_RESIZEIMAGE_ERROR_NO_PAGE;
	}
 
	$args = func_get_args();
 
	$matches = array();
	//   (Page_name/maybe-separated-with/slashes/ATTACHED_FILENAME)
	$file = array_shift($args);
	if (preg_match('#^(.+)/([^/]+)$#', $file, $matches)) {
		if ($matches[1] == '.' || $matches[1] == '..') {
			$matches[1] .= '/'; // Restore relative paths
		}
		$file = $matches[2];
		$page = get_fullname(strip_bracket($matches[1]), $page); // strip is a compat
	}
 
-	$page = '&amp;page=' . rawurlencode($page);
-	$file = '&amp;image=' . rawurlencode($file);
 	$width = isset($args[0]) ? array_shift($args) : '';
-	$width = ($width === '') ? '' : '&amp;w=' . $width;
 	$height = isset($args[0]) ? array_shift($args) : '';
-	$height = ($height === '') ? '' : '&amp;h=' . $height;
 	$quality = isset($args[0]) ? array_shift($args) : '';
-	$quality = ($quality === '') ? '' : '&amp;q=' . $quality;
 	$keep = isset($args[0]) ? (array_shift($args) ? '&amp;k' : '') : '';
-
+	$a_uri['plugin'] = 'resizeimage';
+	$a_uri['page'] = $page;
+	$a_uri['image'] = $file;
+	if($width !== '') {
+		$a_uri['w'] = $width;
+	}
+	if($height !== '') {
+		$a_uri['h'] = $height;
+	}
+	if($quality !== '') {
+		$a_uri['q'] = $quality;
+	}
+	if($keep !== '') {
+		$a_uri['k'] = '';
+	}
+	if ($width && $height){		// if both width and height are set
+		$info = "width=\"$width\" height=\"$height\" ";
+	} else if(!$width && !$height) { // if neither width nor height is set
+		$info = '';
+	}
+	if(isset($vars['media']) && ($vars['media'] === 'print') && isset($info)) {
+		$a_uri['media'] = 'print';
+		return '<img src="' . get_wiki_uri($a_uri, TRUE) . "\"$info/>";
+	}
+	return '<img src="' . overload_wiki_uri($a_uri, TRUE) . '" />';
}
  • function plugin_resizeimage_action()
    function plugin_resizeimage_action()
    {
    	global $vars;
     
    	$page     = isset($vars['page']) ? $vars['page'] : '';
    	$filename = isset($vars['image']) ? $vars['image'] : '';
    	$resize_width = isset($vars['w']) ? $vars['w'] : (isset($vars['width']) ? $vars['width'] : PLUGIN_RESIZEIMAGE_DEFAULTWIDTH);
    	$resize_height = isset($vars['h']) ? $vars['h'] : (isset($vars['height']) ? $vars['height'] : PLUGIN_RESIZEIMAGE_DEFAULTHEIGHT);
    	$resize_quality = isset($vars['q']) ? $vars['q'] : (isset($vars['quality']) ? $vars['quality'] : PLUGIN_RESIZEIMAGE_DEFAULTQUALITY);
    	$resize_keepaspectratio = isset($vars['k']) || isset($vars['keepaspectratio']) || isset($vars['keepaspect']);
     
    	if(check_readable($page, FALSE, FALSE)) {
    +		$media   = isset($vars['media'])   ? $vars['media']    : '';
    +		if ($media === 'print'){
    +			$vars['src'] = $filename;
    +			if(do_plugin_action('ref')) {
    +				exit;
    +			}
    +		}
    		$inputfile = UPLOAD_DIR . encode($page) . '_' . encode(preg_replace('#^.*/#', '', $filename));
    		resizeimagetojpg($inputfile, $cachefile_dir, $resize_width, $resize_height, $resize_quality, $resize_keepaspectratio, $filename);
    		outputjpeg(makeimagefromtext("Not readable."), $resize_quality);
    	}
    	exit;
    }

lib/func.phpparaedit

function overload_wiki_uri($a_overload = array(), $encode = FALSE)
{
	global $vars;
	/* Analyze get parameters. If the first value is pagename, remove it. */
!	$overloadparams = array('ptyear', 'ptmonth', 'c_sep', 'c_date', 'media');
	foreach($overloadparams as $overloadparam) {
		if (isset($vars[$overloadparam]) && !isset($a_overload[$overloadparam])) {
			$a_overload[$overloadparam] = $vars[$overloadparam];
		}
	}
	return get_wiki_uri($a_overload, '', SCRIPT_URI_RELATIVE, !$encode);
}



*1resizeimage導入時にいい設計してたなぁ、おれ

トップ 編集凍結差分バックアップ添付複製名前変更リロード 新規一覧 単語検索 最終更新  ヘルプ  最終更新のRSS
Last-modified: 2010-06-28 (月) 20:47:54 (3400d)