$item_content = $edited_Comment->get_author_name() . ' ' . T_('wrote') . ': <blockquote>' . $edited_Comment->get_content() . '</blockquote>'; $new_Item = new Item(); $new_Item->set('status', 'draft'); $new_Item->set_creator_by_login($current_User->login); $new_Item->set('main_cat_ID', $Blog->get_default_cat_ID()); $new_Item->set('title', T_('Elevated from comment')); $new_Item->set('content', $item_content); if (!$new_Item->dbinsert()) { $Messages->add(T_('Unable to create the new post!'), 'error'); break; } // Deprecate the comment after elevating $edited_Comment->set('status', 'deprecated'); $edited_Comment->dbupdate(); // Move all child comments to new created post move_child_comments_to_item($edited_Comment->ID, $new_Item->ID); header_redirect(url_add_param($admin_url, 'ctrl=items&blog=' . $blog . '&action=edit&p=' . $new_Item->ID, '&')); break; case 'list': case 'mass_delete': /* * Latest comments: */ $AdminUI->title_titlearea = T_('Latest comments'); // Generate available blogs list: $AdminUI->set_coll_list_params('blog_comments', 'edit', array('ctrl' => 'comments', 'filter' => 'restore')); /* * Add sub menu entries: * We do this here instead of _header because we need to include all filter params into regenerate_url() */ attach_browse_tabs();
/** * Move all child comments to new post by parent comment ID * * @param integer/array Parent comment IDs * @param integer Item ID * @param boolean TRUE to convert a comment to root/top comment of the post */ function move_child_comments_to_item($comment_IDs, $item_ID, $convert_to_root = true) { global $DB; $child_comments_SQL = new SQL(); $child_comments_SQL->SELECT('comment_ID'); $child_comments_SQL->FROM('T_comments'); $child_comments_SQL->WHERE('comment_in_reply_to_cmt_ID IN ( ' . $DB->quote($comment_IDs) . ' )'); $child_comments_IDs = $DB->get_col($child_comments_SQL->get()); if (empty($child_comments_IDs)) { // No child comments, Exit here return; } // Move the child comments recursively move_child_comments_to_item($child_comments_IDs, $item_ID, false); // Update item ID to new if ($convert_to_root) { // Make these comments as root comments (remove their parent depending) $update_sql = ', comment_in_reply_to_cmt_ID = NULL'; } $DB->query('UPDATE T_comments SET comment_item_ID = ' . $DB->quote($item_ID) . $update_sql . ' WHERE comment_in_reply_to_cmt_ID IN ( ' . $DB->quote($comment_IDs) . ' )'); }