All pastes #1841462 Raw Edit

translate

public text v1 · immutable
#1841462 ·published 2010-03-15 18:40 UTC
rendered paste body
<?php
function CheckLicense( $regKeys )
{
    global $strRegKeyNo;
    global $strTemplate;
    global $strSupport;
    $strLicense = curlgetcontents( "http://www.incansoft.com/License.php?LICENSE=".$regKeys."|IS0029&DOMAIN=".$_SERVER['HTTP_HOST'] );
    if ( trim( $strLicense ) != $regKeys || $regKeys == "" )
    {
        echo str_replace( "[MESSAGE]", $strRegKeyNo.$strSupport, $strTemplate );
        exit( );
    }
    return TRUE;
}

function CurlGetContents( $strFile )
{
    $objCurl = curl_init( );
    curl_setopt( $objCurl, CURLOPT_URL, $strFile );
    curl_setopt( $objCurl, CURLOPT_HEADER, 0 );
    curl_setopt( $objCurl, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $objCurl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" );
    $strText = curl_exec( $objCurl );
    curl_close( $objCurl );
    return $strText;
}

function ParseDom( $strNode, $intLevel = 0 )
{
    global $strBase;
    global $strLang;
    if ( $strNode->nodeType == XML_TEXT_NODE )
    {
        if ( substr( $strNode->nodeValue, 0, 1 ) == " " )
        {
            $strLS = " ";
        }
        else
        {
            $strLS = "";
        }
        if ( substr( $strNode->nodeValue, strlen( $strNode->nodeValue ) - 1, 1 ) == " " )
        {
            $strTS = " ";
        }
        else
        {
            $strTS = "";
        }
        $strJSON = json_decode( curlgetcontents( "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=".urlencode( $strNode->nodeValue )."&langpair=".$strBase."%7C".$strLang ) );
        $strNode->nodeValue = $strLS.$strJSON->responseData->translatedText.$strTS;
    }
    $strChild = $strNode->childNodes;
    if ( 0 < count( $strChild ) )
    {
        ++$intLevel;
        foreach ( $strChild as $cNode )
        {
            parsedom( $cNode, $intLevel );
            $intLevel -= 1;
        }
    }
}

function ShowMySQLError( $strErrorCode )
{
    global $strTemplate;
    global $strSupport;
    switch ( $strErrorCode )
    {
    case "1" :
        $strError = "<b style=\"font-family: Verdana; font-weight: normal;\">The <a href=\"http://www.incansoft.com/IS0009.php\">Incansoft Translator</a> was not able to <b>Connect</b> to the MySQL Database. This may occur if the MySQL Database has not yet been created or the Login Credentials were not entered correctly in the <b>Configuration</b> file.";
        break;
    case "2" :
        $strError = "<b style=\"font-family: Verdana; font-weight: normal;\">The <a href=\"http://www.incansoft.com/IS0009.php\">Incansoft Translator</a> was not able to <b>Select</b> the MySQL Database. This may occur if the MySQL Database has not yet been created or the Login Credentials were not entered correctly in the <b>Configuration</b> file.";
        break;
    case "3" :
        $strError = "<b style=\"font-family: Verdana; font-weight: normal;\">The <a href=\"http://www.incansoft.com/IS0009.php\">Incansoft Translator</a> was not able to <b>Create</b> the required <b>Tables</b> in the MySQL Database. This may occur if the MySQL Database has not yet been created or the Login Credentials were not entered correctly in the <b>Configuration</b> file.";
        break;
    case "4" :
        $strError = "<b style=\"font-family: Verdana; font-weight: normal;\">The <a href=\"http://www.incansoft.com/IS0009.php\">Incansoft Translator</a> was not able to <b>Insert</b> a <b>New Record</b> in the MySQL Database. This may occur if the MySQL Database has not yet been created or the Login Credentials were not entered correctly in the <b>Configuration</b> file.";
    }
    echo str_replace( "[MESSAGE]", $strError.$strSupport, $strTemplate );
    exit( );
}

error_reporting( 0 );
include( "TransCfg.php" );
$strTemplate = "<html><head><style>div {font-family: Georgia; position: relative;}a {color: #303030; text-decoration: none;}a:hover {color: #961428; border-bottom: 1px dotted #961428;}body {background-image: url(http://www.incansoft.com/Images/Incansoft_BG.png); text-align: center;}hr {border-bottom: 1px solid #C0C0C0;}#Container {background-color: #F2F1E6; border: 1px solid #C0C0C0; margin-left: auto; margin-right: auto; margin-top: 25px; width: 600px;}#Header {border-bottom: 4px solid #961428; height: 48px; margin-left: auto; margin-right: auto; margin-top: 5px; width: 560px;}#Company {color: #404040; float: left; font-size: 24pt; letter-spacing: 5pt; margin-top: 3px; text-align: left; width: 312px;}#Solutions {float: right; font-size: 8pt; letter-spacing: 7px; margin-right: -0px; margin-top: 10px; text-align: right;}#Domain {float: right; font-size: 8pt; letter-spacing: 7px; margin-right: -0px; text-align: right;}#OuterBody {background-color: #F9F7ED; margin: 20px; border: 1px dotted #961428; font-family: Georgia; font-size: 10pt; text-align: center; width: 560px;}#InnerBody {color: #303030; background-color: #F9F7ED; margin: 20px; font-size: 10pt; text-align: justify}#InnerBody a {border-bottom: 1px dotted #303030;}#Footer {color: #303030; border-top: 1px solid #961428; font-size: 8pt; letter-spacing: 4px; margin-bottom: 10px; margin-left: auto; margin-right: auto; margin-top: 10px; text-align: right; width: 560px;}#Copyright {margin-top: 10px;}</style></head><body><div id=\"Container\"><div id=\"Header\"><div id=\"Company\">Incansoft</div><div id=\"Solutions\"><b>Solutions</b> <b style=\"color: #961428;\">Evolved</b></div><div id=\"Domain\"><a href=\"http://www.incansoft.com\">www.incansoft.com</a></div></div><div id=\"OuterBody\"><div id=\"InnerBody\"><b style=\"font-size: 16pt; font-weight: normal; letter-spacing: 5px;\">Translator Error</b><hr size=\"0\" noshade/><br/>[MESSAGE]</div></div><div id=\"Footer\"><div id=\"Copyright\">&copy; 2000 - ".date( "Y" ).", <a href=\"http://www.incansoft.com/\">Incansoft.com</a></div></div></div></body></html>";
$strRegKeyNo = "<b style=\"font-family: Verdana; font-weight: normal;\">It would appear that the <b>Registration Key</b> for this copy of the <a href=\"http://www.incansoft.com/IS0009.php\">Incansoft Translator</a> is not valid. This may be due to a typo when entering it in the <b>Configuration</b> file, or your <b>Hosting Service</b> not supporting all of the required <b>Modules</b>.";
$strSupport = "<br/><br/>If you believe this message was received in error, please contact <a href=\"http://www.incansoft.com/Support.php\">Incansoft Support</a> for assistance. Be certain to provide all of the relevant details we need to assist you in resolving the issue.</b>";
checklicense( $regKeys );
if ( !( $datLink = @mysql_connect( $datHost, $datUser, $datPass ) ) )
{
    exit( showmysqlerror( "1" ) );
}
if ( !@mysql_select_db( $datName ) )
{
    exit( showmysqlerror( "2" ) );
}
if ( !mysql_query( "CREATE TABLE IF NOT EXISTS Translate (ID INT NULL AUTO_INCREMENT , PageURL MEDIUMTEXT NULL , PageLang VARCHAR(8) NULL , PageContent LONGTEXT NULL , TransDate VARCHAR(10) NULL , PRIMARY KEY (`ID`))" ) )
{
    exit( showmysqlerror( "3" ) );
}
if ( isset( $_GET['Lang'], $_GET['Page'] ) )
{
    header( "location: ".$_SERVER['HTTP_REFERER'] );
    exit( );
}
$strLang = strtoupper( $_GET['Lang'] );
$strPage = $_GET['Page'];
if ( !isset( $_GET['NOCACHE'] ) )
{
    $strCached = mysql_fetch_array( mysql_query( "SELECT * FROM Translate WHERE PageURL = '".$strPage."' AND PageLang = '".$strLang."' LIMIT 1" ) );
    if ( $strCached['PageContent'] != "" )
    {
        if ( strtotime( date( "Y-m-d" ) ) - strtotime( $strCached['TransDate'] ) <= $strCache * 86400 )
        {
            echo html_entity_decode( stripslashes( $strCached['PageContent'] ) );
            exit( );
        }
        mysql_query( "DELETE FROM Translate WHERE PageURL = '".$strPage."' AND PageLang = '".$strLang."' LIMIT 1" );
    }
}
( "1.0", "UTF-8" );
$objDocs = new DOMDocument( );
$strDocs = curlgetcontents( $strPage );
$objDocs->loadHTML( $strDocs );
parsedom( $objDocs );
$strData = $objDocs->saveHTML( )."<script type=\"text/JavaScript\">document.getElementById(\"Translator\").style.display = \"none\";</script>";
$strMeta = get_meta_tags( $strPage );
$strDesc = json_decode( curlgetcontents( "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=".urlencode( $strMeta['description'] )."&langpair=".$strBase."%7C".$strLang ) );
$strKeyw = json_decode( curlgetcontents( "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=".urlencode( $strMeta['keywords'] )."&langpair=".$strBase."%7C".$strLang ) );
$strData = str_replace( $strMeta['description'], $strDesc->responseData->translatedText, str_replace( $strMeta['keywords'], $strKeyw->responseData->translatedText, $strData ) );
mysql_query( "INSERT INTO Translate (PageURL, PageLang, PageContent, TransDate) VALUES('".$strPage."', '".$strLang."', '".addslashes( $strData )."', '".date( "Y-m-d" )."')" );
mysql_query( "DELETE FROM Translate WHERE PageURL = ''" );
echo html_entity_decode( $strData );
?>