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


PHP phpbb_unlink函数代码示例

本文整理汇总了PHP中phpbb_unlink函数的典型用法代码示例。如果您正苦于以下问题:PHP phpbb_unlink函数的具体用法?PHP phpbb_unlink怎么用?PHP phpbb_unlink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: parse_attachments

    /**
     * Parse Attachments
     */
    function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false)
    {
        global $config, $auth, $user, $phpbb_root_path, $phpEx, $db;
        $error = array();
        $num_attachments = sizeof($this->attachment_data);
        $this->filename_data['filecomment'] = utf8_normalize_nfc(request_var('filecomment', '', true));
        $upload_file = isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name']) ? true : false;
        $add_file = isset($_POST['add_file']) ? true : false;
        $delete_file = isset($_POST['delete_file']) ? true : false;
        // First of all adjust comments if changed
        $actual_comment_list = utf8_normalize_nfc(request_var('comment_list', array(''), true));
        foreach ($actual_comment_list as $comment_key => $comment) {
            if (!isset($this->attachment_data[$comment_key])) {
                continue;
            }
            if ($this->attachment_data[$comment_key]['attach_comment'] != $actual_comment_list[$comment_key]) {
                $this->attachment_data[$comment_key]['attach_comment'] = $actual_comment_list[$comment_key];
            }
        }
        $cfg = array();
        $cfg['max_attachments'] = $is_message ? $config['max_attachments_pm'] : $config['max_attachments'];
        $forum_id = $is_message ? 0 : $forum_id;
        if ($submit && in_array($mode, array('post', 'reply', 'quote', 'edit')) && $upload_file) {
            if ($num_attachments < $cfg['max_attachments'] || $auth->acl_get('a_') || $auth->acl_get('m_', $forum_id)) {
                $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
                $error = $filedata['error'];
                if ($filedata['post_attach'] && !sizeof($error)) {
                    $sql_ary = array('physical_filename' => $filedata['physical_filename'], 'attach_comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'thumbnail' => $filedata['thumbnail'], 'is_orphan' => 1, 'in_message' => $is_message ? 1 : 0, 'poster_id' => $user->data['user_id']);
                    $db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                    $new_entry = array('attach_id' => $db->sql_nextid(), 'is_orphan' => 1, 'real_filename' => $filedata['real_filename'], 'attach_comment' => $this->filename_data['filecomment']);
                    $this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
                    $this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
                    $this->filename_data['filecomment'] = '';
                    // This Variable is set to false here, because Attachments are entered into the
                    // Database in two modes, one if the id_list is 0 and the second one if post_attach is true
                    // Since post_attach is automatically switched to true if an Attachment got added to the filesystem,
                    // but we are assigning an id of 0 here, we have to reset the post_attach variable to false.
                    //
                    // This is very relevant, because it could happen that the post got not submitted, but we do not
                    // know this circumstance here. We could be at the posting page or we could be redirected to the entered
                    // post. :)
                    $filedata['post_attach'] = false;
                }
            } else {
                $error[] = sprintf($user->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']);
            }
        }
        if ($preview || $refresh || sizeof($error)) {
            // Perform actions on temporary attachments
            if ($delete_file) {
                include_once $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
                $index = array_keys(request_var('delete_file', array(0 => 0)));
                $index = !empty($index) ? $index[0] : false;
                if ($index !== false && !empty($this->attachment_data[$index])) {
                    // delete selected attachment
                    if ($this->attachment_data[$index]['is_orphan']) {
                        $sql = 'SELECT attach_id, physical_filename, thumbnail
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id'] . '
								AND is_orphan = 1
								AND poster_id = ' . $user->data['user_id'];
                        $result = $db->sql_query($sql);
                        $row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        if ($row) {
                            phpbb_unlink($row['physical_filename'], 'file');
                            if ($row['thumbnail']) {
                                phpbb_unlink($row['physical_filename'], 'thumbnail');
                            }
                            $db->sql_query('DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id']);
                        }
                    } else {
                        delete_attachments('attach', array(intval($this->attachment_data[$index]['attach_id'])));
                    }
                    unset($this->attachment_data[$index]);
                    $this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "(\\1 == \$index) ? '' : ((\\1 > \$index) ? '[attachment=' . (\\1 - 1) . ']\\2[/attachment]' : '\\0')", $this->message);
                    // Reindex Array
                    $this->attachment_data = array_values($this->attachment_data);
                }
            } else {
                if (($add_file || $preview) && $upload_file) {
                    if ($num_attachments < $cfg['max_attachments'] || $auth->acl_gets('m_', 'a_', $forum_id)) {
                        $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
                        $error = array_merge($error, $filedata['error']);
                        if (!sizeof($error)) {
                            $sql_ary = array('physical_filename' => $filedata['physical_filename'], 'attach_comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'thumbnail' => $filedata['thumbnail'], 'is_orphan' => 1, 'in_message' => $is_message ? 1 : 0, 'poster_id' => $user->data['user_id']);
                            $db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                            $new_entry = array('attach_id' => $db->sql_nextid(), 'is_orphan' => 1, 'real_filename' => $filedata['real_filename'], 'attach_comment' => $this->filename_data['filecomment']);
                            $this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
                            $this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
                            $this->filename_data['filecomment'] = '';
                        }
                    } else {
                        $error[] = sprintf($user->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']);
                    }
                }
            }
//.........这里部分代码省略.........
开发者ID:jvinhit,项目名称:php,代码行数:101,代码来源:message_parser.php

示例2: delete_attachments

/**
* Delete Attachments
*
* @param string $mode can be: post|message|topic|attach|user
* @param mixed $ids can be: post_ids, message_ids, topic_ids, attach_ids, user_ids
* @param bool $resync set this to false if you are deleting posts or topics
*/
function delete_attachments($mode, $ids, $resync = true)
{
    global $db, $config;
    if (is_array($ids) && sizeof($ids)) {
        $ids = array_unique($ids);
        $ids = array_map('intval', $ids);
    } else {
        $ids = array((int) $ids);
    }
    if (!sizeof($ids)) {
        return false;
    }
    switch ($mode) {
        case 'post':
        case 'message':
            $sql_id = 'post_msg_id';
            break;
        case 'topic':
            $sql_id = 'topic_id';
            break;
        case 'user':
            $sql_id = 'poster_id';
            break;
        case 'attach':
        default:
            $sql_id = 'attach_id';
            $mode = 'attach';
            break;
    }
    $post_ids = $message_ids = $topic_ids = $physical = array();
    // Collect post and topic ids for later use if we need to touch remaining entries (if resync is enabled)
    $sql = 'SELECT post_msg_id, topic_id, in_message, physical_filename, thumbnail, filesize, is_orphan
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE ' . $db->sql_in_set($sql_id, $ids);
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
        // We only need to store post/message/topic ids if resync is enabled and the file is not orphaned
        if ($resync && !$row['is_orphan']) {
            if (!$row['in_message']) {
                $post_ids[] = $row['post_msg_id'];
                $topic_ids[] = $row['topic_id'];
            } else {
                $message_ids[] = $row['post_msg_id'];
            }
        }
        $physical[] = array('filename' => $row['physical_filename'], 'thumbnail' => $row['thumbnail'], 'filesize' => $row['filesize'], 'is_orphan' => $row['is_orphan']);
    }
    $db->sql_freeresult($result);
    // Delete attachments
    $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
		WHERE ' . $db->sql_in_set($sql_id, $ids);
    $db->sql_query($sql);
    $num_deleted = $db->sql_affectedrows();
    if (!$num_deleted) {
        return 0;
    }
    // Delete attachments from filesystem
    $space_removed = $files_removed = 0;
    foreach ($physical as $file_ary) {
        if (phpbb_unlink($file_ary['filename'], 'file', true) && !$file_ary['is_orphan']) {
            // Only non-orphaned files count to the file size
            $space_removed += $file_ary['filesize'];
            $files_removed++;
        }
        if ($file_ary['thumbnail']) {
            phpbb_unlink($file_ary['filename'], 'thumbnail', true);
        }
    }
    if ($space_removed || $files_removed) {
        set_config('upload_dir_size', $config['upload_dir_size'] - $space_removed, true);
        set_config('num_files', $config['num_files'] - $files_removed, true);
    }
    // If we do not resync, we do not need to adjust any message, post, topic or user entries
    if (!$resync) {
        return $num_deleted;
    }
    // No more use for the original ids
    unset($ids);
    // Now, we need to resync posts, messages, topics. We go through every one of them
    $post_ids = array_unique($post_ids);
    $message_ids = array_unique($message_ids);
    $topic_ids = array_unique($topic_ids);
    // Update post indicators for posts now no longer having attachments
    if (sizeof($post_ids)) {
        $sql = 'UPDATE ' . POSTS_TABLE . '
			SET post_attachment = 0
			WHERE ' . $db->sql_in_set('post_id', $post_ids);
        $db->sql_query($sql);
    }
    // Update message table if messages are affected
    if (sizeof($message_ids)) {
        $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
			SET message_attachment = 0
//.........这里部分代码省略.........
开发者ID:bryanveloso,项目名称:sayonarane,代码行数:101,代码来源:functions_admin.php

示例3: main


//.........这里部分代码省略.........
                            $s_forum_id_options .= $holding;
                        }
                        $db->sql_freeresult($result);
                        unset($padding_store);
                        $template->assign_vars(array('S_FORUM_ID_OPTIONS' => $s_forum_id_options));
                        break;
                }
                $sql = 'SELECT *
					FROM ' . EXTENSION_GROUPS_TABLE . '
					ORDER BY allow_group DESC, allow_in_pm DESC, group_name';
                $result = $db->sql_query($sql);
                $old_allow_group = $old_allow_pm = 1;
                while ($row = $db->sql_fetchrow($result)) {
                    $s_add_spacer = $old_allow_group != $row['allow_group'] || $old_allow_pm != $row['allow_in_pm'] ? true : false;
                    $template->assign_block_vars('groups', array('S_ADD_SPACER' => $s_add_spacer, 'S_ALLOWED_IN_PM' => $row['allow_in_pm'] ? true : false, 'S_GROUP_ALLOWED' => $row['allow_group'] ? true : false, 'U_EDIT' => $this->u_action . "&amp;action=edit&amp;g={$row['group_id']}", 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;g={$row['group_id']}", 'GROUP_NAME' => $row['group_name'], 'CATEGORY' => $cat_lang[$row['cat_id']]));
                    $old_allow_group = $row['allow_group'];
                    $old_allow_pm = $row['allow_in_pm'];
                }
                $db->sql_freeresult($result);
                break;
            case 'orphan':
                if ($submit) {
                    $delete_files = isset($_POST['delete']) ? array_keys(request_var('delete', array('' => 0))) : array();
                    $add_files = isset($_POST['add']) ? array_keys(request_var('add', array('' => 0))) : array();
                    $post_ids = request_var('post_id', array('' => 0));
                    if (sizeof($delete_files)) {
                        $sql = 'SELECT *
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
								AND is_orphan = 1';
                        $result = $db->sql_query($sql);
                        $delete_files = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            phpbb_unlink($row['physical_filename'], 'file');
                            if ($row['thumbnail']) {
                                phpbb_unlink($row['physical_filename'], 'thumbnail');
                            }
                            $delete_files[$row['attach_id']] = $row['real_filename'];
                        }
                        $db->sql_freeresult($result);
                    }
                    if (sizeof($delete_files)) {
                        $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files));
                        $db->sql_query($sql);
                        add_log('admin', 'LOG_ATTACH_ORPHAN_DEL', implode(', ', $delete_files));
                        $notify[] = sprintf($user->lang['LOG_ATTACH_ORPHAN_DEL'], implode(', ', $delete_files));
                    }
                    $upload_list = array();
                    foreach ($add_files as $attach_id) {
                        if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id])) {
                            $upload_list[$attach_id] = $post_ids[$attach_id];
                        }
                    }
                    unset($add_files);
                    if (sizeof($upload_list)) {
                        $template->assign_var('S_UPLOADING_FILES', true);
                        $sql = 'SELECT forum_id, forum_name
							FROM ' . FORUMS_TABLE;
                        $result = $db->sql_query($sql);
                        $forum_names = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $forum_names[$row['forum_id']] = $row['forum_name'];
                        }
                        $db->sql_freeresult($result);
                        $sql = 'SELECT forum_id, topic_id, post_id, poster_id
