summaryrefslogtreecommitdiff
path: root/plugins/SocialPhoto/SocialPhoto.php
blob: f072ab8140921cdd30dc3c0fa45e5ac5a3fab2c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

if (!defined('STATUSNET')) {
    exit(1);
}

require_once INSTALLDIR . '/plugins/SocialObject/SocialObject.php';

class SocialPhoto extends SocialObject
{
    public $__table = 'social_photo';
    public $id;
    public $url;
    public $title;
    public $description;

    var $slug = 'photo';
    static function saveNew($notice, $action)
    {
        $photo = new SocialPhoto();
        $photo->id = $notice->id;   # very essential
        $photo->title = $action->trimmed('photo-title');
        $att = $notice->attachments();
        if(empty($att)) {
            # no attachment uploaded?
            $action->clientError(_('No photo was uploaded'));
            $photo->delete();
        }
        $att = $att[0]; # just use the 1st one :P
        $photo->url = $att->url;
        # TODO: Size the photo up/down and
        # save copies of different sizes
        $photo->insert();
    }

    static function schemaDef()
    {
        return array(new ColumnDef('id', 'int',
                                   /*size*/null,
                                   /*nullable*/false,
                                   /*key*/'PRI'),
                     new ColumnDef('title', 'varchar',
                                   /*size*/255,
                                   /*nullable*/false),
                     new ColumnDef('url', 'varchar',
                                   255, false),
                     new ColumnDef('description', 'text',
                                   null, true));
    }
}