File manager - Edit - /var/www/konvoi/data/www/konvoisv.ru/wp-content/plugins/update-alt-attribute/incl/update_media.php
Back
<?php function view_alt(){ error_reporting(0); $tabs = array( 'update_alt_media' => 'Update Images Media', 'update_alt_content' => 'Update Images Content','setting_alt' => 'Settings'); ?> <div class="update_alt_cl"> <h2>Update Image Tag ALT Attribute</h2> <i>Version <?php echo ALT_VERSION; ?></i><br><br> <?php $current = $_GET['tab']; $itab = 1; echo '<h2 class="nav-tab-wrapper">'; foreach( $tabs as $tab => $name ){ $class = ( $tab == $current ) ? ' nav-tab-active' : ''; if(!isset($current)&& $itab==1) $class = ' nav-tab-active'; echo "<a class='nav-tab$class' href='?page=update-image-alt&tab=$tab'>$name</a>"; $itab++; } echo '</h2>'; ?> <?php if($_GET['tab'] == 'update_alt_media' || !isset($_GET['tab'])){ ?> <div class="content_alt"> <div class="maui_logo center"> <a href="http://mauimarketing.com/"><img height="100" width="300" src="<?php echo ALT_PLUGIN_URL;?>/assets/logo.png" alt="Maui Marketing" title="Maui Marketing"></a> </div> <strong>Note: </strong><span>By pressing the <strong>Start Update</strong> button the plugin will create <strong>"ALT Attribute Text"</strong> based on page or post attachment title for any image that currently does not have one. If the image is not attached to a page or post, it will create the attribute text based upon it's file name. Hyphens and other symbols will be converted to spaces. Any image that already has text in the ALT field <em>will not be touched</em>.</span><br> <div class="center"> <button id="bt_alt_update" name="bt_alt">Start Update Only Media</button> </div> </div> <label class="load_ajax">Loading...</label> <label class="notify"></label> <div class="result_update"> <h3 class="title_result">Result Image Tag ALT Attribute Update</h3> <table class="show_list_table"> <tr> <th>#</th> <th>File or Page Name</th> <th>New Image ALT Text</th> </tr> <tr class="list_alt"></tr> </table> </div> <?php } if($_GET['tab'] == 'update_alt_content'){ $get_post = get_option('custom_post_update_alt'); $check_cron = get_option('check_run_cron_alt'); if(isset($_POST['save_change_alt'])){ update_option('custom_post_update_alt',$_POST['post_type_alt']); $get_post = get_option('custom_post_update_alt'); update_option('check_run_cron_alt',$_POST['cron_update_time']); $check_cron = get_option('check_run_cron_alt'); if($check_cron != 1){ wp_clear_scheduled_hook(UPDATE_ALT_POST_CONTENT); }else{ wp_clear_scheduled_hook(UPDATE_ALT_POST_CONTENT); $timeNext = time()+(15*60); if(!empty($get_post)){ wp_schedule_event($timeNext,'hourly',UPDATE_ALT_POST_CONTENT); }else{ wp_clear_scheduled_hook(UPDATE_ALT_POST_CONTENT); echo "<span style='color:red;'>Error: You must select at least a post type! </span>"; } } } ?> <div class="content_alt"> <div class="maui_logo center"> <a href="http://mauimarketing.com/"><img height="100" width="300" src="<?php echo ALT_PLUGIN_URL;?>/assets/logo.png" alt="Maui Marketing" title="Maui Marketing"></a> </div> <strong>Note: </strong><span>First you need to choose <b>Post type</b> which needs to be updated in the Post type List. Next, in the setting, there is a On/Off button to enable or disable the auto-run update ALT images. This function will automatically update <b>20 records</b> after <b>15 minutes.</b></span><br> </div> <form method="post" action="#"> <div class="custom-post"> <h3>1. Select post type</h3> <i><b><?php _e('Select the post types you would like to run the updater on:', 'alt'); ?></b></i> <ul class="custom_post_types_checkboxes"> <?php $get_post_types = get_post_types('', 'objects'); foreach ( $get_post_types as $post_type ) { if($post_type->name != 'revision' && $post_type->name != 'nav_menu_item'){ ?> <li><input type="checkbox" id="post_type_selected" value="<?php echo $post_type->name ?>" name="post_type_alt[]" <?php if(!empty($get_post)) { echo (in_array($post_type->name,$get_post))? 'checked':'';}?>><?php echo $post_type->labels->name ?></li> <?php } } ?> </ul> </div> <div class="bt_alt"> <h3>2. Settings</h3> <input type="checkbox" id="cron_update_time" value="1" name="cron_update_time" <?php echo ($check_cron == 1)?'checked':'';?>> <br> <b>Note: </b><i>Select on to use the cron feature. It will update 20 records every 15 mins.</i> <br> <br> <button id="save_change_alt" name="save_change_alt" value="1">Start Update Only Content</button> </div> </form> <div class="history_alt"> <h4>History:</h4> <?php $path = ALT_PLUGIN_DIR."logs/altcontent/"; $link_file = ALT_PLUGIN_URL.'logs/altcontent/'; $check_his = false; if ($dir = opendir($path)) { $k = 1; while (($files = readdir($dir)) !== false) { $file = str_replace('.txt','',(string)$files); $arr = explode('-',$file); $date = date('Y-m-d H:i:s',$arr[1]); $link = "<a href='".$link_file."".$files."' target='_blank'>Show info</a>"; if(strpos($files,'txt') !== false){ $check_his = true; echo "<b>".$k.". </b>" . $date ." - ".$link."<br />"; $k++; } } closedir($dir); } if(!$check_his){ echo "Empty!"; } ?></div><?php } if($_GET['tab'] == 'setting_alt'){ $check_cron = get_option('cb_update_image_db'); if(isset($_POST['save_change'])){ update_option('cb_update_image_db',$_POST['cb_update_image_db']); $check_cron = get_option('cb_update_image_db'); if($check_cron != 1){ update_option('update_info_db',0); wp_clear_scheduled_hook(MM_UPDATE_INFO_DATABASE); }else{ wp_clear_scheduled_hook(MM_UPDATE_INFO_DATABASE); $timeNext = time()+(15*60); wp_schedule_event($timeNext,'hourly',MM_UPDATE_INFO_DATABASE); } } ?> <form id="mm_update_info_image" method="post" action="#"> <p> <input type="checkbox" id="cb_update_image_db" value="1" name="cb_update_image_db" <?php echo ($check_cron == 1)?'checked':'';?>> <b><i>Auto update info image (alt,width,height) all table in database.</i></b> </p> <button id="save_change" name="save_change" value="1">Save Change</button> </form> <?php } ?> </div> <?php } add_action( 'wp_ajax_func_update_alt_attachment', 'func_update_alt_attachment' ); function func_update_alt_attachment(){ $args = array( 'post_type' => 'attachment', 'orderby' => 'menu_order', 'post_mime_type' => 'image','posts_per_page' => -1); $attachments = get_posts($args); $date = date('Ymdhis'); $txt = array(); $file_path = ALT_PLUGIN_DIR."logs/listalt".$date.".txt"; ob_start(); //print_r($attachments); if (!empty($attachments)){ $i=1; $check_item = false; foreach ($attachments as $attachment ) { $alt_text = get_post_meta($attachment->ID , '_wp_attachment_image_alt', true); $title = $attachment->post_title; $post_id = $attachment->post_parent; $alt_text = str_replace(' ','',trim($alt_text)); if(empty( $alt_text)){ $src = wp_get_attachment_image_src($attachment->ID,'_thumbnail_id',true); $nameFile = basename(esc_url($src[0])); $nameFile = explode('.',$nameFile); $nameFile = $nameFile[0]; $character_special = preg_match('/[\'\/~`\!@#\$%\^&\*\(\)\+=\{\}\[\]\|;:"\]/', $nameFile); if(is_numeric($nameFile) || $character_special){ if($post_id != ''){ $alt = trim(get_the_title($post_id)); }else{ $alt = $nameFile; } }else{ $alt = trim(clean($nameFile)); } $check_item = true; update_post_meta($attachment->ID,'_wp_attachment_image_alt',trim($alt)); ?> <tr class="list_alt_update"> <td><?php echo $i;?></td> <td><?php echo $title;?></td> <td><?php echo $alt; ?></td> </tr> <?php $txt[] = $i."\t".$title."\t\t\t".$alt."\n"; $i++; }else{ $alt_clean = clean($alt_text); if($alt_clean != $alt_text){ update_post_meta($attachment->ID,'_wp_attachment_image_alt',trim($alt_clean)); ?> <tr class="list_alt_update"> <td><?php echo $i;?></td> <td><?php echo $title;?></td> <td><?php echo $alt_clean; ?></td> </tr> <?php $txt[] = $i."\t".$title."\t\t\t".$alt_clean."\n"; $i++; } } } if($check_item){ $openfile = fopen($file_path, "w") or die("Unable to open file!"); fwrite($openfile, $record); foreach($txt as $tt){ fwrite($openfile, $tt); } fclose($openfile); $link_file = ALT_PLUGIN_URL.'logs/listalt'.$date.'.txt'; ?> <tr class="button_list"> <td><a href="<?php echo $link_file;?>" target="_blank">Show list image update alt</a></td> <tr> <?php } $content_html = ob_get_contents(); ob_clean(); ob_end_flush(); echo $content_html;die(); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.58 |
proxy
|
phpinfo
|
Settings