writable, you would be able to add and remove icons!') ?>
$plugin) {
if ($plugin['Name'] == 'Attachment Manager' && strip_tags($plugin['Author']) == 'Aaron D. Campbell') {
$plugin_loc .= dirname($plugin_file);
break;
}
}
}
update_option('wam_plugin_dir', $plugin_loc);
}
return $plugin_loc;
}
/**
* Either returns the icon directory from the plugin options, or gets the
* plugin directory and adds /icons (the default)
*
* @return string - icon directory
*/
function get_icon_dir() {
$icon_loc = get_option('wam_icon_dir');
if ($icon_loc == false) {
$icon_loc = wpAttachmentManager::get_plugin_dir().'/icons';
update_option('wam_icon_dir', $icon_loc);
}
return $icon_loc;
}
/**
* Either returns the icon file types from the plugin options, or returns the
* default (jpg, jpeg, gif, and png)
*
* @return array - icon file types
*/
function get_icon_filetypes() {
$icon_file_types = get_option('icon_file_types');
if ($icon_file_types == false) {
$icon_file_types = array('jpg', 'jpeg', 'gif', 'png');
update_option('icon_file_types', $icon_file_types);
}
return $icon_file_types;
}
/**
* Returns the extentions array from the plugin options. Formatted like:
* $arr[ext] = 'icon_file_name.png';
*
* @return array - extensions array
*/
function get_exts() {
$exts = get_option('wam_exts');
if (!is_array($exts)) {
$exts = wpAttachmentManager::get_default_ext_array();
update_option('wam_exts', $exts);
}
if (WAM_DEBUG) {
echo '
',var_dump($exts),'
';
}
return $exts;
}
/**
* Echos the link to the plugin stylesheet
*/
function css() {
$siteurl = get_option('siteurl');
$css_file = "{$siteurl}/".wpAttachmentManager::get_plugin_dir().'/css/wp-attachment-manager.css';
echo "";
}
/**
* Used to get the default extensions array
*/
function get_default_ext_array() {
return unserialize('a:99:{s:3:"css";s:7:"css.png";s:3:"eml";s:9:"email.png";s:3:"rss";s:8:"feed.png";s:1:"h";s:16:"page_white_h.png";s:3:"avi";s:8:"film.png";s:3:"mov";s:8:"film.png";s:3:"mp4";s:8:"film.png";s:3:"mpg";s:8:"film.png";s:2:"qt";s:8:"film.png";s:2:"rm";s:8:"film.png";s:3:"wmv";s:8:"film.png";s:3:"chm";s:8:"help.png";s:3:"mdb";s:18:"page_white_key.png";s:3:"htm";s:8:"html.png";s:4:"html";s:8:"html.png";s:3:"sht";s:8:"html.png";s:4:"shtm";s:8:"html.png";s:5:"shtml";s:8:"html.png";s:3:"aac";s:9:"music.png";s:3:"aif";s:9:"music.png";s:3:"mid";s:9:"music.png";s:4:"midi";s:9:"music.png";s:3:"mp3";s:9:"music.png";s:3:"mpa";s:9:"music.png";s:2:"ra";s:9:"music.png";s:3:"ram";s:9:"music.png";s:3:"wav";s:9:"music.png";s:3:"wma";s:9:"music.png";s:4:"flac";s:9:"music.png";s:3:"ogg";s:9:"music.png";s:3:"pdf";s:22:"page_white_acrobat.png";s:2:"as";s:27:"page_white_actionscript.png";s:1:"c";s:16:"page_white_c.png";s:3:"raw";s:21:"page_white_camera.png";s:3:"inc";s:18:"page_white_php.png";s:3:"php";s:18:"page_white_php.png";s:4:"php4";s:18:"page_white_php.png";s:4:"php5";s:18:"page_white_php.png";s:4:"phps";s:18:"page_white_php.png";s:5:"phtml";s:18:"page_white_php.png";s:3:"tpl";s:18:"page_white_php.png";s:3:"bmp";s:22:"page_white_picture.png";s:3:"gif";s:22:"page_white_picture.png";s:4:"jpeg";s:22:"page_white_picture.png";s:3:"jpg";s:22:"page_white_picture.png";s:3:"png";s:22:"page_white_picture.png";s:3:"psd";s:22:"page_white_picture.png";s:2:"js";s:23:"page_white_code_red.png";s:3:"ppt";s:25:"page_white_powerpoint.png";s:3:"cfm";s:25:"page_white_coldfusion.png";s:4:"cfml";s:25:"page_white_coldfusion.png";s:2:"bz";s:25:"page_white_compressed.png";s:3:"bz2";s:25:"page_white_compressed.png";s:3:"cab";s:25:"page_white_compressed.png";s:4:"gtar";s:25:"page_white_compressed.png";s:2:"gz";s:25:"page_white_compressed.png";s:4:"gzip";s:25:"page_white_compressed.png";s:3:"rar";s:25:"page_white_compressed.png";s:3:"tar";s:25:"page_white_compressed.png";s:6:"tar-gz";s:25:"page_white_compressed.png";s:3:"tgz";s:25:"page_white_compressed.png";s:3:"war";s:25:"page_white_compressed.png";s:3:"zip";s:25:"page_white_compressed.png";s:2:"rb";s:19:"page_white_ruby.png";s:3:"rbs";s:19:"page_white_ruby.png";s:5:"rhtml";s:19:"page_white_ruby.png";s:3:"cpp";s:24:"page_white_cplusplus.png";s:2:"cs";s:21:"page_white_csharp.png";s:5:"class";s:18:"page_white_cup.png";s:3:"jad";s:18:"page_white_cup.png";s:3:"jar";s:18:"page_white_cup.png";s:3:"jav";s:18:"page_white_cup.png";s:4:"java";s:18:"page_white_cup.png";s:3:"rdf";s:19:"page_white_text.png";s:3:"txt";s:19:"page_white_text.png";s:3:"sql";s:23:"page_white_database.png";s:4:"conf";s:18:"page_white_tux.png";s:2:"ai";s:21:"page_white_vector.png";s:3:"svg";s:21:"page_white_vector.png";s:3:"xls";s:20:"page_white_excel.png";s:3:"doc";s:19:"page_white_word.png";s:3:"fla";s:20:"page_white_flash.png";s:3:"swf";s:20:"page_white_flash.png";s:2:"fh";s:23:"page_white_freehand.png";s:4:"fh10";s:23:"page_white_freehand.png";s:3:"fh3";s:23:"page_white_freehand.png";s:3:"fh4";s:23:"page_white_freehand.png";s:3:"fh5";s:23:"page_white_freehand.png";s:3:"fh6";s:23:"page_white_freehand.png";s:3:"fh7";s:23:"page_white_freehand.png";s:3:"fh8";s:23:"page_white_freehand.png";s:3:"fh9";s:23:"page_white_freehand.png";s:3:"dtd";s:19:"page_white_gear.png";s:3:"tld";s:19:"page_white_gear.png";s:4:"wsdl";s:19:"page_white_gear.png";s:3:"xml";s:19:"page_white_gear.png";s:3:"xsd";s:19:"page_white_gear.png";s:3:"xsl";s:19:"page_white_gear.png";s:5:"xhtml";s:9:"xhtml.png";}');
}
/**
* Displays the "show attachments" checkbox if wam_list_on_posts is set to some
*/
function post_form() {
if (get_option('wam_list_on_posts') == 'some') {
global $post;
$checked = (get_post_meta($post->ID, '_wam_show_attachments', true) == 'true')? ' checked="checked"':'';
echo "
";
}
}
/**
* Adds or removes the show_attachments meta from the post
*
* @param int $pid - Post ID
*/
function handle_save_post($pid) {
if (isset($_POST['wam_show_attachments']) && strtolower($_POST['wam_show_attachments']) == 'true') {
add_post_meta($pid, '_wam_show_attachments', 'true', true);
} else {
delete_post_meta($pid, '_wam_show_attachments');
}
}
/**
* This is used to set some default values when the plugin is activated.
*/
function on_activate() {
update_option('wam_list_on_posts', 'all');
update_option('wam_show_file_icons', 'true');
update_option('wam_dont_show_on_excerpts', 'true');
wpAttachmentManager::get_exts();
}
/**
* This is called if a post is in excerpt. It uses self::excerpt_static to
* set a static variable to true, so we can test for it later.
*/
function check_excerpt($theExcerpt) {
if (WAM_DEBUG) {
echo "excerpt = true\r\n";
}
wpAttachmentManager::excerpt_static(true);
return $theExcerpt;
}
/**
* This is a lame PHP4 hack since it doesn't support static class variables.
* One of these days I'm just going to say "screw people that won't upgrade"
* and do ONLY PHP5
*
* @param bool $set[optional] - What to set the static var to
* @return bool - value of static var
*/
function excerpt_static($set = null) {
static $excerpt = false;
if (!is_null($set)) {
$excerpt = $set;
}
return $excerpt;
}
}
/**
* Add filters and actions
*/
//We have to set the priority of the excerpt check to one, or it will run AFTER the post handler
add_filter('get_the_excerpt', array('wpAttachmentManager','check_excerpt'), 1);
add_filter('the_content', array('wpAttachmentManager','attach_to_post'));
add_action('admin_menu', array('wpAttachmentManager','admin_menu'));
add_action('admin_head', array('wpAttachmentManager','config_head'));
add_action('init', array('wpAttachmentManager','handle_actions'));
add_action('wp_head', array('wpAttachmentManager','css'));
add_action('edit_form_advanced', array('wpAttachmentManager','post_form'));
add_action('save_post', array('wpAttachmentManager','handle_save_post'));
register_activation_hook(__FILE__, array('wpAttachmentManager','on_activate'));