+/**
+ * @brief Subpage with some stats about "the federation" network
+ *
+ * This function generates the "Federation Statistics" subpage for the admin
+ * panel. The page lists some numbers to the part of "The Federation" known to
+ * the node. This data includes the different connected networks (e.g.
+ * Diaspora, Hubzilla, GNU Social) and the used versions in the different
+ * networks.
+ *
+ * The returned string contains the HTML code of the subpage for display.
+ *
+ * @param App $a
+ * @return string
+ */
+function admin_page_federation(&$a) {
+ // get counts on active friendica, diaspora, redmatrix, hubzilla, gnu
+ // social and statusnet nodes this node is knowing
+ //
+ // We are looking for the following platforms in the DB, "Red" should find
+ // all variants of that platform ID string as the q() function is stripping
+ // off one % two of them are needed in the query
+ // Add more platforms if you like, when one returns 0 known nodes it is not
+ // displayed on the stats page.
+ $platforms = array('Friendica', 'Diaspora', '%%red%%', 'Hubzilla', 'GNU Social', 'StatusNet');
+ $colors = array('Friendica' => '#ffc018', // orange from the logo
+ 'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray
+ '%%red%%' => '#c50001', // fire red from the logo
+ 'Hubzilla' => '#43488a', // blue from the logo
+ 'GNU Social'=> '#a22430', // dark red from the logo
+ 'StatusNet' => '#789240'); // the green from the logo (red and blue have already others
+ $counts = array();
+ $total = 0;
+
+ foreach ($platforms as $p) {
+ // get a total count for the platform, the name and version of the
+ // highest version and the protocol tpe
+ $c = q('SELECT count(*) AS total, platform, network, version FROM gserver
+ WHERE platform LIKE "%s" AND last_contact > last_failure AND `version` != ""
+ ORDER BY version ASC;', $p);
+ $total = $total + $c[0]['total'];
+
+ // what versions for that platform do we know at all?
+ // again only the active nodes
+ $v = q('SELECT count(*) AS total, version FROM gserver
+ WHERE last_contact > last_failure AND platform LIKE "%s" AND `version` != ""
+ GROUP BY version
+ ORDER BY version;', $p);
+
+ //
+ // clean up version numbers
+ //
+ // in the DB the Diaspora versions have the format x.x.x.x-xx the last
+ // part (-xx) should be removed to clean up the versions from the "head
+ // commit" information and combined into a single entry for x.x.x.x
+ if($p=='Diaspora') {
+ $newV = array();
+ $newVv = array();
+ foreach($v as $vv) {
+ $newVC = $vv['total'];
+ $newVV = $vv['version'];
+ $posDash = strpos($newVV, '-');
+ if($posDash)
+ $newVV = substr($newVV, 0, $posDash);
+ if(isset($newV[$newVV]))
+ $newV[$newVV] += $newVC;
+ else
+ $newV[$newVV] = $newVC;
+ }
+ foreach ($newV as $key => $value) {
+ array_push($newVv, array('total'=>$value, 'version'=>$key));
+ }
+ $v = $newVv;
+ }
+
+ // early friendica versions have the format x.x.xxxx where xxxx is the
+ // DB version stamp; those should be operated out and versions be
+ // conbined
+ if($p=='Friendica') {
+ $newV = array();
+ $newVv = array();
+ foreach ($v as $vv) {
+ $newVC = $vv['total'];
+ $newVV = $vv['version'];
+ $lastDot = strrpos($newVV,'.');
+ $len = strlen($newVV)-1;
+ if(($lastDot == $len-4) && (!strrpos($newVV,'-rc')==$len-3))
+ $newVV = substr($newVV, 0, $lastDot);
+ if(isset($newV[$newVV]))
+ $newV[$newVV] += $newVC;
+ else
+ $newV[$newVV] = $newVC;
+ }
+ foreach ($newV as $key => $value) {
+ array_push($newVv, array('total'=>$value, 'version'=>$key));
+ }
+ $v = $newVv;
+ }
+
+ foreach ($v as $key => $vv)
+ $v[$key]["version"] = trim(strip_tags($vv["version"]));
+
+ // the 3rd array item is needed for the JavaScript graphs as JS does
+ // not like some characters in the names of variables...
+ $counts[$p]=array($c[0], $v, str_replace(array(' ','%'),'',$p), $colors[$p]);
+ }
+
+ // some helpful text
+ $intro = t('This page offers you some numbers to the known part of the federated social network your Friendica node is part of. These numbers are not complete but only reflect the part of the network your node is aware of.');
+ $hint = t('The <em>Auto Discovered Contact Directory</em> feature is not enabled, it will improve the data displayed here.');
+
+ // load the template, replace the macros and return the page content
+ $t = get_markup_template("admin_federation.tpl");
+ return replace_macros($t, array(
+ '$title' => t('Administration'),
+ '$page' => t('Federation Statistics'),
+ '$intro' => $intro,
+ '$hint' => $hint,
+ '$autoactive' => get_config('system', 'poco_completion'),
+ '$counts' => $counts,
+ '$version' => FRIENDICA_VERSION,
+ '$legendtext' => sprintf(t('Currently this node is aware of %d nodes from the following platforms:'), $total),
+ '$baseurl' => $a->get_baseurl(),
+ ));
+}
+
+/**
+ * @brief Admin Inspect Queue Page
+ *
+ * Generates a page for the admin to have a look into the current queue of
+ * postings that are not deliverabke. Shown are the name and url of the
+ * recipient, the delivery network and the dates when the posting was generated
+ * and the last time tried to deliver the posting.
+ *
+ * The returned string holds the content of the page.
+ *
+ * @param App $a
+ * @return string
+ */
+function admin_page_queue(&$a) {
+ // get content from the queue table
+ $r = q("SELECT c.name,c.nurl,q.id,q.network,q.created,q.last from queue as q, contact as c where c.id=q.cid order by q.cid, q.created;");
+
+ $t = get_markup_template("admin_queue.tpl");
+ return replace_macros($t, array(
+ '$title' => t('Administration'),
+ '$page' => t('Inspect Queue'),
+ '$count' => sizeof($r),
+ 'id_header' => t('ID'),
+ '$to_header' => t('Recipient Name'),
+ '$url_header' => t('Recipient Profile'),
+ '$network_header' => t('Network'),
+ '$created_header' => t('Created'),
+ '$last_header' => t('Last Tried'),
+ '$info' => t('This page lists the content of the queue for outgoing postings. These are postings the initial delivery failed for. They will be resend later and eventually deleted if the delivery fails permanently.'),
+ '$entries' => $r,
+ ));
+}