How to create handy post message in telegram via bot on php - php

I want to create handy message like in this channel
All I've done is just here code sample
$bot = new \TelegramBot\Api\Client('xxx:yyy');
$bot->sendMessage("#dtsautocom", "<a href='https://dts-auto.com/{$passanger_car->main_photo}'>{$passanger_car->name}</a> \n{$passanger_car->year} год, {$passanger_car->price} $, пробег - {$passanger_car->mileage} км \nТелефон продавца: {$passanger_car->phone}", 'HTML');
$bot->run();
I wrapped image link to a tag and I get image, but this is not good solution and I've got this. I want to create like in the first link above. How did they do this? Can anyone give me please code sample of how to do it in right way? Thanks.

They used sendPhoto method with parse_mode set to HTML and formatted photo caption.
For your API library it should be:
$bot->sendPhoto("#dtsautocom", "https://dts-auto.com/{$passanger_car->main_photo}", "{$passanger_car->name}\n{$passanger_car->year} год, {$passanger_car->price} $, пробег - {$passanger_car->mileage} км \nТелефон продавца: {$passanger_car->phone}", null, null, false, 'HTML');

Related

PHP Phaxio paging parameter not working with sendFax function

I am using Phaxio for send FAX and it's working fine till now.
Now i have to add some extra stuff to it. I want to generate some of the data in new pages into same PDF(generate PDF on success of send fax by phaxio).
Currently its being generate new pages only when while it's come up at bottom of the page.
i tried following code by paging paging parameters as given on Phaxio official site http://www.phaxio.com/docs/paging/ but it's not working at all or might be i don't know how to use it.
Please take a look at following code.
require ("Phaxio.php");
$apiKeys['test']='xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$apiSecrets['test']='xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$apiHost='https://api.phaxio.com/v1/';
$filename='html_data.html';
$toNumber="my-10-digit-phone-no";
$phaxio=new Phaxio($apiKeys['test'], $apiSecrets['test'], $apiHost);
$phresult=$phaxio->sendFax($toNumber, $filename,
array('maxperpage' => '400','page' => '1'));
echo "<pre>";
print_r($phresult);
if ( !$phresult->succeeded() ) {
echo ("<H4>Error sending fax to $toNumber with " . $phresult->getMessage()."</H4>");
return FALSE;
}
else {
echo ("<H4>Your fax has been sent.</<H4>");
return TRUE;
}
After spending couple of hours i finally got a very silly but useful solution.
Actually my requirement was that in my FAX PDF there was number of repeated HTML was there like generate invoice in same format(using loop), and i really need like every invoice HTML should be in separate PDF page.
So I've simply used CSS style="page-break-before:always;" and i was done with my issue.
1) via CSS - for the advanced HTML users:
<p style="page-break-after:always;"></p>
2) with a simple comment:
<p><!-- pagebreak --></p>

Specification of mark-up format included in facebook open graph text

