2009-01-15

在symfony项目中应用TinyMCE(续)

类归于: symfony — 标签:, zhuozi @ 09:25

通过上一篇《在symfony项目中应用TinyMCE》文章,我们知道了,如何在symfony配置TinyMCE,如何在模板中应用TinyMCE,
可是,如果我们想在apps/backend中应用应该如何办呢?
通过在google的搜索,有两个方法。
1、配置genertor.yml文件,和config下面的app.yml、setting.yml文件,在网上一搜可以搜索到很多,可是,昨天试了一上午
也没有测试出来,这里就不讲了,主要说一下第二种方法。
2、定义form
我们在lib下面新建一个sfWidgetFormTextareaTinyMCE.class.php文件

<?php
/*
* This file is part of the symfony package.
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* sfWidgetFormTextareaTinyMCE represents a Tiny MCE widget.
*
* You must include the Tiny MCE JavaScript file by yourself.
*
* @package    symfony
* @subpackage widget
* @author     Fabien Potencier <fabien.potencier@symfony-project.com>
* @version    SVN: $Id: sfWidgetFormTextareaTinyMCE.class.php 11894
2008-10-01 16:36:53Z fabien $
*/
class sfWidgetFormTextareaTinyMCE extends sfWidgetFormTextarea
{
/**
* Constructor.
*
* Available options:
*
*  * theme:  The Tiny MCE theme
*  * width:  Width
*  * height: Height
*  * config: The javascript configuration
*
* @param array $options     An array of options
* @param array $attributes  An array of default HTML attributes
*
* @see sfWidgetForm
*/
protected function configure($options = array(), $attributes = array())
{
$this->addOption('theme', 'advanced');
$this->addOption('width');
$this->addOption('height');
$this->addOption('config', '');
}

/**
* @param  string $name        The element name
* @param  string $value       The value selected in this
widget
* @param  array  $attributes  An array of HTML attributes to
be merged with the default HTML attributes
* @param  array  $errors      An array of errors for the
field
*
* @return string An HTML tag string
*
* @see sfWidgetForm
*/
public function render($name, $value = null, $attributes = array(),
$errors = array())
{
$textarea = parent::render($name, $value, $attributes, $errors);

$js = sprintf(<<<EOF
<script type="text/javascript">
tinyMCE.init({
mode:                              "exact",
elements: "%s",
theme:                             "%s",
%s
%s
theme_advanced_toolbar_location:   "top",
theme_advanced_toolbar_align:      "left",
theme_advanced_statusbar_location: "bottom",
theme_advanced_resizing:           true
%s
});
</script>
EOF
,
$this->generateId($name),
$this->getOption('theme'),
$this->getOption('width')  ? sprintf('width:
"%spx",', $this->getOption('width')) : '',
$this->getOption('height') ? sprintf('height:
"%spx",', $this->getOption('height')) : '',
$this->getOption('config') ?
",\n".$this->getOption('config') : ''
);

return $textarea.$js;
}
}

接下来我们需要重新定义lib/form下我们需要的form(e.g. 我们定义的description字段)

public function configure()
{
$this->widgetSchema['description'] = new sfWidgetFormTextareaTinyMCE(array(
'width'  => 450,
'height' => 350,
'config' => 'theme_advanced_disable: "anchor,image,cleanup,help"',
));
}

最后大家别忘记在layout.php 中定义js的路径

javascripts:    [js/tiny_mce.js]

2009-01-14

symfony 环境检查

类归于: symfony — 标签:, maker @ 12:12

symfony中自带了一个检查运行环境的程序, 可以用来检查symfony是否可以在当前环境下正常的运行, 程序路径如下.

/data/bin/check_configuration.php

check_configuration.php是一个独立的php程序, 可以在任何地方独立运行. check_configuration.php 也可以同时运行在web和cli两种模式下.

将check_configuration.php复制到web目录下, 访问http://project/check_configuration.php显示如下

screenshot3或者在shell下执行

php pathtosymfony/data/bin/check_configuration.php

显示如下

screenshot-1

如果返回了语法错误你需要更新一下你的symfony源码, 还有要注意的是很多服务器中web访问和cli执行php使用的是两套php.ini, 所以建议将check_configuration.php单独上传到web目录下在浏览器中进行访问.

check_configuration.php 对运行环境做了以下检查.

必要配置
requires PHP >= 5.2.4
 - php版本必须大于5.2.4
php.ini: requires zend.ze1_compatibility_mode set to off
 - php.ini中zend.ze1_compatibility_mode 的值为 off

可选配置
PDO is installed
 - 需要安装PDO模块
PDO has some drivers installed: mysql, sqlite
 - 需要安装PDO的mysql和sqlite驱动
PHP-XML module installed
 - 需要安装PHP-XML模块
XSL module installed
 - 需要安装XSL模块
can use token_get_all()
 - 可以使用token_get_all函数
can use mb_strlen()
 - 可以使用mb_strlen()函数, 需要安装mbstring模块
can use iconv()
 - 可以使用iconv()函数, 需要安装iconv模块
can use utf8_decode()
 - 可以使用utf8_decode()函数
has a PHP accelerator
 - 存在一个PHP加速器, symfony推荐使用APC
php.ini: short_open_tag set to off
 - php.ini中short_open_tag 的值为 off
php.ini: magic_quotes_gpc set to off
 - php.ini中magic_quotes_gpc 的值为 off, 关闭魔法引号
php.ini: register_globals set to off
 - php.ini中register_globals 的值为 off
php.ini: session.auto_start set to off
 - php.ini中session.auto_start 的值为 off

2009-01-08

在symfony项目中应用TinyMCE

类归于: symfony — 标签:, zhuozi @ 15:30

文章参考自Add TinyMCE to a Symfony project,为了使用方便,简单翻译成了中文,英文不好,凑合看吧,其实不看也行,粘贴代码复制就行。
这个方法在Ubuntu下测试成功。

TinyMCE是所见即所得的html编辑器(还可以叫做rich text 富文本),它可以很好的于Symfony整合在一起。然而,如果你想使用它,你需要下载第三方的源码包。这篇文章可以帮助你解决这个问题。

注意:你需要安装解压缩工具,如果你使用的是Debian和Ubuntu,你可以用apt-get的方法进行安装

/usr/bin/sudo /usr/bin/apt-get install unzip

安装TinyMCE

首先,在你项目的目录下进行配置

PROJECT_HOME=/home/sfprojects/myProject

选择你想使用的app入口(有些地方我就简写了,如果接触过symfony,我想你会明白的)

PROJECT_APP=frontend

设置你想要使用的版本

TINYMCE_VERSION=3.0.5

我们移出TinyMCE版本中的点

TINYMCE_CLEANED_VERSION=`echo $TINYMCE_VERSION | sed -e ’s/\./_/g’`

我们下载TinyMCE的源码包

/usr/bin/wget http://ovh.dl.sourceforge.net/sourceforge/tinymce/tinymce_$TINYMCE_CLEANED_VERSION.zip \
–output-document=/tmp/tinymce_$TINYMCE_VERSION.zip

解压已经下载完的文件

/usr/bin/unzip -o /tmp/tinymce_$TINYMCE_VERSION.zip -d /tmp

如果你愿意,你也可以下载多语言包

/usr/bin/wget http://services.moxiecode.com/i18n/download.aspx?format=zip\&product=tinymce \
–output-document=/tmp/tinymce_language_pack.zip

解压多语言包

/usr/bin/unzip -o /tmp/tinymce_language_pack.zip -d /tmp/tinymce/jscripts/tiny_mce

And move the TinyMCE source folder to the target emplacement in your Symfony project :
把TinyMCE源码文件复制到你的symfony项目中 ($PROJECT_HOME 替换你的目录)

/bin/cp -r /tmp/tinymce/jscripts/tiny_mce/ “$PROJECT_HOME/web/js/”

现在,我们开始配置symfony以便可以使用TinyMCE ($PROJECT_HOME 替换你的目录,$PROJECT_APP替换你的app)

/bin/sed -i -e ‘/^ .settings:/a\
rich_text_js_dir: js/tiny_mce’ “$PROJECT_HOME/apps/$PROJECT_APP/config/settings.yml”

警告:查看你的setting.yml文件以确保一切正常

/usr/bin/vim “$PROJECT_HOME/apps/$PROJECT_APP/config/settings.yml”

你现在可以删除下载的那些文件了

/bin/rm -r /tmp/tinymce
/bin/rm /tmp/tinymce_language_pack.zip
/bin/rm /tmp/tinymce_$TINYMCE_VERSION.zip

你现在可以使用下面的代码来使用TinyMCE了

<?php echo textarea_tag('name', 'default content', 'rich=true size=10x20') ?>
<?php echo textarea_tag('name', 'default content', array(
'rich' => true,
'size' => '10x20',
'tinymce_options' => 'language:"fr",theme_advanced_buttons2:"separator"',
)) ?>

第一个参数, 是name 用于在表单提交
第二个参数, 是内容
第三个参数, 是一个数组,里面包含了多种信息,可以对TinyMCE进行详细的配置
size 大小
language 语言
theme_advanced_buttons2:”separator” 代表不显示第二行工具条
如果你想第2行只显示几个按钮,你可以这样做theme_advanced_buttons2:”加粗,斜体”
(当然你要用它本身定义好的英文名字的功能)
PS:上面直接复制的代码,如果出现错误,打开原始那个英文的连接,复制,出现错误的原因是blog编辑器自动隐藏了部分空格

2009-01-07

symfony 权限访问控制(多用户访问证书)

类归于: symfony — 标签:zhuozi @ 09:39

昨天,在进行编码的时候遇到了一个权限访问的问题。
我们现在有两个系统,1.用户管理系统。2.管理员管理系统。他们都是基于同一个项目,只是权限不同。
这个有点像游戏中的工会,会长的权限很多,副会长有一些限制(比如,他不能把会长提出工会)
但是我们没有把他们放在同一个页面显示。
user 从 www.user.com登录
admin 从 www.admin.com登录
判断完登录之后出现的问题就是,我是user,登录之后可以跳过admin的登录步骤,直接访问admin里面的内容。
同理admin也可以访问user了,这样的效果是我们不想要的。
有一个解决办法是,在登录的时候给予他们证书。
$this->getUser()->addCredential(’user’); //给user 赋予证书
然后在config/security.yml文件中加入
credentials: [ user ] //只有user证书才可以访问
admin的也是同理,这样就解决刚才所说的问题了。
换句话说,这样的设置是为了解决多个不同权限的用户同时访问,如果同一用户单一权限就不用这么麻烦了。

2009-01-06

精选vim的配色

类归于: vi/vim — 标签:, , , bobhero @ 14:01

VIM配色文件很多,一GOOGLE 一大片 ,但是要找一个用着舒服不是很容易 ,就算没有挑花了眼,用时间长了也会视觉疲劳

这里精选了几十个配色文件  ,主要以暗色调为主,色彩明快的风格。打成包供大家下载,并且附上一个快速更换 color的插件

配色文件下载地址 dropbox

插件下载地址    setcolors

我比较喜欢的 dw 系统的 有点像黑客帝国

vim color

vim colors

« 较近文章早前文章 »

WordPress 所驱动