plugin.php 38 KB

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