t('Contenu recommandé'), 'description' => t('Contenu recommandé.'), 'include' => 'cre', 'prefix' => '', 'suffix' => '', 'category' => t('Content'), 'weight' => 0, 'form' => FALSE, 'label' => t('Ajoutez du contenu recommandé'), 'help' => t('Ajoutez le contenu qui vous est recommandé par Geekomatik directement sur votre mini-site.'), 'search' => FALSE ); if ($get_options) { $type['options'] = mysite_type_cre_options(); } return $type; } } /** * Implements mysite_type_hook_active(). */ function mysite_type_cre_active($type) { return array($type => TRUE); } /** * Implements mysite_type_hook_options(). */ function mysite_type_cre_options() { $options = array(); if (module_exists('node_recommendation')) { $options['name'][] = "Recommended node content"; $options['type_id'][] = -100; $options['type'][] = 'cre'; $options['icon'][] = mysite_get_icon('cre', -100); } if (module_exists('enhanced_node_recommendation')) { $options['name'][] = "Contenu recommandé personnalisé"; $options['type_id'][] = -200; $options['type'][] = 'cre'; $options['icon'][] = mysite_get_icon('cre', -200); } return $options; } /** * Implements mysite_type_hook_title(). */ function mysite_type_cre_title($type_id = NULL, $title = NULL) { if (!empty($type_id)) { $type = mysite_type_cre(FALSE); if (($type_id==-100 || $type_id==-200) && is_null($title)) { $title = "node"; } $title = $type['prefix'] .' '. $title .' '. $type['suffix']; $title = trim(rtrim($title)); return $title; } drupal_set_message(t('Could not find title'), 'error'); return; } /** * Implements mysite_type_hook_data(). */ function mysite_type_cre_data($type_id = NULL, $settings = NULL) { if (!empty($type_id)) { if($type_id==-100) { global $user; $uid = $user->uid; if (module_exists('mysite_icon')) { $icon = variable_get('mysite_icon_path', 'files/mysite') .'/'. mysite_get_icon('cre', -100); if (!empty($icon)) { $image = theme_image($icon); } } $recommendations = NULL; $n = variable_get('node_recommendation_page_n', 20); if ($uid == 0) { // return top rated nodes for anon users $recommendations = _node_recommendation_get_top_rate_nodes($n); } else { $tag = variable_get('node_recommendation_tag', 'vote'); $recommendations = cre_top($uid,'node_recommendation_cre_query', $n, 'node',$tag); if ($recommendations == NULL) { // since its not nice to return a BLANK page to the user // even if the user has not rated anything yet or rated everything... // might as well display the top rated nodes... $recommendations = _node_recommendation_get_top_rate_nodes($n); } } $data = array( 'base' => '', 'xml' => '' ); $items = array(); if($recommendations) { $i = 0; foreach($recommendations as $node_rec) { $node = node_load($node_rec->content_id); $items[$i]['type'] = $node->type; $items[$i]['link'] = l($node->title, 'node/'. $nid->nid); $items[$i]['title'] = check_plain($node->title); $items[$i]['subtitle'] = NULL; $items[$i]['date'] = $node->changed; $items[$i]['uid'] = $node->uid; $items[$i]['author'] = check_plain($node->name); $items[$i]['teaser'] = mysite_teaser($node); $items[$i]['nid'] = $node->nid; $i++; } } $data['items'] = $items; return $data; } elseif($type_id==-200) { global $user; $uid = $user->uid; if (module_exists('mysite_icon')) { $icon = variable_get('mysite_icon_path', 'files/mysite') .'/'. mysite_get_icon('cre', -200); if (!empty($icon)) { $image = theme_image($icon); } } $n = variable_get('enhanced_node_recommendation_page_n', 20); $recommendations = $uid ? cre_top($uid, 'enhanced_node_recommendation_cre_query', $n, 'node', variable_get('enhanced_node_recommendation_tag', 'vote')) : _enhanced_node_recommendation_get_top_rated_nodes($n); if(!$recommendations) { $recommendations = _enhanced_node_recommendation_get_top_rated_nodes($n); } $data = array( 'base' => '', 'xml' => '' ); $items = array(); if($recommendations) { $i = 0; foreach($recommendations as $node_rec) { $node = node_load($node_rec->content_id); $items[$i]['type'] = $node->type; $items[$i]['link'] = l($node->title, 'node/'. $nid->nid); $items[$i]['title'] = check_plain($node->title); $items[$i]['subtitle'] = NULL; $items[$i]['date'] = $node->changed; $items[$i]['uid'] = $node->uid; $items[$i]['author'] = check_plain($node->name); $items[$i]['teaser'] = mysite_teaser($node); $items[$i]['nid'] = $node->nid; $i++; } } $data['items'] = $items; return $data; } } drupal_set_message(t('Could not find data'), 'error'); return; } /** * Implements mysite_type_hook_block(). */ function mysite_type_cre_block($arg, $op = 'view') { global $user; if (user_access('access content') && $arg[0] == 'recommendations') { $data = array(); $data['uid'] = $user->uid; $data['type'] = 'og'; if (module_exists('node_recommendation')) { $data['type_id'] = -100; } if (module_exists('enhanced_node_recommendation')) { $data['type_id'] = -200; } $data['title'] = 'node'; $content = mysite_block_handler($data); return $content; } } /** * Implements mysite_type_hook_clear(). */ function mysite_type_cre_clear($type) { // fetch all the active records of this type and see if they really exist in the proper table $sql = "SELECT mid, uid, type_id, title FROM {mysite_data} WHERE type = '%s'"; $result = db_query($sql, $type); $data = array(); while ($item = db_fetch_array($result)) { $sql = "SELECT nid FROM {og} WHERE nid = %d"; $check = db_fetch_object(db_query($sql, $item['type_id'])); if (empty($check->nid)) { $data[$item['mid']] = $item; } } return $data; } ?>