function sendComment($to, $title, $fromName, $fromEmail, $fromUrl, $comment)
 {
     global $serendipity;
     if (empty($fromName)) {
         $fromName = ANONYMOUS;
     }
     $key = md5(uniqid(rand(), true));
     //  CUSTOMIZE
     $subject = PLUGIN_SUGGEST_TITLE;
     $text = sprintf(PLUGIN_SUGGEST_MAIL, $serendipity['baseURL'] . '?suggestkey=' . $key);
     $db = array('email' => $fromEmail, 'entry_id' => 0, 'copycop' => '', 'ip' => $_SERVER['REMOTE_ADDR'], 'submitted' => time(), 'name' => $fromName, 'article' => $comment, 'title' => $title, 'validation' => $key);
     serendipity_db_insert('suggestmails', $db);
     return serendipity_sendMail($to, $subject, $text, $serendipity['blogMail'], null, $serendipity['blogTitle']);
 }
 static function save_oembed($url, $oembed)
 {
     if (empty($url) || !isset($oembed)) {
         return false;
     }
     if (isset($oembed->html)) {
         $oembed->html = OEmbedDatabase::cleanup_html($oembed->html);
     }
     $save = array();
     $save['urlmd5'] = md5($url);
     $save['url'] = $url;
     $save['oetype'] = $oembed->type;
     $save['oeobj'] = serialize($oembed);
     serendipity_db_insert(PLUGIN_OEMBED_DATABASEVNAME, $save);
     return $oembed;
 }
 static function saveCommentSpice($commentid, $twittername, $promo_name, $promo_url, $boo_url)
 {
     global $serendipity;
     if (empty($commentid) || !is_numeric($commentid) || empty($twittername) && empty($promo_name) && empty($boo_url)) {
         return true;
     }
     $spice = array('commentid' => $commentid);
     if (!empty($twittername)) {
         $spice['twittername'] = $twittername;
     }
     if (!empty($promo_name)) {
         $spice['promo_name'] = $promo_name;
     }
     if (!empty($promo_url)) {
         $spice['promo_url'] = $promo_url;
     }
     if (!empty($boo_url)) {
         $spice['boo'] = $boo_url;
     }
     return serendipity_db_insert('commentspice', $spice);
 }
示例#4
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('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;
 }
示例#5
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('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;
 }
/**
 * Allow access to a specific item (category or entry) for a specific usergroup
 *
 * ACL are Access Control Lists. They indicate which read/write permissions a
 * specific item has for specific usergroups.
 * An artifact in terms of Serendipity can be either a category or an entry, or
 * anything beyond that for future compatibility.
 * This function sets up the ACLs.
 *
 * @access public
 * @param   int     The ID of the artifact to set the access
 * @param   string  The type of an artifact (category|entry)
 * @param   string  The type of access to grant (read|write)
 * @param   array   The ID of the group to grant access to
 * @param   string  A variable option for an artifact
 * @return  boolean True if ACL was applied, false if not.
 */
function serendipity_ACLGrant($artifact_id, $artifact_type, $artifact_mode, $groups, $artifact_index = '')
{
    global $serendipity;
    if (empty($groups) || !is_array($groups)) {
        return false;
    }
    // Delete all old existing relations.
    serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}access\n                                WHERE artifact_id    = " . (int) $artifact_id . "\n                                  AND artifact_type  = '" . serendipity_db_escape_string($artifact_type) . "'\n                                  AND artifact_mode  = '" . serendipity_db_escape_string($artifact_mode) . "'\n                                  AND artifact_index = '" . serendipity_db_escape_string($artifact_index) . "'");
    $data = array('artifact_id' => (int) $artifact_id, 'artifact_type' => $artifact_type, 'artifact_mode' => $artifact_mode, 'artifact_index' => $artifact_index);
    if (count($data) < 1) {
        return true;
    }
    foreach ($groups as $group) {
        $data['groupid'] = $group;
        serendipity_db_insert('access', $data);
    }
    return true;
}
示例#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_table(&$s9ydb, $table, $primary_keys, $where = null, $dupe_check = false, $fix_relations = false, $skip_dupes = false)
 {
     global $serendipity;
     echo "<br /><br />Starting with table <strong>{$table}</strong>...<br />\n";
     if ($dupe_check) {
         $dupes = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}" . $table . " " . $where, false, 'both', false, $dupe_check);
         if (!$this->execute) {
             echo 'Dupe-Check: <pre>' . print_r($dupes, true) . '</pre>';
         }
     }
     $res = $this->nativeQuery("SELECT * FROM {$this->data['prefix']}" . $table . " " . $where, $s9ydb);
     echo mysql_error($s9ydb);
     if (!$res || mysql_num_rows($res) < 1) {
         return false;
     }
     $this->counter = 100;
     while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
         $this->counter++;
         if (is_array($primary_keys)) {
             foreach ($primary_keys as $primary_key) {
                 $primary_vals[$primary_key] = $row[$primary_key];
                 unset($row[$primary_key]);
             }
         } else {
             $primary_vals = array();
         }
         $insert = true;
         if (is_array($fix_relations)) {
             foreach ($fix_relations as $primary_key => $fix_relation) {
                 foreach ($fix_relation as $fix_relation_table => $fix_relation_primary_key) {
                     if (isset($primary_vals[$fix_relation_primary_key])) {
                         $assoc_val = $primary_vals[$fix_relation_primary_key];
                     } else {
                         $assoc_val = $row[$primary_key];
                     }
                     if (!$this->execute && empty($assoc_val)) {
                         if ($this->debug) {
                             echo '<pre>';
                             print_r($row);
                             print_r($fix_relation);
                             echo '</pre>';
                         }
                     }
                     $new_val = $this->storage[$fix_relation_table][$fix_relation_primary_key][$assoc_val];
                     if ($skip_dupes && $assoc_val == $new_val) {
                         $insert = false;
                     }
                     if (!empty($new_val)) {
                         $row[$primary_key] = $new_val;
                     }
                     if (!$this->execute && $this->debug) {
                         echo "Fix relation from {$fix_relation_table}.{$fix_relation_primary_key}={$primary_vals[$fix_relation_primary_key]} to {$row[$primary_key]} (assoc_val: {$assoc_val})<br />\n";
                     }
                 }
             }
         }
         if ($insert) {
             if ($dupe_check && isset($dupes[$row[$dupe_check]])) {
                 if ($this->debug) {
                     echo "Skipping duplicate: <pre>" . print_r($dupes[$row[$dupe_check]], true) . "</pre><br />\n";
                 }
                 foreach ($primary_vals as $primary_key => $primary_val) {
                     $this->storage[$table][$primary_key][$primary_val] = $dupes[$row[$dupe_check]][$primary_key];
                     $this->storage['dupes'][$table][$primary_key][$primary_val] = $dupes[$row[$dupe_check]][$primary_key];
                 }
             } elseif ($this->execute) {
                 serendipity_db_insert($table, $this->strtrRecursive($row));
                 foreach ($primary_vals as $primary_key => $primary_val) {
                     $dbid = serendipity_db_insert_id($table, $primary_key);
                     $this->storage[$table][$primary_key][$primary_val] = $dbid;
                 }
                 echo "Migrated entry #{$dbid} into {$table}.<br />\n";
             } else {
                 if ($this->debug) {
                     echo 'DB Insert: <pre>' . print_r($row, true) . '</pre>';
                 }
                 foreach ($primary_vals as $primary_key => $primary_val) {
                     $this->storage[$table][$primary_key][$primary_val] = $this->counter;
                 }
             }
         } else {
             if ($this->debug && !$this->execute) {
                 echo "Ignoring Duplicate.<br />\n";
             }
         }
     }
     if (!$this->execute) {
         echo 'Storage on ' . $table . ':<pre>' . print_r($this->storage[$table], true) . '</pre>';
     } else {
         echo "Finished table <strong>{$table}</strong><br />\n";
     }
 }
