if ($ext == 'gz' || $ext == 'sql') {
                $backups[@filemtime(MYBB_ADMIN_DIR . 'backups/' . $file)] = array("file" => $file, "time" => @filemtime(MYBB_ADMIN_DIR . 'backups/' . $file), "type" => $ext);
            }
        }
    }
    $count = count($backups);
    krsort($backups);
    $table = new Table();
    $table->construct_header($lang->backup_filename);
    $table->construct_header($lang->file_size, array("class" => "align_center"));
    $table->construct_header($lang->creation_date);
    $table->construct_header($lang->controls, array("class" => "align_center"));
    foreach ($backups as $backup) {
        if ($backup['time']) {
            $time = my_date($mybb->settings['dateformat'] . ", " . $mybb->settings['timeformat'], $backup['time']);
        } else {
            $time = "-";
        }
        $table->construct_cell("<a href=\"index.php?module=tools-backupdb&amp;action=dlbackup&amp;file={$backup['file']}\">{$backup['file']}</a>");
        $table->construct_cell(get_friendly_size(filesize(MYBB_ADMIN_DIR . 'backups/' . $backup['file'])), array("class" => "align_center"));
        $table->construct_cell($time);
        $table->construct_cell("<a href=\"index.php?module=tools-backupdb&amp;action=backup&amp;action=delete&amp;file={$backup['file']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_backup_deletion}')\">{$lang->delete}</a>", array("class" => "align_center"));
        $table->construct_row();
    }
    if ($count == 0) {
        $table->construct_cell($lang->no_backups, array('colspan' => 4));
        $table->construct_row();
    }
    $table->output($lang->existing_database_backups);
    $page->output_footer();
}
Пример #2
0
 /**
  * Output the page footer.
  */
 function output_footer($quit = true)
 {
     global $mybb, $maintimer, $db, $lang, $plugins;
     $plugins->run_hooks("admin_page_output_footer");
     $memory_usage = get_friendly_size(get_memory_usage());
     $totaltime = $maintimer->stop();
     $querycount = $db->query_count;
     echo "\t\t\t</div>\n";
     echo "\t\t</div>\n";
     echo "\t<br style=\"clear: both;\" />";
     echo "\t<br style=\"clear: both;\" />";
     echo "\t</div>\n";
     echo "<div id=\"footer\"><p class=\"generation\">" . $lang->sprintf($lang->generated_in, $totaltime, $querycount, $memory_usage) . "</p><p class=\"powered\">Powered By MyBB. &copy; " . COPY_YEAR . " MyBB Group. All Rights Reserved.</p></div>\n";
     if ($mybb->debug_mode) {
         echo $db->explain;
     }
     echo "</div>\n";
     echo "</body>\n";
     echo "</html>\n";
     if ($quit != false) {
         exit;
     }
 }
