function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
     $users = array();
     $entries = array();
     if (!extension_loaded('mysqli')) {
         return MYSQL_REQUIRED;
     }
     $bblogdb = @mysqli_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$bblogdb || mysqli_connect_error()) {
         return sprintf(COULDNT_CONNECT, serendipity_specialchars($this->data['host']));
     }
     if (!@mysqli_select_db($bblogdb, $this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysqli_error($bblogdb));
     }
     /* Users */
     $res = @$this->nativeQuery("SELECT id         AS ID,\n                                    password   AS pw,\n                                    nickname   AS user_login,\n                                    email      AS user_email,\n                                    url        AS user_url\n                               FROM {$this->data['prefix']}authors", $bblogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysqli_error($bblogdb));
     }
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysqli_fetch_assoc($res);
         $data = array('right_publish' => 1, 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'userlevel' => USERLEVEL_ADMIN, 'password' => md5($users[$x]['pw']));
         // Wicked. This is the first blog I've seen storing cleartext passwords :-D
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         echo mysqli_error();
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}sections", $bblogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysqli_error($bblogdb));
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $row = mysqli_fetch_assoc($res);
         $cat = array('category_name' => $row['nicename'], 'category_description' => $row['nicename'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $row['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
         $this->categories[] = $row;
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts ORDER BY postid;", $bblogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysqli_error($bblogdb));
     }
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysqli_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['title']), 'isdraft' => $entries[$x]['status'] == 'live' ? 'false' : 'true', 'allow_comments' => $entries[$x]['allowcomments'] == 'allow' ? 'true' : 'false', 'timestamp' => $entries[$x]['posttime'], 'body' => $this->strtr($entries[$x]['body']), 'extended' => '');
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['author']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['user_login'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
         $sections = explode(':', $entries[$x]['sections']);
         foreach ($sections as $section) {
             if (empty($section)) {
                 continue;
             }
             foreach ($this->categories as $category) {
                 if ($category['sectionid'] == $section) {
                     $categoryid = $category['categoryid'];
                 }
             }
             if ($categoryid > 0) {
                 $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $categoryid);
                 serendipity_db_insert('entrycat', $this->strtrRecursive($data));
             }
         }
     }
     /* Comments */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments WHERE type = 'comment';", $bblogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($bblogdb));
     }
     while ($a = mysqli_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['postid'] == $a['postid']) {
                 $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['posttime'], 'author' => $a['postername'], 'email' => $a['posteremail'], 'url' => $a['posterwebsite'], 'ip' => $a['ip'], 'status' => 'approved', 'body' => $a['commenttext'], 'subscribed' => 'false', 'type' => 'NORMAL');
                 serendipity_db_insert('comments', $this->strtrRecursive($comment));
                 $cid = serendipity_db_insert_id('comments', 'id');
                 serendipity_approveComment($cid, $entry['entryid'], true);
             }
         }
     }
     /* Trackbacks */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments WHERE type = 'trackback';", $bblogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($bblogdb));
     }
     while ($a = mysqli_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['postid'] == $a['postid']) {
                 $trackback = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['posttime'], 'title' => $a['title'], 'author' => $a['postername'], 'email' => $a['posteremail'], 'url' => $a['posterwebsite'], 'ip' => $a['ip'], 'status' => 'approved', 'body' => $a['commenttext'], 'subscribed' => 'false', 'type' => 'TRACKBACK');
                 serendipity_db_insert('comments', $this->strtrRecursive($trackback));
                 $cid = serendipity_db_insert_id('comments', 'id');
                 serendipity_approveComment($cid, $entry['entryid'], true);
             }
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
     $users = array();
     $categories = array();
     $entries = array();
     if (!extension_loaded('mysqli')) {
         return MYSQL_REQUIRED;
     }
     $pmdb = @mysqli_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$pmdb || mysqli_connect_error()) {
         return sprintf(COULDNT_CONNECT, serendipity_specialchars($this->data['host']));
     }
     if (!@mysqli_select_db($pmdb, $this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysqli_error($pmdb));
     }
     /* Users */
     $res = @$this->nativeQuery("SELECT id         AS ID,\n                                    username   AS user_login,\n                                    `password` AS user_pass,\n                                    email      AS user_email,\n                                    status     AS user_level,\n                                    url        AS url\n                               FROM {$this->data['prefix']}members", $pmdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysqli_error($pmdb));
     }
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysqli_fetch_assoc($res);
         $data = array('right_publish' => $users[$x]['user_level'] >= 3 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'password' => $users[$x]['user_pass']);
         // pMachine uses md5, too.
         if ($users[$x]['user_level'] < 12) {
             $data['userlevel'] = USERLEVEL_EDITOR;
         } else {
             $data['userlevel'] = USERLEVEL_ADMIN;
         }
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     $res = @$this->nativeQuery("SELECT id       AS cat_ID,\n                                    category AS cat_name,\n                                    category AS category_description\n                               FROM {$this->data['prefix']}categories ORDER BY id", $pmdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysqli_error($pmdb));
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $categories[] = mysqli_fetch_assoc($res);
     }
     // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
     for ($x = 0, $max_x = sizeof($categories); $x < $max_x; $x++) {
         $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}weblog ORDER BY t_stamp;", $pmdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysqli_error($pmdb));
     }
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysqli_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['title']), 'isdraft' => $entries[$x]['status'] == 'open' ? 'false' : 'true', 'allow_comments' => $entries[$x]['showcomments'] == '1' ? 'true' : 'false', 'timestamp' => $entries[$x]['t_stamp'], 'extended' => $this->strtr($entries[$x]['more']), 'body' => $this->strtr($entries[$x]['body']));
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['member_id']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['username'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
         /* Entry/category */
         foreach ($categories as $category) {
             if ($category['cat_ID'] == $entries[$x]['category']) {
                 $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']);
                 serendipity_db_insert('entrycat', $this->strtrRecursive($data));
                 break;
             }
         }
     }
     /* Comments */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments;", $pmdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($pmdb));
     }
     while ($a = mysqli_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['post_id'] == $a['post_id']) {
                 $author = '';
                 $mail = '';
                 $url = '';
                 if (!empty($a['member_id'])) {
                     foreach ($users as $user) {
                         if ($user['ID'] == $a['member_id']) {
                             $author = $user['user_login'];
                             $mail = $user['user_email'];
                             $url = $user['url'];
                             break;
                         }
                     }
                 }
                 $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['t_stamp'], 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => $a['comment_ip'], 'status' => $a['status'] == 'open' ? 'approved' : 'pending', 'body' => $a['body'], 'subscribed' => 'false', 'type' => 'NORMAL');
                 serendipity_db_insert('comments', $this->strtrRecursive($comment));
                 if ($a['status'] == 'open') {
                     $cid = serendipity_db_insert_id('comments', 'id');
                     serendipity_approveComment($cid, $entry['entryid'], true);
                 }
             }
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
     $users = array();
     $categories = array();
     $entries = array();
     if (!extension_loaded('pgsql')) {
         return PGSQL_REQUIRED;
     }
     $wpdb = pg_connect("{$this->data}['host'], {$this->data}['port'], {$this->data}['user'], {$this->data}['pass'], {$this->data}['name']");
     if (!$wpdb) {
         return sprintf(PGSQL_COULDNT_CONNECT, $this->data['pass']);
     }
     /* Users */
     $res = pg_query($wpdb, "SELECT ID, user_login, user_pass, user_email, user_level FROM {$this->data['prefix']}users;");
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, pg_last_error($wpdb));
     }
     for ($x = 0; $x < pg_num_rows($res); $x++) {
         $users[$x] = pg_fetch_assoc($res);
         $data = array('right_publish' => $users[$x]['user_level'] >= 1 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'password' => $users[$x]['user_pass']);
         // WP uses md5, too.
         if ($users[$x]['user_level'] <= 1) {
             $data['userlevel'] = USERLEVEL_EDITOR;
         } elseif ($users[$x]['user_level'] < 5) {
             $data['userlevel'] = USERLEVEL_CHIEF;
         } else {
             $data['userlevel'] = USERLEVEL_ADMIN;
         }
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     $res = @pg_query($wpdb, "SELECT cat_ID, cat_name, category_description, category_parent FROM {$this->data['prefix']}categories ORDER BY category_parent, cat_ID;");
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, pg_last_error($wpdb));
     }
     // Get all the info we need
     for ($x = 0; $x < pg_num_rows($res); $x++) {
         $categories[] = pg_fetch_assoc($res);
     }
     // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
     for ($x = 0; $x < sizeof($categories); $x++) {
         $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
     }
     // There has to be a more efficient way of doing this...
     foreach ($categories as $cat) {
         if ($cat['category_parent'] != 0) {
             // Find the parent
             $par_id = 0;
             foreach ($categories as $possible_par) {
                 if ($possible_par['cat_ID'] == $cat['category_parent']) {
                     $par_id = $possible_par['categoryid'];
                     break;
                 }
             }
             if ($par_id != 0) {
                 serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category SET parentid={$par_id} WHERE categoryid={$cat['categoryid']};");
             }
             // else { echo "D'oh! " . random_string_of_profanity(); }
         }
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @pg_query($wpdb, "SELECT * FROM {$this->data['prefix']}posts ORDER BY post_date;");
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, pg_last_error($wpdb));
     }
     for ($x = 0; $x < pg_num_rows($res); $x++) {
         $entries[$x] = pg_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['post_title']), 'isdraft' => $entries[$x]['post_status'] == 'publish' ? 'false' : 'true', 'allow_comments' => $entries[$x]['comment_status'] == 'open' ? 'true' : 'false', 'timestamp' => strtotime($entries[$x]['post_date']), 'body' => $this->strtr($entries[$x]['post_content']));
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['post_author']) {
                 $entry['authorid'] = $user['authorid'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
     }
     /* Entry/category */
     $res = @pg_query($wpdb, "SELECT * FROM {$this->data['prefix']}post2cat;");
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, pg_last_error($wpdb));
     }
     while ($a = pg_fetch_assoc($res)) {
         foreach ($categories as $category) {
             if ($category['cat_ID'] == $a['category_id']) {
                 foreach ($entries as $entry) {
                     if ($a['post_id'] == $entry['ID']) {
                         $data = array('entryid' => $entry['entryid'], 'categoryid' => $category['categoryid']);
                         serendipity_db_insert('entrycat', $this->strtrRecursive($data));
                         break;
                     }
                 }
                 break;
             }
         }
     }
     /* Comments */
     $res = @pg_query($wpdb, "SELECT * FROM {$this->data['prefix']}comments;");
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, pg_last_error($wpdb));
     }
     while ($a = pg_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['ID'] == $a['comment_post_ID']) {
                 $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['comment_date']), 'author' => $a['comment_author'], 'email' => $a['comment_author_email'], 'url' => $a['comment_author_url'], 'ip' => $a['comment_author_IP'], 'status' => empty($a['comment_approved']) || $a['comment_approved'] == '1' ? 'approved' : 'pending', 'subscribed' => 'false', 'body' => $a['comment_content'], 'type' => 'NORMAL');
                 serendipity_db_insert('comments', $this->strtrRecursive($comment));
                 if ($comment['status'] == 'approved') {
                     $cid = serendipity_db_insert_id('comments', 'id');
                     serendipity_approveComment($cid, $entry['entryid'], true);
                 }
             }
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
/**
 * Prints the content of the iframe.
 *
 * Called by serendipity_is_iframe, when preview is requested. Fetches data from session.
 * An iframe is used so that a single s9y page must not timeout on intensive operations,
 * and so that the frontend stylesheet can be embedded without screwing up the backend.
 *
 * @access private
 * @see serendipity_is_iframe()
 * @param   mixed   The entry array (comes from session variable)
 * @param   string  Indicates whether an entry is previewed or saved. Save performs XML-RPC calls.
 * @param   boolean Use smarty templating?
 * @return  boolean Indicates whether iframe data was printed
 */
function serendipity_iframe(&$entry, $mode = null)
{
    global $serendipity;
    if (empty($mode) || !is_array($entry)) {
        return false;
    }
    $data = array();
    $data['is_preview'] = true;
    $data['mode'] = $mode;
    switch ($mode) {
        case 'save':
            ob_start();
            $res = serendipity_updertEntry($entry);
            $data['updertHooks'] = ob_get_contents();
            ob_end_clean();
            if (is_string($res)) {
                $data['res'] = $res;
            }
            if (!empty($serendipity['lastSavedEntry'])) {
                $data['lastSavedEntry'] = $serendipity['lastSavedEntry'];
            }
            $data['entrylink'] = serendipity_archiveURL($res, $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp']));
            break;
        case 'preview':
            $serendipity['smarty_preview'] = true;
            $data['preview'] = serendipity_printEntries(array($entry), $entry['extended'] != '' ? 1 : 0, true);
            break;
    }
    return serendipity_smarty_show('preview_iframe.tpl', $data);
}
 function phoneblogz_post($postid, $pbuserno)
 {
     // Firstly try and download the file
     $url = "http://www.phoneblogz.com/listen.php?user="******"phoneblogz_accesscode") . "&id={$postid}";
     $upload = $this->phoneblogz_upload_fromurl("pbpost.mp3", "", $url);
     if (!isset($upload["error"])) {
         // Deal with the local username
         $localuserid = $this->get_config("phoneblogz_usermap_{$pbuserno}");
         if ($localuserid === FALSE || $localuserid < 1) {
             $localuserid = 1;
         }
         // Default to the admin user
         // Get the local username for this user
         $localuser = serendipity_fetchUsers($localuserid);
         $localusername = $localuser[0]["realname"];
         // Attempt to create a new post
         $post_content = $this->get_config("phoneblogz_text");
         $post_content = str_replace("[FLASH]", $this->phoneblogz_flash($upload["url"]), $post_content);
         $post_content = str_replace("[USER]", $localusername, $post_content);
         $first = strpos($post_content, "[");
         $second = strpos($post_content, "]");
         if ($first !== FALSE && $second !== FALSE && $second > $first) {
             $link = "<a href=\"" . $upload["url"] . "\">";
             $link .= substr($post_content, $first + 1, $second - $first - 1);
             $link .= "</a>";
             $post_content = substr($post_content, 0, $first) . $link . substr($post_content, $second + 1);
         }
         $oldsess = $_SESSION['serendipityRightPublish'];
         $_SESSION['serendipityRightPublish'] = true;
         $entry = array('body' => $post_content, 'title' => str_replace("[USER]", $localusername, $this->get_config('phoneblogz_subject')), 'timestamp' => time(), 'isdraft' => 'false', 'allow_comments' => true, 'authorid' => $localuserid, 'categories' => array($this->get_config('categoryid')));
         $GLOBALS['serendipity']['POST']['properties'] = array('fake' => 'fake');
         $post_ID = serendipity_updertEntry($entry);
         $_SESSION['serendipityRightPublish'] = $oldsess;
         $this->set_config("phoneblogz_status_{$postid}", $post_ID);
         return array("postid" => $post_ID);
     } else {
         return array("error" => "Failed to upload the file.  Exact error: " . $upload["error"]);
     }
 }
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
     $users = array();
     $entries = array();
     if (!extension_loaded('mysqli')) {
         return MYSQL_REQUIRED;
     }
     $gdb = @mysqli_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$gdb || mysqli_connect_error()) {
         return sprintf(COULDNT_CONNECT, serendipity_specialchars($this->data['host']));
     }
     if (!@mysqli_select_db($gdb, $this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysqli_error($gdb));
     }
     /* Users */
     $res = @$this->nativeQuery("SELECT user_id       AS ID,\n                                    username      AS user_login,\n                                    user_password AS user_pass,\n                                    user_email    AS user_email,\n                                    user_website  AS user_url,\n                                    user_level\n                               FROM {$this->data['prefix']}users\n                              WHERE user_active = 1", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysqli_error($gdb));
     }
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysqli_fetch_assoc($res);
         $data = array('right_publish' => 1, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'userlevel' => $users[$x]['user_level'] == 0 ? USERLEVEL_EDITOR : USERLEVEL_ADMIN, 'password' => $users[$x]['user_pass']);
         // MD5 compatible
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         echo mysqli_error();
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     $res = @$this->nativeQuery("SELECT cat_id AS cat_ID, \n                                    cat_title AS cat_name \n                               FROM {$this->data['prefix']}categories", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysqli_error($gdb));
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $parent_categories[] = mysqli_fetch_assoc($res);
     }
     for ($x = 0, $max_x = sizeof($parent_categories); $x < $max_x; $x++) {
         $cat = array('category_name' => $parent_categories[$x]['cat_name'], 'category_description' => '', 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $parent_categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
     }
     /* Categories */
     $res = @$this->nativeQuery("SELECT forum_id AS cat_ID,\n                                    cat_id   AS parent_cat_id, \n                                    forum_name AS cat_name, \n                                    forum_desc AS category_description \n                               FROM {$this->data['prefix']}forums ORDER BY forum_order;", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysqli_error($gdb));
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $categories[] = mysqli_fetch_assoc($res);
     }
     // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
     for ($x = 0, $max_x = sizeof($categories); $x < $max_x; $x++) {
         $pcatid = 0;
         foreach ($parent_categories as $pcat) {
             if ($pcat['cat_ID'] == $categories[$x]['parent_cat_id']) {
                 $pcatid = $pcat['cat_ID'];
                 break;
             }
         }
         $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => $pcatid, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @$this->nativeQuery("SELECT t.topic_title, \n                                    t.topic_poster,\n                                    t.forum_id,\n                                    p.post_time,\n                                    pt.post_subject,\n                                    pt.post_text,\n                                    count(p.topic_id) AS ccount,\n                                    p.topic_id,\n                                    MIN(p.post_id) AS post_id\n                               FROM {$this->data['prefix']}topics AS t\n                    LEFT OUTER JOIN {$this->data['prefix']}posts  AS p\n                                 ON t.topic_id = p.topic_id\n                    LEFT OUTER JOIN {$this->data['prefix']}posts_text  AS pt\n                                 ON pt.post_id = p.post_id\n                           GROUP BY p.topic_id\n                           ", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysqli_error($gdb));
     }
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysqli_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['post_subject']), 'isdraft' => 'false', 'allow_comments' => 'true', 'timestamp' => $entries[$x]['post_time'], 'body' => $this->strtr($entries[$x]['post_text']), 'extended' => '');
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['topic_poster']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['user_login'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
         /* Entry/category */
         foreach ($categories as $category) {
             if ($category['cat_ID'] == $entries[$x]['forum_id']) {
                 $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']);
                 serendipity_db_insert('entrycat', $this->strtrRecursive($data));
                 break;
             }
         }
         /* Comments */
         $topic_id = $entries[$x]['topic_id'];
         $c_res = @$this->nativeQuery("SELECT t.topic_title, \n                                        t.topic_poster,\n                                        p.poster_id,\n                                        t.forum_id,\n                                        p.post_time,\n                                        pt.post_subject,\n                                        pt.post_text,\n                                        pt.post_id\n                                   FROM {$this->data['prefix']}topics AS t\n                        LEFT OUTER JOIN {$this->data['prefix']}posts  AS p\n                                     ON t.topic_id = p.topic_id\n                        LEFT OUTER JOIN {$this->data['prefix']}posts_text  AS pt\n                                     ON pt.post_id = p.post_id\n                                  WHERE p.topic_id = {$topic_id} \n                               ", $gdb);
         if (!$c_res) {
             return sprintf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($gdb));
         }
         while ($a = mysqli_fetch_assoc($c_res)) {
             if ($a['post_id'] == $entries[$x]['post_id']) {
                 continue;
             }
             $author = '';
             $mail = '';
             $url = '';
             foreach ($users as $user) {
                 if ($user['ID'] == $a['poster_id']) {
                     $author = $user['user_login'];
                     $mail = $user['user_email'];
                     $url = $user['user_url'];
                     break;
                 }
             }
             $comment = array('entry_id ' => $entries[$x]['entryid'], 'parent_id' => 0, 'timestamp' => $a['post_time'], 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => '', 'status' => 'approved', 'body' => $a['post_text'], 'subscribed' => 'false', 'type' => 'NORMAL');
             serendipity_db_insert('comments', $this->strtrRecursive($comment));
             $cid = serendipity_db_insert_id('comments', 'id');
             serendipity_approveComment($cid, $entries[$x]['entryid'], true);
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
Exemple #7
0
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
     $users = array();
     $categories = array();
     $entries = array();
     if (!extension_loaded('mysql')) {
         return MYSQL_REQUIRED;
     }
     $nucdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$nucdb) {
         return sprintf(COULDNT_CONNECT, $this->data['host']);
     }
     if (!@mysql_select_db($this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysql_error($nucdb));
     }
     /* Users */
     $res = @$this->nativeQuery("SELECT mnumber AS ID, mname AS user_login, mpassword AS user_pass, memail AS user_email, madmin AS user_level FROM {$this->data['prefix']}member;", $nucdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($nucdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysql_fetch_assoc($res);
         $data = array('right_publish' => $users[$x]['user_level'] >= 1 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'password' => $users[$x]['user_pass']);
         // Nucleus uses md5, too.
         if ($users[$x]['user_level'] < 1) {
             $data['userlevel'] = USERLEVEL_EDITOR;
         } else {
             $data['userlevel'] = USERLEVEL_ADMIN;
         }
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     $res = @$this->nativeQuery("SELECT catid AS cat_ID, cname AS cat_name, cdesc AS category_description FROM {$this->data['prefix']}category ORDER BY catid;", $nucdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($nucdb));
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $categories[] = mysql_fetch_assoc($res);
     }
     // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
     for ($x = 0, $max_x = sizeof($categories); $x < $max_x; $x++) {
         $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}item ORDER BY itime;", $nucdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($nucdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysql_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['ititle']), 'isdraft' => $entries[$x]['idraft'] != '1' ? 'false' : 'true', 'allow_comments' => $entries[$x]['iclosed'] == '1' ? 'false' : 'true', 'timestamp' => strtotime($entries[$x]['itime']), 'extended' => $this->strtr($entries[$x]['imore']), 'body' => $this->strtr($entries[$x]['ibody']));
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['iauthor']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['realname'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
         /* Entry/category */
         foreach ($categories as $category) {
             if ($category['cat_ID'] == $entries[$x]['icat']) {
                 $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']);
                 serendipity_db_insert('entrycat', $this->strtrRecursive($data));
                 break;
             }
         }
     }
     /* Comments */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comment;", $nucdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($nucdb));
     }
     while ($a = mysql_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['inumber'] == $a['citem']) {
                 $author = '';
                 $mail = '';
                 if (!empty($a['cmember'])) {
                     foreach ($users as $user) {
                         if ($user['ID'] == $a['cmember']) {
                             $author = $user['user_login'];
                             $mail = $user['user_email'];
                             break;
                         }
                     }
                 }
                 if (empty($author) && empty($mail)) {
                     $author = $a['cuser'];
                     $mail = $a['cmail'];
                 }
                 $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['ctime']), 'author' => $author, 'email' => $mail, 'url' => $a['chost'], 'ip' => $a['cip'], 'status' => 'approved', 'body' => $a['cbody'], 'subscribed' => 'false', 'type' => 'NORMAL');
                 serendipity_db_insert('comments', $this->strtrRecursive($comment));
                 $cid = serendipity_db_insert_id('comments', 'id');
                 serendipity_approveComment($cid, $entry['entryid'], true);
             }
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
 function import()
 {
     global $serendipity;
     if (!file_exists($this->data['url'])) {
         printf(FILE_NOT_FOUND, htmlspecialchars($this->data['url']));
         return false;
     }
     $file = file_get_contents($this->data['url']);
     $tree =& $this->parseXML($file);
     $serendipity['noautodiscovery'] = 1;
     foreach ($tree[0]['children'] as $idx => $entry) {
         if (!is_array($entry)) {
             continue;
         }
         if ($entry['tag'] != 'entry') {
             continue;
         }
         $new_entry = array('allow_comments' => true, 'extended' => '', 'categories' => array(), 'isdraft' => $this->data['type'] == 'draft' ? 'true' : 'false', 'categories' => array($this->data['category'] => $this->data['category']));
         if (!is_array($entry['children'])) {
             continue;
         }
         foreach ($entry['children'] as $idx2 => $entrydata) {
             if (!is_array($entrydata)) {
                 continue;
             }
             switch ($entrydata['tag']) {
                 case 'eventtime':
                     $new_entry['timestamp'] = $this->getTimestamp($entrydata['value']);
                     break;
                 case 'date':
                     $new_entry['timestamp'] = $this->getTimestamp($entrydata['value']);
                     break;
                 case 'subject':
                     $new_entry['title'] = $entrydata['value'];
                     break;
                 case 'event':
                     $new_entry['body'] = $entrydata['value'];
                     break;
                 case 'comments':
                     $new_entry['comments'] = $this->gatherComments($entrydata);
                     break;
             }
         }
         $id = serendipity_updertEntry($new_entry);
         echo 'Inserted entry #' . $id . ', "' . htmlspecialchars($new_entry['title']) . '"<br />' . "\n";
         if (is_array($new_entry['comments'])) {
             $cid_map = array();
             $jids = array();
             foreach ($new_entry['comments'] as $comment) {
                 array_push($jids, $comment['jtalkid']);
                 if (array_key_exists($comment['jparentid'], $cid_map)) {
                     $comment['parent_id'] = $cid_map[$comment['jparentid']];
                 }
                 $cid = serendipity_insertComment($id, $comment);
                 $cid_map[$comment['jtalkid']] = $cid;
             }
             echo 'Inserted comments for entry #' . $id . '<br />' . "\n";
         }
         if (function_exists('ob_flush')) {
             @ob_flush();
         }
         if (function_exists('flush')) {
             @flush();
         }
     }
     return true;
 }
 function fetchFeeds($opt = null)
 {
     global $serendipity;
     set_time_limit(360);
     ignore_user_abort(true);
     $_SESSION['serendipityRightPublish'] = true;
     $serendipity['noautodiscovery'] = true;
     $this->setupDB();
     $feeds = $this->getFeeds($opt);
     $engine = $this->get_config('engine', 'onyx');
     if ($engine == 'onyx') {
         require_once (defined('S9Y_PEAR_PATH') ? S9Y_PEAR_PATH : S9Y_INCLUDE_PATH . 'bundled-libs/') . 'Onyx/RSS.php';
     } elseif ($engine == 'magpierss') {
         // CLSC: NEW "MagpieRSS" include
         require_once dirname(__FILE__) . '/magpierss/rss_fetch.inc';
     } elseif ($engine == 'simplepie') {
         //hwa: NEW "SimplePie" include
         require_once dirname(__FILE__) . '/simplepie/simplepie.inc';
     }
     $cache_authors = array();
     $cache_entries = array();
     $cache_md5 = array();
     $sql_cache_authors = serendipity_db_Query("SELECT authorid, realname\n                                                 FROM {$serendipity['dbPrefix']}authors");
     if (is_array($sql_cache_authors)) {
         foreach ($sql_cache_authors as $idx => $author) {
             $cache_authors[$author['realname']] = $author['authorid'];
         }
     }
     if ($this->debug) {
         printf("DEBUG: cache_authors['realname'] = authorid has %d entries\n", count($cache_authors));
     }
     if ($opt['store_seperate']) {
         $sql_cache_entries = serendipity_db_query("SELECT e.feedid, e.id, e.entrydate, e.entrytitle\n                                                         FROM {$serendipity['dbPrefix']}aggregator_feedlist AS e");
         if (is_array($sql_cache_entries)) {
             foreach ($sql_cache_entries as $idx => $entry) {
                 $cache_entries[$entry['entrytitle']][$entry['feedid']][$entry['entrydate']] = $entry['id'];
             }
         }
     } else {
         $sql_cache_entries = serendipity_db_query("SELECT e.id, e.timestamp, e.authorid, e.title, ep.value\n                                                         FROM {$serendipity['dbPrefix']}entries AS e,\n                                                              {$serendipity['dbPrefix']}entryproperties AS ep\n                                                        WHERE e.id = ep.entryid\n                                                          AND ep.property = 'ep_aggregator_feed'");
         if (is_array($sql_cache_entries)) {
             foreach ($sql_cache_entries as $idx => $entry) {
                 $cache_entries[$entry['title']][$entry['authorid']][$entry['timestamp']] = $entry['id'];
             }
         }
     }
     if ($this->debug) {
         printf("DEBUG: cache_entries['title']['authorid']['timestamp'] = entryid has %d entries.\n", count($cache_entries));
     }
     $sql_cache_md5 = serendipity_db_query("SELECT entryid, md5, timestamp\n                                                     FROM {$serendipity['dbPrefix']}aggregator_md5");
     if (is_array($sql_cache_md5)) {
         foreach ($sql_cache_md5 as $idx => $entry) {
             $cache_md5[$entry['md5']]['entryid'] = $entry['entryid'];
             $cache_md5[$entry['md5']]['timestamp'] = $entry['timestamp'];
         }
     }
     if ($this->debug) {
         printf("DEBUG: cache_md5['md5'] = entryid has %d entries.\n", count($cache_md5));
     }
     foreach ($feeds as $feed) {
         if (!$opt['store_seperate']) {
             printf("Read %s.\n", $feed['feedurl']);
         }
         flush();
         $feed_authorid = $cache_authors[$feed['feedname']];
         if (empty($feed_authorid)) {
             $feed_authorid = 0;
         }
         if ($this->debug) {
             printf("DEBUG: Current authorid = %d\n", $feed_authorid);
         }
         $stack = array();
         if ($engine == 'onyx') {
             if (empty($feed['charset'])) {
                 $this->checkCharset($feed);
             }
             # test multiple likely charsets
             $charsets = array($feed['charset'], "ISO-8859-1", "utf-8");
             $retry = false;
             foreach ($charsets as $ch) {
                 if ($retry) {
                     printf("DEBUG: Retry with charset %s instead of %s\n", $ch, $feed['charset']);
                 }
                 $retry = true;
                 $c = new Onyx_RSS($ch);
                 # does it parse? if so, all is fine...
                 if ($c->parse($feed['feedurl'])) {
                     break;
                 }
             }
             while ($item = $c->getNextItem()) {
                 /* Okay this is where things get tricky. Everybody
                  * encodes their information differently. For now I'm going to focus on
                  * s9y weblogs. */
                 $fake_timestamp = false;
                 $date = $this->parseDate($item['pubdate']);
                 if ($this->debug) {
                     printf("DEBUG: pubDate %s = %s\n", $item['pubdate'], $date);
                 }
                 if ($date == -1) {
                     // Fallback to try for dc:date
                     $date = $this->parseDate($item['dc:date']);
                     if ($this->debug) {
                         printf("DEBUG: falling back to dc:date % s= %s\n", $item['dc:date'], $date);
                     }
                 }
                 if ($date == -1) {
                     // Couldn't figure out the date string. Set it to "now" and hope that the md5hash will get it.
                     $date = time();
                     $fake_timestamp = true;
                     if ($this->debug) {
                         printf("DEBUG: falling back to time() = %s\n", $date);
                     }
                 }
                 if (empty($item['title'])) {
                     if ($this->debug) {
                         printf("DEBUG: skip item: title was empty for %s\n", print_r($item, true));
                     }
                     continue;
                 }
                 $this->decode($c->rss['encoding'], $item);
                 $item['date'] = $date;
                 $stack[] = $item;
             }
         } elseif ($engine == 'magpierss') {
             // ----------------------------------------------------------
             // CLSC: New MagpieRSS code start
             // ----------------------------------------------------------
             $rss = fetch_rss($feed['feedurl']);
             foreach ($rss->items as $item) {
                 $fake_timestamp = false;
                 $date = $item['pubdate'];
                 if ($this->debug) {
                     printf("DEBUG: pubdate = %s\n", $item['pubdate'], $date);
                 }
                 // ----------------------------------------------------------
                 // CLSC:        Try a few different types of timestamp fields
                 //                So that we might get lucky even with non-standard feeds
                 // ----------------------------------------------------------
                 if ($date == "") {
                     // CLSC: magpie syntax for nested fields
                     $date = $item['dc']['date'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to [dc][date] = %s\n", $item['dc:date'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['modified'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to modified = %s\n", $item['modified'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['PubDate'];
                     if ($this->debug) {
                         printf("DEBUG: falling back PubDate = %s\n", $item['PubDate'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['created'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to created = %s\n", $item['created'], $date);
                     }
                 }
                 if ($date == "") {
                     // CLSC: not proper magpie syntax but still catches some
                     $date = $item['dc:date'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to dc:date = %s\n", $item['dc:date'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['updated'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to updated = %s\n", $item['updated'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['published'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to published = %s\n", $item['published'], $date);
                     }
                 }
                 if ($date == "") {
                     // ----------------------------------------------------------
                     //    CLSC:        If none of the above managed to identify a date:
                     //                 Set date to "now" and hope that the md5hash will get it.
                     // ----------------------------------------------------------
                     $date = time();
                     $fake_timestamp = true;
                     if ($this->debug) {
                         printf("DEBUG: falling back to time() = %s\n", $date);
                     }
                 }
                 // CLSC: if date is set to "now" parseDate can't parse it.
                 if ($fake_timestamp != true) {
                     $date = $this->parseDate($date);
                 }
                 if ($item['title'] == "") {
                     if ($this->debug) {
                         printf("DEBUG: skip item: title was empty for %s\n", print_r($item, true));
                     }
                     continue;
                 }
                 $item['date'] = $date;
                 $stack[] = $item;
                 // ----------------------------------------------------------
                 //    CLSC: New MagpieRSS code end
                 // ----------------------------------------------------------
             }
         } elseif ($engine == 'simplepie') {
             // hwa: new SimplePie code  ; lifted from the SimplePie demo
             $simplefeed = new SimplePie();
             $simplefeed->cache = false;
             $simplefeed->set_feed_url($feed['feedurl']);
             // Initialize the whole SimplePie object.  Read the feed, process it, parse it, cache it, and
             // all that other good stuff.  The feed's information will not be available to SimplePie before
             // this is called.
             $success = $simplefeed->init();
             // We'll make sure that the right content type and character encoding gets set automatically.
             // This function will grab the proper character encoding, as well as set the content type to text/html.
             $simplefeed->set_output_encoding(LANG_CHARSET);
             $simplefeed->handle_content_type();
             $item['new_feedicon'] = $simplefeed->get_favicon();
             // error handling
             if ($simplefeed->error()) {
                 if (!$opt['store_seperate']) {
                     printf('<p><b>ERROR:</b> ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($simplefeed->error()) : htmlspecialchars($simplefeed->error(), ENT_COMPAT, LANG_CHARSET)) . "</p>\r\n");
                 }
             }
             if ($success) {
                 foreach ($simplefeed->get_items() as $simpleitem) {
                     // map SimplePie items to s9y items
                     $item['title'] = $simpleitem->get_title();
                     $item['date'] = $simpleitem->get_date('U');
                     $item['pubdate'] = $simpleitem->get_date('U');
                     $item['description'] = $simpleitem->get_description();
                     $item['content'] = $simpleitem->get_content();
                     $item['link'] = $simpleitem->get_permalink();
                     $item['author'] = $simpleitem->get_author();
                     //if ($this->debug) {
                     //  printf("DEBUG: SimplePie item: author: $item['author'], title: $item['title'], date: $item['date']\n");
                     //}
                     $stack[] = $item;
                 }
             } else {
                 if (!$opt['store_seperate']) {
                     printf('<p><b>ERROR:</b> ' . print_r($success, true) . "</p>\r\n");
                 }
             }
         }
         while (list($key, $item) = each($stack)) {
             if ($opt['store_seperate']) {
                 $ep_id = $cache_entries[$item['title']][$feed['feedid']][$item['date']];
                 if ($this->debug) {
                     printf("DEBUG: lookup cache_entries[%s][%s][%s] finds %s.\n", $item['title'], $feed['feedid'], $item['date'], empty($ep_id) ? "nothing" : $ep_id);
                 }
             } else {
                 $ep_id = $cache_entries[$item['title']][$feed_authorid][$item['date']];
                 if ($this->debug) {
                     printf("DEBUG: lookup cache_entries[%s][%s][%s] finds %s.\n", $item['title'], $feed_authorid, $item['date'], empty($ep_id) ? "nothing" : $ep_id);
                 }
             }
             if (!empty($ep_id) and serendipity_db_bool($this->get_config('ignore_updates'))) {
                 if ($this->debug) {
                     printf("DEBUG: entry %s is known and ignore_updates is set.\n", $ep_id);
                 }
                 continue;
             }
             # NOTE: If $ep_id is NULL or EMPTY, it means that an entry with this title does not
             #       yet exist. Later on we check if a similar entry with the body exists and skip
             #       updates in this case. Else it means that the new entry needs to be inserted
             #       as a new one.
             # The entry is probably new?
             $entry = array('id' => $ep_id, 'title' => $item['title'], 'timestamp' => $item['date'], 'extended' => '', 'isdraft' => serendipity_db_bool($this->get_config('publishflag')) ? 'false' : 'true', 'allow_comments' => serendipity_db_bool($this->get_config('allow_comments')) ? 'true' : 'false', 'categories' => $feed['categoryids'], 'author' => $feed['feedname'], 'authorid' => $feed_authorid);
             // ----------------------------------------------------------
             //    CLSC: Added a few flavours
             if ($item['content:encoded']) {
                 $entry['body'] = $item['content:encoded'];
             } elseif ($item['description']) {
                 $entry['body'] = $item['description'];
             } elseif ($item['content']['encoded']) {
                 $entry['body'] = $item['content']['encoded'];
             } elseif ($item['atom_content']) {
                 $entry['body'] = $item['atom_content'];
             } elseif ($item['content']) {
                 $entry['body'] = $item['content'];
             }
             $md5hash = md5($feed_authorid . $item['title'] . $entry['body']);
             # Check 1: Have we seen this MD5?
             if ($this->debug) {
                 printf("DEBUG: lookup cache_md5[%s] finds %s.\n", $md5hash, empty($cache_md5[$md5hash]) ? "nothing" : $cache_md5[$md5hash]['entryid']);
             }
             # If we have this md5, title and body for this article
             # are unchanged. We do not need to do anything.
             if (isset($cache_md5[$md5hash])) {
                 continue;
             }
             # Check 2 (conditional: expire enabled?):
             #         Is this article too old?
             if ($this->get_config('expire') > 0) {
                 $expire = time() - 86400 * $this->get_config('expire');
                 if ($item['date'] < $expire) {
                     if ($this->debug) {
                         printf("DEBUG: '%s' is too old (%s < %s).\n", $item['title'], $item['date'], $expire);
                     }
                     continue;
                 }
             }
             # Check 3: Does this article match our expressions?
             if (!empty($feed['match_expression'])) {
                 $expressions = explode("~", $feed['match_expression']);
                 $match = 0;
                 foreach ($expressions as $expression) {
                     $expression = ltrim(rtrim($expression));
                     if (preg_match("~{$expression}~imsU", $entry['title'] . $entry['body'])) {
                         $match = 1;
                     }
                 }
                 if ($match == 0) {
                     continue;
                 }
             }
             $feed['articleurl'] = $item['link'];
             if ($item['author']) {
                 $feed['author'] = $item['author'];
             } elseif ($item['dc:creator']) {
                 $feed['author'] = $item['dc:creator'];
             }
             // Store as property
             // Plugins might need this.
             $serendipity['POST']['properties'] = array('fake' => 'fake');
             $markups = explode('^', $this->get_config('markup'));
             if (is_array($markups)) {
                 foreach ($markups as $markup) {
                     $serendipity['POST']['properties']['disable_markups'][] = $markup;
                 }
             }
             if ($opt['store_seperate']) {
                 if ($entry['id'] > 0) {
                     serendipity_db_query("UPDATE {$serendipity['dbPrefix']}aggregator_feedlist \n                        SET feedid      = '" . $feed['feedid'] . "',\n                            categoryid  = '" . $feed['categoryids'][0] . "',\n                            entrydate   = '" . serendipity_db_escape_string($entry['timestamp']) . "',\n                            entrytitle  = '" . serendipity_db_escape_string($entry['title']) . "',\n                            entrybody   = '" . serendipity_db_escape_string($entry['body']) . "',\n                            entryurl    = '" . serendipity_db_escape_string($item['link']) . "'\n                        WHERE id = " . $entry['id']);
                     $entryid = $entry['id'];
                 } else {
                     serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}aggregator_feedlist (\n                            feedid,\n                            categoryid,\n                            entrydate,\n                            entrytitle,\n                            entrybody,\n                            entryurl\n                        ) VALUES (\n                            '" . $feed['feedid'] . "',\n                            '" . $feed['categoryids'][0] . "',\n                            '" . serendipity_db_escape_string($entry['timestamp']) . "',\n                            '" . serendipity_db_escape_string($entry['title']) . "',\n                            '" . serendipity_db_escape_string($entry['body']) . "',\n                            '" . serendipity_db_escape_string($item['link']) . "'\n                        )");
                     $entryid = serendipity_db_insert_id();
                 }
                 $this->feedupdate_finish($feed, $entryid);
             } else {
                 $entryid = serendipity_updertEntry($entry);
                 $this->insertProperties($entryid, $feed, $md5hash);
             }
             if (!$opt['store_seperate']) {
                 printf(" Save '%s' as %s.\n", $item['title'], $entryid);
             }
         }
         if (!$opt['store_seperate']) {
             printf("Finish feed.\n");
         }
     }
     if (!$opt['store_seperate']) {
         printf("Finish planetarium.\n");
     }
 }
     }
 }
 // Save server timezone in database always, so substract the offset we added for display; otherwise it would be added time and again
 if (!empty($entry['timestamp'])) {
     $entry['timestamp'] = serendipity_serverOffsetHour($entry['timestamp'], true);
 }
 // Save the entry, or just display a preview
 $data['use_legacy'] = $use_legacy = true;
 serendipity_plugin_api::hook_event('backend_entry_iframe', $use_legacy);
 if ($use_legacy) {
     $data['switched_output'] = true;
     if ($serendipity['POST']['preview'] != 'true') {
         /* We don't need an iframe to save a draft */
         if ($serendipity['POST']['isdraft'] == 'true') {
             $data['is_draft'] = true;
             $errors = serendipity_updertEntry($entry);
             if (is_numeric($errors)) {
                 $errors = "";
             }
         } else {
             if ($serendipity['use_iframe']) {
                 $data['is_iframe'] = true;
                 $data['iframe'] = serendipity_iframe_create('save', $entry);
             } else {
                 $data['iframe'] = serendipity_iframe($entry, 'save');
             }
         }
     } else {
         // Only display the preview
         $serendipity['hidefooter'] = true;
         // Advanced templates use this to show update status and elapsed time
Exemple #11
0
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
     $users = array();
     $entries = array();
     if (!extension_loaded('mysql')) {
         return MYSQL_REQUIRED;
     }
     $gdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$gdb) {
         return sprintf(COULDNT_CONNECT, $this->data['host']);
     }
     if (!@mysql_select_db($this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysql_error($gdb));
     }
     /* Users */
     $res = @$this->nativeQuery("SELECT ID_MEMBER       AS ID,\r\n                                    memberName      AS user_login,\r\n                                    passwd AS user_pass,\r\n                                    emailAddress    AS user_email,\r\n                                    ID_GROUP AS user_level\r\n                               FROM {$this->data['prefix']}members\r\n                              WHERE is_activated = 1", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($gdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysql_fetch_assoc($res);
         $data = array('right_publish' => 1, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'userlevel' => $users[$x]['user_level'] == 1 ? USERLEVEL_ADMIN : USERLEVEL_EDITO, 'password' => $users[$x]['user_pass']);
         // MD5 compatible
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         echo mysql_error();
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     $res = @$this->nativeQuery("SELECT ID_CAT AS cat_ID,\r\n                                    name AS cat_name\r\n                               FROM {$this->data['prefix']}categories", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($gdb));
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $parent_categories[] = mysql_fetch_assoc($res);
     }
     for ($x = 0, $max_x = sizeof($parent_categories); $x < $max_x; $x++) {
         $cat = array('category_name' => $parent_categories[$x]['cat_name'], 'category_description' => '', 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $parent_categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
     }
     /* Categories */
     $res = @$this->nativeQuery("SELECT ID_BOARD AS cat_ID,\r\n                                    ID_CAT   AS parent_cat_id,\r\n                                    name AS cat_name,\r\n                                    description AS category_description\r\n                               FROM {$this->data['prefix']}boards ORDER BY boardOrder;", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($gdb));
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $categories[] = mysql_fetch_assoc($res);
     }
     // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
     for ($x = 0, $max_x = sizeof($categories); $x < $max_x; $x++) {
         $pcatid = 0;
         foreach ($parent_categories as $pcat) {
             if ($pcat['cat_ID'] == $categories[$x]['parent_cat_id']) {
                 $pcatid = $pcat['cat_ID'];
                 break;
             }
         }
         $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => $pcatid, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @$this->nativeQuery("SELECT\r\n\r\n        tm.subject AS post_subject,\r\n        t.ID_MEMBER_STARTED AS topic_poster,\r\n        t.ID_BOARD AS forum_id,\r\n        tm.posterTime AS post_time,\r\n        tm.body AS post_text,\r\n        t.ID_TOPIC AS topic_id,\r\n        t.ID_FIRST_MSG AS post_id,\r\n        t.numReplies AS ccount\r\n\r\n        FROM {$this->data['prefix']}topics AS t\r\n        JOIN {$this->data['prefix']}messages AS tm\r\n          ON tm.ID_MSG = t.ID_FIRST_MSG\r\n\r\n        GROUP BY t.ID_TOPIC", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($gdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysql_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['post_subject']), 'isdraft' => 'false', 'allow_comments' => 'true', 'timestamp' => $entries[$x]['post_time'], 'body' => $this->strtr($entries[$x]['post_text']), 'extended' => '');
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['topic_poster']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['user_login'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
         /* Entry/category */
         foreach ($categories as $category) {
             if ($category['cat_ID'] == $entries[$x]['forum_id']) {
                 $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']);
                 serendipity_db_insert('entrycat', $this->strtrRecursive($data));
                 break;
             }
         }
         $topic_id = $entries[$x]['topic_id'];
         // Store original ID, we might need it at some point.
         serendipity_db_insert('entryproperties', array('entryid' => $entries[$x]['entryid'], 'property' => 'foreign_import_id', 'value' => $entries[$x]['topic_id']));
         // Convert SMF tags
         $t_res = @$this->nativeQuery("SELECT t.tag\r\n                                            FROM {$this->data['prefix']}tags_log AS tl\r\n                                            JOIN {$this->data['prefix']}tags AS t\r\n                                              ON tl.ID_TAG = t.ID_TAG\r\n                                           WHERE tl.ID_TOPIC = {$topic_id}\r\n                                             AND t.approved = 1");
         if (mysql_num_rows($t_res) > 0) {
             while ($a = mysql_fetch_assoc($t_res)) {
                 serendipity_db_insert('entrytags', array('entryid' => $entries[$x]['entryid'], 'tag' => $t_res['tag']));
             }
         }
         /* Comments */
         $c_res = @$this->nativeQuery("SELECT\r\n                tm.subject AS post_subject,\r\n                tm.body AS post_text,\r\n                tm.ID_MSG AS post_id,\r\n                tm.posterTime AS post_time,\r\n                tm.ID_BOARD AS forum_id,\r\n                tm.posterName AS poster_name,\r\n                tm.posterEmail AS poster_email\r\n\r\n                FROM {$this->data['prefix']}topics AS t\r\n                JOIN {$this->data['prefix']}messages AS tm\r\n                  ON tm.ID_TOPIC = t.ID_TOPIC\r\n               WHERE t.ID_TOPIC = {$topic_id}\r\n            ", $gdb);
         if (!$c_res) {
             return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($gdb));
         }
         while ($a = mysql_fetch_assoc($c_res)) {
             if ($a['post_id'] == $entries[$x]['post_id']) {
                 continue;
             }
             $author = $a['poster_name'];
             $mail = $a['poster_email'];
             $url = '';
             foreach ($users as $user) {
                 if ($user['ID'] == $a['poster_id']) {
                     $author = $user['user_login'];
                     $mail = $user['user_email'];
                     $url = $user['user_url'];
                     break;
                 }
             }
             $a['post_text'] = html_entity_decode($a['post_text']);
             $comment = array('entry_id ' => $entries[$x]['entryid'], 'parent_id' => 0, 'timestamp' => $a['post_time'], 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => '', 'status' => 'approved', 'body' => $a['post_text'], 'subscribed' => 'false', 'type' => 'NORMAL');
             serendipity_db_insert('comments', $this->strtrRecursive($comment));
             $cid = serendipity_db_insert_id('comments', 'id');
             serendipity_approveComment($cid, $entries[$x]['entryid'], true);
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
    /**
     * Backend Administration Method (7): Rebuild entry auto-keyword tags
     *
     * @see     displayManageTags() case 7
     */
    function displayTagUpdate()
    {
        global $serendipity;
        $limit = 25;
        $page = isset($serendipity['GET']['page']) ? $serendipity['GET']['page'] : 1;
        $from = ($page - 1) * $limit;
        $to = $page * $limit;
        if ($serendipity['version'][0] > 1) {
            echo '<h3>';
        }
        printf(PLUGIN_EVENT_FREETAG_REBUILD_FETCHNO, $from, $to);
        $entries = serendipity_fetchEntries(null, true, $limit, false, false, 'timestamp DESC', '', true);
        $total = serendipity_getTotalEntries();
        if ($serendipity['version'][0] < 2) {
            printf(PLUGIN_EVENT_FREETAG_REBUILD_TOTAL . '<br />', $total);
        } else {
            printf(PLUGIN_EVENT_FREETAG_REBUILD_TOTAL, $total);
            echo '</h3>';
        }
        if (is_array($entries)) {
            if ($serendipity['version'][0] > 1) {
                echo '<ul class="plainList">' . "\n";
            }
            foreach ($entries as $entry) {
                unset($entry['orderkey']);
                unset($entry['loginname']);
                unset($entry['email']);
                if ($serendipity['version'][0] < 2) {
                    printf('%d - "%s"<br />', $entry['id'], self::specialchars_mapper($entry['title']));
                } else {
                    printf('    <li>%d - "%s"', $entry['id'], self::specialchars_mapper($entry['title']));
                }
                $serendipity['POST']['properties']['fake'] = 'fake';
                $current_cat = $entry['categories'];
                $entry['categories'] = array();
                foreach ($current_cat as $categoryidx => $category_data) {
                    $entry['categories'][$category_data['categoryid']] = $category_data['categoryid'];
                }
                $up = serendipity_updertEntry($entry);
                if (is_string($up)) {
                    echo "<div>{$up}</div>\n";
                }
                if ($serendipity['version'][0] < 2) {
                    echo DONE . "<br />\n";
                } else {
                    echo ' ... ' . DONE . "</li>\n";
                }
            }
            if ($serendipity['version'][0] > 1) {
                echo "</ul>\n";
            }
        }
        if ($serendipity['version'][0] < 2) {
            echo '<br />';
        }
        if ($to < $total) {
            ?>

            <script type="text/javascript">
                if (confirm("<?php 
            echo htmlspecialchars(PLUGIN_EVENT_FREETAG_REBUILD_FETCHNEXT, ENT_COMPAT, LANG_CHARSET);
            ?>
")) {
                    location.href = "?serendipity[adminModule]=event_display&serendipity[adminAction]=managetags&serendipity[tagview]=tagupdate&serendipity[page]=<?php 
            echo (int) ($page + 1);
            ?>
";
                } else {
                    alert("<?php 
            echo DONE;
            ?>
");
                }
            </script>

<?php 
        } else {
            if ($serendipity['version'][0] < 2) {
                echo '<div class="serendipity_msg_notice">' . DONE . '</div>';
            } else {
                echo '<span class="msg_notice"><span class="icon-info-circled"></span>' . DONE . "</span>\n";
            }
        }
    }
Exemple #13
0
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $users = array();
     $entries = array();
     if (!extension_loaded('mysql')) {
         return MYSQL_REQUIRED;
     }
     $nukedb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$nukedb) {
         return sprintf(COULDNT_CONNECT, $this->data['host']);
     }
     if (!@mysql_select_db($this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysql_error($nukedb));
     }
     /* Users: Authors */
     $res = @$this->nativeQuery("SELECT\n                                            aid         AS user_login,\n                                            `pwd`       AS user_pass,\n                                            email       AS user_email,\n                                            name        AS user_name,\n                                            radminsuper AS user_level,\n                                            aid         AS ID\n                                       FROM nuke_authors", $nukedb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($nukedb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysql_fetch_assoc($res);
         $data = array('right_publish' => true, 'realname' => $users[$x]['user_name'], 'username' => $users[$x]['user_login'], 'userlevel' => $users[$x]['user_level'] > 0 ? USERLEVEL_ADMIN : USERLEVEL_EDITOR, 'email' => $users[$x]['user_email'], 'password' => md5($users[$x]['user_pass']));
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Users: Users */
     $res = @$this->nativeQuery("SELECT\n                                            u.uname      AS user_login,\n                                            u.pass       AS user_pass,\n                                            u.email      AS user_email,\n                                            u.name       AS user_name,\n                                            s.user_level AS user_level,\n                                            uname        AS ID\n                                       FROM nuke_users AS u\n                                       JOIN nuke_users_status AS s\n                                         ON u.uid = s.user_id\n                                       ", $nukedb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($nukedb));
     }
     for ($x = $x, $max_x = $x + mysql_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysql_fetch_assoc($res);
         if (empty($users[$x]['user_name'])) {
             $users[$x]['user_name'] = $users[$x]['user_login'];
         }
         $data = array('right_publish' => true, 'realname' => $users[$x]['user_name'], 'username' => $users[$x]['user_login'], 'userlevel' => $users[$x]['user_level'] > 1 ? USERLEVEL_ADMIN : USERLEVEL_EDITOR, 'email' => $users[$x]['user_email'], 'password' => md5($users[$x]['user_pass']));
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     if (!$this->importCategories($nukedb)) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($nukedb));
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @$this->nativeQuery("SELECT\n                                           sid                    AS ID,\n                                           UNIX_TIMESTAMP(`time`) AS tstamp,\n                                           aid                    AS post_author,\n                                           informant              AS informant,\n                                           \n                                           title                  AS post_title,\n                                           hometext               AS post_content,\n                                           bodytext               AS extended\n                                      FROM nuke_stories", $nukedb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($nukedb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysql_fetch_assoc($res);
         if (!empty($entries[$x]['informant'])) {
             $entries[$x]['post_author'] = $entries[$x]['informant'];
         }
         $entry = array('title' => $this->decode($entries[$x]['post_title']), 'isdraft' => 'false', 'allow_comments' => 'true', 'timestamp' => $entries[$x]['tstamp'], 'body' => $this->strtr($entries[$x]['post_content']), 'extended' => $this->strtr($entries[$x]['extended']));
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['post_author']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['user_login'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
     }
     /* Even more category stuff */
     $res = @$this->nativeQuery("SELECT sid AS postcat_post_ID,\n                                           topic AS postcat_cat_ID\n                                      FROM nuke_stories", $nukedb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($nukedb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entrycat = mysql_fetch_assoc($res);
         $entryid = 0;
         $categoryid = 0;
         foreach ($entries as $entry) {
             if ($entry['ID'] == $entrycat['postcat_post_ID']) {
                 $entryid = $entry['entryid'];
                 break;
             }
         }
         foreach ($this->categories as $category) {
             if ($category['cat_ID'] == $entrycat['postcat_cat_ID']) {
                 $categoryid = $category['categoryid'];
             }
         }
         if ($entryid > 0 && $categoryid > 0) {
             $data = array('entryid' => $entryid, 'categoryid' => $categoryid);
             serendipity_db_insert('entrycat', $this->strtrRecursive($data));
         }
     }
     /* Comments */
     $res = @$this->nativeQuery("SELECT sid AS comment_post_ID,\n                                           subject AS title,\n                                           comment AS comment_content,\n                                           email AS comment_author_email,\n                                           url AS comment_author_url,\n                                           name AS comment_author,\n                                           UNIX_TIMESTAMP(`date`) AS tstamp\n                                      FROM nuke_comments", $nukedb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($nukedb));
     }
     while ($a = mysql_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['ID'] == $a['comment_post_ID']) {
                 $author = $a['comment_author'];
                 $mail = $a['comment_author_email'];
                 $url = $a['comment_author_url'];
                 $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['tstamp'], 'author' => $author, 'email' => $mail, 'url' => $url, 'title' => $a['title'], 'ip' => '', 'status' => 'approved', 'body' => $a['comment_content'], 'subscribed' => 'false', 'type' => 'NORMAL');
                 serendipity_db_insert('comments', $this->strtrRecursive($comment));
                 $cid = serendipity_db_insert_id('comments', 'id');
                 serendipity_approveComment($cid, $entry['entryid'], true);
             }
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
 function import()
 {
     global $serendipity;
     if (serendipity_db_bool($this->data['wpxrss'])) {
         return $this->import_wpxrss();
     }
     $c = new Onyx_RSS($this->data['charset']);
     $c->parse($this->data['url']);
     $this->data['encoding'] = $c->rss['encoding'];
     $serendipity['noautodiscovery'] = 1;
     while ($item = $c->getNextItem()) {
         $entry = array();
         if ($this->buildEntry($item, $entry)) {
             serendipity_updertEntry($entry);
         }
     }
     return true;
 }
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
     $users = array();
     $entries = array();
     if (!extension_loaded('mysql')) {
         return MYSQL_REQUIRED;
     }
     $txpdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$txpdb) {
         return sprintf(COULDNT_CONNECT, $this->data['host']);
     }
     if (!@mysql_select_db($this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysql_error($txpdb));
     }
     /* Users */
     $res = @$this->nativeQuery("SELECT user_id    AS ID,\n                                    name       AS user_login,\n                                    `pass`     AS user_pass,\n                                    email      AS user_email,\n                                    privs      AS user_level\n                               FROM {$this->data['prefix']}txp_users", $txpdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($txpdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysql_fetch_assoc($res);
         $data = array('right_publish' => $users[$x]['user_level'] <= 4 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'password' => md5('txp'));
         // blame TXP for using PASSWORD().
         if ($users[$x]['user_level'] == 1) {
             $data['userlevel'] = USERLEVEL_EDITOR;
         } elseif ($users[$x]['user_level'] == 2) {
             $data['userlevel'] = USERLEVEL_CHIEF;
         } else {
             $data['userlevel'] = USERLEVEL_ADMIN;
         }
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     if (!$this->importCategories('root', 0, $txpdb)) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($txpdb));
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     // Notice: Textpattern doesn't honor the prefix for this table. Wicked system.
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}textpattern ORDER BY Posted;", $txpdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($txpdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysql_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['Title']), 'isdraft' => $entries[$x]['Status'] == '4' ? 'false' : 'true', 'allow_comments' => $entries[$x]['Annotate'] == '1' ? 'true' : 'false', 'timestamp' => strtotime($entries[$x]['Posted']), 'extended' => $this->strtr($entries[$x]['Body_html']), 'body' => $this->strtr($entries[$x]['Excerpt']));
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['user_login'] == $entries[$x]['AuthorID']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['user_login'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
         /* Entry/category */
         foreach ($this->categories as $category) {
             if ($category['name'] == $entries[$x]['Category1'] || $category['name'] == $entries[$x]['Category2']) {
                 $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']);
                 serendipity_db_insert('entrycat', $this->strtrRecursive($data));
                 break;
             }
         }
     }
     /* Comments */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}txp_discuss;", $txpdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($txpdb));
     }
     while ($a = mysql_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['ID'] == $a['parentid']) {
                 $author = $a['name'];
                 $mail = $a['email'];
                 $url = $a['web'];
                 $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['posted']), 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => $a['ip'], 'status' => $a['visible'] == '1' ? 'approved' : 'pending', 'body' => $a['message'], 'subscribed' => 'false', 'type' => 'NORMAL');
                 serendipity_db_insert('comments', $this->strtrRecursive($comment));
                 if ($a['visible'] == '1') {
                     $cid = serendipity_db_insert_id('comments', 'id');
                     serendipity_approveComment($cid, $entry['entryid'], true);
                 }
             }
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
Exemple #16
0
 function import()
 {
     global $serendipity;
     $max_import = 9999;
     $serendipity['noautodiscovery'] = true;
     if (!is_dir($this->data['pivot_path']) || !is_readable($this->data['pivot_path'])) {
         $check_dir = $serendipity['serendipityPath'] . $this->data['pivot_path'];
         if (!is_dir($check_dir) || !is_readable($check_dir)) {
             return sprintf(ERROR_NO_DIRECTORY, serendipity_specialchars($this->data['pivot_path']));
         }
         $this->data['pivot_path'] = $check_dir;
     }
     printf('<span class="block_level">' . CHECKING_DIRECTORY . ': ', $this->data['pivot_path']) . '</span>';
     if ($root = opendir($this->data['pivot_path'])) {
         // Fetch category data:
         $s9y_categories = serendipity_fetchCategories('all');
         $categories = $this->unserialize($this->data['pivot_path'] . '/ser-cats.php');
         $pivot_to_s9y = array('categories' => array());
         echo '<ul>';
         foreach ($categories as $pivot_category_id => $category) {
             $found = false;
             $pivot_category = trim(stripslashes($category[0]));
             foreach ($s9y_categories as $idx => $item) {
                 if ($pivot_category == $item['category_name']) {
                     $found = $item['categoryid'];
                     break;
                 }
             }
             if ($found) {
                 echo '<li>Pivot Category "' . serendipity_specialchars($pivot_category) . '" mapped to Serendipity ID ' . $found . '</li>';
                 $pivot_to_s9y['categories'][$pivot_category] = $found;
             } else {
                 echo '<li>Created Pivot Category "' . serendipity_specialchars($pivot_category) . '".</li>';
                 $cat = array('category_name' => $pivot_category, 'category_description' => '', 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
                 serendipity_db_insert('category', $cat);
                 $pivot_to_s9y['categories'][$pivot_category] = serendipity_db_insert_id('category', 'categoryid');
             }
         }
         $i = 0;
         while (false !== ($dir = readdir($root))) {
             if ($dir[0] == '.') {
                 continue;
             }
             if (substr($dir, 0, 8) == 'standard') {
                 printf('<li>' . CHECKING_DIRECTORY . '...</li>', $dir);
                 $data = $this->unserialize($this->data['pivot_path'] . '/' . $dir . '/index-' . $dir . '.php');
                 if (empty($data) || !is_array($data) || count($data) < 1) {
                     echo '<li><span class="msg_error">FATAL: File <em>' . $dir . '/index-' . $dir . '.php</em> has no data!</span></li>';
                     flush();
                     ob_flush();
                     continue;
                 }
                 foreach ($data as $entry) {
                     $entryid = str_pad($entry['code'], 5, '0', STR_PAD_LEFT);
                     if ($i >= $max_import) {
                         echo '<li>Skipping entry data for #' . $entryid . '</li>';
                         continue;
                     }
                     echo '<li>Fetching entry data for #' . $entryid . '</li>';
                     $entrydata = $this->unserialize($this->data['pivot_path'] . '/' . $dir . '/' . $entryid . '.php');
                     if (empty($entrydata) || !is_array($entrydata) || count($entrydata) < 1) {
                         echo '<li><span class="msg_error">FATAL: File <em>' . $dir . '/' . $entryid . '.php</em> has no data!</span></li>';
                         flush();
                         ob_flush();
                         continue;
                     }
                     $entry = array();
                     $entry['title'] = trim(stripslashes($entrydata['title']));
                     $entry['categories'] = array();
                     if (is_array($entrydata['category'])) {
                         foreach ($entrydata['category'] as $pivot_category) {
                             $entry['categories'][] = $pivot_to_s9y['categories'][$pivot_category];
                         }
                     }
                     $entry['timestamp'] = $this->toTimestamp($entrydata['date']);
                     $entry['last_modified'] = !empty($entrydata['edit_date']) ? $this->toTimestamp($entrydata['edit_date']) : $entry['timestamp'];
                     $entry['isdraft'] = $entrydata['status'] == 'publish' ? 'false' : 'true';
                     $entry['body'] = stripslashes($entrydata['introduction']);
                     $entry['extended'] = stripslashes($entrydata['body']);
                     $entry['title'] = stripslashes($entrydata['title']);
                     $entry['authorid'] = $serendipity['authorid'];
                     $entry['author'] = $serendipity['serendipityUser'];
                     $entry['allow_comments'] = $entrydata['allow_comments'] ? 'true' : 'false';
                     $entry['moderate_comments'] = 'false';
                     $entry['exflag'] = !empty($entry['extended']) ? 1 : 0;
                     $entry['trackbacks'] = 0;
                     $entry['comments'] = isset($entrydata['comments']) ? count($entrydata['comments']) : 0;
                     serendipity_updertEntry($entry);
                     $i++;
                     if (isset($entrydata['comments']) && count($entrydata['comments']) > 0) {
                         foreach ($entrydata['comments'] as $comment) {
                             $comment = array('entry_id ' => $entry['id'], 'parent_id' => 0, 'timestamp' => $this->toTimestamp($comment['date']), 'author' => stripslashes($comment['name']), 'email' => stripslashes($comment['email']), 'url' => stripslashes($comment['url']), 'ip' => stripslashes($comment['ip']), 'status' => 'approved', 'body' => stripslashes($comment['comment']), 'subscribed' => $comment['notify'] ? 'true' : 'false', 'type' => 'NORMAL');
                             serendipity_db_insert('comments', $comment);
                         }
                     }
                     echo '<li><span class="msg_success">Entry #' . $entryid . ' imported</span></li>';
                     flush();
                     ob_flush();
                 }
             }
         }
         echo '</ul>';
     } else {
         return sprintf(ERROR_NO_DIRECTORY, serendipity_specialchars($this->data['pivot_path']));
     }
     return true;
 }
Exemple #17
0
 function import()
 {
     global $serendipity;
     static $debug = true;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
     $users = array();
     $categories = array();
     $entries = array();
     if (!extension_loaded('mysqli')) {
         return MYSQL_REQUIRED;
     }
     if (function_exists('set_time_limit')) {
         @set_time_limit(300);
     }
     $wpdb = @mysqli_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$wpdb || mysqli_connect_error()) {
         return sprintf(COULDNT_CONNECT, serendipity_specialchars($this->data['host']));
     }
     if (!@mysqli_select_db($wpdb, $this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysqli_error($wpdb));
     }
     // This will hold the s9y <-> WP ID associations.
     $assoc = array();
     /* Users */
     // Fields: ID, user_login, user_pass, user_email, user_level
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}users;", $wpdb);
     if (!$res) {
         printf(COULDNT_SELECT_USER_INFO, mysqli_error($wpdb));
     } else {
         if ($debug) {
             echo "<span class='block_level'>Importing users...</span>";
         }
         for ($x = 0, $c = mysqli_num_rows($res); $x < $c; $x++) {
             $users[$x] = mysqli_fetch_assoc($res);
             $data = array('right_publish' => !isset($users[$x]['user_level']) || $users[$x]['user_level'] >= 1 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'password' => $users[$x]['user_pass']);
             // WP uses md5, too.
             if (isset($users[$x]['user_level']) && $users[$x]['user_level'] <= 1) {
                 $data['userlevel'] = USERLEVEL_EDITOR;
             } elseif (isset($users[$x]['user_level']) && $users[$x]['user_level'] < 5) {
                 $data['userlevel'] = USERLEVEL_CHIEF;
             } else {
                 $data['userlevel'] = USERLEVEL_ADMIN;
             }
             if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
                 $data['userlevel'] = $serendipity['serendipityUserlevel'];
             }
             serendipity_db_insert('authors', $this->strtrRecursive($data));
             $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
             // Set association.
             $assoc['users'][$users[$x]['ID']] = $users[$x]['authorid'];
         }
         if ($debug) {
             echo "<span class='msg_success'>Imported users.</span>";
         }
         // Clean memory
         unset($users);
     }
     $no_cat = false;
     /* Categories (WP < 2.3 style) */
     $res = @$this->nativeQuery("SELECT cat_ID, cat_name, category_description, category_parent \n                                      FROM {$this->data['prefix']}categories \n                                  ORDER BY category_parent, cat_ID;", $wpdb);
     if (!$res) {
         $no_cat = mysqli_error($wpdb);
     } else {
         if ($debug) {
             echo "<span class='block_level'>Importing categories (WP 2.2 style)...</span>";
         }
         // Get all the info we need
         for ($x = 0; $x < mysqli_num_rows($res); $x++) {
             $categories[] = mysqli_fetch_assoc($res);
         }
         // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
         for ($x = 0, $c = sizeof($categories); $x < $c; $x++) {
             $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
             serendipity_db_insert('category', $this->strtrRecursive($cat));
             $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
             // Set association.
             $assoc['categories'][$categories[$x]['cat_ID']] = $categories[$x]['categoryid'];
         }
         foreach ($categories as $cat) {
             if ($cat['category_parent'] != 0) {
                 // Find the parent
                 $par_id = 0;
                 foreach ($categories as $possible_par) {
                     if ($possible_par['cat_ID'] == $cat['category_parent']) {
                         $par_id = $possible_par['categoryid'];
                         break;
                     }
                 }
                 if ($par_id != 0) {
                     serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category \n                                                 SET parentid={$par_id} \n                                               WHERE categoryid={$cat['categoryid']};");
                 }
             }
         }
         // Clean memory
         unset($categories);
         if ($debug) {
             echo "<span class='block_level'>Imported categories.</span>";
         }
         if ($debug) {
             echo "<span class='block_level'>Rebuilding category tree...</span>";
         }
         serendipity_rebuildCategoryTree();
         if ($debug) {
             echo "<span class='block_level'>Rebuilt category tree.</span>";
         }
     }
     /* Categories (WP >= 2.3 style) */
     $res = @$this->nativeQuery("SELECT taxonomy.description      AS category_description, \n                                           taxonomy.parent           AS category_parent, \n                                           taxonomy.term_taxonomy_id AS cat_ID, \n                                           terms.name                AS cat_name\n\n                                      FROM {$this->data['prefix']}term_taxonomy AS taxonomy\n\n                                      JOIN {$this->data['prefix']}terms AS terms\n                                        ON taxonomy.term_id = terms.term_id\n\n                                     WHERE taxonomy.taxonomy = 'category' \n                                  ORDER BY taxonomy.parent, taxonomy.term_taxonomy_id", $wpdb);
     if (!$res && !$no_cat) {
         $no_cat = mysqli_error($wpdb);
     } elseif ($res) {
         $no_cat = false;
         if ($debug) {
             echo "<span class='block_level'>Importing categories (WP 2.3 style)...</span>";
         }
         // Get all the info we need
         for ($x = 0; $x < mysqli_num_rows($res); $x++) {
             $categories[] = mysqli_fetch_assoc($res);
         }
         // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
         for ($x = 0, $c = sizeof($categories); $x < $c; $x++) {
             $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
             serendipity_db_insert('category', $this->strtrRecursive($cat));
             $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
             // Set association.
             $assoc['categories'][$categories[$x]['cat_ID']] = $categories[$x]['categoryid'];
         }
         foreach ($categories as $cat) {
             if ($cat['category_parent'] != 0) {
                 // Find the parent
                 $par_id = 0;
                 foreach ($categories as $possible_par) {
                     if ($possible_par['cat_ID'] == $cat['category_parent']) {
                         $par_id = $possible_par['categoryid'];
                         break;
                     }
                 }
                 if ($par_id != 0) {
                     serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category \n                                                 SET parentid={$par_id} \n                                               WHERE categoryid={$cat['categoryid']};");
                 }
             }
         }
         // Clean memory
         unset($categories);
         if ($debug) {
             echo "<span class='block_level'>Imported categories.</span>";
         }
         if ($debug) {
             echo "<span class='block_level'>Rebuilding category tree...</span>";
         }
         serendipity_rebuildCategoryTree();
         if ($debug) {
             echo "<span class='block_level'>Rebuilt category tree.</span>";
         }
     }
     if ($no_cat) {
         printf(COULDNT_SELECT_CATEGORY_INFO, $no_cat);
     }
     /* Entries */
     if (serendipity_db_bool($this->data['import_all'])) {
         $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts WHERE post_status IN ('publish', 'draft') ORDER BY post_date;", $wpdb);
     } else {
         $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts ORDER BY post_date;", $wpdb);
     }
     if (!$res) {
         printf(COULDNT_SELECT_ENTRY_INFO, mysqli_error($wpdb));
     } else {
         if ($debug) {
             echo "<span class='block_level'>Importing entries...</span>";
         }
         for ($x = 0, $c = mysqli_num_rows($res); $x < $c; $x++) {
             $entries[$x] = mysqli_fetch_assoc($res);
             $content = explode('<!--more-->', $entries[$x]['post_content'], 2);
             $body = $content[0];
             $extended = $content[1];
             $entry = array('title' => $this->decode($entries[$x]['post_title']), 'isdraft' => $entries[$x]['post_status'] == 'publish' ? 'false' : 'true', 'allow_comments' => $entries[$x]['comment_status'] == 'open' ? 'true' : 'false', 'timestamp' => strtotime($entries[$x]['post_date']), 'body' => $this->strtr($body), 'extended' => $this->strtr($extended), 'authorid' => $assoc['users'][$entries[$x]['post_author']]);
             if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
                 printf(COULDNT_SELECT_ENTRY_INFO, mysqli_error($wpdb));
                 echo "<span class='block_level'>ID: {$entries[$x]['ID']} - {$entry['title']}</span>";
                 return $entries[$x]['entryid'];
             }
             $assoc['entries'][$entries[$x]['ID']] = $entries[$x]['entryid'];
         }
         if ($debug) {
             echo "<span class='msg_success'>Imported entries...</span>";
         }
         // Clean memory
         unset($entries);
     }
     /* Entry/category (WP < 2.3 style)*/
     $no_entrycat = false;
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}post2cat;", $wpdb);
     if (!$res) {
         $no_entrycat = mysqli_error($wpdb);
     } else {
         if ($debug) {
             echo "<span class='block_level'>Importing category associations (WP 2.2 style)...</span>";
         }
         while ($a = mysqli_fetch_assoc($res)) {
             $data = array('entryid' => $assoc['entries'][$a['post_id']], 'categoryid' => $assoc['categories'][$a['category_id']]);
             serendipity_db_insert('entrycat', $this->strtrRecursive($data));
         }
         if ($debug) {
             echo "<span class='msg_success'>Imported category associations.</span>";
         }
     }
     /* Entry/category (WP > 2.3 style)*/
     $res = @$this->nativeQuery("SELECT rel.object_id        AS post_id, \n                                           rel.term_taxonomy_id AS category_id \n                                      FROM {$this->data['prefix']}term_relationships AS rel;", $wpdb);
     if (!$res && !$no_entrycat) {
         $no_entrycat = mysqli_error($wpdb);
     } elseif ($res) {
         $no_entrycat = false;
         if ($debug) {
             echo "<span class='block_level'>Importing category associations (WP 2.3 style)...</span>";
         }
         while ($a = mysqli_fetch_assoc($res)) {
             $data = array('entryid' => $assoc['entries'][$a['post_id']], 'categoryid' => $assoc['categories'][$a['category_id']]);
             serendipity_db_insert('entrycat', $this->strtrRecursive($data));
         }
         if ($debug) {
             echo "<span class='msg_success'>Imported category associations.</span>";
         }
     }
     if ($no_entrycat) {
         printf(COULDNT_SELECT_ENTRY_INFO, $no_entrycat);
     }
     /* Comments */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments;", $wpdb);
     if (!$res) {
         printf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($wpdb));
     } else {
         $serendipity['allowSubscriptions'] = false;
         if ($debug) {
             echo "<span class='block_level'>Importing comments...</span>";
         }
         while ($a = mysqli_fetch_assoc($res)) {
             $comment = array('entry_id ' => $assoc['entries'][$a['comment_post_ID']], 'parent_id' => 0, 'timestamp' => strtotime($a['comment_date']), 'author' => $a['comment_author'], 'email' => $a['comment_author_email'], 'url' => $a['comment_author_url'], 'ip' => $a['comment_author_IP'], 'status' => empty($a['comment_approved']) || $a['comment_approved'] == '1' ? 'approved' : 'pending', 'subscribed' => 'false', 'body' => $a['comment_content'], 'type' => 'NORMAL');
             serendipity_db_insert('comments', $this->strtrRecursive($comment));
             if ($comment['status'] == 'approved') {
                 $cid = serendipity_db_insert_id('comments', 'id');
                 serendipity_approveComment($cid, $assoc['entries'][$a['comment_post_ID']], true);
             }
         }
         if ($debug) {
             echo "<span class='msg_success'>Imported comments.</span>";
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
 function import()
 {
     global $serendipity;
     if (empty($this->data['bloggerfile']) || !file_exists($this->data['bloggerfile'])) {
         echo "Path to blogger file empty or path to file wrong! Go back and correct.";
         return false;
     }
     # get default pass from request
     $defaultpass = $this->data['defaultpass'];
     # get blogger uploaded file path from request and load file
     $html = file_get_contents($this->data['bloggerfile']);
     # find posts using pattern matching
     preg_match_all("/STARTPOST(.*)ENDPOST/sU", $html, $posts);
     # iterate through all posts
     foreach ($posts[1] as $post) {
         # locate the post title
         if (preg_match("/TITLE:(.*)/", $post, $title)) {
             $title = trim($title[1]);
             echo "<b>" . htmlspecialchars($title) . "</b><br />";
         } else {
             $title = "";
             echo "<b>Empty title</b><br />";
         }
         # locate the post author
         if (preg_match("/AUTHOR:(.*)/", $post, $author)) {
             $author = trim($author[1]);
             echo "<em>" . htmlspecialchars($author[1]) . "</em><br />";
         } else {
             $author = "";
             echo "<em>Unknown author</em><br />";
         }
         # locate the post date
         if (preg_match("/DATE:(.*)/", $post, $date)) {
             $date = strtotime(trim($date[1]));
             echo "Posted on " . htmlspecialchars($date[1]) . ".<br />";
         } else {
             $date = time();
             echo "Unknown posting time.<br />";
         }
         # locate the post body
         if (preg_match("/BODY:(.*)-----/sU", $post, $body)) {
             $body = trim($body[1]);
             echo strlen($body) . " Bytes of text.<br />";
         } else {
             $body = "";
             echo "<strong>Empty Body!</strong><br />";
         }
         # find all comments for the post using pattern matching
         if (preg_match_all("/COMMENT:(.*)----/sU", $post, $commentlist)) {
             echo count($commentlist[1]) . " comments found.<br />";
         } else {
             $commentlist = array();
             echo "No comments found.<br />";
         }
         $result = serendipity_db_query("SELECT authorid FROM " . $serendipity['dbPrefix'] . "authors WHERE username = '******' LIMIT 1", true, 'assoc');
         if (!is_array($result)) {
             $data = array('right_publish' => 1, 'realname' => $author, 'username' => $author, 'userlevel' => 0, 'password' => md5($defaultpass));
             // MD5 compatible
             serendipity_db_insert('authors', $data);
             $authorid = serendipity_db_insert_id('authors', 'authorid');
         } else {
             $authorid = $result['authorid'];
         }
         $entry = array('title' => $title, 'isdraft' => 'false', 'allow_comments' => 'true', 'timestamp' => $date, 'body' => $body, 'extended' => '', 'author' => $author, 'authorid' => $authorid);
         echo "Entry insert...<br />";
         if (!is_int($id = serendipity_updertEntry($entry))) {
             echo "Inserting entry failed.<br />";
             return $id;
         } else {
             echo "Entry {$id} inserted.<br />";
         }
         # iterate through all comments
         $c = 0;
         foreach ($commentlist[1] as $comment) {
             $c++;
             # locate the author and author url
             $curl = '';
             $cauthor = '';
             $cdate = time();
             $cbody = '';
             if (preg_match("/AUTHOR:(.*)/", $comment, $cauthor) && preg_match("/href=\"(.*)\"/", $cauthor[1], $curl)) {
                 $curl = isset($curl[1]) ? trim($curl[1]) : '';
                 $cauthor = trim(strip_tags($cauthor[1]));
             }
             # locate the date
             if (preg_match("/DATE:(.*)/", $comment, $cdate)) {
                 $cdate = strtotime($cdate[1]);
             }
             # locate the comment body
             if (preg_match("/BODY:(.*)/s", $comment, $cbody)) {
                 $cbody = trim($cbody[1]);
             }
             $icomment = array('entry_id ' => $id, 'parent_id' => 0, 'timestamp' => $cdate, 'author' => $cauthor, 'email' => '', 'url' => $curl, 'ip' => '', 'status' => 'approved', 'body' => $cbody, 'subscribed' => 'false', 'type' => 'NORMAL');
             serendipity_db_insert('comments', $icomment);
         }
         serendipity_db_query("UPDATE " . $serendipity['dbPrefix'] . "entries SET comments = " . $c . " WHERE id = " . $id);
         echo "Comment count set to: " . $c . "<br />";
     }
     echo "Import finished.<br />";
     return true;
 }
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $users = array();
     $entries = array();
     if (!extension_loaded('mysql')) {
         return MYSQL_REQUIRED;
     }
     $b2db = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$b2db) {
         return sprintf(COULDNT_CONNECT, $this->data['host']);
     }
     if (!@mysql_select_db($this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysql_error($b2db));
     }
     /* Users */
     $res = @$this->nativeQuery("SELECT ID         AS ID,\n                                    user_login AS user_login,\n                                    user_pass  AS user_pass,\n                                    user_email AS user_email,\n                                    user_level AS user_level,\n                                    user_url   AS user_url\n                               FROM evo_users", $b2db);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($b2db));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysql_fetch_assoc($res);
         $data = array('right_publish' => $users[$x]['user_level'] >= 2 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'password' => $users[$x]['user_pass']);
         // MD5 compatible
         if ($users[$x]['user_level'] <= 2) {
             $data['userlevel'] = USERLEVEL_EDITOR;
         } elseif ($users[$x]['user_level'] <= 9) {
             $data['userlevel'] = USERLEVEL_CHIEF;
         } else {
             $data['userlevel'] = USERLEVEL_ADMIN;
         }
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     if (!$this->importCategories(null, 0, $b2db)) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($b2db));
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @$this->nativeQuery("SELECT * FROM evo_posts ORDER BY ID;", $b2db);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($b2db));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysql_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['post_title']), 'isdraft' => $entries[$x]['post_status'] == 'published' ? 'false' : 'true', 'allow_comments' => $entries[$x]['post_comments'] == 'open' ? 'true' : 'false', 'timestamp' => strtotime(isset($entries[$x]['post_issue_date']) ? $entries[$x]['post_issue_date'] : $entries[$x]['post_date']), 'body' => $this->strtr($entries[$x]['post_content']));
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['post_author']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['user_login'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
         /* Entry/category */
         foreach ($this->categories as $category) {
             if ($category['cat_ID'] == $entries[$x]['post_category']) {
                 $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']);
                 serendipity_db_insert('entrycat', $this->strtrRecursive($data));
                 break;
             }
         }
     }
     /* Even more category stuff */
     $res = @$this->nativeQuery("SELECT * FROM evo_postcats;", $b2db);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($b2db));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entrycat = mysql_fetch_assoc($res);
         $entryid = 0;
         $categoryid = 0;
         foreach ($entries as $entry) {
             if ($entry['ID'] == $entrycat['postcat_post_ID']) {
                 $entryid = $entry['entryid'];
                 break;
             }
         }
         foreach ($this->categories as $category) {
             if ($category['cat_ID'] == $entrycat['postcat_cat_ID']) {
                 $categoryid = $category['categoryid'];
             }
         }
         if ($entryid > 0 && $categoryid > 0) {
             $data = array('entryid' => $entryid, 'categoryid' => $categoryid);
             serendipity_db_insert('entrycat', $this->strtrRecursive($data));
         }
     }
     /* Comments */
     $res = @$this->nativeQuery("SELECT * FROM evo_comments;", $b2db);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($b2db));
     }
     while ($a = mysql_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['ID'] == $a['comment_post_ID']) {
                 $author = '';
                 $mail = '';
                 $url = '';
                 if (!empty($a['comment_author_ID'])) {
                     foreach ($users as $user) {
                         if ($user['ID'] == $a['comment_author_ID']) {
                             $author = $user['user_login'];
                             $mail = $user['user_email'];
                             $url = $user['user_url'];
                             break;
                         }
                     }
                 }
                 if (empty($author) && empty($mail)) {
                     $author = $a['comment_author'];
                     $mail = $a['comment_author_email'];
                     $url = $a['comment_author_url'];
                 }
                 $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['comment_date']), 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => $a['comment_author_IP'], 'status' => $a['comment_status'] == 'published' ? 'approved' : 'pending', 'body' => $a['comment_content'], 'subscribed' => 'false', 'type' => 'NORMAL');
                 serendipity_db_insert('comments', $this->strtrRecursive($comment));
                 if ($a['comment_status'] == 'published') {
                     $cid = serendipity_db_insert_id('comments', 'id');
                     serendipity_approveComment($cid, $entry['entryid'], true);
                 }
             }
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
/**
 * Prints the content of the iframe.
 *
 * Called by serendipity_is_iframe, when preview is requested. Fetches data from session.
 * An iframe is used so that a single s9y page must not timeout on intensive operations,
 * and so that the frontend stylesheet can be embedded without screwing up the backend.
 *
 * @access private
 * @see serendipity_is_iframe()
 * @param   mixed   The entry array (comes from session variable)
 * @param   string  Indicates whether an entry is previewed or saved. Save performs XML-RPC calls.
 * @param   boolean Use smarty templating?
 * @return  boolean Indicates whether iframe data was printed
 */
function serendipity_iframe(&$entry, $mode = null, $use_smarty = true)
{
    global $serendipity;
    if (empty($mode) || !is_array($entry)) {
        return false;
    }
    if (!serendipity_checkFormToken()) {
        return false;
    }
    if ($use_smarty) {
        $serendipity['smarty_raw_mode'] = true;
        // Force output of Smarty stuff in the backend
        $serendipity['smarty_preview'] = true;
        serendipity_smarty_init();
        $serendipity['smarty']->assign('is_preview', true);
        ob_start();
    }
    $show = false;
    switch ($mode) {
        case 'save':
            echo '<div style="float: left; height: 75px"></div>';
            $res = serendipity_updertEntry($entry);
            if (is_string($res)) {
                echo '<div class="serendipity_msg_error">' . ERROR . ': <b>' . $res . '</b></div>';
            } else {
                if (!empty($serendipity['lastSavedEntry'])) {
                    // Last saved entry must be propagated to entry form so that if the user re-edits it,
                    // it needs to be stored with the new ID.
                    echo '<script type="text/javascript">parent.document.forms[\'serendipityEntry\'][\'serendipity[id]\'].value = "' . $serendipity['lastSavedEntry'] . '";</script>';
                }
                $entrylink = serendipity_archiveURL($res, $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp']));
                echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . ENTRY_SAVED . ' (<a href="' . $entrylink . '" target="_blank">' . VIEW . '</a>)</div>';
            }
            echo '<br style="clear: both" />';
            $show = true;
            break;
        case 'preview':
            echo '<div id="serendipity_preview_spacer" style="float: left; height: 225px"></div>';
            serendipity_printEntries(array($entry), $entry['extended'] != '' ? 1 : 0, true);
            echo '<br id="serendipity_preview_spacer2" style="clear: both" />';
            $show = true;
            break;
    }
    if ($use_smarty) {
        $preview = ob_get_contents();
        ob_end_clean();
        $serendipity['smarty']->assign_by_ref('preview', $preview);
        $serendipity['smarty']->display(serendipity_getTemplateFile('preview_iframe.tpl', 'serendipityPath'));
    }
    return $show;
}
    function event_hook($event, &$bag, &$eventData, $addData = null)
    {
        global $serendipity;
        $hooks =& $bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch ($event) {
                case 'backend_image_addform':
                    if ($serendipity['version'][0] < 2) {
                        if (class_exists('ZipArchive')) {
                            $checkedY = "";
                            $checkedN = "";
                            $this->get_config('unzipping') ? $checkedY = ' checked="checked"' : ($checkedN = ' checked="checked"');
                            ?>
            <br />
            <div>
                <strong><?php 
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES;
                            ?>
</strong><br />
                <?php 
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES_DESC;
                            ?>
                <div>
                    <input type="radio" class="input_radio" id="unzip_yes" name="serendipity[unzip_archives]" value="<?php 
                            echo YES;
                            ?>
"<?php 
                            echo $checkedY;
                            ?>
><label for="unzip_yes"><?php 
                            echo YES;
                            ?>
</label>
                    <input type="radio" class="input_radio" id="unzip_no" name="serendipity[unzip_archives]" value="<?php 
                            echo NO;
                            ?>
"<?php 
                            echo $checkedN;
                            ?>
><label for="unzip_no"><?php 
                            echo NO;
                            ?>
</label>
                </div>
            </div>
<?php 
                        }
                        ?>
            <br />
            <strong><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG;
                        ?>
:</strong><br />
            <em><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG_DESC;
                        ?>
</em>
            <table id="quickblog_table" style="width: 50%">
                <tr>
                    <td nowrap="nowrap"><?php 
                        echo TITLE;
                        ?>
</td>
                    <td><input class="input_textbox" name="serendipity[quickblog][title]" type="text" style="width: 90%" /></td>
                </tr>

                <tr>
                    <td nowrap="nowrap"><?php 
                        echo ENTRY_BODY;
                        ?>
</td>
                    <td><textarea name="serendipity[quickblog][body]" style="width: 90%; height: 200px"></textarea></td>
                </tr>

                <tr>
                    <td nowrap="nowrap"><?php 
                        echo CATEGORY;
                        ?>
</td>
                    <td><select name="serendipity[quickblog][category]">
                        <option value=""><?php 
                        echo NO_CATEGORY;
                        ?>
</option>
                    <?php 
                        if (is_array($cats = serendipity_fetchCategories())) {
                            $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
                            foreach ($cats as $cat) {
                                echo '<option value="' . $cat['categoryid'] . '">' . str_repeat('&nbsp;', $cat['depth']) . $cat['category_name'] . '</option>' . "\n";
                            }
                        }
                        ?>
                    </select></td>
                </tr>

                <tr>
                    <td nowrap="nowrap"><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET;
                        ?>
</td>
                    <td><select id="select_image_target" name="serendipity[quickblog][target]">
                        <option value="none"<?php 
                        echo serendipity_ifRemember('target', 'none', false, 'selected');
                        ?>
><?php 
                        echo NONE;
                        ?>
</option>
                        <option value="js"<?php 
                        echo serendipity_ifRemember('target', 'js', false, 'selected');
                        ?>
><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET_JS;
                        ?>
</option>
                        <option value="plugin"<?php 
                        echo serendipity_ifRemember('target', 'plugin', false, 'selected');
                        ?>
><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET_ENTRY;
                        ?>
</option>
                        <option value="_blank"<?php 
                        echo serendipity_ifRemember('target', '_blank', false, 'selected');
                        ?>
><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET_BLANK;
                        ?>
</option>
                    </select></td>
                </tr>

                <tr>
                    <td nowrap="nowrap"><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_ASOBJECT;
                        ?>
</td>
                    <td>
                        <input type="radio" class="input_radio" id="image_yes" name="serendipity[quickblog][isobject]" value="<?php 
                        echo YES;
                        ?>
"><label for="image_yes"><?php 
                        echo YES;
                        ?>
</label>
                        <input type="radio" class="input_radio" id="image_no" name="serendipity[quickblog][isobject]" value="<?php 
                        echo NO;
                        ?>
" checked="checked"><label for="image_no"><?php 
                        echo NO;
                        ?>
</label>
                    </td>
                </tr>

                <tr>
                    <td nowrap="nowrap"><?php 
                        echo IMAGE_SIZE;
                        ?>
</td>
                    <td><input class="input_textbox" name="serendipity[quickblog][size]" value="<?php 
                        echo $serendipity['thumbSize'];
                        ?>
" type="text" style="width: 50px" /></td>
                </tr>

                <tr>
                    <td align="center" colspan="2"><br /></td>
                </tr>
            </table>
            <div>
                <em><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_IMAGE_SIZE_DESC;
                        ?>
</em>
            </div>
<?php 
                    } else {
                        ?>

        <div id="imageselectorplus">

<?php 
                        if (class_exists('ZipArchive')) {
                            $checkedY = "";
                            $checkedN = "";
                            $this->get_config('unzipping') ? $checkedY = ' checked="checked"' : ($checkedN = ' checked="checked"');
                            ?>
            <div class="clearfix radio_field">
                <h4><?php 
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES;
                            ?>
</h4>
                <?php 
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES_DESC;
                            ?>
                <div>
                    <input type="radio" class="input_radio" id="unzip_yes" name="serendipity[unzip_archives]" value="<?php 
                            echo YES;
                            ?>
"<?php 
                            echo $checkedY;
                            ?>
><label for="unzip_yes"><?php 
                            echo YES;
                            ?>
</label>
                    <input type="radio" class="input_radio" id="unzip_no" name="serendipity[unzip_archives]" value="<?php 
                            echo NO;
                            ?>
"<?php 
                            echo $checkedN;
                            ?>
><label for="unzip_no"><?php 
                            echo NO;
                            ?>
</label>
                </div>
            </div>
<?php 
                        }
                        ?>
            <h4><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG;
                        ?>
:</h4>
            <em><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG_DESC;
                        ?>
</em>
            <div id="quickblog_tablefield" class="clearfix">
                <div class="quickblog_form_field">
                    <label for="quickblog_titel"><?php 
                        echo TITLE;
                        ?>
</label>
                    <input id="quickblog_title" class="input_textbox" name="serendipity[quickblog][title]" type="text">
                </div>

                <div class="quickblog_textarea_field">
                    <label for="nuggets2"><?php 
                        echo ENTRY_BODY;
                        ?>
</label>
                    <textarea id="nuggets2" class="quickblog_nugget" data-tarea="nuggets2" name="serendipity[quickblog][body]" rows="10" cols="80"></textarea>
<?php 
                        if ($serendipity['wysiwyg']) {
                            $plugins = serendipity_plugin_api::enum_plugins('*', false, 'serendipity_event_nl2br');
                            ?>
                    <input name="serendipity[properties][disable_markups][]" type="hidden" value="<?php 
                            echo $plugins[0]['name'];
                            ?>
">
<?php 
                            if (!class_exists('serendipity_event_ckeditor')) {
                                ?>
                    <script src="<?php 
                                echo $serendipity['serendipityHTTPPath'];
                                ?>
htmlarea/ckeditor/ckeditor/ckeditor.js"></script>
<?php 
                            }
                            // just add a simple basic toolbar, since we cannot use embedded plugins here
                            ?>
                    <script>
                        CKEDITOR.replace( 'nuggets2',
                        {
                            toolbar : [['Format'],['Bold','Italic','Underline','Superscript','-','NumberedList','BulletedList','Outdent','Blockquote'],['JustifyBlock','JustifyCenter','JustifyRight'],['Link','Unlink'],['Source']],
                            toolbarGroups: null
                        });
                    </script>
<?php 
                        }
                        ?>
                </div>

                <div class="quickblog_form_field">
                    <label for="quickblog_select"><?php 
                        echo CATEGORY;
                        ?>
</label>
                    <select id="quickblog_select" name="serendipity[quickblog][category]">
                        <option value=""><?php 
                        echo NO_CATEGORY;
                        ?>
</option>
                    <?php 
                        if (is_array($cats = serendipity_fetchCategories())) {
                            $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
                            foreach ($cats as $cat) {
                                echo '<option value="' . $cat['categoryid'] . '">' . str_repeat('&nbsp;', $cat['depth']) . $cat['category_name'] . '</option>' . "\n";
                            }
                        }
                        ?>
                    </select>
                </div>

                <div class="quickblog_form_select">
                    <label for="select_image_target"><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET;
                        ?>
</label>
                    <select id="select_image_target" name="serendipity[quickblog][target]">
                        <option value="none"<?php 
                        echo serendipity_ifRemember('target', 'none', false, 'selected');
                        ?>
><?php 
                        echo NONE;
                        ?>
</option>
                        <option value="js"<?php 
                        echo serendipity_ifRemember('target', 'js', false, 'selected');
                        ?>
><?php 
                        echo MEDIA_TARGET_JS;
                        ?>
</option>
                        <option value="plugin"<?php 
                        echo serendipity_ifRemember('target', 'plugin', false, 'selected');
                        ?>
><?php 
                        echo MEDIA_ENTRY;
                        ?>
</option>
                        <option value="_blank"<?php 
                        echo serendipity_ifRemember('target', '_blank', false, 'selected');
                        ?>
><?php 
                        echo MEDIA_TARGET_BLANK;
                        ?>
</option>
                    </select>
                </div>

                <div class="clearfix radio_field quickblog_radio_field">
                    <label><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_ASOBJECT;
                        ?>
</label>
                    <div>
                        <input type="radio" class="input_radio" id="image_yes" name="serendipity[quickblog][isobject]" value="<?php 
                        echo YES;
                        ?>
"><label for="image_yes"><?php 
                        echo YES;
                        ?>
</label>
                        <input type="radio" class="input_radio" id="image_no" name="serendipity[quickblog][isobject]" value="<?php 
                        echo NO;
                        ?>
" checked="checked"><label for="image_no"><?php 
                        echo NO;
                        ?>
</label>
                    </div>
                </div>

                <div class="quickblog_form_field">
                    <label for="quickblog_isize"><?php 
                        echo IMAGE_SIZE;
                        ?>
</label>
                    <input id="quickblog_isize" class="input_textbox" name="serendipity[quickblog][size]" value="<?php 
                        echo $serendipity['thumbSize'];
                        ?>
" type="text">
                </div>
            </div>
            <em><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_IMAGE_SIZE_DESC;
                        ?>
</em>
        </div>
<?php 
                    }
                    break;
                case 'backend_image_add':
                    global $new_media;
                    // if file is zip archive and unzipping enabled
                    // unzip file and add all images to database
                    // retrieve file type
                    $target_zip = $eventData;
                    preg_match('@(^.*/)+(.*)\\.+(\\w*)@', $target_zip, $matches);
                    $target_dir = $matches[1];
                    $basename = $matches[2];
                    $extension = $matches[3];
                    $authorid = isset($serendipity['POST']['all_authors']) && $serendipity['POST']['all_authors'] == 'true' ? '0' : $serendipity['authorid'];
                    // only if unzipping function exists, we have archive file and unzipping set to yes
                    if (class_exists('ZipArchive') && $extension == 'zip' && $serendipity['POST']['unzip_archives'] == YES) {
                        // now unzip
                        $zip = new ZipArchive();
                        $res = $zip->open($target_zip);
                        if ($res === TRUE) {
                            $files_to_unzip = array();
                            $extracted_images = array();
                            for ($i = 0; $i < $zip->numFiles; $i++) {
                                $file_to_extract = $zip->getNameIndex($i);
                                if (file_exists($target_dir . $file_to_extract)) {
                                    echo '(' . $file_to_extract . ') ' . ERROR_FILE_EXISTS_ALREADY . '<br />';
                                } else {
                                    $files_to_unzip[] = $file_to_extract;
                                    $extracted_images[] = $target_dir . $file_to_extract;
                                }
                            }
                            $zip->extractTo($target_dir, $files_to_unzip);
                            $zip->close();
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_OK;
                        } else {
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FAILED;
                        }
                        // now proceed all unzipped images
                        foreach ($extracted_images as $target) {
                            preg_match('@(^.*/)+(.*)\\.+(\\w*)@', $target, $matches);
                            $real_dir = $matches[1];
                            $basename = $matches[2];
                            $extension = $matches[3];
                            $tfile = $basename . "." . $extension;
                            preg_match('@' . $serendipity['uploadPath'] . '(.*/)@', $target, $matches);
                            $image_directory = $matches[1];
                            // make thumbnails for new images
                            $thumbs = array(array('thumbSize' => $serendipity['thumbSize'], 'thumb' => $serendipity['thumbSuffix']));
                            serendipity_plugin_api::hook_event('backend_media_makethumb', $thumbs);
                            foreach ($thumbs as $thumb) {
                                // Create thumbnail
                                if ($created_thumbnail = serendipity_makeThumbnail($tfile, $image_directory, $thumb['thumbSize'], $thumb['thumb'])) {
                                    echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_IMAGE_FROM_ARCHIVE . " - " . THUMB_CREATED_DONE . '<br />';
                                }
                            }
                            // Insert into database
                            $image_id = serendipity_insertImageInDatabase($tfile, $image_directory, $authorid, null, $realname);
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_IMAGE_FROM_ARCHIVE . " ({$tfile}) " . PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_ADD_TO_DB . "<br />";
                            $new_media[] = array('image_id' => $image_id, 'target' => $target, 'created_thumbnail' => $created_thumbnail);
                        }
                    }
                case 'backend_image_addHotlink':
                    // Re-Scale thumbnails?
                    $max_scale = array('width' => (int) $this->get_config('thumb_max_width'), 'height' => (int) $this->get_config('thumb_max_height'));
                    if ($max_scale['width'] > 0 || $max_scale['height'] > 0) {
                        $this->resizeThumb($max_scale, $eventData);
                    }
                    if (empty($serendipity['POST']['quickblog']['title'])) {
                        break;
                    }
                    $file = basename($eventData);
                    $directory = str_replace($serendipity['serendipityPath'] . $serendipity['uploadPath'], '', dirname($eventData) . '/');
                    $size = (int) $serendipity['POST']['quickblog']['size'];
                    // check default Serendipity thumbSize, to make this happen like standard image uploads, and to get one "fullsize" image instance only,
                    // else create another quickblog image "resized" instance, to use as entries thumbnail image
                    if ($serendipity['thumbSize'] != $size) {
                        $oldSuffix = $serendipity['thumbSuffix'];
                        $serendipity['thumbSuffix'] = 'quickblog';
                        serendipity_makeThumbnail($file, $directory, $size);
                        $serendipity['thumbSuffix'] = $oldSuffix;
                    }
                    // Non-image object link generation
                    if ($serendipity['POST']['quickblog']['isobject'] == YES) {
                        $objfile = serendipity_parseFileName($file);
                        $filename = $objfile[0];
                        $suffix = $objfile[1];
                        $obj_mime = serendipity_guessMime($suffix);
                        $objpath = $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $directory . $filename . '.' . $suffix;
                        // try to know about a working environment for imagemagicks pdf preview generation
                        if ($serendipity['magick'] === true && strtolower($suffix) == 'pdf' && $serendipity['thumbSize'] == $size) {
                            $objpreview = $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $directory . $filename . '.' . $serendipity['thumbSuffix'] . '.' . $suffix . '.png';
                        } else {
                            $objpreview = serendipity_getTemplateFile('admin/img/mime_' . preg_replace('@[^0-9a-z_\\-]@i', '-', $obj_mime) . '.png');
                        }
                        if (!$objpreview || empty($objpreview)) {
                            $objpreview = serendipity_getTemplateFile('admin/img/mime_unknown.png');
                        }
                    }
                    // New draft post
                    $entry = array();
                    $entry['isdraft'] = 'false';
                    $entry['title'] = function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['quickblog']['title']) : htmlspecialchars($serendipity['POST']['quickblog']['title'], ENT_COMPAT, LANG_CHARSET);
                    if (isset($objpath) && !empty($objpath)) {
                        $entry['body'] = '<a href="' . $objpath . '"><img alt="" class="serendipity_image_left serendipity_quickblog_image" src="' . $objpreview . '">' . $filename . '</a> (-' . $obj_mime . '-)<p>' . $serendipity['POST']['quickblog']['body'] . '</p>';
                    } else {
                        $entry['body'] = '<!--quickblog:' . $serendipity['POST']['quickblog']['target'] . '|' . $eventData . '-->' . $serendipity['POST']['quickblog']['body'];
                    }
                    $entry['authorid'] = $serendipity['authorid'];
                    $entry['exflag'] = false;
                    $entry['categories'][0] = function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['quickblog']['category']) : htmlspecialchars($serendipity['POST']['quickblog']['category'], ENT_COMPAT, LANG_CHARSET);
                    #$entry['allow_comments']    = 'true'; // both disabled
                    #$entry['moderate_comments'] = 'false'; // to take default values
                    $serendipity['POST']['properties']['fake'] = 'fake';
                    $id = serendipity_updertEntry($entry);
                    break;
                case 'frontend_display':
                    // auto resizing images based on width and/or height attributes in img tag
                    if (serendipity_db_bool($this->get_config('autoresize'))) {
                        if (!empty($eventData['body'])) {
                            $eventData['body'] = $this->substituteImages($eventData['body']);
                        }
                        if (!empty($eventData['extended'])) {
                            $eventData['extended'] = $this->substituteImages($eventData['extended']);
                        }
                    }
                    if (empty($eventData['body'])) {
                        return;
                    }
                    // displaying quickblog posts
                    if (is_object($serendipity['smarty']) && preg_match('@<!--quickblog:(.+)-->@imsU', $eventData['body'], $filematch)) {
                        $eventData['body'] = $this->parse_quickblog_post($filematch[1], $eventData['body']);
                    }
                    // displaying galleries introduced by markup
                    foreach ($this->markup_elements as $temp) {
                        if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && !$eventData['properties']['ep_disable_markup_' . $this->instance] && !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
                            $element = $temp['element'];
                            $eventData[$element] = $this->media_insert($eventData[$element], $eventData);
                        }
                    }
                    return true;
                    break;
                case 'backend_entry_presave':
                    if (is_numeric($eventData['id'])) {
                        $eventData['body'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $eventData['body']);
                        $eventData['extended'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $eventData['extended']);
                        $this->gotMilk = true;
                    } else {
                        $this->cache['body'] = $eventData['body'];
                        $this->cache['extended'] = $eventData['extended'];
                    }
                    break;
                case 'backend_publish':
                case 'backend_save':
                    if ($this->gotMilk === false) {
                        $old = md5($this->cache['body']) . md5($this->cache['extended']);
                        $this->cache['body'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $this->cache['body']);
                        $this->cache['extended'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $this->cache['extended']);
                        $new = md5($this->cache['body']) . md5($this->cache['extended']);
                        if ($old != $new) {
                            serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries\n                                                     SET body     = '" . serendipity_db_escape_string($this->cache['body']) . "',\n                                                         extended = '" . serendipity_db_escape_string($this->cache['extended']) . "'\n                                                   WHERE       id = " . (int) $eventData['id']);
                        }
                    }
                    break;
                case 'entry_display':
                    if ($this->selected()) {
                        if (is_array($eventData)) {
                            $eventData['clean_page'] = true;
                            // This is important to not display an entry list!
                        } else {
                            $eventData = array('clean_page' => true);
                        }
                    }
                    break;
                case 'entries_header':
                    if (!$this->selected()) {
                        return true;
                    }
                    if ($serendipity['version'][0] > 1) {
                        return true;
                    }
                    if (!headers_sent()) {
                        header('HTTP/1.0 200');
                        header('Status: 200 OK');
                    }
                    $entry = serendipity_fetchEntry('id', $serendipity['GET']['id']);
                    $imageid = $serendipity['GET']['image'];
                    $imgsrc = '';
                    if (preg_match('@<a title="([^"]+)" id="s9yisp' . $imageid . '"></a>@imsU', $entry['body'], $imgmatch)) {
                        $imgsrc = $imgmatch[1];
                    } elseif (preg_match('@<a title="([^"]+)" id="s9yisp' . $imageid . '"></a>@imsU', $entry['extended'], $imgmatch)) {
                        $imgsrc = $imgmatch[1];
                    } else {
                        return;
                    }
                    $link = '<a href="' . serendipity_archiveURL($serendipity['GET']['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])) . '#s9yisp' . $imageid . '">';
                    echo '<div class="serendipity_Entry_Date">
                             <h3 class="serendipity_date">' . serendipity_formatTime(DATE_FORMAT_ENTRY, $entry['timestamp']) . '</h3>';
                    echo '<h4 class="serendipity_title"><a href="#">' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['title']) : htmlspecialchars($entry['title'], ENT_COMPAT, LANG_CHARSET)) . '</a></h4>';
                    echo '<div class="serendipity_entry"><div class="serendipity_entry_body">';
                    echo '<div class="serendipity_center">' . $link . '<!-- s9ymdb:' . $entry['id'] . ' --><img src="' . $imgsrc . '" /></a></div>';
                    echo '<br />';
                    echo $link . '&lt;&lt; ' . BACK . '</a>';
                    echo "</div>\n</div>\n</div>\n";
                    return true;
                    break;
                case 'frontend_image_add_unknown':
                case 'frontend_image_add_filenameonly':
                case 'frontend_image_selector_submit':
                case 'frontend_image_selector_more':
                case 'frontend_image_selector_imagecomment':
                case 'frontend_image_selector_imagealign':
                case 'frontend_image_selector_imagesize':
                case 'frontend_image_selector_hiddenfields':
                case 'frontend_image_selector_imagelink':
                    return true;
                    break;
                case 'css_backend':
                    if ($serendipity['version'][0] > 1) {
                        ?>

#imageselectorplus .radio_field input {
    margin: 0 0.5em;
}
#quickblog_tablefield {
   display: table-cell;
}
#uploadform .quickblog_nugget {
    margin-left: 0;
    padding: 0;
}
#quickblog_tablefield .quickblog_form_field {
    margin: .375em 0;
}
#quickblog_tablefield .quickblog_radio_field div label,
#quickblog_tablefield .radio_field label {
    padding-left: .5em;
}
#quickblog_tablefield .quickblog_form_select {
    margin-top: 0.75em;
    margin-bottom: 0.75em;
}
#quickblog_tablefield .quickblog_radio_field label {
    padding-left: 0;
}
#quickblog_tablefield .quickblog_radio_field div {
    display: inline;
}
#quickblog_tablefield .quickblog_radio_field input {
    margin-left: 0.5em;
}