示例#9
0
 function import()
 {
     global $serendipity;
     global $elements;
     // Dependency on static pages
     if (!class_exists('serendipity_event_staticpage')) {
         die(IMPORTER_VOODOO_REQUIREMENTFAIL . '<br/>');
     }
     // The selected file
     $file = $_FILES['serendipity']['tmp_name']['import']['voodooPadXML'];
     // Create a parser and set it up with the callbacks
     $xml_parser = xml_parser_create('');
     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
     xml_set_element_handler($xml_parser, "start_element_handler", "end_element_handler");
     xml_set_character_data_handler($xml_parser, "character_data_handler");
     // Feed the contents of the file into the parser
     if (!file_exists($file)) {
         die(sprintf(DOCUMENT_NOT_FOUND, htmlspecialchars($file)));
     }
     if (!($handle = fopen($file, "r"))) {
         die(sprintf(SKIPPING_FILE_UNREADABLE, htmlspecialchars($file)));
     }
     while ($contents = fread($handle, 4096)) {
         xml_parse($xml_parser, $contents, feof($handle));
     }
     fclose($handle);
     xml_parser_free($xml_parser);
     // Maintain a list of the aliases and their links
     $aliases = array();
     // Now have a list of elements referenceable by id
     // so loop through building and/or updating page objects
     while (list($key_a) = each($elements)) {
         $name = $elements[$key_a]->name;
         switch ($name) {
             case 'data':
                 // <data> indicates the start of the VoodooPad entry, so create page object
                 $thispage = array();
                 break;
             case 'key':
                 // This is the unique identifier of the page
                 $mykey = serendipity_makeFilename($elements[$key_a]->data);
                 $mykey = basename($this->data['keyPrefix']) . $mykey;
                 // Pluck out the existing one if its there
                 $page = serendipity_db_query("SELECT * \n                                                    FROM {$serendipity['dbPrefix']}staticpages \n                                                    WHERE filename = '" . serendipity_db_escape_string($mykey . '.htm') . "'\n                                                    LIMIT 1", true, 'assoc');
                 if (is_array($page)) {
                     $thispage =& $page;
                     if (empty($thispage['timestamp'])) {
                         $thispage['timestamp'] = time();
                     }
                 }
                 $thispage['filename'] = $mykey . '.htm';
                 // Thanks for pointing this out to me and not just fixing it, I'm learning.
                 $thispage['permalink'] = $serendipity['serendipityHTTPPath'] . 'index.php?serendipity[subpage]=' . $mykey;
                 break;
             case 'alias':
                 // The title and the string used to match links
                 $thispage['articleformattitle'] = $this->data['wikiName'];
                 $thispage['pagetitle'] = $mykey;
                 $thispage['headline'] = $elements[$key_a]->data;
                 break;
             case 'content':
                 // The content of a voodoopad entry
             // The content of a voodoopad entry
             case 'path':
                 // The path of a url string
                 $thispage['content'] = $elements[$key_a]->data;
                 // If its a content link list it for referencing with the page permalink
                 if ($name == 'content') {
                     $aliases[$thispage['headline']] = $thispage['permalink'];
                     // Either replace or insert depending on previous existence
                     if (!isset($thispage['id'])) {
                         echo '<br/>' . IMPORTER_VOODOO_CREATINGPAGE . ': ' . $mykey;
                         serendipity_db_insert('staticpages', $thispage);
                         $serendipity["POST"]["staticpage"] = serendipity_db_insert_id("staticpages", 'id');
                     } elseif ($this->data['updateExisting'] == 'true') {
                         echo '<br/>' . IMPORTER_VOODOO_UPDATINGPAGE . ': ' . $mykey;
                         serendipity_db_update("staticpages", array("id" => $thispage["id"]), $thispage);
                     } else {
                         echo '<br/>' . IMPORTER_VOODOO_NOTUPDATING . ': ' . $mykey;
                     }
                 } else {
                     // If its a url, the content is the link instead
                     echo '<br/>' . IMPORTER_VOODOO_RECORDURL . ': ' . $thispage['headline'];
                     $aliases[$thispage['headline']] = $thispage['content'];
                 }
                 break;
         }
     }
     // Now rewrite the permalinks
     echo '<br/>';
     if ($this->data['shouldWriteLinks'] == 'true') {
         Serendipity_Import_VoodooPad::write_links($aliases);
     }
     return true;
 }
