Exemplo n.º 1
0
/**
 * @param . $post argument is a reference to the post object which is used to store information for the form
 * @param . $bloginfo_arg argument is reference to a blogInfo object.
 * @todo complete documenting this function. enable trackback and pingback between entries on the same server
 */
function do_edit($post, $blogeditform)
{
    global $CFG, $USER, $returnurl;
    $post->lastmodified = time();
    $dir = blog_file_area_name($post);
    if ($blogeditform->save_files($dir) and $newfilename = $blogeditform->get_new_filename()) {
        $post->attachment = $newfilename;
    }
    // update record
    if (update_record('post', $post)) {
        // delete all tags associated with this entry
        //delete_records('blog_tag_instance', 'entryid', $post->id);
        //delete_records('tag_instance', 'itemid', $post->id, 'itemtype', 'blog');
        untag_an_item('blog', $post->id);
        // add them back
        add_tags_info($post->id);
        add_to_log(SITEID, 'blog', 'update', 'index.php?userid=' . $post->userid . '&postid=' . $post->id, $post->subject);
    } else {
        error('There was an error updating this post in the database', $returnurl);
    }
}
Exemplo n.º 2
0
/**
 * Updates the tags associated with an item
 *
 * Ex 1:
 *  Suppose user 1 is tagged only with "algorithms", "computers" and "software"
 *  By calling update_item_tags('user', 1, 'algorithms, software, mathematics')
 *  User 1 will now be tagged only with "algorithms", "software" and "mathematics"
 *
 * Ex 2:
 *   update_item_tags('user', '1', 'algorithms, 12, 13')
 *   User 1 will now be tagged only with "algorithms", and with tags of ids 12 and 13
 *
 *
 * @param string $item_type name of the table where the item is stored. Ex: 'user'
 * @param string $item_id id of the item to be tagged
 * @param string $tag_names_or_ids_csv comma separated tag names (can be unormalized) or ids of existing tags
 * @param string $tag_type type of the tags that are beeing added (optional, default value is "default")
 */
function update_item_tags($item_type, $item_id, $tag_names_or_ids_csv, $tag_type = "default")
{
    //if $tag_names_csv is an empty string, remove all tag associations of the item
    if (empty($tag_names_or_ids_csv)) {
        untag_an_item($item_type, $item_id);
        return;
    }
    //convert any tag ids passed to their corresponding tag names
    $tag_names_csv = tag_name_from_string($tag_names_or_ids_csv);
    //associate the tags passed with the item
    tag_an_item($item_type, $item_id, $tag_names_csv, $tag_type);
    //get the ids of the tags passed
    $existing_and_new_tags_ids = tags_id(tag_normalize($tag_names_csv));
    // delete any tag instance with $item_type and $item_id
    // that are not in $tag_names_csv
    $tags_id_csv = "'" . implode("','", $existing_and_new_tags_ids) . "'";
    $select = "\n        itemid = '{$item_id}'\n    AND\n        itemtype = '{$item_type}'\n    AND\n        tagid NOT IN ({$tags_id_csv})\n    ";
    delete_records_select('tag_instance', $select);
}