function defineLocale($lang = '')
{
    switch ($lang) {
        case 'de':
            define('LOCALE', 'de_DE');
            break;
        case 'es':
            define('LOCALE', 'es_ES');
            break;
        case 'fr':
            define('LOCALE', 'fr_FR');
            break;
        case 'it':
            define('LOCALE', 'it_IT');
            break;
        case 'en':
            define('LOCALE', 'en_UK');
            break;
        default:
            define('LOCALE', detect_language());
            break;
    }
    putenv("LC_ALL=" . LOCALE);
    setlocale(LC_ALL, LOCALE);
    bind_textdomain_codeset("messages", "UTF-8");
    bindtextdomain("messages", "./locales");
    textdomain("messages");
}
Exemple #2
0
function defineLocale($lang = '')
{
    $locale = langToLocale($lang);
    if (!empty($locale)) {
        define('LOCALE', $locale);
    } else {
        define('LOCALE', detect_language());
    }
    $results = putenv("LC_ALL=" . LOCALE);
    $results = putenv("LANG=" . LOCALE);
    $results = setlocale(LC_ALL, LOCALE . '.utf8');
    $results = bind_textdomain_codeset("messages", "UTF-8");
    $results = bindtextdomain("messages", "./locales");
    $results = textdomain("messages");
}
Exemple #3
0
 /**
  * Send requests
  * Get all answers
  */
 function send_request()
 {
     $data = array('token' => $this->token, 'request' => $this->request);
     $result = Api::action($this->token, $this->request);
     $result = json_decode(json_encode($result));
     if (!empty($result)) {
         if (!empty($result->level)) {
             $this->level = $result->level;
         }
         if (!empty($result->language) && $result->language != 'en') {
             $this->language = $result->language;
             if (!defined('LOCALE')) {
                 defineLocale($this->language);
             }
         } else {
             if (!defined('LOCALE')) {
                 defineLocale(detect_language());
             }
         }
         if (!empty($result->design)) {
             $this->design = $result->design;
         }
         if (isset($result->id) && $result->id == 0) {
             //Destruct cookies
             setcookie('token', '', 0, '/');
             //	redirect();
         } elseif (!empty($_COOKIE['token'])) {
             //2 weeks
             setcookie('token', $_COOKIE['token'], $_SERVER['REQUEST_TIME'] + 3600 * 24 * 14, '/');
             if (!empty($result->id)) {
                 $this->id = $result->id;
             }
         }
     } else {
         $result = null;
         if (!defined('LOCALE')) {
             defineLocale(detect_language());
         }
     }
     if (!defined('TEMPLATE')) {
         $this->setDesign();
     }
     return $result->request;
 }
