コード例 #1
0
ファイル: bblog.inc.php プロジェクト: vonnordmann/Serendipity
 function import()
 {
     global $serendipity;
     // Save this so we can return it to its original value at the end of this method.
     $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     $this->getTransTable();
     $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
     $users = array();
     $entries = array();
     if (!extension_loaded('mysqli')) {
         return MYSQL_REQUIRED;
     }
     $bblogdb = @mysqli_connect($this->data['host'], $this->data['user'], $this->data['pass']);
     if (!$bblogdb || mysqli_connect_error()) {
         return sprintf(COULDNT_CONNECT, serendipity_specialchars($this->data['host']));
     }
     if (!@mysqli_select_db($bblogdb, $this->data['name'])) {
         return sprintf(COULDNT_SELECT_DB, mysqli_error($bblogdb));
     }
     /* Users */
     $res = @$this->nativeQuery("SELECT id         AS ID,\n                                    password   AS pw,\n                                    nickname   AS user_login,\n                                    email      AS user_email,\n                                    url        AS user_url\n                               FROM {$this->data['prefix']}authors", $bblogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_USER_INFO, mysqli_error($bblogdb));
     }
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $users[$x] = mysqli_fetch_assoc($res);
         $data = array('right_publish' => 1, 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'userlevel' => USERLEVEL_ADMIN, 'password' => md5($users[$x]['pw']));
         // Wicked. This is the first blog I've seen storing cleartext passwords :-D
         if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
             $data['userlevel'] = $serendipity['serendipityUserlevel'];
         }
         serendipity_db_insert('authors', $this->strtrRecursive($data));
         echo mysqli_error();
         $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
     }
     /* Categories */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}sections", $bblogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysqli_error($bblogdb));
     }
     // Get all the info we need
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $row = mysqli_fetch_assoc($res);
         $cat = array('category_name' => $row['nicename'], 'category_description' => $row['nicename'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
         serendipity_db_insert('category', $this->strtrRecursive($cat));
         $row['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
         $this->categories[] = $row;
     }
     serendipity_rebuildCategoryTree();
     /* Entries */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts ORDER BY postid;", $bblogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_ENTRY_INFO, mysqli_error($bblogdb));
     }
     for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) {
         $entries[$x] = mysqli_fetch_assoc($res);
         $entry = array('title' => $this->decode($entries[$x]['title']), 'isdraft' => $entries[$x]['status'] == 'live' ? 'false' : 'true', 'allow_comments' => $entries[$x]['allowcomments'] == 'allow' ? 'true' : 'false', 'timestamp' => $entries[$x]['posttime'], 'body' => $this->strtr($entries[$x]['body']), 'extended' => '');
         $entry['authorid'] = '';
         $entry['author'] = '';
         foreach ($users as $user) {
             if ($user['ID'] == $entries[$x]['author']) {
                 $entry['authorid'] = $user['authorid'];
                 $entry['author'] = $user['user_login'];
                 break;
             }
         }
         if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
             return $entries[$x]['entryid'];
         }
         $sections = explode(':', $entries[$x]['sections']);
         foreach ($sections as $section) {
             if (empty($section)) {
                 continue;
             }
             foreach ($this->categories as $category) {
                 if ($category['sectionid'] == $section) {
                     $categoryid = $category['categoryid'];
                 }
             }
             if ($categoryid > 0) {
                 $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $categoryid);
                 serendipity_db_insert('entrycat', $this->strtrRecursive($data));
             }
         }
     }
     /* Comments */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments WHERE type = 'comment';", $bblogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($bblogdb));
     }
     while ($a = mysqli_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['postid'] == $a['postid']) {
                 $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['posttime'], 'author' => $a['postername'], 'email' => $a['posteremail'], 'url' => $a['posterwebsite'], 'ip' => $a['ip'], 'status' => 'approved', 'body' => $a['commenttext'], 'subscribed' => 'false', 'type' => 'NORMAL');
                 serendipity_db_insert('comments', $this->strtrRecursive($comment));
                 $cid = serendipity_db_insert_id('comments', 'id');
                 serendipity_approveComment($cid, $entry['entryid'], true);
             }
         }
     }
     /* Trackbacks */
     $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments WHERE type = 'trackback';", $bblogdb);
     if (!$res) {
         return sprintf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($bblogdb));
     }
     while ($a = mysqli_fetch_assoc($res)) {
         foreach ($entries as $entry) {
             if ($entry['postid'] == $a['postid']) {
                 $trackback = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['posttime'], 'title' => $a['title'], 'author' => $a['postername'], 'email' => $a['posteremail'], 'url' => $a['posterwebsite'], 'ip' => $a['ip'], 'status' => 'approved', 'body' => $a['commenttext'], 'subscribed' => 'false', 'type' => 'TRACKBACK');
                 serendipity_db_insert('comments', $this->strtrRecursive($trackback));
                 $cid = serendipity_db_insert_id('comments', 'id');
                 serendipity_approveComment($cid, $entry['entryid'], true);
             }
         }
     }
     $serendipity['noautodiscovery'] = $noautodiscovery;
     // That was fun.
     return true;
 }
コード例 #2
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;
 }
コード例 #3
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;
 }
コード例 #4
0
ファイル: nucleus.inc.php プロジェクト: rustyx/Serendipity
 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;
 }
コード例 #5
0
/**
 * Insert a media item in the database
 *
 * @access public
 * @param   string      The filename of the media item
 * @param   string      The path to the media item
 * @param   int         The owner author of the item
 * @param   int         The timestamp of when the media item was inserted
 * @return  int         The new media ID
 */
function serendipity_insertImageInDatabase($filename, $directory, $authorid = 0, $time = NULL, $realname = NULL)
{
    global $serendipity;
    if (is_null($time)) {
        $time = time();
    }
    if (is_null($realname)) {
        $realname = $filename;
    }
    $filepath = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $directory . $filename;
    $filesize = @filesize($filepath);
    list($filebase, $extension) = serendipity_parseFileName($filename);
    $thumbpath = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $directory . $filebase . '.' . $serendipity['thumbSuffix'] . '.' . $extension;
    $thumbnail = file_exists($thumbpath) ? $serendipity['thumbSuffix'] : '';
    $fdim = @serendipity_getimagesize($filepath, '', $extension);
    $width = $fdim[0];
    $height = $fdim[1];
    $mime = $fdim['mime'];
    $query = sprintf("INSERT INTO {$serendipity['dbPrefix']}images (\n                    name,\n                    extension,\n                    mime,\n                    size,\n                    dimensions_width,\n                    dimensions_height,\n                    thumbnail_name,\n                    date,\n                    authorid,\n                    path,\n                    realname\n                   ) VALUES (\n                    '%s',\n                    '%s',\n                    '%s',\n                    %s,\n                    %s,\n                    %s,\n                    '%s',\n                    %s,\n                    %s,\n                    '%s',\n                    '%s'\n                   )", serendipity_db_escape_string($filebase), serendipity_db_escape_string($extension), serendipity_db_escape_string($mime), (int) $filesize, (int) $width, (int) $height, serendipity_db_escape_string($thumbnail), (int) $time, (int) $authorid, serendipity_db_escape_string($directory), serendipity_db_escape_string($realname));
    $sql = serendipity_db_query($query);
    if (is_string($sql)) {
        echo $query . '<br />';
        echo $sql . '<br />';
    }
    $image_id = serendipity_db_insert_id('images', 'id');
    if ($image_id > 0) {
        return $image_id;
    }
    return 0;
}
コード例 #6
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;
 }
