当前位置: 首页>>代码示例>>PHP>>正文


PHP MimeMagic::singleton方法代码示例

本文整理汇总了PHP中MimeMagic::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP MimeMagic::singleton方法的具体用法?PHP MimeMagic::singleton怎么用?PHP MimeMagic::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MimeMagic的用法示例。


在下文中一共展示了MimeMagic::singleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: showFile

 function showFile()
 {
     $i = strpos($this->mBasePath, '/');
     $i = $i === false ? 0 : $i + 1;
     $filename = substr($this->mBasePath, $i);
     $i = strpos($filename, '.');
     if ($i !== false) {
         $ext = substr($filename, $i + 1);
         $mime = MimeMagic::singleton();
         $ctype = $mime->guessTypesForExtension($ext);
     } else {
         $ctype = 'application/octet-stream';
     }
     $contents = $this->svn->getFile($this->mBasePath, $this->mRev == 'HEAD' ? null : $this->mRev);
     if ($this->mAction == 'raw' || $this->mAction == 'download') {
         global $wgOut;
         $wgOut->disable();
         if ($this->mAction == 'raw') {
             header('Content-Type: ' . $ctype);
         } else {
             header('Content-Type: application/octet-stream');
         }
         header('Content-Length: ' . strlen($contents));
         print $contents;
         return;
     }
     if (substr($ctype, 0, 5) == 'text/') {
         return Xml::element('pre', array('style' => 'overflow: auto;'), $contents);
     } else {
         return wfMsgHTML('codebrowse-binary-file');
     }
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:32,代码来源:CodeBrowseItemView.php

示例2: execute

 /**
  * This is called upon loading the special page. It should write output to the page with $wgOut.
  * 
  * @param string $par The portion of the URI after Special:StaticDocServer/
  */
 public function execute($par)
 {
     #TODO: switch to $this->getOuput() and $this->getRequest() when we upgrade MW
     global $wgOut, $wgRequest;
     $wgOut->disable();
     $found = FALSE;
     list($productName, $versionName, $path) = explode('/', $par, 3);
     if (substr($par, -1, 1) == '/') {
         $par .= 'index.html';
     }
     // Validate parameters are set
     if (isset($productName) && isset($versionName) && PonyDocsProduct::GetProductByShortName($productName) && PonyDocsProductVersion::GetVersionByName($productName, $versionName)) {
         $filename = PONYDOCS_STATIC_DIR . "/{$par}";
         if (file_exists($filename)) {
             $found = TRUE;
         }
     }
     if (!$found) {
         $wgRequest->response()->header("HTTP/1.1 404 Not Found");
         echo "<html>\n";
         echo "<head><title>Not Found</title></head>\n";
         echo "<body>\n";
         echo "<h1>Bad Request</h1>\n";
         echo "<div>The documentation you have requested does not exist.</div>\n";
         echo "</body>\n";
         echo "</html>\n";
     } else {
         $mimeMagic = MimeMagic::singleton();
         $pathParts = pathinfo($filename);
         /* get mime-type for a specific file */
         header('Content-type: ' . $mimeMagic->guessTypesForExtension($pathParts['extension']));
         readfile($filename);
     }
 }
开发者ID:Velody,项目名称:ponydocs,代码行数:39,代码来源:SpecialStaticDocServer.php

示例3: getMimeType

 function getMimeType()
 {
     if (!isset($this->mime)) {
         $magic = MimeMagic::singleton();
         $this->mime = $magic->guessMimeType($this->path);
     }
     return $this->mime;
 }
开发者ID:rocLv,项目名称:conference,代码行数:8,代码来源:UnregisteredLocalFile.php

示例4: dataFile

 /**
  * Utility function: Get a new file object for a file on disk but not actually in db.
  *
  * File must be in the path returned by getFilePath()
  * @param string $name File name
  * @param string $type MIME type [optional]
  * @return UnregisteredLocalFile
  */
 protected function dataFile($name, $type = null)
 {
     if (!$type) {
         // Autodetect by file extension for the lazy.
         $magic = MimeMagic::singleton();
         $parts = explode($name, '.');
         $type = $magic->guessTypesForExtension($parts[count($parts) - 1]);
     }
     return new UnregisteredLocalFile(false, $this->repo, "mwstore://localtesting/data/{$name}", $type);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:18,代码来源:MediaWikiMediaTestCase.php

示例5: wfGetType

/** */
function wfGetType($filename, $safe = true)
{
    global $wgTrivialMimeDetection;
    $ext = strrchr($filename, '.');
    $ext = $ext === false ? '' : strtolower(substr($ext, 1));
    # trivial detection by file extension,
    # used for thumbnails (thumb.php)
    if ($wgTrivialMimeDetection) {
        switch ($ext) {
            case 'gif':
                return 'image/gif';
            case 'png':
                return 'image/png';
            case 'jpg':
                return 'image/jpeg';
            case 'jpeg':
                return 'image/jpeg';
        }
        return 'unknown/unknown';
    }
    $magic = MimeMagic::singleton();
    // Use the extension only, rather than magic numbers, to avoid opening
    // up vulnerabilities due to uploads of files with allowed extensions
    // but disallowed types.
    $type = $magic->guessTypesForExtension($ext);
    /**
     * Double-check some security settings that were done on upload but might 
     * have changed since.
     */
    if ($safe) {
        global $wgFileBlacklist, $wgCheckFileExtensions, $wgStrictFileExtensions, $wgFileExtensions, $wgVerifyMimeType, $wgMimeTypeBlacklist, $wgRequest;
        $form = new UploadForm($wgRequest);
        list($partName, $extList) = $form->splitExtensions($filename);
        if ($form->checkFileExtensionList($extList, $wgFileBlacklist)) {
            return 'unknown/unknown';
        }
        if ($wgCheckFileExtensions && $wgStrictFileExtensions && !$form->checkFileExtensionList($extList, $wgFileExtensions)) {
            return 'unknown/unknown';
        }
        if ($wgVerifyMimeType && in_array(strtolower($type), $wgMimeTypeBlacklist)) {
            return 'unknown/unknown';
        }
    }
    return $type;
}
开发者ID:ruizrube,项目名称:spdef,代码行数:46,代码来源:StreamFile.php

示例6: setType

	function setType( $image ) {
		$this->mimetype = $image->getMimeType();
		$this->mediatype = $image->getMediaType();

		#FIXME: ugly hack! do this on upload!
		if ( $this->mimetype == 'unknown/unknown' ) {
			$mime = MimeMagic::singleton();
			$ext = preg_replace('!^.*\.([^.]+)$!', '\1', $image->getName());
			$this->mimetype = $mime->guessTypesForExtension($ext);
			$this->mediatype = $mime->getMediaType(null, $this->mimetype);
		}

		if ( preg_match('!/(x-)?ogg$!', $this->mimetype) ) {

			if ( $this->mediatype == MEDIATYPE_AUDIO ) $this->mimetype = 'audio/ogg';
			elseif ( $this->mediatype == MEDIATYPE_VIDEO ) $this->mimetype = 'video/ogg';
			else $this->mimetype = 'application/ogg';
		}
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:19,代码来源:PlayerClass.php

示例7: wfGetType

/** */
function wfGetType($filename)
{
    global $wgTrivialMimeDetection;
    # trivial detection by file extension,
    # used for thumbnails (thumb.php)
    if ($wgTrivialMimeDetection) {
        $ext = strtolower(strrchr($filename, '.'));
        switch ($ext) {
            case '.gif':
                return 'image/gif';
            case '.png':
                return 'image/png';
            case '.jpg':
                return 'image/jpeg';
            case '.jpeg':
                return 'image/jpeg';
        }
        return 'unknown/unknown';
    } else {
        $magic =& MimeMagic::singleton();
        return $magic->guessMimeType($filename);
        //full fancy mime detection
    }
}
开发者ID:ErdemA,项目名称:wikihow,代码行数:25,代码来源:StreamFile.php

示例8: getExtensionList

 /**
  * Given a mime type, return a comma separated list of allowed extensions.
  *
  * @param $mime String mime type
  * @return String Comma separated list of allowed extensions (e.g. ".ogg, .oga")
  */
 private function getExtensionList($mime)
 {
     $exts = MimeMagic::singleton()->getExtensionsForType($mime);
     if ($exts === null) {
         return '';
     }
     $extArray = explode(' ', $exts);
     $extArray = array_unique($extArray);
     foreach ($extArray as &$ext) {
         $ext = '.' . $ext;
     }
     return $this->getLanguage()->commaList($extArray);
 }
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:19,代码来源:SpecialMediaStatistics.php

示例9: getThumbType

 function getThumbType($ext, $mime)
 {
     global $wgDjvuOutputExtension;
     static $mime;
     if (!isset($mime)) {
         $magic = MimeMagic::singleton();
         $mime = $magic->guessTypesForExtension($wgDjvuOutputExtension);
     }
     return array($wgDjvuOutputExtension, $mime);
 }
开发者ID:amjadtbssm,项目名称:website,代码行数:10,代码来源:DjVu.php

示例10: processCreation

 /**
  * @access private
  */
 function processCreation()
 {
     global $wgCityId, $wgSpecialContactEmail;
     global $wgLanguageCode, $wgServer;
     // If not configured, fall back to a default just in case.
     $wgSpecialContactEmail = empty($wgSpecialContactEmail) ? "community@wikia.com" : $wgSpecialContactEmail;
     $user = $this->getUser();
     $output = $this->getOutput();
     $request = $this->getRequest();
     $output->setPageTitle($this->msg('specialcontact-pagetitle')->text());
     $output->setRobotpolicy('noindex,nofollow');
     $output->setArticleRelated(false);
     //build common top of both emails
     $uid = $user->getID();
     $m_shared = '';
     if (empty($uid)) {
         $m_shared .= "USER IS NOT LOGGED IN\n";
     }
     $m_shared .= !empty($this->mRealName) ? $this->mRealName : (!empty($this->mUserName) ? $this->mUserName : '--');
     $m_shared .= " ({$this->mEmail})";
     $m_shared .= " " . (!empty($this->mUserName) ? $wgServer . "/wiki/User:" . urlencode(str_replace(" ", "_", $this->mUserName)) : $wgServer) . "\n";
     //start wikia debug info, sent only to the internal email, not cc'd
     $items = array();
     $items[] = 'wkID: ' . $wgCityId;
     $items[] = 'wkLang: ' . $wgLanguageCode;
     //always add the IP
     $items[] = 'IP:' . $request->getIP();
     //if they are logged in, add the ID(and name) and their lang
     if (!empty($uid)) {
         $items[] = 'uID: ' . $uid . " (User:" . $user->getName() . ")";
         $items[] = 'uLang: ' . $user->getGlobalPreference('language');
     }
     if (!empty($this->mReferral)) {
         $items[] = 'referral: ' . $this->mReferral;
     }
     //smush it all together
     $info = $this->mBrowser . "\n\n";
     if (!empty($uid)) {
         $info .= 'http://community.wikia.com/wiki/Special:LookUpUser/' . urlencode(str_replace(" ", "_", $this->mUserName)) . "_\n";
     }
     $info .= 'http://community.wikia.com/wiki/Special:LookUpUser/' . $this->mEmail . "\n\n";
     $info .= "A/B Tests: " . $this->mAbTestInfo . "\n\n";
     // giving it its own line so that it stands out more
     $info .= implode("; ", $items) . "\n\n";
     //end wikia debug data
     $body = "\n{$this->mProblemDesc}\n\n----\n" . $m_shared . $info;
     if ($this->mCCme) {
         $mcc = $this->msg('specialcontact-ccheader')->text() . "\n\n";
         $mcc .= $m_shared . "\n{$this->mProblemDesc}\n";
     }
     $mail_user = new MailAddress($this->mEmail);
     $mail_community = new MailAddress($wgSpecialContactEmail, 'Wikia Support');
     $errors = '';
     #to us, from user
     if (F::app()->checkSkin('wikiamobile')) {
         //We want an easy way to know that feedback comes from a mobile
         $this->mProblem = 'Mobile: ' . $this->mProblem;
     }
     $subject = $this->msg('specialcontact-mailsub')->text() . (!empty($this->mProblem) ? ' - ' . $this->mProblem : '');
     $screenshot = $request->getFileTempname('wpScreenshot');
     $magic = MimeMagic::singleton();
     $screenshots = array();
     if (!empty($screenshot)) {
         foreach ($screenshot as $image) {
             if (!empty($image)) {
                 $extList = '';
                 $mime = $magic->guessMimeType($image);
                 if ($mime !== 'unknown/unknown') {
                     # Get a space separated list of extensions
                     $extList = $magic->getExtensionsForType($mime);
                     $ext_file = strtok($extList, ' ');
                 } else {
                     $mime = 'application/octet-stream';
                 }
                 $screenshots[] = array('file' => $image, 'ext' => $ext_file, 'mime' => $mime);
             }
         }
         if (!empty($screenshots)) {
             $body .= "\n\nScreenshot attached.";
         }
     }
     # send mail to wgSpecialContactEmail
     # PLATFORM-212 -> To: and From: fields are set to wgSpecialContactEmail, ReplyTo: field is the user email
     $result = UserMailer::send($mail_community, $mail_community, $subject, $body, $mail_user, null, 'SpecialContact', 0, $screenshots);
     if (!$result->isOK()) {
         $errors .= "\n" . $result->getMessage();
     }
     #to user, from us (but only if the first one didnt error, dont want to echo the user on an email we didnt get)
     if (empty($errors) && $this->mCCme && $user->isEmailConfirmed()) {
         $result = UserMailer::send($mail_user, $mail_community, $this->msg('specialcontact-mailsubcc')->text(), $mcc, $mail_user, null, 'SpecialContactCC');
         if (!$result->isOK()) {
             $errors .= "\n" . $result->getMessage();
         }
     }
     if (!empty($errors)) {
         $output->addHTML($this->formatError($this->err));
     }
//.........这里部分代码省略.........
开发者ID:Tjorriemorrie,项目名称:app,代码行数:101,代码来源:SpecialContact.body.php

示例11:

/**
 * BC wrapper for MimeMagic::singleton()
 * @deprecated
 */
function &wfGetMimeMagic()
{
    return MimeMagic::singleton();
}
开发者ID:josephdye,项目名称:wikireader,代码行数:8,代码来源:GlobalFunctions.php

示例12: insertJobs

 /**
  * @param $upload UploadBase
  * @param $mime
  * @param $error
  * @return bool
  */
 public static function insertJobs($upload, $mime, &$error)
 {
     global $wgPdfCreateThumbnailsInJobQueue;
     if (!$wgPdfCreateThumbnailsInJobQueue) {
         return true;
     }
     if (!MimeMagic::singleton()->isMatchingExtension('pdf', $mime)) {
         return true;
         // not a PDF, abort
     }
     $title = $upload->getTitle();
     $uploadFile = $upload->getLocalFile();
     if (is_null($uploadFile)) {
         wfDebugLog('thumbnails', '$uploadFile seems to be null, should never happen...');
         return true;
         // should never happen, but it's better to be secure
     }
     $metadata = $uploadFile->getMetadata();
     $unserialized = unserialize($metadata);
     $pages = intval($unserialized['Pages']);
     $jobs = array();
     for ($i = 1; $i <= $pages; $i++) {
         $jobs[] = new CreatePdfThumbnailsJob($title, array('page' => $i, 'jobtype' => self::BIG_THUMB));
         $jobs[] = new CreatePdfThumbnailsJob($title, array('page' => $i, 'jobtype' => self::SMALL_THUMB));
     }
     Job::batchInsert($jobs);
     return true;
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:34,代码来源:CreatePdfThumbnailsJob.class.php

示例13: setUp

 function setUp()
 {
     $this->mimeMagic = MimeMagic::singleton();
     parent::setUp();
 }
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:5,代码来源:MimeMagicTest.php

示例14: imageInfo

 function imageInfo($filename)
 {
     $info = array('width' => 0, 'height' => 0, 'bits' => 0, 'media' => '', 'major' => '', 'minor' => '');
     $magic = MimeMagic::singleton();
     $mime = $magic->guessMimeType($filename, true);
     list($info['major'], $info['minor']) = explode('/', $mime);
     $info['media'] = $magic->getMediaType($filename, $mime);
     $image = UnregisteredLocalFile::newFromPath($filename, $mime);
     $info['width'] = $image->getWidth();
     $info['height'] = $image->getHeight();
     $gis = $image->getImageSize($filename);
     if (isset($gis['bits'])) {
         $info['bits'] = $gis['bits'];
     }
     return $info;
 }
开发者ID:eFFemeer,项目名称:seizamcore,代码行数:16,代码来源:upgrade1_5.php

示例15: getMediaType

 function getMediaType()
 {
     $magic = MimeMagic::singleton();
     return $magic->getMediaType(null, $this->getMimeType());
 }
开发者ID:ruizrube,项目名称:spdef,代码行数:5,代码来源:ForeignAPIFile.php


注:本文中的MimeMagic::singleton方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。