PHP > Unable to embed youtube video by function - class

I don't know what's wrong with my embed script, to my logic it should properly embed the video in the frame, but it loads a framed view of www.youtube.com instead of my video video.
There are 2 files in a single directory:
ClassMedia.php:
<?php
class Media {
public function embedYT($code){
echo "<iframe width='560' height='349' src='http://www.youtube.com/embed/".$code." frameborder='0' allowfullscreen></iframe>";
}}
Demo.php:
<?php include "classMedia.php"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Demo</title>
</head>
<body>
<?php
$media = new Media();
$code = "XSGBVzeBUbk";
$media-> embedYT($code);
?>
</body>
</html>

You're missing a single quote right after src='http://www.youtube.com/embed/".$code.", you want this:
echo "<iframe width='560' height='349' src='http://www.youtube.com/embed/".$code."' frameborder='0' allowfullscreen></iframe>";
Note the added single quote.
YouTube ends up seeing a bad URL (http://www.youtube.com/embed/$code frameborder= where $code is the real code) and hands you the homepage instead of what you think you were asking for.

Related

Passing variable to layout template in Mojolicious

I am trying to set the refresh rate of a status page using a stash variable
So I have the following code in the controller to render the page:
my $refreshrate = 10;
$self->stash( refreshrate => $refreshrate);
$self->render();
in the html template I have:
% layout 'refreshLayout', title => 'A title';
% content_for refresh => begin
% end
<div>....body content .../<div>
and in the layout template I have:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
<meta charset="UTF-8"/>
<meta http-equiv="refresh" content="<%= refreshrate %>"/>
.....
<title><%= title %></title>
</head>
<body><%= content %></body>
</html>
I always end up with a page rendered with no value in the content attribute of the refresh meta tag.
It looks like the refreshrate replacement does not work.
However both the content and title replacements do work.
So what am I doing wrong here?
And while we are here, why in the layout template do we do use <%= content %> (and not $content)
While in the template of the regular page we use the more logical <%= $variable %>
How does the replacement work in the layout template versus the replacement in the template of the main page?
The stash values appear as perl variables in your templates. (title is special as it's also a default helper function).
If you want to pass the stash value for refreshrate to the layout, you have to add it to your layout() args:
use Mojolicious::Lite;
get '/' => sub {
my $c = shift;
$c->stash (refreshrate => 10),
$c->render(template => 'foo/bar')};
app->start;
__DATA__
## foo/bar.html.ep
% layout 'mylayout', title => 'Hi there',refreshrate => $refreshrate;
Hello World!
## layouts/mylayout.html.ep
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
<meta charset="UTF-8"/>
<meta http-equiv="refresh" content="<%= $refreshrate %>"/>
<title><%= $title %></title></head>
<body><%= content %></body>
</html>
See Layouts in Rendering doc

TYPO3 - Redirect if page disabled

I use TYPO3 6.2.
I'm working on a very special page which is not ready for public but I discovered that Google already found it and indexed it. This a a real problem because the page has to be available only for the 2018 summer.
If I disable the page in the back-end then I can still work on it and the page is no longer available for other people, but the URL generates a 404 Not Found.
-> How to generate a 301 redirect to the homepage instead ?
localconf.php or installtool settings:
#have to be 1
$TYPO3_CONF_VARS['SYS']['curlUse'] = 1;
#have to be empty
$TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT']['init']['postVarSet_failureMode'] = '';
#logical part
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = '/404.html';
$TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'] = 'HTTP/1.1 301 Moved Permanently';
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = 'USER_FUNCTION:fileadmin/scripts/pagenotfound.php:user_pagenotfound->pagenotfound';
content of user function (fileadmin/scripts/pagenotfound.php)
<?php
define('REDIRECTPAGE', '/');
class user_pagenotfound {
function pagenotfound($param, $conf) {
$server_name = $_SERVER;
header("HTTP/1.0 301 Moved Permanently");
print '<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>301 Moved Permanently</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function doRedirect() {
window.location="http://'.$server_name.REDIRECTPAGE.'";
}
doRedirect();
// -->
</script>
</head>
<body style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;text-align:center;";>
<div style="font-size:20px;text-align:center">The page you have requested cannot be found</div>
<div>If you are not automaticly redirected in 3 seconds please click here: <br />
<br /><a href='.$server_name.'>'.$server_name.'</a></div>
</body>
</html>';
exit;
}
}
?>
Source from here: http://www.typo3forum.net/discussion/34942/301-moved-permanently-statt-404-page-not-found by smartlife
And: http://blog.marit.ag/2009/03/20/korrektes-404-error-handling-mit-typo3/

How to add meta tags from widget in Orchard?

I'm trying to add some meta tags from widget (/views/parts/ folder) that gets data from database outside of orchard. I need to put them to head section, and frankly I got no idea how to achieve that.
I tried:
using (Script.Head())
{
<meta property="description" content="ABC">
}
SetMeta("ABC", "description");
But none of these work :-(
Edit: our document.cshtml code:
#using Orchard.Mvc.Html;
#using Orchard.UI.Resources;
#{
RegisterLink(new LinkEntry { Type = "image/x-icon", Rel = "shortcut icon", Href = Url.Content("~/modules/orchard.themes/Content/orchard.ico") });
string title = Convert.ToString(Model.Title);
string siteName = Convert.ToString(WorkContext.CurrentSite.SiteName);
string classForPage = "static " + Html.ClassForPage();
}
<!DOCTYPE html>
<!--[if lt IE 7]>
<html lang="#WorkContext.CurrentCulture" class="#classForPage no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html lang="#WorkContext.CurrentCulture" class="#classForPage no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html lang="#WorkContext.CurrentCulture" class="#classForPage no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html lang="#WorkContext.CurrentCulture" class="#classForPage no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<title>#Html.Title(title, siteName)</title>
<meta name="viewport" content="width=device-width">
#{
Display(Model.Head);
}
<meta property="og:title" content="#Layout.Title - #Convert.ToString(WorkContext.CurrentSite.SiteName)">
<meta property="og:site_name" content="#Convert.ToString(WorkContext.CurrentSite.SiteName)">
<meta property="og:url" content="#Request.Url">
<meta property="og:type" content="article">
<script>(function(d){d.className="dyn"+d.className.substring(6,d.className.length);})(document.documentElement);</script>
</head>
<body>
#Display(Model.Body)
#Display(Model.Tail)
</body>
</html>
Does anybody know how to achieve that?
IResourceManager provides the necessary methods.
For use it in view:
var resourceManager = WorkContext.Resolve<Orchard.UI.Resources.IResourceManager>();
resourceManager.SetMeta(new Orchard.UI.Resources.MetaEntry
{
Name = "description",
Content = "ABC"
});
But it can be also used in other places (e.g. part driver).
Edit
using SetMeta("description", "ABC") in view give the same results.
I used the following code in my layout.cshtml file before header tag and it worked.
#using (Script.Head())
{
<meta name="description" content="<your description>"/>
<meta name="keywords" content="<your keywords here>"/>
}
Enjoy!!!

