RishiShreshtha

Untitled

Sep 30th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2. // hook_menu()
  3. function cdnimage_menu() {
  4.   $items['cdnimage/%'] = array(
  5.     'title' => 'Upload CDN Image',
  6.     'page callback' => 'cdnimages_upload',
  7.     'page arguments' => array(1),
  8.     'access callback' => TRUE,    
  9.     'type' => MENU_NORMAL_ITEM,
  10.   );
  11.   return $items;
  12. }
  13.  
  14. //
  15. function cdnimages_upload($product_id) {
  16.  
  17.   if (is_numeric($product_id)) {
  18.  
  19.     $toggle = db_query('SELECT field_product_type_value
  20.      FROM field_data_field_product_type
  21.      WHERE entity_id=:entity_id', array(':entity_id' => $product_id))->fetchField();
  22.      
  23.       $result = db_query('SELECT it.delta, fm.uri, lms.field_lms_id_value AS lms_id
  24.        FROM file_managed fm
  25.        INNER JOIN field_data_field_product_images pi ON pi.field_product_images_fid = fm.fid
  26.        INNER JOIN field_data_field_product_images_with_tags it ON it.field_product_images_with_tags_value = pi.entity_id
  27.        INNER JOIN field_data_field_lms_id lms ON lms.entity_id = it.entity_id
  28.        WHERE it.entity_id = :entity_id', array(':entity_id' => $product_id));
  29.      
  30.       $rows = $result->fetchAll();
  31.      
  32.       $image_styles = array(
  33.         '240' => '240w_240h',
  34.         '50' => '50w_50h',
  35.         '110' => '110w_110h',
  36.         '320' => '320w_320h',
  37.         '480' => '480w_480h',
  38.         '800' => '800w_800h',
  39.         );
  40.      
  41.       $display_style = array();
  42.      
  43.       foreach($image_styles as $key => $value) {
  44.         $display_style[$key] = image_style_load($value);
  45.       }
  46.      
  47.       foreach($rows as $row) {
  48.         $string_lower = explode(".", strtolower($row->uri));
  49.         $ext = end($string_lower);
  50.         print $row->uri;
  51.        
  52.         foreach($image_styles as $key => $value) {
  53.           $destination = "rcf:///".$row->lms_id."_".$row->delta."-".$key.".".$ext;
  54.           print "$destination --- $value <br>";
  55.           image_style_create_derivative($display_style[$key], $row->uri, $destination);
  56.         }
  57.        
  58.         print "<br><br>";
  59.       }
  60.    
  61.     return;
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment