[plugin] vj_db_info

Post plugins and custom CSS snippets here
User avatar
VJean
BANNED_USERS
BANNED_USERS
Posts: 5
Joined: 05 Sep 2013, 02:39

[plugin] vj_db_info

Postby VJean » 05 Sep 2013, 02:49

small information plugin.

Image

source init.php

Code: Select all

<?php
class VJ_DB_Info extends Plugin {
   private $host;

   function init($host) {
      $this->host = $host;

      $host->add_hook($host::HOOK_PREFS_TAB, $this);
   }

   function about() {
      return array(1.0,
         "DataBase info",
         "[email protected]");
   }

   function api_version() {
      return 2;
   }

   function before($method) {
      if (parent::before($method)) {
         if ($_SESSION["access_level"] < 10) {
            print __("Your access level is insufficient to open this tab.");
            return false;
         }
         return true;
      }
      return false;
   }
   
   function hook_prefs_tab($args) {
    if ($args != "prefSystem") return;
   
    include_once("config.php");
   
    print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("DataBase Info")."\">";
   
    if (defined('DB_TYPE')) {
        print "<p>"._("DB_TYPE = ") ."". DB_TYPE."</p>";
        print "<p>"._("DB_NAME = ") ."". DB_NAME."</p>";

       $result = db_query("SELECT COUNT(*) entries_count FROM ttrss_entries;");
         $entries_count = db_fetch_result($result, 0, "entries_count");
       print "<p>"._("entries_count = ")."$entries_count</p>";

       if (DB_TYPE == "pgsql") {
         $result = db_query("SELECT pg_size_pretty(pg_database_size('".DB_NAME."')), pg_database_size('".DB_NAME."');");
           $pg_size_pretty = db_fetch_result($result, 0, "pg_size_pretty");
           $pg_database_size = db_fetch_result($result, 0, "pg_database_size");
           print "<p>"._("db_size = ")."$pg_size_pretty ($pg_database_size)</p>";
      } else {
         $result = db_query("SELECT sum(data_length+index_length)/1024/1024 Data_Base_Size_in_MB, sum(data_free)/1024/1024 Free_Space_in_MB FROM information_schema.TABLES WHERE table_schema = '".DB_NAME."';");
           $Data_Base_Size_in_MB = db_fetch_result($result, 0, "Data_Base_Size_in_MB");
           $Free_Space_in_MB = db_fetch_result($result, 0, "Free_Space_in_MB");
           print "<p>"._("Data_Base_Size_in_MB = ")."$Data_Base_Size_in_MB</p>";
           print "<p>"._("Free_Space_in_MB = ")."$Free_Space_in_MB</p>";
       }

    } else {
        print_error(__("Not defined DB_TYPE<br>DB_TYPE = ".DB_TYPE));
    }
   
    
      print "<hr>";
      print_notice(__("Tested on MySQL and PostgreSQL."));
      print "</div>"; #pane
    }

}
?>

Return to “Themes and plugins”

Who is online

Users browsing this forum: No registered users and 4 guests