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


PHP UrlManager::getForAsset方法代码示例

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


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

示例1: avatarUpload


//.........这里部分代码省略.........
         $msg = "Avatar file is empty.";
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         echo htmlspecialchars(json_encode(array('error' => $msg)), ENT_NOQUOTES);
         exit;
     }
     if ($size > CINTIENT_AVATAR_MAX_SIZE) {
         $msg = 'Avatar file is too large.';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         echo htmlspecialchars(json_encode(array('error' => $msg)), ENT_NOQUOTES);
         exit;
     }
     //
     // File handling.
     //
     $input = fopen("php://input", "r");
     $temp = tempnam(CINTIENT_WORK_DIR, 'avatartmp');
     $output = fopen($temp, "w");
     $realSize = stream_copy_to_stream($input, $output);
     fclose($input);
     fclose($output);
     if ($realSize != $size) {
         $msg = "Problems with the uploaded avatar file size. [CONTENT_LENGTH={$size}] [FILE_SIZE={$realSize}]";
         SystemEvent::raise(SystemEvent::ERROR, $msg, __METHOD__);
         echo htmlspecialchars(json_encode(array('error' => $msg)), ENT_NOQUOTES);
         exit;
     }
     if (!file_exists($temp)) {
         $msg = "Uploaded avatar file couldn't be saved to temporary dir. [TEMP_FILE={$temp}]";
         SystemEvent::raise(SystemEvent::ERROR, $msg, __METHOD__);
         echo htmlspecialchars(json_encode(array('error' => $msg)), ENT_NOQUOTES);
         exit;
     }
     $fileStats = getimagesize($temp);
     if ($fileStats[2] != IMAGETYPE_JPEG && $fileStats[2] != IMAGETYPE_PNG) {
         unlink($temp);
         $msg = "Avatar file with unsupported format. [FORMAT={$fileStats['mime']}]";
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         echo htmlspecialchars(json_encode(array('error' => $msg)), ENT_NOQUOTES);
         exit;
     }
     $image = null;
     if ($fileStats[2] == IMAGETYPE_JPEG) {
         $image = @imagecreatefromjpeg($temp);
     }
     if ($fileStats[2] == IMAGETYPE_PNG) {
         $image = @imagecreatefrompng($temp);
     }
     if (!$image) {
         unlink($temp);
         $msg = "Problems creating image.";
         SystemEvent::raise(SystemEvent::ERROR, $msg, __METHOD__);
         echo htmlspecialchars(json_encode(array('error' => $msg)), ENT_NOQUOTES);
         exit;
     }
     // We can be dealing with both project and user avatars here
     $subject = $GLOBALS['project'];
     if (!isset($_GET['p'])) {
         $subject = $GLOBALS['user'];
     }
     //
     // Save. If the there is a previous local avatar, extract it and
     // remove it from the filesystem.
     //
     if (($pos = strpos($subject->getAvatar(), 'local:')) === 0) {
         @unlink(CINTIENT_AVATARS_DIR . substr($subject->getAvatar(), 6));
     }
     do {
         $filename = uniqid() . '.jpg';
         if (!file_exists(CINTIENT_AVATARS_DIR . $filename)) {
             break;
         }
     } while (true);
     $subject->setAvatarLocal($filename);
     $dstPath = CINTIENT_AVATARS_DIR . $filename;
     $dstImg = imagecreatetruecolor(CINTIENT_AVATAR_WIDTH, CINTIENT_AVATAR_HEIGHT);
     if (!imagecopyresampled($dstImg, $image, 0, 0, 0, 0, CINTIENT_AVATAR_WIDTH, CINTIENT_AVATAR_HEIGHT, $fileStats[0], $fileStats[1])) {
         unlink($temp);
         $msg = "Problems creating image.";
         SystemEvent::raise(SystemEvent::ERROR, $msg, __METHOD__);
         echo htmlspecialchars(json_encode(array('error' => $msg)), ENT_NOQUOTES);
         exit;
     }
     imagedestroy($image);
     if (!imagejpeg($dstImg, $dstPath, CINTIENT_AVATAR_IMAGE_QUALITY)) {
         unlink($temp);
         $msg = "Problems creating image.";
         SystemEvent::raise(SystemEvent::ERROR, $msg, __METHOD__);
         echo htmlspecialchars(json_encode(array('error' => $msg)), ENT_NOQUOTES);
         exit;
     }
     imagedestroy($dstImg);
     unlink($temp);
     //
     // Don't htmlspecialchars encode the following success JSON, since
     // the final URL will get encoded and on the client side via JS we
     // won't be able to easily turn that into an URL to refresh avatar
     //
     echo json_encode(array('success' => true, 'url' => UrlManager::getForAsset($filename, array('avatar' => 1))));
     exit;
 }
开发者ID:rasismeiro,项目名称:cintient,代码行数:101,代码来源:AjaxManager.php

示例2: getAvatarUrl

 public function getAvatarUrl()
 {
     if (($pos = strpos($this->getAvatar(), 'local:')) === 0) {
         return UrlManager::getForAsset(substr($this->getAvatar(), 6), array('avatar' => 1));
     } else {
         return 'imgs/anon_avatar_50.png';
     }
 }
