Alternatives to getting url of iframe - django

I'm building a website where the users to essentially "mark" things from another site -- e.g. they browse a third party's catalog, and once they hit an item they like, they somehow indicate to my site about that specific item (e.g. via the url). My initial thought was to have an iframe, a "mark" button on my own site in a little bar at the top, and the third party site in the iframe -- however, I found that it's impossible to get the url of an iframe if the user navigates away from the inital url. Is there any alternative to doing this?

You can retrieve html from another site, modify it and show to your user. Sure, you should have a grant from site owner and update your modifier for any html layout update. And you will need to resolve somehow all links from the page, including css, js and so on.
Iframe is not an option, you can't control the page in a frame in any way. That's security policy for all browsers.

(I know I'm a bit late but may be someone find it useful)
I had the same problem. I came to conclusion that only way to do that is creating proxy in PHP. And that's what I did (contents of "proxy.php" file):
<?php
$proxy = 'http://yoursite.com/proxy.php';
$host = parse_url($_GET['url'], PHP_URL_HOST);
$dir = $_SERVER[DOCUMENT_ROOT].'/cache_proxy/'.$host;
if(!is_dir($dir))
mkdir($dir);
$filepath = $dir.'/'.md5($_GET['url']);
if(is_file($filepath)){
include($filepath);
}else{
$page = file_get_contents($_GET['url']);
$page = preg_replace('/(a href)=[\'\"](http.*)[\'\"]/', '$1="'.$proxy.'?url=$2"', $page);
$page = preg_replace('/(a href)=[\'"][^http](.*)[\'"]/', '$1="'.$proxy.'?url=http://'.$host.'/$2"', $page);
$page = preg_replace('/(href|src)=[\'"][^http+](.*)[\'"]/', '$1="http://'.$host.'/$2"', $page);
file_put_contents($filepath, $page);
echo $page;
}?>
Now you can insert iframe with src="http://yoursite.com/proxy.html?url=http://othersite.com"

Related

How to show in address bar www.domain.com instead of www.domain.com/something

I have website made on opencart CMS, it is one page website, so I made redirect in home.tpl on page www.domain.com/promo (it is product page)
<?php
header("Location: /promo");
exit();
?>
Now when someone opens www.domain.com he see www.domain.com/promo.
How to make him see only www.domain.com?
Go to the index.php file and look for the router coding, it should look similar to the code below:
$action = new Action('common/home');
You will then have to change 'common/home' to the location of the page you created within Opencart.
For example: to navigate to the login page we will have to change it to 'account/login'

Extract Sharepoint 2013 wiki page HTML Source / Display wiki page without master layout in iFrame?

What I am trying to achieve is to find a way of displaying a wiki page content in a floating iFrame ( and of course keep the styling ) for a tool that I am developing for our employees. Right now the tool I made is using jQuery dialog box to display a specific document / pdf, For compatibility and usability purposes I would really like to upgrade that so it uses a wiki page instead of documents / PDFs.The problem that I am facing is that there is no really direct link to the content of a Sharepoint wiki page instead the only available direct link is the one to the page all together with all the navigation menus, option panel, user panel etc. I want to avoid using javascrip to strip away these elements. Instead I am simply trying to find out if sharepoint 2013 has some more elegant way of providing the content such as: Web service or javascript SP API.
My ideas so far:
REST Url to give the content back? I know for sure it works for lists and libraries but I couldn't find anything in the REST API About wiki page content
SP.js ? Couldn't find anything about that either
Anyways, it could be possible that I have overlooked things, or probably haven't searched hard enough. However, any help is very very welcome. If you don't know about a concrete solution I would be very happy with nice suggestions too :)
If there is nothing out of the box I will have to get to my backup plan of a jQuery solution to get the page and strip off all unnecessary content and keep the styling.
I believe you are on the right track with REST API, in Enterprise Wiki Page the content is stored in PublishingPageContent property.
The following example demonstrates how to retrieve Enterprise Wiki Page content:
var getWikiPageContent = function (webUrl,itemId,result) {
var listTitle = "Pages";
var url = webUrl + "/_api/web/lists/GetByTitle('" + listTitle + "')/items(" + itemId + ")/PublishingPageContent";
$.getJSON(url,function( data ) {
result(data.value);
});
}
Usage
getWikiPageContent('https://contoso.sharepoint.com/',1,function(pageContent){
console.log(pageContent);
});
And something for those of you who like to have more than one different examples:
var inner_content;
var page_title = "home";
$.ajax({
url: "https://mysharepoint.sharepoint.com/MyEnterpriseWikiSite/_api/web/Lists/getbytitle('Pages')/items?$filter=Title eq '" + page_title +"'",
type: "GET",
headers: {
"ACCEPT": "application/json;odata=verbose"
},
success: function (data) {
if (data.d.results[0]) {
inner_content = data.d.results[0].PublishingPageContent;
}
},
error: function(){ //Show Error here }
});
That's what did the job for me.
This example fetches the inner content of an Enterprise wiki page by Title( make sure you are not using the Name of the page, although Title and Name can be given the same string value, they are different fields in sharepoint 2013 )

How can I add a "trending topics" section to my site's homepage?

I would like to add a custom "trending topics" section to my news website at the top of the homepage. An existing example that shows precisely what I am looking for is the Daily Beast homepage.
I would like to do this with custom code or with a plugin, but not as a widget. Does anyone know how I can do this in a flexible way that can easily customize to style and look of my website.
My site is a Spanish language 24/7 news website called Yasta.pr. Thx!
it depends on how you are storing your data in your database but you can try this:
add a div section in the header of your webpage above the menu bar.
then you can dynamically add the most trending topic to it automatically when the page starts by inserting this code inside it:
<div id="*id_name">
$query = "SELECT * FROM *table_name ORDER BY *most_trending_column LIMIT 1";
mysql_select_db(*database_name, *connection);
$result = mysql_query($query) or die(mysql_error());
$data = mysql_fetch_assoc($result);
echo "<h3 id='*id_name'>" . $data['*title_column_name'] . "</h3>";
</div>
dont forget to connect to your database first.

Facebook Canvas App Page -- Can I change it to the Fan Page?

First up, apologies for my non-technical-ness. I've looked and looked for an answer to this, but had no luck.
My site has a FB App for the purposes of grabbing the auth token so people can share stuff they create on my site right to their FB wall. The app just lets the site grab the token so we don't need to ask people to login to FB over and over.
On FB we have a canvas page to go with this app, but all it does is load our webpage in an iFrame on it (and it looks sorta crappy there).
Is there a way to change the Canvas Page to our FB Fan Page? This way if people click on our "app" from their own wanderings about FB they'll be directed to a FB fan page rather than our page looking weird in FB.
Again, I apologize if this question is way simple. I'm new. If someone has an answer for me and could use puppets to explain-- that'd probably help.
Thanks so mcuh!
This is an obnoxious method but you can redirect the visitors to your Facebook Page when your Canvas Page is loading by checking the URL.
First you have a function that gets the URL of your Canvas Page.
function checkPage()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on")
{
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
{
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else
{
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
Then you check if the URL contains "fb_source" which appears in every Canvas Page, if it does then you redirect them to your desired location.
$currentUrl = checkPage();
if(strpos($currentUrl,'fb_source') !== false)
{
<script type="text/javascript">
top.location.href = "URL HERE";
</script>
}

How can my Iframe content inherit the hosting domains CSS?

Here is the situation:
I have a webservice that returns a form.
This form is then used by many other sites in an iFrame element.
I need the form to "wear" the hosting site's background, color, or in other words CSS (but i will settle for background and logo if this is easier).
My webservice and the other sites are not on the same domain.
I have full control over my webservice and i can define general requirements for all sites.
What is the best way to handle this?
There are several ways to accomplish this:
1 - Pass in a stylesheet as a parameter into the iframe:
Pass in a CSS stylesheet as a query parameter in the src attribute of the iframe. This is perhaps the easiest method, and it gives the owner of that stylesheet more control over how the form looks on that person's site.
<body>
<!-- This is the client's website -->
<!-- This is your form -->
<iframe src="http://example.com/form/abc/?css=http://example.com/file/formStyle.css" />
2 - Pass in the color and logo into the iframe:
This is the same basic idea as in the first example, except you're not referencing an external stylesheet:
<iframe
src="http://example.com/form/abc/?color=#AAAAAA&logo=http://example.com/logo.png" />
3 - Use PostMessage:
Another option is to use the postMessage API. With postMessage, you can pass a message from one context to another, across domains. Thus, the client page could pass the background color to the iframe page, and this could be reused to pass other types of information and data as well.
Iframe code:
// register to listen for postMessage events
window.addEventListener("message", changeBackground, false);
// this is the callback handler to process the event
function changeBackground(event)
{
// make sure the code you put on the client's site is secure. You are responsible
// for making sure only YOU have cross domain access to his/her site.
// NOTE: example.org:8080 is the client's site
if (event.origin !== "http://example.org:8080")
return;
// event.data could contain "#AAAAAA" for instance
document.body.style.backgroundColor = event.data;
// do other stuff
}
}
Top Level Client Page:
// pass the string "#AAAAAA" to the iframe page, where the changeBackground
// function will change the color
// targetOrigin is the URL of the client's site
document.getElementById("theIframe").contentWindow.postMessage("#AAAAAA", targetOrigin);
This solution only works in modern browsers, including IE8, FF3.6+, Chrome 13+, Safari 5+, etc. See the Mozilla Developer Center for more information on HTML5 postMessage.
How to pull the CSS parameter from the query string?
Use the gup function in the iframe page to get the value of the CSS parameter:
function gup(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
Afterwards, you can then use it to create a link CSS tag:
// get url parameter from iframe src:
var cssPath = gup("cssPath");
// create link and append to head
var linkElem = document.createElement("link");
linkElem.setAttribute("href", cssPath);
linkElem.setAttribute("rel","stylesheet");
document.getElementsByTagName("head")[0].appendChild(link);
OR
var color = gup("color");
document.body.setAttribute("style","background-color:" + color);