Changeset 770

Show
Ignore:
Timestamp:
12/30/07 18:31:19 (11 months ago)
Author:
michiel
Message:

introduce a logging class.
For now it only logs stuff in the admin backend.
More work to be done.

Re #161

Location:
trunk
Files:
4 added
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/admin/index.php

    r724 r770  
    173173                                        $admin->show_about(); 
    174174                                        break; 
     175                                case "show_userlog" : 
     176                                        $admin->show_userlog(); 
     177                                        break; 
    175178                                default :  
    176179                                        $admin->show_index(); 
  • trunk/common/mvblog_admin.php

    r757 r770  
    4747                parent::__construct($basedir."plugins/", 1); 
    4848                $this->webroot = $this->webroot."admin/"; 
     49                $this->log = new MvBlog_log($basedir, 1); 
    4950 
    5051                if (array_key_exists("action", $_POST)) 
     
    6768                                $this->_selected_menuitem = "manage"; 
    6869                                $this->_selected_submenuitem = "dossiers"; 
     70                                break; 
     71                        case "show_userlog": 
     72                                $this->_selected_menuitem = "users"; 
     73                                $this->_selected_submenuitem = "log"; 
    6974                                break; 
    7075                        case "show_authors" : 
     
    217222                        $_SESSION["author_website"]  = $row["website"]; 
    218223                        $_SESSION["blog_user"]       = 1; 
     224                        $this->log->add_log(mktime(), $row["id"], 1, "Admin logged in"); 
    219225                        header("Location: index.php"); 
    220226                } else { 
     
    228234         */ 
    229235        public function logout() { 
     236                $this->log->add_log(mktime(), $_SESSION["author_id"], 1, "Admin logged off"); 
    230237                session_destroy(); 
    231238                header("Location: index.php"); 
     
    358365                                <a class="if_menu_item<?php if ($this->_selected_menuitem == "index")      { echo "_act"; } ?>" href="./index.php"><?php echo gettext("Main"); ?></a>&nbsp; 
    359366                                <a class="if_menu_item<?php if ($this->_selected_menuitem == "manage")     { echo "_act"; } ?>" href="./index.php?action=show_posts"><?php echo gettext("Manage"); ?></a>&nbsp; 
    360                                 <a class="if_menu_item<?php if ($this->_selected_menuitem == "users")      { echo "_act"; } ?>" href="./index.php?action=show_authors"><?php echo gettext("Users"); ?></a>&nbsp; 
     367                                <a class="if_menu_item<?php if ($this->_selected_menuitem == "users")      { echo "_act"; } ?>" href="./index.php?action=show_userlog"><?php echo gettext("Users"); ?></a>&nbsp; 
    361368                                <a class="if_menu_item<?php if ($this->_selected_menuitem == "settings")   { echo "_act"; } ?>" href="./index.php?action=show_settings"><?php echo gettext("Settings"); ?></a>&nbsp; 
    362369                                <a class="if_menu_item<?php if ($this->_selected_menuitem == "plugins")    { echo "_act"; } ?>" href="./index.php?action=show_plugins"><?php echo gettext("Plugins"); ?></a>&nbsp; 
     
    551558                                $cat["id"] 
    552559                        ); 
     560                        $logmsg = sprintf("Category %d:%s updated", $cat["id"], $cat["name"]); 
    553561                } else { 
    554562                        $query  = sprintf("INSERT INTO categories (%s, %s, %s, %s, %s) VALUES ('%s', '%s', %d, %d, '%s')", 
     
    560568                                $cat["icon"] 
    561569                        ); 
     570                        $logmsg = sprintf("Category %s created", $cat["name"]); 
    562571                } 
    563572                $res =& $this->db->exec($query); 
     
    565574                        die($res->getUserInfo()); 
    566575                } 
     576                $this->log->add_log(mktime(), $_SESSION["author_id"], 1, $logmsg); 
    567577                header("Location: index.php?action=show_cats"); 
    568578        } 
     
    580590                        die($res->getUserInfo()); 
    581591                } 
     592                $this->log->add_log(mktime(), $_SESSION["author_id"], 1, sprintf("Category %d deleted", $id)); 
    582593                header("Location: index.php?action=show_cats"); 
    583594        } 
     
    677688                                $dossier["id"] 
    678689                        ); 
     690                        $logmsg = sprintf("Dossier %d:%s updated", $dossier["id"], $dossier["name"]); 
    679691                } else { 
    680692                        $query  = sprintf("INSERT INTO dossiers (%s, %s, %s, %s) VALUES ('%s', '%s', %d, %d)", 
     
    685697                                $dossier["public"] 
    686698                        ); 
     699                        $logmsg = sprintf("Dossier %s created", $dossier["name"]); 
    687700                } 
    688701                $res =& $this->db->exec($query); 
     
    690703                        die($res->getUserInfo()); 
    691704                } 
     705                $this->log->add_log(mktime(), $_SESSION["author_id"], 1, $logmsg); 
    692706                header("Location: index.php?action=show_dossiers"); 
    693707        } 
     
    705719                        die($res->getUserInfo()); 
    706720                } 
     721                $this->log->add_log(mktime(), $_SESSION["author_id"], 1, sprintf("Dossier %d deleted", $id)); 
    707722                header("Location: index.php?action=show_dossiers"); 
    708723        } 
     
    837852                                } 
    838853                                $query .= sprintf(" WHERE id = %d", $author["id"]); 
     854                                $logmsg = sprintf("Author %d:%s updated", $author["id"], $author["login"]); 
    839855                        } else { 
    840856                                $query = sprintf("INSERT INTO authors (%s, %s, %s, %s, %s, %s) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", 
     
    847863                                        $author["active"] 
    848864                                ); 
     865                                $logmsg = sprintf("Author %s created", $author["login"]); 
    849866                        } 
    850867                        $res =& $this->db->exec($query); 
     
    852869                                die($res->getUserInfo()); 
    853870                        } 
     871                        $this->log->add_log(mktime(), $_SESSION["author_id"], 1, $logmsg); 
    854872                        header("Location: index.php?action=show_authors"); 
    855873                } else { 
     
    10361054                                } 
    10371055                                $query .= sprintf(" WHERE id = %d", $user["id"]); 
     1056                                $logmsg = sprintf("User %d:%s updated", $user["id"], $user["username"]); 
    10381057                        } else { 
    10391058                                $query = sprintf("INSERT INTO blog_users (%s, %s, %s, %s, %s, %s) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", 
     
    10461065                                        $user["active"] 
    10471066                                ); 
     1067                                $logmsg = sprintf("User %s created", $user["username"]); 
    10481068                        } 
    10491069                        $res =& $this->db->exec($query); 
     
    10511071                                die($res->getUserInfo()); 
    10521072                        } 
     1073                        $this->log->add_log(mktime(), $_SESSION["author_id"], 1, $logmsg); 
    10531074                        header("Location: index.php?action=show_users"); 
    10541075                } else { 
     
    10871108                        } 
    10881109                } 
     1110                $this->log->add_log(mktime(), $_SESSION["author_id"], 1, sprintf("User %d deleted", $userid)); 
    10891111                header("Location: index.php?action=show_users"); 
    10901112        } 
     
    14511473                        $query .= sprintf(", ping_sent = 1, tb_uri = '%s'", preg_quote($tb_uri, "'")); 
    14521474                        $query .= sprintf(" WHERE id = %d", $post["id"]); 
     1475                        $logmsg = sprintf("Article %d:%s updated", $post["id"], $post["title"]); 
    14531476                } else { 
    14541477                        $query  = sprintf("INSERT INTO articles (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", 
     
    14671490                                $post["postformat"] 
    14681491                        ); 
     1492                        $logmsg = sprintf("Article %s created", $post["title"]); 
    14691493                } 
    14701494                $res =& $this->db->exec($query); 
     
    14721496                        die($res->getUserInfo()); 
    14731497                } 
     1498                $this->log->add_log(mktime(), $_SESSION["author_id"], 1, $logmsg); 
    14741499                if (!$post["id"]) { 
    14751500                        /* this is a new post. fetch old data */ 
     
    14991524                                die("error"); 
    15001525                        } 
     1526                        $this->log->add_log(mktime(), $_SESSION["author_id"], 1, sprintf("Trackback for article %s sent to %s", $post["title"], $post["tb_uri"])); 
    15011527                        $sql = sprintf("UPDATE articles SET ping_sent = 1 WHERE id = %d", $post["id"]); 
    15021528                        $res =& $db->exec($sql); 
     
    15231549                        die($res->getUserInfo()); 
    15241550                } 
     1551                $this->log->add_log(mktime(), $_SESSION["author_id"], 1, sprintf("Article %d deleted", $id)); 
    15251552                header("Location: index.php?action=show_posts"); 
    15261553        } 
     
    16011628                $sql = sprintf("DELETE FROM comments WHERE id = %d", $id); 
    16021629                $res = $this->db->exec($sql); 
     1630                $this->log->add_log(mktime(), $_SESSION["author_id"], 1, sprintf("Comment %d deleted", $id)); 
    16031631                header("Location: index.php?action=show_comments"); 
    16041632        } 
     
    16981726                $active_plugins = serialize($this->active_plugins); 
    16991727                $this->save_settings(array("active_plugins" => $active_plugins)); 
     1728                $this->log->add_log(mktime(), $_SESSION["author_id"], 1, sprintf("Plugin %s activated", $plugin)); 
    17001729                return true; 
    17011730        } 
     
    17131742                $active_plugins = serialize($this->active_plugins); 
    17141743                $this->save_settings(array("active_plugins" => $active_plugins)); 
     1744                $this->log->add_log(mktime(), $_SESSION["author_id"], 1, sprintf("Plugin %s de-activated", $plugin)); 
    17151745                return true; 
    17161746        } 
     
    20112041        } 
    20122042        /* }}} */ 
     2043        /* show_userlog {{{ */ 
     2044        /** 
     2045         * Show a log of what happened 
     2046         */ 
     2047        public function show_userlog() { 
     2048                $this->log->show_log(); 
     2049        } 
     2050        /* }}} */ 
    20132051} 
    20142052?> 
  • trunk/common/mvblog_common.php

    r757 r770  
    137137        public function __construct($plugindir="plugins/", $adminmode=0, $upgrade=0) { 
    138138                /* start session and output buffering */ 
    139                 session_start(); 
     139                if (session_id() == "") 
     140                        session_start(); 
    140141                ob_start(); 
    141142