';
}
return theme('asset_wizard_textarea_link', $element, $text);
}
/**
* Theme the textarea link
*/
function theme_asset_wizard_textarea_link($element, $text = NULL) {
$path = drupal_get_path('module', 'asset_wizard');
// add thickbox stuff
drupal_add_js($path .'/js/thickbox/jquery.thickbox.js');
drupal_add_css($path .'/js/thickbox/thickbox.css');
// provide an accurate loadingAnimation path
drupal_add_js('tb_pathToImage = "'. base_path() . $path .'/js/thickbox/loadingAnimation.gif";', 'inline', 'footer');
// jquery form plugin
drupal_add_js($path .'/js/form/jquery.form.js');
// asset wizard stuff
drupal_add_css($path .'/asset_wizard.css');
drupal_add_js($path .'/js/asset_wizard.js');
asset_wizard_js_settings();
if ($element['#asset_return_type']) {
$params = 'return='. $element['#asset_return_type'];
$params .= '&config='. ($element['#asset_config'] ? $element['#asset_config'] : 'macro');
}
$text = $text ? $text : t('Asset Wizard');
$link = tbl($text, 'asset/wizard', array('id' => 'asset-wizard-'. $element['#id'], 'class' => 'asset-wizard-start', 'title' => 'Asset Wizard'), $params, NULL, FALSE, TRUE);
return $link;
}
/**
* always ignore certain textareas based on element attributes (mainly #id)
*/
function _asset_wizard_element_match($element) {
$ignore = array(
'edit-log',
);
if (in_array($element['#id'], $ignore)) {
return false;
}
return true;
}
/**
* Should we show the insert asset link, determined by admin setting
* Borrowed from tinymce.module
*
* @return
* TRUE if can render, FALSE if not allowed.
*/
function _asset_wizard_page_match() {
$page_match = FALSE;
$access_option = variable_get('asset_wizard_access_option', 1);
$access_pages = variable_get('asset_wizard_access_pages', "node/add/*\nnode/*/edit");
if ($access_pages) {
// If the PHP option wasn't selected
if ($access_option < 2) {
$path = drupal_get_path_alias($_GET['q']);
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($access_pages, '/')) .')$/';
$page_match = !($access_option xor preg_match($regexp, $path));
}
else {
$page_match = drupal_eval($access_pages);
}
}
// No pages were specified to block so show on all
else {
$page_match = TRUE;
}
return $page_match;
}
function asset_wizard_methods() {
static $methods;
if (!isset($methods)) {
$methods['browse'] = array(
'name' => t('Browse'),
'callback' => 'asset_wizard_browse',
'description' => t('Choose from a list of existing assets.'),
);
$methods = $methods + module_invoke_all('asset_wizard', 'info');
}
return $methods;
}
/**
* Load the current asset wizard config array, passed in throught $_GET['config']
* Options for config are 'macro' (default), 'id', or the name of a cck field
*/
function asset_wizard_get_config($cfg_name = NULL) {
static $configs = array();
$cfg_name = $cfg_name ? $cfg_name : ($_GET['config'] ? $_GET['config'] : 'default');
$config = array();
if (!isset($config[$cfg_name])) {
// build an array of asset cck fields
$asset_fields = array();
if (module_exists('content')) {
$fields = content_fields();
foreach ($fields as $name => $field) {
if ($field['type'] == 'asset') {
$asset_fields[$name] = $field;
}
}
}
// asset field config
if ($asset_fields[$cfg_name]) {
$config = $asset_fields[$cfg_name];
$config['return type'] = 'id';
}
// id type config
elseif ($cfg_name == 'id') {
$config = array(
'return type' => 'id',
);
}
// everything else, including 'default', gets the default config
else{
$config = array(
'return type' => 'macro',
);
}
$configs[$cfg_name] = $config;
}
return $configs[$cfg_name];
}
function asset_wizard_main() {
$config = asset_wizard_get_config();
$items = array();
foreach (asset_wizard_methods() as $key => $method) {
$items[] = tbl($method['name'], 'asset/wizard/method/'. $key) .' '. $method['description'];
}
$create = array();
foreach (asset_get_types() as $type) {
if (!$config['allowed_types'] ||
($config['allowed_types'][$type->type] && asset_access('create', $type->type))) {
$type_url_str = str_replace('_', '-', $type->type);
$text = t('New !type', array('!type' => drupal_ucfirst($type->name)));
$create[] = tbl($text, 'asset/wizard/add/'. $type_url_str, array(), NULL, NULL, FALSE, TRUE) .' '. $type->description;
}
}
$items[] = array('data' => '
'. t('Create...') .'
', 'children' => $create);
$content = theme('asset_wizard_main', $items);
return theme('asset_wizard_page', $content);
}
/**
* Step 1: Display a browsable list of assets
*/
function asset_wizard_browse($asset = NULL) {
$config = asset_wizard_get_config();
if (!$asset) {
$asset = asset_load(0);
}
$items = array();
if ($asset->aid) {
$parent = asset_load($asset->pid);
$parent->link_title = '..';
$items[] = $parent;
}
$types = array();
$query = 'SELECT aid FROM {asset} WHERE pid=%d';
$args[] = $asset->aid;
if ($config['allowed_types']) {
foreach ($config['allowed_types'] as $type) {
if ($type) {
$types[] = $type;
}
}
if ($types) {
$query .= ' AND type IN ("%s")';
$args[] = implode('","', $types);
}
}
$result = db_query($query, $args);
while ($row = db_fetch_object($result)) {
//$items[$row->aid] = $row->title;
$items[] = asset_load($row->aid);
}
$content = theme('asset_wizard_browse', $items);
return theme('asset_wizard_page', $content);
}
/**
* Step 2: Display a list of available formats for a given asset
*/
function asset_wizard_formats($asset) {
// at this point we need to check if we should continue ($_GET['return']=='macro')
// or simply return the id
if ($_GET['return'] == 'id') {
return drupal_goto('asset/wizard/'. $asset->aid .'/finish/'. $asset->aid);
}
$content = theme('asset_wizard_formats', $asset, $asset->formatters);
return theme('asset_wizard_page', $content);
}
/**
* Step 3: Display the options form
*/
function asset_wizard_format_options($asset, $attr) {
$content = '
EOD;
exit();
}
function theme_asset_wizard_selected() {
if (is_numeric(arg(2))) {
$asset = asset_load(arg(2));
$output = '
Selected Asset
'
.'
'. theme('asset_icon', $asset) .'
';
return $output;
}
}
function theme_asset_wizard_links() {
// figure out the step we are on
$step = 0;
if (arg(2) && !is_numeric(arg(2))) {
$step = 1;
}
elseif (arg(2)) {
$asset = asset_load(arg(2));
if ($asset->type == 'directory') {
$step = 1;
}
else{
if (arg(3) == 'finish') {
$step = 4;
}
elseif (arg(3)) {
$step = 3;
}
else{
$step = 2;
}
}
}
// build the links/spans based on what step we're on
$links = array();
$aid = is_numeric(arg(2)) ? arg(2) : 0;
if ($_GET['return'] == 'id') {
$steps = array(
'asset/wizard' => t('Start'),
'asset/wizard/browse' => t('Select an Asset'),
'asset/wizard/'. $aid .'/finish/'. arg(4) => t('Preview'),
);
}
else{
$steps = array(
'asset/wizard' => t('Start'),
'asset/wizard/browse' => t('Select an Asset'),
'asset/wizard/'. $aid => t('Select a Format'),
'asset/wizard/'. $aid .'/'. arg(3) => t('Formatting Options'),
'asset/wizard/'. $aid .'/finish/'. arg(4) => t('Preview'),
);
}
$i = 0;
foreach ($steps as $path => $text) {
if ($step == $i) {
$links[] = ''. $text .'';
}
elseif ($step > $i) {
$links[] = tbl($text, $path);
}
else{
$links[] = ''. $text .'';
}
$i++;
}
return '
'. join('
', $links) .'
';
}
function asset_wizard_help($section) {
$aid = arg(2);
switch ($section) {
case 'asset/wizard':
return '
'. t('The asset wizard allows you to create and select digital assets to use in the context of this site. To get started, select a method for choosing the appropriate asset.') .'
';
case 'asset/wizard/'. $aid .'/finish':
return '
'. t('Here is the preview of your formatted asset. You can click any of the links in the sidebar to make changes, or click Finish to insert this into the document.') .'
';
case 'asset/wizard/browse':
return '
'. t('Select the asset you wish to use.') .'
';
case 'asset/wizard/'. $aid:
return '
'. t('Select from the list of available formats.') .'