/** * Verifies the authenticity of the provider * * @return boolean True if verified, xml if failed */ public function verify() { $response = $this->request('verify', 'GET'); if ($response->isError()) { $message = $response->getError(); if ($this->xpdo->lexicon && $this->xpdo->lexicon->exists('provider_err_' . $message)) { $message = $this->xpdo->lexicon('provider_err_' . $message); } return $message; } $status = $response->toXml(); return (bool) $status->verified; }
/** * Prepare the comment for rendering * * @param array $properties * @param int $idx * @return array */ public function prepare(array $properties = array(), $idx) { $alt = $idx % 2; $commentArray = $this->toArray(); $commentArray['children'] = ''; $commentArray['alt'] = $alt ? $this->getOption('altRowCss', $properties) : ''; $commentArray['createdon'] = strftime($this->getOption('dateFormat', $properties), strtotime($this->get('createdon'))); $commentArray['url'] = $this->makeUrl(); $commentArray['idx'] = $idx; $commentArray['threaded'] = $this->getOption('threaded', $properties, true); $commentArray['depth'] = $this->get('depth'); $commentArray['depth_margin'] = $this->getOption('useMargins', $properties, false) ? (int) ($this->getOption('threadedPostMargin', $properties, '15') * $this->get('depth')) + 7 : ''; $commentArray['cls'] = $this->getOption('rowCss', $properties, '') . ($this->get('approved') ? '' : ' ' . $this->getOption('unapprovedCls', $properties, 'quip-unapproved')); $commentArray['olCls'] = $this->getOption('olCss', $properties, ''); if ($this->getOption('useGravatar', $properties, true)) { $commentArray['md5email'] = md5($this->get('email')); $commentArray['gravatarIcon'] = $this->getOption('gravatarIcon', $properties, 'mm'); $commentArray['gravatarSize'] = $this->getOption('gravatarSize', $properties, 60); $urlsep = $this->xpdo->context->getOption('xhtml_urls', true) ? '&' : '&'; $commentArray['gravatarUrl'] = $this->getOption('gravatarUrl', $properties) . $commentArray['md5email'] . '?s=' . $commentArray['gravatarSize'] . $urlsep . 'd=' . $commentArray['gravatarIcon']; } else { $commentArray['gravatarUrl'] = ''; } /* check for auth */ if ($this->hasAuth) { /* allow removing of comment if moderator or own comment */ $commentArray['allowRemove'] = $this->getOption('allowRemove', $properties, true); if ($commentArray['allowRemove']) { if ($this->isModerator) { /* Always allow remove for moderators */ $commentArray['allowRemove'] = true; } else { if ($this->get('author') == $this->xpdo->user->get('id')) { /* if not moderator but author of post, check for remove * threshold, which prevents removing comments after X minutes */ $removeThreshold = $this->getOption('removeThreshold', $properties, 3); if (!empty($removeThreshold)) { $diff = time() - strtotime($this->get('createdon')); if ($diff > $removeThreshold * 60) { $commentArray['allowRemove'] = false; } } } } } $commentArray['reported'] = !empty($_GET['reported']) && $_GET['reported'] == $this->get('id') ? 1 : ''; if ($this->get('author') == $this->xpdo->user->get('id') || $this->isModerator) { $params = $this->xpdo->request->getParameters(); $params['quip_comment'] = $this->get('id'); $params[$this->getOption('removeAction', $properties, 'quip-remove')] = true; $commentArray['removeUrl'] = $this->makeUrl('', $params, null, false); $commentArray['options'] = $this->xpdo->quip->getChunk($this->getOption('tplCommentOptions', $properties), $commentArray); } else { $commentArray['options'] = ''; } if ($this->getOption('allowReportAsSpam', $properties, true)) { $params = $this->xpdo->request->getParameters(); $params['quip_comment'] = $this->get('id'); $params[$this->getOption('reportAction', $properties, 'quip-report')] = true; $commentArray['reportUrl'] = $this->makeUrl('', $params, null, false); $commentArray['report'] = $this->xpdo->quip->getChunk($this->getOption('tplReport', $properties), $commentArray); } } else { $commentArray['report'] = ''; } /* get author display name */ $authorTpl = $this->getOption('authorTpl', $properties, 'quipAuthorTpl'); $nameField = $this->getOption('nameField', $properties, 'username'); $commentArray['authorName'] = ''; if (empty($commentArray[$nameField])) { $commentArray['authorName'] = $this->xpdo->quip->getChunk($authorTpl, array('name' => $this->getOption('showAnonymousName', false) ? $this->getOption('anonymousName', $this->xpdo->lexicon('quip.anonymous')) : $commentArray['name'], 'url' => '')); } else { $commentArray['authorName'] = $this->xpdo->quip->getChunk($authorTpl, array('name' => $commentArray[$nameField], 'url' => '')); } if ($this->getOption('showWebsite', $properties, true) && !empty($commentArray['website'])) { $commentArray['authorName'] = $this->xpdo->quip->getChunk($authorTpl, array('name' => $commentArray[$nameField], 'url' => $commentArray['website'])); } if ($this->getOption('threaded', $properties, true) && $this->getOption('stillOpen', $properties, true) && $this->get('depth') < $this->getOption('maxDepth', $properties, 10) && $this->get('approved') && !$this->getOption('closed', $properties, false)) { if (!$this->getOption('requireAuth', $properties, false) || $this->hasAuth) { $params = $this->xpdo->request->getParameters(); $params['quip_thread'] = $this->get('thread'); $params['quip_parent'] = $this->get('id'); $commentArray['replyUrl'] = $this->xpdo->makeUrl($this->getOption('replyResourceId', $properties, 1), '', $params); } } else { $commentArray['replyUrl'] = ''; } return $commentArray; }
/** * Translate any needed properties * @param array $properties * @return array */ public function prepareProperties(array $properties = array()) { foreach ($properties as &$property) { if (!empty($property['lexicon'])) { $this->xpdo->lexicon->load($property['lexicon']); } if (!empty($property['name'])) { $property['name_trans'] = $this->xpdo->lexicon($property['name']); } if (!empty($property['desc'])) { $property['desc_trans'] = $this->xpdo->lexicon($property['desc']); } if (!empty($property['options'])) { foreach ($property['options'] as &$option) { if (empty($option['text']) && !empty($option['name'])) { $option['text'] = $option['name']; unset($option['name']); } if (empty($option['value']) && !empty($option[0])) { $option['value'] = $option[0]; unset($option[0]); } $option['name'] = $this->xpdo->lexicon($option['text']); } } } return $properties; }
/** * Transfers the package from one directory to another. * * @access public * @param string $sourceFile The file to transfer. * @param string $targetDir The directory to transfer into. * @return boolean True if successful. */ public function transferPackage($sourceFile, $targetDir) { $transferred = false; $content = ''; if (is_dir($targetDir) && is_writable($targetDir)) { if (!is_array($this->xpdo->version)) { $this->xpdo->getVersionData(); } $productVersion = $this->xpdo->version['code_name'] . '-' . $this->xpdo->version['full_version']; $source = $this->get('service_url') . $sourceFile . (strpos($sourceFile, '?') !== false ? '&' : '?') . 'revolution_version=' . $productVersion; /* see if user has allow_url_fopen on and is not behind a proxy */ $proxyHost = $this->xpdo->getOption('proxy_host', null, ''); if (ini_get('allow_url_fopen') && empty($proxyHost)) { if ($handle = @fopen($source, 'rb')) { $filesize = @filesize($source); $memory_limit = @ini_get('memory_limit'); if (!$memory_limit) { $memory_limit = '8M'; } $byte_limit = $this->_bytes($memory_limit) * 0.5; if (strpos($source, '://') !== false || $filesize > $byte_limit) { $content = @file_get_contents($source); } else { $content = @fread($handle, $filesize); } @fclose($handle); } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $this->xpdo->lexicon('package_err_file_read', array('source' => $source))); } /* if not, try curl */ } else { if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $source); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 180); $safeMode = @ini_get('safe_mode'); $openBasedir = @ini_get('open_basedir'); if (empty($safeMode) && empty($openBasedir)) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); } $proxyHost = $this->xpdo->getOption('proxy_host', null, ''); if (!empty($proxyHost)) { $proxyPort = $this->xpdo->getOption('proxy_port', null, ''); curl_setopt($ch, CURLOPT_PROXY, $proxyHost); curl_setopt($ch, CURLOPT_PROXYPORT, $proxyPort); $proxyUsername = $this->xpdo->getOption('proxy_username', null, ''); if (!empty($proxyUsername)) { $proxyAuth = $this->xpdo->getOption('proxy_auth_type', null, 'BASIC'); $proxyAuth = $proxyAuth == 'NTLM' ? CURLAUTH_NTLM : CURLAUTH_BASIC; curl_setopt($ch, CURLOPT_PROXYAUTH, $proxyAuth); $proxyPassword = $this->xpdo->getOption('proxy_password', null, ''); $up = $proxyUsername . (!empty($proxyPassword) ? ':' . $proxyPassword : ''); curl_setopt($ch, CURLOPT_PROXYUSERPWD, $up); } } $content = curl_exec($ch); curl_close($ch); /* and as last-ditch resort, try fsockopen */ } else { $content = $this->_getByFsockopen($source); } } if ($content) { if ($cacheManager = $this->xpdo->getCacheManager()) { $filename = $this->signature . '.transport.zip'; $target = $targetDir . $filename; $transferred = $cacheManager->writeFile($target, $content); } } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'MODX could not download the file. You must enable allow_url_fopen, cURL or fsockopen to use remote transport packaging.'); } } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $this->xpdo->lexicon('package_err_target_write', array('targetDir' => $targetDir))); } return $transferred; }
/** * Translate any needed properties * @param array $properties * @return array */ protected function prepareProperties(array $properties = array()) { foreach ($properties as &$property) { if (!empty($property['lexicon'])) { $this->xpdo->lexicon->load($property['lexicon']); } if (!empty($property['name'])) { $property['name_trans'] = $this->xpdo->lexicon($property['name']); } if (!empty($property['desc'])) { $property['desc_trans'] = $this->xpdo->lexicon($property['desc']); } } return $properties; }