diff --git a/init.php b/init.php index a08fb9f5f..aa6ccab61 100644 --- a/init.php +++ b/init.php @@ -11,6 +11,7 @@ define('THEMES_PATH', BASE_PATH . 'themes/'); require_once(LIB_PATH . 'i18n.php'); require_once(LIB_PATH . 'Utils.php'); +require_once(LIB_PATH . 'Cache.php'); define('APP_TITLE', t("MOVIM - Test Client")); diff --git a/lib/Cache.php b/lib/Cache.php index 75a634b1c..c8be69ff3 100644 --- a/lib/Cache.php +++ b/lib/Cache.php @@ -1,12 +1,43 @@ getLogin(); + + if(!is_dir(BASE_PATH."/user/".$login."/cache")) + mkdir(BASE_PATH."/user/".$login."/cache", 0766); + + if(func_num_args() == 1) { + if(file_exists(BASE_PATH."/user/".$login."/cache/".$key)) { + $content = unserialize(file_get_contents(BASE_PATH."/user/".$login."/cache/".$key)); + } + + if(isset($content) && $content != "") + return $content; + else + return ""; + } + + if(func_num_args() == 2) { + if(!file_put_contents(BASE_PATH."/user/".$login."/cache/".$key, serialize($content))) { + throw new MovimException(sprintf(t("Couldn't set cache file %s"), $key)); + }/* else { + file_put_contents(BASE_PATH."/user/".$login."/".$key, $content); + }*/ + } +} #doc # classname: Cache # scope: PUBLIC # #/doc -class Cache +/*class Cache { # internal variables private $_login; @@ -44,5 +75,5 @@ class Cache } } -} +}*/ ### diff --git a/lib/Dispatcher.php b/lib/Dispatcher.php index 471a3baed..454045200 100644 --- a/lib/Dispatcher.php +++ b/lib/Dispatcher.php @@ -48,6 +48,27 @@ class Dispatcher extends Controller } } + function friend() + { + $user = new User(); + if(!$user->isLogged()) { + $this->login(); + } else { + if(isset($_GET['f']) && $_GET['f'] != "" ) { + $this->page->setTitle(sprintf(t('%s - Welcome to Movim'), APP_TITLE)); + $this->page->menuAddLink($this->page->theme_img('img/home_icon.png', 'home_icon').t('Home'), '?q=mainPage'); + $this->page->menuAddLink($_GET['f'], false, true); + $this->page->menuAddLink(t('Configuration'), '?q=config'); + $content = new PageBuilder($user); + + $this->page->setContent($content->build('friend.tpl')); + echo $this->page->build('page.tpl'); + } + else + $this->mainPage(); + } + } + function config() { $user = new User(); diff --git a/lib/Jaxl/CHANGELOG b/lib/Jaxl/CHANGELOG index 09b59c257..f62e6a642 100644 --- a/lib/Jaxl/CHANGELOG +++ b/lib/Jaxl/CHANGELOG @@ -1,5 +1,7 @@ version 2.1.2 ------------- +- Merged Movim 0.1 patched Jaxl lib into 'master' +- Merge branch 'master' of https://github.com/oldschoolindustries/JAXL into oldschoolindustries-master - Improved httpd class and related changed in core jaxl class. Also fixed a few typos inside core classes - Added option to pass getSXE option to Jaxl constructor (Whether Jaxl core should return a SimpleXMLElement object of parsed string with callback payloads) - Better handling for multi-instance jaxl applications (Use JAXL::addCore to add new instance) diff --git a/lib/Jaxl/README.md b/lib/Jaxl/README.md index 3b51df0f2..ea9dea222 100644 --- a/lib/Jaxl/README.md +++ b/lib/Jaxl/README.md @@ -9,7 +9,7 @@ version of Jaxl 1.x series which was hosted at google code. * Support for DIGEST-MD5, PLAIN, ANONYMOUS, X-FACEBOOK-PLATFORM authentication mechanisms * 32 implemented XMPP extensions [(XEP's)](http://xmpp.org/extensions/) including MUC, PubSub and PEP * Setup dynamic number of parallel XMPP instance on the fly -* Monitoring, Usage stat collection, rate limiting and other goodies +* Monitoring, usage stat collection, rate limiting and production ready goodies ## Download diff --git a/lib/Jaxl/core/jaxl.class.php b/lib/Jaxl/core/jaxl.class.php index ef32fb022..5e2e95998 100644 --- a/lib/Jaxl/core/jaxl.class.php +++ b/lib/Jaxl/core/jaxl.class.php @@ -57,14 +57,12 @@ static $included = array(); $tagMap = array( // core classes - 'JAXLBosh' => '/core/jaxl.bosh.php', 'JAXLCron' => '/core/jaxl.cron.php', 'JAXLHTTPd' => '/core/jaxl.httpd.php', 'JAXLog' => '/core/jaxl.logger.php', 'JAXLXml' => '/core/jaxl.parser.php', 'JAXLPlugin' => '/core/jaxl.plugin.php', 'JAXLUtil' => '/core/jaxl.util.php', - 'JAXLS5B' => '/core/jaxl.s5b.php', 'JAXLException' => '/core/jaxl.exception.php', 'XML' => '/core/jaxl.xml.php', // xmpp classes @@ -93,7 +91,7 @@ } return; } - + // cnt of connected instances global $jaxl_instance_cnt; $jaxl_instance_cnt = 0; @@ -116,8 +114,8 @@ * Include Jaxl core in you application and start connecting and managing multiple XMPP accounts * Packaged library is custom configured for running single instance Jaxl applications * - * For connecting multiple instance XMPP accounts inside your application rewrite Jaxl controller - * using combination of env/jaxl.php, env/jaxl.ini and env/jaxl.conf + * For connecting multiple instance XMPP accounts inside your application see documentation for + * addCore() method */ class JAXL extends XMPP { @@ -199,6 +197,11 @@ */ var $roster = array(); + /** + * Default status of connected Jaxl instance + */ + var $status = 'Online using Jaxl library http://code.google.com/p/jaxl'; + /** * Jaxl will track presence stanza's and update local $roster cache */ @@ -226,12 +229,12 @@ /** * Absolute path of log file for this Jaxl instance */ - var $logPath = '/var/log/jaxl.log'; + var $logPath = '/var/www/jaxl/jaxl.log'; /** * Absolute path of pid file for this Jaxl instance */ - var $pidPath = '/var/run/jaxl.pid'; + var $pidPath = '/var/www/jaxl/jaxl.pid'; /** * Enable/Disable shutdown callback on SIGH terms @@ -379,7 +382,7 @@ */ function setStatus($status=false, $show=false, $priority=false, $caps=false, $vcard=false) { $child = array(); - $child['status'] = ($status === false ? 'Online using Movim http://movim.eu' : $status); + $child['status'] = ($status === false ? $this->status : $status); $child['show'] = ($show === false ? 'chat' : $show); $child['priority'] = ($priority === false ? 1 : $priority); if($caps) $child['payload'] = $this->JAXL0115('getCaps', $this->features); @@ -677,11 +680,12 @@ $this->pass = $this->getConfigByPriority(@$config['pass'], "JAXL_USER_PASS", $this->pass); $this->domain = $this->getConfigByPriority(@$config['domain'], "JAXL_HOST_DOMAIN", $this->domain); $this->bareJid = $this->user."@".$this->domain; - + /* Optional params if not configured using jaxl.ini or $config take default values */ $this->host = $this->getConfigByPriority(@$config['host'], "JAXL_HOST_NAME", $this->domain); $this->port = $this->getConfigByPriority(@$config['port'], "JAXL_HOST_PORT", $this->port); $this->resource = $this->getConfigByPriority(@$config['resource'], "JAXL_USER_RESC", "jaxl.".$this->uid.".".$this->clocked); + $this->status = $this->getConfigByPriority(@$config['status'], "JAXL_USER_STATUS", $this->status); $this->logLevel = $this->getConfigByPriority(@$config['logLevel'], "JAXL_LOG_LEVEL", $this->logLevel); $this->logRotate = $this->getConfigByPriority(@$config['logRotate'], "JAXL_LOG_ROTATE", $this->logRotate); $this->logPath = $this->getConfigByPriority(@$config['logPath'], "JAXL_LOG_PATH", $this->logPath); @@ -748,18 +752,18 @@ if(!JAXLUtil::isWin() && JAXLUtil::pcntlEnabled() && $this->sigh) { pcntl_signal(SIGTERM, array($this, "shutdown")); pcntl_signal(SIGINT, array($this, "shutdown")); - $this->log("[[JAXL]] Registering callbacks for CTRL+C and kill.", 4); + $this->log("[[JAXL]] Registering shutdown callbacks", 5); } else { - $this->log("[[JAXL]] No callbacks registered for CTRL+C and kill.", 4); + $this->log("[[JAXL]] No callbacks for shutdown", 5); } // check Jaxl dependency on PHP extension in cli mode if($this->mode == "cli") { if(($this->openSSL = JAXLUtil::sslEnabled())) - $this->log("[[JAXL]] OpenSSL extension is loaded.", 4); + $this->log("[[JAXL]] OpenSSL extension is loaded.", 5); else - $this->log("[[JAXL]] OpenSSL extension not loaded.", 4); + $this->log("[[JAXL]] OpenSSL extension not loaded.", 5); if(!function_exists('fsockopen')) throw new JAXLException("[[JAXL]] Requires fsockopen method"); diff --git a/lib/Jaxl/core/jaxl.util.php b/lib/Jaxl/core/jaxl.util.php index 2da423e8b..7ab9effc0 100644 --- a/lib/Jaxl/core/jaxl.util.php +++ b/lib/Jaxl/core/jaxl.util.php @@ -49,9 +49,8 @@ public static function curl($url, $type='GET', $headers=false, $data=false, $user=false, $pass=false) { $ch = curl_init($url); - if(defined('CURL_ASYNC') && CURL_ASYNC) { - curl_setopt($ch, CURLOPT_TIMEOUT, 1); //1s - } + // added by Movim Project + if(defined('JAXL_CURL_ASYNC') && JAXL_CURL_ASYNC) curl_setopt($ch, CURLOPT_TIMEOUT, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, false); @@ -74,9 +73,8 @@ $rs['errno'] = curl_errno($ch); $rs['errmsg'] = curl_error($ch); $rs['header'] = curl_getinfo($ch); - - curl_close($ch); + curl_close($ch); return $rs; } diff --git a/lib/Jaxl/env/jaxl.ini b/lib/Jaxl/env/jaxl.ini index fc2d8473b..37db3d579 100644 --- a/lib/Jaxl/env/jaxl.ini +++ b/lib/Jaxl/env/jaxl.ini @@ -88,7 +88,7 @@ define('JAXL_COMPONENT_PORT', 5559); // Logging settings - define('JAXL_LOG_PATH', '/var/log/jaxl.log'); + define('JAXL_LOG_PATH', '/var/www/jaxl/jaxl.log'); define('JAXL_LOG_EVENT', true); define('JAXL_LOG_LEVEL', 4); define('JAXL_LOG_ROTATE', false); diff --git a/lib/Jaxl/xmpp/xmpp.class.php b/lib/Jaxl/xmpp/xmpp.class.php index 20df9dbb4..33ac7ec52 100644 --- a/lib/Jaxl/xmpp/xmpp.class.php +++ b/lib/Jaxl/xmpp/xmpp.class.php @@ -287,7 +287,7 @@ * $option = null (read until data is available) * $option = integer (read for so many seconds) */ - function getXML() { + function getXML() { // prepare select streams $streams = array(); $jaxls = $this->instances['xmpp']; foreach($jaxls as $cnt=>$jaxl) { @@ -407,11 +407,16 @@ $this->log("[[XMPPSend]] $ret\n".$xml, 4); return $ret; } - else { + else if($changed === 0) { $this->obuffer .= $xml; $this->log("[[XMPPSend]] Not ready for write, obuffer size:".strlen($this->obuffer), 1); return 0; } + else { + $this->obuffer .= $xml; + $this->log("[[XMPPSend]] Something horibly wrong here", 1); + return 0; + } } else if($xml == '') { $this->log("[[XMPPSend]] Tried to send an empty stanza, not processing", 1); diff --git a/lib/XMPPConnect.php b/lib/XMPPConnect.php index 71c26daae..281008906 100644 --- a/lib/XMPPConnect.php +++ b/lib/XMPPConnect.php @@ -130,7 +130,8 @@ class XMPPConnect } public function postAuth() { - $this->jaxl->getRosterList(); + //$this->jaxl->getRosterList(); + //$this->jaxl->getVCard(); } public function postAuthFailure() { @@ -159,7 +160,7 @@ class XMPPConnect public function logout() { - define('CURL_ASYNC', true); + define('JAXL_CURL_ASYNC', true); $this->jaxl->JAXL0206('endStream'); } @@ -175,7 +176,7 @@ class XMPPConnect */ public function pingServer() { - define('CURL_ASYNC', false); + define('JAXL_CURL_ASYNC', false); $this->jaxl->JAXL0206('ping'); } @@ -194,37 +195,32 @@ class XMPPConnect */ public function handle($payload) { - //movim_log($payload); - $evt = new EventHandler(); if(isset($payload['vCard'])) { // Holy mackerel, that's a vcard! + movim_log($payload); + movim_cache("vcard".$payload["from"], $payload); $evt->runEvent('vcardreceived', $payload); } elseif($payload['queryXmlns'] == "jabber:iq:roster") { + movim_cache("roster", $payload); $evt->runEvent('rosterreceived', $payload); } else { $evt->runEvent('none', var_export($payload, true)); } } - public function postRosterUpdate($payload) { + /*public function postRosterUpdate($payload) { $evt = new EventHandler(); $evt->runEvent('rosterreceived', $payload); - } + }*/ /* vCard methods * Ask for a vCard and handle it */ - public function getVCard() - { - define('CURL_ASYNC', true); - $this->jaxl->JAXL0054('getVCard', false, $this->jaxl->jid, false); - } - - public function vcardReturn($payload) + public function getVCard($jid = false) { - $evt = new EventHandler(); - $evt->runEvent('vcardreceived', $payload); + define('JAXL_CURL_ASYNC', true); + $this->jaxl->JAXL0054('getVCard', $jid, $this->jaxl->jid, false); } /* @@ -289,7 +285,7 @@ class XMPPConnect */ public function getRosterList() { - define('CURL_ASYNC', true); + define('JAXL_CURL_ASYNC', true); $this->jaxl->getRosterList(); } @@ -298,7 +294,7 @@ class XMPPConnect */ public function setStatus($status, $show) { - define('CURL_ASYNC', true); + define('JAXL_CURL_ASYNC', true); $this->jaxl->setStatus($status, $show, 41, true); } @@ -314,7 +310,7 @@ class XMPPConnect */ public function sendMessage($addressee, $body) { - define('CURL_ASYNC', true); + define('JAXL_CURL_ASYNC', true); // Checking on the jid. if($this->checkJid($addressee)) { $this->jaxl->sendMessage($addressee, $body, false, 'chat'); diff --git a/lib/widgets/Chat/Chat.php b/lib/widgets/Chat/Chat.php index c34e17de5..e8d49f311 100644 --- a/lib/widgets/Chat/Chat.php +++ b/lib/widgets/Chat/Chat.php @@ -67,7 +67,6 @@ class Chat extends Widget function ajaxSendMessage($to, $message) { -// movim_log($data); $user = new User(); $xmpp = XMPPConnect::getInstance($user->getLogin()); $xmpp->sendMessage($to, $message); diff --git a/lib/widgets/Friends/Friends.php b/lib/widgets/Friends/Friends.php index 42bd25afd..097a8228e 100644 --- a/lib/widgets/Friends/Friends.php +++ b/lib/widgets/Friends/Friends.php @@ -32,19 +32,26 @@ class Friends extends Widget function onRosterReceived($roster) { - $html = "