When I am performing Open Graph requests, some of the responses that I am expecting to be text are having some kind of markup included. For example, when I am requesting the Name and Description of an album, in the description I get something like \u0040[12412421421:124:The Link]. (The \u0040 is actually the # sign.)
In this case it seems that what it is saying is that the 'The Link' should be a hyperlink to a facebook page with ID 12412421421. I presume there is similar kind of markup for hashtags and external URLs.
I am trying to find some official documentation or description for this, but I can't seem to find any documentation of this (I might be looking with the wrong keywords).
Is there any online documentation that describes this? And better still is there an PHP library or function already available somewhere that converts this text into its HTML equivalent?
I am using this Facebook PHP SDK, but it doesn't seem to offer any such function. (Not sure if there is anything in the new version 4.0 one but I can't use it anyway for now because it requres PHP 5.4+ and my host currently is still on 5.3.).
It's true that the PHP SDK doesn't provide anything to deal with these links and the documentation doesn't document that either. However the API gives all the information you need in the description field itself, so here is what you could do:
$description = "Live concert with #[66961492640:274:Moonbootica] "
. "in #[106078429431815:274:London, United Kingdom]! #music #house";
function get_html_description($description) {
return
// 1. Handle tags (pages, people, etc.)
preg_replace_callback("/#\[([0-9]*):([0-9]*):(.*?)\]/", function($match) {
return ''.$match[3].'';
},
// 2. Handle hashtags
preg_replace_callback("/#(\w+)/", function($match) {
return ''.$match[0].'';
},
// 3. Handle breaklines
str_replace("\n", "<br />", $description)));
}
// Display HTML
echo get_html_description($description);
While 2. and 3. handle hashtags and breaklines, the part 1. of the code basically splits up the tag #[ID:TYPE:NAME] into 3 groups of information (id, type, name) before generating HTML links from the page IDs and names:
Live concert with Moonbootica in London, United Kingdom! #music #house
Live concert with Moonbootica in London, United Kingdom!
#music #house
FYI and even if it's not much useful, here are the meanings of the types:
an app (128),
a page (274),
a user (2048).
the # describes a tag to someone,facebook id doesnt make difference between a fanpage or a single person so you gotta deal with php only.and the # should be the only char that describes a person/page tagged
The markup is used to reference a fanpage.
Example:
"description": "Event organised by #[303925999750490:274:World Next Top Model MALTA]\nPhotography by #[445645795469650:274:Pixbymax Photography]"
The 303925999750490 is the fanpage ID. The World Next Top Model MALTA is the name of fanpage. (Don't know what the 274 means)
When you render this on your page, you can render like this:
Event organised by World Next Top Model MALTA
Photography by Pixbymax Photography

TCPDF How do you make a link to the Table of Contents (TOC)?

Can anyone demonstrate a basic example that adds a link on an arbitrary page in the pdf that takes the user back to the table of contents?
I have everything working fine, but can't get this simple requirement going.
Some background:
You'd think this would be trivial, everything about TCPDF seems to function so well, maybe a bad day I'm having. I have tried the following:
From the documentation there seems to be 2 options for creating internal document links
Via methods addlink() and setlink() to specify a target page.
Via an html anchor tag rendered in the pdf (where you specify the href attribute as #15 for page 15 for eg.)
These methods basically work just fine.
A quote from the author -
The Table Of Content page is created on the current page and then moved to the specified page...To create a link to the TOC page you have to set a link to the last page (you must know the total number of pages before).
I Understand this, I create the TOC last (using the supplied methods), and make a link to this last page, but it is unclickable (not a link in the rendered doc). I therefore have to interpret the quote 'you must know the total number of pages before' as meaning TCPDF must know the number of pages! Clearly a big difference, meaning for most practical purposes the answer is no, not by this method (maybe one link on the last page!)
Finally, the documentation for the addTOC method mentions the $toc_name argument:
TCPDF::addTOC (
$page = '',
$numbersfont = '',
$filler = '.',
$toc_name = 'TOC',
$style = '',
}
$toc_name (string) name to use for TOC bookmark.
Unfortunately I can't see anyway to use this name, no docs, help or examples anywhere.
Someone.. please tell me I'm being silly..
It may be late, but this is what I use (my table of contents is on page 2):
$pdf->addTOCPage();
$link = $pdf->AddLink();
$pdf->SetLink($link, 0, '*2');
$pdf->addTOC(2, 'courier', '.', 'INDEX', 'R', array(128,0,0));
$pdf->endTOCPage();
And then at where ever I want to link back to the TOC in the document, I do the following:
$html = 'Return to TOC';
$pdf->writeHTML($html, true, false, true, false, 'R');
TCPDF Bookmark:
$bookmark = "Title of my Bookmark";
$pdf->Bookmark($bookmark);
This is your best bet for adding to the PDF Bookmarks.

Displaying a list of videos from a channel - Vimeo Advanced API

I need a way to display videos from a specific channel on a page using PHP.
I have authenticated my app and I can use some methods using the advanced API. I am using the official vimeo PHP library to connect.
Below is what I am trying to do and when I dump the array I do not get anything. I can get info back from using get videos from the entire account method.
require_once('/url/vimeo/vimeo.php');
$vimeo = new phpVimeo('number', 'number');
$vimeo->setToken('number','numbers');
$videos = $vimeo->call('vimeo.channels.getVideos', array('ACCOUNT' => 'NAME'));
If I put the channel name where ACCOUNT is I will get an invalid signature error.
Is it worth using something like simple HTML parser for PHP and doing it that or worth sticking with the advanced API?
I would highly advise using the advanced api. If you parse the html, it will break any time vimeo changes their channel pages. Additionally, channels have more than one layout
eg: vimeohq and nicetype
The second parameter of the "call" function should be any querystring parameters the api method requires.
In the case of "vimeo.channels.getVideos" you can provide
channel_id
user_id
page
per_page
summary_response
full_response.
To experiment with the getVideos method, you can use the playground.
So in the end, I believe you want the function to look like this..
$videos = $vimeo->call('vimeo.channels.getVideos', array('channel_id' => 'NAME'));
where NAME is either the channel id, or the channel name (the channel name matches the url slug, so for example "nicetype" not "nice type"

Deleting YouTube videos using Zend/PHP

I'm using Zend and PHP to upload and delete videos from my home page. The uploading part is working fine but to download is more complicated.
$videoEntryToDelete = $yt->getVideoEntry($videoId);
$yt->delete($videoEntryToDelete);
I use this code to delete a video and the first row do work. The video object is created and I can get all data from it. But when I try to delete it I get this error message:
"You must specify an URI to which to post"
Do anyone know how to solve this problem?
Thanks!
By default, getVideoEntry() gets a read only video object. In order to edit it, you must pass true in the third parameter for getVideoEntry(). The video object will then contain all of the metadata, including the URL required to delete it.
Try this:
$videoEntryToDelete = $yt->getVideoEntry($videoId, null, true);
$yt->delete($videoEntryToDelete);
there is also a method ready to use:
$videoEntryToDelete = $yt->getFullVideoEntry($videoId);
$yt->delete($videoEntryToDelete);

Categories