/** * For download file. * * @param string $sFile file in download. * @param string $sName if file in download. * @param string $sMimeType Optional, default value is NULL. * @return void */ public function download($sFile, $sName, $sMimeType = null) { /* This function takes a path to a file to output ($sFile), the filename that the browser will see ($sName) and the MIME type of the file ($sMimeType, optional). If you want to do something on download abort/finish, register_shutdown_function('function_name'); */ //if (!is_readable($sFile)) exit('File not found or inaccessible!'); $sName = \PH7\Framework\Url\Url::decode($sName); // Clean the name file /* Figure out the MIME type (if not specified) */ if (empty($sMimeType)) { $sFileExtension = $this->getFileExt($sFile); $mGetMimeType = $this->getMimeType($sFileExtension); if (!empty($mGetMimeType)) { $sMimeType = $mGetMimeType; } else { $sMimeType = 'application/force-download'; } } @ob_end_clean(); // Turn off output buffering to decrease CPU usage (new \PH7\Framework\Navigation\Browser())->nocache(); // No cache $sPrefix = \PH7\Framework\Registry\Registry::getInstance()->site_name . '_'; // the prefix header('Content-Type: ' . $sMimeType); header('Content-Disposition: attachment; filename=' . \PH7\Framework\Parse\Url::clean($sPrefix) . $sName); header('Content-Transfer-Encoding: binary'); header('Accept-Ranges: bytes'); header('Content-Length: ' . $this->size($sFile)); readfile($sFile); }
/** * Generate a Link tag. * * @param string $sLink The link * @param boolean $bNoFollow Set "true" for the rel="nofollow" attribute otherwise "false". Default value is "true" * @return void The HTML link tag. */ public function urlTag($sLink, $bNoFollow = true) { $sNoFollowTag = $bNoFollow === true ? ' rel="nofollow"' : ''; $sLinkName = \PH7\Framework\Parse\Url::name($sLink); echo '<a href="', $sLink, '" title="', $sLinkName, '"', $sNoFollowTag, '>', $sLinkName, '</a>'; }
/** * @access private * @param array $aParams * @return string * @throws \PH7\Framework\File\Exception If the XML file is not found. */ private static function _uri(array $aParams) { $sModule = $aParams['module']; $sController = $aParams['controller']; $sAction = $aParams['action']; $sVars = ''; // Default value if (!empty($aParams['vars'])) { // Omit the commas which may be part of a sentence in the URL parameters $aParams['vars'] = str_replace(array(', ', ' ,'), '', $aParams['vars']); $aVars = explode(',', $aParams['vars']); foreach ($aVars as $sVar) { $sVars .= PH7_SH . $sVar; } unset($aVars); $sVars = Url::clean($sVars, static::$_bFullClean); } $oUrl = static::loadFile(new \DOMDocument()); foreach ($oUrl->getElementsByTagName('route') as $oRoute) { if (preg_match('#^' . $oRoute->getAttribute('module') . '$#', $sModule) && preg_match('#^' . $oRoute->getAttribute('controller') . '$#', $sController) && preg_match('#^' . $oRoute->getAttribute('action') . '$#', $sAction)) { // Strip the special characters $sUri = $oRoute->getAttribute('url'); $sUri = str_replace('\\', '', $sUri); $sUri = preg_replace('#\\(.+\\)#', '', $sUri); $sUri = preg_replace('#([/\\?]+)$#', '', $sUri); return PH7_URL_ROOT . $sUri . $sVars; } } unset($oUrl); return PH7_URL_ROOT . "{$sModule}/{$sController}/{$sAction}{$sVars}"; }
/** * Generate a Link tag. * * @param string $sLink The link. * @param boolean $bNoFollow Set TRUE to set the link "nofollow", FALSE otherwise. Default TRUE * @return void The HTML link tag. */ public function urlTag($sLink, $bNoFollow = true) { $sLinkName = \PH7\Framework\Parse\Url::name($sLink); $aDefAttrs = ['href' => $sLink, 'title' => $sLinkName]; if ($bNoFollow) { $aDefAttrs += ['rel' => 'nofollow']; } // Add "nofollow" attribute if "$bNoFollow" is TURE $this->htmlTag('a', $aDefAttrs, true, $sLinkName); }