示例#10
0
 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;
 }
示例#11
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;
 }
 function insertFeed(&$array)
 {
     global $serendipity;
     $query = "SELECT authorid\n                    FROM {$serendipity['dbPrefix']}authors\n                   WHERE realname='" . serendipity_db_escape_string($array['feedname']) . "'";
     if (!is_array($res = serendipity_db_query($query))) {
         serendipity_db_insert('authors', array('username' => $array['feedname'], 'realname' => $array['feedname'], 'password' => md5(mt_rand()), 'email' => $array['htmlurl'], 'userlevel' => 0, 'right_publish' => 1));
         $res = serendipity_db_query($query);
     }
     $r = serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}aggregator_feeds\n                                                 (feedname, feedurl, htmlurl, charset, match_expression, feedicon, last_update)\n                                        VALUES ('" . serendipity_db_escape_string($array['feedname']) . "',\n                                                '" . serendipity_db_escape_string($array['feedurl']) . "',\n                                                '" . serendipity_db_escape_string($array['htmlurl']) . "',\n                                                '" . serendipity_db_escape_string($array['charset']) . "',\n                                                '" . serendipity_db_escape_string($array['match_expression']) . "',\n                                                '" . serendipity_db_escape_string($array['feedicon']) . "',\n                                                '" . time() . "')");
     if ($r == false) {
         return $r;
     }
     if (!is_array($array['categoryids'])) {
         $array['categoryids'] = array();
         $array['categoryids'][] = $array['categoryid'];
     }
     return $this->insertFeedCats(serendipity_db_insert_id(), $array['categoryids']);
 }
示例#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();
     $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;
 }
