Esempio n. 1
0
function checkNewsItem($item)
{
    echo "id: " . $item->id . "  " . $item->headline . "";
    $item_id = $item->id;
    $url = $item->url;
    $result = mysql_query("SELECT newsitem_id, url FROM newswire_tb WHERE newsitem_id=" . $item_id . " AND url='" . $url . "'");
    $numResults = mysql_num_rows($result);
    echo "  - num results: " . $numResults . " byline: " . $item->byline;
    if ($numResults < 1) {
        insertNewsItem($item);
    }
    echo '<br><br>';
}
Esempio n. 2
0
function processAddEditNews()
{
    $newsID = $_POST['NewsID'];
    $mode = $_POST['Mode'];
    $headline = $_POST['Headline'];
    $content = $_POST['Content'];
    $errors = '';
    if (empty($headline) || strlen($headline) > 100) {
        $errors .= '<br />* Provide a headline that is less than 100 characters';
    }
    if (empty($content) || strlen($content) > 3000) {
        $errors .= '<br />* Provide content that is less than 3,000 characters';
    }
    if ($mode == 'Add') {
        $slug = slugify($headline);
        if (SlugExists($slug)) {
            $errors .= '<br />* Headline already exists.  Provide a unique headline';
        }
    }
    $userID = $_SESSION['UserID'];
    //image uploading
    $image_info = getimagesize($_FILES['userfile']['tmp_name']);
    $image_width = $image_info[0];
    $image_height = $image_info[1];
    $image_type = $image_info[2];
    $pathinfo = pathinfo($_FILES['userfile']['name']);
    $uploadfile = "../img/news/" . date('YmdHis') . '.' . $pathinfo['extension'];
    if (file_exists($uploadfile)) {
        $msg = 'The file was replaced successfully.';
    } else {
        $msg = 'The file was successfully uploaded.';
    }
    if ($image_type != IMAGETYPE_JPEG && $image_type != IMAGETYPE_GIF && $image_type != IMAGETYPE_PNG) {
        $errors .= '<br />* Only jpeg, gif, or png file types are allowed';
    } else {
        if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
            $errors .= '<br />* Error uploading file';
        } else {
            if ($_FILES['userfile']['error'] == UPLOAD_ERR_NO_FILE) {
                $errors .= '<br />* No file found';
            }
        }
    }
    /*
            else
            {
                $errors .= '<br />* File Upload Error';
            }*/
    if ($errors != '') {
        include '../view/editNews.php';
    } else {
        if ($mode == 'Add') {
            insertNewsItem($headline, $content, $slug, $userID, $uploadfile);
            header("Location:../news/{$slug}");
        } else {
            //slug should never change or else it would break links
            updateNewsItem($newsID, $headline, $content, $userID);
            header("Location:../news/{$slug}");
        }
    }
}