need to replace a link in content pulled with file_get_contents & base url - preg-replace

I am using file_get_contents to pull content from an external page. I then use a base tag to fix all broken links and paths. This works perfectly, However, I have javascript tabs in that page with anchor tags that look like this href="#". Problem is, the tab urls are also affected by the base url tag. When you click on it, it opens the tab but also sends you right back to the external page. Can I use a preg_replace to replace all href="#" with href="http://domain.com/page.php#" to fix the tab links? How will I add it to this code of mine?
<?php
$url = 'http://www.externaldomain.com';
$data = file_get_contents($url);
$data = '<head><base href='.$url.' target="_blank" /></head>'.$data;
echo $data;
?>

Try something like this:
$data = preg_replace('/\bhref="#"/', 'href="http://domain.com/page.php#"', $data);
Just replace the href="#" attributes with your desired ones.

Related

Change the Browser title

I am using links to display PDF files. I wish to show the PDF in a new tab so I add target="_blank". This works fine. A new tab is opened but I wish to change the title of the tab.
The link redirects me to this controller code as follows:-
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
#readfile($file);
The pdf is displayed correctly but there is no view script so I have no control via the script. Is there a header("Browser title: ???") I can use?
TIA Effy
For this problem, I use this trick:
I use a simple html page with an iframe like this:
<html>
<head>
<title>Your PDF Title</title>
<link type="image/x-icon" rel="icon" href="">
</head>
<body>
<iframe src="/module/controller/action/param..." id="ifrm" name="ifrm" width="100%" height="100%">
</iframe>
</body>
</html>
The iframe contains the PDF and the page has title.
Of course, you can use javascript to have a dynamic title
The internal pdfviewer in Firefox seems to fetch the title of the document from the metadata in the pdf.
With for instance Zend_Pdf this metadata can be manipulated.
$title = 'My custom title';
$pdf = Zend_Pdf::load($filepath);
$metadata = $pdf->getMetadata();
$metadataDOM = new DOMDocument();
$metadataDOM->loadXML($metadata);
$domTitle = $metadataDOM->getElementsByTagName('title')->item(0);
$domTitle->nodeValue = $title;
$pdf->setMetadata($metadataDOM->saveXML());
//maybe old style document info:
$pdf->properties['Title'] = $title;//this didn't work for me
echo $pdf->render();
I'm no DOM manipulation expert, but this worked for me with a file created with Illustrator CS5. Freely based on the Zend Framework Documentation. You might need to do some error checking along the way.

Magnific Popup - Popup disappearing on click

I've just recently implemented the 'Magnific Popup' and the popup comes up fine, however when I click an input box the entire popup disappears back to the parent page. On the examples shown on the plugin website, the entire dialog box is clickable until you click outside of that box.
I'm hoping its just something extremely simple I've missed, but it's still doing my head in.
I really appreciate any help I can get!
Thanks :)
If you're using "ajax" content type, you need to make sure that you've got only one root node.
http://dimsemenov.com/plugins/magnific-popup/documentation.html#ajax_type
E.g., this is correct contents of ajax file:
<div>
html content
<script src="something.js"></script>
</div>
Incorrect:
<script src="something.js"></script>
<div>
html content
</div>
Incorrect:
<div>
html content
</div>
<div>Another content</div>
Also make sure that closeOnContentClick is set to false http://dimsemenov.com/plugins/magnific-popup/documentation.html#closeoncontentclick
If, for whatever reason, you can't change the contents of ajax file, you may parse content in parseAjax callback, like described here (so the mfpResponse.data contains only one root node).
I can't reply yet (too low rep..) so adding it like this:
seems that this also counts for type: 'inline'. Safe to always wrap content by a div..
$.magnificPopup.open({
items: {
src: '<div>'+ html +'</div>'
},
type: 'inline',
closeOnContentClick: false
}, 0);
I had the same error.
Turned out to be a dumb mistake from my side, i had the same class on my opener and my inline div.
Open
<div id="popup" class="dialog mfp-hide"></div>
Of course they needed to be different classes like so:
Open
<div id="popup" class="dialog-box mfp-hide"></div>
Dmitry explains the problem here https://github.com/dimsemenov/Magnific-Popup/issues/34
Add modal:true in the magnificPopup:
$('.your_class').magnificPopup({
type: 'ajax',
modal:true
});

