##### Mainboards and Laptops # # if (count($unidentified_hw_pci) > 0) { if ($mainboard_found != 1) { # We are still searching for a mainboard/laptop # check if mainboard or laptop $laptop_prob = lhg_scan_is_laptop($sid); if ($laptop_prob > 0.8) { $mb_or_laptop = "Laptop"; } if ($laptop_prob <= 0.8) { $mb_or_laptop = "Mainboard"; } $mb_name = lhg_get_mainboard_name($sid); $clean_mb_name = lhg_clean_mainboard_name($mb_name); print "<h2>" . $txt_subscr_new . " " . $mb_or_laptop . ": " . $clean_mb_name . "</h2>"; #print '<div id="mbname">Identified name: '.$clean_mb_name."<span id='details-mb' class='details-link'></span></div>"; if ($show_public_profile != 1) { print '<div id="hidden-details-mb">Full identifier: ' . $mb_name . '</div>'; } $mb_usercomment = lhg_get_mb_usercomment($sid); $url_mb = lhg_get_mb_url($sid); $buttontype = "green"; $buttontext = $txt_submit; #"Submit"; if ($mb_usercomment != "") { $buttontype = "light"; } if ($mb_usercomment != "") { $buttontext = "Update";
function lhg_create_mainboard_article($title, $sid, $id) { global $lhg_price_db; 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 1: # see if article was already created based on article 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; } # check 2: # see if article was already created based on title $otitle = $title; $title = lhg_clean_mainboard_name($title); $page = get_page_by_title($title); if ($page->ID != "" && is_page($page->ID)) { return $page->ID; } #if ( is_page($page->ID) ) return $page->ID; $laptop_probability = lhg_scan_is_laptop($sid); // if mainboard if ($laptop_probability < 0.8) { $category = 472; $taglist = array(472); } else { #or if laptop $category = 470; $taglist = array(470); $taglist = array(450); } # Download only once for speed improvement global $lspci_content_from_library; global $dmesg_content_from_library; global $lsb_content_from_library; global $version_content_from_library; if ($lspci_content_from_library == "") { $url = "http://library.linux-hardware-guide.com/showdata.php?sid=" . $sid . "&file=lspci.txt"; $lspci_content_from_library = file_get_contents($url); } 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 ($lsb_content_from_library == "") { $url = "http://library.linux-hardware-guide.com/showdata.php?sid=" . $sid . "&file=lsb_release.txt"; $lsb_content_from_library = file_get_contents($url); } if ($version_content_from_library == "") { $url = "http://library.linux-hardware-guide.com/showdata.php?sid=" . $sid . "&file=version.txt"; $version_content_from_library = file_get_contents($url); } $lspci = explode("\n\n", $lspci_content_from_library); #print "<br>Dump:".var_dump($lspci)."<br>"; $lspci0 = $lspci[0]; $lspci0 = str_replace("\n\n", "", $lspci0); # create filtered and unfiltered list of all PCI IDs as array $pci_array_all $lspci_array = explode("\n", $lspci_content_from_library); $pcilist = array(); foreach ($lspci_array as $line) { #print "L $i:".$line."<br>"; $pciid_found = preg_match("/\\[....:....\\]/", $line, $matches); $subsystem_found = preg_match("/Subsystem/", $line, $matches2); #print preg_match("/\[....:....\]/",$line,$matches)." - ".var_dump($matches)."<br>"; $clean_pciid = $matches[0]; $clean_pciid = str_replace("[", "", $clean_pciid); $clean_pciid = str_replace("]", "", $clean_pciid); # PCI ID found, but no Subsystem ID if ($pciid_found == 1 && $subsystem_found == 0) { array_push($pcilist, $clean_pciid); } } $pci_array_all = $pcilist; #print "URL: $url<br>"; #print "cont: <pre>".$cpu0."</pre>"; # DMI entry $dmesg_content_array = split("\n", $dmesg_content_from_library); $dmi_array = preg_grep("/DMI: /", $dmesg_content_array); $dmi_line = implode("\n", $dmi_array); $dmi_line = str_replace("[ 0.000000]", "", $dmi_line); # Distribution $lsb_content_array = split("\n", $lsb_content_from_library); $lsb_array = preg_grep("/Description/", $lsb_content_array); $distribution = implode(" ", $lsb_array); $distribution = str_replace("Description:", "", $distribution); while (preg_match("/ /", $distribution)) { $distribution = str_replace(" ", " ", $distribution); } if (trim($distribution) == "") { # get distribution name from scan data base $sql = "SELECT distribution FROM `lhgscansessions` WHERE sid = \"" . $sid . "\""; $result = $lhg_price_db->get_results($sql); $result0 = $result[0]; $distribution = $result0->distribution; } # Kernel version $version_content_array = split("\n", $version_content_from_library); $version_array = preg_grep("/Linux version/", $version_content_array); $version_line = $version_array[0]; $version_line = str_replace("Linux version ", "", $version_line); list($version, $null) = split(" ", $version_line); #$article = 'The '.$title." "; #if ($laptop_probability > 0.8) $article .= 'is a laptop and '; # $article .= 'was successfully tested in configuration #[code lang="plain" title="dmesg | grep DMI"] #'.$dmi_line.' #[/code] #under '.trim($distribution).' with Linux kernel version '.trim($version).'. # #'; # $article .= '<h3>Hardware Overview</h3> #The following hardware components are part of the '.$title.' and are supported by the listed kernel drivers: #[code lang="plain" title="lspci -nnk"] #'.$lspci0.' #[/code] #'; $article .= "[lhg_mainboard_intro distribution=\"" . trim($distribution) . "\" version=\"" . trim($version) . "\" dmi_output=\"" . trim($dmi_line) . "\"]\n\n[lhg_mainboard_lspci]\n" . trim($lspci0) . "\n[/lhg_mainboard_lspci]\n"; #print $article; # ToDo: should be created based on lspci and dmesg output $new_taglist = lhg_taglist_by_title($title); $taglist = array_merge($taglist, $new_taglist); $tagstring = lhg_convert_tag_array_to_string($taglist); #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' => array($category), '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>"; # ToDo: store MB in DB # ToDo: store MB in DB # Store scan info in DB # # get CPU identifier #$pos = strpos($cpu0, "model name"); #$pos_end = strpos( substr($cpu0,$pos) , "\n"); #$pos_colon = strpos( substr($cpu0,$pos) , ":"); #print "POS: $pos - $pos_colon - $pos_end<br>"; #print substr($cpu0,$pos+$pos_colon+2, $pos_end-$pos_colon-2)."<br>"; #$cpu_identifier = substr($cpu0,$pos+$pos_colon+2, $pos_end-$pos_colon-2); if ($laptop_probability > 0.8) { # store all pci ids $identifier = lhg_get_mainboard_fingerprint($sid); lhg_create_new_DB_entry_post($newPostID, "laptop", $identifier); } else { # store all pci ids # ToDo: filter pciids not onboard! $identifier = lhg_get_mainboard_fingerprint($sid); #$identifier = implode(",",$pci_array_all); lhg_create_new_DB_entry_post($newPostID, "mainboard", $identifier); } # get Amazon ID, if available $amzid = lhg_get_AMZ_ID_from_scan($sid, "mainboard", ""); #print "AMZID CPU: $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; }