-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Microsoft viewer and goole viewer
- Loading branch information
0 parents
commit c45cd91
Showing
5 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace lesha724\documentviewer; | ||
|
||
use yii\base\InvalidConfigException; | ||
use yii\base\Widget; | ||
use yii\helpers\Html; | ||
|
||
/** | ||
* | ||
*/ | ||
abstract class ADocumentViewer extends Widget | ||
{ | ||
/** | ||
* @var static ширина iframe | ||
*/ | ||
public $width = '100%'; | ||
/** | ||
* @var string высота iframe | ||
*/ | ||
public $height = '100%'; | ||
/** | ||
* @var string url документа | ||
*/ | ||
public $url; | ||
/** | ||
* @var string патерн строки viewer | ||
*/ | ||
protected $_urlViewer; | ||
|
||
/** | ||
* @return string геренрация url для iframe | ||
*/ | ||
protected abstract function _getIframeUrl(); | ||
|
||
public function init(){ | ||
|
||
parent::init(); | ||
|
||
$this->_checkUrl(); | ||
} | ||
|
||
/** | ||
* проверка не пустой ли url | ||
*/ | ||
protected function _checkUrl(){ | ||
if(empty($this->url)) | ||
throw new InvalidConfigException('Ошибка не задан url'); | ||
|
||
if(empty($this->_urlViewer)) | ||
throw new InvalidConfigException('Ошибка не задан url viewer'); | ||
} | ||
|
||
public function run() | ||
{ | ||
parent::run(); // TODO: Change the autogenerated stub | ||
|
||
return $this->_run(); | ||
} | ||
|
||
/** | ||
* герерация iframe | ||
* @return string | ||
*/ | ||
protected function _run(){ | ||
$options = [ | ||
'src'=>$this->_getIframeUrl(), | ||
'width'=>$this->width, | ||
'height'=>$this->height | ||
]; | ||
|
||
return Html::tag('iframe','',$options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Neff | ||
* Date: 11.03.2017 | ||
* Time: 15:12 | ||
*/ | ||
|
||
namespace lesha724\documentviewer; | ||
|
||
/** | ||
* Class GoogleDocumentViewer | ||
* @package lesha724\documentviewer | ||
* @link https://geektimes.ru/post/111647/ | ||
*/ | ||
class GoogleDocumentViewer extends ADocumentViewer | ||
{ | ||
const A_V = 'v'; | ||
const A_GT = 'gt'; | ||
const A_BI = 'bi'; | ||
/** | ||
* включение/выключение (значения соответственно true/false) интерфейса встраиваемого в сторонние html-страницы (по умолчанию false); | ||
* @var bool | ||
*/ | ||
public $embedded = false; | ||
/** | ||
* тип возвращаемого документа: | ||
“v” — будет отрыто приложение просмотра документа (это значение по умолчанию); | ||
“gt” — будет возвращен xml документ с распознанным текстом (пример); | ||
“bi” — будет возвращено изображение страницы документа в формате PNG8 (параметр pagenumber обязателен); | ||
* @var string | ||
*/ | ||
public $a = self::A_V; | ||
|
||
protected $_urlViewer = "https://docs.google.com/gview?url={url}"; | ||
|
||
protected function _getIframeUrl() | ||
{ | ||
// TODO: Implement _getIframeUrl() method. | ||
$url = str_replace('{url}',$this->url, $this->_urlViewer); | ||
|
||
if($this->embedded) | ||
$url.='&embedded=true'; | ||
|
||
$url.='&a='.$this->a; | ||
|
||
return $url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Neff | ||
* Date: 11.03.2017 | ||
* Time: 15:09 | ||
*/ | ||
|
||
namespace lesha724\documentviewer; | ||
|
||
/** | ||
* Class MicrosoftDocumentViewer | ||
* @package lesha724\documentviewer | ||
* @link https://support.office.com/uk-ua/article/%D0%9F%D0%B5%D1%80%D0%B5%D0%B3%D0%BB%D1%8F%D0%B4-%D0%B4%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D1%96%D0%B2-Office-%D0%B2-%D0%86%D0%BD%D1%82%D0%B5%D1%80%D0%BD%D0%B5%D1%82%D1%96-1cc2ea26-0f7b-41f7-8e0e-6461a104544e?ui=uk-UA&rs=uk-UA&ad=UA&fromAR=1 | ||
* @link https://products.office.com/en-us/office-online/view-office-documents-online | ||
* @link https://support.office.com/uk-ua/article/%D0%9F%D1%96%D0%B4%D1%82%D1%80%D0%B8%D0%BC%D0%BA%D0%B0-%D0%B1%D1%80%D0%B0%D1%83%D0%B7%D0%B5%D1%80%D1%96%D0%B2-%D1%83-%D0%B2%D0%B5%D0%B1-%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%B0%D1%85-Office-Online-ad1303e0-a318-47aa-b409-d3a5eb44e452?ui=uk-UA&rs=uk-UA&ad=UA | ||
*/ | ||
class MicrosoftDocumentViewer extends ADocumentViewer | ||
{ | ||
protected $_urlViewer = "https://view.officeapps.live.com/op/embed.aspx?src={url}"; | ||
|
||
protected function _getIframeUrl() | ||
{ | ||
// TODO: Implement _getIframeUrl() method. | ||
|
||
return str_replace('{url}',$this->url, $this->_urlViewer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
online document viewer | ||
====================== | ||
виджет для отображения online документов с помощью google viewer и microsoft document viewer | ||
|
||
Installation | ||
------------ | ||
|
||
The preferred way to install this extension is through [composer](http://getcomposer.org/download/). | ||
|
||
Either run | ||
|
||
``` | ||
php composer.phar require --prefer-dist lesha724/yii2-document-viewer "*" | ||
``` | ||
|
||
or add | ||
|
||
``` | ||
"lesha724/yii2-document-viewer": "*" | ||
``` | ||
|
||
to the require section of your `composer.json` file. | ||
|
||
|
||
Usage | ||
----- | ||
|
||
Once the extension is installed, simply use it in your code by : | ||
|
||
```php | ||
<?= \lesha724\documentviewer\GoogleDocumentViewer::widget([ | ||
'url'=>'http://example.com/test.doc',//url на ваш документ | ||
'width'=>'100%', | ||
'height'=>'100%', | ||
//https://geektimes.ru/post/111647/ | ||
'embedded'=>true, | ||
'a'=>\lesha724\documentviewer\GoogleDocumentViewer::A_V //A_V = 'v', A_GT= 'gt', A_BI = 'bi' | ||
]); ?> | ||
|
||
``` | ||
|
||
```php | ||
<?= \lesha724\documentviewer\MicrosoftDocumentViewer::widget([ | ||
'url'=>'http://example.com/test.doc',//url на ваш документ | ||
'width'=>'100%', | ||
'height'=>'100%' | ||
]); ?> | ||
|
||
``` | ||
|
||
Links | ||
----- | ||
|
||
1. https://support.office.com/uk-ua/article/%D0%9F%D0%B5%D1%80%D0%B5%D0%B3%D0%BB%D1%8F%D0%B4-%D0%B4%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D1%96%D0%B2-Office-%D0%B2-%D0%86%D0%BD%D1%82%D0%B5%D1%80%D0%BD%D0%B5%D1%82%D1%96-1cc2ea26-0f7b-41f7-8e0e-6461a104544e?ui=uk-UA&rs=uk-UA&ad=UA&fromAR=1 | ||
2. https://products.office.com/en-us/office-online/view-office-documents-online | ||
3. https://support.office.com/uk-ua/article/%D0%9F%D1%96%D0%B4%D1%82%D1%80%D0%B8%D0%BC%D0%BA%D0%B0-%D0%B1%D1%80%D0%B0%D1%83%D0%B7%D0%B5%D1%80%D1%96%D0%B2-%D1%83-%D0%B2%D0%B5%D0%B1-%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%B0%D1%85-Office-Online-ad1303e0-a318-47aa-b409-d3a5eb44e452?ui=uk-UA&rs=uk-UA&ad=UA | ||
4. https://geektimes.ru/post/111647/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "lesha724/yii2-document-viewer", | ||
"description": "виджет для отображения online документов с помощью google viewer и microsoft document viewer", | ||
"type": "yii2-extension", | ||
"keywords": ["yii2","extension"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "lesha724", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"yiisoft/yii2": "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"lesha724\\documentviewer\\": "" | ||
} | ||
} | ||
} |