Example #1
0
File: Atom.php Project: hisaboh/w2t
 protected function __add__($arg)
 {
     if ($arg instanceof AtomEntry) {
         $this->entry[] = $arg;
     } else {
         if ($arg instanceof self) {
             foreach ($arg->arEntry() as $entry) {
                 $this->entry[] = $entry;
             }
         } else {
             if (is_implements_of($arg, "AtomInterface")) {
                 $entry = new AtomEntry();
                 $entry->id($arg->atom_id());
                 $entry->title($arg->atom_title());
                 $entry->published($arg->atom_published());
                 $entry->updated($arg->atom_updated());
                 $entry->issued($arg->atom_issued());
                 $content = new AtomContent();
                 $content->value($arg->atom_content());
                 $entry->content($content);
                 $summary = new AtomSummary();
                 $summary->value($arg->atom_summary());
                 $entry->summary($summary);
                 $entry->link(new AtomLink("href=" . $arg->atom_href()));
                 $entry->author(new AtomAuthor("name=" . $arg->atom_author()));
                 $this->entry[] = $entry;
             }
         }
     }
 }
Example #2
0
 function parseXML()
 {
     parent::parseXML();
     $this->_self_url = $this->getXPathValue('atom:link[@rel="self"]/@href');
     $this->_edit_url = $this->getXPathValue('atom:link[@rel="edit"]/@href');
     $this->_photos_url = $this->getXPathValue('atom:link[@rel="photos"]/@href');
 }
Example #3
0
 function __construct()
 {
     $this->_album_collection = null;
     $this->_photo_collection = null;
     $this->_album_collection_url = null;
     $this->_photo_collection_url = null;
     parent::__construct();
 }
Example #4
0
 /**
  * Create ATOM struct of a given category
  *
  * @access  public
  * @param   int     $category   Category ID
  * @param   string  $feed_type  OPTIONAL feed type
  * @return  mixed   Can return the Atom Object or Jaws_Error on error
  */
 function GetCategoryAtomStruct($category, $feed_type = 'atom')
 {
     $model = $this->gadget->model->load('Categories');
     $catInfo = $model->GetCategory($category);
     if (Jaws_Error::IsError($catInfo)) {
         return new Jaws_Error(_t('BLOG_ERROR_GETTING_CATEGORIES_ATOMSTRUCT'));
     }
     $now = Jaws_DB::getInstance()->date();
     $blogTable = Jaws_ORM::getInstance()->table('blog');
     $blogTable->select('blog.id:integer', 'user_id:integer', 'blog_entrycat.category_id:integer', 'username', 'email', 'nickname', 'title', 'fast_url', 'summary', 'text', 'blog.publishtime', 'blog.updatetime', 'clicks:integer', 'comments:integer', 'allow_comments:boolean', 'published:boolean')->join('users', 'blog.user_id', 'users.id')->join('blog_entrycat', 'blog.id', 'blog_entrycat.entry_id');
     $blogTable->where('published', true)->and()->where('blog.publishtime', $now, '<=');
     $blogTable->and()->where('blog_entrycat.category_id', $catInfo['id']);
     $result = $blogTable->orderby('blog.publishtime desc')->fetchAll();
     if (Jaws_Error::IsError($result)) {
         return new Jaws_Error(_t('BLOG_ERROR_GETTING_CATEGORIES_ATOMSTRUCT'));
     }
     $cid = empty($catInfo['fast_url']) ? $catInfo['id'] : Jaws_XSS::filter($catInfo['fast_url']);
     $categoryAtom = new Jaws_AtomFeed();
     $siteURL = $GLOBALS['app']->GetSiteURL('/');
     $url = $this->gadget->urlMap($feed_type == 'atom' ? 'ShowAtomCategory' : 'ShowRSSCategory', array('id' => $cid), true);
     $categoryAtom->SetTitle($this->gadget->registry->fetch('site_name', 'Settings'));
     $categoryAtom->SetLink($url);
     $categoryAtom->SetId($siteURL);
     $categoryAtom->SetTagLine($catInfo['name']);
     $categoryAtom->SetAuthor($this->gadget->registry->fetch('site_author', 'Settings'), $siteURL, $this->gadget->registry->fetch('gate_email', 'Settings'));
     $categoryAtom->SetGenerator('JAWS ' . $GLOBALS['app']->Registry->fetch('version'));
     $categoryAtom->SetCopyright($this->gadget->registry->fetch('site_copyright', 'Settings'));
     $objDate = Jaws_Date::getInstance();
     foreach ($result as $r) {
         $entry = new AtomEntry();
         $entry->SetTitle($r['title']);
         $post_id = empty($r['fast_url']) ? $r['id'] : $r['fast_url'];
         $url = $this->gadget->urlMap('SingleView', array('id' => $post_id), true);
         $entry->SetLink($url);
         $entry->SetId($url);
         $summary = $r['summary'];
         $text = $r['text'];
         // for compatibility with old versions
         $more_pos = Jaws_UTF8::strpos($text, '[more]');
         if ($more_pos !== false) {
             $summary = Jaws_UTF8::substr($text, 0, $more_pos);
             $text = Jaws_UTF8::str_replace('[more]', '', $text);
             // Update this entry to split summary and body of post
             $model = $this->gadget->model->load('Posts');
             $model->SplitEntry($r['id'], $summary, $text);
         }
         $summary = empty($summary) ? $text : $summary;
         $summary = $this->gadget->ParseText($summary);
         $text = $this->gadget->ParseText($text);
         $entry->SetSummary($summary, 'html');
         $entry->SetContent($text, 'html');
         $email = $r['email'];
         $entry->SetAuthor($r['nickname'], $categoryAtom->Link->HRef, $email);
         $entry->SetPublished($objDate->ToISO($r['publishtime']));
         $entry->SetUpdated($objDate->ToISO($r['updatetime']));
         $categoryAtom->AddEntry($entry);
         if (!isset($last_modified)) {
             $last_modified = $r['updatetime'];
         }
     }
     if (isset($last_modified)) {
         $categoryAtom->SetUpdated($objDate->ToISO($last_modified));
     } else {
         $categoryAtom->SetUpdated($objDate->ToISO(date('Y-m-d H:i:s')));
     }
     return $categoryAtom;
 }
