|
Functions | |
| planet_node_info () | |
| Implementation of hook_node_info. | |
| planet_view ($node, $teaser=FALSE, $page=FALSE) | |
| Implementation of hook_view() - Displays a planet node. | |
| planet_access ($op, $node, $account) | |
| Implementation of hook_access() - Define access permissions for planet nodes (aka CRUD) . | |
| planet_form (&$node, &$form_state) | |
| Implementation of hook_form - Display a node editing form. | |
| planet_item_feed_parse ($process_feed, $feed) | |
| Turn each feed item into a node. | |
| planet_access | ( | $ | op, | |
| $ | node, | |||
| $ | account | |||
| ) |
Implementation of hook_access() - Define access permissions for planet nodes (aka CRUD) .
| $op | The operation to be performed: 'create', 'view', 'update', 'delete' | |
| $node | The node on which the operation is to be performed, or, if it does not yet exist, the type of node to be created. | |
| $account | A user object representing the user for whom the operation is to be performed. |
00108 { 00109 // @DIFFINFO using planet-dedicated permissions 00110 // Planet administrator has all permissions related to planet module 00111 if (user_access('administer planet', $account)) 00112 return TRUE; 00113 // Users allowed to edit their own planet nodes, are also allowed to create them, others are not. 00114 $author = user_access('edit own planet feeds', $account); 00115 if ($op == 'create') { 00116 return $author; 00117 } 00118 00119 // Does current user own requested node ? 00120 $own = $account->uid == $node->uid; 00121 if ($op == 'view') 00122 return $own || user_access('view all planet nodes'); 00123 if ($op == 'update' || $op == 'delete') { 00124 return $author && $own; // ok if $author owns the node 00125 } 00126 trigger_error("Unknown operation requested: $op"); 00127 return FALSE; 00128 }

| planet_form | ( | &$ | node, | |
| &$ | form_state | |||
| ) |
Implementation of hook_form - Display a node editing form.
| &$node | The node being added or edited. | |
| $form_state | The form state array (unused). |
00981 { 00982 $form = array(); 00983 $form['title'] = array('#type' => 'textfield', '#title' => 'Title', '#value' => $node->title, '#size' => 30, '#maxlength' => 80); 00984 $form['body'] = array('#type' => 'textarea', '#title' => 'Body', '#value' => $node->body); 00985 return $form; 00986 }
| planet_item_feed_parse | ( | $ | process_feed, | |
| $ | feed | |||
| ) |
Turn each feed item into a node.
| $process_feed | Feed node object | |
| $feed | SimplePie feed object instantiated. |
00998 { 00999 // loop through all of the items in the feed, faster than foreach 01000 $max = $feed->get_item_quantity(); 01001 $count = 0; 01002 module_load_include('inc', 'node', 'node.pages'); 01003 module_load_include('inc', 'node', 'content_types'); 01004 $node = node_get_types('type', 'feed_item'); 01005 01006 for ($i = 0; $i < $max; $i++) { 01007 $item = $feed->get_item($i); 01008 01009 // we don't use $item->get_id(true) from SimplePie because it is slightly buggy 01010 // and requires a lot of overhead to compute each time (since it uses a gigantic array structure) 01011 // instead we opt for a much lighter weight comparison of just the title and body, eliminating the 01012 // possibility of any date changes or other tiny changes causing duplicate nodes that otherwise 01013 // appear to be the same 01014 // that is why the body and title processing appears out here, so we can check for duplicates 01015 // it is fast enough to not make much of a difference otherwise 01016 $body = $item->get_content(); 01017 // this strips out any tags that may appear as <b> in the title, and makes sure " -> " for display 01018 $title = strip_tags(decode_entities($item->get_title())); 01019 01020 // some feeds don't provide titles so we construct one with the first 72 characters of the body 01021 if (!$title) { 01022 // remove any HTML or line breaks so these don't appear in the title 01023 $title = trim(str_replace(array("\n", "\r"), ' ', strip_tags($body))); 01024 $title = trim(substr($title, 0, 72)); 01025 $lastchar = substr($title, -1, 1); 01026 // check to see if the last character in the title is a non-alphanumeric character, except for ? or ! 01027 // if it is strip it off so you don't get strange looking titles 01028 if (preg_match('/[^0-9A-Za-z\!\?]/', $lastchar)) { 01029 $title = substr($title, 0, -1); 01030 } 01031 // ? and ! are ok to end a title with since they make sense 01032 if ($lastchar != '!' and $lastchar != '?') { 01033 $title .= '...'; 01034 } 01035 } 01036 01037 // unique id for each feed item, try and use item permalink, otherwise use feed permalink 01038 if (!$link = $item->get_permalink()) { 01039 $link = $feed->get_permalink(); 01040 } 01041 // we don't need serialize() since we already have strings 01042 $iid = md5($title . $link); 01043 $guid = md5("$title - . " . $process_feed->fid); 01044 // make sure we don't already have this feed item 01045 $duplicate = db_result(db_query("SELECT COUNT(iid) FROM {planet_items} WHERE iid = '%s'", $iid)); 01046 01047 if (!$duplicate) { 01048 01049 01050 $entry = NULL; 01051 if ($guid && strlen($guid) > 0) { 01052 $entry = db_fetch_object(db_query("SELECT nid FROM {planet_items} WHERE guid = '%s' AND fid = %d", $guid, $process_feed->fid)); 01053 } 01054 else if ($link && $link != $feed->link && $link != $feed->url) { 01055 $entry = db_fetch_object(db_query("SELECT nid FROM {planet_items} WHERE guid = '%s' AND fid = %d", $link, $process_feed->fid)); 01056 } 01057 else { 01058 $entry = db_fetch_object(db_query("SELECT ai.nid AS nid FROM {node} n, {planet_items} ai WHERE ai.fid = %d AND ai.nid = n.nid AND n.title = '%s'", $process_feed->fid, $title)); 01059 } 01060 01061 $link = $item->get_permalink(); 01062 // this is node created date format for Drupal 01063 $date = $item->get_date('Y-m-d H:i:s O'); 01064 01065 $entry->changed = $date; 01066 $entry->title = $title; 01067 $entry->body = $body; 01068 $entry->body = planet_convert_relative_urls($body, $link); 01069 $entry->teaser = node_teaser($entry->body); 01070 $entry->revision = true; 01071 01072 if (!isset($entry->nid)) { 01073 //print "Planet item " . $entry->title . "<br />"; 01074 $entry->type = 'planet'; 01075 01076 $options = variable_get('node_options_planet', array()); 01077 01078 $entry->uid = $process_feed->uid; 01079 $entry->status = 1; 01080 $entry->moderate = 0; 01081 $entry->promote = in_array('promote', $options) ? 1 : 0; 01082 $entry->sticky = in_array('sticky', $options) ? 1 : 0; 01083 $entry->comment = in_array('comment', $options) ? 2 : 0; 01084 $entry->format = variable_get('planet_filter_formats', 1); 01085 $entry->created = $date; 01086 $entry->revision = true; 01087 01088 } 01089 01090 node_save($entry); 01091 $item_record = array('fid' => $process_feed->fid, 01092 'nid' => $entry->nid, 01093 'iid' => $iid, 01094 'guid'=> $guid, 01095 'link' =>$link, 01096 'created' => time()); 01097 drupal_write_record('planet_items', $item_record); 01098 watchdog('planet', 'Adding '. $title); 01099 drupal_set_message('Adding '. $title); 01100 } 01101 01102 // we unset $item each time to prevent any pass by reference memory leaks that PHP encounters with objects in foreach loops 01103 unset($item); 01104 } 01105 01106 }


| planet_node_info | ( | ) |
Implementation of hook_node_info.
00023 { 00024 return array( 00025 'planet' => array( 00026 'name' => t('Planet Entry'), 00027 'module' => 'planet', 00028 'description' => t('Node to contain posts aggregated from various blogs.'), 00029 ) 00030 ); 00031 }

| planet_view | ( | $ | node, | |
| $ | teaser = FALSE, |
|||
| $ | page = FALSE | |||
| ) |
Implementation of hook_view() - Displays a planet node.
| $node | The node to be displayed. | |
| $teaser | Whether to generate only a summary ("teaser") of the node. | |
| $page | Whether the node is being displayed as a standalone page. |
DB @CRUD: planet_items[R]
00083 { 00084 // @DIFFINFO removed $link param to match D6 hook definition 00085 if ($page === true && variable_get('planet_redirect_page', 0) == 1) { 00086 // @DIFFINFO only 'link' field is used, so I restricted the query 00087 $obj = db_fetch_object(db_query('SELECT link FROM {planet_items} WHERE nid = %d', $node->nid)); 00088 // @DIFFINFO if the query succeeds, $obj->nid == $node->nid , otherwise, $obj==FALSE, 00089 if ($obj && $obj->link != '') { 00090 header('Location: '. $obj->link); 00091 exit; 00092 } 00093 } 00094 else { 00095 return node_prepare($node, $teaser); 00096 } 00097 }

1.5.8