From 2cc51c1aef20b25eee544ef17ceb3bc27ff00df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 16 Dec 2020 20:13:11 +0100 Subject: [PATCH 1/2] bookmark class doxygen --- htdocs/bookmarks/class/bookmark.class.php | 75 ++++++++++++++--------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/htdocs/bookmarks/class/bookmark.class.php b/htdocs/bookmarks/class/bookmark.class.php index f7098f1d780..f5bbefae3d3 100644 --- a/htdocs/bookmarks/class/bookmark.class.php +++ b/htdocs/bookmarks/class/bookmark.class.php @@ -83,8 +83,14 @@ class Bookmark extends CommonObject */ public $title; + /** + * @var int position of bookmark + */ public $position; + /** + * @var string favicon + */ public $favicon; @@ -116,8 +122,7 @@ class Bookmark extends CommonObject dol_syslog("Bookmark::fetch", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -151,7 +156,9 @@ class Bookmark extends CommonObject // Clean parameters $this->url = trim($this->url); $this->title = trim($this->title); - if (empty($this->position)) $this->position = 0; + if (empty($this->position)) { + $this->position = 0; + } $now = dol_now(); @@ -164,17 +171,15 @@ class Bookmark extends CommonObject $sql .= ($this->fk_user > 0 ? $this->fk_user : "0").","; $sql .= " '".$this->db->idate($now)."',"; $sql .= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',"; - $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', '".$this->db->escape($this->position)."'"; - $sql .= ", ".$this->db->escape($conf->entity); + $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', ".(int) $this->position; + $sql .= ", ".(int) $conf->entity; $sql .= ")"; dol_syslog("Bookmark::create", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark"); - if ($id > 0) - { + if ($id > 0) { $this->id = $id; $this->db->commit(); return $id; @@ -202,7 +207,9 @@ class Bookmark extends CommonObject // Clean parameters $this->url = trim($this->url); $this->title = trim($this->title); - if (empty($this->position)) $this->position = 0; + if (empty($this->position)) { + $this->position = 0; + } $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark"; $sql .= " SET fk_user = ".($this->fk_user > 0 ? $this->fk_user : "0"); @@ -211,12 +218,11 @@ class Bookmark extends CommonObject $sql .= " ,target = '".$this->db->escape($this->target)."'"; $sql .= " ,title = '".$this->db->escape($this->title)."'"; $sql .= " ,favicon = '".$this->db->escape($this->favicon)."'"; - $sql .= " ,position = '".$this->db->escape($this->position)."'"; + $sql .= " ,position = ".(int) $this->position; $sql .= " WHERE rowid = ".$this->id; dol_syslog("Bookmark::update", LOG_DEBUG); - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { return 1; } else { $this->error = $this->db->lasterror(); @@ -237,8 +243,7 @@ class Bookmark extends CommonObject dol_syslog("Bookmark::remove", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { return 1; } else { $this->error = $this->db->lasterror(); @@ -288,7 +293,9 @@ class Bookmark extends CommonObject { global $conf, $langs, $hookmanager; - if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + if (!empty($conf->dol_no_mouse_hover)) { + $notooltip = 1; // Force disable tooltips + } $result = ''; @@ -298,33 +305,40 @@ class Bookmark extends CommonObject $url = DOL_URL_ROOT.'/bookmarks/card.php?id='.$this->id; - if ($option != 'nolink') - { + if ($option != 'nolink') { // Add param to save lastsearch_values or not $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; - if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { + $add_save_lastsearch_values = 1; + } + if ($add_save_lastsearch_values) { + $url .= '&save_lastsearch_values=1'; + } } $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip)) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("ShowBookmark"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; - } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + } else { + $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + } $linkstart = ''; $linkend = ''; $result .= $linkstart; - if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= $this->ref; + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= $this->ref; + } $result .= $linkend; //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); @@ -332,8 +346,11 @@ class Bookmark extends CommonObject $hookmanager->initHooks(array('mybookmarkdao')); $parameters = array('id'=>$this->id, 'getnomurl'=>$result); $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) $result = $hookmanager->resPrint; - else $result .= $hookmanager->resPrint; + if ($reshook > 0) { + $result = $hookmanager->resPrint; + } else { + $result .= $hookmanager->resPrint; + } return $result; } From 3b19151c18639d5cb426f9e2552a5d6298a97e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 16 Dec 2020 20:15:48 +0100 Subject: [PATCH 2/2] bookmark --- htdocs/bookmarks/admin/bookmark.php | 15 ++-- htdocs/bookmarks/bookmarks.lib.php | 132 ++++++++++++++-------------- 2 files changed, 73 insertions(+), 74 deletions(-) diff --git a/htdocs/bookmarks/admin/bookmark.php b/htdocs/bookmarks/admin/bookmark.php index 9aa1989fa2e..c049d4af16f 100644 --- a/htdocs/bookmarks/admin/bookmark.php +++ b/htdocs/bookmarks/admin/bookmark.php @@ -28,20 +28,21 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; // Load translation files required by the page $langs->load("admin"); -if (!$user->admin) -accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} $action = GETPOST('action', 'aZ09'); -if ($action == 'setvalue') -{ +if ($action == 'setvalue') { $showmenu = GETPOST('BOOKMARKS_SHOW_IN_MENU', 'alpha'); $res = dolibarr_set_const($db, "BOOKMARKS_SHOW_IN_MENU", $showmenu, 'chaine', 0, '', $conf->entity); - if (!$res > 0) $error++; + if (!$res > 0) { + $error++; + } - if (!$error) - { + if (!$error) { $db->commit(); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { diff --git a/htdocs/bookmarks/bookmarks.lib.php b/htdocs/bookmarks/bookmarks.lib.php index 63a95fed4c0..ffd1673ac63 100644 --- a/htdocs/bookmarks/bookmarks.lib.php +++ b/htdocs/bookmarks/bookmarks.lib.php @@ -38,20 +38,23 @@ function printDropdownBookmarksList() $url = $_SERVER["PHP_SELF"]; - if (!empty($_SERVER["QUERY_STRING"])) - { + if (!empty($_SERVER["QUERY_STRING"])) { $url .= (dol_escape_htmltag($_SERVER["QUERY_STRING"]) ? '?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]) : ''); } else { global $sortfield, $sortorder; $tmpurl = ''; // No urlencode, all param $url will be urlencoded later - if ($sortfield) $tmpurl .= ($tmpurl ? '&' : '').'sortfield='.$sortfield; - if ($sortorder) $tmpurl .= ($tmpurl ? '&' : '').'sortorder='.$sortorder; - if (is_array($_POST)) - { - foreach ($_POST as $key => $val) - { - if (preg_match('/^search_/', $key) && $val != '') $tmpurl .= ($tmpurl ? '&' : '').$key.'='.$val; + if ($sortfield) { + $tmpurl .= ($tmpurl ? '&' : '').'sortfield='.$sortfield; + } + if ($sortorder) { + $tmpurl .= ($tmpurl ? '&' : '').'sortorder='.$sortorder; + } + if (is_array($_POST)) { + foreach ($_POST as $key => $val) { + if (preg_match('/^search_/', $key) && $val != '') { + $tmpurl .= ($tmpurl ? '&' : '').$key.'='.$val; + } } } $url .= ($tmpurl ? '?'.$tmpurl : ''); @@ -68,8 +71,7 @@ function printDropdownBookmarksList() // Url to go on create new bookmark page $newbtn = ''; - if (!empty($user->rights->bookmark->creer)) - { + if (!empty($user->rights->bookmark->creer)) { //$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&urlsource='.urlencode($url).'&url='.urlencode($url); $urltoadd = DOL_URL_ROOT.'/bookmarks/card.php?action=create&url='.urlencode($url); $newbtn .= ''; @@ -81,13 +83,11 @@ function printDropdownBookmarksList() $sql .= " WHERE (fk_user = ".$user->id." OR fk_user is NULL OR fk_user = 0)"; $sql .= " AND entity IN (".getEntity('bookmarks').")"; $sql .= " ORDER BY position"; - if ($resql = $db->query($sql)) - { + if ($resql = $db->query($sql)) { if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $bookmarkList = '