Example #5
0
File: Feeds.php Project: uda/jaws
 /**
  * Create ATOM struct of recent comments
  *
  * @access  private
  * @param   string  $gadget     Gadget name
  * @param   string  $action     Action name
  * @param   int     $reference  Reference Id
  * @param   string  $feed_type feed type
  * @return  object  Can return the Atom Object
  */
 function GetRecentCommentsAtomStruct($gadget, $action = null, $reference = null, $feed_type = 'atom')
 {
     $max_title_size = 80;
     $cModel = $this->gadget->model->load('Comments');
     $comments = $cModel->GetComments($gadget, $action, $reference, '', array(Comments_Info::COMMENTS_STATUS_APPROVED));
     if (Jaws_Error::IsError($comments)) {
         return new Jaws_Error(_t('COMMENTS_ERROR_GETTING_COMMENTS_ATOMSTRUCT'));
     }
     $commentAtom = new Jaws_AtomFeed();
     $siteURL = $GLOBALS['app']->GetSiteURL('/');
     $params = array('gadgetname' => $gadget);
     if (!empty($action)) {
         $params['actionname'] = $action;
     }
     if (!empty($reference)) {
         $params['reference'] = $reference;
     }
     $url = $this->gadget->urlMap($feed_type == 'atom' ? 'RecentCommentsAtom' : 'RecentCommentsRSS', $params, true);
     $commentAtom->SetTitle($this->gadget->registry->fetch('site_name', 'Settings'));
     $commentAtom->SetLink($url);
     $commentAtom->SetId($siteURL);
     $commentAtom->SetAuthor($this->gadget->registry->fetch('site_author', 'Settings'), $GLOBALS['app']->GetSiteURL('/'), $this->gadget->registry->fetch('gate_email', 'Settings'));
     $commentAtom->SetGenerator('JAWS ' . $GLOBALS['app']->Registry->fetch('version'));
     $commentAtom->SetCopyright($this->gadget->registry->fetch('site_copyright', 'Settings'));
     $commentAtom->SetTagLine(_t('COMMENTS_RECENT_COMMENTS', _t(strtoupper($gadget) . '_TITLE')));
     $objDate = Jaws_Date::getInstance();
     $site = preg_replace('/(.*)\\/.*/i', '\\1', $commentAtom->Link->HRef);
     foreach ($comments as $c) {
         $entry_id = $c['reference'];
         $entry = new AtomEntry();
         $entry->SetTitle(Jaws_UTF8::strlen($c['msg_txt']) >= $max_title_size ? Jaws_UTF8::substr($c['msg_txt'], 0, $max_title_size) . '...' : $c['msg_txt']);
         $entry->SetId("urn:gadget:{$gadget}:action:{$action}:reference:{$reference}:comment:{$c['id']}");
         switch ($gadget) {
             case 'Blog':
                 // So we can use the UrlMapping feature.
                 $url = $GLOBALS['app']->Map->GetURLFor('Blog', 'SingleView', array('id' => $entry_id), true);
                 $url = $url . htmlentities('#comment' . $c['id']);
                 $entry->SetLink($url);
                 break;
             case 'Phoo':
                 $url = $GLOBALS['app']->Map->GetURLFor('Phoo', 'ViewImage', array('id' => $entry_id), true);
                 $url = $url . htmlentities('#comment' . $c['id']);
                 $entry->SetLink($url);
                 break;
             case 'Shoutbox':
                 $url = $GLOBALS['app']->Map->GetURLFor('Shoutbox', 'Comments', array(), true);
                 $url = $url . htmlentities('#comment' . $c['id']);
                 $entry->SetLink($url);
                 break;
         }
         $content = Jaws_String::AutoParagraph($c['msg_txt']);
         $entry->SetSummary($content, 'html');
         $entry->SetContent($content, 'html');
         $entry->SetAuthor($c['name'], $commentAtom->Link->HRef, $c['email']);
         $entry->SetPublished($objDate->ToISO($c['insert_time']));
         $entry->SetUpdated($objDate->ToISO($c['insert_time']));
         $commentAtom->AddEntry($entry);
         if (!isset($last_modified)) {
             $last_modified = $c['insert_time'];
         }
     }
     if (isset($last_modified)) {
         $commentAtom->SetUpdated($objDate->ToISO($last_modified));
     } else {
         $commentAtom->SetUpdated($objDate->ToISO(date('Y-m-d H:i:s')));
     }
     return $commentAtom;
 }
