File tree Expand file tree Collapse file tree 5 files changed +229
-0
lines changed Expand file tree Collapse file tree 5 files changed +229
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace lesha724 \documentviewer ;
4
+
5
+ use yii \base \InvalidConfigException ;
6
+ use yii \base \Widget ;
7
+ use yii \helpers \Html ;
8
+
9
+ /**
10
+ *
11
+ */
12
+ abstract class ADocumentViewer extends Widget
13
+ {
14
+ /**
15
+ * @var static ширина iframe
16
+ */
17
+ public $ width = '100% ' ;
18
+ /**
19
+ * @var string высота iframe
20
+ */
21
+ public $ height = '100% ' ;
22
+ /**
23
+ * @var string url документа
24
+ */
25
+ public $ url ;
26
+ /**
27
+ * @var string патерн строки viewer
28
+ */
29
+ protected $ _urlViewer ;
30
+
31
+ /**
32
+ * @return string геренрация url для iframe
33
+ */
34
+ protected abstract function _getIframeUrl ();
35
+
36
+ public function init (){
37
+
38
+ parent ::init ();
39
+
40
+ $ this ->_checkUrl ();
41
+ }
42
+
43
+ /**
44
+ * проверка не пустой ли url
45
+ */
46
+ protected function _checkUrl (){
47
+ if (empty ($ this ->url ))
48
+ throw new InvalidConfigException ('Ошибка не задан url ' );
49
+
50
+ if (empty ($ this ->_urlViewer ))
51
+ throw new InvalidConfigException ('Ошибка не задан url viewer ' );
52
+ }
53
+
54
+ public function run ()
55
+ {
56
+ parent ::run (); // TODO: Change the autogenerated stub
57
+
58
+ return $ this ->_run ();
59
+ }
60
+
61
+ /**
62
+ * герерация iframe
63
+ * @return string
64
+ */
65
+ protected function _run (){
66
+ $ options = [
67
+ 'src ' =>$ this ->_getIframeUrl (),
68
+ 'width ' =>$ this ->width ,
69
+ 'height ' =>$ this ->height
70
+ ];
71
+
72
+ return Html::tag ('iframe ' ,'' ,$ options );
73
+ }
74
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: Neff
5
+ * Date: 11.03.2017
6
+ * Time: 15:12
7
+ */
8
+
9
+ namespace lesha724 \documentviewer ;
10
+
11
+ /**
12
+ * Class GoogleDocumentViewer
13
+ * @package lesha724\documentviewer
14
+ * @link https://geektimes.ru/post/111647/
15
+ */
16
+ class GoogleDocumentViewer extends ADocumentViewer
17
+ {
18
+ const A_V = 'v ' ;
19
+ const A_GT = 'gt ' ;
20
+ const A_BI = 'bi ' ;
21
+ /**
22
+ * включение/выключение (значения соответственно true/false) интерфейса встраиваемого в сторонние html-страницы (по умолчанию false);
23
+ * @var bool
24
+ */
25
+ public $ embedded = false ;
26
+ /**
27
+ * тип возвращаемого документа:
28
+ “v” — будет отрыто приложение просмотра документа (это значение по умолчанию);
29
+ “gt” — будет возвращен xml документ с распознанным текстом (пример);
30
+ “bi” — будет возвращено изображение страницы документа в формате PNG8 (параметр pagenumber обязателен);
31
+ * @var string
32
+ */
33
+ public $ a = self ::A_V ;
34
+
35
+ protected $ _urlViewer = "https://docs.google.com/gview?url={url} " ;
36
+
37
+ protected function _getIframeUrl ()
38
+ {
39
+ // TODO: Implement _getIframeUrl() method.
40
+ $ url = str_replace ('{url} ' ,$ this ->url , $ this ->_urlViewer );
41
+
42
+ if ($ this ->embedded )
43
+ $ url .='&embedded=true ' ;
44
+
45
+ $ url .='&a= ' .$ this ->a ;
46
+
47
+ return $ url ;
48
+ }
49
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: Neff
5
+ * Date: 11.03.2017
6
+ * Time: 15:09
7
+ */
8
+
9
+ namespace lesha724 \documentviewer ;
10
+
11
+ /**
12
+ * Class MicrosoftDocumentViewer
13
+ * @package lesha724\documentviewer
14
+ * @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
15
+ * @link https://products.office.com/en-us/office-online/view-office-documents-online
16
+ * @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
17
+ */
18
+ class MicrosoftDocumentViewer extends ADocumentViewer
19
+ {
20
+ protected $ _urlViewer = "https://view.officeapps.live.com/op/embed.aspx?src={url} " ;
21
+
22
+ protected function _getIframeUrl ()
23
+ {
24
+ // TODO: Implement _getIframeUrl() method.
25
+
26
+ return str_replace ('{url} ' ,$ this ->url , $ this ->_urlViewer );
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ online document viewer
2
+ ======================
3
+ виджет для отображения online документов с помощью google viewer и microsoft document viewer
4
+
5
+ Installation
6
+ ------------
7
+
8
+ The preferred way to install this extension is through [ composer] ( http://getcomposer.org/download/ ) .
9
+
10
+ Either run
11
+
12
+ ```
13
+ php composer.phar require --prefer-dist lesha724/yii2-document-viewer "*"
14
+ ```
15
+
16
+ or add
17
+
18
+ ```
19
+ "lesha724/yii2-document-viewer": "*"
20
+ ```
21
+
22
+ to the require section of your ` composer.json ` file.
23
+
24
+
25
+ Usage
26
+ -----
27
+
28
+ Once the extension is installed, simply use it in your code by :
29
+
30
+ ``` php
31
+ <?= \lesha724\documentviewer\GoogleDocumentViewer::widget([
32
+ 'url'=>'http://example.com/test.doc',//url на ваш документ
33
+ 'width'=>'100%',
34
+ 'height'=>'100%',
35
+ //https://geektimes.ru/post/111647/
36
+ 'embedded'=>true,
37
+ 'a'=>\lesha724\documentviewer\GoogleDocumentViewer::A_V //A_V = 'v', A_GT= 'gt', A_BI = 'bi'
38
+ ]); ?>
39
+
40
+ ```
41
+
42
+ ``` php
43
+ <?= \lesha724\documentviewer\MicrosoftDocumentViewer::widget([
44
+ 'url'=>'http://example.com/test.doc',//url на ваш документ
45
+ 'width'=>'100%',
46
+ 'height'=>'100%'
47
+ ]); ?>
48
+
49
+ ```
50
+
51
+ Links
52
+ -----
53
+
54
+ 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
55
+ 2 . https://products.office.com/en-us/office-online/view-office-documents-online
56
+ 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
57
+ 4 . https://geektimes.ru/post/111647/
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " lesha724/yii2-document-viewer" ,
3
+ "description" : " виджет для отображения online документов с помощью google viewer и microsoft document viewer" ,
4
+ "type" : " yii2-extension" ,
5
+ "keywords" : [" yii2" ," extension" ],
6
+ "license" : " MIT" ,
7
+ "authors" : [
8
+ {
9
+ "name" : " lesha724" ,
10
+ "email" : " neff.alexey@gmail.com"
11
+ }
12
+ ],
13
+ "require" : {
14
+ "yiisoft/yii2" : " *"
15
+ },
16
+ "autoload" : {
17
+ "psr-4" : {
18
+ "lesha724\\ documentviewer\\ " : " "
19
+ }
20
+ }
21
+ }
You can’t perform that action at this time.
0 commit comments