Пример #1
0
foreach (array('image', 'file') as $field) {
    // make sure it's set in post
    if (isset($_POST[$field])) {
        // if it exists and is in a public directory
        if (file_exists(TYPEF_DIR . $_POST[$field]) && is_int(strpos(realpath(TYPEF_DIR . $_POST[$field]), realpath(TYPEF_DIR . '/files/public/')))) {
            // copy the file to files/public/news
            ${$field} = FileManager::CopyFile(TYPEF_DIR . $_POST[$field], TYPEF_DIR . '/files/public/news/' . basename($_POST[$field]));
            if (${$field}) {
                ${$field} = basename(${$field});
            } else {
                ${$field} = '';
            }
        } elseif (file_exists(TYPEF_DIR . '/files/public/news/' . basename($_POST[$type]))) {
            ${$field} = $_POST[$field];
        } else {
            ${$field} = '';
        }
        $_POST[$field] = ${$field};
    }
}
// process tags
if (isset($_POST['tags']) && is_string($_POST['tags']) && strlen($_POST['tags']) > 0) {
    $_POST['tags'] = preg_split('/[\\s]?,[\\s]?/', $_POST['tags']);
    sort($_POST['tags']);
}
// add article to template
$pm->setVariable('news', $article->getAsArray());
// add page title and header to template
$title = News::GetTitle();
$pm->setVariable('page_title', $title);
$pm->setVariable('page_header', $title);