Create a simple Login page using jsp and session

I have created a simple login page in which user will give an username and password , and then it will be stored in session. After clicking on submit button it will show welcome user or the name. And if the user waits for few seconds then the session will expire and it automatically return back to the login page.
Here is my login page
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html;
charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session"></jsp:useBean>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>login</title>
</head>
<body>
<h1><center>Give your login details</center></h1>
<form method="post" action="check.jsp">
Username:<input type="text" name="username" size="20" value="<%=user.getUser() %>" > <br>
Password:<input type="password" name="password" size="20" value=<%=user.getPassword() %> ><br>
<input type="submit">
</form>
</body>
</html>
now in check.jsp i am doing my checking part for username and password
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session"></jsp:useBean>
<jsp:setProperty name="user" property="*"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>login checking</title>
</head>
<body>
<%
String USER=user.getUsername();
int PASSWORD=user.getPassword();
if(USER.equals("abhirup"))
{
if(PASSWORD==54321)
{
pageContext.forward("display.jsp");
}
else
{
out.println("Wrong password");
pageContext.include("login.jsp");
}
pageContext.include("login.jsp");
}
%>
</body>
</html>
and then finally i am displaying it in display.jsp
<%# page import="java.io.*,java.util.*" page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session" ></jsp:useBean>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Display</title>
</head>
<body>
<% String title="Welcome : successful login";
out.println(title);%>
<h3><center>Your Name:Abhirup Parui</center></h3><br>
Username<%=user.getUsername()%><br>
<%session.setMaxInactiveInterval(20);
pageContext.include("login.jsp");
%>
</body>
</html>
and also this is my LoginUser.java file
package user;
public class LoginUser {
String username;
int password;
public void setUsername(String value)
{
username=value;
}
public void setPassword(int value)
{
password=value;
}
public String getUsername(){return username;}
public int getPassword(){return password;}
}
I am using Eclipse IDE and Tomcat server. Eclipse has shown not a single error in any of the pages but still when i run my login.jsp page.
I am getting this error on running login.jsp
i have followed this link
please help me to find my errors.
Update
I can successfully run my login page.
I am getting this error now, but could not figure out where is the error.
last part of the error is this
how to fix these error . help
Because you're trying to access login.jsp directly from the browser you have to move it out of the WEB-INF directory - files in WEB-INF are not publicly accessible. If you move login.jsp up one directory and enter http://localhost:8088/abhirup/login.jsp in your browser it should pull up the page. However, it is a fairly common practice to put jsp pages under WEB-INF/jsp or something similar and use a servlet to intercept and process requests and then have the servlet forward to the appropriate jsp page.
You have a syntax error on line 1, column 46 of display.jsp because you have the word page before your language declaration. Change this:
<%# page import="java.io.*,java.util.*" page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
to this:
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
I also tried the same code and I found some error in two JSP files
My login.jsp corrected code is as given below:
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html;
charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# page import="user.LoginUser"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session"></jsp:useBean>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login page</title>
</head>
<body>
<h1><center>Give your login details</center></h1>
<form method="post" action="check.jsp">
User name:<input type="text" name="username" size="20" value="<%=user.getUsername() %>"><br>
Password:<input type="password" name="password" size="20" value="<%=user.getPassword()%>" ><br>
Submit <input type="submit">
</form>
</body>
</html>
Corrected check.jsp code is as follows:
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html;charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<%# page import="user.LoginUser"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session"></jsp:useBean>
<jsp:setProperty name="user" property="*"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login checking</title>
</head>
<body>
<%
String USER=user.getUsername();
String PASSWORD=user.getPassword();
if(USER.equals("admin"))
{
if(PASSWORD.equals("admin"))
{
pageContext.forward("display.jsp");
}
else
{
out.println("Wrong password");
pageContext.include("login.jsp");
}
pageContext.include("login.jsp");
}
%>
</body>
</html>
Corrected display.jsp code:
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html;charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<%# page import="user.LoginUser"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session" ></jsp:useBean>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Display</title>
</head>
<body>
<% String title="Welcome : Successful Login";
out.println(title);%>
<h3> <center> Your Name : Reneesh </center> </h3><br>
User name : <%=user.getUsername()%><br>
<%session.setMaxInactiveInterval(20);
%>
</body>
</html>
My Java file LoginUser.java corrected code is as follows:
package user;
public class LoginUser {
String username;
String password;
public void setUsername(String value)
{
username=value;
}
public void setPassword(String value)
{
password=value;
}
public String getUsername()
{
return username;
}
public String getPassword()
{
return password;
}
}
Kindly try with this code, I made some changes in the code by assigning String valuue for Password. I also used Eclipse juno IDE and Apache Tom Cat v 7.0 for running this Dynamic web project. Hope you will try and let me know if there is further error.

