updating album.module for 4.7.3

Darrell - August 20, 2006 - 06:32

I have made changes to album.module for 4.7 and have got to the point where it loads, enables and looks like it is there.
When I click on create album I do not get the create page.
In the watchdog I only get one error message as follows:

Location http://mysite.com/member/album/form
Referrer http://mysite.com/member/album
Message Missing argument 1 for phptemplate_page() in /home/myserver/mysite-www/member/themes/engines/phptemplate/phptemplate.engine on line 139.

Any ideas where to look?

Darrell

updating album.module for 4.7.3

Darrell - August 20, 2006 - 22:17

How does drupal count lines when it references a line number as in

phptemplate/phptemplate.engine on line 139

is line 139 as in counting every line including comments and blank lines or just counting actual lines of code?

Support?????

Darrell - August 22, 2006 - 01:30

I used to be impressed wit the rapid response to questions.

updating album.module for 4.7.3

Darrell - August 24, 2006 - 04:47

I am still waiting!

I have found the answer to everything so far except what is the cause of:

Message Missing argument 1 for phptemplate_page() in /home/myserver/mysite-www/member/themes/engines/phptemplate/phptemplate.engine on line 139.

Any ideas where to look?

Not familiar with the album

alanburke - August 24, 2006 - 09:51

Not familiar with the album module but...

The error relates to the phptemplate engine.
This file generates output that the theme uses for display.

The module [I guess] must be calling this function
Taken from line 139 of phptemplate.engine

