dtvhqlc57127 2012-05-31 16:37
浏览 62
已采纳

url截断链接模块或pagepeeker格式化程序问题在drupal 7中

I have drupal 7 question that may involve some php help. I have created an rss feed from google alerts that I am mapping into fields. I have had success mapping into all the fields except the link module field where I have put a field formatter that creates a pagepeeker screenshot by attaching the appropriate url server query to the feeds url. Feeds is doing its job by taking the Item URL (link) and putting it into the field correctly. I am having an issue with with either pagepeeker or link module because below keeps happening.

To recap-

Google Alert feed -> Link module field -> pagepeeker screenshot formatter

here's the error

The url that google alerts provides is

http://www.google.com/url?sa=X&q=http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius/&ct=ga&cad=CAcQARgAIAEoATAAOABA3t-Y_gRIAlgBYgVlbi1VUw&cd=F7w9TwL-6ao&usg=AFQjCNG2rbJCENvRR2_k6pL9RntjP66Rvg

When the link is displayed I get :

http://pagepeeker.com/thumbs.php?size=m&url=www.google.com/url

Its cutting the url at url and not getting the rest of the url.

Here's the code that pagepeeker uses to parse the url ?

<?php

function _pagepeeker_format_url($url, $domain_only = FALSE) {
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
return FALSE;
}

// try to parse the url
$parsed_url = parse_url($url);
if (!empty($parsed_url)) {
  $host = (!empty($parsed_url['host'])) ? $parsed_url['host'] : '';
  $port = (!empty($parsed_url['port'])) ? ':' . $parsed_url['port'] : '';
  $path = (!empty($parsed_url['path'])) ? $parsed_url['path'] : '';
  $query = (!empty($parsed_url['query'])) ? '?' . $parsed_url['query'] : '';
  $fragment = (!empty($parsed_url['fragment'])) ? '#' . $parsed_url['fragment'] : '';

if ($domain_only) {
  return $host . $port;
}
else {
  return $host . $port . $path . $query . $fragment;
}
}

return FALSE;
}

Could this be the problem?

Please let me know I can clarify in any way.

What I need is for the entire url to get processed and not just the truncated one

Thanks !

  • 写回答

1条回答 默认 最新

  • doudai8783 2012-05-31 22:24
    关注

    I have seen a very similar question here at SO or drupal SO page but couldn't find it so I'm writing "my way" answer again here.

    <?php
    
    
    function _pagepeeker_format_url($url, $domain_only = FALSE) {
    if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
    return FALSE;
    }
    
    //$url = 'http://www.google.com/url?sa=X&q=http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius/&ct=ga&cad=CAcQARgAIAEoATAAOABA3t-Y_gRIAlgBYgVlbi1VUw&cd=F7w9TwL-6ao&usg=AFQjCNG2rbJCENvRR2_k6pL9RntjP66Rvg';
    // Now we use parse_url to split the url to an array with url parts.
    $parsed_url = parse_url($url);
    // $parsed_url['query'] is 'sa=X&q=http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius/&ct=ga&cad=CAcQARgAIAEoATAAOABA3t-Y_gRIAlgBYgVlbi1VUw&cd=F7w9TwL-6ao&usg=AFQjCNG2rbJCENvRR2_k6pL9RntjP66Rvg'
    // ";" can also be used to separate params. But & is the usual one so using it.
    $queryParts = explode('&', $parsed_url['query']);
    
        $params = array();
        foreach ($queryParts as $param) {
            $item = explode('=', $param);
            // sa = X, etc.
            $params[$item[0]] = $item[1];
        }
    //$params is now an array with query parts.
    // $params['sa'] = 'X' , q = 'http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius', etc.
    
    if ($domain_only){
    $new_url_parsts = parse_url($params['q']);
    return $new_url_parts['host'];
    }
    else{
    return $params['q'];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的