Drupal聚合器和定制输出 [英] Drupal aggregators and tailored output

查看:116
本文介绍了Drupal聚合器和定制输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有两个Drupal聚合器块,一个用于Twitter Feed,一个用于博客Feed。这些都以稍微不同的方式提供信息。



我希望博客提要显示标题,然后显示前80个字符作为预告片。



我希望Twitter Feed显示描述,没有其他的。原因是标题是整个状态的链接,而描述将其放在标准文本中,并链接其中包含的任何URL。



到目前为止,我有这个:

  function mythemename_aggregator_block_item($ item,$ feed = 0){

//目标p,div和图像并且preg_replace他们没有
$ tagstoreplace [0] ='/< p> /';
$ tagstoreplace [1] ='/<div(.*?)>(.*?)<\/div>/im';
$ tagstoreplace [2] ='/< img [^>] *> /';

//生成输出
$ output ='< p class =feed-item-title>< a href ='。check_url($ item-> )''>'。 check_plain($ item-> title)。< / a>< / p> \\\

$ output。='< p class =feed-item-description>'。 substr(preg_replace($ tagstoreplace,'',$ item-> description),0,80)。 ...< / p为H.;
return $ output;
}

哪个对我的博客Feed很好,完美无缺。然而,这显然会减少我的twitter饲料到80个字符。我已经尝试了140个字符的妥协,但是它是html和all,< a href =...>< / a> strlen()中,所以它不是真的可行,特别是如果我有一些链接在那里,因为这将使我的博客描述teaser太长。



所以,我的问题是这样的:可以根据哪个聚合器供稿来定制输出吗?



我已经想到通过在页面上获取容器div的ID来执行此操作,但它看起来像是没有进行的。理想情况下,我最终会得到如下代码:

  function mythemename_aggregator_block_item($ item,$ feed = 0){

//目标p,div和图像和preg_replace他们没有
$ tagstoreplace [0] ='/< p> /';
$ tagstoreplace [1] ='/<div(.*?)>(.*?)<\/div>/im';
$ tagstoreplace [2] ='/< img [^>] *> /';

//获取Feed类型
$ blog = // something;
$ twitter = // something;

//生成输出
if($ blog){
$ output ='< p class =feed-item-title>< a href = '。check_url($ item-> link)。'>'。 check_plain($ item-> title)。< / a>< / p> \\\

$ output。='< p class =feed-item-description>'。 substr(preg_replace($ tagstoreplace,'',$ item-> description),0,80)。 ...< / p为H.;
}
if($ twitter){$ output。='< p class =feed-item-description>'。 $ item->描述。 < / p为H.; }

return $ output;

对于这个问题的长度,感谢您的坚持!

解决方案

我已经弄清楚了。每个Feed在$ item-> fid都有一个fid。我的代码现在是:

  function mythemename_aggregator_block_item($ item,$ feed = 0){

/ / target p,div和图像,并且preg_replace没有任何
$ tagstoreplace [0] ='/< p> /';
$ tagstoreplace [1] ='/<div(.*?)>(.*?)<\/div>/im';
$ tagstoreplace [2] ='/< img [^>] *> /';

//显示项目的外部链接。
if($ item-> fid =='3'){
$ output ='< p class =feed-item-title>< a href ='check_url ($ item-> link)。'>'。 check_plain($ item-> title)。< / a>< / p> \\\

$ output。='< p class =feed-item-description>'。 substr(preg_replace($ tagstoreplace,'',$ item-> description),0,80)。 ...< / p为H.;
}
if($ item-> fid =='1'){
$ output。='< p class =feed-item-description>'。 preg_replace($ tagstoreplace,'',$ item-> description)。 < / p为H.;
}
return $ output;
}


I have two Drupal aggregator blocks on my page, one for a Twitter feed, one for a blog feed. These both supply information in slightly different ways.

I would like the blog feed to display title, then the first 80 characters of the post as a teaser.

I would like the Twitter feed to display the description and nothing else. The reason for this is that the title is a whole link to the status whereas the description puts it in standard text and links any URLs included within it.

So far, I have this:

function mythemename_aggregator_block_item($item, $feed = 0) {

  // Target p, div and images and preg_replace them with nothing
  $tagstoreplace[0] = '/<p>/';
  $tagstoreplace[1] = '/<div(.*?)>(.*?)<\/div>/im';
  $tagstoreplace[2] = '/<img[^>]*>/';

  // Generate output
  $output = '<p class="feed-item-title"><a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a></p>\n";
  $output .= '<p class="feed-item-description">' . substr(preg_replace($tagstoreplace, '', $item->description),0,80) . '...</p>';
  return $output;
}

Which is great for my blog feed, perfect. However, it will obviously cut my twitter feed down to 80 chars. I've tried the compromise of 140 chars but with it being html and all, the <a href="..."></a> is included in the strlen() so it's not really workable, especially if I have a few links in there, as it would make my blog description teaser too long.

So, finally, my question is this: Can I tailor the output depending on which aggregator feed I want to supply it to?

I've thought about doing this by getting the ID of the container div on the page, but it looks like that's a no-go. Ideally, I'll end up with code like this:

function mythemename_aggregator_block_item($item, $feed = 0) {

// Target p, div and images and preg_replace them with nothing
$tagstoreplace[0] = '/<p>/';
$tagstoreplace[1] = '/<div(.*?)>(.*?)<\/div>/im';
$tagstoreplace[2] = '/<img[^>]*>/';

// Get feed type
$blog = //something;
$twitter = //something;

// Generate output
if($blog) {
  $output = '<p class="feed-item-title"><a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a></p>\n";
  $output .= '<p class="feed-item-description">' . substr(preg_replace($tagstoreplace, '', $item->description),0,80) . '...</p>';
}
if($twitter) { $output .= '<p class="feed-item-description">' . $item->description . '</p>'; }

return $output;

Sorry about the length of this question and thanks for persevering!

解决方案

I've figured this out. Each feed has a fid at $item->fid. My code now reads:

    function mythemename_aggregator_block_item($item, $feed = 0) {

  // Target p, div and images and preg_replace them with nothing
  $tagstoreplace[0] = '/<p>/';
  $tagstoreplace[1] = '/<div(.*?)>(.*?)<\/div>/im';
  $tagstoreplace[2] = '/<img[^>]*>/';

  // Display the external link to the item.
  if($item->fid == '3') {
    $output = '<p class="feed-item-title"><a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a></p>\n";
    $output .= '<p class="feed-item-description">' . substr(preg_replace($tagstoreplace, '', $item->description),0,80) . '...</p>';
  }
  if($item->fid == '1') {
    $output .= '<p class="feed-item-description">' . preg_replace($tagstoreplace, '', $item->description) . '</p>';
  }
  return $output;
}

这篇关于Drupal聚合器和定制输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