Scald

Créé le 05/09/2014

Dernière mise à jour le 05/09/2014

Étiquettes

Créer programmaticalement des atoms

Image

function make_and_get_scald_image($path, $filename) {
  $file_content = file_get_contents($path);
  $directory = file_default_scheme() . '://thumbnails/image';
  file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
  $destination = file_stream_wrapper_uri_normalize($directory . '/' . $filename);
  $file = file_save_data($file_content, $destination, FILE_EXISTS_REPLACE);

  if ($file) {
    $atoms = array(
      new ScaldAtom('image', 'scald_image'),
    );
    $form = array();
    $form_state = array(
      'values' => array(
        'file' => $file->fid,
      ),
    );
    scald_image_scald_add_form_fill($atoms, $form, $form_state);

    $atom = $atoms[0];
    $atom->title = $filename;
    $sid = scald_atom_save($atom);
    return $sid;
  }
}

Gallery

function make_and_get_scald_gallery($gallery_item_sids) {

  // Prepare atom.
  $atom = new ScaldAtom('gallery', 'scald_gallery');
  $form = array();
  $form_state = array(
    'values' => array(
      'title' => 'your title',
    ),
  );
  scald_gallery_scald_add_form_fill($atom, $form, $form_state);

  // Add gallery_items and data.
  $atom->gallery_items = array(
    LANGUAGE_NONE => array()
  );
  $atom->data = array('items' => array());
  foreach ($gallery_item_sids as $gallery_item_sid) {
    $atom->gallery_items[LANGUAGE_NONE][] = array(
      'sid' => $gallery_item_sid,
      'title_overriden' => 0,
      'title' => '',
      'description' => '',
    );
    $atom->data['items'][$gallery_item_sid] = array(
      'title_overriden' => 0,
      'title' => '',
      'description' => '',
    );
  }

  $gallery_sid = scald_atom_save($atom);

  return $gallery_sid;
}

Youtube

function make_and_get_scald_video($url) {
  $sid = scald_youtube_register(scald_youtube_parse_id($url, TRUE));

  return $sid;
}

Ajouter un commentaire