Browse Source

- Fix the Admin widget to integrate properly the new Modl release

- Fix lot of little issues
- CSS fixs
- Add a FAIL_SAFE mode to prevent errors in the Admin page
pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
059340c9a9
  1. 7
      app/assets/js/movimrpc.js
  2. 1
      app/models/node/Node.php
  3. 29
      app/models/node/NodeDAO.php
  4. 109
      app/widgets/Admin/Admin.php
  5. 72
      app/widgets/Admin/_admin_db.tpl
  6. 10
      app/widgets/ServerNodes/ServerNodes.php
  7. 4
      app/widgets/Tabs/tabs.css
  8. 9
      app/widgets/Vcard/Vcard.php
  9. 4
      bootstrap.php
  10. 15
      index.php
  11. 5
      jajax.php
  12. 3
      system/Conf.php
  13. 2
      system/Session.php
  14. 38
      system/widget/WidgetWrapper.php
  15. 3
      themes/movim/css/style.css
  16. 3
      themes/movim/page.tpl

7
app/assets/js/movimrpc.js

@ -110,8 +110,13 @@ function MovimRPC()
this.commit = function()
{
movim_xmlhttp = this.make_xmlhttp();
if(FAIL_SAFE)
var fail_safe = '?fail_safe=1';
else
var fail_safe = '';
movim_xmlhttp.open('POST', BASE_URI+'jajax.php', true);
movim_xmlhttp.open('POST', BASE_URI+'jajax.php'+fail_safe, true);
var handler = this.handle_rpc_json;

1
app/models/node/Node.php

@ -9,6 +9,7 @@ class Node extends ModlModel {
public $config;
public $updated;
public $subscription;
public $num;
public function __construct() {
$this->_struct = "

29
app/models/node/NodeDAO.php

@ -98,6 +98,12 @@ class NodeDAO extends ModlSQL {
left outer join (select server, node, subscription from subscription where jid = :nodeid)
as s on s.server = node.serverid
and s.node = node.nodeid
left outer join (select node, count(node) as num from (
select session, node, nodeid from postn
where session = :nodeid
group by nodeid, node, session
order by node) as f group by node)
as c on c.node = node.nodeid
where serverid= :serverid
order by node.title, nodeid';
@ -114,13 +120,6 @@ class NodeDAO extends ModlSQL {
}
function deleteNodes($serverid) {
/*$serverid = $this->_db->real_escape_string($serverid);
$sql = '
delete from Node
where serverid=\''.$serverid.'\' ';
return $this->_db->query($sql); */
$this->_sql = '
delete from node
where serverid= :serverid';
@ -136,15 +135,6 @@ class NodeDAO extends ModlSQL {
}
function deleteNode($serverid, $nodeid) {
/*$serverid = $this->_db->real_escape_string($serverid);
$nodeid = $this->_db->real_escape_string($nodeid);
$sql = '
delete from Node
where serverid=\''.$serverid.'\' and
nodeid=\''.$nodeid.'\'';
return $this->_db->query($sql); */
$this->_sql = '
delete from node
where serverid = :serverid
@ -162,13 +152,6 @@ class NodeDAO extends ModlSQL {
}
function getNode($serverid, $nodeid) {
/*$sql = '
select * from Node
where nodeid = \''.$nodeid.'\'
and serverid = \''.$serverid.'\'';
return $this->mapper('Node', $this->_db->query($sql), 'item');*/
$this->_sql = '
select * from node
where

109
app/widgets/Admin/Admin.php

@ -157,6 +157,13 @@ class Admin extends WidgetBase {
\system\Conf::saveConfFile($this->_conf);
}
public function ajaxUpdateDatabase()
{
$md = \modl\Modl::getInstance();
$md->check(true);
RPC::call('movim_reload_this');
}
public function ajaxRecreateDatabase()
{
$pd = new \modl\PostnDAO();
@ -200,16 +207,13 @@ class Admin extends WidgetBase {
$this->createDirs();
$submit = $this->genCallAjax('ajaxAdminSubmit', "movim_parse_form('admin')")
."this.className='button color orange icon loading'; setTimeout(function() {location.reload(false)}, 2000);";
."this.className='button color orange icon loading'; setTimeout(function() {location.reload(false)}, 1000);";
$this->_validatebutton = '
<div class="clear"></div>
<a class="button icon yes color green" style="float: right;" onclick="'.$submit.'">'.t('Submit').'</a>';
$html = '
<form name="admin" id="adminform">';
$html .= '
<fieldset>
<legend>'.t("Compatibility Check").'</legend>
<div class="clear"></div>';
@ -506,88 +510,36 @@ class Admin extends WidgetBase {
}
function prepareAdminDB() {
$html = '';
$dbview = $this->tpl();
$html .= '
<fieldset>
<legend>'.t("Database Settings").'</legend>
<div class="clear"></div>';
$md = \modl\Modl::getInstance();
if(!$md->_connected) {
$html .= '
<div class="message error">'.
t("Modl wasn't able to connect to the database").'<br />
'.$md->_dao->_error.'
</div>
';
} else {
$dbrecreate = $this->genCallAjax('ajaxRecreateDatabase')
." this.className='button color orange icon loading';
setTimeout(function() {location.reload(false)}, 2000);";
$html .= '
<div class="element">
<label for="db">'.t('Recreate the database').'</label>
<a class="button icon loading color red" onclick="'.$dbrecreate.'">'.t('Recreate').'</a>
</div>
<div class="message error">
'.t('This button will clear and recreate the Movim database.').'
</div>
';
}
$html .= '
<div class="element">
<label for="dbType">'.t('Database Type').'</label>
<input type="text" disabled="true" name="dbType" id="dbType" value="'.$this->_conf['dbType'].'" />
</div>';
$html .= '
<div class="element">
<label for="dbUsername">'.t('Username').'</label>
<input type="text" name="dbUsername" id="dbUsername" value="'.$this->_conf['dbUsername'].'" />
</div>';
$html .= '
<div class="element">
<label for="dbPassword">'.t('Password').'</label>
<input type="password" name="dbPassword" id="dbPassword" value="'.$this->_conf['dbPassword'].'" />
</div>';
$html .= '
<div class="element">
<label for="dbHost">'.t('Host').'</label>
<input type="text" name="dbHost" id="dbHost" value="'.$this->_conf['dbHost'].'" />
</div>';
$html .= '
<div class="element">
<label for="dbPort">'.t('Port').'</label>
<input type="text" name="dbPort" id="dbPort" value="'.$this->_conf['dbPort'].'" />
</div>';
$html .= '
<div class="element">
<label for="dbName">'.t('Database Name').'</label>
<input type="text" name="dbName" id="dbName" value="'.$this->_conf['dbName'].'" />
</div>';
$md = \modl\Modl::getInstance();
$infos = $md->check();
$html .= $this->_validatebutton;
$html .= '
</fieldset>';
$html .= '
</form>';
$errors = '';
$dbview->assign('infos', $infos);
$dbview->assign('db_update', $this->genCallAjax('ajaxUpdateDatabase')
."this.className='button color orange icon loading'; setTimeout(function() {location.reload(false)}, 1000);");
try {
$md->connect();
} catch(Exception $e) {
$errors = $e->getMessage();
}
$dbview->assign('connected', $md->_connected);
$dbview->assign('validatebutton', $this->_validatebutton);
$dbview->assign('conf', $this->_conf);
$dbview->assign('supported_db', $md->getSupportedDatabases());
$dbview->assign('errors', $errors);
$html = $dbview->draw('_admin_db', true);
return $html;
}
function build()
{
?>
<form name="admin" id="adminform">
<div id="admincomp" class="tabelem padded" title="<?php echo t("Compatibility Check"); ?>">
<?php echo $this->prepareAdminComp(); ?>
</div>
@ -597,6 +549,7 @@ class Admin extends WidgetBase {
<div id="admindb" class="tabelem padded" title="<?php echo t("Database Settings") ?>">
<?php echo $this->prepareAdminDB(); ?>
</div>
</form>
<?php
}
}

72
app/widgets/Admin/_admin_db.tpl

@ -0,0 +1,72 @@
<fieldset>
<legend>{$c->t('Database Settings')}</legend>
<div class="clear"></div>
{if="!$connected"}
<div class="message error">
{$c->t("Modl wasn't able to connect to the database")}
</div>
<div class="message error">
{$errors}
</div>
{else}
<div class="message success">
{$c->t('Movim is connected to the database')}
</div>
{if="$infos != null"}
<p>{$c->t('The database need to be updated')}</p>
<div class="message warning">
{loop="infos"}
<p>{$value}</p>
{/loop}
<a class="button color green icon refresh"
onclick="{$db_update}"
style="float: right;">{$c->t('Update')}</a>
<div class="clear"></div>
</div>
{else}
<div class="message success">
{$c->t('Movim database is up to date')}
</div>
{/if}
{/if}
<div class="clear"></div>
<div class="element">
<label for="logLevel">{$c->t('Database Type')}</label>
<div class="select">
<select id="dbType" name="dbType">
{loop="supported_db"}
<option value="{$key}"
{if="$key == $conf.dbType"}
selected="selected"
{/if}>
{$value}
</option>
{/loop}
</select>
</div>
</div>
<div class="element">
<label for="dbUsername">{$c->t('Username')}</label>
<input type="text" name="dbUsername" id="dbUsername" value="{$conf.dbUsername}" />
</div>
<div class="element">
<label for="dbPassword">{$c->t('Password')}</label>
<input type="password" name="dbPassword" id="dbPassword" value="{$conf.dbPassword}" />
</div>
<div class="element">
<label for="dbHost">{$c->t('Host')}</label>
<input type="text" name="dbHost" id="dbHost" value="{$conf.dbHost}" />
</div>
<div class="element">
<label for="dbPort">{$c->t('Port')}</label>
<input type="text" name="dbPort" id="dbPort" value="{$conf.dbPort}" />
</div>
<div class="element">
<label for="dbName">{$c->t('Database Name')}</label>
<input type="text" name="dbName" id="dbName" value="{$conf.dbName}" />
</div>
</fieldset>
{$validatebutton}

10
app/widgets/ServerNodes/ServerNodes.php

@ -121,15 +121,19 @@ class ServerNodes extends WidgetCommon
else
$name = $n->nodeid;
$tag = '';
$tags = '';
if($n->num != null)
$tags .= '<span class="tag">'.$n->num.'</span>';
if($n->subscription == 'subscribed')
$tag .= '<span class="tag">'.t('Subscribed').'</span>';
$tags .= '<span class="tag">'.t('Subscribed').'</span>';
$html .= '
<li>
<a href="'.Route::urlize('node', array($n->serverid, $n->nodeid)).'">'.
$name.
$tag.'
$tags.'
</a>
</li>';
}

4
app/widgets/Tabs/tabs.css

@ -11,13 +11,13 @@
#navtabs li {
display: inline-block;
cursor: pointer;
line-height: 3em;
padding: 0em 2em;
white-space: nowrap;
}
#navtabs li a{
display: block;
height:100%;
line-height: 3em;
width:100%;
color: white;
text-decoration: none;

9
app/widgets/Vcard/Vcard.php

@ -84,8 +84,9 @@ class Vcard extends WidgetBase
$c->photobin = $vcard->photobin->value;
$c->description = trim($vcard->desc->value);
if($vcard->privacy->value == 1)
\movim_log('LOOOOOL');
\movim_log($vcard->privacy);
if($vcard->privacy->value == true)
\modl\Privacy::set($c->jid, 1);
else
\modl\Privacy::set($c->jid, 0);
@ -326,8 +327,8 @@ class Vcard extends WidgetBase
</div>
<label>'.t('Is this profile public ?').'</label>
<div class="checkbox">
<input type="checkbox" id="public" name="public" '.$checked.'/>
<label for="public"></label>
<input type="checkbox" id="privacy" name="privacy" '.$checked.'/>
<label for="privacy"></label>
</div>
</div>';

4
bootstrap.php

@ -237,9 +237,7 @@ class Bootstrap {
$db->setConnectionArray(\System\Conf::getServerConf());
$db->connect();
//$db->check();
return true;
}

15
index.php

@ -41,6 +41,13 @@ define('DOCUMENT_ROOT', dirname(__FILE__));
require_once(DOCUMENT_ROOT.'/bootstrap.php');
try {
if((isset($_GET['q']) && $_GET['q'] == 'admin') ||
(isset($_GET['query']) && $_GET['query'] == 'admin')
)
define('FAIL_SAFE', true);
else
define('FAIL_SAFE', false);
$bootstrap = new Bootstrap();
$bootstrap->boot();
@ -55,15 +62,15 @@ try {
} catch (Exception $e) {
//manage errors
\system\Logs\Logger::displayDebugCSS();
if (ENVIRONMENT === 'development') {
if (ENVIRONMENT === 'development' && !FAIL_SAFE) {
?>
<div id="final_exception" class="error debug">
<h2>An error happened</h2>
<p><?php print $e->getMessage();?></p>
</div>
<?php
} else {
} elseif(!FAIL_SAFE) {
?>
<div class="carreful">
<h2> Oops... something went wrong.</h2>
@ -72,7 +79,7 @@ try {
<?php
}
$r = new Route;
if($_GET['q'] == 'admin') {
if(FAIL_SAFE) {
$rqst = new ControllerMain();
$rqst->handle();
}

5
jajax.php

@ -33,6 +33,11 @@ try {
// Closing stuff
WidgetWrapper::destroyInstance();
} catch(\Exception $e) {
if(isset($_GET['fail_safe']) && (int)$_GET['fail_safe']) {
$rpc = new RPC();
$rpc->handle_json();
}
print $e->getMessage();
}
?>

3
system/Conf.php

@ -35,7 +35,7 @@ class Conf
'defLang' => 'en',
'maxUsers' => -1,
'logLevel' => 7,
'timezone' => getLocalTimezone(),
'timezone' => 'Etc/GMT',
'dbType' => 'mysql',
'dbUsername'=> 'username',
'dbPassword'=> 'password',
@ -77,7 +77,6 @@ class Conf
}
static function saveConfFile($conf = array()) {
movim_log($conf);
$doc = new \DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;

2
system/Session.php

@ -36,8 +36,6 @@ class Session
protected function __construct($name)
{
// Does the database exist?
//$var = new SessionVar();
if(self::$sid == null) {
if(isset($_COOKIE['PHPFASTSESSID'])) {
self::$sid = $_COOKIE['PHPFASTSESSID'];

38
system/widget/WidgetWrapper.php

@ -41,24 +41,28 @@ class WidgetWrapper
private function __construct($register)
{
$this->register_widgets = $register;
$sess = Session::start(APP_NAME);
$widgets = $sess->get('loaded_widgets');
if(is_array($widgets)) {
$this->loaded_widgets_old = $widgets;
}
$this->registered_events = $sess->get('registered_events');
// We search all the existent widgets
$this->all_widgets = array();
$widgets_dir = scandir(APP_PATH ."widgets/");
foreach($widgets_dir as $widget_dir) {
if(is_dir(APP_PATH ."widgets/".$widget_dir) &&
$widget_dir != '..' &&
$widget_dir != '.')
array_push($this->all_widgets, $widget_dir);
$md = \modl\Modl::getInstance();
if($md->_connected) {
$sess = Session::start(APP_NAME);
$widgets = $sess->get('loaded_widgets');
if(is_array($widgets)) {
$this->loaded_widgets_old = $widgets;
}
$this->registered_events = $sess->get('registered_events');
// We search all the existent widgets
$this->all_widgets = array();
$widgets_dir = scandir(APP_PATH ."widgets/");
foreach($widgets_dir as $widget_dir) {
if(is_dir(APP_PATH ."widgets/".$widget_dir) &&
$widget_dir != '..' &&
$widget_dir != '.')
array_push($this->all_widgets, $widget_dir);
}
}
}

3
themes/movim/css/style.css

@ -619,7 +619,8 @@ ul.list li a.action:hover {
ul.list li span.tag {
background-color: #555;
padding: 0 1em;
padding: 0 0.5em;
margin-left: 1em;
color: white;
display: inline-block;
min-width: 3em;

3
themes/movim/page.tpl

@ -16,7 +16,8 @@
var ERROR_URI = '<?php echo substr_replace(Route::urlize('disconnect', 'err'), '', -3); ?>';
var PAGE_KEY_URI = '<?php
if(!isset($_SERVER['HTTP_MOD_REWRITE']) || !$_SERVER['HTTP_MOD_REWRITE'])
echo '?q='; ?>'
echo '?q='; ?>';
var FAIL_SAFE = <?php if(FAIL_SAFE) echo FAIL_SAFE; else echo "''"; ?>;
</script>
<?php
$this->addCss('css/animations.css');

Loading…
Cancel
Save