1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace X3dgoo\InstagramScraper\Model; |
4
|
|
|
|
5
|
|
|
use SilverStripe\ORM\DataObject; |
6
|
|
|
use SilverStripe\Forms\LiteralField; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @property bool $Show |
10
|
|
|
* @property string $InstagramID |
11
|
|
|
* @property string $ShortCode |
12
|
|
|
* @property string $Handle |
13
|
|
|
* @property string $Caption |
14
|
|
|
* @property string $Link |
15
|
|
|
* @property string $Type |
16
|
|
|
* @property string $ImageLowResolutionUrl |
17
|
|
|
* @property string $ImageStandardResolutionUrl |
18
|
|
|
* @property string $ImageHighResolutionUrl |
19
|
|
|
* @property string $ImageThumbnailURL |
20
|
|
|
* @property mixed $Posted |
21
|
|
|
* @property int $LikesCount |
22
|
|
|
* @property int $CommentsCount |
23
|
|
|
*/ |
24
|
|
|
class InstagramPost extends DataObject |
25
|
|
|
{ |
26
|
|
|
private static $db = [ |
|
|
|
|
27
|
|
|
'Show' => 'Boolean', |
28
|
|
|
'InstagramID' => 'Varchar(100)', |
29
|
|
|
'ShortCode' => 'Varchar(100)', |
30
|
|
|
'Handle' => 'Varchar(100)', |
31
|
|
|
'Caption' => 'Text', |
32
|
|
|
'Link' => 'Text', |
33
|
|
|
'Type' => 'Varchar(100)', |
34
|
|
|
'ImageLowResolutionUrl' => 'Text', |
35
|
|
|
'ImageStandardResolutionUrl' => 'Text', |
36
|
|
|
'ImageHighResolutionUrl' => 'Text', |
37
|
|
|
'ImageThumbnailURL' => 'Text', |
38
|
|
|
'Posted' => 'Datetime', |
39
|
|
|
'LikesCount' => 'Int', |
40
|
|
|
'CommentsCount' => 'Int', |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
private static $defaults = [ |
|
|
|
|
44
|
|
|
'Show' => true, |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
private static $singular_name = 'Instagram Post'; |
|
|
|
|
48
|
|
|
private static $plural_name = 'Instagram Posts'; |
|
|
|
|
49
|
|
|
private static $default_sort = 'Posted DESC'; |
|
|
|
|
50
|
|
|
private static $table_name = 'InstagramPost'; |
|
|
|
|
51
|
|
|
|
52
|
|
|
private static $summary_fields = [ |
|
|
|
|
53
|
|
|
'ImageThumbnailURL', |
54
|
|
|
'Handle', |
55
|
|
|
'Caption.Summary', |
56
|
|
|
'Posted', |
57
|
|
|
'Show.Nice', |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
private static $field_labels = [ |
|
|
|
|
61
|
|
|
'ImageThumbnailURL' => 'Image', |
62
|
|
|
'Caption.Summary' => 'Caption', |
63
|
|
|
'Show.Nice' => 'Show', |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
public function getCMSFields() |
67
|
|
|
{ |
68
|
|
|
$fields = parent::getCMSFields(); |
69
|
|
|
|
70
|
|
|
if ($this->ImageThumbnailURL) { |
71
|
|
|
$fields->addFieldToTab( |
72
|
|
|
'Root.Main', |
73
|
|
|
LiteralField::create( |
74
|
|
|
'ImagePreview', |
75
|
|
|
'<div class="form-group field text">' . |
76
|
|
|
'<label class="form__field-label">Image</label>' . |
77
|
|
|
'<div class="form__field-holder">' . |
78
|
|
|
'<img src="' . $this->ImageThumbnailURL . '" style="max-width: 200px;" />' . |
79
|
|
|
'</div>' . |
80
|
|
|
'</div>' |
81
|
|
|
), |
82
|
|
|
'Show' |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $fields; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|