Index: ilovethis.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/ilovethis/ilovethis.module,v retrieving revision 1.1 diff -u -r1.1 ilovethis.module --- ilovethis.module 15 Nov 2007 13:44:55 -0000 1.1 +++ ilovethis.module 28 Dec 2007 22:57:06 -0000 @@ -142,7 +142,7 @@ break; case 'view': // add widget to the begin of the node body - $node->content['body']['#value'] = ilovethis_widget($node->type, $node->nid, $view_all = 1). $node->content['body']['#value']; + $node->content['body']['#value'] = ilovethis_widget($node, $teaser, true) . $node->content['body']['#value']; break; } } @@ -230,8 +230,29 @@ * Page to display a user's loved node list. */ function ilovethis_view_page() { - $nid = arg(2); - $output = theme('ilovethis_view_' . variable_get(ILOVETHIS_PAGE_TYPE, 'table'), ilovethis_get($nid), $nid); + $node = node_load($nid = arg(2)); + + $header = array(t('User'), t('Added')); + + $rows = array(); + $row = ilovethis_get($nid); + if (isset($row)) { + foreach ($row as $nid => $data) { + $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $data->uid)); + $title = array(l($username->name, 'user/'. $data->uid), format_date($data->last, 'custom', 'Y-m-d H:i')); + global $user; + if ($user->uid == $data->uid || $user->uid == 1) { + $delete = array(l(t('delete'), 'ilovethis/delete/'. $node->nid. '/'. $data->uid)); + $result = array_merge($title, $delete); + $header[] = t('Action'); + } + else { + $result = $title; + } + $rows[] = array('data' => $result); + } + } + $output = theme('ilovethis_view_' . variable_get(ILOVETHIS_PAGE_TYPE, 'table'), $node, $header, $rows); print theme('page', $output); } @@ -258,79 +279,41 @@ /** * Table which displays loved node lists. */ -function theme_ilovethis_view_table($row = array(), $nid) { - global $user; - - $node = array(); - $node= node_load($nid); - - $header = array( t('User'), t('Added')); - - $rows = array(); - if (isset($row)) { - - unset ($you_love_this); - foreach($row as $nid => $data) { - $tmp_sql = "SELECT name FROM {users} WHERE uid = '".$data->uid."'"; - $tmp_res = db_query(db_rewrite_sql($tmp_sql)); - $username = db_fetch_object($tmp_res); - $username = $username->name; - - $title = array( l($username, "user/".$data->uid) , format_date($data->last, 'custom', 'Y-m-d H:i')); - if ($user->uid == $data->uid || $user->uid == 1) { - $delete = array(l(t('delete'), "ilovethis/delete/".$node->nid. "/". $data->uid )); - $result = array_merge($title, $delete); - $header = array( t('User'), t('Added'), t('Action')); - } - else { - $result = $title; - } - $rows[] = array('data' => $result); +function theme_ilovethis_view_table($node, $header, $rows) { + if (count($rows) > 0) { + $ilovethis .= theme('table', $header, $rows); + $ilovethis .= theme('pager'); + } + else { + $ilovethis .= t('None (yet) loves this !type', array('!type' => $node->type)); + } + $ilovethis .= '
'. ilovethis_widget($node) .'
'; + $output .= '

'. $node->title. '

'; + $output .= '
'. $ilovethis .'
'; + $output .= '
'. $node->body .'
'; + return $output; +} - if ($user->uid == $data->uid){ - $you_love_this=1; - } - } - } - $output .= '

'. $node->title.'

'."\n"; - if (count($rows)>0) { - $output .="
"; - #print row below if you want to give an header to the "lovers" list - #$output .= '

List of the user who joined this '.$node->type.'

'."\n"; - $output .= theme('table', $header, $rows); - $output .= theme('pager'); - } else { - $output .="
"; - $output .="". t("None (yet) loves this" . " " . $node->type).""; +function ilovethis_widget($node, $teaser = false, $view_all = false) { + if (!$teaser && variable_get(ILOVETHIS_NODE_TYPE . $node->type, 0)) { + return theme('ilovethis_widget', $node, $view_all, _ilovethis_check($node->nid)); } - $output .= "
".ilovethis_widget($node->type, $node->nid, $view_all = false)."
"; - $output .="
"; - $output .="
"; - #print row below if you want to give an header to the "text node - #$output .="

".t("Text")."

"; - $output .="
".$node->body."
"; - $output .="
"; - - return $output; } -function ilovethis_widget($type, $node = null, $view_all = false) { +function theme_ilovethis_widget($node, $view_all, $check) { global $user; - if ( !$teaser) { - if (variable_get(ILOVETHIS_NODE_TYPE . $type, 0)) { - $widget ="
"; - $widget .="
"; - if (!_ilovethis_check($node)) { - $widget .= l(t('I love this '.ucfirst ($type)), 'ilovethis/add/'. $node, array('class' => '', 'title' => t('Click here to give your love to this ' . ' '. ucfirst ($type)))); - } else { - $widget .= l(t('I don\'t love this') ." " . ucfirst ($type) , 'ilovethis/delete/'. $node ."/". $user->uid, array('class' => '', 'title' => t('Click here to remove your love from this'. " " .ucfirst ($type)))); - } - $widget .="
"; - if ($view_all==1){ - $widget .="

(".l(t('who loves this')." " . ucfirst ($type) ,"ilovethis/view/".$node, array('class' => '', 'title' => t('List of people loving this '. ucfirst ($type)))) .")

"; - } - $widget .= "
"; - } + if ($check) { + $link = l(t("I don't love this !type", array('!type' => ucfirst($node->type))), 'ilovethis/delete/'. $node->nid ."/". $user->uid, array('class' => '', 'title' => t('Click here to remove your love from this !type', array('!type' => ucfirst($node->type))))); } - return $widget; + else { + $link = l(t('I love this !type', array('!type' => ucfirst($node->type))), 'ilovethis/add/'. $node->nid, array('class' => '', 'title' => t('Click here to give your love to this !type', array('!type' => ucfirst($node->type))))); + } + $output = '
'. $link .'
'; + + if ($view_all) { + $link = l(t('who loves this !type', array('!type' => ucfirst($node->type))), 'ilovethis/view/'. $node->nid, array('class' => '', 'title' => t('List of people loving this !type', array('!type' => ucfirst($node->type))))); + $output .= '

('. $link .')

'; + } + + return '
'. $output .'
'; }