Example #6
0
File: Rss.php Project: hisaboh/w2t
 public function atom()
 {
     Rhaco::import("net.feed.atom.Atom");
     $atom = new Atom();
     $atom->title($this->title());
     $atom->subtitle($this->description());
     $atom->generator($this->webMaster());
     $atom->updated($this->lastBuildDate());
     $link = new AtomLink();
     $link->href($this->link());
     $atom->link($link);
     foreach ($this->arItem() as $item) {
         $entry = new AtomEntry();
         $entry->title($item->title());
         $entry->published($item->pubDate());
         $author = new AtomAuthor();
         $author->name($item->author());
         $entry->author($author);
         $link = new AtomLink();
         $link->href($item->link());
         $entry->link($link);
         $content = new AtomContent();
         $content->value($item->description());
         $entry->content($content);
         $summary = new AtomSummary();
         $summary->value($item->comments());
         $entry->summary($summary);
         $atom->add($entry);
     }
     return $atom;
     /***
     			 $src = text('
     						<rss version="2.0">
     							<channel>
     								<title>rhaco</title>
     								<link>http://rhaco.org</link>
     								<description>php</description>
     								<language>ja</language>
     								<copyright>rhaco.org</copyright>
     								<docs>hogehoge</docs>
     								<lastBuildDate>2007-10-10T10:10:10+09:00</lastBuildDate>
     								<managingEditor>tokushima</managingEditor>
     								<pubDate>2007-10-10T10:10:10+09:00</pubDate>
     								<webMaster>kazutaka</webMaster>
     								<item>
     									<title>rhaco</title>
     									<link>http://rhaco.org</link>
     									<description>rhaco desc</description>
     								</item>
     								<item>
     									<title>everes</title>
     									<link>http://www.everes.net</link>
     									<description>everes desc</description>
     								</item>
     							</channel>
     						</rss>
     					');
     					$xml = Rss::parse($src);
     					eq("2.0",$xml->version());
     					eq("rhaco",$xml->title());
     					eq("http://rhaco.org",$xml->link());
     					eq("php",$xml->description());
     					eq("ja",$xml->language());
     					eq("rhaco.org",$xml->copyright());
     					eq("hogehoge",$xml->docs());
     					eq(1191978610,$xml->lastBuildDate());
     					eq("Wed, 10 Oct 2007 10:10:10 +0900",$xml->fmLastBuildDate());
     					eq("tokushima",$xml->managingEditor());
     					eq(1191978610,$xml->pubDate());
     					eq("Wed, 10 Oct 2007 10:10:10 +0900",$xml->fmPubDate());
     					eq("kazutaka",$xml->webMaster());
     					eq(2,sizeof($xml->item()));
     
     					$atom = $xml->atom();
     					eq(true,$atom instanceof Atom);
     					eq("rhaco",$atom->title());
     					eq("php",$atom->subtitle());
     					eq(1191978610,$atom->updated());
     					eq("kazutaka",$atom->generator());
     					eq(2,sizeof($atom->entry()));
     			*/
 }