Webapp that uses "UIScrollView" in html

I would like to make a webapp that uses the "UIScrollView" xcode-function but in html.
There's no problem making a html page that puts a bunch of images in one row.. I just want to make a iphone horizontal scroll with swipe gesture to show the next image.
Can this be made?
You'll need to watch for touchstart and touchend (or touchmove) to figure out the direction, then just replace the image with the next/previous. Here are some links:
https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html
http://www.sitepen.com/blog/2008/07/10/touching-and-gesturing-on-the-iphone/
Untested:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var startX;
var endX;
var pic=0;
var pics = ['pic1.png','pic2.png','pic3.png'];
document.getElementById('picture').setAttribute('src',pics[pic]);
function touchStart(event){
startX = event.touches[0].pageX;
}
function touchEnd(event){
endX = event.touches[0].pageX;
deltaX=endX-startX;
if(deltaX>0){
next();
}
else{
prev();
}
}
function next(){
pic++;
if(pic>pics.length){pic--;}
document.getElementById('picture').setAttribute('src',pics[pic]);
}
function previous(){
pic--;
if(pic<0){pic++;}
document.getElementById('picture').setAttribute('src',pics[pic]);
}
</script>
<style>
#pictureFrame{height:460px; width:320px; top:0; left:0;}
</style>
</head>
<body>
<div id="pictureFrame"><img ontouchstart="touchStart(event);" ontouchend="touchEnd(event);" id="picture"/></div>
</body>
</html>