update some classes
authorStricted <info@nexus-irc.de>
Mon, 17 Feb 2014 00:18:38 +0000 (01:18 +0100)
committerStricted <info@nexus-irc.de>
Mon, 17 Feb 2014 00:20:57 +0000 (01:20 +0100)
APC.class.php
Feed.class.php
LDAP.class.php
db.class.php
git.class.php
hash.class.php

index 27693bb2742568cda8fd2e771c17502f9e720a18..f5b7fe243cb061dfa0f9069f9a00e66864bff17f 100644 (file)
@@ -24,9 +24,11 @@ class APC {
                if (extension_loaded("apcu")) {
                        $this->apcu = true;
                        $this->version = phpversion('apcu');
-               } else if (extension_loaded("apc")) {
+               }
+               else if (extension_loaded("apc")) {
                        $this->version = phpversion('apc');
-               } else {
+               }
+               else {
                        throw new Exception('APC/APCu support is not enabled.');
                }
        }
index 180c9685956fb751139a8725cd28fc53dd8d05bc..520ddac0b9b64b9c15dd1ce5629c5f9cfe4bcf5c 100644 (file)
@@ -1,39 +1,41 @@
 <?php
 /**
- * @author      Jan Altensen (Stricted)
- * @copyright   2013-2014 Jan Altensen (Stricted)
- * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- */
+* @author      Jan Altensen (Stricted)
+* @copyright   2013-2014 Jan Altensen (Stricted)
+* @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+*/
 class FeedClass {
        public function __construct($url) {
-        $file = file_get_contents($url);
-        $xml = simplexml_load_string($file);
-        $type = $this->getFeedType($xml);
-        $data = null;
-        switch($type) {
-            case 'rss':
-                $data = $this->parseRSSFeed($xml);
-                break;
-            case 'atom':
-                $data = $this->parseAtomFeed($xml);
-                break;
-            default:
-                return null;
-                break;
-        }
-        return $data;  
-    }
-
-    private function parseRSSFeed($xml) {
+               $file = file_get_contents($url);
+               $xml = simplexml_load_string($file);
+               $type = $this->getFeedType($xml);
+               $data = null;
+               switch($type) {
+                       case 'rss':
+                               $data = $this->parseRSSFeed($xml);
+                               break;
+
+                       case 'atom':
+                               $data = $this->parseAtomFeed($xml);
+                               break;
+
+                       default:
+                               return null;
+                               break;
+               }
+               return $data;  
+       }
+
+       private function parseRSSFeed($xml) {
                foreach ($xml->channel->item as $item) {
                        $item->pubDate = $this->getTime($item->pubDate);
                        $item->description = html_entity_decode($item->description);
                        $data[] = $item;
                } 
                return $data;
-    }
+       }
 
