if ($show_public_profile != 1) { $article_created = $txt_subscr_pleaserate . ": <br><nobr>{$out1}</nobr>"; } } } // end of autocreate skipping in debug mode $css_id = "col-hw"; if ($show_public_profile == 1) { $css_id = "col-hw-pub"; } 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)"; }
function lhg_create_cpu_article($title, $sid, $id) { # returns the post id of created or already existing draft article global $lhg_price_db; global $cpus_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 1: # see if article was already created based on article ID #error_log("CPU 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; } # check 2: # see if article was already created based on title # Use clean CPU title # $title = lhg_clean_cpu_title($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; $category = 874; $taglist = array(874); # Download only once for speed improvement if ($cpus_from_library == "") { $url = "http://library.linux-hardware-guide.com/showdata.php?sid=" . $sid . "&file=cpuinfo.txt"; $content = file_get_contents($url); $cpus_from_library = explode("\n\n", $content); } #print "<br>Dump:".var_dump($cpus)."<br>"; $cpu0 = $cpus_from_library[0]; $new_cpulines = array(); $cpulines = explode("\n", $cpu0); foreach ($cpulines as $cpuline) { $length = strlen($cpuline); #print "L: $length :".$cpuline."<br>"; $i = 1; $posold = 0; while ($length > 80) { $pos = strpos($cpuline, " ", 80 * $i); $delta = $pos - $posold; $posold = $pos; $length = $length - $delta; $i++; $cpuline = substr_replace($cpuline, "\n ", $pos, 0); #print "CPL: $cpuline ---- <br>"; } array_push($new_cpulines, $cpuline); } $cpu0 = implode("\n", $new_cpulines); #print "URL: $url<br>"; #print "cont: <pre>".$cpu0."</pre>"; $article = '[code lang="plain" title="cat /proc/cpuinfo"] ' . $cpu0 . ' [/code] '; $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>"; # 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), ":"); #error_log ("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); #error_log("CPU id: $cpu_identifier"); lhg_create_new_DB_entry_post($newPostID, "cpu", $cpu_identifier); # get Amazon ID, if available $amzid = lhg_get_AMZ_ID_from_scan($sid, "cpu", ""); #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; }