4
0

bookmark.php 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. <?php
  2. // PLUGIN INFORMATION
  3. $GLOBALS['plugins'][]['Bookmark'] = array( // Plugin Name
  4. 'name' => 'Bookmark', // Plugin Name
  5. 'author' => 'leet1994', // Who wrote the plugin
  6. 'category' => 'Utilities', // One to Two Word Description
  7. 'link' => '', // Link to plugin info
  8. 'license' => 'personal,business', // License Type use , for multiple
  9. 'idPrefix' => 'BOOKMARK', // html element id prefix
  10. 'configPrefix' => 'BOOKMARK', // config file prefix for array items without the hypen
  11. 'dbPrefix' => 'BOOKMARK', // db prefix
  12. 'version' => '0.1.0', // SemVer of plugin
  13. 'image' => 'plugins/images/bookmark.png', // 1:1 non transparent image for plugin
  14. 'settings' => true, // does plugin need a settings page? true or false
  15. 'homepage' => false // Is plugin for use on homepage? true or false
  16. );
  17. // Logo image under Public Domain from https://openclipart.org/detail/182527/open-book
  18. class Bookmark extends Organizr
  19. {
  20. public function writeLog($type = 'error', $message = null, $username = null)
  21. {
  22. parent::writeLog($type, "Plugin 'Bookmark': " . $message, $username);
  23. }
  24. public function _checkRequest($request)
  25. {
  26. $result = false;
  27. if ($this->config['BOOKMARK-enabled'] && $this->hasDB()) {
  28. /*
  29. $response = [
  30. array(
  31. 'function' => 'query',
  32. 'query' => 'DROP TABLE IF EXISTS `BOOKMARK-categories`'
  33. ),
  34. array(
  35. 'function' => 'query',
  36. 'query' => 'DROP TABLE IF EXISTS `BOOKMARK-tabs`'
  37. )
  38. ];
  39. $this->processQueries($response);
  40. //*/
  41. if (!$this->_checkDatabaseTablesExist()) {
  42. $this->_createDatabaseTables();
  43. }
  44. $result = true;
  45. }
  46. return $result;
  47. }
  48. protected function _checkDatabaseTablesExist()
  49. {
  50. $response = [
  51. array(
  52. 'function' => 'fetchSingle',
  53. 'query' => array(
  54. "SELECT `name` FROM `sqlite_master` WHERE `type` = 'table' AND `name` = 'BOOKMARK-categories'"
  55. ),
  56. 'key' => 'BOOKMARK-categories'
  57. ),
  58. array(
  59. 'function' => 'fetchSingle',
  60. 'query' => array(
  61. "SELECT `name` FROM `sqlite_master` WHERE `type` = 'table' AND `name` = 'BOOKMARK-tabs'"
  62. ),
  63. 'key' => 'BOOKMARK-tabs'
  64. ),
  65. ];
  66. $data = $this->processQueries($response);
  67. return ($data["BOOKMARK-categories"] != false && $data["BOOKMARK-tabs"] != false);
  68. }
  69. protected function _createDatabaseTables()
  70. {
  71. $response = [
  72. array(
  73. 'function' => 'query',
  74. 'query' => 'CREATE TABLE `BOOKMARK-categories` (
  75. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  76. `order` INTEGER,
  77. `category` TEXT UNIQUE,
  78. `category_id` INTEGER,
  79. `default` INTEGER
  80. );'
  81. ),
  82. array(
  83. 'function' => 'query',
  84. 'query' => 'CREATE TABLE `BOOKMARK-tabs` (
  85. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  86. `order` INTEGER,
  87. `category_id` INTEGER,
  88. `name` TEXT,
  89. `url` TEXT,
  90. `enabled` INTEGER,
  91. `group_id` INTEGER,
  92. `image` TEXT,
  93. `background_color` TEXT,
  94. `text_color` TEXT
  95. );'
  96. )
  97. ];
  98. $this->processQueries($response);
  99. }
  100. public function _getSettings()
  101. {
  102. return array(
  103. 'custom' => '
  104. <div class="row">
  105. <div class="col-lg-12">
  106. <div class="panel panel-info">
  107. <div class="panel-heading">
  108. <span lang="en">Notice</span>
  109. </div>
  110. <div class="panel-wrapper collapse in" aria-expanded="true">
  111. <div class="panel-body">
  112. <ul class="list-icons">
  113. <li><i class="fa fa-chevron-right text-info"></i> Add tab that points to <i>api/v2/plugins/bookmark/page</i> and set it\'s type to <i>Organizr</i>.</li>
  114. <li><i class="fa fa-chevron-right text-info"></i> Create Bookmark categories in the new area in <i>Tab Editor</i>.</li>
  115. <li><i class="fa fa-chevron-right text-info"></i> Create Bookmark tabs in the new area in <i>Tab Editor</i>.</li>
  116. <li><i class="fa fa-chevron-right text-info"></i> Open your custom Bookmark page via menu.</li>
  117. </ul>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. '
  124. );
  125. }
  126. public function _getPage()
  127. {
  128. $script = '
  129. <script>
  130. var styles = `
  131. #BOOKMARK-wrapper {
  132. display: flex;
  133. flex-direction: column;
  134. justify-content: flex-start;
  135. }
  136. .BOOKMARK-category {
  137. text-align: center;
  138. margin-bottom: 40px;
  139. }
  140. .BOOKMARK-category-title {
  141. font-weight: 500;
  142. color: #ddd;
  143. font-size: large;
  144. }
  145. .BOOKMARK-category-content {
  146. width: 80%;
  147. margin: 0 auto;
  148. display: flex;
  149. flex-flow: row wrap;
  150. justify-content: center;
  151. }
  152. .BOOKMARK-tab {
  153. display: inline-flex;
  154. justify-content: space-between;
  155. align-items: center;
  156. margin: 10px 10px 0 10px;
  157. height: 50px;
  158. width: 200px;
  159. overflow: hidden;
  160. border: 1px solid;
  161. border-radius: 5px;
  162. transition: all 0.2s ease-in-out;
  163. }
  164. .BOOKMARK-tab:hover {
  165. filter: brightness(80%);
  166. }
  167. .BOOKMARK-tab-image {
  168. width: 50px;
  169. max-width: 50px;
  170. height: 100%;
  171. flex-grow: 33;
  172. }
  173. .BOOKMARK-tab-image img {
  174. width: 100%;
  175. height: 100%;
  176. padding: 8px;
  177. object-fit: contain;
  178. }
  179. .BOOKMARK-tab-image i {
  180. width: 100%;
  181. height: 100%;
  182. line-height: 44px;
  183. font-size: 2.2em;
  184. }
  185. .BOOKMARK-tab-title {
  186. flex-grow: 67;
  187. padding: 0 5px;
  188. color: white;
  189. text-align: left;
  190. font-weight: 500;
  191. }
  192. `;
  193. var styleSheet = document.createElement("style");
  194. styleSheet.type = "text/css";
  195. styleSheet.innerText = styles;
  196. document.head.appendChild(styleSheet);
  197. </script>';
  198. $bookmarks = '<div id="BOOKMARK-wrapper">';
  199. foreach ($this->_getAllCategories() as $category) {
  200. $tabs = $this->_getRelevantTabsForCategory($category['category_id']);
  201. if (count($tabs) == 0) continue;
  202. $bookmarks .= '<div class="BOOKMARK-category">
  203. <div class="BOOKMARK-category-title">
  204. ' . $category['category'] . '
  205. </div>
  206. <div class="BOOKMARK-category-content">';
  207. foreach ($tabs as $tab) {
  208. $bookmarks .= '<a href="'.$tab['url'].'" target="_SELF">
  209. <div class="BOOKMARK-tab"
  210. style="border-color: '.$this->adjustBrightness($tab['background_color'], 0.3).'; background: linear-gradient(90deg, '.$this->adjustBrightness($tab['background_color'], -0.3).' 0%, '.$tab['background_color'].' 70%, '.$this->adjustBrightness($tab['background_color'], 0.1).' 100%);">
  211. <span class="BOOKMARK-tab-image">'.$this->_iconPrefix($tab['image']).'</span>
  212. <span class="BOOKMARK-tab-title" style="color: '.$tab['text_color'].';">'.$tab['name'].'</span>
  213. </div>
  214. </a>';
  215. }
  216. $bookmarks .= '</div></div>';
  217. }
  218. $bookmarks .= '</div>';
  219. return $script . $bookmarks;
  220. }
  221. protected function _iconPrefix($source)
  222. {
  223. $tabIcon = explode("::", $source);
  224. $icons = array(
  225. "materialize" => "mdi mdi-",
  226. "fontawesome" => "fa fa-",
  227. "themify" => "ti-",
  228. "simpleline" => "icon-",
  229. "weathericon" => "wi wi-",
  230. "alphanumeric" => "fa-fw",
  231. );
  232. if (is_array($tabIcon) && count($tabIcon) == 2) {
  233. if ($tabIcon[0] !== 'url' && $tabIcon[0] !== 'alphanumeric') {
  234. return '<i class="' . $icons[$tabIcon[0]] . $tabIcon[1] . '"></i>';
  235. } else if ($tabIcon[0] == 'alphanumeric') {
  236. return '<i>' . $tabIcon[1] . '</i>';
  237. } else {
  238. return '<img src="' . $tabIcon[1] . '" alt="tabIcon" />';
  239. }
  240. } else {
  241. return '<img src="' . $source . '" alt="tabIcon" />';
  242. }
  243. }
  244. protected function _getAllCategories()
  245. {
  246. $response = [
  247. array(
  248. 'function' => 'fetchAll',
  249. 'query' => 'SELECT * FROM `BOOKMARK-categories` ORDER BY `order` ASC'
  250. )
  251. ];
  252. return $this->processQueries($response);
  253. }
  254. protected function _getRelevantTabsForCategory($category_id)
  255. {
  256. $response = [
  257. array(
  258. 'function' => 'fetchAll',
  259. 'query' => array(
  260. "SELECT * FROM `BOOKMARK-tabs` WHERE `enabled`='1' AND `category_id`=? AND `group_id`>=? ORDER BY `order` ASC",
  261. $category_id,
  262. $this->getUserLevel()
  263. )
  264. )
  265. ];
  266. return $this->processQueries($response);
  267. }
  268. public function _getTabs()
  269. {
  270. $response = [
  271. array(
  272. 'function' => 'fetchAll',
  273. 'query' => 'SELECT * FROM `BOOKMARK-tabs` ORDER BY `order` ASC',
  274. 'key' => 'tabs'
  275. ),
  276. array(
  277. 'function' => 'fetchAll',
  278. 'query' => 'SELECT * FROM `BOOKMARK-categories` ORDER BY `order` ASC',
  279. 'key' => 'categories'
  280. ),
  281. array(
  282. 'function' => 'fetchAll',
  283. 'query' => 'SELECT * FROM `groups` ORDER BY `group_id` ASC',
  284. 'key' => 'groups'
  285. )
  286. ];
  287. return $this->processQueries($response);
  288. }
  289. // Tabs
  290. public function _getSettingsTabEditorBookmarkTabsPage()
  291. {
  292. $iconSelectors = '
  293. $(".bookmarkTabIconIconList").select2({
  294. ajax: {
  295. url: \'api/v2/icon\',
  296. data: function (params) {
  297. var query = {
  298. search: params.term,
  299. page: params.page || 1
  300. }
  301. return query;
  302. },
  303. processResults: function (data, params) {
  304. params.page = params.page || 1;
  305. return {
  306. results: data.response.data.results,
  307. pagination: {
  308. more: (params.page * 20) < data.response.data.total
  309. }
  310. };
  311. },
  312. //cache: true
  313. },
  314. placeholder: \'Search for an icon\',
  315. templateResult: formatIcon,
  316. templateSelection: formatIcon
  317. });
  318. $(".bookmarkTabIconImageList").select2({
  319. ajax: {
  320. url: \'api/v2/image/select\',
  321. data: function (params) {
  322. var query = {
  323. search: params.term,
  324. page: params.page || 1
  325. }
  326. return query;
  327. },
  328. processResults: function (data, params) {
  329. params.page = params.page || 1;
  330. return {
  331. results: data.response.data.results,
  332. pagination: {
  333. more: (params.page * 20) < data.response.data.total
  334. }
  335. };
  336. },
  337. //cache: true
  338. },
  339. placeholder: \'Search for an image\',
  340. templateResult: formatImage,
  341. templateSelection: formatImage
  342. });
  343. ';
  344. return '
  345. <script>
  346. buildBookmarkTabEditor();
  347. !function(a){function f(a,b){if(!(a.originalEvent.touches.length>1)){a.preventDefault();var c=a.originalEvent.changedTouches[0],d=document.createEvent("MouseEvents");d.initMouseEvent(b,!0,!0,window,1,c.screenX,c.screenY,c.clientX,c.clientY,!1,!1,!1,!1,0,null),a.target.dispatchEvent(d)}}if(a.support.touch="ontouchend"in document,a.support.touch){var e,b=a.ui.mouse.prototype,c=b._mouseInit,d=b._mouseDestroy;b._touchStart=function(a){var b=this;!e&&b._mouseCapture(a.originalEvent.changedTouches[0])&&(e=!0,b._touchMoved=!1,f(a,"mouseover"),f(a,"mousemove"),f(a,"mousedown"))},b._touchMove=function(a){e&&(this._touchMoved=!0,f(a,"mousemove"))},b._touchEnd=function(a){e&&(f(a,"mouseup"),f(a,"mouseout"),this._touchMoved||f(a,"click"),e=!1)},b._mouseInit=function(){var b=this;b.element.bind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),c.call(b)},b._mouseDestroy=function(){var b=this;b.element.unbind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),d.call(b)}}}(jQuery);
  348. $( \'#bookmarkTabEditorTable\' ).sortable({
  349. stop: function () {
  350. $(\'input.order\').each(function(idx) {
  351. $(this).val(idx + 1);
  352. });
  353. var newTabs = $( "#submit-bookmark-tabs-form" ).serializeToJSON();
  354. newBookmarkTabsGlobal = newTabs;
  355. $(\'.saveBookmarkTabOrderButton\').removeClass(\'hidden\');
  356. //submitTabOrder(newTabs);
  357. }
  358. });
  359. $( \'#bookmarkTabEditorTable\' ).disableSelection();
  360. ' . $iconSelectors . '
  361. </script>
  362. <div class="panel bg-org panel-info">
  363. <div class="panel-heading">
  364. <span lang="en">Bookmark Tab Editor</span>
  365. <button type="button" class="btn btn-info btn-circle pull-right popup-with-form m-r-5" href="#new-bookmark-tab-form" data-effect="mfp-3d-unfold"><i class="fa fa-plus"></i> </button>
  366. <button onclick="submitBookmarkTabOrder(newBookmarkTabsGlobal)" class="btn btn-sm btn-info btn-rounded waves-effect waves-light pull-right animated loop-animation rubberBand m-r-20 saveBookmarkTabOrderButton hidden" type="button"><span class="btn-label"><i class="fa fa-save"></i></span><span lang="en">Save Tab Order</span></button>
  367. </div>
  368. <div class="table-responsive">
  369. <form id="submit-bookmark-tabs-form" onsubmit="return false;">
  370. <table class="table table-hover manage-u-table">
  371. <thead>
  372. <tr>
  373. <th width="70" class="text-center">#</th>
  374. <th lang="en">NAME</th>
  375. <th lang="en">CATEGORY</th>
  376. <th lang="en">GROUP</th>
  377. <th lang="en" style="text-align:center">ACTIVE</th>
  378. <th lang="en" style="text-align:center">EDIT</th>
  379. <th lang="en" style="text-align:center">DELETE</th>
  380. </tr>
  381. </thead>
  382. <tbody id="bookmarkTabEditorTable">
  383. <td class="text-center" colspan="12"><i class="fa fa-spin fa-spinner"></i></td>
  384. </tbody>
  385. </table>
  386. </form>
  387. </div>
  388. </div>
  389. <form id="new-bookmark-tab-form" class="mfp-hide white-popup-block mfp-with-anim">
  390. <h1 lang="en">Add New Tab</h1>
  391. <fieldset style="border:0;">
  392. <div class="form-group">
  393. <label class="control-label" for="new-bookmark-tab-form-inputNameNew" lang="en">Tab Name</label>
  394. <input type="text" class="form-control" id="new-bookmark-tab-form-inputNameNew" name="name" required="" autofocus>
  395. </div>
  396. <div class="form-group">
  397. <label class="control-label" for="new-bookmark-tab-form-inputURLNew" lang="en">Tab URL</label>
  398. <input type="text" class="form-control" id="new-bookmark-tab-form-inputURLNew" name="url" required="">
  399. </div>
  400. <div class="row">
  401. <div class="form-group col-lg-4">
  402. <label class="control-label" for="new-bookmark-tab-form-chooseImage" lang="en">Choose Image</label>
  403. <select class="form-control bookmarkTabIconImageList" id="new-bookmark-tab-form-chooseImage" name="chooseImage"><option lang="en">Select or type Image</option></select>
  404. </div>
  405. <div class="form-group col-lg-4">
  406. <label class="control-label" for="new-bookmark-tab-form-chooseIcon" lang="en">Choose Icon</label>
  407. <select class="form-control bookmarkTabIconIconList" id="new-bookmark-tab-form-chooseIcon" name="chooseIcon"><option lang="en">Select or type Icon</option></select>
  408. </div>
  409. <div class="form-group col-lg-4">
  410. <label class="control-label" for="new-bookmark-tab-form-chooseBlackberry" lang="en">Choose Blackberry Theme Icon</label>
  411. <button id="new-bookmark-tab-form-chooseBlackberry" class="btn btn-xs btn-primary waves-effect waves-light form-control" onclick="showBlackberryThemes(\'new-bookmark-tab-form-inputImageNew\');" type="button">
  412. <i class="fa fa-search"></i>&nbsp; <span lang="en">Choose</span>
  413. </button>
  414. </div>
  415. </div>
  416. <div class="form-group">
  417. <label class="control-label" for="new-bookmark-tab-form-inputImageNew" lang="en">Tab Image</label>
  418. <input type="text" class="form-control" id="new-bookmark-tab-form-inputImageNew" name="image" required="">
  419. </div>
  420. <div class="row">
  421. <div class="form-group col-lg-4">
  422. <label class="control-label" for="new-bookmark-tab-form-inputBackgroundColorNew" lang="en">Background Color</label>
  423. <input type="text" class="form-control" id="new-bookmark-tab-form-inputBackgroundColorNew" name="background_color" required="">
  424. </div>
  425. <div class="form-group col-lg-4">
  426. <label class="control-label" for="new-bookmark-tab-form-inputTextColorNew" lang="en">Text Color</label>
  427. <input type="text" class="form-control" id="new-bookmark-tab-form-inputTextColorNew" name="text_color" required="">
  428. </div>
  429. </div>
  430. </fieldset>
  431. <button class="btn btn-sm btn-info btn-rounded waves-effect waves-light pull-right row b-none addNewBookmarkTab" type="button"><span class="btn-label"><i class="fa fa-plus"></i></span><span lang="en">Add Tab</span></button>
  432. <div class="clearfix"></div>
  433. </form>
  434. <form id="edit-bookmark-tab-form" class="mfp-hide white-popup-block mfp-with-anim">
  435. <input type="hidden" name="id" value="x">
  436. <span class="hidden" id="originalBookmarkTabName"></span>
  437. <h1 lang="en">Edit Tab</h1>
  438. <fieldset style="border:0;">
  439. <div class="form-group">
  440. <label class="control-label" for="edit-bookmark-tab-form-inputName" lang="en">Tab Name</label>
  441. <input type="text" class="form-control" id="edit-bookmark-tab-form-inputName" name="name" required="" autofocus>
  442. </div>
  443. <div class="form-group">
  444. <label class="control-label" for="edit-bookmark-tab-form-inputURL" lang="en">Tab URL</label>
  445. <input type="text" class="form-control" id="edit-bookmark-tab-form-inputURL" name="url" required="">
  446. </div>
  447. <div class="row">
  448. <div class="form-group col-lg-4">
  449. <label class="control-label" for="edit-bookmark-tab-form-chooseImage" lang="en">Choose Image</label>
  450. <select class="form-control bookmarkTabIconImageList" id="edit-bookmark-tab-form-chooseImage" name="chooseImage"><option lang="en">Select or type Image</option></select>
  451. </div>
  452. <div class="form-group col-lg-4">
  453. <label class="control-label" for="edit-bookmark-tab-form-chooseIcon" lang="en">Choose Icon</label>
  454. <select class="form-control bookmarkTabIconIconList" id="edit-bookmark-tab-form-chooseIcon" name="chooseIcon"><option lang="en">Select or type Icon</option></select>
  455. </div>
  456. <div class="form-group col-lg-4">
  457. <label class="control-label" for="edit-bookmark-tab-form-chooseBlackberry" lang="en">Choose Blackberry Theme Icon</label>
  458. <button id="edit-bookmark-tab-form-chooseBlackberry" class="btn btn-xs btn-primary waves-effect waves-light form-control" onclick="showBlackberryThemes(\'edit-bookmark-tab-form-inputImage\');" type="button">
  459. <i class="fa fa-search"></i>&nbsp; <span lang="en">Choose</span>
  460. </button>
  461. </div>
  462. </div>
  463. <div class="form-group">
  464. <label class="control-label" for="edit-bookmark-tab-form-inputImage" lang="en">Tab Image</label>
  465. <input type="text" class="form-control" id="edit-bookmark-tab-form-inputImage" name="image" required="">
  466. </div>
  467. <div class="row">
  468. <div class="form-group col-lg-4">
  469. <label class="control-label" for="new-bookmark-tab-form-inputBackgroundColor" lang="en">Background Color</label>
  470. <input type="text" class="form-control" id="new-bookmark-tab-form-inputBackgroundColor" name="background_color" required="">
  471. </div>
  472. <div class="form-group col-lg-4">
  473. <label class="control-label" for="new-bookmark-tab-form-inputTextColor" lang="en">Text Color</label>
  474. <input type="text" class="form-control" id="new-bookmark-tab-form-inputTextColor" name="text_color" required="">
  475. </div>
  476. </div>
  477. </fieldset>
  478. <button class="btn btn-sm btn-info btn-rounded waves-effect waves-light pull-right row b-none editBookmarkTab" type="button"><span class="btn-label"><i class="fa fa-check"></i></span><span lang="en">Edit Tab</span></button>
  479. <div class="clearfix"></div>
  480. </form>
  481. ';
  482. }
  483. public function _isBookmarkTabNameTaken($name, $id = null)
  484. {
  485. if ($id) {
  486. $response = [
  487. array(
  488. 'function' => 'fetchAll',
  489. 'query' => array(
  490. 'SELECT * FROM `BOOKMARK-tabs` WHERE `name` LIKE ? AND `id` != ?',
  491. $name,
  492. $id
  493. )
  494. ),
  495. ];
  496. } else {
  497. $response = [
  498. array(
  499. 'function' => 'fetchAll',
  500. 'query' => array(
  501. 'SELECT * FROM `BOOKMARK-tabs` WHERE `name` LIKE ?',
  502. $name
  503. )
  504. ),
  505. ];
  506. }
  507. return $this->processQueries($response);
  508. }
  509. public function _getNextBookmarkTabOrder()
  510. {
  511. $response = [
  512. array(
  513. 'function' => 'fetchSingle',
  514. 'query' => array(
  515. 'SELECT `order` from `BOOKMARK-tabs` ORDER BY `order` DESC'
  516. )
  517. ),
  518. ];
  519. return $this->processQueries($response);
  520. }
  521. public function _getBookmarkTabById($id)
  522. {
  523. $response = [
  524. array(
  525. 'function' => 'fetch',
  526. 'query' => array(
  527. 'SELECT * FROM `BOOKMARK-tabs` WHERE `id` = ?',
  528. $id
  529. )
  530. ),
  531. ];
  532. return $this->processQueries($response);
  533. }
  534. public function _getTabByIdCheckUser($id)
  535. {
  536. $tabInfo = $this->_getBookmarkTabById($id);
  537. if ($tabInfo) {
  538. if ($this->qualifyRequest($tabInfo['group_id'], true)) {
  539. return $tabInfo;
  540. }
  541. } else {
  542. $this->setAPIResponse('error', 'id not found', 404);
  543. return false;
  544. }
  545. }
  546. public function _deleteTab($id)
  547. {
  548. $response = [
  549. array(
  550. 'function' => 'query',
  551. 'query' => array(
  552. 'DELETE FROM `BOOKMARK-tabs` WHERE id = ?',
  553. $id
  554. )
  555. ),
  556. ];
  557. $tabInfo = $this->_getBookmarkTabById($id);
  558. if ($tabInfo) {
  559. $this->writeLog('success', 'Tab Delete Function - Deleted Tab [' . $tabInfo['name'] . ']', $this->user['username']);
  560. $this->setAPIResponse('success', 'Tab deleted', 204);
  561. return $this->processQueries($response);
  562. } else {
  563. $this->setAPIResponse('error', 'id not found', 404);
  564. return false;
  565. }
  566. }
  567. public function _addTab($array)
  568. {
  569. if (!$array) {
  570. $this->setAPIResponse('error', 'no data was sent', 422);
  571. return null;
  572. }
  573. $array = $this->checkKeys($this->getTableColumnsFormatted('BOOKMARK-tabs'), $array);
  574. $array['group_id'] = ($array['group_id']) ?? $this->getDefaultGroupId();
  575. $array['category_id'] = ($array['category_id']) ?? $this->_getDefaultBookmarkCategoryId();
  576. $array['enabled'] = ($array['enabled']) ?? 0;
  577. $array['order'] = ($array['order']) ?? $this->_getNextBookmarkTabOrder() + 1;
  578. if (array_key_exists('name', $array)) {
  579. if ($this->_isBookmarkTabNameTaken($array['name'])) {
  580. $this->setAPIResponse('error', 'Tab name: ' . $array['name'] . ' is already taken', 409);
  581. return false;
  582. }
  583. } else {
  584. $this->setAPIResponse('error', 'Tab name was not supplied', 422);
  585. return false;
  586. }
  587. if (!array_key_exists('url', $array)) {
  588. $this->setAPIResponse('error', 'Tab url was not supplied', 422);
  589. return false;
  590. }
  591. if (!array_key_exists('image', $array)) {
  592. $this->setAPIResponse('error', 'Tab image was not supplied', 422);
  593. return false;
  594. }
  595. if (array_key_exists('background_color', $array)) {
  596. if(!$this->_checkColorHexCode($array['background_color'])){
  597. $this->setAPIResponse('error', 'Tab background color is invalid', 422);
  598. return false;
  599. }
  600. }
  601. else{
  602. $this->setAPIResponse('error', 'Tab background color was not supplied', 422);
  603. return false;
  604. }
  605. if (array_key_exists('text_color', $array)) {
  606. if(!$this->_checkColorHexCode($array['text_color'])){
  607. $this->setAPIResponse('error', 'Tab text color is invalid', 422);
  608. return false;
  609. }
  610. }
  611. else{
  612. $this->setAPIResponse('error', 'Tab text color was not supplied', 422);
  613. return false;
  614. }
  615. $response = [
  616. array(
  617. 'function' => 'query',
  618. 'query' => array(
  619. 'INSERT INTO [BOOKMARK-tabs]',
  620. $array
  621. )
  622. ),
  623. ];
  624. $this->setAPIResponse(null, 'Tab added');
  625. $this->writeLog('success', 'Tab Editor Function - Added Tab for [' . $array['name'] . ']', $this->user['username']);
  626. return $this->processQueries($response);
  627. }
  628. public function _updateTab($id, $array)
  629. {
  630. if (!$id || $id == '') {
  631. $this->setAPIResponse('error', 'id was not set', 422);
  632. return null;
  633. }
  634. if (!$array) {
  635. $this->setAPIResponse('error', 'no data was sent', 422);
  636. return null;
  637. }
  638. $tabInfo = $this->_getBookmarkTabById($id);
  639. if ($tabInfo) {
  640. $array = $this->checkKeys($tabInfo, $array);
  641. } else {
  642. $this->setAPIResponse('error', 'No tab info found', 404);
  643. return false;
  644. }
  645. if (array_key_exists('name', $array)) {
  646. if ($this->_isBookmarkTabNameTaken($array['name'], $id)) {
  647. $this->setAPIResponse('error', 'Tab name: ' . $array['name'] . ' is already taken', 409);
  648. return false;
  649. }
  650. }
  651. if (array_key_exists('background_color', $array)) {
  652. if(!$this->_checkColorHexCode($array['background_color'])){
  653. $this->setAPIResponse('error', 'Tab background color is invalid', 422);
  654. return false;
  655. }
  656. }
  657. if (array_key_exists('text_color', $array)) {
  658. if(!$this->_checkColorHexCode($array['text_color'])){
  659. $this->setAPIResponse('error', 'Tab text color is invalid', 422);
  660. return false;
  661. }
  662. }
  663. $response = [
  664. array(
  665. 'function' => 'query',
  666. 'query' => array(
  667. 'UPDATE `BOOKMARK-tabs` SET',
  668. $array,
  669. 'WHERE id = ?',
  670. $id
  671. )
  672. ),
  673. ];
  674. $this->setAPIResponse(null, 'Tab info updated');
  675. $this->writeLog('success', 'Tab Editor Function - Edited Tab Info for [' . $tabInfo['name'] . ']', $this->user['username']);
  676. return $this->processQueries($response);
  677. }
  678. public function _updateTabOrder($array)
  679. {
  680. if (count($array) >= 1) {
  681. foreach ($array as $tab) {
  682. if (count($tab) !== 2) {
  683. $this->setAPIResponse('error', 'data is malformed', 422);
  684. break;
  685. }
  686. $id = $tab['id'] ?? null;
  687. $order = $tab['order'] ?? null;
  688. if ($id && $order) {
  689. $response = [
  690. array(
  691. 'function' => 'query',
  692. 'query' => array(
  693. 'UPDATE `BOOKMARK-tabs` set `order` = ? WHERE `id` = ?',
  694. $order,
  695. $id
  696. )
  697. ),
  698. ];
  699. $this->processQueries($response);
  700. $this->setAPIResponse(null, 'Tab Order updated');
  701. } else {
  702. $this->setAPIResponse('error', 'data is malformed', 422);
  703. }
  704. }
  705. } else {
  706. $this->setAPIResponse('error', 'data is empty or not in array', 422);
  707. return false;
  708. }
  709. }
  710. // Categories
  711. public function _getSettingsTabEditorBookmarkCategoriesPage()
  712. {
  713. return '
  714. <script>
  715. buildBookmarkCategoryEditor();
  716. $( \'#bookmarkCategoryEditorTable\' ).sortable({
  717. stop: function () {
  718. var inputs = $(\'input.order\');
  719. var nbElems = inputs.length;
  720. inputs.each(function(idx) {
  721. $(this).val(idx + 1);
  722. });
  723. submitBookmarkCategoryOrder();
  724. }
  725. });
  726. </script>
  727. <div class="panel bg-org panel-info">
  728. <div class="panel-heading">
  729. <span lang="en">Bookmark Category Editor</span>
  730. <button type="button" class="btn btn-success btn-circle pull-right popup-with-form m-r-5" href="#new-bookmark-category-form" data-effect="mfp-3d-unfold"><i class="fa fa-plus"></i> </button>
  731. </div>
  732. <div class="table-responsive">
  733. <form id="submit-bookmark-categories-form" onsubmit="return false;">
  734. <table class="table table-hover manage-u-table">
  735. <thead>
  736. <tr>
  737. <th lang="en">NAME</th>
  738. <th lang="en" style="text-align:center">TABS</th>
  739. <th lang="en" style="text-align:center">DEFAULT</th>
  740. <th lang="en" style="text-align:center">EDIT</th>
  741. <th lang="en" style="text-align:center">DELETE</th>
  742. </tr>
  743. </thead>
  744. <tbody id="bookmarkCategoryEditorTable"><td class="text-center" colspan="6"><i class="fa fa-spin fa-spinner"></i></td></tbody>
  745. </table>
  746. </form>
  747. </div>
  748. </div>
  749. <form id="new-bookmark-category-form" class="mfp-hide white-popup-block mfp-with-anim">
  750. <h1 lang="en">Add New Bookmark Category</h1>
  751. <fieldset style="border:0;">
  752. <div class="form-group">
  753. <label class="control-label" for="new-bookmark-category-form-inputNameNew" lang="en">Category Name</label>
  754. <input type="text" class="form-control" id="new-bookmark-category-form-inputNameNew" name="category" required="" autofocus>
  755. </div>
  756. </fieldset>
  757. <button class="btn btn-sm btn-info btn-rounded waves-effect waves-light pull-right row b-none addNewBookmarkCategory" type="button"><span class="btn-label"><i class="fa fa-plus"></i></span><span lang="en">Add Category</span></button>
  758. <div class="clearfix"></div>
  759. </form>
  760. <form id="edit-bookmark-category-form" class="mfp-hide white-popup-block mfp-with-anim">
  761. <input type="hidden" name="id" value="">
  762. <h1 lang="en">Edit Category</h1>
  763. <fieldset style="border:0;">
  764. <div class="form-group">
  765. <label class="control-label" for="edit-bookmark-category-form-inputName" lang="en">Category Name</label>
  766. <input type="text" class="form-control" id="edit-bookmark-category-form-inputName" name="category" required="" autofocus>
  767. </div>
  768. </fieldset>
  769. <button class="btn btn-sm btn-info btn-rounded waves-effect waves-light pull-right row b-none editBookmarkCategory" type="button"><span class="btn-label"><i class="fa fa-plus"></i></span><span lang="en">Edit Category</span></button>
  770. <div class="clearfix"></div>
  771. </form>
  772. ';
  773. }
  774. public function _getDefaultBookmarkCategoryId()
  775. {
  776. $response = [
  777. array(
  778. 'function' => 'fetchSingle',
  779. 'query' => array(
  780. 'SELECT `category_id` FROM `BOOKMARK-categories` WHERE `default` = 1'
  781. )
  782. ),
  783. ];
  784. return $this->processQueries($response);
  785. }
  786. public function _getNextBookmarkCategoryOrder()
  787. {
  788. $response = [
  789. array(
  790. 'function' => 'fetchSingle',
  791. 'query' => array(
  792. 'SELECT `order` from `BOOKMARK-categories` ORDER BY `order` DESC'
  793. )
  794. ),
  795. ];
  796. return $this->processQueries($response);
  797. }
  798. public function _getNextBookmarkCategoryId()
  799. {
  800. $response = [
  801. array(
  802. 'function' => 'fetchSingle',
  803. 'query' => array(
  804. 'SELECT `category_id` from `BOOKMARK-categories` ORDER BY `category_id` DESC'
  805. )
  806. ),
  807. ];
  808. return $this->processQueries($response);
  809. }
  810. public function _isBookmarkCategoryNameTaken($name, $id = null)
  811. {
  812. if ($id) {
  813. $response = [
  814. array(
  815. 'function' => 'fetchAll',
  816. 'query' => array(
  817. 'SELECT * FROM `BOOKMARK-categories` WHERE `category` LIKE ? AND `id` != ?',
  818. $name,
  819. $id
  820. )
  821. ),
  822. ];
  823. } else {
  824. $response = [
  825. array(
  826. 'function' => 'fetchAll',
  827. 'query' => array(
  828. 'SELECT * FROM `BOOKMARK-categories` WHERE `category` LIKE ?',
  829. $name
  830. )
  831. ),
  832. ];
  833. }
  834. return $this->processQueries($response);
  835. }
  836. public function _getBookmarkCategoryById($id)
  837. {
  838. $response = [
  839. array(
  840. 'function' => 'fetch',
  841. 'query' => array(
  842. 'SELECT * FROM `BOOKMARK-categories` WHERE `id` = ?',
  843. $id
  844. )
  845. ),
  846. ];
  847. return $this->processQueries($response);
  848. }
  849. public function _clearBookmarkCategoryDefault()
  850. {
  851. $response = [
  852. array(
  853. 'function' => 'query',
  854. 'query' => array(
  855. 'UPDATE `BOOKMARK-categories` SET `default` = 0'
  856. )
  857. ),
  858. ];
  859. return $this->processQueries($response);
  860. }
  861. public function _addCategory($array)
  862. {
  863. if (!$array) {
  864. $this->setAPIResponse('error', 'no data was sent', 422);
  865. return null;
  866. }
  867. $array = $this->checkKeys($this->getTableColumnsFormatted('BOOKMARK-categories'), $array);
  868. $array['default'] = ($array['default']) ?? 0;
  869. $array['order'] = ($array['order']) ?? $this->_getNextBookmarkCategoryOrder() + 1;
  870. $array['category_id'] = ($array['category_id']) ?? $this->_getNextBookmarkCategoryId() + 1;
  871. if (array_key_exists('category', $array)) {
  872. if ($this->_isBookmarkCategoryNameTaken($array['category'])) {
  873. $this->setAPIResponse('error', 'Category name: ' . $array['category'] . ' is already taken', 409);
  874. return false;
  875. }
  876. } else {
  877. $this->setAPIResponse('error', 'Category name was not supplied', 422);
  878. return false;
  879. }
  880. $response = [
  881. array(
  882. 'function' => 'query',
  883. 'query' => array(
  884. 'INSERT INTO [BOOKMARK-categories]',
  885. $array
  886. )
  887. ),
  888. ];
  889. $this->setAPIResponse(null, 'Category added');
  890. $this->writeLog('success', 'Category Editor Function - Added Category for [' . $array['category'] . ']', $this->user['username']);
  891. $result = $this->processQueries($response);
  892. $this->_correctDefaultCategory();
  893. return $result;
  894. }
  895. public function _updateCategory($id, $array)
  896. {
  897. if (!$id || $id == '') {
  898. $this->setAPIResponse('error', 'id was not set', 422);
  899. return null;
  900. }
  901. if (!$array) {
  902. $this->setAPIResponse('error', 'no data was sent', 422);
  903. return null;
  904. }
  905. $categoryInfo = $this->_getBookmarkCategoryById($id);
  906. if ($categoryInfo) {
  907. $array = $this->checkKeys($categoryInfo, $array);
  908. } else {
  909. $this->setAPIResponse('error', 'No category info found', 404);
  910. return false;
  911. }
  912. if (array_key_exists('category', $array)) {
  913. if ($this->_isBookmarkCategoryNameTaken($array['category'], $id)) {
  914. $this->setAPIResponse('error', 'Category name: ' . $array['category'] . ' is already taken', 409);
  915. return false;
  916. }
  917. }
  918. if (array_key_exists('default', $array)) {
  919. if ($array['default']) {
  920. $this->_clearBookmarkCategoryDefault();
  921. }
  922. }
  923. $response = [
  924. array(
  925. 'function' => 'query',
  926. 'query' => array(
  927. 'UPDATE `BOOKMARK-categories` SET',
  928. $array,
  929. 'WHERE id = ?',
  930. $id
  931. )
  932. ),
  933. ];
  934. $this->setAPIResponse(null, 'Category info updated');
  935. $this->writeLog('success', 'Category Editor Function - Edited Category Info for [' . $categoryInfo['category'] . ']', $this->user['username']);
  936. $result = $this->processQueries($response);
  937. $this->_correctDefaultCategory();
  938. return $result;
  939. }
  940. public function _updateCategoryOrder($array)
  941. {
  942. if (count($array) >= 1) {
  943. foreach ($array as $category) {
  944. if (count($category) !== 2) {
  945. $this->setAPIResponse('error', 'data is malformed', 422);
  946. break;
  947. }
  948. $id = $category['id'] ?? null;
  949. $order = $category['order'] ?? null;
  950. if ($id && $order) {
  951. $response = [
  952. array(
  953. 'function' => 'query',
  954. 'query' => array(
  955. 'UPDATE `BOOKMARK-categories` set `order` = ? WHERE `id` = ?',
  956. $order,
  957. $id
  958. )
  959. ),
  960. ];
  961. $this->processQueries($response);
  962. $this->setAPIResponse(null, 'Category Order updated');
  963. } else {
  964. $this->setAPIResponse('error', 'data is malformed', 422);
  965. }
  966. }
  967. } else {
  968. $this->setAPIResponse('error', 'data is empty or not in array', 422);
  969. return false;
  970. }
  971. }
  972. public function _deleteCategory($id)
  973. {
  974. $response = [
  975. array(
  976. 'function' => 'query',
  977. 'query' => array(
  978. 'DELETE FROM `BOOKMARK-categories` WHERE id = ?',
  979. $id
  980. )
  981. ),
  982. ];
  983. $categoryInfo = $this->_getBookmarkCategoryById($id);
  984. if ($categoryInfo) {
  985. $this->writeLog('success', 'Category Delete Function - Deleted Category [' . $categoryInfo['category'] . ']', $this->user['username']);
  986. $this->setAPIResponse('success', 'Category deleted', 204);
  987. $result = $this->processQueries($response);
  988. $this->_correctDefaultCategory();
  989. return $result;
  990. } else {
  991. $this->setAPIResponse('error', 'id not found', 404);
  992. return false;
  993. }
  994. }
  995. protected function _correctDefaultCategory(){
  996. if($this->_getDefaultBookmarkCategoryId() == null){
  997. $response = [
  998. array(
  999. 'function' => 'query',
  1000. 'query' => 'UPDATE `BOOKMARK-categories` SET `default` = 1 WHERE `category_id` = (SELECT `category_id` FROM `BOOKMARK-categories` ORDER BY `category_id` ASC LIMIT 0,1)'
  1001. )
  1002. ];
  1003. return $this->processQueries($response);
  1004. }
  1005. }
  1006. protected function _checkColorHexCode($hex){
  1007. return preg_match('/^\#([0-9a-fA-F]{3}){1,2}$/', $hex);
  1008. }
  1009. /**
  1010. * Increases or decreases the brightness of a color by a percentage of the current brightness.
  1011. *
  1012. * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
  1013. * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
  1014. *
  1015. * @return string
  1016. *
  1017. * @author maliayas
  1018. * @link https://stackoverflow.com/questions/3512311/how-to-generate-lighter-darker-color-with-php
  1019. */
  1020. protected function adjustBrightness($hexCode, $adjustPercent) {
  1021. $hexCode = ltrim($hexCode, '#');
  1022. if (strlen($hexCode) == 3) {
  1023. $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
  1024. }
  1025. $hexCode = array_map('hexdec', str_split($hexCode, 2));
  1026. foreach ($hexCode as & $color) {
  1027. $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
  1028. $adjustAmount = ceil($adjustableLimit * $adjustPercent);
  1029. $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
  1030. }
  1031. return '#' . implode($hexCode);
  1032. }
  1033. }