Example #1
0
function publishToDelicious($title, $url, $note, $tags = array())
{
    if (DELICIOUS_PUB) {
        /* Setup Zend */
        require_once 'Zend/Loader.php';
        Zend_Loader::loadClass('Zend_Service_Delicious');
        $delicious = new Zend_Service_Delicious(DELICIOUS_USER, DELICIOUS_PASS);
        $delicious->createNewPost($title, $url)->setNotes($note)->setTags($tags)->save();
    }
}
Example #2
0
 /**
  * Saves post
  */
 public function save()
 {
     $parms = array('url' => $this->_url, 'description' => $this->_title, 'extended' => $this->_notes, 'shared' => $this->_shared ? 'yes' : 'no', 'tags' => implode(' ', (array) $this->_tags), 'replace' => 'yes');
     if ($this->_date instanceof Zend_Date) {
         $parms['dt'] = $this->_date->get('Y-m-d\\TH:i:s\\Z');
     }
     return $this->_service->makeRequest(Zend_Service_Delicious::PATH_POSTS_ADD, $parms);
 }
Example #3
0
 /**
  * Try to get details of some URL
  *
  * @return void
  */
 public function testGetUrlDetails()
 {
     $details = $this->_delicious->getUrlDetails(self::TEST_URL);
     $this->assertType('array', $details);
     $this->assertArrayHasKey('hash', $details);
     $this->assertArrayHasKey('top_tags', $details);
     $this->assertArrayHasKey('url', $details);
     $this->assertArrayHasKey('total_posts', $details);
     $this->assertEquals(self::TEST_URL, $details['url']);
     $this->assertType('array', $details['top_tags']);
 }
 public function fetch()
 {
     if ($this->_disabled) {
         return array();
     }
     $frontendOptions = array('lifetime' => $this->_config->cacheLifetime, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => $this->_config->cacheDir);
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     if (!($this->_items = $cache->load('delicious'))) {
         $delicious = new Zend_Service_Delicious($this->_config->username, $this->_config->password);
         $results = $delicious->getRecentPosts(null, $this->_config->limit);
         $this->_items = array();
         foreach ($results as $entry) {
             $this->_items[] = new Polycast_Stalker_Item_Delicious($entry->getTitle(), $entry->getUrl(), $entry->getTags(), new DateTime($entry->getDate()->toString()), $entry->getNotes(), $this->_config->items);
         }
         $cache->save($this->_items, 'delicious');
         uasort($this->_items, array('Polycast_Stalker', 'sortItems'));
         $this->_items = array_slice($this->_items, 0, $this->_config->limit, true);
     }
     return count($this->_items);
 }
 /**
  * @return void
  */
 public function testGetPosts()
 {
     $posts = $this->_delicious->getUserPosts(self::TEST_UNAME, 10);
     $this->assertType('Zend_Service_Delicious_PostList', $posts);
     // check if all objects in returned Zend_Service_Delicious_PostList
     // are instances of Zend_Service_Delicious_SimplePost
     foreach ($posts as $post) {
         $this->assertType('Zend_Service_Delicious_SimplePost', $post);
     }
     // test filtering of Zend_Service_Delicious_PostList by tag name
     $filterPostList = $posts->withTag('zfSite');
     foreach ($filterPostList as $post) {
         $this->assertType('array', $post->getTags());
         $this->assertContains('zfSite', $post->getTags());
     }
 }
Example #6
0
    /**
     * Handles all GET requests to a web service
     *
     * @param  string $path  Path
     * @param  array  $parms Array of GET parameters
     * @param  string $type  Type of a request ("xml"|"json")
     * @return mixed  decoded response from web service
     */
    public function makeRequest($path, array $parms = array(), $type = 'xml')
    {
        // if previous request was made less then 1 sec ago
        // wait until we can make a new request
        $timeDiff = microtime(true) - self::$_lastRequestTime;
        if ($timeDiff < 1) {
            usleep((1 - $timeDiff) * 1000000);
        }

        $this->_rest->getHttpClient()->setAuth($this->_authUname, $this->_authPass);

        switch ($type) {
            case 'xml':
                $this->_rest->setUri(self::API_URI);
                break;
            case 'json':
                $parms['raw'] = true;
                $this->_rest->setUri(self::JSON_URI);
                break;
            default:
                /**
                 * @see Zend_Service_Delicious_Exception
                 */
                require_once 'Zend/Service/Delicious/Exception.php';
                throw new Zend_Service_Delicious_Exception('Unknown request type');
        }

        self::$_lastRequestTime = microtime(true);
        $response = $this->_rest->restGet($path, $parms);

        if (!$response->isSuccessful()) {
            /**
             * @see Zend_Service_Delicious_Exception
             */
            require_once 'Zend/Service/Delicious/Exception.php';
            throw new Zend_Service_Delicious_Exception("Http client reported an error: '{$response->getMessage()}'");
        }

        $responseBody = $response->getBody();

        switch ($type) {
            case 'xml':
                $dom = new DOMDocument() ;

                if (!@$dom->loadXML($responseBody)) {
                    /**
                     * @see Zend_Service_Delicious_Exception
                     */
                    require_once 'Zend/Service/Delicious/Exception.php';
                    throw new Zend_Service_Delicious_Exception('XML Error');
                }

                return $dom;
            case 'json':
                return Zend_Json_Decoder::decode($responseBody);
        }
    }
