First of all, this is a great module. Very simple to implement in a custom mod. Thanks!

I think a nice feature would be the ability to define multiple mirrors per module.

for example:

I have a custom module that outputs urls for several seperate function calls.
I would like to be able to assign a different mirror (or turn off cdn completely) in the admin, for these individual elements.

if you were able to define these elements by returning an array of arrays in hook_simplecdnapi()
Something like:

/**
* Implementation of hook_simplecdnapi().
*/
function mymodule_simplecdnapi($op) {
  switch ($op) {
    case 'load':
      $data[] = array(
        'eid' => 'mymodule_some_element',
        'name' => 'My Module: Element 1',
      );
     $data[] = array(
        'eid' => 'mymodule_some_other_element',
        'name' => 'My Module: Element 2',
      );
      return $data;
      break;
  }
}

and then invoke it with:


if (module_exists('simplecdn')) {
   $url = simplecdn_rewrite_url($url, 'mymodule_some_element');
}
if (module_exists('simplecdn')) {
   $url = simplecdn_rewrite_url($url, 'mymodule_some_other_element');
}


from within the same module wherever appropriate.

I guess i could make a separate plugin module for each case, but that seems excessive, no?

thoughts?

thanks again!

CommentFileSizeAuthor
#1 simplecdn_642686_enhanced-api.patch750 bytesrecrit

Comments

recrit’s picture

Status: Active » Needs review
StatusFileSize
new750 bytes

The attach patch has worked well for me and does exactly what you have described. The simplecdn_invoke_simplecdnapi will handle returns from modules implementing simplecdnapi as follows:

  1. Original:
            array(
              'eid' => 'some_element',
              'name' => 'some element name',
            )
    
  2. Multiple:
    array(
            array(
              'eid' => 'some_element_1',
              'name' => 'Some element 1 name',
            ),
            array(
              'eid' => 'some_element_2',
              'name' => 'Some element 2 name',
            ),
    )
    

The 2nd option above allows you to put all of your elements in one module which enables reuse of hooks for preprocessing, etc.