Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/meks-the.../inc
File: class-themeforest-widget.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/* ThemeForest Widget Class */
[2] Fix | Delete
[3] Fix | Delete
class MKS_ThemeForest_Widget extends WP_Widget {
[4] Fix | Delete
[5] Fix | Delete
var $tf_cats; //ThemeForest items categories
[6] Fix | Delete
var $exclude; //Wheter to exclude items or not
[7] Fix | Delete
var $defaults;
[8] Fix | Delete
[9] Fix | Delete
function __construct() {
[10] Fix | Delete
$widget_ops = array( 'classname' => 'mks_themeforest_widget', 'description' => __( 'Display ThemeForest items with this widget', 'meks-themeforest-smart-widget' ) );
[11] Fix | Delete
$control_ops = array( 'id_base' => 'mks_themeforest_widget' );
[12] Fix | Delete
parent::__construct( 'mks_themeforest_widget', __( 'Meks ThemeForest Smart Widget', 'meks-themeforest-smart-widget' ), $widget_ops, $control_ops );
[13] Fix | Delete
[14] Fix | Delete
$this->tf_cats = array(
[15] Fix | Delete
array( 'name' => 'wordpress', 'title' => 'WordPress' ),
[16] Fix | Delete
array( 'name' => 'site-templates', 'title' => 'Site Templates' ),
[17] Fix | Delete
array( 'name' => 'psd-templates', 'title' => 'PSD Templates' ),
[18] Fix | Delete
array( 'name' => 'cms-themes', 'title' => 'CMS Themes' ),
[19] Fix | Delete
array( 'name' => 'ecommerce', 'title' => 'eCommerce' ),
[20] Fix | Delete
array( 'name' => 'blogging', 'title' => 'Blogging' ),
[21] Fix | Delete
array( 'name' => 'marketing', 'title' => 'Marketing' ),
[22] Fix | Delete
array( 'name' => 'forums', 'title' => 'Forums' ),
[23] Fix | Delete
array( 'name' => 'muse-templates', 'title' => 'Muse Templates' ),
[24] Fix | Delete
array( 'name' => 'typeengine-themes', 'title' => 'TypeEngine Themes' )
[25] Fix | Delete
);
[26] Fix | Delete
[27] Fix | Delete
$this->exclude = array();
[28] Fix | Delete
[29] Fix | Delete
if ( !is_admin() ) {
[30] Fix | Delete
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
[31] Fix | Delete
} else {
[32] Fix | Delete
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
$this->defaults = array(
[36] Fix | Delete
'title' => 'ThemeForest',
[37] Fix | Delete
'description' => '',
[38] Fix | Delete
'items_type' => array( 'wordpress' ),
[39] Fix | Delete
'items_from' => 'user',
[40] Fix | Delete
'user' => 'meks',
[41] Fix | Delete
'num_items' => 9,
[42] Fix | Delete
'orderby' => 'uploaded_on',
[43] Fix | Delete
'ref' => 'meks',
[44] Fix | Delete
'more_link_url' => 'https://themeforest.net/user/meks/portfolio?ref=meks',
[45] Fix | Delete
'more_link_txt' => __( 'View more', 'meks-themeforest-smart-widget' ),
[46] Fix | Delete
'order' => 'desc',
[47] Fix | Delete
'target' => '_blank',
[48] Fix | Delete
'exclude' => '',
[49] Fix | Delete
'nofollow' => 0,
[50] Fix | Delete
'token' => ''
[51] Fix | Delete
);
[52] Fix | Delete
[53] Fix | Delete
//Allow themes or plugins to modify default parameters
[54] Fix | Delete
$this->defaults = apply_filters( 'mks_tf_widget_modify_defaults', $this->defaults );
[55] Fix | Delete
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
[59] Fix | Delete
function widget( $args, $instance ) {
[60] Fix | Delete
extract( $args );
[61] Fix | Delete
$instance = wp_parse_args( (array) $instance, $this->defaults );
[62] Fix | Delete
$title = apply_filters( 'widget_title', $instance['title'] );
[63] Fix | Delete
[64] Fix | Delete
echo $before_widget;
[65] Fix | Delete
[66] Fix | Delete
if ( !empty( $title ) ) {
[67] Fix | Delete
echo $before_title . $title . $after_title;
[68] Fix | Delete
} ?>
[69] Fix | Delete
[70] Fix | Delete
<?php if ( !empty( $instance['description'] ) ) : ?>
[71] Fix | Delete
<p><?php echo nl2br( $instance['description'] );?></p>
[72] Fix | Delete
<?php endif; ?>
[73] Fix | Delete
[74] Fix | Delete
<?php
[75] Fix | Delete
[76] Fix | Delete
if ( isset( $instance['exclude'] ) && !empty( $instance['exclude'] ) ) {
[77] Fix | Delete
$this->exclude = explode( ',', $instance['exclude'] );
[78] Fix | Delete
$this->exclude = array_map( 'absint', $this->exclude );
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
$this->token = $instance['token'];
[82] Fix | Delete
[83] Fix | Delete
$items = array();
[84] Fix | Delete
$order = false;
[85] Fix | Delete
switch ( $instance['items_from'] ) {
[86] Fix | Delete
case 'popular': $items = $this->get_popular_items( $instance['items_type'] ); break;
[87] Fix | Delete
case 'latest': $items = $this->get_latest_items( $instance['items_type'] ); break;
[88] Fix | Delete
default:
[89] Fix | Delete
if ( !empty( $instance['user'] ) ) {
[90] Fix | Delete
$users = array_map( 'trim', explode( ',', $instance['user'] ) );
[91] Fix | Delete
$items = $this->get_items_from_users( $users, $instance['items_type'] );
[92] Fix | Delete
[93] Fix | Delete
} break;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
if ( !empty( $items ) ):
[97] Fix | Delete
[98] Fix | Delete
if( $instance['items_from'] == 'user'){
[99] Fix | Delete
[100] Fix | Delete
$this->orderby = $instance['orderby'];
[101] Fix | Delete
$this->items_order = $instance['order'];
[102] Fix | Delete
[103] Fix | Delete
if ( $this->orderby != 'random' ) {
[104] Fix | Delete
usort( $items, array( $this, "cmp" ) );
[105] Fix | Delete
} else {
[106] Fix | Delete
shuffle( $items );
[107] Fix | Delete
}
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
$items = array_slice( $items, 0, absint( $instance['num_items'] ) );
[111] Fix | Delete
$ref = !empty( $instance['ref'] ) ? '?ref='.$instance['ref'] : '';
[112] Fix | Delete
$target = !empty( $instance['target'] ) ? $instance['target'] : '_blank';
[113] Fix | Delete
$nofollow = $instance['nofollow'] ? 'rel="nofollow"' : '';
[114] Fix | Delete
$noopener = $target == '_blank' ? 'rel="noopener"' : '';
[115] Fix | Delete
[116] Fix | Delete
?>
[117] Fix | Delete
[118] Fix | Delete
<ul class="mks_themeforest_widget_ul">
[119] Fix | Delete
<?php foreach ( $items as $item ) : ?>
[120] Fix | Delete
<li><a href="<?php echo esc_url( $item['url'].$ref ); ?>" title="<?php echo esc_attr( $item['item'] ); ?>" target="<?php echo $target; ?>" <?php echo $nofollow; ?>><img width="80" height="80" src="<?php echo esc_url( $item['thumbnail'] );?>" alt="<?php echo esc_attr( $item['item'] ); ?> "/></a></li>
[121] Fix | Delete
<?php endforeach; ?>
[122] Fix | Delete
</ul>
[123] Fix | Delete
[124] Fix | Delete
<?php if ( !empty( $instance['more_link_url'] ) ): ?>
[125] Fix | Delete
<?php $more_text = isset( $instance['more_link_txt'] ) && !empty( $instance['more_link_txt'] ) ? $instance['more_link_txt'] : __( 'View more', 'meks-themeforest-smart-widget' ); ?>
[126] Fix | Delete
<p class="mks_read_more"><a href="<?php echo esc_url( $instance['more_link_url'] ); ?>" target="_blank" class="more" <?php echo esc_attr( $nofollow ); ?> <?php echo esc_attr( $noopener ); ?>><?php echo esc_html( $more_text ); ?></a></p>
[127] Fix | Delete
<?php endif; ?>
[128] Fix | Delete
<?php endif; ?>
[129] Fix | Delete
[130] Fix | Delete
<?php
[131] Fix | Delete
echo $after_widget;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
function update( $new_instance, $old_instance ) {
[135] Fix | Delete
$instance = $old_instance;
[136] Fix | Delete
$instance['title'] = strip_tags( $new_instance['title'] );
[137] Fix | Delete
$instance['description'] = strip_tags( $new_instance['description'] );
[138] Fix | Delete
$instance['user'] = strip_tags( $new_instance['user'] );
[139] Fix | Delete
$instance['num_items'] = absint( $new_instance['num_items'] );
[140] Fix | Delete
$instance['exclude'] = strip_tags( $new_instance['exclude'] );
[141] Fix | Delete
$instance['ref'] = strip_tags( $new_instance['ref'] );
[142] Fix | Delete
$instance['orderby'] = strip_tags( $new_instance['orderby'] );
[143] Fix | Delete
$instance['more_link_url'] = $new_instance['more_link_url'];
[144] Fix | Delete
$instance['more_link_txt'] = $new_instance['more_link_txt'];
[145] Fix | Delete
$instance['order'] = $new_instance['order'];
[146] Fix | Delete
$instance['items_type'] = $new_instance['items_type'];
[147] Fix | Delete
$instance['items_from'] = $new_instance['items_from'];
[148] Fix | Delete
$instance['target'] = $new_instance['target'];
[149] Fix | Delete
$instance['nofollow'] = isset( $new_instance['nofollow'] ) ? 1 : 0;
[150] Fix | Delete
$instance['token'] = strip_tags( $new_instance['token'] );
[151] Fix | Delete
return $instance;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
function form( $instance ) {
[155] Fix | Delete
[156] Fix | Delete
$instance = wp_parse_args( (array) $instance, $this->defaults ); ?>
[157] Fix | Delete
[158] Fix | Delete
<p>
[159] Fix | Delete
<label for="<?php echo $this->get_field_id( 'title' ); ?>">
[160] Fix | Delete
<?php _e( 'Title', 'meks-themeforest-smart-widget' ); ?>:</label>
[161] Fix | Delete
<input id="<?php echo $this->get_field_id( 'title' ); ?>" type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" class="widefat" />
[162] Fix | Delete
</p>
[163] Fix | Delete
<p>
[164] Fix | Delete
<label for="<?php echo $this->get_field_id( 'description' ); ?>">
[165] Fix | Delete
<?php _e( 'Description', 'meks-themeforest-smart-widget' ); ?>:</label>
[166] Fix | Delete
<textarea id="<?php echo $this->get_field_id( 'description' ); ?>" rows="5" name="<?php echo $this->get_field_name( 'description' ); ?>" class="widefat"><?php echo $instance['description']; ?></textarea>
[167] Fix | Delete
</p>
[168] Fix | Delete
<p>
[169] Fix | Delete
<label for="<?php echo $this->get_field_id( 'token' ); ?>">
[170] Fix | Delete
<?php _e( 'Envato API token', 'meks-themeforest-smart-widget' ); ?>:</label>
[171] Fix | Delete
<input id="<?php echo $this->get_field_id( 'token' ); ?>" type="text" name="<?php echo $this->get_field_name( 'token' ); ?>" value="<?php echo esc_attr( strip_tags( $instance['token'] ) ); ?>" class="widefat" />
[172] Fix | Delete
<small class="howto"><?php _e( 'It is highly recommended to provide your Envato API token as using the service without it will be discontinued soon.', 'meks-themeforest-smart-widget' ); ?></small>
[173] Fix | Delete
<small class="howto"><?php echo '<a href="https://build.envato.com/create-token/" target="_blank">'.__( 'Generate token', 'meks-themeforest-smart-widget' ).'</a>'; ?></small>
[174] Fix | Delete
[175] Fix | Delete
</p>
[176] Fix | Delete
<p>
[177] Fix | Delete
<label for="<?php echo $this->get_field_id( 'num_items' ); ?>">
[178] Fix | Delete
<?php _e( 'Number of items to show', 'meks-themeforest-smart-widget' ); ?>:</label>
[179] Fix | Delete
<input id="<?php echo $this->get_field_id( 'num_items' ); ?>" type="number" name="<?php echo $this->get_field_name( 'num_items' ); ?>" value="<?php echo absint( $instance['num_items'] ); ?>" class="widefat" />
[180] Fix | Delete
</p>
[181] Fix | Delete
<p>
[182] Fix | Delete
<label>
[183] Fix | Delete
<?php _e( 'Select items from', 'meks-themeforest-smart-widget' ); ?>:</label><br />
[184] Fix | Delete
<input id="<?php echo $this->get_field_id( 'select_from_popular' ); ?>" type="radio" name="<?php echo $this->get_field_name( 'items_from' ); ?>" value="popular" <?php checked( $instance['items_from'], 'popular' );?> class="meks-themeforest-smart-widget-type" /> <label for="<?php echo $this->get_field_id( 'select_from_popular' ); ?>">
[185] Fix | Delete
<?php _e( 'Popular Items (WordPress Only)', 'meks-themeforest-smart-widget' ); ?></label><br />
[186] Fix | Delete
<input id="<?php echo $this->get_field_id( 'select_from_latest' ); ?>" type="radio" name="<?php echo $this->get_field_name( 'items_from' ); ?>" value="latest" <?php checked( $instance['items_from'], 'latest' );?> class="meks-themeforest-smart-widget-type" /> <label for="<?php echo $this->get_field_id( 'select_from_latest' ); ?>">
[187] Fix | Delete
<?php _e( 'Latest Items', 'meks-themeforest-smart-widget' ); ?></label><br />
[188] Fix | Delete
<input id="<?php echo $this->get_field_id( 'select_from_user' ); ?>" type="radio" name="<?php echo $this->get_field_name( 'items_from' ); ?>" value="user" <?php checked( $instance['items_from'], 'user' );?> class="meks-themeforest-smart-widget-type" /> <label for="<?php echo $this->get_field_id( 'select_from_user' ); ?>">
[189] Fix | Delete
<?php _e( 'Specific User(s)', 'meks-themeforest-smart-widget' ); ?></label>
[190] Fix | Delete
</p>
[191] Fix | Delete
<p class="meks-themeforest-smart-widget-user" <?php echo $this->selected( $instance['items_from'], 'user', 'style="display:none;"', true ); ?>>
[192] Fix | Delete
<label for="<?php echo $this->get_field_id( 'user' ); ?>">
[193] Fix | Delete
<?php _e( 'ThemeForest username(s)', 'meks-themeforest-smart-widget' ); ?>:</label>
[194] Fix | Delete
<input id="<?php echo $this->get_field_id( 'user' ); ?>" type="text" name="<?php echo $this->get_field_name( 'user' ); ?>" value="<?php echo strip_tags( $instance['user'] ); ?>" class="widefat" />
[195] Fix | Delete
<small class="howto"><?php _e( 'For multiple users, separate by comma: i.e. user1,user2,user3', 'meks-themeforest-smart-widget' ); ?></small>
[196] Fix | Delete
</p>
[197] Fix | Delete
<p class="meks-themeforest-smart-widget-cat" <?php echo $this->selected( $instance['items_from'], 'popular', 'style="display:none;"'); ?>>
[198] Fix | Delete
<label>
[199] Fix | Delete
<?php _e( 'Item categories to show', 'meks-themeforest-smart-widget' ); ?>:</label><br />
[200] Fix | Delete
<?php foreach ( $this->tf_cats as $cat ) : ?>
[201] Fix | Delete
<input id="<?php echo $this->get_field_id( $cat['name'].'_id' ); ?>" type="checkbox" name="<?php echo $this->get_field_name( 'items_type' ); ?>[]" value="<?php echo esc_attr( $cat['name'] ); ?>" <?php echo in_array( $cat['name'], $instance['items_type'] ) ? 'checked' : '' ; ?> /> <label for="<?php echo $this->get_field_id( $cat['name'].'_id' ); ?>">
[202] Fix | Delete
<?php echo $cat['title']; ?></label><br />
[203] Fix | Delete
<?php endforeach; ?>
[204] Fix | Delete
</p>
[205] Fix | Delete
<p class="meks-themeforest-smart-widget-order" <?php echo $this->selected( $instance['items_from'], 'user', 'style="display:none;"', true ); ?>>
[206] Fix | Delete
<label>
[207] Fix | Delete
<?php _e( 'Order by', 'meks-themeforest-smart-widget' ); ?>:</label>
[208] Fix | Delete
<select id="<?php echo $this->get_field_id( 'orderby' ); ?>" name="<?php echo $this->get_field_name( 'orderby' ); ?>" value="<?php echo esc_attr( $instance['orderby'] ); ?>" class="widefat">
[209] Fix | Delete
<option value="uploaded_on" <?php selected( $instance['orderby'], 'uploaded_on' );?>>
[210] Fix | Delete
<?php _e( 'Upload date', 'meks-themeforest-smart-widget' ); ?>
[211] Fix | Delete
</option>
[212] Fix | Delete
<option value="last_update" <?php selected( $instance['orderby'], 'last_update' );?>>
[213] Fix | Delete
<?php _e( 'Last update', 'meks-themeforest-smart-widget' ); ?>
[214] Fix | Delete
</option>
[215] Fix | Delete
<option value="sales" <?php selected( $instance['orderby'], 'sales' );?>>
[216] Fix | Delete
<?php _e( 'Number of sales', 'meks-themeforest-smart-widget' ); ?>
[217] Fix | Delete
</option>
[218] Fix | Delete
<option value="cost" <?php selected( $instance['orderby'], 'cost' );?>>
[219] Fix | Delete
<?php _e( 'Price', 'meks-themeforest-smart-widget' ); ?>
[220] Fix | Delete
</option>
[221] Fix | Delete
<option value="random" <?php selected( $instance['orderby'], 'random' );?>>
[222] Fix | Delete
<?php _e( 'Random', 'meks-themeforest-smart-widget' ); ?>
[223] Fix | Delete
</option>
[224] Fix | Delete
</select>
[225] Fix | Delete
</p>
[226] Fix | Delete
<p class="meks-themeforest-smart-widget-order" <?php echo $this->selected( $instance['items_from'], 'user', 'style="display:none;"', true ); ?>>
[227] Fix | Delete
<input id="<?php echo $this->get_field_id( 'order_asc' ); ?>" type="radio" name="<?php echo $this->get_field_name( 'order' ); ?>" value="asc" <?php checked( $instance['order'], 'asc' );?> /> <label for="<?php echo $this->get_field_id( 'order_asc' ); ?>">
[228] Fix | Delete
<?php _e( 'Ascending', 'meks-themeforest-smart-widget' ); ?></label>
[229] Fix | Delete
<input id="<?php echo $this->get_field_id( 'order_desc' ); ?>" type="radio" name="<?php echo $this->get_field_name( 'order' ); ?>" value="desc" <?php checked( $instance['order'], 'desc' );?> /> <label for="<?php echo $this->get_field_id( 'order_desc' ); ?>">
[230] Fix | Delete
<?php _e( 'Descending', 'meks-themeforest-smart-widget' ); ?></label>
[231] Fix | Delete
</p>
[232] Fix | Delete
<p>
[233] Fix | Delete
<label for="<?php echo $this->get_field_id( 'exclude' ); ?>">
[234] Fix | Delete
<?php _e( 'Exclude item(s)', 'meks-themeforest-smart-widget' ); ?>:</label>
[235] Fix | Delete
<input id="<?php echo $this->get_field_id( 'exclude' ); ?>" type="text" name="<?php echo $this->get_field_name( 'exclude' ); ?>" value="<?php echo strip_tags( $instance['exclude'] ); ?>" class="widefat" />
[236] Fix | Delete
<small class="howto"><?php _e( 'Specify item ID to exclude specific item (separate by comma for multiple items): i.e. 8134834,7184572', 'meks-themeforest-smart-widget' ); ?></small>
[237] Fix | Delete
</p>
[238] Fix | Delete
<p>
[239] Fix | Delete
<label for="<?php echo $this->get_field_id( 'ref' ); ?>">
[240] Fix | Delete
<?php _e( 'Referral user', 'meks-themeforest-smart-widget' ); ?>:</label>
[241] Fix | Delete
<input id="<?php echo $this->get_field_id( 'ref' ); ?>" type="text" name="<?php echo $this->get_field_name( 'ref' ); ?>" value="<?php echo strip_tags( $instance['ref'] ); ?>" class="widefat" />
[242] Fix | Delete
<small class="howto"><?php _e( 'Specify username if you want to use items as ThemeForest affiliate links', 'meks-themeforest-smart-widget' ); ?></small>
[243] Fix | Delete
</p>
[244] Fix | Delete
<p>
[245] Fix | Delete
<label for="<?php echo $this->get_field_id( 'more_link_url' ); ?>">
[246] Fix | Delete
<?php _e( 'More link URL', 'meks-themeforest-smart-widget' ); ?>:</label>
[247] Fix | Delete
<input id="<?php echo $this->get_field_id( 'more_link_url' ); ?>" type="text" name="<?php echo $this->get_field_name( 'more_link_url' ); ?>" value="<?php echo esc_attr( $instance['more_link_url'] ); ?>" class="widefat" />
[248] Fix | Delete
<small class="howto"><?php _e( 'Specify URL if you want to show "more" link under the items list', 'meks-themeforest-smart-widget' ); ?></small>
[249] Fix | Delete
</p>
[250] Fix | Delete
<p>
[251] Fix | Delete
<label for="<?php echo $this->get_field_id( 'more_link_txt' ); ?>">
[252] Fix | Delete
<?php _e( 'More link text', 'meks-themeforest-smart-widget' ); ?>:</label>
[253] Fix | Delete
<input id="<?php echo $this->get_field_id( 'more_link_txt' ); ?>" type="text" name="<?php echo $this->get_field_name( 'more_link_txt' ); ?>" value="<?php echo esc_attr( $instance['more_link_txt'] ); ?>" class="widefat" />
[254] Fix | Delete
</p>
[255] Fix | Delete
<p>
[256] Fix | Delete
<label for="<?php echo $this->get_field_id( 'target' ); ?>">
[257] Fix | Delete
<?php _e( 'Open items in', 'meks-themeforest-smart-widget' ); ?>: </label>
[258] Fix | Delete
<select id="<?php echo $this->get_field_id( 'target' ); ?>" name="<?php echo $this->get_field_name( 'target' ); ?>">
[259] Fix | Delete
<option value="_blank" <?php selected( '_blank' , $instance['target'] ); ?>>
[260] Fix | Delete
<?php _e( 'New Window', 'meks-themeforest-smart-widget' ); ?>
[261] Fix | Delete
</option>
[262] Fix | Delete
<option value="_self" <?php selected( '_self' , $instance['target'] ); ?>>
[263] Fix | Delete
<?php _e( 'Same Window', 'meks-themeforest-smart-widget' ); ?>
[264] Fix | Delete
</option>
[265] Fix | Delete
</select>
[266] Fix | Delete
</p>
[267] Fix | Delete
<p>
[268] Fix | Delete
<label for="<?php echo $this->get_field_id( 'nofollow' ); ?>"><input id="<?php echo $this->get_field_id( 'nofollow' ); ?>" type="checkbox" name="<?php echo $this->get_field_name( 'nofollow' ); ?>" value="1" <?php checked( $instance['nofollow'], 1 ); ?> class="widefat" />
[269] Fix | Delete
<?php _e( 'Add rel="nofollow" to item links', 'meks-themeforest-smart-widget' ); ?>
[270] Fix | Delete
</label>
[271] Fix | Delete
</p>
[272] Fix | Delete
[273] Fix | Delete
<?php
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
function envato_request( $query ) {
[277] Fix | Delete
[278] Fix | Delete
$args = array();
[279] Fix | Delete
[280] Fix | Delete
//If token is provided we are using
[281] Fix | Delete
if ( $this->has_token() ) {
[282] Fix | Delete
$headers = array();
[283] Fix | Delete
$headers[] = 'Content-length: 0';
[284] Fix | Delete
$headers['Content-type'] = 'application/json';
[285] Fix | Delete
$headers['Authorization'] = 'Bearer '.$this->token;
[286] Fix | Delete
$args = array(
[287] Fix | Delete
'headers' => $headers
[288] Fix | Delete
);
[289] Fix | Delete
[290] Fix | Delete
$url = 'https://api.envato.com/v1/market/';
[291] Fix | Delete
[292] Fix | Delete
} else {
[293] Fix | Delete
$url = 'http://marketplace.envato.com/api/v3/';
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
$url .= $query;
[297] Fix | Delete
[298] Fix | Delete
//print_r( $url );
[299] Fix | Delete
[300] Fix | Delete
$response = wp_remote_get( $url, $args );
[301] Fix | Delete
[302] Fix | Delete
//print_r( $response );
[303] Fix | Delete
[304] Fix | Delete
//print_r( $response );
[305] Fix | Delete
[306] Fix | Delete
if ( is_wp_error( $response ) || ( wp_remote_retrieve_response_code( $response ) != 200 ) ) {
[307] Fix | Delete
return false;
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
return json_decode( wp_remote_retrieve_body( $response ), true );
[311] Fix | Delete
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
function has_token() {
[315] Fix | Delete
return isset( $this->token ) && !empty( $this->token );
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
function get_items_from_users( $users = array(), $type = array( 'wordpress' ) ) {
[319] Fix | Delete
[320] Fix | Delete
$items = array();
[321] Fix | Delete
[322] Fix | Delete
foreach ( $users as $user ) {
[323] Fix | Delete
$cached = get_transient( $this->id_base.'_'.$user );
[324] Fix | Delete
$item_data_ready = array();
[325] Fix | Delete
[326] Fix | Delete
if ( empty( $cached ) ) {
[327] Fix | Delete
[328] Fix | Delete
$query = 'new-files-from-user:'.$user.',themeforest.json';
[329] Fix | Delete
[330] Fix | Delete
$response = $this->envato_request( $query );
[331] Fix | Delete
[332] Fix | Delete
if ( !isset( $response['new-files-from-user'] ) || empty( $response['new-files-from-user'] ) ) {
[333] Fix | Delete
continue;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
$item_data_ready = $response['new-files-from-user'];
[337] Fix | Delete
set_transient( $this->id_base.'_'.$user, $item_data_ready, DAY_IN_SECONDS );
[338] Fix | Delete
[339] Fix | Delete
} else {
[340] Fix | Delete
$item_data_ready = $cached;
[341] Fix | Delete
}
[342] Fix | Delete
[343] Fix | Delete
$type_check = count( $type ) == count( $this->tf_cats ) ? false : true;
[344] Fix | Delete
[345] Fix | Delete
foreach ( $item_data_ready as $item ) {
[346] Fix | Delete
if ( !in_array( $item['id'], $this->exclude ) ) {
[347] Fix | Delete
if ( $type_check ) {
[348] Fix | Delete
if ( $this->item_type_check( trim( $item['category'] ), $type ) ) {
[349] Fix | Delete
$items[] = $item;
[350] Fix | Delete
}
[351] Fix | Delete
} else {
[352] Fix | Delete
$items[] = $item;
[353] Fix | Delete
}
[354] Fix | Delete
}
[355] Fix | Delete
}
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
return $items;
[359] Fix | Delete
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
function get_popular_items( $type = array( 'wordpress' ) ) {
[363] Fix | Delete
[364] Fix | Delete
$type = array( 'wordpress' ); //Hardcoded to WordPres only, due to current ThemeForest API limitations
[365] Fix | Delete
[366] Fix | Delete
$items = array();
[367] Fix | Delete
$cached = get_transient( $this->id_base.'_popular' );
[368] Fix | Delete
[369] Fix | Delete
$item_data_ready = array();
[370] Fix | Delete
[371] Fix | Delete
if ( empty( $cached ) ) {
[372] Fix | Delete
[373] Fix | Delete
$query = 'popular:themeforest.json';
[374] Fix | Delete
[375] Fix | Delete
$response = $this->envato_request( $query );
[376] Fix | Delete
[377] Fix | Delete
if ( !isset( $response['popular']['items_last_week'] ) || empty( $response['popular']['items_last_week'] ) ) {
[378] Fix | Delete
return $items;
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
$item_data_ready = $response['popular']['items_last_week'];
[382] Fix | Delete
set_transient( $this->id_base.'_popular', $item_data_ready, DAY_IN_SECONDS );
[383] Fix | Delete
[384] Fix | Delete
} else {
[385] Fix | Delete
$item_data_ready = $cached;
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
$type_check = count( $type ) == count( $this->tf_cats ) ? false : true;
[389] Fix | Delete
[390] Fix | Delete
foreach ( $item_data_ready as $item ) {
[391] Fix | Delete
if ( !in_array( $item['id'], $this->exclude ) ) {
[392] Fix | Delete
if ( $type_check ) {
[393] Fix | Delete
if ( $this->item_type_check( trim( $item['category'] ), $type ) ) {
[394] Fix | Delete
$items[] = $item;
[395] Fix | Delete
}
[396] Fix | Delete
} else {
[397] Fix | Delete
$items[] = $item;
[398] Fix | Delete
}
[399] Fix | Delete
}
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
return $items;
[403] Fix | Delete
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
[407] Fix | Delete
function get_latest_items( $types = array( 'wordpress' ) ) {
[408] Fix | Delete
[409] Fix | Delete
$items = array();
[410] Fix | Delete
[411] Fix | Delete
foreach ( $types as $type ) {
[412] Fix | Delete
$cached = get_transient( $this->id_base.'_'.$type );
[413] Fix | Delete
$item_data_ready = array();
[414] Fix | Delete
if ( empty( $cached ) ) {
[415] Fix | Delete
[416] Fix | Delete
$query = 'new-files:themeforest,'.$type.'.json';
[417] Fix | Delete
[418] Fix | Delete
$response = $this->envato_request( $query );
[419] Fix | Delete
[420] Fix | Delete
//print_r( $response['new-files'] );
[421] Fix | Delete
[422] Fix | Delete
if ( !isset( $response['new-files'] ) || empty( $response['new-files'] ) ) {
[423] Fix | Delete
continue;
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
$item_data_ready = $response['new-files'];
[427] Fix | Delete
set_transient( $this->id_base.'_'.$type, $item_data_ready, DAY_IN_SECONDS );
[428] Fix | Delete
[429] Fix | Delete
} else {
[430] Fix | Delete
$item_data_ready = $cached;
[431] Fix | Delete
}
[432] Fix | Delete
[433] Fix | Delete
foreach ( $item_data_ready as $item ) {
[434] Fix | Delete
if ( !in_array( $item['id'], $this->exclude ) ) {
[435] Fix | Delete
$items[] = $item;
[436] Fix | Delete
}
[437] Fix | Delete
}
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
return $items;
[441] Fix | Delete
[442] Fix | Delete
}
[443] Fix | Delete
[444] Fix | Delete
function item_type_check( $category, $types ) {
[445] Fix | Delete
[446] Fix | Delete
foreach ( $types as $type ) {
[447] Fix | Delete
if ( strpos( 'mks'.$category, $type ) ) {
[448] Fix | Delete
return true;
[449] Fix | Delete
}
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
return false;
[453] Fix | Delete
}
[454] Fix | Delete
[455] Fix | Delete
function enqueue_styles() {
[456] Fix | Delete
wp_register_style( 'meks-themeforest-widget', MTW_PLUGIN_URI . 'css/style.css', false, MKS_TF_WIDGET_VER );
[457] Fix | Delete
wp_enqueue_style( 'meks-themeforest-widget' );
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
function enqueue_scripts() {
[461] Fix | Delete
global $pagenow, $typenow;
[462] Fix | Delete
[463] Fix | Delete
if( $pagenow == 'widgets.php' ){
[464] Fix | Delete
wp_enqueue_script( 'meks-themeforest-widget', MTW_PLUGIN_URI . 'js/admin.js', array('jquery') , MKS_TF_WIDGET_VER );
[465] Fix | Delete
}
[466] Fix | Delete
}
[467] Fix | Delete
[468] Fix | Delete
function selected( $a, $b, $output, $reverse = false ) {
[469] Fix | Delete
if($reverse){
[470] Fix | Delete
return (string) $a !== (string) $b ? $output : '';
[471] Fix | Delete
} else {
[472] Fix | Delete
return (string) $a === (string) $b ? $output : '';
[473] Fix | Delete
}
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
function cmp( $a, $b ) {
[477] Fix | Delete
if ( $this->orderby == 'last_update' || $this->orderby == 'uploaded_on' ) {
[478] Fix | Delete
if ( $this->items_order == 'desc' ) {
[479] Fix | Delete
return strcmp( strtotime( $b[$this->orderby] ), strtotime( $a[$this->orderby] ) );
[480] Fix | Delete
} else {
[481] Fix | Delete
return strcmp( strtotime( $a[$this->orderby] ), strtotime( $b[$this->orderby] ) );
[482] Fix | Delete
}
[483] Fix | Delete
} else {
[484] Fix | Delete
if ( $this->items_order == 'desc' ) {
[485] Fix | Delete
return $b[$this->orderby] > $a[$this->orderby] ? true : false;
[486] Fix | Delete
} else {
[487] Fix | Delete
return $b[$this->orderby] > $a[$this->orderby] ? false : true;
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
}
[491] Fix | Delete
}
[492] Fix | Delete
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
?>
[496] Fix | Delete
[497] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function