'admin/block/taxonomy_block', 'title' => t('taxonomy block'), 'callback' => 'taxonomy_block_admin', 'access' => user_access('administer taxonomy blocks')); } return $items; } /** * Provides the blocks that this module is capable of displaying. * * @param $op the operation that is being requested. This defaults to 'list', which indicates that the method should * which blocks are available. * @param $delta the specific block to display. This is actually the offset into an array. * @return one of two possibilities. The first is an array of available blocks. The other is an array containing a * block. */ function taxonomy_block_block($op = 'list', $delta = 0) { if ($op == 'list') { return taxonomy_block_get_blocks(); } elseif ($op == 'configure') { return l(t('Edit Taxonomy Block Settings'), 'admin/block/taxonomy_block/edit/'. $delta); } else { if (user_access('access content')) { return taxonomy_block_get_block($delta); } } } /** * Displays and allows an administrator to admin this module. * * @return the content for the admin page. */ function taxonomy_block_admin($op = NULL, $bid = NULL){ if ($_POST['op']) { $op = $_POST['op']; $edit = $_POST['edit']; } switch ($op) { case 'delete' : $output = taxonomy_block_confirm_delete($bid); break; case 'edit' : $output = taxonomy_block_form($bid); break; case t('Create Block') : if(substr($edit['tid'], 0, 1)=='v') { $type = 'vocabulary'; $tid = substr($edit['tid'], 1); } else { $type = 'term'; $tid = $edit['tid']; } taxonomy_block_insert($tid, $edit['name'], $edit['description'], $edit['length'], $type, $edit['teaser']); break; case t('Edit Block') : if(substr($edit['tid'], 0, 1)=='v') { $type = 'vocabulary'; $tid = substr($edit['tid'], 1); } else { $type = 'term'; $tid = $edit['tid']; } taxonomy_block_update($bid, $tid, $edit['name'], $edit['description'], $edit['length'], $type, $edit['teaser']); break; case t('Delete Block') : taxonomy_block_delete($bid); break; case t('Cancel'); drupal_goto('admin/block/taxonomy_block'); break; } if (!$output) { /*$form['current_blocks'] = array( '#type' => 'fieldset', '#title' => t('Current Blocks'), );*/ $output = taxonomy_block_show_blocks(); $form['create_blocks'] = array( '#type' => 'fieldset', '#title' => t('Create Block'), ); taxonomy_block_form(NULL, $form['create_blocks']); return $output.drupal_get_form('taxonomy_block_admin', $form); } elseif ($op != 'delete') { return drupal_get_form('taxonomy_block_admin', $output); } print theme('page', $output, t('Taxonomy Block Adminstration')); } /** * Inserts a block into the database. * * @ingroup taxonomy_block_db * @param @$node The node that is being inserted. */ function taxonomy_block_insert($tid, $name, $description, $length, $type, $teaser='') { $sql = 'INSERT INTO {taxonomy_block} (tid, name, description, length, type, teaser) VALUES (%d, \'%s\', \'%s\', %d, \'%s\', %d)'; db_query($sql, array($tid, $name, $description, $length, $type, $teaser)); } /** * Updates a block into the database. * * @ingroup taxonomy_block_db * @param @$node The node that is being inserted. */ function taxonomy_block_update($bid, $tid, $name, $description, $length, $type, $teaser='') { $sql = 'UPDATE {taxonomy_block} SET tid = %d, name = \'%s\', description = \'%s\', length = %d, type = \'%s\', teaser = %d WHERE bid = %d'; db_query($sql, array($tid, $name, $description, $length, $type, $teaser, $bid)); } /** * Deletes ra block from the database. * * @ingroup taxonomy_block_db * @param $bid The id of the block that is being deleted. */ function taxonomy_block_delete($bid) { db_query('DELETE FROM {taxonomy_block} WHERE bid = %d', $bid); } /** * Displays the create form. * * @ingroup taxonomy_block_form. * @return html formatted create form. */ function taxonomy_block_form($bid = NULL, &$form = NULL) { if ($bid) { $block = db_fetch_object(db_query('SELECT * FROM {taxonomy_block} WHERE bid = %d', $bid)); } $form['name'] = array( '#type' => 'textfield', '#title' => t('Block Name'), '#default_value' => $block->name, '#size' => 40, '#maxlength' => 40, '#description' => t('This is the name of your block.'), ); $form['description'] = array( '#type' => 'textfield', '#title' => t('Block Description'), '#default_value' => $block->description, '#size' => 40, '#maxlength' => 40, '#description' => t('This is the description of your block. It is not displayed to users.'), ); $form['teaser'] = array( '#type' => 'textfield', '#title' => t('Teaser Length'), '#default_value' => $block->teaser, '#size' => 40, '#maxlength' => 40, '#description' => t('This is the length of node body content to display under each title in characters. Leave blank for none.'), ); $form['length'] = array( '#type' => 'textfield', '#title' => t('Block Length'), '#default_value' => $block->length, '#size' => 40, '#maxlength' => 40, '#description' => t('This is the number of nodes to display.'), ); $tid = $block->type == 'vocabulary' ? 'v'. $block->tid : $block->tid; $vocabs = taxonomy_get_vocabularies(); $links[] = ''; foreach ($vocabs as $vocab) { $links['v'.$vocab->vid] = $vocab->name; $tree = taxonomy_get_tree($vocab->vid); foreach ($tree as $term) { $links[$term->tid] = $vocab->name .' - '. $term->name; } } $form['tid'] = array( '#type' => 'select', '#title' => '', '#default_value' => $tid, '#options' => $links, '#description' => t('Select taxonomy type to display'), ); if ($bid) { $form['submit'] = array( '#type' => 'submit', '#value' => t('Edit Block'), ); $form['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), ); } else { $form['submit'] = array( '#type' => 'submit', '#value' => t('Create Block'), ); } return $form; } /** * Displays the block delete confirmation form. * * @ingroup taxonomy_block_form. * @return block delete confirmaiton form. */ function taxonomy_block_confirm_delete($bid) { $block = db_fetch_object(db_query('SELECT * FROM {taxonomy_block} WHERE bid = %d', $bid)); if ($block->bid) { $form['delete'] = array( '#type' => 'submit', '#value' => t('Delete Block')); $form['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), ); return drupal_get_form('taxonomy_block_confirm_delete', $form); } } /** * Displays the blocks. * * @ingroup taxonomy_block_view. * @return html formatted list of blocks with delete links. */ function taxonomy_block_show_blocks() { $result = db_query('SELECT * FROM {taxonomy_block}'); while ($block = db_fetch_object($result)) { $links = array(); $links[] = l(t('edit'), 'admin/block/taxonomy_block/edit/'. $block->bid, array('title'=>t('edit block')));; $links[] = l(t('delete'), 'admin/block/taxonomy_block/delete/'. $block->bid, array('title'=>t('delete block')));; $blocks[] = $block->description .' - '. theme('links', $links); } return theme('item_list', $blocks); } /** * Returns the requested block. * * @ingroup taxonomy_block_view. * @param $bid The id of the block to display. * @return html formatted block. */ function taxonomy_block_get_block($bid) { $tids = array(); $result = db_fetch_object(db_query('SELECT * FROM {taxonomy_block} WHERE bid = %d', $bid)); if ($result) { if ($result->type=='term') { $tids[] = $result->tid; } else { $tree = taxonomy_get_tree($result->tid); foreach ($tree as $term) { $tids[] = $term->tid; } } $nodes = db_query(db_rewrite_sql('SELECT DISTINCT(n.nid), nr.title, nr.body FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid INNER JOIN {node_revisions} nr on n.nid = nr.nid WHERE t.tid IN (%s) AND n.status = 1 ORDER BY sticky DESC, created DESC LIMIT %d'), implode($tids, ','), $result->length); $block['subject'] = $result->name; while ($node = db_fetch_object($nodes)) { $x++; $content .= '

'. l($node->title, 'node/'. $node->nid, array('title'=>t('view all'))) .'

'; if($result->teaser) { $content .= strip_tags(substr($node->body, 0, $result->teaser) . (strlen($node->body) > $result->teaser ? '...' : '')) .'
'; } else { $content .= ''; } } $content .= ''; $block['content'] = $content; return $block; } else { return null; } } /** * Returns an array of block descriptions for the block config page. * * @ingroup taxonomy_block_block. * @return array of block descriptions. */ function taxonomy_block_get_blocks() { $results = db_query('SELECT * FROM {taxonomy_block}'); while ($block = db_fetch_object($results)) { $blocks[$block->bid]['info'] = t('Taxonomy Block: ') . $block->description; } return $blocks; } /** * Returns a dropdown event taxonomy term input control. * * @param $tid The current term id. * @param $submit Adds 'onChange' form submit javascript command to control. * @ingroup taxonomy_block_block. * @return A form with a dropdown event taxonomy term input control. */ /*function _taxonomy_block_get_taxonomy_dropdown($tid = NULL) { $vocabs = taxonomy_get_vocabularies(); $links[] = ''; foreach ($vocabs as $vocab) { $links['v'.$vocab->vid] = $vocab->name; $tree = taxonomy_get_tree($vocab->vid); foreach ($tree as $term) { $links[$term->tid] = $vocab->name .' - '. $term->name; } } $form['tid'] = array( '#type' => 'select', '#title' => '', '#default_value' => $tid, '#options' => $links, '#description' => t('Select taxonomy type to display'), ); return $form; }*/ ?>