3 * Table Definition for oauth_application
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Oauth_application extends Managed_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(191) not_null not 255 because utf8mb4 takes more space
16 public $name; // varchar(191) not_null not 255 because utf8mb4 takes more space
17 public $description; // varchar(191) not 255 because utf8mb4 takes more space
18 public $icon; // varchar(191) not_null not 255 because utf8mb4 takes more space
19 public $source_url; // varchar(191) not 255 because utf8mb4 takes more space
20 public $organization; // varchar(191) not 255 because utf8mb4 takes more space
21 public $homepage; // varchar(191) not 255 because utf8mb4 takes more space
22 public $callback_url; // varchar(191) not_null not 255 because utf8mb4 takes more space
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
28 /* the code above is auto generated do not remove the tag below */
32 public static $readAccess = 1;
33 public static $writeAccess = 2;
35 public static $browser = 1;
36 public static $desktop = 2;
38 function getConsumer()
40 return Consumer::getKV('consumer_key', $this->consumer_key);
43 static function maxDesc()
45 // This used to default to textlimit or allow unlimited descriptions,
46 // but this isn't part of a notice and the field's limited to 191 chars
47 // in the DB, so those seem silly. (utf8mb4 takes up more space, so can't use 255)
49 // Now just defaulting to 191 max unless a smaller application desclimit
50 // is actually set. Setting to 0 will use the maximum.
52 $desclimit = intval(common_config('application', 'desclimit'));
53 if ($desclimit > 0 && $desclimit < $max) {
60 static function descriptionTooLong($desc)
62 $desclimit = self::maxDesc();
63 return ($desclimit > 0 && !empty($desc) && (mb_strlen($desc) > $desclimit));
66 function setAccessFlags($read, $write)
69 $this->access_type |= self::$readAccess;
71 $this->access_type &= ~self::$readAccess;
75 $this->access_type |= self::$writeAccess;
77 $this->access_type &= ~self::$writeAccess;
81 function setOriginal($filename)
83 $imagefile = new ImageFile(null, Avatar::path($filename));
85 // XXX: Do we want to have a bunch of different size icons? homepage, stream, mini?
86 // or just one and control size via CSS? --Zach
89 $this->icon = Avatar::url($filename);
90 common_debug(common_log_objstring($this));
91 return $this->update($orig);
94 static function getByConsumerKey($key)
100 $app = new Oauth_application();
101 $app->consumer_key = $key;
103 $result = $app->find(true);
105 return empty($result) ? null : $app;
109 * Handle an image upload
111 * Does all the magic for handling an image upload, and crops the
116 function uploadLogo()
118 if ($_FILES['app_icon']['error'] ==
122 $imagefile = ImageFile::fromUpload('app_icon');
123 } catch (Exception $e) {
124 common_debug("damn that sucks");
125 $this->showForm($e->getMessage());
129 $filename = Avatar::filename($this->id,
130 image_type_to_extension($imagefile->type),
132 'oauth-app-icon-'.common_timestamp());
134 $filepath = Avatar::path($filename);
136 move_uploaded_file($imagefile->filepath, $filepath);
138 $this->setOriginal($filename);
142 function delete($useWhere=false)
144 $this->_deleteAppUsers();
146 $consumer = $this->getConsumer();
149 return parent::delete($useWhere);
152 function _deleteAppUsers()
154 $oauser = new Oauth_application_user();
155 $oauser->application_id = $this->id;
159 public static function schemaDef()
162 'description' => 'OAuth application registration record',
164 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
165 'owner' => array('type' => 'int', 'not null' => true, 'description' => 'owner of the application'),
166 'consumer_key' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'application consumer key'),
167 'name' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'name of the application'),
168 'description' => array('type' => 'varchar', 'length' => 191, 'description' => 'description of the application'),
169 'icon' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'default' => '/theme/base/default-avatar-stream.png', 'description' => 'application icon'),
170 'source_url' => array('type' => 'varchar', 'length' => 191, 'description' => 'application homepage - used for source link'),
171 'organization' => array('type' => 'varchar', 'length' => 191, 'description' => 'name of the organization running the application'),
172 'homepage' => array('type' => 'varchar', 'length' => 191, 'description' => 'homepage for the organization'),
173 'callback_url' => array('type' => 'varchar', 'length' => 191, 'description' => 'url to redirect to after authentication'),
174 'type' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'type of app, 1 = browser, 2 = desktop'),
175 'access_type' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'default access type, bit 1 = read, bit 2 = write'),
176 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
177 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
179 'primary key' => array('id'),
180 'unique keys' => array(
181 'oauth_application_name_key' => array('name'), // in the long run, we should perhaps not force these unique, and use another source id
183 'foreign keys' => array(
184 'oauth_application_owner_fkey' => array('profile', array('owner' => 'id')), // Are remote users allowed to create oauth application records?
185 'oauth_application_consumer_key_fkey' => array('consumer', array('consumer_key' => 'consumer_key')),