installdir = WP_PLUGIN_URL . '/' . str_replace(basename(__FILE__),"",plugin_basename(__FILE__));
add_action('admin_menu', array(&$this, 'action_admin_menu'));
add_filter("the_content",array(&$this, 'filter_the_content'));
add_filter("prepend_attachment",array(&$this, 'filter_prepend_attachment'));
add_filter("attachment_fields_to_edit", array(&$this, 'filter_attachment_fields_to_edit'), null, 2);
add_filter("attachment_fields_to_save", array(&$this, 'filter_attachment_fields_to_save'), null , 2);
register_activation_hook(__FILE__, array(&$this, 'plugin_construct'));
register_deactivation_hook(__FILE__, array(&$this, 'plugin_destruct'));
}
function action_admin_menu() {
add_settings_section($this->slug, $this->name, array(&$this, 'select_image_text'), 'media');
add_settings_field($this->slug . '-use-images-on-post', __('Use Images on Post Page',"dws_attributron-2000"), array(&$this, 'select_image_on_post'), 'media', $this->slug);
add_settings_field($this->slug . '-use-images-on-attachment', __('Use Images on Attachment Page',"dws_attributron-2000"), array(&$this, 'select_image_on_attachment'), 'media', $this->slug);
add_settings_field($this->slug . '-flickr-api-key', __('Flickr API Key',"dws_attributron-2000"), array(&$this, 'flickr_api_key'), 'media', $this->slug);
// add_settings_field($this->slug . '-flickr-api-secret', __('Flickr API Secret',"dws_attributron-2000"), array(&$this, 'flickr_api_secret'), 'media', $this->slug);
register_setting('media', 'dws_' . $this->slug);
}
function filter_prepend_attachment($content) {
global $post;
$options = get_option('dws_' . $this->slug);
$return = "";
$attachment_id = $post->ID;
$meta = get_post_custom($attachment_id);
if (get_post_meta($attachment_id,"_credit",true)) {
if (get_post_meta($attachment_id,"_link",true)) {
$author = get_post_meta($attachment_id,"_credit",true);
$author = get_post_meta($attachment_id,"_credit",true);
$link = get_post_meta($attachment_id,"_link",true);
$author = "$author";
} else {
$author = get_post_meta($attachment_id,"_credit",true);
}
$title = "" . get_the_title($attachment_id) . "";
$copyright = $this->license_slug_to_html(get_post_meta($attachment_id,"_copyright",true));
if ($copyright) {
$return .= "
$title $copyright $author";
} else {
$return .= "$title by $author";
}
$content .= "". __("Source:","dws_attributron-2000") ."
$return
";
}
return $content;
}
function filter_the_content($content) {
global $post;
$options = get_option('dws_' . $this->slug);
$return = "";
if (is_single() || is_page()) {
$attachments = get_children("post_parent=$post->ID&post_type=attachment");
if ($attachments) {
foreach ($attachments as $attachment_id => $attachment) {
$meta = get_post_custom($attachment_id);
if (get_post_meta($attachment_id,"_credit",true)) {
if (get_post_meta($attachment_id,"_link",true)) {
$author = get_post_meta($attachment_id,"_credit",true);
$author = get_post_meta($attachment_id,"_credit",true);
$link = get_post_meta($attachment_id,"_link",true);
$author = "$author";
} else {
$author = get_post_meta($attachment_id,"_credit",true);
}
$title = "" . get_the_title($attachment_id) . "";
$copyright = $this->license_slug_to_html(get_post_meta($attachment_id,"_copyright",true));
if ($copyright) {
$return .= "$title $copyright $author";
} else {
$return .= "$title by $author";
}
}
}
$content .= "". __("Sources:","dws_attributron-2000") ."
$return
";
}
}
return $content;
}
function license_slug_to_html($slug) {
global $post;
$options = get_option('dws_' . $this->slug);
if (is_single() || is_page()) $use_images = $options["use-images-on-post"];
if (is_attachment()) $use_images = $options["use-images-on-attachment"];
switch ($slug) {
case "c":
$copyright = "©";
break;
case "cc-by":
$copyright = 'CC BY';
if ($use_images) {
$copyright = '
';
}
break;
case "cc-by-sa":
$copyright = 'CC BY-SA';
if ($use_images) {
$copyright = '
';
}
break;
case "cc-by-nc":
$copyright = 'CC BY-NC';
if ($use_images) {
$copyright = '
';
}
break;
case "cc-by-nd":
$copyright = 'CC BY-ND';
if ($use_images) {
$copyright = '
';
}
break;
case "cc-by-nc-sa":
$copyright = 'CC BY-NC-SA';
if ($use_images) {
$copyright = '
';
}
break;
case "cc-by-nc-nd":
$copyright = 'CC BY-NC-ND';
if ($use_images) {
$copyright = '
';
}
break;
case "pd":
$copyright = "". __("Public Domain","dws_attributron-2000") ."";
break;
case "fu":
$copyright = "". __("Fair Use","dws_attributron-2000") ."";
break;
}
return $copyright;
}
function select_image_text() {
echo ''. __("For more information about Flickr API keys, visit their Flickr Services page.
","dws_attributron-2000") ."
";
}
function select_image_on_post() {
$options = get_option('dws_' . $this->slug);
?>
value="1" id="slug . '-use-images-on-post'; ?>" name="slug; ?>[use-images-on-post]">
slug);
?>
value="1" id="slug . '-use-images-on-attachment'; ?>" name="slug; ?>[use-images-on-attachment]">
slug);
?>
" id="slug . '-flickr-api-key'; ?>" name="slug; ?>[flickr-api-key]" />
slug);
?>
" id="slug . '-flickr-api-secret'; ?>" name="slug; ?>[flickr-api-secret]" />
slug);
// http://net.tutsplus.com/tutorials/wordpress/creating-custom-fields-for-attachments-in-wordpress/ Thanks!
$form_fields["credit"] = array(
"label" => __("Author"),
"input" => "text",
"value" => get_post_meta($post->ID, "_credit", true)
);
$form_fields["link"] = array(
"label" => __("Author Link"),
"input" => "text",
"value" => get_post_meta($post->ID, "_link", true),
"helps" => "If you have a Flickr API key entered into the plugin settings, you can paste the Flickr image URL here to auto-populate the fields."
);
$form_fields["copyright"] = array(
"label" => __("Copyright"),
"input" => "html",
"html" => "
",
"value" => get_post_meta($post->ID, "_copyright", true)
);
return $form_fields;
}
function filter_attachment_fields_to_save($post, $attachment) {
if (isset($attachment['credit']) ){
update_post_meta($post['ID'], '_credit', $attachment['credit']);
update_post_meta($post['ID'], '_copyright', $attachment['copyright']);
update_post_meta($post['ID'], '_link', $attachment['link']);
}
return $post;
}
function plugin_construct() {
$options = array();
$options['use-images-on-attachment'] = 'on';
update_option('dws_' . $this->slug,$options);
}
function plugin_destruct() {
delete_option('dws_' . $this->slug);
}
}
$local_blogs = new DWS_Attributron_2000();
}