1<?php 2 3namespace FYKOS\dokuwiki\Extension\PluginNewsFeed; 4 5use Doku_Renderer; 6use dokuwiki\Extension\SyntaxPlugin; 7use dokuwiki\Form\Form; 8use helper_plugin_newsfeed; 9 10/** 11 * Class AbstractStream 12 * @author Michal Červeňák <miso@fykos.cz> 13 */ 14abstract class AbstractStream extends SyntaxPlugin { 15 16 protected helper_plugin_newsfeed $helper; 17 18 public function __construct() { 19 $this->helper = $this->loadHelper('newsfeed'); 20 } 21 22 public function getType(): string { 23 return 'substition'; 24 } 25 26 public function getPType(): string { 27 return 'block'; 28 } 29 30 public function getSort(): int { 31 return 3; 32 } 33 34 protected function renderEditModal(Doku_Renderer $renderer, array $params): void { 35 $id = uniqid(); 36 global $ID; 37 $renderer->nocache(); 38 if (auth_quickaclcheck($ID) >= AUTH_EDIT) { 39 $this->renderModalContent($renderer, $id, $params); 40 } 41 } 42 43 protected function renderModalContent(Doku_Renderer $renderer, string $id, array $params): void { 44 //button 45 $renderer->doc .= '<button data-toggle="modal" data-target="#feedModal' . $id . '" class="btn btn-primary" > 46<span class="fa fa-edit"></span> 47</button>'; 48 // content 49 $renderer->doc .= '<div id="feedModal' . $id . '" class="modal" data-id="' . $id . '"> 50<div class="modal-dialog"> 51<div class="modal-content"> 52<div class="modal-header"> 53<h5 class="modal-title">' . $this->helper->getLang('edit_stream') . '</h5> 54<button type="button" class="close" data-dismiss="modal" aria-label="Close"> 55<span aria-hidden="true">×</span> 56</button> 57</div> 58<div class="modal-body">'; 59 $this->renderStreamHead($renderer, $params); 60 $renderer->doc .= '</div></div></div></div>'; 61 } 62 63 protected function renderStream(Doku_Renderer $renderer, array $params): void { 64 $attributes = []; 65 66 foreach ($params as $key => $value) { 67 $attributes['data-' . $key] = $value; 68 } 69 $renderer->doc .= '<div class="news-stream">'; 70 $this->renderEditModal($renderer, $params); 71 72 $renderer->doc .= '<div class="stream row" ' . buildAttributes($attributes) . '></div>'; 73 74 $renderer->doc .= '<div class="load-bar w-100" style="text-align:center;clear:both"><svg xmlns="http://www.w3.org/2000/svg" width="25%" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-blank"><rect x="0" y="0" width="100" height="100" fill="none" class="bk"/><g transform="scale(0.55)"><circle cx="30" cy="150" r="30" fill="#1175da"><animate attributeName="opacity" from="0" to="1" dur="1s" begin="0" repeatCount="indefinite" keyTimes="0;0.5;1" values="0;1;1"/></circle><path d="M90,150h30c0-49.7-40.3-90-90-90v30C63.1,90,90,116.9,90,150z" fill="#1175da"><animate attributeName="opacity" from="0" to="1" dur="1s" begin="0.1" repeatCount="indefinite" keyTimes="0;0.5;1" values="0;1;1"/></path><path d="M150,150h30C180,67.2,112.8,0,30,0v30C96.3,30,150,83.7,150,150z" fill="#1175da"><animate attributeName="opacity" from="0" to="1" dur="1s" begin="0.2" repeatCount="indefinite" keyTimes="0;0.5;1" values="0;1;1"/></path></g></svg></div>'; 75 $renderer->doc .= '<button class="more-news btn btn-info w-100" disabled="disabled" data-stream="' . $params['stream'] . '"> 76 ' . $this->getLang('btn_more_news') . ' 77 </button>'; 78 79 $renderer->doc .= '</div>'; 80 } 81 82 83 protected function renderStreamHead(Doku_Renderer $renderer, array $params): void { 84 global $ID; 85 if (auth_quickaclcheck($ID) >= AUTH_EDIT) { 86 $renderer->doc .= '<div class="btn-group-vertical">'; 87 $renderer->doc .= '<div class="mb-3">'; 88 $renderer->doc .= $this->printPreviewBtn($params['stream']); 89 $renderer->doc .= '</div>'; 90 $renderer->doc .= '<div class="mb-3">'; 91 $renderer->doc .= $this->printCreateBtn($params['stream']); 92 $renderer->doc .= '</div>'; 93 $renderer->doc .= '<div class="mb-3">'; 94 $renderer->doc .= $this->printPullBtn($params['stream']); 95 $renderer->doc .= '</div>'; 96 $renderer->doc .= '<div class="mb-3">'; 97 $renderer->doc .= $this->printCacheBtn(); 98 $renderer->doc .= '</div>'; 99 $renderer->doc .= '</div>'; 100 } 101 } 102 103 private function printPullBtn($stream): string { 104 $form = new Form(); 105 $form->setHiddenField('do', 'admin'); 106 $form->setHiddenField('page', 'newsfeed_push'); 107 $form->setHiddenField('news[stream]', $stream); 108 $form->addButton('submit', $this->getLang('btn_push_stream')) 109 ->addClass('btn btn-info'); 110 return $form->toHTML(); 111 } 112 113 private function printPreviewBtn($stream): string { 114 return '<a class="btn btn-secondary" href="' . wl(null, [ 115 'do' => helper_plugin_newsfeed::FORM_TARGET, 116 'news[do]' => 'preview', 117 'news[stream]' => $stream, 118 ]) . '">' . $this->getLang('Preview') . '</a>'; 119 } 120 121 private function printCreateBtn($stream): string { 122 $form = new Form(); 123 $form->setHiddenField('do', helper_plugin_newsfeed::FORM_TARGET); 124 $form->setHiddenField('news[do]', 'create'); 125 $form->setHiddenField('news[id]', 0); 126 $form->setHiddenField('news[stream]', $stream); 127 $form->addButton('submit', $this->getLang('btn_create_news')) 128 ->addClass('btn btn-primary'); 129 return $form->toHTML(); 130 } 131 132 private function printCacheBtn(): string { 133 $form = new Form(); 134 $form->setHiddenField('do', helper_plugin_newsfeed::FORM_TARGET); 135 $form->setHiddenField('news[do]', 'purge'); 136 $form->addButton('submit', $this->getLang('cache_del_full')) 137 ->addClass('btn btn-warning'); 138 return $form->toHTML(); 139 } 140 141} 142