admin_url( 'admin-ajax.php' ) ) );
}
}
//footer scripts
add_action( 'admin_print_footer_scripts', 'am_hili_admin_footer_js' );
if (!function_exists('am_hili_admin_footer_js')){
function am_hili_admin_footer_js(){
?>
(.*?)\<\/a>/si', $content, $amhiliTexts)){
$amhiliText = $wpdb->_real_escape(trim(strip_tags($amhiliTexts[2])));
}
if (preg_match('/href=("|\')(.*?)("|\')/i',$content,$amhiliUrls)){
$amhiliUrl = trim($amhiliUrls[2]);
}
//handling the database if id, text and url found
if (isset($amhiliID) and isset($amhiliUrl) and isset($amhiliText) and isset($post_id) and $post_id > 0){
//update link if found
if($hiliRow = $wpdb->get_row("select * from ".AM_HILI_LINKS." where link_id='$amhiliID'")){
if ($hiliRow->link_url != $amhiliUrl or $hiliRow->link_text != $amhiliText){
$wpdb->query($wpdb->prepare("update ".AM_HILI_LINKS." set link_url='$amhiliUrl', link_text='$amhiliText', post_id='$post_id' where link_id=%d",$amhiliID));
}
}
else {
//re-insert link if was removed accidently
$wpdb->query($wpdb->prepare("insert into ".AM_HILI_LINKS." (link_id,post_id, blog_id, link_url, link_text,link_type)
values('$amhiliID','$post_id', '".BLOG_ID."','$amhiliUrl', '$amhiliText','%s')",'l'));
}
}
}
}
//removing not used links from the data base
if($post_id!=0 and $hiliRows = $wpdb->get_results("select link_id,post_id from ".AM_HILI_LINKS." where post_id='$post_id'")){
foreach ($hiliRows as $row){
if (!in_array($row->link_id,$amHiliIdDs)){
$wpdb->query($wpdb->prepare("delete from ".AM_HILI_LINKS." where link_id='".$row->link_id."' and post_id=%d",$post_id));
}
}
}
//remove all inline links have no post id asigned to it
$wpdb->query($wpdb->prepare("delete from ".AM_HILI_LINKS." where link_type='l' and post_id=%d",0));
//check if this post must be excluded from auto insert links
if (!isset($_POST['am_hili_exclude_this_post'])){
delete_post_meta( $post_id, '_am_hili_exclude_post');
} else {
update_post_meta( $post_id, '_am_hili_exclude_post','yes');
}
}
}
add_action( 'save_post', 'am_hili_get_shortcode');