We have clarified our Privacy Statement. Please have a look at our changes.
Browse Source

* statistic functions can now be disabled. When enabled, db-settings are rawly checked.

* On a failed db update, the script no longer stops but instead throws E_USER_ERROR and continues
* see also ticket #5 which is solved with this revision.


git-svn-id: svn+ssh://svn.izzysoft.de/public/histview/trunk@53 2e17d4db-7539-0410-9bcc-c6eb479cd550
tags/v0.1.9
Izzy 11 years ago
parent
commit
a9030a5636
5 changed files with 55 additions and 9 deletions
  1. +28
    -4
      class.download.inc
  2. +11
    -3
      class.hvconfig.inc
  3. +10
    -0
      histview.css
  4. +4
    -0
      histview.hist
  5. +2
    -2
      histview.php

+ 28
- 4
class.download.inc View File

@@ -50,6 +50,7 @@ class download extends hvconfig {
if (is_array($this->db)) { // setup default db
$this->db_setup($this->db["host"],$this->db["database"],$this->db["user"],$this->db["pass"],$this->db["table"]);
}
$this->set_statisticsmode($this->statisticsmode); // make sure stats are disabled w/o database
}

/** Setup bots to ignore / reject
@@ -132,6 +133,28 @@ class download extends hvconfig {
$this->argsep = $sep;
}

/** Set the statisticsmode
* Use this to turn on (1)/Off (0) statistic functions (database related
* stuff like download counters) at runtime
* @method set_statisticsmode
* @param integer mode 0 (to turn off stats) or 1 (to turn them on)
* @return boolean success
*/
function set_statisticsmode($mode) {
$valid_modes = array(0,1);
if (!is_int($mode) || !in_array($mode,$valid_modes)) {
trigger_error("Invalid value '$mode' for statisticsmode ignored",E_USER_ERROR);
return FALSE;
}
if ($mode==1 && (empty($this->dbhost)||empty($this->database)||empty($this->dbuser)||empty($this->dbtable))) {
trigger_error("Cannot enable statistics mode - invalid database settings (no dbhost, database, dbuser, and/or dbtable configured)",E_USER_ERROR);
$this->statisticsmode = 0;
return FALSE;
}
$this->statisticsmode = $mode;
return TRUE;
}

/** Setup bots to be ignored/rejected
* @method private add_bot
* @param mixed bot string or array of strings (substr of botnames)
@@ -354,13 +377,13 @@ class download extends hvconfig {
}
}

/** Increase download counter in the database (if the Remote UA is not in the
* ignore list)
/** Increase download counter in the database (if statisticsmode is enabled
* and the Remote UA is not in the ignore list)
* @method dbcounter
* @param string filename Filename to process
*/
function dbcounter($file) {
if (!isset($this->dbuser)) return;
if ($this->statisticsmode==0 || !isset($this->dbuser)) return;
$date = date('Y-m-d');
foreach ($this->ignored_bots as $ua) {
if (strpos($this->remote_ua,strtolower($ua))!==FALSE) { // do not count bot downloads
@@ -384,7 +407,8 @@ class download extends hvconfig {
$db->Database = $this->database;
$db->User = $this->dbuser;
$db->Password = $this->dbpass;
@$db->query($query);
$db->Halt_On_Error = "no";
@$db->query($query) || trigger_error("Failed to update the database: ".$db->Error." (".$db->Errno.")",E_USER_ERROR);
}
}


+ 11
- 3
class.hvconfig.inc View File

@@ -211,10 +211,18 @@ class hvconfig {
* @attribute string icondir
*/
$this->icondir = "/images/icons";
/** Shall we use the statistic functions (download counter)?
* 0-No, 1-Yes
* @class hvconfig
* @attribute integer statisticsmode
*/
$this->statisticsmode = 1;
//-----------------------------------------------------[ Database to use ]---
/** Database to store download statistics. To override these settings later,
* it won't work this way -- use the <code>db_setup</code> method instead!
* The array defined here has the elements host, database, user, pass, table
/** Database to store download statistics. Irrelevant (i.e. not used) when
* statistics are turned off (statisticsmode=0). To override these settings
* later, it won't work this way -- use the <code>db_setup</code> method
* instead! The array defined here has the elements host, database, user,
* pass, table
* @class hvconfig
* @attribute array db
*/

+ 10
- 0
histview.css View File

@@ -25,3 +25,13 @@
.feature { color:#090; }
.removed { text-decoration:line-through; }
.changed { text-decoration:none; }

div.ebox {
padding:2px;
background: #e5e5e5;
margin:0.5em;
text-align:center;
color: #f00;
font-weight: bold;
border: 1px solid black;
}

+ 4
- 0
histview.hist View File

@@ -11,6 +11,10 @@ v0.1.6
can override those lateron, as usual). To make future updates easier, it
automatically includes a personal configuration file if that exists
+ histview class now also uses the configuration file(s)
* statistic functions (database related stuff like download counter) can be
disabled now for the download class
* if a database update fails, script is no longer stopped. Instead, an error
is thrown (E_USER_ERROR) and the script continues, ignoring the issue

v0.1.5 (08.05.2008)
-------------------

+ 2
- 2
histview.php View File

@@ -21,7 +21,7 @@ $prog = $_REQUEST["prog"];
if (empty($prog) || @preg_match("/[^\w]/u",$prog)) $prog = "HistView";
# $file should be alphanumeric - no special chars or / or \
$file = $_REQUEST["file"];
if (empty($file) || @preg_match("/[^\w\s-\pL]/u",$file)) unset ($file);
if (empty($file) || @preg_match("/[^\w-_.]/u",$file)) unset ($file);
# $dir should only be one of ours - here: "tar","deb","rpm"
$dir = $_REQUEST["dir"];
if (!empty($dir) && !in_array($dir,array("tar","deb","rpm"))) unset ($file,$dir);
@@ -47,7 +47,7 @@ if (!empty($_REQUEST["file"])) {

#-----------------------------------------------[ Display the history file ]---
include("histview.inc");
$file = strtolower($prog).".hist";
$file = $dirs["tar"]."/".strtolower($prog).".hist"; // ChangeLog to parse
# Simple method, no download links to provide:
#$hv = new histview($file);
# Providing download links:

Loading…
Cancel
Save