18 require_once SQ_PACKAGES_PATH.
'/web_services/rest/page_templates/page_rest_resource/page_rest_resource.inc';
33 private $_errors = Array();
43 parent::__construct($assetid);
59 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'SQ_REPLACE_MYSOURCE_LEVEL_KEYWORDS', $this->
attr(
'allow_global_replace'));
64 if (isset($_POST[$this->
getPrefix().
'_oauth_reset_session_vars']) || (isset($_SESSION[
'oauth'][$this->
id][
'oauth_token']) && !isset($_SESSION[
'oauth'][$this->
id][
'access_token']))) {
66 unset($_POST[$this->
getPrefix().
'_oauth_reset_session_vars']);
77 if (!empty($this->_res[
'responses'])) {
78 foreach ($this->_res[
'responses'] as &$resp) {
81 if ($resp[
'info'][
'http_code'] >= 400) {
111 $oauth->setKeywordReplacements($this->_extra_replacements);
115 foreach ($available_keywords as $keyword => $val) {
119 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
120 $metadata_fields = $mm->getMetadata($this->
id);
121 foreach($metadata_fields as $schema_fieldid => $field_data) {
122 foreach ($field_data as $item) {
123 $available_keywords[
'asset_metadata_'.$item[
'name']] = $item[
'value'];
127 $oauth->setKeywordReplacements($available_keywords);
134 if (!isset($_GET[
'oauth_token']) && !isset($_GET[
'oauth_verifier'])) {
136 if (!isset($_SESSION[
'oauth'][$this->
id][
'oauth_token'])) {
137 $this->_res = $oauth->getRequestToken();
138 $this->_errors = $oauth->getErrors();
141 if (isset($this->_res[
'request_token'][
'oauth_token']) && isset($this->_res[
'request_token'][
'oauth_token_secret'])) {
143 $_SESSION[
'oauth'][$this->id][
'oauth_token'] = $this->_res[
'request_token'][
'oauth_token'];
144 $_SESSION[
'oauth'][$this->id][
'oauth_token_secret'] = $this->_res[
'request_token'][
'oauth_token_secret'];
146 $redirect_authorise = $this->
attr(
'redirect_authorise');
147 if($redirect_authorise) {
148 $oauth->authorizeRedirect($this->_res[
'request_token']);
151 $this->_res =& $oauth->authorize($this->_res[
'request_token']);
152 $this->_errors = $oauth->getErrors();
160 if (!isset($_SESSION[
'oauth'][$this->
id][
'access_token']) && isset($_SESSION[
'oauth'][$this->
id][
'oauth_token_secret'])) {
161 $this->_res =& $oauth->getAccessToken($_GET[
'oauth_token'], $_GET[
'oauth_verifier'], $_SESSION[
'oauth'][$this->
id][
'oauth_token_secret']);
162 $this->_errors = $oauth->getErrors();
165 if (isset($this->_res[
'access_token'][
'oauth_token']) && isset($this->_res[
'access_token'][
'oauth_token_secret'])) {
166 $_SESSION[
'oauth'][$this->id][
'access_token'] = $this->_res[
'access_token'][
'oauth_token'];
167 $_SESSION[
'oauth'][$this->id][
'access_token_secret'] = $this->_res[
'access_token'][
'oauth_token_secret'];
185 $oauth_session_vars = isset($_SESSION[
'oauth'][$this->
id]) ? $_SESSION[
'oauth'][$this->id] : Array();
186 foreach ($oauth_session_vars as $session_var_name => $session_var_val) {
187 unset($_SESSION[
'oauth'][$this->
id][$session_var_name]);
207 $auth_headers = Array();
208 if (empty($urls))
return Array();
211 foreach ($args as $config_name => $config_value) {
212 $oauth->setConfig($config_name, $config_value);
219 foreach ($urls as $url) {
220 $auth_headers[$url] = $oauth->getUserDataAuthHeader($url, $access_token[
'access_token'], $access_token[
'access_token_secret']);
224 return $auth_headers;
239 $access_token = $this->
attr(
'access_token');
240 $access_token_secret = $this->
attr(
'access_token_secret');
241 if(!empty($access_token) && !empty($access_token_secret))
return TRUE;
243 if (isset($_SESSION[
'oauth'][$this->
id][
'access_token']) && isset($_SESSION[
'oauth'][$this->
id][
'access_token_secret'])) {
259 $access_token = $this->
attr(
'access_token');
260 $access_token_secret = $this->
attr(
'access_token_secret');
261 if(!empty($access_token) && !empty($access_token_secret)) {
262 return (Array(
'access_token' => $access_token,
'access_token_secret' => $access_token_secret));
264 if (isset($_SESSION[
'oauth'][$this->
id][
'access_token']) && isset($_SESSION[
'oauth'][$this->
id][
'access_token_secret'])) {
265 return (Array(
'access_token' => $_SESSION[
'oauth'][$this->
id][
'access_token'],
'access_token_secret' => $_SESSION[
'oauth'][$this->
id][
'access_token_secret']));
282 $res = parent::getAvailableKeywords();
283 $res[
'oauth_reset_session_vars'] = translate(
'oauth_reset_session_vars_keyword');
284 $res[
'oauth_access_token_available'] = translate(
'oauth_access_token_available');
285 $res[
'oauth_errors'] = translate(
'oauth_errors');
301 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
304 <form
id=
"<?php echo $this->getPrefix() ?>_oauth_reset_session_vars_form" method=
"POST" action=
"<?php echo current_url(TRUE, TRUE); ?>">
305 <?php echo submit_button($this->
getPrefix().
'_oauth_reset_session_vars', translate(
'oauth_reset_session_vars')); ?>
308 $replacement = ob_get_contents();
341 return implode(
'<br />', $this->_errors);