-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPicturePost.php
More file actions
279 lines (126 loc) · 4.17 KB
/
PicturePost.php
File metadata and controls
279 lines (126 loc) · 4.17 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
class WPicturePost extends UFormWorklet
{
public $modelClassName = 'MPictureForm';
public $post;
public function accessRules()
{
return array(
array('deny', 'users'=>array('?'))
);
}
public function afterModel()
{
if($this->isPopup())
{
if(isset($_GET['image']))
$this->model->imageUrl = $_GET['image'];
if(isset($_GET['source']))
$this->model->source = $_GET['source'];
app()->controller->layout = 'popup';
}
}
public function taskIsPopup()
{
return app()->controller->routeEased == 'picture/post' && (!isset($_POST['isPopup']) || $_POST['isPopup']);
}
public function properties()
{
return array(
'action' => url('/picture/post'),
'elements' => array(
CHtml::hiddenField('isPopup', $this->isPopup()),
'parentId' => array('type' => 'hidden'),
'imageUrl' => array('type' => 'hidden'),
'source' => array('type' => 'hidden'),
'boardId' => array('type' => 'dropdownlist', 'items' => wm()->get('picture.helper')->boards()),
'message' => array('type' => 'textarea', 'layout' => "<div class=\"clearfix\">{label}</div>{input}\n{hint}"),
),
'buttons' => array(
'submit' => array('type' => 'submit',
'label' => $this->t('{#post_v_ucf} It'))
),
'model' => $this->model
);
}
public function beforeRenderOutput()
{
cs()->registerScriptFile(asma()->publish($this->module->basePath.DS.'js'.DS.'simpleSlide'.DS.'jquery.simpleSlide.js'));
}
public function taskSettings()
{
return array(
'noImagesFound' => str_replace('"','\"',$this->t('Unfortunately we were not able to find any big images.')),
'minWidth' => $this->param('minWidth'),
);
}
public function afterRenderOutput()
{
$settings = CJavaScript::encode($this->settings());
cs()->registerScript(__CLASS__,'$.uniprogy.picture.post.init('.$settings.');');
if($this->isPopup())
{
$images = CJavaScript::jsonEncode(array($this->model->imageUrl));
cs()->registerScript('$.uniprogy.picture.post.load',
'$.uniprogy.picture.post.load('. $images.',"'.CJavaScript::quote($this->model->source).'")');
}
}
public function taskSave()
{
$helper = wm()->get('picture.helper');
$channel = '';
$picture = null;
if($this->model->parentId)
{
$parent = MPicturePost::model()->findByPk($this->model->parentId);
$this->post = $helper->repost($parent, $this->model->boardId, $this->model->message);
wm()->get('picture.event')->repost($parent->id,$this->post->id);
wm()->get('picture.helper')->updateStats($this->model->parentId, 'reposts');
$this->successUrl = url('/picture/view', array('id' => $this->post->id));
return true;
}
elseif(is_numeric($this->model->source))
{
$bin = app()->storage->bin($this->model->source);
if($bin)
{
$picture = $helper->savePicture($bin->getFilePath('original'), $bin);
$channel = 'upload';
$this->model->source = null;
}
}
elseif($this->model->imageUrl)
{
$file = $helper->saveInStorage($this->model->imageUrl);
if($file)
{
$picture = $helper->savePicture($file);
$channel = 'web';
}
}
if($picture)
{
$this->post = $helper->post($picture->id, $this->model->boardId, $this->model->message, $channel, $this->model->source);
wm()->get('picture.event')->post($this->post->id);
$this->successUrl = url('/picture/view', array('id' => $this->post->id));
return true;
}
$this->model->addError('boardId', $this->t('Unknown error occured. Please try again later.'));
}
public function ajaxSuccess()
{
if($this->isPopup())
{
$content = $this->render('thankYou',array(),true);
wm()->get('base.init')->addToJson(array(
'content' => array('replace' =>
$content
.CHtml::script('jQuery("#closeButton").click(function(){window.close();});')
.CHtml::script('jQuery("#viewButton").click(function(){window.open("'.aUrl('/picture/view', array('id' => $this->post->id)).'");});')
),
));
}
else
parent::ajaxSuccess();
}
}