Browse Source

Class file relocations

Issue #3878
tags/3.6
Adam Magness 1 year ago
parent
commit
9e99066fd7
100 changed files with 659 additions and 8456 deletions
  1. 4
    3
      boot.php
  2. 2
    2
      doc/Developer-How-To-Move-Classes-to-src.md
  3. 4
    4
      doc/autoloader.md
  4. 24
    23
      include/Contact.php
  5. 2
    1
      include/ForumManager.php
  6. 0
    866
      include/NotificationsManager.php
  7. 7
    6
      include/Photo.php
  8. 8
    7
      include/acl_selectors.php
  9. 44
    43
      include/api.php
  10. 4
    3
      include/auth.php
  11. 2
    1
      include/auth_ejabberd.php
  12. 2
    1
      include/cache.php
  13. 3
    2
      include/contact_selectors.php
  14. 3
    2
      include/contact_widgets.php
  15. 6
    5
      include/conversation.php
  16. 3
    2
      include/cron.php
  17. 6
    5
      include/cronjobs.php
  18. 3
    2
      include/datetime.php
  19. 3
    3
      include/dba.php
  20. 0
    112
      include/dbm.php
  21. 18
    17
      include/dbstructure.php
  22. 15
    14
      include/delivery.php
  23. 0
    2966
      include/dfrn.php
  24. 0
    3943
      include/diaspora.php
  25. 2
    1
      include/directory.php
  26. 3
    2
      include/discover_poco.php
  27. 6
    5
      include/enotify.php
  28. 11
    10
      include/event.php
  29. 2
    1
      include/expire.php
  30. 4
    4
      include/fcontact.php
  31. 2
    1
      include/feed.php
  32. 5
    4
      include/follow.php
  33. 3
    2
      include/gprobe.php
  34. 11
    10
      include/group.php
  35. 9
    8
      include/identity.php
  36. 43
    42
      include/items.php
  37. 6
    5
      include/like.php
  38. 5
    4
      include/message.php
  39. 2
    1
      include/nav.php
  40. 10
    9
      include/notifier.php
  41. 8
    7
      include/oauth.php
  42. 2
    1
      include/oembed.php
  43. 7
    6
      include/onepoll.php
  44. 16
    15
      include/ostatus.php
  45. 3
    2
      include/plugin.php
  46. 3
    2
      include/post_update.php
  47. 2
    1
      include/pubsubpublish.php
  48. 8
    7
      include/queue.php
  49. 4
    3
      include/queue_fn.php
  50. 3
    2
      include/redir.php
  51. 9
    8
      include/security.php
  52. 2
    1
      include/session.php
  53. 30
    29
      include/socgraph.php
  54. 10
    9
      include/text.php
  55. 15
    14
      include/threads.php
  56. 3
    2
      include/uimport.php
  57. 2
    1
      include/update_gcontact.php
  58. 9
    8
      include/user.php
  59. 2
    1
      index.php
  60. 3
    2
      mod/admin.php
  61. 3
    2
      mod/allfriends.php
  62. 2
    1
      mod/api.php
  63. 3
    2
      mod/attach.php
  64. 4
    3
      mod/cal.php
  65. 7
    6
      mod/common.php
  66. 2
    1
      mod/community.php
  67. 3
    2
      mod/contactgroup.php
  68. 7
    6
      mod/contacts.php
  69. 4
    3
      mod/crepair.php
  70. 8
    7
      mod/delegate.php
  71. 14
    13
      mod/dfrn_confirm.php
  72. 7
    6
      mod/dfrn_notify.php
  73. 15
    14
      mod/dfrn_poll.php
  74. 15
    14
      mod/dfrn_request.php
  75. 3
    2
      mod/directory.php
  76. 1
    1
      mod/dirfind.php
  77. 19
    18
      mod/display.php
  78. 3
    2
      mod/editpost.php
  79. 5
    4
      mod/events.php
  80. 3
    2
      mod/friendica.php
  81. 5
    4
      mod/fsuggest.php
  82. 6
    5
      mod/group.php
  83. 2
    1
      mod/ignored.php
  84. 2
    1
      mod/install.php
  85. 28
    27
      mod/item.php
  86. 6
    5
      mod/lockview.php
  87. 4
    3
      mod/lostpass.php
  88. 7
    6
      mod/manage.php
  89. 2
    1
      mod/match.php
  90. 8
    7
      mod/message.php
  91. 2
    1
      mod/modexp.php
  92. 2
    1
      mod/mood.php
  93. 3
    2
      mod/msearch.php
  94. 10
    9
      mod/network.php
  95. 3
    2
      mod/nogroup.php
  96. 5
    4
      mod/noscrape.php
  97. 4
    3
      mod/notes.php
  98. 2
    1
      mod/notice.php
  99. 2
    1
      mod/notifications.php
  100. 0
    0
      mod/notify.php

+ 4
- 3
boot.php View File

@@ -24,6 +24,7 @@ use Friendica\App;
24 24
 use Friendica\Core\System;
25 25
 use Friendica\Core\Config;
26 26
 use Friendica\Core\PConfig;
27
+use Friendica\Database\DBM;
27 28
 use Friendica\Util\Lock;
28 29
 
29 30
 require_once 'include/network.php';
