Exemple #1
0
function file_write($dir, $page, $str, $notimestamp = FALSE)
{
    global $notify, $notify_diff_only, $notify_subject;
    global $whatsdeleted, $maxshow_deleted;
    global $qblog_page_re;
    $qm = get_qm();
    if (PKWK_READONLY) {
        return;
    }
    // Do nothing
    if ($dir != DATA_DIR && $dir != DIFF_DIR) {
        die($qm->m['file']['err_invalid_dir']);
    }
    $page = strip_bracket($page);
    $file = $dir . encode($page) . '.txt';
    $file_exists = file_exists($file);
    // ----
    // Record last modified date for QHM cache func.
    $lm_file = CACHE_DIR . QHM_LASTMOD;
    file_put_contents($lm_file, date('Y-m-d H:i:s'));
    // ----
    // Delete?
    if ($dir == DATA_DIR && $str === '') {
        // Page deletion
        if (!$file_exists) {
            return;
        }
        // Ignore null posting for DATA_DIR
        // Update RecentDeleted (Add the $page)
        add_recent($page, $whatsdeleted, '', $maxshow_deleted);
        //QBlog 記事 であれば、削除処理を呼び出す
        if (preg_match($qblog_page_re, $page)) {
            qblog_remove_post($page);
        }
        // Remove the page
        unlink($file);
        // Update RecentDeleted, and remove the page from RecentChanges
        lastmodified_add($whatsdeleted, $page);
        // Clear is_page() cache
        is_page($page, TRUE);
        return;
    } else {
        if ($dir == DIFF_DIR && $str === " \n") {
            return;
            // Ignore null posting for DIFF_DIR
        }
    }
    // ----
    // File replacement (Edit)
    if (!is_pagename($page)) {
        die_message(str_replace('$1', htmlspecialchars($page), str_replace('$2', 'WikiName', $qm->m['fmt_err_invalidiwn'])));
    }
    $str = rtrim(preg_replace('/' . "\r" . '/', '', $str)) . "\n";
    $timestamp = $file_exists && $notimestamp ? filemtime($file) : FALSE;
    $fp = fopen($file, 'a') or die($qm->replace('file.err_not_writable', h(basename($dir)), encode($page)));
    set_file_buffer($fp, 0);
    flock($fp, LOCK_EX);
    ftruncate($fp, 0);
    rewind($fp);
    fputs($fp, $str);
    flock($fp, LOCK_UN);
    fclose($fp);
    if ($timestamp) {
        pkwk_touch_file($file, $timestamp);
    }
    // Optional actions
    if ($dir == DATA_DIR) {
        // Update RecentChanges (Add or renew the $page)
        if ($timestamp === FALSE) {
            lastmodified_add($page);
        }
        add_tinycode($page);
        // Command execution per update
        if (defined('PKWK_UPDATE_EXEC') && PKWK_UPDATE_EXEC) {
            system(PKWK_UPDATE_EXEC . ' > /dev/null &');
        }
    } else {
        if ($dir == DIFF_DIR && $notify) {
            if ($notify_diff_only) {
                $str = preg_replace('/^[^-+].*\\n/m', '', $str);
            }
            $footer['ACTION'] = 'Page update';
            $footer['PAGE'] =& $page;
            $footer['URI'] = get_script_uri() . '?' . rawurlencode($page);
            $footer['USER_AGENT'] = TRUE;
            $footer['REMOTE_ADDR'] = TRUE;
            if (isset($_SESSION['usr'])) {
                $str .= "\n\n " . $qm->replace('file.lbl_editor', $_SESSION['usr']) . "\n";
            }
            pkwk_mail_notify($notify_subject, $str, $footer) or die($qm->m['file']['err_mail_failed']);
        }
    }
    is_page($page, TRUE);
    // Clear is_page() cache
}
Exemple #2
0
function file_write($dir, $page, $str, $notimestamp = FALSE)
{
    global $update_exec;
    global $notify, $notify_diff_only, $notify_subject;
    global $notify_exclude;
    global $whatsdeleted, $maxshow_deleted;
    global $_string;
    // if (PKWK_READONLY) return; // Do nothing
    if (auth::check_role('readonly')) {
        return;
    }
    // Do nothing
    if ($dir != DATA_DIR && $dir != DIFF_DIR) {
        die('file_write(): Invalid directory');
    }
    $page = strip_bracket($page);
    $file = $dir . encode($page) . '.txt';
    $file_exists = file_exists($file);
    // ----
    // Delete?
    if ($dir == DATA_DIR && $str === '') {
        // Page deletion
        if (!$file_exists) {
            return;
        }
        // Ignore null posting for DATA_DIR
        // Update RecentDeleted (Add the $page)
        add_recent($page, $whatsdeleted, '', $maxshow_deleted);
        // Remove the page
        unlink($file);
        // Update RecentDeleted, and remove the page from RecentChanges
        lastmodified_add($whatsdeleted, $page);
        // Clear is_page() cache
        is_page($page, TRUE);
        return;
    } else {
        if ($dir == DIFF_DIR && $str === " \n") {
            return;
            // Ignore null posting for DIFF_DIR
        }
    }
    // ----
    // File replacement (Edit)
    if (!is_pagename($page)) {
        die_message(str_replace('$1', htmlspecialchars($page), str_replace('$2', 'WikiName', $_msg_invalidiwn)));
    }
    $str = rtrim(preg_replace('/' . "\r" . '/', '', $str)) . "\n";
    $timestamp = $file_exists && $notimestamp ? filemtime($file) : FALSE;
    $fp = fopen($file, 'a') or die('fopen() failed: ' . htmlspecialchars(basename($dir) . '/' . encode($page) . '.txt') . '<br />' . "\n" . 'Maybe permission is not writable or filename is too long');
    set_file_buffer($fp, 0);
    @flock($fp, LOCK_EX);
    $last = ignore_user_abort(1);
    ftruncate($fp, 0);
    rewind($fp);
    fputs($fp, $str);
    ignore_user_abort($last);
    @flock($fp, LOCK_UN);
    fclose($fp);
    if ($timestamp) {
        pkwk_touch_file($file, $timestamp);
    }
    // Optional actions
    if ($dir == DATA_DIR) {
        if ($timestamp === FALSE) {
            lastmodified_add($page);
        }
        // Command execution per update
        if (defined('PKWK_UPDATE_EXEC') && PKWK_UPDATE_EXEC) {
            system(PKWK_UPDATE_EXEC . ' > /dev/null &');
        } elseif ($update_exec) {
            system($update_exec . ' > /dev/null &');
        }
    } else {
        if ($dir == DIFF_DIR && $notify) {
            $notify_exec = TRUE;
            foreach ($notify_exclude as $exclude) {
                $exclude = preg_quote($exclude);
                if (substr($exclude, -1) == '.') {
                    $exclude = $exclude . '*';
                }
                if (preg_match('/^' . $exclude . '/', $_SERVER["REMOTE_ADDR"])) {
                    $notify_exec = FALSE;
                    break;
                }
            }
            if ($notify_exec !== FALSE) {
                if ($notify_diff_only) {
                    $str = preg_replace('/^[^-+].*\\n/m', '', $str);
                }
                $summary['ACTION'] = 'Page update';
                $summary['PAGE'] =& $page;
                $summary['URI'] = get_page_absuri($page);
                $summary['USER_AGENT'] = TRUE;
                $summary['REMOTE_ADDR'] = TRUE;
                pkwk_mail_notify($notify_subject, $str, $summary);
                //			pkwk_mail_notify($notify_subject, $str, $summary) or
                //				die('pkwk_mail_notify(): Failed');
            }
        }
    }
    is_page($page, TRUE);
    // Clear is_page() cache
}
Exemple #3
0
function file_write($dir, $page, $str, $notimestamp = false)
{
    global $_msg_invalidiwn, $notify, $notify_diff_only, $notify_subject;
    global $whatsdeleted, $maxshow_deleted;
    if (PKWK_READONLY) {
        return;
    }
    // Do nothing
    if ($dir != DATA_DIR && $dir != DIFF_DIR) {
        die('file_write(): Invalid directory');
    }
    $page = strip_bracket($page);
    $file = $dir . encode($page) . '.txt';
    $file_exists = file_exists($file);
    // ----
    // Delete?
    if ($dir == DATA_DIR && $str === '') {
        // Page deletion
        if (!$file_exists) {
            return;
        }
        // Ignore null posting for DATA_DIR
        // Update RecentDeleted (Add the $page)
        add_recent($page, $whatsdeleted, '', $maxshow_deleted);
        // Remove the page
        unlink($file);
        // Update RecentDeleted, and remove the page from RecentChanges
        lastmodified_add($whatsdeleted, $page);
        // Clear is_page() cache
        is_page($page, true);
        return;
    } elseif ($dir == DIFF_DIR && $str === " \n") {
        return;
        // Ignore null posting for DIFF_DIR
    }
    // ----
    // File replacement (Edit)
    if (!is_pagename($page)) {
        die_message(str_replace('$1', htmlsc($page), str_replace('$2', 'WikiName', $_msg_invalidiwn)));
    }
    $str = rtrim(preg_replace('/' . "\r" . '/', '', $str)) . "\n";
    $timestamp = $file_exists && $notimestamp ? filemtime($file) : false;
    $fp = fopen($file, 'a') or die('fopen() failed: ' . htmlsc(basename($dir) . '/' . encode($page) . '.txt') . '<br />' . "\n" . 'Maybe permission is not writable or filename is too long');
    set_file_buffer($fp, 0);
    flock($fp, LOCK_EX);
    ftruncate($fp, 0);
    rewind($fp);
    fputs($fp, $str);
    flock($fp, LOCK_UN);
    fclose($fp);
    if ($timestamp) {
        pkwk_touch_file($file, $timestamp);
    }
    // Optional actions
    if ($dir == DATA_DIR) {
        // Update RecentChanges (Add or renew the $page)
        if ($timestamp === false) {
            lastmodified_add($page);
        }
        // Command execution per update
        if (defined('PKWK_UPDATE_EXEC') && PKWK_UPDATE_EXEC) {
            system(PKWK_UPDATE_EXEC . ' > /dev/null &');
        }
    } elseif ($dir == DIFF_DIR && $notify) {
        if ($notify_diff_only) {
            $str = preg_replace('/^[^-+].*\\n/m', '', $str);
        }
        $footer['ACTION'] = 'Page update';
        $footer['PAGE'] =& $page;
        $footer['URI'] = get_script_uri() . '?' . rawurlencode($page);
        $footer['USER_AGENT'] = true;
        $footer['REMOTE_ADDR'] = true;
        pkwk_mail_notify($notify_subject, $str, $footer) or die('pkwk_mail_notify(): Failed');
    }
    is_page($page, true);
    // Clear is_page() cache
}