pad url submit script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alokpgupta
Forum Newbie
Posts: 1
Joined: Sat Apr 12, 2008 1:00 pm

pad url submit script

Post by alokpgupta »

Hi Friends,
I am new user on this site and also have a bit knowledge about php.
currently i download a script from internet but not working proper.

Code: Select all

<?php
 echo "Content-type: text\plain\n\n";
 include("config.php");
 
  function GetStartTag($parser,$element_name,$element_attribs)
  {
    global $tagstack;
    $tagstack .= "<" . $element_name . ">";
  }
 
  function GetData($parser,$data)
  {
    global $tagstack, $tagarray, $lasttag;
    if ($lasttag == $tagstack) $tagarray["$tagstack"] .= $data; else $tagarray["$tagstack"] = $data;
    $lasttag = $tagstack;
  }
 
  function GetEndTag($parser,$element_name)
  {
    global $tagstack;
    $x = "<" . $element_name . ">";
    if (strrchr($tagstack,$x) == $x) $tagstack = substr($tagstack,0,strrpos($tagstack,$x));
    else
    {
      echo "Error: no corresponding start tag for end tag",htmlspecialchars($x),"<br><br>";
          continue;
    }
  }
 
 
////////////////////////////////////////////
  $link_id = mysql_connect($dbhost, $userid, $userpassword) or die("Error connecting to the database server.");  // changed in v2.00.05 (OG)
  mysql_select_db ($dbname);
  $pads = file("pads.txt");
  echo "Files to import:".count($pads)."\n";
