diff options
Diffstat (limited to 'src/SemanticScuttle/Model')
-rw-r--r-- | src/SemanticScuttle/Model/Bookmark.php | 63 | ||||
-rw-r--r-- | src/SemanticScuttle/Model/RemoteUser.php | 48 | ||||
-rw-r--r-- | src/SemanticScuttle/Model/Template.php | 107 | ||||
-rw-r--r-- | src/SemanticScuttle/Model/Theme.php | 97 | ||||
-rw-r--r-- | src/SemanticScuttle/Model/User.php | 209 | ||||
-rw-r--r-- | src/SemanticScuttle/Model/User/SslClientCert.php | 148 | ||||
-rw-r--r-- | src/SemanticScuttle/Model/UserArray.php | 41 |
7 files changed, 713 insertions, 0 deletions
diff --git a/src/SemanticScuttle/Model/Bookmark.php b/src/SemanticScuttle/Model/Bookmark.php new file mode 100644 index 0000000..1330642 --- /dev/null +++ b/src/SemanticScuttle/Model/Bookmark.php @@ -0,0 +1,63 @@ +<?php +/** + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +/** + * Bookmark model class, keeping the data of a single bookmark. + * It will slowly replace the old array style format. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class SemanticScuttle_Model_Bookmark +{ + /** + * Status "public" / visible for all + */ + const SPUBLIC = 0; + + /** + * Status "shared" / visible for people on your watchlist + */ + const SWATCHLIST = 1; + + /** + * Status "private" / visible for yourself only + */ + const SPRIVATE = 2; + + + + /** + * Checks if the given URL is valid and may be used with this + * SemanticScuttle installation. + * + * @param string $url URL to verify. + * + * @return boolean True if the URL is allowed, false if not + */ + public static function isValidUrl($url) + { + $scheme = parse_url($url, PHP_URL_SCHEME); + if (array_search($scheme, $GLOBALS['allowedProtocols']) === false) { + return false; + } + return true; + } + +} + + +?>
\ No newline at end of file diff --git a/src/SemanticScuttle/Model/RemoteUser.php b/src/SemanticScuttle/Model/RemoteUser.php new file mode 100644 index 0000000..6d48e3a --- /dev/null +++ b/src/SemanticScuttle/Model/RemoteUser.php @@ -0,0 +1,48 @@ +<?php +/** + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net> + * @author Christian Weiske <cweiske@cweiske.de> + * @author Eric Dane <ericdane@users.sourceforge.net> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +/** + * Remote User helper methods. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class SemanticScuttle_Model_RemoteUser +{ + /** + * Returns the remote user's IP. + * + * @return string IP address. NULL if not found. + */ + public static function getIp() + { + $ip = null; + if (getenv('REMOTE_ADDR')) { + $ip = getenv('REMOTE_ADDR'); + } else if (getenv('HTTP_CLIENT_IP')) { + $ip = getenv('HTTP_CLIENT_IP'); + } else if (getenv('HTTP_X_FORWARDED_FOR')) { + $ip = getenv('HTTP_X_FORWARDED_FOR'); + } + + return $ip; + } + +} + +?>
\ No newline at end of file diff --git a/src/SemanticScuttle/Model/Template.php b/src/SemanticScuttle/Model/Template.php new file mode 100644 index 0000000..234e23f --- /dev/null +++ b/src/SemanticScuttle/Model/Template.php @@ -0,0 +1,107 @@ +<?php +/** + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net> + * @author Christian Weiske <cweiske@cweiske.de> + * @author Eric Dane <ericdane@users.sourceforge.net> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +/** + * SemanticScuttle HTML templating system. + * This templating system is really, really simple and based + * on including php files while proving a set of + * variables in the template scope. + * When rendering templates, they are directly echoed to the + * browser. There is no in-built way to capture their output. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net> + * @author Christian Weiske <cweiske@cweiske.de> + * @author Eric Dane <ericdane@users.sourceforge.net> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class SemanticScuttle_Model_Template +{ + /** + * Array of variables to be available in template + * scope. + * + * @var array + */ + protected $vars = array(); + + /** + * File name of template + */ + protected $file = ''; + + /** + * Template service instance + * + * @var SemanticScuttle_Service_Template + */ + protected $ts; + + + + /** + * Create a new template instance + * + * @param string $file Template filename, + * full path + * @param array $vars Template variables + * @param SemanticScuttle_Service_Template $ts Template service + */ + public function __construct( + $file, $vars = null, + SemanticScuttle_Service_Template $ts = null + ) { + $this->vars = $vars; + $this->file = $file; + $this->ts = $ts; + } + + + + /** + * Sets variables and includes the template file, + * causing it to be rendered. + * + * Does not take care of themes and so. + * The include path must be set so the correct theme is used. + * + * @return void + */ + public function parse() + { + if (isset($this->vars)) { + extract($this->vars); + } + include $this->file; + } + + + + /** + * Loads another template + * + * @param string $file Filename of template, relative + * to template directory + * + * @return SemanticScuttle_Service_Template Template object + */ + public function includeTemplate($file) + { + return $this->ts->loadTemplate($file, $this->vars); + } +} +?>
\ No newline at end of file diff --git a/src/SemanticScuttle/Model/Theme.php b/src/SemanticScuttle/Model/Theme.php new file mode 100644 index 0000000..65861b8 --- /dev/null +++ b/src/SemanticScuttle/Model/Theme.php @@ -0,0 +1,97 @@ +<?php +/** + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license AGPL v3 or later http://www.gnu.org/licenses/agpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +/** + * A theme, the visual representation of SemanticScuttle. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license AGPL v3 or later http://www.gnu.org/licenses/agpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class SemanticScuttle_Model_Theme +{ + /** + * Theme name. Also the path part of template and resource files + * + * @var string + */ + protected $name = null; + + /** + * Local path to the www themes directory. + * Needs to have a trailing slash. + * + * @var string + */ + protected $wwwThemeDir = null; + + + + /** + * Create a new theme instance. + * + * @param string $name Theme name "data/templates/(*)/" + */ + public function __construct($name = 'default') + { + $this->name = $name; + $this->wwwThemeDir = $GLOBALS['wwwdir'] . '/themes/'; + //TODO: implement theme hierarchies with parent fallback + } + + + + /** + * Returns the URL path to a resource file (www/themes/$name/$file). + * Automatically falls back to the parent theme if the file does not exist + * in the theme. + * + * Must always be used when adding i.e. images to the output. + * + * @param string $file File name to find the path for, i.e. "scuttle.css". + * + * @return string Full path + */ + public function resource($file) + { + $themeFile = $this->wwwThemeDir . $this->name . '/' . $file; + if (file_exists($themeFile)) { + return ROOT . 'themes/' . $this->name . '/' . $file; + } + + $defaultFile = $this->wwwThemeDir . 'default/' . $file; + if (file_exists($defaultFile)) { + return ROOT . 'themes/default/' . $file; + } + + //file does not exist. fall back to the theme file + // to guide the theme author a bit. + // TODO: logging. in admin mode, there should be a message + return ROOT . 'themes/' . $this->name . '/' . $file; + } + + + + /** + * Returns the theme name. + * + * @return string Theme name + */ + public function getName() + { + return $this->name; + } +} +?>
\ No newline at end of file diff --git a/src/SemanticScuttle/Model/User.php b/src/SemanticScuttle/Model/User.php new file mode 100644 index 0000000..e5d29af --- /dev/null +++ b/src/SemanticScuttle/Model/User.php @@ -0,0 +1,209 @@ +<?php +/** + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net> + * @author Christian Weiske <cweiske@cweiske.de> + * @author Eric Dane <ericdane@users.sourceforge.net> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +/** + * SemanticScuttle user object. + * Rarely used fields are filled if required. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net> + * @author Christian Weiske <cweiske@cweiske.de> + * @author Eric Dane <ericdane@users.sourceforge.net> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class SemanticScuttle_Model_User +{ + var $id; + var $username; + var $name; + var $email; + var $homepage; + var $content; + var $datetime; + var $isAdmin; + var $privateKey; + + /** + * Create a new user object + * + * @param integer $id User ID + * @param string $username Username + */ + public function __construct($id, $username) + { + $this->id = $id; + $this->username = $username; + } + + /** + * Returns user ID + * + * @return integer ID + */ + public function getId() + { + return (int)$this->id; + } + + /** + * Returns logon user name + * + * @return string User name + */ + public function getUsername() + { + return $this->username; + } + + /** + * Returns private key + * + * @param boolean return sanitized value which basically drops + * leading dash if exists + * + * @return string private key + */ + public function getPrivateKey($sanitized = false) + { + // Look for value only if not already set + if (!isset($this->privateKey)) { + $us = SemanticScuttle_Service_Factory::get('User'); + $user = $us->getUser($this->id); + $this->privateKey = $user['privateKey']; + } + if ($sanitized == true) { + return substr($this->privateKey, -32); + } else { + return $this->privateKey; + } + } + + /** + * Returns full user name as specified in the profile. + * + * @return string Full name + */ + public function getName() + { + // Look for value only if not already set + if (!isset($this->name)) { + $us = SemanticScuttle_Service_Factory::get('User'); + $user = $us->getUser($this->id); + $this->name = $user['name']; + } + return $this->name; + } + + /** + * Returns user email address + * + * @return string Email address + */ + public function getEmail() + { + // Look for value only if not already set + if (!isset($this->email)) { + $us = SemanticScuttle_Service_Factory::get('User'); + $user = $us->getUser($this->id); + $this->email = $user['email']; + } + return $this->email; + } + + /** + * Returns user homepage as specified in the profile. + * + * @return string Homepage + */ + public function getHomepage() + { + // Look for value only if not already set + if(!isset($this->homepage)) { + $us = SemanticScuttle_Service_Factory::get('User'); + $user = $us->getUser($this->id); + $this->homepage = $user['homepage']; + } + return $this->homepage; + } + + /** + * Returns custom user description as specified in the profile. + * + * @return string User description + */ + public function getContent() + { + // Look for value only if not already set + if(!isset($this->content)) { + $us = SemanticScuttle_Service_Factory::get('User'); + $user = $us->getUser($this->id); + $this->content = $user['uContent']; + } + return $this->content; + } + + /** + * Returns user creation time. + * UTC/Zulu time zone is used. + * + * @return string Datetime value: "YYYY-MM-DD HH:MM:SS" + */ + public function getDatetime() + { + // Look for value only if not already set + if(!isset($this->content)) { + $us = SemanticScuttle_Service_Factory::get('User'); + $user = $us->getUser($this->id); + $this->datetime = $user['uDatetime']; + } + return $this->datetime; + } + + /** + * Tells you if the user is an administrator + * + * @return boolean True if the user is admin + */ + public function isAdmin() + { + // Look for value only if not already set + if(!isset($this->isAdmin)) { + $us = SemanticScuttle_Service_Factory::get('User'); + $this->isAdmin = $us->isAdmin($this->username); + } + return $this->isAdmin; + } + + /** + * Returns the number of bookmarks the user owns + * + * @param string $range Range of bookmarks: + * 'public', 'shared', 'private' + * or 'all' + * + * @return integer Number of bookmarks + * + * @uses SemanticScuttle_Service_Bookmark::countBookmarks() + */ + public function getNbBookmarks($range = 'public') + { + $bs = SemanticScuttle_Service_Factory::get('Bookmark'); + return $bs->countBookmarks($this->getId(), $range); + } + +} +?> diff --git a/src/SemanticScuttle/Model/User/SslClientCert.php b/src/SemanticScuttle/Model/User/SslClientCert.php new file mode 100644 index 0000000..383b601 --- /dev/null +++ b/src/SemanticScuttle/Model/User/SslClientCert.php @@ -0,0 +1,148 @@ +<?php +/** + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license AGPL http://www.gnu.org/licenses/agpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +/** + * SSL client certificate model. Represents one single client certificate + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license AGPL http://www.gnu.org/licenses/agpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class SemanticScuttle_Model_User_SslClientCert +{ + public $id; + public $uId; + public $sslSerial; + public $sslClientIssuerDn; + public $sslName; + public $sslEmail; + + + + /** + * Creates and returns a new object and fills it with + * the passed values from the database. + * + * @param array $arCertRow Database row array + * + * @return SemanticScuttle_Model_User_SslClientCert + */ + public static function fromDb($arCertRow) + { + $cert = new self(); + foreach (get_object_vars($cert) as $variable => $dummy) { + if (isset($arCertRow[$variable])) { + $cert->$variable = $arCertRow[$variable]; + } + } + return $cert; + } + + + + /** + * Loads the user's/browser's client certificate information into + * an object and returns it. + * Expects that all information is available. + * Better check with + * SemanticScuttle_Service_User_SslClientCert::hasValidCert() before. + * + * @return SemanticScuttle_Model_User_SslClientCert + * + * @see SemanticScuttle_Service_User_SslClientCert::hasValidCert() + */ + public static function fromCurrentCert() + { + $cert = new self(); + $cert->sslSerial = $_SERVER['SSL_CLIENT_M_SERIAL']; + $cert->sslClientIssuerDn = $_SERVER['SSL_CLIENT_I_DN']; + $cert->sslName = $_SERVER['SSL_CLIENT_S_DN_CN']; + $cert->sslEmail = $_SERVER['SSL_CLIENT_S_DN_Email']; + return $cert; + } + + + + /** + * Tells you if this certificate is the one the user is currently browsing + * with. + * + * @return boolean True if this certificate is the current browser's + */ + public function isCurrent() + { + if (!isset($_SERVER['SSL_CLIENT_M_SERIAL']) + || !isset($_SERVER['SSL_CLIENT_I_DN']) + ) { + return false; + } + + return $this->sslSerial == $_SERVER['SSL_CLIENT_M_SERIAL'] + && $this->sslClientIssuerDn == $_SERVER['SSL_CLIENT_I_DN']; + } + + + + /** + * Checks if this certificate is registered (exists) in the certificate + * array + * + * @param array $arCertificates Array of certificate objects + * + * @return boolean True or false + */ + public function isRegistered($arCertificates) + { + foreach ($arCertificates as $cert) { + if ($cert->equals($this)) { + return true; + } + } + return false; + } + + + + /** + * Deletes this certificate from database + * + * @return boolean True if all went well, false if not + */ + public function delete() + { + $ok = SemanticScuttle_Service_Factory::get('User_SslClientCert') + ->delete($this); + if ($ok) { + $this->id = null; + } + return $ok; + } + + + + /** + * Compares this certificate with the given one. + * + * @param SemanticScuttle_Service_Factory $cert Another user certificate + * + * @return boolean True if both match. + */ + public function equals(SemanticScuttle_Model_User_SslClientCert $cert) + { + return $this->sslSerial == $cert->sslSerial + && $this->sslClientIssuerDn == $cert->sslClientIssuerDn; + } +} +?>
\ No newline at end of file diff --git a/src/SemanticScuttle/Model/UserArray.php b/src/SemanticScuttle/Model/UserArray.php new file mode 100644 index 0000000..a0d9c9b --- /dev/null +++ b/src/SemanticScuttle/Model/UserArray.php @@ -0,0 +1,41 @@ +<?php +/** + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +/** + * Mostly static methods that help working with a user row array from database. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class SemanticScuttle_Model_UserArray +{ + /** + * Returns full user name as specified in the profile if it is set, + * otherwise the nickname/loginname is returned. + * + * @param array $row User row array from database + * + * @return string Full name or username + */ + public static function getName($row) + { + if (isset($row['name']) && $row['name']) { + return $row['name']; + } + return $row['username']; + } +} +?>
\ No newline at end of file |