item
* The syndication feed channel data is contained in $post->feed
* The subscription data is contained in $post->link
* @return string The new content to give the syndicated item.
*/
function ada_fwp_add_source_to_content ($content, $post) {
$googleNewsLinkPattern = '/https:\/\/news\.google\.com\/rss\/articles\/(.*?)/';
if (!preg_match_all($googleNewsLinkPattern, $content, $matches)) {
$content;
}
else {
$dom = new DOMDocument();
//$dom->loadHTML($content);
@$dom->loadHTML($content);
// Find the element
$aElement = $dom->getElementsByTagName('a')->item(0);
// Get the href attribute value
$href = $aElement->getAttribute('href');
// Output the href value
$urlParts = parse_url($href);
// Extract the path from the URL.
$path = $urlParts['path'];
// Use basename() to get the part after the last '/'.
$partAfterLastSlash = basename($path);
$decodedUrl = urldecode($partAfterLastSlash);
// Now, you can decode it from base64.
$decodedData = base64_decode($decodedUrl);
$decodedData = preg_replace('/^.*?(https?:\/\/)/', '$1', $decodedData);
$decodedData = preg_replace('/[^a-zA-Z0-9-_.~?&=:%\/]/', '', $decodedData);
$pattern = '/^(.*?https:\/\/.*?)(https:\/\/.*)$/';
$filtered_url = preg_replace($pattern, '$1', $decodedData);
$syndicatedContent = str_replace($href,$filtered_url, $content);
$content = $syndicatedContent;
}
// Send it back
return $content;
}