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.');
}
}
<?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;
$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
* 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.");
}
-
}
/**
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;
}
*
* @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;
}
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();
*/
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) {
$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];
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;
$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;
$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");
}
}
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);
}
}
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);
}
}
*/
public function compare ($hash, $data) {
$newhash = $this->hash($data);
+
if ($newhash == $hash) {
return true;
}
+
return false;
}
*/
public function compare_file ($hash, $file) {
$newhash = $this->hash_file($file);
+
if ($newhash == $hash) {
return true;
}
+
return false;
}
}