diff --git a/app/controllers/InfosController.php b/app/controllers/InfosController.php index 6f7b6bb22..8e3bfd8e5 100644 --- a/app/controllers/InfosController.php +++ b/app/controllers/InfosController.php @@ -2,6 +2,7 @@ class InfosController extends BaseController { function load() { + header('Content-type: application/json'); $this->session_only = false; $this->raw = true; } diff --git a/app/views/admin.tpl b/app/views/admin.tpl index 53fb8e45e..3c2e2198a 100644 --- a/app/views/admin.tpl +++ b/app/views/admin.tpl @@ -7,6 +7,7 @@
widget('Admin');?> widget('Statistics');?> + widget('Api');?>
diff --git a/app/widgets/Admin/Admin.php b/app/widgets/Admin/Admin.php index 6bbf500aa..a9c4fd0ef 100644 --- a/app/widgets/Admin/Admin.php +++ b/app/widgets/Admin/Admin.php @@ -27,8 +27,10 @@ class Admin extends WidgetBase { $this->addjs('admin.js'); $this->_conf = Conf::getServerConf(); - $this->saveConfig($_POST); - $_POST = null; + if(isset($_POST)) { + $this->saveConfig($_POST); + $_POST = null; + } } private function saveConfig($form) { @@ -151,9 +153,7 @@ class Admin extends WidgetBase { return $html; } - function prepareAdminGen() { - $html = ''; - + function prepareAdminGen() { $html .= '
'.$this->__('admin.general').' diff --git a/app/widgets/Api/Api.php b/app/widgets/Api/Api.php new file mode 100644 index 000000000..464ae57ef --- /dev/null +++ b/app/widgets/Api/Api.php @@ -0,0 +1,86 @@ + + * * + * Copyright (C)2014 MOVIM project + * + * See COPYING for licensing information. + */ + +class Api extends WidgetBase { + function load() + { + } + + function display() + { + $this->view->assign( + 'infos', + $this->__( + 'api.info', + '', + '', + '', + '')); + + $json = requestURL(MOVIM_API.'status', 1, array('uri' => BASE_URI)); + $json = json_decode($json); + + $conf = Conf::getServerConf(); + + if(isset($json)) { + $this->view->assign('json', $json); + if($json->status == 200) { + $this->view->assign('unregister', $this->genCallAjax('ajaxUnregister')); + $this->view->assign('unregister_status', $conf['unregister']); + } else { + $conf['unregister'] = false; + Conf::saveConfFile($conf); + $this->view->assign('register', $this->genCallAjax('ajaxRegister')); + } + } else { + $this->view->assign('json', null); + } + } + + function ajaxRegister() + { + $rewrite = false; + if(isset($_SERVER['HTTP_MOD_REWRITE']) && $_SERVER['HTTP_MOD_REWRITE']) { + $rewrite = true; + } + + $json = requestURL( + MOVIM_API.'register', + 1, + array( + 'uri' => BASE_URI, + 'rewrite' => $rewrite)); + $json = json_decode($json); + + if(isset($json) && $json->status == 200) { + RPC::call('movim_reload_this'); + Notification::appendNotification(t('Configuration updated')); + } + } + + function ajaxUnregister() + { + $conf = Conf::getServerConf(); + $conf['unregister'] = !$conf['unregister']; + Conf::saveConfFile($conf); + + sleep(2); + + RPC::call('movim_reload_this'); + RPC::commit(); + } +} diff --git a/app/widgets/Api/api.tpl b/app/widgets/Api/api.tpl new file mode 100644 index 000000000..287eeb30b --- /dev/null +++ b/app/widgets/Api/api.tpl @@ -0,0 +1,42 @@ +
+

{$infos}

+ + {if="isset($json)"} + {if="$json->status == 200"} +
+ {$c->__('api.registered')} + {if="!$unregister_status"} + + {$c->__('button.unregister')} + + {/if} +
+
+ + {if="$json->pod->activated"} +
+ {$c->__('api.validated')} +
+ {else} +
{$c->__('api.wait')}
+ {/if} + + {if="$unregister_status"} +
{$c->__('api.unregister')} + + {$c->__('button.reset')} + +
+
+ {/if} + {else} +
+ {$c->__('api.register')} + {$c->__('button.register')} +
+
+ {/if} + {else} +
{$c->__('api.error')}
+ {/if} +
diff --git a/app/widgets/Api/locales.ini b/app/widgets/Api/locales.ini new file mode 100644 index 000000000..297d92663 --- /dev/null +++ b/app/widgets/Api/locales.ini @@ -0,0 +1,7 @@ +api.title = 'API' +api.info = 'Here you can register your pod on the official %sMovim API%s and be listed on %sthe pods page%s.' +api.register = 'Your pod is not registered on the API' +api.registered = 'Your pod is registered on the API' +api.wait = 'Your pod is not yet validated' +api.validated = 'Your pod is validated' +api.unregister = 'You asked to be removed from the API, this request will be processed in a couple of hours' diff --git a/app/widgets/Config/Config.php b/app/widgets/Config/Config.php index 0ef343883..e2156088a 100644 --- a/app/widgets/Config/Config.php +++ b/app/widgets/Config/Config.php @@ -54,7 +54,7 @@ class Config extends WidgetBase { $this->user->setConfig($data); RPC::call('movim_reload_this'); - Notification::appendNotification(t('Configuration updated')); + Notification::appendNotification($this->__('config.updated')); } function ajaxSubmit($data) { diff --git a/app/widgets/Config/locales.ini b/app/widgets/Config/locales.ini index 487fde904..472bf887b 100644 --- a/app/widgets/Config/locales.ini +++ b/app/widgets/Config/locales.ini @@ -6,3 +6,4 @@ config.background_color = 'Background color' config.font_size = 'Font size' config.pattern = 'Pattern' config.info = 'This configuration is shared wherever you are connected !' +config.updated = 'Configuration updated' diff --git a/app/widgets/Infos/Infos.php b/app/widgets/Infos/Infos.php index be2cf0809..36fbdc33c 100644 --- a/app/widgets/Infos/Infos.php +++ b/app/widgets/Infos/Infos.php @@ -35,13 +35,21 @@ class Infos extends WidgetBase $sd = new \Modl\SessionxDAO(); + // We see if we have the url rewriting + $rewrite = false; + if(isset($_SERVER['HTTP_MOD_REWRITE']) && $_SERVER['HTTP_MOD_REWRITE']) { + $rewrite = true; + } + $infos = array( 'url' => BASE_URI, 'language' => $conf['defLang'], 'whitelist' => $conf['xmppWhiteList'], 'timezone' => $conf['timezone'], 'description' => $conf['description'], - 'phpversion' => phpversion(), + 'unregister' => $conf['unregister'], + 'php_version' => phpversion(), + 'rewrite' => $rewrite, 'version' => APP_VERSION, 'population' => $pop, 'connected' => $sd->getConnected() diff --git a/app/widgets/Pods/Pods.php b/app/widgets/Pods/Pods.php index 04c381f34..9ba9976eb 100644 --- a/app/widgets/Pods/Pods.php +++ b/app/widgets/Pods/Pods.php @@ -31,7 +31,7 @@ class Pods extends WidgetBase $json = json_decode($json); if(is_object($json) && $json->status == 200) { - $this->view->assign('pods', $json->pods); + $this->view->assign('pods', $json); } } } diff --git a/app/widgets/Pods/pods.tpl b/app/widgets/Pods/pods.tpl index fee3532ec..d91613981 100644 --- a/app/widgets/Pods/pods.tpl +++ b/app/widgets/Pods/pods.tpl @@ -1,17 +1,23 @@ -{loop="$pods"} -
-
- - {$value->url} - -
-
{$value->description}
-
- {$value->language} - {$value->connected} • {$value->population} -
-
-{/loop} +{if="isset($pods)"} + {loop="$pods->pods"} +
+
+ + {function="parse_url($value->url, PHP_URL_HOST)"} + +
+
{$value->description}
+
+ {$value->language} + {$value->connected} • {$value->population} +
+
+ {/loop} +{else} +
+
{$c->__('api.error')}
+
+{/if} diff --git a/bootstrap.php b/bootstrap.php index f57c75701..eb06faa55 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -115,7 +115,7 @@ class Bootstrap { define('HELPERS_PATH', DOCUMENT_ROOT . '/app/helpers/'); define('WIDGETS_PATH', DOCUMENT_ROOT . '/app/widgets/'); - define('MOVIM_API', 'http://localhost/api/movim_api/public/'); + define('MOVIM_API', 'https://api.movim.eu/'); if (!defined('DOCTYPE')) { define('DOCTYPE','text/html'); diff --git a/locales/locales.ini b/locales/locales.ini index f5f5b3ee2..12175cca1 100644 --- a/locales/locales.ini +++ b/locales/locales.ini @@ -61,6 +61,8 @@ button.update = 'Update' button.updating = 'Updating' button.submit = 'Submit' button.reset = 'Reset' +button.register = 'Register' +button.unregister = 'Unregister' button.save = 'Save' button.clear = 'Clear' button.upload = 'Upload' @@ -254,3 +256,6 @@ post.share = 'Share with' post.share_everyone = 'Everyone' post.share_your_contacts= 'Your contacts' post.delete = 'Delete this post' + +[api] +api.error = 'The API is not reachable, try again later' diff --git a/system/Conf.php b/system/Conf.php index cc6c3cdf8..414475705 100644 --- a/system/Conf.php +++ b/system/Conf.php @@ -45,6 +45,7 @@ class Conf 'boshUrl' => 'http://localhost:5280/http-bind', 'xmppWhiteList' => '', 'info' => '', + 'unregister' => false, 'user' => 'admin', 'pass' => '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'sizeLimit' => 20240001); diff --git a/system/Utils.php b/system/Utils.php index 60cc61bb5..d9586f4b8 100644 --- a/system/Utils.php +++ b/system/Utils.php @@ -452,13 +452,23 @@ function generateKey($size) { /* * @desc Request a simple url */ -function requestURL($url, $timeout = 10) { +function requestURL($url, $timeout = 10, $post = false) { $ch = curl_init($url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, $timeout); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + + if(is_array($post)) { + $params = ''; + + foreach($post as $key => $value) { + $params .= $key . '=' . $value .'&'; + } + curl_setopt ($ch, CURLOPT_POST, 1); + curl_setopt ($ch, CURLOPT_POSTFIELDS, $params); + } $rs = array(); diff --git a/themes/movim/css/nav.css b/themes/movim/css/nav.css index 58c32e896..f0b0c534a 100644 --- a/themes/movim/css/nav.css +++ b/themes/movim/css/nav.css @@ -77,6 +77,7 @@ nav .wrapper { .menu li .up { background-image: url(../img/icons/menu/upload.svg); } .menu li .plus { background-image: url(../img/icons/menu/plus.svg); } .menu li .search { background-image: url(../img/icons/menu/search.svg); } +.menu li .pods { background-image: url(../img/icons/menu/net.svg); } .menu li .users, .menu li .account { background-image: url(../img/icons/menu/users.svg); } .menu li .expand { background-image: url(../img/icons/menu/expand.svg); } diff --git a/themes/movim/img/icons/menu/net.svg b/themes/movim/img/icons/menu/net.svg new file mode 100644 index 000000000..9710d3108 --- /dev/null +++ b/themes/movim/img/icons/menu/net.svg @@ -0,0 +1,88 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + +