function createZIP($taskId, $blogName) { global $db_conn, $rootdir; $fpath = $rootdir . "/books/" . $taskId . "/" . $blogName . ".fb2"; if (file_exists($fpath)) { updateTaskStatus($taskId, 7); $zip = new ZipArchive(); $zip->open($fpath . ".zip", ZipArchive::CREATE); $zip->addFile($fpath, $blogName . ".fb2"); $zip->close(); unlink($fpath); updateTaskStatus($taskId, 8); } else { // File with FB2 book is absent for some reason // Notification! // ... $db_conn->exec("UPDATE gmj_tasks SET status=2, time=time+INTERVAL 1 YEAR WHERE id='" . $taskId . "'"); return exit; } }
/** * List all the scheduled task in place on the forum. * * @uses ManageScheduledTasks template, view_scheduled_tasks sub-template */ public function action_tasks() { global $context, $txt, $scripturl; // We'll need to recalculate dates and stuff like that. require_once SUBSDIR . '/ScheduledTasks.subs.php'; // Mama, setup the template first - cause it's like the most important bit, like pickle in a sandwich. // ... ironically I don't like pickle. </grudge> $context['sub_template'] = 'view_scheduled_tasks'; $context['page_title'] = $txt['maintain_tasks']; // Saving changes? if (isset($_REQUEST['save']) && isset($_POST['enable_task'])) { checkSession(); // Enable and disable as required. $enablers = array(0); foreach ($_POST['enable_task'] as $id => $enabled) { if ($enabled) { $enablers[] = (int) $id; } } // Do the update! updateTaskStatus($enablers); // Pop along... calculateNextTrigger(); } // Want to run any of the tasks? if (isset($_REQUEST['run']) && isset($_POST['run_task'])) { // Lets figure out which ones they want to run. $tasks = array(); foreach ($_POST['run_task'] as $task => $dummy) { $tasks[] = (int) $task; } // Load up the tasks. $nextTasks = loadTasks($tasks); // Lets get it on! require_once SUBSDIR . '/ScheduledTask.class.php'; call_integration_include_hook('integrate_autotask_include'); ignore_user_abort(true); foreach ($nextTasks as $task_id => $taskname) { run_this_task($task_id, $taskname); } // Things go as expected? If not save the error in session if (!empty($context['scheduled_errors'])) { $_SESSION['st_error'] = $context['scheduled_errors']; } redirectexit('action=admin;area=scheduledtasks;done'); } // Build the list so we can see the tasks $listOptions = array('id' => 'scheduled_tasks', 'title' => $txt['maintain_tasks'], 'base_href' => $scripturl . '?action=admin;area=scheduledtasks', 'get_items' => array('function' => array($this, 'list_getScheduledTasks')), 'columns' => array('name' => array('header' => array('value' => $txt['scheduled_tasks_name'], 'style' => 'width: 40%;'), 'data' => array('sprintf' => array('format' => ' <a class="linkbutton" href="' . $scripturl . '?action=admin;area=scheduledtasks;sa=taskedit;tid=%1$d" title="' . $txt['scheduled_task_edit'] . ' %2$s"><i class="fa fa-pencil-square-o"></i> %2$s</a><br /><span class="smalltext">%3$s</span>', 'params' => array('id' => false, 'name' => false, 'desc' => false)))), 'next_due' => array('header' => array('value' => $txt['scheduled_tasks_next_time']), 'data' => array('db' => 'next_time', 'class' => 'smalltext')), 'regularity' => array('header' => array('value' => $txt['scheduled_tasks_regularity']), 'data' => array('db' => 'regularity', 'class' => 'smalltext')), 'enabled' => array('header' => array('value' => $txt['scheduled_tasks_enabled'], 'style' => 'width: 6%;text-align: center;'), 'data' => array('sprintf' => array('format' => ' <input type="hidden" name="enable_task[%1$d]" id="task_%1$d" value="0" /><input type="checkbox" name="enable_task[%1$d]" id="task_check_%1$d" %2$s class="input_check" />', 'params' => array('id' => false, 'checked_state' => false)), 'class' => 'centertext')), 'run_now' => array('header' => array('value' => $txt['scheduled_tasks_run_now'], 'style' => 'width: 12%;text-align: center;'), 'data' => array('sprintf' => array('format' => ' <input type="checkbox" name="run_task[%1$d]" id="run_task_%1$d" class="input_check" />', 'params' => array('id' => false)), 'class' => 'centertext'))), 'form' => array('href' => $scripturl . '?action=admin;area=scheduledtasks'), 'additional_rows' => array(array('class' => 'submitbutton', 'position' => 'below_table_data', 'value' => ' <input type="submit" name="run" value="' . $txt['scheduled_tasks_run_now'] . '" class="right_submit" /> <input type="submit" name="save" value="' . $txt['scheduled_tasks_save_changes'] . '" class="right_submit" />'), array('position' => 'after_title', 'value' => $txt['scheduled_tasks_time_offset'], 'class' => 'windowbg2'))); require_once SUBSDIR . '/GenericList.class.php'; createList($listOptions); $context['sub_template'] = 'view_scheduled_tasks'; $context['tasks_were_run'] = isset($_GET['done']); // If we had any errors, place them in context as well if (isset($_SESSION['st_error'])) { $context['scheduled_errors'] = $_SESSION['st_error']; unset($_SESSION['st_error']); } }
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; } } } }
function embedImages($authorId, $authorName, $site, $taskId) { global $db_conn, $rootdir; updateTaskStatus($taskId, 5); $fpath = $rootdir . "/books/" . $taskId . "/" . $authorName . ".fb2"; $xml = "<a></a>"; $fb2 = new SimpleXMLElement($xml); $sth = $db_conn->prepare("SELECT id,image FROM gmj_posts WHERE author='" . $authorId . "' AND site='" . $site . "' AND (image='2' OR image='3') AND image_in_book='0' GROUP BY id ASC"); $sth->execute(); $images = $sth->fetchAll(PDO::FETCH_ASSOC); foreach ($images as $image) { if ($image["image"] == 2) { $imageType = "image/jpeg"; $ext = "jpg"; } if ($image["image"] == 3) { $ext = "png"; $imageType = "image/" . $ext; } $path = getURL($site) . "/Blog/Attachment.ashx?aid=" . $image["id"]; $base64 = wordwrap(base64_encode(file_get_contents($path)), 120, "\n", TRUE); // Inserting binary images $binary = $fb2->addChild("binary", $base64); $binary->addAttribute('id', 'image' . $image["id"] . '.' . $ext); $binary->addAttribute('content-type', $imageType); $binaries = $binary->asXML() . "\n"; file_put_contents($fpath, $binaries, FILE_APPEND); $db_conn->exec("UPDATE gmj_posts SET image_in_book='1' WHERE id='" . $image["id"] . "' AND site='" . $site . "'"); } file_put_contents($fpath, "</FictionBook>", FILE_APPEND); // Updating images counter and status $sth = $db_conn->prepare("SELECT COUNT(*) FROM gmj_posts WHERE author='" . $authorId . "' AND site='" . $site . "' AND image_in_book='1'"); $sth->execute(); $imagesCount = $sth->fetchColumn(); $db_conn->exec("UPDATE gmj_tasks SET images_count='" . $imagesCount . "', status='6' WHERE id='" . $taskId . "'"); }