iq_fckeditor 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +3 -0
- data/Rakefile +23 -0
- data/app/controllers/simple_fck_upload_controller.rb +24 -0
- data/app/helpers/application_helper.rb +34 -0
- data/app/views/iq_fckeditor/_fckeditor.html.erb +7 -0
- data/app/views/iq_fckeditor/custom_config.js.erb +64 -0
- data/app/views/iq_fckeditor/file_listing.xml.builder +21 -0
- data/app/views/iq_fckeditor/file_uploaded.html.erb +8 -0
- data/config/initializers/default_path.rb +1 -0
- data/iq_fckeditor.gemspec +23 -0
- data/lib/iq_fckeditor/engine.rb +5 -0
- data/lib/iq_fckeditor/version.rb +3 -0
- data/lib/iq_fckeditor.rb +243 -0
- data/tasks/iq_fckeditor_tasks.rake +4 -0
- data/test/iq_fckeditor_test.rb +9 -0
- data/test/test_helper.rb +4 -0
- metadata +91 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: c17edd0e9789c472b17295c59d4c8153c91b9d0e2eb739d49ba72d4aeefb64c7
         | 
| 4 | 
            +
              data.tar.gz: 181b60fd0991cb9f2859301d7880229259fade6c1d94d1f5c4b6896a27d0b34d
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 594e3a2730b198aeb039bd792d447e1b6732a49c3d0b8999ffc5459b0e513925c9e6133106d2fb9b45adc3f9046e83547e394b9f4840e4c4f40681e67e4f4dd9
         | 
| 7 | 
            +
              data.tar.gz: ed0a6d6b5b7d6fc22cfee6514c97efd17de382d6211fa10894f3f144f0ede44e07ccdac38c91ec933f85d44a6da2dcf4ead1c7b3e6ee3f8c468640ce6805ac1d
         | 
    
        data/LICENSE
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            MIT License
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) [year] [fullname]
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 6 | 
            +
            of this software and associated documentation files (the "Software"), to deal
         | 
| 7 | 
            +
            in the Software without restriction, including without limitation the rights
         | 
| 8 | 
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 9 | 
            +
            copies of the Software, and to permit persons to whom the Software is
         | 
| 10 | 
            +
            furnished to do so, subject to the following conditions:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            The above copyright notice and this permission notice shall be included in all
         | 
| 13 | 
            +
            copies or substantial portions of the Software.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 16 | 
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 17 | 
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 18 | 
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 19 | 
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 20 | 
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         | 
| 21 | 
            +
            SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            require 'rake'
         | 
| 2 | 
            +
            require 'rake/testtask'
         | 
| 3 | 
            +
            require 'rake/rdoctask'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            desc 'Default: run unit tests.'
         | 
| 6 | 
            +
            task :default => :test
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            desc 'Test the iq_fckeditor plugin.'
         | 
| 9 | 
            +
            Rake::TestTask.new(:test) do |t|
         | 
| 10 | 
            +
              t.libs << 'lib'
         | 
| 11 | 
            +
              t.libs << 'test'
         | 
| 12 | 
            +
              t.pattern = 'test/**/*_test.rb'
         | 
| 13 | 
            +
              t.verbose = true
         | 
| 14 | 
            +
            end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            desc 'Generate documentation for the iq_fckeditor plugin.'
         | 
| 17 | 
            +
            Rake::RDocTask.new(:rdoc) do |rdoc|
         | 
| 18 | 
            +
              rdoc.rdoc_dir = 'rdoc'
         | 
| 19 | 
            +
              rdoc.title    = 'IqFckeditor'
         | 
| 20 | 
            +
              rdoc.options << '--line-numbers' << '--inline-source'
         | 
| 21 | 
            +
              rdoc.rdoc_files.include('README')
         | 
| 22 | 
            +
              rdoc.rdoc_files.include('lib/**/*.rb')
         | 
| 23 | 
            +
            end
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            # -*- encoding : utf-8 -*-
         | 
| 2 | 
            +
            require((File.dirname(__FILE__) + "/../../lib/iq_fckeditor"))
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class SimpleFckUploadController < ActionController::Base
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              include(IqFckeditor::Controller)
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              # # You can modify where the uploads should go to and from which url they are
         | 
| 9 | 
            +
              # # accessible from the web. Paste, uncomment and modify some of the following
         | 
| 10 | 
            +
              # # lines in your environment.rb or whereever you want them to place.
         | 
| 11 | 
            +
              #
         | 
| 12 | 
            +
              # SimpleFckUploadController.fckeditor_command_action_url = fubar_url()
         | 
| 13 | 
            +
              #
         | 
