Download & Extend

Allow multiple mirrors per module

Project:Simple CDN
Version:6.x-1.1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

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:

<?php
/**
* 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:

<?php
if (module_exists('simplecdn')) {
  
$url = simplecdn_rewrite_url($url, 'mymodule_some_element');
}
?>

<?php
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!

Comments

#1

Status:active» needs review

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:
    <?php
           
    array(
             
    'eid' => 'some_element',
             
    'name' => 'some element name',
            )
    ?>
  2. Multiple:
    <?php
    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.

AttachmentSize
simplecdn_642686_enhanced-api.patch 750 bytes
nobody click here