コード例 #7
0
 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";
     }
 }
コード例 #8
0
 function fetchFeeds($opt = null)
 {
     global $serendipity;
     set_time_limit(360);
     ignore_user_abort(true);
     $_SESSION['serendipityRightPublish'] = true;
     $serendipity['noautodiscovery'] = true;
     $this->setupDB();
     $feeds = $this->getFeeds($opt);
     $engine = $this->get_config('engine', 'onyx');
     if ($engine == 'onyx') {
         require_once (defined('S9Y_PEAR_PATH') ? S9Y_PEAR_PATH : S9Y_INCLUDE_PATH . 'bundled-libs/') . 'Onyx/RSS.php';
     } elseif ($engine == 'magpierss') {
         // CLSC: NEW "MagpieRSS" include
         require_once dirname(__FILE__) . '/magpierss/rss_fetch.inc';
     } elseif ($engine == 'simplepie') {
         //hwa: NEW "SimplePie" include
         require_once dirname(__FILE__) . '/simplepie/simplepie.inc';
     }
     $cache_authors = array();
     $cache_entries = array();
     $cache_md5 = array();
     $sql_cache_authors = serendipity_db_Query("SELECT authorid, realname\n                                                 FROM {$serendipity['dbPrefix']}authors");
     if (is_array($sql_cache_authors)) {
         foreach ($sql_cache_authors as $idx => $author) {
             $cache_authors[$author['realname']] = $author['authorid'];
         }
     }
     if ($this->debug) {
         printf("DEBUG: cache_authors['realname'] = authorid has %d entries\n", count($cache_authors));
     }
     if ($opt['store_seperate']) {
         $sql_cache_entries = serendipity_db_query("SELECT e.feedid, e.id, e.entrydate, e.entrytitle\n                                                         FROM {$serendipity['dbPrefix']}aggregator_feedlist AS e");
         if (is_array($sql_cache_entries)) {
             foreach ($sql_cache_entries as $idx => $entry) {
                 $cache_entries[$entry['entrytitle']][$entry['feedid']][$entry['entrydate']] = $entry['id'];
             }
         }
     } else {
         $sql_cache_entries = serendipity_db_query("SELECT e.id, e.timestamp, e.authorid, e.title, ep.value\n                                                         FROM {$serendipity['dbPrefix']}entries AS e,\n                                                              {$serendipity['dbPrefix']}entryproperties AS ep\n                                                        WHERE e.id = ep.entryid\n                                                          AND ep.property = 'ep_aggregator_feed'");
         if (is_array($sql_cache_entries)) {
             foreach ($sql_cache_entries as $idx => $entry) {
                 $cache_entries[$entry['title']][$entry['authorid']][$entry['timestamp']] = $entry['id'];
             }
         }
     }
     if ($this->debug) {
         printf("DEBUG: cache_entries['title']['authorid']['timestamp'] = entryid has %d entries.\n", count($cache_entries));
     }
     $sql_cache_md5 = serendipity_db_query("SELECT entryid, md5, timestamp\n                                                     FROM {$serendipity['dbPrefix']}aggregator_md5");
     if (is_array($sql_cache_md5)) {
         foreach ($sql_cache_md5 as $idx => $entry) {
             $cache_md5[$entry['md5']]['entryid'] = $entry['entryid'];
             $cache_md5[$entry['md5']]['timestamp'] = $entry['timestamp'];
         }
     }
     if ($this->debug) {
         printf("DEBUG: cache_md5['md5'] = entryid has %d entries.\n", count($cache_md5));
     }
     foreach ($feeds as $feed) {
         if (!$opt['store_seperate']) {
             printf("Read %s.\n", $feed['feedurl']);
         }
         flush();
         $feed_authorid = $cache_authors[$feed['feedname']];
         if (empty($feed_authorid)) {
             $feed_authorid = 0;
         }
         if ($this->debug) {
             printf("DEBUG: Current authorid = %d\n", $feed_authorid);
         }
         $stack = array();
         if ($engine == 'onyx') {
             if (empty($feed['charset'])) {
                 $this->checkCharset($feed);
             }
             # test multiple likely charsets
             $charsets = array($feed['charset'], "ISO-8859-1", "utf-8");
             $retry = false;
             foreach ($charsets as $ch) {
                 if ($retry) {
                     printf("DEBUG: Retry with charset %s instead of %s\n", $ch, $feed['charset']);
                 }
                 $retry = true;
                 $c = new Onyx_RSS($ch);
                 # does it parse? if so, all is fine...
                 if ($c->parse($feed['feedurl'])) {
                     break;
                 }
             }
             while ($item = $c->getNextItem()) {
                 /* Okay this is where things get tricky. Everybody
                  * encodes their information differently. For now I'm going to focus on
                  * s9y weblogs. */
                 $fake_timestamp = false;
                 $date = $this->parseDate($item['pubdate']);
                 if ($this->debug) {
                     printf("DEBUG: pubDate %s = %s\n", $item['pubdate'], $date);
                 }
                 if ($date == -1) {
                     // Fallback to try for dc:date
                     $date = $this->parseDate($item['dc:date']);
                     if ($this->debug) {
                         printf("DEBUG: falling back to dc:date % s= %s\n", $item['dc:date'], $date);
                     }
                 }
                 if ($date == -1) {
                     // Couldn't figure out the date string. Set it to "now" and hope that the md5hash will get it.
                     $date = time();
                     $fake_timestamp = true;
                     if ($this->debug) {
                         printf("DEBUG: falling back to time() = %s\n", $date);
                     }
                 }
                 if (empty($item['title'])) {
                     if ($this->debug) {
                         printf("DEBUG: skip item: title was empty for %s\n", print_r($item, true));
                     }
                     continue;
                 }
                 $this->decode($c->rss['encoding'], $item);
                 $item['date'] = $date;
                 $stack[] = $item;
             }
         } elseif ($engine == 'magpierss') {
             // ----------------------------------------------------------
             // CLSC: New MagpieRSS code start
             // ----------------------------------------------------------
             $rss = fetch_rss($feed['feedurl']);
             foreach ($rss->items as $item) {
                 $fake_timestamp = false;
                 $date = $item['pubdate'];
                 if ($this->debug) {
                     printf("DEBUG: pubdate = %s\n", $item['pubdate'], $date);
                 }
                 // ----------------------------------------------------------
                 // CLSC:        Try a few different types of timestamp fields
                 //                So that we might get lucky even with non-standard feeds
                 // ----------------------------------------------------------
                 if ($date == "") {
                     // CLSC: magpie syntax for nested fields
                     $date = $item['dc']['date'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to [dc][date] = %s\n", $item['dc:date'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['modified'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to modified = %s\n", $item['modified'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['PubDate'];
                     if ($this->debug) {
                         printf("DEBUG: falling back PubDate = %s\n", $item['PubDate'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['created'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to created = %s\n", $item['created'], $date);
                     }
                 }
                 if ($date == "") {
                     // CLSC: not proper magpie syntax but still catches some
                     $date = $item['dc:date'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to dc:date = %s\n", $item['dc:date'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['updated'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to updated = %s\n", $item['updated'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['published'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to published = %s\n", $item['published'], $date);
                     }
                 }
                 if ($date == "") {
                     // ----------------------------------------------------------
                     //    CLSC:        If none of the above managed to identify a date:
                     //                 Set date to "now" and hope that the md5hash will get it.
                     // ----------------------------------------------------------
                     $date = time();
                     $fake_timestamp = true;
                     if ($this->debug) {
                         printf("DEBUG: falling back to time() = %s\n", $date);
                     }
                 }
                 // CLSC: if date is set to "now" parseDate can't parse it.
                 if ($fake_timestamp != true) {
                     $date = $this->parseDate($date);
                 }
                 if ($item['title'] == "") {
                     if ($this->debug) {
                         printf("DEBUG: skip item: title was empty for %s\n", print_r($item, true));
                     }
                     continue;
                 }
                 $item['date'] = $date;
                 $stack[] = $item;
                 // ----------------------------------------------------------
                 //    CLSC: New MagpieRSS code end
                 // ----------------------------------------------------------
             }
         } elseif ($engine == 'simplepie') {
             // hwa: new SimplePie code  ; lifted from the SimplePie demo
             $simplefeed = new SimplePie();
             $simplefeed->cache = false;
             $simplefeed->set_feed_url($feed['feedurl']);
             // Initialize the whole SimplePie object.  Read the feed, process it, parse it, cache it, and
             // all that other good stuff.  The feed's information will not be available to SimplePie before
             // this is called.
             $success = $simplefeed->init();
             // We'll make sure that the right content type and character encoding gets set automatically.
             // This function will grab the proper character encoding, as well as set the content type to text/html.
             $simplefeed->set_output_encoding(LANG_CHARSET);
             $simplefeed->handle_content_type();
             $item['new_feedicon'] = $simplefeed->get_favicon();
             // error handling
             if ($simplefeed->error()) {
                 if (!$opt['store_seperate']) {
                     printf('<p><b>ERROR:</b> ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($simplefeed->error()) : htmlspecialchars($simplefeed->error(), ENT_COMPAT, LANG_CHARSET)) . "</p>\r\n");
                 }
             }
             if ($success) {
                 foreach ($simplefeed->get_items() as $simpleitem) {
                     // map SimplePie items to s9y items
                     $item['title'] = $simpleitem->get_title();
                     $item['date'] = $simpleitem->get_date('U');
                     $item['pubdate'] = $simpleitem->get_date('U');
                     $item['description'] = $simpleitem->get_description();
                     $item['content'] = $simpleitem->get_content();
                     $item['link'] = $simpleitem->get_permalink();
                     $item['author'] = $simpleitem->get_author();
                     //if ($this->debug) {
                     //  printf("DEBUG: SimplePie item: author: $item['author'], title: $item['title'], date: $item['date']\n");
                     //}
                     $stack[] = $item;
                 }
             } else {
                 if (!$opt['store_seperate']) {
                     printf('<p><b>ERROR:</b> ' . print_r($success, true) . "</p>\r\n");
                 }
             }
         }
         while (list($key, $item) = each($stack)) {
             if ($opt['store_seperate']) {
                 $ep_id = $cache_entries[$item['title']][$feed['feedid']][$item['date']];
                 if ($this->debug) {
                     printf("DEBUG: lookup cache_entries[%s][%s][%s] finds %s.\n", $item['title'], $feed['feedid'], $item['date'], empty($ep_id) ? "nothing" : $ep_id);
                 }
             } else {
                 $ep_id = $cache_entries[$item['title']][$feed_authorid][$item['date']];
                 if ($this->debug) {
                     printf("DEBUG: lookup cache_entries[%s][%s][%s] finds %s.\n", $item['title'], $feed_authorid, $item['date'], empty($ep_id) ? "nothing" : $ep_id);
                 }
             }
             if (!empty($ep_id) and serendipity_db_bool($this->get_config('ignore_updates'))) {
                 if ($this->debug) {
                     printf("DEBUG: entry %s is known and ignore_updates is set.\n", $ep_id);
                 }
                 continue;
             }
             # NOTE: If $ep_id is NULL or EMPTY, it means that an entry with this title does not
             #       yet exist. Later on we check if a similar entry with the body exists and skip
             #       updates in this case. Else it means that the new entry needs to be inserted
             #       as a new one.
             # The entry is probably new?
             $entry = array('id' => $ep_id, 'title' => $item['title'], 'timestamp' => $item['date'], 'extended' => '', 'isdraft' => serendipity_db_bool($this->get_config('publishflag')) ? 'false' : 'true', 'allow_comments' => serendipity_db_bool($this->get_config('allow_comments')) ? 'true' : 'false', 'categories' => $feed['categoryids'], 'author' => $feed['feedname'], 'authorid' => $feed_authorid);
             // ----------------------------------------------------------
             //    CLSC: Added a few flavours
             if ($item['content:encoded']) {
                 $entry['body'] = $item['content:encoded'];
             } elseif ($item['description']) {
                 $entry['body'] = $item['description'];
             } elseif ($item['content']['encoded']) {
                 $entry['body'] = $item['content']['encoded'];
             } elseif ($item['atom_content']) {
                 $entry['body'] = $item['atom_content'];
             } elseif ($item['content']) {
                 $entry['body'] = $item['content'];
             }
             $md5hash = md5($feed_authorid . $item['title'] . $entry['body']);
             # Check 1: Have we seen this MD5?
             if ($this->debug) {
                 printf("DEBUG: lookup cache_md5[%s] finds %s.\n", $md5hash, empty($cache_md5[$md5hash]) ? "nothing" : $cache_md5[$md5hash]['entryid']);
             }
             # If we have this md5, title and body for this article
             # are unchanged. We do not need to do anything.
             if (isset($cache_md5[$md5hash])) {
                 continue;
             }
             # Check 2 (conditional: expire enabled?):
             #         Is this article too old?
             if ($this->get_config('expire') > 0) {
                 $expire = time() - 86400 * $this->get_config('expire');
                 if ($item['date'] < $expire) {
                     if ($this->debug) {
                         printf("DEBUG: '%s' is too old (%s < %s).\n", $item['title'], $item['date'], $expire);
                     }
                     continue;
                 }
             }
             # Check 3: Does this article match our expressions?
             if (!empty($feed['match_expression'])) {
                 $expressions = explode("~", $feed['match_expression']);
                 $match = 0;
                 foreach ($expressions as $expression) {
                     $expression = ltrim(rtrim($expression));
                     if (preg_match("~{$expression}~imsU", $entry['title'] . $entry['body'])) {
                         $match = 1;
                     }
                 }
                 if ($match == 0) {
                     continue;
                 }
             }
             $feed['articleurl'] = $item['link'];
             if ($item['author']) {
                 $feed['author'] = $item['author'];
             } elseif ($item['dc:creator']) {
                 $feed['author'] = $item['dc:creator'];
             }
             // Store as property
             // Plugins might need this.
             $serendipity['POST']['properties'] = array('fake' => 'fake');
             $markups = explode('^', $this->get_config('markup'));
             if (is_array($markups)) {
                 foreach ($markups as $markup) {
                     $serendipity['POST']['properties']['disable_markups'][] = $markup;
                 }
             }
             if ($opt['store_seperate']) {
                 if ($entry['id'] > 0) {
                     serendipity_db_query("UPDATE {$serendipity['dbPrefix']}aggregator_feedlist \n                        SET feedid      = '" . $feed['feedid'] . "',\n                            categoryid  = '" . $feed['categoryids'][0] . "',\n                            entrydate   = '" . serendipity_db_escape_string($entry['timestamp']) . "',\n                            entrytitle  = '" . serendipity_db_escape_string($entry['title']) . "',\n                            entrybody   = '" . serendipity_db_escape_string($entry['body']) . "',\n                            entryurl    = '" . serendipity_db_escape_string($item['link']) . "'\n                        WHERE id = " . $entry['id']);
                     $entryid = $entry['id'];
                 } else {
                     serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}aggregator_feedlist (\n                            feedid,\n                            categoryid,\n                            entrydate,\n                            entrytitle,\n                            entrybody,\n                            entryurl\n                        ) VALUES (\n                            '" . $feed['feedid'] . "',\n                            '" . $feed['categoryids'][0] . "',\n                            '" . serendipity_db_escape_string($entry['timestamp']) . "',\n                            '" . serendipity_db_escape_string($entry['title']) . "',\n                            '" . serendipity_db_escape_string($entry['body']) . "',\n                            '" . serendipity_db_escape_string($item['link']) . "'\n                        )");
                     $entryid = serendipity_db_insert_id();
                 }
                 $this->feedupdate_finish($feed, $entryid);
             } else {
                 $entryid = serendipity_updertEntry($entry);
                 $this->insertProperties($entryid, $feed, $md5hash);
             }
             if (!$opt['store_seperate']) {
                 printf(" Save '%s' as %s.\n", $item['title'], $entryid);
             }
         }
         if (!$opt['store_seperate']) {
             printf("Finish feed.\n");
         }
     }
     if (!$opt['store_seperate']) {
         printf("Finish planetarium.\n");
     }
 }
コード例 #9
0
ファイル: pivot.inc.php プロジェクト: vonnordmann/Serendipity
 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;
 }
コード例 #10
0
ファイル: smf.inc.php プロジェクト: rustyx/Serendipity
 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;
 }
コード例 #11
0
    function shownotes()
    {
        global $serendipity;
        if ($serendipity['version'][0] < 2) {
            echo '<h3>' . PLUGIN_ADMINNOTES_TITLE . '</h3>';
        } else {
            echo '<h2>' . PLUGIN_ADMINNOTES_TITLE . '</h2>';
        }
        if (!serendipity_db_bool($this->get_config('feedback')) && $serendipity['serendipityUserlevel'] < USERLEVEL_CHIEF) {
            return false;
        }
        switch ($_REQUEST['action']) {
            case 'edit':
                $entry = $this->getMyNotes((int) $_REQUEST['note']);
                $mode = 'update';
            case 'new':
                if (!isset($mode)) {
                    $mode = 'insert';
                }
                if (!is_array($entry)) {
                    $entry = array();
                }
                if ($_REQUEST['submit']) {
                    $valid_groups = serendipity_getAllGroups($serendipity['authorid']);
                    $targets = array();
                    if (is_array($_REQUEST['note_target'])) {
                        foreach ($_REQUEST['note_target'] as $groupid) {
                            $found = false;
                            foreach ($valid_groups as $group) {
                                if ($group['confkey'] == $groupid) {
                                    $found = true;
                                    break;
                                }
                            }
                            if ($found) {
                                $targets[] = (int) $groupid;
                            }
                        }
                    }
                    if ($mode == 'update') {
                        $noteid = (int) $_REQUEST['note'];
                        $q = serendipity_db_query("UPDATE {$serendipity['dbPrefix']}adminnotes\n                                                 SET authorid = {$serendipity['authorid']},\n                                                     subject = '" . serendipity_db_escape_string($_REQUEST['note_subject']) . "',\n                                                     body = '" . serendipity_db_escape_string($_REQUEST['note_body']) . "',\n                                                     notetype = '" . serendipity_db_escape_string($_REQUEST['note_notetype']) . "'\n                                               WHERE noteid = {$noteid}");
                        $q = serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}adminnotes_to_groups WHERE noteid = {$noteid}");
                        foreach ($targets as $target) {
                            $q = serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}adminnotes_to_groups (noteid, groupid) VALUES ({$noteid}, {$target})");
                        }
                        if (is_string($q)) {
                            echo $q . "<br />\n";
                        }
                    } else {
                        serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}adminnotes (authorid, notetime, subject, body, notetype) VALUES ('" . $serendipity['authorid'] . "', " . time() . ", '" . serendipity_db_escape_string($_REQUEST['note_subject']) . "', '" . serendipity_db_escape_string($_REQUEST['note_body']) . "', '" . serendipity_db_escape_string($_REQUEST['note_notetype']) . "')");
                        $noteid = serendipity_db_insert_id('adminnotes', 'noteid');
                        foreach ($targets as $target) {
                            serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}adminnotes_to_groups (noteid, groupid) VALUES ({$noteid}, {$target})");
                        }
                    }
                    if ($serendipity['version'][0] < 2) {
                        echo '<div class="serendipityAdminMsgSuccess"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . DONE . ': ' . sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%H:%M:%S')) . '</div>';
                    } else {
                        echo '<span class="msg_success"><span class="icon-ok-circled"></span> ' . DONE . ': ' . sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%H:%M:%S')) . '</span>';
                    }
                }
                echo '<p>' . PLUGIN_ADMINNOTES_FEEDBACK_INFO . '</p>';
                echo '<form action="?" method="post">';
                echo serendipity_setFormToken();
                echo '<input type="hidden" name="serendipity[adminModule]" value="event_display" />';
                echo '<input type="hidden" name="serendipity[adminAction]" value="adminnotes" />';
                echo '<input type="hidden" name="action" value="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($_REQUEST['action']) : htmlspecialchars($_REQUEST['action'], ENT_COMPAT, LANG_CHARSET)) . '" />';
                echo '<input type="hidden" name="note" value="' . $entry['noteid'] . '" />';
                echo '<input type="hidden" name="note_notetype" value="note" />';
                if ($serendipity['version'][0] < 2) {
                    echo TITLE . '<br />';
                    echo '<input class="input_textbox" type="text" name="note_subject" value="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['subject']) : htmlspecialchars($entry['subject'], ENT_COMPAT, LANG_CHARSET)) . '" /><br /><br />';
                } else {
                    echo '<div class="form_field">';
                    echo '<label for="note_subject" class="block_level">' . TITLE . '</label>';
                    echo '<input id="note_subject" type="text" name="note_subject" value="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['subject']) : htmlspecialchars($entry['subject'], ENT_COMPAT, LANG_CHARSET)) . '">';
                    echo '</div>';
                }
                if ($serendipity['version'][0] < 2) {
                    echo USERCONF_GROUPS . '<br />';
                } else {
                    echo '<div class="form_multiselect">';
                    echo '<label for="note_target" class="block_level">' . USERCONF_GROUPS . '</label>';
                }
                $valid_groups = serendipity_getAllGroups($serendipity['authorid']);
                if (isset($_REQUEST['note_target'])) {
                    $selected = $_REQUEST['note_target'];
                } elseif ($mode == 'update') {
                    $sql = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}adminnotes_to_groups");
                    $selected = array();
                    foreach ($sql as $row) {
                        $selected[] = $row['groupid'];
                    }
                }
                echo '<select id="note_target" name="note_target[]" multiple="multiple" size="5">';
                foreach ($valid_groups as $group) {
                    # PRESELECT!
                    if (in_array($group['confkey'], (array) $selected) || count($selected) == 0) {
                        $is_selected = 'selected="selected"';
                    } else {
                        $is_selected = '';
                    }
                    echo '<option ' . $is_selected . ' value="' . $group['confkey'] . '">' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($group['confvalue']) : htmlspecialchars($group['confvalue'], ENT_COMPAT, LANG_CHARSET)) . '</option>' . "\n";
                }
                if ($serendipity['version'][0] < 2) {
                    echo '</select><br /><br />';
                } else {
                    echo '</select></div>';
                }
                if ($serendipity['version'][0] < 2) {
                    echo ENTRY_BODY . '<br />';
                } else {
                    echo '<div class="form_area">';
                    echo '<label for="note_body" class="block_level">' . ENTRY_BODY . '</label>';
                }
                echo '<textarea id="note_body" rows=10 cols=80 name="note_body">' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['body']) : htmlspecialchars($entry['body'], ENT_COMPAT, LANG_CHARSET)) . '</textarea>';
                if ($serendipity['version'][0] < 2) {
                    echo '<br /><br />';
                    echo '<input type="submit" name="submit" value="' . SAVE . '" class="serendipityPrettyButton input_button" />';
                } else {
                    echo '</div>';
                    echo '<div class="form_buttons"><input type="submit" name="submit" value="' . SAVE . '"></div>';
                }
                echo '</form>';
                break;
            case 'delete':
                $newLoc = '?' . serendipity_setFormToken('url') . '&amp;serendipity[adminModule]=event_display&amp;serendipity[adminAction]=adminnotes&amp;action=isdelete&amp;note=' . (int) $_REQUEST['note'];
                $entry = $this->getMyNotes((int) $_REQUEST['note']);
                if ($serendipity['version'][0] > 1) {
                    echo '<span class="msg_hint"><span class="icon-help-circled"></span> ';
                }
                printf(DELETE_SURE, $entry['noteid'] . ' - ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['subject']) : htmlspecialchars($entry['subject'], ENT_COMPAT, LANG_CHARSET)));
                if ($serendipity['version'][0] > 1) {
                    echo '</span>';
                }
                if ($serendipity['version'][0] < 2) {
                    ?>
                    <br />
                    <br />
                    <div>
                        <a href="<?php 
                    echo function_exists('serendipity_specialchars') ? serendipity_specialchars($_SERVER["HTTP_REFERER"]) : htmlspecialchars($_SERVER["HTTP_REFERER"], ENT_COMPAT, LANG_CHARSET);
                    ?>
" class="serendipityPrettyButton"><?php 
                    echo NOT_REALLY;
                    ?>
</a>
                        <?php 
                    echo str_repeat('&nbsp;', 10);
                    ?>
                        <a href="<?php 
                    echo $newLoc;
                    ?>
" class="serendipityPrettyButton"><?php 
                    echo DUMP_IT;
                    ?>
</a>
                    </div>
<?php 
                } else {
                    ?>
                    <div class="form_buttons">
                        <a class="button_link state_submit" href="<?php 
                    echo $newLoc;
                    ?>
"><?php 
                    echo DUMP_IT;
                    ?>
</a>
                        <a class="button_link state_cancel" href="<?php 
                    echo function_exists('serendipity_specialchars') ? serendipity_specialchars($_SERVER["HTTP_REFERER"]) : htmlspecialchars($_SERVER["HTTP_REFERER"], ENT_COMPAT, LANG_CHARSET);
                    ?>
"><?php 
                    echo NOT_REALLY;
                    ?>
</a>
                    </div>
<?php 
                }
                break;
            case 'isdelete':
                if (!serendipity_checkFormToken()) {
                    break;
                }
                $entry = $this->getMyNotes((int) $_REQUEST['note']);
                if (isset($entry['noteid'])) {
                    serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}adminnotes           WHERE noteid = " . (int) $_REQUEST['note']);
                    serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}adminnotes_to_groups WHERE noteid = " . (int) $_REQUEST['note']);
                }
                if ($serendipity['version'][0] > 1) {
                    echo '<span class="msg_success"><span class="icon-ok-circled"></span> ';
                }
                printf(RIP_ENTRY, $entry['noteid'] . ' - ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['subject']) : htmlspecialchars($entry['subject'], ENT_COMPAT, LANG_CHARSET)));
                if ($serendipity['version'][0] > 1) {
                    echo '</span>';
                }
                break;
            default:
                $notes = $this->getMyNotes(false);
                echo '<ol class="note_list plainList">';
                if (is_array($notes)) {
                    foreach ($notes as $note) {
                        if ($serendipity['version'][0] < 2) {
                            echo '<li><strong>' . $note['subject'] . '</strong> ' . POSTED_BY . ' ' . $note['realname'] . ' ' . ON . ' ' . serendipity_strftime(DATE_FORMAT_SHORT, $note['notetime']) . '<br />';
                            echo '<a class="serendipityPrettyButton" href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=adminnotes&amp;action=edit&amp;note=' . $note['noteid'] . '">' . EDIT . '</a> ';
                            echo '<a class="serendipityPrettyButton" href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=adminnotes&amp;action=delete&amp;note=' . $note['noteid'] . '">' . DELETE . '</a> ';
                            echo '<br /><br /></li>';
                        } else {
                            echo '<li><h3>' . $note['subject'] . '</h3><p>' . POSTED_BY . ' ' . $note['realname'] . ' ' . ON . ' ' . serendipity_strftime(DATE_FORMAT_SHORT, $note['notetime']) . '</p>';
                            echo '<div class="form_buttons"><a class="button_link state_submit" href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=adminnotes&amp;action=edit&amp;note=' . $note['noteid'] . '">' . EDIT . '</a> ';
                            echo '<a class="button_link state_cancel" href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=adminnotes&amp;action=delete&amp;note=' . $note['noteid'] . '">' . DELETE . '</a></div></li>';
                        }
                    }
                }
                echo '</ol>';
                if ($serendipity['version'][0] < 2) {
                    echo '<a class="serendipityPrettyButton" href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=adminnotes&amp;action=new">' . NEW_ENTRY . '</a>';
                } else {
                    echo '<div class="form_buttons"><a class="button_link state_submit" href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=adminnotes&amp;action=new">' . NEW_ENTRY . '</a></div>';
                }
                break;
        }
    }