Пример #3
0
function build_attachment_row($attachment, &$table, $use_form = false)
{
    global $mybb, $form;
    $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
    // Here we do a bit of detection, we want to automatically check for removal any missing attachments and any not assigned to a post uploaded > 24hours ago
    // Check if the attachment exists in the file system
    $checked = false;
    $title = $cell_class = '';
    if (!file_exists(MYBB_ROOT . $mybb->settings['uploadspath'] . "/{$attachment['attachname']}")) {
        $cell_class = "bad_attachment";
        $title = $lang->error_not_found;
        $checked = true;
    } elseif (!$attachment['pid'] && $attachment['dateuploaded'] < TIME_NOW - 60 * 60 * 24 && $attachment['dateuploaded'] != 0) {
        $cell_class = "bad_attachment";
        $title = $lang->error_not_attached;
        $checked = true;
    } else {
        if (!$attachment['tid'] && $attachment['pid']) {
            $cell_class = "bad_attachment";
            $title = $lang->error_does_not_exist;
            $checked = true;
        } else {
            if ($attachment['visible'] == 0) {
                $cell_class = "invisible_attachment";
            }
        }
    }
    if ($cell_class) {
        $cell_class .= " align_center";
    } else {
        $cell_class = "align_center";
    }
    if ($use_form == true && is_object($form)) {
        $table->construct_cell($form->generate_check_box('aids[]', $attachment['aid'], '', array('checked' => $checked)));
    }
    $table->construct_cell(get_attachment_icon(get_extension($attachment['filename'])), array('width' => 1));
    $table->construct_cell("<a href=\"../attachment.php?aid={$attachment['aid']}\" target=\"_blank\">{$attachment['filename']}</a>");
    $table->construct_cell(get_friendly_size($attachment['filesize']), array('class' => $cell_class));
    if ($attachment['user_username']) {
        $attachment['username'] = $attachment['username'];
    }
    $table->construct_cell(build_profile_link($attachment['username'], $attachment['uid'], "_blank"), array("class" => "align_center"));
    $table->construct_cell("<a href=\"../" . get_post_link($attachment['pid']) . "\" target=\"_blank\">" . htmlspecialchars_uni($attachment['subject']) . "</a>", array("class" => "align_center"));
    $table->construct_cell(my_number_format($attachment['downloads']), array("class" => "align_center"));
    if ($attachment['dateuploaded'] > 0) {
        $date = my_date($mybb->settings['dateformat'], $attachment['dateuploaded']) . ", " . my_date($mybb->settings['timeformat'], $attachment['dateuploaded']);
    } else {
        $date = $lang->unknown;
    }
    $table->construct_cell($date, array("class" => "align_center"));
    $table->construct_row();
}
Пример #4
0
     if ($user['avatartype'] == "gallery" || stristr($user['avatar'], $mybb->settings['avatardir'])) {
         $current_avatar_msg = "<br /><strong>{$lang->user_current_using_gallery_avatar}</strong>";
     } elseif ($user['avatartype'] == "remote" || my_strpos(my_strtolower($user['avatar']), "http://") !== false) {
         $current_avatar_msg = "<br /><strong>{$lang->user_current_using_remote_avatar}</strong>";
         $avatar_url = $user['avatar'];
     }
 }
 if ($errors) {
     $avatar_url = htmlspecialchars_uni($mybb->input['avatar_url']);
 }
 if ($mybb->settings['maxavatardims'] != "") {
     list($max_width, $max_height) = explode("x", my_strtolower($mybb->settings['maxavatardims']));
     $max_size = "<br />{$lang->max_dimensions_are} {$max_width}x{$max_height}";
 }
 if ($mybb->settings['avatarsize']) {
     $maximum_size = get_friendly_size($mybb->settings['avatarsize'] * 1024);
     $max_size .= "<br />{$lang->avatar_max_size} {$maximum_size}";
 }
 if ($user['avatar']) {
     $remove_avatar = "<br /><br />" . $form->generate_check_box("remove_avatar", 1, "<strong>{$lang->remove_avatar}</strong>");
 }
 $table->construct_cell($lang->avatar_desc . "{$remove_avatar}<br /><small>{$max_size}</small>");
 $table->construct_row();
 $table->output($lang->avatar . ": {$user['username']}");
 // Custom avatar
 if ($mybb->settings['avatarresizing'] == "auto") {
     $auto_resize = $lang->avatar_auto_resize;
 } else {
     if ($mybb->settings['avatarresizing'] == "user") {
         $auto_resize = "<input type=\"checkbox\" name=\"auto_resize\" value=\"1\" checked=\"checked\" id=\"auto_resize\" /> <label for=\"auto_resize\">{$lang->attempt_to_auto_resize}</label></span>";
     }
Пример #5
0
/**
 * Upload an attachment in to the file system
 *
 * @param array Attachment data (as fed by PHPs $_FILE)
 * @return array Array of attachment data if successful, otherwise array of error data
 */
function upload_attachment($attachment)
{
    global $db, $theme, $templates, $posthash, $pid, $tid, $forum, $mybb, $lang, $plugins, $cache;
    $posthash = $db->escape_string($mybb->input['posthash']);
    if (isset($attachment['error']) && $attachment['error'] != 0) {
        $ret['error'] = $lang->error_uploadfailed . $lang->error_uploadfailed_detail;
        switch ($attachment['error']) {
            case 1:
                // UPLOAD_ERR_INI_SIZE
                $ret['error'] .= $lang->error_uploadfailed_php1;
                break;
            case 2:
                // UPLOAD_ERR_FORM_SIZE
                $ret['error'] .= $lang->error_uploadfailed_php2;
                break;
            case 3:
                // UPLOAD_ERR_PARTIAL
                $ret['error'] .= $lang->error_uploadfailed_php3;
                break;
            case 4:
                // UPLOAD_ERR_NO_FILE
                $ret['error'] .= $lang->error_uploadfailed_php4;
                break;
            case 6:
                // UPLOAD_ERR_NO_TMP_DIR
                $ret['error'] .= $lang->error_uploadfailed_php6;
                break;
            case 7:
                // UPLOAD_ERR_CANT_WRITE
                $ret['error'] .= $lang->error_uploadfailed_php7;
                break;
            default:
                $ret['error'] .= $lang->sprintf($lang->error_uploadfailed_phpx, $attachment['error']);
                break;
        }
        return $ret;
    }
    if (!is_uploaded_file($attachment['tmp_name']) || empty($attachment['tmp_name'])) {
        $ret['error'] = $lang->error_uploadfailed . $lang->error_uploadfailed_php4;
        return $ret;
    }
    $ext = get_extension($attachment['name']);
    // Check if we have a valid extension
    $query = $db->simple_select("attachtypes", "*", "extension='" . $db->escape_string($ext) . "'");
    $attachtype = $db->fetch_array($query);
    if (!$attachtype['atid']) {
        $ret['error'] = $lang->error_attachtype;
        return $ret;
    }
    // Check the size
    if ($attachment['size'] > $attachtype['maxsize'] * 1024 && $attachtype['maxsize'] != "") {
        $ret['error'] = $lang->sprintf($lang->error_attachsize, $attachtype['maxsize']);
        return $ret;
    }
    // Double check attachment space usage
    if ($mybb->usergroup['attachquota'] > 0) {
        $query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='" . $mybb->user['uid'] . "'");
        $usage = $db->fetch_array($query);
        $usage = $usage['ausage'] + $attachment['size'];
        if ($usage > $mybb->usergroup['attachquota'] * 1024) {
            $friendlyquota = get_friendly_size($mybb->usergroup['attachquota'] * 1024);
            $ret['error'] = $lang->sprintf($lang->error_reachedattachquota, $friendlyquota);
            return $ret;
        }
    }
    // Check if an attachment with this name is already in the post
    $query = $db->simple_select("attachments", "*", "filename='" . $db->escape_string($attachment['name']) . "' AND (posthash='{$posthash}' OR (pid='" . intval($pid) . "' AND pid!='0'))");
    $prevattach = $db->fetch_array($query);
    if ($prevattach['aid']) {
        $ret['error'] = $lang->error_alreadyuploaded;
        return $ret;
    }
    // Check if the attachment directory (YYYYMM) exists, if not, create it
    $month_dir = gmdate("Ym");
    if (!@is_dir($mybb->settings['uploadspath'] . "/" . $month_dir)) {
        @mkdir($mybb->settings['uploadspath'] . "/" . $month_dir);
        // Still doesn't exist - oh well, throw it in the main directory
        if (!@is_dir($mybb->settings['uploadspath'] . "/" . $month_dir)) {
            $month_dir = '';
        }
    }
    // If safe_mode is enabled, don't attempt to use the monthly directories as it won't work
    if (ini_get('safe_mode') == 1 || strtolower(ini_get('safe_mode')) == 'on') {
        $month_dir = '';
    }
    // All seems to be good, lets move the attachment!
    $filename = "post_" . $mybb->user['uid'] . "_" . TIME_NOW . "_" . md5(random_str()) . ".attach";
    $file = upload_file($attachment, $mybb->settings['uploadspath'] . "/" . $month_dir, $filename);
    // Failed to create the attachment in the monthly directory, just throw it in the main directory
    if ($file['error'] && $month_dir) {
        $file = upload_file($attachment, $mybb->settings['uploadspath'] . '/', $filename);
    }
    if ($month_dir) {
        $filename = $month_dir . "/" . $filename;
    }
    if ($file['error']) {
        $ret['error'] = $lang->error_uploadfailed . $lang->error_uploadfailed_detail;
        switch ($file['error']) {
            case 1:
                $ret['error'] .= $lang->error_uploadfailed_nothingtomove;
                break;
            case 2:
                $ret['error'] .= $lang->error_uploadfailed_movefailed;
                break;
        }
        return $ret;
    }
    // Lets just double check that it exists
    if (!file_exists($mybb->settings['uploadspath'] . "/" . $filename)) {
        $ret['error'] = $lang->error_uploadfailed . $lang->error_uploadfailed_detail . $lang->error_uploadfailed_lost;
        return $ret;
    }
    // Generate the array for the insert_query
    $attacharray = array("pid" => intval($pid), "posthash" => $posthash, "uid" => $mybb->user['uid'], "filename" => $db->escape_string($file['original_filename']), "filetype" => $db->escape_string($file['type']), "filesize" => intval($file['size']), "attachname" => $filename, "downloads" => 0, "dateuploaded" => TIME_NOW);
    // If we're uploading an image, check the MIME type compared to the image type and attempt to generate a thumbnail
    if ($ext == "gif" || $ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "jpe") {
        // Check a list of known MIME types to establish what kind of image we're uploading
        switch (my_strtolower($file['type'])) {
            case "image/gif":
                $img_type = 1;
                break;
            case "image/jpeg":
            case "image/x-jpg":
            case "image/x-jpeg":
            case "image/pjpeg":
            case "image/jpg":
                $img_type = 2;
                break;
            case "image/png":
            case "image/x-png":
                $img_type = 3;
                break;
            default:
                $img_type = 0;
        }
        $supported_mimes = array();
        $attachtypes = $cache->read("attachtypes");
        foreach ($attachtypes as $attachtype) {
            if (!empty($attachtype['mimetype'])) {
                $supported_mimes[] = $attachtype['mimetype'];
            }
        }
        // Check if the uploaded file type matches the correct image type (returned by getimagesize)
        $img_dimensions = @getimagesize($mybb->settings['uploadspath'] . "/" . $filename);
        if (!is_array($img_dimensions) || $img_dimensions[2] != $img_type && !in_array(mime_content_type($filename), $supported_mimes)) {
            @unlink($mybb->settings['uploadspath'] . "/" . $filename);
            $ret['error'] = $lang->error_uploadfailed;
            return $ret;
        }
        require_once MYBB_ROOT . "inc/functions_image.php";
        $thumbname = str_replace(".attach", "_thumb.{$ext}", $filename);
        $thumbnail = generate_thumbnail($mybb->settings['uploadspath'] . "/" . $filename, $mybb->settings['uploadspath'], $thumbname, $mybb->settings['attachthumbh'], $mybb->settings['attachthumbw']);
        if ($thumbnail['filename']) {
            $attacharray['thumbnail'] = $thumbnail['filename'];
        } elseif ($thumbnail['code'] == 4) {
            $attacharray['thumbnail'] = "SMALL";
        }
    }
    if ($forum['modattachments'] == 1 && !is_moderator($forum['fid'], "", $mybb->user['uid'])) {
        $attacharray['visible'] = 0;
    } else {
        $attacharray['visible'] = 1;
    }
    $plugins->run_hooks_by_ref("upload_attachment_do_insert", $attacharray);
    $aid = $db->insert_query("attachments", $attacharray);
    if ($tid) {
        update_thread_counters($tid, array("attachmentcount" => "+1"));
    }
    $ret['aid'] = $aid;
    return $ret;
}
Пример #6
0
    $query = $db->simple_select("attachments", "SUM(filesize) AS ausage, COUNT(aid) AS acount", "uid='" . $mybb->user['uid'] . "'");
    $usage = $db->fetch_array($query);
    $totalusage = $usage['ausage'];
    $totalattachments = $usage['acount'];
    $friendlyusage = get_friendly_size($totalusage);
    if ($mybb->usergroup['attachquota']) {
        $percent = round($totalusage / ($mybb->usergroup['attachquota'] * 1024) * 100) . "%";
        $attachquota = get_friendly_size($mybb->usergroup['attachquota'] * 1024);
        $usagenote = $lang->sprintf($lang->attachments_usage_quota, $friendlyusage, $attachquota, $percent, $totalattachments);
    } else {
        $percent = $lang->unlimited;
        $attachquota = $lang->unlimited;
        $usagenote = $lang->sprintf($lang->attachments_usage, $friendlyusage, $totalattachments);
    }
    $multipage = multipage($totalattachments, $perpage, $page, "usercp.php?action=attachments");
    $bandwidth = get_friendly_size($bandwidth);
    if (!$attachments) {
        eval("\$attachments = \"" . $templates->get("usercp_attachments_none") . "\";");
        $usagenote = '';
    }
    $plugins->run_hooks("usercp_attachments_end");
    eval("\$manageattachments = \"" . $templates->get("usercp_attachments") . "\";");
    output_page($manageattachments);
}
if ($mybb->input['action'] == "do_attachments" && $mybb->request_method == "post") {
    // Verify incoming POST request
    verify_post_check($mybb->get_input('my_post_key'));
    $plugins->run_hooks("usercp_do_attachments_start");
    require_once MYBB_ROOT . "inc/functions_upload.php";
    if (!isset($mybb->input['attachments']) || !is_array($mybb->input['attachments'])) {
        error($lang->no_attachments_selected);
Пример #7
0
     $start = 0;
     $page = 1;
 }
 $multipage = multipage($unapproved_attachments, $perpage, $page, "modcp.php?action=modqueue&amp;type=attachments");
 $query = $db->query("\n\t\t\tSELECT a.*, p.subject AS postsubject, p.dateline, p.uid, u.username, t.tid, t.subject AS threadsubject\n\t\t\tFROM  " . TABLE_PREFIX . "attachments a\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "posts p ON (p.pid=a.pid)\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=p.tid)\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid=p.uid)\n\t\t\tWHERE a.visible='0'{$tflist_queue_attach}\n\t\t\tORDER BY a.dateuploaded DESC\n\t\t\tLIMIT {$start}, {$perpage}\n\t\t");
 $attachments = '';
 while ($attachment = $db->fetch_array($query)) {
     $altbg = alt_trow();
     if (!$attachment['dateuploaded']) {
         $attachment['dateuploaded'] = $attachment['dateline'];
     }
     $attachdate = my_date('relative', $attachment['dateuploaded']);
     $attachment['postsubject'] = htmlspecialchars_uni($attachment['postsubject']);
     $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
     $attachment['threadsubject'] = htmlspecialchars_uni($attachment['threadsubject']);
     $attachment['filesize'] = get_friendly_size($attachment['filesize']);
     $link = get_post_link($attachment['pid'], $attachment['tid']) . "#pid{$attachment['pid']}";
     $thread_link = get_thread_link($attachment['tid']);
     $profile_link = build_profile_link($attachment['username'], $attachment['uid']);
     eval("\$attachments .= \"" . $templates->get("modcp_modqueue_attachments_attachment") . "\";");
 }
 if (!$attachments && $mybb->input['type'] == "attachments") {
     eval("\$attachments = \"" . $templates->get("modcp_modqueue_attachments_empty") . "\";");
 }
 if ($attachments) {
     add_breadcrumb($lang->mcp_nav_modqueue_attachments, "modcp.php?action=modqueue&amp;type=attachments");
     $plugins->run_hooks("modcp_modqueue_attachments_end");
     if ($nummodqueuethreads > 0 || $mybb->usergroup['issupermod'] == 1) {
         eval("\$thread_link = \"" . $templates->get("modcp_modqueue_thread_link") . "\";");
         $navsep = " | ";
     }
Пример #8
0
function fs_run()
{
    global $db, $debug, $templates, $templatelist, $mybb, $maintimer, $globaltime, $ptimer, $parsetime, $target, $udata;
    if (function_exists("memory_get_usage")) {
        $memory_usage = get_friendly_size(memory_get_peak_usage(true));
    } else {
        $memory_usage = 'Unknown';
    }
    $query_count = $db->query_count;
    // patchs
    if ($target['script'] == 'index.php' && empty($target['uid'])) {
        --$query_count;
    } else {
        if ($target['script'] == 'portal.php') {
            //++$query_count;
        } else {
            if ($target['script'] == 'showthread.php') {
                ++$query_count;
            }
        }
    }
    if (!is_array($udata) || empty($udata['uid'])) {
        --$query_count;
    }
    header("content-type: text/xml");
    $output = "<?xml version='1.0' encoding='UTF-8'?>\n<FloatStats>\n\t<DatabaseQueries>{$query_count}</DatabaseQueries>\n\t<MemoryUsage>{$memory_usage}</MemoryUsage>\n</FloatStats>";
    echo $output;
    exit;
}
Пример #9
0
/**
 * Prints a debug information page
 */
function debug_page()
{
    global $db, $debug, $templates, $templatelist, $mybb, $maintimer, $globaltime, $ptimer, $parsetime, $lang;
    $totaltime = $maintimer->totaltime;
    $phptime = $maintimer->format($maintimer->totaltime - $db->query_time);
    $query_time = $maintimer->format($db->query_time);
    $percentphp = number_format($phptime / $maintimer->totaltime * 100, 2);
    $percentsql = number_format($query_time / $maintimer->totaltime * 100, 2);
    $phpversion = PHP_VERSION;
    $serverload = get_server_load();
    if ($mybb->settings['gzipoutput'] != 0) {
        $gzipen = "Enabled";
    } else {
        $gzipen = "Disabled";
    }
    echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
    echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">";
    echo "<head>";
    echo "<title>MyBB Debug Information</title>";
    echo "</head>";
    echo "<body>";
    echo "<h1>MyBB Debug Information</h1>\n";
    echo "<h2>Page Generation</h2>\n";
    echo "<table bgcolor=\"#666666\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#CCCCCC\" colspan=\"4\"><b><span style=\"size:2;\">Page Generation Statistics</span></b></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Page Generation Time:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$totaltime} seconds</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">No. DB Queries:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$db->query_count}</font></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">PHP Processing Time:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$phptime} seconds ({$percentphp}%)</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">DB Processing Time:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$query_time} seconds ({$percentsql}%)</font></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Extensions Used:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$mybb->config['database']['type']}, xml</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Global.php Processing Time:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$globaltime} seconds</font></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">PHP Version:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$phpversion}</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Server Load:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$serverload}</font></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">GZip Encoding Status:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$gzipen}</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">No. Templates Used:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">" . count($templates->cache) . " (" . intval(count(explode(",", $templatelist))) . " Cached / " . intval(count($templates->uncached_templates)) . " Manually Loaded)</font></td>\n";
    echo "</tr>\n";
    $memory_usage = get_memory_usage();
    if (!$memory_usage) {
        $memory_usage = $lang->unknown;
    } else {
        $memory_usage = get_friendly_size($memory_usage) . " ({$memory_usage} bytes)";
    }
    $memory_limit = @ini_get("memory_limit");
    echo "<tr>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Memory Usage:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$memory_usage}</font></td>\n";
    echo "<td bgcolor=\"#EFEFEF\" width=\"25%\"><b><font face=\"Tahoma\" size=\"2\">Memory Limit:</font></b></td>\n";
    echo "<td bgcolor=\"#FEFEFE\" width=\"25%\"><font face=\"Tahoma\" size=\"2\">{$memory_limit}</font></td>\n";
    echo "</tr>\n";
    echo "</table>\n";
    echo "<h2>Database Connections (" . count($db->connections) . " Total) </h2>\n";
    echo "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n";
    echo "<tr>\n";
    echo "<td style=\"background: #fff;\">" . implode("<br />", $db->connections) . "</td>\n";
    echo "</tr>\n";
    echo "</table>\n";
    echo "<br />\n";
    echo "<h2>Database Queries (" . $db->query_count . " Total) </h2>\n";
    echo $db->explain;
    echo "<h2>Template Statistics</h2>\n";
    if (count($templates->cache) > 0) {
        echo "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n";
        echo "<tr>\n";
        echo "<td style=\"background-color: #ccc;\"><strong>Templates Used (Loaded for this Page) - " . count($templates->cache) . " Total</strong></td>\n";
        echo "</tr>\n";
        echo "<tr>\n";
        echo "<td style=\"background: #fff;\">" . implode(", ", array_keys($templates->cache)) . "</td>\n";
        echo "</tr>\n";
        echo "</table>\n";
        echo "<br />\n";
    }
    if (count($templates->uncached_templates) > 0) {
        echo "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n";
        echo "<tr>\n";
        echo "<td style=\"background-color: #ccc;\"><strong>Templates Requiring Additional Calls (Not Cached at Startup) - " . count($templates->uncached_templates) . " Total</strong></td>\n";
        echo "</tr>\n";
        echo "<tr>\n";
        echo "<td style=\"background: #fff;\">" . implode(", ", $templates->uncached_templates) . "</td>\n";
        echo "</tr>\n";
        echo "</table>\n";
        echo "<br />\n";
    }
    echo "</body>";
    echo "</html>";
    exit;
}
Пример #10
0
 $query = $db->simple_select("threads", "COUNT(*) AS newthreads", "dateline > '{$timecut}' AND visible='1' AND closed NOT LIKE 'moved|%'");
 $newthreads = my_number_format($db->fetch_field($query, "newthreads"));
 // Get the number of posts
 $posts = my_number_format($stats['numposts']);
 // Get the number of unapproved posts
 if ($stats['numunapprovedposts'] < 0) {
     $status['numunapprovedposts'] = 0;
 }
 $unapproved_posts = my_number_format($stats['numunapprovedposts']);
 // Get the number of new posts for today
 $query = $db->simple_select("posts", "COUNT(*) AS newposts", "dateline > '{$timecut}' AND visible='1'");
 $newposts = my_number_format($db->fetch_field($query, "newposts"));
 // Get the number and total file size of attachments
 $query = $db->simple_select("attachments", "COUNT(*) AS numattachs, SUM(filesize) as spaceused", "visible='1' AND pid > '0'");
 $attachs = $db->fetch_array($query);
 $attachs['spaceused'] = get_friendly_size($attachs['spaceused']);
 // Get the number of unapproved attachments
 $query = $db->simple_select("attachments", "COUNT(*) AS numattachs", "visible='0' AND pid > '0'");
 $unapproved_attachs = my_number_format($db->fetch_field($query, "numattachs"));
 // Fetch the last time an update check was run
 $update_check = $cache->read("update_check");
 // If last update check was greater than two weeks ago (14 days) show an alert
 if (isset($update_check['last_check']) && $update_check['last_check'] <= TIME_NOW - 60 * 60 * 24 * 14) {
     $lang->last_update_check_two_weeks = $lang->sprintf($lang->last_update_check_two_weeks, "index.php?module=home-version_check");
     $page->output_error("<p>{$lang->last_update_check_two_weeks}</p>");
 }
 // If the update check contains information about a newer version, show an alert
 if (isset($update_check['latest_version_code']) && $update_check['latest_version_code'] > $mybb->version_code) {
     $lang->new_version_available = $lang->sprintf($lang->new_version_available, "MyBB {$mybb->version}", "<a href=\"http://mybb.com/downloads\" target=\"_blank\">MyBB {$update_check['latest_version']}</a>");
     $page->output_error("<p><em>{$lang->new_version_available}</em></p>");
 }
 $table->construct_header("Month", array("colspan" => 1));
 $table->construct_header("Year", array("colspan" => 1));
 $table->construct_cell("<strong>Total</strong>", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($total_bandwidth_week), array('width' => '25%'));
 $table->construct_cell(get_friendly_size($total_bandwidth_month), array('width' => '200'));
 $table->construct_cell(get_friendly_size($total_bandwidth_year), array('width' => '200'));
 $table->construct_row();
 $table->construct_cell("<strong>Sent By CloudFlare</strong>", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($bandwidth_sent_week), array('width' => '25%'));
 $table->construct_cell(get_friendly_size($bandwidth_sent_month), array('width' => '200'));
 $table->construct_cell(get_friendly_size($bandwidth_sent_year), array('width' => '200'));
 $table->construct_row();
 $table->construct_cell("<strong>Saved By CloudFlare</strong>", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($saved_bandwidth_week), array('width' => '25%'));
 $table->construct_cell(get_friendly_size($saved_bandwidth_month), array('width' => '200'));
 $table->construct_cell(get_friendly_size($saved_bandwidth_year), array('width' => '200'));
 $table->construct_row();
 $table->output("Bandwidth Usage");
 $table = new Table();
 $table->construct_header("Type", array("colspan" => 1));
 $table->construct_header("Week", array("colspan" => 1));
 $table->construct_header("Month", array("colspan" => 1));
 $table->construct_header("Year", array("colspan" => 1));
 $table->construct_cell("<strong>Total</strong>", array('width' => '25%'));
 $table->construct_cell($total_requests_week, array('width' => '25%'));
 $table->construct_cell($total_requests_month, array('width' => '25%'));
 $table->construct_cell($total_requests_year, array('width' => '25%'));
 $table->construct_row();
 $table->construct_cell("<strong>Sent By CloudFlare</strong>", array('width' => '25%'));
 $table->construct_cell($sent_requests_week, array('width' => '25%'));
 $table->construct_cell($sent_requests_month, array('width' => '25%'));
 $table->construct_header("Month", array("colspan" => 1));
 $table->construct_header("Year", array("colspan" => 1));
 $table->construct_cell("<strong>Total</strong>", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($total_bandwidth_week) . " (100%)", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($total_bandwidth_month) . " (100%)", array('width' => '200'));
 $table->construct_cell(get_friendly_size($total_bandwidth_year) . " (100%)", array('width' => '200'));
 $table->construct_row();
 $table->construct_cell("<strong>Sent By CloudFlare</strong>", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($bandwidth_sent_week) . " ({$bandwidth_percent_week_sent}%)", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($bandwidth_sent_month) . " ({$bandwidth_percent_month_sent}%)", array('width' => '200'));
 $table->construct_cell(get_friendly_size($bandwidth_sent_year) . " ({$bandwidth_percent_year_sent}%)", array('width' => '200'));
 $table->construct_row();
 $table->construct_cell("<strong>Saved By CloudFlare</strong>", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($saved_bandwidth_week) . " ({$bandwidth_percent_week_saved}%)", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($saved_bandwidth_month) . " ({$bandwidth_percent_month_saved}%)", array('width' => '200'));
 $table->construct_cell(get_friendly_size($saved_bandwidth_year) . " ({$bandwidth_percent_year_saved}%)", array('width' => '200'));
 $table->construct_row();
 $table->output("Bandwidth Usage");
 $table = new Table();
 $table->construct_header("Type", array("colspan" => 1));
 $table->construct_header("Week", array("colspan" => 1));
 $table->construct_header("Month", array("colspan" => 1));
 $table->construct_header("Year", array("colspan" => 1));
 $table->construct_cell("<strong>Total</strong>", array('width' => '25%'));
 $table->construct_cell(number_format($total_requests_week) . " (100%)", array('width' => '25%'));
 $table->construct_cell(number_format($total_requests_month) . " (100%)", array('width' => '25%'));
 $table->construct_cell(number_format($total_requests_year) . " (100%)", array('width' => '25%'));
 $table->construct_row();
 $table->construct_cell("<strong>Sent By CloudFlare</strong>", array('width' => '25%'));
 $table->construct_cell(number_format($sent_requests_week) . " ({$requests_percent_week_sent}%)", array('width' => '25%'));
 $table->construct_cell(number_format($sent_requests_month) . " ({$requests_percent_month_sent}%)", array('width' => '25%'));
