urle由链接模块或pagepeeker格式化程序在drupal 7中断开 [英] url cutoff by link module or pagepeeker formatter issue in drupal 7
问题描述
要重述 -
Google Alert feed - > Link module field - > pagepeeker screenshot formatter
这里是错误
Google提醒的网址是
当链接显示时,我得到:
http://pagepeeker.com/thumbs.php?size=m& URL = www.google.co m / url
它将URL链接到url,而不是其余的url。
以下是pagepeeker用于解析URL的代码?
<?php
函数_pagepeeker_format_url($ url,$ domain_only = FALSE){
if(filter_var($ url,FILTER_VALIDATE_URL)=== FALSE){
return FALSE;
}
//尝试解析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。 $端口;
}
else {
return $ host。 $ port。 $路径。 $查询。 $片段;
}
}
return FALSE;
}
这可能是问题吗?
请让我知道我可以以任何方式澄清。
我需要的是整个网址被处理,而不仅仅是截断的
谢谢! / p>
我在SO或drupal SO页面看到一个非常相似的问题,但找不到,所以我在写我的方式在这里回答。
<?php
函数_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 /最新-新阿纳斯塔西-贝弗利丘睫毛天才/&安培; CT = GA&安培; CAD = CAcQARgAIAEoATAAOABA3t-Y_gRIAlgBYgVlbi1VUw&安培; CD = F7w9TwL-6ao&安培; USG = AFQjCNG2rbJCENvRR2_k6pL9RntjP66Rvg';
//现在我们使用parse_url将url拆分为一个包含url部分的数组。
$ parsed_url = parse_url($ url);
// $ parsed_url ['query']是'sa = X& q = http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-flash -genius /& ct = ga& cad = CAcQARgAIAEoATAAOABA3t-Y_gRIAlgBYgVlbi1VUw& cd = F7w9TwL-6ao& usg = AFQjCNG2rbJCENvRR2_k6pL9RntjP66Rvg'
//;也可以用来分隔参数。但&是通常使用它。
$ queryParts = explode('&',$ parsed_url ['query']);
$ params = array();
foreach($ queryParts as $ param){
$ item = explode('=',$ param);
// sa = X等
$ params [$ item [0]] = $ item [1];
}
// $ params现在是一个包含查询部分的数组。
// $ params ['sa'] ='X',q ='http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-flash -genius'等
if($ domain_only){
$ new_url_parsts = parse_url($ params ['q']);
return $ new_url_parts ['host'];
}
else {
return $ params ['q'];
}
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
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 !
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'];
}
这篇关于urle由链接模块或pagepeeker格式化程序在drupal 7中断开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!