You are here

function textimage_update_2 in Textimage 5.2

Same name and namespace in other branches
  1. 6.2 textimage.install \textimage_update_2()

File

./textimage.install, line 141

Code

function textimage_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {textimage_image} (\n        pid INT UNSIGNED NOT NULL DEFAULT 0,\n        file VARCHAR(255) NOT NULL PRIMARY KEY,\n        data TEXT NOT NULL)\n        /*!40100 DEFAULT CHARACTER SET utf8 */");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {textimage_image} (\n        pid INTEGER NOT NULL DEFAULT 0,\n        file VARCHAR(255) NOT NULL,\n        data TEXT NOT NULL DEFAULT ''\n        PRIMARY KEY (file));");
      break;
  }
  include_once drupal_get_path('module', 'textimage') . '/textimage_admin.inc';
  foreach (textimage_get_presets() as $preset) {
    $path = realpath(file_directory_path() . '/textimage/' . $preset->name);
    if (is_dir($path)) {
      $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
      foreach ($files as $file => $object) {
        $file = str_replace($path . '/', '', $file);
        $args = explode('/', $file);
        $filename = urldecode(array_pop($args));
        $additional_text = $args;
        preg_match('/\\.([a-z]+)$/i', $filename, $matches);
        $format = $matches[1];
        if ($format == 'jpg') {
          $format = 'jpeg';
        }
        $text = preg_replace('/\\.([a-z]+)$/i', '', $filename);
        db_query("INSERT {textimage_image} (pid, file, data) VALUES (%d, '%s', '%s')", $preset['pid'], file_directory_path() . '/textimage/' . $preset->name . '/' . $file, serialize(array(
          'format' => $format,
          'text' => $text,
          'additional_text' => $additional_text,
        )));
      }
    }
  }
  return $ret;
}