Build A Digg Clone With Drigg For Drupal – Part 2 Installing And Configuring Drupal And Drigg

Pages: 1 2 3 4 5

Finishing Up Your Drigg Install And Giving Users Access

We now need to give users the correct access levels for your drigg website, otherwise they wont be able to do anything or brows stories. To do this we need to make a visit to Drupals Access control section which can be found at the URL below.

http://yoursite.com/admin/user/access

Rather than go through each and every option we have provided a screenshot of what should be ticked initially at setup. Simply copy what we have ticked in you install and click Save Configuration at the end of it.

Enable Seo Titles
While playing with the system, you must have noticed that stories are referred to as /node/3 or /node/5 etc. This is less than optimal. In order to have URLs like /Category/The-articles-title-more-or-less, you will need to:

  • Open the file [your_server]/sites/all/modules/drigg/custom_url_rewrite_function.php. This file came with the drigg module.
  • Select all of the text and copy it to the clipboard (all of it, from function custom_url_rewrite($op, $result, $path, $path_language=NULL) to the end of the file
  • Paste it right at the end of your settings.php file, which is probably located in sites/default/settings.php
  • That’s it!

Below is the code you need to paste into /sites/all/settings.php.

function custom_url_rewrite($op, $result, $path, $path_language=NULL) {

  $term_list=variable_get("drigg_section_list",array());
  $tag_vid=variable_get('drigg_tag_vid','');

  // This is OUTGOING stuff
  if($op == 'alias'){

    // Make outgoing links look right
    if (preg_match('|^node/([^/]+)(.*)$|', $path, $matches)) {
      $n = $matches[1];
      $rest = $matches[2];

      if(is_numeric($n)){
        $res= drigg_settings_lookup_drigg_node_by_dnid($n);
        if($res){
          // Return the right URL
          $safe_section=$res->safe_section;
          $title_url=$res->title_url;
          // I hate this, but we need to have it because you never know
          $safe_section = $safe_section != '' ? $safe_section : 'All';
          return("$safe_section/$title_url$rest");
        }
      }
    }

    // Make TAG links look right
    if (preg_match('|^taxonomy/term/([0-9]+)(/?)(.*)$|', $path, $matches)) {

      if($matches[3] == ''){
        $tid = $matches[1];
        $res=drigg_settings_lookup_term_name_by_tid($tid);
        if($res){
          $res=urlencode($res);
          return("tag/".$res);
        }
      }

    }

    // Make users look right
    if (preg_match('|^user/([^/]+)(.*)$|', $path, $matches)) {
      $uid = $matches[1];
      $rest = $matches[2];
      $res=drigg_settings_lookup_user_name_by_uid($uid);
      if($res){
        $res=urlencode($res);
        return("users/${res}${rest}");
      }
    }

  }

  // This is INCOMING requests
  if($op == 'source'){

    // Change the INCOMING links, so that people can view
    // www.a.com/Community/Embedded_Linux_pioneer_offers_webinar/ or even
    // www.a.com/Community/Embedded_Linux_pioneer_offers_webinar/edit
    //
    if(preg_match('%^(.*?)/([^/]+)(.*)$%', $path, $matches)){
      $cat = $matches[1];
      $title_url = $matches[2];
      $rest = $matches[3];
      if( isset($term_list['by_safe_name'][$cat]) || $cat== 'All'){
        $res=drigg_settings_lookup_drigg_node_by_title_url($matches[2]);
        if($res){
          $nid=$res->dnid;
          $safe_section = $res->safe_section;

          // Check that the article's category matches the requested
          // one. This is not strictly necessary
          /* if($cat != "All" && $cat != $safe_section){
            return 'file_not_found';
          }*/ 

          return 'node/'.$nid.$rest;
        }
      }
    }

    // Change /tag/pippo into taxonomy/term/33
    if(preg_match('%^tag/([^/]+)$%', $path, $matches)){
      $tag = urldecode($matches[1]);
      $tid= drigg_settings_lookup_term_tid_by_name($tag);

      if($tid){
        return 'taxonomy/term/'.$tid;
      }
    }

    // Change /users/pippo into user/33
    if (preg_match('|^users/([^/]+)(.*)$|', $path, $matches)) {
      $name = urldecode($matches[1]);
      $rest = $matches[2];
      $res=drigg_settings_lookup_user_uid_by_name($name);

      if($res){
        return("user/${res}${rest}");
      }
    }

  }

  return $result;
}

function drigg_settings_lookup_term_tid_by_name($name){
  static $cache;

  if(!$cache[$name]){
    $res=db_result(db_query("SELECT tid FROM {term_data} WHERE name ='%s'",$name));
    $cache[$name]=$res;
  }
  return $cache[$name];
}

function drigg_settings_lookup_term_name_by_tid($tid){
  static $cache;

  if(!$cache[$tid]){
    $res=db_result(db_query("SELECT name FROM {term_data} WHERE tid =%d",$tid));
    $cache[$tid]=$res;
    #drupal_set_message("HERE: SELECT name FROM {term_data} WHERE tid =$tid: $res");

  }
  return $cache[$tid];
}

function drigg_settings_lookup_drigg_node_by_dnid($dnid){
  static $cache;

  if(!$cache[$dnid]){
    $res=db_fetch_object(db_query("SELECT safe_section,title_url FROM {drigg_node} WHERE dnid ='%d'",$dnid));
    $cache[$dnid]=$res;
  }
  return $cache[$dnid];
}

function drigg_settings_lookup_drigg_node_by_title_url($title_url){
  static $cache;

  if(!$cache[$title_url]){
        $res = db_fetch_object(db_query("SELECT dnid,safe_section FROM {drigg_node} WHERE title_url ='%s'",$title_url));
    $cache[$title_url]=$res;
  }
  return $cache[$title_url];
}

function drigg_settings_lookup_user_uid_by_name($name){
  static $users;

  if(!$users[$name]){
    $uid= db_result(db_query("SELECT uid FROM {users} WHERE name ='%s'",$name));
    $users[$name]=$uid;
  }
  return $users[$name];
}
function drigg_settings_lookup_user_name_by_uid($uid){
  static $users;

  if(!$users[$uid]){
    $name= db_result(db_query("SELECT name FROM {users} WHERE uid =%d",$uid));
    $users[$uid]=$name;
  }
  return $users[$uid];
}

The only other thing left to do is configure your recaptcha plugin which you will need to register at the ReCaptcha website for. Place recaptcha on you registration form and any other form you like to prevent spam.

Then enable some sidebar blocks from the blocks administration section.

This has been quite a challenging article to write and keep it simple enough to understand for anyone new to drupal. Hopefully though you will have read this article and now have a functioning drigg site, we know this isn’t the complete low down on Drigg and thats why we have a few more articles planned covering some of the more advanced features and functions that drigg can perform.

We will also be showing you, how to vastly expand you Drigg site beyond anything any of it’s competitors can offer by the use of modules, Optimizing Drupal and Drigg for faster load times and less bandwidth usage, releasing a few free Drigg templates and showing a few tutorials on how to template for the drigg system.

Oh! and answering any questions you may have, and if you want a tutorial for Drigg please contact us and let us know what you wold like us to cover next.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Pages: 1 2 3 4 5

Article Details

#

Author: Lincoln on October 22nd, 2008

Category: Drigg, Planet Drupal

Tags: , , , , ,

  1. Ronit says:

    thnx a lot man !!!
    really helped me a lot !!

    cheers again

  2. Gaurav Paul says:

    Hi Lincoln,

    With this tutorial i got through in installation. but some problem persist.

    I have a Wordpress installation in root (public_html) and new drigg installation in subdirectory “beta” (public_html/beta). i have also redirectet beta.mysite.com to mysite.com/beta. Now when i browse to mysite.com/beta front page works good. Then if i use any link within the drupal installation it looks like (mysite.com/link) instead of (mysite.com/beta/link)and using that link takes me to the Wordpress site not to drupal installation. I tried with .htaccess and setings.php but no success :( .

    $base_url = mysite.com OR beta.mysite.com
    RewriteBase /beta OR /

    (I tried every possible combination of two above)

    you can check it out http://www.opencamp.in (WP site)

    and http://www.opencamp.in/beta or http://www.beta.opencamp.in (drupal+drigg with drupala theme site)

    Help!

  3. Lincoln says:

    Hi Gaurav,

    You cannot simply redirect a subdomain to the root of your Drupal install /beta. You must install drupal on the subdomain you created with no redirect. http://www.beta.opencamp.in/ install drupal under that domain and it will work.

    ;)

  4. Gaurav Paul says:

    :)

    Any input? how to setup mailing function for drigg (for forget your password thingy).

    i guess it has to do with php.ini

  5. Gaurav Paul says:

    Thanks bud for your awesome article..

    for sending mail from drupal try “SMTP” module :)

  6. eldred says:

    Thanks for the amazingly easy to understand and impliment tutorial. Was just wondering if you still had plans to release an article about the section of the drigg you mentioned “we know this isn’t the complete low down on Drigg and thats why we have a few more articles planned covering some of the more advanced features and functions that drigg can perform.”

    Also was wondering if there will be a tutorial on implimenting either a dynamic display block or frontpage slideshow block that could show the latest of highest karma scoopes?

  7. eldred says:

    Another question i forgot is about Embedding videos.I clicked on all the video types options but when i go to submit scoop, there is no section to embed video.How can i solve this?

  8. jewel says:

    I’m really missing u man! Where are you now? Why r u absent in such a long time?
    This is the greatest article that has written in this topic.

  9. Dana says:

    This is gonna be excellent, gonna do a better digg.

  10. Drupal is very power, when we build a large sized website, it is one of the best selection.