Permalink
Browse files

Added a new plugin for Skitch

  • Loading branch information...
1 parent 84ff6f1 commit cf32d13c79e08c0ac830b7b818a1c917b89b26e6 segphault committed May 29, 2011
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,97 @@
+<?php
+/*
+ * Copyright 2008-2009 Laurent Eschenauer and Alard Weisscher
+ * and Ryan Paul
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+class SkitchItem extends SourceItem implements ImageItem {
+
+ protected $_prefix = 'skitch';
+
+ protected $_preamble = 'Took the screenshot: ';
+
+ public function getType() {
+ return SourceItem::IMAGE_TYPE;
+ }
+
+ public function getTitle() {
+ return $this->_data['title'];
+ }
+
+ public function setTitle($title) {
+ $db = Zend_Registry::get('database');
+ $sql = "UPDATE `skitch_data` SET `title`=:title "
+ . "WHERE source_id = :source_id AND id = :item_id ";
+ $data = array("source_id" => $this->getSource(),
+ "item_id" => $this->getID(),
+ "title" => $title);
+
+ return $db->query($sql, $data);
+ }
+
+ public function getDescription() {
+ return $this->_data['description'];
+ }
+
+ public function setDescription($description) {
+ $db = Zend_Registry::get('database');
+ $sql = "UPDATE `skitch_data` SET `description`=:description"
+ . "WHERE source_id = :source_id AND id = :item_id ";
+ $data = array("source_id" => $this->getSource(),
+ "item_id" => $this->getID(),
+ "description" => $description);
+
+ return $db->query($sql, $data);
+ }
+
+ public function getLink() {
+ return $this->_data['link'];
+ }
+
+ public function setLink($link) {
+ $db = Zend_Registry::get('database');
+ $sql = "UPDATE `skitch_data` SET `link`=:link "
+ . "WHERE source_id = :source_id AND id = :item_id ";
+ $data = array("source_id" => $this->getSource(),
+ "item_id" => $this->getID(),
+ "link" => $link);
+
+ return $db->query($sql, $data);
+ }
+
+ public function getImageUrl() {
+ return $this->_data['href'];
+ }
+
+ public function getThumbnailUrl() {
+ return $this->_data['image'];
+ }
+
+ public function getRssContent() {
+ $url = $this->_data['url'];
+ $link = $this->getLink();
+ $title = $this->_data['title'];
+ $html = "<a href='$link'><img src='$url' alt='$title'></a>";
+ return $html;
+ }
+
+ public function getBackup() {
+ $item = array();
+ $item['Link'] = $this->getLink();
+ $item['Description'] = $this->_data['description'];
+ $item['Date'] = $this->_data['created_at'];
+ return $item;
+ }
+}
@@ -0,0 +1,97 @@
+<?php
+/*
+ * Copyright 2008-2009 Laurent Eschenauer, Alard Weisscher, Ryan Paul
+ * and Ryan Paul
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+class SkitchModel extends SourceModel {
+
+ protected $_name = 'skitch_data';
+
+ protected $_prefix = 'skitch';
+
+ protected $_search = 'description';
+
+ protected $_update_tweet = "Uploaded %d images to Skitch %s";
+
+ public function getServiceName() {
+ return "Skitch";
+ }
+
+ public function isStoryElement() {
+ return true;
+ }
+
+ public function getServiceURL() {
+ if ($username = $this->getProperty('username')) {
+ return "http://skitch.com/$username";
+ }
+ else {
+ return "http://skitch.com";
+ }
+ }
+
+ public function getServiceDescription() {
+ return "Skitch is a screenshot sharing service.";
+ }
+
+ public function importData() {
+ $items = $this->updateData(true);
+ $this->setImported(true);
+ return $items;
+ }
+
+ public function updateData($import=false) {
+
+ // Verify that we have the required settings
+ if (!($username = ($this->getProperty('username')))) {
+ throw new Stuffpress_Exception("Update failed, connector not properly configured");
+ }
+
+ $feed_url = "http://skitch.com/feeds/$username/atom.xml";
+
+ try {
+ $items = $feed = Zend_Feed::import($feed_url);
+ return $this->processItems($items);
+ } catch (Zend_Feed_Exception $e) {
+ return;
+ }
+
+ // Mark as updated (could have been with errors)
+ $this->markUpdated();
+ }
+
+ private function processItems($stories) {
+ $result = array();
+
+ foreach ($stories as $story) {
+ $data = array();
+
+ $data['title'] = (string) $story->title();
+ $data['link'] = (string) $story->link[0]["href"];
+ $data['created_at'] = (string) $story->published;
+ $data['image'] = (string) $story->link[1]["href"];
+ $data['thumbnail'] = (string) $story->link[2]["href"];
+ $data['href'] = (string) $story->link[1]["href"];
+ $data['description'] = (string) $story->{'media:description'};
+
+ $id = $this->addItem($data, strtotime($data['created_at']), SourceItem::IMAGE_TYPE, false, false, false, $data['title']);
+ if ($id) $result[] = $id;
+ }
+
+ return $result;
+ }
+
+}
@@ -0,0 +1,4 @@
+<div class="scrnshots">
+ <div class="description"><?= $this->item->getDescription(); ?></div>
+ <div class="content"><a href="<?= $this->item->getLink(); ?>" title="<?= $this->item->getTitle(); ?>" target="_blank"><img src="<?= $this->item->getImageURL(); ?>" /></a></div>
+</div>
@@ -0,0 +1,14 @@
+<div class="scrnshots">
+
+ <?php if ($this->item->getTitle()) : ?>
+ <div class="titlewrapper">
+ <div class="title" id="title_<?= $this->count ?>"><?= $this->item->getTitle(); ?></div>
+ </div>
+ <?php elseif (!($this->item->getTitle()) && $this->edit) : ?>
+ <div class="titlewrapper">
+ <div class="title" id="title_<?= $this->count ?>">[Click to add text]</div>
+ </div>
+ <?php endif ?>
+ <div class="content"><a href="<?= $this->item->getImageURL(); ?>" title="<?= $this->item->getTitle(); ?>" rel="lightbox[set]" ><img src="<?= $this->item->getThumbnailUrl(); ?>" /></a></div>
+
+</div>
@@ -0,0 +1,9 @@
+<div class="scrnshots">
+ <div class="title"><a href="<?= $this->item->getLink(); ?>"><?= $this->item->getTitle(); ?></a></div>
+ <div class="content"><a href="<?= $this->item->getLink(); ?>" title="<?= $this->item->getTitle(); ?>" target="_blank"><img src="<?= $this->item->getImageURL(); ?>" width="350" /></a></div>
+ <?php if ($this->item->getDescription()) : ?>
+ <div class="note">
+ <?= $this->item->getDescription(); ?>
+ </div>
+ <?php endif ?>
+</div>
@@ -0,0 +1,4 @@
+<div class="skitch">
+ <div class="description"><?= $this->item->getDescription(); ?></div>
+ <div class="content"><a href="<?= $this->item->getLink(); ?>" title="<?= $this->item->getTitle(); ?>" target="_blank"><img src="<?= $this->item->getImageURL(); ?>" /></a></div>
+</div>
@@ -0,0 +1,14 @@
+<div class="skitch">
+
+ <?php if ($this->item->getTitle()) : ?>
+ <div class="titlewrapper">
+ <div class="title" id="title_<?= $this->count ?>"><?= $this->item->getTitle(); ?></div>
+ </div>
+ <?php elseif (!($this->item->getTitle()) && $this->edit) : ?>
+ <div class="titlewrapper">
+ <div class="title" id="title_<?= $this->count ?>">[Click to add text]</div>
+ </div>
+ <?php endif ?>
+ <div class="content"><a href="<?= $this->item->getImageURL(); ?>" title="<?= $this->item->getTitle(); ?>" rel="lightbox[set]" ><img src="<?= $this->item->getThumbnailUrl(); ?>" /></a></div>
+
+</div>
@@ -0,0 +1,9 @@
+<div class="skitch">
+ <div class="title"><a href="<?= $this->item->getLink(); ?>"><?= $this->item->getTitle(); ?></a></div>
+ <div class="content"><a href="<?= $this->item->getLink(); ?>" title="<?= $this->item->getTitle(); ?>" target="_blank"><img src="<?= $this->item->getThumbnailURL(); ?>" width="350" /></a></div>
+ <?php if ($this->item->getDescription()) : ?>
+ <div class="note">
+ <?= $this->item->getDescription(); ?>
+ </div>
+ <?php endif ?>
+</div>
@@ -145,6 +145,37 @@ LOCK TABLES `scrnshots_data` WRITE;
/*!40000 ALTER TABLE `scrnshots_data` ENABLE KEYS */;
UNLOCK TABLES;
+--
+-- Table structure for table `skitch_data`
+--
+
+DROP TABLE IF EXISTS `skitch_data`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `skitch_data` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `source_id` int(10) unsigned NOT NULL,
+ `created_at` varchar(45) NOT NULL,
+ `title` text NOT NULL,
+ `description` text NOT NULL,
+ `link` varchar(256) NOT NULL,
+ `href` varchar(256) NOT NULL,
+ `thumbnail` varchar(256) NOT NULL,
+ `image` varchar(256) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `DUPLICATES` USING BTREE (`source_id`,`link`),
+ FULLTEXT KEY `SEARCH` (`description`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Dumping data for table `skitch_data`
+--
+
+LOCK TABLES `skitch_data` WRITE;
+/*!40000 ALTER TABLE `skitch_data` DISABLE KEYS */;
+/*!40000 ALTER TABLE `skitch_data` ENABLE KEYS */;
+UNLOCK TABLES;
--
-- Table structure for table `digg_data`

0 comments on commit cf32d13

Please sign in to comment.