Beispiel #1
0
function insertBlogPosts($blogPosts, $blogId, $site, $coauthor = 0)
{
    global $db_conn;
    for ($i = 0; $i < 10; $i++) {
        $postTable = $blogPosts->find('table[class=BlogT]', $i);
        if ($postTable) {
            $postAuthorData = $postTable->find('td[align=left] a', 0);
            // Post author name
            $postAuthorName = $postAuthorData->innertext;
            // Post author ID
            $postAuthorId = $postAuthorData->href;
            $postAuthorId = getID($postAuthorId, 'bid');
            // Insert blog id & blog name with correct case
            $sth = $db_conn->prepare("SELECT name FROM gmj_blogs WHERE id='" . $postAuthorId . "' AND site='" . $site . "'");
            $sth->execute();
            $postAuthorNameDB = $sth->fetchColumn();
            if (!$postAuthorNameDB || $postAuthorName != $postAuthorNameDB) {
                if ($postAuthorNameDB) {
                    // Updating DB record with correct case
                    $db_conn->exec("UPDATE gmj_blogs SET name='" . $postAuthorName . "' WHERE id='" . $postAuthorId . "' AND site='" . $site . "'");
                } else {
                    // Inserting a new DB record
                    insert2DB('blogs', array($site, $postAuthorId, $postAuthorName));
                }
            }
            if ($postAuthorId == $blogId || $postAuthorId == $coauthor) {
                // Post title
                $postTitle = $postTable->find('th[align=left]', 0)->innertext;
                $postTitle = trim($postTitle);
                if (preg_match('/[а-яА-ЯA-Za-z0-9]/', $postTitle) == 0 && $postTitle != "") {
                    $postTitle = "";
                }
                // Post time
                $postTime = $postTable->find('th[align=right]', 0)->innertext;
                $postTime = gmjTime($postTime);
                // Post ID
                $postId = $postTable->find('td[align=right] a', 0)->href;
                $postId = getID($postId, 'rid');
                $post = $postTable->find('td[colspan=2]', 0);
                $attachment = $post->find('div[class=att]', 0);
                $post = $post->innertext;
                $ext = 0;
                if ($attachment) {
                    $post = str_replace($attachment, "", $post);
                    // Image ID
                    $image = $attachment->find('img', 0);
                    if ($image) {
                        $path = getURL($site) . "/Blog/Attachment.ashx?aid=" . $postId;
                        $ext = exif_imagetype($path);
                        if ($ext != 2 && $ext != 3) {
                            $ext = 0;
                        }
                    }
                }
                // Post itself
                $post = preg_replace('#(<br />)+#i', '<br />', $post);
                $pattern = "~(<a href='[^']*' rel='nofollow' target='_blank'>)([^<]*)(</a>)~";
                $post = preg_replace($pattern, '$2', $post);
                // Insert post into the DB
                insert2DB('posts', array($site, $postId, $postTitle, $post, $postTime, $blogId, $ext));
            }
        } else {
            break;
        }
    }
}
Beispiel #2
0
<?php