Example #7
0
 function parseXML()
 {
     parent::parseXML();
 }
Example #8
0
function atom_save($document)
{
    global $config, $javascript_msg;
    // Split up the post to get the title and content separately
    $div = strpos($document, "\n");
    $title = trim(substr($document, 0, $div));
    $content = substr($document, $div + 1);
    // Prep these elements for use in the Atom objects later
    $title = array('title' => htmlspecialchars($title), 'mode' => 'escaped', 'type' => 'text/html');
    $content = array('content' => htmlspecialchars($content), 'mode' => 'escaped', 'type' => 'text/html');
    // Create Auth Object
    if ($config['plugins'][$_SESSION['plugin']]['type'] == 'blogger') {
        require_once dirname(__FILE__) . '/class.basicauth.php';
        $auth = new BasicAuth($config['plugins'][$_SESSION['plugin']]['username'], $config['plugins'][$_SESSION['plugin']]['password']);
    } else {
        require_once dirname(__FILE__) . '/class.wsse.php';
        $auth = new WSSE($config['plugins'][$_SESSION['plugin']]['username'], $config['plugins'][$_SESSION['plugin']]['password']);
    }
    // Break down the identifier details into its parts
    if (preg_match('/^\\[(https?)?.*@https?.*\\]$/Ui', $_SESSION['plugin_identifier'])) {
        $at = strpos($_SESSION['plugin_identifier'], '@');
        $entry_uri = substr($_SESSION['plugin_identifier'], 1, $at - 1);
        if (trim($entry_uri) == '') {
            $entry_uri = false;
        }
        $feed_uri = substr($_SESSION['plugin_identifier'], $at + 1, -1);
    } else {
        // Couldn't figure out where to save to
        $javascript_msg = '@Couldn\'t locate the blog to save this post to.';
        return $_SESSION['filename'];
    }
    // If we're updating an existing one, we need some details
    if ($entry_uri !== false) {
        // Create the new entry and get it as XML
        $ae = new AtomEntry($title, $content);
        $ae = $ae->to_xml('PUT');
        $ar = new AtomRequest('PUT', urldecode($entry_uri), $auth, $ae);
        $response = $ar->exec();
        if ($response == 200) {
            $javascript_msg = 'Post saved successfully.';
            return;
        } else {
            $javascript_msg = '@Saving your post failed, please try again. (' . $ar->get_response() . ')';
            return;
        }
    } else {
        // Make the entry, and get it in XML (for POSTing)
        $ae = new AtomEntry($title, $content);
        $ae = $ae->to_xml('POST');
        $ar = new AtomRequest('POST', urldecode($feed_uri), $auth, $ae);
        $response = $ar->exec();
        if ($response == 200 || $response == 201) {
            // Need to get the EditURI for this new post now
            $ae = new AtomEntry();
            $ae->from_xml($ar->get_response());
            $link = $ae->get_links('rel', 'service.edit');
            $javascript_msg = 'Post saved successfully.';
            $_SESSION['plugin_identifier'] = '[' . urlencode($link[0]['href']) . '@' . $feed_uri . ']';
            return;
        } else {
            $javascript_msg = '@Saving your post failed, please try again. (' . $ar->get_response() . ')';
            return;
        }
    }
}
Example #9
0
File: Opml.php Project: hisaboh/w2t
 public function atom()
 {
     Rhaco::import("net.feed.atom.Atom");
     $atom = new Atom();
     $atom->title($this->title());
     foreach ($this->outlines() as $outline) {
         $entry = new AtomEntry();
         $entry->title($outline->title());
         $entry->published(time());
         if ($outline->isHtmlUrl()) {
             $entry->link(new AtomLink("type=html,href=" . $outline->htmlUrl()));
         }
         if ($outline->isXmlUrl()) {
             $entry->link(new AtomLink("type=xml,href=" . $outline->xmlUrl()));
         }
         $entry->content(new AtomContent("value=" . $outline->description()));
         $entry->summary(new AtomSummary("value=" . $outline->tags()));
         $atom->add($entry);
     }
     return $atom;
     /***
     			$text = text('
     						<?xml version="1.0" encoding="utf-8"?>
     						<opml version="1.0">
     						<head>
     							<title>Subscriptions</title>
     							<dateCreated>Mon, 19 May 2008 04:51:05 UTC</dateCreated>
     							<ownerName>rhaco</ownerName>
     						</head>
     						<body>
     						<outline title="Subscriptions">
     							  <outline title="スパムとか" htmlUrl="http://www.everes.net/" type="rss" xmlUrl="http://www.everes.net/blog/atom/" />
     							  <outline title="tokushimakazutaka.com" htmlUrl="http://tokushimakazutaka.com" type="rss" xmlUrl="tokushimakazutaka.com/rss" />
     							<outline title="rhaco">
     							</outline>
     							<outline title="php">
     							  <outline title="riaf-ja blog" htmlUrl="http://blog.riaf.jp/" type="rss" xmlUrl="http://blog.riaf.jp/rss" />
     							</outline>
     							<outline title="お知らせ">
     							</outline>
     						</outline>
     						</body></opml>
     					');
     
     			$feed = Opml::parse($text);
     			eq("Subscriptions",$feed->title());
     			eq("1.0",$feed->version());
     			eq(1211172665,$feed->dateCreated());
     			eq("rhaco",$feed->ownerName());
     			eq(null,$feed->ownerEmail());
     			
     			eq(1,sizeof($feed->outline()));
     			$opml = $feed->outline();
     			eq("Subscriptions",$opml[0]->title());
     	
     			eq(3,sizeof($opml[0]->xml()));
     			eq(3,sizeof($opml[0]->html()));
     
     			$atom = $feed->atom();
     			eq(true,$atom instanceof Atom);
     			eq("Subscriptions",$atom->title());
     			eq(null,$atom->subtitle());
     			eq(time(),$atom->updated());
     			eq(null,$atom->generator());
     			eq(5,sizeof($atom->entry()));
     		*/
 }
