public function generateImage($object, $field, $instance, $bundle)
 {
     static $images = array();
     $min_resolution = empty($instance['settings']['min_resolution']) ? '100x100' : $instance['settings']['min_resolution'];
     $max_resolution = empty($instance['settings']['max_resolution']) ? '600x600' : $instance['settings']['max_resolution'];
     $extension = 'jpg';
     if (!isset($images[$extension][$min_resolution][$max_resolution]) || count($images[$extension][$min_resolution][$max_resolution]) <= DEVEL_GENERATE_IMAGE_MAX) {
         if ($tmp_file = drupal_tempnam('temporary://', 'imagefield_')) {
             $destination = $tmp_file . '.' . $extension;
             file_unmanaged_move($tmp_file, $destination, FILE_EXISTS_REPLACE);
             $min = explode('x', $min_resolution);
             $max = explode('x', $max_resolution);
             $max[0] = $max[0] < $min[0] ? $min[0] : $max[0];
             $max[1] = $max[1] < $min[1] ? $min[1] : $max[1];
             $width = rand((int) $min[0], (int) $max[0]);
             $height = rand((int) $min[1], (int) $max[1]);
             $gray = isset($this->settings['devel_image_provider_gray']) ? $this->settings['devel_image_provider_gray'] : NULL;
             $tags = isset($this->settings['devel_image_provider_tags']) ? $this->settings['devel_image_provider_tags'] : NULL;
             $url = "{$this->provider_base_url}/{$width}/{$height}";
             if (!empty($tags)) {
                 $url .= '/' . $tags;
             }
             $url = $gray ? $url . '/bw' : $url;
             // Generate seed value.
             $seed = isset($this->settings['devel_image_provider_seed']) ? $this->settings['devel_image_provider_seed'] : NULL;
             $rand_value = rand(0, $seed);
             $url .= '/' . $rand_value;
             $method = isset($this->settings['devel_image_provider_get_method']) ? $this->settings['devel_image_provider_get_method'] : 'file_get_contents';
             $path = devel_image_provider_get_file($url, $destination, $method);
             $source = new stdClass();
             $source->uri = $path;
             $source->uid = 1;
             // TODO: randomize? Use case specific.
             $source->filemime = 'image/jpg';
             if (!empty($instance['settings']['file_directory'])) {
                 $instance['settings']['file_directory'] = $instance['settings']['file_directory'] . '/';
             }
             $destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
             file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
             $destination = $destination_dir . basename($path);
             $file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
         } else {
             return FALSE;
         }
     } else {
         // Select one of the images we've already generated for this field.
         $file = new stdClass();
         $file->fid = array_rand($images[$extension][$min_resolution][$max_resolution]);
     }
     $object_field['fid'] = $file->fid;
     $object_field['alt'] = devel_create_greeking(4);
     $object_field['title'] = devel_create_greeking(4);
     return $object_field;
 }
 public function generateImage($object, $field, $instance, $bundle)
 {
     static $images = array();
     $min_resolution = empty($instance['settings']['min_resolution']) ? '100x100' : $instance['settings']['min_resolution'];
     $max_resolution = empty($instance['settings']['max_resolution']) ? '600x600' : $instance['settings']['max_resolution'];
     $extension = 'jpg';
     if (!isset($images[$extension][$min_resolution][$max_resolution]) || count($images[$extension][$min_resolution][$max_resolution]) <= DEVEL_GENERATE_IMAGE_MAX) {
         if ($tmp_file = drupal_tempnam('temporary://', 'imagefield_')) {
             $destination = $tmp_file . '.' . $extension;
             file_unmanaged_move($tmp_file, $destination, FILE_CREATE_DIRECTORY);
             $min = explode('x', $min_resolution);
             $max = explode('x', $max_resolution);
             $max[0] = $max[0] < $min[0] ? $min[0] : $max[0];
             $max[1] = $max[1] < $min[1] ? $min[1] : $max[1];
             $width = rand((int) $min[0], (int) $max[0]);
             $height = rand((int) $min[1], (int) $max[1]);
             $gray = isset($this->settings['devel_image_provider_gray']) ? $this->settings['devel_image_provider_gray'] : NULL;
             $gray_part = $gray ? '/g' : '';
             $url = "{$this->provider_base_url}" . $gray_part . "/{$width}/{$height}";
             $categories = isset($this->settings['devel_image_provider_categories']) ? $this->settings['devel_image_provider_categories'] : array();
             $category = array_rand($categories);
             if (!empty($category) && $category != 'any') {
                 $url .= '/' . $category;
             }
             $include_text = isset($this->settings['devel_image_provider_include_text']) ? $this->settings['devel_image_provider_include_text'] : FALSE;
             switch ($include_text) {
                 case 'custom':
                     $custom_text = isset($this->settings['devel_image_provider_custom_text']) ? $this->settings['devel_image_provider_custom_text'] : '';
                     break;
                 case 'random':
                     $custom_text = trim(substr(devel_create_greeking(mt_rand(1, 4)), 0, 16));
                     break;
                 case 'default':
                 default:
                     $custom_text = '';
                     break;
             }
             if (!empty($custom_text)) {
                 // Replace the spaces with - as per lorempixum specifications.
                 $custom_text = str_replace(' ', '-', check_plain($custom_text));
                 $url .= '/' . $custom_text;
             }
             $method = isset($this->settings['devel_image_provider_get_method']) ? $this->settings['devel_image_provider_get_method'] : 'file_get_contents';
             $path = devel_image_provider_get_file($url, $destination, $method);
             $source = new stdClass();
             $source->uri = $path;
             $source->uid = 1;
             // TODO: randomize? Use case specific.
             $source->filemime = 'image/jpg';
             if (!empty($instance['settings']['file_directory'])) {
                 $instance['settings']['file_directory'] = $instance['settings']['file_directory'] . '/';
             }
             $destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
             file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
             $destination = $destination_dir . basename($path);
             $file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
         } else {
             return FALSE;
         }
     } else {
         // Select one of the images we've already generated for this field.
         $file = new stdClass();
         $file->fid = array_rand($images[$extension][$min_resolution][$max_resolution]);
     }
     $object_field['fid'] = $file->fid;
     $object_field['alt'] = devel_create_greeking(4);
     $object_field['title'] = devel_create_greeking(4);
     return $object_field;
 }
 public function generateImage($object, $field, $instance, $bundle)
 {
     static $images = array();
     $min_resolution = empty($instance['settings']['min_resolution']) ? '100x100' : $instance['settings']['min_resolution'];
     $max_resolution = empty($instance['settings']['max_resolution']) ? '600x600' : $instance['settings']['max_resolution'];
     $extension = 'jpg';
     if (!isset($images[$extension][$min_resolution][$max_resolution]) || count($images[$extension][$min_resolution][$max_resolution]) <= DEVEL_GENERATE_IMAGE_MAX) {
         if ($tmp_file = drupal_tempnam('temporary://', 'imagefield_')) {
             $destination = $tmp_file . '.' . $extension;
             file_unmanaged_move($tmp_file, $destination, FILE_CREATE_DIRECTORY);
             $min = explode('x', $min_resolution);
             $max = explode('x', $max_resolution);
             $max[0] = $max[0] < $min[0] ? $min[0] : $max[0];
             $max[1] = $max[1] < $min[1] ? $min[1] : $max[1];
             $width = rand((int) $min[0], (int) $max[0]);
             $height = rand((int) $min[1], (int) $max[1]);
             $background_color = isset($this->settings['devel_image_provider_background_color']) ? $this->settings['devel_image_provider_background_color'] : FALSE;
             if ($background_color) {
                 if (preg_match('/^#[a-f0-9]{6}$/i', $background_color)) {
                     // Check for valid hex number
                     $background_color = "/" . str_replace('#', '', check_plain($background_color));
                     // Strip out #
                 } else {
                     $background_color = '';
                 }
             } else {
                 $background_color = '';
             }
             $text_color = isset($this->settings['devel_image_provider_text_color']) ? $this->settings['devel_image_provider_text_color'] : FALSE;
             if ($text_color) {
                 // Check for valid hex number.
                 if (preg_match('/^#[a-f0-9]{6}$/i', $text_color)) {
                     // Strip out # character.
                     $text_color = "/" . str_replace('#', '', check_plain($text_color));
                 } else {
                     $text_color = '';
                 }
             } else {
                 $text_color = '';
             }
             $include_text = isset($this->settings['devel_image_provider_include_text']) ? $this->settings['devel_image_provider_include_text'] : FALSE;
             switch ($include_text) {
                 case 'custom':
                     $custom_text = isset($this->settings['devel_image_provider_custom_text']) ? $this->settings['devel_image_provider_custom_text'] : '';
                     break;
                 case 'random':
                     // Small random text as text size is depending on the image size.
                     $custom_text = trim(substr(devel_create_greeking(mt_rand(1, 3)), 0, 8));
                     break;
                 case 'default':
                 default:
                     $custom_text = '';
                     break;
             }
             if (!empty($custom_text)) {
                 //Replace the spaces with + as per provider specifications
                 $custom_text = "&text=" . str_replace(' ', '+', check_plain($custom_text));
             }
             $url = "{$this->provider_base_url}/" . $width . "x" . $height . '/' . $background_color . '/' . $text_color . '&text=' . $custom_text;
             $method = isset($this->settings['devel_image_provider_get_method']) ? $this->settings['devel_image_provider_get_method'] : 'file_get_contents';
             $path = devel_image_provider_get_file($url, $destination, $method);
             $source = new stdClass();
             $source->uri = $path;
             $source->uid = 1;
             // TODO: randomize? Use case specific.
             $source->filemime = 'image/jpg';
             if (!empty($instance['settings']['file_directory'])) {
                 $instance['settings']['file_directory'] = $instance['settings']['file_directory'] . '/';
             }
             $destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
             file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
             $destination = $destination_dir . basename($path);
             $file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
         } else {
             return FALSE;
         }
     } else {
         // Select one of the images we've already generated for this field.
         $file = new stdClass();
         $file->fid = array_rand($images[$extension][$min_resolution][$max_resolution]);
     }
     $object_field['fid'] = $file->fid;
     $object_field['alt'] = devel_create_greeking(4);
     $object_field['title'] = devel_create_greeking(4);
     return $object_field;
 }
 public function generateImage($object, $field, $instance, $bundle)
 {
     $object_field = array();
     static $available_images = array();
     if (empty($available_images)) {
         $available_images = $this->getImages();
     }
     if (empty($available_images)) {
         $args = func_get_args();
         return call_user_func_array('_image_devel_generate', $args);
     }
     $extension = array_rand(array('jpg' => 'jpg', 'png' => 'png'));
     $min_resolution = empty($instance['settings']['min_resolution']) ? '100x100' : $instance['settings']['min_resolution'];
     $max_resolution = empty($instance['settings']['max_resolution']) ? '600x600' : $instance['settings']['max_resolution'];
     if (FALSE === ($tmp_file = drupal_tempnam('temporary://', 'imagefield_'))) {
         return FALSE;
     }
     $destination = $tmp_file . '.' . $extension;
     file_unmanaged_move($tmp_file, $destination, FILE_EXISTS_REPLACE);
     $rand_file = array_rand($available_images);
     if (!empty($instance['settings']['file_directory'])) {
         $instance['settings']['file_directory'] = $instance['settings']['file_directory'] . '/';
     }
     $destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
     file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
     if ($this->settings['devel_image_no_alter']) {
         $file = $available_images[$rand_file];
         $file = file_copy($file, $destination_dir);
     } else {
         $image = image_load($rand_file);
         $min = explode('x', $min_resolution);
         $max = explode('x', $max_resolution);
         $max[0] = $max[0] < $min[0] ? $min[0] : $max[0];
         $max[1] = $max[1] < $min[1] ? $min[1] : $max[1];
         $width = rand((int) $min[0], (int) $max[0]);
         $height = rand((int) $min[1], (int) $max[1]);
         if (!image_scale_and_crop($image, $width, $height)) {
             return FALSE;
         }
         // Use destination image type.
         $image->info['extension'] = $extension;
         if (!image_save($image, $destination)) {
             return FALSE;
         }
         $source = new stdClass();
         $source->uri = $destination;
         $source->uid = 1;
         // TODO: randomize? Use case specific.
         $source->filemime = $image->info['mime_type'];
         $source->filename = drupal_basename($image->source);
         $destination = $destination_dir . basename($destination);
         $file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
     }
     $object_field['fid'] = $file->fid;
     $object_field['alt'] = devel_create_greeking(4);
     $object_field['title'] = devel_create_greeking(4);
     return $object_field;
 }