コード例 #12
0
ファイル: nuke.inc.php プロジェクト: Juuro/Dreamapp-Website
 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;
 }
コード例 #13
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;
 }
コード例 #14
0
 function &updateCategory()
 {
     global $serendipity;
     if (!is_numeric($this->category['id'])) {
         $q = 'SELECT COUNT(id) AS counter
                 FROM ' . $serendipity['dbPrefix'] . 'faq_categorys
                WHERE parent_id = ' . $this->category['parent_id'];
         $res = serendipity_db_query($q, true, 'assoc');
         $this->category['catorder'] = $res['counter'] + 1;
         $this->postgreCategoryPrepare();
         $result = serendipity_db_insert('faq_categorys', $this->category);
         $serendipity['POST']['cid'] = serendipity_db_insert_id('faq_categorys', 'id');
     } else {
         $result = serendipity_db_update('faq_categorys', array('id' => $this->category['id']), $this->category);
     }
     return $result;
 }
コード例 #15
0
/**
 * 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);
            }
        }
    }
}
コード例 #16
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;
 }
コード例 #17
0
ファイル: wordpress.inc.php プロジェクト: jimjag/Serendipity
 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
/**
 * Create a new Category
 *
 * @access public
 * @param   string  The new category name
 * @param   string  The new category description
 * @param   int     The category owner
 * @param   string  An icon representing the category
 * @param   int     A possible parentid to a category
 * @return  int     The new category's ID
 */
