some code styleup
authorStricted <info@nexus-irc.de>
Mon, 17 Feb 2014 03:56:06 +0000 (04:56 +0100)
committerStricted <info@nexus-irc.de>
Mon, 17 Feb 2014 03:56:06 +0000 (04:56 +0100)
APC.class.php
Feed.class.php
LDAP.class.php
LDAPHash.class.php
autoload.class.php
bcrypt.class.php
db.class.php
git.class.php
hash.class.php

index f5b7fe243cb061dfa0f9069f9a00e66864bff17f..83cf39b974a6f78a51ad47e3c9520e266fd91a07 100644 (file)
@@ -18,7 +18,7 @@ class APC {
        public $version = 0;
        
        /**
-        * init APC class
+        * Constructs a new instance of APC class.
         */
        public function __construct () {
                if (extension_loaded("apcu")) {
index 520ddac0b9b64b9c15dd1ce5629c5f9cfe4bcf5c..63020b31f8292b59b9b6c1f4fa59d65ea9eb0727 100644 (file)
@@ -4,28 +4,38 @@
 * @copyright   2013-2014 Jan Altensen (Stricted)
 * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 */
-class FeedClass {
+class Feed {
+       /**
+        * Constructs a new instance of Feed class.
+        *
+        * @param       string  $url
+        * @return      array
+        */
        public function __construct($url) {
                $file = file_get_contents($url);
                $xml = simplexml_load_string($file);
                $type = $this->getFeedType($xml);
-               $data = null;
+               $data = array();
+               
                switch($type) {
                        case 'rss':
                                $data = $this->parseRSSFeed($xml);
                                break;
-
+                       
                        case 'atom':
                                $data = $this->parseAtomFeed($xml);
                                break;
-
-                       default:
-                               return null;
-                               break;
                }
+               
                return $data;  
        }
-
+       
+       /**
+        * parse rss feed
+        *
+        * @param       object  $xml
+        * @return      array
+        */
        private function parseRSSFeed($xml) {
                foreach ($xml->channel->item as $item) {
                        $item->pubDate = $this->getTime($item->pubDate);
@@ -34,7 +44,13 @@ class FeedClass {
                } 
                return $data;
        }
-
+       
+       /**
+        * parse rss feed
+        *
+        * @param       object  $xml
+        * @return      array
+        */
        private function parseAtomFeed($xml) {
                $entries = $xml->children()->entry;
                foreach ($entries as $entry) {
@@ -45,15 +61,33 @@ class FeedClass {
                }
                return $data;
        }
-
+       
+       /**
+        * get feed time
+        *
+        * @param       string  $time
+        * @return      integer
+        */
        private function getTime($time) {
-               return date("d.m.Y H:i:s",intval(strtotime($time)));
+               return date("d.m.Y H:i:s", $this->getTimeStamp($time));
        }
-
+       
+       /**
+        * get feed timestamp
+        *
+        * @param       string  $time
+        * @return      integer
+        */
        private function getTimeStamp($time) {
                return intval(strtotime($time));
        }
-
+       
+       /**
+        * get feed type
+        *
+        * @param       object  $xml
+        * @return      array
+        */
        public static function getFeedType($xml) {
                $type = '';
                if (isset($xml->channel->item)) {
index b53721adcb1b24b825a38fe1333e4974b538a84b..d0ede6e8a505cc0d563808d0549549728b1dec99 100644 (file)
@@ -8,11 +8,13 @@
 class LDAP {
        /**
         * LDAP resource id
+        * @var object
         */
        protected $ldap = Null; 
        
        /**
         * LDAP DN
+        * @var string
         */
        protected $dn = '';
        
index 4528179118adf1e5d6ac2f7a1fc52c2cc063d5ca..c3ef96dd0deb7d615d59d98fe2e88459a1969133 100644 (file)
@@ -5,7 +5,6 @@
  * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  */
 class LDAPHash {
-
        /**
         * compare given ldap hash with given password
         *
index 0329e0252ae94c73c07106a64d43a04cc7cd3632..5e92a64c5f5b28a9993dd7723d3e4b16cd9fb1a9 100644 (file)
@@ -5,28 +5,28 @@
  * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  */
 class autoload {
-    /*
-     * constructor to set autoloader
-     */
-    public function __construct () {
-        spl_autoload_register(array('self', 'autoload'));
-    }
-    
-    /*
-     * autoload class files from namespace uses
-     *
-     * @param    string    $className
-     */
-    public static function autoload ($className) {
-        $namespaces = explode('\\', $className);
-        if (count($namespaces) > 1) {
-            array_shift($namespaces);
-            $classPath = dirname(__FILE__) . '/' . implode('/', $namespaces) . '.class.php';
-            if (file_exists($classPath)) {
-                require_once($classPath);
-            }
-        }
-    }
+       /*
+        * constructor to set autoloader
+        */
+       public function __construct () {
+               spl_autoload_register(array('self', 'autoload'));
+       }
+
+       /*
+        * autoload class files from namespace uses
+        *
+        * @param       string  $className
+        */
+       public static function autoload ($className) {
+               $namespaces = explode('\\', $className);
+               if (count($namespaces) > 1) {
+                       array_shift($namespaces);
+                       $classPath = dirname(__FILE__) . '/' . implode('/', $namespaces) . '.class.php';
+                       if (file_exists($classPath)) {
+                               require_once($classPath);
+                       }
+               }
+       }
 }
 new autoload();
 ?> 
\ No newline at end of file
index a515ece4d632ea839e96b187c5f353a98920dd4e..599fb0139624bb54316f6b4ea18b4615198fe716 100644 (file)
@@ -32,7 +32,7 @@ class bcrypt {
         * crypt new password
         *
         * @param       string  $password
-        * @param       string  $double <optional>
+        * @param       string  $double
         * @return      string
         */
        public function crypt ($password, $double = false) {
index 76eab9bbe2452cb62eaca46af7b7b65d3f66a855..626f883bc9f2d5e213d621bb1349cd791588e7d3 100644 (file)
@@ -6,52 +6,89 @@
  */
 
 class DB {
+       /**
+        * PDO object
+        * @var object
+        */
        private $conn = NULL;
-       private $error = NULL;
+       
+       /**
+        * error string
+        * @var string
+        */
+       private $error = '';
 
        /**
         * Connects to SQL Server
-        * 
-        * @return      true/false
+        *
+        * @param       string  $driver
+        * @param       string  $host
+        * @param       string  $username
+        * @param       string  $password
+        * @param       string  $database
+        * @param       integer $port
+        * @param       array   $options
+        * @return      boolean
         */
-       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
+       public function connect($driver, $host, $username, $password, $database, $port = 0, $options = array()) {
+               if (!extension_loaded("pdo")) {
+                       // check if extension loaded
+                       die("Missing <a href=\"http://www.php.net/manual/en/book.pdo.php\">PDO</a> PHP extension.");
+               }
+               
+               $driver = strtolower($driver);
                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=".$v, $username, $password, $driver_options);
-                                       break;
+                       if ($driver == "mysql") {
+                               if (!extension_loaded("pdo_mysql")) {
+                                       // check if extension loaded
+                                       die("Missing <a href=\"http://php.net/manual/de/ref.pdo-mysql.php\">pdo_mysql</a> PHP extension.");
+                               }
+                               
+                               if (empty($port)) {
+                                       $port=3306;
+                               }
+                               
+                               $this->conn = new PDO("mysql:host=".$host.";port=".$port.";dbname=".$v, $username, $password, $options);
+                       }
+                       else if ($driver == "pgsql") {
+                               if (!extension_loaded("pdo_pgsql")) {
+                                       // check if extension loaded
+                                       die("Missing <a href=\"http://php.net/manual/de/ref.pdo-pgsql.php\">pdo_pgsql</a> PHP extension.");
+                               }
+                               
+                               if (empty($port)) {
+                                       $port=5432;
+                               }
                                
-                               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=".$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($v)) {
-                                               @touch($database);
-                                       }
-                                       
-                                       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;
-                                       }
-                                       break;
-                                       
-                               default:
-                                       $this->error = "not supported database type found";
+                               $this->conn = new PDO("pgsql:host=".$host.";port=".$port.";dbname=".$database, $username, $password, $options);
+                       }
+                       else if ($driver == "sqlite") {
+                               if (!extension_loaded("pdo_sqlite")) {
+                                       // check if extension loaded
+                                       die("Missing <a href=\"http://php.net/manual/de/ref.pdo-sqlite.php\">pdo_sqlite</a> PHP extension.");
+                               }
+                               
+                               if (!file_exists($database)) {
+                                       @touch($database);
+                               }
+                               
+                               if (file_exists($database) && is_readable($database) && is_writable($database)) {
+                                       $this->conn = new PDO("sqlite:".$database, $username, $password, $options);
+                               }
+                               else {
+                                       $this->error = "cant crate/connect the/to sqlite database";
                                        return false;
-                                       break;
+                               }
                        }
+                       else{
+                               $this->error = "not supported database type found";
+                               return false;
+                       }
+                       
                        return true;
-               } catch (PDOException $e) {
+                       
+               }
+               catch (PDOException $e) {
                        $this->error = $e->getMessage();
                        return false;
                }
@@ -67,9 +104,9 @@ class DB {
        /**
         * Sends a database query to SQL server.
         *
-        * @param       string          $res            a database query
-        * @param       array           $bind           
-        * @return      integer                                 id of the query result
+        * @param       string  $res
+        * @param       array   $bind           
+        * @return      integer 
         */
        public function query ($res, $bind = array()) {
                try {
@@ -84,37 +121,40 @@ class DB {
                        }
                        
                        return $query;
-               } catch (PDOException $e) {
+               }
+               catch (PDOException $e) {
                        $this->error = $e->getMessage();
                }
        }
-
        
        /**
         * Gets a row from SQL database query result.
         *
-        * @param       string          $res            a database query
-        * @return                              array           a row from result
+        * @param       string  $res
+        * @return      array
         */
        public function fetch_array ($res) {
                try {
                        return $res->fetch(PDO::FETCH_ASSOC);
-               } catch (PDOException $e) {
+               }
+               catch (PDOException $e) {
                        $this->error = $e->getMessage();
                }
        }
        
        /**
         * return the last insert id
+        *
+        * @return      integer
         */
        public function last_id () {
                return $this->conn->lastInsertId();
        }
        
        /**
-        * Returns SQL error number for last error.
+        * Returns SQL last error.
         *
-        * @return      integer         MySQL error number
+        * @return      string
         */
        public function error () {
                return $this->error;
index 4acb81f36009c4a437090e4195df78444e064c65..bbb74355f1fdb733e5a61e29b9124c5afdaf0081 100644 (file)
@@ -6,7 +6,12 @@
  */
 class git {
        protected $repo;
-
+       
+       /**
+        * Constructs a new instance of git class.
+        *
+        * @param       string  $repo
+        */
        public function __construct ($repo) {
                $this->repo = $repo;
        }
@@ -14,8 +19,7 @@ class git {
        /*
         * parse all commits from repo
         *
-        * @param       string  $repo
-        * @param       int             $count
+        * @param       integer $count
         * @param       string  $branch
         * @return      array
         */
@@ -70,7 +74,6 @@ class git {
        /*
         * get latest commit hash
         *
-        * @param       string  $repo
         * @param       string  $branch
         * @raturn      string
         */
@@ -83,9 +86,8 @@ class git {
        /*
         * get commit count
         *
-        * @param       string  $repo
         * @param       string  $branch
-        * @raturn      string
+        * @raturn      integer
         */
        public function get_count ($branch = "master") {
                $count = shell_exec('git --git-dir='.$this->repo.' rev-list --oneline --first-parent --header '.$branch.' | wc -l | sed "s/[ \t]//g"');
@@ -96,7 +98,6 @@ class git {
        /*
         * get commit version
         *
-        * @param       string  $repo
         * @param       string  $branch
         * @raturn      string
         */
index 994c129d59d355fbe6e7fb91464af55cc8bba0dc..719610f812ebda3e652a53f2c7249063b3c0ac74 100644 (file)
@@ -5,20 +5,39 @@
  * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  */
 class hash {
-       protected $raw;
-       protected $hmac;
-       protected $key;
-       protected $algo;
+       /**
+        * raw output
+        * @var string
+        */
+       protected $raw = '';
+       
+       /**
+        * hash with hmac
+        * @var string
+        */
+       protected $hmac = '';
+       
+       /**
+        * hmac key
+        * @var string
+        */
+       protected $key = '';
+       
+       /**
+        * hash algorithm
+        * @var string
+        */
+       protected $algo = '';
        
        /**
         * constructor to validate algorithm
         *
-        * @param       string          $algo
-        * @param       optional        $raw
-        * @param       optional        $hmac
-        * @param       optional        $key
+        * @param       string  $algo
+        * @param       string  $raw
+        * @param       string  $hmac
+        * @param       string  $key
         */
-       public function __construct ($algo, $raw = Null, $hmac = Null, $key = Null) {
+       public function __construct ($algo, $raw = '', $hmac = '', $key = '') {
                $this->raw = $raw;
                $this->hmac = $hmac;
                $this->key = $key;
@@ -34,8 +53,8 @@ class hash {
        /**
         * hash given data with given algorithm
         *
-        * @param       mixed           $data
-        * @return      hash
+        * @param       string  $data
+        * @return      string
         */
        public function hash ($data) {
                if (!empty($this->hmac)) {
@@ -49,8 +68,8 @@ class hash {
        /**
         * hash given file with given algorithm
         *
-        * @param       mixed           $file
-        * @return      hash
+        * @param       string  $file
+        * @return      string
         */
        public function hash_file ($file) {
                if (!empty($this->hmac)) {
@@ -64,8 +83,8 @@ class hash {
        /**
         * compare the given data
         *
-        * @param       hash            $hash
-        * @param       mixed           $data
+        * @param       string  $hash
+        * @param       string  $data
         * @return      boolean
         */
        public function compare ($hash, $data) {
@@ -81,8 +100,8 @@ class hash {
        /**
         * compare the given file
         *
-        * @param       hash            $hash
-        * @param       mixed           $file
+        * @param       string  $hash
+        * @param       string  $file
         * @return      boolean
         */
        public function compare_file ($hash, $file) {