echo "\n <tr>\n <td id=\"" . $css_id . "\">\n\n {$logo}\n\n\n "; $otitle = $title; # CPUs if ($scantype == "cpu") { $title = lhg_get_short_title(lhg_clean_cpu_title($otitle)); $meta_info = lhg_get_title_metas(lhg_clean_cpu_title($otitle)); } # CPUs if ($scantype == "drive") { $title = lhg_get_short_title(lhg_clean_drive_title($otitle)); $meta_info = lhg_get_title_metas(lhg_clean_drive_title($otitle)); } # USB devices if ($usbid != "" && $scantype != "mainboard") { $title = lhg_get_short_title(lhg_clean_usb_title($otitle)); $meta_info = lhg_get_title_metas(lhg_clean_usb_title($otitle)); $scantype = "usb"; } if ($title == "") { $title = "(No identifier found)"; } #$title = "Scantype: $scantype".$title; print '<div class="subscribe-hwtext">'; # use full product name if available if ($full_title != "") { $title = $full_title; } print ' <div class="subscribe-hwtext-span"><b>' . $title . '</b><span id="show-details-hw-' . $id . '"></span></div>'; if ($scantype == "cpu" or $scantype == "usb" or $scantype == "drive") { #print ' <div id="details-hw-'.$id.'" class="details">Full identifier: '.$otitle.' print '
function lhg_create_usb_article($title, $sid, $usbid) { # Library download timeout settings ini_set('default_socket_timeout', 5); global $lhg_price_db; global $lsusb_content_from_library; global $dmesg_content_from_library; global $lang; # article creation should be limited to .com server if ($lang == "de") { error_log("Article creation on .de server should not happen. ID: {$id}"); return; } # check if article was already created #error_log("USB article ID: $id"); $sql = "SELECT created_postid FROM `lhghwscans` WHERE id = \"" . $id . "\" "; $created_id = $lhg_price_db->get_var($sql); if ($created_id != 0) { return $created_id; } #$category = 478; $taglist = array(156); if ($lsusb_content_from_library == "") { $url = "http://library.linux-hardware-guide.com/showdata.php?sid=" . $sid . "&file=lsusb.txt"; $lsusb_content_from_library = file_get_contents($url); if ($lsusb_content_from_library === false) { throw new Exception('Failed to open ' . $url); } } #extract lsusb line foreach (preg_split("/((\r?\n)|(\r\n?))/", $lsusb_content_from_library) as $line) { if (strpos($line, $usbid) > 0) { $lsusbOutput = $line; } } if ($lsusbOutput == "") { $lsusbOutput = $lsusb_content_from_library; } #extract relevant dmesg output if ($dmesg_content_from_library == "") { $url = "http://library.linux-hardware-guide.com/showdata.php?sid=" . $sid . "&file=dmesg.txt"; $dmesg_content_from_library = file_get_contents($url); if ($dmesg_content_from_library === false) { throw new Exception('Failed to open ' . $url); } } #1 get usb port number: search line where USB ID is present: foreach (preg_split("/((\r?\n)|(\r\n?))/", $dmesg_content_from_library) as $line) { if (strpos($line, substr($usbid, 0, 4)) > 0 && strpos($line, substr($usbid, -4)) > 0) { $pos_start = strpos($line, "]"); $pos_end = strpos($line, ":"); $usbline = substr($line, $pos_start, $pos_end - $pos_start); break; } } #2 get all relevant lines foreach (preg_split("/((\r?\n)|(\r\n?))/", $dmesg_content_from_library) as $line) { if (strpos($line, $usbline) > 0) { $dmesgOutput .= substr($line, $pos_start + 2) . "\r\n"; } } #print "Tags: "; var_dump( $taglist ); print "<br>"; $new_taglist = lhg_taglist_by_title($title); $taglist = array_merge($taglist, $new_taglist); $tagstring = lhg_convert_tag_array_to_string($taglist); #print "newTags: "; var_dump( $taglist ); print "<br>"; $title = wp_strip_all_tags($title); $title_orig = $title; $title_orig_filtered = str_replace(", Inc.", "", $title_orig); $title = lhg_clean_usb_title($title); $article = 'The ' . $title_orig_filtered . ' is a USB ' . $type . ' with USB ID ' . $usbid . ' [code lang="plain" title="lsusb"] ' . $lsusbOutput . ' [/code] It is automatically recognized and fully supported by the Linux kernel: [code lang="plain" title="dmesg"] ' . $dmesgOutput . ' [/code] '; $category_array = lhg_category_by_title($title); #print "Article creation started"; #print "<br>Title: $title <br> ScanID: $sid<br>"; $title = "<!--:us-->" . $title . "<!--:-->"; $myPost = array('post_status' => 'draft', 'post_content' => "<!--:us-->" . $article . "<!--:-->", 'post_type' => 'post', 'post_author' => 1, 'post_title' => $title, 'post_category' => $category_array, 'tags_input' => $tagstring); global $wpdb; #$post_if = $wpdb->get_var("SELECT count(post_title) FROM $wpdb->posts WHERE post_title like '$title'"); #print "PI: ".$post_if; $post_if2 = $wpdb->get_var("SELECT count(post_title) FROM {$wpdb->posts} WHERE post_title like '{$title}' AND post_status = 'draft' "); #print "PI2: ".$post_if2; $sql = "SELECT created_postid FROM `lhghwscans` WHERE id = \"" . $id . "\" "; $created_id = $lhg_price_db->get_var($sql); if ($post_if2 > 0 or $created_id != 0) { #print "Title exists"; if ($created_id != 0) { $newPostID = $created_id; } if ($created_id == 0) { $newPostID = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_title like '{$title}' AND post_status = 'draft' "); } # store created_id for already existing articles if ($created_id == 0) { $sql = "UPDATE `lhghwscans` SET created_postid = \"" . $newPostID . "\" WHERE id = \"" . $id . "\" "; $result = $lhg_price_db->query($sql); } } else { //-- Create the new post #print "new article"; $newPostID = wp_insert_post($myPost); $sql = "UPDATE `lhghwscans` SET created_postid = \"" . $newPostID . "\" WHERE id = \"" . $id . "\" "; $result = $lhg_price_db->query($sql); } #print "<br>done<br>"; # Store post in DB lhg_create_new_DB_entry_post($newPostID, "usb", $usbid); #lhg_link_new_DB_entry_in_scan ( $newPostID, "usb", $usbid, $sid ); # get Amazon ID, if available $amzid = lhg_get_AMZ_ID_from_scan($sid, "usb", $usbid); #print "AMZID: $amzid"; # set Amazon ID $key = "amazon-product-single-asin"; $value = $amzid; if (get_post_meta($newPostID, $key, FALSE)) { //if the custom field already has a value update_post_meta($newPostID, $key, $value); } else { //if the custom field doesn't have a value add_post_meta($newPostID, $key, $value); } return $newPostID; }