开发者ID:rasismeiro,项目名称:cintient,代码行数:8,代码来源:Project.php

示例3: postBuild

    public function postBuild()
    {
        SystemEvent::raise(SystemEvent::DEBUG, "Called.", __METHOD__);
        // Backup the original junit report file
        if (!@copy($this->getPtrProjectBuild()->getPtrProject()->getReportsWorkingDir() . CINTIENT_JUNIT_REPORT_FILENAME, $this->getPtrProjectBuild()->getBuildDir() . CINTIENT_JUNIT_REPORT_FILENAME)) {
            SystemEvent::raise(SystemEvent::ERROR, "Could not backup original Junit XML file [PID={$this->getProjectId()}] [BUILD={$this->getProjectBuildId()}]", __METHOD__);
            return false;
        }
        // Backup the original codecoverage xml report file
        if (!@copy($this->getPtrProjectBuild()->getPtrProject()->getReportsWorkingDir() . CINTIENT_CODECOVERAGE_XML_REPORT_FILENAME, $this->getPtrProjectBuild()->getBuildDir() . CINTIENT_CODECOVERAGE_XML_REPORT_FILENAME)) {
            SystemEvent::raise(SystemEvent::ERROR, "Could not backup original code coverage XML file [PID={$this->getProjectId()}] [BUILD={$this->getProjectBuildId()}]", __METHOD__);
            return false;
        }
        // Copy the original codecoverage html dir and "massage" the files
        $ret = true;
        $origCovDir = $this->getPtrProjectBuild()->getPtrProject()->getReportsWorkingDir() . CINTIENT_CODECOVERAGE_HTML_DIR;
        if (file_exists($origCovDir)) {
            $htmlCovDir = $this->getPtrProjectBuild()->getBuildDir() . CINTIENT_CODECOVERAGE_HTML_DIR;
            if (!@mkdir($htmlCovDir) || !file_exists($htmlCovDir)) {
                SystemEvent::raise(SystemEvent::ERROR, "Could not create dir for HTML coverage files [DIR={$htmlCovDir}] [PID={$this->getProjectId()}] [BUILD={$this->getProjectBuildId()}]", __METHOD__);
                return false;
            }
            foreach (new DirectoryIterator($origCovDir) as $file) {
                if ($file->isDot()) {
                    continue;
                }
                $src = $origCovDir . $file;
                $dest = $htmlCovDir . $file;
                if (!copy($src, $dest)) {
                    SystemEvent::raise(SystemEvent::ERROR, "Problems copying a file from the original codecoverage HTML dir [FILE={$file}] [DIR={$htmlCovDir}] [PID={$this->getProjectId()}] [BUILD={$this->getProjectBuildId()}]", __METHOD__);
                    $ret = false;
                } else {
                    $ret = $ret & true;
                    //
                    // We're taking the chance to hack into every code coverage
                    // HTML generated file and bent it to our purposes. While we
                    // don't have the ability to generate our very own
                    //
                    $destHtml = file_get_contents($dest);
                    $that = $this;
                    # Wow, beautiful, thank you PHP 5.3.x...
                    //
                    // Get all links working apropriately for Cintient
                    //
                    $newDestHtml = preg_replace_callback('/((?:src|href)=)"([\\w.#]+)"/m', function ($match) use($that) {
                        return $match[1] . '"' . UrlManager::getForAsset($match[2], array('bid' => $that->getBuildId(), 'cc' => true)) . '"';
                    }, $destHtml, -1);
                    // Add a few CSS tweaks
                    SystemEvent::raise(SystemEvent::ERROR, $file, __METHOD__);
                    if ($file == 'style.css') {
                        $newDestHtml .= "html,body,table,tr,td,a{font-size:8pt;font-family:sans-serif,arial,helvetica;}";
                        $newDestHtml .= <<<EOT
body {
  background: #FBFBFB; /* non-CSS3 */
  filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#eeeeee'); /* for IE */
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0.16, #fff), color-stop(0.9, #eee)); /* for webkit browsers */
  background: -moz-linear-gradient(top, #fff 16%, #eee 90%); /* for firefox 3.6+ */
}
EOT;
                    }
                    file_put_contents($dest, $newDestHtml);
                }
            }
            // TODO: remove the original codecoverage dir.
        }
        return $ret;
    }
开发者ID:rasismeiro,项目名称:cintient,代码行数:67,代码来源:PhpUnit.php

示例4: getAvatarUrl

 public function getAvatarUrl()
 {
     if (($pos = strpos($this->getAvatar(), 'local:')) === 0) {
         return UrlManager::getForAsset(substr($this->getAvatar(), 6), array('avatar' => 1));
     } elseif (($pos = strpos($this->getAvatar(), 'gravatar:')) === 0) {
         // TODO: Maybe it's best to keep a user's gravatar email a hash it on-the-fly
         // instead of storing the definitive URL to it.
         return substr($this->getAvatar(), 9);
     } else {
         return 'imgs/anon_avatar_50.png';
     }
 }
开发者ID:rasismeiro,项目名称:cintient,代码行数:12,代码来源:User.php


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