Oct 27

Download Counter 是用于管理 WordPress 文件下载的插件,在后台管理中填入下载文件数据(标题,真实地址)后,通过:
< lang="php" linenum="off">
[Download]文件ID[/Download]

在文章中插入附件下载代码。

顾名思义,Download Counter 可以统计附件的下载次数,并让下载者看到此文件已被载过多少次。

Download Counter 1.2 基于 JerryDownload Counter 1.1,原始版本则是 VanguardDownload Counter v1.0

主要的改动有:

1.去掉了作用不大但是及其影响速度的验证链接是否有效的功能;
2.重新设计后台管理界面,默认显示最后 10 个添加的文件信息,避免文件多了后超长的列表;
3.增加搜索功能,可以通过文件 ID 或者文件名(文件描述)来搜索文件;
4.修复在 IE 7 下显示不正常的 BUG,少许迎合 XHTML 的改动(懒得全部改了反正是后台)。

附件下载 Download Counter 1.2 。


Oct 26

CoolCode默认显示模式是自动换行,当你的正文版面宽度很窄时,这样频繁的换行会使阅读代码变得困难。于是做了一点小改动,当点击代码界面时,自动显示滚动条,此时代码不换行。

需要改动的文件有.css,.js,.php。

.css


.hl-surround {
    background-color: #F9FBFC;
    border: 1px solid #C3CED9;
    padding: 0;
    margin: 0;
    margin-bottom: 5px;
    width: 98%;
    height: auto;
    overflow: hidden;
    white-space: normal;
    text-align: left;
    font-family: "Courier New", "BitStream Vera Sans Mono", Fixedsys, Courier, monospace;
}

主要是添加(改动)overflow: hidden 和 white-space: normal 这两个属性;

.js


function switchscroll(id){
if(id.style.overflow!="auto"){
	id.style.overflow="auto";
	id.style.whiteSpace="nowrap";
}else{
	id.style.overflow="hidden";
	id.style.whiteSpace="normal";
}
}

把这个函数添加进去;

.php


<div class="hl-surround" onclick="switchscroll(this);">

在.php中找到<div class="hl-surround",在其中添加一个onclick的事件,一共有四处。

示例,点击代码窗口:


$options = array(
    'numbers' => HL_NUMBERS_LI,
);
$hl =& Text_Highlighter::factory($lang, $options);
$this->blocks[$blockID] .= '<div class="hl-surround" onclick="switchscroll(this);">' . str_replace($this->hl_class, $this->hl_style, $hl->highlight($txt)) . '</div>';
$this->blocks[$blockID] = preg_replace('/<span style="[^"]*?"></span>/', '', $this->blocks[$blockID]);
$this->blocks[$blockID] = str_replace('<ol class="hl-main">',
    '<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)">',
    $this->blocks[$blockID]);
$this->blocks[$blockID] = str_replace(""> </span></li>", "">&nbsp;</span></li>", $this->blocks[$blockID]);
$this->blocks[$blockID] = preg_replace('/<li><span style=(.*?)> </si', '<li><span style=\1>&nbsp;<', $this->blocks[$blockID]);

if ($hackphp) {
    $this->blocks[$blockID] = str_replace("<span style="color: Blue;">&lt;?php</span></li>n<li>", '', $this->blocks[$blockID]);
    $this->blocks[$blockID] = str_replace('<li><span style="color: Blue;">?&gt;</span></li>', '', $this->blocks[$blockID]);
}

附件是改好的文件。

BTW: IE真是...不好说了,注意到没,点击后,在FireFox下不会出现垂直滚动条,因为那个滚动条宽度并没计算到原容器里面,而在IE下点击,会出现垂直滚动条,它把滚动条的宽度也计算进去了>_<


Oct 16

Shutter是一个能实现类似LightBox效果的Javascript脚本,也就是在当前页面全屏遮罩下显示缩略图对应的原始图片,它比LightBox小多了,只有8K左右大小。作者同时写出了WordPress的插件Shutter-Reload。不过Shutter-Reload本身不带缩略图生成功能,所以我们可以结合iimage-Gallery在文章中方便的实现Shutter效果的图片集。

Shutter-Reload有个选项叫"Shutter on all image links with rel="prettyPhoto" or "shutterset" or "shutterset_123"",我们只要利用这个稍微修改一下iimage-Gallery就行了,让它生成缩略图的时候同时添加相应的Class标记。

把修改好的iimage-gallery.php覆盖原来的文件(请先备份),然后用如下语句添加Gallery:


<gallery crop="true"  stand_alone="false" shutterset="quakemachine">
图片地址1
...
图片地址N
</gallery>

除了shutterset,前面的都属于原iimage-Gallery自带的选项,现在设置为当独立浏览模式关闭时(也就是stand_alone="false")使用Shutter方式浏览图片,shutterset是个ID,在当前页面需唯一,可以设置为任意英文,数字和"-"号,不支持中文。具体效果可以参考MRemote一文的截图。

Shutter和iimage-Gallery请到原作者页面下载,附件是改好的iimage-gallery.php文件。


Sep 10

一直想做一个实时预览文章的东西,却不知道做在哪好。现在终于完成了,请看本站的“文章检索”页面。

舍弃了华丽但是臃肿的af-extended-live-archive,换用了Viper007Bond同学的Clean Archives Reloaded,特别欣赏作者对JS代码随用随载的方法,而不是一股脑全往Header里面丢。

看到文章列表后面那个小图标了吗?点它!---这就是我加的一点小佐料:文章实时预览。

参考ajaxwp,改变思路,用WordPress原本的方式渲染文章,用脚本访问 ajax-wp.php:


<?php
/**
 * AjaxWp - An AJAX enchancement for Wordpress
 * Copyright (c) 2006, Gianni Milanesi <gianni@giannim.com>
 *
 * AjaxWp is freely distributable under the terms of an MIT-style license.
 * For details, see the AjaxWp web site: http://www.giannim.com/projects/ajax-wp
 *
 */
	$postid = $_GET['postid'];
	require('../../../wp-blog-header.php');
	// Load the requested posts
	query_posts('p='.$postid);
	include("ajax-single.php");
?>

其中ajax-single.php则为原模板single.php去掉头尾等多余内容而来:


<div id="content">
	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
		<div class="entry">
		<div class="post" id="post-<?php the_ID(); ?>">
			<h2><a href="<?php echo get_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title('-image-'); ?></a></h2>
			<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
			<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?><br />
	<?php endwhile; else: ?>
		<div class="entry">
			<p>Sorry, no posts matched your criteria.</p>
		</div>
    <?php endif; ?>
</div>

我希望能得到一些意见建议,如果把这东西处理好了,做成插件应该是蛮好的。