function serendipity_addCategory($name, $desc, $authorid, $icon, $parentid)
{
    global $serendipity;
    $query = "INSERT INTO {$serendipity['dbPrefix']}category\n                    (category_name, category_description, authorid, category_icon, parentid, category_left, category_right)\n                  VALUES\n                    ('" . serendipity_db_escape_string($name) . "',\n                     '" . serendipity_db_escape_string($desc) . "',\n                      " . (int) $authorid . ",\n                     '" . serendipity_db_escape_string($icon) . "',\n                      " . (int) $parentid . ",\n                       0,\n                       0)";
    serendipity_db_query($query);
    $cid = serendipity_db_insert_id('category', 'categoryid');
    serendipity_plugin_api::hook_event('backend_category_addNew', $cid);
    $data = array('categoryid' => $cid, 'category_name' => $name, 'category_description' => $desc);
    serendipity_insertPermalink($data, 'category');
    return $cid;
}
コード例 #19
0
ファイル: phpbb.inc.php プロジェクト: vonnordmann/Serendipity
 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 insertPoll()
 {
     global $serendipity;
     $now = time();
     $q = serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}polls (\n                                    title, active, timestamp\n                                     ) VALUES (\n                                    '" . serendipity_db_escape_string($serendipity['POST']['currentPoll']['title']) . "',\n                                    0,\n                                    '" . $now . "')");
     if ($q) {
         return serendipity_db_insert_id('polls', 'id');
     }
 }
