function _ad_ui_install_ads in Advertisement 7.3
1 call to _ad_ui_install_ads()
- drush_ad_ui_install in modules/
ad_ui/ ad_ui.drush.inc - Callback to install example ads and terms.
File
- modules/
ad_ui/ ad_ui.drush.inc, line 107
Code
function _ad_ui_install_ads() {
$ads = array(
'Rectangle' => array(
'160x120_1.gif' => 'http://www.apple.com/',
'160x120_2.jpg' => 'http://www.microsoft.com/',
'160x120_3.jpg' => 'http://www.google.com/',
),
'Skyscraper' => array(
'160x600_1.jpg' => 'http://www.facebook.com/',
'160x600_2.jpg' => 'http://www.yahoo.com/',
'160x600_3.jpg' => 'http://www.reddit.com/',
),
'Leaderboard' => array(
'728x90_1.jpg' => 'http://www.twitter.com/',
'728x90_2.gif' => 'http://www.linkedin.com/',
'728x90_3.gif' => 'http://www.youtube.com/',
),
);
$target_dir = "public://ads/";
file_prepare_directory($target_dir, FILE_CREATE_DIRECTORY);
foreach ($ads as $size => $ad) {
$n = 0;
$term = current(taxonomy_get_term_by_name($size, 'advertisement_size'));
foreach ($ad as $image => $destination) {
$n++;
$image_path = drupal_get_path('module', 'ad_ui') . '/images/' . $image;
$image_dest = "{$target_dir}/{$image}";
$ad = entity_create('node', array(
'type' => 'ad',
'status' => 1,
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
'uid' => 1,
'title' => $size . ' ' . $n,
'field_ad_image' => array(
LANGUAGE_NONE => array(
(array) file_save_data(file_get_contents($image_path), $image_dest),
),
),
'field_ad_link' => array(
LANGUAGE_NONE => array(
array(
'url' => $destination,
),
),
),
'field_ad_size' => array(
LANGUAGE_NONE => array(
array(
'tid' => $term->tid,
),
),
),
));
entity_save('node', $ad);
}
}
}