This repository has been archived by the owner on Sep 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
external-media.php
144 lines (127 loc) · 4.73 KB
/
external-media.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/*
Plugin Name: External Media
Plugin URI:
Description: A plugin for sell media to reference external sites
Version: 0.0.1
Author: Harald Walker
Author URI:
Author Email: [email protected]
License: GPL
*/
if (!class_exists('externalMedia')) {
class externalMedia {
function externalMedia() {
$this->version = "0.0.1";
}
function external_media_meta_box($fields=null) {
global $post;
if ( is_array( $fields ) ){
$my_fields = $fields;
} else {
global $sell_media_item_meta_fields;
$my_fields = $sell_media_item_meta_fields;
}
$not_for_sale = get_post_meta( $post->ID, 'external_media_disabled_sale', true );
$sale_link = get_post_meta( $post->ID, 'external_media_sales_link', true );
$sale_agency = get_post_meta( $post->ID, 'external_media_agency', true );
include ("item-settings.php");
}
function external_media_save_custom_meta($post_id) {
if ( isset( $_POST[ 'external_media_disabled_sale' ] ) ){
update_post_meta( $post_id, 'external_media_disabled_sale', 1 );
} else {
delete_post_meta( $post_id, 'external_media_disabled_sale', 1 );
}
if ( isset( $_POST[ 'external_media_sales_link' ] ) ){
$old = get_post_meta( $post_id, 'external_media_sales_link', true );
$new = $_POST[ 'external_media_sales_link' ];
if ('' == $new) {
delete_post_meta( $post_id, 'external_media_sales_link');
} elseif ( $new && $new != $old ) {
update_post_meta( $post_id, 'external_media_sales_link', $new );
}
}
if ( isset( $_POST[ 'external_media_agency' ] ) ){
$old = get_post_meta( $post_id, 'external_media_agency', true );
$new = $_POST[ 'external_media_agency' ];
if ('' == $new) {
delete_post_meta( $post_id, 'external_media_agency');
} elseif ( $new && $new != $old ) {
update_post_meta( $post_id, 'external_media_agency', $new );
}
}
}
function external_media_item_header( $columns ){
$columns_local = array();
$columns_local['external_media_disabled_sale'] = "Disabled";
return array_merge( $columns_local, $columns );
}
function external_media_item_content( $column, $post_id ){
switch( $column ) {
case "external_media_disabled_sale":
$this->external_media_item_status( $post_id );
break;
default:
break;
}
}
function external_media_item_status($post_id) {
$sale_disabled = get_post_meta( $post_id, 'external_media_disabled_sale', true );
if ( $sale_disabled && $sale_disabled == '1' ) {
$sale_link = get_post_meta( $post_id, 'external_media_sales_link', true );
if ( !empty( $sale_link )) {
echo '<a target="_blank" href="'.$sale_link.'">Link</a>';
} else {
echo "X";
}
}
}
}
}
/**
* Print the buy button, depending on settings
*
* @access public
* @return html
*/
function external_media_item_buy_button($post_id=null, $button=null, $text=null, $echo=true) {
$prefix = 'sell_media';
$sale_disabled = get_post_meta( $post_id, 'external_media_disabled_sale', true );
if ( $sale_disabled && $sale_disabled == '1' ) {
$sale_link = get_post_meta( $post_id, 'external_media_sales_link', true );
if ( !empty( $sale_link )) {
$agency = get_post_meta( $post_id, 'external_media_agency', true );
$text = apply_filters('sell_media_purchase_text', __( $text,'sell_media' ), $post_id );
if ( !empty( $agency )) {
$text = $text.' from '.external_media_agency_list($agency, false);
}
$html = '<a target="_blank" href="'.$sale_link.'" class="sell-media-buy-' . $button . '">'.$text.'</a>';
} else {
$html = '<div class="sell-media-buy-' . $button . '">not for sale</div>';
}
} else {
$html = sell_media_item_buy_button($post_id, $button, $text, $echo);
}
if ( $echo ) print $html; else return $html;
}
function external_media_agency_list( $current=null, $create_select=true ){
$items = array(
"AL" => "Alamy",
"GY" => "Getty",
"IS" => "iStock",
"SY" => "Stocksy",
"TS" => "Thinkstock",
"CB" => "Corbis"
);
if ( $create_select ) {
sell_media_build_select( $items, array( 'name' => 'external_media_agency', 'required' => false, 'title' => 'Agency', 'current' => $current ) );
} else {
return $items[$current];
}
}
$externalMedia = new externalMedia();
add_filter( 'manage_edit-sell_media_item_columns', array(&$externalMedia,'external_media_item_header' ));
add_filter( 'manage_pages_custom_column', array(&$externalMedia,'external_media_item_content'), 10, 2 );
add_action( 'sell_media_additional_item_meta_section', array(&$externalMedia, 'external_media_meta_box' ));
add_action( 'save_post', array(&$externalMedia, 'external_media_save_custom_meta' ));