public static function avatarUpload() { if (!isset($_GET['qqfile'])) { $msg = "No avatar file was uploaded."; SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__); echo htmlspecialchars(json_encode(array('error' => $msg)), ENT_NOQUOTES); exit; } // // Check server-side upload limits // $postSize = Utility::phpIniSizeToBytes(ini_get('post_max_size')); $uploadSize = Utility::phpIniSizeToBytes(ini_get('upload_max_filesize')); if ($postSize < CINTIENT_AVATAR_MAX_SIZE || $uploadSize < CINTIENT_AVATAR_MAX_SIZE) { $size = max(1, CINTIENT_AVATAR_MAX_SIZE / 1024 / 1024) . 'M'; $msg = "Avatar max file size too big. Increase post_max_size and upload_max_filesize to {$size}"; SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__); echo htmlspecialchars(json_encode(array('error' => $msg)), ENT_NOQUOTES); exit; } // // Checking content length // if (!isset($_SERVER["CONTENT_LENGTH"])) { $msg = "No support for fetching CONTENT_LENGTH from server."; SystemEvent::raise(SystemEvent::ERROR, $msg, __METHOD__); echo htmlspecialchars(json_encode(array('error' => $msg)), ENT_NOQUOTES); exit; } $size = (int) $_SERVER["CONTENT_LENGTH"]; if ($size == 0) { $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; }
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'; } }
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; }
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'; } }