PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/wiki-plugins/wikiplugin_twitter.php

https://gitlab.com/ElvisAns/tiki
PHP | 228 lines | 208 code | 9 blank | 11 comment | 16 complexity | 4279fcba42c1c915d518bdd83d3b430e 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_twitter_info()
  8. {
  9. return [
  10. 'name' => tra('Twitter'),
  11. 'documentation' => 'PluginTwitter',
  12. 'description' => tra('Display the activity for a twitter account'),
  13. 'prefs' => ['wikiplugin_twitter'],
  14. 'body' => '',
  15. 'iconname' => 'twitter',
  16. 'introduced' => 7,
  17. 'params' => [
  18. 'tweet' => [
  19. 'required' => true,
  20. 'name' => tra('Twitter Path'),
  21. 'description' => tr(
  22. 'Depends on the type of timeline (Users, Collections, Favorites or Lists). For a
  23. User, it is the Account Name (like %0twitterdev%1), for Favorites, something like
  24. %0twitterdev/favorites%1. For lists, something like %0twitterdev/lists/listname%1, etc. ',
  25. '<code>',
  26. '</code>'
  27. ),
  28. 'since' => '7.0',
  29. 'filter' => 'text',
  30. 'default' => ''
  31. ],
  32. 'widgetId' => [
  33. 'required' => true,
  34. 'name' => tra('Widget Id'),
  35. 'description' => tra('Numeric identifier of the widget'),
  36. 'since' => '13.1',
  37. 'filter' => 'digits',
  38. 'default' => ''
  39. ],
  40. 'theme' => [
  41. 'required' => false,
  42. 'name' => tra('Theme'),
  43. 'description' => tr('Embedded timelines are available in light and dark themes for customization.
  44. The light theme is for pages that use a light colored background, while the dark theme is for pages
  45. that use a dark colored background. Default is %0light%1.', '<code>', '</code>'),
  46. 'since' => '13.1',
  47. 'filter' => 'alpha',
  48. 'options' => [
  49. ['text' => '', 'value' => ''],
  50. ['text' => tra('light'), 'value' => 'light'],
  51. ['text' => tra('dark'), 'value' => 'dark'],
  52. ],
  53. 'default' => 'light'
  54. ],
  55. 'tweetcolor' => [
  56. 'required' => false,
  57. 'name' => tra('Link Color'),
  58. 'description' => tra('Text color for individual tweets. Default is theme default.'),
  59. 'since' => '7.0',
  60. 'accepted' => tra('Valid HTML color codes (with beginning #) or names.'),
  61. 'filter' => 'text'
  62. ],
  63. 'tweetbg' => [
  64. 'required' => false,
  65. 'name' => tra('Border Color'),
  66. 'description' => tra('Change the border color used by the widget. Default is theme default.'),
  67. 'since' => '7.0',
  68. 'accepted' => tra('Valid HTML color codes (with beginning #) or names.'),
  69. 'filter' => 'text'
  70. ],
  71. 'height' => [
  72. 'required' => false,
  73. 'name' => tra('Height'),
  74. 'description' => tr('Height of widget in pixels. Default is %0.', '<code>300</code>'),
  75. 'since' => '7.0',
  76. 'filter' => 'digits',
  77. 'default' => 300
  78. ],
  79. 'width' => [
  80. 'required' => false,
  81. 'name' => tra('Width'),
  82. 'description' => tr(
  83. 'Width of widget in pixels or \'auto\' to fit to width of page. Default is %0.',
  84. '<code>auto</code>'
  85. ),
  86. 'accepted' => tra('Number of pixels or the word \'auto\'.'),
  87. 'since' => '7.0',
  88. 'filter' => 'text',
  89. 'default' => 'auto'
  90. ],
  91. 'noheader' => [
  92. 'required' => false,
  93. 'advanced' => true,
  94. 'name' => tra('No Header'),
  95. 'description' => tra('Default is with Header'),
  96. 'since' => '13.1',
  97. 'filter' => 'text',
  98. 'options' => [
  99. ['text' => tra('Header'), 'value' => ''],
  100. ['text' => tra('No Header'), 'value' => 'y'],
  101. ],
  102. ],
  103. 'nofooter' => [
  104. 'required' => false,
  105. 'advanced' => true,
  106. 'name' => tra('No Footer'),
  107. 'description' => tra('Default is with Footer'),
  108. 'since' => '13.1',
  109. 'filter' => 'text',
  110. 'options' => [
  111. ['text' => tra('Footer'), 'value' => ''],
  112. ['text' => tra('No Footer'), 'value' => 'y'],
  113. ],
  114. ],
  115. 'noborders' => [
  116. 'required' => false,
  117. 'advanced' => true,
  118. 'name' => tra('Layout Option: No Borders'),
  119. 'description' => tra('Default is with Borders'),
  120. 'since' => '13.1',
  121. 'filter' => 'text',
  122. 'options' => [
  123. ['text' => tra('Borders'), 'value' => ''],
  124. ['text' => tra('No Borders'), 'value' => 'y'],
  125. ],
  126. ],
  127. 'noscrollbar' => [
  128. 'required' => false,
  129. 'advanced' => true,
  130. 'name' => tra('No Scrollbar'),
  131. 'description' => tra('Default is with Scrollbar'),
  132. 'since' => '13.1',
  133. 'filter' => 'text',
  134. 'options' => [
  135. ['text' => tra('Scrollbar'), 'value' => ''],
  136. ['text' => tra('No Scrollbar'), 'value' => 'y'],
  137. ],
  138. ],
  139. 'shellbg' => [
  140. 'required' => false,
  141. 'advanced' => true,
  142. 'name' => tra('Transparent Background'),
  143. 'description' => tra('Transparent Shell Background. Default is theme default'),
  144. 'since' => '7.0',
  145. 'filter' => 'text',
  146. 'options' => [
  147. ['text' => tra('Theme default'), 'value' => ''],
  148. ['text' => tra('Transparent'), 'value' => 'transparent'],
  149. ],
  150. ],
  151. ],
  152. ];
  153. }
  154. function wikiplugin_twitter($data, $params)
  155. {
  156. $default = ['shellbg' => '', 'shellcolor' => '', 'tweetbg' => '', 'tweetcolor' => '', 'width' => 'auto', 'height' => 300];
  157. $params = array_merge($default, $params);
  158. extract($params, EXTR_SKIP);
  159. // Variables sanitizing
  160. $tweetlimit = (int)$tweetlimit;
  161. $tweetbg = preg_replace('/[^#0-9a-zA-Z]/', '', $tweetbg);
  162. $tweetcolor = preg_replace('/[^#0-9a-zA-Z]/', '', $tweetcolor);
  163. $tweet = preg_replace('/[^#0-9a-zA-Z%\/=]/', '', $tweet);
  164. $widgetId = preg_replace('/[^0-9]/', '', $widgetId);
  165. if ($theme != 'dark') {
  166. $theme = 'light';
  167. }
  168. $datachrome = [];
  169. if ($noheader == 'y') {
  170. $datachrome[] = 'noheader';
  171. }
  172. if ($nofooter == 'y') {
  173. $datachrome[] = 'nofooter';
  174. }
  175. if ($noborders == 'y') {
  176. $datachrome[] = 'noborders';
  177. }
  178. if ($noscrollbar == 'y') {
  179. $datachrome[] = 'noscrollbar';
  180. }
  181. if ($shellbg == 'transparent') {
  182. $datachrome[] = 'transparent' ;
  183. }
  184. if (count($datachrome) > 0) {
  185. $datachromehtml = "data-chrome=' " . implode(' ', $datachrome) . "' ";
  186. }
  187. if ($width != 'auto') {
  188. $width = preg_replace('/[^0-9]/', '', $width);
  189. }
  190. $height = (int)$height;
  191. // Inspiration: http://stackoverflow.com/questions/14303710/how-to-customize-twitter-widget-style
  192. // and https://dev.twitter.com/web/embedded-timelines
  193. // Note: the $widgetId is more important than the $tweet in defining what is displayed
  194. $html = "<a class=\"twitter-timeline\" href=\"https://twitter.com/$tweet\" data-widget-id=\"$widgetId\"
  195. $datachromehtml
  196. " . (empty($tweetlimit) ? '' : " data-tweet-limit='$tweetlimit'\n") .
  197. (empty($tweetcolor) ? "" : " data-link-color='$tweetcolor'\n") .
  198. (empty($tweetbg) ? "" : " data-border-color='$tweetbg'\n") .
  199. "data-theme='$theme'
  200. height='$height'
  201. width='$width'
  202. " .
  203. "data-show-replies='false'
  204. data-aria-polite='polite'>Tweets from @$tweet</a>
  205. <script>
  206. !function(d,s,id){
  207. var js,fjs=d.getElementsByTagName(s)[0];
  208. if(!d.getElementById(id)){
  209. js=d.createElement(s);
  210. js.id=id;
  211. js.src=\"http://platform.twitter.com/widgets.js\";
  212. fjs.parentNode.insertBefore(js,fjs);
  213. }
  214. }(document,'script','twitter-wjs');
  215. </script>";
  216. //debug return '~np~'.nl2br(htmlspecialchars($html)).'~/np~';
  217. //debug return '~np~'.$html.nl2br(htmlspecialchars($html)).'~/np~';
  218. return '~np~' . $html . '~/np~';
  219. }