Пример #13
0
 /**
  * Output the page footer.
  *
  * @param bool $quit
  */
 function output_footer($quit = true)
 {
     global $mybb, $maintimer, $db, $lang, $plugins;
     $args = array('this' => &$this, 'quit' => &$quit);
     $plugins->run_hooks("admin_page_output_footer", $args);
     $memory_usage = get_friendly_size(get_memory_usage());
     $totaltime = format_time_duration($maintimer->stop());
     $querycount = $db->query_count;
     if (my_strpos(getenv("REQUEST_URI"), "?")) {
         $debuglink = htmlspecialchars_uni(getenv("REQUEST_URI")) . "&amp;debug=1#footer";
     } else {
         $debuglink = htmlspecialchars_uni(getenv("REQUEST_URI")) . "?debug=1#footer";
     }
     echo "\t\t\t</div>\n";
     echo "\t\t</div>\n";
     echo "\t<br style=\"clear: both;\" />";
     echo "\t<br style=\"clear: both;\" />";
     echo "\t</div>\n";
     echo "<div id=\"footer\"><p class=\"generation\">" . $lang->sprintf($lang->generated_in, $totaltime, $debuglink, $querycount, $memory_usage) . "</p><p class=\"powered\">Powered By <a href=\"http://www.mybb.com/\" target=\"_blank\">MyBB</a>, &copy; 2002-" . COPY_YEAR . " <a href=\"http://www.mybb.com/\" target=\"_blank\">MyBB Group</a>.</p></div>\n";
     if ($mybb->debug_mode) {
         echo $db->explain;
     }
     echo "</div>\n";
     echo "</body>\n";
     echo "</html>\n";
     if ($quit != false) {
         exit;
     }
 }
