Make links clickable in PHP with twitterlibphp? - php

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);

Related

Fortnite API html

I want to put my fortnite stats on my website HTML/CSS. I find this.
But I don't know php very good, so I need your help. Must I delete this: 'your_api_key' and put : your_api_key without the ' ' ?
And lines like this:
$this->auth = new Fortnite_Auth($this);
$this->challenges = new Fortnite_Challenges($this);
$this->leaderboard = new Fortnite_Leaderboard($this);
$this->items = new Fortnite_Items($this);
$this->news = new Fortnite_News($this);
$this->patchnotes = new Fortnite_PatchNotes($this);
$this->pve = new Fortnite_PVE($this);
$this->status = new Fortnite_Status($this);
$this->weapons = new Fortnite_Weapons($this);
$this->user = new Fortnite_User($this)
Must I modify something?
(here are some informations:
-user_id: 501b9f2dfda34249a2749467513172bf
-username: NoMaD_DEEPonion
-platform: pc
-windows: season 5
)
For all this code, I used xammp server (I hope it's good)
Thank you for your help
You should always quote '' your key/strings. So it would look like:
$api->setKey('123qwerty456');
$api->user->id('NoMaD_DEEPonion');
Please read their documentation. You're supposed to get an API key from them to get started. And you don't have to edit Client.php. You're supposed to include the files instead. Try including Autoloader.php, since it requires the necessary files.
XAMPP is alright for development, but not suitable for production/public. Good luck!
What #sykez wrote.
I personally use https://fortniteapi.com/ to get the data. They also have a sweet POSTMAN page with different requests https://documenter.getpostman.com/view/4499368/RWEjoGqD
At last. I am not really sure that this will be a good project to start learning PHP from. I really suggest that you get to understand the basics of PHP first before you jump into API calls, processing arrays and more.

PHP Live Chat Message insert ( Live streaming Chat, not VideoID Comment )

I'm actually building a PHP bot that reads the youtube live streaming chat, and store in a Database the message that contains a specific keyword wrote by the users during the livestream. All the logic is in place, what is missing is the feedback on chat when the bot is "triggered".
I looked everywhere but seams the PHP documentation is missing, if you look inside the PHP Classes there is the public function insert, but there is no example at all on how to use it?
Someone know how to use it?
Should be something "simple" like: $result = $youtube->liveChatMessages->Insert($args); but I can't figure out on what args looks like.
HERE the only reference about the Insert method
Thanks to all for any suggestion on how to use it!
17/06/2018 edit Working Example
$liveChatMessage = new Google_Service_YouTube_LiveChatMessage();
$liveChatSnippet = new Google_Service_YouTube_LiveChatMessageSnippet();
$liveChatSnippet->setLiveChatId($liveChatID);
$liveChatSnippet->setType("textMessageEvent");
$messageDetails = new Google_Service_YouTube_LiveChatTextMessageDetails();
$messageDetails->setMessageText("Message to type in chat");
$liveChatSnippet->setTextMessageDetails($messageDetails);
$liveChatMessage->setSnippet($liveChatSnippet);
$videoCommentInsertResponse = $youtube->liveChatMessages->insert('snippet', $liveChatMessage);

Implementing SmartyBC

Just a small question for anyone out there that uses smarty. I am trying to pass PHP directly into my code, but when I do, the cached version cuts out the PHP and just prints it directly like so.
<div class="dashboard-card-content">
<?php
$con = mysqli_connect(Nice,Try,Fly,Guy);
$company_id = $_smarty_tpl->tpl_vars['auth']->value['user_id'];
$company_id = mysqli_query($con,"SELECT company_id FROM cscart_users WHERE user_id = $company_id")->fetch_object()->company_id;
$company_id = mysqli_query($con,"SELECT goal FROM cscart_companies WHERE company_id = $company_id")->fetch_object()->goal;
echo "Your current goal is: ".$company_id;
?>
This just prints all of it out on my webpage, so I tried using the following:
{Literal}
{Include_php}
{php}
And I just can't find a way to get my PHP code to go into my TPL how I want it. This is becoming really frustrating and all I want is for my cache files to leave the PHP code alone. Sorry if this is a dumb question but I have been researching this for a while. How do I implement SmartyBC so that I can still use PHP injections. And if using SmartyBC is a bad idea, can someone give me a dumbed down version of how to use a seperate PHP function page to set variables to show in the Template?
Smarty is a template engine for presentation logic only. You cannot put application logic inside a template. It was possible in older versions of Smarty but fortunately not anymore. Just execute those funcions in a php file and pass the result to the template.
And yes, you can use SmartyBC: http://www.smarty.net/docs/en/bc.tpl, but that's supposed to be used for compatibility with existing projects. It's a really bad idea and shouldn't be used for new projects.
Why do you want to use php in Smarty?
Put your logic into a class or function, and pass the data via the controller: Registry::get('view')->assign('smarty_variable', $data), and you are good to go.
You can create PHP function which gets necessary data from database. E.g.
function fn_get_company_goal($user_id)
{
$company_id = db_get_field("SELECT company_id FROM ?:users WHERE user_id = ?i, $user_id");
$goal = db_get_field("SELECT goal FROM ?:companies WHERE company_id = ?i, $company_id");
return $goal;
}
Put it to your addon. Then you can use it in the Smarty template in the following manner:
{$goal = $user_id|fn_get_company_goal}

Fetch 3 Last video from youtube channel

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;
}

Zend-framework: YouTube video link validation

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.

Categories