@@ -768,7 +769,7 @@ function run_update_function($x) {
768 769
 function check_plugins(App $a) {
769 770
 
770 771
 	$r = q("SELECT * FROM `addon` WHERE `installed` = 1");
771
-	if (dbm::is_result($r)) {
772
+	if (DBM::is_result($r)) {
772 773
 		$installed = $r;
773 774
 	} else {
774 775
 		$installed = array();
@@ -1054,7 +1055,7 @@ function current_theme() {
1054 1055
 		$r = q("select theme from user where uid = %d limit 1",
1055 1056
 			intval($a->profile_uid)
1056 1057
 		);
1057
-		if (dbm::is_result($r)) {
1058
+		if (DBM::is_result($r)) {
1058 1059
 			$page_theme = $r[0]['theme'];
1059 1060
 		}
1060 1061
 	}
@@ -1176,7 +1177,7 @@ function feed_birthday($uid, $tz) {
1176 1177
 			intval($uid)
1177 1178
 	);
1178 1179
 
1179
-	if (dbm::is_result($p)) {
1180
+	if (DBM::is_result($p)) {
1180 1181
 		$tmp_dob = substr($p[0]['dob'], 5);
1181 1182
 		if (intval($tmp_dob)) {
1182 1183
 			$y = datetime_convert($tz, $tz, 'now', 'Y');

+ 2
- 2
doc/Developer-How-To-Move-Classes-to-src.md View File

@@ -73,7 +73,7 @@ If there are only a handful of references to a single non-namespaced class, just
73 73
 ````php
74 74
 namespace Friendica\Core;
75 75
 ...
76
-if (\dbm::is_result($r)) {
76
+if (\DBM::is_result($r)) {
77 77
     ...
78 78
 }
79 79
 ````
@@ -82,7 +82,7 @@ namespace Friendica\Core;
82 82
 
83 83
 use \dbm;
84 84
 
85
-if (dbm::is_result($r)) {
85
+if (DBM::is_result($r)) {
86 86
     ...
87 87
 }
88 88
 ````

+ 4
- 4
doc/autoloader.md View File

@@ -104,7 +104,7 @@ class Dfrn {
104 104
 
105 105
 mail_post($a){
106 106
 	...
107
-	Friendica\dfrn::mail($item, $owner);
107
+	Friendica\DFRN::mail($item, $owner);
108 108
 	...
109 109
 }
110 110
 ```
@@ -125,12 +125,12 @@ switch($contact['network']) {
125 125
 	case NETWORK_DFRN:
126 126
 		if ($mail) {
127 127
 			$item['body'] = ...
128
-			$atom = Dfrn::mail($item, $owner);
128
+			$atom = DFRN::mail($item, $owner);
129 129
 		} elseif ($fsuggest) {
130
-			$atom = Dfrn::fsuggest($item, $owner);
130
+			$atom = DFRN::fsuggest($item, $owner);
131 131
 			q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item['id']));
132 132
 		} elseif ($relocate)
133
-			$atom = Dfrn::relocate($owner, $uid);
133
+			$atom = DFRN::relocate($owner, $uid);
134 134
 [...]
135 135
 ```
136 136
 

+ 24
- 23
include/Contact.php View File

@@ -4,9 +4,10 @@ use Friendica\App;
4 4
 use Friendica\Core\PConfig;
5 5
 use Friendica\Core\System;
6 6
 use Friendica\Core\Worker;
7
+use Friendica\Database\DBM;
7 8
 use Friendica\Network\Probe;
8 9
 use Friendica\Protocol\Diaspora;
9
-use Friendica\Protocol\Dfrn;
10
+use Friendica\Protocol\DFRN;
10 11
 
11 12
 // Included here for completeness, but this is a very dangerous operation.
12 13
 // It is the caller's responsibility to confirm the requestor's intent and
@@ -49,7 +50,7 @@ function contact_remove($id) {
49 50
 	$r = q("SELECT `uid` FROM `contact` WHERE `id` = %d AND NOT `self` LIMIT 1",
50 51
 		intval($id)
51 52
 	);
52
-	if (!dbm::is_result($r) || !intval($r[0]['uid'])) {
53
+	if (!DBM::is_result($r) || !intval($r[0]['uid'])) {
53 54
 		return;
54 55
 	}
55 56
 
@@ -94,7 +95,7 @@ function terminate_friendship($user,$self,$contact) {
94 95
 	} elseif ($contact['network'] === NETWORK_DIASPORA) {
95 96
 		Diaspora::send_unshare($user,$contact);
96 97
 	} elseif ($contact['network'] === NETWORK_DFRN) {
97
-		Dfrn::deliver($user,$contact,'placeholder', 1);
98
+		DFRN::deliver($user,$contact,'placeholder', 1);
98 99
 	}
99 100
 
100 101
 }
@@ -163,7 +164,7 @@ function unmark_for_death($contact) {
163 164
 	);
164 165
 
165 166
 	// We don't need to update, we never marked this contact as dead
166
-	if (!dbm::is_result($r)) {
167
+	if (!DBM::is_result($r)) {
167 168
 		return;
168 169
 	}
169 170
 
@@ -213,7 +214,7 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
213 214
 	$r = dba::inArray($s);
214 215
 
215 216
 	// Fetch contact data from the contact table for the given user, checking with the alias
216
-	if (!dbm::is_result($r)) {
217
+	if (!DBM::is_result($r)) {
217 218
 		$s = dba::p("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
218 219
 				`keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`
219 220
 			FROM `contact` WHERE `alias` IN (?, ?, ?) AND `uid` = ?",
@@ -222,7 +223,7 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
222 223
 	}
223 224
 
224 225
 	// Fetch the data from the contact table with "uid=0" (which is filled automatically)
225
-	if (!dbm::is_result($r)) {
226
+	if (!DBM::is_result($r)) {
226 227
 		$s = dba::p("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
227 228
 			`keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`
228 229
 			FROM `contact` WHERE `nurl` = ? AND `uid` = 0",
@@ -231,7 +232,7 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
231 232
 	}
232 233
 
233 234
 	// Fetch the data from the contact table with "uid=0" (which is filled automatically) - checked with the alias
234
-	if (!dbm::is_result($r)) {
235
+	if (!DBM::is_result($r)) {
235 236
 		$s = dba::p("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
236 237
 			`keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`
237 238
 			FROM `contact` WHERE `alias` IN (?, ?, ?) AND `uid` = 0",
@@ -240,7 +241,7 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
240 241
 	}
241 242
 
242 243
 	// Fetch the data from the gcontact table
243
-	if (!dbm::is_result($r)) {
244
+	if (!DBM::is_result($r)) {
244 245
 		$s = dba::p("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`,
245 246
 			`keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
246 247
 			FROM `gcontact` WHERE `nurl` = ?",
@@ -248,7 +249,7 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
248 249
 		$r = dba::inArray($s);
249 250
 	}
250 251
 
251
-	if (dbm::is_result($r)) {
252
+	if (DBM::is_result($r)) {
252 253
 		// If there is more than one entry we filter out the connector networks
253 254
 		if (count($r) > 1) {
254 255
 			foreach ($r AS $id => $result) {
@@ -351,20 +352,20 @@ function get_contact_details_by_addr($addr, $uid = -1) {
351 352
 			dbesc($addr), intval($uid));
352 353
 
353 354
 	// Fetch the data from the contact table with "uid=0" (which is filled automatically)
354
-	if (!dbm::is_result($r))
355
+	if (!DBM::is_result($r))
355 356
 		$r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
356 357
 			`keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`
357 358
 			FROM `contact` WHERE `addr` = '%s' AND `uid` = 0",
358 359
 				dbesc($addr));
359 360
 
360 361
 	// Fetch the data from the gcontact table
361
-	if (!dbm::is_result($r))
362
+	if (!DBM::is_result($r))
362 363
 		$r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`,
363 364
 			`keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
364 365
 			FROM `gcontact` WHERE `addr` = '%s'",
365 366
 				dbesc($addr));
366 367
 
367
-	if (!dbm::is_result($r)) {
368
+	if (!DBM::is_result($r)) {
368 369
 		$data = Probe::uri($addr);
369 370
 
370 371
 		$profile = get_contact_details_by_url($data['url'], $uid);
@@ -486,7 +487,7 @@ function random_profile() {
486 487
 			ORDER BY rand() LIMIT 1",
487 488
 		dbesc(NETWORK_DFRN));
488 489
 
489
-	if (dbm::is_result($r))
490
+	if (DBM::is_result($r))
490 491
 		return dirname($r[0]['url']);
491 492
 	return '';
492 493
 }
@@ -553,12 +554,12 @@ function get_contact($url, $uid = 0, $no_update = false) {
553 554
 	$contact = dba::select('contact', array('id', 'avatar-date'), array('nurl' => normalise_link($url), 'uid' => $uid), array('limit' => 1));
554 555
 
555 556
 	// Then the addr (nick@server.tld)
556
-	if (!dbm::is_result($contact)) {
557
+	if (!DBM::is_result($contact)) {
557 558
 		$contact = dba::select('contact', array('id', 'avatar-date'), array('addr' => $url, 'uid' => $uid), array('limit' => 1));
558 559
 	}
559 560
 
560 561
 	// Then the alias (which could be anything)
561
-	if (!dbm::is_result($contact)) {
562
+	if (!DBM::is_result($contact)) {
562 563
 		// The link could be provided as http although we stored it as https
563 564
 		$ssl_url = str_replace('http://', 'https://', $url);
564 565
 		$r = dba::p("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN (?, ?, ?) AND `uid` = ? LIMIT 1",
@@ -567,7 +568,7 @@ function get_contact($url, $uid = 0, $no_update = false) {
567 568
 		dba::close($r);
568 569
 	}
569 570
 
570
-	if (dbm::is_result($contact)) {
571
+	if (DBM::is_result($contact)) {
571 572
 		$contact_id = $contact["id"];
572 573
 
573 574
 		// Update the contact every 7 days
@@ -597,7 +598,7 @@ function get_contact($url, $uid = 0, $no_update = false) {
597 598
 		// Get data from the gcontact table
598 599
 		$gcontacts = dba::select('gcontact', array('name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'),
599 600
 						array('nurl' => normalise_link($url)), array('limit' => 1));
600
-		if (!dbm::is_result($gcontacts)) {
601
+		if (!DBM::is_result($gcontacts)) {
601 602
 			return 0;
602 603
 		}
603 604
 
@@ -626,7 +627,7 @@ function get_contact($url, $uid = 0, $no_update = false) {
626 627
 		$contacts = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
627 628
 				dbesc(normalise_link($data["url"])),
628 629
 				intval($uid));
629
-		if (!dbm::is_result($contacts)) {
630
+		if (!DBM::is_result($contacts)) {
630 631
 			return 0;
631 632
 		}
632 633
 
@@ -635,7 +636,7 @@ function get_contact($url, $uid = 0, $no_update = false) {
635 636
 		// Update the newly created contact from data in the gcontact table
636 637
 		$gcontact = dba::select('gcontact', array('location', 'about', 'keywords', 'gender'),
637 638
 					array('nurl' => normalise_link($data["url"])), array('limit' => 1));
638
-		if (dbm::is_result($gcontact)) {
639
+		if (DBM::is_result($gcontact)) {
639 640
 			// Only use the information when the probing hadn't fetched these values
640 641
 			if ($data['keywords'] != '') {
641 642
 				unset($gcontact['keywords']);
@@ -663,7 +664,7 @@ function get_contact($url, $uid = 0, $no_update = false) {
663 664
 				array('id' => $contact_id), array('limit' => 1));
664 665
 
665 666
 	// This condition should always be true
666
-	if (!dbm::is_result($contact)) {
667
+	if (!DBM::is_result($contact)) {
667 668
 		return $contact_id;
668 669
 	}
669 670
 
@@ -711,7 +712,7 @@ function blockedContact($cid) {
711 712
 	}
712 713
 
713 714
 	$blocked = dba::select('contact', array('blocked'), array('id' => $cid), array('limit' => 1));
714
-	if (!dbm::is_result($blocked)) {
715
+	if (!DBM::is_result($blocked)) {
715 716
 		return false;
716 717
 	}
717 718
 	return (bool)$blocked['blocked'];
@@ -730,7 +731,7 @@ function hiddenContact($cid) {
730 731
 	}
731 732
 
732 733
 	$hidden = dba::select('contact', array('hidden'), array('id' => $cid), array('limit' => 1));
733
-	if (!dbm::is_result($hidden)) {
734
+	if (!DBM::is_result($hidden)) {
734 735
 		return false;
735 736
 	}
736 737
 	return (bool)$hidden['hidden'];
@@ -793,7 +794,7 @@ function posts_from_contact_url(App $a, $contact_url) {
793 794
 		WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0",
794 795
 		dbesc(normalise_link($contact_url)));
795 796
 
796
-	if (!dbm::is_result($r)) {
797
+	if (!DBM::is_result($r)) {
797 798
 		return '';
798 799
 	}
799 800
 

+ 2
- 1
include/ForumManager.php View File

@@ -2,6 +2,7 @@
2 2
 
3 3
 use Friendica\App;
4 4
 use Friendica\Core\System;
5
+use Friendica\Database\DBM;
5 6
 
6 7
 /**
7 8
  * @file include/ForumManager.php
@@ -93,7 +94,7 @@ class ForumManager {
93 94
 		$total = count($contacts);
94 95
 		$visible_forums = 10;
95 96
 
96
-		if (dbm::is_result($contacts)) {
97
+		if (DBM::is_result($contacts)) {
97 98
 
98 99
 			$id = 0;
99 100
 

+ 0
- 866
include/NotificationsManager.php View File

@@ -1,866 +0,0 @@
1
-<?php
2
-/**
3
- * @file include/NotificationsManager.php
4
- * @brief Methods for read and write notifications from/to database
5
- *  or for formatting notifications
6
- */
7
-
8
-use Friendica\Core\Pconfig;
9
-use Friendica\Core\System;
10
-
11
-require_once 'include/html2plain.php';
12
-require_once 'include/datetime.php';
13
-require_once 'include/bbcode.php';
14
-require_once 'include/Contact.php';
15
-
16
-/**
17
- * @brief Methods for read and write notifications from/to database
18
- *  or for formatting notifications
19
- */
20
-class NotificationsManager {
21
-	private $a;
22
-
23
-	public function __construct() {
24
-		$this->a = get_app();
25
-	}
26
-
27
-	/**
28
-	 * @brief set some extra note properties
29
-	 *
30
-	 * @param array $notes array of note arrays from db
31
-	 * @return array Copy of input array with added properties
32
-	 *
33
-	 * Set some extra properties to note array from db:
34
-	 *  - timestamp as int in default TZ
35
-	 *  - date_rel : relative date string
36
-	 *  - msg_html: message as html string
37
-	 *  - msg_plain: message as plain text string
38
-	 */
39
-	private function _set_extra($notes) {
40
-		$rets = array();
41
-		foreach($notes as $n) {
42
-			$local_time = datetime_convert('UTC',date_default_timezone_get(),$n['date']);
43
-			$n['timestamp'] = strtotime($local_time);
44
-			$n['date_rel'] = relative_date($n['date']);
45
-				$n['msg_html'] = bbcode($n['msg'], false, false, false, false);
46
-				$n['msg_plain'] = explode("\n",trim(html2plain($n['msg_html'], 0)))[0];
47
-
48
-			$rets[] = $n;
49
-		}
50
-		return $rets;
51
-	}
52
-
53
-
54
-	/**
55
-	 * @brief Get all notifications for local_user()
56
-	 *
57
-	 * @param array $filter optional Array "column name"=>value: filter query by columns values
58
-	 * @param string $order optional Space separated list of column to sort by. prepend name with "+" to sort ASC, "-" to sort DESC. Default to "-date"
59
-	 * @param string $limit optional Query limits
60
-	 *
61
-	 * @return array of results or false on errors
62
-	 */
63
-	public function getAll($filter = array(), $order="-date", $limit="") {
64
-		$filter_str = array();
65
-		$filter_sql = "";
66
-		foreach($filter as $column => $value) {
67
-			$filter_str[] = sprintf("`%s` = '%s'", $column, dbesc($value));
68
-		}
69
-		if (count($filter_str)>0) {
70
-			$filter_sql = "AND ".implode(" AND ", $filter_str);
71
-		}
72
-
73
-		$aOrder = explode(" ", $order);
74
-		$asOrder = array();
75
-		foreach($aOrder as $o) {
76
-			$dir = "asc";
77
-			if ($o[0]==="-") {
78
-				$dir = "desc";
79
-				$o = substr($o,1);
80
-			}
81
-			if ($o[0]==="+") {
82
-				$dir = "asc";
83
-				$o = substr($o,1);
84
-			}
85
-			$asOrder[] = "$o $dir";
86
-		}
87
-		$order_sql = implode(", ", $asOrder);
88
-
89
-		if($limit!="")
90
-			$limit = " LIMIT ".$limit;
91
-
92
-			$r = q("SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit",
93
-				intval(local_user())
94
-			);
95
-
96
-		if (dbm::is_result($r))
97
-			return $this->_set_extra($r);
98
-
99
-		return false;
100
-	}
101
-
102
-	/**
103
-	 * @brief Get one note for local_user() by $id value
104
-	 *
105
-	 * @param int $id
106
-	 * @return array note values or null if not found
107
-	 */
108
-	public function getByID($id) {
109
-		$r = q("SELECT * FROM `notify` WHERE `id` = %d AND `uid` = %d LIMIT 1",
110
-			intval($id),
111
-			intval(local_user())
112
-		);
113
-		if (dbm::is_result($r)) {
114
-			return $this->_set_extra($r)[0];
115
-		}
116
-		return null;
117
-	}
118
-
119
-	/**
120
-	 * @brief set seen state of $note of local_user()
121
-	 *
122
-	 * @param array $note
123
-	 * @param bool $seen optional true or false, default true
124
-	 * @return bool true on success, false on errors
125
-	 */
126
-	public function setSeen($note, $seen = true) {
127
-		return q("UPDATE `notify` SET `seen` = %d WHERE ( `link` = '%s' OR ( `parent` != 0 AND `parent` = %d AND `otype` = '%s' )) AND `uid` = %d",
128
-			intval($seen),
129
-			dbesc($note['link']),
130
-			intval($note['parent']),
131
-			dbesc($note['otype']),
132
-			intval(local_user())
133
-		);
134
-	}
135
-
136
-	/**
137
-	 * @brief set seen state of all notifications of local_user()
138
-	 *
139
-	 * @param bool $seen optional true or false. default true
140
-	 * @return bool true on success, false on error
141
-	 */
142
-	public function setAllSeen($seen = true) {
143
-		return q("UPDATE `notify` SET `seen` = %d WHERE `uid` = %d",
144
-			intval($seen),
145
-			intval(local_user())
146
-		);
147
-	}
148
-
149
-	/**
150
-	 * @brief List of pages for the Notifications TabBar
151
-	 *
152
-	 * @return array with with notifications TabBar data
153
-	 */
154
-	public function getTabs() {
155
-		$tabs = array(
156
-			array(
157
-				'label' => t('System'),
158
-				'url'=>'notifications/system',
159
-				'sel'=> (($this->a->argv[1] == 'system') ? 'active' : ''),
160
-				'id' => 'system-tab',
161
-				'accesskey' => 'y',
162
-			),
163
-			array(
164
-				'label' => t('Network'),
165
-				'url'=>'notifications/network',
166
-				'sel'=> (($this->a->argv[1] == 'network') ? 'active' : ''),
167
-				'id' => 'network-tab',
168
-				'accesskey' => 'w',
169
-			),
170
-			array(
171
-				'label' => t('Personal'),
172
-				'url'=>'notifications/personal',
173
-				'sel'=> (($this->a->argv[1] == 'personal') ? 'active' : ''),
174
-				'id' => 'personal-tab',
175
-				'accesskey' => 'r',
176
-			),
177
-			array(
178
-				'label' => t('Home'),
179
-				'url' => 'notifications/home',
180
-				'sel'=> (($this->a->argv[1] == 'home') ? 'active' : ''),
181
-				'id' => 'home-tab',
182
-				'accesskey' => 'h',
183
-			),
184
-			array(
185
-				'label' => t('Introductions'),
186
-				'url' => 'notifications/intros',
187
-				'sel'=> (($this->a->argv[1] == 'intros') ? 'active' : ''),
188
-				'id' => 'intro-tab',
189
-				'accesskey' => 'i',
190
-			),
191
-		);
192
-
193
-		return $tabs;
194
-	}
195
-
196
-	/**
197
-	 * @brief Format the notification query in an usable array
198
-	 *
199
-	 * @param array $notifs The array from the db query
200
-	 * @param string $ident The notifications identifier (e.g. network)
201
-	 * @return array
202
-	 *	string 'label' => The type of the notification
203
-	 *	string 'link' => URL to the source
204
-	 *	string 'image' => The avatar image
205
-	 *	string 'url' => The profile url of the contact
206
-	 *	string 'text' => The notification text
207
-	 *	string 'when' => The date of the notification
208
-	 *	string 'ago' => T relative date of the notification
209
-	 *	bool 'seen' => Is the notification marked as "seen"
210
-	 */
211
-	private function formatNotifs($notifs, $ident = "") {
212
-
213
-		$notif = array();
214
-		$arr = array();
215
-
216
-		if (dbm::is_result($notifs)) {
217
-
218
-			foreach ($notifs as $it) {
219
-				// Because we use different db tables for the notification query
220
-				// we have sometimes $it['unseen'] and sometimes $it['seen].
221
-				// So we will have to transform $it['unseen']
222
-				if (array_key_exists('unseen', $it)) {
223
-					$it['seen'] = ($it['unseen'] > 0 ? false : true);
224
-				}
225
-
226
-				// Depending on the identifier of the notification we need to use different defaults
227
-				switch ($ident) {
228
-					case 'system':
229
-						$default_item_label = 'notify';
230
-						$default_item_link = System::baseUrl(true).'/notify/view/'. $it['id'];
231
-						$default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO);
232
-						$default_item_url = $it['url'];
233
-						$default_item_text = strip_tags(bbcode($it['msg']));
234
-						$default_item_when = datetime_convert('UTC', date_default_timezone_get(), $it['date'], 'r');
235
-						$default_item_ago = relative_date($it['date']);
236
-						break;
237
-
238
-					case 'home':
239
-						$default_item_label = 'comment';
240
-						$default_item_link = System::baseUrl(true).'/display/'.$it['pguid'];
241
-						$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
242
-						$default_item_url = $it['author-link'];
243
-						$default_item_text = sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']);
244
-						$default_item_when = datetime_convert('UTC', date_default_timezone_get(), $it['created'], 'r');
245
-						$default_item_ago = relative_date($it['created']);
246
-						break;
247
-
248
-					default:
249
-						$default_item_label = (($it['id'] == $it['parent']) ? 'post' : 'comment');
250
-						$default_item_link = System::baseUrl(true).'/display/'.$it['pguid'];
251
-						$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
252
-						$default_item_url = $it['author-link'];
253
-						$default_item_text = (($it['id'] == $it['parent'])
254
-									? sprintf(t("%s created a new post"), $it['author-name'])
255
-									: sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']));
256
-						$default_item_when = datetime_convert('UTC', date_default_timezone_get(), $it['created'], 'r');
257
-						$default_item_ago = relative_date($it['created']);
258
-
259
-				}
260
-
261
-				// Transform the different types of notification in an usable array
262
-				switch ($it['verb']){
263
-					case ACTIVITY_LIKE:
264
-						$notif = array(
265
-							'label' => 'like',
266
-							'link' => System::baseUrl(true).'/display/'.$it['pguid'],
267
-							'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
268
-							'url' => $it['author-link'],
269
-							'text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']),
270
-							'when' => $default_item_when,
271
-							'ago' => $default_item_ago,
272
-							'seen' => $it['seen']
273
-						);
274
-						break;
275
-
276
-					case ACTIVITY_DISLIKE:
277
-						$notif = array(
278
-							'label' => 'dislike',
279
-							'link' => System::baseUrl(true).'/display/'.$it['pguid'],
280
-							'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
281
-							'url' => $it['author-link'],
282
-							'text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']),
283
-							'when' => $default_item_when,
284
-							'ago' => $default_item_ago,
285
-							'seen' => $it['seen']
286
-						);
287
-						break;
288
-
289
-					case ACTIVITY_ATTEND:
290
-						$notif = array(
291
-							'label' => 'attend',
292
-							'link' => System::baseUrl(true).'/display/'.$it['pguid'],
293
-							'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
294
-							'url' => $it['author-link'],
295
-							'text' => sprintf(t("%s is attending %s's event"), $it['author-name'], $it['pname']),
296
-							'when' => $default_item_when,
297
-							'ago' => $default_item_ago,
298
-							'seen' => $it['seen']
299
-						);
300
-						break;
301
-
302
-					case ACTIVITY_ATTENDNO:
303
-						$notif = array(
304
-							'label' => 'attendno',
305
-							'link' => System::baseUrl(true).'/display/'.$it['pguid'],
306
-							'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
307
-							'url' => $it['author-link'],
308
-							'text' => sprintf( t("%s is not attending %s's event"), $it['author-name'], $it['pname']),
309
-							'when' => $default_item_when,
310
-							'ago' => $default_item_ago,
311
-							'seen' => $it['seen']
312
-						);
313
-						break;
314
-
315
-					case ACTIVITY_ATTENDMAYBE:
316
-						$notif = array(
317
-							'label' => 'attendmaybe',
318
-							'link' => System::baseUrl(true).'/display/'.$it['pguid'],
319
-							'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
320
-							'url' => $it['author-link'],
321
-							'text' => sprintf(t("%s may attend %s's event"), $it['author-name'], $it['pname']),
322
-							'when' => $default_item_when,
323
-							'ago' => $default_item_ago,
324
-							'seen' => $it['seen']
325
-						);
326
-						break;
327
-
328
-					case ACTIVITY_FRIEND:
329
-						$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
330
-						$obj = parse_xml_string($xmlhead.$it['object']);
331
-						$it['fname'] = $obj->title;
332
-
333
-						$notif = array(
334
-							'label' => 'friend',
335
-							'link' => System::baseUrl(true).'/display/'.$it['pguid'],
336
-							'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
337
-							'url' => $it['author-link'],
338
-							'text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']),
339
-							'when' => $default_item_when,
340
-							'ago' => $default_item_ago,
341
-							'seen' => $it['seen']
342
-						);
343
-						break;
344
-
345
-					default:
346
-						$notif = array(
347
-							'label' => $default_item_label,
348
-							'link' => $default_item_link,
349
-							'image' => $default_item_image,
350
-							'url' => $default_item_url,
351
-							'text' => $default_item_text,
352
-							'when' => $default_item_when,
353
-							'ago' => $default_item_ago,
354
-							'seen' => $it['seen']
355
-						);
356
-				}
357
-
358
-				$arr[] = $notif;
359
-			}
360
-		}
361
-
362
-		return $arr;
363
-
364
-	}
365
-
366
-	/**
367
-	 * @brief Total number of network notifications
368
-	 * @param int|string $seen
369
-	 *	If 0 only include notifications into the query
370
-	 *	which aren't marked as "seen"
371
-	 * @return int Number of network notifications
372
-	 */
373
-	private function networkTotal($seen = 0) {
374
-		$sql_seen = "";
375
-
376
-		if($seen === 0)
377
-			$sql_seen = " AND `item`.`unseen` = 1 ";
378
-
379
-		$r = q("SELECT COUNT(*) AS `total`
380
-				FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
381
-				WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
382
-				 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
383
-				$sql_seen",
384
-			intval(local_user())
385
-		);
386
-
387
-		if (dbm::is_result($r))
388
-			return $r[0]['total'];
389
-
390
-		return 0;
391
-	}
392
-
393
-	/**
394
-	 * @brief Get network notifications
395
-	 *
396
-	 * @param int|string $seen
397
-	 *	If 0 only include notifications into the query
398
-	 *	which aren't marked as "seen"
399
-	 * @param int $start Start the query at this point
400
-	 * @param int $limit Maximum number of query results
401
-	 *
402
-	 * @return array with
403
-	 *	string 'ident' => Notification identifier
404
-	 *	int 'total' => Total number of available network notifications
405
-	 *	array 'notifications' => Network notifications
406
-	 */
407
-	public function networkNotifs($seen = 0, $start = 0, $limit = 80) {
408
-		$ident = 'network';
409
-		$total = $this->networkTotal($seen);
410
-		$notifs = array();
411
-		$sql_seen = "";
412
-
413
-		if($seen === 0)
414
-			$sql_seen = " AND `item`.`unseen` = 1 ";
415
-
416
-
417
-		$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
418
-				`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
419
-				`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
420
-			FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
421
-			WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
422
-				 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
423
-				$sql_seen
424
-			ORDER BY `item`.`created` DESC LIMIT %d, %d ",
425
-				intval(local_user()),
426
-				intval($start),
427
-				intval($limit)
428
-		);
429
-
430
-		if (dbm::is_result($r))
431
-			$notifs = $this->formatNotifs($r, $ident);
432
-
433
-		$arr = array (
434
-			'notifications' => $notifs,
435
-			'ident' => $ident,
436
-			'total' => $total,
437
-		);
438
-
439
-		return $arr;
440
-	}
441
-
442
-	/**
443
-	 * @brief Total number of system notifications
444
-	 * @param int|string $seen
445
-	 *	If 0 only include notifications into the query
446
-	 *	which aren't marked as "seen"
447
-	 * @return int Number of system notifications
448
-	 */
449
-	private function systemTotal($seen = 0) {
450
-		$sql_seen = "";
451
-
452
-		if($seen === 0)
453
-			$sql_seen = " AND `seen` = 0 ";
454
-
455
-		$r = q("SELECT COUNT(*) AS `total` FROM `notify` WHERE `uid` = %d $sql_seen",
456
-			intval(local_user())
457
-		);
458
-
459
-		if (dbm::is_result($r))
460
-			return $r[0]['total'];
461
-
462
-		return 0;
463
-	}
464
-
465
-	/**
466
-	 * @brief Get system notifications
467
-	 *
468
-	 * @param int|string $seen
469
-	 *	If 0 only include notifications into the query
470
-	 *	which aren't marked as "seen"
471
-	 * @param int $start Start the query at this point
472
-	 * @param int $limit Maximum number of query results
473
-	 *
474
-	 * @return array with
475
-	 *	string 'ident' => Notification identifier
476
-	 *	int 'total' => Total number of available system notifications
477
-	 *	array 'notifications' => System notifications
478
-	 */
479
-	public function systemNotifs($seen = 0, $start = 0, $limit = 80) {
480
-		$ident = 'system';
481
-		$total = $this->systemTotal($seen);
482
-		$notifs = array();
483
-		$sql_seen = "";
484
-
485
-		if($seen === 0)
486
-			$sql_seen = " AND `seen` = 0 ";
487
-
488
-		$r = q("SELECT `id`, `url`, `photo`, `msg`, `date`, `seen` FROM `notify`
489
-				WHERE `uid` = %d $sql_seen ORDER BY `date` DESC LIMIT %d, %d ",
490
-			intval(local_user()),
491
-			intval($start),
492
-			intval($limit)
493
-		);
494
-
495
-		if (dbm::is_result($r))
496
-			$notifs = $this->formatNotifs($r, $ident);
497
-
498
-		$arr = array (
499
-			'notifications' => $notifs,
500
-			'ident' => $ident,
501
-			'total' => $total,
502
-		);
503
-
504
-		return $arr;
505
-	}
506
-
507
-	/**
508
-	 * @brief Addional SQL query string for the personal notifications
509
-	 *
510
-	 * @return string The additional sql query
511
-	 */
512
-	private function _personal_sql_extra() {
513
-		$myurl = System::baseUrl(true) . '/profile/'. $this->a->user['nickname'];
514
-		$myurl = substr($myurl,strpos($myurl,'://')+3);
515
-		$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
516
-		$diasp_url = str_replace('/profile/','/u/',$myurl);
517
-		$sql_extra = sprintf(" AND ( `item`.`author-link` regexp '%s' OR `item`.`tag` regexp '%s' OR `item`.`tag` regexp '%s' ) ",
518
-			dbesc($myurl . '$'),
519
-			dbesc($myurl . '\\]'),
520
-			dbesc($diasp_url . '\\]')
521
-		);
522
-
523
-		return $sql_extra;
524
-	}
525
-
526
-	/**
527
-	 * @brief Total number of personal notifications
528
-	 * @param int|string $seen
529
-	 *	If 0 only include notifications into the query
530
-	 *	which aren't marked as "seen"
531
-	 * @return int Number of personal notifications
532
-	 */
533
-	private function personalTotal($seen = 0) {
534
-		$sql_seen = "";
535
-		$sql_extra = $this->_personal_sql_extra();
536
-
537
-		if($seen === 0)
538
-			$sql_seen = " AND `item`.`unseen` = 1 ";
539
-
540
-		$r = q("SELECT COUNT(*) AS `total`
541
-				FROM `item` INNER JOIN `item` AS `pitem` ON  `pitem`.`id`=`item`.`parent`
542
-				WHERE `item`.`visible` = 1
543
-				$sql_extra
544
-				$sql_seen
545
-				AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 " ,
546
-			intval(local_user())
547
-		);
548
-
549
-		if (dbm::is_result($r))
550
-			return $r[0]['total'];
551
-
552
-		return 0;
553
-	}
554
-
555
-	/**
556
-	 * @brief Get personal notifications
557
-	 *
558
-	 * @param int|string $seen
559
-	 *	If 0 only include notifications into the query
560
-	 *	which aren't marked as "seen"
561
-	 * @param int $start Start the query at this point
562
-	 * @param int $limit Maximum number of query results
563
-	 *
564
-	 * @return array with
565
-	 *	string 'ident' => Notification identifier
566
-	 *	int 'total' => Total number of available personal notifications
567
-	 *	array 'notifications' => Personal notifications
568
-	 */
569
-	public function personalNotifs($seen = 0, $start = 0, $limit = 80) {
570
-		$ident = 'personal';
571
-		$total = $this->personalTotal($seen);
572
-		$sql_extra = $this->_personal_sql_extra();
573
-		$notifs = array();
574
-		$sql_seen = "";
575
-
576
-		if($seen === 0)
577
-			$sql_seen = " AND `item`.`unseen` = 1 ";
578
-
579
-		$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
580
-				`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
581
-				`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
582
-			FROM `item` INNER JOIN `item` AS `pitem` ON  `pitem`.`id`=`item`.`parent`
583
-			WHERE `item`.`visible` = 1
584
-				$sql_extra
585
-				$sql_seen
586
-				AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
587
-			ORDER BY `item`.`created` DESC LIMIT %d, %d " ,
588
-				intval(local_user()),
589
-				intval($start),
590
-				intval($limit)
591
-		);
592
-
593
-		if (dbm::is_result($r))
594
-			$notifs = $this->formatNotifs($r, $ident);
595
-
596
-		$arr = array (
597
-			'notifications' => $notifs,
598
-			'ident' => $ident,
599
-			'total' => $total,
600
-		);
601
-
602
-		return $arr;
603
-	}
604
-
605
-	/**
606
-	 * @brief Total number of home notifications
607
-	 * @param int|string $seen
608
-	 *	If 0 only include notifications into the query
609
-	 *	which aren't marked as "seen"
610
-	 * @return int Number of home notifications
611
-	 */
612
-	private function homeTotal($seen = 0) {
613
-		$sql_seen = "";
614
-
615
-		if($seen === 0)
616
-			$sql_seen = " AND `item`.`unseen` = 1 ";
617
-
618
-		$r = q("SELECT COUNT(*) AS `total` FROM `item`
619
-				WHERE `item`.`visible` = 1 AND
620
-				 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1
621
-				$sql_seen",
622
-			intval(local_user())
623
-		);
624
-
625
-		if (dbm::is_result($r))
626
-			return $r[0]['total'];
627
-
628
-		return 0;
629
-	}
630
-
631
-	/**
632
-	 * @brief Get home notifications
633
-	 *
634
-	 * @param int|string $seen
635
-	 *	If 0 only include notifications into the query
636
-	 *	which aren't marked as "seen"
637
-	 * @param int $start Start the query at this point
638
-	 * @param int $limit Maximum number of query results
639
-	 *
640
-	 * @return array with
641
-	 *	string 'ident' => Notification identifier
642
-	 *	int 'total' => Total number of available home notifications
643
-	 *	array 'notifications' => Home notifications
644
-	 */
645
-	public function homeNotifs($seen = 0, $start = 0, $limit = 80) {
646
-		$ident = 'home';
647
-		$total = $this->homeTotal($seen);
648
-		$notifs = array();
649
-		$sql_seen = "";
650
-
651
-		if($seen === 0)
652
-			$sql_seen = " AND `item`.`unseen` = 1 ";
653
-
654
-		$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
655
-				`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
656
-				`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
657
-			FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
658
-			WHERE `item`.`visible` = 1 AND
659
-				 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1
660
-				$sql_seen
661
-			ORDER BY `item`.`created` DESC LIMIT %d, %d ",
662
-				intval(local_user()),
663
-				intval($start),
664
-				intval($limit)
665
-		);
666
-
667
-		if (dbm::is_result($r))
668
-			$notifs = $this->formatNotifs($r, $ident);
669
-
670
-		$arr = array (
671
-			'notifications' => $notifs,
672
-			'ident' => $ident,
673
-			'total' => $total,
674
-		);
675
-
676
-		return $arr;
677
-	}
678
-
679
-	/**
680
-	 * @brief Total number of introductions
681
-	 * @param bool $all
682
-	 *	If false only include introductions into the query
683
-	 *	which aren't marked as ignored
684
-	 * @return int Number of introductions
685
-	 */
686
-	private function introTotal($all = false) {
687
-		$sql_extra = "";
688
-
689
-		if(!$all)
690
-			$sql_extra = " AND `ignore` = 0 ";
691
-
692
-		$r = q("SELECT COUNT(*) AS `total` FROM `intro`
693
-			WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
694
-				intval($_SESSION['uid'])
695
-		);
696
-
697
-		if (dbm::is_result($r))
698
-			return $r[0]['total'];
699
-
700
-		return 0;
701
-	}
702
-
703
-	/**
704
-	 * @brief Get introductions
705
-	 *
706
-	 * @param bool $all
707
-	 *	If false only include introductions into the query
708
-	 *	which aren't marked as ignored
709
-	 * @param int $start Start the query at this point
710
-	 * @param int $limit Maximum number of query results
711
-	 *
712
-	 * @return array with
713
-	 *	string 'ident' => Notification identifier
714
-	 *	int 'total' => Total number of available introductions
715
-	 *	array 'notifications' => Introductions
716
-	 */
717
-	public function introNotifs($all = false, $start = 0, $limit = 80) {
718
-		$ident = 'introductions';
719
-		$total = $this->introTotal($seen);
720
-		$notifs = array();
721
-		$sql_extra = "";
722
-
723
-		if(!$all)
724
-			$sql_extra = " AND `ignore` = 0 ";
725
-
726
-		/// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact
727
-		$r = q("SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
728
-				`fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`,
729
-				`fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`,
730
-				`gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
731
-				`gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
732
-				`gcontact`.`network` AS `gnetwork`, `gcontact`.`addr` AS `gaddr`
733
-			FROM `intro`
734
-				LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
735
-				LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
736
-				LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
737
-			WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0
738
-			LIMIT %d, %d",
739
-				intval($_SESSION['uid']),
740
-				intval($start),
741
-				intval($limit)
742
-		);
743
-
744
-		if (dbm::is_result($r))
745
-			$notifs = $this->formatIntros($r);
746
-
747
-		$arr = array (
748
-			'ident' => $ident,
749
-			'total' => $total,
750
-			'notifications' => $notifs,
751
-		);
752
-
753
-		return $arr;
754
-	}
755
-
756
-	/**
757
-	 * @brief Format the notification query in an usable array
758
-	 *
759
-	 * @param array $intros The array from the db query
760
-	 * @return array with the introductions
761
-	 */
762
-	private function formatIntros($intros) {
763
-		$knowyou = '';
764
-
765
-		foreach($intros as $it) {
766
-			// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
767
-			// We have to distinguish between these two because they use different data.
768
-
769
-			// Contact suggestions
770
-			if($it['fid']) {
771
-
772
-				$return_addr = bin2hex($this->a->user['nickname'] . '@' . $this->a->get_hostname() . (($this->a->path) ? '/' . $this->a->path : ''));
773
-
774
-				$intro = array(
775
-					'label' => 'friend_suggestion',
776
-					'notify_type' => t('Friend Suggestion'),
777
-					'intro_id' => $it['intro_id'],
778
-					'madeby' => $it['name'],
779
-					'contact_id' => $it['contact-id'],
780
-					'photo' => ((x($it,'fphoto')) ? proxy_url($it['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
781
-					'name' => $it['fname'],
782
-					'url' => zrl($it['furl']),
783
-					'hidden' => $it['hidden'] == 1,
784
-					'post_newfriend' => (intval(PConfig::get(local_user(),'system','post_newfriend')) ? '1' : 0),
785
-
786
-					'knowyou' => $knowyou,
787
-					'note' => $it['note'],
788
-					'request' => $it['frequest'] . '?addr=' . $return_addr,
789
-
790
-				);
791
-
792
-			// Normal connection requests
793
-			} else {
794
-
795
-				$it = $this->getMissingIntroData($it);
796
-
797
-				// Don't show these data until you are connected. Diaspora is doing the same.
798
-				if($it['gnetwork'] === NETWORK_DIASPORA) {
799
-					$it['glocation'] = "";
800
-					$it['gabout'] = "";
801
-					$it['ggender'] = "";
802
-				}
803
-				$intro = array(
804
-					'label' => (($it['network'] !== NETWORK_OSTATUS) ? 'friend_request' : 'follower'),
805
-					'notify_type' => (($it['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
806
-					'dfrn_id' => $it['issued-id'],
807
-					'uid' => $_SESSION['uid'],
808
-					'intro_id' => $it['intro_id'],
809
-					'contact_id' => $it['contact-id'],
810
-					'photo' => ((x($it,'photo')) ? proxy_url($it['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
811
-					'name' => $it['name'],
812
-					'location' => bbcode($it['glocation'], false, false),
813
-					'about' => bbcode($it['gabout'], false, false),
814
-					'keywords' => $it['gkeywords'],
815
-					'gender' => $it['ggender'],
816
-					'hidden' => $it['hidden'] == 1,
817
-					'post_newfriend' => (intval(PConfig::get(local_user(),'system','post_newfriend')) ? '1' : 0),
818
-					'url' => $it['url'],
819
-					'zrl' => zrl($it['url']),
820
-					'addr' => $it['gaddr'],
821
-					'network' => $it['gnetwork'],
822
-					'knowyou' => $it['knowyou'],
823
-					'note' => $it['note'],
824
-				);
825
-			}
826
-
827
-			$arr[] = $intro;
828
-		}
829
-
830
-		return $arr;
831
-	}
832
-
833
-	/**
834
-	 * @brief Check for missing contact data and try to fetch the data from
835
-	 *     from other sources
836
-	 *
837
-	 * @param array $arr The input array with the intro data
838
-	 *
839
-	 * @return array The array with the intro data
840
-	 */
841
-	private function getMissingIntroData($arr) {
842
-		// If the network and the addr isn't available from the gcontact
843
-		// table entry, take the one of the contact table entry
844
-		if ($arr['gnetwork'] == "") {
845
-			$arr['gnetwork'] = $arr['network'];
846
-		}
847
-		if ($arr['gaddr'] == "") {
848
-			$arr['gaddr'] = $arr['addr'];
849
-		}
850
-
851
-		// If the network and addr is still not available
852
-		// get the missing data data from other sources
853
-		if ($arr['gnetwork'] == "" || $arr['gaddr'] == "") {
854
-			$ret = get_contact_details_by_url($arr['url']);
855
-
856
-			if ($arr['gnetwork'] == "" && $ret['network'] != "") {
857
-				$arr['gnetwork'] = $ret['network'];
858
-			}
859
-			if ($arr['gaddr'] == "" && $ret['addr'] != "") {
860
-				$arr['gaddr'] = $ret['addr'];
861
-			}
862
-		}
863
-
864
-		return $arr;
865
-	}
866
-}

+ 7
- 6
include/Photo.php View File

@@ -7,6 +7,7 @@
7 7
 use Friendica\App;
8 8
 use Friendica\Core\Config;
9 9
 use Friendica\Core\System;
10
+use Friendica\Database\DBM;
10 11
 
11 12
 require_once("include/photos.php");
12 13
 
@@ -630,7 +631,7 @@ class Photo {
630 631
 	public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '') {
631 632
 
632 633
 		$r = dba::select('photo', array('guid'), array("`resource-id` = ? AND `guid` != ?", $rid, ''), array('limit' => 1));
633
-		if (dbm::is_result($r)) {
634
+		if (DBM::is_result($r)) {
634 635
 			$guid = $r['guid'];
635 636
 		} else {
636 637
 			$guid = get_guid();
@@ -643,7 +644,7 @@ class Photo {
643 644
 				'datasize' => strlen($this->imageString()), 'data' => $this->imageString(), 'scale' => $scale, 'profile' => $profile,
644 645
 				'allow_cid' => $allow_cid, 'allow_gid' => $allow_gid, 'deny_cid' => $deny_cid, 'deny_gid' => $deny_gid, 'desc' => $desc);
645 646
 
646
-		if (dbm::is_result($x)) {
647
+		if (DBM::is_result($x)) {
647 648
 			$r = dba::update('photo', $fields, array('id' => $x['id']));
648 649
 		} else {
649 650
 			$r = dba::insert('photo', $fields);
@@ -713,7 +714,7 @@ function guess_image_type($filename, $fromcurl=false) {
713 714
  */
714 715
 function update_contact_avatar($avatar, $uid, $cid, $force = false) {
715 716
 	$r = q("SELECT `avatar`, `photo`, `thumb`, `micro`, `nurl` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
716
-	if (!dbm::is_result($r)) {
717
+	if (!DBM::is_result($r)) {
717 718
 		return false;
718 719
 	} else {
719 720
 		$data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
@@ -730,7 +731,7 @@ function update_contact_avatar($avatar, $uid, $cid, $force = false) {
730 731
 			// Update the public contact (contact id = 0)
731 732
 			if ($uid != 0) {
732 733
 				$pcontact = dba::select('contact', array('id'), array('nurl' => $r[0]['nurl']), array('limit' => 1));
733
-				if (dbm::is_result($pcontact)) {
734
+				if (DBM::is_result($pcontact)) {
734 735
 					update_contact_avatar($avatar, 0, $pcontact['id'], $force);
735 736
 				}
736 737
 			}
@@ -748,7 +749,7 @@ function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) {
748 749
 		intval($uid),
749 750
 		intval($cid)
750 751
 	);
751
-	if (dbm::is_result($r) && strlen($r[0]['resource-id'])) {
752
+	if (DBM::is_result($r) && strlen($r[0]['resource-id'])) {
752 753
 		$hash = $r[0]['resource-id'];
753 754
 	} else {
754 755
 		$hash = photo_new_resource();
@@ -919,7 +920,7 @@ function store_photo(App $a, $uid, $imagedata = "", $url = "") {
919 920
 		WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
920 921
 		intval($uid));
921 922
 
922
-	if (!dbm::is_result($r)) {
923
+	if (!DBM::is_result($r)) {
923 924
 		logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG);
924 925
 		return(array());
925 926
 	}

+ 8
- 7
include/acl_selectors.php View File

@@ -6,6 +6,7 @@
6 6
 
7 7
 use Friendica\App;
8 8
 use Friendica\Core\Config;
9
+use Friendica\Database\DBM;
9 10
 
10 11
 require_once "include/contact_selectors.php";
11 12
 require_once "include/contact_widgets.php";
@@ -36,7 +37,7 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
36 37
 
37 38
 	call_hooks($a->module . '_pre_' . $selname, $arr);
38 39
 
39
-	if (dbm::is_result($r)) {
40
+	if (DBM::is_result($r)) {
40 41
 		foreach ($r as $rr) {
41 42
 			if ((is_array($preselected)) && in_array($rr['id'], $preselected)) {
42 43
 				$selected = " selected=\"selected\" ";
@@ -159,7 +160,7 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
159 160
 
160 161
 	call_hooks($a->module . '_pre_' . $selname, $arr);
161 162
 
162
-	if (dbm::is_result($r)) {
163
+	if (DBM::is_result($r)) {
163 164
 		foreach ($r as $rr) {
164 165
 			if ((is_array($preselected)) && in_array($rr['id'], $preselected)) {
165 166
 				$selected = " selected=\"selected\" ";
@@ -239,7 +240,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
239 240
 
240 241
 	$receiverlist = array();
241 242
 
242
-	if (dbm::is_result($r)) {
243
+	if (DBM::is_result($r)) {
243 244
 		foreach ($r as $rr) {
244 245
 			if ((is_array($preselected)) && in_array($rr['id'], $preselected)) {
245 246
 				$selected = " selected=\"selected\" ";
@@ -286,7 +287,7 @@ function prune_deadguys($arr) {
286 287
 
287 288
 	$r = q("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 ");
288 289
 
289
-	if (dbm::is_result($r)) {
290
+	if (DBM::is_result($r)) {
290 291
 		$ret = array();
291 292
 		foreach ($r as $rr) {
292 293
 			$ret[] = intval($rr['id']);
@@ -342,7 +343,7 @@ function populate_acl($user = null, $show_jotnets = false) {
342 343
 			$r = q("SELECT `pubmail` FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
343 344
 				intval(local_user())
344 345
 			);
345
-			if (dbm::is_result($r)) {
346
+			if (DBM::is_result($r)) {
346 347
 				$mail_enabled = true;
347 348
 				if (intval($r[0]['pubmail'])) {
348 349
 					$pubmail_enabled = true;
@@ -635,7 +636,7 @@ function acl_lookup(App $a, $out_type = 'json') {
635 636
 	}
636 637
 
637 638
 
638
-	if (dbm::is_result($r)) {
639
+	if (DBM::is_result($r)) {
639 640
 		$forums = array();
640 641
 		foreach ($r as $g) {
641 642
 			$entry = array(
@@ -689,7 +690,7 @@ function acl_lookup(App $a, $out_type = 'json') {
689 690
 				dbesc($search),
690 691
 				implode("', '", $known_contacts)
691 692
 		);
692
-		if (dbm::is_result($r)) {
693
+		if (DBM::is_result($r)) {
693 694
 			foreach ($r as $row) {
694 695
 				$contact = get_contact_details_by_url($row['author-link']);
695 696
 

+ 44
- 43
include/api.php View File

@@ -11,6 +11,7 @@ use Friendica\Core\System;
11 11
 use Friendica\Core\Config;
12 12
 use Friendica\Core\NotificationsManager;
13 13
 use Friendica\Core\Worker;
14
+use Friendica\Database\DBM;
14 15
 
15 16
 require_once 'include/HTTPExceptions.php';
16 17
 require_once 'include/bbcode.php';
@@ -211,7 +212,7 @@ $called_api = null;
211 212
 				dbesc(trim($user)),
212 213
 				dbesc($encrypted)
213 214
 			);
214
-			if (dbm::is_result($r)) {
215
+			if (DBM::is_result($r)) {
215 216
 				$record = $r[0];
216 217
 			}
217 218
 		}
@@ -460,7 +461,7 @@ $called_api = null;
460 461
 	function api_unique_id_to_url($id) {
461 462
 		$r = dba::select('contact', array('url'), array('uid' => 0, 'id' => $id), array('limit' => 1));
462 463
 
463
-		if (dbm::is_result($r)) {
464
+		if (DBM::is_result($r)) {
464 465
 			return $r["url"];
465 466
 		} else {
466 467
 			return false;
@@ -591,14 +592,14 @@ $called_api = null;
591 592
 		api_best_nickname($uinfo);
592 593
 
593 594
 		// if the contact wasn't found, fetch it from the contacts with uid = 0
594
-		if (!dbm::is_result($uinfo)) {
595
+		if (!DBM::is_result($uinfo)) {
595 596
 			$r = array();
596 597
 
597 598
 			if ($url != "") {
598 599
 				$r = q("SELECT * FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s' LIMIT 1", dbesc(normalise_link($url)));
599 600
 			}
600 601
 
601
-			if (dbm::is_result($r)) {
602
+			if (DBM::is_result($r)) {
602 603
 				$network_name = network_to_name($r[0]['network'], $r[0]['url']);
603 604
 
604 605
 				// If no nick where given, extract it from the address
@@ -1092,7 +1093,7 @@ $called_api = null;
1092 1093
 					AND `created` > '%s' AND `id` = `parent`",
1093 1094
 					intval(api_user()), dbesc($datefrom));
1094 1095
 
1095
-				if (dbm::is_result($r)) {
1096
+				if (DBM::is_result($r)) {
1096 1097
 					$posts_day = $r[0]["posts_day"];
1097 1098
 				} else {
1098 1099
 					$posts_day = 0;
@@ -1113,7 +1114,7 @@ $called_api = null;
1113 1114
 					AND `created` > '%s' AND `id` = `parent`",
1114 1115
 					intval(api_user()), dbesc($datefrom));
1115 1116
 
1116
-				if (dbm::is_result($r)) {
1117
+				if (DBM::is_result($r)) {
1117 1118
 					$posts_week = $r[0]["posts_week"];
1118 1119
 				} else {
1119 1120
 					$posts_week = 0;
@@ -1134,7 +1135,7 @@ $called_api = null;
1134 1135
 					AND `created` > '%s' AND `id` = `parent`",
1135 1136
 					intval(api_user()), dbesc($datefrom));
1136 1137
 
1137
-				if (dbm::is_result($r)) {
1138
+				if (DBM::is_result($r)) {
1138 1139
 					$posts_month = $r[0]["posts_month"];
1139 1140
 				} else {
1140 1141
 					$posts_month = 0;
@@ -1163,7 +1164,7 @@ $called_api = null;
1163 1164
 		if (requestdata('media_ids')) {
1164 1165
 			$r = q("SELECT `resource-id`, `scale`, `nickname`, `type` FROM `photo` INNER JOIN `user` ON `user`.`uid` = `photo`.`uid` WHERE `resource-id` IN (SELECT `resource-id` FROM `photo` WHERE `id` = %d) AND `scale` > 0 AND `photo`.`uid` = %d ORDER BY `photo`.`width` DESC LIMIT 1",
1165 1166
 				intval(requestdata('media_ids')), api_user());
1166
-			if (dbm::is_result($r)) {
1167
+			if (DBM::is_result($r)) {
1167 1168
 				$phototypes = Photo::supportedTypes();
1168 1169
 				$ext = $phototypes[$r[0]['type']];
1169 1170
 				$_REQUEST['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $r[0]['nickname'] . '/image/' . $r[0]['resource-id'] . ']';
@@ -1258,7 +1259,7 @@ $called_api = null;
1258 1259
 				dbesc(normalise_link($user_info['url']))
1259 1260
 		);
1260 1261
 
1261
-		if (dbm::is_result($lastwall)) {
1262
+		if (DBM::is_result($lastwall)) {
1262 1263
 			$lastwall = $lastwall[0];
1263 1264
 
1264 1265
 			$in_reply_to = api_in_reply_to($lastwall);
@@ -1356,7 +1357,7 @@ $called_api = null;
1356 1357
 				dbesc(normalise_link($user_info['url']))
1357 1358
 		);
1358 1359
 
1359
-		if (dbm::is_result($lastwall)) {
1360
+		if (DBM::is_result($lastwall)) {
1360 1361
 			$lastwall = $lastwall[0];
1361 1362
 
1362 1363
 			$in_reply_to = api_in_reply_to($lastwall);
@@ -1428,11 +1429,11 @@ $called_api = null;
1428 1429
 		if (x($_GET, 'q')) {
1429 1430
 			$r = q("SELECT id FROM `contact` WHERE `uid` = 0 AND `name` = '%s'", dbesc($_GET["q"]));
1430 1431
 
1431
-			if (!dbm::is_result($r)) {
1432
+			if (!DBM::is_result($r)) {
1432 1433
 				$r = q("SELECT `id` FROM `contact` WHERE `uid` = 0 AND `nick` = '%s'", dbesc($_GET["q"]));
1433 1434
 			}
1434 1435
 
1435
-			if (dbm::is_result($r)) {
1436
+			if (DBM::is_result($r)) {
1436 1437
 				$k = 0;
1437 1438
 				foreach ($r AS $user) {
1438 1439
 					$user_info = api_get_user($a, $user["id"], "json");
@@ -1681,7 +1682,7 @@ $called_api = null;
1681 1682
 		);
1682 1683
 
1683 1684
 		/// @TODO How about copying this to above methods which don't check $r ?
1684
-		if (!dbm::is_result($r)) {
1685
+		if (!DBM::is_result($r)) {
1685 1686
 			throw new BadRequestException("There is no status with this id.");
1686 1687
 		}
1687 1688
 
@@ -1736,7 +1737,7 @@ $called_api = null;
1736 1737
 		logger('API: api_conversation_show: '.$id);
1737 1738
 
1738 1739
 		$r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($id));
1739
-		if (dbm::is_result($r)) {
1740
+		if (DBM::is_result($r)) {
1740 1741
 			$id = $r[0]["parent"];
1741 1742
 		}
1742 1743
 
@@ -1769,7 +1770,7 @@ $called_api = null;
1769 1770
 			intval($start), intval($count)
1770 1771
 		);
1771 1772
 
1772
-		if (!dbm::is_result($r)) {
1773
+		if (!DBM::is_result($r)) {
1773 1774
 			throw new BadRequestException("There is no status with this id.");
1774 1775
 		}
1775 1776
 
@@ -1827,7 +1828,7 @@ $called_api = null;
1827 1828
 		);
1828 1829
 
1829 1830
 		/// @TODO other style than above functions!
1830
-		if (dbm::is_result($r) && $r[0]['body'] != "") {
1831
+		if (DBM::is_result($r) && $r[0]['body'] != "") {
1831 1832
 			if (strpos($r[0]['body'], "[/share]") !== false) {
1832 1833
 				$pos = strpos($r[0]['body'], "[share");
1833 1834
 				$post = substr($r[0]['body'], $pos);
@@ -2093,7 +2094,7 @@ $called_api = null;
2093 2094
 		$item = q("SELECT * FROM `item` WHERE `id`=%d AND `uid`=%d LIMIT 1",
2094 2095
 				$itemid, api_user());
2095 2096
 
2096
-		if (!dbm::is_result($item) || count($item) == 0) {
2097
+		if (!DBM::is_result($item) || count($item) == 0) {
2097 2098
 			throw new BadRequestException("Invalid item.");
2098 2099
 		}
2099 2100
 
@@ -3004,7 +3005,7 @@ $called_api = null;
3004 3005
 			intval(api_user())
3005 3006
 		);
3006 3007
 
3007
-		if (!dbm::is_result($r)) {
3008
+		if (!DBM::is_result($r)) {
3008 3009
 			return;
3009 3010
 		}
3010 3011
 
@@ -3138,7 +3139,7 @@ $called_api = null;
3138 3139
 			intval($id));
3139 3140
 
3140 3141
 		// error message if specified id is not in database
3141
-		if (!dbm::is_result($r)) {
3142
+		if (!DBM::is_result($r)) {
3142 3143
 			if ($verbose == "true") {
3143 3144
 				$answer = array('result' => 'error', 'message' => 'message id not in database');
3144 3145
 				return api_format_data("direct_messages_delete", $type, array('$result' => $answer));
@@ -3229,7 +3230,7 @@ $called_api = null;
3229 3230
 				intval($since_id),
3230 3231
 				intval($start),	intval($count)
3231 3232
 		);
3232
-		if ($verbose == "true" && !dbm::is_result($r)) {
3233
+		if ($verbose == "true" && !DBM::is_result($r)) {
3233 3234
 			$answer = array('result' => 'error', 'message' => 'no mails available');
3234 3235
 			return api_format_data("direct_messages_all", $type, array('$result' => $answer));
3235 3236
 		}
@@ -3334,7 +3335,7 @@ $called_api = null;
3334 3335
 		$r = q("SELECT DISTINCT `resource-id` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
3335 3336
 				intval(api_user()),
3336 3337
 				dbesc($album));
3337
-		if (!dbm::is_result($r))
3338
+		if (!DBM::is_result($r))
3338 3339
 			throw new BadRequestException("album not available");
3339 3340
 
3340 3341
 		// function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
@@ -3345,7 +3346,7 @@ $called_api = null;
3345 3346
 						dbesc($rr['resource-id'])
3346 3347
 						);
3347 3348
 
3348
-			if (!dbm::is_result($photo_item)) {
3349
+			if (!DBM::is_result($photo_item)) {
3349 3350
 				throw new InternalServerErrorException("problem with deleting items occured");
3350 3351
 			}
3351 3352
 			drop_item($photo_item[0]['id'],false);
@@ -3391,7 +3392,7 @@ $called_api = null;
3391 3392
 		$r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
3392 3393
 				intval(api_user()),
3393 3394
 				dbesc($album));
3394
-		if (!dbm::is_result($r)) {
3395
+		if (!DBM::is_result($r)) {
3395 3396
 			throw new BadRequestException("album not available");
3396 3397
 		}
3397 3398
 		// now let's update all photos to the albumname
@@ -3431,7 +3432,7 @@ $called_api = null;
3431 3432
 			'image/gif' => 'gif'
3432 3433
 		);
3433 3434
 		$data = array('photo'=>array());
3434
-		if (dbm::is_result($r)) {
3435
+		if (DBM::is_result($r)) {
3435 3436
 			foreach ($r as $rr) {
3436 3437
 				$photo = array();
3437 3438
 				$photo['id'] = $rr['resource-id'];
@@ -3500,7 +3501,7 @@ $called_api = null;
3500 3501
 					intval(api_user()),
3501 3502
 					dbesc($photo_id),
3502 3503
 					dbesc($album));
3503
-			if (!dbm::is_result($r)) {
3504
+			if (!DBM::is_result($r)) {
3504 3505
 				throw new BadRequestException("photo not available");
3505 3506
 			}
3506 3507
 		}
@@ -3620,7 +3621,7 @@ $called_api = null;
3620 3621
 				intval(api_user()),
3621 3622
 				dbesc($photo_id)
3622 3623
 			);
3623
-		if (!dbm::is_result($r)) {
3624
+		if (!DBM::is_result($r)) {
3624 3625
 			throw new BadRequestException("photo not available");
3625 3626
 		}
3626 3627
 		// now we can perform on the deletion of the photo
@@ -3636,7 +3637,7 @@ $called_api = null;
3636 3637
 				dbesc($photo_id)
3637 3638
 				);
3638 3639
 
3639
-			if (!dbm::is_result($photo_item)) {
3640
+			if (!DBM::is_result($photo_item)) {
3640 3641
 				throw new InternalServerErrorException("problem with deleting items occured");
3641 3642
 			}
3642 3643
 			// function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
@@ -3699,7 +3700,7 @@ $called_api = null;
3699 3700
 				intval(api_user()),
3700 3701
 				intval($profileid));
3701 3702
 			// error message if specified profile id is not in database
3702
-			if (!dbm::is_result($r)) {
3703
+			if (!DBM::is_result($r)) {
3703 3704
 				throw new BadRequestException("profile_id not available");
3704 3705
 			}
3705 3706
 			$is_default_profile = $r['profile'];
@@ -3804,7 +3805,7 @@ $called_api = null;
3804 3805
 			$contact = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d",
3805 3806
 							intval($cid),
3806 3807
 							intval(api_user()));
3807
-			$contact_not_found |= !dbm::is_result($contact);
3808
+			$contact_not_found |= !DBM::is_result($contact);
3808 3809
 		}
3809 3810
 		return $contact_not_found;
3810 3811
 	}
@@ -4020,7 +4021,7 @@ $called_api = null;
4020 4021
 		);
4021 4022
 
4022 4023
 		// prepare output data for photo
4023
-		if (dbm::is_result($r)) {
4024
+		if (DBM::is_result($r)) {
4024 4025
 			$data = array('photo' => $r[0]);
4025 4026
 			$data['photo']['id'] = $data['photo']['resource-id'];
4026 4027
 			if ($scale !== false) {
@@ -4129,7 +4130,7 @@ $called_api = null;
4129 4130
 			intval(api_user())
4130 4131
 		);
4131 4132
 
4132
-		if ((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) {
4133
+		if ((! DBM::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) {
4133 4134
 			throw new BadRequestException("Unknown contact");
4134 4135
 		}
4135 4136
 
@@ -4276,7 +4277,7 @@ $called_api = null;
4276 4277
 		$r = q("SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'",
4277 4278
 			dbesc(normalise_link($profile)));
4278 4279
 
4279
-		if (dbm::is_result($r)) {
4280
+		if (DBM::is_result($r)) {
4280 4281
 			$nick = $r[0]["nick"];
4281 4282
 		}
4282 4283
 
@@ -4284,7 +4285,7 @@ $called_api = null;
4284 4285
 			$r = q("SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'",
4285 4286
 				dbesc(normalise_link($profile)));
4286 4287
 
4287
-			if (dbm::is_result($r)) {
4288
+			if (DBM::is_result($r)) {
4288 4289
 				$nick = $r[0]["nick"];
4289 4290
 			}
4290 4291
 		}
@@ -4355,7 +4356,7 @@ $called_api = null;
4355 4356
 				intval($item['uid']),
4356 4357
 				dbesc($item['thr-parent']));
4357 4358
 
4358
-			if (dbm::is_result($r)) {
4359
+			if (DBM::is_result($r)) {
4359 4360
 				$in_reply_to['status_id'] = intval($r[0]['id']);
4360 4361
 			} else {
4361 4362
 				$in_reply_to['status_id'] = intval($item['parent']);
@@ -4369,7 +4370,7 @@ $called_api = null;
4369 4370
 				intval($in_reply_to['status_id'])
4370 4371
 			);
4371 4372
 
4372
-			if (dbm::is_result($r)) {
4373
+			if (DBM::is_result($r)) {
4373 4374
 				if ($r[0]['nick'] == "") {
4374 4375
 					$r[0]['nick'] = api_get_nick($r[0]["url"]);
4375 4376
 				}
@@ -4503,7 +4504,7 @@ $called_api = null;
4503 4504
 				intval($uid),
4504 4505
 				intval($gid));
4505 4506
 			// error message if specified gid is not in database
4506
-			if (!dbm::is_result($r))
4507
+			if (!DBM::is_result($r))
4507 4508
 				throw new BadRequestException("gid not available");
4508 4509
 		}
4509 4510
 		else
@@ -4558,7 +4559,7 @@ $called_api = null;
4558 4559
 			intval($uid),
4559 4560
 			intval($gid));
4560 4561
 		// error message if specified gid is not in database
4561
-		if (!dbm::is_result($r))
4562
+		if (!DBM::is_result($r))
4562 4563
 			throw new BadRequestException('gid not available');
4563 4564
 
4564 4565
 		// get data of the specified group id and group name
@@ -4567,7 +4568,7 @@ $called_api = null;
4567 4568
 			intval($gid),
4568 4569
 			dbesc($name));
4569 4570
 		// error message if specified gid is not in database
4570
-		if (!dbm::is_result($rname))
4571
+		if (!DBM::is_result($rname))
4571 4572
 			throw new BadRequestException('wrong group name');
4572 4573
 
4573 4574
 		// delete group
@@ -4606,7 +4607,7 @@ $called_api = null;
4606 4607
 			intval($uid),
4607 4608
 			dbesc($name));
4608 4609
 		// error message if specified group name already exists
4609
-		if (dbm::is_result($rname))
4610
+		if (DBM::is_result($rname))
4610 4611
 			throw new BadRequestException('group name already exists');
4611 4612
 
4612 4613
 		// check if specified group name is a deleted group
@@ -4614,7 +4615,7 @@ $called_api = null;
4614 4615
 			intval($uid),
4615 4616
 			dbesc($name));
4616 4617
 		// error message if specified group name already exists
4617
-		if (dbm::is_result($rname))
4618
+		if (DBM::is_result($rname))
4618 4619
 			$reactivate_group = true;
4619 4620
 
4620 4621
 		// create group
@@ -4845,7 +4846,7 @@ $called_api = null;
4845 4846
 			intval($uid));
4846 4847
 
4847 4848
 		// error message if specified id is not in database
4848
-		if (!dbm::is_result($r)) {
4849
+		if (!DBM::is_result($r)) {
4849 4850
 			$answer = array('result' => 'error', 'message' => 'message id not in database');
4850 4851
 			return api_format_data("direct_messages_setseen", $type, array('$result' => $answer));
4851 4852
 		}
@@ -4903,7 +4904,7 @@ $called_api = null;
4903 4904
 		$profile_url = $user_info["url"];
4904 4905
 
4905 4906
 		// message if nothing was found
4906
-		if (!dbm::is_result($r)) {
4907
+		if (!DBM::is_result($r)) {
4907 4908
 			$success = array('success' => false, 'search_results' => 'problem with query');
4908 4909
 		} elseif (count($r) == 0) {
4909 4910
 			$success = array('success' => false, 'search_results' => 'nothing found');
@@ -4956,7 +4957,7 @@ $called_api = null;
4956 4957
 				intval($profileid));
4957 4958
 
4958 4959
 			// error message if specified gid is not in database
4959
-			if (!dbm::is_result($r)) {
4960
+			if (!DBM::is_result($r)) {
4960 4961
 				throw new BadRequestException("profile_id not available");
4961 4962
 			}
4962 4963
 		} else {

+ 4
- 3
include/auth.php View File

@@ -3,6 +3,7 @@
3 3
 use Friendica\App;
4 4
 use Friendica\Core\System;
5 5
 use Friendica\Core\Config;
6
+use Friendica\Database\DBM;
6 7
 
7 8
 require_once('include/security.php');
8 9
 require_once('include/datetime.php');
@@ -58,7 +59,7 @@ if (isset($_SESSION) && x($_SESSION,'authenticated') && (!x($_POST,'auth-params'
58 59
 		$r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
59 60
 			intval($_SESSION['visitor_id'])
60 61
 		);
61
-		if (dbm::is_result($r)) {
62
+		if (DBM::is_result($r)) {
62 63
 			$a->contact = $r[0];
63 64
 		}
64 65
 	}
@@ -81,7 +82,7 @@ if (isset($_SESSION) && x($_SESSION,'authenticated') && (!x($_POST,'auth-params'
81 82
 			intval($_SESSION['uid'])
82 83
 		);
83 84
 
84
-		if (!dbm::is_result($r)) {
85
+		if (!DBM::is_result($r)) {
85 86
 			nuke_session();
86 87
 			goaway(System::baseUrl());
87 88
 		}
@@ -177,7 +178,7 @@ if (isset($_SESSION) && x($_SESSION,'authenticated') && (!x($_POST,'auth-params'
177 178
 				dbesc(trim($_POST['username'])),
178 179
 				dbesc($encrypted)
179 180
 			);
180
-			if (dbm::is_result($r))
181
+			if (DBM::is_result($r))
181 182
 				$record = $r[0];
182 183
 		}
183 184
 

+ 2
- 1
include/auth_ejabberd.php View File

@@ -34,6 +34,7 @@
34 34
 
35 35
 use Friendica\App;
36 36
 use Friendica\Core\Config;
37
+use Friendica\Database\DBM;
37 38
 
38 39
 if (sizeof($_SERVER["argv"]) == 0)
39 40
 	die();
@@ -152,7 +153,7 @@ class exAuth {
152 153
 			$sQuery = "SELECT `uid` FROM `user` WHERE `nickname`='".dbesc($sUser)."'";
153 154
 			$this->writeLog(LOG_DEBUG, "using query ". $sQuery);
154 155
 			$r = q($sQuery);
155
-			$found = dbm::is_result($r);
156
+			$found = DBM::is_result($r);
156 157
 		} else {
157 158
 			$found = false;
158 159
 		}

+ 2
- 1
include/cache.php View File

@@ -7,6 +7,7 @@
7 7
 
8 8
 use Friendica\Core\Config;
9 9
 use Friendica\Core\PConfig;
10
+use Friendica\Database\DBM;
10 11
 
11 12
 class Cache {
12 13
 	/**
@@ -104,7 +105,7 @@ class Cache {
104 105
 			dbesc($key)
105 106
 		);
106 107
 
107
-		if (dbm::is_result($r)) {
108
+		if (DBM::is_result($r)) {
108 109
 			$cached = $r[0]['v'];
109 110
 			$value = @unserialize($cached);
110 111
 

+ 3
- 2
include/contact_selectors.php View File

@@ -1,5 +1,6 @@
1 1
 <?php
2 2
 
3
+use Friendica\Database\DBM;
3 4
 use Friendica\Protocol\Diaspora;
4 5
 
5 6
 function contact_profile_assign($current,$foreign_net) {
@@ -13,7 +14,7 @@ function contact_profile_assign($current,$foreign_net) {
13 14
 	$r = q("SELECT `id`, `profile-name`, `is-default` FROM `profile` WHERE `uid` = %d",
14 15
 			intval($_SESSION['uid']));
15 16
 
16
-	if (dbm::is_result($r)) {
17
+	if (DBM::is_result($r)) {
17 18
 		foreach ($r as $rr) {
18 19
 			$selected = (($rr['id'] == $current || ($current == 0 && $rr['is-default'] == 1)) ? " selected=\"selected\" " : "");
19 20
 			$o .= "<option value=\"{$rr['id']}\" $selected >{$rr['profile-name']}</option>\r\n";
@@ -106,7 +107,7 @@ function network_to_name($s, $profile = "") {
106 107
 				INNER JOIN `gserver` ON `gserver`.`nurl` = `gcontact`.`server_url`
107 108
 				WHERE `gcontact`.`nurl` = ? AND `platform` != ''", normalise_link($profile));
108 109
 
109
-		if (dbm::is_result($r)) {
110
+		if (DBM::is_result($r)) {
110 111
 			$networkname = $r['platform'];
111 112
 		}
112 113
 	}

+ 3
- 2
include/contact_widgets.php View File

@@ -4,6 +4,7 @@ use Friendica\App;
4 4
 use Friendica\Core\System;
5 5
 use Friendica\Core\Config;
6 6
 use Friendica\Core\PConfig;
7
+use Friendica\Database\DBM;
7 8
 
8 9
 require_once 'include/contact_selectors.php';
9 10
 
@@ -233,11 +234,11 @@ function common_friends_visitor_widget($profile_uid) {
233 234
 		if (get_my_url()) {
234 235
 			$r = dba::select('contact', array('id'),
235 236
 					array('nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid), array('limit' => 1));
236
-			if (dbm::is_result($r)) {
237
+			if (DBM::is_result($r)) {
237 238
 				$cid = $r['id'];
238 239
 			} else {
239 240
 				$r = dba::select('gcontact', array('id'), array('nurl' => normalise_link(get_my_url())), array('limit' => 1));
240
-				if (dbm::is_result($r))
241
+				if (DBM::is_result($r))
241 242
 					$zcid = $r['id'];
242 243
 			}
243 244
 		}

+ 6
- 5
include/conversation.php View File

@@ -4,6 +4,7 @@ use Friendica\App;
4 4
 use Friendica\Core\Config;
5 5
 use Friendica\Core\PConfig;
6 6
 use Friendica\Core\System;
7
+use Friendica\Database\DBM;
7 8
 
8 9
 require_once "include/bbcode.php";
9 10
 require_once "include/acl_selectors.php";
@@ -122,7 +123,7 @@ function localize_item(&$item) {
122 123
 			WHERE `item`.`contact-id`=`contact`.`id`
123 124
 			AND `item`.`uri`='%s'",
124 125
 			dbesc($item['parent-uri']));
125
-		if (!dbm::is_result($r)) {
126
+		if (!DBM::is_result($r)) {
126 127
 			return;
127 128
 		}
128 129
 		$obj = $r[0];
@@ -273,7 +274,7 @@ function localize_item(&$item) {
273 274
 			AND `item`.`uri`='%s'",
274 275
 			dbesc($item['parent-uri']));
275 276
 
276
-		if (!dbm::is_result($r)) {
277
+		if (!DBM::is_result($r)) {
277 278
 			return;
278 279
 		}
279 280
 
@@ -329,7 +330,7 @@ function localize_item(&$item) {
329 330
 					intval($item['uid'])
330 331
 			);
331 332
 
332
-			if (dbm::is_result($r) && $r[0]['plink']) {
333
+			if (DBM::is_result($r) && $r[0]['plink']) {
333 334
 				$target = $r[0];
334 335
 				$Bname = $target['author-name'];
335 336
 				$Blink = $target['author-link'];
@@ -941,7 +942,7 @@ function best_link_url($item, &$sparkle, $url = '') {
941 942
 		$r = dba::select('contact', array('id'),
942 943
 			array('network' => NETWORK_DFRN, 'uid' => local_user(), 'nurl' => normalise_link($clean_url), 'pending' => false),
943 944
 			array('limit' => 1));
944
-		if (dbm::is_result($r)) {
945
+		if (DBM::is_result($r)) {
945 946
 			$best_url = 'redir/' . $r['id'];
946 947
 			$sparkle = true;
947 948
 			if ($url != '') {
@@ -992,7 +993,7 @@ function item_photo_menu($item) {
992 993
 	$network = '';
993 994
 	$rel = 0;
994 995
 	$r = dba::select('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])), array('limit' => 1));
995
-	if (dbm::is_result($r)) {
996
+	if (DBM::is_result($r)) {
996 997
 		$cid = $r['id'];
997 998
 		$network = $r['network'];
998 999
 		$rel = $r['rel'];

+ 3
- 2
include/cron.php View File

@@ -2,6 +2,7 @@
2 2
 
3 3
 use Friendica\Core\Config;
4 4
 use Friendica\Core\Worker;
5
+use Friendica\Database\DBM;
5 6
 
6 7
 function cron_run(&$argv, &$argc){
7 8
 	global $a;
@@ -161,7 +162,7 @@ function cron_poll_contacts($argc, $argv) {
161 162
 		dbesc(NETWORK_MAIL2)
162 163
 	);
163 164
 
164
-	if (!dbm::is_result($contacts)) {
165
+	if (!DBM::is_result($contacts)) {
165 166
 		return;
166 167
 	}
167 168
 
@@ -171,7 +172,7 @@ function cron_poll_contacts($argc, $argv) {
171 172
 			intval($c['id'])
172 173
 		);
173 174
 
174
-		if (!dbm::is_result($res)) {
175
+		if (!DBM::is_result($res)) {
175 176
 			continue;
176 177
 		}
177 178
 

+ 6
- 5
include/cronjobs.php View File

@@ -2,6 +2,7 @@
2 2
 
3 3
 use Friendica\App;
4 4
 use Friendica\Core\Config;
5
+use Friendica\Database\DBM;
5 6
 use Friendica\Network\Probe;
6 7
 
7 8
 function cronjobs_run(&$argv, &$argc){
@@ -78,7 +79,7 @@ function cronjobs_run(&$argv, &$argc){
78 79
  */
79 80
 function cron_update_photo_albums() {
80 81
 	$r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`");
81
-	if (!dbm::is_result($r)) {
82
+	if (!DBM::is_result($r)) {
82 83
 		return;
83 84
 	}
84 85
 
@@ -98,7 +99,7 @@ function cron_expire_and_remove_users() {
98 99
 
99 100
 	// delete user records for recently removed accounts
100 101
 	$r = q("SELECT * FROM `user` WHERE `account_removed` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
101
-	if (dbm::is_result($r)) {
102
+	if (DBM::is_result($r)) {
102 103
 		foreach ($r as $user) {
103 104
 			dba::delete('user', array('uid' => $user['uid']));
104 105
 		}
@@ -211,7 +212,7 @@ function cron_repair_diaspora(App $a) {
211 212
 	$r = q("SELECT `id`, `url` FROM `contact`
212 213
 		WHERE `network` = '%s' AND (`batch` = '' OR `notify` = '' OR `poll` = '' OR pubkey = '')
213 214
 			ORDER BY RAND() LIMIT 50", dbesc(NETWORK_DIASPORA));
214
-	if (!dbm::is_result($r)) {
215
+	if (!DBM::is_result($r)) {
215 216
 		return;
216 217
 	}
217 218
 
@@ -246,7 +247,7 @@ function cron_repair_database() {
246 247
 	// Sometimes there seem to be issues where the "self" contact vanishes.
247 248
 	// We haven't found the origin of the problem by now.
248 249
 	$r = q("SELECT `uid` FROM `user` WHERE NOT EXISTS (SELECT `uid` FROM `contact` WHERE `contact`.`uid` = `user`.`uid` AND `contact`.`self`)");
249
-	if (dbm::is_result($r)) {
250
+	if (DBM::is_result($r)) {
250 251
 		foreach ($r AS $user) {
251 252
 			logger('Create missing self contact for user '.$user['uid']);
252 253
 			user_create_self_contact($user['uid']);
@@ -262,7 +263,7 @@ function cron_repair_database() {
262 263
 
263 264
 	// Update the global contacts for local users
264 265
 	$r = q("SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`");
265
-	if (dbm::is_result($r)) {
266
+	if (DBM::is_result($r)) {
266 267
 		foreach ($r AS $user) {
267 268
 			update_gcontact_for_user($user["uid"]);
268 269
 		}

+ 3
- 2
include/datetime.php View File

@@ -6,6 +6,7 @@
6 6
 
7 7
 use Friendica\Core\Config;
8 8
 use Friendica\Core\PConfig;
9
+use Friendica\Database\DBM;
9 10
 
10 11
 /**
11 12
  * @brief Two-level sort for timezones.
@@ -589,7 +590,7 @@ function update_contact_birthdays() {
589 590
 	// In-network birthdays are handled within local_delivery
590 591
 
591 592
 	$r = q("SELECT * FROM `contact` WHERE `bd` != '' AND `bd` > '0001-01-01' AND SUBSTRING(`bd`, 1, 4) != `bdyear` ");
592
-	if (dbm::is_result($r)) {
593
+	if (DBM::is_result($r)) {
593 594
 		foreach ($r as $rr) {
594 595
 
595 596
 			logger('update_contact_birthday: ' . $rr['bd']);
@@ -611,7 +612,7 @@ function update_contact_birthdays() {
611 612
 				dbesc(datetime_convert('UTC','UTC', $nextbd)),
612 613
 				dbesc('birthday'));
613 614
 
614
-			if (dbm::is_result($s)) {
615
+			if (DBM::is_result($s)) {
615 616
 				continue;
616 617
 			}
617 618
 

+ 3
- 3
include/dba.php View File

@@ -1,7 +1,7 @@
1 1
 <?php
2 2
 use \Friendica\Core\System;
3
+use Friendica\Database\DBM;
3 4
 
4
-require_once("dbm.php");
5 5
 require_once('include/datetime.php');
6 6
 
7 7
 /**
@@ -176,7 +176,7 @@ class dba {
176 176
 		}
177 177
 
178 178
 		$r = self::p("EXPLAIN ".$query);
179
-		if (!dbm::is_result($r)) {
179
+		if (!DBM::is_result($r)) {
180 180
 			return;
181 181
 		}
182 182
 
@@ -227,7 +227,7 @@ class dba {
227 227
 		switch (self::$driver) {
228 228
 			case 'pdo':
229 229
 				$r = dba::p("SELECT 1");
230
-				if (dbm::is_result($r)) {
230
+				if (DBM::is_result($r)) {
231 231
 					$row = dba::inArray($r);
232 232
 					$connected = ($row[0]['1'] == '1');
233 233
 				}

+ 0
- 112
include/dbm.php View File

@@ -1,112 +0,0 @@
1
-<?php
2
-/**
3
- * @brief This class contain functions for the database management
4
- *
5
- * This class contains functions that doesn't need to know if pdo, mysqli or whatever is used.
6
- */
7
-class dbm {
8
-	/**
9
-	 * @brief Return a list of database processes
10
-	 *
11
-	 * @return array
12
-	 *      'list' => List of processes, separated in their different states
13
-	 *      'amount' => Number of concurrent database processes
14
-	 */
15
-	public static function processlist() {
16
-		$r = q("SHOW PROCESSLIST");
17
-		$s = array();
18
-
19
-		$processes = 0;
20
-		$states = array();
21
-		foreach ($r AS $process) {
22
-			$state = trim($process["State"]);
23
-
24
-			// Filter out all non blocking processes
25
-			if (!in_array($state, array("", "init", "statistics", "updating"))) {
26
-				++$states[$state];
27
-				++$processes;
28
-			}
29
-		}
30
-
31
-		$statelist = "";
32
-		foreach ($states AS $state => $usage) {
33
-			if ($statelist != "")
34
-				$statelist .= ", ";
35
-			$statelist .= $state.": ".$usage;
36
-		}
37
-		return(array("list" => $statelist, "amount" => $processes));
38
-	}
39
-
40
-	/**
41
-	 * Checks if $array is a filled array with at least one entry.
42
-	 *
43
-	 * @param       $array  mixed   A filled array with at least one entry
44
-	 * @return      Whether $array is a filled array or an object with rows
45
-	 */
46
-	public static function is_result($array) {
47
-		// It could be a return value from an update statement
48
-		if (is_bool($array)) {
49
-			return $array;
50
-		}
51
-
52
-		if (is_object($array)) {
53
-			return dba::num_rows($array) > 0;
54
-		}
55
-
56
-		return (is_array($array) && (count($array) > 0));
57
-	}
58
-
59
-	/**
60
-	 * @brief Callback function for "esc_array"
61
-	 *
62
-	 * @param mixed $value Array value
63
-	 * @param string $key Array key
64
-	 * @param boolean $add_quotation add quotation marks for string values
65
-	 */
66
-	private static function esc_array_callback(&$value, $key, $add_quotation) {
67
-
68
-		if (!$add_quotation) {
69
-			if (is_bool($value)) {
70
-				$value = ($value ? '1' : '0');
71
-			} else {
72
-				$value = dbesc($value);
73
-			}
74
-			return;
75
-		}
76
-
77
-		if (is_bool($value)) {
78
-			$value = ($value ? 'true' : 'false');
79
-		} elseif (is_float($value) || is_integer($value)) {
80
-			$value = (string)$value;
81
-		} else {
82
-			 $value = "'".dbesc($value)."'";
83
-		}
84
-	}
85
-
86
-	/**
87
-	 * @brief Escapes a whole array
88
-	 *
89
-	 * @param mixed $arr Array with values to be escaped
90
-	 * @param boolean $add_quotation add quotation marks for string values
91
-	 */
92
-	public static function esc_array(&$arr, $add_quotation = false) {
93
-		array_walk($arr, 'self::esc_array_callback', $add_quotation);
94
-	}
95
-
96
-	/**
97
-	 * Checks Converts any date string into a SQL compatible date string
98
-	 *
99
-	 * @param string $date a date string in any format
100
-	 * @return string SQL style date string
101
-	 */
102
-	public static function date($date = 'now') {
103
-		$timestamp = strtotime($date);
104
-
105
-		// Don't allow lower date strings as '0001-01-01 00:00:00'
106
-		if ($timestamp < -62135596800) {
107
-			$timestamp = -62135596800;
108
-		}
109
-
110
-		return date('Y-m-d H:i:s', (int)$timestamp);
111
-	}
112
-}

+ 18
- 17
include/dbstructure.php View File

@@ -3,6 +3,7 @@
3 3
 use Friendica\App;
4 4
 use Friendica\Core\System;
5 5
 use Friendica\Core\Config;
6
+use Friendica\Database\DBM;
6 7
 
7 8
 require_once "boot.php";
8 9
 require_once "include/text.php";
@@ -20,7 +21,7 @@ function convert_to_innodb() {
20 21
 	$r = q("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `engine` = 'MyISAM' AND `table_schema` = '%s'",
21 22
 		dbesc(dba::database_name()));
22 23
 
23
-	if (!dbm::is_result($r)) {
24
+	if (!DBM::is_result($r)) {
24 25
 		echo t('There are no tables on MyISAM.')."\n";
25 26
 		return;
26 27
 	}
@@ -30,7 +31,7 @@ function convert_to_innodb() {
30 31
 		echo $sql."\n";
31 32
 
32 33
 		$result = dba::e($sql);
33
-		if (!dbm::is_result($result)) {
34
+		if (!DBM::is_result($result)) {
34 35
 			print_update_error($sql);
35 36
 		}
36 37
 	}
@@ -50,7 +51,7 @@ function update_fail($update_id, $error_message) {
50 51
 	);
51 52
 
52 53
 	// No valid result?
53
-	if (!dbm::is_result($adminlist)) {
54
+	if (!DBM::is_result($adminlist)) {
54 55
 		logger(sprintf('Cannot notify administrators about update_id=%d, error_message=%s', $update_id, $error_message), LOGGER_NORMAL);
55 56
 
56 57
 		// Don't continue
@@ -114,7 +115,7 @@ function table_structure($table) {
114 115
 
115 116
 	$table_status = q("SHOW TABLE STATUS WHERE `name` = '%s'", $table);
116 117
 
117
-	if (dbm::is_result($table_status)) {
118
+	if (DBM::is_result($table_status)) {
118 119
 		$table_status = $table_status[0];
119 120
 	} else {
120 121
 		$table_status = array();
@@ -123,7 +124,7 @@ function table_structure($table) {
123 124
 	$fielddata = array();
124 125
 	$indexdata = array();
125 126
 
126
-	if (dbm::is_result($indexes))
127
+	if (DBM::is_result($indexes))
127 128
 		foreach ($indexes AS $index) {
128 129
 			if ($index['Key_name'] != 'PRIMARY' && $index['Non_unique'] == '0' && !isset($indexdata[$index["Key_name"]])) {
129 130
 				$indexdata[$index["Key_name"]] = array('UNIQUE');
@@ -137,7 +138,7 @@ function table_structure($table) {
137 138
 
138 139
 			$indexdata[$index["Key_name"]][] = $column;
139 140
 		}
140
-	if (dbm::is_result($structures)) {
141
+	if (DBM::is_result($structures)) {
141 142
 		foreach ($structures AS $field) {
142 143
 			$fielddata[$field["Field"]]["type"] = $field["Type"];
143 144
 			if ($field["Null"] == "NO") {
@@ -157,7 +158,7 @@ function table_structure($table) {
157 158
 			}
158 159
 		}
159 160
 	}
160
-	if (dbm::is_result($full_columns)) {
161
+	if (DBM::is_result($full_columns)) {
161 162
 		foreach ($full_columns AS $column) {
162 163
 			$fielddata[$column["Field"]]["Collation"] = $column["Collation"];
163 164
 		}
@@ -200,7 +201,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
200 201
 
201 202
 	if ($action) {
202 203
 		Config::set('system', 'maintenance', 1);
203
-		Config::set('system', 'maintenance_reason', sprintf(t(': Database update'), dbm::date().' '.date('e')));
204
+		Config::set('system', 'maintenance_reason', sprintf(t(': Database update'), DBM::date().' '.date('e')));
204 205
 	}
205 206
 
206 207
 	$errors = false;
@@ -214,7 +215,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
214 215
 		$tables = q("SHOW TABLES");
215 216
 	}
216 217
 
217
-	if (dbm::is_result($tables)) {
218
+	if (DBM::is_result($tables)) {
218 219
 		foreach ($tables AS $table) {
219 220
 			$table = current($table);
220 221
 
@@ -243,7 +244,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
243 244
 		$sql3 = "";
244 245
 		if (!isset($database[$name])) {
245 246
 			$r = db_create_table($name, $structure["fields"], $verbose, $action, $structure['indexes']);
246
-			if (!dbm::is_result($r)) {
247
+			if (!DBM::is_result($r)) {
247 248
 				$errors .= print_update_error($name);
248 249
 			}
249 250
 			$is_new_table = True;
@@ -433,7 +434,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
433 434
 			}
434 435
 
435 436
 			if ($action) {
436
-				Config::set('system', 'maintenance_reason', sprintf(t('%s: updating %s table.'), dbm::date().' '.date('e'), $name));
437
+				Config::set('system', 'maintenance_reason', sprintf(t('%s: updating %s table.'), DBM::date().' '.date('e'), $name));
437 438
 
438 439
 				// Ensure index conversion to unique removes duplicates
439 440
 				if ($is_unique && ($temp_name != $name)) {
@@ -441,13 +442,13 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
441 442
 						dba::e("SET session old_alter_table=1;");
442 443
 					} else {
443 444
 						dba::e("DROP TABLE IF EXISTS `".$temp_name."`;");
444
-						if (!dbm::is_result($r)) {
445
+						if (!DBM::is_result($r)) {
445 446
 							$errors .= print_update_error($sql3);
446 447
 							return $errors;
447 448
 						}
448 449
 
449 450
 						$r = dba::e("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
450
-						if (!dbm::is_result($r)) {
451
+						if (!DBM::is_result($r)) {
451 452
 							$errors .= print_update_error($sql3);
452 453
 							return $errors;
453 454
 						}
@@ -455,7 +456,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
455 456
 				}
456 457
 
457 458
 				$r = @dba::e($sql3);
458
-				if (!dbm::is_result($r)) {
459
+				if (!DBM::is_result($r)) {
459 460
 					$errors .= print_update_error($sql3);
460 461
 				}
461 462
 				if ($is_unique && ($temp_name != $name)) {
@@ -463,17 +464,17 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
463 464
 						dba::e("SET session old_alter_table=0;");
464 465
 					} else {
465 466
 						$r = dba::e("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";");
466
-						if (!dbm::is_result($r)) {
467
+						if (!DBM::is_result($r)) {
467 468
 							$errors .= print_update_error($sql3);
468 469
 							return $errors;
469 470
 						}
470 471
 						$r = dba::e("DROP TABLE `".$name."`;");
471
-						if (!dbm::is_result($r)) {
472
+						if (!DBM::is_result($r)) {
472 473
 							$errors .= print_update_error($sql3);
473 474
 							return $errors;
474 475
 						}
475 476
 						$r = dba::e("RENAME TABLE `".$temp_name."` TO `".$name."`;");
476
-						if (!dbm::is_result($r)) {
477
+						if (!DBM::is_result($r)) {
477 478
 							$errors .= print_update_error($sql3);
478 479
 							return $errors;
479 480
 						}

+ 15
- 14
include/delivery.php View File

@@ -3,8 +3,9 @@
3 3
 use Friendica\App;
4 4
 use Friendica\Core\System;
5 5
 use Friendica\Core\Config;
6
+use Friendica\Database\DBM;
6 7
 use Friendica\Protocol\Diaspora;
7
-use Friendica\Protocol\Dfrn;
8
+use Friendica\Protocol\DFRN;
8 9
 
9 10
 require_once 'include/queue_fn.php';
10 11
 require_once 'include/html2plain.php';
@@ -95,7 +96,7 @@ function delivery_run(&$argv, &$argc){
95 96
 				intval($item_id)
96 97
 			);
97 98
 
98
-			if ((!dbm::is_result($r)) || (!intval($r[0]['parent']))) {
99
+			if ((!DBM::is_result($r)) || (!intval($r[0]['parent']))) {
99 100
 				continue;
100 101
 			}
101 102
 
@@ -155,7 +156,7 @@ function delivery_run(&$argv, &$argc){
155 156
 			intval($uid)
156 157
 		);
157 158
 
158
-		if (!dbm::is_result($r)) {
159
+		if (!DBM::is_result($r)) {
159 160
 			continue;
160 161
 		}
161 162
 
@@ -226,7 +227,7 @@ function delivery_run(&$argv, &$argc){
226 227
 			intval($contact_id)
227 228
 		);
228 229
 
229
-		if (dbm::is_result($r)) {
230
+		if (DBM::is_result($r)) {
230 231
 			$contact = $r[0];
231 232
 		}
232 233
 		if ($contact['self']) {
@@ -243,12 +244,12 @@ function delivery_run(&$argv, &$argc){
243 244
 
244 245
 				if ($mail) {
245 246
 					$item['body'] = fix_private_photos($item['body'],$owner['uid'],null,$message[0]['contact-id']);
246
-					$atom = Dfrn::mail($item, $owner);
247
+					$atom = DFRN::mail($item, $owner);
247 248
 				} elseif ($fsuggest) {
248
-					$atom = Dfrn::fsuggest($item, $owner);
249
+					$atom = DFRN::fsuggest($item, $owner);
249 250
 					q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item['id']));
250 251
 				} elseif ($relocate) {
251
-					$atom = Dfrn::relocate($owner, $uid);
252
+					$atom = DFRN::relocate($owner, $uid);
252 253
 				} elseif ($followup) {
253 254
 					$msgitems = array();
254 255
 					foreach ($items as $item) {  // there is only one item
@@ -260,7 +261,7 @@ function delivery_run(&$argv, &$argc){
260 261
 							$msgitems[] = $item;
261 262
 						}
262 263
 					}
263
-					$atom = Dfrn::entries($msgitems,$owner);
264
+					$atom = DFRN::entries($msgitems,$owner);
264 265
 				} else {
265 266
 					$msgitems = array();
266 267
 					foreach ($items as $item) {
@@ -289,7 +290,7 @@ function delivery_run(&$argv, &$argc){
289 290
 							$msgitems[] = $item;
290 291
 						}
291 292
 					}
292
-					$atom = Dfrn::entries($msgitems,$owner);
293
+					$atom = DFRN::entries($msgitems,$owner);
293 294
 				}
294 295
 
295 296
 				logger('notifier entry: '.$contact["url"].' '.$target_item["guid"].' entry: '.$atom, LOGGER_DEBUG);
@@ -343,13 +344,13 @@ function delivery_run(&$argv, &$argc){
343 344
 							break;
344 345
 						}
345 346
 						logger('mod-delivery: local delivery');
346
-						Dfrn::import($atom, $x[0]);
347
+						DFRN::import($atom, $x[0]);
347 348
 						break;
348 349
 					}
349 350
 				}
350 351
 
351 352
 				if (!was_recently_delayed($contact['id'])) {
352