Index: delicious.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/delicious/delicious.install,v retrieving revision 1.1 diff -u -w -B -F^f -r1.1 delicious.install --- delicious.install 24 Jul 2006 01:12:36 -0000 1.1 +++ delicious.install 14 Jun 2007 22:25:14 -0000 @@ -1,5 +1,5 @@ type)) { if (variable_get("delicious_crosslink", 0)) { - $links[] = 'uid")); } if ($uname) { - $node->body = _delicious_tag_text($node->body, $uname); - $node->teaser = _delicious_tag_text($node->teaser, $uname); + if ($node->content['teaser']) { + $node->content['teaser'] = array('#value' => _delicious_tag_text($node->teaser, $uname), '#weight' => 10); + } + if ($node->content['body']) { + $node->content['body'] = array('#value' => _delicious_tag_text($node->body, $uname), '#weight' => 10 ); + } } } break; @@ -245,9 +254,9 @@ function delicious_nodeapi(&$node, $op, return; } -// -// _cron() hook -// +/** + * Implementation of hook_cron(). + */ function delicious_cron() { $result = db_query("SELECT DISTINCT(u.uid), u.name, d.user, d.pass, d.lastupdate, d.lastcode FROM {users} u INNER JOIN {delicious_user} d ON u.uid = d.uid"); while ($u = db_fetch_object($result)) { @@ -261,9 +270,9 @@ function delicious_cron() { } -// -// _block() hook -// +/** + * Implementation of hook_block(). + */ function delicious_block($op = 'list', $delta = 0) { if (!user_access('view delicious links')) return; @@ -282,14 +291,17 @@ function delicious_block($op = 'list', $ return $block; } } +// @} End of @name Drupal hooks -// ---------------------------------------------------------------------------- -// callbacks (and support), mostly for displaying information -// - -// -// Display delicious overview (a page of all users with delicious tags) -// +/** + * @name callbacks (and support), mostly for displaying information + * + * @{ + */ + +/** + * Display delicious overview (a page of all users with delicious tags) + */ function delicious_page() { $result = pager_query("SELECT u.name, du.uid, COUNT(dt.uid) AS linkcount FROM {delicious_user} du LEFT JOIN {delicious_tag} dt ON du.uid = dt.uid LEFT JOIN {users} u on du.uid = u.uid GROUP BY dt.uid ORDER BY u.name", 20, $count_query="select count(distinct(uid)) from {delicious_user}"); @@ -316,9 +328,9 @@ function delicious_page() { return $output; } -// -// render a list of all user's links for a given tag -// +/** + * render a list of all user's links for a given tag + */ function delicious_page_tag($tag = "", $uid = "") { if (!$tag) { return delicious_page(); @@ -369,14 +381,14 @@ function delicious_page_tag($tag = "", $ $output = "

" . l(t('View "%n" for all users', array('%n' => $tag)), "delicious/tag/$tag") . "

"; $output .= theme('table', $header, $rows); - $output = "
$output
\n"; + $output = "
$output
\n"; return $output; } -// -// Render a user's tag and links with javascript actuators -// +/** + * Render a user's tag and links with javascript actuators + */ function delicious_page_user($uid = 0) { $output = theme('delicious_user', $uid); if (!$output) @@ -385,18 +397,18 @@ function delicious_page_user($uid = 0) { return $output; } -// -// render/handle user specific settings page -// +/** + * render/handle user specific settings page + */ function delicious_page_settings() { $uid = arg(1); - $output = delicious_page_settings_form($uid, $existence); + $output = drupal_get_form('delicious_page_settings_form',$uid); return $output; } -// -// render user specific delicious settings form -// +/** + * render user specific delicious settings form + */ function delicious_page_settings_form($uid) { // Check to see if a delicious_user entry exists $result = db_query("SELECT * FROM {delicious_user} WHERE uid = %d", $uid); @@ -467,10 +479,13 @@ function delicious_page_settings_form($u ); } - return drupal_get_form('delicious_page_settings', $form); + return $form; } -function delicious_page_settings_submit($form_id, $form_values) { +/** + * submission handling for delicious_page_settings_form() + */ +function delicious_page_settings_form_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']); @@ -486,14 +501,17 @@ function delicious_page_settings_submit( drupal_set_message(t("Settings updated.")); } } +// @} End of @name callbacks (and support), mostly for displaying information -// ---------------------------------------------------------------------------- -// block admin, support and render -// - -// -// render admin page -// +/** + * @name block admin, support and render + * + * @{ + */ + +/** + * render admin page + */ function delicious_admin() { $result = pager_query("SELECT dbid, title, maxentries FROM {delicious_block} ORDER BY title", 20); @@ -520,44 +538,56 @@ function delicious_admin() { return $output; } -// -// render block add or edit page, and/or handle results -// +/** + * render block add or edit page, and/or handle results + */ function delicious_admin_edit($block = 0) { if (arg(2) == 'edit' && (!is_numeric($block) || $block == 0)) { return drupal_access_denied(); } - $output = delicious_block_form($block); + $output = drupal_get_form('delicious_block_form',$block); return $output; } + +function delicious_admin_delete_confirm_submit($form_id, $form_values) { + if ($form_values['confirm']) { + delicious_delete_block($form_values['block']); + } + return 'admin/delicious'; +} + function delicious_admin_delete($dbid = 0) { $block = delicious_load_block($dbid); if ($block['title'] == '') { return drupal_access_denied(); } + return drupal_get_form('delicious_admin_delete_confirm', $dbid); +} + +function delicious_admin_delete_confirm_page() { + return drupal_get_form('delicious_admin_delete_confirm', arg(1)); +} + +function delicious_admin_delete_confirm($dbid){ + + $form['block'] = array('#type' => 'value', '#value' => $dbid); - return confirm_form('delicious_admin_delete_confirm', $form, + return confirm_form($form, t('Are you sure you want to delete %title?', array('%title' => $block['title'])), $_GET['destination'] ? $_GET['destination'] : 'admin/delicious', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); -} -function delicious_admin_delete_confirm_submit($form_id, $form_values) { - if ($form_values['confirm']) { - delicious_delete_block($form_values['block']); - } - return 'admin/delicious'; } -// -// display add/edit block form -// +/** + * display add/edit block form + */ function delicious_block_form($dbid = 0) { $block = delicious_load_block($dbid); @@ -605,13 +635,13 @@ function delicious_block_form($dbid = 0) ); } - return drupal_get_form('delicious_block_edit', $form); + return $form ; } -// -// save block to db -// -function delicious_block_edit_submit($form_id, $form_values) { +/** + * save block to db + */ +function delicious_block_form_submit($form_id, $form_values) { if ($form_values['dbid']) { db_query("UPDATE {delicious_block} SET title='%s', users='%s', tags='%s', maxentries=%d WHERE dbid=%d", $form_values['title'], $form_values['users'], $form_values['tags'], $form_values['maxentries'], $form_values['dbid']); } @@ -622,24 +652,25 @@ function delicious_block_edit_submit($fo return 'admin/delicious'; } -// -// load block from db -// +/** + * load block from db + */ function delicious_load_block($block) { $obj = db_fetch_array(db_query("SELECT * FROM {delicious_block} WHERE dbid=%d", $block)); return $obj; } -// -// delete a block from db -// +/** + * delete a block from db + */ function delicious_delete_block($block) { db_query("DELETE FROM {delicious_block} WHERE dbid=%d", $block); } -// -// render recent links for _block() hook -// +/** + * render recent links for _block() hook + * TODO: make this themeable + */ function delicious_recent($id) { $block = db_fetch_object(db_query("SELECT * FROM {delicious_block} WHERE dbid=%d", $id)); @@ -648,7 +679,7 @@ function delicious_recent($id) { $ulist = explode(',', $block->users); foreach ($ulist AS $user) { if (!$users) { - $users = "u.name in ("; + $users = "u.name IN ("; } else { $users .= ", "; @@ -662,7 +693,7 @@ function delicious_recent($id) { $ulist = explode(',', $block->tags); foreach ($ulist AS $tag) { if (!$tags) { - $tags = "dt.name in ("; + $tags = "dt.name IN ("; } else { $tags .= ", "; @@ -674,19 +705,28 @@ function delicious_recent($id) { if ($users || $tags) { - $where = "where "; + $where = "WHERE "; if ($users) $where .= "$users "; if ($users && $tags) - $where .= "and "; + $where .= "AND "; if ($tags) $where .= "$tags "; } - $result = db_query_range("SELECT distinct(dl.description), dl.href FROM {delicious_link} dl LEFT JOIN {delicious_tag} dt ON dl.lid = dt.lid LEFT JOIN {users} u ON dl.uid = u.uid $where ORDER BY dl.linktime desc", 0, intval($block->maxentries)); + // show private links only to owners + $where .= " AND (shared OR dl.uid = {$GLOBALS[user]->uid})"; + $result = db_query_range("SELECT distinct(dl.description), dl.href, dl.linktime FROM {delicious_link} dl LEFT JOIN {delicious_tag} dt ON dl.lid = dt.lid LEFT JOIN {users} u ON dl.uid = u.uid $where ORDER BY dl.linktime desc", 0, intval($block->maxentries)); + + $output = ''; + $day = ''; while ($link = db_fetch_object($result)) { - $output .= "
  • " . _delicious_get_link($link) . "
  • "; + if (($day_new = strftime('%x', $link->linktime)) != $day) { + $day = $day_new; + $output .= "\n$day\n"; // todo: make this valid html, ie. a nested ul list + } + $output .= "
  • " . _delicious_get_link($link) . "
  • \n"; } if ($output) { @@ -694,14 +734,19 @@ function delicious_recent($id) { } return array("content" => $output, "subject" => $block->title); } +// @} End of @name block admin, support and render -// ---------------------------------------------------------------------------- -// REST calls to del.icio.us API -// - -// -// drupal_http_support etc FROM alastair tse -// +/** + * @name REST calls to del.icio.us API + * + * @{ + */ + +/** + * drupal_http_support etc FROM alastair tse + * + * @private + */ function _delicious_make_auth_header($username, $password) { $realm = "del.icio.us API"; $user_agent = "drupal.contributions.delicious.module/1.0"; @@ -714,9 +759,11 @@ function _delicious_make_auth_header($us return $headers; } -// -// get a page FROM the delicious API -// +/** + * get a page FROM the delicious API + * + * @private + */ function _delicious_get_page($page, $user, $pass) { // Force 1 second throttle. global $lastDeliciousHit; @@ -728,9 +775,11 @@ function _delicious_get_page($page, $use _delicious_make_auth_header($user, $pass)); } -// -// cron support: update all users who have Delicious Links -// +/** + * cron support: update all users who have Delicious Links + * + * @private + */ function _delicious_update_user($user) { $resp = _delicious_get_page(DELICIOUS_UPDATE_URL, $user->user, $user->pass); $resp->code = intval($resp->code); @@ -760,16 +809,22 @@ function _delicious_update_user($user) { return 0; } +// @} End of@name REST calls to del.icio.us API -// ---------------------------------------------------------------------------- -// XML parsing objects -// -// If another object gets created, refactor some of the code into a base object -// and inherit - -// -// parse the update string -// +/** + * @name XML parsing objects + * + * If another object gets created, refactor some of the code into a base object + * and inherit + * + * @{ + */ + +/** + * parse the update string + * + * @private + */ class _delicious_update_parser { function parse($data) { @@ -801,10 +856,12 @@ function _delicious_update_user($user) { } -// -// parse all posts, and write them to the database; delete all unsynced -// posts for that user. -// +/** + * parse all posts, and write them to the database; delete all unsynced + * posts for that user. + * + * @private + */ class _delicious_post_parser { function _delicious_post_parser($uid = 0) { @@ -841,11 +898,12 @@ function _delicious_update_user($user) { } $hash = $attrs["HASH"]; $time = _delicious_date_parse($attrs["TIME"]); // yay we gotta parse this don't we? + $shared = !isset($attrs["SHARED"]); $obj = db_fetch_object(db_query("SELECT * FROM {delicious_link} WHERE hash='%s'", $hash)); if ($obj) { - db_query("UPDATE {delicious_link} SET synced=1, description='%s', extended='%s', href='%s', linktime='%s' WHERE hash='%s'", $desc, $extended, $href, $time, $hash); + db_query("UPDATE {delicious_link} SET synced=1, description='%s', extended='%s', href='%s', linktime='%s', shared=%d WHERE hash='%s'", $desc, $extended, $href, $time, $hash, $shared); foreach($tags AS $tag) { $tagobj = db_fetch_object(db_query("SELECT * FROM {delicious_tag} WHERE lid=$obj->lid and name='$tag'")); @@ -858,7 +916,7 @@ function _delicious_update_user($user) { else { $lid = db_next_id("{delicious_link}_lid"); - db_query("INSERT INTO {delicious_link} (lid, uid, href, description, extended, linktime, hash, synced) VALUES (%d, %d, '%s', '%s', '%s', %d, '%s', 1)", $lid, $this->uid, $href, $desc, $extended, $time, $hash); + db_query("INSERT INTO {delicious_link} (lid, uid, href, description, extended, linktime, hash, synced, shared) VALUES (%d, %d, '%s', '%s', '%s', %d, '%s', 1, %d)", $lid, $this->uid, $href, $desc, $extended, $time, $hash, $shared); foreach($tags AS $tag) { @@ -872,12 +930,19 @@ function _delicious_update_user($user) { } } -// ---------------------------------------------------------------------------- -// smart/crosslinking stuff and general support +// @} End of @name XML parsing objects -// -// render a link to the node's first term if present for crosslinking -// +/** + * @name smart/crosslinking stuff and general support + * + * @{ + */ + +/** + * render a link to the node's first term if present for crosslinking + * + * @private + */ function _delicious_term_link(&$node) { $terms = taxonomy_node_get_terms($node->nid); $term = $terms[0]->name; @@ -899,35 +964,27 @@ function _delicious_term_link(&$node) { return $url; } -// -// smart-tagging support -// +/** + * smart-tagging support + * + * @private + */ function _delicious_tag_string($text, $tags, $username) { - - if (!$tags) - return $text; - - // error, it must start with a tag... :-( - foreach ($tags AS $tag) { - if (!empty($tag) && $tag != ' ') { - $path = DELICIOUS_BASE_URL . urlencode($username) . '/' .urlencode($tag); + // TODO: url checking + // TODO: cache this! what about a filter? $modulepath = drupal_get_path('module', 'delicious'); - $deliciousLink = "
    "; - - if (!preg_match('/<.+>/',$text)) { - $text = preg_replace('/(\b'.$tag.'\b)/i','$1'.$deliciousLink,$text); - } else { - $text = preg_replace('/(?<=>)([^<]+)?(\b'.$tag.'\b)/i','$1$2'.$deliciousLink,$text); - } - } - } - - return $text; + return preg_replace( + '/\b('. implode('|', array_map('preg_quote', $tags)) .')\b/', + '$1', + $text + ); } -// -// support function for tagged text -// +/** + * support function for tagged text + * + * @private + */ function _delicious_tag_text($text, $name) { $result = db_query("SELECT distinct(name) FROM {delicious_tag}"); while ($tag = db_fetch_object($result)) { @@ -936,9 +993,11 @@ function _delicious_tag_text($text, $nam return _delicious_tag_string($text, $tags, $name); } -// -// General configuration support -// +/** + * General configuration support + * + * @private + */ function _delicious_nodetype_applicable($type) { $del = variable_get('delicious_node_types', array('blog', 'story', 'page')); if (!is_array($del)) @@ -947,16 +1006,30 @@ function _delicious_nodetype_applicable( return in_array($type, $del); } -// Translate delicious dates into normal dates +/** + * Translate delicious dates into normal dates + * + * @private + */ function _delicious_date_parse($date) { $date = str_replace('T', ' ', $date); $date = str_replace('Z', ' ', $date); return strtotime($date); } -// -// theming function -// +/** + * @private + */ +function _delicious_get_link($obj) { + return l($obj->description, $obj->href, array ('title' => format_date($obj->linktime), 'class' => 'delicious_node'), NULL, NULL, TRUE); +} +// @} End of @name smart/crosslinking stuff and general support + +/** + * theming function + * + * @ingroup themeable + */ function theme_delicious_user($uid) { global $numActuators; @@ -1023,7 +1096,3 @@ function theme_delicious_user($uid) { return $output; } - -function _delicious_get_link($obj) { - return "$obj->description"; -}