| 14 | 
            +
              # # Use this plugin as File-Uploader only
         | 
| 15 | 
            +
              # SimpleFckUploadController.fckeditor_uploads_base_path = "#{RAILS_ROOT}/public/uploads"
         | 
| 16 | 
            +
              # SimpleFckUploadController.fckeditor_uploads_base_url = "http://www.example.com/uploads" # or just "/uploads"
         | 
| 17 | 
            +
              #
         | 
| 18 | 
            +
              # # If you want to use This controller as FileProvider leave
         | 
| 19 | 
            +
              # fckeditor_uploads_base_url as it is and only set the following if you don't
         | 
| 20 | 
            +
              # use map.resource for this controller (then it will determine the url
         | 
| 21 | 
            +
              # automatically).
         | 
| 22 | 
            +
              # SimpleFckUploadController.fckeditor_file_action_url = foo_bar_path()
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            # -*- encoding : utf-8 -*-
         | 
| 2 | 
            +
            module ApplicationHelper
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              # Renders a text-field for the given object and method plus a FCK integration
         | 
| 5 | 
            +
              # for this field. The parameter ''fckeditor_custom_config_url'' should contain
         | 
| 6 | 
            +
              # the url of a (static) fckcustom_config.js or the url to a
         | 
| 7 | 
            +
              # ''fckeditor_custom_config'' action, given by
         | 
| 8 | 
            +
              # ''acts_as_fckeditor_file_provider'' to use file handling over the controller.
         | 
| 9 | 
            +
              # Valid ''fck_options'' are:
         | 
| 10 | 
            +
              #   width, hight: the dimensions for the fck control
         | 
| 11 | 
            +
              #   toolbarset: name of a toolbar set used. You can specify custom toolbar
         | 
| 12 | 
            +
              #     sets in the custom_config.js.erb file under 'app/views' in this plugin.
         | 
| 13 | 
            +
              #   base_path: a custom BasePath the fck editor should use
         | 
| 14 | 
            +
              def fckeditor( object_name, method_name, fckeditor_custom_config_url, fck_options = { }, options = { })
         | 
| 15 | 
            +
                # Try to get the value to be shown
         | 
| 16 | 
            +
                obj = instance_variable_get("@#{object_name}")
         | 
| 17 | 
            +
                value = (obj && obj.send(method_name.to_sym)) || ""
         | 
| 18 | 
            +
                id = (obj && "#{object_name}_#{obj.id}_#{method_name}_editor") || "#{object_name}_0_#{method_name}_editor"
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                fck_options[:toolbarset] ||= fck_options[:toolbarSet] #Accept both styles
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                render :partial => 'iq_fckeditor/fckeditor', :locals => {
         | 
| 23 | 
            +
                  :v => "oFck#{id}", :object_name => object_name, :method_name => method_name,
         | 
| 24 | 
            +
                  :custom_config_url => fckeditor_custom_config_url,
         | 
| 25 | 
            +
                  :width => (fck_options[:width] && "'#{fck_options[:width] }'") || 'null',
         | 
| 26 | 
            +
                  :height => (fck_options[:height] && "'#{fck_options[:height] }'") || 'null',
         | 
| 27 | 
            +
                  :toolbarset => (fck_options[:toolbarset] && "'#{fck_options[:toolbarset] }'") || "'Default'",
         | 
| 28 | 
            +
                  :value => value,
         | 
| 29 | 
            +
                  :id => id,
         | 
| 30 | 
            +
                  :base_path => (fck_options[:base_path]  && "'#{fck_options[:base_path] }'") || 'null'
         | 
| 31 | 
            +
                }
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            end
         | 
| @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            <textarea id='<%= id %>' name='<%= "#{object_name}[#{method_name}]"%>'><%= h value %></textarea>
         | 
| 2 | 
            +
            <%= javascript_tag do %>
         | 
| 3 | 
            +
              var <%= v %> = new FCKeditor('<%= id %>', <%= width %>, <%= height %>, <%= toolbarset %>, '<%= escape_javascript(value) %>', <%= base_path %>);
         | 
| 4 | 
            +
              <%= v %>.BasePath = "<%= ActionController::Base::relative_url_root %>/javascripts/fckeditor/";
         | 
| 5 | 
            +
              <%= v %>.Config["CustomConfigurationsPath"] = '<%= custom_config_url %>';
         | 
| 6 | 
            +
              <%= v %>.ReplaceTextarea();
         | 
| 7 | 
            +
            <% end %>
         | 
| @@ -0,0 +1,64 @@ | |
| 1 | 
            +
            FCKConfig.LinkBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Connector=<%= @command_url %>';
         | 