<?php 
                    }
                    break;
                case 'css':
                    ?>

#content .serendipity_quickblog_image {
    border: medium none transparent;
}
.serendipity_mediainsert_gallery {
    border: 1px solid #C0C0C0;
    margin: 0px;
    overflow: auto;
    padding: 0.4em;
}

<?php 
                    break;
                case 'frontend_image_selector':
                    if ($serendipity['version'][0] < 2) {
                        $eventData['finishJSFunction'] = 'serendipity_imageSelectorPlus_done(\'' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['GET']['textarea']) : htmlspecialchars($serendipity['GET']['textarea'], ENT_COMPAT, LANG_CHARSET)) . '\')';
                    } else {
                        $eventData['finishJSFunction'] = 'serendipity.serendipity_imageSelector_done(\'' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['GET']['textarea']) : htmlspecialchars($serendipity['GET']['textarea'], ENT_COMPAT, LANG_CHARSET)) . '\')';
                    }
                    return true;
                    break;
                default:
                    return false;
            }
        } else {
            return false;
        }
    }
    function displayManageTags($event, &$bag, &$eventData, $addData)
    {
        global $serendipity;
        if ($this->get_config('dbversion', 1) != 2) {
            $this->install();
            $this->set_config('dbversion', 2);
        }
        if ($serendipity['version'][0] < 2) {
            ?>
            <div style="border: 1px solid #000;" class="freetagMenu">
            <ul>
<?php 
        } else {
            ?>
            <h2><?php 
            echo PLUGIN_EVENT_FREETAG_MANAGETAGS;
            ?>
</h2>

            <div class="freetagMenu">
            <ul class="plainList clearfix">
<?php 
        }
        ?>
                <li><a class="button_link" href="<?php 
        echo FREETAG_MANAGE_URL;
        ?>
&amp;serendipity[tagview]=all"><?php 
        echo PLUGIN_EVENT_FREETAG_MANAGE_ALL;
        ?>
</a></li>
                <li><a class="button_link" href="<?php 
        echo FREETAG_MANAGE_URL;
        ?>
&amp;serendipity[tagview]=leaf"><?php 
        echo PLUGIN_EVENT_FREETAG_MANAGE_LEAF;
        ?>
</a></li>
                <li><a class="button_link" href="<?php 
        echo FREETAG_MANAGE_URL;
        ?>
&amp;serendipity[tagview]=entryuntagged"><?php 
        echo PLUGIN_EVENT_FREETAG_MANAGE_UNTAGGED;
        ?>
</a></li>
                <li><a class="button_link" href="<?php 
        echo FREETAG_MANAGE_URL;
        ?>
&amp;serendipity[tagview]=entryleaf"><?php 
        echo PLUGIN_EVENT_FREETAG_MANAGE_LEAFTAGGED;
        ?>
</a></li>
                <li><a class="button_link" href="<?php 
        echo FREETAG_MANAGE_URL;
        ?>
&amp;serendipity[tagview]=keywords"><?php 
        echo PLUGIN_EVENT_FREETAG_KEYWORDS;
        ?>
</a></li>
                <li><a class="button_link" href="<?php 
        echo FREETAG_MANAGE_URL;
        ?>
&amp;serendipity[tagview]=cat2tag"><?php 
        echo PLUGIN_EVENT_FREETAG_GLOBALLINKS;
        ?>
</a></li>
                <li><a class="button_link" href="<?php 
        echo FREETAG_MANAGE_URL;
        ?>
&amp;serendipity[tagview]=tagupdate" onclick="return confirm('<?php 
        echo function_exists('serendipity_specialchars') ? serendipity_specialchars(PLUGIN_EVENT_FREETAG_REBUILD_DESC) : htmlspecialchars(PLUGIN_EVENT_FREETAG_REBUILD_DESC, ENT_COMPAT, LANG_CHARSET);
        ?>
');" ><?php 
        echo PLUGIN_EVENT_FREETAG_REBUILD;
        ?>
</a></li>
                <li><a class="button_link" href="<?php 
        echo FREETAG_MANAGE_URL;
        ?>
&amp;serendipity[tagview]=cleanupmappings"><?php 
        echo PLUGIN_EVENT_FREETAG_MANAGE_CLEANUP;
        ?>
</a></li>
            </ul>
            </div>
        <?php 
        if (isset($this->eventData['GET']['tagaction']) && !empty($this->eventData['GET']['tagaction'])) {
            $this->displayTagAction();
        }
        if (isset($this->eventData['GET']['tagview'])) {
            switch ($this->eventData['GET']['tagview']) {
                case "entryuntagged":
                    $this->displayUntaggedEntries();
                    break;
                case "entryleaf":
                    $this->displayLeafTaggedEntries();
                    break;
                case "all":
                    $tags = (array) $this->getAllTags();
                    $this->displayEditTags($tags);
                    break;
                case "leaf":
                    $tags = $this->getLeafTags();
                    $this->displayEditTags($tags);
                    break;
                case 'keywords':
                    $tags = (array) $this->getAllTags();
                    $this->displayKeywordAssignment($tags);
                    break;
                case 'tagupdate':
                    $per_fetch = 25;
                    $page = isset($serendipity['GET']['page']) ? $serendipity['GET']['page'] : 1;
                    $from = ($page - 1) * $per_fetch;
                    $to = $page * $per_fetch;
                    if ($serendipity['version'][0] > 1) {
                        echo '<h3>';
                    }
                    printf(PLUGIN_EVENT_FREETAG_REBUILD_FETCHNO, $from, $to);
                    $entries = serendipity_fetchEntries(null, true, $per_fetch, false, false, 'timestamp DESC', '', true);
                    $total = serendipity_getTotalEntries();
                    if ($serendipity['version'][0] < 2) {
                        printf(PLUGIN_EVENT_FREETAG_REBUILD_TOTAL . '<br />', $total);
                    } else {
                        printf(PLUGIN_EVENT_FREETAG_REBUILD_TOTAL, $total);
                        echo '</h3>';
                    }
                    if (is_array($entries)) {
                        if ($serendipity['version'][0] > 1) {
                            echo '<ul class="plainList">';
                        }
                        foreach ($entries as $entry) {
                            unset($entry['orderkey']);
                            unset($entry['loginname']);
                            unset($entry['email']);
                            if ($serendipity['version'][0] < 2) {
                                printf('%d - "%s"<br />', $entry['id'], function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['title']) : htmlspecialchars($entry['title'], ENT_COMPAT, LANG_CHARSET));
                            } else {
                                printf('<li>%d - "%s"', $entry['id'], function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['title']) : htmlspecialchars($entry['title'], ENT_COMPAT, LANG_CHARSET));
                            }
                            $serendipity['POST']['properties']['fake'] = 'fake';
                            $current_cat = $entry['categories'];
                            $entry['categories'] = array();
                            foreach ($current_cat as $categoryidx => $category_data) {
                                $entry['categories'][$category_data['categoryid']] = $category_data['categoryid'];
                            }
                            $up = serendipity_updertEntry($entry);
                            if (is_string($up)) {
                                echo "<div>{$up}</div>\n";
                            }
                            if ($serendipity['version'][0] < 2) {
                                echo DONE . "<br />\n";
                            } else {
                                echo ' ... ' . DONE . "</li>\n";
                            }
                        }
                        if ($serendipity['version'][0] > 1) {
                            echo '</ul>';
                        }
                    }
                    if ($serendipity['version'][0] < 2) {
                        echo '<br />';
                    }
                    if ($to < $total) {
                        ?>
                        <script type="text/javascript">
                            if (confirm("<?php 
                        echo function_exists('serendipity_specialchars') ? serendipity_specialchars(PLUGIN_EVENT_FREETAG_REBUILD_FETCHNEXT) : htmlspecialchars(PLUGIN_EVENT_FREETAG_REBUILD_FETCHNEXT, ENT_COMPAT, LANG_CHARSET);
                        ?>
")) {
                                location.href = "?serendipity[adminModule]=event_display&serendipity[adminAction]=managetags&serendipity[tagview]=tagupdate&serendipity[page]=<?php 
                        echo $page + 1;
                        ?>
";
                            } else {
                                alert("<?php 
                        echo function_exists('serendipity_specialchars') ? serendipity_specialchars(DONE) : htmlspecialchars(DONE, ENT_COMPAT, LANG_CHARSET);
                        ?>
");
                            }
                        </script>
                    <?php 
                    } else {
                        if ($serendipity['version'][0] < 2) {
                            echo '<div class="serendipity_msg_notice">' . DONE . '</div>';
                        } else {
                            echo '<span class="msg_notice"><span class="icon-info-circled"></span>' . DONE . '</span>';
                        }
                    }
                    break;
                case 'cat2tag':
                    $e = serendipity_db_query("SELECT e.id, e.title, c.category_name, et.tag\n                                        FROM {$serendipity['dbPrefix']}entries AS e\n                             LEFT OUTER JOIN {$serendipity['dbPrefix']}entrycat AS ec\n                                          ON e.id = ec.entryid\n                             LEFT OUTER JOIN {$serendipity['dbPrefix']}category AS c\n                                          ON ec.categoryid = c.categoryid\n                             LEFT OUTER JOIN {$serendipity['dbPrefix']}entrytags AS et\n                                          ON e.id = et.entryid", false, 'assoc');
                    // Get all categories and tags of all entries
                    $entries = array();
                    foreach ($e as $row) {
                        $entries[$row['id']]['title'] = $row['title'];
                        $entries[$row['id']]['categories'][$row['category_name']] = $row['category_name'];
                        $entries[$row['id']]['tags'][$row['tag']] = $row['tag'];
                    }
                    // Cycle all entries
                    if ($serendipity['version'][0] > 1) {
                        echo '<ul class="plainList">';
                    }
                    foreach ($entries as $id => $props) {
                        $newtags = array();
                        // Fetch all tags that should be added
                        foreach ($props['categories'] as $tag) {
                            if (empty($tag)) {
                                continue;
                            }
                            $newtags[$tag] = $tag;
                        }
                        // Subtract all tags that already exist
                        foreach ($props['tags'] as $tag) {
                            unset($newtags[$tag]);
                        }
                        if (count($newtags) < 1) {
                            continue;
                        }
                        $this->addTagsToEntry($id, $newtags);
                        if ($serendipity['version'][0] < 2) {
                            printf(PLUGIN_EVENT_FREETAG_GLOBALCAT2TAG_ENTRY . '<br />', $id, function_exists('serendipity_specialchars') ? serendipity_specialchars($props['title']) : htmlspecialchars($props['title'], ENT_COMPAT, LANG_CHARSET), function_exists('serendipity_specialchars') ? serendipity_specialchars(implode(', ', $newtags)) : htmlspecialchars(implode(', ', $newtags), ENT_COMPAT, LANG_CHARSET));
                        } else {
                            echo '<li>';
                            printf(PLUGIN_EVENT_FREETAG_GLOBALCAT2TAG_ENTRY, $id, function_exists('serendipity_specialchars') ? serendipity_specialchars($props['title']) : htmlspecialchars($props['title'], ENT_COMPAT, LANG_CHARSET), function_exists('serendipity_specialchars') ? serendipity_specialchars(implode(', ', $newtags)) : htmlspecialchars(implode(', ', $newtags), ENT_COMPAT, LANG_CHARSET));
                            echo '</li>';
                        }
                    }
                    if ($serendipity['version'][0] > 1) {
                        echo '</ul>';
                    }
                    if ($serendipity['version'][0] < 2) {
                        echo PLUGIN_EVENT_FREETAG_GLOBALCAT2TAG . '<br />';
                    } else {
                        echo '<span class="msg_notice"><span class="icon-info-circled"></span>' . PLUGIN_EVENT_FREETAG_GLOBALCAT2TAG . '</span>';
                    }
                    break;
                case 'cleanupmappings':
                    $this->cleanupTagAssignments();
                    break;
                default:
                    if (!empty($this->eventData['GET']['tagview'])) {
                        echo "Can't execute tagview";
                    }
                    break;
            }
        }
        return true;
    }
<?php

if (IN_serendipity !== true) {
    die("Don't hack!");
}
global $serendipity;
$data = array();
switch ($serendipity['POST']['adminAction']) {
    case 'publish':
        if (!serendipity_checkFormToken()) {
            break;
        }
        $success = serendipity_updertEntry(array('id' => serendipity_specialchars($serendipity['POST']['id']), 'timestamp' => time(), 'isdraft' => 0));
        if (is_numeric($success)) {
            $data['published'] = $success;
        } else {
            $data['error_publish'] = $success;
        }
        break;
    case 'updateCheckDisable':
        if (!serendipity_checkFormToken() || !serendipity_checkPermission('blogConfiguration')) {
            break;
        }
        serendipity_set_config_var('updateCheck', false);
        break;
}
$user = serendipity_fetchAuthor($serendipity['authorid']);
// chrome-compatible, from Oliver Gassner, adapted from TextPattern. Hi guys, keep it up. :-)
$bookmarklet = "javascript:var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='" . $serendipity['baseURL'] . "',l=d.location,e=encodeURIComponent,p='serendipity_admin.php?serendipity[adminModule]=entries&serendipity[adminAction]=new&serendipity[title]='+e(d.title)+'&serendipity[body]='+e(s)+'&serendipity[url]='+location.href,u=f+p;a=function(){%20%20if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=800,height=800'))%20%20%20%20l.href=u;};if(/Firefox/.test(navigator.userAgent))%20%20setTimeout(a,0);else%20%20a();void(0)";
$data['bookmarklet'] = $bookmarklet;
$data['username'] = $user[0]['realname'];
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
     $users = array();
     $entries = array();
     if (!extension_loaded('mysql')) {
         return MYSQL_REQUIRED;
     }
     $gdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$gdb) {
         return sprintf(COULDNT_CONNECT, $this->data['host']);
     }
     if (!@mysql_select_db($this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysql_error($gdb));
     }
     /* Users */
     $res = @$this->nativeQuery("SELECT uid        AS ID,\n                                    username   AS user_login,\n                                    passwd     AS user_pass,\n                                    email      AS user_email,\n                                    homepage   AS user_url\n                               FROM {$this->data['prefix']}users", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($gdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysql_fetch_assoc($res);
         $data = array('right_publish' => 1, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'userlevel' => USERLEVEL_ADMIN, 'password' => $users[$x]['user_pass']);
         // MD5 compatible
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         echo mysql_error();
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     $res = @$this->nativeQuery("SELECT tid AS cat_ID, topic AS cat_name, topic AS category_description FROM {$this->data['prefix']}topics ORDER BY tid;", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($gdb));
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $categories[] = mysql_fetch_assoc($res);
     }
     // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
     for ($x = 0, $max_x = sizeof($categories); $x < $max_x; $x++) {
         $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}stories ORDER BY sid;", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($gdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysql_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['title']), 'isdraft' => $entries[$x]['draft_flag'] == '0' ? 'false' : 'true', 'allow_comments' => $entries[$x]['comments'] == '1' ? 'true' : 'false', 'timestamp' => strtotime($entries[$x]['date']), 'body' => $this->strtr($entries[$x]['introtext']), 'extended' => $this->strtr($entries[$x]['bodytext']));
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['uid']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['user_login'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
         /* Entry/category */
         foreach ($categories as $category) {
             if ($category['cat_ID'] == $entries[$x]['tid']) {
                 $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']);
                 serendipity_db_insert('entrycat', $this->strtrRecursive($data));
                 break;
             }
         }
     }
     /* Comments */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments;", $gdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($gdb));
     }
     while ($a = mysql_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['sid'] == $a['sid']) {
                 $author = '';
                 $mail = '';
                 $url = '';
                 foreach ($users as $user) {
                     if ($user['ID'] == $a['uid']) {
                         $author = $user['user_login'];
                         $mail = $user['user_email'];
                         $url = $user['user_url'];
                         break;
                     }
                 }
                 $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['date']), 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => $a['ip'], 'status' => 'approved', 'body' => $a['comment'], 'subscribed' => 'false', 'type' => 'NORMAL');
                 serendipity_db_insert('comments', $this->strtrRecursive($comment));
                 $cid = serendipity_db_insert_id('comments', 'id');
                 serendipity_approveComment($cid, $entry['entryid'], true);
             }
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
         $entry['timestamp'] = $serendipity['POST']['timestamp'];
     }
 }
 // Save server timezone in database always, so substract the offset we added for display; otherwise it would be added time and again
 if (!empty($entry['timestamp'])) {
     $entry['timestamp'] = serendipity_serverOffsetHour($entry['timestamp'], true);
 }
 // Save the entry, or just display a preview
 $use_legacy = true;
 serendipity_plugin_api::hook_event('backend_entry_iframe', $use_legacy);
 if ($use_legacy) {
     if ($serendipity['POST']['preview'] != 'true') {
         /* We don't need an iframe to save a draft */
         if ($serendipity['POST']['isdraft'] == 'true') {
             echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . IFRAME_SAVE_DRAFT . '</div><br />';
             serendipity_updertEntry($entry);
         } else {
             if ($serendipity['use_iframe']) {
                 echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . IFRAME_SAVE . '</div><br />';
                 serendipity_iframe_create('save', $entry);
             } else {
                 serendipity_iframe($entry, 'save');
             }
         }
     } else {
         // Only display the preview
         $serendipity['hidefooter'] = true;
         // Advanced templates use this to show update status and elapsed time
         if (!is_numeric($entry['last_modified'])) {
             $entry['last_modified'] = time();
         }
 function import()
 {
     global $serendipity;
     // Force user to select a blog to act on
     if (empty($this->data['bId']) || $this->data['bId'] == 0) {
         echo 'Please select a blog to import!';
         return false;
     }
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     // Prepare export request
     $req = new HTTP_Request('http://www.blogger.com/feeds/' . $this->data['bId'] . '/archive');
     $req->addHeader('GData-Version', 2);
     $req->addHeader('Authorization', 'AuthSub token="' . $this->data['bAuthToken'] . '"');
     // Attempt fetch blog export
     $req->sendRequest();
     // Handle errors
     if ($req->getResponseCode() != '200') {
         echo "Error occured while trying to export the blog.";
         return false;
     }
     // Export success
     echo '<span class="block_level">Successfully exported entries from Blogger</span>';
     // Get Serendipity authors list
     $authorList = array();
     $s9y_users = serendipity_fetchUsers();
     foreach ($s9y_users as $user) {
         $authorList[$user['authorid']] = $user['username'];
     }
     unset($s9y_users);
     // Load export
     $bXml = simplexml_load_string($req->getResponseBody());
     // Process entries
     $entryList = $entryFailList = array();
     foreach ($bXml->entry as $bEntry) {
         // Check entry type
         switch ($bEntry->category['term']) {
             case 'http://schemas.google.com/blogger/2008/kind#post':
                 // Process posts:
                 // Create author if not in serendipity
                 $author = (string) $bEntry->author->name;
                 if (!array_search($author, $authorList)) {
                     serendipity_db_insert('authors', array('right_publish' => 1, 'realname' => $author, 'username' => $author, 'userlevel' => 0, 'password' => md5($this->data['defaultpass'])));
                     $authorid = serendipity_db_insert_id('authors', 'authorid');
                     $authorList[$authorid] = $author;
                 }
                 $sEntry = array('title' => $this->decode((string) $bEntry->title), 'isdraft' => $bEntry->children('http://purl.org/atom/app#')->control->draft == 'yes' ? 'true' : 'false', 'allow_comments' => count($bEntry->xpath("*[@rel='replies']")) > 0 ? 'true' : 'false', 'timestamp' => strtotime($bEntry->published), 'body' => $this->strtr((string) $bEntry->content), 'extended' => '', 'categories' => $this->data['bCategory'], 'author' => $author, 'authorid' => $authorid);
                 // Add entry to s9y
                 echo '..~.. ';
                 if (is_int($id = serendipity_updertEntry($sEntry))) {
                     // Add entry id to processed table for later lookups
                     $entryList[(string) $bEntry->id] = array($id, $sEntry['title'], 0);
                 } else {
                     // Add to fail list
                     $entryFailList[] = $sEntry['title'];
                 }
                 break;
             case 'http://schemas.google.com/blogger/2008/kind#comment':
                 // Process comments:
                 // Extract entry id for comment
                 $cEntryId = $bEntry->xpath("thr:in-reply-to[@ref]");
                 $cEntryId = (string) $cEntryId[0]['ref'];
                 // Check to make sure the related entry has been added to s9y
                 if (array_key_exists($cEntryId, $entryList)) {
                     // Add to s9y
                     $sComment = array('entry_id ' => $entryList[$cEntryId][0], 'parent_id' => 0, 'timestamp' => strtotime($bEntry->published), 'author' => (string) $bEntry->author->name, 'email' => (string) $bEntry->author->email, 'url' => (string) isset($bEntry->author->uri) ? $bEntry->author->uri : '', 'ip' => '', 'status' => 'approved', 'body' => $this->strtr((string) $bEntry->content), 'subscribed' => 'false', 'type' => 'NORMAL');
                     serendipity_db_insert('comments', $sComment);
                     // Update entry list with comment count
                     $entryList[$cEntryId][2]++;
                 }
                 break;
         }
     }
     // Report on resultant authors
     echo '<span class="block_level">Current list of authors: </span>' . join(', ', array_values($authorList));
     // Do cleanup and report on entries
     echo '<span class="block_level">The following entries were successfully imported:</span>';
     echo '<ul>';
     foreach ($entryList as $eId => $eDetails) {
         // Update comment count for entry in s9y
         serendipity_db_query("UPDATE " . $serendipity['dbPrefix'] . "entries SET comments = " . $eDetails[2] . " WHERE id = " . $eDetails[0]);
         echo '<li>' . $eDetails[1] . ' comments(' . $eDetails[2] . ')</li>';
     }
     echo '</ul>';
     // Report fails
     echo '<span class="block_level">The following entries ran into trouble and was not imported:</span>';
     echo '<ul>';
     foreach ($entryFailList as $eId => $eDetails) {
         echo '<li>' . $eDetails . '</li>';
     }
     echo '</ul>';
     // Reset autodiscovery
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // All done!
     echo '<span class="msg_notice">Import finished.</span>';
     return true;
 }
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $users = array();
     $entries = array();
     if (!extension_loaded('mysql')) {
         return MYSQL_REQUIRED;
     }
     $ltdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$ltdb) {
         return sprintf(COULDNT_CONNECT, $this->data['host']);
     }
     if (!@mysql_select_db($this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysql_error($ltdb));
     }
     /* Users */
     $res = @$this->nativeQuery("SELECT \n                                            user AS user_login,\n                                            `password` AS user_pass,\n                                            email AS user_email,\n                                            full_name AS user_name,\n                                            site_admin AS user_level,\n                                            id AS ID\n                                       FROM lt_users", $ltdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($ltdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysql_fetch_assoc($res);
         $data = array('right_publish' => true, 'realname' => $users[$x]['user_name'], 'username' => $users[$x]['user_login'], 'userlevel' => $users[$x]['user_level'] > 0 ? USERLEVEL_ADMIN : USERLEVEL_EDITOR, 'email' => $users[$x]['user_email'], 'password' => $users[$x]['user_pass']);
         // MD5 compatible
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     if (!$this->importCategories(null, 0, $ltdb)) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($ltdb));
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @$this->nativeQuery("SELECT \n                                           article_id AS ID,\n                                           UNIX_TIMESTAMP(`date`) AS tstamp, \n                                           user_id AS post_author, \n                                           status AS post_status,\n                                           text AS post_content,\n                                           topic AS post_title\n                                      FROM lt_articles \n                                      JOIN lt_articles_text\n                                        ON lt_articles_text.article_id = lt_articles.id\n                               ORDER BY ID;", $ltdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($ltdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysql_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['post_title']), 'isdraft' => $entries[$x]['post_status'] == '1' ? 'false' : 'true', 'allow_comments' => 'true', 'timestamp' => $entries[$x]['tstamp'], 'body' => $this->strtr($entries[$x]['post_content']));
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['post_author']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['user_login'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
     }
     /* Even more category stuff */
     $res = @$this->nativeQuery("SELECT article_id AS postcat_post_ID, \n                                           category_id AS postcat_cat_ID \n                                      FROM lt_article_categories_link", $ltdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($ltdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entrycat = mysql_fetch_assoc($res);
         $entryid = 0;
         $categoryid = 0;
         foreach ($entries as $entry) {
             if ($entry['ID'] == $entrycat['postcat_post_ID']) {
                 $entryid = $entry['entryid'];
                 break;
             }
         }
         foreach ($this->categories as $category) {
             if ($category['cat_ID'] == $entrycat['postcat_cat_ID']) {
                 $categoryid = $category['categoryid'];
             }
         }
         if ($entryid > 0 && $categoryid > 0) {
             $data = array('entryid' => $entryid, 'categoryid' => $categoryid);
             serendipity_db_insert('entrycat', $this->strtrRecursive($data));
         }
     }
     /* Comments */
     $res = @$this->nativeQuery("SELECT article_id AS comment_post_ID,\n                                           topic AS title,\n                                           text AS comment_content,\n                                           user_email AS comment_author_email,\n                                           user_url AS comment_author_url,\n                                           user_name AS comment_author,\n                                           user_id AS comment_author_ID,\n                                           UNIX_TIMESTAMP(`date`) AS tstamp,\n                                           client_ip AS comment_author_IP,\n                                           status AS comment_status\n                                      FROM lt_articles_comments;", $ltdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($ltdb));
     }
     while ($a = mysql_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['ID'] == $a['comment_post_ID']) {
                 $author = '';
                 $mail = '';
                 $url = '';
                 if (!empty($a['comment_author_ID']) && $a['comment_author_ID'] > 0) {
                     foreach ($users as $user) {
                         if ($user['ID'] == $a['comment_author_ID']) {
                             $author = $user['user_login'];
                             $mail = $user['user_email'];
                             $url = $user['user_url'];
                             break;
                         }
                     }
                 }
                 if (empty($author) && empty($mail)) {
                     $author = $a['comment_author'];
                     $mail = $a['comment_author_email'];
                     $url = $a['comment_author_url'];
                 }
                 $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['tstamp'], 'author' => $author, 'email' => $mail, 'url' => $url, 'title' => $a['title'], 'ip' => $a['comment_author_IP'], 'status' => $a['comment_status'] == '2' ? 'pending' : 'approved', 'body' => $a['comment_content'], 'subscribed' => 'false', 'type' => 'NORMAL');
                 serendipity_db_insert('comments', $this->strtrRecursive($comment));
                 if ($a['comment_status'] != '2') {
                     $cid = serendipity_db_insert_id('comments', 'id');
                     serendipity_approveComment($cid, $entry['entryid'], true);
                 }
             }
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
function universal_updertEntry(&$entry)
{
    // The permission check is only executed, if this is set:
    $serendipity['GET']['adminModule'] = 'entries';
    return serendipity_updertEntry($entry);
}
Exemple #29
0
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
     $users = array();
     $entries = array();
     if (!extension_loaded('mysql')) {
         return MYSQL_REQUIRED;
     }
     $sunlogdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$sunlogdb) {
         return sprintf(COULDNT_CONNECT, $this->data['host']);
     }
     if (!@mysql_select_db($this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysql_error($sunlogdb));
     }
     /* Users */
     $res = @$this->nativeQuery("SELECT id         AS ID,\n                                    name       AS user_login,\n                                    email      AS user_email,\n                                    homepage   AS user_url\n                               FROM {$this->data['prefix']}users", $sunlogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($sunlogdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysql_fetch_assoc($res);
         $data = array('right_publish' => 1, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'userlevel' => USERLEVEL_ADMIN, 'password' => md5('sunlog'));
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         echo mysql_error();
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     if (!$this->importCategories(null, 0, $sunlogdb)) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($sunlogdb));
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}articles ORDER BY id;", $sunlogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($sunlogdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysql_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['title']), 'isdraft' => $entries[$x]['draft'] == '0' ? 'false' : 'true', 'allow_comments' => $entries[$x]['c_comments'] == '1' ? 'true' : 'false', 'timestamp' => strtotime($entries[$x]['timestamp']), 'body' => $this->strtr($entries[$x]['lead_converted']), 'extended' => $this->strtr($entries[$x]['article_converted']));
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['author']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['user_login'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
     }
     /* Even more category stuff */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}transfer_c;", $sunlogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($sunlogdb));
     }
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $entrycat = mysql_fetch_assoc($res);
         $entryid = 0;
         $categoryid = 0;
         foreach ($entries as $entry) {
             if ($entry['id'] == $entrycat['article']) {
                 $entryid = $entry['entryid'];
                 break;
             }
         }
         foreach ($this->categories as $category) {
             if ($category['id'] == $entrycat['category']) {
                 $categoryid = $category['categoryid'];
             }
         }
         if ($entryid > 0 && $categoryid > 0) {
             $data = array('entryid' => $entryid, 'categoryid' => $categoryid);
             serendipity_db_insert('entrycat', $this->strtrRecursive($data));
         }
     }
     /* Comments */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}c_comments;", $sunlogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($sunlogdb));
     }
     while ($a = mysql_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['id'] == $a['for_entry']) {
                 $author = '';
                 $mail = '';
                 $url = '';
                 foreach ($users as $user) {
                     if ($user['ID'] == $a['user']) {
                         $author = $user['user_login'];
                         $mail = $user['user_email'];
                         $url = $user['user_url'];
                         break;
                     }
                 }
                 $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['insertdate']), 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => '', 'status' => 'approved', 'body' => $a['comment'], 'subscribed' => 'false', 'type' => 'NORMAL');
                 serendipity_db_insert('comments', $this->strtrRecursive($comment));
                 $cid = serendipity_db_insert_id('comments', 'id');
                 serendipity_approveComment($cid, $entry['entryid'], true);
             }
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
 function import()
 {
     global $serendipity;
     $force = $this->data['mt_force'] == 'true';
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     // Rewritten to parse the file line by line. Can save quite some
     // memory on large blogs
     //$contents   = file_get_contents($_FILES['serendipity']['tmp_name']['import']['mt_dat']);
     $this->categories = serendipity_fetchCategories();
     $tasks = array();
     $entries = array();
     if (empty($_FILES['serendipity']['tmp_name']['import']['mt_dat'])) {
         $fh = fopen('/tmp/mt.dat', 'r');
     } else {
         $fh = fopen($_FILES['serendipity']['tmp_name']['import']['mt_dat'], 'r');
     }
     $entry = array();
     $el = "";
     $c_el = "";
     $skip = false;
     $is_comment = false;
     $is_trackback = false;
     $nofetch = false;
     while (!feof($fh)) {
         if ($nofetch === false) {
             $this->debug('Next line');
             $line = $this->decode(fgets($fh, 8192));
         } else {
             $this->debug('NO Next line');
             // Keep line from previous run.
             $nofetch = false;
         }
         if ($is_comment || $is_trackback) {
             $this->debug("COMMENT/TRACKBACK mode is active.");
             if (preg_match('/^--------/', $line)) {
                 $this->debug("Next full section requested.");
                 $is_comment = $is_trackback = false;
             } elseif (preg_match('/^-----/', $line)) {
                 $this->debug("Next partial section requested.");
                 if ($is_trackback) {
                     $this->debug("Parsing trackback.");
                     $entry['s9y_comments'][] = $this->doCommentWork($comment, $tasks, 'TRACKBACK');
                 } elseif ($is_comment) {
                     $this->debug("Parsing comment.");
                     $entry['s9y_comments'][] = $this->doCommentWork($comment, $tasks, 'NORMAL');
                 }
                 $el = $c_el = "";
             }
         }
         if ($skip && !preg_match('/^--------/', $line)) {
             $this->debug("No next section match, and skip is activated. Skipping '{$line}'");
             continue;
         }
         if (preg_match('/^--------/', $line)) {
             // We found the end marker of the current entry. Add to entries-Array
             $this->debug("End marker found. Parsing full entry.");
             $entries[] = $this->doEntryWork($entry, $tasks);
             $entry = array();
             $el = "";
             $c_el = "";
             $skip = false;
             $is_comment = false;
             $is_trackback = false;
         } elseif (preg_match('/^-----/', $line)) {
             $this->debug("New section match. Current EL: {$el}");
             unset($el);
             # DEBUG!
             if (empty($el)) {
                 $line = $this->decode(fgets($fh, 8192));
                 $this->debug("Inspecting next line: {$line}");
                 $tline = trim($line);
                 while (($is_comment || $is_trackback) && empty($tline)) {
                     $line = $this->decode(fgets($fh, 8192));
                     $tline = trim($line);
                     $this->debug("Continuing inspecting next line: {$line}");
                 }
                 if (preg_match('/^--------/', $line)) {
                     $this->debug('Next line is new element. End marker found. Parsing full entry.');
                     $entries[] = $this->doEntryWork($entry, $tasks);
                     $entry = array();
                     $el = "";
                     $c_el = "";
                     $skip = false;
                     $is_comment = false;
                     $is_trackback = false;
                 } elseif (preg_match('/^([A-Z\\s]+):/', $line, $matches)) {
                     $this->debug("Match result: {$matches['1']}");
                     if ($matches[1] == 'COMMENT') {
                         $this->debug("Marking COMMENT.");
                         $is_comment = true;
                         $is_trackback = false;
                         $comment = array();
                         $skip = false;
                     } elseif ($matches[1] == 'PING') {
                         $this->debug("Marking TRACKBACK");
                         $is_comment = false;
                         $is_trackback = true;
                         $comment = array();
                         $skip = false;
                     }
                     $this->debug("Setting EL to {$matches[1]}");
                     $el = $matches[1];
                     $c_el = "";
                 } else {
                     $this->debug("Could not parse next line. Keeping it for next cycle.");
                     $nofetch = true;
                 }
             } else {
                 $this->debug("Resetting EL to an empty string");
                 $el = $c_el = "";
             }
         } elseif (empty($el)) {
             $this->debug("EL is empty. Line is '{$line}'");
             $content = "";
             if (preg_match('/^([A-Z\\s]+):\\s+(.*)$/s', $line, $matches)) {
                 $this->debug("Section match {$matches[1]} found, input: {$matches[2]}");
                 $c_el = $matches[1];
                 $content = $matches[2];
             } elseif (!empty($c_el)) {
                 $this->debug("Still in subsection of previous run: {$c_el}.");
                 $content = trim($line);
             }
             if (!empty($content)) {
                 if ($is_comment || $is_trackback) {
                     $this->debug("Appending to comments: {$line}");
                     $comment[$c_el] = $content;
                 } else {
                     $this->debug("Appending to entry: {$line}");
                     if (isset($entry[$c_el])) {
                         $entry[$c_el] .= "" . $content;
                     } else {
                         $entry[$c_el] = $content;
                     }
                 }
             }
         } elseif ($is_comment || $is_trackback) {
             $this->debug("Appending Line in current Element {$el} to comments: {$line}");
             $comment[$el] .= $line;
         } else {
             $this->debug("Appending Line in current Element {$el} to entries: {$line}");
             $entry[$el] .= $line;
         }
     }
     fclose($fh);
     if (!sizeof($tasks) || $force == true) {
         serendipity_db_begin_transaction();
         foreach ($entries as $entry) {
             #echo '<pre>' . printR_($entry, true) . '</pre><br />';
             #continue;
             if (empty($entry['authorid'])) {
                 $entry['authorid'] = $serendipity['authorid'];
                 $entry['author'] = $serendipity['realname'];
             }
             if (!isset($entry['isdraft'])) {
                 $entry['isdraft'] = 'false';
             }
             if (!isset($entry['allow_comments'])) {
                 $entry['allow_comments'] = 'true';
             }
             $comments = $entry['s9y_comments'];
             $entryprops = $entry['props'];
             unset($entry['props']);
             unset($entry['s9y_comments']);
             if (!is_int($r = serendipity_updertEntry($entry))) {
                 echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />' . $r . '</div>';
             } else {
                 $this->debug('Saved entry ' . $r . ' (' . $entry['title'] . ')');
                 $entry['id'] = $r;
                 foreach ((array) $comments as $comment) {
                     $comment['entry_id'] = $r;
                     if ($rc = serendipity_db_insert('comments', $comment)) {
                         $cid = serendipity_db_insert_id('comments', 'id');
                         serendipity_approveComment($cid, $entry['id'], true);
                     } else {
                         echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />' . $rc . '</div>';
                     }
                 }
                 // Let the plugins do some additional stuff. Here it's used with
                 // event_entryproperties in mind to setup the nl2br-stuff
                 serendipity_plugin_api::hook_event('backend_import_entry', $entry, $entryprops);
             }
         }
         serendipity_db_end_transaction(true);
         return true;
     } else {
         return '<ul><li>' . implode('</li><li>', array_unique($tasks)) . '</li></ul>';
     }
 }