Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
form_action_call_rest_resource.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/cms/form/form_action/form_action.inc';
19 require_once SQ_ATTRIBUTES_PATH.'/http_request/http_request.inc';
20 
33 {
34 
39  function __construct()
40  {
41  parent::__construct();
42 
43  }//end constructor
44 
45 
52  public static function paintInlineInterface(Form $form, $settings, Backend_Outputter $o, $prefix)
53  {
54  if (!isset($settings['http_request'])) {
55  $req_settings = serialize(Array());
56  } else {
57  $req_settings = $settings['http_request'];
58  }
59 
60  // Set up HTTP request attribute
61  $http_request = new Asset_Attribute_HTTP_Request(0, $req_settings);
62 
63  $http_request->paint($prefix);
64 
65  }//end paintInlineInterface()
66 
67 
74  public static function processInlineInterface(Form $form, &$settings, Backend_Outputter $o, $prefix)
75  {
76  if (!isset($settings['http_request'])) {
77  $req_settings = serialize(Array());
78  } else {
79  $req_settings = $settings['http_request'];
80  }
81 
82  // Set up HTTP request attribute
83  $http_request = new Asset_Attribute_HTTP_Request(0, $req_settings);
84 
85  $http_request->process($prefix);
86 
87  $settings['http_request'] = $http_request->value;
88 
89  return TRUE;
90 
91  }//end processInlineInterface()
92 
93 
100  public static function paintSummary(Form $form, $settings, Backend_Outputter $o, $prefix)
101  {
102  if (!isset($settings['http_request'])) {
103  $req_settings = Array();
104  } else {
105  $req_settings = unserialize($settings['http_request']);
106  }
107 
108  ?><table class="no-borders">
109  <colgroup>
110  <col width="80" />
111  <col/>
112  </colgroup>
113  <tbody>
114  <tr>
115  <td class="sq-backend-table-cell" style="vertical-align: top"><p><strong><?php echo translate('http_request_method'); ?></strong></p></td>
116  <td class="sq-backend-table-cell" style="vertical-align: top"><p><?php
117 
118  // Get manually-entered "method" settings.
119  if (!empty($req_settings['method'])) {
120  echo $req_settings['method'];
121  } else {
122  ?><span class="sq-backend-warning">No method specified.</span><?php
123  }
124  ?></p></td>
125  </tr>
126  <tr>
127  <td class="sq-backend-table-cell" style="vertical-align: top"><p><strong><?php echo translate('http_request_urls'); ?></strong></p></td>
128  <td class="sq-backend-table-cell" style="vertical-align: top"><p><?php
129  if (!empty($req_settings['urls'])) {
130  foreach ($req_settings['urls'] as $url) {
131  echo ellipsisize($url, 512).'<br />';
132  }
133  } else {
134  ?><span class="sq-backend-warning">No URLs specified.</span><?php
135  }
136  ?></p></td></tr>
137  </tbody>
138  </table>
139  <?php
140 
141  }//end paintSummary()
142 
143 
150  public static function execute(Form $form, $settings)
151  {
152 
153  $req_settings = $settings['http_request'];
154 
155  // Set up http request object
156  $http_request = new Asset_Attribute_HTTP_Request(0, $req_settings);
157 
158  $current_value = @unserialize($http_request->value);
159 
160  // Get list of replacements
161  $keywords_list = Array();
162  if (isset($current_value['urls'])) {
163  $keywords_list = array_merge(
164  $keywords_list,
165  retrieve_keywords_replacements(implode(', ', $current_value['urls']))
166  );
167  }
168 
169  if (isset($current_value['request_headers'])) {
170  $keywords_list = array_merge(
171  $keywords_list,
172  retrieve_keywords_replacements(implode(', ', $current_value['request_headers']))
173  );
174  }
175 
176  if (isset($current_value['request_body'])) {
177  $keywords_list = array_merge(
178  $keywords_list,
179  retrieve_keywords_replacements($current_value['request_body'])
180  );
181  }
182 
183  if (isset($current_value['http_auth_options'])) {
184  $keywords_list = array_merge(
185  $keywords_list,
186  retrieve_keywords_replacements(implode(', ', $current_value['http_auth_options']))
187  );
188  }
189 
190  $keywords_list = array_unique($keywords_list);
191 
192  // ...and find their replacements
193  $replacements = Array();
194  foreach ($keywords_list as $keyword) {
195  $keyword_value = $form->_getThankYouKeywordReplacement($keyword);
196  if (strlen($keyword_value) > 0) {
197  $replacements[$keyword] = $keyword_value;
198  } else {
199  $replacements[$keyword] = $form->getKeywordReplacement($keyword);
200  //Fix #4336
201  if ($replacements[$keyword] == "%$keyword%" && 0 !== strpos($keyword, 'globals_')) {
202  $replacements[$keyword] = '';
203  }
204  }
205  }
206 
207  // set them to the http request object
208  $http_request->setKeywordReplacements($replacements);
209 
210  // send the request
211  $res =& $http_request->run();
212 
213  return TRUE;
214 
215  }//end execute()
216 
217 
224  public static function isValid(Form $form, $settings)
225  {
226  if (!isset($settings['http_request'])) {
227  $req_settings = Array();
228  } else {
229  $req_settings = unserialize($settings['http_request']);
230  }
231 
232  // if either no method or urls are set, won't be able to send the request...
233  if (empty($req_settings['method'])) return FALSE;
234  if (empty($req_settings['urls'])) return FALSE;
235 
236 
237  return TRUE;
238 
239  }//end isValid
240 
241 }//end class
242 
243 ?>