mysite_content_add($uid = NULL, $type = NULL, $type_id = NULL, $page = 0, $title = NULL)
mysite.module, line 2532
Menu callback to add a content item
All values are set to NULL to force error checking and guard against spoofing.
$uid The $user->uid of the owner of this MySite page.
$type The type of content to be saved. Types tell MySite how to handle data gathering.
$type_id The unique id of the content, such as type = blog, type_id = 2 would return the blog of user 2.
$page The current page of the mysite collection.
$title The title to be saved as for this element.
function mysite_content_add($uid = NULL, $type = NULL, $type_id = NULL, $page = 0, $title = NULL) {
global $user;
$dest = referer_uri();
// one some cases, we call this from an external function.
if (is_null($uid)) {
$uid = arg(1);
$type = arg(3);
$type_id = arg(4);
}
if (is_numeric($type_id) && is_string($type) && ($user->uid == $uid || user_access('administer mysite'))) {
// get the title of the page
$load = mysite_load_includes('types', $type);
if (empty($title)) {
$title = module_invoke('mysite_type', $type .'_title', $type_id);
}
// make sure the content is not already in the user's MySite collection.
$check = mysite_check($uid, $type, $type_id);
if ($check <= 0) {
// insert the data we need at the first position of the last column
$layout = mysite_get_layout($uid);
$mysite = mysite_get($uid);
$position = count($layout['regions']) - 1;
db_query("UPDATE {mysite_data} SET sort = sort+1 WHERE uid = %d AND page = %d AND position = %d", $uid, $page, $position);
$mid = db_next_id('{mysite_data}_mid');
$sql = "INSERT INTO {mysite_data} (mid, uid, page, title, type, type_id, sort, format, position) VALUES (%d, %d, %d, '%s', '%s', %d, %d, '%s', %d)";
db_query($sql, $mid, $uid, $page, $title, $type, $type_id, 1, $mysite->format, $position);
mysite_updated($uid);
drupal_set_message(t('Item added.'), 'status');
}
else {
drupal_set_message(t('@title has already been added to your personal page.', array('@title' => $title)), 'status');
}
}
else {
drupal_set_message(t('You are not authorized to add this item.'), 'error');
}
if (empty($dest)) {
drupal_goto('mysite/'. $uid .'/content/'. $page);
}
drupal_goto($dest);
}