Exemplo n.º 1
0
function lhg_pci_component_is_onboard($title, $sid, $id, $pciid)
{
    # ToDo: default = onboard (should be smarter)
    $onboardstatus = "yes";
    # not shown components are onboard
    $showme = lhg_show_scanned_component($title, $id, $pciid);
    if ($showme == false) {
        $onboardstatus = "yes";
    }
    # check DB if something was defined by user
    global $lhg_price_db;
    $sql = "SELECT onboard FROM `lhghwscans` WHERE id = %s";
    $safe_sql = $lhg_price_db->prepare($sql, $id);
    $DB_onboard = $lhg_price_db->get_var($safe_sql);
    #print "DB: $id - $DB_onboard<br>";
    $prob_laptop = lhg_scan_is_laptop($sid);
    if ($DB_onboard == "yes") {
        $onboardstatus = "yes";
        return $onboardstatus;
    }
    if ($DB_onboard == "no") {
        $onboardstatus = "no";
        return $onboardstatus;
    }
    if (is_int(strpos($title, "USB controller ["))) {
        $onboardstatus = "no";
    }
    if (is_int(strpos($title, "VGA compatible controller ["))) {
        $onboardstatus = "no";
    }
    if (is_int(strpos($title, "Communication controller"))) {
        $onboardstatus = "no";
    }
    if (is_int(strpos($title, "Intel Corporation")) && is_int(strpos($title, "Graphics Controller"))) {
        $onboardstatus = "yes";
    }
    if (is_int(strpos($title, "Intel Corporation")) && is_int(strpos($title, "High Definition Audio"))) {
        $onboardstatus = "yes";
    }
    if (is_int(strpos($title, "Intel Corporation")) && is_int(strpos($title, "SATA Controller"))) {
        $onboardstatus = "yes";
    }
    if ($prob_laptop > 0.8) {
        # looks like a laptop. All PCI components onboard
        #if (is_int(strpos($title,"USB controller [") ) )            $onboardstatus = "yes";
        #if (is_int(strpos($title,"VGA compatible controller [") ) ) $onboardstatus = "yes";
        #if (is_int(strpos($title,"Audio device [") ) )              $onboardstatus = "yes";
        #if (is_int(strpos($title,"Ethernet controller [") ) )       $onboardstatus = "yes";
        #if (is_int(strpos($title,"Network controller [") ) )        $onboardstatus = "yes";
        $onboardstatus = "yes";
    }
    #print "PL: $prob_laptop - ";
    if ($prob_laptop < 0.1) {
        if (is_int(strpos($title, "IDE interface")) && is_int(strpos($title, "Intel Corporation"))) {
            $onboardstatus = "yes";
        }
        if (is_int(strpos($title, "Bridge ")) && is_int(strpos($title, "Intel Corporation"))) {
            $onboardstatus = "yes";
        }
        if (is_int(strpos($title, "USB controller ")) && is_int(strpos($title, "Intel Corporation"))) {
            $onboardstatus = "yes";
        }
        #print "11<br>";
    }
    return $onboardstatus;
}
Exemplo n.º 2
0
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;
}