Пример #14
0
    $table->construct_header($lang->size, array("class" => "align_center", "width" => 100));
    $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150));
    $query = $db->simple_select("datacache");
    while ($cacheitem = $db->fetch_array($query)) {
        $table->construct_cell("<strong><a href=\"index.php?module=tools-cache&amp;action=view&amp;title=" . urlencode($cacheitem['title']) . "\">{$cacheitem['title']}</a></strong>");
        $table->construct_cell(get_friendly_size(strlen($cacheitem['cache'])), array("class" => "align_center"));
        if (method_exists($cache, "update_" . $cacheitem['title'])) {
            $table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=rebuild&amp;title=" . urlencode($cacheitem['title']) . "&amp;my_post_key={$mybb->post_code}\">" . $lang->rebuild_cache . "</a>", array("class" => "align_center"));
        } elseif (method_exists($cache, "reload_" . $cacheitem['title'])) {
            $table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=reload&amp;title=" . urlencode($cacheitem['title']) . "&amp;my_post_key={$mybb->post_code}\">" . $lang->reload_cache . "</a>", array("class" => "align_center"));
        } elseif (function_exists("update_" . $cacheitem['title'])) {
            $table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=rebuild&amp;title=" . urlencode($cacheitem['title']) . "&amp;my_post_key={$mybb->post_code}\">" . $lang->rebuild_cache . "</a>", array("class" => "align_center"));
        } elseif (function_exists("reload_" . $cacheitem['title'])) {
            $table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=reload&amp;title=" . urlencode($cacheitem['title']) . "&amp;my_post_key={$mybb->post_code}\">" . $lang->reload_cache . "</a>", array("class" => "align_center"));
        } else {
            $table->construct_cell("");
        }
        $table->construct_row();
    }
    // Rebuilds forum settings
    $cachedsettings = (array) $mybb->settings;
    if (isset($cachedsettings['internal'])) {
        unset($cachedsettings['internal']);
    }
    $table->construct_cell("<strong><a href=\"index.php?module=tools-cache&amp;action=view&amp;title=settings\">settings</a></strong>");
    $table->construct_cell(get_friendly_size(strlen(my_serialize($cachedsettings))), array("class" => "align_center"));
    $table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=reload&amp;title=settings&amp;my_post_key={$mybb->post_code}\">" . $lang->reload_cache . "</a>", array("class" => "align_center"));
    $table->construct_row();
    $table->output("<div style=\"float: right;\"><small><a href=\"index.php?module=tools-cache&amp;action=rebuild_all&amp;my_post_key={$mybb->post_code}\">" . $lang->rebuild_reload_all . "</a></small></div>" . $lang->cache_manager);
    $page->output_footer();
}
Пример #15
0
/**
 * Upload an attachment in to the file system
 *
 * @param array $attachment Attachment data (as fed by PHPs $_FILE)
 * @param boolean $update_attachment Whether or not we are updating a current attachment or inserting a new one
 * @return array Array of attachment data if successful, otherwise array of error data
 */
