Jump to content

nappyhead

Members
  • Posts

    8
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

nappyhead's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I was given this function question for an interview. I don't think I'm interested in the job and therefore will not submit this, but I am curious how to answer this. Once I start something like this, I can't just quit without knowing the answer. Questions: 1. Does the function have any errors? 2. What is the purpose of the function? 3. What can be done to improve it? 4. Why is isset() used instead of a simple conditional used above it? 5. What assumptions can you make about the database structure? function auto_query( $table, $vars ) { $_result = $this->query( "EXPLAIN $_table_name" ); $_fields = array(); // Empty array assigned to variable while( $_row = $_result->fetchRow() ) { array_push( $_fields, $_row['Field'] ); // Push one or more elements onto the end of array } if( $vars[$table . 'id'] ) { $_query = "UPDATE $_table SET "; } else { $_query = "INSERT INTO $_table SET " . $_table . '_date_created = NOW(), '; } $_query_params = array(); // Empty array assigned to variable foreach( $_fields as $_field ) { if( isset( $_vars[$_field] ) ) { $_query_params[] = "$_field = " . $this->dbh->quoteSmart( $_vars[$_field] ); } } $_query .= implode( ',', $_query_params ); // Join array elements with a string if( $_vars[$_table . '_id'] ) { $_query .= " WHERE {$_table}_id = " . $this->dbh->quoteSmart($_vars[$_table . '_id']); } return $_query; }
  2. Thank you. I'll remember to label it a Drupal module next time. I'll use your advice to make the fix and report back if my problem is resolved.
  3. This is a node voting module I created and it has a slight problem that I cannot figure out. It's supposed to be a simple 'Vote Up' or 'Vote Down' feature. You click 'Vote Up' and one appears in your vote tally. You click 'Vote Down' and your original vote tally is subtracted by one back down to zero. When it goes back to zero, it gets stuck there. It stays on zero no matter if I choose 'Vote Up' or 'Vote Down' again. There's something that's happening when I move my vote tally back down to zero. Maybe something isn't setup correctly with the $current_votes variable. I don't know. I've been at this for hours. Here's the code: <?php function bonnier_vote_perm() { return array('vote on content'); } function bonnier_vote_menu() { $items = array(); $items['vote'] = array( 'title' => 'vote', 'page callback' => 'bonnier_vote_vote', 'access arguments' => array('vote on content'), 'type' => MENU_CALLBACK, ); return $items; } function bonnier_vote_vote() { $nid = $_REQUEST['nid']; $value = $_REQUEST['votes']; $current_votes = db_result(db_query("SELECT votes FROM bonnier_vote WHERE nid = $nid")); if ($current_votes) { $new_votes = $current_votes + $value; db_query("UPDATE bonnier_vote SET votes = $new_votes WHERE nid = $nid"); } else { db_query("INSERT INTO bonnier_vote (nid, votes) VALUES ($nid, $value)"); } drupal_set_message('Your vote has been recorded'); drupal_goto('node/'.$nid); } function bonnier_vote_nodeapi(&$node, $op, $teaser = null, $page = null) { if ($op == 'view' && !$teaser) { $votes = db_result(db_query("SELECT votes FROM bonnier_vote WHERE nid = {$node->nid}")); if (!$votes) { $votes = 0; } $widget = '<div>'; $widget .= l('Vote Up', 'vote', array('query' => array('nid' => $node->nid, 'votes' => 1))); $widget .= ' '; $widget .= l('Vote Down', 'vote', array('query' => array('nid' => $node->nid, 'value' => -1))); $widget .= ' '; $widget .= 'Score: '. $votes; $widget .= '</div>'; $node->content['vote_widget'] = array( '#value' => $widget, '#weight' => -10, ); } } Any bit of advice would be much appreciated.
  4. Thanks Maq, The admin section of my gallery only lists all photos in the gallery with a delete link next to each photo. Very simple right now. I understand your concept and will take a shot at it.
  5. Hi, I created a simple user gallery that allows anybody to upload photos to it. I now want all uploaded photos sent to a queue to await for approval by me. When the 'approved' checkbox is clicked for a particular photo (or multiple photos), the photos are then published to the public gallery. I need some advice on how to approach this. I'm not asking for a complete solution; I just need something to go by in my research and I'll work to figure it all out. Thank you.
  6. I'm not sure if this has been discussed, and I'd like to know if this is going to require some complex coding to accomplish. My goal is to allow my users to enter a particular date (m/d/y) into their profile, which would send out an email - related to the site - to that user on the date that they submitted. I'm assuming you simply have to apply an if statement when the date is submitted in their profile.  if (today's date == to the date you submitted) {     send out the designated email to the user } I'd appreciate any tips to help me accomplish this. TB 
  7. I've been using hotlink protection through this htaccess code. RewriteEngine on RewriteCond %{HTTP_REFERER} . RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?mysite\. [NC] RewriteCond %{HTTP_REFERER} !google\. [NC] RewriteCond %{HTTP_REFERER} !search\?q=cache [NC] RewriteCond %{REQUEST_URI} !^/hotlink\.png$ RewriteRule \.(gif|jpg)$ /hotlink.png [NC,L] It works properly and prevents hotlinking from ALL image directories on my server. How can I tell it to allow hotlinking from a couple of directories that I designate? for example, I'd like to ALLOW hotlinking at the following URLs: mysite.com/downloads/ and mysite.com/photos/ It this isn't the place to discuss these types of issues, could someone direct me to a good site that covers this? I've tried Google searching for an answer but I've been unsuccessful. Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.