示例#14
0
 function importCategories($nukedb)
 {
     $res = $this->nativeQuery("SELECT topicname   AS cat_name,\n                                          topictext   AS cat_description,\n                                          topicid     AS cat_ID\n                                     FROM nuke_topics", $nukedb);
     if (!$res) {
         echo mysql_error();
         return false;
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $row = mysql_fetch_assoc($res);
         $cat = array('category_name' => $row['cat_name'], 'category_description' => $row['cat_description'], '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;
     }
     return true;
 }
示例#15
0
 function import_wpxrss()
 {
     // TODO: Backtranscoding to NATIVE charset. Currently only works with UTF-8.
     $dry_run = false;
     $serendipity['noautodiscovery'] = 1;
     $uri = $this->data['url'];
     require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
     serendipity_request_start();
     $req = new HTTP_Request($uri, array('allowRedirects' => true, 'maxRedirects' => 5));
     $res = $req->sendRequest();
     if (PEAR::isError($res) || $req->getResponseCode() != '200') {
         serendipity_request_end();
         echo IMPORT_FAILED . ': ' . htmlspecialchars($this->data['url']);
         echo "<br />\n";
         return false;
     }
     $fContent = $req->getResponseBody();
     serendipity_request_end();
     echo strlen($fContent) . " Bytes<br />\n";
     if (version_compare(PHP_VERSION, '5.0') === -1) {
         printf(UNMET_REQUIREMENTS, 'PHP >= 5.0');
         echo "<br />\n";
         return false;
     }
     $xml = simplexml_load_string($fContent);
     unset($fContent);
     /* ************* USERS **********************/
     $_s9y_users = serendipity_fetchUsers();
     $s9y_users = array();
     if (is_array($s9y_users)) {
         foreach ($_s9y_users as $v) {
             $s9y_users[$v['realname']] = $v;
         }
     }
     /* ************* CATEGORIES **********************/
     $_s9y_cat = serendipity_fetchCategories('all');
     $s9y_cat = array();
     if (is_array($s9y_cat)) {
         foreach ($_s9y_cat as $v) {
             $s9y_cat[$v['category_name']] = $v['categoryid'];
         }
     }
     $wp_ns = 'http://wordpress.org/export/1.0/';
     $dc_ns = 'http://purl.org/dc/elements/1.1/';
     $content_ns = 'http://purl.org/rss/1.0/modules/content/';
     $wp_core = $xml->channel->children($wp_ns);
     foreach ($wp_core->category as $idx => $cat) {
         //TODO: Parent generation unknown.
         $cat_name = (string) $cat->cat_name;
         if (!isset($s9y_cat[$cat_name])) {
             $cat = array('category_name' => $cat_name, 'category_description' => '', 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
             printf(CREATE_CATEGORY, htmlspecialchars($cat_name));
             echo "<br />\n";
             if ($dry_run) {
                 $s9y_cat[$cat_name] = time();
             } else {
                 serendipity_db_insert('category', $cat);
                 $s9y_cat[$cat_name] = serendipity_db_insert_id('category', 'categoryid');
             }
         }
     }
     /* ************* ITEMS **********************/
     foreach ($xml->channel->item as $idx => $item) {
         $wp_items = $item->children($wp_ns);
         $dc_items = $item->children($dc_ns);
         $content_items = $item->children($content_ns);
         // TODO: Attachments not handled
         if ((string) $wp_items->post_type == 'attachment' or (string) $wp_items->post_type == 'page') {
             continue;
         }
         $entry = array('title' => (string) $item->title, 'isdraft' => (string) $wp_items->status == 'publish' ? 'false' : 'true', 'allow_comments' => (string) $wp_items->comment_status == 'open' ? true : false, 'categories' => array(), 'body' => (string) $content_items->encoded);
         if (preg_match('@^([0-9]{4})\\-([0-9]{2})\\-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$@', (string) $wp_items->post_date, $timematch)) {
             $entry['timestamp'] = mktime($timematch[4], $timematch[5], $timematch[6], $timematch[2], $timematch[3], $timematch[1]);
         } else {
             $entry['timestamp'] = time();
         }
         if (isset($item->category[1])) {
             foreach ($item->category as $idx => $category) {
                 $cstring = (string) $category;
                 if (!isset($s9y_cat[$cstring])) {
                     echo "WARNING: {$category} unset!<br />\n";
                 } else {
                     $entry['categories'][] = $s9y_cat[$cstring];
                 }
             }
         } else {
             $cstring = (string) $item->category;
             $entry['categories'][] = $s9y_cat[$cstring];
         }
         $wp_user = (string) $dc_items->creator;
         if (!isset($s9y_users[$wp_user])) {
             if ($dry_run) {
                 $s9y_users[$wp_user]['authorid'] = time();
             } else {
                 $s9y_users[$wp_user]['authorid'] = serendipity_addAuthor($wp_user, md5(time()), $wp_user, '', USERLEVEL_EDITOR);
             }
             printf(CREATE_AUTHOR, htmlspecialchars($wp_user));
             echo "<br />\n";
         }
         $entry['authorid'] = $s9y_users[$wp_user]['authorid'];
         if ($dry_run) {
             $id = time();
         } else {
             $id = serendipity_updertEntry($entry);
         }
         $s9y_cid = array();
         // Holds comment ids to s9y ids association.
         $c_i = 0;
         foreach ($wp_items->comment as $comment) {
             $c_i++;
             $c_id = (string) $comment->comment_id;
             $c_pid = (string) $comment->comment_parent;
             $c_type = (string) $comment->comment_type;
             if ($c_type == 'pingback') {
                 $c_type2 = 'PINGBACK';
             } elseif ($c_type == 'trackback') {
                 $c_type2 = 'TRACKBACK';
             } else {
                 $c_type2 = 'NORMAL';
             }
             $s9y_comment = array('entry_id ' => $id, 'parent_id' => $s9y_cid[$c_pd], 'author' => (string) $comment->comment_author, 'email' => (string) $comment->comment_author_email, 'url' => (string) $comment->comment_author_url, 'ip' => (string) $comment->comment_author_IP, 'status' => empty($comment->comment_approved) || $comment->comment_approved == '1' ? 'approved' : 'pending', 'subscribed' => 'false', 'body' => (string) $comment->comment_content, 'type' => $c_type2);
             if (preg_match('@^([0-9]{4})\\-([0-9]{2})\\-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$@', (string) $comment->comment_date, $timematch)) {
                 $s9y_comment['timestamp'] = mktime($timematch[4], $timematch[5], $timematch[6], $timematch[2], $timematch[3], $timematch[1]);
             } else {
                 $s9y_comment['timestamp'] = time();
             }
             if ($dry_run) {
                 $cid = time();
             } else {
                 serendipity_db_insert('comments', $s9y_comment);
                 $cid = serendipity_db_insert_id('comments', 'id');
                 if ($s9y_comment['status'] == 'approved') {
                     serendipity_approveComment($cid, $id, true);
                 }
             }
             $s9y_cid[$c_id] = $cid;
         }
         echo "Entry '" . htmlspecialchars($entry['title']) . "' ({$c_i} comments) imported.<br />\n";
     }
     return true;
 }
/**
 * Search through link body, and automagically send a trackback ping.
 *
 * This is the trackback starter function that searches your text and sees if any
 * trackback URLs are in there
 *
 * @access public
 * @param   int     The ID of our entry
 * @param   string  The author of our entry
 * @param   string  The title of our entry
 * @param   string  The text of our entry
 * @param   boolean Dry-Run, without performing trackbacks?
 * @return
 */
function serendipity_handle_references($id, $author, $title, $text, $dry_run = false)
{
    global $serendipity;
    static $old_references = array();
    static $saved_references = array();
    static $saved_urls = array();
    if (is_object($serendipity['logger'])) {
        $serendipity['logger']->debug("serendipity_handle_references");
    }
    if ($dry_run) {
        // Store the current list of references. We might need to restore them for later user.
        $old_references = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}references WHERE (type = '' OR type IS NULL) AND entry_id = " . (int) $id, false, 'assoc');
        if (is_string($old_references)) {
            if (is_object($serendipity['logger'])) {
                $serendipity['logger']->debug($old_references);
            }
        }
        if (is_array($old_references) && count($old_references) > 0) {
            $current_references = array();
            foreach ($old_references as $idx => $old_reference) {
                // We need the current reference ID to restore it later.
                $saved_references[$old_reference['link'] . $old_reference['name']] = $current_references[$old_reference['link'] . $old_reference['name']] = $old_reference;
                $saved_urls[$old_reference['link']] = true;
            }
        }
        if (is_object($serendipity['logger'])) {
            $serendipity['logger']->debug("Got references in dry run: " . print_r($current_references, true));
        }
    } else {
        // A dry-run was called previously and restorable references are found. Restore them now.
        $del = serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}references WHERE (type = '' OR type IS NULL) AND entry_id = " . (int) $id);
        if (is_string($del)) {
            if (is_object($serendipity['logger'])) {
                $serendipity['logger']->debug($del);
            }
        }
        if (is_object($serendipity['logger'])) {
            $serendipity['logger']->debug("Deleted references");
        }
        if (is_array($old_references) && count($old_references) > 0) {
            $current_references = array();
            foreach ($old_references as $idx => $old_reference) {
                // We need the current reference ID to restore it later.
                $current_references[$old_reference['link'] . $old_reference['name']] = $old_reference;
                $q = serendipity_db_insert('references', $old_reference, 'show');
                $cr = serendipity_db_query($q);
                if (is_string($cr)) {
                    if (is_object($serendipity['logger'])) {
                        $serendipity['logger']->debug($cr);
                    }
                }
            }
        }
        if (is_object($serendipity['logger'])) {
            $serendipity['logger']->debug("Got references in final run:" . print_r($current_references, true));
        }
    }
    if (!preg_match_all('@<a[^>]+?href\\s*=\\s*["\']?([^\'" >]+?)[ \'"][^>]*>(.+?)</a>@i', $text, $matches)) {
        $matches = array(0 => array(), 1 => array());
    } else {
        // remove full matches
        array_shift($matches);
    }
    // Make trackback URL
    $url = serendipity_archiveURL($id, $title, 'baseURL');
    // Make sure that the trackback-URL does not point to https
    $url = str_replace('https://', 'http://', $url);
    // Add URL references
    $locations = $matches[0];
    $names = $matches[1];
    $checked_locations = array();
    serendipity_plugin_api::hook_event('backend_trackbacks', $locations);
    for ($i = 0, $j = count($locations); $i < $j; ++$i) {
        if (is_object($serendipity['logger'])) {
            $serendipity['logger']->debug("Checking {$locations[$i]}...");
        }
        if ($locations[$i][0] == '/') {
            $locations[$i] = 'http' . (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off' ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $locations[$i];
        }
        if (isset($checked_locations[$locations[$i]])) {
            if (is_object($serendipity['logger'])) {
                $serendipity['logger']->debug("Already checked");
            }
            continue;
        }
        if (preg_match_all('@<img[^>]+?alt=["\']?([^\'">]+?)[\'"][^>]+?>@i', $names[$i], $img_alt)) {
            if (is_array($img_alt) && is_array($img_alt[0])) {
                foreach ($img_alt[0] as $alt_idx => $alt_img) {
                    // Replace all <img>s within a link with their respective ALT tag, so that references
                    // can be stored with a title.
                    $names[$i] = str_replace($alt_img, $img_alt[1][$alt_idx], $names[$i]);
                }
            }
        }
        $query = "SELECT COUNT(id) FROM {$serendipity['dbPrefix']}references\n                                  WHERE entry_id = " . (int) $id . "\n                                    AND link = '" . serendipity_db_escape_string($locations[$i]) . "'\n                                    AND (type = '' OR type IS NULL)";
        $row = serendipity_db_query($query, true, 'num');
        if (is_string($row)) {
            if (is_object($serendipity['logger'])) {
                $serendipity['logger']->debug($row);
            }
        }
        $names[$i] = strip_tags($names[$i]);
        if (empty($names[$i])) {
            if (is_object($serendipity['logger'])) {
                $serendipity['logger']->debug("Found reference {$locations[$i]} w/o name. Adding location as name");
            }
            $names[$i] = $locations[$i];
        }
        if ($row[0] > 0 && isset($saved_references[$locations[$i] . $names[$i]])) {
            if (is_object($serendipity['logger'])) {
                $serendipity['logger']->debug("Found references for {$id}, skipping rest");
            }
            continue;
        }
        if (!isset($serendipity['noautodiscovery']) || !$serendipity['noautodiscovery']) {
            if (!$dry_run) {
                if (!isset($saved_urls[$locations[$i]])) {
                    if (is_object($serendipity['logger'])) {
                        $serendipity['logger']->debug("Enabling autodiscovery");
                    }
                    serendipity_reference_autodiscover($locations[$i], $url, $author, $title, serendipity_trackback_excerpt($text));
                } else {
                    if (is_object($serendipity['logger'])) {
                        $serendipity['logger']->debug("This reference was already used before in {$id} and therefore will not be trackbacked again");
                    }
                }
            } else {
                if (is_object($serendipity['logger'])) {
                    $serendipity['logger']->debug("Dry run: Skipping autodiscovery");
                }
            }
            $checked_locations[$locations[$i]] = true;
            // Store trackbacked link so that no further trackbacks will be sent to the same link
        } else {
            if (is_object($serendipity['logger'])) {
                $serendipity['logger']->debug("Skipping full autodiscovery");
            }
        }
    }
    $del = serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}references WHERE entry_id=" . (int) $id . " AND (type = '' OR type IS NULL)");
    if (is_string($del)) {
        if (is_object($serendipity['logger'])) {
            $serendipity['logger']->debug($del);
        }
    }
    if (is_object($serendipity['logger'])) {
        $serendipity['logger']->debug("Deleted references again");
    }
    if (!is_array($old_references)) {
        $old_references = array();
    }
    $duplicate_check = array();
    for ($i = 0; $i < $j; ++$i) {
        $i_link = serendipity_db_escape_string(strip_tags($names[$i]));
        $i_location = serendipity_db_escape_string($locations[$i]);
        // No link with same description AND same text should be inserted.
        if (isset($duplicate_check[$i_location . $i_link])) {
            continue;
        }
        if (isset($current_references[$locations[$i] . $names[$i]])) {
            $query = "INSERT INTO {$serendipity['dbPrefix']}references (id, entry_id, name, link) VALUES(";
            $query .= (int) $current_references[$locations[$i] . $names[$i]]['id'] . ", " . (int) $id . ", '" . $i_link . "', '" . $i_location . "')";
            $ins = serendipity_db_query($query);
            if (is_string($ins)) {
                if (is_object($serendipity['logger'])) {
                    $serendipity['logger']->debug($ins);
                }
            }
            $duplicate_check[$locations[$i] . $names[$i]] = true;
        } else {
            $query = "INSERT INTO {$serendipity['dbPrefix']}references (entry_id, name, link) VALUES(";
            $query .= (int) $id . ", '" . $i_link . "', '" . $i_location . "')";
            $ins = serendipity_db_query($query);
            if (is_string($ins)) {
                if (is_object($serendipity['logger'])) {
                    $serendipity['logger']->debug($ins);
                }
            }
            $old_references[] = array('id' => serendipity_db_insert_id('references', 'id'), 'name' => $i_link, 'link' => $i_location, 'entry_id' => (int) $id);
            $duplicate_check[$i_location . $i_link] = true;
        }
        if (is_object($serendipity['logger'])) {
            $serendipity['logger']->debug("Current lookup for {$locations[$i]}{$names[$i]} is" . print_r($current_references[$locations[$i] . $names[$i]], true));
        }
        if (is_object($serendipity['logger'])) {
            $serendipity['logger']->debug($query);
        }
    }
    if (is_object($serendipity['logger'])) {
        $serendipity['logger']->debug(print_r($old_references, true));
    }
    // Add citations
    preg_match_all('@<cite[^>]*>([^<]+)</cite>@i', $text, $matches);
    foreach ($matches[1] as $citation) {
        $query = "INSERT INTO {$serendipity['dbPrefix']}references (entry_id, name) VALUES(";
        $query .= (int) $id . ", '" . serendipity_db_escape_string($citation) . "')";
        $cite = serendipity_db_query($query);
        if (is_string($cite)) {
            if (is_object($serendipity['logger'])) {
                $serendipity['logger']->debug($cite);
            }
        }
    }
}
示例#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;
 }