-    private function parseAtomFeed($xml) {
+       private function parseAtomFeed($xml) {
                $entries = $xml->children()->entry;
                foreach ($entries as $entry) {
                        $entry->children()->author = $entry->children()->author->name;
@@ -42,22 +44,26 @@ class FeedClass {
                        $data[] = $entry->children();
                }
                return $data;
-    }
+       }
 
-    private function getTime($time) {
-               return date("d.m.Y H:i:s",intval(strtotime($time)));;
+       private function getTime($time) {
+               return date("d.m.Y H:i:s",intval(strtotime($time)));
        }
-       
-    private function getTimeStamp($time) {
-               return intval(strtotime($time));;
+
+       private function getTimeStamp($time) {
+               return intval(strtotime($time));
        }
 
-    public static function getFeedType($xml) {
-        $type = false;
-        if (isset($xml->channel->item)) $type = 'rss';
-        if (isset($xml->entry)) $type = 'atom';
+       public static function getFeedType($xml) {
+               $type = '';
+               if (isset($xml->channel->item)) {
+                       $type = 'rss';
+               }
+               else if (isset($xml->entry)) {
+                       $type = 'atom';
+               }
 
-        return $type;
-    }
+               return $type;
+       }
 }
 ?>
\ No newline at end of file
index fbf462387b55e2ae873a4c0ead66a5fd6bb7de91..b53721adcb1b24b825a38fe1333e4974b538a84b 100644 (file)
@@ -20,10 +20,9 @@ class LDAP {
         * Constructs a new instance of LDAP class.
         */
        public function __construct () {
-               if(!extension_loaded("ldap")) {
+               if (!extension_loaded("ldap")) {
                        throw new Exception("Can not find LDAP extension.");
                }
-
        }
        
        /**
@@ -37,13 +36,16 @@ class LDAP {
        public function connect ($server, $port, $dn) {
                $this->ldap = ldap_connect($server, $port);
                $this->dn = $dn;
-               if($this->ldap) {
+               
+               if ($this->ldap) {
                        ldap_set_option($this->ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
                        ldap_set_option($this->ldap, LDAP_OPT_REFERRALS, 0);
                        return true;
-               } else {
+               }
+               else {
                        throw new Exception("Cant connect to ldap server.");
                }
+               
                return false;
        }
        
index ccca08ea038568b286da094c08e28945db57c1d6..76eab9bbe2452cb62eaca46af7b7b65d3f66a855 100644 (file)
@@ -14,30 +14,32 @@ class DB {
         * 
         * @return      true/false
         */
-       public function connect($driver, $host, $user, $pass, $db, $port = Null) {
+       public function connect($driver, $host, $username, $password, $database, $port = "", $driver_options = array()) {
                if (!extension_loaded("pdo")) die("Missing <a href=\"http://www.php.net/manual/en/book.pdo.php\">PDO</a> PHP extension."); // check if extension loaded
                try {
                        switch (strtolower($driver)) {
                                case "mysql":
                                        if (!extension_loaded("pdo_mysql")) die("Missing <a href=\"http://php.net/manual/de/ref.pdo-mysql.php\">pdo_mysql</a> PHP extension."); // check if extension loaded
-                                       if(empty($port)) $port=3306;
-                                       $this->conn = new PDO("mysql:host=".$host.";port=".$port.";dbname=".$db, $user, $pass);
+                                       if (empty($port)) $port=3306;
+                                       $this->conn = new PDO("mysql:host=".$host.";port=".$port.";dbname=".$v, $username, $password, $driver_options);
                                        break;
                                
                                case "pgsql":
                                        if (!extension_loaded("pdo_pgsql")) die("Missing <a href=\"http://php.net/manual/de/ref.pdo-pgsql.php\">pdo_pgsql</a> PHP extension."); // check if extension loaded
-                                       if(empty($port)) $port=5432;
-                                       $this->conn = new PDO("pgsql:host=".$host.";port=".$port.";dbname=".$db, $user, $pass);
+                                       if (empty($port)) $port=5432;
+                                       $this->conn = new PDO("pgsql:host=".$host.";port=".$port.";dbname=".$database, $username, $password, $driver_options);
                                        break;
                                        
                                case "sqlite":
                                        if (!extension_loaded("pdo_sqlite")) die("Missing <a href=\"http://php.net/manual/de/ref.pdo-sqlite.php\">pdo_sqlite</a> PHP extension."); // check if extension loaded 
-                                       if(!file_exists($db)) {
-                                               @touch($db);
+                                       if (!file_exists($v)) {
+                                               @touch($database);
                                        }
-                                       if(file_exists($db) && is_readable($db) && is_writable($db)) {
-                                               $this->conn = new PDO("sqlite:".$db, $user, $pass);
-                                       } else {
+                                       
+                                       if (file_exists($database) && is_readable($database) && is_writable($database)) {
+                                               $this->conn = new PDO("sqlite:".$database, $username, $password, $driver_options);
+                                       }
+                                       else {
                                                $this->error = "cant crate/connect the/to sqlite database";
                                                return false;
                                        }
@@ -73,10 +75,14 @@ class DB {
                try {
                        $query = Null;
                        $query = $this->conn->prepare($res);
-                       if(is_array($bind) && !empty($bind))
+                       
+                       if (is_array($bind) && !empty($bind)) {
                                $query->execute($bind);
-                       else
+                       }
+                       else {
                                $query->execute();
+                       }
+                       
                        return $query;
                } catch (PDOException $e) {
                        $this->error = $e->getMessage();
index 412ed712680e11c0c2ac170e8bfde6cf07a8b867..4acb81f36009c4a437090e4195df78444e064c65 100644 (file)
@@ -21,7 +21,7 @@ class git {
         */
        public function get_commits ($count = -1, $branch = "master") {
                $data = array();
-               if(!$data) {
+               if (!$data) {
                        $cmd = "git --git-dir=".$this->repo." rev-list --header --max-count=".$count." ".$branch." ";
                        $rev_list = shell_exec($cmd);
                        foreach(explode("\000", $rev_list) as $rev) {
@@ -29,24 +29,30 @@ class git {
                                $rev_lines = explode("\n", str_replace("\r", "", $rev));
                                $commit['id'] = $rev_lines[0];
                                foreach($rev_lines as $rev_line) {
-                                       if(substr($rev_line, 0, 4) == "    ") {
-                                               if(isset($commit['text'])) {
+                                       if (substr($rev_line, 0, 4) == "    ") {
+                                               if (isset($commit['text'])) {
                                                        $commit['text'] .= "\n".substr($rev_line, 4);
-                                               } else
+                                               }
+                                               else {
                                                        $commit['text'] = substr($rev_line, 4);
-                                       } else {
+                                               }
+                                       }
+                                       else {
                                                $opt = explode(" ", $rev_line, 2);
-                                               if($opt[0] == "tree") {
+                                               if ($opt[0] == "tree") {
                                                        $commit['tree'] = $opt[1];
-                                               } else if($opt[0] == "parent") {
+                                               }
+                                               else if ($opt[0] == "parent") {
                                                        $commit['parent'][] = $opt[1];
-                                               } else if($opt[0] == "author") {
+                                               }
+                                               else if ($opt[0] == "author") {
                                                        preg_match('/(.*) <([^>]*)> ([0-9]*) ([+\-0-9]{5})/i', $opt[1], $matches);
                                                        $commit['author'] = $matches[1];
                                                        $commit['author_mail'] = $matches[2];
                                                        $commit['author_time'] = $matches[3];
                                                        $commit['author_timezone'] = $matches[4];
-                                               } else if($opt[0] == "committer") {
+                                               }
+                                               else if ($opt[0] == "committer") {
                                                        preg_match('/(.*) <([^>]*)> ([0-9]*) ([+\-0-9]{5})/i', $opt[1], $matches);
                                                        $commit['committer'] = $matches[1];
                                                        $commit['committer_mail'] = $matches[2];
@@ -111,27 +117,35 @@ class git {
                if ($age > 60*60*24*365*2) {
                        $age_str = floor($age/60/60/24/365);
                        $age_str .= " years ago";
-               } else if ($age > 60*60*24*(365/12)*2) {
+               }
+               else if ($age > 60*60*24*(365/12)*2) {
                        $age_str = floor($age/60/60/24/(365/12));
                        $age_str .= " months ago";
-               } else if ($age > 60*60*24*7*2) {
+               }
+               else if ($age > 60*60*24*7*2) {
                        $age_str = floor($age/60/60/24/7);
                        $age_str .= " weeks ago";
-               } else if ($age > 60*60*24*2) {
+               }
+               else if ($age > 60*60*24*2) {
                        $age_str = floor($age/60/60/24);
                        $age_str .= " days ago";
-               } else if ($age > 60*60*2) {
+               }
+               else if ($age > 60*60*2) {
                        $age_str = floor($age/60/60);
                        $age_str .= " hours ago";
-               } else if ($age > 60*2) {
+               }
+               else if ($age > 60*2) {
                        $age_str = floor($age/60);
                        $age_str .= " min ago";
-               } else if ($age > 2) {
+               }
+               else if ($age > 2) {
                        $age_str = $age;
                        $age_str .= " sec ago";
-               } else if ($age >= 0) {
+               }
+               else if ($age >= 0) {
                        $age_str = "right now";
-               } else {
+               }
+               else {
                        $age_str = "right now";
                }
                return $age_str;
@@ -147,13 +161,16 @@ class git {
                $now = time();
                $age = ($last_change > 0 ? ($now - $last_change) : 0);
                
-               if($age == 0) {
+               if ($age == 0) {
                        $age_class = "noage";
-               } else if ($age < 60*60*2) {
+               }
+               else if ($age < 60*60*2) {
                        $age_class = "age0";
-               } else if ($age < 60*60*24*2) {
+               }
+               else if ($age < 60*60*24*2) {
                        $age_class = "age1";
-               } else {
+               }
+               else {
                        $age_class = "age2";
                }
                return $age_class;
index 7db046e06a2da41cd4f309f836ca1f7e03a39c4f..994c129d59d355fbe6e7fb91464af55cc8bba0dc 100644 (file)
@@ -22,9 +22,11 @@ class hash {
                $this->raw = $raw;
                $this->hmac = $hmac;
                $this->key = $key;
+               
                if (in_array($algo, hash_algos())) {
                        $this->algo = $algo;
-               } else {
+               }
+               else {
                        die("algorithm ".$algo." not supported");
                }
        }
@@ -38,7 +40,8 @@ class hash {
        public function hash ($data) {
                if (!empty($this->hmac)) {
                        return hash_hmac($this->algo, $data, $this->key, $this->raw);
-               } else {
+               }
+               else {
                        return hash($this->algo, $data, $this->raw);
                }
        }
@@ -52,7 +55,8 @@ class hash {
        public function hash_file ($file) {
                if (!empty($this->hmac)) {
                        return hash_hmac_file($this->algo, $file, $this->key, $this->raw);
-               } else {
+               }
+               else {
                        return hash_file($this->algo, $file, $this->raw);
                }
        }
@@ -66,9 +70,11 @@ class hash {
         */
        public function compare ($hash, $data) {
                $newhash = $this->hash($data);
+               
                if ($newhash == $hash) {
                        return true;
                }
+               
                return false;
        }
        
@@ -81,9 +87,11 @@ class hash {
         */
        public function compare_file ($hash, $file) {
                $newhash = $this->hash_file($file);
+               
                if ($newhash == $hash) {
                        return true;
                }
+               
                return false;
        }
 }