t('Post'),
'description' => t('Post: Add a specific post.'),
'include' => 'node',
'prefix' => t('The post'),
'suffix' => t(''),
'category' => t('Content'),
'weight' => 0,
'form' => FALSE,
'label' => t('Add Post'),
'help' => t('You can add individual posts to your page.'),
'search' => TRUE
);
if ($get_options) {
$type['options'] = mysite_type_comment_options();
}
return $type;
}
}
/**
* Implements mysite_type_hook_active().
*/
function mysite_type_anode_active($type) {
// some users must be allowed to view content, otherwise, give a configuration message
$result = db_query("SELECT perm FROM {permission}");
$check = '';
$br = '';
$message = '';
while ($perms = db_fetch_object($result)) {
$check .= $perms->perm;
}
if (stristr($check, 'access content')) {
$value = TRUE;
}
else {
$value = FALSE;
$message = l(t('No users have permission to access site content'), 'admin/user/access');
$br = '
';
}
// there must be at least one allowed type
$allowed = variable_get('mysite_node_settings', array());
// if this variable is saved as blank, then a 0 => 1 value is present
unset($allowed[0]);
if (empty($allowed)) {
$value = FALSE;
$message = $br . l(t('At least one content type must be configured for MySite.'), 'admin/settings/mysite/type/node');
}
return array($type => $value, 'message' => $message);
}
/**
* Implements mysite_type_hook_options().
*/
function mysite_type_anode_options() {
$options = array();
// we are dealing with nodes, so node_access requires db_rewrite_sql here. See http://drupal.org/node/135378.
$sql = db_rewrite_sql("SELECT nid, title FROM {node} WHERE status = 1 ORDER BY title");
$result = db_query($sql);
$nodes = array();
while ($item = db_fetch_object($result)) {
$nodes[] = $item;
}
foreach ($nodes as $key => $value) {
$options['name'][] = mysite_type_comment_title($value->nid, $value->title);
$options['type_id'][] = $value->nid;
$options['type'][] = 'anode';
$icon = mysite_get_icon('node', $value->uid);
$options['icon'][] = mysite_get_icon('node', $type->myid);
}
return $options;
}
/**
* Implements mysite_type_hook_data().
*/
function mysite_type_anode_data($type_id = NULL, $settings = NULL) {
if (!empty($type_id)) {
$data = mysite_get_custom('node', $type_id, FALSE);
$sql = db_rewrite_sql("SELECT n.nid, n.changed FROM {node} n WHERE n.type = '%s' AND n.status = 1 ORDER BY n.changed DESC");
$result = db_query_range($sql, $data->type_key, 0, variable_get('mysite_elements', 5));
$data = array(
'base' => '',
'xml' => ''
);
$items = array();
$i = 0;
while ($nid = db_fetch_object($result)) {
$node = node_load($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'] = 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_title().
*/
function mysite_type_anode_title($type_id = NULL, $title = NULL) {
if (!empty($type_id)) {
if (is_null($title)) {
$data = mysite_get_custom('node', $type_id, FALSE);
$title = node_get_types('name', $data->type_key);
}
$type = mysite_type_node(FALSE);
$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_block_node().
*/
function mysite_type_anode_block_node($nid = NULL, $type = NULL) {
global $user;
$types = variable_get('mysite_node_settings', array());
if (in_array($type, $types)) {
$info = mysite_get_myid('node', $type);
if (!empty($info)) {
$data = array();
$data['uid'] = $user->uid;
$data['type'] = 'node';
$data['type_id'] = $info;
$data['title'] = mysite_type_node_title($info);
$content = mysite_block_handler($data);
return $content;
}
}
}
/**
* Implements mysite_type_hook_search().
*
* @ingroup forms
*/
function mysite_type_node_search($uid = NULL) {
if (!is_null($uid)) {
$output .= drupal_get_form('mysite_type_node_search_form', $uid);
return $output;
}
}
/**
* FormsAPI for mysite_type_comment_search
*
* @ingroup forms
*/
function mysite_type_anode_search_form($uid) {
$form['add_comment']['comment_title'] = array('#type' => 'textfield',
'#title' => t('Post title'),
'#maxlength' => 64,
'#size' => 40,
'#description' => t('The title of the post you wish to add.'),
'#required' => TRUE,
'#autocomplete_path' => 'autocomplete/mysite/comment'
);
$form['add_comment']['uid'] = array('#type' => 'hidden', '#value' => $uid);
$form['add_comment']['type'] = array('#type' => 'hidden', '#value' => 'comment');
$form['add_comment']['submit'] = array('#type' => 'submit', '#value' => t('Add Post Comments'));
return $form;
}
/**
* Implements mysite_type_hook_search_form_submit().
*
* @ingroup forms
*/
function mysite_type_anode_search_form_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
$sql = db_rewrite_sql("SELECT nid, title FROM {node} WHERE LOWER(title) LIKE LOWER('%s%%') AND status = 1");
$result = db_query($sql, $form_values['comment_title']);
$count = 0;
while ($node = db_fetch_object($result)) {
$data[$count]['uid'] = $form_values['uid'];
$data[$count]['type'] = $form_values['type'];
$data[$count]['type_id'] = $node->nid;
$data[$count]['title'] = mysite_type_comment_title($node->nid, $node->title);
$data[$count]['description'] = $node->title;
$count++;
}
// pass the $data to the universal handler
mysite_search_handler($data, 'comment');
return;
}
/**
* Implements mysite_type_hook_autocomplete().
*
* @ingroup forms
*/
function mysite_type_anode_autocomplete($string) {
$matches = array();
$sql = db_rewrite_sql("SELECT nid, title FROM {node} WHERE LOWER(title) LIKE LOWER('%s%%') AND status = 1");
$result = db_query_range($sql, $string, 0, 10);
while ($node = db_fetch_object($result)) {
$matches[$node->title] = check_plain($node->title);
}
return $matches;
}
/**
* Implements mysite_type_hook_clear().
*/
function mysite_type_anode_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 {node} WHERE nid = %d AND n.status = 1";
$check = db_fetch_object(db_query($sql, $item['type_id']));
if (empty($check->nid)) {
$data[$item['mid']] = $item;
}
}
return $data;
}