Пример #1
0
$category = new News_Category($categoryid);
if (!$category->exists()) {
    $category = null;
}
// get, validate, and set incoming the values
$article->set('categoryid', $categoryid);
$article->set('title', $_POST['title']);
$article->set('article', $_POST['article']);
$article->set('status', News_Article::ValidateField('status', @$_POST['status']));
$article->set('pubdate', News_Article::ValidateField('pubdate', @$_POST['pubdate']));
$article->set('expdate', @$_POST['expdate']);
// handle (auto)summary
$autosummary = News_Article::ValidateField('autosummary', @$_POST['autosummary']);
$text = @$_POST[$autosummary ? 'article' : 'summary'];
$article->set('autosummary', $autosummary);
$article->set('summary', News_Article::ValidateField('summary', array($autosummary, $text)));
// process image and file
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];