Retina iconLink with Google Drive API - php

I'm an getting a list of files in a folder. The response contains a iconLink for every file returned. This icon is 16x16 pixels.
Does anyone know a way to retrieve a retina image? Or another way to retrieve a bigger icon image?
https://developers.google.com/drive/v2/reference/files
top: Google Drive UI
bottom: Google Drive API integration

The good news is although not officailly documented driver does have 2x resolution icons. The bad news is they have inconsistent file names; for example the icon you linked in the comments has a 32px version availabel here: ssl.gstatic.com/docs/doclist/images/mediatype/icon_3_pdf_x32.png
Now here is my soltion, it's not perfect but it will do the job for a while:
function getIcons($file_type)
{
$icons = [
'pdf' => [
'icon' => 'icon_12_pdf_list.png',
'retina' => 'icon_3_pdf_x32.png'
],
'document' => [
'icon' => 'icon_1_document_x16.png',
'retina' => 'icon_1_document_x32.png'
],
'image' => [
'icon' => 'con_1_image_x16.png',
'retina' => 'icon_1_image_x32.png'
],
'word' => [
'icon' => 'icon_1_word_x16.png',
'retina' => 'icon_1_word_x32.png'
],
'text' => [
'icon' => 'icon_1_text_x16.png',
'retina' => 'icon_1_text_x32.png'
],
'spreadsheet' => [
'icon' => 'icon_1_spreadsheet_x16.png',
'retina' => 'icon_1_spreadsheet_x32.png'
],
'form' => [
'icon' => 'icon_2_form_x16.png',
'retina' => 'icon_2_form_x32.png'
],
'audio' => [
'icon' => 'icon_1_audio_x16.png',
'retina' => 'icon_1_audio_x32.png'
]
];
return isset($icons[$file_type]) ? $icons[$file_type] : $icons['text'];
}
The reasion I say it will work for a while is that I'm asuming the _3_ in pdf icon file name for instance is the version number. So if Google updates it's icons again in the future this solution may brake.

I'm using drive rest api and what i observed was that iconLink attribute had a definite pattern.
"https://drive-thirdparty.googleusercontent.com/" + size + mimetype
By default size is 16. So, before adding your icon to Image, use this:
String iconLink = (String) jsonObject.get("iconLink");
iconLink=iconLink.replace("16","128");
check out these both links:
https://drive-thirdparty.googleusercontent.com/128/type/application/pdf
https://drive-thirdparty.googleusercontent.com/16/type/application/pdf

Looks like images with x128 also added/present for various versions:
Ver. 1
Ver. 2
Ver. 3
Better to replace the x16 from the fetched iconLink and replace it with x128.

Related

How to open PDF in new tab using KNP Menu Bundle

I want to open PDF document in new TAB while pressing button "Download PDF".
Found a solution on SO that you have to add 'target' => "_blank", but in my case it's not working and I don't have an idea why. Tried setLinkAttribute, setChildAttribute, setAttribute and none of these are working. Also, content disposition inline already added.
$menu
->addChild(
'download_file',
[
'route' => 'admin_download_file',
'routeParameters' => [
'token' => $admin->getToken(),
],
]
)
->setAttribute('type', 'link')
->setLinkAttribute('target', '_blank');
->setLinkAttributes(['target', '_blank']);
or I think on child level something like:
->addChild(
'download_file',
[
'route' => 'admin_download_file',
'routeParameters' => [
'token' => $admin->getToken(),
],
'linkAttributes' => ['target' => '_blank']
]
)

how to get the page number inside content (html layout) of kartik mpdf

I am using Kartik mpdf library to generate pdf. I am generating barcode in the body of the pdf which contains mcqs question generated through loop so pages are inserted randomly depending on the questions, So I need the page number to be set in my barcode on each page.
Kartik mpdf provides a method 'SetFooter' => ['{PAGENO}|'] which gives page number in footer but this {'PAGENO'} is not working in my html document... How would I get the page number inside my document.
PAGENO has nothing to do with kartik, is from mpdf. When you say is not working in your html, that's because that placeholder variable is going to be parsed with mpdf, so if you are not generating a pdf it wont take effect.
On the other hand, you can't show the page number in your html. There's no pages numbers on a html document, as it will depend in the page size and the font size of the browser, so it won't be possible to know "where you are" on the server side.
I hope you are using renderPartial method. Please find my code below.
$pdf = new Pdf([
'mode' => Pdf::MODE_UTF8, // leaner size using standard fonts
'destination' => Pdf::DEST_BROWSER,
'orientation' => Pdf::ORIENT_PORTRAIT,
'content' => $this->renderPartial('print', [
'model' => $model,
'quotations' => $modelQtn,
'pageNo' => ['{PAGENO} of {nb}'],
]),
'filename' => $model->po_no,
'cssFile' => [
'#vendor/../backend/assets/css/custom-style.css',
'#vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',
],
// any css to be embedded if required
'cssInline' => '
.kv-heading-1 {
font-size:26px
}
.text-center {
font-family : Arial !important;
font-size:
}',
'options' => [
// any mpdf options you wish to set
'title' => 'Purchase Order'
],
'methods' => [
'SetTitle' => $model->po_no,
'SetSubject' => 'Mohammed Iqbal Khan',
'SetHeader' => [ 'Generated On: ' . date("F j, Y, g:i a")],
'SetFooter' => ['|Page {PAGENO} of {nb}|'],
'SetAuthor' => 'Mohammed Iqbal Khan',
'SetCreator' => 'Mohammed Iqbal Khan',
'SetKeywords' => 'Mohammed Iqbal Khan',
'SetWatermarkText' => 'DRAFT',
'SetWatermarkImage' => '',
]
]);
return $pdf->render();
Once you pass the page no method, then you can use the below code to show page no in your document while generating.
<?= $pageNo[0];?>