// Forbid to open this file directly from browser
if (preg_match("/addEmail.php/i", $_SERVER['PHP_SELF'])) {
    header("Location: ../index.php");
}
// Bind email and task
$sth = $db_conn->prepare("SELECT COUNT(*) FROM gmj_emails WHERE id='" . $taskId . "'");
$sth->execute();
$emailCount = $sth->fetchColumn();
// Not more than 20 emails for each task
// You may change this value in config.php
if ($emailCount >= $max_emails) {
    exit($error[0] . $textErrors[11] . $error[2]);
}
$sth = $db_conn->prepare("SELECT COUNT(*) FROM gmj_emails WHERE id='" . $taskId . "' AND email='" . $_POST['email'] . "'");
$sth->execute();
$emailCount = $sth->fetchColumn();
if ($emailCount == 0) {
    insert2DB('emails', array($taskId, $_POST['email']));
} else {
    // The task is already on for this email
    exit($error[0] . $textCommon[1] . " " . $_POST['blogName'] . $textErrors[12] . $textStatus[4] . $error[3]);
}
Beispiel #3
0
}
// Trying to get blog ID via the DB
$sth = $db_conn->prepare("SELECT id FROM gmj_blogs WHERE lower(name)='" . $blogName . "' AND site='" . $_POST['site'] . "'");
$sth->execute();
$blogId = $sth->fetchColumn();
if ($blogId == "") {
    // Trying to get blog ID via the Parser
    $blogId = getUserId($blogName, $_POST['site']);
    if ($blogId == "na") {
        exit($error[0] . naErrorMessage($_POST['site']) . $error[1]);
    }
    if ($blogId == 0) {
        exit($error[0] . $textCommon[1] . " <b>" . $_POST['blogName'] . "</b> " . $textErrors[6] . $error[1]);
    }
    // Adding blog ID to the DB
    insert2DB('blogs', array($_POST['site'], $blogId, $blogName));
    $taskId = "";
    $taskStatus = 0;
} else {
    // Checking if a task already exists
    $sth = $db_conn->prepare("SELECT id,status FROM gmj_tasks WHERE \n\t\tsite='" . $_POST['site'] . "' AND \n\t\tauthor_id='" . $blogId . "' AND \n\t\tcoauthor_name='" . $coAuthorName . "' AND\n\t\treal_name='" . $realName . "' AND\n\t\treal_surname='" . $realSurname . "' AND\n\t\timages='" . $images . "'\n\t");
    $sth->execute();
    $taskInfo = $sth->fetch();
    if ($taskInfo != "") {
        if ($taskInfo[1] == 8) {
            // The task exists and the book is ready
            // Checking if this book is up-to-date
            $sth = $db_conn->prepare("SELECT id FROM gmj_posts WHERE author='" . $blogId . "' AND site='" . $_POST['site'] . "' AND post_in_book='1' ORDER BY id DESC LIMIT 1");
            $sth->execute();
            $lastPostInBook = $sth->fetchColumn();
            $blogPosts = getPostsTable($blogId, $_POST['site']);
Beispiel #4
0
<?php

// Forbid to open this file directly from browser
if (preg_match("/addTask.php/i", $_SERVER['PHP_SELF'])) {
    header("Location: ../index.php");
}
// Checking access to blog
$blogPosts = getPostsTable($blogId, $_POST['site']);
if ($blogPosts == "noaccess") {
    exit($error[0] . $textCommon[1] . " <b>" . $_POST['blogName'] . "</b> " . $textErrors[7] . $error[1]);
}
if ($blogPosts == "na") {
    exit($error[0] . naErrorMessage($_POST['site']) . $error[1]);
}
// Inserting a new task into the DB, $taskId will be ID of the newly added task
$taskId = insert2DB('tasks', array($_POST['site'], $blogId, $coAuthorName, $realName, $realSurname, $images));
if ($coAuthorName != "") {
    // Trying to get coauthor's ID from the DB
    $sth = $db_conn->prepare("SELECT id FROM gmj_blogs WHERE lower(name)='" . $coAuthorName . "' AND site='" . $_POST['site'] . "'");
    $sth->execute();
    $coauthorId = $sth->fetchColumn();
} else {
    $coauthorId = 0;
}
if ($coAuthorName == "" || $coAuthorName != "" && $coauthorId != "") {
    // Inserting topics ($blogPosts) from the first (0) page
    insertBlogPosts($blogPosts, $blogId, $_POST['site'], $coauthorId);
    $db_conn->exec("UPDATE gmj_tasks SET pages_parsed=pages_parsed+1 WHERE id='" . $taskId . "'");
}
// Notifying me about a new task
$message = "Some guy with IP " . $_SERVER['REMOTE_ADDR'] . " has just added a new task for blog " . $_POST['blogName'] . " (email " . $_POST['email'] . ").";