is any method to validate Youtube video link with Zend-framework ?
If user inputs not valid link, for example http://www.youtube.com/watch?00zzv=nel how can I check it before inserting into site ?
I'm pretty sure that there is no built in validator for this, but writing custom validators is super easy:
class My_Validate_Youtube extends Zend_Validate_Abstract{
public function isValid($value){
// check url here
if (no_good($value)){
$this->_error("Explain the error here");
return false;
}
return true;
}
}
Just put whatever checks you need in that class, and run the validator on any Youtube links to be checked.
edit:
From Laykes, you might want to consider using the validator to check if the video actually exists, instead of determining if it fits a pattern. Depends on your use cases though- eg how much latency do you want to introduce by making a call to the Youtube API?
I don't know if it is possible, however, I would take a different approach and try and see if the link has comments on it.
Take this for example. From here:
http://framework.zend.com/manual/en/zend.gdata.youtube.html
$yt = new Zend_Gdata_YouTube();
$commentFeed = $yt->getVideoCommentFeed('abc123813abc');
foreach ($commentFeed as $commentEntry) {
echo $commentEntry->title->text . "\n";
echo $commentEntry->content->text . "\n\n\n";
}
If you use the video id in the VideoCommentFeed argument, you will be able to get the value in $commentFeed. If you then get an error, you know that the video does not exist.
I am sure if you try other methods you will probably find example what you want.
Related
Right now i am working on a Codeigniter project in which I am sending a link to the user to update their password, every thing is working according to the plan. Now all I need to know is that how can I extract data from URL that the user is following to update password.
Example:
http://localhost/ciauth/user/password_reset/user#gmail.com/6f1bb1aeba261e92c390ac28d85267767038703e
I want to extract the code after the E-mail ID.
Never mind i have solved it doing
$url_code=$this->uri->segment(4);
This is okay. But it will be better if you implement it with your action function:
public function password_reset($email, $code){
// $email: user#gmail.com
// $code: 6f1bb1aeba261e92c390ac28d85267767038703e
}
Try this, From this you can do extract full url, Place below code to your password_reset() to see your url extraction
echo'<pre>';print_r($this->uri->segment_array());die;
Never mind i have solved it doing
$url_code=$this->uri->segment(4);
So I am making a PHP app that asks for the users Facebook (in those exact terms) I want it to be able to handle the copy and past Facebook URL as well as well as simply just their user name. I found this:
function GetUsernameFromFacebookURL($url) {
$correctURLPattern = '/^https?:\/\/(?:www|m)\.facebook.com\/(?:profile\.php\?id=)?([a-zA-Z0-9\.]+)$/';
if (!preg_match($correctURLPattern, $url, $matches)) {
throw new Exception('Not a valid URL');
}
return $matches[1];
The above code is really good at handling:
https://www.facebook.com/JohnDoe
https://m.facebook.com/sally.struthers
https://www.facebook.com/profile.php?id=24353623
But I would like it to return the input value if no URL is inserted, how do I do this? In addition, I notice a lot of Facebook URLs have additional arguments, such as; https://www.facebook.com/johndoe?fref=ufi - how do I compensate for that?
Using Youtube API, I've created class for my needs. (It works with Zend FW)
class youtube extends html {
var $yt, $user;
public function __construct($user) {
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$this->yt = new Zend_Gdata_YouTube();
$this->yt->setMajorProtocolVersion(2);
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$this->yt->getHttpClient()->setConfig(array('timeout' => 180));
$this->user = $user;
}
}
The problem is, when I use
$this->yt->getuserUploads($this->user)
on other class methods, it gets ALL videos. I want to get 3 last videos of $user. How to do this?
I'm really short on time at the moment otherwise I'd have a go using your code. This might help if you can't work it out or if no one comes back with an answer using your code.
I put together a quick and dirty solution as an answer for someone who wanted to show the thumbnail corresponding to the latest video uploaded to Youtube by a specific user - I coded a simple controller action and view that would display a video thumbnail which was a link to the video itself.
The example can easily be tweaked to show a particular number of videos by changing the
if($i==1) break;
line however there are probably more elegant ways of doing it than the way I did - as I say it was quick and dirty to answer a question.
I used the Zend_Feed_Reader class instead of the Zend_Gdata_YouTube class. In the short term it might help.
Good luck, let me know if this helped.
All the best, Dave :-D
Link to the question with my example
Take a look at:
$query = $yt->newVideoQuery();
$query->maxResults = 3;
$query->orderBy = 'published';
$query->author = 'ThisIsHorosho';
$query->startIndex = 1;
$videoFeed = $yt->getUserUploads(null,$query);
foreach($videoFeed as $videoEntry)
{
echo $videoEntry->getVideoWatchPageUrl() . PHP_EOL;
}
I am doing a php portal.
i did an announcement section where user can post message and attach a file.
so in this situation, a user has uploaded one and at the page, there will be a hyperlink for the attachment. if i hover on it, i can see this "192.168.0.100/Announcement/file.pdf"
so logically if im in the internal network and click on that it would not be a problem as it can get the file from that ip.
next situation is i have forwarded the server ip so that public can access from outside. now i'm as a user accessing from outside.
so if i were to go to the announcement location and hover on it again it will show the same link "192.168.0.100/Announcement/file.pdf". I will definitely wont be able to open it as that ip is internal.
so i am thinking how can i make it when i'm internal, the ip is the internal one and when im outside,the ip link would be the public?
i got this snippet from a ex colleague but i dont really know what the code does. Can someone help me explain this? i tried searching this thing i want to do on the net,but i dont have a proper keyword for it.
below is the snippet:
<?php
//filename constant.php
define('SERVERIP',((preg_match("/^192\.168/i",$_SERVER['REMOTE_ADDR']))?'192.168.0.100':'175.136.xxx.xxx'),true);
?>
And below is part of the code in the page for the announcement and attachment:
include('_include/constant.php');
$dir = "C:/Inetpub/wwwroot/Announcement/";
$http = sprintf('http://%s/Announcement/',SERVERIP);
print '<td class="middle '.$CLASS.'" align="left" height="20">'.''.$filename .'</td>';
Can any php pros here help me to understand whats happening so that next time i know what i'am actually implementing?
You do not need to implement any of this... you need to change how you are referencing the URLs and everything else will fall into place. For example, this will show http://192.168.0.100/ when you are on the LAN in your company. When you access this website from the outside, it will show the IP address or domain name you are accessing from outside.
You should be using...
something PDF
as opposed to:
<a href="http://192.168.0.100/something.pdf>something PDF</a>
which is what it seems like you're doing.
What you have is a ternary operation, the results of which are being assigned to the constant SERVERIP. It is using a regex to match against the $_SERVER['REMOTE_ADDR'], if it begins with 192.168, then it gets the 192.168 value, otherwise it gets the 175.136 value. And for some reason it is passing true to enforce a case insensitive search.
You can read more on define within the PHP docs.
Lighter example of ternary op:
$overlyComplex = true;
$thatDudesCodeSucks = (true === $overlyComplex) ? 'yes' : 'no';
// Shorthand for
if (true === $overlyComplex) {
$thatDudesCodeSucks = 'yes';
} else {
$thatDudesCodeSucks = 'no';
}
var_dump($thatDudesCodeSucks); // echos yes
Hey guys, I'm using Twitter's PHP API, called twitterlibphp, and it works well, but there's one thing that I need to be able to initiate, which is the linking of URLs and #username replies. I already have the function for this written up correctly (it is called clickable_link($text);) and have tested it successfully. I am not too familiar with parts of twitterlibphp (link goes to source code), and I am not sure where to put the function clickable_link() in order to make URLs and #username's clickable. I hope that is enough information, thanks a lot.
EDIT:
In addition, I would like only one status to come up in the function GetFriendsTimeline(), right now 20 come up, is there any easy way to limit it to one?
I would extend the Twitter class and put the functionality in my own getUserTimeline method.
class MyTwitter extends Twitter
{
public function getUserTimeline()
{
$result = parent::getUserTimeline();
// Your functionality ...
return $result;
}
}
You don't need to put clickable_link() in twitterlibphp. Instead, call it right before you output a status message. Example:
$twitter = new Twitter('username', 'password');
$result = $twitter->getUserTimeline();
... parse the $result XML here ...
echo 'Status : '.clickable_link($status);