summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-05-20 14:57:56 -0400
committerEvan Prodromou <evan@prodromou.name>2008-05-20 14:57:56 -0400
commit5d1a6f0fef3b99167babfa304ceda9b67720f399 (patch)
tree451830a55e2cacac2d224ac85a6e2d74a57a36ac
parenta9c57467e77f5420cca866d5e4c28b10da2f75fc (diff)
add validation methods to classes
darcs-hash:20080520185756-84dde-290bc12cddfc1738a96385e95821d466eff11196.gz
-rw-r--r--classes/Avatar.php12
-rw-r--r--classes/Notice.php9
-rw-r--r--classes/Profile.php29
-rw-r--r--classes/Remote_profile.php5
-rw-r--r--classes/User.php10
-rw-r--r--doc/README6
-rw-r--r--doc/TODO4
7 files changed, 75 insertions, 0 deletions
diff --git a/classes/Avatar.php b/classes/Avatar.php
index 2e0e1f3fb..57e0d2fa8 100644
--- a/classes/Avatar.php
+++ b/classes/Avatar.php
@@ -25,4 +25,16 @@ class Avatar extends DB_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+
+ function validateMediatype() {
+ return Validate::string($this->mediatype, array('min_length' => 1, 'max_length' => 32));
+ }
+
+ function validateFilename() {
+ return Validate::string($this->filename, array('min_length' => 1, 'max_length' => 255));
+ }
+
+ function validateUrl() {
+ return Validate::uri($this->url, array('allowed_schemes' => array('http', 'https')));
+ }
}
diff --git a/classes/Notice.php b/classes/Notice.php
index 24c813330..3e6835ec9 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -52,4 +52,13 @@ class Notice extends DB_DataObject
}
return $this->profile;
}
+
+ function validateContent() {
+ return Validate::string($this->content, array('min_length' => 1, 'max_length' => 140));
+ }
+
+ function validateUrl() {
+ return is_null($this->url) ||
+ Validate::uri($this->url, array('allowed_schemes' => array('http', 'https')));
+ }
}
diff --git a/classes/Profile.php b/classes/Profile.php
index 686a79163..4119cd411 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -72,4 +72,33 @@ class Profile extends DB_DataObject
return NULL;
}
}
+
+ function validateNickname() {
+ return Validate::string($this->nickname, array('min_length' => 1, 'max_length' => 64,
+ 'format' => VALIDATE_ALPHA_LOWER . VALIDATE_NUM));
+ }
+
+ function validateProfileurl() {
+ return Validate::uri($this->profileurl, array('allowed_schemes' => array('http', 'https')));
+ }
+
+ function validateHomepage() {
+ return (is_null($this->homepage) ||
+ Validate::uri($this->homepage, array('allowed_schemes' => array('http', 'https'))));
+ }
+
+ function validateBio() {
+ return is_null($this->bio) ||
+ Validate::string($this->bio, array('min_length' => 1, 'max_length' => 140));
+ }
+
+ function validateLocation() {
+ return is_null($this->location) ||
+ Validate::string($this->location, array('min_length' => 1, 'max_length' => 255));
+ }
+
+ function validateFullname() {
+ return is_null($this->fullname) ||
+ Validate::string($this->fullname, array('min_length' => 1, 'max_length' => 255));
+ }
}
diff --git a/classes/Remote_profile.php b/classes/Remote_profile.php
index 0aa727ad1..f36ac5f0c 100644
--- a/classes/Remote_profile.php
+++ b/classes/Remote_profile.php
@@ -40,4 +40,9 @@ class Remote_profile extends DB_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+
+ function validateUrl() {
+ return is_null($this->url) ||
+ Validate::uri($this->url, array('allowed_schemes' => array('http', 'https')));
+ }
}
diff --git a/classes/User.php b/classes/User.php
index 8986053c5..8effd856a 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -22,6 +22,7 @@ if (!defined('LACONICA')) { exit(1); }
* Table Definition for user
*/
require_once 'DB/DataObject.php';
+require_once 'Validate.php';
class User extends DB_DataObject
{
@@ -59,4 +60,13 @@ class User extends DB_DataObject
$sub->subscribed = $other->id;
return $sub->find();
}
+
+ function validateEmail() {
+ return Validate::email($this->email, true);
+ }
+
+ function validateNickname() {
+ return Validate::string($this->nickname, array('min_length' => 1, 'max_length' => 64,
+ 'format' => VALIDATE_ALPHA_LOWER . VALIDATE_NUM));
+ }
}
diff --git a/doc/README b/doc/README
new file mode 100644
index 000000000..546e4320b
--- /dev/null
+++ b/doc/README
@@ -0,0 +1,6 @@
+This package requires PHP 5.x and the following PHP Pear libraries:
+
+- DB_DataObject
+- Validate
+- XMLWriter
+
diff --git a/doc/TODO b/doc/TODO
index b8bb2f708..5105fa217 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -53,6 +53,10 @@
- site logo
- instructions
- deal with PHP quotes escaping
+- fix layout of textarea
+- make notices into "big links"
+- fix spacing on notices
+- limit entry in textarea to 140 chars
- release 0.2
- set Last-Modified
- XML sitemap generation