/**
 * Smarty {sugar_evalcolumn_old} function plugin
 *
 * Type:     function<br>
 * Name:     sugar_evalcolumn_old<br>
 * Purpose:  evaluate a string by substituting values in the rowData parameter. Used for ListViews<br>
 * 
 * @author Wayne Pan {wayne at sugarcrm.com
 * @param array
 * @param Smarty
 */
function smarty_function_sugar_evalcolumn_old($params, &$smarty)
{
    if (!isset($params['var']) || !isset($params['rowData'])) {
        if (!isset($params['var'])) {
            $smarty->trigger_error("evalcolumn: missing 'var' parameter");
        }
        if (!isset($params['rowData'])) {
            $smarty->trigger_error("evalcolumn: missing 'rowData' parameter");
        }
        return;
    }
    if ($params['var'] == '') {
        return;
    }
    if (is_array($params['var'])) {
        foreach ($params['var'] as $key => $value) {
            $params['var'][$key] = searchReplace($value, $params['rowData']);
        }
    } else {
        $params['var'] = searchReplace($params['var'], $params['rowData']);
    }
    if (isset($params['toJSON'])) {
        $json = getJSONobj();
        $params['var'] = $json->encode($params['var']);
    }
    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $params['var']);
    } else {
        return $params['var'];
    }
}
/**
 * Elimina las palabras reservadas y las palabras muy cortas del string de búsqueda;
 * 	También llama a la function searchReplace
 *
 * @param  (string) $search       a buscar
 * @param  (array)  $aSearchKey   array con las $searchKey validas (ej: statusApproved, searchUsers)
 * @param  (bool)   $addPlus      agrega a cada palabra el operador '+' para que la palabra sea obligatoria
 * @param  (bool)   $addWildcard  agrega un asterisco a la ultima palabra, para busquedas parciales
 * @return (array)  devuelve      un array con las palabras a buscar
 * */
function cleanSearchString($search, $aSearchKey, $addPlus = true, $addWildcard = false)
{
    $CI =& get_instance();
    $result = array();
    $search = str_replace('  ', ' ', str_replace(config_item('searchKeys'), '', $search));
    if (substr($search, 0, 1) == '"' && substr($search, strlen($search) - 1, 1) == '"') {
        $result = array(searchReplace($CI->db->escape_like_str($search)));
    } else {
        $aSearch = explode(' ', $CI->db->escape_like_str($search));
        for ($i = 0; $i < count($aSearch); $i++) {
            if (strlen($aSearch[$i]) >= 3) {
                // TODO: harckodeta
                $result[] = searchReplace($aSearch[$i]);
            }
        }
    }
    if (empty($result)) {
        return array();
    }
    if ($addWildcard == true) {
        $result[count($result) - 1] = $result[count($result) - 1] . '*';
    }
    for ($i = 0; $i < count($aSearchKey); $i++) {
        $aSearchKey[$i] = '+' . $aSearchKey[$i];
    }
    for ($i = 0; $i < count($result); $i++) {
        $result[$i] = ($addPlus == true ? '+' : '') . $result[$i];
    }
    $result = array_merge($aSearchKey, $result);
    return $result;
}
Example #3
0
    function saveEntriesSearchPage($aWhere, $lastEntryId, $pageSize)
    {
        $aWhere[] = ' entries.entryId > ' . (int) $lastEntryId;
        $lastEntryId = null;
        $values = array();
        $query = " SELECT entryId, entryTitle, entryContent, entries.feedId\n\t\t\tFROM entries\n\t\t\tWHERE " . implode(' AND ', $aWhere) . "\n\t\t\tORDER BY entryId ASC\n\t\t\tLIMIT " . $pageSize . "  ";
        // pr($query); die;
        $query = $this->db->query($query);
        foreach ($query->result_array() as $data) {
            $lastEntryId = $data['entryId'];
            $searchKey = 'searchEntries searchInFeedId' . $data['feedId'];
            $feed = $this->Feeds_Model->get($data['feedId']);
            $values[$data['entryId']] = array('entityTypeId' => $this->db->escape(config_item('entityTypeEntry')), 'entityId' => $this->db->escape($data['entryId']), 'entityFullSearch' => $this->db->escape(searchReplace($searchKey . ' ' . $data['entryTitle'] . ' ' . rip_tags($data['entryContent']) . ' ' . $feed['feedName'])), 'entityNameSearch' => $this->db->escape(searchReplace($searchKey . ' ' . $data['entryTitle'] . ' ' . $feed['feedName'])), 'entityName' => $this->db->escape($data['entryTitle']));
        }
        $query->free_result();
        if (!empty($values)) {
            $inserts = array();
            foreach ($values as $data) {
                $inserts[] = "( " . implode(", ", $data) . " )";
            }
            $query = ' INSERT INTO entities_search
				(entityTypeId, entityId, entityFullSearch, entityNameSearch, entityName)
				VALUES
				' . implode(', ', $inserts) . '
				ON DUPLICATE KEY UPDATE
				entityFullSearch = VALUES(entityFullSearch),
				entityNameSearch = VALUES(entityNameSearch),
				entityName       = VALUES(entityName) ';
            //vd($query); die;
            $this->db->query($query);
        }
        unset($values);
        unset($inserts);
        return $lastEntryId;
    }
