portions based on code from crw: http://ninjafish.org/project/wiki Drupal freelinking project: http://www.drupal.org/project/freelinking $Id: freelinking.module,v 1.32.2.7 2008-07-05 11:40:12 eafarris Exp $ */ function freelinking_menu() { $items['freelinking'] = array( 'title' => 'Freelinks', 'description' => 'A list of freelinks used on this site', 'page callback' => 'freelinking_page', 'access arguments' => array('access freelinking list'), ); $items['admin/settings/freelinking'] = array( 'title' => 'Freelinking settings', 'description' => 'Configure wiki-style freelinking settings for node content', 'page callback' => 'drupal_get_form', 'page arguments' => array('freelinking_settings'), 'access arguments' => array('administer freelinking'), ); return $items; } // endfunction freelinking_menu function freelinking_perm() { return array('administer freelinking', 'access freelinking list'); } function freelinking_page($thetitle = NULL) { if ($thetitle) { // find the matching title $freelink = _freelinking_make_link($thetitle); drupal_goto($freelink['path'], isset($freelink['options']['query']) ? $freelink['options']['query'] : ''); } else { // no title was passed -- show a list of wikiwords and status $header = array('phrase', 'target'); $query = "SELECT phrase, path FROM {freelinking} ORDER BY phrase"; $result = db_query($query); $i = 0; while ($freelink = db_fetch_object($result)) { // looping through phrase, target pairs $rows[$i][] = urldecode($freelink->phrase); if (preg_match('/^(http|mailto|ftp):/', $freelink->path)) { // an absolute link $rows[$i][] = '' . $freelink->path . ''; } else { // a freelink $fltargetnid = _freelinking_exists($freelink->phrase); $freelink = _freelinking_make_link($freelink->phrase); if ($fltargetnid) { $link = l(t('see this content'), drupal_get_path_alias('node/' . $fltargetnid)); } else { // content not found, show link to create $link = '' . t('create this content') . ''; } $rows[$i][] = $link; } $i++; } if (isset($rows)) { return theme('table', $header, $rows); } else { drupal_set_message(t('There are no freelinks on this site.')); return ''; } } } // endfunction freelinking_page function freelinking_block($op = 'list', $delta = 0) { switch ($op) { case 'list': $blocks[0]['info'] = t('Freelink targets that need to be created'); return $blocks; break; case 'configure': $form['freelinking_block_options'] = array( '#type' => 'fieldset', '#title' => t('Freelinking Block Options') ); $form['freelinking_block_options']['freelinking_blocktitle'] = array( '#title' => t('Title of freelinks block'), '#type' => 'textfield', '#default_value' => variable_get('freelinking_blocktitle', t('Create This Content')), '#size' => 30, '#maxlength' => 60, '#description' => t('Title of the block that shows freelinked phrases without content.') ); for ($i = 5; $i <=30; $i=$i+5) { $options[$i] = $i; } $form['freelinking_block_options']['freelinking_blocknum'] = array( '#title' => t('Number of non-existing link phrases to show'), '#type' => 'select', '#options' => $options, '#default_value' => variable_get('freelinking_blocknum', '10'), '#description' => t('Number of phrases to show in the block.') ); return $form; break; case 'view': switch ($delta) { case 0: $query = 'SELECT * FROM {freelinking} WHERE path LIKE "%node/add%" ORDER BY RAND()'; $result = db_query($query); $i = 0; $content = ''; while ($freelink = db_fetch_object($result)) { if ($i == variable_get('freelinking_blocknum', 10)) { // we're done break; } $items[] = l(urldecode($freelink->phrase), $freelink->path, array(), $freelink->args); $i++; } // endwhile looping through flpairs $block['subject'] = variable_get('freelinking_blocktitle', 'Create This Content'); $block['content'] = theme('item_list', $items); return $block; default: break; } // endswitch $delta default: break; } // endswitch $op } // endfunction freelinking_block function freelinking_settings() { $notfoundoptions = array( 'create only' => t('Only try to create content'), 'no access search' => t('Search for content if user can\'t create'), 'always search' => t('Always search for content'), ); $form["freelinking_nodetype"] = array( '#title' => t('Default for new content'), '#type' => 'select', '#options' => node_get_types('names'), '#default_value' => variable_get("freelinking_nodetype", 'story'), '#description' => t('Type of content that the freelinking filter will create when clicking on a freelink without a target.') ); $form['freelinking_notfound'] = array( '#title' => t('What to do if content not found'), '#type' => 'select', '#options' => $notfoundoptions, '#default_value' => variable_get('freelinking_notfound', 'no access search'), '#description' => t('What to do when clicking on a freelink without a target. Choose to always attempt to create the content, search if the user doesn\'t have permission to create (the default), or to always search. NOTE: search functions require search.module to be activated.'), ); $form["freelinking_restriction"] = array( '#title' => t('Restrict free links to this content type'), '#type' => 'select', '#multiple' => 'true', '#options' => array_merge(array('none' => t('No restrictions')), node_get_types('names')), '#default_value' => variable_get("freelinking_restriction", 'none'), '#description' => t('If desired, you can restrict the freelinking title search to just content of these types. Note that if this does not include as the "Default for new content," above, new freelinked content cannot be found.') ); $form["freelinking_camelcase"] = array( '#title' => t('Allow CamelCase linking'), '#type' => 'checkbox', '#default_value' => variable_get("freelinking_camelcase", 0), '#description' => t('If desired, you can enable CamelCase linking'), ); $form["freelinking_onceonly"] = array( '#title' => t('Only link first occurance'), '#type' => 'checkbox', '#default_value' => variable_get("freelinking_onceonly", 0) == 1 ? TRUE : FALSE, '#description' => t('If desired you can only turn the first occurance of a freelink into a link. This can improve the appearance of content that includes a lot of the same CamelCase words.') ); return system_settings_form($form); } function freelinking_filter($op, $delta = 0, $format = -1, $text = '') { switch ($op) { case 'list': return (array(0 => t('freelinking filter'))); break; case 'name': return t('freelinking filter'); break; case 'description': return t('Enables freelinking between nodes with CamelCase or delimiters like [[ and ]].'); break; case 'process': return _freelinking_do_filtering($text, FALSE); break; case 'prepare': return $text; break; } // endswitch $op } // endfunction freelinking_filter function freelinking_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { switch ($op) { case 'update': _freelinking_do_filtering($node->body, TRUE); break; case 'insert': _freelinking_do_filtering($node->body, TRUE); break; } // endswitch $op } // endfunction freelinking_nodeapi function freelinking_filter_tips($delta, $format, $long = FALSE) { if ($long) { $output = 'Content in [[double square brackets]] will be linked to existing content with that title, or a page to create that content. '; $output .= 'Links can contain an optional bar, "|". Content on the left of the bar is the target; to the right, the link shown. '; $output .= 'Links to pages outside this site are allowed. They must start with one of the following: "http", "https", "ftp", or "mailto", and can exist either by themselves, or on the left of the bar. '; $output .= 'Examples: '; $ouptut .= '