* @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @package Zend_OpenId */ namespace ZendOpenIdTest; use Zend\Http\Response; use ZendOpenId\OpenId; /** * Zend_OpenId */ /** * @todo code should be moved into test class */ OpenId::$exitOnRedirect = false; /** * @category Zend * @package Zend_OpenId * @subpackage UnitTests */ class ResponseHelper extends Response { private $_canSendHeaders; public function __construct($canSendHeaders) { $this->_canSendHeaders = $canSendHeaders; } public function canSendHeaders($throw = false) { return $this->_canSendHeaders;
if (isset($_REQUEST["filegalfixvndmsfiles"])) { $filegallib->fix_vnd_ms_files(); } if ($prefs['fgal_viewerjs_feature'] === 'y') { $viewerjs_err = ''; if (empty($prefs['fgal_viewerjs_uri'])) { $viewerjs_err = tra('ViewerJS URI not set'); } else { if (strpos($prefs['fgal_viewerjs_uri'], '://') === false) { // local install if (!is_readable($prefs['fgal_viewerjs_uri'])) { $viewerjs_err = tr('ViewerJS URI not found (local file not readable)'); } } else { // remote (will take a while) $file_headers = get_headers(\ZendOpenId\OpenId::absoluteUrl($prefs['fgal_viewerjs_uri'])); if (strpos($file_headers[0], '200') === false) { $viewerjs_err = tr('ViewerJS URI not found (%0)', $file_headers[0]); } } } $smarty->assign('viewerjs_err', $viewerjs_err); } if (!empty($prefs['fgal_sort_mode']) && preg_match('/(.*)_(asc|desc)/', $prefs['fgal_sort_mode'], $matches)) { $smarty->assign('fgal_sortorder', $matches[1]); $smarty->assign('fgal_sortdirection', $matches[2]); } else { $smarty->assign('fgal_sortorder', 'created'); $smarty->assign('fgal_sortdirection', 'desc'); } $options_sortorder = array(tra('Creation Date') => 'created', tra('Name') => 'name', tra('Last modification date') => 'lastModif', tra('Hits') => 'hits', tra('Owner') => 'user', tra('Description') => 'description', tra('ID') => 'id');
function wikiplugin_mediaplayer($data, $params) { global $prefs; $access = TikiLib::lib('access'); static $iMEDIAPLAYER = 0; $id = 'mediaplayer' . ++$iMEDIAPLAYER; if (empty($params['mp3']) && empty($params['flv']) && empty($params['src'])) { return ''; } if (!empty($params['src']) && $params['style'] != 'native') { $access->check_feature('feature_jquery_media'); } $defaults_mp3 = array('width' => 200, 'height' => 20, 'player' => 'player_mp3.swf', 'where' => 'vendor/player/mp3/template_default/'); $defaults_flv = array('width' => 320, 'height' => 240, 'player' => 'player_flv.swf', 'where' => 'vendor/player/flv/template_default/'); $defaults_html5 = array('width' => '', 'height' => ''); $defaults = array('width' => 320, 'height' => 240); if (!empty($params['flv'])) { $params = array_merge($defaults_flv, $params); } elseif (!empty($params['mp3'])) { $params = array_merge($defaults_mp3, $params); } elseif (!empty($params['style']) && $params['style'] == 'native') { $params = array_merge($defaults_html5, $params); } else { $params = array_merge($defaults, $params); } if (!empty($params['src']) && (empty($params['style']) || $params['style'] != 'native')) { $headerlib = TikiLib::lib('header'); $js = "\n var media_{$id} = \$('#{$id}').media( {"; foreach ($params as $param => $value) { if ($param == 'src') { continue; } if (is_numeric($value) == false && strtolower($value) != 'true' && strtolower($value) != 'false') { $value = "\"" . $value . "\""; } $js .= "{$param}: {$value},"; } // Force scaling (keeping the aspect ratio) of the QuickTime player // Tried with .mp4. Not sure how this will work with other formats, not using QuickTime. // See: http://jquery.malsup.com/media/#players for default players for different formats. arildb $js .= " params: { \n\t\t\t\tscale: 'aspect'\n\t\t\t\t} \n\t\t\t} );"; // check for support for PDF if ($params['type'] === 'pdf') { if ($prefs['fgal_viewerjs_feature'] === 'y') { $src = \ZendOpenId\OpenId::absoluteUrl($params['src']); $src = $prefs['fgal_viewerjs_uri'] . '#' . $src; $out = "<iframe width=\"{$params['width']}\" height=\"{$params['height']}\" src=\"{$src}\"></iframe>"; return $out; } else { $js = ' var found = false; $.each(navigator.plugins, function(i, plugins) { $.each(plugins, function(i, plugin) { if (plugin.type === "application/pdf") { found = true; return; } }); }); if (!found) { // IE doesnt bother using the plugins array (sometimes?), plus ActiveXObject is hidden now so just try and catch... :( try { var oAcro7 = new ActiveXObject("AcroPDF.PDF.1"); if (oAcro7) { found = true; } } catch (e) { } } if (found) { ' . $js . ' } else { // no pdf plugin $("#' . $id . '").text(tr("Download file:") + " " + "' . $params['src'] . '"); }'; } } $headerlib->add_jq_onready($js); return "<a href=\"" . $params['src'] . "\" id=\"{$id}\"></a>"; } // Check the style of the player $styles = array('normal', 'mini', 'maxi', 'multi', 'native'); if (empty($params['style']) || $params['style'] == 'normal' || !in_array($params['style'], $styles)) { $player = $params['player']; } elseif ($params['style'] == 'native') { $player = ''; } else { $params['where'] = str_replace('_default', '_' . $params['style'], $params['where']); $player = str_replace('.swf', '_' . $params['style'] . '.swf', $params['player']); } // check if native native HTML5 video object is requested if ($params['style'] == 'native') { if ($params['mediatype'] == 'audio') { $mediatype = 'audio'; } else { $mediatype = 'video'; } $code = '<' . $mediatype; if (!empty($params['height'])) { $code .= ' height="' . $params['height'] . '"'; } if (!empty($params['width'])) { $code .= ' width="' . $params['width'] . '"'; } $code .= ' style="max-width: 100%" controls>'; $code .= ' <source src="' . $params['src'] . '" type=\'' . $params['type'] . '\'>'; // type can be e.g. 'video/webm; codecs="vp8, vorbis"' $code .= '</' . $mediatype . '>'; } else { // else use flash $code = '<object type="application/x-shockwave-flash" data="' . $params['where'] . $player . '" width="' . $params['width'] . '" height="' . $params['height'] . '">'; $code .= '<param name="movie" value="' . $params['where'] . $player . '" />'; if (!empty($params['fullscreen'])) { $code .= '<param name="allowFullscreen" value="' . $params['fullscreen'] . '" />'; } if (empty($params['wmode'])) { $wmode = 'transparent'; } else { $wmode = $params['wmode']; } $code .= '<param name="wmode" value="' . $wmode . '" />'; $code .= '<param name="FlashVars" value="'; if (empty($params['flv']) && !empty($params['mp3'])) { $code .= 'mp3=' . $params['mp3']; } // Disabled due to MSIE issue still experienced with version 9: http://flv-player.net/help/#faq2 //unset($params['width']); unset($params['height']); unset($params['where']); unset($params['player']); unset($params['mp3']); unset($params['style']); unset($params['fullscreen']); unset($params['wmode']); foreach ($params as $key => $value) { $code .= '&' . $key . '=' . $value; } $code .= '" />'; $code .= '</object>'; } // end of else use flash return "~np~{$code}~/np~"; }
/** * Performs authentication validation for dumb consumers * Returns array of variables to push back to consumer. * It MUST contain 'is_valid' variable with value 'true' or 'false'. * * @param float $version OpenID version * @param array $params GET or POST request variables * @return array */ protected function _checkAuthentication($version, $params) { $ret = array(); if ($version >= 2.0) { $ret['ns'] = OpenId::NS_2_0; } $ret['openid.mode'] = 'id_res'; if (empty($params['openid_assoc_handle']) || empty($params['openid_signed']) || empty($params['openid_sig']) || !$this->_storage->getAssociation($params['openid_assoc_handle'], $macFunc, $secret, $expires)) { $ret['is_valid'] = 'false'; return $ret; } $signed = explode(',', $params['openid_signed']); $data = ''; foreach ($signed as $key) { $data .= $key . ':'; if ($key == 'mode') { $data .= "id_res\n"; } else { $data .= $params['openid_' . strtr($key, '.', '_')] . "\n"; } } if ($this->_secureStringCompare(base64_decode($params['openid_sig']), OpenId::hashHmac($macFunc, $data, $secret))) { $ret['is_valid'] = 'true'; } else { $ret['is_valid'] = 'false'; } return $ret; }
/** * Performs check of OpenID identity. * * This is the first step of OpenID authentication process. * On success the function does not return (it does HTTP redirection to * server and exits). On failure it returns false. * * @param bool $immediate enables or disables interaction with user * @param string $id OpenID identity * @param string $returnTo HTTP URL to redirect response from server to * @param string $root HTTP URL to identify consumer on server * @param mixed $extensions extension object or array of extensions objects * @param Response $response an optional response object to perform HTTP or HTML form redirection * @return bool */ protected function _checkId($immediate, $id, $returnTo = null, $root = null, $extensions = null, Response $response = null) { $this->_setError(''); if (!OpenId::normalize($id)) { $this->_setError("Normalisation failed"); return false; } $claimedId = $id; if (!$this->_discovery($id, $server, $version)) { $this->_setError("Discovery failed: " . $this->getError()); return false; } if (!$this->_associate($server, $version)) { $this->_setError("Association failed: " . $this->getError()); return false; } if (!$this->_getAssociation($server, $handle, $macFunc, $secret, $expires)) { /* Use dumb mode */ unset($handle); unset($macFunc); unset($secret); unset($expires); } $params = array(); if ($version >= 2.0) { $params['openid.ns'] = OpenId::NS_2_0; } $params['openid.mode'] = $immediate ? 'checkid_immediate' : 'checkid_setup'; $params['openid.identity'] = $id; $params['openid.claimed_id'] = $claimedId; if ($version <= 2.0) { if ($this->_session !== null) { $this->_session->identity = $id; $this->_session->claimed_id = $claimedId; } elseif (defined('SID')) { $_SESSION["zend_openid"] = array("identity" => $id, "claimed_id" => $claimedId); } elseif (!headers_sent()) { $this->_session = new SessionContainer("zend_openid"); $this->_session->identity = $id; $this->_session->claimed_id = $claimedId; } } if (isset($handle)) { $params['openid.assoc_handle'] = $handle; } $params['openid.return_to'] = OpenId::absoluteUrl($returnTo); if (empty($root)) { $root = OpenId::selfUrl(); if ($root[strlen($root) - 1] != '/') { $root = dirname($root); } } if ($version >= 2.0) { $params['openid.realm'] = $root; } else { $params['openid.trust_root'] = $root; } if (!Extension\AbstractExtension::forAll($extensions, 'prepareRequest', $params)) { $this->_setError("Extension::prepareRequest failure"); return false; } OpenId::redirect($server, $params, $response); return true; }
public function action_finder($input) { global $prefs, $user; if ($this->parentIds === null) { $ids = TikiLib::lib('filegal')->getGalleriesParentIds(); $this->parentIds = array('galleries' => array(), 'files' => array()); foreach ($ids as $id) { if ($id['parentId'] > 0) { $this->parentIds['galleries'][(int) $id['galleryId']] = (int) $id['parentId']; } } $tiki_files = TikiDb::get()->table('tiki_files'); $this->parentIds['files'] = $tiki_files->fetchMap('fileId', 'galleryId', array()); } // turn off some elfinder commands here too (stops the back-end methods being accessible) $disabled = array('mkfile', 'edit', 'archive', 'resize'); // done so far: 'rename', 'rm', 'duplicate', 'upload', 'copy', 'cut', 'paste', 'mkdir', 'extract', // check for a "userfiles" gallery - currently although elFinder can support more than one root, it always starts in the first one $opts = array('debug' => true, 'roots' => array()); $rootDefaults = array('driver' => 'TikiFiles', 'disabled' => $disabled, 'accessControl' => array($this, 'elFinderAccess'), 'uploadMaxSize' => ini_get('upload_max_filesize'), 'accessControlData' => array('deepGallerySearch' => $input->deepGallerySearch->int(), 'parentIds' => $this->parentIds)); // gallery to start in $startGallery = $input->defaultGalleryId->int(); if ($startGallery) { $gal_info = TikiLib::lib('filegal')->get_file_gallery_info($startGallery); if (!$gal_info) { TikiLib::lib('errorreport')->report(tr('Gallery ID %0 not found', $startGallery)); $startGallery = $prefs['fgal_root_id']; } } // 'startPath' not functioning with multiple roots as yet (https://github.com/Studio-42/elFinder/issues/351) // so work around it for now with startRoot $opts['roots'][] = array_merge(array('path' => $prefs['fgal_root_id']), $rootDefaults); $startRoot = 0; if (!empty($user) && $prefs['feature_userfiles'] == 'y' && $prefs['feature_use_fgal_for_user_files'] == 'y') { if ($startGallery && $startGallery == $prefs['fgal_root_user_id'] && !Perms::get('file gallery', $startGallery)->admin_file_galleries) { $startGallery = (int) TikiLib::lib('filegal')->get_user_file_gallery(); } $userRootId = $prefs['fgal_root_user_id']; if ($startGallery != $userRootId) { $gal_info = TikiLib::lib('filegal')->get_file_gallery_info($startGallery); if ($gal_info['type'] == 'user') { $startRoot = count($opts['roots']); } } else { $startRoot = count($opts['roots']); } $opts['roots'][] = array_merge(array('path' => $userRootId), $rootDefaults); } if ($prefs['feature_wiki_attachments'] == 'y' && $prefs['feature_use_fgal_for_wiki_attachments'] === 'y') { if ($startGallery && $startGallery == $prefs['fgal_root_wiki_attachments_id']) { $startRoot = count($opts['roots']); } $opts['roots'][] = array_merge(array('path' => $prefs['fgal_root_wiki_attachments_id']), $rootDefaults); } if ($startGallery) { $opts['startRoot'] = $startRoot; $d = $opts['roots'][$startRoot]['path'] == $startGallery ? '' : 'd_'; // needs to be the cached name in elfinder (with 'd_' in front) unless it's the root id $opts['roots'][$startRoot]['startPath'] = $d . $startGallery; } /* thumb size not working due to css issues - tried this in setup/javascript.php but needs extensive css overhaul to get looking right if ($prefs['fgal_elfinder_feature'] === 'y') { $tmbSize = (int) $prefs['fgal_thumb_max_size'] / 2; TikiLib::lib('header')->add_css(".elfinder-cwd-icon {width:{$tmbSize}px; height:{$tmbSize}px;}"); // def 48 $tmbSize += 4; // def 52 TikiLib::lib('header')->add_css(".elfinder-cwd-view-icons .elfinder-cwd-file-wrapper {width:{$tmbSize}px; height:{$tmbSize}px;}"); $tmbSize += 28; $tmbSizeW = $tmbSize + 40; // def 120 x 80 TikiLib::lib('header')->add_css(".elfinder-cwd-view-icons .elfinder-cwd-file {width: {$tmbSizeW}px;height: {$tmbSize}px;}"); } */ // run elFinder $elFinder = new tikiElFinder($opts); $connector = new elFinderConnector($elFinder); $filegallib = TikiLib::lib('filegal'); if ($input->cmd->text() === 'tikiFileFromHash') { // intercept tiki only commands $fileId = $elFinder->realpath($input->hash->text()); if (strpos($fileId, 'f_') !== false) { $info = $filegallib->get_file(str_replace('f_', '', $fileId)); } else { $info = $filegallib->get_file_gallery(str_replace('d_', '', $fileId)); } $params = array(); if ($input->filegals_manager->text()) { $params['filegals_manager'] = $input->filegals_manager->text(); } if ($input->insertion_syntax->text()) { $params['insertion_syntax'] = $input->insertion_syntax->text(); } $info['wiki_syntax'] = $filegallib->getWikiSyntax($info['galleryId'], $info, $params); $info['data'] = ''; // binary data makes JSON fall over return $info; } else { if ($input->cmd->text() === 'file') { // intercept download command and use tiki-download_file so the mime type and extension is correct $fileId = $elFinder->realpath($input->target->text()); if (strpos($fileId, 'f_') !== false) { global $base_url; $fileId = str_replace('f_', '', $fileId); $display = ''; $url = $base_url . 'tiki-download_file.php?fileId=' . $fileId; if (!$input->download->int()) { // images can be displayed $info = $filegallib->get_file($fileId); if (strpos($info['filetype'], 'image/') !== false) { $url .= '&display'; } else { if ($prefs['fgal_viewerjs_feature'] === 'y' && ($info['filetype'] === 'application/pdf' or strpos($info['filetype'], 'application/vnd.oasis.opendocument.') !== false)) { $url = \ZendOpenId\OpenId::absoluteUrl($prefs['fgal_viewerjs_uri']) . '#' . $url; } } } TikiLib::lib('access')->redirect($url); return array(); } } } // elfinder needs "raw" $_GET or $_POST if ($_SERVER["REQUEST_METHOD"] == 'POST') { $_POST = $input->asArray(); } else { $_GET = $input->asArray(); } $connector->run(); // deals with response return array(); }
/** * testing setSelfUrl * */ public function testSetSelfUrl() { unset($_SERVER['SCRIPT_URI']); unset($_SERVER['HTTPS']); unset($_SERVER['HTTP_HOST']); unset($_SERVER['SERVER_NAME']); unset($_SERVER['SERVER_PORT']); unset($_SERVER['SCRIPT_URL']); unset($_SERVER['REDIRECT_URL']); unset($_SERVER['PHP_SELF']); unset($_SERVER['SCRIPT_NAME']); unset($_SERVER['PATH_INFO']); $_SERVER['SCRIPT_URI'] = "http://www.test.com/"; $this->assertSame('http://www.test.com/', OpenId::selfUrl()); $this->assertSame(null, OpenId::setSelfUrl("http://localhost/test")); $this->assertSame("http://localhost/test", OpenId::selfUrl()); $this->assertSame("http://localhost/test", OpenId::setSelfUrl()); $this->assertSame('http://www.test.com/', OpenId::selfUrl()); $this->assertSame(null, OpenId::setSelfUrl()); $this->assertSame('http://www.test.com/', OpenId::selfUrl()); }