';
}
}
return $attachment_str.$debug;
}
/**
* Returns a link to a file, including an icon if needed.
*
* @param object $attachment - wp-attachment object
* @return string - link to attachment
*/
function get_attachment_link($attachment) {
$link = "guid);
$exts = wpAttachmentManager::get_exts();
$img = (isset($exts[$ext]))? $exts[$ext]:get_option('wam_default_icon');
if (!empty($img)) {
$icon_dir = wpAttachmentManager::get_icon_dir();
$icon_url = path_join(wpAttachmentManager::get_icon_url(),$img);
$image_size = getimagesize(path_join($icon_dir,$img));
$lp = $image_size[0]+4;
$height = $image_size[1];
$siteurl = get_settings('siteurl').'/';
$link .= ' class="wam_icon_link"';
$link .= " style='padding-left:{$lp}px; line-height:{$height}px; background-image:url(\"{$icon_url}\");'";
}
}
$link .= ">{$attachment->post_title}";
return $link;
}
/**
* This attaches to init, and was needed so we could use wp_redirect. It
* checks to see if an icon is has been requested to be removed. Then it
* removes it, and redirects back to the options page, and gives a succes or
* error message
*/
function handle_actions() {
if (isset($_GET['page']) && $_GET['page'] == 'attachment_manager') {
if ( isset($_GET['action']) ) {
if ('remove' == $_GET['action']) {
$exts = wpAttachmentManager::get_exts();
$exts = array_diff($exts, array($_GET['icon']));
update_option('wam_exts', $exts);
$icon_dir = wpAttachmentManager::get_icon_dir().'/';
if (is_writable($icon_dir.$_GET['icon']) && @unlink($icon_dir.$_GET['icon'])) {
wp_redirect('options-general.php?page=attachment_manager&remove=true');
} else {
wp_redirect('options-general.php?page=attachment_manager&remove=false');
}
}
exit;
} elseif (isset($_FILES['wam_add_icon'])) {
$file = path_join(wpAttachmentManager::get_icon_dir(), basename($_FILES['wam_add_icon']['name']));
if (move_uploaded_file($_FILES['wam_add_icon']['tmp_name'], $file)) {
wp_redirect('options-general.php?page=attachment_manager&upload=true');
} else {
wp_redirect('options-general.php?page=attachment_manager&upload=false');
}
}
}
}
/**
* This is used to attach the JS and CSS needed for the options page
*/
function config_head() {
if (isset($_GET['page']) && $_GET['page'] == 'attachment_manager') {
// wpAttachmentManager::css();
}
}
/**
* This is used to display the options page for this plugin
*/
function config() {
$debug = '';
$siteurl = get_settings('siteurl').'/';
$plugin_dir = wpAttachmentManager::get_plugin_dir();
$icon_dir = wpAttachmentManager::get_icon_dir();
$icon_url = wpAttachmentManager::get_icon_url();
$icon_file_types = wpAttachmentManager::get_icon_filetypes();
$debug .= "
writable, you would be able to add and remove icons!') ?>
',var_dump($exts),'';
}
return $exts;
}
/**
* Echos the link to the plugin stylesheet
*/
function css() {
$css_file = path_join(wpAttachmentManager::get_plugin_url(),'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() {
if (get_option('wam_list_on_posts') === false) {
update_option('wam_list_on_posts', 'all');
}
if (get_option('wam_show_file_icons') === false) {
update_option('wam_show_file_icons', 'true');
}
if (get_option('wam_dont_show_on_excerpts') === false) {
update_option('wam_dont_show_on_excerpts', 'true');
}
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'));