示例#18
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 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;
 }
示例#19
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('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;
 }
示例#20
0
 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;
 }
/**
 * Inserts a new entry into the database or updates an existing entry
 *
 * Another central function, that parses, prepares and commits changes to an entry
 *
 * @access public
 * @param   array       The new/modified entry data.
 * @return  mixed       Integer with new entry ID if successfull, a string or array if error(s).
 */
function serendipity_updertEntry($entry)
{
    global $serendipity;
    include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
    $errors = array();
    serendipity_plugin_api::hook_event('backend_entry_updertEntry', $errors, $entry);
    if (count($errors) > 0) {
        // Return error message(s)
        return implode("\n", $errors);
    }
    serendipity_plugin_api::hook_event('backend_entry_presave', $entry);
    $categories = $entry['categories'];
    unset($entry['categories']);
    $newEntry = 0;
    $exflag = 0;
    if (isset($entry['properties'])) {
        unset($entry['properties']);
    }
    if (!is_numeric($entry['timestamp'])) {
        $entry['timestamp'] = time();
    }
    /* WYSIWYG-editor inserts empty ' ' for extended body; this is reversed here */
    if (isset($entry['extended']) && (trim($entry['extended']) == '' || trim($entry['extended']) == '<br />' || trim($entry['extended']) == '<p></p>' || str_replace(array("\r", "\n", "\t", "", "<br />", "<p>", "</p>", "<br>"), array('', '', '', '', '', '', '', ''), trim($entry['extended'])) == '')) {
        $entry['extended'] = '';
    }
    if (strlen($entry['extended'])) {
        $exflag = 1;
    }
    $entry['exflag'] = $exflag;
    if (!is_numeric($entry['id'])) {
        /* we need to insert */
        unset($entry['id']);
        $entry['comments'] = 0;
        if (!isset($entry['last_modified']) || !is_numeric($entry['last_modified'])) {
            $entry['last_modified'] = $entry['timestamp'];
        }
        // New entries need an author
        $entry['author'] = $serendipity['user'];
        if (!isset($entry['authorid']) || empty($entry['authorid'])) {
            $entry['authorid'] = $serendipity['authorid'];
        }
        if (!$_SESSION['serendipityRightPublish']) {
            $entry['isdraft'] = 'true';
        }
        if (!isset($entry['allow_comments'])) {
            $entry['allow_comments'] = 'false';
        }
        if (!isset($entry['moderate_comments'])) {
            $entry['moderate_comments'] = 'false';
        }
        $res = serendipity_db_insert('entries', $entry);
        if ($res) {
            $entry['id'] = $serendipity['lastSavedEntry'] = serendipity_db_insert_id('entries', 'id');
            if (is_array($categories)) {
                foreach ($categories as $cat) {
                    if (is_numeric($cat)) {
                        serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entrycat (entryid, categoryid) VALUES ({$entry['id']}, {$cat})");
                    }
                }
            }
            serendipity_insertPermalink($entry);
        } else {
            //Some error message here
            return ENTRIES_NOT_SUCCESSFULLY_INSERTED;
        }
        $newEntry = 1;
    } else {
        /* we need to update */
        // Get settings from entry if already in DB, which should not be alterable with POST methods
        $_entry = serendipity_fetchEntry('id', $entry['id'], 1, 1);
        $entry['authorid'] = $_entry['authorid'];
        if (isset($serendipity['GET']['adminModule']) && $serendipity['GET']['adminModule'] == 'entries' && $entry['authorid'] != $serendipity['authorid'] && !serendipity_checkPermission('adminEntriesMaintainOthers')) {
            // Only chiefs and admins can change other's entry. Else update fails.
            return;
        }
        if (!$_SESSION['serendipityRightPublish']) {
            $entry['isdraft'] = 'true';
        }
        if (is_array($categories)) {
            serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entrycat WHERE entryid={$entry['id']}");
            foreach ($categories as $cat) {
                serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entrycat (entryid, categoryid) VALUES ({$entry['id']}, {$cat})");
            }
        }
        //if (!serendipity_db_bool($entry['isdraft']) && !serendipity_db_bool($_entry['isdraft'])) {
        $entry['last_modified'] = time();
        //}
        $res = serendipity_db_update('entries', array('id' => $entry['id']), $entry);
        $newEntry = 0;
        serendipity_updatePermalink($entry);
    }
    if (is_string($res)) {
        return $res;
    }
    // Reset session data, so that a reload to this frame should not happen!
    $_SESSION['save_entry']['id'] = (int) $entry['id'];
    if (!serendipity_db_bool($entry['isdraft'])) {
        serendipity_plugin_api::hook_event('frontend_display', $entry, array('no_scramble' => true, 'from' => 'functions_entries:updertEntry'));
        $drafted_entry = $entry;
    }
    serendipity_purgeEntry($entry['id'], $entry['timestamp']);
    if (!serendipity_db_bool($entry['isdraft']) && $entry['timestamp'] <= serendipity_serverOffsetHour()) {
        // When saving an entry, first all references need to be gathered. But trackbacks to them
        // shall only be send at the end of the execution flow. However, certain plugins depend on
        // the existance of handled references. Thus we store the current references at this point,
        // execute the plugins and then reset the found references to the original state.
        serendipity_handle_references($entry['id'], $serendipity['blogTitle'], $drafted_entry['title'], $drafted_entry['body'] . $drafted_entry['extended'], true);
    }
    // Send publish tags if either a new article has been inserted from scratch, or if the entry was previously
    // stored as draft and is now published
    $entry['categories'] =& $categories;
    if (!serendipity_db_bool($entry['isdraft']) && ($newEntry || serendipity_db_bool($_entry['isdraft']))) {
        serendipity_plugin_api::hook_event('backend_publish', $entry, $newEntry);
    } else {
        serendipity_plugin_api::hook_event('backend_save', $entry, $newEntry);
    }
    if (!serendipity_db_bool($entry['isdraft']) && $entry['timestamp'] <= serendipity_serverOffsetHour()) {
        // Now that plugins are executed, we go ahead into the Temple of Doom and send possibly failing trackbacks.
        // First, original list of references is restored (inside the function call)
        serendipity_handle_references($entry['id'], $serendipity['blogTitle'], $drafted_entry['title'], $drafted_entry['body'] . $drafted_entry['extended'], false);
    }
    return (int) $entry['id'];
}
function wp_newCategory($message)
{
    global $serendipity;
    $val = $message->params[1];
    $username = $val->getval();
    $val = $message->params[2];
    $password = $val->getval();
    if (!serendipity_authenticate_author($username, $password)) {
        return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
    }
    $val = $message->params[3];
    if (is_object($val)) {
        $cat = XML_RPC_decode($val);
        $category = array();
        $category['category_name'] = $cat['name'];
        $category['category_description'] = $cat['description'];
        if (!empty($cat['parent_id'])) {
            $category['parentid'] = $cat['parent_id'];
        }
        if (serendipity_db_insert('category', $category)) {
            $saved = serendipity_fetchCategoryInfo(0, $cat['name']);
            $saved_id = $saved['categoryid'];
            return new XML_RPC_Response(new XML_RPC_Value($saved_id, 'i4'));
        }
    }
    return new XML_RPC_Response('', 99, 'Error writing category');
}
示例#23
0
 /**
  * Set cache information about a plugin
  *
  * @access public
  * @param   mixed       Either an plugin object or a plugin information array that holds the information about the plugin
  * @param   string      The filename of the plugin
  * @param   object      The property bag object bundled with the plugin
  * @param   array       Previous/additional information about the plugin
  * @param   string      The location/type of a plugin (local|spartacus)
  * @return
  */
 function &setPluginInfo(&$plugin, &$pluginFile, &$bag, &$class_data, $pluginlocation = 'local')
 {
     global $serendipity;
     static $dbfields = array('plugin_file', 'class_name', 'plugin_class', 'pluginPath', 'name', 'description', 'version', 'upgrade_version', 'plugintype', 'pluginlocation', 'stackable', 'author', 'requirements', 'website', 'last_modified');
     serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}pluginlist WHERE plugin_file = '" . serendipity_db_escape_string($pluginFile) . "' AND pluginlocation = '" . serendipity_db_escape_string($pluginlocation) . "'");
     if (!empty($pluginFile) && file_exists($pluginFile)) {
         $lastModified = filemtime($pluginFile);
     } else {
         $lastModified = 0;
     }
     if (is_object($plugin)) {
         $data = array('class_name' => get_class($plugin), 'stackable' => $bag->get('stackable'), 'name' => $bag->get('name'), 'description' => $bag->get('description'), 'author' => $bag->get('author'), 'version' => $bag->get('version'), 'upgrade_version' => isset($class_data['upgrade_version']) ? $class_data['upgrade_version'] : $bag->get('version'), 'requirements' => serialize($bag->get('requirements')), 'website' => $bag->get('website'), 'plugin_class' => $class_data['name'], 'pluginPath' => $class_data['pluginPath'], 'plugin_file' => $pluginFile, 'pluginlocation' => $pluginlocation, 'plugintype' => $serendipity['GET']['type'], 'last_modified' => $lastModified);
         $groups = $bag->get('groups');
     } elseif (is_array($plugin)) {
         $data = $plugin;
         $groups = $data['groups'];
         unset($data['installable']);
         unset($data['true_name']);
         unset($data['customURI']);
         unset($data['groups']);
         if (isset($data['pluginpath'])) {
             $data['pluginPath'] = $data['pluginpath'];
         }
         $data['requirements'] = serialize($data['requirements']);
     }
     if (!isset($data['stackable']) || empty($data['stackable'])) {
         $data['stackable'] = '0';
     }
     if (!isset($data['last_modified'])) {
         $data['last_modified'] = $lastModified;
     }
     // Only insert data keys that exist in the DB.
     $insertdata = array();
     foreach ($dbfields as $field) {
         $insertdata[$field] = $data[$field];
     }
     if ($data['upgradable']) {
         serendipity_db_query("UPDATE {$serendipity['dbPrefix']}pluginlist\n                                     SET upgrade_version = '" . serendipity_db_escape_string($data['upgrade_version']) . "'\n                                   WHERE plugin_class    = '" . serendipity_db_escape_string($data['plugin_class']) . "'");
     }
     serendipity_db_insert('pluginlist', $insertdata);
     serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}plugincategories WHERE class_name = '" . serendipity_db_escape_string($data['class_name']) . "'");
     foreach ((array) $groups as $group) {
         if (empty($group)) {
             continue;
         }
         $cat = array('class_name' => $data['class_name'], 'category' => $group);
         serendipity_db_insert('plugincategories', $cat);
     }
     $data['groups'] = $groups;
     return $data;
 }