コード例 #21
0
/**
 * 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'];
}
コード例 #22
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;
 }
コード例 #23
0
/**
 * Adds a default internal group (Editor, Chief Editor, Admin)
 *
 * @access public
 * @param   string  The name of the group to insert
 * @param   int     The userlevel that represents this group (0|1|255 for Editor/Chief/Admin).
 * @return true
 */
function serendipity_addDefaultGroup($name, $level)
{
    global $serendipity;
    static $perms = null;
    if ($perms === null) {
        $perms = serendipity_getPermissionNames();
    }
    serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}groups (name) VALUES ('" . serendipity_db_escape_string($name) . "')");
    $gid = (int) serendipity_db_insert_id('groups', 'id');
    serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}groupconfig (id, property, value) VALUES ({$gid}, 'userlevel', '" . (int) $level . "')");
    $authors = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}authors WHERE userlevel = " . (int) $level);
    if (is_array($authors)) {
        foreach ($authors as $author) {
            serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}authorgroups (authorid, groupid) VALUES ('{$author['authorid']}', '{$gid}')");
        }
    }
    foreach ($perms as $permName => $permArray) {
        if (in_array($level, $permArray)) {
            serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}groupconfig (id, property, value) VALUES ({$gid}, '" . serendipity_db_escape_string($permName) . "', 'true')");
        } else {
            serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}groupconfig (id, property, value) VALUES ({$gid}, '" . serendipity_db_escape_string($permName) . "', 'false')");
        }
    }
    return true;
}
コード例 #24
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;
 }