function translate($offset = 1)
{
    global $_POST;
    extract($_POST);
    require_lib("validate");
    $v = new validate();
    $v->isOk($language, "string", 1, 2, "Invalid language code.");
    $v->isOk($country, "string", 2, 2, "Invalid country code.");
    $v->isOk($encoding, "string", 1, 255, "Invalid character encoding.");
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class=err>{$e['msg']}</li>";
        }
        return enter($confirm);
    }
    $fields = array();
    $fields["untrans"] = "";
    $fields["search"] = "";
    $fields["replace"] = "";
    $fields["sr_inf"] = "";
    extract($fields, EXTR_SKIP);
    if (!isset($untrans)) {
        $untrans = "";
    }
    $locale = $language . "_" . $country;
    $sz_msgdir = "locale/{$locale}/LC_MESSAGES";
    $sz_msgpath = "locale/{$locale}/LC_MESSAGES/messages.po";
    // Create the directory if it does not already exist
    if (!cfs::is_dir($sz_msgdir)) {
        cfs::mkdir($sz_msgdir);
    }
    // Open the pot file
    if (!cfs::is_file($sz_msgpath) || cfs::filesize($sz_msgpath) == 0) {
        $ar_messages = cfs::get_contents("messages.po");
        cfs::put_contents($sz_msgpath, $ar_messages);
    }
    // Retrieve the translation text
    $tl = "";
    $ar_pot_file = cfs::file($sz_msgpath);
    if (!empty($untrans)) {
        $ar_pot_file = removeTranslated($ar_pot_file);
    }
    if (isset($srchrep)) {
        $sr_ar = searchReplace($ar_pot_file, $search, $replace, $locale);
        $ar_pot_file = $sr_ar["file"];
        $sr_inf = "Replaced: <b>{$sr_ar['count']}</b>";
    }
    // Retrieve the amount of msgid's for the offset
    $n_count = 0;
    for ($i = 0; $i < count($ar_pot_file); $i++) {
        if (!isset($ar_pot_file[$i])) {
            continue;
        }
        if (preg_match("/(^msgid \")([^\"]*)(\")/", $ar_pot_file[$i], $ar_matches) && $ar_matches[2] != "") {
            $n_count++;
        }
    }
    // Calculate the page numbers
    $current_page = intval($offset / OFFSET_SIZE) + 1;
    $total_pages = intval($n_count / OFFSET_SIZE) + 1;
    // Calculate the starting value of the next and previous buttons
    $n_next = $offset + OFFSET_SIZE;
    $n_prev = $offset - OFFSET_SIZE;
    // Decide which buttons to display
    if ($n_next > $n_count) {
        $sz_next = "<input type=submit value='" . ct("Translate") . "'>";
    } else {
        $sz_next = "<input type=submit name='next' value='" . ct("Next &raquo") . "'>";
    }
    if ($n_prev < 0) {
        $sz_prev = "";
    } else {
        $sz_prev = "<input type=submit name='prev' value='" . ct("&laquo Previous") . "'>";
    }
    // POT file is empty
    if (!count($ar_pot_file)) {
        $OUTPUT = "<li class='err'>Unable to load translation text.</li>" . mkQuickLinks(ql("locale-translate.php", "Translate Cubit"), ql("locale-settings.php", "Locale Settings"));
        return $OUTPUT;
    }
    // Start reading each line of the translation within the offset
    $n_count2 = 0;
    foreach ($ar_pot_file as $i => $value) {
        if (preg_match("/(^msgid \")([^\"]*)(\")/", $ar_pot_file[$i], $ar_msgid) && $ar_msgid[2] != "") {
            $n_count2++;
            if ($n_count2 >= $offset && $n_count2 < $n_next) {
                if (preg_match("/(^msgstr \")([^\"]*)(\")/", $ar_pot_file[$i + 1], $ar_msgstr)) {
                    $tl .= "<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><b>" . htmlspecialchars($ar_msgid[2]) . "</b></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td align=center>\n\t\t\t\t\t\t<input type=text style='width: 495px;\n\t\t\t\t\t\tbackground:'" . bgcolorg() . "' name='tl[" . ($i + 1) . "]'\n\t\t\t\t\t\tvalue='{$ar_msgstr['2']}'>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
                }
            }
        }
    }
    require "locale_codes.php";
    // Retrieve the name of the language
    if (isset($ar_languages) && is_array($ar_languages)) {
        $lang_out = "";
        foreach ($ar_languages as $lang_name => $lang_code) {
            if ($lang_code == $language) {
                $lang_out = $lang_name;
            }
        }
    } else {
        $OUTPUT = "<li class='err'>Unable to load language codes.</li>" . mkQuickLinks(ql("locale-translate.php", "Translate Cubit"), ql("locale-settings.php", "Locale Settings"));
        return $OUTPUT;
    }
    // Retrieve the name of the country
    if (isset($ar_countries) && is_array($ar_countries)) {
        $country_out = "";
        foreach ($ar_countries as $country_name => $country_code) {
            if ($country_code == $country) {
                $country_out = $country_name;
            }
        }
    } else {
        $OUTPUT = "<li class='err'>Unable to load country codes.</li>" . mkQuickLinks(ql("locale-translate.php", "Translate Cubit"), ql("locale-settings.php", "Locale Settings"));
        return $OUTPUT;
    }
    $OUTPUT = "<center>\n\t<h3>" . ct("Translate Cubit") . "</h3>\n\t<form method=post action='" . SELF . "' name='form'>\n\t<input type=hidden name=key value='write'>\n\t<input type=hidden name=loffset value='{$offset}'>\n\t<input type=hidden name=language value='{$language}'>\n\t<input type=hidden name=country value='{$country}'>\n\t<input type=hidden name=encoding value='{$encoding}'>\n\t<input type='hidden' name='total_pages' value='{$total_pages}' />\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=500>\n      <tr>\n        <th colspan=2>" . ct("Translation Info") . "</th>\n      </tr>\n\t  <tr class='" . bg_class() . "'>\n\t    <td>" . ct("Language") . "</td>\n\t    <td>{$lang_out}</td>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t    <td>" . ct("Country") . "</td>\n\t    <td>{$country_out}</td>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t    <td>" . ct("Character Encoding") . "</td>\n\t    <td>\n\t      {$encoding}\n\t    </td>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t    <td>" . ct("Page") . "</td>\n\t    <td>\n\t    \t<input type='text' name='page_txt' size='3' value='{$current_page}'\n\t    \tstyle='text-align: center'> of {$total_pages}\n\t    \t<input type='submit' name='page_btn' value='Goto' />\n\t    </td>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t  \t<td colspan='2' align='center'>\n\t  \t\t<input type='checkbox' name='untrans' value='checked' {$untrans}\n\t  \t\tonchange='javascript:document.form.submit();' />\n\t  \t\tDisplay Only Untranslated Sentences\n\t  \t</td>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t  \t<td colspan='2'>\n\t  \t\t<table " . TMPL_tblDflts . " width='100%'>\n\t  \t\t\t<tr>\n\t  \t\t\t\t<th colspan='5'>Search and Replace</th>\n\t  \t\t\t</tr>\n\t  \t\t\t<tr class='" . bg_class() . "'>\n\t  \t\t\t\t<td>Search</td>\n\t  \t\t\t\t<td>\n\t  \t\t\t\t\t<input type='text' name='search' value='{$search}'\n\t  \t\t\t\t\tstyle='width: 100%' />\n\t  \t\t\t\t</td>\n\t  \t\t\t\t<td>Replace</td>\n\t  \t\t\t\t<td>\n\t  \t\t\t\t\t<input type='text' name='replace' value='{$replace}'\n\t  \t\t\t\t\tstyle='width: 100%' />\n\t  \t\t\t\t</td>\n\t  \t\t\t\t<td>\n\t  \t\t\t\t\t<input type='submit' name='srchrep' value='Search & Replace'\n\t  \t\t\t\t\tstyle='width: 100%' />\n\t  \t\t\t\t</td>\n\t  \t\t\t</tr>\n\t  \t\t\t<tr>\n\t  \t\t\t\t<td colspan='5' align='center'>{$sr_inf}</td>\n\t  \t\t\t</tr>\n\t  \t\t</table>\n\t  \t</td>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t    <td colspan=2>\n\t      Some of the translation sentences includes special words and characters\n\t      such as `" . htmlspecialchars("&laquo") . "', `" . htmlspecialchars("&raquo") . "', `<', `<<', ect... Please include these words\n\t      and characters in your translation sentences as well.<p>\n\t      After clicking <i>" . ct("Next") . "</i> or <i>" . ct("Previous") . "</i> the current state of the translation is automatically saved.\n\t  </tr>\n\t</table>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=500>\n\t  <tr>\n\t    <th>" . ct("Translate") . "</th>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t    <td>\n\t      <table border=0 cellpadding=0 cellspacing=0 width=500>\n\t        <tr class='" . bg_class() . "'>\n\t          <td width=50% align=left>{$sz_prev}</td>\n\t          <td width=50% align=right>{$sz_next}</td>\n\t        </tr>\n\t      </table>\n\t    </td>\n\t  </tr>\n\t  {$tl}\n\t  <tr class='" . bg_class() . "'>\n\t    <td>\n\t      <table border=0 cellpadding=0 cellspacing=0 width=500>\n\t        <tr class='" . bg_class() . "'>\n\t          <td width=50% align=left>{$sz_prev}</td>\n\t          <td width=50% align=right>{$sz_next}</td>\n\t        </tr>\n\t      </table>\n\t    </td>\n\t  </tr>\n\t</table>\n\t</form>\n\t</center>" . mkQuickLinks(ql("locale-translate.php", "Translate Cubit"), ql("locale-settings.php", "Locale Settings"));
    return $OUTPUT;
}