This plugin displays a link to a random entry. Usage: <%Plugin(RandomEntry,optional: customized text instead of title)%>
| General Plugin info | |
|---|---|
| Author: | 020200 (base by katatonik and sulleleven) |
| Current Version: | 0.25 |
| Download: | - |
| Code: | code |
| Demo: | - |
| Forum Thread: | Forum Thread |
Just save the code as NP_RandomEntry.php into your plugin directory and install via the Nucleus admin interface.
Use it like this:
<%plugin(RandomEntry,optional customized linktext)%>
This will show you a random Link with the title of the item. You can also customize the text of the link as a plugin parameter. You can select a specific blog in the pluginadmin-menu.
<?php class NP_RandomEntry extends NucleusPlugin { /* * Version history * 0.25 - View title of random entry or selected text from options (by 020200, http://node3000.org) * 0.2 - Added Blogselection (by sulleleven, http://artistjoint.com/) * 0.1 - A simple Randomplug (by katatonik, http://campcatatonia.org/) */ function getEventList() { return array(); } function getName() { return 'RandomEntry'; } function getAuthor() { return '020200 (base by katatonik and sulleleven)'; } function getURL() { return 'http://www.node3000.org/020200/'; } function getVersion() { return '0.25'; } function getDescription() { return 'This plugin displays a link to a random entry. Usage: <%Plugin(RandomEntry,optional: customized text instead of title)%>'; } // create options function install() { $this->createOption('Activate','Do you want to activate/randomize a specific blog? if set to NO then all blogs will be used','yesno','no'); $this->createOption('WhichBlog','If you chose YES to option 1 then you MUST specify a Blog ID number to randomize items from or disregard this option','text',''); } //end function doSkinVar($skinType) { global $manager, $blog, $CONF; $params = func_get_args(); $thisblogID = $this->getOption('WhichBlog'); $status = $this->getOption('Activate'); $b =& $blog; if ($params[1]){ $theword = $params[1]; } else { $theword = "view random entry";} // If Status is set to 'YES' then randomize all items from specified blog id $sql = "SELECT inumber FROM nucleus_item WHERE iblog = $thisblogID"; // store all item ids from specified blog in array // If Status is set to 'NO' then randomize all item ids from all blogs if ($status == 'no') { $sql = "SELECT inumber FROM nucleus_item"; } // store all item ids in array $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $all_ids[] = $row['inumber']; } // create random number mt_srand((double)microtime()*1000000); $key = array_rand($all_ids, 1); $number = $all_ids[$key]; $itemlink = createItemLink($number, ''); // select title from selected item $sqltitle = "SELECT ititle FROM nucleus_item WHERE inumber = $number"; $tque = mysql_query($sqltitle); $titlelink = mysql_result($tque, 0); // output stuff if ($params[1]){$theword = $params[1];} else { $theword = $titlelink;} // use one of the following outputs echo "<a href=\"".$b->getURL.$itemlink."\">$theword</a>"; // default to be used within your skins // echo "<a href=\"".$IndexURL.$theword.$itemlink."\""; // non-blog page using .inc file but this workaround may not be needed but I set it up to resolve a problem with the link parsing properly // echo "".$IndexURL.$theword.$itemlink."" // non-blog page for use within a javascript call such as--- onClick="frmUpdate('<%plugin(RandomEntry_rev1,index.php)%>'); // in the alternative outputs, you can use the variable $theword to specify the url of the blog items or as in default, just specify text for link } } ?>
NP_RandomEntry version 0.25 works with Nucleus CMS 3.31 - 2007-10-28 Armon
:: Plugins ::