### Eclipse Workspace Patch 1.0 #P click2bookmark Index: click2bookmark.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/click2bookmark/click2bookmark.install,v retrieving revision 1.2 diff -u -r1.2 click2bookmark.install --- click2bookmark.install 21 Jan 2008 09:32:46 -0000 1.2 +++ click2bookmark.install 10 Dec 2008 03:56:18 -0000 @@ -4,45 +4,40 @@ /** * Implementation of hook_install(). */ - function click2bookmark_install() { - - switch ($GLOBALS['db_type']) { - - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {click2bookmark} ( - c2bid INT UNSIGNED NOT NULL AUTO_INCREMENT, - uid INT UNSIGNED NOT NULL DEFAULT 0, - path VARCHAR(255) NOT NULL, - title VARCHAR(255) NOT NULL, - PRIMARY KEY (c2bid) - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); - break; - - case 'pgsql': - db_query("CREATE TABLE {click2bookmark} ( - c2bid serial CHECK (c2bid >= 0), - uid int NOT NULL default '0', - path varchar(255) NOT NULL default '', - title varchar(255) NOT NULL default '', - PRIMARY KEY (c2bid) - )"); - break; - - } // End case - + drupal_install_schema('click2bookmark'); } - - - /** * Implementation of hook_uninstall(). */ function click2bookmark_uninstall() { - db_query('DROP TABLE {click2bookmark}'); + drupal_uninstall_schema('click2bookmark'); foreach(node_get_types() as $type => $name) { variable_del(CLICK2BOOKMARK_NODE_TYPE . $type); } -} \ No newline at end of file + +} + +/** + * Implementation of hook_schema(). + */ +function click2bookmark_schema() { + + $schema = array(); + $schema['click2bookmark'] = array( + 'description' => t('Stores bookmarks.'), + 'fields' => array( + 'c2bid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => t('Primary Key: Unique id.'),), + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => t('{user}.uid of bookmark owner.'),), + 'path' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => t('Menu path.'),), + 'title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => t('Custom title.'),), + ), + 'indexes' => array( + 'path' => array('path'), + 'uid' => array('uid'), + ), + 'primary key' => array('c2bid'), + ); + return $schema; +} Index: click2bookmark.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/click2bookmark/click2bookmark.module,v retrieving revision 1.6 diff -u -r1.6 click2bookmark.module --- click2bookmark.module 28 Feb 2008 12:06:54 -0000 1.6 +++ click2bookmark.module 10 Dec 2008 03:56:20 -0000 @@ -12,8 +12,8 @@ /** * Implementation of hook_help() */ -function click2bookmark_help($section) { - switch ($section) { +function click2bookmark_help($path, $arg) { + switch ($path) { case 'admin/help#click2bookmark': return t( "
The click2bookmark modules adds a link 'Add to bookmark' on all the nodes of a selected content type. A link 'My bookmarks' is added to the navigation bar, as well as a block listing all the bookmarks.
@@ -34,88 +34,74 @@ /** * Implementation of hook_menu(). */ -function click2bookmark_menu($may_cache) { - +function click2bookmark_menu() { $items = array(); - - if ($may_cache) { - $items[] = array( - 'path' => 'bookmark/add', - 'callback' => '_click2bookmark_bookmark_add', - 'type' => MENU_CALLBACK, - 'access' => user_access(CLICK2BOOKMARK_PERM), - ); - $items[] = array( - 'path' => 'bookmark/view', - 'callback' => '_click2bookmark_bookmarks_view', - 'title' => t('My bookmarks'), - 'access' => user_access(CLICK2BOOKMARK_PERM), - ); - $items[] = array( - 'path' => 'bookmark/del', - 'callback' => '_click2bookmark_bookmark_del', - 'type' => MENU_CALLBACK, - 'access' => user_access(CLICK2BOOKMARK_PERM), - ); - $items[] = array( - 'path' => 'admin/settings/click2bookmark', - 'title' => t('Click2bookmark settings'), - 'description' => t('Settings per content type.'), - 'callback' => 'drupal_get_form', - 'callback arguments' => 'click2bookmark_settings', - 'type' => MENU_NORMAL_ITEM, - 'access' => user_access(CLICK2BOOKMARK_ADMIN), - ); - - } + $items['bookmark/add'] = array( + 'title' => 'Add bookmark', + 'page callback' => '_click2bookmark_bookmark_add', + 'type' => MENU_CALLBACK, + 'access arguments' => array(CLICK2BOOKMARK_PERM), + ); + $items['bookmark/view'] = array( + 'title' => t('My bookmarks'), + 'page callback' => '_click2bookmark_bookmarks_view', + 'access arguments' => array(CLICK2BOOKMARK_PERM), + ); + $items['bookmark/del'] = array( + 'title' => 'Delete bookmark', + 'page callback' => '_click2bookmark_bookmark_del', + 'type' => MENU_CALLBACK, + 'access arguments' => array(CLICK2BOOKMARK_PERM), + ); + $items['admin/settings/click2bookmark'] = array( + 'title' => t('Click2bookmark settings'), + 'description' => t('Settings per content type.'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('click2bookmark_settings'), + 'type' => MENU_NORMAL_ITEM, + 'access arguments' => array(CLICK2BOOKMARK_ADMIN), + ); + return $items; } function _click2bookmark_bookmark_add($nid = 0) { - global $user, $_SESSION; - - $ajax_enabled = (variable_get(CLICK2BOOKMARK_AJAX, 0) == 1); - - $result = db_query('SELECT * FROM {node} WHERE nid="%d"', $nid); - if ($result && db_num_rows($result) > 0) { - $node = db_fetch_object($result); - } else { - drupal_set_message(t('This content can\'t be bookmarked...')); - return false; - }; - if (!$node->nid) { - drupal_set_message(t('This content can\'t be bookmarked...')); - return false; + if ($node = node_load(array('nid' => $nid))) { + if (variable_get(CLICK2BOOKMARK_NODE_TYPE . $node->type, 0)) { + // book mark it + _click2bookmark_bookmark_node($node); + drupal_goto($node->path ? $node->path : 'node/'.$node->nid); + } } - if (!variable_get(CLICK2BOOKMARK_NODE_TYPE . $node->type, 0)) { - drupal_set_message(t('This content can\'t be bookmarked...')); - return false; + $ajax_enabled = (variable_get(CLICK2BOOKMARK_AJAX, 0) == 1); + if (!$ajax_enabled) { + drupal_set_message(t('This content can\'t be bookmarked...')); } - $node->path = drupal_get_path_alias('node/'.$nid); + return false; +} - +function _click2bookmark_bookmark_node($node) { + global $user; + $ajax_enabled = (variable_get(CLICK2BOOKMARK_AJAX, 0) == 1); + $node->path = drupal_get_path_alias('node/'. $node->nid); if ($user->uid) { // Store into database - $result = db_query('SELECT path FROM {click2bookmark} WHERE path="%s" AND uid="%d"', $node->path, $user->uid); - if ($result && db_num_rows($result) > 0) { + $result = db_result(db_query('SELECT path FROM {click2bookmark} WHERE path="%s" AND uid=%d', $node->path, $user->uid)); + if ($result) { if (!$ajax_enabled) { drupal_set_message(t('This page is already bookmarked by you!')); - } else { + } + else { //TODO: No feedback provided, something I need to work on }; - } else { - $result = db_query('INSERT INTO {click2bookmark} (uid, path, title) VALUES (%d, \'%s\', \'%s\')', $user->uid, $node->path ? $node->path : 'node/'.$node->nid, $node->title); + } + else { + $result = db_query("INSERT INTO {click2bookmark} (uid, path, title) VALUES (%d, '%s', '%s')", $user->uid, $node->path ? $node->path : 'node/'.$node->nid, $node->title); if (!$ajax_enabled) { - if ($result) { - drupal_set_message(t('Bookmark saved!')); - } else { - drupal_set_message(t('Error while saving bookmark...')); - }; - } else { - //TODO: We returned 'Bookmark saved', whichever the returned status is. Needs work. - }; + drupal_set_message(t('Bookmark saved!')); + } }; } else { // Store into cookie @@ -130,11 +116,8 @@ // Status returned by the javascript. }; }; - - drupal_goto($node->path ? $node->path : 'node/'.$node->nid); } - function _click2bookmark_bookmarks_view() { print theme('page', theme('click2bookmark_bookmarks_view', _click2bookmark_load())); } @@ -224,11 +207,9 @@ for ($i = 0; $i < sizeof($pages); $i++) { $bookmark = explode('|', $pages[$i]); if (is_array($bookmark)) { - $result = db_query('SELECT path FROM {click2bookmark} WHERE path="%s" AND uid="%d"', $bookmark[0], $account->uid); - if ($result && db_num_rows($result) > 0) { - // Don't add duplicates - } else { - $result = db_query('INSERT INTO {click2bookmark} (uid, path, title) VALUES (%d, \'%s\', \'%s\')',$account->uid, $bookmark[0], $bookmark[1]); + $result = db_results(db_query('SELECT count(path) AS count FROM {click2bookmark} WHERE path="%s" AND uid=%d', $bookmark[0], $account->uid)); + if (!$result) { + $result = db_query("INSERT INTO {click2bookmark} (uid, path, title) VALUES (%d, '%s', '%s')",$account->uid, $bookmark[0], $bookmark[1]); }; }; }; @@ -249,7 +230,7 @@ if ($type != 'node' || $teaser || !user_access(CLICK2BOOKMARK_PERM) || !variable_get(CLICK2BOOKMARK_NODE_TYPE . $node->type, 0)) { return $link; }; - + // Create 'Click to bookmark' link $link['click2bookmark_add_bookmark'] = array( 'title' => t('Click to bookmark'), @@ -287,22 +268,23 @@ } + /** * Implementation of hook_block(). */ function click2bookmark_block($op = 'list', $delta = 0, $edit = array()) { - - if (!user_access(CLICK2BOOKMARK_PERM)) { return array(); }; - - if ($op == 'list') { + // allow anyone to configure the block + if ($op == 'list') { $blocks[0] = array( 'info' => t('My bookmarks'), - 'enabled' => 1, + 'status' => 1, + 'weight' => 0, 'region' => 'left', ); return $blocks; - } else if ($op == 'view') { + } else if ($op == 'view' && user_access(CLICK2BOOKMARK_PERM)) { + switch($delta) { case 0: $block = array( @@ -397,4 +379,18 @@ }; return theme_links($links, array('class' => 'click2bookmark-block-links')); -} \ No newline at end of file +} + +/** + * Implementation of hook_theme(). + */ +function click2bookmark_theme($existing, $type, $theme, $path) { + return array( + 'click2bookmark_display_block' => array( + 'arguments' => array('bookmark_list' => array()), + ), + 'click2bookmark_bookmarks_view' => array( + 'arguments' => array('bookmark_list' => array()), + ), + ); +} Index: click2bookmark.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/click2bookmark/click2bookmark.info,v retrieving revision 1.4 diff -u -r1.4 click2bookmark.info --- click2bookmark.info 21 Jan 2008 09:32:46 -0000 1.4 +++ click2bookmark.info 10 Dec 2008 03:56:18 -0000 @@ -1,4 +1,6 @@ ; $Id: click2bookmark.info,v 1.4 2008/01/21 09:32:46 ericdes Exp $ name = "Click2bookmark" description = "Allow users to bookmark nodes and retrieve them in a block." -project = "click2bookmark" \ No newline at end of file +core = 6.x +dependencies[] = content +package = Other