Example #1
0
$frm->addrow("Reverse Threading", $frm->select_tag("reverse_threading", array("No", "Yes"), $reverse_threading, $disabled_form_input));
$frm->addrow("Move Threads On Reply", $frm->select_tag("float_to_top", array("No", "Yes"), $float_to_top, $disabled_form_input));
$frm->addrow("Message List Length (Flat Mode)", $frm->text_box("list_length_flat", $list_length_flat, 10, false, false, $disabled_form_input));
$frm->addrow("Message List Length (Threaded Mode, Nr. of Threads)", $frm->text_box("list_length_threaded", $list_length_threaded, 10, false, false, $disabled_form_input));
$frm->addrow("Read Page Length", $frm->text_box("read_length", $read_length, 10, false, false, $disabled_form_input));
$frm->addrow("Display IP Addresses <small>(note: admins always see it)</small>", $frm->select_tag("display_ip_address", array("No", "Yes"), $display_ip_address, $disabled_form_input));
$frm->addrow("Count views", $frm->select_tag("count_views", array(0 => "No", 1 => "Yes, show views added to subject", 2 => "Yes, show views as extra column"), $count_views, $disabled_form_input));
$row = $frm->addrow("Count views per thread for non-threaded list views", $frm->select_tag("count_views_per_thread", array(0 => "No", 1 => "Yes"), $count_views_per_thread, $disabled_form_input));
$frm->addhelp($row, "Count views per thread for non-threaded list", "By default, Phorum only counts views per message. While this is okay\n     for a forum that runs in threaded view (since there you will always\n     show only one message at a time), it might not work well for forums\n     that run in a non-threaded view (there only one message will get\n     its view count updated, although multiple messages might show).\n     Additionally, if the list view is flat and the read view is threaded, the\n     view count on the list view will only show how often the first message\n     in the thread was viewed.<br/>\n     <br/>\n     With this option enabled, a separate view counter will be updated\n     for the full thread when viewing any of the read pages for that thread.\n     For non-threaded list views, this counter will then be used as the view\n     count for the thread. Note that this does require an extra SQL query\n     to update the separate counter, so on very busy servers you might not\n     want to enable this option.");
$frm->addbreak("Posting Settings");
$frm->addrow("Check for Duplicates", $frm->select_tag("check_duplicate", array("No", "Yes"), $check_duplicate, $disabled_form_input));
$frm->addbreak("Attachment Settings");
$frm->addrow("Number Allowed (0 to disable)", $frm->text_box("max_attachments", $max_attachments, 10, false, false, $disabled_form_input));
$frm->addrow("Allowed Files (eg: gif;jpg;png, empty for any)", $frm->text_box("allow_attachment_types", $allow_attachment_types, 10, false, false, $disabled_form_input));
list($system_max_upload, $php_max_upload, $db_max_upload) = phorum_get_system_max_upload();
$max_size = phorum_api_format_filesize($system_max_upload);
$row = $frm->addrow("Max File Size In KB ({$max_size} maximum)", $frm->text_box("max_attachment_size", $max_attachment_size, 10, false, false, $disabled_form_input));
$frm->addhelp($row, "Max File Size", "This is the maximum that one uploaded file can be.  If you see a maximum here, that is the maximum imposed by either your PHP installation, database server or both.  Leaving this field as 0 will use this maximum.");
$frm->addrow("Max cumulative File Size In KB (0 for unlimited)", $frm->text_box("max_totalattachment_size", $max_totalattachment_size, 10, false, false, $disabled_form_input));
$frm->show();
?>

<script type="text/javascript">
//<![CDATA[

