- /**
- * @brief Additional SQL query string for the personal notifications
- *
- * @return string The additional SQL query
- */
- private function personalSqlExtra()
- {
- $myurl = System::baseUrl(true) . '/profile/' . self::getApp()->user['nickname'];
- $myurl = substr($myurl, strpos($myurl, '://') + 3);
- $myurl = str_replace(['www.', '.'], ['', '\\.'], $myurl);
- $diasp_url = str_replace('/profile/', '/u/', $myurl);
- $sql_extra = sprintf(
- " AND (`item`.`author-link` REGEXP '%s' OR `item`.`tag` REGEXP '%s' OR `item`.`tag` REGEXP '%s') ",
- dbesc($myurl . '$'),
- dbesc($myurl . '\\]'),
- dbesc($diasp_url . '\\]')
- );
-
- return $sql_extra;
- }
-
- /**
- * @brief Total number of personal notifications
- * @param int|string $seen If 0 only include notifications into the query
- * which aren't marked as "seen"
- *
- * @return int Number of personal notifications
- */
- private function personalTotal($seen = 0)
- {
- $sql_seen = "";
- $index_hint = "";
- $sql_extra = $this->personalSqlExtra();
-
- if ($seen === 0) {
- $sql_seen = " AND `item`.`unseen` ";
- $index_hint = "USE INDEX (`uid_unseen_contactid`)";
- }
-
- $r = q(
- "SELECT COUNT(*) AS `total`
- FROM `item` $index_hint
- WHERE `item`.`visible`
- $sql_extra
- $sql_seen
- AND NOT `item`.`deleted` AND `item`.`uid` = %d AND NOT `item`.`wall`",
- intval(local_user())
- );
- if (DBM::is_result($r)) {
- return $r[0]['total'];
- }
-
- return 0;
- }
-