function upload_attachment($attachment, $update_attachment = false)
{
    global $mybb, $db, $theme, $templates, $posthash, $pid, $tid, $forum, $mybb, $lang, $plugins, $cache;
    $posthash = $db->escape_string($mybb->get_input('posthash'));
    $pid = (int) $pid;
    if (isset($attachment['error']) && $attachment['error'] != 0) {
        $ret['error'] = $lang->error_uploadfailed . $lang->error_uploadfailed_detail;
        switch ($attachment['error']) {
            case 1:
                // UPLOAD_ERR_INI_SIZE
                $ret['error'] .= $lang->error_uploadfailed_php1;
                break;
            case 2:
                // UPLOAD_ERR_FORM_SIZE
                $ret['error'] .= $lang->error_uploadfailed_php2;
                break;
            case 3:
                // UPLOAD_ERR_PARTIAL
                $ret['error'] .= $lang->error_uploadfailed_php3;
                break;
            case 4:
                // UPLOAD_ERR_NO_FILE
                $ret['error'] .= $lang->error_uploadfailed_php4;
                break;
            case 6:
                // UPLOAD_ERR_NO_TMP_DIR
                $ret['error'] .= $lang->error_uploadfailed_php6;
                break;
            case 7:
                // UPLOAD_ERR_CANT_WRITE
                $ret['error'] .= $lang->error_uploadfailed_php7;
                break;
            default:
                $ret['error'] .= $lang->sprintf($lang->error_uploadfailed_phpx, $attachment['error']);
                break;
        }
        return $ret;
    }
    if (!is_uploaded_file($attachment['tmp_name']) || empty($attachment['tmp_name'])) {
        $ret['error'] = $lang->error_uploadfailed . $lang->error_uploadfailed_php4;
        return $ret;
    }
    $attachtypes = $cache->read('attachtypes');
    $attachment = $plugins->run_hooks("upload_attachment_start", $attachment);
    $ext = get_extension($attachment['name']);
    // Check if we have a valid extension
    if (!isset($attachtypes[$ext])) {
        $ret['error'] = $lang->error_attachtype;
        return $ret;
    } else {
        $attachtype = $attachtypes[$ext];
    }
    // Check the size
    if ($attachment['size'] > $attachtype['maxsize'] * 1024 && $attachtype['maxsize'] != "") {
        $ret['error'] = $lang->sprintf($lang->error_attachsize, $attachtype['maxsize']);
        return $ret;
    }
    // Double check attachment space usage
    if ($mybb->usergroup['attachquota'] > 0) {
        $query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='" . $mybb->user['uid'] . "'");
        $usage = $db->fetch_array($query);
        $usage = $usage['ausage'] + $attachment['size'];
        if ($usage > $mybb->usergroup['attachquota'] * 1024) {
            $friendlyquota = get_friendly_size($mybb->usergroup['attachquota'] * 1024);
            $ret['error'] = $lang->sprintf($lang->error_reachedattachquota, $friendlyquota);
            return $ret;
        }
    }
    // Gather forum permissions
    $forumpermissions = forum_permissions($forum['fid']);
    // Check if an attachment with this name is already in the post
    if ($pid != 0) {
        $uploaded_query = "pid='{$pid}'";
    } else {
        $uploaded_query = "posthash='{$posthash}'";
    }
    $query = $db->simple_select("attachments", "*", "filename='" . $db->escape_string($attachment['name']) . "' AND " . $uploaded_query);
    $prevattach = $db->fetch_array($query);
    if ($prevattach['aid'] && $update_attachment == false) {
        if (!$mybb->usergroup['caneditattachments'] && !$forumpermissions['caneditattachments']) {
            $ret['error'] = $lang->error_alreadyuploaded_perm;
            return $ret;
        }
        $ret['error'] = $lang->error_alreadyuploaded;
        return $ret;
    }
    // Check to see how many attachments exist for this post already
    if ($mybb->settings['maxattachments'] > 0 && $update_attachment == false) {
        $query = $db->simple_select("attachments", "COUNT(aid) AS numattachs", $uploaded_query);
        $attachcount = $db->fetch_field($query, "numattachs");
        if ($attachcount >= $mybb->settings['maxattachments']) {
            $ret['error'] = $lang->sprintf($lang->error_maxattachpost, $mybb->settings['maxattachments']);
            return $ret;
        }
    }
    $month_dir = '';
    if ($mybb->safemode == false) {
        // Check if the attachment directory (YYYYMM) exists, if not, create it
        $month_dir = gmdate("Ym");
        if (!@is_dir($mybb->settings['uploadspath'] . "/" . $month_dir)) {
            @mkdir($mybb->settings['uploadspath'] . "/" . $month_dir);
            // Still doesn't exist - oh well, throw it in the main directory
            if (!@is_dir($mybb->settings['uploadspath'] . "/" . $month_dir)) {
                $month_dir = '';
            }
        }
    }
    // All seems to be good, lets move the attachment!
    $filename = "post_" . $mybb->user['uid'] . "_" . TIME_NOW . "_" . md5(random_str()) . ".attach";
    $file = upload_file($attachment, $mybb->settings['uploadspath'] . "/" . $month_dir, $filename);
    // Failed to create the attachment in the monthly directory, just throw it in the main directory
    if (!empty($file['error']) && $month_dir) {
        $file = upload_file($attachment, $mybb->settings['uploadspath'] . '/', $filename);
    } elseif ($month_dir) {
        $filename = $month_dir . "/" . $filename;
    }
    if (!empty($file['error'])) {
        $ret['error'] = $lang->error_uploadfailed . $lang->error_uploadfailed_detail;
        switch ($file['error']) {
            case 1:
                $ret['error'] .= $lang->error_uploadfailed_nothingtomove;
                break;
            case 2:
                $ret['error'] .= $lang->error_uploadfailed_movefailed;
                break;
        }
        return $ret;
    }
    // Lets just double check that it exists
    if (!file_exists($mybb->settings['uploadspath'] . "/" . $filename)) {
        $ret['error'] = $lang->error_uploadfailed . $lang->error_uploadfailed_detail . $lang->error_uploadfailed_lost;
        return $ret;
    }
    // Generate the array for the insert_query
    $attacharray = array("pid" => $pid, "posthash" => $posthash, "uid" => $mybb->user['uid'], "filename" => $db->escape_string($file['original_filename']), "filetype" => $db->escape_string($file['type']), "filesize" => (int) $file['size'], "attachname" => $filename, "downloads" => 0, "dateuploaded" => TIME_NOW);
    // If we're uploading an image, check the MIME type compared to the image type and attempt to generate a thumbnail
    if ($ext == "gif" || $ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "jpe") {
        // Check a list of known MIME types to establish what kind of image we're uploading
        switch (my_strtolower($file['type'])) {
            case "image/gif":
                $img_type = 1;
                break;
            case "image/jpeg":
            case "image/x-jpg":
            case "image/x-jpeg":
            case "image/pjpeg":
            case "image/jpg":
                $img_type = 2;
                break;
            case "image/png":
            case "image/x-png":
                $img_type = 3;
                break;
            default:
                $img_type = 0;
        }
        $supported_mimes = array();
        foreach ($attachtypes as $attachtype) {
            if (!empty($attachtype['mimetype'])) {
                $supported_mimes[] = $attachtype['mimetype'];
            }
        }
        // Check if the uploaded file type matches the correct image type (returned by getimagesize)
        $img_dimensions = @getimagesize($mybb->settings['uploadspath'] . "/" . $filename);
        $mime = "";
        $file_path = $mybb->settings['uploadspath'] . "/" . $filename;
        if (function_exists("finfo_open")) {
            $file_info = finfo_open(FILEINFO_MIME);
            list($mime, ) = explode(';', finfo_file($file_info, MYBB_ROOT . $file_path), 1);
            finfo_close($file_info);
        } else {
            if (function_exists("mime_content_type")) {
                $mime = mime_content_type(MYBB_ROOT . $file_path);
            }
        }
        if (!is_array($img_dimensions) || $img_dimensions[2] != $img_type && !in_array($mime, $supported_mimes)) {
            delete_uploaded_file($mybb->settings['uploadspath'] . "/" . $filename);
            $ret['error'] = $lang->error_uploadfailed;
            return $ret;
        }
        require_once MYBB_ROOT . "inc/functions_image.php";
        $thumbname = str_replace(".attach", "_thumb.{$ext}", $filename);
        $attacharray = $plugins->run_hooks("upload_attachment_thumb_start", $attacharray);
        $thumbnail = generate_thumbnail($mybb->settings['uploadspath'] . "/" . $filename, $mybb->settings['uploadspath'], $thumbname, $mybb->settings['attachthumbh'], $mybb->settings['attachthumbw']);
        if ($thumbnail['filename']) {
            $attacharray['thumbnail'] = $thumbnail['filename'];
        } elseif ($thumbnail['code'] == 4) {
            $attacharray['thumbnail'] = "SMALL";
        }
    }
    if ($forumpermissions['modattachments'] == 1 && !is_moderator($forum['fid'], "canapproveunapproveattachs")) {
        $attacharray['visible'] = 0;
    } else {
        $attacharray['visible'] = 1;
    }
    $attacharray = $plugins->run_hooks("upload_attachment_do_insert", $attacharray);
    if ($prevattach['aid'] && $update_attachment == true) {
        unset($attacharray['downloads']);
        // Keep our download count if we're updating an attachment
        $db->update_query("attachments", $attacharray, "aid='" . $db->escape_string($prevattach['aid']) . "'");
        // Remove old attachment file
        // Check if this attachment is referenced in any other posts. If it isn't, then we are safe to delete the actual file.
        $query = $db->simple_select("attachments", "COUNT(aid) as numreferences", "attachname='" . $db->escape_string($prevattach['attachname']) . "'");
        if ($db->fetch_field($query, "numreferences") == 0) {
            delete_uploaded_file($mybb->settings['uploadspath'] . "/" . $prevattach['attachname']);
            if ($prevattach['thumbnail']) {
                delete_uploaded_file($mybb->settings['uploadspath'] . "/" . $prevattach['thumbnail']);
            }
            $date_directory = explode('/', $prevattach['attachname']);
            if (@is_dir($mybb->settings['uploadspath'] . "/" . $date_directory[0])) {
                delete_upload_directory($mybb->settings['uploadspath'] . "/" . $date_directory[0]);
            }
        }
        $aid = $prevattach['aid'];
    } else {
        $aid = $db->insert_query("attachments", $attacharray);
        if ($pid) {
            update_thread_counters($tid, array("attachmentcount" => "+1"));
        }
    }
    $ret['aid'] = $aid;
    return $ret;
}
Пример #16
0
function xthreads_sanitize_disp(&$s, &$tfinfo, $mename = null, $noextra = false)
{
    $evalfunc = 'xthreads_evalcache_' . $tfinfo['field'];
    if (!$noextra) {
        // this "hack" stops this function being totally independent of the outside world :(
        global $threadfields_x;
        if (!isset($threadfields_x)) {
            $threadfields_x = array();
        }
        $sx =& $threadfields_x[$tfinfo['field']];
    }
    // otherwise, let the following line dummy the variable
    $sx = array('title' => htmlspecialchars_uni($tfinfo['title']), 'desc' => htmlspecialchars_uni($tfinfo['desc']), 'num_values' => 1, 'num_values_friendly' => my_number_format(1), 'raw_value' => $s);
    $dispfmt = 'dispformat';
    if (!xthreads_user_in_groups($tfinfo['viewable_gids'])) {
        $dispfmt = 'unviewableval';
    }
    if ($tfinfo['inputtype'] == XTHREADS_INPUT_FILE || $tfinfo['inputtype'] == XTHREADS_INPUT_FILE_URL && !preg_match('~^[a-z]+\\://~i', $s)) {
        global $xta_cache, $mybb;
        // attached file
        if (!$s) {
            $s = array('value' => $evalfunc('blankval'));
            xthreads_sanitize_disp_set_blankthumbs($s, $tfinfo);
            return;
        }
        if (xthreads_empty($tfinfo['multival'])) {
            xthreads_sanitize_disp_set_xta_fields($s, $s, $tfinfo, $dispfmt, $evalfunc);
            $sx['value'] =& $s['value'];
        } else {
            $aids = explode(',', $s);
            $s = array('total_downloads' => 0, 'total_filesize' => 0, 'updatetime' => 0, 'uploadtime' => 0, 'value' => '', 'num_files' => 0);
            $sx['items'] = $sx['value'] = array();
            $comma = '';
            foreach ($aids as $aid) {
                $xta =& $sx['items'][];
                xthreads_sanitize_disp_set_xta_fields($xta, $aid, $tfinfo, 'dispitemformat', $evalfunc);
                if (!$xta['aid']) {
                    continue;
                }
                $sx['value'][] = $xta['value'];
                $s['total_downloads'] += $xta['downloads'];
                $s['total_filesize'] += $xta['filesize'];
                $s['uploadtime'] = max($xta['uploadtime'], $s['uploadtime']);
                ++$s['num_files'];
                $s['value'] .= $comma . $xta['value'];
                $comma = $tfinfo['multival'];
            }
            $s['total_downloads_friendly'] = my_number_format($s['total_downloads']);
            $s['total_filesize_friendly'] = get_friendly_size($s['total_filesize']);
            $s['upload_time'] = my_date($mybb->settings['timeformat'], $s['uploadtime']);
            $s['upload_date'] = my_date($mybb->settings['dateformat'], $s['uploadtime']);
            $s['value'] = $evalfunc($dispfmt, array('VALUE' => $s['value']));
            $sx['num_values'] = $s['num_files'];
            $sx['num_values_friendly'] = $s['num_files_friendly'] = my_number_format($s['num_files']);
        }
    } else {
        if ($s === '' || $s === null) {
            $sx['num_values'] = 0;
            $sx['num_values_friendly'] = my_number_format(0);
            $s = $evalfunc('blankval');
            return;
        }
        if (!xthreads_empty($tfinfo['multival'])) {
            // we _could_ optimise this out if the final $dispformat never actually refers to {VALUE}, but this is perhaps an unlikely situation, and we don't know whether the dispitemformat has some special eval'd code we should run
            $vals = explode("\n", str_replace("\r", '', $s));
            $i = 0;
            $sx['value'] = array();
            foreach ($vals as &$v) {
                xthreads_sanitize_disp_field($v, $tfinfo, 'dispitemformat', $mename);
                $sx['value'][$i++] = $v;
            }
            $sx['num_values'] = $i;
            $sx['num_values_friendly'] = my_number_format($i);
            $s = implode($tfinfo['multival'], $vals);
            $s = $evalfunc($dispfmt, array('VALUE' => $s));
        } else {
            xthreads_sanitize_disp_field($s, $tfinfo, $dispfmt, $mename);
            $sx['value'] =& $s;
        }
    }
}
Пример #17
0
function process_post_attachments($id, &$post, $edit_post = false)
{
    global $attachcache, $mybb, $theme, $templates, $forumpermissions, $lang;
    $validationcount = 0;
    $tcount = 0;
    $attachment_list = array();
    if (is_array($attachcache[$id])) {
        // This post has 1 or more attachments
        foreach ($attachcache[$id] as $aid => $attachment) {
            if ($attachment['visible']) {
                // There is an attachment thats visible!
                $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
                $attachment['filesize_b'] = $attachment['filesize'];
                $attachment['filesize'] = get_friendly_size($attachment['filesize']);
                $ext = get_extension($attachment['filename']);
                if ($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg") {
                    $type = 'image';
                } elseif ($ext == "pdf") {
                    $type = 'pdf';
                } else {
                    $type = $ext;
                }
                $attachment['icon'] = get_attachment_icon($ext);
                // Support for [attachment=id] code
                if (stripos($post['message'], "[attachment=" . $attachment['aid'] . "]") !== false && !$edit_post) {
                    if ($type == 'image') {
                        $replace = '[img]' . absolute_url("attachment.php?aid={$attachment['aid']}") . '[/img]';
                    } else {
                        $replace = '[url=' . absolute_url("attachment.php?aid={$attachment['aid']}") . ']' . $attachment['filename'] . "[/url]({$lang->postbit_attachment_size} {$attachment['filesize']} / {$lang->postbit_attachment_downloads} {$attachment['downloads']})";
                    }
                    $post['message'] = preg_replace("#\\[attachment=" . $attachment['aid'] . "]#si", $replace, $post['message']);
                } else {
                    $url = absolute_url("attachment.php?aid={$attachment['aid']}");
                    $thumbnail_url = $attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != '' ? absolute_url("attachment.php?thumbnail={$attachment['aid']}") : $url;
                    $attachment_list[] = new xmlrpcval(array('filename' => new xmlrpcval($attachment['filename'], 'base64'), 'filesize' => new xmlrpcval($attachment['filesize_b'], 'int'), 'content_type' => new xmlrpcval($type, 'string'), 'thumbnail_url' => new xmlrpcval($thumbnail_url, 'string'), 'url' => new xmlrpcval($url, 'string'), 'attachment_id' => new xmlrpcval($attachment['aid'], 'string')), 'struct');
                }
            }
        }
    }
    return $attachment_list;
}
Пример #18
0
    $sub_tabs['add_attachment_type'] = array('title' => $lang->add_new_attachment_type, 'link' => "index.php?module=config-attachment_types&amp;action=add");
    $page->output_nav_tabs($sub_tabs, 'attachment_types');
    $table = new Table();
    $table->construct_header($lang->extension, array("colspan" => 2));
    $table->construct_header($lang->mime_type);
    $table->construct_header($lang->maximum_size, array("class" => "align_center"));
    $table->construct_header($lang->controls, array("class" => "align_center", "colspan" => 2));
    $query = $db->simple_select("attachtypes", "*", "", array('order_by' => 'extension'));
    while ($attachment_type = $db->fetch_array($query)) {
        // Just show default icons in ACP
        $attachment_type['icon'] = htmlspecialchars_uni(str_replace("{theme}", "images", $attachment_type['icon']));
        if (!$attachment_type['icon'] || $attachment_type['icon'] == "images/attachtypes/") {
            $attachment_type['icon'] = "&nbsp;";
        } else {
            $attachment_type['icon'] = "<img src=\"../{$attachment_type['icon']}\" alt=\"\" />";
        }
        $table->construct_cell($attachment_type['icon'], array("width" => 1));
        $table->construct_cell("<strong>.{$attachment_type['extension']}</strong>");
        $table->construct_cell(htmlspecialchars_uni($attachment_type['mimetype']));
        $table->construct_cell(get_friendly_size($attachment_type['maxsize'] * 1024), array("class" => "align_center"));
        $table->construct_cell("<a href=\"index.php?module=config-attachment_types&amp;action=edit&amp;atid={$attachment_type['atid']}\">{$lang->edit}</a>", array("class" => "align_center"));
        $table->construct_cell("<a href=\"index.php?module=config-attachment_types&amp;action=delete&amp;atid={$attachment_type['atid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_attachment_type_deletion}')\">{$lang->delete}</a>", array("class" => "align_center"));
        $table->construct_row();
    }
    if ($table->num_rows() == 0) {
        $table->construct_cell($lang->no_attachment_types, array('colspan' => 6));
        $table->construct_row();
    }
    $table->output($lang->attachment_types);
    $page->output_footer();
}
Пример #19
0
             eval("\$attachments .= \"" . $templates->get("post_attachments_attachment") . "\";");
         }
         $attachcount++;
     }
     $noshowattach = '';
     $query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='" . $mybb->user['uid'] . "'");
     $usage = $db->fetch_array($query);
     if ($usage['ausage'] > $mybb->usergroup['attachquota'] * 1024 && $mybb->usergroup['attachquota'] != 0) {
         $noshowattach = 1;
     }
     if ($mybb->usergroup['attachquota'] == 0) {
         $friendlyquota = $lang->unlimited;
     } else {
         $friendlyquota = get_friendly_size($mybb->usergroup['attachquota'] * 1024);
     }
     $friendlyusage = get_friendly_size($usage['ausage']);
     $lang->attach_quota = $lang->sprintf($lang->attach_quota, $friendlyusage, $friendlyquota);
     if ($mybb->settings['maxattachments'] == 0 || $mybb->settings['maxattachments'] != 0 && $attachcount < $mybb->settings['maxattachments'] && !$noshowattach) {
         eval("\$attach_add_options = \"" . $templates->get("post_attachments_add") . "\";");
     }
     if (($mybb->usergroup['caneditattachments'] || $forumpermissions['caneditattachments']) && $attachcount > 0) {
         eval("\$attach_update_options = \"" . $templates->get("post_attachments_update") . "\";");
     }
     if ($attach_add_options || $attach_update_options) {
         eval("\$newattach = \"" . $templates->get("post_attachments_new") . "\";");
     }
     eval("\$attachbox = \"" . $templates->get("post_attachments") . "\";");
 }
 // If the user is logged in, provide a save draft button.
 if ($mybb->user['uid']) {
     eval("\$savedraftbutton = \"" . $templates->get("post_savedraftbutton", 1, 0) . "\";");
Пример #20
0
function xthreads_fetch_url($url, $max_size = 0, $valid_ext = '', $valid_magic = array())
{
    global $lang;
    if (!$lang->xthreads_xtfurlerr_invalidurl) {
        $lang->load('xthreads');
    }
    $url = str_replace("", '', $url);
    $purl = @parse_url($url);
    if (xthreads_empty($purl['host'])) {
        return array('error' => $lang->xthreads_xtfurlerr_invalidurl);
    }
    // attempt to decode special IP tricks, eg 0x7F.0.0.0 or even 127.000.0.0
    if (substr_count($purl['host'], '.') == 3 && preg_match('~^[0-9a-fA-FxX.]+$~', $purl['host'])) {
        $parts = explode('.', $purl['host']);
        $modify = true;
        foreach ($parts as &$part) {
            if ($part === '') {
                return array('error' => $lang->xthreads_xtfurlerr_invalidurl);
            }
            if ($part[0] === '0' && isset($part[1])) {
                if ($part[1] == 'x' || $part[1] == 'X') {
                    // check hex digit
                    $hexpart = substr($part, 2);
                    if ($hexpart === '' || !ctype_xdigit($hexpart)) {
                        $modify = false;
                        break;
                    } else {
                        $part = hexdec($hexpart);
                    }
                } elseif (!is_numeric($part)) {
                    $modify = false;
                    break;
                } elseif (preg_match('~^[0-7]+$~', $part)) {
                    $part = octdec($part);
                } else {
                    $part = (int) $part;
                }
            } elseif (!is_numeric($part)) {
                $modify = false;
                break;
            } else {
                $part = (int) $part;
            }
            // converts stuff like 000 into 0, although above should do that
        }
        if ($modify) {
            $purl['host'] = implode('.', $parts);
        }
    } elseif (substr_count($purl['host'], ':') > 1 && substr_count($purl['host'], ':') < 8 && preg_match('~^\\[(?:[0-9a-f]{1,4}\\:){0,7}(?:\\:\\:?(?:[0-9a-f]{1,4}\\:){0,6})?(?:[0-9a-f]{1,4})\\]$~i', $purl['host']) && strpos($purl['host'], ':::') === false) {
        $parts = explode(':', strtolower(substr($purl['host'], 1, -1)));
        // expand double-colon
        $expand = 8 - count($parts);
        if ($expand) {
            if (($i = array_search('', $parts, true)) !== false) {
                array_splice($parts, $i, 1, array_fill(0, $expand + 1, '0'));
            }
            // TODO: check if IP is still valid
        }
        // strip leading zeros
        foreach ($parts as &$part) {
            $part = ltrim($part, '0');
            if ($part === '') {
                $part = '0';
            }
        }
        // compress stream of zeros
        $parts = implode(':', $parts);
        preg_match_all('~(?<=\\:)(0\\:){2,}~', ':' . $parts . ':', $ipzeros, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
        if (!empty($ipzeros) && !empty($ipzeros[0])) {
            $longest = 0;
            $longest_start = 0;
            foreach ($ipzeros[0] as $ipzero) {
                $l = strlen($ipzero[0]);
                if ($l > $longest) {
                    $longest = $l;
                    $longest_start = $ipzero[1];
                }
            }
            if ($longest && $longest_start) {
                // this should _always_ be true here
                $parts = ' ' . $parts;
                $parts = substr($parts, 0, $longest_start - 1) . '::' . substr($parts, $longest_start + $longest);
                $parts = ltrim($parts);
            }
        }
        $purl['host'] = '[' . $parts . ']';
    }
    if (XTHREADS_URL_FETCH_DISALLOW_HOSTS && in_array($purl['host'], array_map('trim', explode(',', XTHREADS_URL_FETCH_DISALLOW_HOSTS)))) {
        return array('error' => $lang->xthreads_xtfurlerr_badhost);
    }
    $portmap = array('http' => 80, 'https' => 443, 'ftp' => 21, 'ftps' => 990);
    $scheme = strtolower($purl['scheme']);
    if (!isset($portmap[$scheme])) {
        return array('error' => $lang->xthreads_xtfurlerr_invalidscheme);
    }
    if (!$purl['port']) {
        $purl['port'] = $portmap[$scheme];
    } elseif (XTHREADS_URL_FETCH_DISALLOW_PORT && $purl['port'] != $portmap[$scheme]) {
        return array('error' => $lang->xthreads_xtfurlerr_badport);
    }
    $ret = array('tmp_name' => tempnam(xthreads_get_temp_dir(), mt_rand()), 'name' => basename($purl['path']), 'name_disposition' => false, 'size' => 0);
    @unlink($ret['tmp_name']);
    if (substr($purl['path'], -1) == '/' || xthreads_empty($ret['name'])) {
        $ret['name'] = 'index.html';
    }
    require_once MYBB_ROOT . 'inc/xthreads/xt_urlfetcher.php';
    $fetcher = getXTUrlFetcher($purl['scheme']);
    if (!isset($fetcher)) {
        return array('error' => $lang->xthreads_xtfurlerr_nofetcher);
    }
    $fp = @fopen($ret['tmp_name'], 'wb');
    if (!$fp) {
        return array('error' => $lang->xthreads_xtfurlerr_cantwrite);
    }
    xthreads_fetch_url_register_tmp($ret['tmp_name']);
    @set_time_limit(0);
    $fetcher->url = $url;
    $fetcher->setRefererFromUrl();
    $fetcher->charset = $lang->settings['charset'];
    $fetcher->lang = $lang->settings['htmllang'];
    $GLOBALS['xtfurl_ret'] =& $ret;
    $GLOBALS['xtfurl_max_size'] = $max_size;
    $fetcher->meta_function = 'xthreads_fetch_url_meta';
    $GLOBALS['xtfurl_datalen'] = 0;
    $GLOBALS['xtfurl_magicchecked'] = false;
    $GLOBALS['xtfurl_validmagic'] =& $valid_magic;
    $GLOBALS['xtfurl_databuf'] = '';
    $GLOBALS['xtfurl_exts'] =& $valid_ext;
    $GLOBALS['xtfurl_fp'] =& $fp;
    $fetcher->body_function = 'xthreads_fetch_url_write';
    $result = $fetcher->fetch();
    // TODO: fix the following
    if ($result === false) {
        $error = $fetcher->getError($errcode);
        $langvar = 'xthreads_xtfurlerr_' . $error;
        if (isset($lang->{$langvar})) {
            $ret['error'] = $lang->{$langvar};
        } else {
            $ret['error'] = $lang->sprintf($lang->xthreads_xtfurlerr_errcode, $fetcher->name, $errcode, htmlspecialchars_uni($error));
        }
    }
    $fetcher->close();
    if (!$ret['error']) {
        // check magic if not done
        if ($result && !$GLOBALS['xtfurl_magicchecked'] && !empty($valid_magic)) {
            if (!xthreads_fetch_url_validmagic($GLOBALS['xtfurl_databuf'], $valid_magic)) {
                $GLOBALS['xtfurl_magicchecked'] = 'invalid';
                $result = null;
            }
        }
        if ($result === null) {
            // aborted - most likely from early termination
            if ($ret['size'] && $max_size && $ret['size'] > $max_size) {
                $ret['error'] = $lang->sprintf($lang->xthreads_xtaerr_error_attachsize, get_friendly_size($max_size));
            } elseif ($GLOBALS['xtfurl_magicchecked'] == 'invalid') {
                // this also covers extension check
                $ret['error'] = $lang->error_attachtype;
            }
        }
    }
    fclose($fp);
    if ($ret['error']) {
        @unlink($ret['tmp_name']);
    } else {
        $ret['size'] = @filesize($ret['tmp_name']);
        if ($ret['size'] < 1 || empty($ret['name'])) {
            // weird...
            @unlink($ret['tmp_name']);
        }
    }
    @set_time_limit(30);
    return $ret;
}
Пример #21
0
        admin_redirect("index.php?module=tools-cache");
    } else {
        flash_message($lang->error_cannot_rebuild, 'error');
        admin_redirect("index.php?module=tools-cache");
    }
}
if (!$mybb->input['action']) {
    $plugins->run_hooks("admin_tools_cache_start");
    $page->output_header($lang->cache_manager);
    $sub_tabs['cache_manager'] = array('title' => $lang->cache_manager, 'link' => "index.php?module=tools-cache", 'description' => $lang->cache_manager_description);
    $page->output_nav_tabs($sub_tabs, 'cache_manager');
    $table = new Table();
    $table->construct_header($lang->name);
    $table->construct_header($lang->size, array("class" => "align_center", "width" => 100));
    $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150));
    $query = $db->simple_select("datacache");
    while ($cacheitem = $db->fetch_array($query)) {
        $table->construct_cell("<strong><a href=\"index.php?module=tools-cache&amp;action=view&amp;title=" . urlencode($cacheitem['title']) . "\">{$cacheitem['title']}</a></strong>");
        $table->construct_cell(get_friendly_size(strlen($cacheitem['cache'])), array("class" => "align_center"));
        if (method_exists($cache, "update_" . $cacheitem['title'])) {
            $table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=rebuild&amp;title=" . urlencode($cacheitem['title']) . "&amp;my_post_key={$mybb->post_code}\">" . $lang->rebuild_cache . "</a>", array("class" => "align_center"));
        } elseif (method_exists($cache, "reload_" . $cacheitem['title'])) {
            $table->construct_cell("<a href=\"index.php?module=tools-cache&amp;action=reload&amp;title=" . urlencode($cacheitem['title']) . "&amp;my_post_key={$mybb->post_code}\">" . $lang->reload_cache . "</a>", array("class" => "align_center"));
        } else {
            $table->construct_cell("");
        }
        $table->construct_row();
    }
    $table->output($lang->cache_manager);
    $page->output_footer();
}
 if ($attachs['spaceused'] > 0) {
     $attach_average_size = round($attachs['spaceused'] / $attachs['numattachs']);
     $bandwidth_average_usage = round($attachs['bandwidthused']);
 } else {
     $attach_average_size = 0;
     $bandwidth_average_usage = 0;
 }
 $table->construct_cell("<strong>{$lang->total_cache_size}</strong>", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($cache->size_of()), array('width' => '25%'));
 $table->construct_cell("<strong>{$lang->estimated_attachment_bandwidth_usage}</strong>", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($bandwidth_average_usage), array('width' => '25%'));
 $table->construct_row();
 $table->construct_cell("<strong>{$lang->max_upload_post_size}</strong>", array('width' => '200'));
 $table->construct_cell(@ini_get('upload_max_filesize') . ' / ' . @ini_get('post_max_size'), array('width' => '200'));
 $table->construct_cell("<strong>{$lang->average_attachment_size}</strong>", array('width' => '25%'));
 $table->construct_cell(get_friendly_size($attach_average_size), array('width' => '25%'));
 $table->construct_row();
 $table->output($lang->stats);
 $table->construct_header($lang->task);
 $table->construct_header($lang->run_time, array("width" => 200, "class" => "align_center"));
 $task_cache = $cache->read("tasks");
 $nextrun = $task_cache['nextrun'];
 $query = $db->simple_select("tasks", "*", "nextrun >= '{$nextrun}' AND enabled='1'", array("order_by" => "nextrun", "order_dir" => "asc", 'limit' => 3));
 while ($task = $db->fetch_array($query)) {
     $task['title'] = htmlspecialchars_uni($task['title']);
     $next_run = date($mybb->settings['dateformat'], $task['nextrun']) . ", " . date($mybb->settings['timeformat'], $task['nextrun']);
     $table->construct_cell("<strong>{$task['title']}</strong>");
     $table->construct_cell($next_run, array("class" => "align_center"));
     $table->construct_row();
 }
 $table->output($lang->next_3_tasks);
