Пример #1
0
function blog2DB($task)
{
    global $db_conn;
    foreach ($task as $parameters) {
        // Getting coauthor's ID
        if ($parameters["coauthor_name"]) {
            $sth = $db_conn->prepare("SELECT id FROM gmj_blogs WHERE lower(name)='" . $parameters["coauthor_name"] . "' AND site='" . $parameters["site"] . "'");
            $sth->execute();
            $coauthorId = $sth->fetchColumn();
            if ($coauthorId == "") {
                $coauthorId = getUserId($parameters["coauthor_name"], $parameters["site"]);
                if ($coauthorId == "na") {
                    // Site is unavailable, temporarily stopping processing
                    updateTaskStatus($parameters["id"], 0);
                    return exit;
                }
                // Coauthor not found
                if ($coauthorId == 0) {
                    $db_conn->exec("UPDATE gmj_tasks SET coauthor_name='' WHERE id='" . $parameters["id"] . "'");
                }
            }
        } else {
            $coauthorId = 0;
        }
        updateTaskStatus($parameters["id"], 1);
        // Processing blog's pages one by one
        for ($i = $parameters["pages_parsed"];; $i++) {
            $blogPosts = getPostsTable($parameters["author_id"], $parameters["site"], $i);
            if ($blogPosts == "noaccess") {
                // Blog's owner unexpectedly blocked access to his/her blog, terminating
                // Make notification!
                // ...
                $db_conn->exec("DELETE gmj_tasks,gmj_emails FROM gmj_tasks INNER JOIN gmj_emails WHERE gmj_tasks.id='" . $parameters["id"] . "' AND gmj_emails.id='" . $parameters["id"] . "'");
                return exit;
                break;
            }
            if ($blogPosts == "na") {
                // Site is unavailable, temporarily stopping processing
                updateTaskStatus($parameters["id"], 0);
                return exit;
                break;
            }
            if ($blogPosts) {
                // Inserting posts in the DB
                insertBlogPosts($blogPosts, $parameters["author_id"], $parameters["site"], $coauthorId);
                $db_conn->exec("UPDATE gmj_tasks SET pages_parsed=pages_parsed+1 WHERE id='" . $parameters["id"] . "'");
            } else {
                updateTaskStatus($parameters["id"], 2);
                break;
            }
        }
    }
}
Пример #2
0
    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']);
            if ($blogPosts == "noaccess" || $blogPosts == "na") {
                // Blog's owner blocked access to his/her blog or the site is unavailable
                $giveBook = true;
            } else {
                // Scanning the first page for new posts
                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');
                        // Checking if this post belongs to the blog's author/co-author