function display_shoutbox() { global $db, $game, $portal_action; $count = $portal_action == 'full_shoutbox' ? 30 : 10; $sql = 'SELECT sb.*, u.user_name, u.user_avatar FROM shoutbox sb INNER JOIN (user u) USING (user_id) ORDER BY timestamp DESC LIMIT 0, ' . $count; if (($sb_posts = $db->queryrowset($sql)) === false) { message(DATABASE_ERROR, 'Could not query shoutbox data'); } include_once 'include/libs/images.php'; $game->out(' <table class="style_outer" border="0" cellpadding="2" cellspacing="2" width="90%"> <tr> <td align="center"> <span class="sub_caption">Shoutbox:</span><br><br> <table width="100%" border="0" cellpadding="2" cellspacing="2" class="style_inner"> '); $count = count($sb_posts) - 1; for ($i = $count; $i >= 0; --$i) { // $game->out('<i>'.$sb_posts[$i]['player_name'].' ('.date('d.m.y H:i', $sb_posts[$i]['timestamp']).')</i>:<br>'.wordwrap($sb_posts[$i]['message'], 50, '<br>', 1).'<br>'); $game->out('<tr><td width="7%">'); if (!empty($sb_posts[$i]['user_avatar'])) { $info = scale_image($sb_posts[$i]['user_avatar'], 100 * 0.35, 166 * 0.35); if ($info[0] > 0 && $info[1] > 0) { $game->out('<img src="' . $sb_posts[$i]['user_avatar'] . '" width="' . $info[0] . '" height="' . $info[1] . '">'); } else { $game->out(' '); } } else { $game->out(' '); } $game->out('</td>'); $game->out('<td width="92%"><a href="' . parse_link('a=stats&a2=viewplayer&id=' . $sb_posts[$i]['user_id']) . '"><i>' . $sb_posts[$i]['user_name'] . '</a> (' . date('d.m.y H:i', $sb_posts[$i]['timestamp']) . ')</i>: ' . wordwrap($sb_posts[$i]['message'], 85, '<br>', 1) . '</td></tr>'); } $game->out(' </table> <br> <table width="100%" border="0" cellpadding="1" cellspacing="1"> <tr> <form name="shoutbox" method="post" action="' . parse_link('a=portal&do=post_shoutbox') . '" onSubmit="return this.submit_post.disabled = true;"> <td width="100%"> <input type="text" name="shoutbox_msg" size="80" class="field_nosize" maxlength="480" style="background-image:url(' . $game->GFX_PATH . 'template_bg4.jpg);"> <input type="submit" name="submit_post" class="button_nosize" width="100" value="' . constant($game->sprache("TEXT0")) . '" style="background-image:url(' . $game->GFX_PATH . 'template_bg4.jpg);"> </td> </form> </tr> <tr> <td> ' . ($portal_action == 'full_shoutbox' ? '<a href="' . parse_link('a=portal') . '">' . constant($game->sprache("TEXT1")) . '</a>' : '<a href="' . parse_link('a=portal&do=full_shoutbox') . '">' . constant($game->sprache("TEXT2")) . '</a>') . ' </td> </tr> </table> </td> </tr> </table> '); }
/** * Create a thumbnail from a given file * * This function will create a new thumbnail based on input file and return * path of generated thumbnail on success (FALSE othervise). If thumbnails * already exists it will return its path * * @param string $path * @param string $prefix * @param integer $max_width * @param integer $max_height * @return string */ function create($path, $prefix, $max_width, $max_height) { $destination = THUMBNAILS_PATH . '/' . $prefix . '-' . basename($path); if (is_file($destination)) { return $destination; } else { if (scale_image($path, $destination, $max_width, $max_height, IMAGETYPE_JPEG)) { return $destination; } // if } // if return false; }
function cleanse_html($atom, $href) { $html = SimpleHtmlDom\str_get_html($atom); foreach ($html->find('img') as $element) { // Skip smilies if (str_contains($element->src, '/smilies/')) { continue; } $class = 'img img-thumbnail forum-thumb'; $element->outertext = '<a href="' . $href . '"><img class="' . $class . '" src="' . scale_image($element->src, 200) . '"></a>'; } foreach ($html->find('p') as $element) { if ($element->class == 'dummy') { $element->outertext = '<small class="feed-small">' . $element->innertext . '</small>'; } } $html->save; return $html; }
function resize_image_squared($image_path, $target_width) { scale_image($image_path, $target_width, $target_width); // target_width suffices. squared image. list($width, $height) = getimagesize($image_path); crop_image($image_path, min($width, $height), min($width, $height)); }
/** * Edit Project Icon * * @param void * @return null */ function edit_icon() { if ($this->active_project->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_project->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if if (!extension_loaded('gd')) { $message = lang('<b>GD not Installed</b> - GD extension is not installed on your system. You will not be able to upload project icons, company logos and avatars!'); if ($this->request->isAsyncCall()) { echo "<p>{$message}</p>"; die; } else { $this->wireframe->addPageMessage($message, PAGE_MESSAGE_ERROR); } // if } // if if ($this->request->isSubmitted()) { if (!isset($_FILES['icon']) || !is_uploaded_file($_FILES['icon']['tmp_name'])) { $message = lang('Please select an image'); if ($this->request->isAsyncCall()) { $this->httpError(HTTP_ERR_OPERATION_FAILED, $message); } else { flash_error($message); $this->redirectToUrl($this->active_project->getEditIconUrl()); } // if } // if if (can_resize_images()) { $errors = new ValidationErrors(); do { $from = WORK_PATH . '/' . make_password(10) . '_' . $_FILES['icon']['name']; } while (is_file($from)); if (!move_uploaded_file($_FILES['icon']['tmp_name'], $from)) { $errors->addError(lang("Can't copy image to work path"), 'icon'); } else { if (FIX_UPLOAD_PERMISSION !== false) { @chmod($from, FIX_UPLOAD_PERMISSION); } // if // small avatar $to = $this->active_project->getIconPath(); $small = scale_image($from, $to, 16, 16, IMAGETYPE_GIF); // large avatar $to = $this->active_project->getIconPath(true); $large = scale_image($from, $to, 40, 40, IMAGETYPE_GIF); @unlink($from); } // if if (empty($from)) { $errors->addError('Select icon', 'icon'); } // if if ($errors->hasErrors()) { $this->smarty->assign('errors', $errors); $this->render(); } // if cache_remove('project_icons'); } // if } // if }
function upload($attachid) { global $attachmentids, $options, $attachdb; if ($attachdb[$attachid]) { if ($attachdb[$attachid]['isimage']) { $attachmentids[$attachid] = $attachdb[$attachid]['articleid']; $a_thumb_path = $attachdb[$attachid]['thumb_filepath']; $a_path = $attachdb[$attachid]['filepath']; if ($attachdb[$attachid]['thumb_filepath'] && $options['attachments_thumbs'] && file_exists(SABLOG_ROOT . $a_thumb_path)) { $attachdb[$attachid]['filepath'] = $attachdb[$attachid]['thumb_filepath']; $a_path = $a_thumb_path; } else { $imagesize = @getimagesize(SABLOG_ROOT . $a_path); $size = explode('x', strtolower($options['attachments_thumbs_size'])); $im = scale_image(array('max_width' => $size[0], 'max_height' => $size[1], 'cur_width' => $imagesize[0], 'cur_height' => $imagesize[1])); $attachdb[$attachid]['thumb_width'] = $im['img_width']; $attachdb[$attachid]['thumb_height'] = $im['img_height']; } return "<div class=\"attach\"><a href=\"" . $options['url'] . "attachment.php?id={$attachid}\" target=\"_blank\"><img src=\"" . $options['url'] . "{$a_path}\" alt=\"{$attachdb[$attachid][filename]} - 大小: {$attachdb[$attachid][filesize]} - 尺寸: {$imagesize[0]} x {$imagesize[1]} - 点击打开新窗口浏览全图\" width=\"{$attachdb[$attachid][thumb_width]}\" height=\"{$attachdb[$attachid][thumb_height]}\" /></a></div>"; } else { $attachmentids[$attachid] = $attachdb[$attachid]['articleid']; return "<a href=\"" . $options['url'] . "attachment.php?id={$attachid}\" title=\"{$attachdb[$attachid][filename]} - 大小:{$attachdb[$attachid][filesize]} - 下载次数:{$attachdb[$attachid][downloads]}\" target=\"_blank\">{$attachdb[$attachid][filename]}</a>"; } } else { return "[attach={$attachid}]"; } }
if ($mybb->user['receivepms'] != 0 && $buddy['receivepms'] != 0 && $groupscache[$buddy['usergroup']]['canusepms'] != 0) { eval("\$send_pm = \"" . $templates->get("misc_buddypopup_user_sendpm") . "\";"); } else { $send_pm = ''; } if ($buddy['lastactive']) { $last_active = $lang->sprintf($lang->last_active, my_date($mybb->settings['dateformat'], $buddy['lastactive']) . ", " . my_date($mybb->settings['timeformat'], $buddy['lastactive'])); } else { $last_active = $lang->sprintf($lang->last_active, $lang->never); } if ($buddy['avatar']) { $buddy['avatar'] = htmlspecialchars_uni($buddy['avatar']); if ($buddy['avatardimensions']) { require_once MYBB_ROOT . "inc/functions_image.php"; list($width, $height) = explode("|", $buddy['avatardimensions']); $scaled_dimensions = scale_image($width, $height, 44, 44); } else { $scaled_dimensions = array("width" => 44, "height" => 44); } } else { $buddy['avatar'] = $theme['imgdir'] . "/default_avatar.gif"; $scaled_dimensions = array("width" => 44, "height" => 44); } $margin_top = ceil((50 - $scaled_dimensions['height']) / 2); if ($buddy['lastactive'] > $timecut && ($buddy['invisible'] == 0 || $mybb->user['usergroup'] == 4) && $buddy['lastvisit'] != $buddy['lastactive']) { eval("\$buddys['online'] .= \"" . $templates->get("misc_buddypopup_user_online") . "\";"); } else { eval("\$buddys['offline'] .= \"" . $templates->get("misc_buddypopup_user_offline") . "\";"); } } } else {
function fetch_scaled_avatar($user, $max_width = 80, $max_height = 80) { $scaled_dimensions = array("width" => $max_width, "height" => $max_height); if ($user['avatar']) { if ($user['avatardimensions']) { require_once MYBB_ROOT . "inc/functions_image.php"; list($width, $height) = explode("|", $user['avatardimensions']); $scaled_dimensions = scale_image($width, $height, $max_width, $max_height); } } return array("width" => $scaled_dimensions['width'], "height" => $scaled_dimensions['height']); }
function createThumb($str_image_src, $ext, $suffix, $int_new_width, $int_new_height, $sql, $fid) { if ($ext == "jpg") { $res_src_image = imagecreatefromjpeg($str_image_src); } elseif ($ext == "png") { $res_src_image = imagecreatefrompng($str_image_src); } elseif ($ext == "gif") { $res_src_image = imagecreatefromgif($str_image_src); } $str_image_dest = basename($str_image_src); $str_image_dest = realpath('.') . '\\images\\' . substr($str_image_dest, 0, strrpos($str_image_dest, '.')) . $suffix . '.jpg'; $int_new_height_tmp = get_image_height($res_src_image, $int_new_width); $res_dst_image = imagecreatetruecolor($int_new_width, $int_new_height); // Check proportions are the same. if ($int_new_height / $int_new_width == imageSY($res_src_image) / imageSX($res_src_image)) { // Resize Image imagecopyresampled($res_dst_image, $res_src_image, 0, 0, 0, 0, $int_new_width, $int_new_height, imagesx($res_src_image), imagesy($res_src_image)); } else { // Scale Image $res_scaled_image = scale_image(&$res_src_image, $int_new_width, $int_new_height); // Crop Image crop_image(&$res_dst_image, &$res_scaled_image, $int_new_width, $int_new_height); } imagejpeg($res_dst_image, $str_image_dest); global $nooutput; if ($nooutput == '' or !isset($nooutput)) { if (!isset($_SESSION["file_info"])) { $_SESSION["file_info"] = array(); } ob_end_clean(); ob_start(); imagejpeg($res_dst_image); $imagevariable = ob_get_contents(); ob_end_clean(); $file_id = md5($_FILES["Filedata"]["tmp_name"] + rand() * 100000); $_SESSION["file_info"][$file_id] = $imagevariable; echo "FILEID:" . $file_id . "\n"; // Return the file id to the script echo "FID:" . $fid; return $res_dst_image; } }
function MakeThumbnail($upfiledir, $src, $tName, $tw = '', $th = '', $scale = true, $tDir = "thumb") { global $iCMS; $R = array(); $image = ""; $tMap = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); $tw = empty($tw) ? (int) $iCMS->config['thumbwidth'] : $tw; $th = empty($th) ? (int) $iCMS->config['thumbhight'] : $th; if ($tw && $th) { list($width, $height, $type) = @getimagesize($src); if ($width < 1 && $height < 1) { $R['width'] = $tw; $R['height'] = $th; $R['src'] = $src; return $R; } if ($width > $tw || $height > $th) { createdir($upfiledir . $tDir); if ($scale) { $im = scale_image(array("mw" => $tw, "mh" => $th, "cw" => $width, "ch" => $height)); } else { $im = array('w' => $tw, 'h' => $th); } $R['width'] = $im['w']; $R['height'] = $im['h']; $tName .= '_' . $R['width'] . 'x' . $R['height']; $img = icf($tMap[$type], $src); if ($img['res']) { $thumb = imagecreatetruecolor($im['w'], $im['h']); imagecopyresampled($thumb, $img['res'], 0, 0, 0, 0, $im['w'], $im['h'], $width, $height); PHP_VERSION != '4.3.2' && UnsharpMask($thumb); $R['src'] = $upfiledir . $tDir . "/" . $tName; __image($thumb, $img['type'], $R['src']); $R['src'] .= '.' . $img['type']; } else { $R['src'] = $src; } } else { $R['width'] = $width; $R['height'] = $height; $R['src'] = $src; } return $R; } }
/** * Generates a thumbnail based on specified dimensions (supports png, jpg, and gif) * * @param string the full path to the original image * @param string the directory path to where to save the new image * @param string the filename to save the new image as * @param integer maximum hight dimension * @param integer maximum width dimension * @return array thumbnail on success, error code 4 on failure */ function generate_thumbnail($file, $path, $filename, $maxheight, $maxwidth) { if (!function_exists("imagecreate")) { $thumb['code'] = 3; return $thumb; } $imgdesc = getimagesize($file); $imgwidth = $imgdesc[0]; $imgheight = $imgdesc[1]; $imgtype = $imgdesc[2]; $imgattr = $imgdesc[3]; $imgbits = $imgdesc['bits']; $imgchan = $imdesc['channels']; if ($imgwidth == 0 || $imgheight == 0) { $thumb['code'] = 3; return $thumb; } if ($imgwidth >= $maxwidth || $imgheight >= $maxheight) { check_thumbnail_memory($imgwidth, $imgheight, $imgtype, $imgbits, $imgchan); if ($imgtype == 3) { if (@function_exists("imagecreatefrompng")) { $im = @imagecreatefrompng($file); } } elseif ($imgtype == 2) { if (@function_exists("imagecreatefromjpeg")) { $im = @imagecreatefromjpeg($file); } } elseif ($imgtype == 1) { if (@function_exists("imagecreatefromgif")) { $im = @imagecreatefromgif($file); } } else { $thumb['code'] = 3; return $thumb; } if (!$im) { $thumb['code'] = 3; return $thumb; } $scale = scale_image($imgwidth, $imgheight, $maxwidth, $maxheight); $thumbwidth = $scale['width']; $thumbheight = $scale['height']; $thumbim = @imagecreatetruecolor($thumbwidth, $thumbheight); if (!$thumbim) { $thumbim = @imagecreate($thumbwidth, $thumbheight); $resized = true; } // Attempt to preserve the transparency if there is any $trans_color = imagecolortransparent($im); if ($trans_color >= 0 && $trans_color < imagecolorstotal($im)) { $trans = imagecolorsforindex($im, $trans_colors); $new_trans_color = imagecolorallocate($thumbim, $trans['red'], $trans['blue'], $trans['green']); imagefill($thumbim, 0, 0, $new_trans_color); imagecolortransparent($thumbim, $new_trans_color); } if (!isset($resized)) { @imagecopyresampled($thumbim, $im, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imgwidth, $imgheight); } else { @imagecopyresized($thumbim, $im, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imgwidth, $imgheight); } @imagedestroy($im); if (!function_exists("imagegif") && $imgtype == 1) { $filename = str_replace(".gif", ".jpg", $filename); } switch ($imgtype) { case 1: if (function_exists("imagegif")) { @imagegif($thumbim, $path . "/" . $filename); } else { @imagejpeg($thumbim, $path . "/" . $filename); } break; case 2: @imagejpeg($thumbim, $path . "/" . $filename); break; case 3: @imagepng($thumbim, $path . "/" . $filename); break; } @my_chmod($path . "/" . $filename, '0666'); @imagedestroy($thumbim); $thumb['code'] = 1; $thumb['filename'] = $filename; return $thumb; } else { return array("code" => 4); } }
$image_res = imagecreatefromjpeg($img_temp); break; default: $image_res = false; } if ($image_res) { $img_info = pathinfo($img_name); $img_extension = strtolower($img_info["extension"]); $img_name_only = strtolower($img_info["filename"]); $new_file_name = $img_name_only . "_" . rand(0, 9999999999) . '.' . $img_extension; $thumb_folder = $img_folder . $thumb_prefix . $new_file_name; $image_folder = $img_folder . $new_file_name; if (!scale_image($image_res, $thumb_folder, $img_type, $img_width, $img_height, $jpg_quality, 'thumb')) { die("Error creating thumb :("); } if (!scale_image($image_res, $image_folder, $img_type, $img_width, $img_height, $jpg_quality, 'original')) { die("Error creating image :("); } if (save_data($_POST, $thumb_prefix, $new_file_name, $twidth, $theight, $fwidth, $fheight)) { echo '<IMG SRC="../photos/' . $thumb_prefix . $new_file_name . '">'; } imagedestroy($image_res); } } function save_data($post, $tmb, $img, $twidth, $theight, $fwidth, $fheight) { $title = $post["image_title"]; $date = $post["image_date"]; $category = $post["image_category"]; $gear = $post["image_gear"]; $description = $post["image_description"];
for ($i = 0; $i < $user['stars']; ++$i) { $user['userstars'] .= "<img src=\"{$starimage}\" border=\"0\" alt=\"*\" />"; } } if ($user['userstars'] && $usergroup['groupimage']) { $user['userstars'] = "<br />" . $user['userstars']; } // Show avatar if ($user['avatar'] != '') { $user['avatar'] = htmlspecialchars_uni($user['avatar']); $avatar_dimensions = explode("|", $user['avatardimensions']); if ($avatar_dimensions[0] && $avatar_dimensions[1]) { list($max_width, $max_height) = explode("x", my_strtolower($mybb->settings['memberlistmaxavatarsize'])); if ($avatar_dimensions[0] > $max_width || $avatar_dimensions[1] > $max_height) { require_once MYBB_ROOT . "inc/functions_image.php"; $scaled_dimensions = scale_image($avatar_dimensions[0], $avatar_dimensions[1], $max_width, $max_height); $avatar_width_height = "width=\"{$scaled_dimensions['width']}\" height=\"{$scaled_dimensions['height']}\""; } else { $avatar_width_height = "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\""; } } eval("\$user['avatar'] = \"" . $templates->get("memberlist_user_avatar") . "\";"); } else { $user['avatar'] = ""; } $user['regdate'] = my_date($mybb->settings['dateformat'], $user['regdate']) . ", " . my_date($mybb->settings['timeformat'], $user['regdate']); $user['lastvisit'] = my_date($mybb->settings['dateformat'], $user['lastactive']) . ", " . my_date($mybb->settings['timeformat'], $user['lastactive']); $user['postnum'] = my_number_format($user['postnum']); eval("\$users .= \"" . $templates->get("memberlist_user") . "\";"); } // Do we have no results?
require_once SABLOG_ROOT . 'include/func/attachment.func.php'; $attachdb = array(); $query = $DB->query("SELECT attachmentid, articleid, dateline, filename, filetype, filesize, downloads, filepath, thumb_filepath, thumb_width, thumb_height, isimage FROM {$db_prefix}attachments WHERE articleid IN ({$aids}) ORDER BY attachmentid"); $size = explode('x', strtolower($options['attachments_thumbs_size'])); while ($attach = $DB->fetch_array($query)) { $attach['filesize'] = sizecount($attach['filesize']); $attach['dateline'] = sadate('Y-m-d H:i', $attach['dateline']); $attach['filepath'] = $options['attachments_dir'] . $attach['filepath']; $attach['thumbs'] = 0; if ($attach['isimage']) { if ($attach['thumb_filepath'] && $options['attachments_thumbs'] && file_exists(SABLOG_ROOT . $options['attachments_dir'] . $attach['thumb_filepath'])) { $attach['thumbs'] = 1; $attach['thumb_filepath'] = $options['attachments_dir'] . $attach['thumb_filepath']; } else { $imagesize = @getimagesize(SABLOG_ROOT . $attach['filepath']); $im = scale_image(array('max_width' => $size[0], 'max_height' => $size[1], 'cur_width' => $imagesize[0], 'cur_height' => $imagesize[1])); $attach['thumb_width'] = $im['img_width']; $attach['thumb_height'] = $im['img_height']; } $articledb[$attach['articleid']]['image'][$attach['attachmentid']] = $attach; } else { $articledb[$attach['articleid']]['file'][$attach['attachmentid']] = $attach; } //插入附件到文章中用的 $attachdb[$attach['attachmentid']] = $attach; } unset($attach); $DB->free_result($query); $attachmentids = array(); $aids = explode(',', $aids); foreach ($aids as $articleid) {
function show_file($file_id, $user, $success = null) { global $LSP_URL, $DATA_DIR; $dbh =& get_db(); $stmt = $dbh->prepare('SELECT licenses.name AS license, size, realname, filename, users.login, ' . 'categories.name AS category, subcategories.name AS subcategory,' . 'insert_date, update_date, description, downloads, files.id FROM files ' . 'INNER JOIN categories ON categories.id=files.category ' . 'INNER JOIN subcategories ON subcategories.id=files.subcategory ' . 'INNER JOIN users ON users.id=files.user_id ' . 'INNER JOIN licenses ON licenses.id=files.license_id ' . 'WHERE files.id=:file_id'); $stmt->bindParam(':file_id', $file_id); $found = false; if ($stmt->execute()) { while ($object = $stmt->fetch(PDO::FETCH_ASSOC)) { $title = array($object['category'], $object['subcategory'], get_file_url($file_id)); if ($success == null) { echo '<div class="col-md-9">'; create_title($title); } else { if ($success === true) { display_success("Updated successfully", $title); echo '<div class="col-md-9">'; } else { if ($success === false) { display_error("Update failed.", $title); echo '<div class="col-md-9">'; } else { display_success("{$success}", $title); } } } echo '<table class="table table-striped">'; show_basic_file_info($object, false); // Bump the download button under details block $url = htmlentities('download_file.php?file=' . $object['id'] . '&name=' . $object['filename']); echo '<tr><td><strong>Name:</strong> ' . $object['filename']; if (is_image($url)) { echo '<br><br><a href="' . $url . '"><img class="thumbnail" src="' . scale_image($DATA_DIR . $file_id, 300, parse_extension($url)) . '" alt=""></a>'; } echo '</td><td class="lsp-file-info">'; echo '<a href="' . $url . '" id="downloadbtn" class="lsp-dl-btn btn btn-primary">'; echo '<span class="fa fa-download lsp-download"></span> Download</a>'; echo '</td></tr>'; echo '<tr><td colspan="2"><div class="well"><strong>Description:</strong><p>'; echo $object['description'] != '' ? parse_links(newline_to_br($object['description'], true)) : 'No description available.'; echo '</p></div></td></tr>'; echo '<tr><td colspan="2">'; echo '<nav id="lspnav" class="navbar navbar-default"><ul class="nav navbar-nav">'; $can_edit = $object['login'] == $user || is_admin(get_user_id($user)); $can_rate = !SESSION_EMPTY(); $rate_self = $object['login'] == $user; global $LSP_URL; create_toolbar_item('Comment', "{$LSP_URL}?comment=add&file={$file_id}", 'fa-comment', $can_rate); create_toolbar_item('Edit', "{$LSP_URL}?content=update&file={$file_id}", 'fa-pencil', $can_edit); create_toolbar_item('Delete', "{$LSP_URL}?content=delete&file={$file_id}", 'fa-trash', $can_edit); $star_url = $LSP_URL . '?' . file_show_query_string() . '&rate='; create_toolbar_item(get_stars($file_id, $star_url, $rate_self ? false : $can_rate), '', null, $can_rate, $rate_self); echo '</ul></nav>'; echo '<strong>Comments:</strong>'; echo '</td></tr>'; get_comments($file_id); echo '</table></div>'; $found = true; break; } } if (!$found) { display_error('Invalid file: "' . sanitize($file_id) . '"'); } $stmt = null; $dbh = null; }
function generate_thumbnail($attach_thumb = array()) { global $settingInfo; $return = array(); $image = ""; $thumb_file = $attach_thumb['filepath']; $remap = array(1 => 'gif', 2 => 'jpg', 3 => 'png'); if ($attach_thumb['thumbswidth'] && $attach_thumb['thumbsheight']) { $filesize = GetImageSize($thumb_file); if ($filesize[0] > $attach_thumb['thumbswidth'] || $filesize[1] > $attach_thumb['thumbsheight']) { $im = scale_image(array("max_width" => $attach_thumb['thumbswidth'], "max_height" => $attach_thumb['thumbsheight'], "cur_width" => $filesize[0], "cur_height" => $filesize[1])); $return['thumbwidth'] = $im['img_width']; $return['thumbheight'] = $im['img_height']; if ($remap[$filesize[2]] == 'gif') { if (function_exists('imagecreatefromgif')) { $image = imagecreatefromgif($thumb_file); $type = 'gif'; } } else { if ($remap[$filesize[2]] == 'png') { if (function_exists('imagecreatefrompng')) { $image = imagecreatefrompng($thumb_file); $type = 'png'; } } else { if ($remap[$filesize[2]] == 'jpg') { if (function_exists('imagecreatefromjpeg')) { $image = imagecreatefromjpeg($thumb_file); $type = 'jpg'; } } } } if ($image) { $thumb = imagecreatetruecolor($im['img_width'], $im['img_height']); imagecopyresampled($thumb, $image, 0, 0, 0, 0, $im['img_width'], $im['img_height'], $filesize[0], $filesize[1]); $file_extension = $attach_thumb['extension']; $thumb_filename = str_replace("." . $file_extension, "", $attach_thumb['filename']) . '_f2s'; $curPath = str_replace($attach_thumb['filename'], "", $attach_thumb['filepath']); if ($file_extension == 'gif') { imagegif($thumb, $curPath . $thumb_filename . ".gif"); imagedestroy($thumb); } else { if ($file_extension == 'jpg') { imagejpeg($thumb, $curPath . $thumb_filename . ".jpg"); imagedestroy($thumb); } else { if ($file_extension == 'png') { imagepng($thumb, $curPath . $thumb_filename . ".png"); imagedestroy($thumb); } else { $return['thumbfilepath'] = $thumb['filepath']; return $return; } } } $return['thumbfilepath'] = $curPath . $thumb_filename . '.' . $file_extension; return $return; } else { $return['thumbwidth'] = $im['img_width']; $return['thumbheight'] = $im['img_height']; $return['thumbfilepath'] = $attach_thumb['filepath']; return $return; } } else { $return['thumbwidth'] = $filesize[0]; $return['thumbheight'] = $filesize[1]; $return['thumbfilepath'] = $attach_thumb['filepath']; return $return; } } }
$img_p = $obj->prop; } else { $logger->error("MAIL - DB error - unnumbered case"); $error_flag = 1; } } $mysqli->close(); } if ($error_flag) { error_page($x); exit(1); } $img_path = "images" . DIRECTORY_SEPARATOR; $img_fullname = $img_path . $img_name; $image = new Imagick($img_fullname); scale_image($img_p, $height, $width, $image); if (array_key_exists('text', $_GET)) { $text = $_GET['text']; $text = preg_replace('/\\|/i', "\n", $text); $pointsize = max(min($width / strlen($text) * 1.2, $height * 0.2), 5); $font = "mplus-1c-medium.ttf"; $draw = new ImagickDraw(); $draw->setFillColor(new ImagickPixel("#" . $foreground->get_hex())); $draw->setFont($font); $draw->setFontSize($pointsize); $draw->setTextUnderColor(new ImagickPixel("#" . $background->get_hex())); $draw->setGravity(imagick::GRAVITY_SOUTH); $image->annotateImage($draw, 0, 0, 0, $text); } $image->setFilename("puppy"); $output = $image->getimageblob();
/** * Save company details info * * @param void * @return void */ function index() { $brand_path = PUBLIC_PATH . '/brand'; $default_image_name = 'invoicing_logo.jpg'; $default_full_image_name = $brand_path . '/' . $default_image_name; if (!folder_is_writable($brand_path)) { $brand_folder_writable = false; $this->wireframe->addPageMessage(lang('Brand folder is not writable (:brand_folder). You will not be able to upload company logo.', array('brand_folder' => $brand_path)), PAGE_MESSAGE_WARNING); } // if $company_data = $this->request->post('company'); if (!is_foreachable($company_data)) { $company_data = array('name' => ConfigOptions::getValue('invoicing_company_name'), 'details' => ConfigOptions::getValue('invoicing_company_details')); } // if if ($this->request->isSubmitted()) { $errors = new ValidationErrors(); db_begin_work(); $company_name = trim(array_var($company_data, 'name')); $company_details = trim(array_var($company_data, 'details')); if (!$company_name || !$company_details) { if (!$company_name) { $errors->addError(lang('Company name is required'), 'company_name'); } // if if (!$company_details) { $errors->addError(lang('Company details are required'), 'company_details'); } // if } else { // copy and convert logo $logo_file = array_var($_FILES, 'company_logo', null); if ($logo_file['name']) { $pathinfo = pathinfo($logo_file['name']); do { $new_filename = make_string(30) . '.' . array_var($pathinfo, 'extension'); $new_file_full_path = $brand_path . '/' . $new_filename; } while (is_file($new_file_full_path)); if (move_uploaded_file($logo_file['tmp_name'], $new_file_full_path)) { if (FIX_UPLOAD_PERMISSION !== false) { @chmod($new_file_full_path, FIX_UPLOAD_PERMISSION); } // if scale_image($new_file_full_path, $new_file_full_path, 600, 150, IMAGETYPE_JPEG, 100); } else { $errors->addError(lang('Could not upload company logo'), 'company_logo'); } // if } // if $company_logo_url = get_company_invoicing_logo_url(); db_commit(); } // if if (!$errors->hasErrors()) { // set config options ConfigOptions::setValue('invoicing_company_name', $company_name); ConfigOptions::setValue('invoicing_company_details', $company_details); @unlink($default_full_image_name); rename($new_file_full_path, $default_full_image_name); flash_success('Company identity successfully modified'); $this->redirectTo('admin_invoicing_company_identity'); db_commit(); } else { @unlink($new_file_full_path); db_rollback(); $this->smarty->assign('errors', $errors); } // if } // if $company_logo_url = get_company_invoicing_logo_url(); $this->smarty->assign(array('company_data' => $company_data, 'company_logo_url' => $company_logo_url)); }
function &xthreads_build_thumbnail($thumbdims, $aid, $fieldname, $filename, $path, $month_dir, $img_dimensions = null) { if (empty($img_dimensions)) { //$img_dimensions = @getimagesize($path.$month_dir.$filename); $img_dimensions = @getimagesize($filename); } $update_thumbs = array('orig' => array('w' => $img_dimensions[0], 'h' => $img_dimensions[1], 'type' => $img_dimensions[2])); if (is_array($img_dimensions)) { $filterfunc = 'xthreads_imgthumb_' . $fieldname; foreach ($thumbdims as $dims => $complex) { $destname = basename(substr($filename, 0, -6) . $dims . '.thumb'); if ($complex) { require_once MYBB_ROOT . 'inc/xthreads/xt_image.php'; $img = new XTImageTransform(); if ($img->_load($filename)) { // run filter chain $filterfunc($dims, $img); // write out file & save $img->_enableWrite = true; $img->write($path . $month_dir . '/' . $destname); $update_thumbs[$dims] = array('w' => $img->WIDTH, 'h' => $img->HEIGHT, 'type' => $img->typeGD, 'file' => $month_dir . $destname); } else { // failed $update_thumbs[$dims] = array('w' => 0, 'h' => 0, 'type' => 0, 'file' => ''); } } else { $p = strpos($dims, 'x'); if (!$p) { continue; } $w = (int) substr($dims, 0, $p); $h = (int) substr($dims, $p + 1); if ($img_dimensions[0] > $w || $img_dimensions[1] > $h) { // TODO: think about using own function to apply image convolution require_once MYBB_ROOT . 'inc/functions_image.php'; $thumbnail = generate_thumbnail($filename, $path . $month_dir, $destname, $h, $w); // if it fails, there's nothing much we can do... so twiddle thumbs is the solution if ($thumbnail['code'] == 1) { $newdims = scale_image($img_dimensions[0], $img_dimensions[1], $w, $h); $update_thumbs[$dims] = array('w' => $newdims['width'], 'h' => $newdims['height'], 'type' => $img_dimensions[2], 'file' => $month_dir . $destname); } else { $update_thumbs[$dims] = array('w' => 0, 'h' => 0, 'type' => 0, 'file' => ''); } } else { // image is small (hopefully), just copy it over // TODO: maybe use hardlink instead? @copy($filename, $path . $month_dir . $destname); $update_thumbs[$dims] = array('w' => $img_dimensions[0], 'h' => $img_dimensions[1], 'type' => $img_dimensions[2], 'file' => $month_dir . $destname); } } } } global $db; $db->update_query('xtattachments', array('thumbs' => $db->escape_string(serialize($update_thumbs))), 'aid=' . $aid); return $update_thumbs; }
function getImages($fileName) { $size = getImageSize($fileName); // Determine if the filetype uploaded is supported. // TODO: Change these to constants. switch ($size[2]) { case '2': // JPEG $image = imageCreateFromJPEG($fileName); break; case '3': // PNG $image = imageCreateFromPNG($fileName); break; default: error_page(tra("The format of your uploaded image is not supported.")); } $width = $size[0]; $height = $size[1]; $smallImage = scale_image($image, $width, $height, SMALL_IMG_WIDTH, SMALL_IMG_HEIGHT); if ($width > MAX_IMG_WIDTH || $height > MAX_IMG_HEIGHT) { $image = scale_image($image, $width, $height, MAX_IMG_WIDTH, MAX_IMG_HEIGHT); } /* echo "<br><br>Image type: $size[2]"; echo "<br>Original width: $width"; echo "<br>Original height: $height"; echo "<br>Scalar: $scalar"; echo "<br>Dest width: " . ($width / $scalar); echo "<br>Dest height: " . ($height / $scalar); echo "<br>Horizontal offset: $horiz_offset"; echo "<br>Vertical offset: $vert_offset"; echo "<br><br><a href=\"images/user_profile/test.jpg\">View result</a>"; */ return array($image, $smallImage); }
function createThumb($str_image_src, $ext, $suffix, $int_new_width, $int_new_height) { if ($ext == "jpg") { $res_src_image = imagecreatefromjpeg($str_image_src); } elseif ($ext == "png") { $res_src_image = imagecreatefrompng($str_image_src); } elseif ($ext == "gif") { $res_src_image = imagecreatefromgif($str_image_src); } $str_image_dest = basename($str_image_src); $str_image_dest = 'd:/websites/myrealtornow.ca/images/' . substr($str_image_dest, 0, strrpos($str_image_dest, '.')) . $suffix . '.jpg'; $int_new_height_tmp = get_image_height($res_src_image, $int_new_width); $res_dst_image = imagecreatetruecolor($int_new_width, $int_new_height); // Check proportions are the same. if ($int_new_height / $int_new_width == imageSY($res_src_image) / imageSX($res_src_image)) { // Resize Image imagecopyresampled($res_dst_image, $res_src_image, 0, 0, 0, 0, $int_new_width, $int_new_height, imagesx($res_src_image), imagesy($res_src_image)); } else { // Scale Image $res_scaled_image = scale_image(&$res_src_image, $int_new_width, $int_new_height); // Crop Image crop_image(&$res_dst_image, &$res_scaled_image, $int_new_width, $int_new_height); } imagejpeg($res_dst_image, $str_image_dest); }
$post['user_name'] = '<b>' . $post['user_name'] . '</b>'; } $own_post = $post['user_id'] == $game->player['user_id'] ? true : false; $game->out(' <table class="style_inner" width="480" align="center" border="0" cellpadding="2" cellspacing="2"> <tr> <tr> <td width="100"><a href="' . ($post['user_id'] != 0 ? parse_link('a=stats&a2=viewplayer&id=' . $post['user_id']) : 'javascript:void(0)') . '" name="' . $post['post_id'] . '">' . $post['user_name'] . '</a></td> <td width="335"><i>' . date('d.m.y H:i:s', $post['post_date']) . '</i>' . (!empty($post['post_title']) ? ' - <b>' . htmlspecialchars(stripslashes($post['post_title'])) . '</b>' : '') . '</td> <td width="45" align="right">' . ($is_mod || $own_post && $post['post_id'] != $thread['thread_first_post_id'] ? '[<a href="' . parse_link('a=alliance_board&delete_post=' . $post['post_id'] . $override_str) . '">X</a>]' : '') . ' ' . ($is_mod || $own_post ? '[<a href="' . parse_link('a=alliance_board&edit_post=' . $post['post_id'] . $override_str) . '">E</a>]' : '') . '</td> </tr> <tr height="1"><td colspan="3"></td></tr> <tr> <td width="70" valign="top">'); if (!empty($post['user_avatar'])) { $info = scale_image($post['user_avatar'], 100 * 0.6, 166 * 0.6); if ($info[0] > 0 && $info[1] > 0) { $game->out('<img src="' . $post['user_avatar'] . '" width="' . $info[0] . '" height="' . $info[1] . '">'); } else { $game->out(' '); } } else { $game->out(' '); } // 24/10/08 - AC: Ok, check status but also check if he's still in the alliance if ($post['user_alliance'] == $post['alliance_id']) { if ($post['user_alliance_status'] == 2) { $game->out('<br><font color="yellow">' . constant($game->sprache("TEXT28")) . '</font>'); } elseif ($post['user_alliance_status'] == 3) { $game->out('<br><font color="red">' . constant($game->sprache("TEXT29")) . '</font>'); } elseif ($post['user_alliance_status'] == 4) {
function api_get_entitities(&$text, $bbcode) { /* To-Do: * Links at the first character of the post */ $a = get_app(); $include_entities = strtolower(x($_REQUEST, 'include_entities') ? $_REQUEST['include_entities'] : "false"); if ($include_entities != "true") { preg_match_all("/\\[img](.*?)\\[\\/img\\]/ism", $bbcode, $images); foreach ($images[1] as $image) { $replace = proxy_url($image); $text = str_replace($image, $replace, $text); } return array(); } $bbcode = bb_CleanPictureLinks($bbcode); // Change pure links in text to bbcode uris $bbcode = preg_replace("/([^\\]\\='" . '"' . "]|^)(https?\\:\\/\\/[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\_\\~\\#\\%\$\\!\\+\\,]+)/ism", '$1[url=$2]$2[/url]', $bbcode); $entities = array(); $entities["hashtags"] = array(); $entities["symbols"] = array(); $entities["urls"] = array(); $entities["user_mentions"] = array(); $URLSearchString = "^\\[\\]"; $bbcode = preg_replace("/#\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '#$2', $bbcode); $bbcode = preg_replace("/\\[bookmark\\=([{$URLSearchString}]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url=$1]$2[/url]', $bbcode); //$bbcode = preg_replace("/\[url\](.*?)\[\/url\]/ism",'[url=$1]$1[/url]',$bbcode); $bbcode = preg_replace("/\\[video\\](.*?)\\[\\/video\\]/ism", '[url=$1]$1[/url]', $bbcode); $bbcode = preg_replace("/\\[youtube\\]([A-Za-z0-9\\-_=]+)(.*?)\\[\\/youtube\\]/ism", '[url=https://www.youtube.com/watch?v=$1]https://www.youtube.com/watch?v=$1[/url]', $bbcode); $bbcode = preg_replace("/\\[youtube\\](.*?)\\[\\/youtube\\]/ism", '[url=$1]$1[/url]', $bbcode); $bbcode = preg_replace("/\\[vimeo\\]([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[url=https://vimeo.com/$1]https://vimeo.com/$1[/url]', $bbcode); $bbcode = preg_replace("/\\[vimeo\\](.*?)\\[\\/vimeo\\]/ism", '[url=$1]$1[/url]', $bbcode); $bbcode = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '[img]$3[/img]', $bbcode); //preg_match_all("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $bbcode, $urls1); preg_match_all("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", $bbcode, $urls); $ordered_urls = array(); foreach ($urls[1] as $id => $url) { //$start = strpos($text, $url, $offset); $start = iconv_strpos($text, $url, 0, "UTF-8"); if (!($start === false)) { $ordered_urls[$start] = array("url" => $url, "title" => $urls[2][$id]); } } ksort($ordered_urls); $offset = 0; //foreach ($urls[1] AS $id=>$url) { foreach ($ordered_urls as $url) { if (substr($url["title"], 0, 7) != "http://" and substr($url["title"], 0, 8) != "https://" and !strpos($url["title"], "http://") and !strpos($url["title"], "https://")) { $display_url = $url["title"]; } else { $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url["url"]); $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url); if (strlen($display_url) > 26) { $display_url = substr($display_url, 0, 25) . "…"; } } //$start = strpos($text, $url, $offset); $start = iconv_strpos($text, $url["url"], $offset, "UTF-8"); if (!($start === false)) { $entities["urls"][] = array("url" => $url["url"], "expanded_url" => $url["url"], "display_url" => $display_url, "indices" => array($start, $start + strlen($url["url"]))); $offset = $start + 1; } } preg_match_all("/\\[img](.*?)\\[\\/img\\]/ism", $bbcode, $images); $ordered_images = array(); foreach ($images[1] as $image) { //$start = strpos($text, $url, $offset); $start = iconv_strpos($text, $image, 0, "UTF-8"); if (!($start === false)) { $ordered_images[$start] = $image; } } //$entities["media"] = array(); $offset = 0; foreach ($ordered_images as $url) { $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url); $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url); if (strlen($display_url) > 26) { $display_url = substr($display_url, 0, 25) . "…"; } $start = iconv_strpos($text, $url, $offset, "UTF-8"); if (!($start === false)) { $image = get_photo_info($url); if ($image) { // If image cache is activated, then use the following sizes: // thumb (150), small (340), medium (600) and large (1024) if (!get_config("system", "proxy_disabled")) { $media_url = proxy_url($url); $sizes = array(); $scale = scale_image($image[0], $image[1], 150); $sizes["thumb"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); if ($image[0] > 150 or $image[1] > 150) { $scale = scale_image($image[0], $image[1], 340); $sizes["small"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); } $scale = scale_image($image[0], $image[1], 600); $sizes["medium"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); if ($image[0] > 600 or $image[1] > 600) { $scale = scale_image($image[0], $image[1], 1024); $sizes["large"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); } } else { $media_url = $url; $sizes["medium"] = array("w" => $image[0], "h" => $image[1], "resize" => "fit"); } $entities["media"][] = array("id" => $start + 1, "id_str" => (string) $start + 1, "indices" => array($start, $start + strlen($url)), "media_url" => normalise_link($media_url), "media_url_https" => $media_url, "url" => $url, "display_url" => $display_url, "expanded_url" => $url, "type" => "photo", "sizes" => $sizes); } $offset = $start + 1; } } return $entities; }
$subnav = '《' . $article['title'] . '》的附件'; $sql .= " AND a.articleid='{$articleid}'"; } $view = in_array($view, array('image', 'file')) ? $view : ''; $total = $DB->result($DB->query("SELECT COUNT(attachmentid) FROM {$db_prefix}attachments a " . $sql), 0); if ($total) { $multipage = multi($total, $pagenum, $page, 'cp.php?job=attachment&action=list&view=' . $view . '&articleid=' . $articleid); $query = $DB->query("SELECT a.*,ar.title as article,ar.visible FROM {$db_prefix}attachments a LEFT JOIN {$db_prefix}articles ar ON (ar.articleid=a.articleid) {$sql} ORDER BY a.attachmentid DESC LIMIT {$start_limit}, {$pagenum}"); $attachdb = array(); while ($attach = $DB->fetch_array($query)) { if ($attach['isimage']) { if (!$attach['thumb_filepath']) { $attach['thumb_filepath'] = $attach['filepath']; } $imsize = @getimagesize($attachdir . $attach['filepath']); $im = scale_image(array('max_width' => 320, 'max_height' => 240, 'cur_width' => $imsize[0], 'cur_height' => $imsize[1])); $attach['thumb_width'] = $im['img_width']; $attach['thumb_height'] = $im['img_height']; $attach['thumb_filepath'] = $options['url'] . $options['attachments_dir'] . $attach['thumb_filepath']; } $attach['filename'] = htmlspecialchars($attach['filename']); $attach['filepath'] = htmlspecialchars($attach['filepath']); $attach['filesize'] = sizecount($attach['filesize']); $attach['filetype'] = htmlspecialchars($attach['filetype']); $attach['dateline'] = date("Y-m-d H:i", $attach['dateline']); $pathdata = explode('/', $attach['filepath']); if (count($pathdata) == 2) { $attach['subdir'] = '根目录'; } else { $attach['subdir'] = $pathdata[1]; }
/** * Build a post bit * * @param array The post data * @param int The type of post bit we're building (1 = preview, 2 = pm, 3 = announcement, else = post) * @return string The built post bit */ function build_postbit($post, $post_type = 0) { global $db, $altbg, $theme, $mybb, $postcounter; global $titlescache, $page, $templates, $forumpermissions, $attachcache; global $lang, $ismod, $inlinecookie, $inlinecount, $groupscache, $fid; global $plugins, $parser, $cache, $ignored_users, $hascustomtitle; $hascustomtitle = 0; // Set default values for any fields not provided here foreach (array('subject_extra', 'attachments', 'button_rep', 'button_warn', 'button_reply_pm', 'button_replyall_pm', 'button_forward_pm', 'button_delete_pm') as $post_field) { if (empty($post[$post_field])) { $post[$post_field] = ''; } } // Set up the message parser if it doesn't already exist. if (!$parser) { require_once MYBB_ROOT . "inc/class_parser.php"; $parser = new postParser(); } $unapproved_shade = ''; if ($post['visible'] == 0 && $post_type == 0) { $altbg = $unapproved_shade = 'trow_shaded'; } elseif ($altbg == 'trow1') { $altbg = 'trow2'; } else { $altbg = 'trow1'; } $post['fid'] = $fid; switch ($post_type) { case 1: // Message preview global $forum; $parser_options['allow_html'] = $forum['allowhtml']; $parser_options['allow_mycode'] = $forum['allowmycode']; $parser_options['allow_smilies'] = $forum['allowsmilies']; $parser_options['allow_imgcode'] = $forum['allowimgcode']; $parser_options['allow_videocode'] = $forum['allowvideocode']; $parser_options['me_username'] = $post['username']; $parser_options['filter_badwords'] = 1; $id = 0; break; case 2: // Private message global $message, $pmid; $parser_options['allow_html'] = $mybb->settings['pmsallowhtml']; $parser_options['allow_mycode'] = $mybb->settings['pmsallowmycode']; $parser_options['allow_smilies'] = $mybb->settings['pmsallowsmilies']; $parser_options['allow_imgcode'] = $mybb->settings['pmsallowimgcode']; $parser_options['allow_videocode'] = $mybb->settings['pmsallowvideocode']; $parser_options['me_username'] = $post['username']; $parser_options['filter_badwords'] = 1; $id = $pmid; break; case 3: // Announcement global $announcementarray, $message; $parser_options['allow_html'] = $announcementarray['allowhtml']; $parser_options['allow_mycode'] = $announcementarray['allowmycode']; $parser_options['allow_smilies'] = $announcementarray['allowsmilies']; $parser_options['allow_imgcode'] = 1; $parser_options['allow_videocode'] = 1; $parser_options['me_username'] = $post['username']; $parser_options['filter_badwords'] = 1; break; default: // Regular post global $forum, $thread, $tid; $oldforum = $forum; $id = intval($post['pid']); $parser_options['allow_html'] = $forum['allowhtml']; $parser_options['allow_mycode'] = $forum['allowmycode']; $parser_options['allow_smilies'] = $forum['allowsmilies']; $parser_options['allow_imgcode'] = $forum['allowimgcode']; $parser_options['allow_videocode'] = $forum['allowvideocode']; $parser_options['filter_badwords'] = 1; if (!$post['username']) { $post['username'] = $lang->guest; } if ($post['userusername']) { $parser_options['me_username'] = $post['userusername']; } else { $parser_options['me_username'] = $post['username']; } break; } // Sanatize our custom profile fields for use in templates, if people choose to use them foreach ($post as $post_field => $field_value) { if (substr($post_field, 0, 3) != 'fid') { continue; } $post[$post_field] = htmlspecialchars_uni($field_value); } if (!$postcounter) { // Used to show the # of the post if ($page > 1) { if (!$mybb->settings['postsperpage'] || (int) $mybb->settings['postsperpage'] < 1) { $mybb->settings['postsperpage'] = 20; } $postcounter = $mybb->settings['postsperpage'] * ($page - 1); } else { $postcounter = 0; } $post_extra_style = "border-top-width: 0;"; } elseif ($mybb->input['mode'] == "threaded") { $post_extra_style = "border-top-width: 0;"; } else { $post_extra_style = "margin-top: 5px;"; } if (!$altbg) { // Define the alternate background colour if this is the first post $altbg = "trow1"; } $postcounter++; // Format the post date and time using my_date $post['postdate'] = my_date($mybb->settings['dateformat'], $post['dateline']); $post['posttime'] = my_date($mybb->settings['timeformat'], $post['dateline']); // Dont want any little 'nasties' in the subject $post['subject'] = $parser->parse_badwords($post['subject']); // Pm's have been htmlspecialchars_uni()'ed already. if ($post_type != 2) { $post['subject'] = htmlspecialchars_uni($post['subject']); } if (empty($post['subject'])) { $post['subject'] = ' '; } $post['author'] = $post['uid']; // Get the usergroup if ($post['userusername']) { if (!$post['displaygroup']) { $post['displaygroup'] = $post['usergroup']; } $usergroup = $groupscache[$post['displaygroup']]; } else { $usergroup = $groupscache[1]; } if (!is_array($titlescache)) { $cached_titles = $cache->read("usertitles"); if (!empty($cached_titles)) { foreach ($cached_titles as $usertitle) { $titlescache[$usertitle['posts']] = $usertitle; } } if (is_array($titlescache)) { krsort($titlescache); } unset($usertitle, $cached_titles); } // Work out the usergroup/title stuff $post['groupimage'] = ''; if (!empty($usergroup['image'])) { $language = $mybb->settings['bblanguage']; if (!empty($mybb->user['language'])) { $language = $mybb->user['language']; } $usergroup['image'] = str_replace("{lang}", $language, $usergroup['image']); $usergroup['image'] = str_replace("{theme}", $theme['imgdir'], $usergroup['image']); eval("\$post['groupimage'] = \"" . $templates->get("postbit_groupimage") . "\";"); if ($mybb->settings['postlayout'] == "classic") { $post['groupimage'] .= "<br />"; } } if ($post['userusername']) { // This post was made by a registered user $post['username'] = $post['userusername']; $post['profilelink_plain'] = get_profile_link($post['uid']); $post['username_formatted'] = format_name($post['username'], $post['usergroup'], $post['displaygroup']); $post['profilelink'] = build_profile_link($post['username_formatted'], $post['uid']); if (trim($post['usertitle']) != "") { $hascustomtitle = 1; } if ($usergroup['usertitle'] != "" && !$hascustomtitle) { $post['usertitle'] = $usergroup['usertitle']; } elseif (is_array($titlescache) && !$usergroup['usertitle']) { reset($titlescache); foreach ($titlescache as $key => $titleinfo) { if ($post['postnum'] >= $key) { if (!$hascustomtitle) { $post['usertitle'] = $titleinfo['title']; } $post['stars'] = $titleinfo['stars']; $post['starimage'] = $titleinfo['starimage']; break; } } } if ($usergroup['stars']) { $post['stars'] = $usergroup['stars']; } if (empty($post['starimage'])) { $post['starimage'] = $usergroup['starimage']; } if ($post['starimage'] && $post['stars']) { // Only display stars if we have an image to use... $post['starimage'] = str_replace("{theme}", $theme['imgdir'], $post['starimage']); $post['userstars'] = ''; for ($i = 0; $i < $post['stars']; ++$i) { $post['userstars'] .= "<img src=\"" . $post['starimage'] . "\" border=\"0\" alt=\"*\" />"; } $post['userstars'] .= "<br />"; } $postnum = $post['postnum']; $post['postnum'] = my_number_format($post['postnum']); // Determine the status to show for the user (Online/Offline/Away) $timecut = TIME_NOW - $mybb->settings['wolcutoff']; if ($post['lastactive'] > $timecut && ($post['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1) && $post['lastvisit'] != $post['lastactive']) { eval("\$post['onlinestatus'] = \"" . $templates->get("postbit_online") . "\";"); } else { if ($post['away'] == 1 && $mybb->settings['allowaway'] != 0) { eval("\$post['onlinestatus'] = \"" . $templates->get("postbit_away") . "\";"); } else { eval("\$post['onlinestatus'] = \"" . $templates->get("postbit_offline") . "\";"); } } if ($post['avatar'] != "" && ($mybb->user['showavatars'] != 0 || !$mybb->user['uid'])) { $post['avatar'] = htmlspecialchars_uni($post['avatar']); $avatar_dimensions = explode("|", $post['avatardimensions']); if ($avatar_dimensions[0] && $avatar_dimensions[1]) { list($max_width, $max_height) = explode("x", my_strtolower($mybb->settings['postmaxavatarsize'])); if ($avatar_dimensions[0] > $max_width || $avatar_dimensions[1] > $max_height) { require_once MYBB_ROOT . "inc/functions_image.php"; $scaled_dimensions = scale_image($avatar_dimensions[0], $avatar_dimensions[1], $max_width, $max_height); $avatar_width_height = "width=\"{$scaled_dimensions['width']}\" height=\"{$scaled_dimensions['height']}\""; } else { $avatar_width_height = "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\""; } } eval("\$post['useravatar'] = \"" . $templates->get("postbit_avatar") . "\";"); $post['avatar_padding'] = "padding-right: 10px;"; } else { $post['useravatar'] = ''; $post['avatar_padding'] = ''; } eval("\$post['button_find'] = \"" . $templates->get("postbit_find") . "\";"); if ($mybb->settings['enablepms'] == 1 && $post['receivepms'] != 0 && $mybb->usergroup['cansendpms'] == 1 && my_strpos("," . $post['ignorelist'] . ",", "," . $mybb->user['uid'] . ",") === false) { eval("\$post['button_pm'] = \"" . $templates->get("postbit_pm") . "\";"); } if ($post_type != 3 && $mybb->settings['enablereputation'] == 1 && $mybb->settings['postrep'] == 1 && $mybb->usergroup['cangivereputations'] == 1 && $usergroup['usereputationsystem'] == 1 && ($mybb->settings['posrep'] || $mybb->settings['neurep'] || $mybb->settings['negrep']) && $post['uid'] != $mybb->user['uid']) { if (!$post['pid']) { $post['pid'] = 0; } eval("\$post['button_rep'] = \"" . $templates->get("postbit_rep_button") . "\";"); } if ($post['website'] != "") { $post['website'] = htmlspecialchars_uni($post['website']); eval("\$post['button_www'] = \"" . $templates->get("postbit_www") . "\";"); } else { $post['button_www'] = ""; } if ($post['hideemail'] != 1 && $mybb->usergroup['cansendemail'] == 1) { eval("\$post['button_email'] = \"" . $templates->get("postbit_email") . "\";"); } else { $post['button_email'] = ""; } $post['userregdate'] = my_date($mybb->settings['regdateformat'], $post['regdate']); // Work out the reputation this user has (only show if not announcement) if ($post_type != 3 && $usergroup['usereputationsystem'] != 0 && $mybb->settings['enablereputation'] == 1) { $post['userreputation'] = get_reputation($post['reputation'], $post['uid']); eval("\$post['replink'] = \"" . $templates->get("postbit_reputation") . "\";"); } // Showing the warning level? (only show if not announcement) if ($post_type != 3 && $mybb->settings['enablewarningsystem'] != 0 && $usergroup['canreceivewarnings'] != 0 && ($mybb->usergroup['canwarnusers'] != 0 || $mybb->user['uid'] == $post['uid'] && $mybb->settings['canviewownwarning'] != 0)) { $warning_level = round($post['warningpoints'] / $mybb->settings['maxwarningpoints'] * 100); if ($warning_level > 100) { $warning_level = 100; } $warning_level = get_colored_warning_level($warning_level); // If we can warn them, it's not the same person, and we're in a PM or a post. if ($mybb->usergroup['canwarnusers'] != 0 && $post['uid'] != $mybb->user['uid'] && ($post_type == 0 || $post_type == 2)) { eval("\$post['button_warn'] = \"" . $templates->get("postbit_warn") . "\";"); $warning_link = "warnings.php?uid={$post['uid']}"; } else { $warning_link = "usercp.php"; } eval("\$post['warninglevel'] = \"" . $templates->get("postbit_warninglevel") . "\";"); } eval("\$post['user_details'] = \"" . $templates->get("postbit_author_user") . "\";"); } else { // Message was posted by a guest or an unknown user $post['profilelink'] = format_name($post['username'], 1); if ($usergroup['usertitle']) { $post['usertitle'] = $usergroup['usertitle']; } else { $post['usertitle'] = $lang->guest; } $usergroup['title'] = $lang->na; $post['userregdate'] = $lang->na; $post['postnum'] = $lang->na; $post['button_profile'] = ''; $post['button_email'] = ''; $post['button_www'] = ''; $post['signature'] = ''; $post['button_pm'] = ''; $post['button_find'] = ''; $post['onlinestatus'] = ''; $post['replink'] = ''; eval("\$post['user_details'] = \"" . $templates->get("postbit_author_guest") . "\";"); } $post['button_edit'] = ''; $post['button_quickdelete'] = ''; $post['button_quote'] = ''; $post['button_quickquote'] = ''; $post['button_report'] = ''; // For private messages, fetch the reply/forward/delete icons if ($post_type == 2 && $post['pmid']) { global $replyall; eval("\$post['button_reply_pm'] = \"" . $templates->get("postbit_reply_pm") . "\";"); eval("\$post['button_forward_pm'] = \"" . $templates->get("postbit_forward_pm") . "\";"); eval("\$post['button_delete_pm'] = \"" . $templates->get("postbit_delete_pm") . "\";"); if ($replyall == true) { eval("\$post['button_replyall_pm'] = \"" . $templates->get("postbit_replyall_pm") . "\";"); } } if (!$post_type) { // Figure out if we need to show an "edited by" message $post['editedmsg'] = ''; if ($post['edituid'] != 0 && $post['edittime'] != 0 && $post['editusername'] != "" && ($mybb->settings['showeditedby'] != 0 && $usergroup['cancp'] == 0 || $mybb->settings['showeditedbyadmin'] != 0 && $usergroup['cancp'] == 1)) { $post['editdate'] = my_date($mybb->settings['dateformat'], $post['edittime']); $post['edittime'] = my_date($mybb->settings['timeformat'], $post['edittime']); $post['editnote'] = $lang->sprintf($lang->postbit_edited, $post['editdate'], $post['edittime']); $post['editedprofilelink'] = build_profile_link($post['editusername'], $post['edituid']); eval("\$post['editedmsg'] = \"" . $templates->get("postbit_editedby") . "\";"); } if ((is_moderator($fid, "caneditposts") || $forumpermissions['caneditposts'] == 1 && $mybb->user['uid'] == $post['uid']) && $mybb->user['uid'] != 0) { eval("\$post['button_edit'] = \"" . $templates->get("postbit_edit") . "\";"); } // Quick Delete button $can_delete = 0; if ($mybb->user['uid'] == $post['uid']) { if ($forumpermissions['candeletethreads'] == 1 && $postcounter == 1) { $can_delete = 1; } else { if ($forumpermissions['candeleteposts'] == 1 && $postcounter != 1) { $can_delete = 1; } } } if ((is_moderator($fid, "candeleteposts") || $can_delete == 1) && $mybb->user['uid'] != 0) { eval("\$post['button_quickdelete'] = \"" . $templates->get("postbit_quickdelete") . "\";"); } // Inline moderation stuff if ($ismod) { if (isset($mybb->cookies[$inlinecookie]) && my_strpos($mybb->cookies[$inlinecookie], "|" . $post['pid'] . "|")) { $inlinecheck = "checked=\"checked\""; $inlinecount++; } else { $inlinecheck = ""; } eval("\$post['inlinecheck'] = \"" . $templates->get("postbit_inlinecheck") . "\";"); if ($post['visible'] == 0) { $invisiblepost = 1; } } else { $post['inlinecheck'] = ""; } $post['postlink'] = get_post_link($post['pid'], $post['tid']); eval("\$post['posturl'] = \"" . $templates->get("postbit_posturl") . "\";"); global $forum, $thread; if ($forum['open'] != 0 && ($thread['closed'] != 1 || is_moderator($forum['fid']))) { eval("\$post['button_quote'] = \"" . $templates->get("postbit_quote") . "\";"); } if ($forumpermissions['canpostreplys'] != 0 && ($thread['closed'] != 1 || is_moderator($fid)) && $mybb->settings['multiquote'] != 0 && $forum['open'] != 0 && !$post_type) { eval("\$post['button_multiquote'] = \"" . $templates->get("postbit_multiquote") . "\";"); } if ($mybb->user['uid'] != "0") { eval("\$post['button_report'] = \"" . $templates->get("postbit_report") . "\";"); } if ($mybb->settings['logip'] != "no") { if ($mybb->settings['logip'] == "show") { eval("\$post['iplogged'] = \"" . $templates->get("postbit_iplogged_show") . "\";"); } else { if ($mybb->settings['logip'] == "hide" && is_moderator($fid, "canviewips")) { eval("\$post['iplogged'] = \"" . $templates->get("postbit_iplogged_hiden") . "\";"); } else { $post['iplogged'] = ""; } } } else { $post['iplogged'] = ""; } } elseif ($post_type == 3) { if ($mybb->usergroup['issupermod'] == 1 || is_moderator($fid)) { eval("\$post['button_edit'] = \"" . $templates->get("announcement_edit") . "\";"); eval("\$post['button_quickdelete'] = \"" . $templates->get("announcement_quickdelete") . "\";"); } } if ($post['smilieoff'] == 1) { $parser_options['allow_smilies'] = 0; } // If we have incoming search terms to highlight - get it done. if (!empty($mybb->input['highlight'])) { $parser_options['highlight'] = $mybb->input['highlight']; $post['subject'] = $parser->highlight_message($post['subject'], $parser_options['highlight']); } $post['message'] = $parser->parse_message($post['message'], $parser_options); get_post_attachments($id, $post); if ($post['includesig'] != 0 && $post['username'] && $post['signature'] != "" && ($mybb->user['uid'] == 0 || $mybb->user['showsigs'] != 0) && ($post['suspendsignature'] == 0 || $post['suspendsignature'] == 1 && $post['suspendsigtime'] != 0 && $post['suspendsigtime'] < TIME_NOW) && $usergroup['canusesig'] == 1 && ($usergroup['canusesigxposts'] == 0 || $usergroup['canusesigxposts'] > 0 && $postnum > $usergroup['canusesigxposts'])) { $sig_parser = array("allow_html" => $mybb->settings['sightml'], "allow_mycode" => $mybb->settings['sigmycode'], "allow_smilies" => $mybb->settings['sigsmilies'], "allow_imgcode" => $mybb->settings['sigimgcode'], "me_username" => $post['username'], "filter_badwords" => 1); if ($usergroup['signofollow']) { $sig_parser['nofollow_on'] = 1; } $post['signature'] = $parser->parse_message($post['signature'], $sig_parser); eval("\$post['signature'] = \"" . $templates->get("postbit_signature") . "\";"); } else { $post['signature'] = ""; } $icon_cache = $cache->read("posticons"); if ($post['icon'] > 0 && $icon_cache[$post['icon']]) { $icon = $icon_cache[$post['icon']]; $icon['path'] = htmlspecialchars_uni($icon['path']); $icon['name'] = htmlspecialchars_uni($icon['name']); $post['icon'] = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" style=\"vertical-align: middle;\" /> "; } else { $post['icon'] = ""; } $post_visibility = ''; switch ($post_type) { case 1: // Message preview $post = $plugins->run_hooks("postbit_prev", $post); break; case 2: // Private message $post = $plugins->run_hooks("postbit_pm", $post); break; case 3: // Announcement $post = $plugins->run_hooks("postbit_announcement", $post); break; default: // Regular post $post = $plugins->run_hooks("postbit", $post); // Is this author on the ignore list of the current user? Hide this post $ignore_bit = ''; if (is_array($ignored_users) && $post['uid'] != 0 && isset($ignored_users[$post['uid']]) && $ignored_users[$post['uid']] == 1) { $ignored_message = $lang->sprintf($lang->postbit_currently_ignoring_user, $post['username']); eval("\$ignore_bit = \"" . $templates->get("postbit_ignored") . "\";"); $post_visibility = "display: none;"; } break; } if ($mybb->settings['postlayout'] == "classic") { eval("\$postbit = \"" . $templates->get("postbit_classic") . "\";"); } else { eval("\$postbit = \"" . $templates->get("postbit") . "\";"); } $GLOBALS['post'] = ""; return $postbit; }
/** * Formats an avatar to a certain dimension * * @param string $avatar The avatar file name * @param string $dimensions Dimensions of the avatar, width x height (e.g. 44|44) * @param string $max_dimensions The maximum dimensions of the formatted avatar * @return array Information for the formatted avatar */ function format_avatar($avatar, $dimensions = '', $max_dimensions = '') { global $mybb; static $avatars; if (!isset($avatars)) { $avatars = array(); } if (!$avatar) { // Default avatar $avatar = $mybb->settings['useravatar']; $dimensions = $mybb->settings['useravatardims']; } if (!$max_dimensions) { $max_dimensions = $mybb->settings['maxavatardims']; } // An empty key wouldn't work so we need to add a fall back $key = $dimensions; if (empty($key)) { $key = 'default'; } $key2 = $max_dimensions; if (empty($key2)) { $key2 = 'default'; } if (isset($avatars[$avatar][$key][$key2])) { return $avatars[$avatar][$key][$key2]; } $avatar_width_height = ''; if ($dimensions) { $dimensions = explode("|", $dimensions); if ($dimensions[0] && $dimensions[1]) { list($max_width, $max_height) = explode('x', $max_dimensions); if (!empty($max_dimensions) && ($dimensions[0] > $max_width || $dimensions[1] > $max_height)) { require_once MYBB_ROOT . "inc/functions_image.php"; $scaled_dimensions = scale_image($dimensions[0], $dimensions[1], $max_width, $max_height); $avatar_width_height = "width=\"{$scaled_dimensions['width']}\" height=\"{$scaled_dimensions['height']}\""; } else { $avatar_width_height = "width=\"{$dimensions[0]}\" height=\"{$dimensions[1]}\""; } } } $avatars[$avatar][$key][$key2] = array('image' => htmlspecialchars_uni($mybb->get_asset_url($avatar)), 'width_height' => $avatar_width_height); return $avatars[$avatar][$key][$key2]; }