Example #1
0
    /**
     * Generates HTML to either embed a file or link to file for download
     *
     * @param      string $file File to embed
     * @param      array  $attr Attributes to apply to the HTML
     * @return     string
     */
    private function _embed($file, $attr = array())
    {
        $ext = strtolower(Filesystem::extension($file));
        switch ($ext) {
            case 'unity3d':
                $attr['width'] = isset($attr['width']) && $attr['width'] ? $attr['width'] : 400;
                $attr['height'] = isset($attr['height']) && $attr['height'] ? $attr['height'] : 400;
                if (isset($attr['style']['width'])) {
                    $attr['width'] = intval($attr['style']['width']);
                }
                if (isset($attr['style']['height'])) {
                    $attr['height'] = intval($attr['style']['height']);
                }
                $attr['href'] = isset($attr['href']) && $attr['href'] && $attr['href'] != 'none' ? $attr['href'] : $this->_link($file);
                /*if (!array_key_exists('alt', $attr)
                		 && array_key_exists('altimage', $attr)
                		 && $attr['altimage'] != ''
                		 && file_exists($this->_path($attr['altimage'])))
                		{
                			//$attr['href'] = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
                			$althref = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
                			$attr['alt']  = '<a class="attachment" rel="internal" href="' . $althref . '" title="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '">';
                			$attr['alt'] .= '<img src="' . $this->_link($attr['altimage']) . '" alt="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '" />';
                			$attr['alt'] .= '</a>';
                		}
                		else
                		{
                			$althref = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
                			$attr['alt']  = (isset($attr['alt'])) ? $attr['alt'] : '';
                			$attr['alt'] .= '<a class="attachment" rel="internal" href="' . $althref . '" title="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '">' . $attr['desc'] . '</a>';
                		}*/
                $rand = rand(0, 100000);
                $html = '<script type="text/javascript" src="' . (\Request::scheme() == 'https' ? 'https://ssl-' : 'http://') . 'webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js"></script>' . "\n";
                $html .= '<div id="unityPlayer' . $rand . '">
							<div class="missing">
								<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
									<img alt="Unity Web Player. Install now!" src="' . (\Request::scheme() == 'https' ? 'https://ssl-' : 'http://') . 'webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
								</a>
							</div>
						</div>' . "\n";
                $html .= '<script type="text/javascript">' . "\n";
                $html .= '<!--
							var config = {
								width: ' . intval($attr['width']) . ',
								height: ' . intval($attr['height']) . ',
								params: { enableDebugging:"0" }
							}
							var u = new UnityObject2(config);
							var unityObject = $("#unityPlayer' . $rand . '");
							u.initPlugin(unityObject, "' . $attr['href'] . '");
							-->' . "\n";
                $html .= '</script>' . "\n";
                break;
            case 'cdf':
                $attr['width'] = isset($attr['width']) && $attr['width'] ? $attr['width'] : 400;
                $attr['height'] = isset($attr['height']) && $attr['height'] ? $attr['height'] : 400;
                if (isset($attr['style']['width'])) {
                    $attr['width'] = intval($attr['style']['width']);
                }
                if (isset($attr['style']['height'])) {
                    $attr['height'] = intval($attr['style']['height']);
                }
                $attr['href'] = isset($attr['href']) && $attr['href'] && $attr['href'] != 'none' ? $attr['href'] : $this->_link($file);
                $rand = rand(0, 100000);
                if (!array_key_exists('alt', $attr) && array_key_exists('altimage', $attr) && $attr['altimage'] != '' && file_exists($this->_path($attr['altimage']))) {
                    //$attr['href'] = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
                    $althref = array_key_exists('althref', $attr) && $attr['althref'] != '' ? $attr['althref'] : $attr['href'];
                    $attr['alt'] = '<a href="http://www.wolfram.com/cdf-player/" title="CDF Web Player. Install now!">';
                    $attr['alt'] .= '<img src="' . $this->_link($attr['altimage']) . '" alt="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '" />';
                    $attr['alt'] .= '</a>';
                } else {
                    $attr['alt'] = '<div class="embedded-plugin" style="width: ' . intval($attr['width']) . 'px; height: ' . intval($attr['height']) . 'px;"><a class="missing-plugin" href="http://www.wolfram.com/cdf-player/" title="CDF Web Player. Install now!"><img alt="CDF Web Player. Install now!" src="' . $juri->getScheme() . '://www.wolfram.com/cdf/images/cdf-player-black.png" width="187" height="41" /></a></div>';
                }
                $html = '<script type="text/javascript" src="' . \Request::scheme() . '://www.wolfram.com/cdf-player/plugin/v2.1/cdfplugin.js"></script>';
                $html .= '<script type="text/javascript">';
                //$html .= '<!--';
                $html .= '	var cdf = new cdfplugin();';
                $html .= "var defaultContent = '" . $attr['alt'] . "';";
                $html .= '	if (defaultContent!= "") {';
                $html .= '		cdf.setDefaultContent(defaultContent);';
                $html .= '	}';
                $html .= '	cdf.embed(\'' . $attr['href'] . '\', ' . intval($attr['width']) . ', ' . intval($attr['height']) . ');';
                //$html .= ' -->';
                $html .= '</script>' . "\n";
                $html .= '<noscript>';
                $html .= '<div class="embedded-plugin" style="width: ' . intval($attr['width']) . 'px; height: ' . intval($attr['height']) . ';">';
                $html .= $attr['alt'];
                $html .= '</div>';
                $html .= '</noscript>' . "\n";
                break;
            default:
                $attr['alt'] = isset($attr['alt']) ? htmlentities($attr['alt'], ENT_COMPAT, 'UTF-8') : $attr['desc'];
                if (!$attr['alt']) {
                    $attr['alt'] = $file;
                }
                if (in_array($ext, $this->imgs)) {
                    $styles = '';
                    if (count($attr['style']) > 0) {
                        $s = array();
                        foreach ($attr['style'] as $k => $v) {
                            $s[] = strtolower($k) . ':' . $v;
                        }
                        $styles = implode('; ', $s);
                    }
                    $attr['style'] = '';
                    $attribs = array();
                    foreach ($attr as $k => $v) {
                        $k = strtolower($k);
                        if ($k != 'href' && $k != 'rel' && $k != 'desc' && $v) {
                            $attribs[] = $k . '="' . trim($v, '"') . '"';
                        }
                    }
                    $html = '<span class="figure"' . ($styles ? ' style="' . $styles . '"' : '') . '>';
                    $img = '<img src="' . $this->_link($file) . '" ' . implode(' ', $attribs) . ' />';
                    if ($attr['href'] == 'none') {
                        $html .= $img;
                    } else {
                        $attr['href'] = $attr['href'] ? $attr['href'] : $this->_link($file);
                        $attr['rel'] = isset($attr['rel']) ? $attr['rel'] : 'lightbox';
                        $html .= '<a rel="' . $attr['rel'] . '" href="' . $attr['href'] . '">' . $img . '</a>';
                    }
                    if (isset($attr['desc']) && $attr['desc']) {
                        $html .= '<span class="figcaption">' . $attr['desc'] . '</span>';
                    }
                    $html .= '</span>';
                } else {
                    $attr['details'] = isset($attr['details']) ? $attr['details'] : true;
                    $attr['href'] = isset($attr['href']) && $attr['href'] != '' ? $attr['href'] : $this->_link($file);
                    $attr['rel'] = isset($attr['rel']) ? $attr['rel'] : 'internal';
                    $size = null;
                    if (file_exists($this->_path($file))) {
                        $size = filesize($this->_path($file));
                    } else {
                        if (file_exists($this->_path($file, true))) {
                            $size = filesize($this->_path($file, true));
                        }
                    }
                    $attr['title'] = !isset($attr['title']) || !$attr['title'] ? $attr['alt'] : $attr['title'];
                    $html = '<a class="attachment" rel="' . $attr['rel'] . '" href="' . $attr['href'] . '" title="' . $attr['title'] . '">' . $attr['desc'] . '</a>';
                    if ($size !== null && $attr['details']) {
                        $html .= ' (<span class="file-atts">' . \Hubzero\Utility\Number::formatBytes($size);
                        if (isset($attr['created_by'])) {
                            $user = User::getInstance($attr['created_by']);
                            $html .= ', ' . Lang::txt('uploaded by %s ', stripslashes($user->get('name')));
                        }
                        if (isset($attr['created'])) {
                            $html .= ' ' . Date::of($attr['created'])->relative();
                        }
                        $html .= '</span>)';
                    }
                }
                break;
        }
        return $html;
    }