Exemple #4
0
function post_is_importable($item, $abook)
{
    if (!$abook) {
        return true;
    }
    if ($abook['abook_channel'] && !feature_enabled($abook['abook_channel'], 'connfilter')) {
        return true;
    }
    if (!$item) {
        return false;
    }
    if (!$abook['abook_incl'] && !$abook['abook_excl']) {
        return true;
    }
    require_once 'include/html2plain.php';
    $text = prepare_text($item['body'], $item['mimetype']);
    $text = html2plain($text);
    $lang = null;
    if (strpos($abook['abook_incl'], 'lang=') !== false || strpos($abook['abook_excl'], 'lang=') !== false) {
        $lang = detect_language($text);
    }
    $tags = count($item['term']) ? $item['term'] : false;
    // exclude always has priority
    $exclude = $abook['abook_excl'] ? explode("\n", $abook['abook_excl']) : null;
    if ($exclude) {
        foreach ($exclude as $word) {
            $word = trim($word);
            if (substr($word, 0, 1) === '#' && $tags) {
                foreach ($tags as $t) {
                    if ($t['type'] == TERM_HASHTAG && (substr($t, 1) === substr($word, 1) || substr($word, 1) === '*')) {
                        return false;
                    }
                }
            } elseif (strpos($word, '/') === 0 && preg_match($word, $body)) {
                return false;
            } elseif (strpos($word, 'lang=') === 0 && $lang && strcasecmp($lang, trim(substr($word, 5))) == 0) {
                return false;
            } elseif (stristr($text, $word) !== false) {
                return false;
            }
        }
    }
    $include = $abook['abook_incl'] ? explode("\n", $abook['abook_incl']) : null;
    if ($include) {
        foreach ($include as $word) {
            $word = trim($word);
            if (substr($word, 0, 1) === '#' && $tags) {
                foreach ($tags as $t) {
                    if ($t['type'] == TERM_HASHTAG && (substr($t, 1) === substr($word, 1) || substr($word, 1) === '*')) {
                        return true;
                    }
                }
            } elseif (strpos($word, '/') === 0 && preg_match($word, $body)) {
                return true;
            } elseif (strpos($word, 'lang=') === 0 && $lang && strcasecmp($lang, trim(substr($word, 5))) == 0) {
                return true;
            } elseif (stristr($text, $word) !== false) {
                return true;
            }
        }
    } else {
        return true;
    }
    return false;
}
Exemple #5
0
function item_store_update($arr, $allow_exec = false)
{
    $d = array('item' => $arr, 'allow_exec' => $allow_exec);
    call_hooks('item_store_update', $d);
    $arr = $d['item'];
    $allow_exec = $d['allow_exec'];
    $ret = array('success' => false, 'item_id' => 0);
    if (!intval($arr['uid'])) {
        logger('item_store_update: no uid');
        $ret['message'] = 'no uid.';
        return $ret;
    }
    if (!intval($arr['id'])) {
        logger('item_store_update: no id');
        $ret['message'] = 'no id.';
        return $ret;
    }
    $orig_post_id = $arr['id'];
    $uid = $arr['uid'];
    $orig = q("select * from item where id = %d and uid = %d limit 1", intval($orig_post_id), intval($uid));
    if (!$orig) {
        logger('item_store_update: original post not found: ' . $orig_post_id);
        $ret['message'] = 'no original';
        return $ret;
    }
    // override the unseen flag with the original
    if ($arr['item_flags'] & ITEM_UNSEEN) {
        $arr['item_flags'] = $arr['item_flags'] ^ ITEM_UNSEEN;
    }
    if ($orig[0]['item_flags'] & ITEM_VERIFIED) {
        $orig[0]['item_flags'] = $orig[0]['item_flags'] ^ ITEM_VERIFIED;
    }
    if ($orig[0]['item_flags'] & ITEM_OBSCURED) {
        $orig[0]['item_flags'] = $orig[0]['item_flags'] ^ ITEM_OBSCURED;
    }
    $arr['item_flags'] = intval($arr['item_flags']) | $orig[0]['item_flags'];
    $arr['item_restrict'] = intval($arr['item_restrict']) | $orig[0]['item_restrict'];
    if (array_key_exists('edit', $arr)) {
        unset($arr['edit']);
    }
    $arr['mimetype'] = x($arr, 'mimetype') ? notags(trim($arr['mimetype'])) : 'text/bbcode';
    if ($arr['mimetype'] == 'application/x-php' && !$allow_exec) {
        logger('item_store: php mimetype but allow_exec is denied.');
        $ret['message'] = 'exec denied.';
        return $ret;
    }
    if (!($arr['item_flags'] & ITEM_OBSCURED)) {
        $arr['lang'] = detect_language($arr['body']);
        // apply the input filter here - if it is obscured it has been filtered already
        $arr['body'] = z_input_filter($arr['uid'], $arr['body'], $arr['mimetype']);
        if (local_user() && !$arr['sig']) {
            $channel = get_app()->get_channel();
            if ($channel['channel_hash'] === $arr['author_xchan']) {
                $arr['sig'] = base64url_encode(rsa_sign($arr['body'], $channel['channel_prvkey']));
                $arr['item_flags'] |= ITEM_VERIFIED;
            }
        }
        $allowed_languages = get_pconfig($arr['uid'], 'system', 'allowed_languages');
        if (is_array($allowed_languages) && $arr['lang'] && !array_key_exists($arr['lang'], $allowed_languages)) {
            $translate = array('item' => $arr, 'from' => $arr['lang'], 'to' => $allowed_languages, 'translated' => false);
            call_hooks('item_translate', $translate);
            if (!$translate['translated'] && intval(get_pconfig($arr['uid'], 'system', 'reject_disallowed_languages'))) {
                logger('item_store: language ' . $arr['lang'] . ' not accepted for uid ' . $arr['uid']);
                $ret['message'] = 'language not accepted';
                return $ret;
            }
            $arr = $translate['item'];
        }
        if ($arr['item_private']) {
            $key = get_config('system', 'pubkey');
            $arr['item_flags'] = $arr['item_flags'] | ITEM_OBSCURED;
            if ($arr['title']) {
                $arr['title'] = json_encode(crypto_encapsulate($arr['title'], $key));
            }
            if ($arr['body']) {
                $arr['body'] = json_encode(crypto_encapsulate($arr['body'], $key));
            }
        }
    }
    if (x($arr, 'object') && is_array($arr['object'])) {
        activity_sanitise($arr['object']);
        $arr['object'] = json_encode($arr['object']);
    }
    if (x($arr, 'target') && is_array($arr['target'])) {
        activity_sanitise($arr['target']);
        $arr['target'] = json_encode($arr['target']);
    }
    if (x($arr, 'attach') && is_array($arr['attach'])) {
        activity_sanitise($arr['attach']);
        $arr['attach'] = json_encode($arr['attach']);
    }
    unset($arr['id']);
    unset($arr['uid']);
    unset($arr['aid']);
    unset($arr['mid']);
    unset($arr['parent']);
    unset($arr['parent_mid']);
    unset($arr['created']);
    unset($arr['author_xchan']);
    unset($arr['owner_xchan']);
    unset($arr['thr_parent']);
    unset($arr['llink']);
    $arr['edited'] = x($arr, 'edited') !== false ? datetime_convert('UTC', 'UTC', $arr['edited']) : datetime_convert();
    $arr['expires'] = x($arr, 'expires') !== false ? datetime_convert('UTC', 'UTC', $arr['expires']) : $orig[0]['expires'];
    if (array_key_exists('comments_closed', $arr) && $arr['comments_closed'] != NULL_DATE) {
        $arr['comments_closed'] = datetime_convert('UTC', 'UTC', $arr['comments_closed']);
    } else {
        $arr['comments_closed'] = $orig[0]['comments_closed'];
    }
    $arr['commented'] = $orig[0]['commented'];
    $arr['received'] = datetime_convert();
    $arr['changed'] = datetime_convert();
    $arr['diaspora_meta'] = x($arr, 'diaspora_meta') ? $arr['diaspora_meta'] : $orig[0]['diaspora_meta'];
    $arr['location'] = x($arr, 'location') ? notags(trim($arr['location'])) : $orig[0]['location'];
    $arr['coord'] = x($arr, 'coord') ? notags(trim($arr['coord'])) : $orig[0]['coord'];
    $arr['verb'] = x($arr, 'verb') ? notags(trim($arr['verb'])) : $orig[0]['verb'];
    $arr['obj_type'] = x($arr, 'obj_type') ? notags(trim($arr['obj_type'])) : $orig[0]['obj_type'];
    $arr['object'] = x($arr, 'object') ? trim($arr['object']) : $orig[0]['object'];
    $arr['tgt_type'] = x($arr, 'tgt_type') ? notags(trim($arr['tgt_type'])) : $orig[0]['tgt_type'];
    $arr['target'] = x($arr, 'target') ? trim($arr['target']) : $orig[0]['target'];
    $arr['plink'] = x($arr, 'plink') ? notags(trim($arr['plink'])) : $orig[0]['plink'];
    $arr['allow_cid'] = array_key_exists('allow_cid', $arr) ? trim($arr['allow_cid']) : $orig[0]['allow_cid'];
    $arr['allow_gid'] = array_key_exists('allow_gid', $arr) ? trim($arr['allow_gid']) : $orig[0]['allow_gid'];
    $arr['deny_cid'] = array_key_exists('deny_cid', $arr) ? trim($arr['deny_cid']) : $orig[0]['deny_cid'];
    $arr['deny_gid'] = array_key_exists('deny_gid', $arr) ? trim($arr['deny_gid']) : $orig[0]['deny_gid'];
    $arr['item_private'] = array_key_exists('item_private', $arr) ? intval($arr['item_private']) : $orig[0]['item_private'];
    $arr['title'] = array_key_exists('title', $arr) && strlen($arr['title']) ? trim($arr['title']) : '';
    $arr['body'] = array_key_exists('body', $arr) && strlen($arr['body']) ? trim($arr['body']) : '';
    $arr['attach'] = x($arr, 'attach') ? notags(trim($arr['attach'])) : $orig[0]['attach'];
    $arr['app'] = x($arr, 'app') ? notags(trim($arr['app'])) : $orig[0]['app'];
    //	$arr['item_restrict'] = ((x($arr,'item_restrict')) ? intval($arr['item_restrict'])       : $orig[0]['item_restrict'] );
    //	$arr['item_flags']    = ((x($arr,'item_flags'))    ? intval($arr['item_flags'])          : $orig[0]['item_flags'] );
    $arr['sig'] = x($arr, 'sig') ? $arr['sig'] : '';
    $arr['layout_mid'] = array_key_exists('layout_mid', $arr) ? dbesc($arr['layout_mid']) : $orig[0]['layout_mid'];
    $arr['public_policy'] = x($arr, 'public_policy') ? notags(trim($arr['public_policy'])) : $orig[0]['public_policy'];
    $arr['comment_policy'] = x($arr, 'comment_policy') ? notags(trim($arr['comment_policy'])) : $orig[0]['comment_policy'];
    call_hooks('post_remote_update', $arr);
    if (x($arr, 'cancel')) {
        logger('item_store_update: post cancelled by plugin.');
        $ret['message'] = 'cancelled.';
        return $ret;
    }
    // pull out all the taxonomy stuff for separate storage
    $terms = null;
    if (array_key_exists('term', $arr)) {
        $terms = $arr['term'];
        unset($arr['term']);
    }
    dbesc_array($arr);
    logger('item_store_update: ' . print_r($arr, true), LOGGER_DATA);
    $str = '';
    foreach ($arr as $k => $v) {
        if ($str) {
            $str .= ",";
        }
        $str .= " `" . $k . "` = '" . $v . "' ";
    }
    $r = dbq("update `item` set " . $str . " where id = " . $orig_post_id . " limit 1");
    if ($r) {
        logger('item_store_update: updated item ' . $orig_post_id, LOGGER_DEBUG);
    } else {
        logger('item_store_update: could not update item');
        $ret['message'] = 'DB update failed.';
        return $ret;
    }
    $r = q("delete from term where oid = %d and otype = %d", intval($orig_post_id), intval(TERM_OBJ_POST));
    if ($terms && is_array($terms)) {
        foreach ($terms as $t) {
            q("insert into term (uid,oid,otype,type,term,url)\n\t\t\t\tvalues(%d,%d,%d,%d,'%s','%s') ", intval($uid), intval($orig_post_id), intval(TERM_OBJ_POST), intval($t['type']), dbesc($t['term']), dbesc($t['url']));
        }
        $arr['term'] = $terms;
    }
    call_hooks('post_remote_update_end', $arr);
    send_status_notifications($orig_post_id, $arr);
    tag_deliver($uid, $orig_post_id);
    $ret['success'] = true;
    $ret['item_id'] = $orig_post_id;
    return $ret;
}
Exemple #6
0
/**
 * Adds data to the automatic translation system.
 * 
 * Use this to add a bunch of data to the translation system.
 * Sample is best to understand:
 * <code php>
 * function SomeControllersInitMethod()
 * {
 *     $str_const = default_string('TXT_TEST','Hello {user.name}! I want to tell you all about {product.name}. Is {user.email} your email address?');
 *     add_trans_data('user',UserModel::Make()->eq('id',1)->current());
 *     add_trans_data('product',ProductModel::Make()->eq('id',1)->current());
 *     $this->content($str_content);
 * }
 * </code>
 * @param string $name Name of the data
 * @param mixed $data The data do add. Can be int, bool string, object, array, ...
 * @param int $depth Current recursion depth. Ignore this, it's internal only.
 * @return void
 */