コード例 #25
0
/**
 * Store the comment made by a visitor in the database
 *
 * @access public
 * @param   int     The ID of an entry
 * @param   array   An array that holds the input data from the visitor
 * @param   string  The type of a comment (normal/trackback)
 * @param   string  Where did a comment come from? (internal|trackback|plugin)
 * @param   string  Additional plugin data (spamblock plugin etc.)
 * @return  boolean Returns true if the comment could be added
 */
function serendipity_insertComment($id, $commentInfo, $type = 'NORMAL', $source = 'internal', $ca = array())
{
    global $serendipity;
    if (!empty($ca['status'])) {
        $commentInfo['status'] = $ca['status'];
    }
    $title = serendipity_db_escape_string(isset($commentInfo['title']) ? $commentInfo['title'] : '');
    $comments = $commentInfo['comment'];
    $ip = serendipity_db_escape_string(isset($commentInfo['ip']) ? $commentInfo['ip'] : $_SERVER['REMOTE_ADDR']);
    $commentsFixed = serendipity_db_escape_string($commentInfo['comment']);
    $name = serendipity_db_escape_string($commentInfo['name']);
    $url = serendipity_db_escape_string($commentInfo['url']);
    $email = serendipity_db_escape_string($commentInfo['email']);
    $parentid = isset($commentInfo['parent_id']) && is_numeric($commentInfo['parent_id']) ? $commentInfo['parent_id'] : 0;
    $status = serendipity_db_escape_string(isset($commentInfo['status']) ? $commentInfo['status'] : (serendipity_db_bool($ca['moderate_comments']) ? 'pending' : 'approved'));
    $t = serendipity_db_escape_string(isset($commentInfo['time']) ? $commentInfo['time'] : time());
    $referer = substr(isset($_SESSION['HTTP_REFERER']) ? serendipity_db_escape_string($_SESSION['HTTP_REFERER']) : '', 0, 200);
    $query = "SELECT a.email, e.title, a.mail_comments, a.mail_trackbacks\n                FROM {$serendipity['dbPrefix']}entries AS e\n     LEFT OUTER JOIN {$serendipity['dbPrefix']}authors AS a\n                  ON a.authorid = e.authorid\n             WHERE e.id  = '" . (int) $id . "'\n               AND e.isdraft = 'false'";
    if (!serendipity_db_bool($serendipity['showFutureEntries'])) {
        $query .= " AND e.timestamp <= " . serendipity_db_time();
    }
    $row = serendipity_db_query($query, true);
    // Get info on author/entry
    if (!is_array($row) || empty($id)) {
        // No associated entry found.
        if ($GLOBALS['tb_logging']) {
            $fp = fopen('trackback2.log', 'a');
            fwrite($fp, '[' . date('d.m.Y H:i') . '] entry reference not found: ' . $query . "\n");
            fclose($fp);
        }
        return false;
    }
    $send_optin = false;
    if (isset($commentInfo['subscribe'])) {
        if (!isset($serendipity['allowSubscriptionsOptIn']) || $serendipity['allowSubscriptionsOptIn']) {
            $subscribe = 'false';
            $send_optin = true;
        } else {
            $subscribe = 'true';
        }
    } else {
        $subscribe = 'false';
    }
    $dbhash = md5(uniqid(rand(), true));
    if ($status == 'confirm') {
        $dbstatus = 'confirm' . $dbhash;
    } elseif ($status == 'confirm1') {
        $auth = serendipity_db_query("SELECT *\n                                        FROM {$serendipity['dbPrefix']}options\n                                       WHERE okey  = 'mail_confirm'\n                                         AND name  = '" . $email . "'\n                                         AND value = '" . $name . "'", true);
        if (!is_array($auth)) {
            serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}options (okey, name, value)\n                                       VALUES ('mail_confirm{$dbhash}', '{$email}', '{$name}')");
            $dbstatus = 'confirm' . $dbhash;
        } else {
            $serendipity['csuccess'] = 'true';
            $status = $dbstatus = 'approved';
        }
    } else {
        $dbstatus = $status;
    }
    $query = "INSERT INTO {$serendipity['dbPrefix']}comments (entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer)";
    $query .= " VALUES ('" . (int) $id . "', '{$parentid}', '{$ip}', '{$name}', '{$email}', '{$url}', '{$commentsFixed}', '{$type}', '{$t}', '{$title}', '{$subscribe}', '{$dbstatus}', '{$referer}')";
    if ($GLOBALS['tb_logging']) {
        $fp = fopen('trackback2.log', 'a');
        fwrite($fp, '[' . date('d.m.Y H:i') . '] SQL: ' . $query . "\n");
    }
    serendipity_db_query($query);
    $cid = serendipity_db_insert_id('comments', 'id');
    // Send mail to the author if he chose to receive these mails, or if the comment is awaiting moderation
    if ($status != 'confirm' && (serendipity_db_bool($ca['moderate_comments']) || $type == 'NORMAL' && serendipity_db_bool($row['mail_comments']) || $type == 'TRACKBACK' && serendipity_db_bool($row['mail_trackbacks']))) {
        serendipity_sendComment($cid, $row['email'], $name, $email, $url, $id, $row['title'], $comments, $type, serendipity_db_bool($ca['moderate_comments']));
    }
    // Approve with force, if moderation is disabled
    if ($GLOBALS['tb_logging']) {
        fwrite($fp, '[' . date('d.m.Y H:i') . '] status: ' . $status . ', moderate: ' . $ca['moderate_comments'] . "\n");
    }
    if ($status != 'confirm' && (empty($ca['moderate_comments']) || serendipity_db_bool($ca['moderate_comments']) == false)) {
        if ($GLOBALS['tb_logging']) {
            fwrite($fp, '[' . date('d.m.Y H:i') . '] Approving...' . "\n");
        }
        serendipity_approveComment($cid, $id, true);
    } elseif ($GLOBALS['tb_logging']) {
        fwrite($fp, '[' . date('d.m.Y H:i') . '] No need to approve...' . "\n");
    }
    if ($status == 'confirm') {
        $subject = sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $row['title']);
        $message = sprintf(CONFIRMATION_MAIL_ALWAYS, $name, $row['title'], $commentsFixed, $serendipity['baseURL'] . 'comment.php?c=' . $cid . '&hash=' . $dbhash);
        serendipity_sendMail($email, $subject, $message, $serendipity['blogMail']);
    } elseif ($status == 'confirm1') {
        $subject = sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $row['title']);
        $message = sprintf(CONFIRMATION_MAIL_ONCE, $name, $row['title'], $commentsFixed, $serendipity['baseURL'] . 'comment.php?c=' . $cid . '&hash=' . $dbhash);
        serendipity_sendMail($email, $subject, $message, $serendipity['blogMail']);
    }
    if ($send_optin) {
        $dupe_check = serendipity_db_query("SELECT count(entry_id) AS counter\n                                              FROM {$serendipity['dbPrefix']}comments\n                                             WHERE entry_id = " . (int) $id . "\n                                               AND email = '{$email}'\n                                               AND subscribed = 'true'", true);
        if (!is_array($dupe_check) || $dupe_check['counter'] < 1) {
            serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}options (okey, name, value)\n                                       VALUES ('commentsub_{$dbhash}', '" . time() . "', '{$cid}')");
            $subject = sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $row['title']);
            $message = sprintf(CONFIRMATION_MAIL_SUBSCRIPTION, $name, $row['title'], serendipity_archiveURL($id, $row['title'], 'baseURL'), $serendipity['baseURL'] . 'comment.php?optin=' . $dbhash);
            serendipity_sendMail($email, $subject, $message, $serendipity['blogMail']);
        }
    }
    serendipity_purgeEntry($id, $t);
    if ($GLOBALS['tb_logging']) {
        fclose($fp);
    }
    return $cid;
}
コード例 #26
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;
 }