开发者ID:jvinhit,项目名称:php,代码行数:67,代码来源:acp_attachments.php

示例4: parse_attachments

    /**
     * Parse Attachments
     */
    function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false)
    {
        global $config, $auth, $user, $phpbb_root_path, $phpEx, $db, $request;
        $error = array();
        $num_attachments = sizeof($this->attachment_data);
        $this->filename_data['filecomment'] = $request->variable('filecomment', '', true);
        $upload = $request->file($form_name);
        $upload_file = !empty($upload) && $upload['name'] !== 'none' && trim($upload['name']);
        $add_file = isset($_POST['add_file']) ? true : false;
        $delete_file = isset($_POST['delete_file']) ? true : false;
        // First of all adjust comments if changed
        $actual_comment_list = $request->variable('comment_list', array(''), true);
        foreach ($actual_comment_list as $comment_key => $comment) {
            if (!isset($this->attachment_data[$comment_key])) {
                continue;
            }
            if ($this->attachment_data[$comment_key]['attach_comment'] != $actual_comment_list[$comment_key]) {
                $this->attachment_data[$comment_key]['attach_comment'] = $actual_comment_list[$comment_key];
            }
        }
        $cfg = array();
        $cfg['max_attachments'] = $is_message ? $config['max_attachments_pm'] : $config['max_attachments'];
        $forum_id = $is_message ? 0 : $forum_id;
        if ($submit && in_array($mode, array('post', 'reply', 'quote', 'edit')) && $upload_file) {
            if ($num_attachments < $cfg['max_attachments'] || $auth->acl_get('a_') || $auth->acl_get('m_', $forum_id)) {
                $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
                $error = $filedata['error'];
                if ($filedata['post_attach'] && !sizeof($error)) {
                    $sql_ary = array('physical_filename' => $filedata['physical_filename'], 'attach_comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'thumbnail' => $filedata['thumbnail'], 'is_orphan' => 1, 'in_message' => $is_message ? 1 : 0, 'poster_id' => $user->data['user_id']);
                    $db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                    $new_entry = array('attach_id' => $db->sql_nextid(), 'is_orphan' => 1, 'real_filename' => $filedata['real_filename'], 'attach_comment' => $this->filename_data['filecomment'], 'filesize' => $filedata['filesize']);
                    $this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
                    $this->message = preg_replace_callback('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#', function ($match) {
                        return '[attachment=' . ($match[1] + 1) . ']' . $match[2] . '[/attachment]';
                    }, $this->message);
                    $this->filename_data['filecomment'] = '';
                    // This Variable is set to false here, because Attachments are entered into the
                    // Database in two modes, one if the id_list is 0 and the second one if post_attach is true
                    // Since post_attach is automatically switched to true if an Attachment got added to the filesystem,
                    // but we are assigning an id of 0 here, we have to reset the post_attach variable to false.
                    //
                    // This is very relevant, because it could happen that the post got not submitted, but we do not
                    // know this circumstance here. We could be at the posting page or we could be redirected to the entered
                    // post. :)
                    $filedata['post_attach'] = false;
                }
            } else {
                $error[] = $user->lang('TOO_MANY_ATTACHMENTS', (int) $cfg['max_attachments']);
            }
        }
        if ($preview || $refresh || sizeof($error)) {
            if (isset($this->plupload) && $this->plupload->is_active()) {
                $json_response = new \phpbb\json_response();
            }
            // Perform actions on temporary attachments
            if ($delete_file) {
                include_once $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
                $index = array_keys($request->variable('delete_file', array(0 => 0)));
                $index = !empty($index) ? $index[0] : false;
                if ($index !== false && !empty($this->attachment_data[$index])) {
                    // delete selected attachment
                    if ($this->attachment_data[$index]['is_orphan']) {
                        $sql = 'SELECT attach_id, physical_filename, thumbnail
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id'] . '
								AND is_orphan = 1
								AND poster_id = ' . $user->data['user_id'];
                        $result = $db->sql_query($sql);
                        $row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        if ($row) {
                            phpbb_unlink($row['physical_filename'], 'file');
                            if ($row['thumbnail']) {
                                phpbb_unlink($row['physical_filename'], 'thumbnail');
                            }
                            $db->sql_query('DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id']);
                        }
                    } else {
                        delete_attachments('attach', array(intval($this->attachment_data[$index]['attach_id'])));
                    }
                    unset($this->attachment_data[$index]);
                    $this->message = preg_replace_callback('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#', function ($match) use($index) {
                        return $match[1] == $index ? '' : ($match[1] > $index ? '[attachment=' . ($match[1] - 1) . ']' . $match[2] . '[/attachment]' : $match[0]);
                    }, $this->message);
                    // Reindex Array
                    $this->attachment_data = array_values($this->attachment_data);
                    if (isset($this->plupload) && $this->plupload->is_active()) {
                        $json_response->send($this->attachment_data);
                    }
                }
            } else {
                if (($add_file || $preview) && $upload_file) {
                    if ($num_attachments < $cfg['max_attachments'] || $auth->acl_gets('m_', 'a_', $forum_id)) {
                        $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message, false, $this->mimetype_guesser, $this->plupload);
                        $error = array_merge($error, $filedata['error']);
                        if (!sizeof($error)) {
                            $sql_ary = array('physical_filename' => $filedata['physical_filename'], 'attach_comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'thumbnail' => $filedata['thumbnail'], 'is_orphan' => 1, 'in_message' => $is_message ? 1 : 0, 'poster_id' => $user->data['user_id']);
//.........这里部分代码省略.........
开发者ID:binano,项目名称:phpbb,代码行数:101,代码来源:message_parser.php

示例5: delete_attachments

function delete_attachments($mode, $ids, $resync = TRUE)
{
    global $_CLASS, $config;
    if (is_array($ids)) {
        $ids = array_unique($ids);
    }
    if (!sizeof($ids)) {
        return false;
    }
    $sql_id = $mode == 'user' ? 'poster_id' : ($mode == 'post' ? 'post_msg_id' : ($mode == 'topic' ? 'topic_id' : 'attach_id'));
    $post_ids = $topic_ids = $physical = array();
    // Collect post and topics ids for later use
    if ($mode == 'attach' || $mode == 'user' || $mode == 'topic' && $resync) {
        $sql = 'SELECT post_msg_id as post_id, topic_id, physical_filename, thumbnail, filesize
			FROM ' . FORUMS_ATTACHMENTS_TABLE . '
			WHERE ' . $sql_id . ' IN (' . implode(', ', $ids) . ')';
        $result = $_CLASS['core_db']->query($sql);
        while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
            $post_ids[] = $row['post_id'];
            $topic_ids[] = $row['topic_id'];
            $physical[] = array('filename' => $row['physical_filename'], 'thumbnail' => $row['thumbnail'], 'filesize' => $row['filesize']);
        }
        $_CLASS['core_db']->free_result($result);
    }
    if ($mode == 'post') {
        $sql = 'SELECT topic_id, physical_filename, thumbnail, filesize
			FROM ' . FORUMS_ATTACHMENTS_TABLE . '
			WHERE post_msg_id IN (' . implode(', ', $ids) . ')
				AND in_message = 0';
        $result = $_CLASS['core_db']->query($sql);
        while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
            $topic_ids[] = $row['topic_id'];
            $physical[] = array('filename' => $row['physical_filename'], 'thumbnail' => $row['thumbnail'], 'filesize' => $row['filesize']);
        }
        $_CLASS['core_db']->free_result($result);
    }
    // Delete attachments
    $_CLASS['core_db']->query('DELETE FROM ' . FORUMS_ATTACHMENTS_TABLE . ' WHERE ' . $sql_id . ' IN (' . implode(', ', $ids) . ')');
    $num_deleted = $_CLASS['core_db']->affected_rows();
    if (!$num_deleted) {
        return 0;
    }
    // Delete attachments from filesystem
    $space_removed = $files_removed = 0;
    foreach ($physical as $file_ary) {
        if (phpbb_unlink($file_ary['filename'], 'file')) {
            $space_removed += $file_ary['filesize'];
            $files_removed++;
        }
        if ($file_ary['thumbnail']) {
            phpbb_unlink($file_ary['filename'], 'thumbnail');
        }
    }
    set_config('upload_dir_size', $config['upload_dir_size'] - $space_removed, true);
    set_config('num_files', $config['num_files'] - $files_removed, true);
    if ($mode == 'topic' && !$resync) {
        return $num_deleted;
    }
    if ($mode == 'post') {
        $post_ids = $ids;
    }
    unset($ids);
    $post_ids = array_unique($post_ids);
    $topic_ids = array_unique($topic_ids);
    // Update post indicators
    if (sizeof($post_ids)) {
        if ($mode == 'post' || $mode == 'topic') {
            $_CLASS['core_db']->query('UPDATE ' . FORUMS_POSTS_TABLE . ' 
				SET post_attachment = 0
				WHERE post_id IN (' . implode(', ', $post_ids) . ')');
        }
        if ($mode == 'user' || $mode == 'attach') {
            $remaining = array();
            $sql = 'SELECT post_msg_id
					FROM ' . FORUMS_ATTACHMENTS_TABLE . ' 
					WHERE post_msg_id IN (' . implode(', ', $post_ids) . ')
						AND in_message = 0';
            $result = $_CLASS['core_db']->query($sql);
            while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
                $remaining[] = $row['post_msg_id'];
            }
            $_CLASS['core_db']->free_result($result);
            $unset_ids = array_diff($post_ids, $remaining);
            if (sizeof($unset_ids)) {
                $_CLASS['core_db']->query('UPDATE ' . FORUMS_POSTS_TABLE . ' 
					SET post_attachment = 0
					WHERE post_id IN (' . implode(', ', $unset_ids) . ')');
            }
            $remaining = array();
            $sql = 'SELECT post_msg_id
					FROM ' . FORUMS_ATTACHMENTS_TABLE . ' 
					WHERE post_msg_id IN (' . implode(', ', $post_ids) . ')
						AND in_message = 1';
            $result = $_CLASS['core_db']->query($sql);
            while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
                $remaining[] = $row['post_msg_id'];
            }
            $_CLASS['core_db']->free_result($result);
            $unset_ids = array_diff($post_ids, $remaining);
            if (sizeof($unset_ids)) {
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:viperals-svn,代码行数:101,代码来源:functions_admin.php

示例6: delete_forum_content

function delete_forum_content($forum_id)
{
    global $_CLASS, $site_file_root;
    require_once $site_file_root . 'includes/forums/functions_posting.php';
    $_CLASS['core_db']->transaction();
    switch ($_CLASS['core_db']->db_layer) {
        // Needs updating and testing
        /*		case 'mysql4':
        		case 'mysqli':
        			// Select then delete all attachments
        			$sql = 'SELECT a.topic_id
        				FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . " a
        				WHERE p.forum_id = $forum_id
        					AND a.in_message = 0
        					AND a.topic_id = p.topic_id";
        			$result = $_CLASS['core_db']->query($sql);	
        		
        			$topic_ids = array();
        			while ($row = $_CLASS['core_db']->fetch_row_assoc($result))
        			{
        				$topic_ids[] = $row['topic_id'];
        			}
        			$_CLASS['core_db']->free_result($result);
        			
        			delete_attachments('topic', $topic_ids, false);
        
        			// Delete everything else and thank MySQL for offering multi-table deletion
        			$tables_ary = array(
        				BOOKMARKS_TABLE 	=> 'bm.topic_id',
        				SEARCH_MATCH_TABLE	=> 'wm.post_id',
        				REPORTS_TABLE		=> 're.post_id',
        				TOPICS_WATCH_TABLE	=> 'tw.topic_id',
        				TOPICS_TRACK_TABLE	=> 'tt.topic_id',
        				POLL_OPTIONS_TABLE	=> 'po.topic_id',
        				POLL_VOTES_TABLE	=> 'pv.topic_id'
        			);
        
        			$sql = 'DELETE QUICK FROM ' . POSTS_TABLE;
        			$sql_using = "\nUSING " . POSTS_TABLE . ' p';
        			$sql_where = "\nWHERE p.forum_id = $forum_id\n";
        			$sql_optimise = 'OPTIMIZE TABLE . ' . POSTS_TABLE;
        
        			foreach ($tables_ary as $table => $field)
        			{
        				$sql .= ", $table";
        				$sql_using .= ", $table " . strtok($field, '.');
        				$sql_where .= "\nAND $field = p." . strtok('');
        				$sql_optimise .= ', ' . $table;
        			}
        
        			$_CLASS['core_db']->query($sql . $sql_using . $sql_where);
        
        			$tables_ary = array(FORUMS_ACCESS_TABLE, TOPICS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, ACL_GROUPS_TABLE, ACL_USERS_TABLE, MODERATOR_TABLE, LOG_TABLE);
        			foreach ($tables_ary as $table)
        			{
        				$_CLASS['core_db']->query("DELETE QUICK FROM $table WHERE forum_id = $forum_id");
        				$sql_optimise .= ', ' . $table;
        			}
        
        			// Now optimise a hell lot of tables
        			$_CLASS['core_db']->query($sql_optimise);
        		break;
        */
        default:
            // Select then delete all attachments
            $sql = 'SELECT a.attach_id, a.physical_filename, a.thumbnail
				FROM ' . FORUMS_POSTS_TABLE . ' p, ' . FORUMS_ATTACHMENTS_TABLE . " a\n\t\t\t\tWHERE p.forum_id = {$forum_id}\n\t\t\t\t\tAND a.in_message = 0\n\t\t\t\t\tAND a.post_msg_id = p.post_id";
            $result = $_CLASS['core_db']->query($sql);
            $attach_ids = array();
            while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
                $attach_ids[] = $row['attach_id'];
                phpbb_unlink($row['physical_filename'], 'file');
                if ($row['thumbnail']) {
                    phpbb_unlink($row['physical_filename'], 'thumbnail');
                }
            }
            $_CLASS['core_db']->free_result($result);
            if (count($attach_ids)) {
                $attach_id_list = implode(',', array_unique($attach_ids));
                $_CLASS['core_db']->query('DELETE FROM ' . FORUMS_ATTACHMENTS_TABLE . " WHERE attach_id IN ({$attach_id_list})");
                unset($attach_ids, $attach_id_list);
            }
            // Delete everything else and curse your DB for not offering multi-table deletion
            $tables_ary = array('post_id' => array(FORUMS_SEARCH_MATCH_TABLE, FORUMS_REPORTS_TABLE), 'topic_id' => array(FORUMS_BOOKMARKS_TABLE, FORUMS_WATCH_TABLE, FORUMS_TRACK_TABLE, FORUMS_POLL_OPTIONS_TABLE, FORUMS_POLL_VOTES_TABLE));
            foreach ($tables_ary as $field => $tables) {
                $start = 0;
                $id_array = array();
                $sql = "SELECT {$field}\n\t\t\t\t\tFROM " . FORUMS_POSTS_TABLE . '
					WHERE forum_id = ' . $forum_id;
                $result = $_CLASS['core_db']->query($sql);
                while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
                    $id_array[] = $row[$field];
                }
                $_CLASS['core_db']->free_result($result);
                if (empty($id_array)) {
                    continue;
                }
                foreach ($tables as $table) {
                    $_CLASS['core_db']->query("DELETE FROM {$table} WHERE {$field} IN (" . implode(',', $id_array) . ')');
                }
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:viperals-svn,代码行数:101,代码来源:admin_forums.php

示例7: parse_attachments

 function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false)
 {
     global $config, $_CLASS, $site_file_root, $forum_id;
     $error = array();
     $num_attachments = sizeof($this->attachment_data);
     $this->filename_data['filecomment'] = request_var('filecomment', '', true);
     $upload_file = isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name']) ? true : false;
     $add_file = isset($_POST['add_file']);
     $delete_file = isset($_POST['delete_file']);
     $edit_comment = isset($_POST['edit_comment']);
     $cfg = array();
     $cfg['max_attachments'] = $is_message ? $config['max_attachments_pm'] : $config['max_attachments'];
     $forum_id = $is_message ? 0 : $forum_id;
     if ($submit && in_array($mode, array('post', 'reply', 'quote', 'edit')) && $upload_file) {
         if ($num_attachments < $cfg['max_attachments'] || $_CLASS['auth']->acl_gets('m_', 'a_')) {
             $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
             $error = $filedata['error'];
             if ($filedata['post_attach'] && !sizeof($error)) {
                 $new_entry = array('physical_filename' => $filedata['physical_filename'], 'comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'attach_id' => 0, 'thumbnail' => $filedata['thumbnail']);
                 $this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
                 $this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
                 $this->filename_data['filecomment'] = '';
                 // This Variable is set to false here, because Attachments are entered into the
                 // Database in two modes, one if the id_list is 0 and the second one if post_attach is true
                 // Since post_attach is automatically switched to true if an Attachment got added to the filesystem,
                 // but we are assigning an id of 0 here, we have to reset the post_attach variable to false.
                 //
                 // This is very relevant, because it could happen that the post got not submitted, but we do not
                 // know this circumstance here. We could be at the posting page or we could be redirected to the entered
                 // post. :)
                 $filedata['post_attach'] = false;
             }
         } else {
             $error[] = sprintf($_CLASS['core_user']->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']);
         }
     }
     if ($preview || $refresh || sizeof($error)) {
         // Perform actions on temporary attachments
         if ($delete_file) {
             $index = (int) key($_POST['delete_file']);
             // delete selected attachment
             if (!$this->attachment_data[$index]['attach_id']) {
                 phpbb_unlink($this->attachment_data[$index]['physical_filename'], 'file');
                 if ($this->attachment_data[$index]['thumbnail']) {
                     phpbb_unlink($this->attachment_data[$index]['physical_filename'], 'thumbnail');
                 }
             } else {
                 delete_attachments('attach', array(intval($this->attachment_data[$index]['attach_id'])));
             }
             unset($this->attachment_data[$index]);
             $this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "(\\1 == \$index) ? '' : ((\\1 > \$index) ? '[attachment=' . (\\1 - 1) . ']\\2[/attachment]' : '\\0')", $this->message);
             // Reindex Array
             $this->attachment_data = array_values($this->attachment_data);
         } else {
             if ($edit_comment || $add_file || $preview) {
                 if ($edit_comment) {
                     $actual_comment_list = request_var('comment_list', array(''));
                     foreach ($actual_comment_list as $index => $entry) {
                         $this->attachment_data[$index]['comment'] = preg_replace('#&amp;(\\#[0-9]+;)#', '&\\1', $entry);
                     }
                 }
                 if (($add_file || $preview) && $upload_file) {
                     if ($num_attachments < $cfg['max_attachments'] || $_CLASS['auth']->acl_gets('m_', 'a_')) {
                         $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
                         $error = array_merge($error, $filedata['error']);
                         if (!sizeof($error)) {
                             $new_entry = array('physical_filename' => $filedata['physical_filename'], 'comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'attach_id' => 0, 'thumbnail' => $filedata['thumbnail']);
                             $this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
                             $this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
                             $this->filename_data['filecomment'] = '';
                         }
                     } else {
                         $error[] = sprintf($_CLASS['core_user']->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']);
                     }
                 }
             }
         }
     }
     foreach ($error as $error_msg) {
         $this->warn_msg[] = $error_msg;
     }
 }
开发者ID:BackupTheBerlios,项目名称:viperals-svn,代码行数:82,代码来源:message_parser.php

示例8: delete_attachments


//.........这里部分代码省略.........
     * @since 3.1.7-RC1
     */
    $vars = array('mode', 'ids', 'resync', 'sql_id', 'post_ids', 'topic_ids', 'message_ids', 'physical');
    extract($phpbb_dispatcher->trigger_event('core.delete_attachments_before', compact($vars)));
    // Delete attachments
    $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
		WHERE ' . $db->sql_in_set($sql_id, $ids);
    $sql .= $sql_where;
    $db->sql_query($sql);
    $num_deleted = $db->sql_affectedrows();
    /**
     * Perform additional actions after attachment(s) deletion from the database
     *
     * @event core.delete_attachments_from_database_after
     * @var	string	mode			Variable containing attachments deletion mode, can be: post|message|topic|attach|user
     * @var	mixed	ids				Array or comma separated list of ids corresponding to the mode
     * @var	bool	resync			Flag indicating if posts/messages/topics should be synchronized
     * @var	string	sql_id			The field name to collect/delete data for depending on the mode
     * @var	array	post_ids		Array with post ids for deleted attachment(s)
     * @var	array	topic_ids		Array with topic ids for deleted attachment(s)
     * @var	array	message_ids		Array with private message ids for deleted attachment(s)
     * @var	array	physical		Array with deleted attachment(s) physical file(s) data
     * @var	int		num_deleted		The number of deleted attachment(s) from the database
     * @since 3.1.7-RC1
     */
    $vars = array('mode', 'ids', 'resync', 'sql_id', 'post_ids', 'topic_ids', 'message_ids', 'physical', 'num_deleted');
    extract($phpbb_dispatcher->trigger_event('core.delete_attachments_from_database_after', compact($vars)));
    if (!$num_deleted) {
        return 0;
    }
    // Delete attachments from filesystem
    $space_removed = $files_removed = 0;
    foreach ($physical as $file_ary) {
        if (phpbb_unlink($file_ary['filename'], 'file', true) && !$file_ary['is_orphan']) {
            // Only non-orphaned files count to the file size
            $space_removed += $file_ary['filesize'];
            $files_removed++;
        }
        if ($file_ary['thumbnail']) {
            phpbb_unlink($file_ary['filename'], 'thumbnail', true);
        }
    }
    /**
     * Perform additional actions after attachment(s) deletion from the filesystem
     *
     * @event core.delete_attachments_from_filesystem_after
     * @var	string	mode			Variable containing attachments deletion mode, can be: post|message|topic|attach|user
     * @var	mixed	ids				Array or comma separated list of ids corresponding to the mode
     * @var	bool	resync			Flag indicating if posts/messages/topics should be synchronized
     * @var	string	sql_id			The field name to collect/delete data for depending on the mode
     * @var	array	post_ids		Array with post ids for deleted attachment(s)
     * @var	array	topic_ids		Array with topic ids for deleted attachment(s)
     * @var	array	message_ids		Array with private message ids for deleted attachment(s)
     * @var	array	physical		Array with deleted attachment(s) physical file(s) data
     * @var	int		num_deleted		The number of deleted attachment(s) from the database
     * @var	int		space_removed	The size of deleted files(s) from the filesystem
     * @var	int		files_removed	The number of deleted file(s) from the filesystem
     * @since 3.1.7-RC1
     */
    $vars = array('mode', 'ids', 'resync', 'sql_id', 'post_ids', 'topic_ids', 'message_ids', 'physical', 'num_deleted', 'space_removed', 'files_removed');
    extract($phpbb_dispatcher->trigger_event('core.delete_attachments_from_filesystem_after', compact($vars)));
    if ($space_removed || $files_removed) {
        set_config_count('upload_dir_size', $space_removed * -1, true);
        set_config_count('num_files', $files_removed * -1, true);
    }
    // If we do not resync, we do not need to adjust any message, post, topic or user entries
开发者ID:WarriorMachines,项目名称:warriormachines-phpbb,代码行数:67,代码来源:functions_admin.php

示例9: array_keys

<h1><?php echo $_CLASS['core_user']->lang[$l_title]; ?></h1>

<p><?php echo $_CLASS['core_user']->lang[$l_title . '_EXPLAIN']; ?></p>

<?php

if ($submit && $mode == 'orphan')
{
	$delete_files = (isset($_POST['delete'])) ? array_keys(request_var('delete', array('' => 0))) : array();
	$add_files = (isset($_POST['add'])) ? array_keys(request_var('add', array('' => 0))) : array();
	$post_ids = request_var('post_id', 0);

	foreach ($delete_files as $delete)
	{
		phpbb_unlink($delete);
		phpbb_unlink($delete, 'thumbnail');
	}

	if (sizeof($delete_files))
	{
		add_log('admin', sprintf($_CLASS['core_user']->lang['LOG_ATTACH_ORPHAN_DEL'], implode(', ', $delete_files)));
		$notify[] = sprintf($_CLASS['core_user']->lang['LOG_ATTACH_ORPHAN_DEL'], implode(', ', $delete_files));
	}

	$upload_list = array();
	foreach ($add_files as $file)
	{
		if (!in_array($file, $delete_files) && $post_ids[$file])
		{
			$upload_list[$post_ids[$file]] = $file;
		}
开发者ID:BackupTheBerlios,项目名称:viperals-svn,代码行数:31,代码来源:admin_attachments.php

示例10: delete_attachments

/**
* Delete Attachments
*
* @param string $mode can be: post|topic|attach|user
* @param mixed $ids can be: post_ids, topic_ids, attach_ids, user_ids
* @param bool $resync set this to false if you are deleting posts or topics
*/
function delete_attachments($mode, $ids, $resync = true)
{
	global $db, $config;

	if (is_array($ids) && sizeof($ids))
	{
		$ids = array_unique($ids);
		$ids = array_map('intval', $ids);
	}
	else
	{
		$ids = array((int) $ids);
	}

	if (!sizeof($ids))
	{
		return false;
	}

	$sql_id = ($mode == 'user') ? 'poster_id' : (($mode == 'post') ? 'post_msg_id' : (($mode == 'topic') ? 'topic_id' : 'attach_id'));

	$post_ids = $topic_ids = $physical = array();

	// Collect post and topics ids for later use
	if ($mode == 'attach' || $mode == 'user' || ($mode == 'topic' && $resync))
	{
		$sql = 'SELECT post_msg_id as post_id, topic_id, physical_filename, thumbnail, filesize
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE ' . $db->sql_in_set($sql_id, $ids);
		$result = $db->sql_query($sql);

		while ($row = $db->sql_fetchrow($result))
		{
			$post_ids[] = $row['post_id'];
			$topic_ids[] = $row['topic_id'];
			$physical[] = array('filename' => $row['physical_filename'], 'thumbnail' => $row['thumbnail'], 'filesize' => $row['filesize']);
		}
		$db->sql_freeresult($result);
	}

	if ($mode == 'post')
	{
		$sql = 'SELECT topic_id, physical_filename, thumbnail, filesize
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE ' . $db->sql_in_set('post_msg_id', $ids) . '
				AND in_message = 0';
		$result = $db->sql_query($sql);

		while ($row = $db->sql_fetchrow($result))
		{
			$topic_ids[] = $row['topic_id'];
			$physical[] = array('filename' => $row['physical_filename'], 'thumbnail' => $row['thumbnail'], 'filesize' => $row['filesize']);
		}
		$db->sql_freeresult($result);
	}

	// Delete attachments
	$sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
		WHERE ' . $db->sql_in_set($sql_id, $ids);
	$db->sql_query($sql);
	$num_deleted = $db->sql_affectedrows();

	if (!$num_deleted)
	{
		return 0;
	}

	// Delete attachments from filesystem
	$space_removed = $files_removed = 0;
	foreach ($physical as $file_ary)
	{
		if (phpbb_unlink($file_ary['filename'], 'file', true))
		{
			$space_removed += $file_ary['filesize'];
			$files_removed++;
		}

		if ($file_ary['thumbnail'])
		{
			phpbb_unlink($file_ary['filename'], 'thumbnail', true);
		}
	}
	set_config('upload_dir_size', $config['upload_dir_size'] - $space_removed, true);
	set_config('num_files', $config['num_files'] - $files_removed, true);

	if ($mode == 'topic' && !$resync)
	{
		return $num_deleted;
	}

	if ($mode == 'post')
	{
		$post_ids = $ids;
//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:101,代码来源:functions_admin.php


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