function add_trans_data($name, $data, $depth = 0)
{
    if ($data instanceof \ScavixWDF\Model\DataSource) {
        return;
    }
    if ($data instanceof \ScavixWDF\WdfException) {
        return;
    }
    if ($data instanceof \ScavixWDF\Base\Renderable) {
        return;
    }
    // todo: more class-based exceptions
    if ($depth > 1) {
        return;
    }
    $name = str_replace(array('{', '}'), array('', ''), $name);
    if ($data instanceof Model) {
        $data = $data->AsArray();
    }
    if ($data instanceof DateTime) {
        if (!isset($GLOBALS['current_language'])) {
            detect_language();
        }
        $ci = Localization::getCultureInfo($GLOBALS['current_language']);
        $GLOBALS['translation']['data'][$name . "_asdate"] = $ci->FormatDate($data);
        $data = $ci->FormatDateTime($data);
    }
    if (is_object($data)) {
        $data = (array) $data;
    }
    if (is_array($data)) {
        foreach ($data as $k => $v) {
            add_trans_data("{" . $name . "." . $k . "}", $v, $depth + 1);
        }
        return;
    }
    $GLOBALS['translation']['data'][$name] = $data;
}
Exemple #7
0
 function _init_input()
 {
     if (isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_COOKIE['GLOBALS']) || isset($_FILES['GLOBALS'])) {
         system_error('request_tainting');
     }
     if (!MAGIC_QUOTES_GPC) {
         $_GET = daddslashes($_GET);
         $_POST = daddslashes($_POST);
         $_COOKIE = daddslashes($_COOKIE);
         $_FILES = daddslashes($_FILES);
     }
     $prelength = strlen($this->config['cookie']['cookiepre']);
     foreach ($_COOKIE as $key => $val) {
         if (substr($key, 0, $prelength) == $this->config['cookie']['cookiepre']) {
             $this->var['cookie'][substr($key, $prelength)] = $val;
         }
     }
     if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) {
         $_GET = array_merge($_GET, $_POST);
     }
     if (isset($_GET['diy'])) {
         $_GET['diy'] = empty($_GET['diy']) ? '' : $_GET['diy'];
     }
     foreach ($_GET as $k => $v) {
         $this->var['gp_' . $k] = $v;
     }
     if (isset($this->var['gp_page'])) {
         $this->var['gp_page'] = rawurlencode($this->var['gp_page']);
     }
     $this->var['mod'] = empty($this->var['gp_mod']) ? '' : htmlspecialchars($this->var['gp_mod']);
     $this->var['inajax'] = empty($this->var['gp_inajax']) ? 0 : (empty($this->var['config']['output']['ajaxvalidate']) ? 1 : ($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' || $_SERVER['REQUEST_METHOD'] == 'POST' ? 1 : 0));
     $this->var['page'] = empty($this->var['gp_page']) ? 1 : max(1, intval($this->var['gp_page']));
     $this->var['sid'] = $this->var['cookie']['sid'] = isset($this->var['cookie']['sid']) ? htmlspecialchars($this->var['cookie']['sid']) : '';
     $this->var['gp_handlekey'] = !empty($this->var['gp_handlekey']) && preg_match('/^\\w+$/', $this->var['gp_handlekey']) ? $this->var['gp_handlekey'] : '';
     if (empty($this->var['cookie']['saltkey'])) {
         $this->var['cookie']['saltkey'] = random(8);
         dsetcookie('saltkey', $this->var['cookie']['saltkey'], 86400 * 30, 1, 1);
     }
     $this->var['authkey'] = md5($this->var['config']['security']['authkey'] . $this->var['cookie']['saltkey']);
     //---------------------------
     //vot: Multi-Lingual Support
     // set default
     $default_lang = strtolower($this->var['config']['output']['language']);
     $lng = '';
     if ($this->var['config']['enable_multilingual']) {
         // Adjust language names with language titles
         foreach ($this->var['config']['languages'] as $k => $v) {
             if (empty($v['name'])) {
                 $this->var['config']['languages'][$k]['name'] = $v['title'];
             }
         }
         // set language from cookies
         if ($this->var['cookie']['language']) {
             $lng = strtolower($this->var['cookie']['language']);
         }
         // check if the language from GET is valid
         if (isset($this->var['gp_language'])) {
             $tmp = strtolower($this->var['gp_language']);
             if (isset($this->var['config']['languages'][$tmp])) {
                 // set from GET
                 $lng = $tmp;
             }
             // set new language to cookie
             dsetcookie('language', $lng);
             $url = $_SERVER['REQUEST_URI'];
             $url = preg_replace("~[\\?\\&]language\\=\\w*~i", '', $url);
             dheader('Location: ' . $url);
             exit;
         }
         // Check for language auto-detection
         if (!$lng) {
             $detect = (bool) $this->var['config']['detect_language'];
             if ($detect) {
                 $lng = detect_language($this->var['config']['languages'], $default_lang);
                 //DEBUG
                 //echo "Auto-Detect lang=",$lng,"<br>";
             }
         }
     }
     // Set language to default if no language detected
     if (!$lng) {
         $lng = $default_lang;
     }
     //DEBUG
     //echo "Result lng=",$lng,"<br>";
     $this->var['oldlanguage'] = $lng;
     // Store Old Language Value for compare
     // define DISCUZ_LANG
     define('DISCUZ_LANG', $lng);
     // set new language to cookie
     dsetcookie('language', $lng);
     // set new language variables
     $this->var['language'] = $lng;
     $this->var['langpath'] = DISCUZ_ROOT . 'source/language/' . $lng . '/';
     $this->var['langurl'] = $this->var['siteroot'] . 'source/language/' . $lng . '/';
     $this->var['langicon'] = $this->var['config']['languages'][$lng]['icon'];
     $this->var['langname'] = $this->var['config']['languages'][$lng]['name'];
     $this->var['langtitle'] = $this->var['config']['languages'][$lng]['title'];
     $this->var['langdir'] = strtolower($this->var['config']['languages'][$lng]['dir']);
     // define LANGUAGE RTL Suffix
     define('RTLSUFFIX', $this->var['langdir'] == 'rtl' ? '_rtl' : '');
     // set jspath (for include *.js)
     //		$this->var['setting']['jspath'] = $this->var['siteroot'] . 'static/js/';
 }
    $r = array();
    if (file_exists($file)) {
        foreach (file($file) as $line) {
            if (preg_match('/^message(\\d+)=(.*)$/', $line, $match)) {
                $r[$match[1]] = $match[2];
            }
        }
    }
    return $r;
}
// remove trailing slash if there is one:
if (substr($DirLang, -1) == '/') {
    $DirLang = substr($DirLang, 0, strlen($DirLang) - 1);
}
if ($Lang == 'auto') {
    $Lang = detect_language($DirLang);
}
$message = read_language_data("{$DirLang}/awstats-{$Lang}.txt");
if (!$message) {
    $message[7] = 'Statistics for';
    $message[10] = 'Number of visits';
    $message[11] = 'Unique visitors';
    $message[56] = 'Pages';
    $message[57] = 'Hits';
    $message[60] = 'Jan';
    $message[61] = 'Feb';
    $message[62] = 'Mar';
    $message[63] = 'Apr';
    $message[64] = 'May';
    $message[65] = 'Jun';
    $message[66] = 'Jul';
Exemple #9
0
    }
    // check if the language from GET is valid
    if (isset($this->var['gp_language'])) {
        $tmp = strtolower($this->var['gp_language']);
        if (isset($this->var['config']['languages'][$tmp])) {
            // set from GET
            $lng = $tmp;
        }
        //DEBUG
        //echo "_GET lang=",$lng,"<br>";
    }
    // Check for language auto-detection
    if (!$lng) {
        $detect = (bool) $this->var['config']['detect_language'];
        if ($detect) {
            $lng = detect_language($this->var['config']['languages'], $default_lang);
            //DEBUG
            //echo "Detect lang=",$lng,"<br>";
        }
    }
}
// Set language to default if no language detected
if (!$lng) {
    $lng = $default_lang;
}
//DEBUG
//echo "Result lang=",$lng,"<br>";
$this->var['oldlanguage'] = $lng;
// Store Old Language Value for compare
// define DISCUZ_LANG
define('DISCUZ_LANG', $lng);