Show/hide Iframe

I am using wordpress for my website and I am trying to set up my pages so that a user has to click a button to view the content. Yes, very simple with show/hide etc but the button I Want the user to click is this http://www.facebook.com/plugins/like.php
To display that in my page i need to use an iframe which is where it gets tricky. I have set up the show/hide code so that when a user clicks the like button (or anywhere in the iframe) it will display the content. But, no such luck!
This is my code
<div id="imagebox" style="display:none;"><?php $image = wp_get_attachment_image_src(get_field('image'), 'full'); ?>
<img src="<?php echo $image[0]; ?>" alt="<?php get_the_title(get_field('image')) ?>" /> </div>
<div onclick="ShowDiv()"><iframe src="http://www.facebook.com/plugins/like.php? href=http://www.facebook.com/BrandBang&" allowTransparency="true">
</iframe></div>
<script language="javascript">
function ShowDiv()
{
document.getElementById("imagebox").style.display = '';
}
</script>
I know that it is hard to use iframes to do what I am trying to do, but i am a total newbie when it comes to this stuff. Any help would be great!
Have tried giving your div an id="imagebox"?
EDIT:
This was already answered here.
But, I didn't realize at first sight that you're loading something in the iframe that is not coming from your own domain, so you're going to fall in a cross site scripting event, which is not allowed.
Afaik, you have to redesign some way your implementation.
For instance, you could retrieve the generated html from facebook using curl and then outputting in your own div. Something like that should work.

jqtouch go back after form submiting

I'm using jQtouch to build a page where the user can enter a kind of an ID and
get information (exam result) for this ID.
Because I take the results from the server, I used a form in the first page
with a text field and a submit button, and the action of this form send the user to the next page. Or at least, supposed to...
The problem is that also I'm being transferred to page with the results, and see the results properly, the Back button do nothing! BTW, in the address bar (above) I still see the name of the first page.
How can I go back to the "form" page? Thanks
<div class="current" id="byUserId">
<div class="toolbar">
<a class="back" id="goBack" > Back</a>
<h1> Exam Results</h1>
</div> ...
where the id="goBack" has a javascript:
$(function() {
$('#goBack').click(function() {
location.href = "enterId.jsp";
});
});
Using the regular back doesn;t work either:
<a class="back" href="#"> Back</a>
I now this is pretty late, but I had a similar frustrations and finally figured it out. The problem is that jQTouch intercepts all AJAX and form submit commands and safely send them itself. This isn't a problem except for when it's expecting some sort of callback, and there isn't one. In my case, I wanted to submit a form without a callback. To do this, look in the jqtouch.js library (around line 434) and comment out the following line:
if (href != '#') {
$.ajax({
url: href,
data: settings.data,
type: settings.method,
success: function (data) {
**// var firstPage = insertPages(data, settings.animation);**
This basically just tells jQTouch to submit the AJAX call but do nothing afterwards (don't change div's, don't show any callbacks and don't do any animations). Hope this helps.

Facebook sharer,share image

I found a lot of posts, but none of them help me.
I want to share an image that is not visible. Another issue is, when I click share, all images from the page are available for sharing. How can I fix it so that only images that I want to share are visible for sharing?
I have read this Facebook Open Graph Protocol, but that didn't help me.
Here is my function to create a share button :
function WP_fb_sharer($post) {
$link = js_escape(get_permalink($post->ID));
$button = '<a name="fb_share" type="box_count" share_url="' . $link . '" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>';
$button = '
<div style="float: left; margin-left: 10px; margin-bottom: 4px;">
' . $button . '
</div>';
return $button;
}
Is there any image size limit for Facebook?
Have a read of this answer. Facebook was recommending the use of Like Plugin instead of the Share button, and I'm just checking and the old share document is now redirecting to the Like Plugin!
So just use the Like Plugin instead.
EDIT:
If you need to attached an image, just use the og:image meta tag and for videos use og:video. Check the "Attaching Audio and Video Data" section.