示例#1
0
function plugin_attachref_action()
{
    global $vars;
    global $_attachref_messages;
    $retval['msg'] = $_attachref_messages['msg_title'];
    $retval['body'] = '';
    $refer = isset($vars['refer']) ? $vars['refer'] : false;
    if (isset($_FILES[PLUGIN_ATTACH_FILE_FIELD_NAME]) && $refer !== false) {
        $wiki = Factory::Wiki($refer);
        if (!$wiki->isValied()) {
            Utility::dieMessage('#attachref : invalied page.');
        }
        $file = $_FILES[PLUGIN_ATTACH_FILE_FIELD_NAME];
        $attachname = $file['name'][0];
        $filename = preg_replace('/\\..+$/', '', $attachname, 1);
        // If exist file, add a name '_0', '_1', ...
        $count = '_0';
        while (file_exists(UPLOAD_DIR . encode($refer) . '_' . encode($attachname))) {
            $attachname = preg_replace('/^[^\\.]+/', $filename . $count++, $attachname);
        }
        $file['name'][0] = $attachname;
        $attach_filename = attachref_get_attach_filename($file);
        $pass = isset($vars['pass']) ? md5($vars['pass']) : NULL;
        $retval = attach_upload($refer, $pass);
        if ($retval['result'] == TRUE) {
            $retval = attachref_insert_ref($attach_filename);
        }
        Utility::redirect($wiki->uri());
    } else {
        $retval = attachref_showform();
    }
    return $retval;
}
示例#2
0
function plugin_attachref_action()
{
    global $script, $vars, $username;
    global $html_transitional;
    $qm = get_qm();
    //check auth
    $editable = edit_auth($vars['refer'], FALSE, FALSE);
    if (!$editable) {
        return array('msg' => $qm->m['plg_attachref']['title_ntc_admin'], 'body' => '<p>' . $qm->m['plg_attachref']['ntc_admin'] . '</p>');
    }
    //戻り値を初期化
    $retval['msg'] = $qm->m['plg_attachref']['title'];
    $retval['body'] = '';
    if (array_key_exists('attach_file', $_FILES) and array_key_exists('refer', $vars) and is_page($vars['refer'])) {
        $file = $_FILES['attach_file'];
        $attachname = $file['name'];
        $filename = preg_replace('/\\..+$/', '', $attachname, 1);
        //! swfuを持っていたら (管理者のみ)--------------------------------------------
        if ($editable && has_swfu()) {
            //アップロードするファイル名を決め(日本語ダメ、重複もダメ)
            $upload_name = $file['name'];
            if (preg_match('/^[-_.+a-zA-Z0-9]+$/', $upload_name)) {
                while (!$overwrite && file_exists(SWFU_IMAGE_DIR . $upload_name)) {
                    $upload_name = 's_' . $upload_name;
                }
                $upload_file = SWFU_IMAGE_DIR . $upload_name;
                $fname = $upload_name;
                $disp = $qm->m['plg_attachref']['img_desc'];
            } else {
                $matches = array();
                if (!preg_match('/[^.]+\\.(.*)$/', $upload_name, $matches)) {
                    echo 'invalid file name : ' . $upload_name;
                    exit(0);
                }
                $ext = $matches[1];
                $tmp_name = tempnam(SWFU_IMAGE_DIR, 'auto_');
                $upname = $tmp_name . '.' . $ext;
                $disp = $upload_name;
                rename($tmp_name, $upname);
                $upload_file = SWFU_IMAGE_DIR . basename($upname);
                $fname = basename($upname);
            }
            move_uploaded_file($file['tmp_name'], $upload_file);
            chmod($upload_file, 0666);
            //regist db
            $stat = stat($upload_file);
            $data = array('name' => $fname, 'description' => $disp, 'created' => $stat['mtime'], 'size' => $stat['size'], 'page_name' => $vars['refer']);
            require_once SWFU_TEXTSQL_PATH;
            $db = new CTextDB(SWFU_IMAGEDB_PATH);
            $db->insert($data);
            $retval = attachref_insert_ref(SWFU_IMAGE_DIR . $fname);
            return $retval;
        }
        //すでに存在した場合、 ファイル名に'_0','_1',...を付けて回避(姑息)
        $count = '_0';
        while (file_exists(ATTACHREF_UPLOAD_DIR . encode($vars['refer']) . '_' . encode($attachname))) {
            $attachname = preg_replace('/^[^\\.]+/', $filename . $count++, $file['name']);
        }
        $file['name'] = $attachname;
        require_once PLUGIN_DIR . "attach.inc.php";
        if (!exist_plugin('attach') or !function_exists('attach_upload')) {
            return array('msg' => $qm->m['plg_attachref']['err_notfound']);
        }
        $pass = array_key_exists('pass', $vars) ? $vars['pass'] : NULL;
        $retval = attach_upload($file, $vars['refer'], $pass);
        if ($retval['result'] == TRUE) {
            $retval = attachref_insert_ref($file['name']);
        }
    } else {
        $retval = attachref_showform();
        // XHTML 1.0 Transitional
        $html_transitional = TRUE;
    }
    return $retval;
}
function plugin_attachref_action()
{
    global $script, $vars;
    global $_attachref_messages;
    global $pkwk_dtd;
    $retval['msg'] = $_attachref_messages['msg_title'];
    $retval['body'] = '';
    if (isset($_FILES['attach_file']) && isset($vars['refer']) && is_page($vars['refer'])) {
        $file = $_FILES['attach_file'];
        $attachname = $file['name'];
        $filename = preg_replace('/\\..+$/', '', $attachname, 1);
        // If exist file, add a name '_0', '_1', ...
        $count = '_0';
        while (file_exists(UPLOAD_DIR . encode($vars['refer']) . '_' . encode($attachname))) {
            $attachname = preg_replace('/^[^\\.]+/', $filename . $count++, $file['name']);
        }
        $file['name'] = $attachname;
        require_once PLUGIN_DIR . 'attach.inc.php';
        if (!exist_plugin('attach') or !function_exists('attach_upload')) {
            return array('msg' => 'attach.inc.php not found or not correct version.');
        }
        $attach_filename = attachref_get_attach_filename($file);
        $pass = isset($vars['pass']) ? md5($vars['pass']) : NULL;
        $retval = attach_upload($file, $vars['refer'], $pass);
        if ($retval['result'] == TRUE) {
            $retval = attachref_insert_ref($attach_filename);
        }
    } else {
        $retval = attachref_showform();
        // XHTML 1.0 Transitional
        if (!isset($pkwk_dtd) || $pkwk_dtd == PKWK_DTD_XHTML_1_1) {
            $pkwk_dtd = PKWK_DTD_XHTML_1_0_TRANSITIONAL;
        }
    }
    return $retval;
}