You are here

function _freelinking_make_link in Freelinking 5

Same name and namespace in other branches
  1. 6 freelinking.module \_freelinking_make_link()
  2. 6.2 freelinking.module \_freelinking_make_link()
2 calls to _freelinking_make_link()
freelinking_page in ./freelinking.module
freelinking_page_form in ./freelinking.module

File

./freelinking.module, line 499

Code

function _freelinking_make_link($thetitle) {

  // helper function for freelinking_page
  global $user;

  // Returns a link to a node named $thetitle if found, or a link to new content otherwise.
  $nid = _freelinking_exists($thetitle);
  if ($nid) {

    // the node exists, set the path to go there
    $freelink['path'] = 'node/' . $nid;
  }
  else {

    // node doesn't exist, set path to create it
    switch (variable_get('freelinking_notfound', 'no access search')) {
      case 'create only':
        $freelink['path'] = 'node/add/' . variable_get('freelinking_nodetype', 'story');
        $freelink['args'] = 'edit[title]=' . $thetitle;
        break;
      case 'no access search':
        if (node_access('create', variable_get('freelinking_nodetype', 'story'))) {
          $freelink['path'] = 'node/add/' . variable_get('freelinking_nodetype', 'story');
          $freelink['args'] = 'edit[title]=' . $thetitle;
        }
        else {
          $freelink['path'] = 'search/node/' . $thetitle;
        }
        break;
      case 'always search':
        $freelink['path'] = 'search/node/' . $thetitle;
        break;
    }

    // endswitch notfound options
  }
  _freelinking_store($thetitle, $freelink['path'], $freelink['args']);
  return $freelink;
}