Browse Source

- Add a first version of the API support

pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
03168c3515
  1. 1
      app/controllers/InfosController.php
  2. 1
      app/views/admin.tpl
  3. 10
      app/widgets/Admin/Admin.php
  4. 86
      app/widgets/Api/Api.php
  5. 42
      app/widgets/Api/api.tpl
  6. 7
      app/widgets/Api/locales.ini
  7. 2
      app/widgets/Config/Config.php
  8. 1
      app/widgets/Config/locales.ini
  9. 10
      app/widgets/Infos/Infos.php
  10. 2
      app/widgets/Pods/Pods.php
  11. 40
      app/widgets/Pods/pods.tpl
  12. 2
      bootstrap.php
  13. 5
      locales/locales.ini
  14. 1
      system/Conf.php
  15. 16
      system/Utils.php
  16. 1
      themes/movim/css/nav.css
  17. 88
      themes/movim/img/icons/menu/net.svg

1
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;
}

1
app/views/admin.tpl

@ -7,6 +7,7 @@
<div class="moving_block" >
<?php $this->widget('Admin');?>
<?php $this->widget('Statistics');?>
<?php $this->widget('Api');?>
</div>
</div>
</div>

10
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 .= '
<fieldset>
<legend>'.$this->__('admin.general').'</legend>

86
app/widgets/Api/Api.php

@ -0,0 +1,86 @@
<?php
/**
* @package Widgets
*
* @file Statistics.php
* This file is part of MOVIM.
*
* @brief The administration widget.
*
* @author Timothée Jaussoin <edhelas@gmail.com>
* *
* 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',
'<a href="http://api.movim.eu/" target="_blank">',
'</a>',
'<a href="'.$this->route('pods').'">',
'</a>'));
$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();
}
}

42
app/widgets/Api/api.tpl

@ -0,0 +1,42 @@
<div id="api" class="tabelem padded" title="{$c->__("api.title")}">
<p>{$infos}</p>
{if="isset($json)"}
{if="$json->status == 200"}
<div class="message success">
{$c->__('api.registered')}
{if="!$unregister_status"}
<a class="button color red oppose" onclick="{$unregister}">
{$c->__('button.unregister')}
</a>
{/if}
<div class="clear"></div>
</div>
{if="$json->pod->activated"}
<div class="message success">
{$c->__('api.validated')}
</div>
{else}
<div class="message warning">{$c->__('api.wait')}</div>
{/if}
{if="$unregister_status"}
<div class="message info">{$c->__('api.unregister')}
<a class="button color orange oppose" onclick="{$unregister}">
{$c->__('button.reset')}
</a>
<div class="clear"></div>
</div>
{/if}
{else}
<div class="message info">
{$c->__('api.register')}
<a class="button color green oppose" onclick="{$register}">{$c->__('button.register')}</a>
<div class="clear"></div>
</div>
{/if}
{else}
<div class="message error">{$c->__('api.error')}</div>
{/if}
</div>

7
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'

2
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) {

1
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'

10
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()

2
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);
}
}
}

40
app/widgets/Pods/pods.tpl

@ -1,17 +1,23 @@
{loop="$pods"}
<article class="block">
<header>
<span class="title">
<a href="{$value->url}" target="_blank">{$value->url}</a>
</span>
</header>
<section class="content">{$value->description}</section>
<footer>
<img
title="{$value->language}"
alt="{$value->language}"
src="{$c->flagPath($value->language)}"/>
<span>{$value->connected}{$value->population}</span>
</footer>
</article>
{/loop}
{if="isset($pods)"}
{loop="$pods->pods"}
<article class="block">
<header>
<span class="title">
<a href="{$value->url}" target="_blank">{function="parse_url($value->url, PHP_URL_HOST)"}</a>
</span>
</header>
<section class="content">{$value->description}</section>
<footer>
<img
title="{$value->language}"
alt="{$value->language}"
src="{$c->flagPath($value->language)}"/>
<span>{$value->connected}{$value->population}</span>
</footer>
</article>
{/loop}
{else}
<div class="padded">
<div class="message error">{$c->__('api.error')}</div>
</div>
{/if}

2
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');

5
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'

1
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);

16
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();

1
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); }

88
themes/movim/img/icons/menu/net.svg

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generated by IcoMoon.io -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
width="32"
height="32"
viewBox="0 0 32 32"
id="svg2"
inkscape:version="0.48.4 r9939"
sodipodi:docname="net.svg">
<metadata
id="metadata10">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs8" />
<sodipodi:namedview
pagecolor="#000000"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="1"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1014"
id="namedview6"
showgrid="false"
inkscape:zoom="14.86"
inkscape:cx="6.1596339"
inkscape:cy="16.001358"
inkscape:window-x="0"
inkscape:window-y="23"
inkscape:window-maximized="1"
inkscape:current-layer="svg2" />
<path
sodipodi:type="arc"
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linecap:square;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path3803"
sodipodi:cx="6.8304172"
sodipodi:cy="6.3270526"
sodipodi:rx="4.3405113"
sodipodi:ry="4.3405113"
d="m 11.170928,6.3270526 a 4.3405113,4.3405113 0 1 1 -8.6810222,0 4.3405113,4.3405113 0 1 1 8.6810222,0 z"
transform="matrix(0.98959123,0.26962431,-0.26962431,0.98959123,6.1616871,-1.2238856)" />
<path
transform="matrix(0.98959123,0.26962431,-0.26962431,0.98959123,0.5889972,17.993748)"
sodipodi:type="arc"
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linecap:square;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path3803-9"
sodipodi:cx="6.8304172"
sodipodi:cy="6.3270526"
sodipodi:rx="4.3405113"
sodipodi:ry="4.3405113"
d="m 11.170928,6.3270526 a 4.3405113,4.3405113 0 1 1 -8.6810222,0 4.3405113,4.3405113 0 1 1 8.6810222,0 z" />
<path
transform="matrix(0.98959123,0.26962431,-0.26962431,0.98959123,21.461565,12.407638)"
sodipodi:type="arc"
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linecap:square;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path3803-7"
sodipodi:cx="6.8304172"
sodipodi:cy="6.3270526"
sodipodi:rx="4.3405113"
sodipodi:ry="4.3405113"
d="m 11.170928,6.3270526 a 4.3405113,4.3405113 0 1 1 -8.6810222,0 4.3405113,4.3405113 0 1 1 8.6810222,0 z" />
<path
style="fill:none;stroke:#ffffff;stroke-width:3.07699394;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="M 11.228485,6.6048146 26.723175,20.627194 5.5128348,26.795047 z"
id="path3837"
inkscape:connector-curvature="0" />
</svg>
Loading…
Cancel
Save