t('storylinks'), 'description' => t('storylink Posts: All storylink posts from a specific user'), 'include' => 'storylink', 'prefix' => t('les nouvelles de '), 'suffix' => t(''), 'weight' => -10, 'form' => FALSE, 'label' => t('Add User storylink'), 'help' => t('You can choose storylink postings by specific users. Type a user name in the search box, or choose from a recently active storylinker.'), 'search' => TRUE, 'threshold' => STORYLINK_THRESHOLD ); if ($get_options) { $type['options'] = mysite_type_storylink_options(); } return $type; } } /** * Set the options for this type */ function mysite_type_storylink_options() { $options = array(); // can't respect storylink permissions because authenticated users aren't in the users_roles table // but it only pulls users who have blogged. $sql = "SELECT DISTINCT(u.uid), u.name FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'storylink' ORDER BY n.nid DESC"; $result = db_query_range($sql, STORYLINK_FROM, STORYLINK_THRESHOLD); $storylinks = array(); while($item = db_fetch_object($result)) { $storylinks[] =$item; } foreach ($storylinks as $key => $value) { $options['name'][] = $value->name . t(""); $options['type_id'][] = $value->uid; $options['type'][] = 'storylink'; } return $options; } /** * Return the title if given an id */ function mysite_type_storylink_title($type_id = NULL, $title = NULL) { if(!empty($type_id)) { if (is_null($title)) { $storylink = user_load(array('uid' => $type_id)); $title = $storylink->name; } $type = mysite_type_storylink(); $title = $type['prefix'] . ' ' . check_plain($title) . t("") . ' ' . $type['suffix']; $title = trim(rtrim($title)); return $title; } drupal_set_message(t('Could not find title'), 'error'); return; } /** * Return the page data for a requested id */ function mysite_type_storylink_data($type_id = NULL) { if(!empty($type_id)) { $sql = db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.type = 'storylink' AND n.status = 1 AND n.uid = %d ORDER BY n.changed DESC"); $result = db_query_range($sql, $type_id, 0, variable_get('mysite_elements', 5)); $data = array( 'base' => 'storylink/' . $type_id, 'xml' => 'storylink/' . $type_id . '/feed', ); $items = array(); $i = 0; while ($nid = db_fetch_object($result)) { $node = node_load(array('nid' => $nid->nid)); $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'] = check_markup($node->teaser, $node->format); $items[$i]['nid'] = $node->nid; $i++; } $data['items'] = $items; return $data; } drupal_set_message(t('Could not find data'), 'error'); return; } /** * Return block settings for this type */ function mysite_type_storylink_block($arg, $op = 'view') { global $user; if (user_access('edit mysite') && ($arg[0] == 'storylink' || $arg[0] == 'user') && is_numeric($arg[1])) { $storylink = user_load(array('uid' => $arg[1])); if (user_access('edit own storylink', $storylink)) { $data = array(); $data['uid'] = $user->uid; $data['type'] = 'storylink'; $data['type_id'] = $storylink->uid; $data['title'] = mysite_type_storylink_title($storylink->uid, $storylink->name); $content = mysite_block_handler($data); return $content; } } } /** * Search options for this type */ function mysite_type_storylink_search($uid = NULL) { if (!is_null($uid)) { $form['add_storylink']['storylink_title'] = array('#type' => 'textfield', '#title' => t('User Name'), '#default_value' => $edit['storylink_title'], '#maxlength' => 64, '#description' => t('The user name of the storylink you wish to add.'), '#required' => FALSE, // this must be false, since all the search for are the same form '#autocomplete_path' => 'autocomplete/mysite/storylink' ); $form['add_storylink']['uid'] = array('#type' => 'hidden', '#value' => $uid); $form['add_storylink']['type'] = array('#type' => 'hidden', '#value' => 'storylink'); $form['add_storylink']['submit'] = array('#type' => 'submit', '#value' =>t('Add storylink')); $output .= drupal_get_form('mysite_type_storylink_search', $form); return $output; } } /** * Form handler for search */ function mysite_type_storylink_search_submit($form_id, $form_values) { // we use LIKE here in case JavaScript autocomplete support doesn't work. // or in case the user doesn't autocomplete the form $result = db_query("SELECT DISTINCT(u.uid), u.name FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'storylink' AND u.name LIKE LOWER('%s%%')", $form_values['storylink_title']); $count = 0; while ($storylink = db_fetch_object($result)) { $data[$count]['uid'] = $form_values['uid']; $data[$count]['type'] = $form_values['type']; $data[$count]['type_id'] = $storylink->uid; $data[$count]['title'] = mysite_type_storylink_title($storylink->uid, $storylink->name); $data[$count]['description'] = t('The storylink posts of %user', array('%user' => $storylink->name)); $count++; } // pass the $data to the universal handler mysite_search_handler($data, 'storylink'); return; } /** * AJAX autocomplete for storylink titles * The include files have no menu callbacks! */ function mysite_type_storylink_autocomplete($string) { $matches = array(); $result = db_query_range("SELECT DISTINCT(u.uid), u.name FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'storylink' AND u.name LIKE LOWER('%s%%')", $string, 0, 10); while ($storylink = db_fetch_object($result)) { $matches[$storylink->name] = check_plain($storylink->name); } return $matches; } /** * Cron cleanup function */ function mysite_type_storylink_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 DISTINCT(u.uid) FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'storylink' AND u.uid = %d"; $check = db_fetch_object(db_query($sql, $item['type_id'], $implode)); if(empty($check->uid)) { $data[$item['mid']] = $item; } } return $data; }