* @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);
}
return $data;
}
-
+
+ /**
+ * parse rss feed
+ *
+ * @param object $xml
+ * @return array
+ */
private function parseAtomFeed($xml) {
$entries = $xml->children()->entry;
foreach ($entries as $entry) {
}
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)) {
* @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
*/
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;
}
/**
* 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 {
}
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;
* @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;
/**
* hash given data with given algorithm
*
- * @param mixed $data
- * @return hash
+ * @param string $data
+ * @return string
*/
public function hash ($data) {
if (!empty($this->hmac)) {
/**
* 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)) {
/**
* compare the given data
*
- * @param hash $hash
- * @param mixed $data
+ * @param string $hash
+ * @param string $data
* @return boolean
*/
public function compare ($hash, $data) {
/**
* compare the given file
*
- * @param hash $hash
- * @param mixed $file
+ * @param string $hash
+ * @param string $file
* @return boolean
*/
public function compare_file ($hash, $file) {