function Newnews(&$smarty, &$form)
{
    $news = new Noticias($smarty, $form);
    if (isset($form['page'])) {
        if (is_array($_FILES)) {
            ## se há arquivos enviados.
            foreach ($_FILES as $nome => $file) {
                $arquivo = new Arquivo();
                $arquivo->SetOrigem($file['tmp_name']);
                $arquivo->SetDestino(NOTICIAS_DIR_IMG);
                $arquivo->SetPropriedades($file);
                if ($arquivo->error) {
                    return $smarty->getFinishError($arquivo->error);
                }
                if ($arquivo->SetMimetype($arquivo->prop['filename'], array('jpg', 'jepg', 'gif', 'png'), $file['type']) == true) {
                    return $smarty->getFinishError('ERROR_017');
                }
                if ($arquivo->UploadFile() == true) {
                    return $smarty->getFinishError('ERROR_021');
                }
                $thb[$nome] = $arquivo->Thumbnail(NOTICIAS_THB_SIZE);
                $arquivo->FileLogs($nome);
                $form[$nome] = $arquivo->filelog[$nome]['filename'];
                $form[$nome . '_thb'] = $thb[$nome]['thb_name'];
            }
        }
        return $news->NewNoticias($smarty, $form);
    }
}
function smarty_function_SelectFolders($params, &$smarty)
{
    if (!$params['src'] || $params['src'] == "") {
        return $smarty->getFinishError('traducao_erro_01');
    }
    if (!$params['id'] || $params['id'] == "") {
        return $smarty->getFinishError('traducao_erro_02');
    }
    if (!$params['src'] || $params['src'] == "") {
        $params['src'] = $smarty->SelectFolders['src'];
    }
    if (!$params['list'] || $params['list'] == "") {
        $params['list'] = 'file';
    }
    $optionSelect = '<select id="' . $params["id"] . '" name="' . $params["id"] . '"';
    if (isset($params["size"]) && $params["size"] != "") {
        $optionSelect .= 'size="' . $params["size"] . '"';
    }
    if (isset($params["height"]) && $params["height"] != "") {
        $optionSelect .= 'height="' . $params["height"] . '"';
    }
    if (isset($params["onChange"]) && $params["onChange"] != "") {
        $optionSelect .= 'onchange="' . $params["onChange"] . '"';
    }
    if (isset($params["onFocus"]) && $params["onFocus"] != "") {
        $optionSelect .= 'onfocus="' . $params["onFocus"] . '"';
    }
    if (isset($params["onBlur"]) && $params["onBlur"] != "") {
        $optionSelect .= 'onblur="' . $params["onBlur"] . '"';
    }
    $optionSelect .= ' >';
    if (isset($params["SetInicial"])) {
        $optionSelect .= '<option value="">' . $params["SetInicial"] . '</option>' . "\r\n";
    }
    $arq = new Arquivo();
    $arq->SetOrigem($params['src']);
    $x = $arq->loadContent($params['list'], $params['limit']);
    foreach ($x as $i => $value) {
        $pt = explode('/', $value);
        $modulonome = array_pop($pt);
        if (isset($params['Ignore'])) {
            $ignore = explode(',', $params['Ignore']);
            if (in_array($modulonome, $ignore)) {
                continue;
            }
        }
        if (isset($params['SetSelectd']) && $params['SetSelectd'] == $modulonome) {
            $optionSelect .= '<option value="' . $modulonome . '" selected="selected">' . $modulonome . '</option>';
        } else {
            $optionSelect .= '<option value="' . $modulonome . '" >' . $modulonome . '</option>';
        }
    }
    $optionSelect .= '</select>';
    return $optionSelect;
}
 function EditNews(&$smarty, $idde, $form)
 {
     unset($form[idde]);
     $tabela = $smarty->cfg['prefix'] . 'news';
     $form = Check::RegForm($form);
     if (is_numeric($idde)) {
         if (is_array($_FILES)) {
             foreach ($_FILES as $nome => $file) {
                 if ($file['tmp_name'] == '') {
                     continue;
                 }
                 $result = $this->SqlSelect("SELECT {$nome},{$nome}_thb FROM {$tabela} WHERE ID_NEWS = '{$idde}'");
                 $item = mysql_fetch_array($result, MYSQL_ASSOC);
                 unlink(realpath(NOTICIAS_DIR_IMG . '/' . $item[$nome]));
                 unlink(realpath(NOTICIAS_DIR_IMG . THUMBNAIL_DIR_IMG . '/' . $item[$nome . '_thb']));
                 $arquivo = new Arquivo();
                 $arquivo->SetOrigem($file['tmp_name']);
                 $arquivo->SetDestino(NOTICIAS_DIR_IMG);
                 $arquivo->SetPropriedades($file);
                 if ($arquivo->error) {
                     return $smarty->getFinishError($arquivo->error);
                 }
                 if ($arquivo->SetMimetype($arquivo->prop['filename'], array('jpg', 'jepg', 'gif', 'png'), $file['type']) == true) {
                     return $smarty->getFinishError('ERROR_017');
                 }
                 if ($arquivo->UploadFile() == true) {
                     return $smarty->getFinishError('ERROR_021');
                 }
                 $thb[$nome] = $arquivo->Thumbnail(NOTICIAS_THB_SIZE);
                 $arquivo->FileLogs($nome);
                 $form[$nome] = $arquivo->filelog[$nome]['filename'];
                 $form[$nome . '_thb'] = $thb[$nome]['thb_name'];
             }
         }
         $sql = $this->SqlUpdate($tabela, $form, "ID_NEWS = '{$idde}'");
         $request = $this->SqlSelect($sql);
         if ($request != 1) {
             return $request;
         }
     }
 }
