From 54025ed4dd7baad48c79d800d01720c1dc1544d5 Mon Sep 17 00:00:00 2001 From: Benjamin Sonntag Date: Sun, 26 Aug 2012 10:52:58 +0000 Subject: [PATCH] fixing quota names --- bureau/class/m_piwik.php | 169 ++++++++++++++++++++++++--------------- bureau/class/m_quota.php | 24 +++--- bureau/locales/Makefile | 8 +- 3 files changed, 122 insertions(+), 79 deletions(-) diff --git a/bureau/class/m_piwik.php b/bureau/class/m_piwik.php index ab635597..8de3b4fc 100644 --- a/bureau/class/m_piwik.php +++ b/bureau/class/m_piwik.php @@ -1,11 +1,6 @@ piwik_server_uri=''; } + $this->piwik_admin_token=variable_get('piwik_admin_token',null); if (is_null($this->piwik_admin_token)) { // if not configuration var, setup one (with a default value) variable_set('piwik_admin_token','','Remote Piwik super-admin token'); $this->piwik_admin_token=''; } - } + } /** * Quota name */ - function hook_quota_names() { - return array("piwik"=>_("Statistics through Piwik accounts")); + function alternc_quota_names() { + return "piwik"; } /* ----------------------------------------------------------------- */ - /** hook called when an AlternC account is deleted + /** Fonction appellée par membres quand un membre est effacé. + * @param integer $uid Numéro de membre effacé. + * @access private */ - function hook_admin_del_member() { - //FIXME : implement the hook_admin_del_member for piwik + function alternc_del_member() { + //FIXME return true; } - /* ----------------------------------------------------------------- */ - /** Returns the used quota for the $name service for the current user. + /** + * Returns the used quota for the $name service for the current user. * @param $name string name of the quota * @return integer the number of service used or false if an error occured * @access private */ - function hook_quota_get($name) { + function alternc_get_quota() { global $db, $cuid; - if ($name=="piwik") { - $db->query("SELECT COUNT(id) AS nb FROM piwik_users WHERE uid='$cuid'"); - $db->next_record(); - return $db->f('nb'); - } else - return false; + $db->query("SELECT COUNT(id) AS nb FROM piwik_users WHERE uid='$cuid'"); + $db->next_record(); + + return $db->f('nb'); } - - function url() { + function url() + { return $this->piwik_server_uri; } /***********************/ - /* User-related tasks */ + /* Users related tasks */ /***********************/ + // Créé un utilisateur + // Si échoue en remote, n'enregistre rien function user_add($user_login, $user_mail = null) { global $db, $mem, $cuid, $err; @@ -104,15 +103,20 @@ class m_piwik { $user_alias = $user_login; $api_data = $this->call_privileged_page('API', 'UsersManager.addUser', array('userLogin' => $user_login, 'password' => $user_pass, 'email' => $user_mail, 'alias' => $user_alias), 'JSON'); - if ($api_data) { - if ($api_data->result === 'success') { + if ($api_data) + { + if ($api_data->result === 'success') + { $user = $this->get_user($user_login); $user_creation_date = $user->date_registered; $db->query("INSERT INTO piwik_users (uid, login, created_date) VALUES ('$cuid', '$user_login', '$user_creation_date')"); } - } else { // api_data = false -> error is already filled + } + else // api_data = false -> error is already filled + { return FALSE; } + } @@ -122,8 +126,8 @@ class m_piwik { return true; } - - function get_user($user_login) { + function get_user($user_login) + { $api_data = $this->call_privileged_page('API', 'UsersManager.getUser', array('userLogin' => $user_login)); if ($api_data) @@ -132,7 +136,6 @@ class m_piwik { return FALSE; } - // Supprime l'utilisateur Piwik passé en parametre // Ne le supprime pas localement tant que pas supprimé en remote function user_delete($piwik_user_login) { @@ -141,18 +144,25 @@ class m_piwik { $db->query("SELECT created_date, COUNT(id) AS cnt FROM piwik_users WHERE uid='$cuid' AND login='$piwik_user_login'"); $db->next_record(); - if ($db->f('cnt') == 1) { + if ($db->f('cnt') == 1) + { + $api_data = $this->call_privileged_page('API', 'UsersManager.getUser', array('userLogin' => $piwik_user_login)); printvar($api_data); if ($api_data[0]->date_registered == $db->f('created_date')) echo "equals"; else echo "non equals"; - // $api_data = $this->call_privileged_page('API', 'UsersManager.deleteUser', array('idSite' => $site_id)); - } else { - $err->raise("piwik", _("You are not allowed to delete the statistics of this website")); - return FALSE; - } + // $api_data = $this->call_privileged_page('API', 'UsersManager.deleteUser', array('idSite' => $site_id)); + + + } + else + { + $err->raise("piwik", _("You are not allowed to delete the statistics of this website")); + return FALSE; + } + //SitesManager.deleteSite (idSite) //FIXME return true; @@ -161,16 +171,22 @@ class m_piwik { function users_list() { global $db, $cuid; + $db->query("SELECT login FROM piwik_users WHERE uid = '$cuid'"); + if ($db->num_rows() == 0) return array(); + $users = ''; while ($db->next_record()) $users .= ($users !== '') ? ',' . $db->f('login') : $db->f('login'); + return $this->call_privileged_page('API', 'UsersManager.getUsers', array('userLogins' => $users)); } + + // Verifie que l'utilisateur existe bien dans piwik function user_checkremote($puser_id) { //FIXME @@ -194,17 +210,22 @@ class m_piwik { + + /***********************/ - /* Site-related tasks */ + /* Sites related tasks */ /***********************/ - function site_list() { + function site_list() + { $api_data = $this->call_privileged_page('API', 'SitesManager.getAllSites'); $data = array(); - if($api_data) { - foreach ($api_data AS $site) { + if($api_data) + { + foreach ($api_data AS $site) + { $item = new stdClass(); @@ -214,30 +235,36 @@ class m_piwik { $user_data = $this->call_privileged_page('API', 'UsersManager.getUsersAccessFromSite', array('idSite' => $site->idsite)); - if (is_array($user_data)) { + if (is_array($user_data)) + { printvar($user_data); - } else if(is_object($user_data)) { + } + else if(is_object($user_data)) + { $item->rights = json_decode($user_data[0]); } + + $data[] = $item; } + return $data; - } else + } + else return FALSE; + } - - // Ajoute un site à Piwik // can't figure out how to pass multiple url through the API function site_add($siteName, $urls, $ecommerce = FALSE) { $urls = is_array($urls) ? implode(',', $urls) : $urls; $api_data = $this->call_privileged_page('API', 'SitesManager.addSite', array('siteName' => $siteName, 'urls' => $urls)); printvar($api_data); + return TRUE; } - // Supprime un site de Piwik function site_delete($site_id) { global $db, $cuid, $err; @@ -245,21 +272,23 @@ class m_piwik { $db->query("SELECT COUNT(id) AS cnt FROM piwik_sites WHERE uid='$cuid' AND piwik_id='$site_id'"); $db->next_record(); - if ($db->f('cnt') == 1) { + if ($db->f('cnt') == 1) + { $api_data = $this->call_privileged_page('API', 'SitesManager.deleteSite', array('idSite' => $site_id)); printvar($api_data); - } else { + } + else + { $err->raise("piwik", _("You are not allowed to delete the statistics of this website")); return FALSE; - } + } //SitesManager.deleteSite (idSite) //FIXME return true; } - // Ajoute un alias sur un site existant function site_alias_add() { // FIXME @@ -268,20 +297,21 @@ class m_piwik { - /* Helper code FIXME: rename those function using "private" + "_" prefix */ + /* Helper code */ - function clean_user_name($username) { + function clean_user_name($username) + { return mysql_real_escape_string(trim($username)); } - - function dev() { + function dev() + { // $this->call_page('module', 'method', array('user' => 'fser', 'pass' => 'toto')); // return $this->users_list(); } - - function call_page($module, $method, $arguments=array(), $output = 'JSON') { + function call_page($module, $method, $arguments=array(), $output = 'JSON') + { global $err; $url = sprintf('%s/?module=%s&method=%s&format=%s', $this->piwik_server_uri, $module, $method, $output); foreach ($arguments AS $k=>$v) @@ -293,30 +323,39 @@ class m_piwik { //} echo $url; $page_content = file_get_contents($url); - if ($page_content === FALSE) { + if ($page_content === FALSE) + { $err->raise("piwik", _("Unable to reach the API")); return FALSE; } - if ($output == 'JSON') { + if ($output == 'JSON') + { $api_data = json_decode($page_content); - if ($api_data == FALSE) { + if ($api_data == FALSE) + { $err->raise("piwik", _("Error while decoding response from the API")); return FALSE; } return $api_data; - } else { + } + else + { $err->raise("piwik", _("Other format than JSON is not implemented yet")); return FALSE; } + } - function call_privileged_page($module, $method, $arguments=array(), $output = 'JSON') { + function call_privileged_page($module, $method, $arguments=array(), $output = 'JSON') + { $arguments['token_auth'] = $this->piwik_admin_token; + return $this->call_page($module, $method, $arguments, $output); } - } /* Class piwik */ + +?> diff --git a/bureau/class/m_quota.php b/bureau/class/m_quota.php index a04755c6..0261d6aa 100644 --- a/bureau/class/m_quota.php +++ b/bureau/class/m_quota.php @@ -91,18 +91,23 @@ class m_quota { } } } - // New Hook $qname=$hooks->invoke("hook_quota_names"); // return strings or arrays foreach($qname as $res) - if ($res && is_array($res)) { - foreach($res as $k=>$v) { - $qlist[$k]=$v; - $this->clquota[$k]=$k; + if ($res) { + if (is_array($res)) { + foreach($res as $k) { + $qlist[$k]=_("quota_".$k); + $this->clquota[$k]=$c; + } + } else { + $qlist[$res]=_("quota_".$res); + $this->clquota[$res]=$c; + } } return $qlist; } - + /* ----------------------------------------------------------------- */ /** Return a ressource usage (u) and total quota (t) @@ -135,12 +140,11 @@ class m_quota { ); } } - // New Hook : foreach ($ttmp as $tt) { - $res=$hooks->invoke("hook_quota_get",array($tt["name"])); + $res=$hooks->invoke("",$tt["name"]); foreach($res as $r) { - if ($r!==false) { - $this->quotas[$tt["name"]]=array("t"=>$tt["total"],"u"=>$r); + if ($r) { + $this->quotas[$tt["name"]]=array("t"=>$tt["total"],"u"); } } } diff --git a/bureau/locales/Makefile b/bureau/locales/Makefile index e038983e..0ddb6b51 100644 --- a/bureau/locales/Makefile +++ b/bureau/locales/Makefile @@ -1,11 +1,11 @@ -all: manual.pot messages.pot */LC_MESSAGES/manual.po */LC_MESSAGES/messages.po +all: mailman_manual.pot mailman.pot */LC_MESSAGES/mailman_manual.po */LC_MESSAGES/mailman.po -messages.pot: ../*/*.php +mailman.pot: ../*/*.php [ -r $@ ] || touch $@ xgettext --copyright-holder="AlternC Team" --package-name="AlternC" --package-version="2.0" --msgid-bugs-address="i18n@alternc.org" --force-po -o $@ --keyword=__ --keyword=_ -L PHP -F --from-code UTF-8 -j $^ -%/LC_MESSAGES/messages.po: messages.pot +%/LC_MESSAGES/mailman.po: mailman.pot msgmerge -v -U $@ $^ -%/LC_MESSAGES/manual.po: manual.pot +%/LC_MESSAGES/mailman_manual.po: mailman_manual.pot msgmerge -v -U $@ $^