Пример #23
0
/**
 * Fetch the attachments for a specific post and parse inline [attachment=id] code.
 * Note: assumes you have $attachcache, an array of attachments set up.
 *
 * @param int The ID of the item.
 * @param array The post or item passed by reference.
 */
function get_post_attachments($id, &$post)
{
    global $attachcache, $mybb, $theme, $templates, $forumpermissions, $lang;
    $validationcount = 0;
    $tcount = 0;
    if (isset($attachcache[$id]) && is_array($attachcache[$id])) {
        // This post has 1 or more attachments
        foreach ($attachcache[$id] as $aid => $attachment) {
            if ($attachment['visible']) {
                // There is an attachment thats visible!
                $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
                $attachment['filesize'] = get_friendly_size($attachment['filesize']);
                $ext = get_extension($attachment['filename']);
                if ($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg") {
                    $isimage = true;
                } else {
                    $isimage = false;
                }
                $attachment['icon'] = get_attachment_icon($ext);
                // Support for [attachment=id] code
                if (stripos($post['message'], "[attachment=" . $attachment['aid'] . "]") !== false) {
                    // Show as thumbnail IF image is big && thumbnail exists && setting=='thumb'
                    // Show as full size image IF setting=='fullsize' || (image is small && permissions allow)
                    // Show as download for all other cases
                    if ($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != "" && $mybb->settings['attachthumbnails'] == "yes") {
                        eval("\$attbit = \"" . $templates->get("postbit_attachments_thumbnails_thumbnail") . "\";");
                    } elseif (($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == 1 || $mybb->settings['attachthumbnails'] == "no") && $isimage) {
                        eval("\$attbit = \"" . $templates->get("postbit_attachments_images_image") . "\";");
                    } else {
                        eval("\$attbit = \"" . $templates->get("postbit_attachments_attachment") . "\";");
                    }
                    $post['message'] = preg_replace("#\\[attachment=" . $attachment['aid'] . "]#si", $attbit, $post['message']);
                } else {
                    // Show as thumbnail IF image is big && thumbnail exists && setting=='thumb'
                    // Show as full size image IF setting=='fullsize' || (image is small && permissions allow)
                    // Show as download for all other cases
                    if ($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != "" && $mybb->settings['attachthumbnails'] == "yes") {
                        eval("\$post['thumblist'] .= \"" . $templates->get("postbit_attachments_thumbnails_thumbnail") . "\";");
                        if ($tcount == 5) {
                            $thumblist .= "<br />";
                            $tcount = 0;
                        }
                        ++$tcount;
                    } elseif (($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == 1 || $mybb->settings['attachthumbnails'] == "no") && $isimage) {
                        eval("\$post['imagelist'] .= \"" . $templates->get("postbit_attachments_images_image") . "\";");
                    } else {
                        eval("\$post['attachmentlist'] .= \"" . $templates->get("postbit_attachments_attachment") . "\";");
                    }
                }
            } else {
                $validationcount++;
            }
        }
        if ($validationcount > 0 && is_moderator($post['fid'])) {
            if ($validationcount == 1) {
                $postbit_unapproved_attachments = $lang->postbit_unapproved_attachment;
            } else {
                $postbit_unapproved_attachments = $lang->sprintf($lang->postbit_unapproved_attachments, $validationcount);
            }
            eval("\$post['attachmentlist'] .= \"" . $templates->get("postbit_attachments_attachment_unapproved") . "\";");
        }
        if ($post['thumblist']) {
            eval("\$post['attachedthumbs'] = \"" . $templates->get("postbit_attachments_thumbnails") . "\";");
        }
        if ($post['imagelist']) {
            eval("\$post['attachedimages'] = \"" . $templates->get("postbit_attachments_images") . "\";");
        }
        if ($post['attachmentlist'] || $post['thumblist'] || $post['imagelist']) {
            eval("\$post['attachments'] = \"" . $templates->get("postbit_attachments") . "\";");
        }
    }
}
Пример #24
0
 public function __destruct()
 {
     global $start_timer, $load_timer, $db;
     $load_time = $start_timer - $load_timer;
     $end_timer = microtime(true);
     $total_time = $end_timer - $start_timer;
     $php_time = number_format($total_time - $db->query_time, 7);
     $query_time = number_format($db->query_time, 7);
     if ($total_time > 0) {
         $percentphp = number_format($php_time / $total_time * 100, 2);
         $percentsql = number_format($query_time / $total_time * 100, 2);
     } else {
         // if we've got a super fast script...  all we can do is assume something
         $percentphp = 0;
         $percentsql = 0;
     }
     $phpversion = PHP_VERSION;
     $serverload = get_server_load();
     $current_memory_usage = get_memory_usage();
     if ($current_memory_usage) {
         $memory_usage = " / Memory Usage: " . get_friendly_size($current_memory_usage);
     } else {
         $memory_usage = '';
     }
     $this->trace0("Generated in {$total_time} seconds ({$percentphp}% PHP / {$percentsql}% MySQL) / Initialize Load Time: {$load_time} / SQL Queries: {$db->query_count}{$memory_usage} PHP version: {$phpversion} / Server Load: {$serverload}");
 }