Example #10
0
 /**
  * @return void
  * @param String $xml
  * @desc Populates the variables of the AtomFeed, based on a complete XML representation of it.
  */
 function from_xml($xml)
 {
     $orig_xml = $xml;
     // Strip down the XML to just the part we want to work with
     if (preg_match('/(<feed.*)<entry/sUi', $xml, $feed_xml)) {
         $xml = $feed_xml[1];
     }
     // ATOM FEED VERSION
     if (preg_match('/<feed[^>]+version="([^"]*)"/is', $xml, $ver)) {
         $this->set_version($ver[1]);
     }
     // TITLE
     if (preg_match_all('/<title([^>]*)>(.*)<\\/title>/sUi', $xml, $title)) {
         $title_attribs = $this->extract_attribs($title[1][0]);
         $title = array('title' => $title[2][0]);
         $title = array_merge_recursive($title, $title_attribs);
         $this->set_title($title);
     }
     // TAGLINE
     if (preg_match_all('/<tagline([^>]*)>(.*)<\\/tagline>/sUi', $xml, $tagline)) {
         $tagline_attribs = $this->extract_attribs($tagline[1][0]);
         $tagline = array('tagline' => $tagline[2][0]);
         $tagline = array_merge_recursive($tagline, $tagline_attribs);
         $this->set_tagline($tagline);
     }
     // ID
     if (preg_match('/<id>([^<]*)<\\/id>/is', $xml, $id)) {
         $this->set_id($id[1]);
     }
     // INFO
     if (preg_match('/<info([^>]+)>(.*)<\\/info>/is', $xml, $info)) {
         $info_attribs = $this->extract_attribs($info[1]);
         $info = array('info' => $info[2]);
         $info = array_merge_recursive($info, $info_attribs);
         $this->set_info($info);
     }
     // MODIFIED
     if (preg_match('/<modified>([^<]*)<\\/modified>/is', $xml, $modified)) {
         $this->set_modified($modified[1]);
     }
     // GENERATOR
     if (preg_match_all('/<generator([^>]*)>(.*)<\\/generator>/sUi', $xml, $generator)) {
         $generator_attribs = $this->extract_attribs($generator[1][0]);
         $generator = array('generator' => $generator[2][0]);
         $generator = array_merge_recursive($generator, $generator_attribs);
         $this->set_generator($generator);
     }
     // LINKS
     if (preg_match_all('/<link([^>]+)>/Ui', $xml, $links)) {
         foreach ($links[1] as $link) {
             $link = $this->extract_attribs($link);
             $this->add_link($link['href'], $link['rel'], $link['title'], $link['type']);
         }
     }
     // Handle all of the entries, creating AtomEntry objects and linking them
     preg_match_all('/(<entry[^>]*>.*<\\/entry>)/sUi', $orig_xml, $entries_raw);
     if (strlen($entries_raw[0][0])) {
         foreach ($entries_raw[1] as $e => $entry) {
             $ae = new AtomEntry();
             $ae->from_xml($entry);
             if ($ae) {
                 $this->add_entry($ae);
             }
         }
     }
 }
