3 * Table Definition for oauth_application
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Oauth_application extends Memcached_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'oauth_application'; // table name
13 public $id; // int(4) primary_key not_null
14 public $owner; // int(4) not_null
15 public $consumer_key; // varchar(255) not_null
16 public $name; // varchar(255) not_null
17 public $description; // varchar(255)
18 public $icon; // varchar(255) not_null
19 public $source_url; // varchar(255)
20 public $organization; // varchar(255)
21 public $homepage; // varchar(255)
22 public $callback_url; // varchar(255) not_null
23 public $type; // tinyint(1)
24 public $access_type; // tinyint(1)
25 public $created; // datetime not_null
26 public $modified; // timestamp not_null default_CURRENT_TIMESTAMP
29 function staticGet($k,$v=NULL) {
30 return Memcached_DataObject::staticGet('Oauth_application',$k,$v);
32 /* the code above is auto generated do not remove the tag below */
36 public static $readAccess = 1;
37 public static $writeAccess = 2;
39 public static $browser = 1;
40 public static $desktop = 2;
42 function getConsumer()
44 return Consumer::staticGet('consumer_key', $this->consumer_key);
47 static function maxDesc()
49 // This used to default to textlimit or allow unlimited descriptions,
50 // but this isn't part of a notice and the field's limited to 255 chars
51 // in the DB, so those seem silly.
53 // Now just defaulting to 255 max unless a smaller application desclimit
54 // is actually set. Setting to 0 will use the maximum.
56 $desclimit = intval(common_config('application', 'desclimit'));
57 if ($desclimit > 0 && $desclimit < $max) {
64 static function descriptionTooLong($desc)
66 $desclimit = self::maxDesc();
67 return ($desclimit > 0 && !empty($desc) && (mb_strlen($desc) > $desclimit));
70 function setAccessFlags($read, $write)
73 $this->access_type |= self::$readAccess;
75 $this->access_type &= ~self::$readAccess;
79 $this->access_type |= self::$writeAccess;
81 $this->access_type &= ~self::$writeAccess;
85 function setOriginal($filename)
87 $imagefile = new ImageFile($this->id, Avatar::path($filename));
89 // XXX: Do we want to have a bunch of different size icons? homepage, stream, mini?
90 // or just one and control size via CSS? --Zach
93 $this->icon = Avatar::url($filename);
94 common_debug(common_log_objstring($this));
95 return $this->update($orig);
98 static function getByConsumerKey($key)
104 $app = new Oauth_application();
105 $app->consumer_key = $key;
107 $result = $app->find(true);
109 return empty($result) ? null : $app;
113 * Handle an image upload
115 * Does all the magic for handling an image upload, and crops the
120 function uploadLogo()
122 if ($_FILES['app_icon']['error'] ==
126 $imagefile = ImageFile::fromUpload('app_icon');
127 } catch (Exception $e) {
128 common_debug("damn that sucks");
129 $this->showForm($e->getMessage());
133 $filename = Avatar::filename($this->id,
134 image_type_to_extension($imagefile->type),
136 'oauth-app-icon-'.common_timestamp());
138 $filepath = Avatar::path($filename);
140 move_uploaded_file($imagefile->filepath, $filepath);
142 $this->setOriginal($filename);
148 $this->_deleteAppUsers();
150 $consumer = $this->getConsumer();
156 function _deleteAppUsers()
158 $oauser = new Oauth_application_user();
159 $oauser->application_id = $this->id;