--- delicious.module 2007-04-11 09:53:40.561615900 +0200 +++ delicious.module.jotarp 2007-04-11 10:36:59.367145600 +0200 @@ -108,7 +109,7 @@ // _perm() hook // function delicious_perm() { - return array ('view delicious links', 'create delicious links', 'administer delicious'); + return array ('delicious account', 'view delicious links', 'create delicious links', 'administer delicious'); } // @@ -188,27 +189,60 @@ ); // User's personal page if ($user->uid) { + // Tabs: $items[] = array( 'path' => 'user/' . $user->uid . '/delicious', 'title' => t('delicious'), - 'access' => user_access('create delicious links'), + 'access' => user_access('delicious account'), 'callback' => 'delicious_page_settings', 'type' => MENU_LOCAL_TASK, - 'weight' => 5 + 'weight' => 5); + + $items[] = array( + 'path' => 'user/' . $user->uid . '/delicious/create', + 'title' => t('create links'), + 'access' => user_access('create delicious links'), + 'callback' => 'delicious_page_create', + 'type' => MENU_LOCAL_TASK, + 'weight' => 5); + + $items[] = array( + 'path' => 'user/' . $user->uid . '/delicious/settings', + 'title' => t('account'), + 'access' => user_access('delicious account'), + 'callback' => 'delicious_page_settings', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -10 ); } } else { // administrators editing arbitrary users is dynamic, and so outside the may_cache line. if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) != $user->uid) { - $targetuser->uid = arg(1); + $targetuser = user_load(array('uid' => arg(1))); $items[] = array( 'path' => 'user/' . arg(1) . '/delicious', 'title' => t('delicious'), - 'access' => user_access('create delicious links', $targetuser) && user_access('administer users'), + 'access' => user_access('delicious account', $targetuser) && user_access('administer users'), 'callback' => 'delicious_page_settings', 'type' => MENU_LOCAL_TASK, - 'weight' => 5 + 'weight' => 5); + + $items[] = array( + 'path' => 'user/' . arg(1) . '/delicious/create', + 'title' => t('create links'), + 'access' => user_access('create delicious links', $targetuser) && user_access('administer users'), + 'callback' => 'delicious_page_create', + 'type' => MENU_LOCAL_TASK, + 'weight' => 5); + + $items[] = array( + 'path' => 'user/' . arg(1) . '/delicious/settings', + 'title' => t('account'), + 'access' => user_access('delicious account', $targetuser) && user_access('administer users'), + 'callback' => 'delicious_page_settings', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -10 ); } @@ -411,7 +445,6 @@ '#value' => $uid, ); - if ($userinfo) { $form["user"] = array( '#type' => 'textfield', '#title' => t("username"), @@ -428,6 +461,61 @@ '#maxlength' => 24, '#description' => t('Your del.icio.us Password. '), ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + + $form['#base'] = 'delicious_page_settings'; + return $form; +} + +function delicious_page_settings_submit($form_id, $form_values) { + // Check to see if a delicious_user entry exists + $result = db_query("SELECT * FROM {delicious_user} WHERE uid = %d", $form_values['uid']); + $userinfo = db_fetch_object($result); + + if ($userinfo) { + // modify fields + $result = db_query("UPDATE {delicious_user} SET user='%s', pass='%s', lastcode=0, overview=%d, pagesize=%d WHERE uid=%d", $form_values['user'], $form_values['pass'], $form_values['overview'], $form_values['pagesize'], $form_values['uid']); + drupal_set_message(t("del.icio.us username and password updated.")); + } else { + // create a delicious_user entry + $result = db_query("INSERT INTO {delicious_user} (uid,user,pass) VALUES (%d,'%s','%s')", $form_values['uid'], $form_values['user'], $form_values['pass']); + drupal_set_message(t("del.icio.us username and password stored. Now you can enable Delicious Links.")); + } +} + +// +// render/handle user specific create page +// +function delicious_page_create() { + $uid = arg(1); + $output = drupal_get_form('delicious_page_create_form', $uid); + return $output; +} + +// +// render user specific delicious create form +// +function delicious_page_create_form($uid) { + // Check to see if a delicious_user entry exists + $result = db_query("SELECT * FROM {delicious_user} WHERE uid = %d", $uid); + $userinfo = db_fetch_object($result); + + $form['uid'] = array( + '#type' => 'hidden', + '#value' => $uid, + ); + + if ($userinfo) { + $form["createlink"] = array( + '#type' => 'checkbox', + '#title' => t("enable create links?"), + '#return_value' => 1, + '#default_value' => $userinfo->createlink, + '#description' => t('Enable create'), + ); $form["overview"] = array( '#type' => 'checkbox', '#title' => t("simple overview page?"), @@ -443,52 +531,26 @@ '#maxlength' => 2, '#description' => t('If using the simple overview, how many links per page?'), ); - $form['pagesize'] = array( - '#type' => 'textfield', - '#title' => t("pagesize"), - '#default_value' => $userinfo->pagesize, - '#size' => 2, - '#maxlength' => 2, - '#description' => t('If using the simple overview, how many links per page?'), - ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); - $form['disable'] = array( - '#type' => 'submit', - '#value' => t('Disable'), - ); } else { $form['message'] = array( '#type' => 'markup', - '#value' => "

" . t("Delicious links fetching is currently disabled for this account.") . "

", - ); - $form['enable'] = array( - '#type' => 'submit', - '#value' => t('Enable'), + '#value' => "

" . t("Please, first fill out the del.icio.us username and password.") . "

", ); } - - return $form ; + + $form['#base'] = 'delicious_page_create'; + return $form; } -function delicious_page_settings_submit($form_id, $form_values) { - if ($_POST['op'] == t('Enable')) { - // create a delicious_user entry - $result = db_query("INSERT INTO {delicious_user} (uid) VALUES (%d)", $form_values['uid']); - drupal_set_message(t("Delicious Links have been enabled; please fill out the del.icio.us username and password.")); - } - else if ($_POST['op'] == t('Disable')) { - $result = db_query("DELETE FROM {delicious_user} WHERE uid=%d", $form_values['uid']); - drupal_set_message(t("Delicious Links fetching disabled.")); - } - else if ($_POST['op'] == t('Submit')) { +function delicious_page_create_submit($form_id, $form_values) { // modify fields - $result = db_query("UPDATE {delicious_user} SET user='%s', pass='%s', lastcode=0, overview=%d, pagesize=%d WHERE uid=%d", $form_values['user'], $form_values['pass'], $form_values['overview'], $form_values['pagesize'], $form_values['uid']); - drupal_set_message(t("Settings updated.")); - } + $result = db_query("UPDATE {delicious_user} SET createlink=%d, lastcode=0, overview=%d, pagesize=%d WHERE uid=%d", $form_values['createlink'], $form_values['overview'], $form_values['pagesize'], $form_values['uid']); + drupal_set_message(t("Settings updated.")); } // ----------------------------------------------------------------------------