Archive for the ‘drupal’ category

drupal anywhere 8: 用代码修改编辑任意文章:node_save

April 25th, 2010

drupal anywhere 6 时介绍过强大的一个API叫node_load ,他是读,那么修改和保存呢,而且在drupal anywhere 7时介绍过chdir在任意文件夹下调用drupal的全部组件。这样的方法你会发现我经常用到。

今天介绍一下用代码去修改文章,就是drupal所谓的node了,同node_load一样,你需要先确定一个node_id:例如1吧。详细的使用

1.在根目录建立文件夹叫test,以后所有的测试文件都放里面

2.在这个文件夹上,使用drupal anywhere 7时介绍过chdir , 建立文件node_load.php

3.文件开始:

<?php
chdir(‘/home2/crawgirl/public_html/feedme/’);
require_once ‘./includes/bootstrap.inc’;
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

//////////////////////

$nid=1;

$node=node_load($nid);//读取

print_r($node);//了解一下这个node的结构,如果你不记得了

//////////////////////

$body=$node->body;//读取内容,准备修改

$body=”我想修改的内容放这里,或者使用正则表达式”;

$node->body=$body;//修改完后,给body重新赋值

node_save($node);//保存

$node=NULL;//养成习惯,不用的对象马上清空了

/////////////////////

?>

就是如此简单,用同样的方法,能修改node的任何内容。注意了,如果你打开了drupal 的cache,那么可能页面还没改过来,你需要打开这个node的编辑页面才行。

——————————————

drupal 7 : node_save 的改变

Share

php function:真正的并发请求,curl_multi,PHP多线程并发

April 25th, 2010

这是一个自己写的函数

由于blog位置显示的原因,请点击code的原文

http://www.trackself.com/code/curl_multi.html

关键在于GOOGLE一下:$mh = curl_multi_init();   以curl_multi为关键词则可

程序的好处在于我将日常的需要都写在里面了,而且节约CPU和内存

Share

drupal anywhere 7 : chdir , 整理好drupal anywhere的文件

April 25th, 2010

drupal anywhere 6 的时候说过,建立的文件要与index.php同一目录下,这样根目录不就很多php文件罗?

你也许会想,直接将include的地址改为../不就行了?

就是改为:require_once ‘../includes/bootstrap.inc’; 这样的形式

执行一下试试,结果报错:
Warning: require_once(./includes/cache.inc) [function.require-once]: failed to open stream: No such file or directory in /home2/crawgirl/public_html/feedme/includes/bootstrap.inc on line 1009

Fatal error: require_once() [function.require]: Failed opening required ‘./includes/cache.inc’ (include_path=’.:/usr/lib64/php’) in /home2/crawgirl/public_html/feedme/includes/bootstrap.inc on line 1009

有下面的解决办法:

1.在drupal 的根目录下建立文件夹:anywhere

2.在此文件夹上建立文件: nodeload.php

3.输入代码:

<?php

chdir(‘/home2/crawgirl/public_html/feedme/’);
require_once ‘./includes/bootstrap.inc’;
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
print_r(node_load(1));

?>

这样做了后,事情变得非常有趣,例如我们在网上看到一个不错的PHP函数或者程序或者类,我们可以直接下载下来与drupal对接了,只要放在drupal的任何新建的一个子文件夹上就OK了,然后在需要调用它的页面,增加上面的几行……

Share

drupal performance:kill taxonomy_get_term and reduce a lot selects

April 25th, 2010

P: The ideas is exactly same of killing drupal_lookup_path and the function is just a little change , so if you want to have a clear explaination , go to http://www.trackself.com/archives/447.html

1.locate modules/taxonomy/taxonomy.module  ,  function  taxonomy_get_term

2.change it to :http://www.trackself.com/code/taxonomy_get_term.txt

there is a Chinese version of this post and should give you a more clear view , sorry for my poor english.

Share

drupal performace:kill drupal_lookup_path and reduce a lot select

April 24th, 2010

p:This is a translated post of “http://www.trackself.com/archives/432.html” before i post it to drupal.org.

Because of my poor english  , i will cut the crap.

using this method will reduce my site  form 77 selects  to 43 ,and copy the same method to taxonomy_get_term , will then reduce from 43 to 28 ,  if you’re using pathauto and path and a lot terms , it’s a lot more useful.

1.after using cacherouter and trun on drupal normal cache ,  my site  still have  77 select per view when login.

2.using devel , i found a lot of drupal_lookup_path and taxonomy_get_term

3.learning from http://drupal.org/node/192448 and http://www.lullabot.com/articles/a_beginners_guide_to_caching_data ,  i use  “PHP static “  plus “drupal cache_set” to reduce the selects.

4.locate include/path.inc , found :

$alias = db_result(db_query(.....", $path, $path_language));

change it to

http://www.trackself.com/code/drupal_get_path.txt

you should read the Chinese version here if you want to know clearer.

Share
« 1 ... 12 13 14 15 16 17 18 19 20 21 22 23 »