Example #5
0
    // Replace codes.
    $match;
    if (preg_match('/<code>(.+?)<\\/code>/', $line, $match)) {
        if (!isset($uuids[$match[1]])) {
            $uuids[$match[1]] = 'OBF-' . uniqid();
        }
        $line = str_replace($match[1], $uuids[$match[1]], $line);
    }
    // Remove IDs that start with a number.
    $line = preg_replace('/\\sid="\\d.*?"/', '', $line);
    // If this is a text line, replace all the text.
    $match;
    if (preg_match('/^<de>(.+?)<\\/de>/', trim($line), $match)) {
        if (!isset($texts[$match[1]])) {
            $wordCount = count(explode(' ', $match[1]));
            $text = devel_create_greeking($wordCount, $wordCount < 3);
            $texts[$match[1]] = $text;
        }
        $line = preg_replace('/<de>.+?<\\/de>/', "<de>{$texts[$match[1]]}</de>", $line);
    }
    fwrite($out, $line);
}
// Close the XML files.
fclose($in);
fclose($out);
echo "Done with the XML files. Moving on to the ASCII dumps...\n";
// Replace all UUIDs in the ascii files.
foreach ([__DIR__ . '/lp21_curriculum_obfuscated.ascii' => __DIR__ . '/lp21_curriculum.ascii', __DIR__ . '/lp21_taxonomy_tree_obfuscated.ascii' => __DIR__ . '/lp21_taxonomy_tree.ascii'] as $outFile => $inFile) {
    // Reset the file contents.
    file_put_contents($outFile, '');
    // Open both files.