]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/XMPPHP/XMLStream.php
dbc4719e427f43bd223504d115d3e44dd427c9f7
[quix0rs-gnu-social.git] / extlib / XMPPHP / XMLStream.php
1 <?php
2 /**
3  * XMPPHP: The PHP XMPP Library
4  * Copyright (C) 2008  Nathanael C. Fritz
5  * This file is part of SleekXMPP.
6  * 
7  * XMPPHP is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  * 
12  * XMPPHP is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with XMPPHP; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  *
21  * @category   xmpphp 
22  * @package     XMPPHP
23  * @author       Nathanael C. Fritz <JID: fritzy@netflint.net>
24  * @author       Stephan Wentz <JID: stephan@jabber.wentz.it>
25  * @author       Michael Garvin <JID: gar@netflint.net>
26  * @copyright  2008 Nathanael C. Fritz
27  */
28
29 /** XMPPHP_Exception */
30 require_once dirname(__FILE__) . '/Exception.php';
31
32 /** XMPPHP_XMLObj */
33 require_once dirname(__FILE__) . '/XMLObj.php';
34
35 /** XMPPHP_Log */
36 require_once dirname(__FILE__) . '/Log.php';
37
38 /**
39  * XMPPHP XML Stream
40  * 
41  * @category   xmpphp 
42  * @package     XMPPHP
43  * @author       Nathanael C. Fritz <JID: fritzy@netflint.net>
44  * @author       Stephan Wentz <JID: stephan@jabber.wentz.it>
45  * @author       Michael Garvin <JID: gar@netflint.net>
46  * @copyright  2008 Nathanael C. Fritz
47  * @version     $Id$
48  */
49 class XMPPHP_XMLStream {
50         /**
51          * @var resource
52          */
53         protected $socket;
54         /**
55          * @var resource
56          */
57         protected $parser;
58         /**
59          * @var string
60          */
61         protected $buffer;
62         /**
63          * @var integer
64          */
65         protected $xml_depth = 0;
66         /**
67          * @var string
68          */
69         protected $host;
70         /**
71          * @var integer
72          */
73         protected $port;
74         /**
75          * @var string
76          */
77         protected $stream_start = '<stream>';
78         /**
79          * @var string
80          */
81         protected $stream_end = '</stream>';
82         /**
83          * @var boolean
84          */
85         protected $disconnected = false;
86         /**
87          * @var boolean
88          */
89         protected $sent_disconnect = false;
90         /**
91          * @var array
92          */
93         protected $ns_map = array();
94         /**
95          * @var array
96          */
97         protected $current_ns = array();
98         /**
99          * @var array
100          */
101         protected $xmlobj = null;
102         /**
103          * @var array
104          */
105         protected $nshandlers = array();
106         /**
107          * @var array
108          */
109         protected $xpathhandlers = array();
110         /**
111          * @var array
112          */
113         protected $idhandlers = array();
114         /**
115          * @var array
116          */
117         protected $eventhandlers = array();
118         /**
119          * @var integer
120          */
121         protected $lastid = 0;
122         /**
123          * @var string
124          */
125         protected $default_ns;
126         /**
127          * @var string
128          */
129         protected $until = '';
130         /**
131          * @var string
132          */
133         protected $until_count = '';
134         /**
135          * @var array
136          */
137         protected $until_happened = false;
138         /**
139          * @var array
140          */
141         protected $until_payload = array();
142         /**
143          * @var XMPPHP_Log
144          */
145         protected $log;
146         /**
147          * @var boolean
148          */
149         protected $reconnect = true;
150         /**
151          * @var boolean
152          */
153         protected $been_reset = false;
154         /**
155          * @var boolean
156          */
157         protected $is_server;
158         /**
159          * @var float
160          */
161         protected $last_send = 0;
162         /**
163          * @var boolean
164          */
165         protected $use_ssl = false;
166         /**
167          * @var integer
168          */
169         protected $reconnectTimeout = 30;
170
171         /**
172          * Constructor
173          *
174          * @param string  $host
175          * @param string  $port
176          * @param boolean $printlog
177          * @param string  $loglevel
178          * @param boolean $is_server
179          */
180         public function __construct($host = null, $port = null, $printlog = false, $loglevel = null, $is_server = false) {
181                 $this->reconnect = !$is_server;
182                 $this->is_server = $is_server;
183                 $this->host = $host;
184                 $this->port = $port;
185                 $this->setupParser();
186                 $this->log = new XMPPHP_Log($printlog, $loglevel);
187         }
188
189         /**
190          * Destructor
191          * Cleanup connection
192          */
193         public function __destruct() {
194                 if(!$this->disconnected && $this->socket) {
195                         $this->disconnect();
196                 }
197         }
198         
199         /**
200          * Return the log instance
201          *
202          * @return XMPPHP_Log
203          */
204         public function getLog() {
205                 return $this->log;
206         }
207         
208         /**
209          * Get next ID
210          *
211          * @return integer
212          */
213         public function getId() {
214                 $this->lastid++;
215                 return $this->lastid;
216         }
217
218         /**
219          * Set SSL
220          *
221          * @return integer
222          */
223         public function useSSL($use=true) {
224                 $this->use_ssl = $use;
225         }
226
227         /**
228          * Add ID Handler
229          *
230          * @param integer $id
231          * @param string  $pointer
232          * @param string  $obj
233          */
234         public function addIdHandler($id, $pointer, $obj = null) {
235                 $this->idhandlers[$id] = array($pointer, $obj);
236         }
237
238         /**
239          * Add Handler
240          *
241          * @param string $name
242          * @param string  $ns
243          * @param string  $pointer
244          * @param string  $obj
245          * @param integer $depth
246          */
247         public function addHandler($name, $ns, $pointer, $obj = null, $depth = 1) {
248                 #TODO deprication warning
249                 $this->nshandlers[] = array($name,$ns,$pointer,$obj, $depth);
250         }
251
252         /**
253          * Add XPath Handler
254          *
255          * @param string $xpath
256          * @param string $pointer
257          * @param
258          */
259         public function addXPathHandler($xpath, $pointer, $obj = null) {
260                 if (preg_match_all("/\(?{[^\}]+}\)?(\/?)[^\/]+/", $xpath, $regs)) {
261                         $ns_tags = $regs[0];
262                 } else {
263                         $ns_tags = array($xpath);
264                 }
265                 foreach($ns_tags as $ns_tag) {
266                         list($l, $r) = split("}", $ns_tag);
267                         if ($r != null) {
268                                 $xpart = array(substr($l, 1), $r);
269                         } else {
270                                 $xpart = array(null, $l);
271                         }
272                         $xpath_array[] = $xpart;
273                 }
274                 $this->xpathhandlers[] = array($xpath_array, $pointer, $obj);
275         }
276
277         /**
278          * Add Event Handler
279          *
280          * @param integer $id
281          * @param string  $pointer
282          * @param string  $obj
283          */
284         public function addEventHandler($name, $pointer, $obj) {
285                 $this->eventhandlers[] = array($name, $pointer, $obj);
286         }
287
288         /**
289          * Connect to XMPP Host
290          *
291          * @param integer $timeout
292          * @param boolean $persistent
293          * @param boolean $sendinit
294          */
295         public function connect($timeout = 30, $persistent = false, $sendinit = true) {
296                 $this->sent_disconnect = false;
297                 $starttime = time();
298                 
299                 do {
300                         $this->disconnected = false;
301                         $this->sent_disconnect = false;
302                         if($persistent) {
303                                 $conflag = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
304                         } else {
305                                 $conflag = STREAM_CLIENT_CONNECT;
306                         }
307                         $conntype = 'tcp';
308                         if($this->use_ssl) $conntype = 'ssl';
309                         $this->log->log("Connecting to $conntype://{$this->host}:{$this->port}");
310                         try {
311                                 $this->socket = @stream_socket_client("$conntype://{$this->host}:{$this->port}", $errno, $errstr, $timeout, $conflag);
312                         } catch (Exception $e) {
313                                 throw new XMPPHP_Exception($e->getMessage());
314                         }
315                         if(!$this->socket) {
316                                 $this->log->log("Could not connect.",  XMPPHP_Log::LEVEL_ERROR);
317                                 $this->disconnected = true;
318                                 # Take it easy for a few seconds
319                                 sleep(min($timeout, 5));
320                         }
321                 } while (!$this->socket && (time() - $starttime) < $timeout);
322                 
323                 if ($this->socket) {
324                         stream_set_blocking($this->socket, 1);
325                         if($sendinit) $this->send($this->stream_start);
326                 } else {
327                         throw new XMPPHP_Exception("Could not connect before timeout.");
328                 }
329         }
330
331         /**
332          * Reconnect XMPP Host
333          */
334         public function doReconnect() {
335                 if(!$this->is_server) {
336                         $this->log->log("Reconnecting ($this->reconnectTimeout)...",  XMPPHP_Log::LEVEL_WARNING);
337                         $this->connect($this->reconnectTimeout, false, false);
338                         $this->reset();
339                         $this->event('reconnect');
340                 }
341         }
342
343         public function setReconnectTimeout($timeout) {
344                 $this->reconnectTimeout = $timeout;
345         }
346         
347         /**
348          * Disconnect from XMPP Host
349          */
350         public function disconnect() {
351                 $this->log->log("Disconnecting...",  XMPPHP_Log::LEVEL_VERBOSE);
352                 if(false == (bool) $this->socket) {
353                         return;
354                 }
355                 $this->reconnect = false;
356                 $this->send($this->stream_end);
357                 $this->sent_disconnect = true;
358                 $this->processUntil('end_stream', 5);
359                 $this->disconnected = true;
360         }
361
362         /**
363          * Are we are disconnected?
364          *
365          * @return boolean
366          */
367         public function isDisconnected() {
368                 return $this->disconnected;
369         }
370
371         /**
372          * Core reading tool
373          * 0 -> only read if data is immediately ready
374          * NULL -> wait forever and ever
375          * integer -> process for this amount of time 
376          */
377         
378         private function __process($maximum=5) {
379                 
380                 $remaining = $maximum;
381                 
382                 do {
383                         $starttime = (microtime(true) * 1000000);
384                         $read = array($this->socket);
385                         $write = array();
386                         $except = array();
387                         if (is_null($maximum)) {
388                                 $secs = NULL;
389                                 $usecs = NULL;
390                         } else if ($maximum == 0) {
391                                 $secs = 0;
392                                 $usecs = 0;
393                         } else {
394                                 $usecs = $remaining % 1000000;
395                                 $secs = floor(($remaining - $usecs) / 1000000);
396                         }
397                         $updated = @stream_select($read, $write, $except, $secs, $usecs);
398                         if ($updated === false) {
399                                 $this->log->log("Error on stream_select()",  XMPPHP_Log::LEVEL_VERBOSE);                                
400                                 if ($this->reconnect) {
401                                         $this->doReconnect();
402                                 } else {
403                                         fclose($this->socket);
404                                         $this->socket = NULL;
405                                         return false;
406                                 }
407                         } else if ($updated > 0) {
408                                 # XXX: Is this big enough?
409                                 $buff = @fread($this->socket, 4096);
410                                 if(!$buff) { 
411                                         if($this->reconnect) {
412                                                 $this->doReconnect();
413                                         } else {
414                                                 fclose($this->socket);
415                                                 $this->socket = NULL;
416                                                 return false;
417                                         }
418                                 }
419                                 $this->log->log("RECV: $buff",  XMPPHP_Log::LEVEL_VERBOSE);
420                                 $ok = xml_parse($this->parser, $buff, false);
421                 if (!$ok) {
422                     $errcode = xml_get_error_code($this->parser);
423                     $errstr = xml_error_string($errcode);
424                     $this->log->log("XML ERROR: $errstr", XMPPHP_Log::LEVEL_VERBOSE);
425                 }
426                         } else {
427                                 # $updated == 0 means no changes during timeout.
428                         }
429                         $endtime = (microtime(true)*1000000);
430                         $time_past = $endtime - $starttime;
431                         $remaining = $remaining - $time_past;
432                 } while (is_null($maximum) || $remaining > 0);
433                 return true;
434         }
435         
436         /**
437          * Process
438          *
439          * @return string
440          */
441         public function process() {
442                 $this->__process(NULL);
443         }
444
445         /**
446          * Process until a timeout occurs
447          *
448          * @param integer $timeout
449          * @return string
450          */
451         public function processTime($timeout=NULL) {
452                 if (is_null($timeout)) {
453                         return $this->__process(NULL);
454                 } else {
455                         return $this->__process($timeout * 1000000);
456                 }
457         }
458
459         /**
460          * Process until a specified event or a timeout occurs
461          *
462          * @param string|array $event
463          * @param integer $timeout
464          * @return string
465          */
466         public function processUntil($event, $timeout=-1) {
467                 $start = time();
468                 if(!is_array($event)) $event = array($event);
469                 $this->until[] = $event;
470                 end($this->until);
471                 $event_key = key($this->until);
472                 reset($this->until);
473                 $this->until_count[$event_key] = 0;
474                 $updated = '';
475                 while(!$this->disconnected and $this->until_count[$event_key] < 1 and (time() - $start < $timeout or $timeout == -1)) {
476                         $this->__process();
477                 }
478                 if(array_key_exists($event_key, $this->until_payload)) {
479                         $payload = $this->until_payload[$event_key];
480                         unset($this->until_payload[$event_key]);
481                         unset($this->until_count[$event_key]);
482                         unset($this->until[$event_key]);
483                 } else {
484                         $payload = array();
485                 }
486                 return $payload;
487         }
488
489         /**
490          * Obsolete?
491          */
492         public function Xapply_socket($socket) {
493                 $this->socket = $socket;
494         }
495
496         /**
497          * XML start callback
498          * 
499          * @see xml_set_element_handler
500          *
501          * @param resource $parser
502          * @param string   $name
503          */
504         public function startXML($parser, $name, $attr) {
505                 if($this->been_reset) {
506                         $this->been_reset = false;
507                         $this->xml_depth = 0;
508                 }
509                 $this->xml_depth++;
510                 if(array_key_exists('XMLNS', $attr)) {
511                         $this->current_ns[$this->xml_depth] = $attr['XMLNS'];
512                 } else {
513                         $this->current_ns[$this->xml_depth] = $this->current_ns[$this->xml_depth - 1];
514                         if(!$this->current_ns[$this->xml_depth]) $this->current_ns[$this->xml_depth] = $this->default_ns;
515                 }
516                 $ns = $this->current_ns[$this->xml_depth];
517                 foreach($attr as $key => $value) {
518                         if(strstr($key, ":")) {
519                                 $key = explode(':', $key);
520                                 $key = $key[1];
521                                 $this->ns_map[$key] = $value;
522                         }
523                 }
524                 if(!strstr($name, ":") === false)
525                 {
526                         $name = explode(':', $name);
527                         $ns = $this->ns_map[$name[0]];
528                         $name = $name[1];
529                 }
530                 $obj = new XMPPHP_XMLObj($name, $ns, $attr);
531                 if($this->xml_depth > 1) {
532                         $this->xmlobj[$this->xml_depth - 1]->subs[] = $obj;
533                 }
534                 $this->xmlobj[$this->xml_depth] = $obj;
535         }
536
537         /**
538          * XML end callback
539          * 
540          * @see xml_set_element_handler
541          *
542          * @param resource $parser
543          * @param string   $name
544          */
545         public function endXML($parser, $name) {
546                 #$this->log->log("Ending $name",  XMPPHP_Log::LEVEL_DEBUG);
547                 #print "$name\n";
548                 if($this->been_reset) {
549                         $this->been_reset = false;
550                         $this->xml_depth = 0;
551                 }
552                 $this->xml_depth--;
553                 if($this->xml_depth == 1) {
554                         #clean-up old objects
555                         #$found = false; #FIXME This didn't appear to be in use --Gar
556                         foreach($this->xpathhandlers as $handler) {
557                                 if (is_array($this->xmlobj) && array_key_exists(2, $this->xmlobj)) {
558                                         $searchxml = $this->xmlobj[2];
559                                         $nstag = array_shift($handler[0]);
560                                         if (($nstag[0] == null or $searchxml->ns == $nstag[0]) and ($nstag[1] == "*" or $nstag[1] == $searchxml->name)) {
561                                                 foreach($handler[0] as $nstag) {
562                                                         if ($searchxml !== null and $searchxml->hasSub($nstag[1], $ns=$nstag[0])) {
563                                                                 $searchxml = $searchxml->sub($nstag[1], $ns=$nstag[0]);
564                                                         } else {
565                                                                 $searchxml = null;
566                                                                 break;
567                                                         }
568                                                 }
569                                                 if ($searchxml !== null) {
570                                                         if($handler[2] === null) $handler[2] = $this;
571                                                         $this->log->log("Calling {$handler[1]}",  XMPPHP_Log::LEVEL_DEBUG);
572                                                         $handler[2]->$handler[1]($this->xmlobj[2]);
573                                                 }
574                                         }
575                                 }
576                         }
577                         foreach($this->nshandlers as $handler) {
578                                 if($handler[4] != 1 and array_key_exists(2, $this->xmlobj) and  $this->xmlobj[2]->hasSub($handler[0])) {
579                                         $searchxml = $this->xmlobj[2]->sub($handler[0]);
580                                 } elseif(is_array($this->xmlobj) and array_key_exists(2, $this->xmlobj)) {
581                                         $searchxml = $this->xmlobj[2];
582                                 }
583                                 if($searchxml !== null and $searchxml->name == $handler[0] and ($searchxml->ns == $handler[1] or (!$handler[1] and $searchxml->ns == $this->default_ns))) {
584                                         if($handler[3] === null) $handler[3] = $this;
585                                         $this->log->log("Calling {$handler[2]}",  XMPPHP_Log::LEVEL_DEBUG);
586                                         $handler[3]->$handler[2]($this->xmlobj[2]);
587                                 }
588                         }
589                         foreach($this->idhandlers as $id => $handler) {
590                                 if(array_key_exists('id', $this->xmlobj[2]->attrs) and $this->xmlobj[2]->attrs['id'] == $id) {
591                                         if($handler[1] === null) $handler[1] = $this;
592                                         $handler[1]->$handler[0]($this->xmlobj[2]);
593                                         #id handlers are only used once
594                                         unset($this->idhandlers[$id]);
595                                         break;
596                                 }
597                         }
598                         if(is_array($this->xmlobj)) {
599                                 $this->xmlobj = array_slice($this->xmlobj, 0, 1);
600                                 if(isset($this->xmlobj[0]) && $this->xmlobj[0] instanceof XMPPHP_XMLObj) {
601                                         $this->xmlobj[0]->subs = null;
602                                 }
603                         }
604                         unset($this->xmlobj[2]);
605                 }
606                 if($this->xml_depth == 0 and !$this->been_reset) {
607                         if(!$this->disconnected) {
608                                 if(!$this->sent_disconnect) {
609                                         $this->send($this->stream_end);
610                                 }
611                                 $this->disconnected = true;
612                                 $this->sent_disconnect = true;
613                                 fclose($this->socket);
614                                 if($this->reconnect) {
615                                         $this->doReconnect();
616                                 }
617                         }
618                         $this->event('end_stream');
619                 }
620         }
621
622         /**
623          * XML character callback
624          * @see xml_set_character_data_handler
625          *
626          * @param resource $parser
627          * @param string   $data
628          */
629         public function charXML($parser, $data) {
630                 if(array_key_exists($this->xml_depth, $this->xmlobj)) {
631                         $this->xmlobj[$this->xml_depth]->data .= $data;
632                 }
633         }
634
635         /**
636          * Event?
637          *
638          * @param string $name
639          * @param string $payload
640          */
641         public function event($name, $payload = null) {
642                 $this->log->log("EVENT: $name",  XMPPHP_Log::LEVEL_DEBUG);
643                 foreach($this->eventhandlers as $handler) {
644                         if($name == $handler[0]) {
645                                 if($handler[2] === null) {
646                                         $handler[2] = $this;
647                                 }
648                                 $handler[2]->$handler[1]($payload);
649                         }
650                 }
651                 foreach($this->until as $key => $until) {
652                         if(is_array($until)) {
653                                 if(in_array($name, $until)) {
654                                         $this->until_payload[$key][] = array($name, $payload);
655                                         if(!isset($this->until_count[$key])) {
656                                                 $this->until_count[$key] = 0;
657                                         }
658                                         $this->until_count[$key] += 1;
659                                         #$this->until[$key] = false;
660                                 }
661                         }
662                 }
663         }
664
665         /**
666          * Read from socket
667          */
668         public function read() {
669                 $buff = @fread($this->socket, 1024);
670                 if(!$buff) { 
671                         if($this->reconnect) {
672                                 $this->doReconnect();
673                         } else {
674                                 fclose($this->socket);
675                                 return false;
676                         }
677                 }
678                 $this->log->log("RECV: $buff",  XMPPHP_Log::LEVEL_VERBOSE);
679                 $ok = xml_parse($this->parser, $buff, false);
680                 if (!$ok) {
681                     $errcode = xml_get_error_code($this->parser);
682                     $errstr = xml_error_string($errcode);
683                     $this->log->log("XML ERROR: $errstr", XMPPHP_Log::LEVEL_VERBOSE);
684                 }
685         }
686
687         /**
688          * Send to socket
689          *
690          * @param string $msg
691          */
692         public function send($msg, $timeout=NULL) {
693
694                 if (is_null($timeout)) {
695                         $secs = NULL;
696                         $usecs = NULL;
697                 } else if ($timeout == 0) {
698                         $secs = 0;
699                         $usecs = 0;
700                 } else {
701                         $maximum = $timeout * 1000000;
702                         $usecs = $maximum % 1000000;
703                         $secs = floor(($maximum - $usecs) / 1000000);
704                 }
705                 
706                 $read = array();
707                 $write = array($this->socket);
708                 $except = array();
709                 
710                 $select = @stream_select($read, $write, $except, $secs, $usecs);
711                 
712                 if($select === False) {
713                         $this->log->log("ERROR sending message; reconnecting.");
714                         $this->doReconnect();
715                         # TODO: retry send here
716                         return false;
717                 } elseif ($select > 0) {
718                         $this->log->log("Socket is ready; send it.", XMPPHP_Log::LEVEL_VERBOSE);
719                 } else {
720                         $this->log->log("Socket is not ready; break.", XMPPHP_Log::LEVEL_ERROR);
721                         return false;
722                 }
723                 
724                 $sentbytes = @fwrite($this->socket, $msg);
725                 $this->log->log("SENT: " . mb_substr($msg, 0, $sentbytes, '8bit'), XMPPHP_Log::LEVEL_VERBOSE);
726                 if($sentbytes === FALSE) {
727                         $this->log->log("ERROR sending message; reconnecting.", XMPPHP_Log::LEVEL_ERROR);
728                         $this->doReconnect();
729                         return false;
730                 }
731                 $this->log->log("Successfully sent $sentbytes bytes.", XMPPHP_Log::LEVEL_VERBOSE);
732                 return $sentbytes;
733         }
734
735         public function time() {
736                 list($usec, $sec) = explode(" ", microtime());
737                 return (float)$sec + (float)$usec;
738         }
739
740         /**
741          * Reset connection
742          */
743         public function reset() {
744                 $this->xml_depth = 0;
745                 unset($this->xmlobj);
746                 $this->xmlobj = array();
747                 $this->setupParser();
748                 if(!$this->is_server) {
749                         $this->send($this->stream_start);
750                 }
751                 $this->been_reset = true;
752         }
753
754         /**
755          * Setup the XML parser
756          */
757         public function setupParser() {
758                 $this->parser = xml_parser_create('UTF-8');
759                 xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1);
760                 xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
761                 xml_set_object($this->parser, $this);
762                 xml_set_element_handler($this->parser, 'startXML', 'endXML');
763                 xml_set_character_data_handler($this->parser, 'charXML');
764         }
765
766         public function readyToProcess() {
767                 $read = array($this->socket);
768                 $write = array();
769                 $except = array();
770                 $updated = @stream_select($read, $write, $except, 0);
771                 return (($updated !== false) && ($updated > 0));
772         }
773 }