Beispiel #1
0
<?php

require_once GRID_DIR . '/library/simplehtmldom/simple_html_dom.php';
if (!empty($_SESSION['is_admin']) && !empty($_POST['urls'])) {
    $results = array();
    $urls = explode("\n", $_POST['urls']);
    foreach ($urls as $url) {
        $url = trim($url);
        if (empty($url) || substr($url, 0, 4) != 'http') {
            continue;
        }
        if (substr($url, -4, 4) == '.pdf') {
            download_pdf($url);
        } else {
            import_article($url);
        }
    }
}
//$this->redirect('/c/library');
exit;
function import_article($url)
{
    $md5 = md5($url);
    $path = GRID_DIR . "/import/{$md5}.html";
    $token = READABILITY_API_KEY;
    $url_encoded = urlencode($url);
    $request = "https://readability.com/api/content/v1/parser?url={$url_encoded}&token={$token}";
    $json = download_file($request);
    $result = json_decode($json);
    if (!empty($result->title)) {
        $content = process_content($result);
        //			$dom = domxml_open_file('xmldb.xml');
        if ($dom) {
            $root = $dom->document_element();
            $schema_version = $root->get_elements_by_tagname('schema_version');
            $schema_version = $schema_version[0]->get_content();
            if ($schema_version > MAX_SOURCE_SCHEMA_VERSION) {
                die("Incorrect source schema version");
            }
            $articles = $root->get_elements_by_tagname("article");
            foreach ($articles as $article) {
                $child_nodes = $article->child_nodes();
                $article_data = array();
                foreach ($child_nodes as $child) {
                    $article_data[$child->tagname()] = $child->get_content();
                }
                $is_imported = import_article($link, $article_data);
            }
            print "<p><a class=\"button\" href=\"prefs.php\">Return to preferences</a>";
        } else {
            print "Error: could not parse document.";
        }
    } else {
        print "<p>Error: please upload XMLDB.</p>";
    }
}
?>
</div>
</body>
</html>

    hesk_error($hesklang['kbdis']);
}
/* This will tell the header to include WYSIWYG editor Javascript */
define('WYSIWYG', 1);
/* What should we do? */
if ($action = hesk_REQUEST('a')) {
    if ($action == 'add_article') {
        add_article();
    } elseif ($action == 'add_category') {
        add_category();
    } elseif ($action == 'manage_cat') {
        manage_category();
    } elseif ($action == 'edit_article') {
        edit_article();
    } elseif ($action == 'import_article') {
        import_article();
    } elseif ($action == 'list_private') {
        list_private();
    } elseif ($action == 'list_draft') {
        list_draft();
    } elseif (defined('HESK_DEMO')) {
        hesk_process_messages($hesklang['ddemo'], 'manage_knowledgebase.php', 'NOTICE');
    } elseif ($action == 'new_article') {
        new_article();
    } elseif ($action == 'new_category') {
        new_category();
    } elseif ($action == 'remove_article') {
        remove_article();
    } elseif ($action == 'save_article') {
        save_article();
    } elseif ($action == 'order_article') {