示例#1
0
// }
// if ($aPosts = $oDelicious->GetPosts($sTag)) {
// foreach ($aPosts as $aPost) {
// echo '<a href="'.$aPost['url'].'">'.$aPost['desc'].'</a>';
// echo $aPost['notes'];
// echo $aPost['updated'];
// }
// } else {
// echo $oDelicious->LastErrorString();
// }
// $sTag = 'twitter', // filter by tag
// $iCount = 15 // number of posts to retrieve, min 15, max 100
// if ($aPosts = $oDelicious->GetRecentPosts($sTag,$iCount)) {
// foreach ($aPosts as $aPost) {
// echo '<a href="'.$aPost['url'].'">'.$aPost['desc'].'</a>';
// echo $aPost['notes'];
// echo $aPost['updated'];
// }
// } else {
// echo $oDelicious->LastErrorString();
// }
$aPost = array();
$aPost['url'] = 'http://www.yahoo.com';
$aPost['description'] = 'Yahoo! home page';
$aPost['notes'] = 'Lame search engine';
$aPost['updated'] = date('Y-m-d H:i:s');
//mysql timestamp
$aTags = array('lame', 'dumb', 'search engine');
//must be array
$oDelicious->AddPost($aPost['url'], $aPost['description'], $aPost['notes'], $aTags, $aPost['updated'], true);
 /**
  * There seems to be no PostUpdateItem event so here we go
  */
 function event_PreUpdateItem($data)
 {
     $mode = 'insert';
     $itemid = $data['itemid'];
     $tags = requestVar('plugin_technoratitags_field');
     if ($tags != '') {
         $tag_arr = array();
         $tag_arr = explode(" ", $tags);
         $tag_arr = array_unique($tag_arr);
         $tags = implode(" ", $tag_arr);
     }
     /* First check if there is already a row for this post */
     $result = sql_query("SELECT * FROM " . $this->tablename . " WHERE itemid=" . $data['itemid']);
     if (sql_num_rows($result) > 0) {
         $mode = 'update';
     }
     sql_free_result($result);
     if ($mode == 'insert') {
         $query = "INSERT INTO " . $this->tablename . " (itemid,tags) VALUES (" . $itemid . ",'" . $tags . "')";
     } else {
         $query = "UPDATE " . $this->tablename . " SET tags = '" . $tags . "' WHERE itemid = " . $itemid;
     }
     // update
     sql_query($query);
     if ($this->getOption('DelIcioUs') == "yes") {
         global $manager;
         $url = createItemLink($itemid);
         // get item info
         $item =& $manager->getItem($itemid, 0, 0);
         $title = $data['title'] != '' ? $data['title'] : $item['title'];
         $authorid = $item['authorid'];
         $user = $this->getMemberOption($authorid, 'DeliciousUser');
         $password = $this->getMemberOption($authorid, 'DeliciousPassword');
         if ($user != '' && $password != '') {
             $oPhpDelicious = new PhpDelicious($user, $password);
             if (isset($tag_arr)) {
                 $oPhpDelicious->AddPost($url, $title, '', $tag_arr);
             } else {
                 // remove the link is no tag for this post, link with no tag is just useless
                 $oPhpDelicious->DeletePost($url);
             }
         }
     }
 }