function smarty_function_LoadLingua($params, &$smarty)
{
    if (!$params['src'] || $params['src'] == "") {
        return $smarty->getFinishError('traducao_erro_01');
    }
    if (!$params['id'] || $params['id'] == "") {
        return $smarty->getFinishError('traducao_erro_02');
    }
    if (!$params['send'] || $params['send'] == "") {
        return $smarty->getFinishError('traducao_erro_04');
    }
    $arq = new Arquivo();
    $arq->SetOrigem($params['src']);
    $x = $arq->loadPastas();
    $a = '<select name="' . $params['id'] . '" id="' . $params['id'] . '" onchange="CheckForm(\'' . $params['send'] . '\')">';
    $a .= '<option name="escolha" value="0" selected="selected">' . $smarty->get_config_vars('trad_select') . '</option>';
    foreach ($x as $i => $value) {
        $pt = explode('/', $value);
        $modulonome = array_pop($pt);
        $a .= '<option value="' . $modulonome . '" >' . $modulonome . '</option>';
    }
    $a .= '</select>';
    return $a;
}
function smarty_insert_editores($params, &$smarty)
{
    // Automatically calculates the editor base path based on the _samples directory.
    // This is usefull only for these samples. A real application should use something like this:
    // $oFCKeditor->BasePath = '/fckeditor/' ;	// '/fckeditor/' is the default value.
    function reloadlng($str, &$smarty)
    {
        foreach (glob("./modulos/*", GLOB_ONLYDIR) as $dirname) {
            foreach (glob($dirname . '/' . $smarty->cfg['language_atual'] . '.*.conf') as $filename) {
                $smarty->config_load(realpath($filename), "atual");
            }
        }
        if ($smarty->get_config_vars($str) == '') {
            return $str;
        }
        return $smarty->get_config_vars($str);
    }
    if (!isset($params['InstanceName']) || empty($params['InstanceName'])) {
        $smarty->trigger_error('fckeditor: required parameter "InstanceName" missing');
    }
    if (isset($smarty->FCKCFG['Width'])) {
        $base_arguments['Width'] = $smarty->FCKCFG['Width'];
    } elseif (isset($params['Width'])) {
        $base_arguments['Width'] = $smarty->params['Width'];
    } else {
        $base_arguments['Width'] = '100%';
    }
    if (isset($smarty->FCKCFG['Height'])) {
        $base_arguments['Height'] = $smarty->FCKCFG['Height'];
    } elseif (isset($params['Height'])) {
        $base_arguments['Height'] = $smarty->params['Height'];
    } else {
        $base_arguments['Height'] = '380';
    }
    if (isset($smarty->FCKCFG['ToolbarSet'])) {
        $base_arguments['ToolbarSet'] = $smarty->FCKCFG['ToolbarSet'];
    } elseif (isset($params['ToolbarSet'])) {
        $base_arguments['ToolbarSet'] = $smarty->params['ToolbarSet'];
    } else {
        $base_arguments['ToolbarSet'] = 'Basic';
    }
    if (isset($smarty->FCKCFG['patchSiteTemplate'])) {
        $base_arguments['patchSiteTemplate'] = $smarty->FCKCFG['patchSiteTemplate'];
    } elseif (isset($params['patchSiteTemplate'])) {
        $base_arguments['patchSiteTemplate'] = $smarty->params['patchSiteTemplate'];
    } else {
        $base_arguments['patchSiteTemplate'] = './templates';
    }
    $config_arguments = array('DocType' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', 'AutoDetectLanguage' => false, 'DefaultLanguage' => $_SESSION['language'], 'CustomConfigurationsPath' => "atrconfig.js", 'LinkDlgHideTarget' => true, 'DisableObjectResizing' => true, 'DisableFFTableHandles' => true, 'LinkDlgHideTarget' => true, 'LinkDlgHideAdvanced' => true, 'ImageDlgHideLink' => true, 'ImageDlgHideAdvanced' => true, 'FlashDlgHideAdvanced' => true, 'FormatOutput' => true, 'FormatSource' => true);
    // Use all other parameters for the config array (replace if needed)
    $other_arguments = array_diff_assoc($params, $base_arguments);
    $config_arguments = array_merge($config_arguments, $other_arguments);
    // parametro Value
    $oFCKeditor = new FCKeditor($params['InstanceName']);
    $oFCKeditor->Config = $config_arguments;
    $file = new Arquivo();
    $sBasePath = '' . $smarty->get_config_vars('modulo_dir') . 'FCKeditor/';
    if ($smarty->FCKCFG['ID_SITE']) {
        $sBaseSrc = $smarty->get_config_vars('patchsite') . 'sites/' . $smarty->FCKCFG['ID_SITE'] . '/';
        $file->SetOrigem('./' . $sBaseSrc . 'css');
        $css = $file->loadContent('file', '/*.css');
        $oFCKeditor->Config['EditorAreaCSS'] = $smarty->get_config_vars('http') . 'sites/css/' . $smarty->FCKCFG['ID_SITE'] . '/' . basename($css[0]);
        $oFCKeditor->Config['BaseHref'] = $smarty->get_config_vars('http') . 'sites/' . $smarty->FCKCFG['ID_SITE'] . '/';
    } else {
        $sBaseSrc = $smarty->get_config_vars('patchsite');
        $file->SetOrigem($smarty->get_config_vars('patch') . 'css');
        $css = $file->loadContent('file', '/*.css');
        $oFCKeditor->Config['EditorAreaCSS'] = $smarty->get_config_vars('http') . 'css/' . basename($css[0]);
        $oFCKeditor->Config['BaseHref'] = $smarty->get_config_vars('http');
    }
    $oFCKeditor->BasePath = $sBasePath;
    $valor = isset($params['Value']) ? $params['Value'] : $smarty->FCKCFG['Value'];
    if (@is_file(realpath($valor))) {
        $file->SetOrigem($valor, true);
        $pfile = file_get_contents($file->origem);
        if (basename($valor) != 'feet.tpl') {
            $pfile = '<div id="' . $smarty->get_config_vars('page_main') . '">' . $pfile . '</div>';
        }
        $searcharray = array("/(\\<head)(.*)?(\\>)(.*)(\\<\\/head\\>)/siU", "/(\\{)(insert)(.*)(name=\"(.*)\")(.*)\\}/siU", "/([^\"])(\\{\\#)(.*)(\\#\\})/esiU", "/([^\"])(\\{[\$])(.*)(\\})/siU", "/[^\"]\\{(.*)-\\>(.*)(\\s(.*))?(\\})/siU");
        $replacearray = array('', '<span fck="\\2" class="FCK__Inserts"\\3\\4\\6>\\2 \\5</span>', '"<span fck=\\"vars\\" class=\\"FCK__vars\\" value=\\"\\3\\">".reloadlng("\\3",$smarty)."</span>"', '<span fck="\\3" class="FCK__vars">' . $smarty->get_config_vars('fkc_ref') . '\\3</span>', '<span fck="fckobj" class="FCK__vars" fck2="\\1" fck3="\\2" \\3>' . $smarty->get_config_vars('fkc_obj') . ': \\2</span>');
        $oFCKeditor->Value = preg_replace($searcharray, $replacearray, $pfile);
        $smarty->clear_config('atual');
    }
    $oFCKeditor->Config['ImageBrowserURL'] = $smarty->get_config_vars('http') . $smarty->get_config_vars('modulo_dir') . 'FCKeditor/editorftp/browser.html?ServerPath=' . $sBaseSrc . 'templates/&Type=Image&Connector=connectors/connector.php';
    $oFCKeditor->Config['LinkBrowserURL'] = $smarty->get_config_vars('http') . $smarty->get_config_vars('modulo_dir') . 'FCKeditor/editorftp/browser.html?ServerPath=' . $sBaseSrc . 'templates/&Connector=connectors/connector.php';
    $oFCKeditor->Config['FlashBrowserURL'] = $smarty->get_config_vars('http') . $smarty->get_config_vars('modulo_dir') . 'FCKeditor/editorftp/browser.html?ServerPath=' . $sBaseSrc . 'templates/&Type=Flash&Connector=connectors/connector.php';
    $oFCKeditor->Width = $base_arguments['Width'];
    $oFCKeditor->Height = $base_arguments['Height'];
    $oFCKeditor->ToolbarSet = $base_arguments['ToolbarSet'];
    $oFCKeditor->Config['AutoDetectLanguage'] = isset($params['AutoDetectLanguage']) ? $params['AutoDetectLanguage'] : $config_arguments['AutoDetectLanguage'];
    $oFCKeditor->Config['DefaultLanguage'] = isset($params['DefaultLanguage']) ? $params['DefaultLanguage'] : $config_arguments['DefaultLanguage'];
    $oFCKeditor->Config['CustomConfigurationsPath'] = isset($smarty->cfg['CustomConfigurationsPath']) ? $smarty->cfg['CustomConfigurationsPath'] : $config_arguments['CustomConfigurationsPath'];
    return $oFCKeditor->CreateHtml();
}