Example #7
0
         $p->vxContainer('add_sync', $sync);
         break;
     }
 case 'add_sync_start':
     if (!$p->User->vxIsLogin()) {
         die($p->URL->vxToRedirect($p->URL->vxGetLogin($p->URL->vxGetAddSync())));
         break;
     } else {
         $sync = array();
         $sync['status'] = 'default';
         if (isset($_POST['d_u']) && isset($_POST['d_p'])) {
             $del_user = fetch_single($_POST['d_u']);
             $del_pass = fetch_single($_POST['d_p']);
             if ($del_user != '' && $del_pass != '') {
                 require_once 'Zend/Service/Delicious.php';
                 $del = new Zend_Service_Delicious($del_user, $del_pass);
                 try {
                     $posts = $del->getAllPosts();
                 } catch (Zend_Service_Delicious_Exception $e) {
                     $posts = false;
                     $sync['status'] = 'error';
                 }
                 if ($posts) {
                     var_dump($posts);
                     $result = Add::vxSync($p->User, $p->db, $posts);
                     var_dump($result);
                 }
             } else {
                 $sync['status'] = 'default';
             }
         } else {
Example #8
0
 /**
  *
  * @return void
  */
 public function testDates()
 {
     $this->assertType('array', $this->_delicious->getDates());
 }
Example #9
0
 /**
  *
  * @return void
  */
 public function testDates()
 {
     $this->assertTrue(is_array($this->_delicious->getDates()));
 }
Example #10
0
 /**
  * Saves post
  *
  * @return DOMDocument
  */
 public function save()
 {
     $parms = array('url' => $this->_url, 'description' => $this->_title, 'extended' => $this->_notes, 'shared' => $this->shared ? 'yes' : 'no', 'tags' => implode(' ', (array) $this->_tags), 'replace' => 'yes');
     return $this->service->makeRequest(Delicious::PATH_POSTS_ADD, $parms);
 }
Example #11
0
 /**
  * Handles all GET requests to a web service
  *
  * @param string $path Path
  * @param array $parms Array of GET parameters
  * @param string $type Type of a request xml|json
  * @return DOMDocument response from web service
  */
 public function makeRequest($path, $parms = array(), $type = 'xml')
 {
     settype($parms, 'array');
     // if previous request was made less then 1 sec ago
     // wait until we can make a new request
     $timeDiff = microtime(true) - self::$_lastRequestTime;
     if ($timeDiff < 1) {
         usleep((1 - $timeDiff) * 1000000);
     }
     $this->_http->resetParameters();
     foreach ($parms as $f_parm => $f_value) {
         $this->_http->setParameterGet($f_parm, $f_value);
     }
     switch ($type) {
         case 'xml':
             $this->_http->setUri(self::API_URI . $path);
             break;
         case 'json':
             $this->_http->setUri(self::JSON_URI . $path);
             $this->_http->setParameterGet('raw', true);
             break;
         default:
             throw new Zend_Service_Delicious_Exception('Unknown request type');
     }
     self::$_lastRequestTime = microtime(true);
     $response = $this->_http->request(Zend_Http_Client::GET);
     if (!$response->isSuccessful()) {
         throw new Zend_Service_Delicious_Exception("Http client reported an error: '{$response->getMessage()}'");
     }
     $responseBody = $response->getBody();
     switch ($type) {
         case 'xml':
             $dom = new DOMDocument();
             if (!@$dom->loadXML($responseBody)) {
                 throw new Zend_Service_Delicious_Exception('XML Error');
             }
             return $dom;
         case 'json':
             return Zend_Json::decode($responseBody);
     }
 }
 /**
  * For an individual tag
  *
  * @param string $user 
  * @param string $count 
  * @param string $tag 
  * @return void
  * @author Dan Chadwick
  */
 private function get_user_posts_by_tag($user, $count, $tag)
 {
     $links = array();
     $delicious = new Zend_Service_Delicious();
     try {
         $posts = $delicious->getUserPosts($user, $count, $tag);
         foreach ($posts as $post) {
             $links[] = array('title' => $post->getTitle(), 'url' => $post->getUrl());
         }
         return $links;
     } catch (Exception $e) {
         Kohana::log('debug', 'Delicious err.' . $e->getMessage());
     }
 }