for ($aaa=0; $aaa<count($pads); $aaa++) {   $padurl = $pads[$aaa];        $padurl = rtrim($padurl);
    echo "Processing: ".$padurl."...";
    $isvalidcat = 0;
    $catinpad = "";
    if (!$padary = @file($padurl)) { echo "Can't open pad file\n";  continue;   }
 
    for ($j=1; $j<count($padary); $j++) {
            // the category in PAD file 
        if (strlen(stristr($padary[$j], "<Program_Category_Class>"))>5) { // changed in v2.00.01 (DV)
                  $tmp = explode(">", $padary[$j]);   $tmp = explode("<", $tmp[1]);    $catinpad = $tmp[0];      }
    }
    if (!$catary = @file($catfile)) {   echo "Can't open category file\n";      continue;        }
    for ($k=0; $k<count($catary); $k++) {
         $cdisp = rtrim($catary[$k]);
         $cmach = rawurlencode($cdisp);
         $cdisp2 = explode("::", $cdisp);
         $cmach2 = explode("%3A%3A", $cmach);
         $cdispwsc= htmlspecialchars($cdisp); // added in v2.00.01 (DV)
          if ($catinpad == $cdisp) { //a pre-defined category?
               $isvalidcat = 1;        break;  
         }  
          else if ($catinpad == $cdispwsc) {    $isvalidcat = 1;       break;  }
    }
    
    if ($isvalidcat == 0) {     echo("Error: Unrecognized category $catinpad. Press the Back button.\n");       continue;   }
    
$tagstack = "";
$lasttag = "?";
    if (!$data = @file($padurl)) {
        echo("Error opening $padurl\n");        continue;   }
    
    $data = implode("",$data);  // changed in v2.00.02 (OG)
    $data = substr($data, strpos($data,"<?xml"));  // remove any http headers
 
    // Look up the XML encoding  // added in v2.00.02 (OG)
    if ( preg_match("/<\?xml [^>]*encoding=['\"](.*?)['\"][^>]*>.*/", $data, $m) )
        $encoding = strtoupper($m[1]);
    else
        $encoding = "UTF-8";
 
  // If the encoding is not natively supported by the PHP XML parser, try to
  // decode on our own (to UTF-8), if decoding is not possible, assume UTF-8,
  // which is the XML default.  // added in v2.00.02 (OG)
  if ( ($encoding != "UTF-8") && ($encoding != "US-ASCII") && ($encoding != "ISO-8859-1") )
  {     $encoding = ""; 
    if ( function_exists("mb_convert_encoding") )    {      $encoded_source = @mb_convert_encoding($data, "UTF-8", $encoding);
      if ( $encoded_source != NULL )      {        $data = str_replace($m[0], "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", $encoded_source);
        $encoding = "UTF-8";      }
    }
  }
  if (!($xml_parser = xml_parser_create($encoding))) echo("Error creating XML parser\n");  // changed in v2.00.02 (OG)
  xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");  // added in v2.00.02 (OG)
  xml_set_element_handler($xml_parser,"GetStartTag","GetEndTag");
  xml_set_character_data_handler($xml_parser,"GetData");
  xml_parse($xml_parser,$data,true);
  xml_parser_free($xml_parser);
 
 //  echo "<b>Results for $padurl</b>:<br><br>";
 
  $reqtags = array("<XML_DIZ_INFO><COMPANY_INFO><COMPANY_NAME>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_NAME>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_VERSION>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_RELEASE_MONTH>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_RELEASE_DAY>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_RELEASE_YEAR>",
                   "<XML_DIZ_INFO><COMPANY_INFO><COMPANY_WEBSITE_URL>",
                   "<XML_DIZ_INFO><COMPANY_INFO><CONTACT_INFO><CONTACT_EMAIL>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_COST_DOLLARS>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_TYPE>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_OS_SUPPORT>",
                   "<XML_DIZ_INFO><PROGRAM_INFO><FILE_INFO><FILE_SIZE_K>",
                   "<XML_DIZ_INFO><PROGRAM_DESCRIPTIONS><ENGLISH><KEYWORDS>",
                   "<XML_DIZ_INFO><PROGRAM_DESCRIPTIONS><ENGLISH><CHAR_DESC_450>",
                   "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_INFO_URL>",
                   "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_SCREENSHOT_URL>",
                   "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_XML_FILE_URL>",
                   "<XML_DIZ_INFO><WEB_INFO><DOWNLOAD_URLS><PRIMARY_DOWNLOAD_URL>",
                   "<XML_DIZ_INFO><ASP><ASP_MEMBER_NUMBER>",
                   "<XML_DIZ_INFO><PROGRAM_DESCRIPTIONS><ENGLISH><CHAR_DESC_45>",
                   "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_ICON_URL>",);
 
  // set defaults for cost, screenshot, and ASP number if blank
  $tag = "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_COST_DOLLARS>";
  if (empty($tagarray["$tag"]) or ($tagarray["$tag"] == "")) $tagarray["$tag"] = "0.00";
  $tag = "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_SCREENSHOT_URL>";
  if (empty($tagarray["$tag"]) or ($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";
  $tag = "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_ICON_URL>";
  if (empty($tagarray["$tag"]) or ($tagarray["$tag"] == "")) $tagarray["$tag"] = "";
  $tag = "<XML_DIZ_INFO><ASP><ASP_MEMBER_NUMBER>";
  if (empty($tagarray["$tag"]) or ($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";
 
 
  // check for missing/empty tags
 
  $paderr = false;
 
  foreach ($reqtags as $tag)
  {     if ($tag == "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_ICON_URL>") {   continue;    }
    if (empty($tagarray["$tag"]))    {      echo "Required tag not found in PAD file: ",htmlspecialchars($tag),"\n";      $paderr = true;    }
    else    {      $tagarray["$tag"] = trim($tagarray["$tag"]);
      if  ($tagarray["$tag"] == "")      {        echo "Required data not found in tag: ",htmlspecialchars($tag),"\n";     $paderr = true;      }
    }
  }
  if ($paderr) {    echo("PAD file rejected\n");    continue;
   }
  $tag = $reqtags[0];  $company =     substr($tagarray["$tag"], 0, 50);
  $tag = $reqtags[1];  $title =       substr($tagarray["$tag"], 0, 50);
  $tag = $reqtags[2];  $version =     substr($tagarray["$tag"], 0, 10);   // modified in v2.00.03 (OG)
  $tag = $reqtags[3];  $pmonth =      $tagarray["$tag"];
  $tag = $reqtags[4];  $pday =        $tagarray["$tag"];
  $tag = $reqtags[5];  $pyear =       $tagarray["$tag"];
  $tag = $reqtags[6];  $website =     substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[7];  $email =       substr($tagarray["$tag"], 0, 50);   // modified in v2.00.03 (OG)
  $tag = $reqtags[8];  $cost =        $tagarray["$tag"];
  $tag = $reqtags[9];  $ptype =       substr($tagarray["$tag"], 0, 15);   // modified in v2.00.03 (OG)
  $tag = $reqtags[10]; $os =          substr($tagarray["$tag"], 0, 80);   // modified in v2.00.03 (OG)
  $tag = $reqtags[11]; $ksize =       $tagarray["$tag"];
  $tag = $reqtags[12]; $keywords =    substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[13]; $description = $tagarray["$tag"];
  $tag = $reqtags[14]; $homepage =    substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[15]; $screenshot =  substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[16]; $padfile =     substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[17]; $download =    substr($tagarray["$tag"], 0, 128);  // modified in v2.00.03 (OG)
  $tag = $reqtags[18]; $aspnumber =   substr($tagarray["$tag"], 0, 5);    // modified in v2.00.03 (OG)
  $tag = $reqtags[19]; $short_description =   $tagarray["$tag"];    // modified in v2.00.03 (OG)
  $tag = $reqtags[20]; $icon =  substr($tagarray["$tag"], 0, 128);
 
  // added in v2.00.08 (OG)
  // prepend protocol if not provided
  if ((trim($website) != "") && (strstr($website, "://") === FALSE))
    $website = "http://" . $website;
  if ((trim($homepage) != "") && (strstr($homepage, "://") === FALSE))
    $homepage = "http://" . $homepage;
  if ((trim($screenshot) != "") && (strstr($screenshot, "://") === FALSE))
    $screenshot = "http://" . $screenshot;
  if ((trim($icon) != "") && (strstr($icon, "://") === FALSE))
    $icon = "http://" . $icon;
  if ((trim($download) != "") && (strstr($download, "://") === FALSE))
    $download = "http://" . $download;
  if (strlen($pmonth) == 1) $pmonth = "0" . $pmonth;
  if (strlen($pday) == 1) $pday = "0" . $pday;
  $pdate = $pyear . "-" . $pmonth . "-" . $pday;
  $ksize = str_replace(",","",$ksize);  // remove any commas
 
  // count chars in description minus html encodings
 
  $desc2 = str_replace("<","x",strtolower($description));
  $desc2 = str_replace(">","x",$desc2);
  $desc2 = str_replace("&","x",$desc2);
  $desc2 = str_replace(""","x",$desc2);
  if (strlen($desc2) > 450) {
    echo("Error: CHAR_DESC_450 field exceeds 450 character limit.\n");
  }
 
  $desc3 = str_replace("<","x",strtolower($short_description));
  $desc3 = str_replace(">","x",$desc3);
  $desc3 = str_replace("&","x",$desc3);
  $desc3 = str_replace(""","x",$desc3);
  if (strlen($desc3) > 45) {
    echo("Error: CHAR_DESC_45 field exceeds 45 character limit.\n");
  }
//  if (strcasecmp($padurl,$padfile) <> 0) // removed in v2.00.01 (DV)
//    die("Error: submitted url ($padurl) does not match url inside PAD file ($padfile). Click back button and correct the URL"); // removed in v2.00.01 (DV)
 
  $tomorrow = date("Y-m-d",time()+86400);
  if ($pdate > $tomorrow)
    echo("Error: Forward dating not allowed. Release date ($pdate) is greater than tomorrow's date ($tomorrow)\n");
 
  // connect to database
 
  $company = addslashes($company);
  $keywords = addslashes($keywords);
  $title = addslashes($title);
  $description = addslashes($description);
  $short_description = addslashes($short_description);
  $download = addslashes($download); // added in v1.50.03 (DV)
  $poll = 0;
 
  // see if company/title already in paddata table
echo "27 ";
  $result = mysql_query("select * from paddata where (company = '$company' and title = '$title') or (padfile = '$padfile')", $link_id);  // modified in v2.00.03 (OG)
  $replace = (mysql_num_rows($result) <> 0);
  $res = mysql_fetch_array($result);
  if ($replace) $id = $res["id"];
  // insert (replace) fields into paddata table
 
  $flist =  "company, title, version, pdate, website, email, cost, ptype, os, ksize, ";
  $flist .= "category, keywords, description, short_description, homepage, icon, screenshot, padfile, download, aspnumber, poll";
 
  if ($replace) $flist .= ", id";
 
  $vlist =  "'$company', '$title', '$version', '$pdate', '$website', '$email', '$cost', '$ptype', '$os', '$ksize', ";
  $vlist .= "'$catinpad', '$keywords', '$description', '$short_description', '$homepage', '$icon', '$screenshot', '$padfile', '$download', '$aspnumber', '$poll'";
 
  if ($replace) $vlist .= ", $id";
 
  $sql_command = "insert";
  
  if ($replace) $sql_command = "replace";
 
  if (!mysql_query("$sql_command into paddata ($flist) values($vlist)", $link_id)) echo("Error updating paddata table\n");
 
  // update activity log
 
  $ipaddr = getenv("REMOTE_ADDR");
  mysql_query("insert into editlog values(now(), '$aspnumber', '$ipaddr', 'Add PAD: $company - $title')", $link_id);
 
  // disconnect from database
 
 
  // display messages
  $company = htmlspecialchars(stripslashes($company));
  $title = htmlspecialchars(stripslashes($title));
  $keywords = htmlspecialchars(stripslashes($keywords));
  $description = htmlspecialchars(stripslashes($description));
  $short_description = htmlspecialchars(stripslashes($short_description));
  $download = htmlspecialchars(stripslashes($download),ENT_QUOTES); // added in v1.50.03 (DV)
  $cost = sprintf("%01.2f",$cost);
 
  if ($replace) echo "Existing program record successfully updated: $title\n";
  else echo "New program successfully added: $title\n";
 
}
 
?>
 
 
http://www.etrusoft.com/quick_screen_c ... ark2.xml

Problem : only 4, 5 url at a time save in the database

please help me
thanks

ALOK
Post Reply