コード例 #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
 function updatePageType()
 {
     global $serendipity;
     if (!isset($this->pagetype['id'])) {
         $result = serendipity_db_insert('staticpages_types', $this->pagetype);
         if (is_string($result)) {
             echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />ERROR: ' . $result . '</div>';
         }
         $serendipity["POST"]["pagetype"] = serendipity_db_insert_id('staticpages_types', 'id');
     } else {
         $result = serendipity_db_update('staticpages_types', array('id' => $this->pagetype['id']), $this->pagetype);
         if (is_string($result)) {
             echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />ERROR: ' . $result . '</div>';
         }
     }
 }
コード例 #29
0
ファイル: sunlog.inc.php プロジェクト: Juuro/Dreamapp-Website
 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;
 }
コード例 #30
0
function DMA_forum_InsertThread($boardid, $authorname, $title, $message, $announce = 0, $frommail, $fromname, $pageurl, $admin_notify = true)
{
    global $serendipity;
    if (serendipity_userLoggedIn()) {
        $authorname = $serendipity['serendipityUser'];
        $KEXTRA = ", authorid";
        $VEXTRA = ", '" . $serendipity['authorid'] . "'";
        $EEXTRA = " lastauthorid = '" . $serendipity['authorid'] . "', ";
    } else {
        $KEXTRA = "";
        $VEXTRA = "";
        $EEXTRA = "";
    }
    $now = time();
    $q = "INSERT INTO {$serendipity['dbPrefix']}dma_forum_threads (\n                        boardid,\n                        title,\n                        lastposttime,\n                        announce\n            ) VALUES (\n                        '" . intval($boardid) . "',\n                        '" . serendipity_db_escape_string(trim($title)) . "',\n                        '" . $now . "',\n                        '" . $announce . "'\n            )";
    $sql = serendipity_db_query($q);
    $threadid = serendipity_db_insert_id('dma_forum_threads', 'threadid');
    $q = "INSERT INTO {$serendipity['dbPrefix']}dma_forum_posts (\n                    threadid,\n                    postdate,\n                    title,\n                    message,\n                    authorname" . $KEXTRA . "\n        ) VALUES (\n                    '" . intval($threadid) . "',\n                    '" . $now . "',\n                    '" . serendipity_db_escape_string(trim($title)) . "',\n                    '" . serendipity_db_escape_string(trim($message)) . "',\n                    '" . serendipity_db_escape_string(trim($authorname)) . "'" . $VEXTRA . "\n        )";
    $sql = serendipity_db_query($q);
    $postid = serendipity_db_insert_id('dma_forum_posts', 'postid');
    if (isset($_SESSION['forum_visited']) && intval($_SESSION['forum_visited']) >= 1) {
        $q = "UPDATE {$serendipity['dbPrefix']}dma_forum_users SET posts = posts+1, lastpost = '" . $postid . "' WHERE authorid = '" . intval($serendipity['authorid']) . "'";
        serendipity_db_query($q);
    }
    DMA_forum_CheckLastProperties(intval($boardid));
    $_SESSION['lastthreadtext'] = trim($message);
    $_SESSION['lastposttime'] = time();
    $fromname = DMA_strip($fromname);
    $frommail = DMA_strip($frommail);
    if ($admin_notify === true) {
        $subject = str_replace("{postauthor}", trim($authorname), PLUGIN_FORUM_EMAIL_NOTIFY_SUBJECT);
        $subject = str_replace("{blogurl}", $serendipity['baseURL'], $subject);
        $body = PLUGIN_FORUM_EMAIL_NOTIFY_PART1 . PLUGIN_FORUM_EMAIL_NOTIFY_PART2 . PLUGIN_FORUM_EMAIL_NOTIFY_PART3;
        $body = str_replace("{postauthor}", trim($authorname), $body);
        $body = str_replace("{forumurl}", $serendipity['baseURL'] . "index.php?serendipity[subpage]=" . $pageurl, $body);
        $body = str_replace("{threadtitle}", function_exists('serendipity_specialchars') ? serendipity_specialchars(trim($title)) : htmlspecialchars(trim($title), ENT_COMPAT, LANG_CHARSET), $body);
        $body = str_replace("{replytext}", function_exists('serendipity_specialchars') ? serendipity_specialchars(strip_tags(trim($message))) : htmlspecialchars(strip_tags(trim($message)), ENT_COMPAT, LANG_CHARSET), $body);
        $body = str_replace("{posturl}", $serendipity['baseURL'] . "index.php?serendipity[subpage]=" . $pageurl . "&boardid=" . intval($boardid) . "&threadid=" . intval($threadid), $body);
        $from = "{$fromname} <{$frommail}>";
        $to = "" . $serendipity['blogMail'] . "";
        $headers = "From: {$from}\r\n";
        $headers .= "Reply-To: {$frommail}\r\n";
        $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n\r\n";
        mail($to, $subject, $body, $headers);
    }
    unset($_GET);
    $_GET['boardid'] = intval($boardid);
    $_GET['threadid'] = intval($threadid);
    return $postid;
}