Inline Tags Sample Module Code

<?php
/**
 * Module implementing Drupal's hook_nodeapi
 * @see http://api.drupal.org/api/function/hook_nodeapi/6
 * Important Note: This is sample code.  You'll need to modify this code to just use the inline tags on your choice of content types
 * and to check if the user has permission to use inline tags
 */
function inlinetags_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'submit':
      break;
      //before stuff makes it into the database (before update or insert)
    case 'presave':
      //parse out any inline tags within body
      $bd = _parseinlinetags( $node->body );
      //parse out any inline tags that may have made it into the teaser
      $ts = _parseinlinetags( $node->teaser );
      //replace the body with a version that has removed the inline tags code
      $node->body = $bd[0];
      //replace the teaser with a version that has removed the inline tags code
      $node->teaser = $ts[0];
      //if there were any preexisting tags then add them to the tag string
      if ($bd[1] !=''){
        //note my tags vocabulary id is just hard coded here
        $vid = 1;
        $tagstring = $bd[1];
        //if there were pre-existing tags, add them to the tag string
        if ($node->taxonomy['tags'][1]!='') {
          //prepend the new tags to any old ones
          $tagstring .= ','.$node->taxonomy['tags'][1];
        }
        //now add them to the tags vocab for the insert or update operation
        $node->taxonomy['tags'] = array($vid => $tagstring);
      }
      break;
    case 'insert':
    case 'update':
      break;
    case 'view':
      break;
  }
}
/**
 * A private function to parse out placeholder tags
 * This version has been stripped to parse out just placeholders with a format like:
 *
 *
 * @param string $page_contents
 * @return array an array with $return[0] the tags parsed out and $return[1] as a string with the tags
 */
function _parseinlinetags( $page_contents )
{
  $matches = explode( '' ) );
    $pageplaceholder = str_replace( '[/tags]', '', $placeholder );
  }
  $search = '';
  $page_contents = str_replace ( $search, '', $page_contents );

  $return[] = $page_contents;
  $return[] = $pageplaceholder;
  return $return;
}
?>

Share or Comment via Twitter