示例#24
0
 function importCategories($parentname = 'root', $parentid = 0, $txpdb)
 {
     $res = $this->nativeQuery("SELECT * FROM {$this->data['prefix']}txp_category\n                                     WHERE parent = '" . mysql_escape_string($parentname) . "' AND type = 'article'", $txpdb);
     if (!$res) {
         echo mysql_error();
         return false;
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $row = mysql_fetch_assoc($res);
         $cat = array('category_name' => $row['name'], 'category_description' => $row['name'], 'parentid' => $parentid, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $row['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
         $this->categories[] = $row;
         $this->importCategories($row['name'], $row['categoryid'], $txpdb);
     }
     return true;
 }
 function twitterGet($url)
 {
     global $serendipity;
     $page = 1;
     // Twitter starts with page 1!
     $has_more = true;
     $last_tweetid = 0;
     $failsafe = 50;
     // Maximum of pages. I don't think it should ever get this high.
     while ($has_more) {
         if ($this->debug) {
             $this->debugOut("Getting {$url}{$page}.");
         }
         $out = file_get_contents($url . $page);
         $page++;
         $current_count = 0;
         if (empty($out) || $page > $failsafe) {
             if ($this->debug) {
                 $this->debugOut("No more results! (Failsafe?)");
             }
             $has_more = false;
         }
         $data = json_decode($out);
         if (!is_array($data)) {
             if ($this->debug) {
                 $this->debugOut("No result set.");
             }
         } else {
             foreach ($data as $twitter_obj) {
                 if (!is_object($twitter_obj) || empty($twitter_obj->id)) {
                     continue;
                 }
                 $current_count++;
                 $twitter_db = array('id' => $twitter_obj->id, 'tweetdate' => strtotime($twitter_obj->created_at), 'tweet' => $twitter_obj->text, 'reply_to_status' => $twitter_obj->in_reply_to_status_id, 'reply_to_user' => $twitter_obj->in_reply_to_user_id, 'username' => $twitter_obj->user->name, 'source' => $twitter_obj->source);
                 if ($last_tweetid == 0) {
                     $last_tweetid = $twitter_obj->id;
                 }
                 $db_result = serendipity_db_insert('tweets', $twitter_db);
                 if ($this->debug) {
                     $this->debugOut("Got #{$current_count}: " . substr($twitter_obj->text, 0, 15) . " dbresult:{$db_result}");
                 }
             }
         }
         if ($current_count < 100) {
             if ($this->debug) {
                 $this->debugOut("No more pages.");
             }
             $has_more = false;
         }
     }
     if ($this->debug) {
         $this->debugOut("Storing last tweet: {$last_tweetid}");
     }
     if ($last_tweetid > 0) {
         $this->set_config('last_tweetid', $last_tweetid);
     }
 }
 /**
  * Sets or deletes properties for this category from the database.
  * @param int cid The category ID to use
  * @param array val optional An array associating SQL column names with
  *     their desired values (default false)
  * @param bool deleteOnly optional Whether to skip inserting new values (default false)
  * @return true
  */
 function setProps($cid, $val = false, $deleteOnly = false)
 {
     global $serendipity;
     serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}categorytemplates\n                                    WHERE categoryid = " . (int) $cid);
     if ($deleteOnly === false) {
         $db = serendipity_db_insert('categorytemplates', $val, 'execute');
         return $db;
     }
     return true;
 }
示例#27
0
 function importCategories($parentid = 0, $new_parentid = 0, $ltdb)
 {
     if (is_null($parentid)) {
         $where = 'WHERE parent_id = 0';
     } else {
         $where = "WHERE parent_id = '" . mysql_escape_string($parentid) . "'";
     }
     $res = $this->nativeQuery("SELECT name AS cat_name,\n                                          description AS cat_description,\n                                          id AS cat_ID\n                                     FROM lt_articles_categories\n                                     " . $where, $ltdb);
     if (!$res) {
         echo mysql_error();
         return false;
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $row = mysql_fetch_assoc($res);
         $cat = array('category_name' => $row['cat_name'], 'category_description' => $row['cat_description'], 'parentid' => (int) $new_parentid, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $row['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
         $this->categories[] = $row;
         $this->importCategories($row['cat_ID'], $row['categoryid'], $ltdb);
     }
     return true;
 }
示例#28
0
 static function updateOpenID($openid_url, $authorID)
 {
     global $serendipity;
     if (!is_array(serendipity_db_query("SELECT username FROM {$serendipity['dbPrefix']}openid_authors LIMIT 1", true, 'both', false, false, false, true))) {
         serendipity_db_schema_import("CREATE TABLE {$serendipity['dbPrefix']}openid_authors (\r\n              openid_url varchar(255) default null,\r\n              hash varchar(32) default null,\r\n              authorid int(11) default '0'\r\n            );");
     }
     $hash = md5($openid_url);
     if (serendipity_common_openid::getOpenID($authorID, true)) {
         $retVal = serendipity_db_update('openid_authors', array('authorid' => $authorID), array('openid_url' => $openid_url, 'hash' => $hash));
     } else {
         $retVal = serendipity_db_insert('openid_authors', array('openid_url' => $openid_url, 'hash' => $hash, 'authorid' => $authorID));
     }
     return $retVal === true ? true : false;
 }
示例#29
0
 function importCategories($parentid = 0, $new_parentid = 0, $sunlogdb)
 {
     $where = "WHERE parent = '" . mysql_escape_string($parentid) . "'";
     $res = $this->nativeQuery("SELECT * FROM {$this->data['prefix']}categories\n                                     " . $where, $sunlogdb);
     if (!$res) {
         echo mysql_error();
         return false;
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) {
         $row = mysql_fetch_assoc($res);
         $cat = array('category_name' => $row['title'], 'category_description' => $row['optional_1'] . ' ' . $row['optional_2'] . ' ' . $row['optional_3'], 'parentid' => (int) $new_parentid, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $row['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
         $this->categories[] = $row;
         $this->importCategories($row['id'], $row['categoryid'], $sunlogdb);
     }
     return true;
 }
 /**
  * -stm:
  * set the pair (categoryid, staticpage) for a given categoryid
  *
  * @return true
  *
  */
 function setCatProps($cid, $val = false, $deleteOnly = false)
 {
     global $serendipity;
     if (debug_staticpage == 'true') {
         echo "category ";
         echo $cid;
         echo " staticpage ";
         echo $val['staticpage_categorypage'];
     }
     serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}staticpage_categorypage\n                                    WHERE categoryid = " . (int) $cid);
     if ($deleteOnly === false) {
         return serendipity_db_insert('staticpage_categorypage', $val);
     }
     return true;
 }