// Handle changes to the setting inheritance select list.
$PJ('select[name=inherit_id]').change(function updateInheritedFields()
{
    var inherit = $PJ('select[name=inherit_id]').val();

    // No inheritance. All fields will be made read/write.
Example #2
0
////////////////////////////////////////////////////////////////////////////////
if (!defined("PHORUM_ADMIN")) {
    return;
}
require_once './include/api/file.php';
// Execute file purging for real?
if (count($_POST)) {
    $deleted = phorum_api_file_purge_stale(TRUE);
    phorum_admin_okmsg("Purged " . count($deleted) . " files");
}
// Retrieve a list of stale files.
$purge_files = phorum_api_file_purge_stale(FALSE);
require_once './include/admin/PhorumInputForm.php';
$frm = new PhorumInputForm("", "post", count($purge_files) ? "Purge stale files now" : "Refresh screen");
$frm->hidden("module", "file_purge");
$frm->addbreak("Purging stale files...");
$frm->addmessage("It's possible that there are files stored in the Phorum system,\n     which no longer are linked to anything. For example, if users\n     write messages with attachments, but do not post them in the end,\n     the attachment files will be left behind in the database.\n     Using this maintenance tool, you can purge those stale files\n     from the system.");
$prev_reason = '';
if (count($purge_files)) {
    $frm->addbreak("There are currently " . count($purge_files) . " stale files in the database");
    foreach ($purge_files as $id => $file) {
        if ($file['reason'] != $prev_reason) {
            $prev_reason = $file['reason'];
            $frm->addsubbreak("Reason: " . $file['reason']);
        }
        $frm->addrow(htmlspecialchars($file["filename"]), phorum_api_format_filesize($file["filesize"]));
    }
} else {
    $frm->addmessage("There are currently no stale files in the database");
}
$frm->show();
Example #3
0
    }
}
// ----------------------------------------------------------------------
// Display the files for the current user.
// ----------------------------------------------------------------------
$files = $PHORUM['DB']->get_user_file_list($PHORUM["user"]["user_id"]);
$total_size = 0;
foreach ($files as $key => $file) {
    $files[$key]["filesize"] = phorum_api_format_filesize($file["filesize"]);
    $files[$key]["raw_dateadded"] = $file["add_datetime"];
    $files[$key]["dateadded"] = phorum_api_format_date($PHORUM["short_date_time"], $file["add_datetime"]);
    $files[$key]["url"] = phorum_api_url(PHORUM_FILE_URL, "file={$key}", "filename=" . urlencode($file['filename']));
    $total_size += $file["filesize"];
}
$template = "cc_files";
if ($PHORUM["max_file_size"]) {
    $PHORUM["DATA"]["FILE_SIZE_LIMIT"] = $PHORUM["DATA"]["LANG"]["FileSizeLimits"] . ' ' . phorum_api_format_filesize($PHORUM["max_file_size"] * 1024);
}
if ($PHORUM["file_types"]) {
    $PHORUM["DATA"]["FILE_TYPE_LIMIT"] = $PHORUM["DATA"]["LANG"]["FileTypeLimits"];
}
if ($PHORUM["file_space_quota"]) {
    $PHORUM["DATA"]["FILE_QUOTA_LIMIT"] = $PHORUM["DATA"]["LANG"]["FileQuotaLimits"] . ' ' . phorum_api_format_filesize($PHORUM["file_space_quota"] * 1024);
}
foreach ($files as $id => $file) {
    $files[$id]['filename'] = htmlspecialchars($file['filename'], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
}
$PHORUM["DATA"]["FILES"] = $files;
$PHORUM["DATA"]["TOTAL_FILES"] = count($files);
$PHORUM["DATA"]["TOTAL_FILE_SIZE"] = phorum_api_format_filesize($total_size);
Example #4
0
/**
 * @deprecated Replaced by {@link phorum_api_format_filesize()}.
 */
function phorum_filesize($sz)
{
    return phorum_api_format_filesize($sz);
}
Example #5
0
     }
     // This one is filled from the language file, so there's no need
     // to run htmlspecialchars on this one.
     if ($var == "submitbutton_text") {
         continue;
     }
     if ($var == "attachments") {
         if (is_array($val)) {
             foreach ($val as $nr => $data) {
                 // Do not show attachments which are not kept.
                 if (!$data["keep"]) {
                     unset($message["attachments"][$nr]);
                     continue;
                 }
                 $message[$var][$nr]["name"] = htmlspecialchars($data["name"], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
                 $message[$var][$nr]["size"] = phorum_api_format_filesize(round($data["size"]));
             }
         }
     } elseif ($var == "author") {
         if (empty($PHORUM["custom_display_name"])) {
             $message[$var] = htmlspecialchars($val, ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
         }
     } else {
         if (is_scalar($val)) {
             $message[$var] = htmlspecialchars($val, ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
         } else {
             // Not used in the template, unless proven otherwise.
             $message[$var] = '[removed from template data]';
         }
     }
 }
Example #6
0
    if (function_exists("phorum_api_cache_purge")) {
        $full_purge = isset($_POST["purge_all"]) && $_POST["purge_all"];
        $report = phorum_api_cache_purge($full_purge);
        print $report . "<br/>";
    }
    // Cleanup compiled templates.
    $purged = 0;
    $dh = opendir($PHORUM['CACHECONFIG']['directory']);
    if (!$dh) {
        die("Can't opendir " . htmlspecialchars($PHORUM['CACHECONFIG']['directory']));
    }
    while ($entry = readdir($dh)) {
        if (preg_match('/^tpl-.*[a-f0-9]{32}\\.php(-stage2)?$/', $entry)) {
            $compiled_tpl = $PHORUM['CACHECONFIG']['directory'] . "/{$entry}";
            $size = filesize($compiled_tpl);
            if (@unlink($compiled_tpl)) {
                $purged += $size;
            }
        }
    }
    print "Finished purging compiled Phorum templates<br/>\n" . "Purged " . phorum_api_format_filesize($purged) . "<br/>";
    print "<br/>";
    print "DONE<br/><br/>";
}
require_once './include/admin/PhorumInputForm.php';
$frm = new PhorumInputForm("", "post", "Purge cache");
$frm->hidden("module", "cache_purge");
$frm->addbreak("Purging the Phorum cache");
$frm->addmessage("For improving performance, Phorum uses caching techniques for taking some load of the database and webserver. After running Phorum for some time, the amount of cached data will grow though. Using this maintenance tool, you can purge stale data from the Phorum cache to bring it back in size. Purging the cache will also cleanup all compiled template files.");
$frm->addrow("Cleanup all cache items, not only the expired ones", $frm->select_tag("purge_all", array("No", "Yes"), 0));
$frm->show();
Example #7
0
/**
 * Check if the active user has permissions to store a personal
 * file or a message attachment.
 *
 * Note that the checks for message attachments aren't all checks that are
 * done by Phorum. The attachment posting script does run some additional
 * checks on the message level (e.g. to see if the maximum cumulative
 * attachment size is not exceeded).
 *
 * @example file_store.php Store a personal file.
 *
 * @param array $file
 *     This is an array, containing information about the
 *     file that will be uploaded. The array should contain at least the
 *     "link" field. That field will be used to handle checking for personal
 *     uploaded files in the control center (PHORUM_LINK_USER) or message
 *     attachments (PHORUM_LINK_MESSAGE). Next to that, interesting file
 *     fields to pass to this function are "filesize" (to check maximum size)
 *     and "filename" (to check allowed file type extensions). A "user_id"
 *     field can either be provided or the user_id of the active Phorum
 *     user will be used.
 *
 * @return array
 *     If access is allowed, then TRUE will be returned. If access is denied,
 *     then FALSE will be returned. The functions
 *     {@link phorum_api_error_message()} and {@link phorum_api_error_code()}
 *     can be used to retrieve information about the error that occurred.
 */
function phorum_api_file_check_write_access($file)
{
    global $PHORUM;
    // Reset error storage.
    $PHORUM["API"]["errno"] = NULL;
    $PHORUM["API"]["error"] = NULL;
    if (!isset($file["link"])) {
        trigger_error("phorum_api_file_check_write_access(): \$file parameter needs a " . "\"link\" field.", E_USER_ERROR);
    }
    if (empty($file["user_id"])) {
        $file["user_id"] = $PHORUM["user"]["user_id"];
    }
    // ---------------------------------------------------------------------
    // Handle write access checks for uploading user files.
    // ---------------------------------------------------------------------
    if ($file["link"] == PHORUM_LINK_USER) {
        // If file uploads are enabled, then access is granted. Access
        // is always granted to administrator users.
        if (!$PHORUM["file_uploads"] && !$PHORUM["user"]["admin"]) {
            return phorum_api_error(PHORUM_ERRNO_NOACCESS, $PHORUM["DATA"]["LANG"]["UploadNotAllowed"]);
        }
        // Check if the file doesn't exceed the maximum allowed file size.
        if (isset($file["filesize"]) && $PHORUM["max_file_size"] > 0 && $file["filesize"] > $PHORUM["max_file_size"] * 1024) {
            return phorum_api_error(PHORUM_ERRNO_NOACCESS, $PHORUM["DATA"]["LANG"]["FileTooLarge"]);
        }
        // Check if the user won't exceed the file quota when storing the file.
        if (isset($file["filesize"]) && $PHORUM["file_space_quota"] > 0) {
            $sz = $PHORUM['DB']->get_user_filesize_total($PHORUM["user"]["user_id"]);
            $sz += $file["filesize"];
            if ($sz > $PHORUM["file_space_quota"] * 1024) {
                return phorum_api_error(PHORUM_ERRNO_NOACCESS, $PHORUM["DATA"]["LANG"]["FileOverQuota"]);
            }
        }
        // Check if the file type is allowed.
        if (isset($file["filename"]) && isset($PHORUM["file_types"]) && trim($PHORUM["file_types"]) != '') {
            // Determine the file extension for the file.
            $pos = strrpos($file["filename"], ".");
            if ($pos !== FALSE) {
                $ext = strtolower(substr($file["filename"], $pos + 1));
            } else {
                $ext = strtolower($file["filename"]);
            }
            // Create an array of allowed file extensions.
            $allowed_exts = explode(";", strtolower($PHORUM["file_types"]));
            // Check if the extension for the file is an allowed extension.
            if (!in_array($ext, $allowed_exts)) {
                return phorum_api_error(PHORUM_ERRNO_NOACCESS, $PHORUM["DATA"]["LANG"]["FileWrongType"]);
            }
        }
    } elseif ($file["link"] == PHORUM_LINK_EDITOR || $file["link"] == PHORUM_LINK_MESSAGE) {
        // Check if the file doesn't exceed the maximum allowed file size
        // for the active forum.
        if (isset($file["filesize"])) {
            // Find the maximum allowed attachment size. This depends on
            // both the settings for the current forum and the limits
            // that are enforced by the system.
            require_once PHORUM_PATH . '/include/api/system.php';
            list($max_upload, $php_max_upload, $db_max_upload) = phorum_get_system_max_upload();
            $max_forum = $PHORUM["max_attachment_size"] * 1024;
            if ($max_forum > 0 && $max_forum < $max_upload) {
                $max_upload = $max_forum;
            }
            // Check if the file doesn't exceed the maximum allowed size.
            if ($max_upload > 0 && $file["filesize"] > $max_upload) {
                return phorum_api_error(PHORUM_ERRNO_NOACCESS, str_replace('%size%', phorum_api_format_filesize($max_upload), $PHORUM["DATA"]["LANG"]["AttachFileSize"]));
            }
        }
        // Check if the file type is allowed for the active forum.
        if (isset($file["filename"]) && isset($PHORUM["allow_attachment_types"]) && trim($PHORUM["allow_attachment_types"]) != '') {
            // Determine the file extension for the file.
            $pos = strrpos($file["filename"], ".");
            if ($pos !== FALSE) {
                $ext = strtolower(substr($file["filename"], $pos + 1));
            } else {
                $ext = strtolower($file["filename"]);
            }
            // Create an array of allowed file extensions.
            $allowed_exts = explode(";", strtolower($PHORUM["allow_attachment_types"]));
            // Check if the extension for the file is an allowed extension.
            if (!in_array($ext, $allowed_exts)) {
                return phorum_api_error(PHORUM_ERRNO_NOACCESS, $PHORUM["DATA"]["LANG"]["AttachInvalidType"] . " " . str_replace('%types%', implode(", ", $allowed_exts), $PHORUM["DATA"]["LANG"]["AttachFileTypes"]));
            }
        }
    }
    return TRUE;
}
Example #8
0
function phorum_single_check_upload_limits($howmuch, $what, $maxphp, $maxdb)
{
    // Check PHP limits.
    if (!empty($maxphp) && $howmuch > $maxphp) {
        return array(PHORUM_SANITY_WARN, "You have configured " . htmlspecialchars($what) . " to " . phorum_api_format_filesize($howmuch) . ". Your PHP installation only\n         supports " . phorum_api_format_filesize($maxphp) . ". Your users might\n         have problems with uploading their files because of this.", "Raise the options post_max_size and upload_max_filesize in your\n         php.ini file to match the Max File Size option or lower this\n         configuration option for your forums.");
    }
    // Check database limits.
    if (!empty($maxdb) && $howmuch > $maxdb) {
        return array(PHORUM_SANITY_WARN, "You have configured " . htmlspecialchars($what) . " to " . phorum_api_format_filesize($howmuch) . ". Your database only supports " . phorum_api_format_filesize($maxdb) . ". Your users might have problems\n         with uploading their files because of this.", "Configure your database to allow larger packets or lower the\n         Max File Size configuration option for your forums.");
    }
    return NULL;
}
Example #9
0
             if ($row["moderator_post"]) {
                 $row["ip"] = $PHORUM["DATA"]["LANG"]["Moderator"];
             } elseif (is_numeric(str_replace(".", "", $row["ip"]))) {
                 $row["ip"] = substr($row["ip"], 0, strrpos($row["ip"], '.')) . '.---';
             } else {
                 $row["ip"] = "---" . strstr($row["ip"], ".");
             }
         } else {
             $row["ip"] = "";
         }
     }
     if ($PHORUM["max_attachments"] > 0 && isset($row["meta"]["attachments"])) {
         $row["attachments"] = $row["meta"]["attachments"];
         // unset($row["meta"]["attachments"]);
         foreach ($row["attachments"] as $key => $file) {
             $row["attachments"][$key]["size"] = phorum_api_format_filesize($file["size"]);
             $row["attachments"][$key]["name"] = htmlspecialchars($file['name'], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
             $safe_file = preg_replace('/[^\\w\\_\\-\\.]/', '_', $file['name']);
             $safe_file = preg_replace('/_+/', '_', $safe_file);
             $row["attachments"][$key]["url"] = str_replace(array('%file_id%', '%file_name%'), array($file['file_id'], $safe_file), $attachment_url_template);
             $row["attachments"][$key]["download_url"] = str_replace(array('%file_id%', '%file_name%'), array($file['file_id'], $safe_file), $attachment_download_url_template);
         }
     }
     $messages[$row["message_id"]] = $row;
 }
 if ($PHORUM["threaded_read"]) {
     // run read-threads mods
     if (isset($PHORUM["hooks"]["readthreads"])) {
         $messages = phorum_api_hook("readthreads", $messages);
     }
     $messages = phorum_api_thread_sort($messages);
Example #10
0
File: file.php Project: netovs/Core
/**
 * Remove all expired objects from the cache.
 *
 * @param boolean $full
 *     If TRUE, then the full cache will be expired, not only the
 *     expired part of the cache.
 *
 * @return string
 *     A string describing the result status. This is used by the
 *     cache purging screen in the admin interface to show the result.
 */
function phorum_api_cache_purge($full = FALSE)
{
    global $PHORUM;
    $cache_path = phorum_api_cache_mkpath();
    list($total, $purged, $dummy) = phorum_api_cache_purge_recursive($cache_path, "", 0, 0, $full);
    // Return a report about the purging action.
    return "Finished purging the file based data cache<br/>\n" . "Purged " . phorum_api_format_filesize($purged) . " of " . phorum_api_format_filesize($total) . "<br/>\n";
}
Example #11
0
$previewmessage = $message;
// Add the message author's signature to the message body.
if (isset($message["user_id"]) && !empty($message["user_id"])) {
    $user = phorum_api_user_get($message["user_id"]);
    if ($user && $message["show_signature"]) {
        $previewmessage["body"] .= "\n\n" . $user["signature"];
    }
}
// Add the list of attachments.
if ($attach_count) {
    define('PREVIEW_NO_ATTACHMENT_CLICK', "javascript:alert('" . $PHORUM["DATA"]["LANG"]["PreviewNoClickAttach"] . "')");
    // Create the URL and formatted size for attachment files.
    foreach ($previewmessage["attachments"] as $nr => $data) {
        $previewmessage["attachments"][$nr]["url"] = phorum_api_url(PHORUM_FILE_URL, "file={$data['file_id']}", "filename=" . urlencode($data['name']));
        $previewmessage["attachments"][$nr]["download_url"] = phorum_api_url(PHORUM_FILE_URL, "file={$data['file_id']}", "filename=" . urlencode($data['name']), "download=1");
        $previewmessage["attachments"][$nr]["size"] = phorum_api_format_filesize($data["size"]);
    }
}
// Fill the author for new postings with the display name
// for authenticated users, if editing the author
// field is not allowed.
if (($mode == "post" || $mode == "reply") && !$PHORUM["DATA"]["OPTION_ALLOWED"]["edit_author"] && $PHORUM["DATA"]["LOGGEDIN"]) {
    $previewmessage["author"] = $message["author"] = $PHORUM["user"]["display_name"];
}
// Format the message using the default formatting.
$formatted = phorum_api_format_messages(array($previewmessage['message_id'] => $previewmessage));
$previewmessage = $formatted[$previewmessage['message_id']];
// Recount the number of attachments. Formatting mods might have changed
// the number of attachments we have to display using default formatting.
// Also, remove the attachments that are not visible from the preview data.
$attach_count = 0;
Example #12
0
 // zero in size. We asume that people who upload zero byte
 // files will almost always have problems uploading. We simply
 // skip 0 byte files here, so after this loop we'll show a
 // generic upload error if no files were uploaded in the end.
 if ($file["size"] == 0) {
     continue;
 }
 // Let the file storage API run some upload access checks
 // (maximum attachment file size and file type).
 if (!phorum_api_file_check_write_access(array("link" => PHORUM_LINK_EDITOR, "filename" => $file["name"], "filesize" => $file["size"]))) {
     $PHORUM["DATA"]["ERROR"] = phorum_api_error_message();
     break;
 }
 // Check if the total cumulative attachment size isn't too large.
 if ($PHORUM["max_totalattachment_size"] > 0 && $file["size"] + $attach_totalsize > $PHORUM["max_totalattachment_size"] * 1024) {
     $PHORUM["DATA"]["ERROR"] = str_replace('%size%', phorum_api_format_filesize($PHORUM["max_totalattachment_size"] * 1024), $PHORUM["DATA"]["LANG"]["AttachTotalFileSize"]);
     break;
 }
 // Add the file data and user_id to the file info for the hook call.
 $file["data"] = @file_get_contents($file["tmp_name"]);
 $file["user_id"] = $PHORUM["user"]["user_id"];
 /*
  * [hook]
  *     before_attach
  *
  * [description]
  *     The primary use of this hook would be for creating an
  *     alternate storage system for attachments. You would need to use
  *     the <hook>after_attach</hook> hook to complete the process as you
  *     do not yet have the <literal>file_id</literal> for the file. You
  *     will need to use the <hook>file_retrieve</hook> hook to retreive