This forum is for module development and code related questions, not general module support. For general support, use the Post installation forum.

node privacy by.... can we have user?

Hi... I was looking at the nodeprivacybyrole module, and it's pretty cool and really useful.

Is there any node privacy by [b]user[/b] module in work or in plan?

Footnotes module - a proposed solution

There is an old problem in Drupal, which is that when you copy/paste text containing references to within the page, then because of the way Drupal handles the URLs, if you click on the references you get sent to the front page, instead of getting sent to the reference in the same page.
I find this particularly annoying because the site I am developing will take content (articles) copy/pasted from Word or OpenOffice (Word/XP now does a particularly nice job of converting superscripted footnote references into something easily readable on the web when you copy/paste), and these articles very often have footnotes generated by the Word or OpenOffice.

I wrote this module (for 4.5.0) to handle the problem - but feel a bit intimidated submitting it to CVS because a) there are clearly lots of people who are far better than me at doing this kind of thing and b) I can't guarantee to maintain it, plus c) although it seems to work for me there may be other cases I've not taken into account.

What does the module do?
Basically, it works with page, story, or book type nodes, searches the node body for any occurrences of href=#xxx (or href=yyy#xxx) and replaces these with href=pathalias#xxx. Occurrences of href=#xxx are stripped out of the teaser (don't want them to appear here and anyway they could lead to confusion). In all other node types, it just strips the notes out altogether (this of course is fine for my purposes but not necessarily very generic).

In order for the module to work, you have to have the "path" module enabled, and enter a "Path alias" for the content. You can't just use the node number, because when you are in the process of creating a node, the node number is not yet known. Consequently, you can't use it (logical!!).

Anyway, here is the code. Any comments would be very welcome - otherwise feel free to use and I hope this is helpful:

// $Id: node_footnotes.module,v 0.1 2004/10/20 Joel Guesclin $

/**
 * @file
 * Resolves the problem of dead footnotes (eg bottom of page notes) as
 * generated by Word or OpenOffice
 */


/**
 * Implementation of hook_help().
 */
function node_footnotes_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Converts footnote references to include node reference');
  }
}

/**
 * Implementation of hook_nodeapi().
 */

function node_footnotes_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'validate':
      if ($node->type == 'page' || $node->type == 'story' || $node->type == 'book') {
         if ($node->title) {
// Here is the original regular expression to get all anchors out of a chunk of HTML:
// '/<a(\s)+[^>]*href(\s)*=(\s)*(\'|")*[^"\'>]+(\'|")*[^>]*(\s)*>(.|\s)*?<\/a(\s)*>/i'
// Thankyou Sam Fullman at codewalkers.com for a sweet piece of coding!!!
// And then, we add the hash in order to find only the footnote type href's
             $findMatches = preg_match_all
('/(<a(\s)+[^>]*href(\s)*=(\s)*(\'|")*)([^"\'>]*)#+([^"\'>]+(\'|")*[^>]*(\s)*>(.|\s)*?<\/a(\s)*>)/i',
$node->body,$matches); // "
             if($findMatches){
                if (empty($node->path)) {
                   form_set_error('path', t('You must supply a path.'));
                   break;
                   }
                $string = $node->body;
                $pattern = '/(<a(\s)+[^>]*href(\s)*=(\s)*(\'|")*)([^"\'>]*)#+([^"\'>]+(\'|")*[^>]*(\s)*>(.|\s)*?<\/a(\s)*>)/i'; // "
                $replacement = '\\1'.$node->path.'#\\7';
                $node->body = preg_replace($pattern, $replacement, $string);
                if ($node->teaser) {
                   $string = $node->teaser;
                   $replacement = '';
                   $node->teaser = preg_replace($pattern, $replacement, $string);
                   }
                }
             }
         }
      else {
         $pattern = '/(<a(\s)+[^>]*href(\s)*=(\s)*(\'|")*)([^"\'>]*)#+([^"\'>]+(\'|")*[^>]*(\s)*>(.|\s)*?<\/a(\s)*>)/i'; // "
         if ($node->body) {
            $string = $node->body;
            $replacement = '';
            $node->body = preg_replace($pattern, $replacement, $string);
            }
         if ($node->teaser) {
            $string = $node->teaser;
            $replacement = '';
            $node->teaser = preg_replace($pattern, $replacement, $string);
            }
         }

  }
}

By the way, the occasional comments (//") are just there to unconfuse MPS PHP Designer so that it switches its colour coding back to something coherent!

User Searchable User List (development)

USER SEARCHABLE USER LIST:
I am still fairly new to Drupal but after some thought and initial reading of API's and modules etc. I thought I'd throw in my thoughts and see if anything bounces back (as it is very slow going from the ground up on my own!).

Currently it is possible to view a list of users (details) according to role.
I wish to create a new search/reporting facility that produces sub-sets of this list.
If my ideas rework existing code or are way off base for some reason then please feel free to point in the right direction.

My approach is to be in two phases (unless someone decides to help accelerate it. I need to have phase 1 by end of this month; phase two is the nicer way to do it, but consider phase 1 proof of concept):

Phase One
Phase 1 will
i) create a simple form for user input that lists the available profile fields for the search. This will only be avilable to members of the site (rid>0), and will allow selection of the criteria (from list or checkbox according to the profile_field type)

ii) on form submission the selection criteria will be used to form the data query before calling the function to produce the list of users
OR (if easier/possible for phase 1 )
use an overide of whatever the function is to 'display users list' and only display a user IF all search profile_field values = listing-user-profile_field values.

Extended User Attributes

Hi All

I'm had a search through the modules/forums and I hope I'm not missing something.

Can anyone help point me the right way to extend the user attributes? I'd like to capture more info when a user registers e.g Hobbies, Age, more exact location....... what's the best way to go about this? Write a module or re-write drupal?

thanks
Simon

Music module!

I needed to upload/download and play mp3 files on my site so I made a music module, it's still a bit buggy but overal it works good, I used the getid3 project to enable reading id3v2 tags, it disabled rewriting tags, because it was returning just to many errors at this time. Apart from storing the id3v2 info in the file, it's also stored in the db in a seperate table. Anyway i've been using it for some time now on my site and it's doing what it's supposed to except for the download feature. I just noticed a few days ago, that when a user is not logged in some files can be downloaded and some can't and return a '500 Internal Server Error'. Here's the code I use in for the download hook:

  switch (arg(1)) {
    case "download":
      $node = node_load(array("nid" => arg(2)));
      header("Expires: ". gmdate("D, d M Y H:i:s") ." GMT");
      header("Content-Type: audio/mpeg");
      header("Content-Length: ". $node->filesize);
      header("Content-Disposition: attachment; filename=" .$node->filename);
      readfile(variable_get("music_files_dir", "music_files/") ."musicfile_$node->nid.mp3");
      db_query("UPDATE {music} SET downloads = downloads + 1 WHERE nid = $node->nid");
      break;
  }

I suspect it probably has something to do with drupal caching these pages, because while logged in there's no problem at all.
If anyone can has any idea how I should handle this or how I can disable the caching for these pages, please let me know.

Blog this! module

I created a module to add a Blog this! bookmarklet to the user pages for Drupal 4.5. It is available for download here.

I have a few questions to ask the Drupal devs or more experienced module programmers:

Pages

Subscribe with RSS Subscribe to RSS - Module development and code questions