Wkhtmltopdf + cakepdf - Custom page size

I can't figure out how to enable custom page sizes with CakePDF and wkhtmltopdf. I have the following configuration code:
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
'binary' => '/usr/local/bin/wkhtmltopdf',
],
'orientation' => 'portrait',
'pageSize' => '', // this line
'download' => true
]);
I want to have 150x150mm pages. I already tried several things like passing an array [150,150] but also things like '150 150' or '150mm 150mm'. Is this even possible?
The CakePDF pageSize option maps to the page-size option of wkhtmltopdf, which takes QPrinter::PaperSize constant names, like for example A4, A5, B0, B1, Legal, Letter, etc., ie you cannot define a custom size using that option.
If you need a custom size, then you have to use the wkhtmltopdf specific page-width and page-height options, which both take millimeter values by default.
Quote from the wkhtmltopdf docs:
Page sizes:
The default page size of the rendered document is A4, but using this
--page-size option this can be changed to almost anything else, such as: A3,
Letter and Legal. For a full list of supported pages sizes please see
http://qt-project.org/doc/qt-4.8/qprinter.html#PaperSize-enum.
For a more fine grained control over the page size the --page-height and
--page-width options may be used
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
'binary' => '/usr/local/bin/wkhtmltopdf',
'options' => [
'page-width' => 150,
'page-height' => 150
]
],
'orientation' => 'portrait',
'download' => true
]);
See also
wkhtmltopdf docs
Qt Documentation > QtGui > QPrinter > enum QPrinter::PaperSize

Youtube embed start time convert to time in seconds directly in array from regex group

I want to extend one php package which returns embed code from YouTube. I want to extend it and make embed code with start time querystring.
Piece of Code:
'website' => 'http://youtube.com',
'ssl' => true,
'url' => [
'^(https?://)?(?:www\.)?youtu\.be/([0-9a-zA-Z-_]{11})',
'^(https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com/(?:embed/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:.+&t=)(\S+)',
],
'info' => [
'id' => '{1}',
'url' => '{protocol}://youtu.be/{1}',
'dataUrl' => '{protocol}://gdata.youtube.com/feeds/api/videos/{1}?v=2&alt=jsonc',
'imageRoot' => '{protocol}://img.youtube.com/vi/{1}/',
],
'render' => [
// iframe attributes
'sizeRatio' => 1.77,
'iframe' => [
'src' => '{protocol}://www.youtube.com/embed/{1}?rel=0&wmode=transparent&start={3}',
'width' => 560,
'height' => 315,
'allowfullscreen' => null,
'frameborder' => 0,
],
{3} is a start time from YouTube in format like 1h22m59s or 22m59s or 59s. I am getting {3} from regex from the last group : (?:.+&t=)(\S+)',
Is it possible to run function directly in array value to convert {3} time in seconds? For embed videos I need &start=123 (not ?start=1h22m59s )
I solved it by editing package source. It was the best solution.

Images are not saved into the photo_dir folder using cakephp-upload plugin on CakePHP 3.2

I am using the cakephp-upload plugin and I managed to upload images to my server:
WorkersTable:
public function initialize(array $config)
{
parent::initialize($config);
$this->table('workers');
$this->displayField('id');
$this->primaryKey('id');
$this->addBehavior('Josegonzalez/Upload.Upload', [
'avatar' => [
'fields' => [
'dir' => 'photo_dir'
]
]
]);
}
view.ctp:
echo $this->Form->create($newWorker, ['type' => 'file']);
echo $this->Form->input('avatar', ['type' => 'file']);
echo $this->Form->input('photo_dir', ['type' => 'hidden']);
Now the avatar images are uploaded, but they are not put into the photo_dir subdirectory.
What am I missing? It works without any problems in my CakePHP 2.8.x application.
Author of the plugin here.
The fields.dir attribute does not state what the subdirectory should be. It is a reference to the column in your database table where we should save the director where we saved the file.
If you want to change the place where you save files on disk, you should instead use the path option. Here is an example where i use the photo_dir subdirectory:
$this->addBehavior('Josegonzalez/Upload.Upload', [
'avatar' => [
'path' => 'webroot{DS}files{DS}{model}{DS}{field}{DS}photo_dir{DS}'
]
]);
The default value for the path option is webroot{DS}files{DS}{model}{DS}{field}{DS}.
Shouldn't it be:
$this->addBehavior('Josegonzalez/Upload.Upload', [
'avatar' => [
'fields' => [
'dir' => 'avatar_dir'
]
]
]);
echo $this->Form->input('avatar_dir', ['type' => 'hidden']);
If you want to use better option than you can use below plugin which has better option for upload the file rather than Josegonzalez/Upload.Upload plugin.
I have used below one in my project.
Utils Plugin for Cake 3.x
Link for this plugin : https://github.com/cakemanager/cakephp-utils
Documentation : http://cakemanager.org/docs/utils/1.0/behaviors/uploadable/
And this is the configuration :
$this->addBehavior('Utils.Uploadable', [
'image' => [
'path' => '{ROOT}{DS}{WEBROOT}{DS}uploads{DS}{field}{DS}',
'fileName' => md5(rand(1000, 5000000)) . '.{extension}',
'removeFileOnDelete' => true,
'removeFileOnUpdate' => FALSE
],
]);
Here you can customise it. Let me know if you have any question regarding this.

Categories