Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 4b3dd160dcd0ecbd1a5c852593122aeaea49a220 Brandon Calloway committed Jul 27, 2010
Showing with 1,990 additions and 0 deletions.
  1. +20 −0 LICENSE
  2. +34 −0 README.textile
  3. +120 −0 Rakefile
  4. +41 −0 app/controllers/flickr_gallery_controller.rb
  5. +33 −0 app/controllers/flickr_pages_controller.rb
  6. +109 −0 app/helpers/flickr_pages_helper.rb
  7. +4 −0 app/models/flickr_page.rb
  8. +5 −0 app/views/flickr_pages/_photos.html.haml
  9. +12 −0 app/views/flickr_pages/index.html.haml
  10. +2 −0 config/routes.rb
  11. +13 −0 flickr_pages_extension.rb
  12. +28 −0 lib/tasks/flickr_pages_extension_tasks.rake
  13. BIN public/images/spinner.gif
  14. +72 −0 public/javascripts/fancybox/jquery.easing-1.3.pack.js
  15. +1,077 −0 public/javascripts/fancybox/jquery.fancybox-1.3.1.js
  16. +44 −0 public/javascripts/fancybox/jquery.fancybox-1.3.1.pack.js
  17. +13 −0 public/javascripts/fancybox/jquery.mousewheel-3.0.2.pack.js
  18. BIN public/stylesheets/fancybox/blank.gif
  19. BIN public/stylesheets/fancybox/fancy_close.png
  20. BIN public/stylesheets/fancybox/fancy_loading.png
  21. BIN public/stylesheets/fancybox/fancy_nav_left.png
  22. BIN public/stylesheets/fancybox/fancy_nav_right.png
  23. BIN public/stylesheets/fancybox/fancy_shadow_e.png
  24. BIN public/stylesheets/fancybox/fancy_shadow_n.png
  25. BIN public/stylesheets/fancybox/fancy_shadow_ne.png
  26. BIN public/stylesheets/fancybox/fancy_shadow_nw.png
  27. BIN public/stylesheets/fancybox/fancy_shadow_s.png
  28. BIN public/stylesheets/fancybox/fancy_shadow_se.png
  29. BIN public/stylesheets/fancybox/fancy_shadow_sw.png
  30. BIN public/stylesheets/fancybox/fancy_shadow_w.png
  31. BIN public/stylesheets/fancybox/fancy_title_left.png
  32. BIN public/stylesheets/fancybox/fancy_title_main.png
  33. BIN public/stylesheets/fancybox/fancy_title_over.png
  34. BIN public/stylesheets/fancybox/fancy_title_right.png
  35. BIN public/stylesheets/fancybox/fancybox-x.png
  36. BIN public/stylesheets/fancybox/fancybox-y.png
  37. BIN public/stylesheets/fancybox/fancybox.png
  38. +363 −0 public/stylesheets/fancybox/jquery.fancybox-1.3.1.css
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Scully Group
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
+h1. Spree Flickr Photos Extension
+
+A quick-and-dirty extension that allows you to add paginated Flickr Galleries to a Spree store.
+
+
+h2. Requirements
+
+<p>*Gems*<br />
+Flickr_fu, "http://github.com/commonthread/flickr_fu":http://github.com/commonthread/flickr_fu<br/>
+Will_Paginate, "http://wiki.github.com/mislav/will_paginate":http://wiki.github.com/mislav/will_paginate</p>
+
+h1. How to Install
+
+Place the flickr_pages_ extension in vendor/extensions
+<pre><code>
+ git://github.com/bcalloway/spree-flickr-pages.git vender/extensions/flickr_pages
+</code></pre>
+
+
+h2. How to Use
+
+As per the flickr_fu instructions, place a file called flickr.yml in the config directory that contains the following information:
+<pre><code>
+ key: abc123abc123abc123abc123abc123abc123abc123abc123abc #your api key
+ secret: abc123abc123abc #your secret key
+</code></pre>
+
+In order to pull the desired photos from your Flickr account, route to this uri:<code>/photos</code>
+
+In order to show a gallery of tagged photos, route to this uri: <code>/photos/:tag</code> where the tag param is the tag you with to show.
+
+You can also use setnames instead of tags if you wish. Just look through the code and you'll see how to accomplish this.
+
+Copyright (c) 2010 Brandon Calloway, released under the MIT License
120 Rakefile
@@ -0,0 +1,120 @@
+# I think this is the one that should be moved to the extension Rakefile template
+
+# In rails 1.2, plugins aren't available in the path until they're loaded.
+# Check to see if the rspec plugin is installed first and require
+# it if it is. If not, use the gem version.
+
+# Determine where the RSpec plugin is by loading the boot
+unless defined? RADIANT_ROOT
+ ENV["RAILS_ENV"] = "test"
+ case
+ when ENV["RADIANT_ENV_FILE"]
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
+ else
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
+ end
+end
+
+require 'rake'
+require 'rake/rdoctask'
+require 'rake/testtask'
+
+rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
+$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
+require 'spec/rake/spectask'
+# require 'spec/translator'
+
+# Cleanup the RADIANT_ROOT constant so specs will load the environment
+Object.send(:remove_const, :RADIANT_ROOT)
+
+extension_root = File.expand_path(File.dirname(__FILE__))
+
+task :default => :spec
+task :stats => "spec:statsetup"
+
+desc "Run all specs in spec directory"
+Spec::Rake::SpecTask.new(:spec) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+namespace :spec do
+ desc "Run all specs in spec directory with RCov"
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.rcov = true
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
+ end
+
+ desc "Print Specdoc for all specs"
+ Spec::Rake::SpecTask.new(:doc) do |t|
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ end
+
+ [:models, :controllers, :views, :helpers].each do |sub|
+ desc "Run the specs under spec/#{sub}"
+ Spec::Rake::SpecTask.new(sub) do |t|
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
+ end
+ end
+
+ # Hopefully no one has written their extensions in pre-0.9 style
+ # desc "Translate specs from pre-0.9 to 0.9 style"
+ # task :translate do
+ # translator = ::Spec::Translator.new
+ # dir = RAILS_ROOT + '/spec'
+ # translator.translate(dir, dir)
+ # end
+
+ # Setup specs for stats
+ task :statsetup do
+ require 'code_statistics'
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
+ ::CodeStatistics::TEST_TYPES << "Model specs"
+ ::CodeStatistics::TEST_TYPES << "View specs"
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
+ end
+
+ namespace :db do
+ namespace :fixtures do
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
+ task :load => :environment do
+ require 'active_record/fixtures'
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
+ end
+ end
+ end
+ end
+end
+
+desc 'Generate documentation for the testimonial extension.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'TestimonialExtension'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+# For extensions that are in transition
+desc 'Test the testimonial extension.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+# Load any custom rakefiles for extension
+Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,41 @@
+class FlickrGalleryController < Spree::BaseController
+
+ require 'open-uri'
+ require 'nokogiri'
+
+ before_filter :protect_from_forgery, :except => [:index]
+
+ def index
+
+ config = YAML.load_file("config/flickr.yml")
+ @api_key = config['key']
+ @user = config['user']
+
+ # setid = ""
+
+ if !params[:setid]
+ sets = Nokogiri::XML(open("http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=#{@api_key}&user_id=#{@user}"))
+ first_photoset = sets.xpath("/rsp/photosets/photoset").first
+
+ setid = first_photoset['id']
+ else
+ setid = params[:setid]
+ end
+
+ @photoset_photos = Nokogiri::XML(open("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=#{@api_key}&photoset_id=#{setid}"))
+ @photos = []
+
+ @photoset_photos.xpath("/rsp/photoset/photo").each do |photo|
+ @photos.push(photo)
+ end
+
+ @results = @photos.paginate(:page => params[:page], :per_page => 1)
+
+ respond_to do |format|
+ format.html
+ format.js { render :partial => 'photos' }
+ end
+ end
+
+
+end
@@ -0,0 +1,33 @@
+class FlickrPagesController < Spree::BaseController
+
+ require 'flickr_fu'
+
+ before_filter :protect_from_forgery, :except => [:index, :gallery]
+
+ def flickr_connect(tag)
+ @flickr = Flickr.new('config/flickr.yml')
+ config = YAML.load_file("config/flickr.yml")
+ @user = config['user']
+
+ @photos = @flickr.photos.search(:user_id => "#{@user}", :tags => "#{tag}")
+ @results = @photos.paginate(:page => params[:page], :per_page => 16)
+ end
+
+ def index
+ self.flickr_connect("favorites")
+
+ respond_to do |format|
+ format.html
+ end
+ end
+
+ def gallery
+ params[:tag] = "favorites" if !params[:tag]
+ self.flickr_connect("#{params[:tag]}")
+
+ respond_to do |format|
+ format.html { render :template => '/flickr_pages/index.html.haml' }
+ end
+ end
+
+end
@@ -0,0 +1,109 @@
+module FlickrPagesHelper
+
+ require 'open-uri'
+ require 'nokogiri'
+
+ # Pull all photosets for the user
+ def get_photosets
+ config = YAML.load_file("config/flickr.yml")
+ @api_key = config['key']
+ @user = config['user']
+
+ @doc = Nokogiri::XML(open("http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=#{@api_key}&user_id=#{@user}"))
+
+ first = true
+ flickr_photosets = []
+
+ @doc.xpath("/rsp/photosets/photoset").each do |node|
+ title = node.children
+
+ # get the first photo in the set for the primary photo
+ @photoset_photos = Nokogiri::XML(open("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=#{@api_key}&photoset_id=#{node['id']}&per_page=1"))
+ first_photo = @photoset_photos.xpath("/rsp/photoset/photo").first
+
+ # now take that id and find me the actual photo
+ @set_photo = Nokogiri::XML(open("http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=#{@api_key}&photo_id=#{first_photo['id']}"))
+
+ set_photo = ""
+
+ @set_photo.xpath("/rsp/sizes/size").each do |size|
+ if size['label'] == "Square"
+ set_photo = size['source']
+ end
+ end
+
+ a_class = ""
+
+ if !params[:setid] && first
+ a_class = "current"
+ elsif params[:setid] == node['id']
+ a_class = "current"
+ end
+
+ flickr_photosets.push("<a class=\"#{a_class}\" href=\"/photogallery/#{node['id']}\"><img src=\"#{set_photo}\" /><br /><span class=\"title\">#{title.text}</span></a>")
+
+ # its not the first run through
+ first = false
+ end
+
+ return flickr_photosets
+ end
+
+ def get_photo(photo_id, photo_size)
+ config = YAML.load_file("config/flickr.yml")
+ api_key = config['key']
+
+ photoset_photo = Nokogiri::XML(open("http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=#{api_key}&photo_id=#{photo_id}"))
+
+ set_photo = ""
+
+ photoset_photo.xpath("/rsp/sizes/size").each do |size|
+ if size['label'] == photo_size
+ set_photo = size['source']
+ end
+ end
+
+ return set_photo
+
+ end
+
+ def get_setname
+ config = YAML.load_file("config/flickr.yml")
+ api_key = config['key']
+ user = config['user']
+
+ if !params[:setid]
+ sets = Nokogiri::XML(open("http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=#{api_key}&user_id=#{user}"))
+ first_photoset = sets.xpath("/rsp/photosets/photoset").first
+
+ setid = first_photoset['id']
+ else
+ setid = params[:setid]
+ end
+
+ setinfo = Nokogiri::XML(open("http://api.flickr.com/services/rest/?method=flickr.photosets.getInfo&api_key=#{api_key}&photoset_id=#{setid}"))
+ set_title = setinfo.xpath("/rsp/photoset/title").first
+
+ return set_title.text
+ end
+
+ # Pull all tags for the user
+ def get_tags
+ config = YAML.load_file("config/flickr.yml")
+ @api_key = config['key']
+ @user = config['user']
+
+ @doc = Nokogiri::XML(open("http://api.flickr.com/services/rest/?method=flickr.tags.getListUser&api_key=#{@api_key}&user_id=#{@user}"))
+
+ flickr_tags =[]
+
+ @doc.xpath("/rsp/who/tags/tag").each do |node|
+ if !node.text.match(/\d+/).nil?
+ flickr_tags.push("<li id=\"#{node.text}\"><a href=\"/photos/#{node.text}\">#{node.text}</a></li>")
+ end
+ end
+
+ return flickr_tags
+ end
+
+end
@@ -0,0 +1,4 @@
+class FlickrPage < ActiveRecord::Base
+
+end
+
@@ -0,0 +1,5 @@
+%ul
+ - for photo in @results
+ %li
+ %a{ :href => "#{photo.url(:medium)}", :rel => "brewgrass", :class => "group" }
+ = image_tag photo.url(:square)
@@ -0,0 +1,12 @@
+%h1
+ = "#{params[:tag]}" if params[:tag]
+ Photo Gallery
+
+%ul#photosets
+ /= get_photosets
+ = get_tags
+
+#photos
+ = render 'photos'
+
+= will_paginate @results
@@ -0,0 +1,2 @@
+map.connect '/photos', :controller => 'flickr_pages', :action => 'index'
+map.connect '/photos/:tag', :controller => 'flickr_pages', :action => 'gallery'
Oops, something went wrong.

0 comments on commit 4b3dd16

Please sign in to comment.