Display Cross-domain feed RSS in Wordpress site - ajax

I need to display cross-domain feeds-rss (XML format)in my site, but i get a error because ajax cross-domain call are not allowed. I've been told about json-p...anyone knows how to use or have some good tutorial?
Thanks

the simplest way is just to create an widget for wordpress or download some kind of like your requirement.
Because json-p load data in JSON format if you want to get data from JSON format then the given link will help you :
getJSON
ajax
or you can access the rss feed with php like given example :
$xml = 'http://blog.webtech11.com/feed';
$doc = new DOMDocument();
$doc->load($xml);
$item = $doc->getElementsByTagName('item');
//$data = array();
for($i=0; $i<=3; $i++){
$title = $item->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$link = $item->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
echo '<h2>' . $title . '</h2>';
}
in this example i access latest 4 blog entries..
hope this will help you

Related

Dinamyc web scraping with goutte and Laravel

Is there a way to do a web scraping without define the HTML tags?
I have my code:
$crawler = $client->request('GET', 'https://www.cnnchile.com/opinion/');
$result = $crawler->filter('.inner-item__content > h2')->each(function ($node) {
return $node->text();
});
but how you can see I alaways define the HTML tag where it's the content, it's there a way to get in general the data? I mean without define that
Thanks
You want just the page content? Then use body as the filter tag.

How to display correct link in CI anchor

I have a form with upload file option.
I get the file_path on $data uploaded by user. Now I want to use this
file_path to be the link in my anchor tag.
My problem is i can't get the correct link. it seems like that the base URL was being included in the link showed in the lower left of the screen.
I also read some post here to add "http://" before the link. but the link appeared was like this
c/xampp/htdocs/.../uploads/products/filename.pdf
no colon.
any idea on how can I access my uploaded file be access via link.
Thanks
paste this line in your /applications/config/config.php just right before
$config['base_url'] = "";
and change this to
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://');
$root = $protocol.$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
This approach makes your base_url() function returns the current host or url you are in. Even if you upload this to any server it will always return the exact url of your website.
Then you use it like this
<?= base_url('uploads/products/filename.pdf'); ?>
That's all you have to do. Hope this helps!

How to redirect WORDPRESS hotlinked image ( for exp : Image.jpg) to post/page where it is?

Recently google change image search and as a result most of the traffic click over view original image and it send them to direct image file.
I have changed my .htaccess and stop all hot linking and redirect to my homepage if they click over image file.
Recently I've also tried if it is possible to redirect to post or page where image is.
By the following code
<?php
require('../wp-blog-header.php');
$imageURL = strip_tags( $_GET['id'] );
if imageURL!== "") {
$query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment'AND post_parent > '0' AND guid = '$imageURL'";
$linkedImage = $wpdb-get_row($query);
$attachmentUrl = get_attachment_link($linkedImage->ID);
if($attachmentUrl !== "" && !is_numeric(stripos($attachmentUrl, "attachment_id=0"))) {
header("HTTP/1.1 302 Found");
header("Location: ". $attachmentUrl);
exit;
}
}
$newUrl = get_site_url() . "/image-not-found";
header("HTTP/1.0 404 Not Found");
header("Location: " . $newUrl);
exit;
?>
But it redirect to http://www.mydomain.com/?attachment_id=
id is nil or can't fetch the proper id
My website in Wordpress CMS version 3.5.1
can anyone help how to redirect to proper attachment page for .jpg file direct request.
Thanks in advance
Your code would only work if there was an ID parameter on the requested URL that would be an exact match with the image URL, for instance http://www.example.com/?id=http://www.example.com/uploads/Some-Image.jpg
Is this the case? Even so, you shouldn't use id since it's a reserved parameter for other things in WP. In your .htaccess, you should redirect http://www.example.com/uploads/Some-Image.jpg to, for example, http://www.example.com/?image_redirect=http://www.example.com/uploads/Some-Image.jpg. Then use $imageURL = $_GET['image_redirect'].
Other notes: strip_tags doesn't make a string safe to use as a SQL query. In WordPress, you have esc_sql($string) for that. Also, you should rather use if ( $imageUrl != '' ), not with !==. And there's an error on line 5, it should say $wpdb->get_row, you currently have a minus sign. I assume these are typos. And finally, you shouldn't use Location: header with a status code 404.

html is pass using jquery ajax but pdf is not generating in mpdf for codeigniter

I want to create a PDF in codeigniter using mPDF. My html is passed to the controller using jQuery AJAX. Data is coming to the $html But it is not working. It works fine when html is hard coded. Can any one help me please?
public function pdf($paper='A4')
{
$html = '';
$html = $this->input->POST('content');
$this->load->library('mpdf54/mpdf');
$CI->mpdf = new mPDF('utf-8',$paper);
$mpdf->debug = true;
$this->mpdf->WriteHTML($html);
$this->mpdf->Output();
exit;
}
Try grabbing all the POST vars by using
$html = $this->input->POST();
then echo those out to yourself before moving farther to be sure they are getting set.
public function pdf($paper='A4')
{
print_r($this->input->POST());
return;
}
This of course is only for testing but might help you to see why your $html var isn't getting set. Try that out and give us the results.

Rewriting URL's in codeigniter with url_title()?

I am rewriting my website with codeigniter and have something I want to do but not sure it is possible.
I have a gallery on my site powered by the Flickr API. Here is an example of the code I use to display the Landscape pictures:
<?php foreach ($landscapes->photoset->photo as $l->photoset->photo) : ?>
<a href="<?=$l->photoset->photo->farm?>/<?=$l->photoset->photo->server?>/<?=$l->photoset->photo->id?>/<?=$l->photoset->photo->secret?>/<?=$l->photoset->photo->title?>">
<img class="f_thumb" src="<?=$l->photoset->photo->farm?>.static.flickr.com/<?=$l->photoset->photo->server?>/<?=$l->photoset->photo->id ?>_<?=$l->photoset->photo->secret ?>_s.jpg" title="<?=$l->photoset->photo->title?>" alt="<?=$l->photoset->photo->title?>" />
</a>
<?php endforeach; ?>
As you can see when a user clicks on a picture I pass over the Farm, Server, ID, Secret and Title elements using URI segments and build the page in the controller using
$data['farm'] = $this->uri->segment(3);
$data['server'] = $this->uri->segment(4);
$data['id'] = $this->uri->segment(5);
$data['secret'] = $this->uri->segment(6);
$data['title'] = $this->uri->segment(7);
Everything works and is fine, but the URL’s are a tad long. Example:
http://localhost:8888/wip/index.php/gallery/focus/3/2682/4368875046/e8f97f61d9/Old_Mill_House_in_Donegal
Is there a way to rewrite the URL so its more like:
http://localhost:8888/wip/index.php/gallery/focus/Old_Mill_House_in_Donegal
I was looking at using:
$url_title = $this->uri->segment(7);
$url_title = url_title($url_title, 'underscore', TRUE);
But I can’t seem to be able to get it to work. Any ideas?
Are the links linking internally? Or are they linking to flickr? If it's internally, I'd suppose you could pass all the requisite information via POST. If it's to flickr, I don't think there is a way you can control how they want requests to come in for a specific item.
What's the endgame/purpose of all that extra info (secret, server, etc)?

Resources