diff options
Diffstat (limited to 'site/app/controllers/addons_controller.php')
-rw-r--r-- | site/app/controllers/addons_controller.php | 104 |
1 files changed, 103 insertions, 1 deletions
diff --git a/site/app/controllers/addons_controller.php b/site/app/controllers/addons_controller.php index d4ace7d..28caa85 100644 --- a/site/app/controllers/addons_controller.php +++ b/site/app/controllers/addons_controller.php @@ -56,6 +56,8 @@ class AddonsController extends AppController var $securityLevel = 'low'; + var $link_sharing_services; + function beforeFilter() { // Disable ACLs because this controller is entirely public. $this->SimpleAuth->enabled = false; @@ -64,6 +66,96 @@ class AddonsController extends AppController if (array_key_exists('addons-author-addons-select', $this->params['url']) && ctype_digit($this->params['url']['addons-author-addons-select'])) { redirectWithNewLocaleAndExit(array('addon',$this->params['url']['addons-author-addons-select'])); } + + // Set of available link sharing services with associated labels and + // submission URL templates. + // @TODO: Move this to a model class when share counts are enabled in DB + $this->link_sharing_services = array( + + // see: http://digg.com/tools/integrate#3 + 'digg' => array( + 'label' => ___('addons_share_label_digg', 'Digg this!'), + 'url' => 'http://digg.com/submit?url={URL}&title={TITLE}&bodytext={DESCRIPTION}&media=news&topic=tech_news' + ), + + // see: http://www.facebook.com/share_options.php + 'facebook' => array( + 'label' => ___('addons_share_label_facebook', 'Post to Facebook'), + 'url' => 'http://www.facebook.com/share.php?u={URL}&t={TITLE}' + ), + + // see: http://delicious.com/help/savebuttons + 'delicious' => array( + 'label' => ___('addons_share_label_delicious', 'Add to Delicious'), + 'url' => 'http://delicious.com/save?url={URL}&title={TITLE}¬es={DESCRIPTION}' + ), + + // see: http://www.myspace.com/posttomyspace + 'myspace' => array( + 'label' => ___('addons_share_label_myspace', 'Post to MySpace'), + 'url' => 'http://www.myspace.com/index.cfm?fuseaction=postto&t={TITLE}&c={DESCRIPTION}&u={URL}&l=1' + ), + + // see: http://friendfeed.com/embed/link + 'friendfeed' => array( + 'label' => ___('addons_share_label_friendfeed', 'Share on FriendFeed'), + 'url' => 'http://friendfeed.com/?url={URL}&title={TITLE}' + ) + + ); + + } + + /** + * Share an addon with a link sharing service. + * @param int $id the id of the addon + */ + function share($id = null) { + global $valid_status; + + $_conditions = array( + 'Addon.id' => $id, + 'Addon.inactive' => 0, + 'Addon.addontype_id' => array( + ADDON_EXTENSION, ADDON_THEME, ADDON_DICT, + ADDON_SEARCH, ADDON_LPAPP, ADDON_PLUGIN + ), + 'Addon.status' => $valid_status + ); + $addon = $this->Addon->find($_conditions, null , null , 1); + + $service = @$this->link_sharing_services[$_GET['service']]; + + // Panic if either the addon or the sharing service is not found. + if (empty($addon) || empty($service)) { + $this->flash(_('error_addon_notfound'), '/', 3); + return; + } + + $this->publish('addon_id', $id); + + // Build a suitable link title based on the addon name, version, and + // the site title. + $title = + sprintf( + _('addons_display_pagetitle'), + $addon['Translation']['name']['string'].' '. + $addon['Version'][0]['version'] + ) . + ' :: '. + sprintf( + _('addons_home_pagetitle'), + APP_PRETTYNAME + ); + + $this->publish('share_title', $title); + + // Come up with description text from the summary + $this->publish('description', $addon['Translation']['summary']['string']); + + $this->publish('service_url', $service['url']); + + $this->layout = 'ajax'; } /** @@ -101,6 +193,16 @@ class AddonsController extends AppController return; } + // TODO: Look up the current share totals for this addon. + // $share_counts = $this->ShareCount->getTotalCountsForAddon( + // $addon_data['Addon']['id'] + // ); + // $this->set('link_sharing_counts', $share_counts); + + // Not using publish() here because this will all be app constants, + // localized strings with placeholders, or counts from the DB. + $this->set('link_sharing_services', $this->link_sharing_services); + if($loggedIn) { $isauthor = $this->Amo->checkOwnership($id, $addon_data['Addon'], true); $this->publish('isAuthor', $isauthor); @@ -119,7 +221,7 @@ class AddonsController extends AppController $_addoncriteria = array( 'Addon.id' => $_addonids, 'Addon.inactive' => 0, - 'Addon.status' => $this->status + 'Addon.status' => $valid_status ); $authorAddons = $this->Addon->findAll($_addoncriteria, null, 'Translation.name'); } else { |