Example #11
0
 public function setDateModified($epoch)
 {
     $this->updated = AtomEntry::setDate('updated', $epoch);
     return $this->updated;
 }
Example #12
0
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
$contents2 = dbSortedContents(array());
extract($contents2[0]);
global $blog;
//
$atom = new AtomFeed(array('xml:lang' => 'ja'));
$atom->title($blog);
$atom->link("{$_SERVER['SCRIPT_NAME']}");
$atom->link("{$_SERVER['REQUEST_URI']}", 'self');
$atom->id("{$_SERVER['SCRIPT_NAME']}/feed");
$atom->updated($moddate);
$atom->author(array('name' => 'nyankoPress'));
$cnt = 0;
foreach ($contents2 as $value) {
    extract($value);
    $entry = new AtomEntry();
    $entry->title($title);
    $entry->link("{$_SERVER['SCRIPT_NAME']}?p={$page}");
    $entry->id("{$_SERVER['SCRIPT_NAME']}/p{$page}");
    $entry->summary(mb_strimwidth(strip_tags($contents), 0, 80, '…', 'utf-8'));
    $entry->updated($moddate);
    $entry->author(array('name' => $author));
    $atom->addEntry($entry);
    $cnt++;
    if ($cnt >= 10) {
        break;
    }
}
header('Content-Type: application/atom+xml');
echo $atom->saveXml();