| 2 | 
            +
            FCKConfig.ImageBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Type=Image&Connector=<%= @command_url %>';
         | 
| 3 | 
            +
            FCKConfig.FlashBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Type=Flash&Connector=<%= @command_url %>';
         | 
| 4 | 
            +
            FCKConfig.LinkUploadURL = '<%= @command_url %>';
         | 
| 5 | 
            +
            FCKConfig.ImageUploadURL = '<%= @command_url %>';
         | 
| 6 | 
            +
            FCKConfig.FlashUploadURL = '<%= @command_url %>';
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            // ONLY CHANGE BELOW HERE
         | 
| 9 | 
            +
            FCKConfig.Plugins.Add( 'flvPlayer', 'de' );
         | 
| 10 | 
            +
            FCKConfig.Plugins.Add( 'hopcomImageGallery' , 'en' ) ;
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/silver/';
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            FCKConfig.ToolbarSets["Simple"] = [
         | 
| 15 | 
            +
            	['Source','-','-','Templates'],
         | 
| 16 | 
            +
            	['Cut','Copy','Paste','PasteWord','-','Print','SpellCheck'],
         | 
| 17 | 
            +
            	['Undo','Redo','-','Find','Replace','-','SelectAll'],
         | 
| 18 | 
            +
            	'/',
         | 
| 19 | 
            +
            	['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
         | 
| 20 | 
            +
            	['OrderedList','UnorderedList','-','Outdent','Indent'],
         | 
| 21 | 
            +
            	['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
         | 
| 22 | 
            +
            	['Link','Unlink'],
         | 
| 23 | 
            +
            	'/',
         | 
| 24 | 
            +
            	['Image','Flash','flvPlayer','Table','Rule','Smiley'],
         | 
| 25 | 
            +
            	['FontName','FontSize'],
         | 
| 26 | 
            +
            	['TextColor','BGColor'],
         | 
| 27 | 
            +
            	['-','About']
         | 
| 28 | 
            +
            ] ;
         | 
| 29 | 
            +
            FCKConfig.ToolbarSets["Hopcom"] = [
         | 
| 30 | 
            +
            	['Source','-','Save','NewPage','-','Templates'],
         | 
| 31 | 
            +
            	['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],
         | 
| 32 | 
            +
            	['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat','FitWindow','ShowBlocks'],
         | 
| 33 | 
            +
            	'/',
         | 
| 34 | 
            +
            	['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
         | 
| 35 | 
            +
            	['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote'],
         | 
| 36 | 
            +
            	['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
         | 
| 37 | 
            +
            	['Link','Unlink','Anchor'],
         | 
| 38 | 
            +
            	['Image','Flash','flvPlayer','Table','Rule','Smiley','SpecialChar'],
         | 
| 39 | 
            +
            	['-','FontName','FontSize'],
         | 
| 40 | 
            +
            	['TextColor','BGColor']		// No comma for the last row.
         | 
| 41 | 
            +
            ] ;
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            FCKConfig.ToolbarSets["Mcontent"] = [
         | 
| 44 | 
            +
            	['Source','Save','Cut','Copy','Paste','Undo','Redo'],
         | 
| 45 | 
            +
            	['Bold','Italic','Underline','-','Subscript','Superscript'],
         | 
| 46 | 
            +
            	['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote','SpecialChar','Smiley'],
         | 
| 47 | 
            +
                '/',
         | 
| 48 | 
            +
            	['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull','-','Link','Unlink','Anchor','-','Image','Flash','flvPlayer','Table','-','FontName','FontSize','TextColor','BGColor']			// No comma for the last row.
         | 
| 49 | 
            +
            ] ;
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            FCKConfig.ToolbarSets["Sidebar"] = [
         | 
| 52 | 
            +
            	['Save','Bold','Italic','Underline','SpecialChar'],
         | 
| 53 | 
            +
            	['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull','OrderedList','UnorderedList'],
         | 
| 54 | 
            +
            	['Link','Unlink','Anchor','TextColor','BGColor'],
         | 
| 55 | 
            +
            	['Image','Flash','flvPlayer','FontSize'],
         | 
| 56 | 
            +
            	['FontName']
         | 
| 57 | 
            +
                // No comma for the last row.
         | 
| 58 | 
            +
            ] ;
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            FCKConfig.ToolbarSets["DraftBlogPost"] = [
         | 
| 61 | 
            +
            	['Source','OrderedList','UnorderedList','-','Link','Unlink','-','Image','Flash','flvPlayer','hopcomImageGallery','-','Smiley','-','Cut','Copy','Paste','PasteText','PasteWord'],
         | 
| 62 | 
            +
            	['Bold','Italic','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyFull','TextColor']
         | 
| 63 | 
            +
            ] ;
         | 
| 64 | 
            +
             | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            xml.instruct!
         | 
| 2 | 
            +
            #=> <?xml version="1.0" encoding="utf-8" ?>
         | 
| 3 | 
            +
            xml.Connector("command" => params[:Command], "resourceType" => 'File') do
         | 
| 4 | 
            +
              xml.CurrentFolder("url" => @url_to_dir, "path" => params[:CurrentFolder])
         | 
| 5 | 
            +
              if @folders
         | 
| 6 | 
            +
                xml.Folders do
         | 
| 7 | 
            +
                  @folders.each do |folder|
         | 
| 8 | 
            +
                    xml.Folder("name" => folder)
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
              if @files
         | 
| 13 | 
            +
                xml.Files do
         | 
| 14 | 
            +
                  @files.keys.sort.each do |f|
         | 
| 15 | 
            +
                    xml.File("name" => f, "size" => @files[f])
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
              xml.NewFolder(:name => @new_folder) if @new_folder
         | 
| 20 | 
            +
              xml.Error("number" => @error_number) if @error_number
         | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,8 @@ | |
| 1 | 
            +
            <%= javascript_tag do %>
         | 
| 2 | 
            +
              if (window.parent.frames['frmUpload']) {
         | 
| 3 | 
            +
                window.parent.frames['frmUpload'].OnUploadCompleted(<%= @error_number %>, '<%=  @file_name %>');
         | 
| 4 | 
            +
              }
         | 
| 5 | 
            +
              else {
         | 
| 6 | 
            +
                window.parent.OnUploadCompleted(<%= @error_number %>, '<%=  @file_url %>', '<%=  @file_name %>');
         | 
| 7 | 
            +
              }
         | 
| 8 | 
            +
            <% end %>
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            IqFckeditor.default_uploads_base_path = Rails.root.join("/data/:resource_path")
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            $:.push File.expand_path("../lib", __FILE__)
         | 
| 3 | 
            +
            require "iq_fckeditor/version"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |s|
         | 
| 6 | 
            +
              s.name        = "iq_fckeditor"
         | 
| 7 | 
            +
              s.version     = IqFckeditor::VERSION
         | 
| 8 | 
            +
              s.platform    = Gem::Platform::RUBY
         | 
| 9 | 
            +
              s.authors     = ["Till Schulte-Coerne"]
         | 
| 10 | 
            +
              s.email       = ["till.schulte-coerne@innoq.com"]
         | 
| 11 | 
            +
              s.homepage    = "http://github.com/tilsc/iq_fckeditor"
         | 
| 12 | 
            +
              s.summary     = "IqFckeditor"
         | 
| 13 | 
            +
              s.description = s.summary
         | 
| 14 | 
            +
              s.extra_rdoc_files = ['README.md', 'LICENSE']
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              s.add_development_dependency "bundler"
         | 
| 17 | 
            +
              s.add_dependency "actionpack"
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              s.files = %w(LICENSE README.md Rakefile iq_fckeditor.gemspec) + Dir.glob("{app,config,lib,tasks,test}/**/*")
         | 
| 20 | 
            +
              s.test_files = Dir.glob("{test}/**/*")
         | 
| 21 | 
            +
              s.executables = Dir.glob("{bin}/**/*")
         | 
| 22 | 
            +
              s.require_paths = ["lib"]
         | 
| 23 | 
            +
            end
         | 
    
        data/lib/iq_fckeditor.rb
    ADDED
    
    | @@ -0,0 +1,243 @@ | |
| 1 | 
            +
            require 'iq_fckeditor/version'
         | 
| 2 | 
            +
            require 'iq_fckeditor/engine'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # -*- encoding : utf-8 -*-
         | 
| 5 | 
            +
            module IqFckeditor
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              cattr_accessor :default_uploads_base_path
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              # Include as InstanceMethods into the acts_as_fckeditor_file_provider
         | 
| 10 | 
            +
              module Controller
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                extend ActiveSupport::Concern
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                #accepted MIME types for upload
         | 
| 15 | 
            +
                MIME_TYPES = [
         | 
| 16 | 
            +
                  "text/comma-separated-values",
         | 
| 17 | 
            +
                  "text/csv",
         | 
| 18 | 
            +
                  "application/vnd.ms-excel",
         | 
| 19 | 
            +
                  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
         | 
| 20 | 
            +
                  "image/jpeg",
         | 
| 21 | 
            +
                  "image/pjpeg",
         | 
| 22 | 
            +
                  "image/gif",
         | 
| 23 | 
            +
                  "image/png",
         | 
| 24 | 
            +
                  "application/pdf",
         | 
| 25 | 
            +
                  "application/zip",
         | 
| 26 | 
            +
                  "application/x-shockwave-flash",
         | 
| 27 | 
            +
                  "application/octet-stream" #TODO: Muss weg!
         | 
| 28 | 
            +
                ]
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                included do
         | 
| 31 | 
            +
                  # Some Configurtion Parameters
         | 
| 32 | 
            +
                  cattr_accessor :fckeditor_file_action_url
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  cattr_accessor :fckeditor_command_action_url
         | 
| 35 | 
            +
             | 
| 36 | 
            +
             | 
| 37 | 
            +
                  cattr_accessor :fckeditor_uploads_base_path
         | 
| 38 | 
            +
                  # This will default to IqFckeditor.default_uploads_base_path
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  cattr_accessor :fckeditor_uploads_base_url
         | 
| 41 | 
            +
                  self.fckeditor_uploads_base_url = ":fckeditor_file_action_url?file="
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  #TODO: geht das besser?
         | 
| 44 | 
            +
                  self.protect_from_forgery :except => [:fckeditor_command]
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                # Generates a config providing urls for the plugin. This is the hook to
         | 
| 48 | 
            +
                # provide different fck configs for different resources
         | 
| 49 | 
            +
                def fckeditor_custom_config
         | 
| 50 | 
            +
                  respond_to do |format|
         | 
| 51 | 
            +
                    @command_url = self.fckeditor_command_action_url || url_for_action("fckeditor_command")
         | 
| 52 | 
            +
                    format.js do
         | 
| 53 | 
            +
                      render :template => 'iq_fckeditor/custom_config', :layout => false
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                # Accessor to the uploaded files. E.g. an image will have the path:
         | 
| 59 | 
            +
                #   <controller resource path>/fckeditor_file?file=<path and filename>
         | 
| 60 | 
            +
                def fckeditor_file
         | 
| 61 | 
            +
                  if (params[:file])
         | 
| 62 | 
            +
                    dir, url_to_dir = fckeditor_base_dir_and_url
         | 
| 63 | 
            +
                    path = append_path dir, params[:file]
         | 
| 64 | 
            +
                    if FileTest.file?(path)
         | 
| 65 | 
            +
                      if (params[:thumb] =~ /^[1-9][0-9][0-9]?$/) # 10 - 999
         | 
| 66 | 
            +
                        ext = File.extname(path)
         | 
| 67 | 
            +
                        thumb_path = File.join(File.dirname(path), '.thumbs', File.basename(path, ext)) + ".#{params[:thumb]}#{ext}"
         | 
| 68 | 
            +
                        if !(FileTest.file?(thumb_path))
         | 
| 69 | 
            +
                          FileUtils.mkdir(File.dirname(thumb_path)) unless File.directory?(File.dirname(thumb_path))
         | 
| 70 | 
            +
                          tmp = Paperclip::Thumbnail.new(File.new(path), :geometry => "#{params[:thumb]}x#{params[:thumb]}>").make
         | 
| 71 | 
            +
                          FileUtils.mv(tmp.path, thumb_path)
         | 
| 72 | 
            +
                          tmp.unlink
         | 
| 73 | 
            +
                        end
         | 
| 74 | 
            +
                        path = thumb_path
         | 
| 75 | 
            +
                      end
         | 
| 76 | 
            +
                      if stale?(:last_modified => File.mtime(path).utc)
         | 
| 77 | 
            +
                        if stale?(:etag => Digest::MD5.hexdigest(File.read(path))) #Only calc checksum if :last_modified 'failes'
         | 
| 78 | 
            +
                          send_file(path, :type => Mime::Type.lookup_by_extension(File.extname(path)), :disposition => 'inline') #Finally send the file
         | 
| 79 | 
            +
                        end
         | 
| 80 | 
            +
                      end
         | 
| 81 | 
            +
                    else
         | 
| 82 | 
            +
                      head 404
         | 
| 83 | 
            +
                    end
         | 
| 84 | 
            +
                  else
         | 
| 85 | 
            +
                    head 404
         | 
| 86 | 
            +
                  end
         | 
| 87 | 
            +
                end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                # This is a resource based variant of fckeditor_command?Command=GetFoldersAndFiles
         | 
| 90 | 
            +
                def fckeditor_directory
         | 
| 91 | 
            +
                  respond_to do |format|
         | 
| 92 | 
            +
                    format.xml do
         | 
| 93 | 
            +
                      fckeditor_get_folders_and_files(true)
         | 
| 94 | 
            +
                    end
         | 
| 95 | 
            +
                  end
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                # Executes some server side commands the js client side calls:
         | 
| 99 | 
            +
                #   GetFoldersAndFiles, GetFolders (2.times{GET})
         | 
| 100 | 
            +
                #   CreateFolder (GET)
         | 
| 101 | 
            +
                #   FileUpload (POST)
         | 
| 102 | 
            +
                # These operations are addessed by parameters:
         | 
| 103 | 
            +
                #   fckeditor_command?Command=<command>
         | 
| 104 | 
            +
                # I found no way to configure this in the FCK javascriptside. Also the GETs
         | 
| 105 | 
            +
                # on modifications realy suck. If you find a way to modify this: please tell
         | 
| 106 | 
            +
                # me how you did it.
         | 
| 107 | 
            +
                def fckeditor_command
         | 
| 108 | 
            +
                  case params[:Command]
         | 
| 109 | 
            +
                  when 'GetFoldersAndFiles', 'GetFolders'
         | 
| 110 | 
            +
                    respond_to do |format|
         | 
| 111 | 
            +
                      format.xml do
         | 
| 112 | 
            +
                        fckeditor_get_folders_and_files(params[:Command] == 'GetFoldersAndFiles')
         | 
| 113 | 
            +
                      end
         | 
| 114 | 
            +
                    end
         | 
| 115 | 
            +
                  when 'CreateFolder'
         | 
| 116 | 
            +
                    respond_to do |format|
         | 
| 117 | 
            +
                      format.xml do
         | 
| 118 | 
            +
                        fckeditor_create_folder
         | 
| 119 | 
            +
                      end
         | 
| 120 | 
            +
                    end
         | 
| 121 | 
            +
                  when 'FileUpload'
         | 
| 122 | 
            +
                    respond_to do |format|
         | 
| 123 | 
            +
                      format.html do
         | 
| 124 | 
            +
                        fckeditor_upload
         | 
| 125 | 
            +
                      end
         | 
| 126 | 
            +
                    end
         | 
| 127 | 
            +
                  else
         | 
| 128 | 
            +
                    if (params[:NewFile])
         | 
| 129 | 
            +
                      fckeditor_upload
         | 
| 130 | 
            +
                    else
         | 
| 131 | 
            +
                      head 404
         | 
| 132 | 
            +
                    end
         | 
| 133 | 
            +
                  end
         | 
| 134 | 
            +
                end
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                protected
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                def url_for_action(action = nil)
         | 
| 139 | 
            +
                  path = ((ActionController::Base::relative_url_root || "") + request.path).split('/')
         | 
| 140 | 
            +
                  path.pop
         | 
| 141 | 
            +
                  path << action.to_s if action
         | 
| 142 | 
            +
                  path.join('/')
         | 
| 143 | 
            +
                end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                # This method returns the real base directory of this request and the path
         | 
| 146 | 
            +
                # for the url used by the clients later. This two strings are prefixed to
         | 
| 147 | 
            +
                # the path given by the fck javascriptside:
         | 
| 148 | 
            +
                #   <path on the server filesystem>: <base dir> + <fck path>
         | 
| 149 | 
            +
                #   <url>: http://<servername>/<base url> + <fck path>
         | 
| 150 | 
            +
                def fckeditor_base_dir_and_url
         | 
| 151 | 
            +
                  resource_path = url_for_action(nil)
         | 
| 152 | 
            +
                  dir = (self.class.fckeditor_uploads_base_path || IqFckeditor.default_uploads_base_path).gsub(/:resource_path/, resource_path)
         | 
| 153 | 
            +
                  FileUtils.mkdir_p(dir)
         | 
| 154 | 
            +
                  url = self.class.fckeditor_uploads_base_url.gsub(/:resource_path/, resource_path).gsub(/:fckeditor_file_action_url/, self.class.fckeditor_file_action_url || url_for_action("fckeditor_file"))
         | 
| 155 | 
            +
                  return [dir, url]
         | 
| 156 | 
            +
                end
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                # Appends a path to a given base directory and verifies that the result is
         | 
| 159 | 
            +
                # in the base path (think about ''../bla'').
         | 
| 160 | 
            +
                def append_path base_dir, path
         | 
| 161 | 
            +
                  res = File.expand_path(File.join(base_dir, path)).to_s
         | 
| 162 | 
            +
                  if res.index(File.expand_path(base_dir).to_s) == 0 # ok
         | 
| 163 | 
            +
                    res
         | 
| 164 | 
            +
                  else
         | 
| 165 | 
            +
                    File.expand_path(base_dir + path)
         | 
| 166 | 
            +
                  end
         | 
| 167 | 
            +
                end
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                # This renders a XML file for the FCK client providing the folders (and
         | 
| 170 | 
            +
                # files) in the directory given by 'CurrentFolder'.
         | 
| 171 | 
            +
                def fckeditor_get_folders_and_files(include_files = true)
         | 
| 172 | 
            +
                  @folders = []
         | 
| 173 | 
            +
                  @files = {}
         | 
| 174 | 
            +
                  dir, @url_to_dir = fckeditor_base_dir_and_url
         | 
| 175 | 
            +
                  @current_folder = params[:CurrentFolder] || '/'
         | 
| 176 | 
            +
                  @url_to_dir += @current_folder # Complete URL path to this directory
         | 
| 177 | 
            +
                  dir = append_path(dir, @current_folder) + "/" #Complete 'local' path to this directory
         | 
| 178 | 
            +
                  Dir.entries(dir).each do |entry|
         | 
| 179 | 
            +
                    next if entry =~ /^\./
         | 
| 180 | 
            +
                    path = dir + entry
         | 
| 181 | 
            +
                    if FileTest.directory?(path)
         | 
| 182 | 
            +
                      @folders.push entry
         | 
| 183 | 
            +
                    elsif (include_files and FileTest.file?(path))
         | 
| 184 | 
            +
                      @files[entry] = (File.size(path) / 1024)
         | 
| 185 | 
            +
                    end
         | 
| 186 | 
            +
                  end
         | 
| 187 | 
            +
                  render :template => 'iq_fckeditor/file_listing.xml', :layout => false
         | 
| 188 | 
            +
                end
         | 
| 189 | 
            +
             | 
| 190 | 
            +
                # Creates a folder given by 'NewFolderName' under 'CurrentFolder' and
         | 
| 191 | 
            +
                # returns a XML to the FCK client.
         | 
| 192 | 
            +
                def fckeditor_create_folder
         | 
| 193 | 
            +
                  begin
         | 
| 194 | 
            +
                    dir, @url_to_dir = fckeditor_base_dir_and_url
         | 
| 195 | 
            +
                    dir = append_path(dir, params[:CurrentFolder]) + "/"
         | 
| 196 | 
            +
                    @current_folder = params[:CurrentFolder] + params[:NewFolderName]
         | 
| 197 | 
            +
                    new_path = dir + params[:NewFolderName]
         | 
| 198 | 
            +
                    if !(File.stat(dir).writable?)
         | 
| 199 | 
            +
                      @error_number = 103
         | 
| 200 | 
            +
                      #elsif params[:CurrentFolder] !~ /[\w\d\s]+/
         | 
| 201 | 
            +
                      #  @errorNumber = 102
         | 
| 202 | 
            +
                    elsif FileTest.exists?(new_path)
         | 
| 203 | 
            +
                      @error_number = 101
         | 
| 204 | 
            +
                    else
         | 
| 205 | 
            +
                      Dir.mkdir(new_path, 0775)
         | 
| 206 | 
            +
                      @new_folder = params[:NewFolderName]
         | 
| 207 | 
            +
                      @error_number = 0
         | 
| 208 | 
            +
                    end
         | 
| 209 | 
            +
                  rescue => e
         | 
| 210 | 
            +
                    logger.error(e)
         | 
| 211 | 
            +
                    @error_number = 110 if @error_number.nil?
         | 
| 212 | 
            +
                  end
         | 
| 213 | 
            +
                  render :template => 'iq_fckeditor/file_listing.xml', :layout => false
         | 
| 214 | 
            +
                end
         | 
| 215 | 
            +
             | 
| 216 | 
            +
                # Moves an uploaded file to it's final destination on the server and returns
         | 
| 217 | 
            +
                # a javascript encapsulated into HTML to fck client.
         | 
| 218 | 
            +
                def fckeditor_upload
         | 
| 219 | 
            +
                  begin
         | 
| 220 | 
            +
                    ftype = params[:NewFile].content_type.strip
         | 
| 221 | 
            +
                    if ! MIME_TYPES.include?(ftype)
         | 
| 222 | 
            +
                      @error_number = 202
         | 
| 223 | 
            +
                      raise "#{ftype} is invalid MIME type"
         | 
| 224 | 
            +
                    else
         | 
| 225 | 
            +
                      dir, url_to_dir = fckeditor_base_dir_and_url
         | 
| 226 | 
            +
                      dir = append_path(dir, (params[:CurrentFolder] ? params[:CurrentFolder] : "/")) + "/"
         | 
| 227 | 
            +
                      @file_name = params[:NewFile].original_filename
         | 
| 228 | 
            +
                      full_file_name = dir + @file_name
         | 
| 229 | 
            +
                      @file_url = url_to_dir + (params[:CurrentFolder] ? params[:CurrentFolder] : "/") + @file_name
         | 
| 230 | 
            +
                      File.open(full_file_name,"wb",0664) do |fp|
         | 
| 231 | 
            +
                        FileUtils.copy_stream(params[:NewFile], fp)
         | 
| 232 | 
            +
                      end
         | 
| 233 | 
            +
                      @error_number = 0
         | 
| 234 | 
            +
                    end
         | 
| 235 | 
            +
                  rescue => e
         | 
| 236 | 
            +
                    logger.error(e)
         | 
| 237 | 
            +
                    @error_number = 110 if @error_number.nil?
         | 
| 238 | 
            +
                  end
         | 
| 239 | 
            +
                  render :template => 'iq_fckeditor/file_uploaded.html', :layout => false
         | 
| 240 | 
            +
                end
         | 
| 241 | 
            +
             | 
| 242 | 
            +
              end
         | 
| 243 | 
            +
            end
         | 
    
        data/test/test_helper.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | @@ -0,0 +1,91 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: iq_fckeditor
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.4
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Till Schulte-Coerne
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2023-07-18 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bundler
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '0'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ">="
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: actionpack
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            description: IqFckeditor
         | 
| 42 | 
            +
            email:
         | 
| 43 | 
            +
            - till.schulte-coerne@innoq.com
         | 
| 44 | 
            +
            executables: []
         | 
| 45 | 
            +
            extensions: []
         | 
| 46 | 
            +
            extra_rdoc_files:
         | 
| 47 | 
            +
            - README.md
         | 
| 48 | 
            +
            - LICENSE
         | 
| 49 | 
            +
            files:
         | 
| 50 | 
            +
            - LICENSE
         | 
| 51 | 
            +
            - README.md
         | 
| 52 | 
            +
            - Rakefile
         | 
| 53 | 
            +
            - app/controllers/simple_fck_upload_controller.rb
         | 
| 54 | 
            +
            - app/helpers/application_helper.rb
         | 
| 55 | 
            +
            - app/views/iq_fckeditor/_fckeditor.html.erb
         | 
| 56 | 
            +
            - app/views/iq_fckeditor/custom_config.js.erb
         | 
| 57 | 
            +
            - app/views/iq_fckeditor/file_listing.xml.builder
         | 
| 58 | 
            +
            - app/views/iq_fckeditor/file_uploaded.html.erb
         | 
| 59 | 
            +
            - config/initializers/default_path.rb
         | 
| 60 | 
            +
            - iq_fckeditor.gemspec
         | 
| 61 | 
            +
            - lib/iq_fckeditor.rb
         | 
| 62 | 
            +
            - lib/iq_fckeditor/engine.rb
         | 
| 63 | 
            +
            - lib/iq_fckeditor/version.rb
         | 
| 64 | 
            +
            - tasks/iq_fckeditor_tasks.rake
         | 
| 65 | 
            +
            - test/iq_fckeditor_test.rb
         | 
| 66 | 
            +
            - test/test_helper.rb
         | 
| 67 | 
            +
            homepage: http://github.com/tilsc/iq_fckeditor
         | 
| 68 | 
            +
            licenses: []
         | 
| 69 | 
            +
            metadata: {}
         | 
| 70 | 
            +
            post_install_message: 
         | 
| 71 | 
            +
            rdoc_options: []
         | 
| 72 | 
            +
            require_paths:
         | 
| 73 | 
            +
            - lib
         | 
| 74 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 75 | 
            +
              requirements:
         | 
| 76 | 
            +
              - - ">="
         | 
| 77 | 
            +
                - !ruby/object:Gem::Version
         | 
| 78 | 
            +
                  version: '0'
         | 
| 79 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 80 | 
            +
              requirements:
         | 
| 81 | 
            +
              - - ">="
         | 
| 82 | 
            +
                - !ruby/object:Gem::Version
         | 
| 83 | 
            +
                  version: '0'
         | 
| 84 | 
            +
            requirements: []
         | 
| 85 | 
            +
            rubygems_version: 3.2.3
         | 
| 86 | 
            +
            signing_key: 
         | 
| 87 | 
            +
            specification_version: 4
         | 
| 88 | 
            +
            summary: IqFckeditor
         | 
| 89 | 
            +
            test_files:
         | 
| 90 | 
            +
            - test/test_helper.rb
         | 
| 91 | 
            +
            - test/iq_fckeditor_test.rb
         |