TRUE
(PHP-mode, experts only).'),
),
);
$form['asset_access_pages'] = array(
'#type' => 'textarea',
'#title' => t('Pages'),
'#default_value' => variable_get('asset_access_pages',"node/add/*\nnode/*/edit"),
'#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are 'blog' for the blog page and blog/* for every personal blog. This form is currently just a placeholder. The values are not used anywhere yet.
'); $formatters = asset_get_formatters(true); foreach ($formatters as $type => $exts){ $form[$type] = array( '#type' => 'fieldset', '#title' => $type == '*' ? t('All Types') : $type, '#tree' => false, ); foreach($exts as $ext => $formats) { $form[$type]['asset_default_formatter_' . $type . '_' . $ext] = array ( '#type' => 'select', '#title' => $ext, '#options' => asset_formatter_options($type, $ext), '#default_value' => variable_get('asset_default_formatter_'. $type . '_' . $ext, 'asset:link'), ); $form[$type]['asset_default_formatter_teaser_' . $type . '_' . $ext] = array ( '#type' => 'select', '#title' => $ext, '#options' => asset_formatter_options($type, $ext), '#default_value' => variable_get('asset_default_formatter_teaser_' . $type . '_' . $ext, 'asset:link'), ); } } return system_settings_form($form); } function theme_asset_admin_formatter_defaults($form){ $formatters = asset_get_formatters(); foreach($formatters as $type => $exts){ $rows = array(); foreach($exts as $ext => $formats){ unset($form[$type]['asset_default_formatter_'. $type . '_'.$ext]['#title']); unset($form[$type]['asset_default_formatter_teaser_'. $type . '_'.$ext]['#title']); $rows[] = array( $ext, drupal_render($form[$type]['asset_default_formatter_'. $type . '_'.$ext]), drupal_render($form[$type]['asset_default_formatter_teaser_'. $type . '_'.$ext]), ); } $form[$type]['#value'] = theme('table',array('','Full Page','Teaser'),$rows); } return drupal_render($form); } /** * Implementation of hook_nodeapi() * This is where we build the asset_node records. */ function asset_nodeapi(& $node, $op, $a3 = NULL, $a4 = NULL) { switch ($op) { // must do this on submit rather than update or insert because we want the // pre filtered node->body case 'submit': // clear previous count db_query('DELETE FROM {asset_node} WHERE nid=%d', $node->nid); // only update if using a format that includes the asset filter $filters = filter_list_format($node->format); if (!$filters['asset/0']) { return; } $refs = array(); foreach (asset_get_macros($node->body) as $macro) { $refs[$macro['aid']]++; } foreach ($refs as $aid => $ref) { db_query('INSERT INTO {asset_node} (aid,nid,refs) VALUES (%d,%d,%d)', $aid, $node->nid, $ref); } break; case 'load' : $result = db_query('SELECT * FROM {asset_node} WHERE nid=%d AND refs > 0', $node->nid); while ($asset = db_fetch_object($result)) { $additions['assets'][] = $asset->aid; } return (array) $additions; } } /** * Implementation of hook_filter(). */ function asset_filter($op, $delta = 0, $format = -1, $text = '') { switch ($op) { case 'list' : return array (0 => t('Inline file assets')); case 'description' : return t('Add formatted file assets to your posts.'); case 'process' : foreach (asset_get_macros($text) as $unexpanded_macro => $macro) { $expanded_macro = asset_render_macro($macro); $text = str_replace($unexpanded_macro, $expanded_macro, $text); } return $text; default : return $text; } } /** * Implementation of hook_filter_tips(). */ function asset_filter_tips($delta, $format, $long = false) { if ($long) { return t('Inline assets are allowed. Use the Insert Assets link or the WYSIWYG editor button to insert the proper format.'); } else { return t('Inline assets are allowed.'); } } /** * Return all img_assist macros as an array. */ function asset_get_macros($text) { $m = array (); preg_match_all('/ \[ ( [^\[\]]+ )* \] /x', $text, $matches); $tag_match = (array) array_unique($matches[1]); // Don't process duplicates. foreach ($tag_match as $macro) { $current_macro = '[' . $macro . ']'; $param = array_map('trim', explode('|', $macro)); $func_name = array_shift($param); // The first macro param is assumed to be the function name. //$num_params = count($param); // Get the number of parameters if ($func_name == 'asset') { $vars = array (); foreach ($param as $p) { $pos = strpos($p, '='); $varname = substr($p, 0, $pos); $varvalue = substr($p, $pos +1); $vars[$varname] = $varvalue; } // the full unaltered filter string is the key for the array of filter attributes $m[$current_macro] = $vars; } } return $m; } /** * build html from atrributes array. * * @param $attr * Array of attributes parsed from filter macro. */ function asset_render_macro($attr = array ()) { $asset = asset_load($attr['aid']); if ($attr['formatter']) { return module_invoke($attr['formatter'], 'asset_formatter', 'render', $asset, $attr); } else { return theme('asset_render_default', $asset); } } /** * Default rendering available to all assets. */ function theme_asset_render_default($asset) { return '' . ($asset->title ? $asset->title : $asset->filename) . ''; } /** * Build a macro from the specified attributes. */ function asset_build_macro($attr = array ()) { $macro = '[asset'; foreach ($attr as $k => $v) { $macro .= '|' . $k . '=' . $v; } $macro .= ']'; return $macro; } /** * Utility function to retrieve a list of all available formatters. * * @return array * returns an array keyed by filetype(extension) with elements as arrays of format information. */ function asset_get_formatters($reset = FALSE) { static $formatters; if(!isset($formatters) || $reset){ if(!$reset && ($cache = cache_get('asset_formatters')) && !empty($cache->data)){ $formatters = unserialize($cache->data); }else{ $formatters = array (); foreach (module_implements('asset_formatter') as $module) { $list = module_invoke($module, 'asset_formatter', 'info'); foreach ((array)$list as $key => $data) { $data['module'] = $module; $data['format'] = $key; foreach ($data['types'] as $type=>$exts) { foreach($exts as $ext){ $formatters[$type][$ext][] = $data; } } } } cache_set('asset_formatters', 'cache', serialize($formatters)); } } return $formatters; } /** * Utility function to return an array of available formatters for a file suitable for FAPI #options * * @param $filename * Filename to retrieve options for. Will also work with just an extension. */ function asset_formatter_options($type = '*', $filename = null) { $pos = strrpos($filename, '.'); if ($pos === false) { // allow for case where extension is passed instead of filename $ext = $filename; } else { $ext = substr($filename, $pos +1); } $formatters = asset_get_formatters(); $options = array (); if (is_array($formatters[$type][$ext])) { foreach ($formatters[$type][$ext] as $formatter) { $options[$formatter['module'] . ':' . $formatter['format']] = $formatter['name']; } } if (is_array($formatters[$type]['*'])) { foreach ($formatters[$type]['*'] as $formatter) { $options[$formatter['module'] . ':' . $formatter['format']] = $formatter['name']; } } if (is_array($formatters['*']['*'])) { foreach ($formatters['*']['*'] as $formatter) { $options[$formatter['module'] . ':' . $formatter['format']] = $formatter['name']; } } return $options; } /** * Implementation of hook_asset_formatter(). */ function asset_asset_formatter($op = 'info', $asset = NULL, $attr = array()){ switch($op){ case 'info': $formats['link'] = array ( 'name' => t('Link'), 'types' => array ( '*' => array('*')), 'description' => t('A simple download link.'), ); $formats['image'] = array ( 'name' => t('Image'), 'types' => array ( 'local' => array('jpg','gif','png')), 'description' => t('The full-size image.'), ); return $formats; case 'options': switch ($attr['format']) { case 'image' : $info = image_get_info(file_create_path($asset->filepath)); $form['height'] = array ( '#type' => 'textfield', '#title' => t('Height'), '#size' => '10', '#default_value' => $info['height'], ); $form['width'] = array ( '#type' => 'textfield', '#title' => t('Width'), '#size' => '10', '#default_value' => $info['width'], ); $form['resizable'] = array ( '#type' => 'hidden', '#value' => 'true', ); return $form; default : return array(); } break; case 'render': switch ($attr['format']) { case 'image' : $img_attributes = array (); if ($attr['height']) { $img_attributes['height'] = $attr['height']; } if ($attr['width']) { $img_attributes['width'] = $attr['width']; } return ''; default : return theme('asset_render_default', $asset); } break; case 'preview': switch ($attr['format']) { case 'image' : return theme('image', file_create_path($asset->filepath), '', '', array ('width' => '100'), false); case 'link' : return; } break; case 'details': switch ($attr['format']) { case 'image' : $info = image_get_info(file_create_path($asset->filepath)); return array ( t('Width') => $info['width'] . 'px', t('Height') => $info['height'] . 'px', ); } return array (); case 'img': switch ($attr['format']) { case 'image' : return file_create_path($asset->filepath); case 'link' : default : // when we get around to building icons. $icon = drupal_get_path('module', 'asset') . '/icons/' . $asset->extension . '.png'; if (file_exists($icon)) { return $icon; } // if all else fails send back a transparent gif so the default bg image shows return drupal_get_path('module', 'asset') . '/transparent.gif'; } break; } } /** * Implemetation of hook_assetapi() */ /** REMOVE function asset_assetapi($op = 'list', $asset = null, $attr = array ()) { switch ($op) { case 'list' : $formats['link'] = array ( 'name' => t('Link'), 'types' => array ('*'), 'description' => t('A simple download link.'), ); $formats['image'] = array ( 'name' => t('Image'), 'types' => array ('jpg','gif','png'), 'description' => t('The full-size image.'), ); return $formats; case 'options' : switch ($attr['format']) { case 'image' : $info = image_get_info(file_create_path($asset->filepath)); $form['height'] = array ( '#type' => 'textfield', '#title' => t('Height'), '#size' => '10', '#default_value' => $info['height'], ); $form['width'] = array ( '#type' => 'textfield', '#title' => t('Width'), '#size' => '10', '#default_value' => $info['width'], ); $form['resizable'] = array ( '#type' => 'hidden', '#value' => 'true', ); return $form; default : return array(); } break; case 'preview' : switch ($attr['format']) { case 'image' : return theme('image', file_create_path($asset->filepath), '', '', array ('width' => '100'), false); case 'link' : return; } break; case 'details' : switch ($attr['format']) { case 'image' : $info = image_get_info(file_create_path($asset->filepath)); return array ( t('Width') => $info['width'] . 'px', t('Height') => $info['height'] . 'px', ); } return array (); case 'img' : switch ($attr['format']) { case 'image' : return file_create_path($asset->filepath); case 'link' : default : // when we get around to building icons. $icon = drupal_get_path('module', 'asset') . '/icons/' . $asset->extension . '.png'; if (file_exists($icon)) { return $icon; } // if all else fails send back a transparent gif so the default bg image shows return drupal_get_path('module', 'asset') . '/transparent.gif'; } break; case 'render' : switch ($attr['format']) { case 'image' : $img_attributes = array (); if ($attr['height']) { $img_attributes['height'] = $attr['height']; } if ($attr['width']) { $img_attributes['width'] = $attr['width']; } return ''; default : return theme('asset_render_default', $asset); } } } END REMOVE **/ /** * Menu callback to load the asset popup window. */ function asset_wizard() { // all wizard related functionality first comes through this function so load the wizard inc require_once (drupal_get_path('module', 'asset') . '/asset_wizard.inc'); drupal_add_js(drupal_get_path('module', 'asset') . '/asset.js'); drupal_add_css(drupal_get_path('module', 'asset') . '/asset.css'); $theme = variable_get('asset_wizard_theme',drupal_get_path('module','asset').'/themes/default/asset_wizard.css'); drupal_add_css($theme); switch (arg(2)) { case 'textarea' : drupal_add_js(drupal_get_path('module', 'asset') . '/asset_textarea.js'); break; case 'tinymce' : drupal_add_js(drupal_get_path('module', 'tinymce') . '/tinymce/jscripts/tiny_mce/tiny_mce_popup.js'); drupal_add_js(drupal_get_path('module', 'asset') . '/tinymce/asset_tinymce.js'); break; } $output = drupal_get_form('asset_wizard_form'); ob_end_clean(); print theme('asset_popup', $output); exit; } /** * Implementation of hook_elements * This is where we add the link to textareas */ function asset_elements() { $type['textarea'] = array ('#process' => array ('asset_textarea' => array())); return $type; } /** * The #process callback function for the textareas */ function asset_textarea($element) { if(_asset_page_match()){ $output = theme('asset_textarea_link', $element); $element['#suffix'] .= $output; } return $element; } /** * Should we show the insert access link, determined by admin setting * Borrowed from tinymce.module * * @return * TRUE if can render, FALSE if not allowed. */ function _asset_page_match() { $page_match = FALSE; $access_option = variable_get('asset_access_option',1); $access_pages = variable_get('asset_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)/', '/\\\\\*/', '/(^|\|)\\\\