CVS edit link for miclaelpporter

I work with Duo Consulting, we are currently working on V-card and simple mobile redirect modules. We would like to share them back to the community. The simple mobile redirect will provide text fields for quick entry of custom URL's for mobile platforms, iPad, iPhone, Blackberry, Android etc. This will make it quick and easy to enter urls for the mobile version of the site if it was not build in Drupal. There is also a function to store a cookie to use the 'desktop' version of the site. I would also like to help wit bug fixes as I find ones that I can fix.

Comments

michaelpporter’s picture

Assigned: Unassigned » michaelpporter

attached is the simple_mobile_redirect module I am proposing

michaelpporter’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new5.01 KB

attached file

avpaderno’s picture

Assigned: michaelpporter » Unassigned
Status: Needs review » Needs work
Issue tags: +Module review

Hello, and thanks for applying for a CVS account. I am adding the review tags, and some volunteers will review the code, pointing out what it needs to be changed.

As per requirements, the motivation message should be expanded to contain more features of the proposed project. For themes, it should include also a screenshot of the theme, and (when possible) a link to a working demo site using the proposed theme; for modules, it should include also a comparison with the existing solutions.

michaelpporter’s picture

This is working on http://www.duoconsulting.com/ you have to browse with a mobile device or change the header using dev tools to fake an iPhone/iPad etc. once on the mobile site http://m.duoconsulting.com/ you can link back to the main site which sets a cookie to used to not redirect you back to the mobile site.

michaelpporter’s picture

The simple_mobile_redirect module is designed to make it easy to direct people to a mobile version of the site that is hosted on a different URL. There are settings for: iPad, iPhone/iPod touch,Android,Opera Mini,Blackberry,Palm Web OS,Window Mobile. If you browse to a site that contains '?nomobi=yes' it will set a cookie to prevent redirecting the user to the mobile site. Browsing to '/clearsimplemobileredirect' it will clear the cookie and redirect per the settings.

michaelpporter’s picture

Assigned: Unassigned » michaelpporter
Status: Needs work » Needs review

What is the status of the review?

michaelpporter’s picture

Assigned: michaelpporter » Unassigned
michaelpporter’s picture

Title: miclaelpporter [miclaelpporter] » michaelpporter [michaelpporter]

corrected spelling of name

michaelpporter’s picture

Title: michaelpporter [michaelpporter] » simple_mobile_redirect [simple_mobile_redirect]

Updated to the project name

avpaderno’s picture

Title: simple_mobile_redirect [simple_mobile_redirect] » michaelpporter [michaelpporter]
meba’s picture

The module has obvious coding standard issues like indenting, see http://drupal.org/coding-standards please.

Security seems fine.

avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Needs work
  • The points reported in this review are not in order or importance / relevance.
  • Most of the times I report the code that present an issue. In such cases, the same error can be present in other parts of the code; the fact I don't report the same issue more than once doesn't mean the same issue is not present in different places.
  • Not all the reported points are application blockers; some of the points I report are simple suggestions to who applies for a CVS account. For a list of what is considered a blocker for the application approval, see CVS applications review, what to expect. Keep in mind the list is still under construction, and can be changed to adapt it to what has been found out during code review, or to make the list clearer to who applies for a CVS account.
  1. ; Information added by drupal.org packaging script on Jul-26-2010
    version = "6.x-1.1"
    core = "6.x"
    project = "simple_mobile_redirect"
    package = "Simple Mobile Redirect"
    datestamp = "1222796709"
    

    Those lines need to be removed from the .info file.

  2. function simple_mobile_redirect_perm() {
      return array('Administer Simple Mobile Redirect configuration');
    }
    
    

    The permission doesn't follow the schema used for Drupal permissions. It should be administer simple mobile.

  3. See http://drupal.org/coding-standards to understand how a module should be written. In particular, see how the code should be formatted, and how constants should be written.
  4. function _simple_mobile_redirect_clearcookie() {
    	setcookie("nomobi", "", time()-3600);
    	header('Location: /'); 
    }
    
    

    The code is not using the correct Drupal function that should be used to redirect users to a different location. Drupal can be installed on a sub-directory of the web root directory; redirecting the user to / would not redirect it to the home page of a Drupal-powered site.

  5.   switch(true){ 
    
        case (preg_match('/ipad/i',$user_agent)); // find the word ipad in the user agent
          $is_mobile_browser = $ipad; 
          $platform = 'Apple iPad';
          if(substr($ipad,0,4)=='http'){ // Is there a URL to redirect iPads to?
            $simplemobileredirect = $ipad; 
          } 
        break; // break out and skip the rest
    
    

    I would not use switch() when the code is not checking a variable (or the value returned from a function) against different values; apart that, there is a PHP error in the code.
    Comments should be placed in a different line than the code.

  6.   drupal_load('module', 'simple_mobile_redirect');
      $variables = array_keys(simple_mobile_redirect_variables());
    
    

    The function being called doesn't exist.

michaelpporter’s picture

Status: Needs work » Needs review
StatusFileSize
new4.3 KB

I have updated the module based on the notes above. I have added comments to some cases where I keep the code as is.

4. I can not use drupal_goto() here as this is part of the boot hook, per drupal loading still. I have added a setting/variable that can be set for the non-mobile home page.

5. I feel a switch is better here even though there is not one variable being checked, this allows the code to move on once it found a match, better than a if/ifelse/else IMO

avpaderno’s picture

Status: Needs review » Needs work
  1. /**
     * Implementation of hook_perm().
     */
    function simple_mobile_redirect_perm() {
      return array('administer simple mobile');
    }
    function _simple_mobile_redirect_clearcookie() {
      setcookie("nomobi", "", time()-3600);
      $simplemobileredirect = variable_get('simple_mobile_redirect_mobileredirect', '/');
      if ($simplemobileredirect == '/'){
        $simplemobileredirect = '';
      }
      drupal_goto($simplemobileredirect);
    }
    

    Leave an empty line between a function and the other.

  2.   switch(true){ 
        // find the word ipad in the user agent
        case (preg_match('/ipad/i',$user_agent)); 
    
    

    See http://drupal.org/coding-standards to understand how a module should be written. In particular, see how constants should be written, and how the code should be formatted.
    The syntax used for case (preg_match('/ipad/i',$user_agent)); is not the syntax suggested by the coding standards.
    The code should be written as

      switch (TRUE) { 
        // find the word ipad in the user agent
        case (preg_match('/ipad/i',$user_agent)): 
    
    
michaelpporter’s picture

Status: Needs work » Needs review
StatusFileSize
new6.74 KB

Cleaned up the layout based on the latest comments.

avpaderno’s picture

Assigned: avpaderno » Unassigned
michaelpporter’s picture

kiamlaluno thank you for your time and input.

avpaderno’s picture

Status: Needs review » Needs work

The code is not using spaces where the coding standards suggest to use it. That is done in almost all the code, and that makes it difficult to read. Point #2 of my previous comment is still applicable.

michaelpporter’s picture

Status: Needs work » Needs review
StatusFileSize
new4.34 KB

Updated the code to change end of functions and "if's" from ){ to ) { per formatting.

avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Fixed
michaelpporter’s picture

Status: Fixed » Closed (works as designed)
avpaderno’s picture

Status: Closed (works as designed) » Fixed

Status: Fixed » Closed (fixed)
Issue tags: -Module review

Automatically closed -- issue fixed for 2 weeks with no activity.

avpaderno’s picture

Component: Miscellaneous » new project application
Issue summary: View changes
Status: Closed (fixed) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.