-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.driver.php
192 lines (163 loc) · 4.97 KB
/
extension.driver.php
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
Class Extension_Highrise extends Extension {
private $url;
private $token;
private $save;
public function __construct(Array $args) {
parent::__construct($args);
$config = Symphony::Configuration();
$this->url = $config->get('url','highrise');
$this->token = $config->get('token','highrise');
$this->save = $config->get('save','highrise');
}
public function about() {
return array(
'name' => 'Highrise',
'version' => '0.1a',
'release-date' => '2011-04-20',
'author' => array(
'name' => 'Willy',
'website' => 'http://1009design.com/',
'email' => '[email protected]'
),
'description' => 'push'
);
}
public function getSubscribedDelegates() {
return array(
//註冊欄位到prefrence
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPreferences'
),
//儲存prefrence時的動作
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => '__SavePreferences'
),
//
array(
'page' => '/frontend/',
'delegate' => 'EventPreSaveFilter',
'callback' => 'eventPreSaveFilter'
),
array(
'page' => '/frontend/',
'delegate' => 'EventPostSaveFilter',
'callback' => 'eventPostSaveFilter'
),
array(
'page' => '/blueprints/events/new/',
'delegate' => 'AppendEventFilter',
'callback' => 'appendEventFilter'
),
array(
'page' => '/blueprints/events/edit/',
'delegate' => 'AppendEventFilter',
'callback' => 'appendEventFilter'
)
);
}
/**
* Append highrise mode preferences
*
* @param array $context
* delegate context
*/
public function appendPreferences($context) {
// Create preference group
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', __('Highrise')));
$config = Symphony::Configuration();
// Append settings
$text = $config->get('save-entry','highrise');
$saveInput = Widget::Input('settings[highrise][save-entry]', 'yes', 'checkbox');
if(empty($text) || $text == 'yes') {
$saveInput->setAttribute('checked', 'checked');
}
$saveLabel = Widget::Label($saveInput->generate() . ' ' . __('Continue save data'));
$saveHelp = new XMLElement('p', __('api token can be found under My Info'), array('class' => 'help'));
$text = $config->get('url','highrise');
$urlInput = Widget::Input('settings[highrise][url]', empty($text)?'':$text, 'text');
$urlLabel = Widget::Label('URL:',$urlInput);
$urlHelp = new XMLElement('p', __('Check the box to continue saving process otherwise stops after eventPreSaveFilter called.'), array('class' => 'help'));
$text = $config->get('token','highrise');
$tokenInput = Widget::Input('settings[highrise][token]', empty($text)?'':$text, 'text');
$tokenLabel = Widget::Label('Token:',$tokenInput);
$tokenHelp = new XMLElement('p', __('e.g. http://yourcompany.highrisehq.com'), array('class' => 'help'));
$group->appendChild($saveLabel);
$group->appendChild($saveHelp);
$group->appendChild($urlLabel);
$group->appendChild($urlHelp);
$group->appendChild($tokenLabel);
$group->appendChild($tokenHelp);
// Append new preference group
$context['wrapper']->appendChild($group);
}
/**
* Save preferences
*
* @param array $context
* delegate context
*/
public function __SavePreferences($context) {
if(!is_array($context['settings'])) {
$context['settings'] = array('highrise' => array('url' => '', 'token' => '', 'save-entry'=>'no'));
} elseif(!isset($context['settings']['highrise']['save-entry'])) {
$context['settings']['highrise']['save-entry'] = 'no';
}
}
public function eventPreSaveFilter($context) {
if($this->save == 'no') {
$this->_save($context);
$context['messages'][] = array(
'Highrise', FALSE, __('prevents from saving to section')
);
}
}
public function eventPostSaveFilter($context) {
//
// check saving result
// $success = $this->_checkSave()
//
$success = true;
if($success) {
$this->_save($context);
}
}
private function _save($context) {
include EXTENSIONS . '/highrise/lib/push2Highrise.php';
if( !isset($_POST['type']) ) {
$_POST['type'] = '';
}
$p = new Push_Highrise($this->url,$this->token);
switch($_POST['type']) {
case 'pushDeal':
$p->pushDeal($_POST);
break;
case 'pushNote':
$p->pushNote($_POST);
break;
case 'pushTask':
$p->pushTask($_POST);
break;
case 'pushContact':
$p->pushContact($_POST);
break;
default:
//do nothing
break;
}
return false;
}
public function appendEventFilter($context) {
$context['options'][] = array(
'highrise-create-user',
@in_array('highrise-create-user', $context['selected']),
'Highrise: Create User '
);
}
}