/**
* Prepare the values passed to the theme_page function to be passed
* into a pluggable template engine.
*/
function phptemplate_page($content) {

  /* Set title and breadcrumb to declared values */
  if (drupal_is_front_page()) {
    $mission = filter_xss_admin(theme_get_setting('mission'));
  }

  /* Add favicon */
  if (theme_get_setting('toggle_favicon') && ($favicon_url = check_url(theme_get_setting('favicon')))) {
    drupal_set_html_head('<link rel="shortcut icon" href="'. $favicon_url .'" type="image/x-icon" />');
  }

The error means it is expecting
$content
to be passed, but that doesn't appear to be happening.

So maybe you have change the code in the module so that it DOES pass it.

OR , I might be talking rubbish...

Regards
Alan
PS This might all be obvious to you, but just in case...

updating album.module for 4.7.3 HELP!!

Darrell - August 25, 2006 - 20:37

I have made changes to album.module for 4.7 and have got to the point where it loads, enables and looks like it is there.
When I click on create album I now get the create page and I can create an album. Everything looks like it is working except the picture file is not uploaded.
If I click on the album file and select edit I can then upload the picture file and everything works.
In the watchdog there is the following error message.

Location http://mysite.com/member/album/validate
Referrer http://mysite.com/member/album/form
Message Invalid argument supplied for foreach() in /home/machin/machinemaster-www/member/modules/image/image.module on line 306.
Severity error

I could post what I have if someone would like to help.

module for 4.7.3 HELP!!

Darrell - August 26, 2006 - 00:24

This is where I have got to.
In album.module

foreach ($uploads as $field => $filename) {
if ($filename) {
$node = new stdClass();
$node->title = $filename;
global $user;
$node->uid = $user->uid;
$node->folksonomy['album_'. $user->uid] = array('name' => $edit['album_tags']);
$node->type = 'image';

this is not providing what image.module wants to see here

function image_insert($node) {
foreach ($node->images as $label => $image) {
_image_insert($node, $label, file_create_path($image));
}
}

Would someone please help me?????

module for 4.7.3 HELP!!

Darrell - August 26, 2006 - 18:04

I think that this code in album.module

<?php
function album_save($nodes) {
  foreach (
$nodes as $node) {
   
$nid = node_save($node);
   
$links[] = $nid ? l($node->title, "node/$nid") : t('failed to save %title', array('title' => $node->title));
  }
  return
$links;
}
?>

sends info to this code in version 4.6 image.module

<?php
function image_insert($node) {
  foreach (
$node->images as $label => $image) {
   
_image_insert($node->nid, $label, file_create_path($image));
  }
}
?>

The 4.7 image.module is changed to

<?php
function image_insert($node) {
  foreach (
$node->images as $label => $image) {
   
_image_insert($node, $label, file_create_path($image));
  }
}
?>

I could sure use some pointers on what I need to change to get album.module to work.

module for 4.7.3 HELP!!

Darrell - August 27, 2006 - 20:09

Could someone at least tell me what values are being sent and what values 4.7 is looking for?
An RTFM with a link to revelant page might help.
The problem I am having with example code is that I can't tell when a word is litteral and when it is to be changed to fit the module I am working on. Some are obvious others I am just guessing.

PISS OFF

Darrell - September 5, 2006 - 06:16

That would have been better than being ignored!!

Well, I was keeping an eye

alanburke - September 5, 2006 - 08:14

Well, I was keeping an eye on this thread, but unable to add more than I did already.

Thanks, at least

Darrell - September 5, 2006 - 21:10

Thanks, at least now I know someone was watching.
I really did expect some help from those that broke the code in working modules.
I am trying to learn how to program modules.

Any update on this? I would

deaconzero - September 21, 2006 - 05:20

Any update on this? I would help, but I got nothin... :(... let me know if there is anything new on it.

Album for 4.7

Darrell - September 21, 2006 - 07:16

I have messed with the code in album.module and placed print statements in image.module to see what is being sent.
I have album.module to the point where it loads and configures. It shows the image upload form and lets me pick photos on my local system and saves the album. At this point I get a watchdog error that reads:

warning: Invalid argument supplied for foreach() in /home/machin/mysite-www/member/modules/image/image.module on line 306.

The problem is that all that gets saved is the name of the photo. In the data base in files there is a listing that has the name of the photo and the file size. Folksonomy lists the nid and album name. There is no file in files/images. I can edit each photo and upload the photo from the edit page and then the photo is in the album.
This is album.module as far as I have got.

<?php
//  v 4.7.0 Album

function album_menu($may_cache) {
  if (
$may_cache) {
   
$items[] = array('path' => 'album', 'title' => t('albums'),
    
'callback' => 'album_page', 'access' => user_access('access content'));
   
$items[] = array('path' => 'album/validate', 'title' => t('albums'),
    
'callback' => 'album_validate', 'access' => user_access('access content'),
     
'type' => MENU_CALLBACK);
  }
  else {
    global
$user;
   
$sql = "SELECT DISTINCT(name) FROM {folksonomy} WHERE realm = 'album_$user->uid'";
   
$unlimited = variable_get('album_unlimited', TRUE);
    if (
$unlimited || db_num_rows(db_query($sql)) == 0) {
     
$type = MENU_NORMAL_ITEM;
    }
    else {
     
$type = MENU_CALLBACK;
    }
   
$items[] = array('path' => 'album/form', 'title' => t('create album'), 'callback' => 'album_form', 'access' => user_access('create images'), 'type' => $type);

    if (
$user->uid) {
     
$items[] = array('path' => "album/$user->uid", 'title' => t('my albums'), 'callback' => 'album_page', 'callback arguments' => array($user->uid), 'access' => user_access('access content'));
    }
  }
  return
$items ? $items : array();
}

function
album_form() {
 
$edit = $_REQUEST['edit'];
 
$form['album_tags'] = array(
 
'#type' => 'textfield',
 
'#title' => t('Album Title'),
 
'#default_value' => $edit['album_tags'],
 
'#required' => TRUE,
 
'#size' => 100,
 
'#maxlength' => 255,
);

// change n below to show more or less file upload fields
 
$n = 2;
  for (
$i=1; $i <= $n; $i++) {
 
$edit = $_REQUEST['edit'];
 
$form['#attributes'] = array("enctype" => "multipart/form-data");
 
$form["photo$i"] = array(
 
'#type' => 'file',
 
'#title' => t('Photo'). $i,
 
'#size' => 100,
);
}
 
$form['#attributes'] = array("enctype" => "multipart/form-data");
 
$form['submit'] = array(
 
'#button_type' => 'submit',
 
'#type' => 'submit',
 
'#value' => t('Upload'),
 
'#submit' => TRUE,
);

 
$form['#method'] = 'post';
 
$output = drupal_get_form('album', $form);
return
$output;
}

function
album_validate() {
 
$edit = $_REQUEST['edit'];
 
$uploads = $_FILES['edit']['name'];
  if (!
$edit['album_tags']) {
   
$msg = t('You must specify an album title.');
   
form_set_error('album_tags', $msg);
   
$errors[] = $msg;
  }
  foreach (
$uploads as $field => $filename) {
    if (
$filename) {
     
$node = new stdClass();
     
$node->title = $filename;
      global
$user;
     
$node->uid = $user->uid;
     
$node->folksonomy['album_'. $user->uid] = array('name' => $edit['album_tags']);
     
$node->type = 'image';

     
// TODO: in HEAD, use node_submit() instead of node_save() and simplify this greatly.
      // Validate for normal users:
     
$node->uid = $user->uid ? $user->uid : 0;
     
// Force defaults in case people modify the form:
     
$node->status = variable_get("node_status_$node->type", 1);
     
$node->promote = variable_get("node_promote_$node->type", 0);
     
$node->moderate = variable_get("node_moderate_$node->type", 0);
     
$node->sticky = variable_get("node_sticky_$node->type", 0);
     
$node->revision = variable_get("node_revision_$node->type", 0);
      unset(
$node->created);
     
// the line below needs some work before transforming into node_submit(). maybe move up before replacing code with node_submit()
//      image_validate($node, $field);
     
node_invoke_nodeapi($node, 'validate');
     
$node->validated = TRUE;
      if (
$error = form_get_errors()) {
       
$errors[] = $error;
        unset(
$error);
      }
      else {
       
$nodes[] = $node;
      }
    }
  }
  if (
$errors) {
   
album_form();
  }
  else {
   
$links = album_save($nodes);
   
drupal_set_message(t('album saved.'));
   
$dest = 'album/'. $node->uid. '/'. urlencode($edit['album_tags']);
   
drupal_goto($dest);
  }
}

function
album_save($nodes) {
  foreach (
$nodes as $node) {
   
$nid = node_save($node);
   
$links[] = $nid ? l($node->title, "node/$nid") : t('failed to save %title', array('title' => $node->title));
  }
  return
$links;
}

function
album_user($type, $edit, &$user, $category = NULL) {
  switch (
$type) {
    case
'view':
      if (
user_access('access content')) {
       
$sql = "SELECT DISTINCT(name), realm FROM {folksonomy} WHERE realm = 'album_%d' ORDER BY id DESC";
       
$result = db_query_range($sql, $user->uid, 0, 6);
        while (
$row = db_fetch_object($result)) {
         
$id = substr($row->realm, strpos($row->realm, '_')+1);
         
$links[] = l($row->name, "album/$id/". urlencode($row->name));
        }
        return array(
t('History') => $form[] = array(
 
'#type' => 'item',
 
'#title' => t('Albums'),
 
'#default_value' => theme('item_list', $links)),
);
      }
  }
}

// this module does not use the $operator param yet. But you can construct URLs with an /and at the end and these will require
// images which have been tagged for all of the folksonomy terms.
function album_page($uid = NULL, $str_tags = NULL, $operator = 'or') {
  if (
is_null($uid)) {
return
album_list();
  }
  elseif (
is_null($str_tags)) {
return
album_list($uid);
  }
  else {
    if (
strstr($str_tags, ',')) {
     
$tags = explode(',', $str_tags);
    }
    else {
     
$tags = array($str_tags);
    }
    if (
$tags) {
     
$title = str_replace(array(',', '+'), ', ', $str_tags);
     
$bc = array(l(t('Home'), ''), l(t('albums'), 'album'));
      if (
$uid) {
       
$account = user_load(array('uid' => $uid));
       
$bc[] = l(t('%name albums', array('%name' => $account->name)), "album/$uid");
      }
     
$result = folksonomy_select_nodes($tags, $operator, 'image', 'album_'. $uid);
     
// append 'add to this album' link if available. a bit messy for now.
     
if ($uid == $user->uid && user_access('create images' || 'access content' || 'view') && module_exist('folksonomy')) {
       
$links[] = l(t('add to this album'), 'album/form', array(), "edit[album_realm]=album_$uid&edit[album_tags]=$str_tags");
      }
     
$output = theme('item_list', $links);
     
$output .= taxonomy_render_nodes($result);
     
drupal_set_breadcrumb($bc);
     
drupal_set_title($title);
      return
$output;
    }
    else {
     
drupal_not_found();
    }
  }
}

function
album_list($uid = NULL) {
  if (
$uid) {
   
$sql = "SELECT f.name AS fname, realm, u.name, u.uid, COUNT(f.name) AS fcount FROM {folksonomy} f INNER JOIN {node} n ON f.id = n.nid INNER JOIN {users} u ON n.uid = u.uid WHERE realm = 'album_%d' GROUP BY f.name, realm, u.name, u.uid ORDER BY id DESC";
   
$cnt = db_num_rows(db_query("SELECT DISTINCT(name) FROM {folksonomy} WHERE realm = 'album_$uid'"));
   
$sql_cnt = "SELECT $cnt";
   
$result = pager_query($sql, 50, 0, $sql_cnt, $uid);
   
$account = user_load(array('uid' => $uid));
   
$bc = array(l(t('Home'), ''), l(t('albums'), 'album'));
   
drupal_set_breadcrumb($bc);
   
drupal_set_title((t('%name albums', array('%name' => $account->name))));
  }
  else {
   
$sql = "SELECT f.name as fname, realm, u.name, u.uid, COUNT(f.name) AS fcount FROM {folksonomy} f INNER JOIN {node} n ON f.id = n.nid INNER JOIN {users} u ON n.uid = u.uid WHERE realm LIKE 'album_%' GROUP BY f.name, realm, u.name, u.uid ORDER BY id DESC";
   
$cnt = db_num_rows(db_query("SELECT DISTINCT(name) FROM {folksonomy} WHERE realm LIKE 'album_%'"));
   
$sql_cnt = "SELECT $cnt";
   
$result = pager_query($sql, 50, 0, $sql_cnt);
  }
 
$header = array(t('album'), t('submitter'), t('count'));
  while (
$row = db_fetch_object($result)) {
   
$id = substr($row->realm, strpos($row->realm, '_')+1);
   
$rows[] = array(l($row->fname, "album/$id/". urlencode($row->fname)), urlencode($row->name), theme($row), $row->fcount);
  }
  if (
$pager = theme('pager', NULL, 50)) {
   
$rows[] = array(array('data' => $pager, 'colspan' => 3));
  }
 
$output = theme_table($header, $rows);
  return
$output;
}

function
album_settings() {
 
$form['album_unlimited'] = array(
 
'#type' => 'checkbox',
 
'#title' => t('Unlimited albums'),
 
'#return_value' => 1,
 
'#default_value' => variable_get('album_unlimited', TRUE),
 
'#description' => t('If you want to limit users to a single album, uncheck this box.'),
);

        return
$form;
}

function
album_help($section) {
 
$output = "";

  switch (
$section) {
    case
'admin/help#album':
      break;
    case
'admin/modules#description':
      return
t("Image albums");
  }
}
?>

When I put a print statement in image.module at line 307 to see what album is sending I get the following:

stdClass Object ( [nid] => 134 [vid] => 134 [type] => image [status] => 1 [created] => 1157821401 [changed] => 1157821401 [comment] => 0 [promote] => 0 [moderate] => 0 [sticky] => 0 [revision_timestamp] => 1157821401 [title] => cd.jpg [body] => [teaser] => [log] => [format] => 0 [uid] => 1 [name] => [picture] => [data] => [last_comment_timestamp] => 1157821401 [last_comment_name] => [comment_count] => 0 [taxonomy] => Array ( ) [files] => Array ( ) [is_new] => [folksonomy] => Array ( [album_1] => Array ( [name] => Darrell ) ) [revision] => 0 [path] => [validated] => 1 ) links is : 1

If I use create content image it sends the following to image.module:

stdClass Object ( [nid] => 134 [vid] => 134 [type] => image [status] => 1 [created] => 1157821401 [changed] => 1157821827 [comment] => 0 [promote] => 0 [moderate] => 0 [sticky] => 0 [revision_timestamp] => 1157821401 [title] => cd.jpg [body] => [teaser] => [log] => [format] => 1 [uid] => 1 [name] => Admin [picture] => [data] => a:2:{s:5:"roles";a:1:{i:0;s:1:"2";}s:11:"mail_accept";s:1:"0";} [images] => Array ( [_original] => files/images/temp/cd.jpg [thumbnail] => images/temp/cd.thumbnail.jpg [preview] => files/images/temp/cd.jpg ) [last_comment_timestamp] => 1157821401 [last_comment_name] => [comment_count] => 0 [taxonomy] => Array ( [1] => Array ( [13] => 13 ) ) [files] => Array ( ) [image] => [date] => 2006-09-09 10:03:21 -0700 [revision] => 0 [preview] => Preview [submit] => Submit [delete] => Delete [form_id] => image_node_form [menu] => Array ( [title] => [description] => [pid] => 1 [path] => [weight] => 0 [mid] => 0 [type] => 86 ) [path] => [upload] => [attach] => http://mysite.com/member/upload/js [validated] => 1 [is_new] => ) links is : 1

I just don't know what I need to change to get the info out of album.module.

Sure could use some help.

I wish I could help, but

deaconzero - September 21, 2006 - 16:56

I wish I could help, but that's way over my head when it comes to coding. Hopefully someone will come along to rescue the prohject... any takers.... come on, you know you want to help... :)

Some progress and an idea where to start

Darrell - September 24, 2006 - 21:59

I think the part that still needs fixed is the hook_validate section needs to be divided up because of the way hook_validate now works.

<?php
function album_validate() {
 
$edit = $_REQUEST['edit'];
 
$uploads = $_FILES['edit']['name'];
  if (!
$edit['album_tags']) {
   
$msg = t('You must specify an album title.');
   
form_set_error('album_tags', $msg);
   
$errors[] = $msg;
  }
  foreach (
$uploads as $field => $filename) {
    if (
$filename) {
     
$node = new stdClass();
     
$node->title = $filename;
      global
$user;
     
$node->uid = $user->uid;
     
$node->folksonomy['album_'. $user->uid] = array('name' => $edit['album_tags']);
     
$node->type = 'image';

     
// TODO: in HEAD, use node_submit() instead of node_save() and simplify this greatly.
      // Validate for normal users:
     
$node->uid = $user->uid ? $user->uid : 0;
     
// Force defaults in case people modify the form:
     
$node->status = variable_get("node_status_$node->type", 1);
     
$node->promote = variable_get("node_promote_$node->type", 0);
     
$node->moderate = variable_get("node_moderate_$node->type", 0);
     
$node->sticky = variable_get("node_sticky_$node->type", 0);
     
$node->revision = variable_get("node_revision_$node->type", 0);
      unset(
$node->created);
     
// the line below needs some work before transforming into node_submit(). maybe move up before replacing code with node_submit()
//      image_validate($node, $field);
     
node_invoke_nodeapi($node, 'validate');
     
$node->validated = TRUE;
      if (
$error = form_get_errors()) {
       
$errors[] = $error;
        unset(
$error);
      }
      else {
       
$nodes[] = $node;
      }
    }
  }
  if (
$errors) {
   
album_form();
  }
  else {
   
$links = album_save($nodes);
   
drupal_set_message(t('album saved.'));
   
$dest = 'album/'. $node->uid. '/'. urlencode($edit['album_tags']);
   
drupal_goto($dest);
  }
}
?>

This is trying to do changes and I don't think changes are allowed in validate.
I think that this function needs to become

function album_insert()

as the only validating that I think I need can be done with

'#required' => TRUE,

in the $form arrays.
Any one willing to give me some help????

Really a good module, any

toma - October 17, 2006 - 22:53

Really a good module, any chance to have a work version for 4.7.3 ?

 
 

Drupal is a registered trademark of Dries Buytaert.