Exemplo n.º 1
0
function createChildLinks($EN_US_mlid, $EngLinkTitle, $mlid_trans, $currentLanguage)
{
    global $db, $error_log;
    $to_language = array($currentLanguage['sovee_code']);
    $msg = "Creating children for the {$currentLanguage} version of {$EngLinkTitle} -- {$EN_US_mlid} (which is mlid={$mlid_trans})\n";
    fwrite($error_log, $msg);
    // Walk through the EN-US children of the given menu
    $translatedRow = $allrows = array();
    // Find all non-hidden EN-US children of a given EN-US top-level (plid=0) menu
    $q1 = "SELECT * from menu_links WHERE menu_name='primary-links' and plid=\"" . $EN_US_mlid . "\" \n       AND hidden=0  \n       AND (options regexp 's:8:\"langcode\";s:5:\"en-us\"' OR options NOT regexp '\"langcode\"')\n       ORDER BY weight";
    //            OR (options NOT regexp '\"langcode\"'  AND link_path NOT regexp '^node/')
    $r1 = mysql_query($q1, $db);
    sqlErrors($q1);
    $msg = "q1 = {$q1}\n\n";
    $msg .= "Children of {$EngLinkTitle} are:\n";
    while ($myrow = mysql_fetch_assoc($r1)) {
        $allrows[] = $myrow;
        $msg .= "   " . $myrow['link_title'] . "\n";
    }
    fwrite($error_log, $msg);
    foreach ($allrows as $translatedRow) {
        $newPlid = $translatedRow['mlid'];
        $originalPlid = $translatedRow['plid'];
        $translatedRow['plid'] = $translatedRow['p1'] = $mlid_trans;
        $translatedLinkTitle = trim(translateString("en-us", $currentLanguage['sovee_code'], $translatedRow['link_title']));
        $msg = "Translating " . $translatedRow['link_title'] . " to " . $currentLanguage['sovee_code'] . " gives {$translatedLinkTitle}\n\n";
        fwrite($error_log, $msg);
        if (strlen($translatedLinkTitle) < 1) {
            // Use English if Sovee translation fails
            $msg = "> > > Unable to create " . $currentLanguage['sovee_code'] . " for \"" . $translatedRow['link_title'] . "\", using English\n\n";
            fwrite($error_log, $msg);
            $translatedLinkTitle = $currentMenuAry['link_title'];
        }
        $translatedRow['link_title'] = $translatedLinkTitle;
        $translatedRow['options'] = "a:2:{s:10:\"attributes\";a:1:{s:5:\"title\";s:0:\"\";}s:8:\"langcode\";s:" . strlen($currentLanguage['drupal_code']) . ":\"" . $currentLanguage['drupal_code'] . "\";}";
        $EN_US_mlid = $translatedRow['mlid'];
        $translatedRow['mlid'] = "NULL";
        $linkPath = $translatedRow['link_path'];
        $nodeNumber = preg_replace("/node\\//", "", $linkPath);
        if (is_numeric($nodeNumber)) {
            $msg = "Going to translate node {$nodeNumber} into " . $currentLanguage['sovee_code'] . "  . . .\n";
            fwrite($error_log, $msg);
            // Does a translation already exist for this node?
            $existingTranslationAry = checkForTranslatedVersion($nodeNumber, $currentLanguage['drupal_code']);
            $msg = "Checking return from checkForTranslatedVersion\nexistingTranslationAry = \n";
            $msg .= print_r($existingTranslationAry, TRUE);
            fwrite($error_log, $msg);
            if (isset($existingTranslationAry['nid'])) {
                $newNodeID = $existingTranslationAry['nid'];
                $translatedRow['link_title'] = $existingTranslationAry['title'];
                $q6 = "UPDATE node SET status=1, tnid=\"{$nodeNumber}\" WHERE nid=\"{$newNodeID}\" LIMIT 1";
                $r7 = mysql_query($q6, $db);
                $msg = "An existing " . $currentLanguage['drupal_code'] . " translation for node {$nodeNumber}, which is node {$newNodeID}, \"" . $translatedRow['link_title'] . "\"\n";
                $msg .= print_r($existingTranslationAry, TRUE);
                $msg .= $q6 . "\n";
                fwrite($error_log, $msg);
            } else {
                // A translation does NOT exist. Create one
                $msg = "An existing " . $currentLanguage['drupal_code'] . " translation for node {$nodeNumber} does NOT exist.\n";
                $msg .= print_r($existingTranslationAry, TRUE);
                fwrite($error_log, $msg);
                $testAry = translateOneNode($nodeNumber, $to_language, "Menu Generator");
                $newNodeID = $testAry['nid'];
            }
            $q4 = "DELETE FROM menu_links WHERE link_path = \"node/" . $newNodeID . "\"";
            $r4 = mysql_query($q4, $db);
            sqlErrors($q4);
            $translatedRow['link_path'] = "node/" . $newNodeID;
            // Build the INSERT statement
            $q3 = "INSERT INTO menu_links SET ";
            foreach ($translatedRow as $key => $value) {
                if ($value != "NULL") {
                    $q3 .= "{$key} = \"" . addslashes($value) . "\",";
                } else {
                    $q3 .= "{$key} = NULL,";
                }
            }
            $q3 = rtrim($q3, ',');
            $r3 = mysql_query($q3, $db);
            $err_msg = trim(mysql_error($db));
            if (strlen($err_msg) > 0) {
                $msg = "MYSQL_ERROR: {$err_msg}\nQuery = {$q1}\n";
                echo $msg;
                fwrite($error_log, $msg);
            }
            $msg1 = "q3 = {$q3}\n";
            $r5 = mysql_query("SELECT LAST_INSERT_ID() as mlid", $db);
            // Get the mlid of the newly-inserted row
            while ($mtmp = mysql_fetch_assoc($r5)) {
                $mlid_last = $mtmp['mlid'];
            }
            $q4 = "UPDATE menu_links SET p2 = mlid WHERE mlid=\"" . $mlid_last . "\" LIMIT 1";
            $msg1 .= "Q4 = {$q4}\n\n";
            $r4 = mysql_query($q4, $db);
            sqlErrors($q4);
            fwrite($error_log, $msg1);
            // End of if (is_numeric($nodeNumber)) //yes//
        } else {
            // Handle link_path without node identifier
            // ADD NEW CODE FOR LINK_PATH
            $msg = "Looking for link_paths without node identifiers in " . $currentLanguage['drupal_code'] . "\n\n";
            fwrite($error_log, $msg);
            $q5a = "SELECT mlid, link_title from menu_links where link_path = \"{$linkPath}\"\n                        AND menu_name = 'primary-links'\n                        AND options regexp '\"langcode\";s:" . strlen($currentLanguage['drupal_code']) . ":\"" . $currentLanguage['drupal_code'] . "\";'\n                        ORDER BY hidden ASC\n\t\t\tLIMIT 1";
            // We need only one value, take the first visible one, if multiple are present
            $r5a = mysql_query($q5a, $db);
            sqlErrors($q5a);
            if (mysql_num_rows($r5a) > 0) {
                while ($m5a = mysql_fetch_assoc($r5a)) {
                    $thisMlid = $m5a['mlid'];
                    $thisLinkTitle = $m5a['link_title'];
                    $msg = "Found {$thisLinkTitle} at mlid={$thisMlid}\n";
                    fwrite($error_log, $msg);
                }
                $q6a = "UPDATE menu_links SET plid='" . $mlid_trans . "', p1='" . $mlid_trans . "', hidden='0', \n\t\t\t\tlink_title = '" . $translatedLinkTitle . "'\n                                WHERE mlid='" . $thisMlid . "'";
                $msg = "q6a = {$q6a}\n";
                fwrite($error_log, $msg);
                $r6a = mysql_query($q6a, $db);
                sqlErrors($q6a);
            } else {
                //INSERT NEW ROW, GRAB NEW MLID, POPULATE p1
                $q6a = "INSERT INTO menu_links SET\n\t\t\tmenu_name = 'primary-links',\n\t\t\tmlid      = NULL,\n\t\t\tplid      = '" . $mlid_trans . "',\n\t\t\tlink_path = '" . $linkPath . "',\n\t\t\trouter_path = '" . $translatedRow['router_path'] . "',\n\t\t        link_title = '" . $translatedLinkTitle . "',\n\t\t\toptions    = 'a:2:{s:10:\"attributes\";a:1:{s:5:\"title\";s:0:\"\";}s:8:\"langcode\";s:" . strlen($currentLanguage['drupal_code']) . ":\"" . $currentLanguage['drupal_code'] . "\";}',\n\t\t\tmodule     = '" . $translatedRow['module'] . "', \n\t\t\thidden     = '0',\n\t\t\texternal     = '" . $translatedRow['external'] . "',\n\t\t\thas_children =  '" . $translatedRow['has_children'] . "',\n                        expanded     = '" . $translatedRow['expanded'] . "',\n                        weight     = '" . $translatedRow['weight'] . "',\n                        depth     = '" . $translatedRow['depth'] . "',\n                        customized     = '" . $translatedRow['customized'] . "',\n\t\t\tp1             =  '" . $mlid_trans . "',\n\t\t\tupdated    = '0'";
                $msg = "q6a = {$q6a}\n";
                fwrite($error_log, $msg);
                $r6a = mysql_query($q6a, $db);
                sqlErrors($q6a);
                $r7 = mysql_query("SELECT LAST_INSERT_ID() as mlid", $db);
                // Get the mlid of the newly-inserted row
                while ($mtmp = mysql_fetch_assoc($r7)) {
                    $mlid_last = $mtmp['mlid'];
                }
                $q6b = "UPDATE menu_links SET p1 = mlid WHERE mlid=\"" . $mlid_last . "\" LIMIT 1";
                $r6b = mysql_query($q6b, $db);
                $msg = "q6b = {$q6b}\n";
                sqlErrors($q6b);
            }
        }
        // End of if (is_numeric($nodeNumber))
    }
    // End of foreach($allrows as $translatedRow)
}
Exemplo n.º 2
0
    $nodeAry = fetchEnglishNodes($content_type, $modulo);
    //   Translate each English Langauge node into the specified language
    foreach ($nodeAry as $nid) {
        //      $nid = 11419;
        //	$content_type="campaign";
        //  Has the node already been processed?
        $chkQry = "SELECT status from sovee.progress where node=\"" . $nid . "\" AND language=\"" . $to_languages[0] . "\"";
        $chkRslt = mysql_query($chkQry, $db);
        $nodeComplete = 0;
        while ($xrow = mysql_fetch_assoc($chkRslt)) {
            $nodeComplete = $xrow['status'];
        }
        if ($nodeComplete == 0) {
            echo "PROCESSING {$content_type} NODE {$nid}\n\n";
            fwrite($progress_log, "      {$nid}\n");
            $translatedXMLary = translateOneNode($nid, $to_languages, $content_type);
            //			$translationSuccess = $translatedXMLary['status'];
            //			$translatedXML      = $translatedXML['translated_xml'];
        }
    }
}
fclose($error_log);
fclose($progress_log);
# ==================================================================================
#  Translate one Drupal node
#    Return an array containing success/failure code
#    and the translated XML node
#  A failure in translating any part of a node will return a failure code
#  Method:
#    1) Determine $containerArray -- an array of the position of all English strings that need to be translated for this ContentType
#    2) Extract the English strings from this node. Place each string into its own DIV, and separate the DIVs with $separator, and add to $allContainers
Exemplo n.º 3
0
    $content_type = trim($thisRow['type']);
    //      $content_type="featured_article";
    foreach ($languageCodes as $currentLanguage) {
        $soveeLanguageAry = array($currentLanguage['sovee_code']);
        // Obtain a list of nodes of type $content_type
        // that have NOT been translated into the current language
        $q1 = "select nid,tnid,title,language from node where (type='" . $content_type . "' \n\t\t\tAND status=1 AND language='en-us') \n\t\t\tAND nid NOT IN \n\t\t\t(select tnid from node where type='" . $content_type . "' \n\t\t\t  AND status=1 AND language='" . $currentLanguage['drupal_code'] . "')";
        $r1 = mysql_query($q1, $db);
        $err_msg = trim(mysql_error($db));
        if (strlen($err_msg) > 0) {
            $msg = "MYSQL_ERROR: {$err_msg}\nQuery = {$q1}\n";
            echo $msg;
            fwrite($error_log, $msg);
        }
        while ($nodeRow = mysql_fetch_assoc($r1)) {
            $nodeNumber = $nodeRow['nid'];
            $msg = "Translating node {$nodeNumber}, title='" . $nodeRow['title'] . "', into " . $currentLanguage['sovee_code'] . " . . . \n\n";
            echo $msg;
            fwrite($error_log, $msg);
            $translationResult = translateOneNode($nodeNumber, $soveeLanguageAry, "Content Generator");
            // Make sure the source node's tnid points to its nid (tnid = nid for EN-US), allowing all translations to appear in Drupal admin panel translation tables
            $q2 = "UPDATE node set tnid = nid WHERE nid = \"{$nodeNumber}\" LIMIT 1";
            $r2 = mysql_query($q2, $db);
        }
    }
    // End of     foreach($languageCodes as $currentLanguage)
}
// End of    while ($thisRow = mysql_fetch_assoc($rslt))
$msg = "Ending run at " . date("j-F-Y  g:i A") . "\n";
echo $msg;
fwrite($error_log, $msg);