· 5 years ago · Mar 13, 2020, 06:54 AM
1<?php
2
3class SimpleImagePoster {
4static public function sip_plugin_menu(){
5
6 add_menu_page('Quantum Grabber', 'Quantum Grabber', 'manage_options', 'simple-image-poster', array('SimpleImagePoster', 'sip_panel'));
7 add_submenu_page( 'simple-image-poster', __('Bulk Poster', 'simple-image-poster'), __('Bulk Poster', 'simple-image-poster'), 'manage_options', 'simple-image-poster',array('SimpleImagePoster', 'sip_panel'));
8
9 $cek_lic_params = array(
10 'slm_action' => 'slm_check',
11 'secret_key' => QTM_SPECIAL_SECRET_KEY,
12 'license_key' => get_option('sample_license_key'),
13 );
14 // Send query to the license manager server
15 $response = wp_remote_get(add_query_arg($cek_lic_params, QTM_LICENSE_SERVER_URL), array('timeout' => 30, 'sslverify' => false));
16 //print_r($response);
17 $license_data = json_decode(wp_remote_retrieve_body($response));
18 //if($license_data->result == 'success'){
19 add_submenu_page( 'simple-image-poster', __('Keywords', 'simple-image-poster'), __('Keywords', 'simple-image-poster'), 'manage_options', 'simple-image-savekw',array('SimpleImagePoster', 'save_kw_html'));
20 //}
21 //elseif($license_data->message === 'License key already in use on '.$_SERVER['SERVER_NAME']) {
22 //echo $license_data->message;
23
24 // add_submenu_page( 'simple-image-poster', __('Keywords', 'simple-image-poster'), __('Keywords', 'simple-image-poster'), 'manage_options', 'simple-image-savekw',array('SimpleImagePoster', 'save_kw_html'));
25 // }
26 //print_r ($license_data);
27 add_submenu_page( 'simple-image-poster', __('Template', 'simple-image-poster'), __('Template', 'simple-image-poster'), 'manage_options', 'simple-image-template',array('SimpleImagePoster', 'sip_template'));
28 add_submenu_page( 'simple-image-poster', __('Setting', 'simple-image-poster'), __('Setting', 'simple-image-poster'), 'manage_options', 'simple-image-setting',array('SimpleImagePoster', 'sip_setting'));
29 add_submenu_page( 'simple-image-poster', __('Post Management', 'simple-image-poster'), __('Post Management', 'simple-image-poster'), 'manage_options', 'simple-image-post-management',array('SimpleImagePoster', 'post_management'));
30}
31static public function post_management(){
32 if(isset($_REQUEST['nonce_token'])) {
33 $nonce = $_REQUEST[ 'nonce_token' ];
34 $postid = $_REQUEST[ 'post' ];
35 $nonce = wp_verify_nonce( $nonce, 'delete_att_' . $postid );
36 switch ( $nonce ) {
37 case 1:
38 echo '<div class="update-message notice inline notice-alt updated-message notice-success"><p aria-label="updated!">Images has been deleted. Back to <a href="'.admin_url('admin.php?page=simple-image-post-management').'">Post Management</p></div>';
39 $postids = self::count_img_number($postid);// get all att id from this post
40 foreach ($postids as $postid){
41 wp_delete_attachment($postid->ID,"true");
42 }
43 wp_redirect( admin_url() );
44 exit();
45 //break;
46 case 2:
47 echo '<div class="update-message notice inline notice-alt updated-message notice-success"><p aria-label="updated!">Images has been deleted. Back to <a href="'.admin_url('admin.php?page=simple-image-post-management').'">Post Management</p></div>';
48 $postids = self::count_img_number($postid);// get all att id from this post
49 foreach ($postids as $postid){
50 wp_delete_attachment($postid->ID,"true");
51 }
52 wp_redirect( admin_url() );
53 exit();
54 // break;
55 default:
56 wp_redirect( admin_url() );
57 exit( 'Illegal access, sssttt...' );
58 }
59 }
60
61 global $post;
62 $paged = isset($_GET['paged']) ? $_GET['paged'] : 1;
63
64 if ($_GET['sort'] == "few_images") {
65 $meta_query = array(
66 array(
67 'key' => '_few_images',
68 )
69 );
70
71 } else {
72 $meta_query = array(
73 array(
74 'key' => 'success_posted_field',
75 )
76 );
77 }
78 $args = array(
79 'post_type' => 'post',
80 //'post_status' => 'publish',
81 'posts_per_page' => 80,
82 'paged' => $paged,
83 'orderby'=>'date',
84 'order' => 'DESC',
85 'meta_query' => $meta_query,
86 );
87
88 $few_args = array(
89 'post_type' => 'post',
90 //'post_status' => 'publish',
91 'posts_per_page' => 80,
92 'paged' => $paged,
93 'orderby'=>'date',
94 'order' => 'DESC',
95 'meta_query' => array(
96 array(
97 'key' => '_few_images',
98 )
99 ),
100 );
101
102 $all_args = array(
103 'post_type' => 'post',
104 //'post_status' => 'publish',
105 'posts_per_page' => 80,
106 'paged' => $paged,
107 'orderby'=>'date',
108 'order' => 'DESC',
109 'meta_query' => array(
110 array(
111 'key' => 'success_posted_field',
112 )
113 ),
114 );
115
116 $few_imgs = new WP_Query($few_args);
117 $all_imgs = new WP_Query($all_args);
118 $get_posts = new WP_Query($args);
119
120 if (basename($_SERVER['REQUEST_URI']) == "admin.php?page=simple-image-post-management&sort=few_images") {
121 $is_fewpost_active = "active";
122 } else {
123 $is_allpost_active = "active";
124 }
125 //print_r($get_posts);?>
126 <div class="left-panel full-width">
127 <div class="header">
128 <h2>Post Management</h2><span class="posted-number"></span>
129 <div class="tabs">
130 <span class="tab-class <?php echo $is_allpost_active;?>"><a href="<?php echo get_option('siteurl');?>/wp-admin/admin.php?page=simple-image-post-management&sort=all_post"><?php echo "All post (".$all_imgs->found_posts.")";?></a></span>
131 <span class="tab-class <?php echo $is_fewpost_active;?>"><a href="<?php echo get_option('siteurl');?>/wp-admin/admin.php?page=simple-image-post-management&sort=few_images"><?php echo "Post with Few Images (".$few_imgs->found_posts.")";?> </a></span>
132 </div>
133 </div>
134 <?php if($get_posts->have_posts()): ?>
135 <table class="wp-list-table widefat fixed striped users">
136 <thead>
137 <td class="checkbox"><input type="checkbox" id="selectall"></td>
138 <td>Title</td>
139 <td>Keyword</td>
140 <td>Image</td>
141 <td>Date</td>
142 <td>Action</td>
143 </thead>
144 <tbody>
145 <?php while ($get_posts->have_posts() ): $get_posts->the_post();?>
146 <tr>
147 <td class="checkbox"><input type="checkbox" class="singlechekbox" value=<?php echo $post->ID;?> data-kw="<?php echo get_post_meta($post->ID, "success_posted_field", true);?>"></td>
148 <td id="post-id" style="display:none"><?php echo $post->ID;?></td>
149 <td><?php the_title();?></td>
150 <td id="kw"><?php echo get_post_meta($post->ID, "success_posted_field", true);?></td>
151 <td><?php echo count(self::count_img_number($post->ID));?> | <a id="one-grab" href="#">Grab</a> |
152 <?php
153 $url = wp_nonce_url( admin_url("/admin.php?page=simple-image-post-management"), 'delete_att_' . $post->ID, 'nonce_token' );
154 $url = add_query_arg( 'post', $post->ID, $url ); // Add the id of the user we send to
155 ?>
156 <a href="<?php echo $url; ?>"><?php _e( '<i class=" icon-trash-empty"></i>', 'textdomain' ); ?></a>
157 </td>
158 <td><?php self::sip_post_status($post);?></td>
159 <td><a title="edit post" class="item-action edit" href="<?php echo get_option('siteurl');?>/wp-admin/post.php?action=edit&post=<?php echo $post->ID;?>"><i class="icon-pencil"></i></a><a title="view post" class="item-action view" href="<?php echo get_option('siteurl');?>?p=<?php echo $post->ID;?>"><i class=" icon-eye"></i></a><a title="delete post" class="item-action delete" href="<?php echo wp_nonce_url( site_url() . "/wp-admin/post.php?action=trash&post=" . $post->ID, 'trash-post_' . $post->ID);?>" onclick="javascript:if(!confirm('Are you sure you want to move this item to trash?')) return false;"><i class="icon-trash-empty"></i></a></td>
160 </tr>
161
162 <?php endwhile; wp_reset_postdata();?>
163 </tbody>
164 </table>
165
166 <select id="bulkopt" name="bulkopt">
167 <option value="0">---</option>
168 <option value="grab">Grab Images</option>
169 <option value="delete-image">Delete Image</option>
170 <option value="delete-post">Delete Post</option>
171 <option value="delete-post-image">Delete Post and Image</option>
172 </select>
173 <input type='button' id='apply' name='apply' value='Apply'>
174
175 </div>
176 <div class="pagination">
177 <?php echo self::pagination($get_posts->max_num_pages, $paged);?>
178 </div>
179 <?php else:?>
180 <div class="left-panel">
181 <div class="update-message notice inline notice-warning notice-alt"><p class="no-post">NO POST CREATED</p></div>
182 </div>
183 <?php endif;?>
184 <div class="fixed-wrap" style="display:none">
185 <div class="right-panel">
186 <div class="header">
187 <h2>Result</h2>
188 <span class="close"><a href="<?php echo basename($_SERVER['REQUEST_URI']);?>">Close</a></span>
189 </div>
190 <div id="loader" class="loader">
191 </div>
192 <div id="done">
193 <div class="update-message notice inline notice-alt updated-message notice-success"><p aria-label="updated!">Done!</p></div>
194 </div>
195 <div class="rp-inner">
196 <ol id="sukses">
197 </ol>
198 <ol id="gagal">
199 </ol>
200 </div>
201 </div>
202 </div>
203<?php
204}
205
206static public function sip_setting(){
207 $se = array("bing"=>"bing", "google"=>"google");
208 if (get_option('search_engine')=="bing"){
209 $is_bing = "selected";
210 } else {
211 $is_google ="selected";
212 }
213 $arrSize = array('all' => 'all', 'small' => 'small', 'medium' => 'medium', 'large' => 'large', 'wallpaper' => 'wallpaper');
214 if (get_option('save_image_as')=='keyword') {
215 $is_keyword = "selected";
216 } elseif (get_option('save_image_as')=='origin') {
217 $is_origin = "selected";
218 }
219 else {
220 $is_template = "selected";
221 }
222 if (get_option("image_license")=="all"){
223 $is_all = "selected";
224 } elseif (get_option("image_license")=="all_creative_commons"){
225 $is_all_creative_commons = "selected";
226 } elseif (get_option("image_license")=="public_domain"){
227 $is_public_domain = "selected";
228 }elseif (get_option("image_license")=="free_to_share_and_use"){
229 $is_free_to_share_and_use = "selected";
230 } elseif (get_option("image_license")=="free_to_share_and_use_com") {
231 $is_free_to_share_and_use_com = "selected";
232 } elseif(get_option("image_license")=="free_to_modify_share_and_use"){
233 $is_free_to_modify_share_and_use = "selected";
234 } else {
235 $is_free_to_modify_share_and_use_com = "selected";
236 }
237
238
239 // $str_flip_disable = "";
240 // $is_image_flipped ="";
241 // $is_flip_available = false;
242 // if (function_exists('imageflip')) {
243 // $is_flip_available = true;
244 // } else {
245 // $str_flip_disable = "disabled";
246 // }
247 if (get_option('save_image')==1) {
248 $is_save_image=' checked ';
249 }
250 if (get_option('save_mode')==1) {
251 $is_save_mode=' checked ';
252 }
253 if (get_option('reset_img_metadata')==1) {
254 $is_image_flipped=' checked ';
255 }
256 $is_cron_loop='';
257 if (get_option('sip_cron_kw_loop')==1)
258 $is_cron_loop=' checked ';
259 $is_save_ori='';
260 if (get_option('save_ori_filename')==1)
261 $is_save_ori=' checked ';
262
263 ?>
264<div class="wrap">
265<div class="left-panel">
266 <div class="header">
267 <h2>Image Setting</h2>
268 </div>
269 <div class="item-setting">
270 <label>Search Engine</label>
271 <select id="search_engine" name="search_engine">
272 <?php foreach ($se as $idx => $value) {
273 $sel = "";
274 if ($idx == get_option('search_engine') ) $sel = ' selected ';?>
275 <option value="<?php echo $idx;?>" <?php echo $sel;?>><?php echo $value;?></option>
276 <?php }?>
277 </select>
278 </div>
279 <div class="item-setting">
280 <label>Save Image to Server</label>
281 <?php //echo get_option("save_mode");?>
282 <input type="checkbox" id="save_image" name="save_image"
283 <?php echo $is_save_image;?> value=1 /> <?php echo "Yes";?>
284 </div>
285 <div class="item-setting">
286 <label>Save hosting</label>
287 <?php //echo get_option("save_mode");?>
288 <input type="checkbox" id="save_mode" name="save_mode"
289 <?php echo $is_save_mode;?> value=1 /> <?php echo "Yes";?>
290 </div>
291 <div class="item-setting">
292 <label>Image number each post</label>
293 <input size=3 id="num_image" name="num_image" value="<?php echo get_option('num_image');?>" />
294 </div>
295 <div class="item-setting">
296 <label>Image size</label>
297 <select id="img_size" name="img_size">
298 <?php foreach ($arrSize as $idx => $value) {
299 $sel = "";
300 if ($idx == get_option('img_size') ) $sel = ' selected ';?>
301 <option value="<?php echo $idx;?>" <?php echo $sel;?>><?php echo $value;?></option>
302 <?php }?>
303 </select>
304 </div>
305 <div class="item-setting">
306 <label>Image License</label>
307 <select id="image_license" name="image_license">
308 <option value="all" <?php echo $is_all;?>>All</option>
309 <option value="all_creative_commons" <?php echo $is_all_creative_commons;?>>All Creative Commons</option>
310 <option value="public_domain" <?php echo $is_public_domain;?>>Public Domain</option>
311 <option value="free_to_share_and_use" <?php echo $is_free_to_share_and_use;?>>Free to share and Use</option>
312 <option value="free_to_share_and_use_com" <?php echo $is_free_to_share_and_use_com;?>>Free to Share and Use Commercially</option>
313 <option value="free_to_modify_share_and_use" <?php echo $is_free_to_modify_share_and_use;?>>Free to Modify, Share and Use</option>
314 <option value="free_to_modify_share_and_use_com" <?php echo $is_free_to_modify_share_and_use_com;?>>Free to Modify, Share and Use Commercially</option>
315 </select>
316 </div>
317 <div class="item-setting">
318 <label>Reset Image metadata</label>
319 <input type="checkbox" id="reset_img_metadata" name="reset_img_metadata"
320 <?php echo $is_image_flipped;?> value=1 /> <?php echo "Yes";?>
321 </div>
322 <div class="item-setting">
323 <label>Save image as:</label>
324 <select id="save_image_as" name="save_image_as">
325 <option value="origin" <?php echo $is_origin;?>>Original File Name</option>
326 <option value="keyword" <?php echo $is_keyword;?>>Keyword</option>
327 <option value="template" <?php echo $is_template;?>>Template</option>
328 </select>
329 </div>
330 <div class="item-setting">
331 <label>Grab image result only from sites:</label>
332 <?php
333 $target = get_option('target_site');
334 $target_sites=array("none", "pinterest.com", "blogspot.com", "flickr.com",
335 "pixabay.com", "amazon.com");?>
336 <select id="target_site" name="target_site">
337 <?php foreach ($target_sites as $idx => $value) {
338 $value = trim($value);
339 $sel = "";
340 if (strcmp(trim($target), $value) == 0) $sel = ' selected ';?>
341 <option value=<?php echo $value.''.$sel;?>><?php echo $value;?></option>
342 <?php }?>
343 </select>
344 <?php //echo get_option("target_site");?>
345 </div>
346 <div class="item-setting">
347 <label>Exclude website from search result:</label>
348 <input size=30 id="exclude_site" name="exclude_site" value="<?php echo get_option('exclude_site');?>" /> <span class="ket">Ex: youtube.com</span>
349 </div>
350</div>
351<div class="right-panel">
352 <div class="header">
353 <h2>CRON Setting</h2>
354 </div>
355 <div class="item-setting">
356 <label>Category</label>
357 <?php
358 $cron_cat = get_option('cron_category');
359 wp_dropdown_categories(array(
360 'hide_empty' => 0,
361 'name' => 'cron_category',
362 'orderby' => 'name',
363 'selected' => $cron_cat,
364 'hierarchical' => true,
365 'show_option_none' => __('None')));
366 ?>
367 </div>
368 <div class="item-setting">
369 <label>Start Post Date</label>
370 <?php
371 $base_date = mktime(0, 0, 0, (int)get_option('date_month'), (int)get_option('date_day'), (int)get_option('date_year'));
372 //echo get_option('date_month')."-".get_option('date_day')."-".get_option('date_year');
373
374 echo self::show_day();
375 echo self::show_month();
376 echo self::show_year();
377 ?>
378 </div>
379 <div class="item-setting">
380 <label>Post Interval</label>
381 <input type="text" value=<?php echo get_option("interval_num");?> name="interval[value]" id="interval_num" style="width:40px;">
382 <?php
383 if (get_option("interval_type")=="hours"){
384 $is_hours = "selected";
385 }
386 else {
387 $is_days = "selected";
388 }
389 ?>
390 <select name="interval[type]" id="interval_type">
391 <option value="hours"<?php echo $is_hours;?>>Hour</option>
392 <option value="days" <?php echo $is_days;?>>Day</option>
393 </select>
394 </div>
395 <div class="item-setting">
396 <?php
397 if (get_option("cron_post_status")=="publish"){
398 $is_publish = "selected";
399 } else {
400 $is_draft ="selected";
401 }
402 ?>
403 <label>Post Status</label>
404 <select name="cron_post_status" id="cron_post_status">
405 <option value="publish" <?php echo $is_publish;?>>Published</option>
406 <option value="draft" <?php echo $is_draft;?>>Draft</option>
407 </select>
408 </div>
409 <div class="item-setting">
410 <label>Post again after last keyword</label>
411 <input type="checkbox" id="sip_cron_kw_loop" name="sip_cron_kw_loop" <?php echo $is_cron_loop;?>
412 value=1 /><?php echo "Yes";?>
413 </div>
414</div>
415<input type='button' id='save_setting' name='submit' value='Save Settings' />
416<div id="saved"></div>
417</div>
418<?php
419}
420static public function sip_template(){
421 $template = get_option('post_template');
422 $title_template = get_option('title_template');
423 $attachment_title_template = get_option('attachment_title_template');
424 $attachment_filename_template = get_option('attachment_filename_template');
425 $attachment_caption_template = htmlspecialchars(get_option('attachment_caption_template'));
426 $attachment_description_template = htmlspecialchars(get_option('attachment_description_template'));
427 ?>
428<div class="wrap">
429<div class="left-panel">
430 <div class="header">
431 <h2>Templates</h2>
432 </div>
433 <div class="item-setting">
434 <label>Title Template</label><br>
435 <input type="text" id="title_template" name="title_template" value="<?php echo $title_template;?>"><br />
436 </div>
437 <div class="item-setting">
438 <label>Post Template</label>
439 <textarea name="post_template" id="post_template" cols="75" rows="20"><?php echo $template;?></textarea><br />
440 </div>
441 <div class="item-setting">
442 <label>Attachment Filename Template</label><br>
443 <input type="text" id="attachment_filename_template" name="attachment_filename_template"
444 value="<?php echo $attachment_filename_template;?>">
445 </div>
446 <div class="item-setting">
447 <label>Attachment Title Template</label><br>
448 <input type="text" id="attachment_title_template" name="attachment_title_template"
449 value="<?php echo $attachment_title_template;?>">
450 </div>
451 <div class="item-setting">
452 <label>Attachment Caption Template</label><br>
453 <input type="text" id="attachment_caption_template" name="attachment_caption_template"
454 value="<?php echo $attachment_caption_template;?>">
455 </div>
456 <div class="item-setting">
457 <label>Attachment Description Template</label><br>
458 <input type="text" id="attachment_description_template" name="attachment_description_template"
459 value="<?php echo $attachment_description_template;?>">
460 </div>
461 <input type='button' id='save_template' name='submit' value='Save Post Template' />
462</div>
463<div class="right-panel">
464 <div class="header">
465 <h2>Documentation</h2>
466 </div>
467 <div class="item-setting">
468 <label>Title Template Shortcodes</label><br>
469 <ul class="shortcode-list">
470 <li><p><span class="sc">{IMG_NUMBER}</span>: Number of images uploaded to its post</p></li>
471 <li><p><span class="sc">{POST_KEYWORD}</span>: keyword for its post</p></li>
472 </ul>
473 <label>Post Template Shortcodes</label><br>
474 <ul class="shortcode-list">
475 <li><p><span class="sc">{IMG_NUMBER}</span>: Number of images uploaded to its post</p></li>
476 <li><p><span class="sc">{POST_KEYWORD}</span>: keyword for its post</p></li>
477 <li><p><span class="sc">{PERMALINK}</span>: permalink for its post</p></li>
478 <li><p><span class="sc">{POST_TITLE}</span>: title for its post</p></li>
479 <li><p><span class="sc">{POST_CATEGORY}</span>: category for its post</p></li>
480 <li><p><span class="sc">{GALLERY}</span>: gallery for its post</p></li>
481 <li><p><span class="sc">{IMG_X}</span>: Display image number X</p></li>
482 <li><p><span class="sc">{IMG_SRC_X}</span>: Display image source number x that uploaded for its post. ex: IMG_SRC_1</p></li>
483 <li><p><span class="sc">{IMG_TITLE_X}</span>: Display image title number x that uploaded for its post. ex: IMG_TITLE_1</p></li>
484 <li><p><span class="sc">{ARTICLE}</span>: Generate article based on keyword</p></li>
485 <li><p><span class="sc">{IMG}</span>: Insert all images that uploaded to its post</p></li>
486
487 </ul>
488 <label>Attachment Filename Template Shortcodes</label><br>
489 <ul class="shortcode-list">
490 <li><p><span class="sc">{POST_KEYWORD}</span>: keyword from its parent post</p></li>
491 <li><p><span class="sc">{IMG_TITLE}</span>: image title grabbed from remote server</p></li>
492 <li><p><span class="sc">{IMG_FILENAME}</span>: image filename grabbed from remote server</p></li>
493 </ul>
494
495 <label>Attachment Title Template Shortcodes</label><br>
496 <ul class="shortcode-list">
497 <li><p><span class="sc">{POST_KEYWORD}</span>: keyword from its parent post</p></li>
498 <li><p><span class="sc">{IMG_TITLE}</span>: image title grabbed from remote server</p></li>
499 <li><p><span class="sc">{IMG_FILENAME}</span>: image filename grabbed from remote server</p></li>
500 </ul>
501 <label>Attachment Caption Template Shortcodes</label><br>
502 <ul class="shortcode-list">
503 <li><p><span class="sc">{POST_KEYWORD}</span>: keyword from its parent post</p></li>
504 <li><p><span class="sc">{IMG_TITLE}</span>: image title grabbed from remote server</p></li>
505 <li><p><span class="sc">{IMG_FILENAME}</span>: image filename grabbed from remote server</p></li>
506 <li><p><span class="sc">{IMG_LINK}</span>: image link from remote server</p></li>
507 <li><p><span class="sc">{IMG_DOMAIN}</span>: Domain name of grabbed image</p></li>
508 </ul>
509 <label>Attachment Description Template Shortcodes</label><br>
510 <ul class="shortcode-list">
511 <li><p><span class="sc">{POST_KEYWORD}</span>: keyword from its parent post</p></li>
512 <li><p><span class="sc">{IMG_TITLE}</span>: image title grabbed from remote server</p></li>
513 <li><p><span class="sc">{IMG_FILENAME}</span>: image filename grabbed from remote server</p></li>
514 <li><p><span class="sc">{IMG_LINK}</span>: image link from remote server</p></li>
515 <li><p><span class="sc">{IMG_DOMAIN}</span>: Domain name of grabbed image</p></li>
516 </ul>
517 </div>
518</div>
519</div>
520<?php }
521
522static public function save_kw_html(){?>
523<div class="wrap">
524<div class="left-panel">
525<div class="header">
526 <h2>Keywords</h2>
527</div>
528<?php if (isset($_REQUEST['campaign']) ){
529 echo $_REQUEST['campaign'];
530 }
531 else {?>
532 <form name="frmPost" method="post">
533 <div class="item-setting">
534 <label>Add keywords here (one per line)</label>
535 <textarea name="add_kw" id="add_kw" cols="60" rows="20"></textarea><br>
536 <input type='button' id='remove_duplicate' name='remove_duplicate' value='Remove Duplicate' />
537 <input type='button' id='save_kw' name='submit' value='Saved Keyword' /><br>
538 <label>Saved Keyword</label>
539 <textarea name="kw_list" id="kw_list" cols="60" rows="20" disabled><?php echo get_option('sip_saved_kw');?></textarea>
540 <input type='button' id='delete_kw' name='submit' value='Delete Keyword' /><br>
541 </div>
542</form>
543<?php }?>
544</div>
545</div>
546<?php }
547
548static public function sip_panel(){
549 // include_once('fetchimage.php');
550 // $fetchimage = new FetchImage();
551 // $images = $fetchimage->google_image_grab("ford fiesta 2014");
552 // print_r($images);
553 ?>
554<div class="wrap">
555
556<div class="left-panel">
557 <div class="header">
558 <h2>Bulk Poster</h2>
559 </div>
560 <form name="frmPost" method="post">
561 <div class="item-setting">
562 <label>Keywords</label>
563 <?php
564 $kw_posted = self::get_meta_values('success_posted_field', 'post');
565 $arr_sip_saved_kw = explode("\n", get_option('sip_saved_kw'));
566 ?>
567 <select name="bulk_post_titles[]" id="bulk_post_titles" multiple="multiple" size="10">
568 <?php
569 foreach($arr_sip_saved_kw as $sip_saved_kw) {
570 if (in_array($sip_saved_kw, $kw_posted)) {?>
571 <option value="<?php echo $sip_saved_kw;?>" disabled><?php echo $sip_saved_kw;?></option>
572 <?php }
573 else {?>
574 <option value="<?php echo $sip_saved_kw;?>"><?php echo $sip_saved_kw;?></option>
575 <?php }?>
576 <?php }?>
577 </select>
578 <?php
579 if (get_option('sip_saved_kw')=="") {
580 echo "<div>Your keyword is empty, fill <a href=".site_url("/wp-admin/admin.php?page=simple-image-savekw").">here</a></div>";
581 } else {
582 echo "<div>".count($arr_sip_saved_kw)." keywords</div>";
583 }?>
584 </div>
585 <div class="item-setting">
586 <label>Category</label>
587 <?php
588 wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'category', 'orderby' => 'name',
589 'selected' => $cron_cat, 'hierarchical' => true, 'show_option_none' => __('None')));
590 ?>
591 </div>
592 <div class="item-setting">
593 <label>Post Status</label>
594 <select name="bulk_post_status" id="bulk_post_status">
595 <option value="publish">Published</option>
596 <option value="draft">Draft</option>
597 </select>
598 </div>
599 <div class="item-setting">
600 <label>Start Post Date</label>
601 <?php
602 echo self::show_day();
603 echo self::show_month();
604 echo self::show_year();
605 ?>
606 </div>
607 <div class="item-setting">
608 <label>Post Interval</label>
609 <input type="text" value="1" name="interval[value]" id="interval_num" style="width:40px;">
610 <select name="interval[type]" id="interval_type">
611 <option value="hours">Hour</option>
612 <option value="days">Day</option>
613 </select>
614 </div>
615 <input type='button' id='bulk-post' name='submit' value='Create Bulk Post' />
616 </form>
617</div>
618
619<div class="right-panel">
620 <div class="header">
621 <h2>Result</h2>
622 </div>
623 <div id="loader" class="loader">
624 </div>
625 <div id="done">
626 <div class="update-message notice inline notice-alt updated-message notice-success"><p aria-label="updated!">Done!</p></div>
627 </div>
628 <div class="rp-inner">
629 <ol id="sukses">
630 </ol>
631 <ol id="gagal">
632 </ol>
633 </div>
634</div>
635</div>
636<?php
637}
638public function get_title_template($title, $id) {
639 $template = get_option('title_template');
640 if ($template==""){
641 $template = "{POST_KEYWORD}";
642 }
643 $args1 = array(
644 'post_type'=>'attachment',
645 'posts_per_page'=>-1,
646 'post_parent'=>$id
647 );
648 $allphotos = get_posts($args1);
649 $imgnumber = count($allphotos);
650 $template = str_replace('{POST_KEYWORD}', $title, $template);
651 $template = str_replace('{IMG_NUMBER}', $imgnumber, $template);
652 return $template;
653}
654public function get_att_title_template($kw, $title, $localurl) {
655
656 $img_filename = preg_replace('/\.[^.]+$/', '', basename($localurl));
657 $img_filename = str_replace("-", " ", $img_filename);
658 $template = get_option('attachment_title_template');
659 if ($template==""){
660 $template = "{IMG_TITLE}";
661 }
662 $template = str_replace('{POST_KEYWORD}', $kw, $template);
663 $template = str_replace('{IMG_TITLE}', $title, $template);
664 $template = str_replace('{IMG_FILENAME}', $img_filename, $template);
665 return $template;
666}
667
668public function get_filename_template($kw, $title, $localurl) {
669
670 $img_filename = preg_replace('/\.[^.]+$/', '', basename($localurl));
671 //$img_filename = str_replace("-", " ", $img_filename);
672 $kw = str_replace("-", " ", $kw);
673 $template = get_option('attachment_filename_template');
674 if ($template==""){
675 $template = "{IMG_FILENAME}";
676 }
677 $template = str_replace('{POST_KEYWORD}', $kw, $template);
678 $template = str_replace('{IMG_TITLE}', $title, $template);
679 $template = str_replace('{IMG_FILENAME}', $img_filename, $template);
680 return $template;
681}
682
683public function get_caption_template($kw, $title, $localurl, $domain, $imglink) {
684
685 $img_filename = preg_replace('/\.[^.]+$/', '', basename($localurl));
686 $img_filename = str_replace("-", " ", $img_filename);
687 $kw = str_replace("-", " ", $kw);
688 $domain = $domain;
689 $imglink = $imglink;
690 $template = get_option('attachment_caption_template');
691 if ($template==""){
692 $template = "source: {IMG_DOMAIN}";
693 }
694 $template = str_replace('{POST_KEYWORD}', $kw, $template);
695 $template = str_replace('{IMG_TITLE}', $title, $template);
696 $template = str_replace('{IMG_FILENAME}', $img_filename, $template);
697 $template = str_replace('{IMG_DOMAIN}', $domain, $template);
698 $template = str_replace('{IMG_LINK}', $imglink, $template);
699 return $template;
700}
701
702public function get_description_template($kw, $title, $localurl, $domain, $imglink) {
703
704 $img_filename = preg_replace('/\.[^.]+$/', '', basename($localurl));
705 $img_filename = str_replace("-", " ", $img_filename);
706 $kw = str_replace("-", " ", $kw);
707 $domain = $domain;
708 $imglink = $imglink;
709 $template = get_option('attachment_description_template');
710 if ($template==""){
711 $template = "source: {IMG_TITLE}";
712 }
713 $template = str_replace('{POST_KEYWORD}', $kw, $template);
714 $template = str_replace('{IMG_TITLE}', $title, $template);
715 $template = str_replace('{IMG_FILENAME}', $img_filename, $template);
716 $template = str_replace('{IMG_DOMAIN}', $domain, $template);
717 $template = str_replace('{IMG_LINK}', $imglink, $template);
718 return $template;
719}
720
721public function post_title_shortcode(){
722 global $post;
723 return get_the_title();
724}
725public function download_image(){
726 $kw = $_POST['kw'];
727 $imgsrc = $_POST['imgsrc'];
728 $post_id = $_POST['id'];
729 $idx = $_POST['idx'];
730 $imgtitle =$_POST['imgtitle'];
731 $domain = $_POST['domain'];
732 $imglink = $_POST['imglink'];
733
734 $att_title = self::get_att_title_template($kw, $imgtitle, $imgsrc);
735 $filename_template = self::get_filename_template($kw, $imgtitle, $imgsrc);
736 $caption_template = self::get_caption_template($kw, $imgtitle, $imgsrc, $domain, $imglink);
737 $description_template = self::get_description_template($kw, $imgtitle, $imgsrc, $domain, $imglink);
738
739 require_once 'spintax.php';
740 $spin = new Spintax();
741
742 $att_title = $spin->process($att_title);
743 $filename_spinned = $spin->process($filename_template);
744 $caption_spinned = $spin->process($caption_template);
745 $description_spinned = $spin->process($description_template);
746
747 if (get_option("save_image")==1) {
748 require_once( ABSPATH . 'wp-admin/includes/file.php' );
749
750 // URL to the image from remote server.
751 $url = preg_replace('/\?.*/', '', "$imgsrc");
752 $timeout_seconds = 30;
753
754 // Download file to temp dir.
755 $temp_file = download_url( $url, $timeout_seconds );
756 //print_r($temp_file);
757 if ( ! is_wp_error( $temp_file ) ) {
758
759 // Array based on $_FILE as seen in PHP file uploads.
760
761 if (get_option("save_image_as")=="keyword"){
762 $ext = pathinfo($url, PATHINFO_EXTENSION);
763 $filename = $kw."-".$idx.".".$ext;
764 } elseif (get_option("save_image_as")=="origin") {
765 $filename = basename($url);
766 } else {
767 $ext = pathinfo($url, PATHINFO_EXTENSION);
768 $filename = $filename_spinned.".".$ext;
769 }
770
771 $file = array(
772 //'name' => basename($url), // ex: wp-header-logo.png
773 'name' => $filename,
774 //'type' => 'image/png',
775 'tmp_name' => $temp_file,
776 'error' => 0,
777 'size' => filesize( $temp_file ),
778 );
779
780 $overrides = array(
781 'test_form' => false,
782 'test_size' => true,
783 'test_upload' => true,
784 );
785
786 // Move the temporary file into the uploads directory.
787 $results = wp_handle_sideload( $file, $overrides );
788 //print_r($results);
789 if ( ! empty( $results['error'] ) ) {
790 // Insert any error handling here.
791 echo json_encode(array("status"=>0,"desc"=>"Fail to move to uploads directory","idx"=>$ext) );
792 } else {
793 $filename = $results['file']; // Full path to the file.
794 $local_url = $results['url']; // URL to the file in the uploads dir.
795 $type = $results['type']; // MIME type of the file.
796
797 // Perform any actions here based in the above results.
798
799 $post_data = array(
800 'post_mime_type' => $type,
801 'guid' => $local_url,
802 'post_title' => $att_title,
803 'post_excerpt' => $caption_spinned,
804 'post_content' => $description_spinned,
805 );
806 $attach_id = wp_insert_attachment( $post_data, $filename, $post_id);
807
808 if ($attach_id){
809 update_post_meta($attach_id, '_wp_attachment_image_alt', $imgtitle);
810 if (get_option("save_mode")==0){
811 wp_update_attachment_metadata( $attach_id, wp_generate_attachment_metadata( $attach_id, $filename ) );
812 }
813 echo json_encode(array("status"=>1,"desc"=>"Success attached to post","id"=>$attach_id, "img_src"=>wp_get_attachment_image_src($attach_id, "full"), "idx"=>$idx ) );
814 } else {
815 echo json_encode(array("status"=>2, "desc"=>"Success move the temporary file into the uploads directory", "idx"=>$idx) );
816 }
817 }
818 }
819 else {
820 echo json_encode(array("status"=>3,"desc"=>"Fail to download", "idx"=>$idx) );
821 }
822 }
823 else {
824 echo json_encode(array("status"=>1,"desc"=>"Success attached to post","id"=>0, "img_src"=>$imgsrc, "idx"=>$idx ) );
825 }
826
827
828 die();
829}
830public function create_post(){
831 ini_set('max_execution_time', 300);
832 $params = $_POST;
833 $title = trim($params['bulk_post_title']);
834 //$title = $kw;
835 $key = $params['current'];
836 $total = $params['total'];
837 $post_status = $_POST['bulk_post_status'];
838 $base_date = mktime(0, 0, 0, (int)$params['date_month'], (int)$params['date_day'], (int)$params['date_year']);
839 $post_interval = '+' . ($params['interval_num'] * $key) . ' ' . $params['interval_type'];
840 $post_time = strtotime($post_interval, $base_date);
841 $post_time = date('Y-m-d H:i:s', $post_time);
842 //echo $title;
843 include_once('fetchimage.php');
844 $fetchimage = new FetchImage();
845
846
847 $post_tag = $fetchimage->getKeywordSuggestionsFromGoogle($title);
848 // //echo $judul."<br/>";
849 $new_draft_post = array(
850 'post_title' => $title,
851 'post_content' => '',
852 'post_category' => array($params['category']),
853 'post_status' =>$post_status,
854 'tags_input' => $post_tag,
855 'post_date' => $post_time,
856 );
857 $new_draft_id = wp_insert_post($new_draft_post);
858 // echo $new_draft_id;
859 if ($new_draft_id) {
860 update_post_meta($new_draft_id, 'success_posted_field', $title);
861 if (get_option("search_engine") == "bing"){
862 $images = $fetchimage->get_bing_image($title, 50, get_option('target_site'), get_option("exclude_site"), get_option("img_size"), get_option("image_license"));
863 } else {
864 //$images = $fetchimage->get_google_image2($title);
865 //Google API
866 //$images = $fetchimage->get_google_image($title, 30, "none", $imgSize = "large", false, "AIzaSyD4Tv3qwbdKZ9aNkrrug-nr257wWEP_m9g", "018135149211235252173:lbrb5q6a_0g");
867 $images = $fetchimage->google_image_grab($title);
868 }
869 $i=0;
870 foreach($images as $image){
871 if ($i++ > get_option('num_image')) break;
872 $imgsrcs[] = $image['mediaurl'];
873 $imgtitle[] = $image['title'];
874 $imgthumb[] = $image['thumbnail'];
875 $imglink[] = $image['link'];
876 $host[] = parse_url($image['link'], PHP_URL_HOST);
877 }
878 echo json_encode(array("imgsrc"=>$imgsrcs, "imgtitle"=>$imgtitle, "id"=>$new_draft_id,"kw"=>$title, "imgthumb"=>$imgthumb, "imglink"=>$imglink, "host"=>$host, "num_img"=>get_option('num_image')));
879 //print_r($images);
880 }
881 die();
882 //return true;
883 }
884public function attach_image_to_post(){
885 $imgsrc = $_POST['imgsrc'];
886 $new_draft_id = $_POST['id'];
887 $kw = $_POST['kw'];
888 $idx = $_POST['idx'];
889 $wp_upload_dir = wp_upload_dir();
890 $wp_filetype = wp_check_filetype(basename($imgsrc), null);
891 $desc = null;
892 $imgtitle = $_POST['imgtitle'];
893 $file = array();
894
895 if(get_option('save_image_as')=='keyword') {// save as kw
896 $file['name'] = $kw.".jpg";
897 }else{
898 $file['name'] = basename($imgsrc);
899 }
900 $file['tmp_name'] = download_url($imgsrc);
901 if (is_wp_error($file['tmp_name'])):
902 @unlink($file['tmp_name']);
903 return NULL;
904 endif;
905 $post_data = array(
906 'post_mime_type' => $wp_filetype['type'],
907 'guid' => $wp_upload_dir['url'] .$imgsrc,
908 'post_title' => basename($imgsrc),
909 'post_content' => "",
910 );
911 $attach_id = media_handle_sideload($file, $new_draft_id, $desc, $post_data);
912 update_post_meta($attach_id, '_wp_attachment_image_alt', $kw);
913 $attach_data = wp_generate_attachment_metadata( $attach_id, get_attached_file($attach_id));
914 wp_update_attachment_metadata( $attach_id, $attach_data );
915 $data = json_encode(array("id"=>$attach_id, "imgtitle"=>$imgtitle) );
916 print_r($data);
917
918 die();
919}
920public function one_grab(){
921 $title = $_POST['kw'];
922 $id = $_POST['id'];
923 include_once('fetchimage.php');
924 $fetchimage = new FetchImage();
925 if (get_option("search_engine") == "bing"){
926 $images = $fetchimage->get_bing_image($title, 50, get_option('target_site'), get_option("exclude_site"), get_option("img_size"), get_option("image_license"));
927 } else {
928 $images = $fetchimage->google_image_grab($title);
929 }
930 $i=0;
931 foreach($images as $image){
932 if ($i++ > get_option('num_image')) break;
933 $imgsrcs[] = $image['mediaurl'];
934 $imgtitle[] = $image['title'];
935 $imgthumb[] = $image['thumbnail'];
936 $imglink[] = $image['link'];
937 $host[] = parse_url($image['link'], PHP_URL_HOST);
938 }
939 echo json_encode(array("imgsrc"=>$imgsrcs, "imgtitle"=>$imgtitle, "id"=>$id,"kw"=>$title, "imgthumb"=>$imgthumb, "imglink"=>$imglink, "host"=>$host, "num_img"=>get_option('num_image')));
940
941 die();
942}
943public function zero_image_posted(){
944 $id = $_POST['id'];
945 update_post_meta($id, '_few_images', 0);
946 echo "saved";
947 die();
948}
949public function count_image_posted(){
950 $id = $_POST['id'];
951 $kw = $_POST['kw'];
952 $imgsrcs = $_POST["imgsrc"];
953 $imgtitles =$_POST["imgtitle"];
954 $template = get_option("post_template");
955 include_once('fetchimage.php');
956 $fetchimage = new FetchImage();
957 $article = $fetchimage->get_article($kw);
958 if ($template==""){
959 $template = '{We have collected all our best {POST_KEYWORD} in one place.| You have just found the right place about {POST_KEYWORD}.}
960 These are our {images|photos|gallery|pictures} collection about <b>{POST_KEYWORD}</b>.
961 <img src="{IMG_SRC_4}" tag="{IMG_TITLE_4}">
962 {IMG_TITLE_4}
963 <img src="{IMG_SRC_2}" tag="{IMG_TITLE_2}">
964 {IMG_TITLE_2}
965 <img src="{IMG_SRC_3}" tag="{IMG_TITLE_3}">
966 {IMG_TITLE_3}
967 You can explore more about {POST_CATEGORY} on this site. I hope you will be inspired about <a href="{PERMALINK}">{POST_KEYWORD}</a>.';
968 }
969 $args1 = array(
970 'post_type'=>'attachment',
971 'posts_per_page'=>-1,
972 'post_parent'=>$id
973 );
974 $allphotos = get_posts($args1);
975 $count = count($allphotos);
976 if (!$imgsrcs){
977 $count = 0;
978 }
979 if ($count<4){
980 update_post_meta($id, '_few_images', $count);
981 } else {
982 delete_post_meta($id, '_few_images');
983 }
984
985 //print_r($data);
986 $i=1;
987 if (get_option("save_image")==1){
988 foreach($allphotos as $allphoto){
989 $img_src = wp_get_attachment_image_src($allphoto->ID, "full");
990 $image = get_post($allphoto->ID);
991 $template = str_replace("{IMG_SRC_".$i."}", $img_src[0], $template);
992 $template = str_replace("{IMG_".$i."}", "<img src='".$img_src[0]."' alt='{IMG_TITLE_".$i."}'><p class='wp-caption-text'>".$image->post_excerpt."</p>", $template);
993 $template = str_replace("{IMG_TITLE_".$i."}", get_the_title($allphoto->ID), $template);
994 $template = str_replace("{IMG_CAPTION_".$i."}", "<p class='wp-caption-text'>".$image->post_excerpt."</p>", $template);
995 $img .= "<img src='".$img_src[0]."' alt='".$image->post_title."'><p class='wp-caption-text'>".$image->post_excerpt."</p>";
996 $i++;
997 }
998 } else {
999 foreach($imgsrcs as $imgsrc){
1000 $template = str_replace("{IMG_".$i."}", "<img src='".$imgsrcs[$i-1]."' alt='".$imgtitles[$i-1]."'>", $template);
1001 $template = str_replace("{IMG_SRC_".$i."}", $imgsrcs[$i-1], $template);
1002 $template = str_replace("{IMG_TITLE_".$i."}", $imgtitles[$i-1], $template);
1003 $img .= "<img src='".$imgsrcs[$i-1]."' alt='".$imgtitles[$i-1]."'><p class='wp-caption-text'>".$imgtitles[$i-1]."</p>";
1004 $i++;
1005 }
1006 }
1007 $template = str_replace("{IMG}", $img, $template);
1008 $template = str_replace("{POST_KEYWORD}", get_post_meta($id, "success_posted_field", true), $template);
1009 $template = str_replace("{PERMALINK}", get_the_permalink($id), $template);
1010 $template = str_replace("{POST_TITLE}", get_the_title($id), $template);
1011 $template = str_replace("{POST_CATEGORY}", get_the_category( $id )[0]->name, $template);
1012 $template = str_replace("{GALLERY}", "[gallery orderby='rand' size='medium' columns='4' link='post']", $template);
1013 $template = str_replace("{ARTICLE}", $article, $template);
1014
1015 require_once 'spintax.php';
1016 $spin = new Spintax();
1017 $template = $spin->process($template);
1018
1019 $post_title = self::get_title_template(get_post_meta($id, "success_posted_field", true), $id);
1020 $post_title = $spin->process($post_title);
1021
1022 $my_post = array(
1023 'ID' => $id,
1024 'post_title' =>$post_title,
1025 'post_content' => $template,
1026 );
1027 wp_update_post( $my_post );
1028
1029
1030 echo json_encode(array("count"=>$count,"link"=>get_the_permalink($id), "template"=>$template ) );
1031
1032 die();
1033}
1034public function bulk_grab(){
1035 $id = $_POST['id'];
1036 $kws = $_POST['element'];
1037 $idxs = $_POST['idx'];
1038 include_once('fetchimage.php');
1039 $fetchimage = new FetchImage();
1040
1041 $title = get_post_meta($id, "success_posted_field", true);
1042 if (get_option("search_engine") == "bing"){
1043 $images = $fetchimage->get_bing_image($title, 50, get_option('target_site'), get_option("exclude_site"), get_option("img_size"), get_option("image_license"));
1044 } else {
1045 $images = $fetchimage->google_image_grab($title);
1046 }
1047 $i=0;
1048 foreach($images as $image){
1049 if ($i++ > get_option('num_image')) break;
1050 $imgsrcs[] = $image['mediaurl'];
1051 $imgtitle[] = $image['title'];
1052 $imgthumb[] = $image['thumbnail'];
1053 $imglink[] = $image['link'];
1054 $host[] = parse_url($image['link'], PHP_URL_HOST);
1055 }
1056 echo json_encode(array("imgsrc"=>$imgsrcs, "imgtitle"=>$imgtitle, "id"=>$id,"kw"=>$title, "imgthumb"=>$imgthumb, "imglink"=>$imglink, "host"=>$host, "num_img"=>get_option('num_image')));
1057 //print_r($bing_images);
1058 //echo $idx;
1059 die();
1060}
1061public function bulk_delete_image(){
1062 $ids = $_POST['ids'];
1063 $i = 0;
1064 foreach ($ids as $id) {
1065 $postids = self::count_img_number($id);// get all att id from this post
1066 foreach ($postids as $postid){
1067 wp_delete_attachment($postid->ID,"true");
1068 $i++;
1069 }
1070 }
1071 echo "<p>".$i." images has been deleted from ".count($ids)." post</p>";
1072 die();
1073}
1074public function bulk_delete_post(){
1075 $ids = $_POST['ids'];
1076 $i = 0;
1077 foreach ($ids as $id) {
1078 wp_delete_post($id,"true");
1079 $i++;
1080 }
1081 echo "<p>".$i." posts has been deleted</p>";
1082 die();
1083}
1084public function bulk_delete_post_and_image(){
1085 $ids = $_POST['ids'];
1086 $j = 0;
1087 foreach ($ids as $id) {
1088 $postids = self::count_img_number($id);// get all att id from this post
1089 foreach ($postids as $postid){
1090 wp_delete_attachment($postid->ID,"true");
1091 $j++;
1092 }
1093 }
1094 $i = 0;
1095 foreach ($ids as $id) {
1096 wp_delete_post($id,"true");
1097 $i++;
1098 }
1099 echo "<p>".$i." posts and ".$j." images has been deleted</p>";
1100
1101 die();
1102}
1103public function get_posts(){
1104 $post_id = $_POST['id'];
1105 echo get_post_meta($post_id, "success_posted_field", true);
1106 die();
1107 return true;
1108}
1109static public function quantum_cron() {
1110 include_once('fetchimage.php');
1111 $fetchimage = new FetchImage();
1112 require_once 'spintax.php';
1113 $spin = new Spintax();
1114
1115 // $ls_kw = get_option('sip_saved_kw');
1116 $idx = get_option('sip_kw_index');
1117 $post_status = get_option('cron_post_status');
1118 $post_category = get_option('cron_category');
1119 $isKWLoop = get_option('sip_cron_kw_loop');
1120 $base_date = mktime(0, 0, 0, (int)get_option('date_month'), (int)get_option('date_day'), (int)get_option('date_year'));
1121 $post_interval = '+' . (get_option('interval_num') * $idx) . ' ' . get_option('interval_type');
1122 $post_time = strtotime($post_interval, $base_date);
1123 $post_time = date('Y-m-d H:i:s', $post_time);
1124
1125 $arr = explode("\n", get_option('sip_saved_kw'));
1126 if ($idx == "" || $idx > count($arr) - 1 && $isKWLoop == 1) {
1127 $idx = 0;
1128 }
1129 if (count($arr) > $idx) {
1130 $kw = $arr[$idx];
1131 $article = $fetchimage->get_article($kw);
1132 //$kw = str_replace(" ","-", $kw);
1133 update_option('sip_kw_index', ($idx + 1));
1134 if ($kw != "") {
1135 $post_tag = $fetchimage->getKeywordSuggestionsFromGoogle($kw);
1136 $new_draft_post = array(
1137 'post_title' => $kw,
1138 'post_content' => "",
1139 'post_category' => array($post_category),
1140 'post_status' =>$post_status,
1141 'tags_input' => $post_tag,
1142 'post_date' => $post_time,
1143 );
1144 $post_id = wp_insert_post($new_draft_post);
1145 update_post_meta($post_id, 'success_posted_field', $kw);
1146
1147 $bing_images = $fetchimage->get_bing_image($kw, 13, get_option("target_site"), get_option("exclude_site"), get_option("img_size"), get_option("image_license"));
1148 $i=0;
1149 foreach($bing_images as $bing_image){
1150 if ($i++ > get_option('num_image')) break;
1151 $imgsrcs[] = $bing_image['mediaurl'];
1152 $imgtitle[] = $bing_image['title'];
1153 $imgthumb[] = $bing_image['thumbnail'];
1154 $imglink[] = $bing_image['link'];
1155 $host[] = parse_url($bing_image['link'], PHP_URL_HOST);
1156
1157 }
1158 $results = array("imgsrc"=>$imgsrcs, "imgtitle"=>$imgtitle, "id"=>$new_draft_id,"kw"=>$title, "imgthumb"=>$imgthumb, "imglink"=>$imglink, "host"=>$host);
1159 if (get_option("save_image")==1) {
1160 $j = 0;
1161 foreach($results['imgsrc'] as $imgsrc){
1162 require_once( ABSPATH . 'wp-admin/includes/file.php' );
1163 $url = preg_replace('/\?.*/', '', "$imgsrc");
1164 $timeout_seconds = 20;
1165 $temp_file = download_url( $url, $timeout_seconds );
1166
1167 if ( ! is_wp_error( $temp_file ) ) {
1168 //$j++;
1169
1170 if (get_option("save_image_as")=="keyword"){
1171 $ext = pathinfo($url, PATHINFO_EXTENSION);
1172 $filename = $kw.".jpeg";
1173 } elseif (get_option("save_image_as")=="origin") {
1174 $filename = basename($url);
1175 $filename = str_replace(".jpg","", $filename);
1176 $filename = str_replace(".jpeg","", $filename);
1177 $filename = str_replace(".png", "", $filename);
1178 $filename = $filename.".jpeg";
1179 //$filename = "apalah.jpeg";
1180 } else {
1181 $ext = pathinfo($url, PATHINFO_EXTENSION);
1182 $filename_template = self::get_filename_template($kw, $imgtitle[$j], $imgsrcs[$j]);
1183 $filename_spinned = $spin->process($filename_template);
1184 $filename_spinned = str_replace(" ","-", $filename_spinned);
1185 $filename = $filename_spinned.".jpeg";
1186 }
1187 }
1188 $file = array(
1189 //'name' => basename($url), // ex: wp-header-logo.png
1190 'name' => $filename,
1191 //'name' => 'nama-file.jpeg',
1192 'type' => 'image/jpeg',
1193 'tmp_name' => $temp_file,
1194 'error' => 0,
1195 'size' => filesize( $temp_file ),
1196 );
1197
1198 $overrides = array(
1199 'test_form' => false,
1200 'test_size' => true,
1201 'test_upload' => true,
1202 );
1203
1204 // Move the temporary file into the uploads directory.
1205 $results = wp_handle_sideload( $file, $overrides );
1206 $filename = $results['file']; // Full path to the file.
1207 $local_url = $results['url']; // URL to the file in the uploads dir.
1208 $type = $results['type']; // MIME type of the file.
1209
1210 // Perform any actions here based in the above results.
1211
1212 $post_data = array(
1213 'post_mime_type' => $type,
1214 'guid' => $local_url,
1215 'post_title' => $imgtitle[$j],
1216 'post_content' => basename($url),
1217 );
1218 $attach_id = wp_insert_attachment( $post_data, $filename, $post_id );
1219 require_once( ABSPATH . 'wp-admin/includes/image.php' );
1220 if (get_option("save_mode")==0){
1221 wp_update_attachment_metadata( $attach_id, wp_generate_attachment_metadata( $attach_id, $filename ) );
1222 }
1223 $j++;
1224 }
1225 }
1226 //proses template to update the content
1227 $id = $post_id;
1228 $template = get_option("post_template");
1229 if ($template==""){
1230 $template = '{We have collected all our best {POST_KEYWORD} in one place.| You have just found the right place about {POST_KEYWORD}.}
1231 These are our {images|photos|gallery|pictures} collection about <b>{POST_KEYWORD}</b>.
1232 <img src="{IMG_SRC_4}" tag="{IMG_TITLE_4}">
1233 {IMG_TITLE_4}
1234 <img src="{IMG_SRC_2}" tag="{IMG_TITLE_2}">
1235 {IMG_TITLE_2}
1236 <img src="{IMG_SRC_3}" tag="{IMG_TITLE_3}">
1237 {IMG_TITLE_3}
1238 You can explore more about {POST_CATEGORY} on this site. I hope you will be inspired about <a href="{PERMALINK}">{POST_KEYWORD}</a>.';
1239 }
1240 $args1 = array(
1241 'post_type'=>'attachment',
1242 'posts_per_page'=>-1,
1243 'post_parent'=>$id
1244 );
1245 $allphotos = get_posts($args1);
1246 $count = count($allphotos);
1247 //print_r($data);
1248 $k=1;
1249 if (get_option("save_image")==1){
1250 foreach($allphotos as $allphoto){
1251 $img_src = wp_get_attachment_image_src($allphoto->ID, "full");
1252 $image = get_post($allphoto->ID);
1253 $template = str_replace("{IMG_SRC_".$k."}", $img_src[0], $template);
1254 $template = str_replace("{IMG_".$k."}", "<img src='".$img_src[0]."' alt='{IMG_TITLE_".$k."}'><p class='wp-caption-text'>".$image->post_excerpt."</p>", $template);
1255 $template = str_replace("{IMG_TITLE_".$k."}", get_the_title($allphoto->ID), $template);
1256 $template = str_replace("{IMG_CAPTION_".$k."}", "<p class='wp-caption-text'>".$image->post_excerpt."</p>", $template);
1257 $k++;
1258 }
1259 } else {
1260 foreach($imgsrcs as $imgsrc){
1261 $template = str_replace("{IMG_".$k."}", "<img src='".$imgsrcs[$k-1]."' alt='".$imgtitle[$k-1]."'>", $template);
1262 $template = str_replace("{IMG_SRC_".$k."}", $imgsrcs[$k-1], $template);
1263 $template = str_replace("{IMG_TITLE_".$k."}", $imgtitle[$k-1], $template);
1264 $k++;
1265 }
1266
1267 }
1268 $template = str_replace("{POST_KEYWORD}", get_post_meta($id, "success_posted_field", true), $template);
1269 $template = str_replace("{PERMALINK}", get_the_permalink($id), $template);
1270 $template = str_replace("{POST_TITLE}", get_the_title($id), $template);
1271 $template = str_replace("{POST_CATEGORY}", get_the_category( $id )[0]->name, $template);
1272 $template = str_replace("{GALLERY}", "[gallery orderby='rand' size='medium' columns='4' link='post']", $template);
1273 $template = str_replace("{ARTICLE}", $article, $template);
1274
1275
1276 $template = $spin->process($template);
1277
1278 $post_title = self::get_title_template(get_post_meta($id, "success_posted_field", true), $id);
1279 $post_title = $spin->process($post_title);
1280
1281 $my_post = array(
1282 'ID' => $post_id,
1283 'post_title' =>$post_title,
1284 'post_content' => $template,
1285 );
1286 wp_update_post( $my_post );
1287
1288 }
1289 } else {
1290 echo "End of Keyword. Cron mandek";
1291 }
1292 // wp_die();
1293 }
1294 function save_kw() {
1295 $additional_kw = $_POST['add_kw'];
1296 $additional_kw_arr = explode("\n", $additional_kw);
1297 $existed_kw = get_option("sip_saved_kw");
1298 $existed_kw_arr = explode("\n", $existed_kw);
1299 $merge_kw = array_merge($additional_kw_arr, $existed_kw_arr);
1300 $result = implode("\n", $merge_kw);
1301 if ($existed_kw){
1302 update_option("sip_saved_kw", $result);
1303 } else {
1304 update_option("sip_saved_kw", $additional_kw);
1305 }
1306 //update_option("cron_category", $_POST['category']);
1307 update_option('sip_kw_index', 0);
1308 echo "Keywords Saved";
1309 die();
1310 return true;
1311 }
1312 function delete_kw(){
1313 update_option("sip_saved_kw","");
1314 echo "Keywords has been deleted";
1315 die();
1316 }
1317 function save_template() {
1318 update_option("post_template", stripslashes($_POST['post_template']));
1319 update_option("title_template", $_POST['title_template']);
1320 update_option("attachment_title_template", $_POST['attachment_title_template']);
1321 update_option("attachment_filename_template", $_POST['attachment_filename_template']);
1322 update_option("attachment_caption_template", stripslashes($_POST['attachment_caption_template']));
1323 update_option("attachment_description_template", stripslashes($_POST['attachment_description_template']));
1324
1325 echo "Template Saved";
1326 die();
1327 return true;
1328 }
1329 function save_settings() {
1330 update_option("search_engine", $_POST['search_engine']);
1331 update_option("num_image", $_POST['num_image']);
1332 update_option("img_size", $_POST['img_size']);
1333 update_option("save_image", $_POST['save_image']);
1334 update_option("save_mode", $_POST['save_mode']);
1335 update_option("reset_img_metadata", $_POST['reset_img_metadata']);
1336 update_option("save_image_as", $_POST['save_image_as']);
1337 update_option("image_license", $_POST['image_license']);
1338 update_option("target_site", $_POST['target_site']);
1339 update_option("exclude_site", $_POST['exclude_site']);
1340 update_option("cron_category", $_POST['cron_category']);
1341 update_option("date_day", $_POST['date_day']);
1342 update_option("date_month", $_POST['date_month']);
1343 update_option("date_year", $_POST['date_year']);
1344 update_option("interval_num", $_POST['interval_num']);
1345 update_option("interval_type", $_POST['interval_type']);
1346 update_option("cron_post_status", $_POST['cron_post_status']);
1347 update_option("sip_cron_kw_loop", $_POST['sip_cron_kw_loop']);
1348 // if (isset($_POST['reset_img_metadata'])) update_option("reset_img_metadata", 1);
1349 // else update_option("reset_img_metadata", 0);
1350 echo "Saved";
1351 die();
1352 return true;
1353 }
1354 function show_year() {
1355 $cur_year = date("Y");
1356 $str = '<select name="date[year]" id="date_year">';
1357 FOR ($currentMonth = $cur_year + 2;$currentMonth >= $cur_year - 2;$currentMonth--) {
1358 $str.= "<OPTION VALUE=\"";
1359 $str.= INTVAL($currentMonth);
1360 $str.= "\"";
1361 IF ($currentMonth == get_option("date_year")) {
1362 $str.= " SELECTED";
1363 }
1364 $str.= ">" . $currentMonth . "";
1365 }
1366 $str.= "</SELECT>";
1367 return $str;
1368 }
1369 function show_month() {
1370 $monthName = ARRAY(1 => "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
1371 $useDate = TIME();
1372 $str = '<select name="date[month]" id="date_month">';
1373 FOR ($currentMonth = 1;$currentMonth <= 12;$currentMonth++) {
1374 $str.= "<OPTION VALUE=\"";
1375 $str.= INTVAL($currentMonth);
1376 $str.= "\"";
1377 IF (get_option("date_month") == $currentMonth) {
1378 $str.= " SELECTED";
1379 }
1380 $str.= ">" . $monthName[$currentMonth] . "";
1381 }
1382 $str.= "</SELECT>";
1383 return $str;
1384 }
1385 function show_day() {
1386 $useDate = TIME();
1387 $str = '<select name="date[day]" id="date_day">';
1388 FOR ($currentDay = 1;$currentDay <= 31;$currentDay++) {
1389 $str.= " <OPTION VALUE='$currentDay'";
1390 IF (get_option("date_day") == $currentDay) {
1391 $str.= " SELECTED";
1392 }
1393 $str.= ">$currentDay";
1394 }
1395 $str.= "</SELECT>";
1396 return $str;
1397 }
1398
1399 function pagination($total, $paged){
1400
1401 $pagination = paginate_links( array(
1402 'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
1403 'total' => $total,
1404 'current' => max( 1, $paged ),
1405 'format' => '?paged=%#%',
1406 'show_all' => false,
1407 'type' => 'plain',
1408 'end_size' => 2,
1409 'mid_size' => 1,
1410 'prev_next' => true,
1411 'prev_text' => sprintf( '<i class="icon icon-left-open-big"></i> %1$s', __( '', 'text-domain' ) ),
1412 'next_text' => sprintf( '%1$s <i class="icon icon-right-open-big"></i>', __( '', 'text-domain' ) ),
1413 'add_args' => false,
1414 'add_fragment' => '',
1415 ) );
1416 return $pagination;
1417 }
1418
1419 function count_img_number($id) {
1420 $args1 = array(
1421 'post_type'=>'attachment',
1422 'posts_per_page'=>-1,
1423 'post_parent'=>$id
1424 );
1425 $allphotos = get_posts($args1);
1426 //$count = count($allphotos);
1427 return $allphotos;
1428 }
1429 function sip_post_status($post){
1430 global $mode;
1431
1432 if ( '0000-00-00 00:00:00' === $post->post_date ) {
1433 $t_time = $h_time = __( 'Unpublished' );
1434 $time_diff = 0;
1435 } else {
1436 $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
1437 $m_time = $post->post_date;
1438 $time = get_post_time( 'G', true, $post );
1439
1440 $time_diff = time() - $time;
1441
1442 if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
1443 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
1444 } else {
1445 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
1446 }
1447 }
1448
1449 if ( 'publish' === $post->post_status ) {
1450 $status = __( 'Published' );
1451 } elseif ( 'future' === $post->post_status ) {
1452 if ( $time_diff > 0 ) {
1453 $status = '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
1454 } else {
1455 $status = __( 'Scheduled' );
1456 }
1457 } else {
1458 $status = __( 'Last Modified' );
1459 }
1460
1461 /**
1462 * Filters the status text of the post.
1463 *
1464 * @since 4.8.0
1465 *
1466 * @param string $status The status text.
1467 * @param WP_Post $post Post object.
1468 * @param string $column_name The column name.
1469 * @param string $mode The list display mode ('excerpt' or 'list').
1470 */
1471 $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );
1472
1473 if ( $status ) {
1474 echo $status . '<br />';
1475 }
1476
1477 if ( 'excerpt' === $mode ) {
1478 /**
1479 * Filters the published time of the post.
1480 *
1481 * If `$mode` equals 'excerpt', the published time and date are both displayed.
1482 * If `$mode` equals 'list' (default), the publish date is displayed, with the
1483 * time and date together available as an abbreviation definition.
1484 *
1485 * @since 2.5.1
1486 *
1487 * @param string $t_time The published time.
1488 * @param WP_Post $post Post object.
1489 * @param string $column_name The column name.
1490 * @param string $mode The list display mode ('excerpt' or 'list').
1491 */
1492 echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
1493 } else {
1494
1495 /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
1496 echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>';
1497 }
1498 }
1499 function get_meta_values( $key = '', $type = 'post' ) {
1500 global $wpdb;
1501 if( empty( $key ) )
1502 return;
1503 $r = $wpdb->get_col( $wpdb->prepare( "
1504 SELECT pm.meta_value FROM {$wpdb->postmeta} pm
1505 LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
1506 WHERE pm.meta_key = '%s'
1507 AND p.post_type = '%s'
1508 ", $key, $type ) );
1509 return $r;
1510 }
1511
1512 function find_duplicate(){
1513 $kws = $_POST['kws'];
1514 $saved_kw = get_option('sip_saved_kw');
1515 $saved_kw_arr = explode("\n", get_option('sip_saved_kw'));
1516 $join = array_merge($kws, $saved_kw_arr);
1517 $uniq_kw = array_unique($join);
1518 $array_intersect = array_intersect($kws, $join);
1519 $diff = array_diff($array_intersect, $saved_kw_arr);
1520 $save_kw = implode("\n", $diff);
1521 //update_option("sip_saved_kw", $save_kw);
1522 print_r($save_kw);
1523
1524
1525 die();
1526 }
1527
1528 public function setExtension($array)
1529 {
1530
1531 if ( empty($array['file']))
1532 return false;
1533
1534 $fileInfo = pathinfo($array['file']);
1535 $filePath = $fileInfo['dirname'] . '/'.$fileInfo['basename'];
1536 switch ($fileInfo['extension']) {
1537 case 'jpg':
1538 $array['file'] = self::removeExif($filePath, 'jpg');
1539 break;
1540 case 'png':
1541 $array['file'] = self::removeExif($filePath, 'png');
1542 break;
1543 }
1544
1545 return $array;
1546 }
1547
1548 private function removeExif($imagePath, $type)
1549 {
1550 if (empty($imagePath) || !is_admin())
1551 return false;
1552
1553 if ($type == 'jpg')
1554 $clearExif = imagecreatefromjpeg($imagePath);
1555 elseif ($type == 'png')
1556 $clearExif = imagecreatefrompng($imagePath);
1557 else
1558 return $imagePath;
1559
1560 imagejpeg($clearExif, $imagePath, 100);
1561 imagedestroy($clearExif);
1562
1563 return $imagePath;
1564 }
1565
1566}//end class
1567
1568
1569
1570
1571$sip = new SimpleImagePoster();
1572
1573add_action('admin_menu', array('SimpleImagePoster','sip_plugin_menu'));
1574add_action('wp_ajax_bulk_grab', array('SimpleImagePoster','bulk_grab'));
1575
1576add_action('wp_ajax_bulk_delete_post', array('SimpleImagePoster','bulk_delete_post'));
1577add_action('wp_ajax_bulk_delete_image', array('SimpleImagePoster','bulk_delete_image'));
1578add_action('wp_ajax_bulk_delete_post_and_image', array('SimpleImagePoster','bulk_delete_post_and_image'));
1579add_action('wp_ajax_count_image_posted', array('SimpleImagePoster','count_image_posted'));
1580add_action('wp_ajax_zero_image_posted', array('SimpleImagePoster','zero_image_posted'));
1581add_action('wp_ajax_one_grab', array('SimpleImagePoster','one_grab'));
1582add_action('wp_ajax_download_image', array('SimpleImagePoster','download_image'));
1583add_action('wp_ajax_save_kw', array('SimpleImagePoster','save_kw'));
1584add_action('wp_ajax_delete_kw', array('SimpleImagePoster','delete_kw'));
1585add_action('wp_ajax_save_template', array('SimpleImagePoster','save_template'));
1586add_action('wp_ajax_save_settings', array('SimpleImagePoster','save_settings'));
1587add_action('wp_ajax_create_post', array('SimpleImagePoster','create_post'));
1588add_action('wp_ajax_get_posts', array('SimpleImagePoster','get_posts'));
1589
1590add_action('wp_ajax_find_duplicate', array('SimpleImagePoster','find_duplicate'));
1591//add_action('wp_ajax_sip_cron', array('SimpleImagePoster','sip_cron'));
1592add_action('quantum_cron_action',array('SimpleImagePoster','quantum_cron'));
1593add_shortcode('post_title',array('SimpleImagePoster','post_title_shortcode'));
1594wp_enqueue_script('sip-plugin', plugins_url( '/js/custom.js' , __FILE__ ) , array( 'jquery' ));
1595wp_localize_script( 'sip-plugin', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php')));
1596function sip_admin_style() {
1597 wp_register_style( 'sip-style', plugins_url('style.css', __FILE__) );
1598 wp_enqueue_style( 'sip-style' );
1599}
1600add_action( 'admin_enqueue_scripts', 'sip_admin_style' );
1601function success_posted_post_meta() {
1602 register_post_meta( 'post', 'success_posted_field', array(
1603 'show_in_rest' => true,
1604 'single' => true,
1605 'type' => 'string',
1606 ) );
1607}
1608add_action( 'init', 'success_posted_post_meta' );
1609if (get_option('reset_img_metadata')==1) {
1610if (!function_exists('wp_handle_upload'))
1611 require_once( ABSPATH . 'wp-admin/includes/file.php' );
1612 add_action('wp_handle_upload', array('SimpleImagePoster', 'setExtension'));
1613}
1614
1615add_action("wp_head", "remove_width_att");
1616function remove_width_att(){
1617 echo "<style>.wp-caption{width:auto !important}.wp-caption img[class*='wp-image-'] {
1618 width: auto;max-width: initial;
1619 }</style>";
1620}
1621
1622//include_once('license.php');
1623// $qtm_license = new QTMLicense();
1624// add_action('admin_menu', $qtm_license->slm_sample_license_menu);