PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/wiki-plugins/wikiplugin_draw.php

https://gitlab.com/ElvisAns/tiki
PHP | 193 lines | 167 code | 19 blank | 7 comment | 19 complexity | 033ef7b6540b99825af43655d8fa7d93 MD5 | raw file
  1. <?php
  2. // (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
  3. //
  4. // All Rights Reserved. See copyright.txt for details and a complete list of authors.
  5. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
  6. // $Id$
  7. function wikiplugin_draw_info()
  8. {
  9. return [
  10. 'name' => tra('Draw'),
  11. 'documentation' => 'PluginDraw',
  12. 'description' => tra('Embed a drawing in a page'),
  13. 'prefs' => [ 'feature_draw' , 'wikiplugin_draw'],
  14. 'iconname' => 'edit',
  15. 'tags' => [ 'basic' ],
  16. 'introduced' => 7.1,
  17. 'params' => [
  18. 'id' => [
  19. 'required' => false,
  20. 'name' => tra('Drawing ID'),
  21. 'description' => tra('Internal ID of the file ID'),
  22. 'filter' => 'digits',
  23. 'accepted' => ' ID number',
  24. 'default' => '',
  25. 'since' => '7.1',
  26. 'profile_reference' => 'file',
  27. ],
  28. 'width' => [
  29. 'required' => false,
  30. 'name' => tra('Width'),
  31. 'description' => tr(
  32. 'Width in pixels or percentage. Default value is page width, for example, %0 or %1',
  33. '<code>200px</code>',
  34. '<code>100%</code>'
  35. ),
  36. 'filter' => 'text',
  37. 'accepted' => 'Number of pixels followed by \'px\' or percent followed by % (e.g. "200px" or "100%").',
  38. 'default' => 'Image width',
  39. 'since' => '7.1'
  40. ],
  41. 'height' => [
  42. 'required' => false,
  43. 'name' => tra('Height'),
  44. 'description' => tra('Height in pixels or percentage. Default value is complete drawing height.'),
  45. 'filter' => 'text',
  46. 'accepted' => 'Number of pixels followed by \'px\' or percent followed by % (e.g. "200px" or "100%").',
  47. 'default' => 'Image height',
  48. 'since' => '7.1'
  49. ],
  50. 'archive' => [
  51. 'required' => false,
  52. 'name' => tra('Force Display Archive'),
  53. 'description' => tr('The latest revision of file is automatically shown, by setting archive to Yes (%0),
  54. it bypasses this check and shows the archive rather than the latest revision', '<code>y</code>'),
  55. 'filter' => 'alpha',
  56. 'default' => 'n',
  57. 'since' => '8.0',
  58. 'options' => [
  59. ['text' => '', 'value' => ''],
  60. ['text' => tra('Yes'), 'value' => 'y'],
  61. ['text' => tra('No'), 'value' => 'n']
  62. ]
  63. ],
  64. ],
  65. ];
  66. }
  67. function wikiplugin_draw($data, $params)
  68. {
  69. global $tiki_p_edit, $tiki_p_admin, $tiki_p_upload_files, $prefs, $user, $page;
  70. $headerlib = TikiLib::lib('header');
  71. $tikilib = TikiLib::lib('tiki');
  72. $smarty = TikiLib::lib('smarty');
  73. $filegallib = TikiLib::lib('filegal');
  74. $globalperms = Perms::get();
  75. extract(array_merge($params, []), EXTR_SKIP);
  76. static $drawIndex = 0;
  77. ++$drawIndex;
  78. if (! isset($id)) {
  79. //check permissions
  80. if ($tiki_p_upload_files != 'y') {
  81. return;
  82. }
  83. $label = tra('Draw New SVG Image');
  84. $page = htmlentities($page);
  85. $content = htmlentities($data);
  86. $formId = "form$drawIndex";
  87. $gals = $filegallib->list_file_galleries(0, -1, 'name_desc', $user);
  88. $galHtml = "";
  89. if (! function_exists('wp_draw_cmp')) {
  90. function wp_draw_cmp($a, $b)
  91. {
  92. return strcmp(strtolower($a["name"]), strtolower($b["name"]));
  93. }
  94. }
  95. usort($gals['data'], 'wp_draw_cmp');
  96. foreach ($gals['data'] as $gal) {
  97. if ($gal['name'] != "Wiki Attachments" && $gal['name'] != "Users File Galleries") {
  98. $galHtml .= "<option value='" . $gal['id'] . "'>" . $gal['name'] . "</option>";
  99. }
  100. }
  101. $in = tr(" in ");
  102. $headerlib->add_jq_onready(
  103. <<<JQ
  104. $('#newDraw$drawIndex').submit(function() {
  105. var form = $(this);
  106. var fields = form.serializeArray();
  107. $.wikiTrackingDraw = {
  108. fileId: 0,
  109. page: '$page',
  110. index: '$drawIndex',
  111. label: '$label',
  112. type: 'draw',
  113. content: '',
  114. params: {
  115. width: '',
  116. height: '',
  117. id: 0 //this will be updated
  118. }
  119. };
  120. $.each(fields, function(i, field){
  121. form.data(field.name.toLowerCase(), field.value);
  122. });
  123. return form.ajaxEditDraw();
  124. });
  125. JQ
  126. );
  127. return <<<EOF
  128. ~np~
  129. <form id="newDraw$drawIndex" method="get" action="tiki-edit_draw.php">
  130. <p>
  131. <input type="submit" class="btn btn-primary btn-sm" name="label" value="$label" class="newSvgButton" />$in
  132. <select name="galleryId">
  133. $galHtml
  134. </select>
  135. <input type="hidden" name="index" value="$drawIndex"/>
  136. <input type="hidden" name="page" value="$page"/>
  137. <input type="hidden" name="archive" value="$archive"/>
  138. </p>
  139. </form>
  140. ~/np~
  141. EOF;
  142. }
  143. $fileInfo = $filegallib->get_file_info($id);
  144. //this sets the image to latest in a group of archives
  145. if (! isset($archive) || $archive != 'y') {
  146. if (! empty($fileInfo['archiveId']) && $fileInfo['archiveId'] > 0) {
  147. $id = $fileInfo['archiveId'];
  148. $fileInfo = $filegallib->get_file_info($id);
  149. }
  150. }
  151. if (! isset($fileInfo['created'])) {
  152. return tra("File not found.");
  153. } else {
  154. $globalperms = Perms::get([ 'type' => 'file', 'object' => $fileInfo['fileId'] ]);
  155. if ($globalperms->view_file_gallery != 'y') {
  156. return "";
  157. }
  158. $label = tra('Edit SVG Image');
  159. $ret = '<div type="image/svg+xml" class="svgImage pluginImg table-responsive' . $fileInfo['fileId'] . '" style="' .
  160. (isset($height) ? "height: $height;" : "" ) .
  161. (isset($width) ? "width: $width;" : "" )
  162. . '">' . $fileInfo['data'] . '</div>';
  163. if ($globalperms->upload_files == 'y') {
  164. $smarty->loadPlugin('smarty_function_icon');
  165. $editicon = smarty_function_icon(['name' => 'edit'], $smarty->getEmptyInternalTemplate());
  166. $ret .= "<a href='tiki-edit_draw.php?fileId=$id&page=$page&index=$drawIndex&label=$label" .
  167. (isset($width) ? "&width=$width" : "") . (isset($height) ? "&height=$height" : "") .
  168. "' onclick='return $(this).ajaxEditDraw();' title='Edit: " . $fileInfo['filename'] .
  169. "' data-fileid='" . $fileInfo['fileId'] . "' data-galleryid='" . $fileInfo['galleryId'] . "'>" .
  170. $editicon . "</a>";
  171. }
  172. return '~np~' . $ret . '~/np~';
  173. }
  174. }