Class List Method List File List

# Module: WpTimthumbs::Detectable

Included in:
  WpTimthumbs
Defined in:
  lib/common/collections/wp_timthumbs/detectable.rb

## Instance Method Summary (collapse)

- - (WpTimthumb) create_item(wp_target, path = nil) protected
- - (WpTimthumbs) passive_detection(wp_target, options = {})

  No passive detection.

- - (Array<WpTimthumb>) targets_items(wp_target, options = {}) protected
- - (Array<WpTimthumb>) targets_items_from_file(file, wp_target) protected
- - (Array<WpTimthumb>) theme_timthumbs(theme_name, wp_target) protected

## Instance Method Details

### - (`WpTimthumb`) create_item(wp_target, path = nil) (protected)

Parameters:

- wp_target (`WpTarget`)
- [ (`Hash`) —

  a customizable set of options

Returns:

- (`WpTimthumb`)

    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    # File 'lib/common/collections/wp_timthumbs/detectable.rb', line 72

    def create_item(wp_target, path = nil)
      options = {
        wp_content_dir: wp_target.wp_content_dir,
        wp_plugins_dir: wp_target.wp_plugins_dir
      }

      options.merge!(path: path) if path

      WpTimthumb.new(wp_target.uri, options)
    end

### - (`WpTimthumbs`) passive_detection(wp_target, options = {})

No passive detection

Parameters:

- wp_target (`WpTarget`)
- options (`Hash`) (defaults to: `{}`)

Returns:

- (`WpTimthumbs`)

    12
    13
    14
    # File 'lib/common/collections/wp_timthumbs/detectable.rb', line 12

    def passive_detection(wp_target, options = {})
      new
    end

### - (`Array<WpTimthumb>`) targets_items(wp_target, options = {}) (protected)

Parameters:

- wp_target (`WpTarget`)
- options (`Hash`) (defaults to: `{}`)

Options Hash (`options`):

- :file (`String`) —

  The path to the file containing the targets

- :theme_name (`String`)

Returns:

- (`Array<WpTimthumb>`)

    24
    25
    26
    27
    28
    29
    30
    31
    32
    # File 'lib/common/collections/wp_timthumbs/detectable.rb', line 24

    def targets_items(wp_target, options = {})
      targets = options[:theme_name] ? theme_timthumbs(options[:theme_name], wp_target) : []

      if options[:file]
        targets += targets_items_from_file(options[:file], wp_target)
      end

      targets.uniq { |i| i.url }
    end

### - (`Array<WpTimthumb>`) targets_items_from_file(file, wp_target) (protected)

Parameters:

- file (`String`)
- wp_target (`WpTarget`)

Returns:

- (`Array<WpTimthumb>`)

    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    # File 'lib/common/collections/wp_timthumbs/detectable.rb', line 57

    def targets_items_from_file(file, wp_target)
      targets = []

      File.open(file, 'r') do |f|
        f.readlines.collect do |path|
          targets << create_item(wp_target, path.strip)
        end
      end
      targets
    end

### - (`Array<WpTimthumb>`) theme_timthumbs(theme_name, wp_target) (protected)

Parameters:

- theme_name (`String`)
- wp_target (`WpTarget`)

Returns:

- (`Array<WpTimthumb>`)

    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    # File 'lib/common/collections/wp_timthumbs/detectable.rb', line 38

    def theme_timthumbs(theme_name, wp_target)
      targets     = []
      wp_timthumb = create_item(wp_target)

      %w{
        timthumb.php lib/timthumb.php inc/timthumb.php includes/timthumb.php
        scripts/timthumb.php tools/timthumb.php functions/timthumb.php
      }.each do |path|
        wp_timthumb.path = "$wp-content$/themes/#{theme_name}/#{path}"

        targets << wp_timthumb.dup
      end
      targets
    end