예제 #1
0
 /**
  * get_addons function.
  *
  * Function to get all addons
  *
  * @access public
  * @param int    $selected    (default: 1)      - name or directory of the the addon to be selected in a dropdown
  * @param string $type        (default: '')     - type of addon - can be an array
  * @param string $function    (default: '')     - function of addon- can be an array
  * @param string $order       (default: 'name') - value to handle "ORDER BY" for database request of addons
  * @param boolean $check_permission (default: false) - wether to check module permissions (BE call) or not
  * @return array
  */
 public static function get_addons($selected = 1, $type = '', $function = '', $order = 'name', $check_permission = false)
 {
     $self = self::getInstance();
     if (CAT_Backend::isBackend()) {
         $check_permission = true;
     }
     $and = '';
     $get_type = '';
     $get_function = '';
     $where = '';
     if (is_array($type)) {
         $get_type = '( ';
         $and = ' AND ';
         foreach ($type as $item) {
             $get_type .= 'type = \'' . htmlspecialchars($item) . '\'' . $and;
         }
         $get_type = substr($get_type, 0, -5) . ' )';
     } else {
         if ($type != '') {
             $and = ' AND ';
             $get_type = 'type = \'' . htmlspecialchars($type) . '\'';
         }
     }
     if (is_array($function)) {
         $get_function = $and . '( ';
         foreach ($function as $item) {
             $get_function .= 'function = \'' . htmlspecialchars($item) . '\' AND ';
         }
         $get_function = substr($get_function, 0, -5) . ' )';
     } else {
         if ($function != '') {
             $get_function = $and . 'function = \'' . htmlspecialchars($function) . '\'';
         }
     }
     if ($get_type || $get_function) {
         $where = 'WHERE ';
     }
     // ==================
     // ! Get all addons
     // ==================
     $addons_array = array();
     $addons = $self->db()->query(sprintf("SELECT * FROM `:prefix:addons` %s%s%s ORDER BY 'type' ASC, '%s' ASC", $where, $get_type, $get_function, htmlspecialchars($order)));
     if ($addons->rowCount() > 0) {
         $counter = 1;
         while ($addon = $addons->fetchRow()) {
             if (!$check_permission || $addon['type'] != 'language' && CAT_Users::get_permission($addon['directory'], $addon['type']) || $addon['type'] == 'language') {
                 $addons_array[$counter] = array_merge($addon, array('VALUE' => $addon['directory'], 'NAME' => $addon['name'], 'SELECTED' => $selected == $counter || $selected == $addon['name'] || $selected == $addon['directory'] ? true : false));
                 $counter++;
             }
         }
     }
     // reorder array
     $addons_array = CAT_Helper_Array::ArraySort($addons_array, $order, 'asc', true);
     return $addons_array;
 }
예제 #2
0
파일: I18n.php 프로젝트: ircoco/BlackCatCMS
 /**
  * This method is based on code you may find here:
  * http://aktuell.de.selfhtml.org/artikel/php/httpsprache/
  *
  *
  **/
 private function getBrowserLangs($strict_mode = true)
 {
     if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         return $this->_config['defaultlang'];
     }
     $browser_langs = array();
     $lang_variable = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
     if (empty($lang_variable)) {
         return $this->_config['defaultlang'];
     }
     $accepted_languages = preg_split('/,\\s*/', $lang_variable);
     $current_q = 0;
     foreach ($accepted_languages as $accepted_language) {
         // match valid language entries
         $res = preg_match('/^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;\\s*q=(0(?:\\.[0-9]{1,3})?|1(?:\\.0{1,3})?))?$/i', $accepted_language, $matches);
         // invalid syntax
         if (!$res) {
             continue;
         }
         // get language code
         $lang_code = explode('-', $matches[1]);
         if (isset($matches[2])) {
             $lang_quality = (double) $matches[2];
         } else {
             $lang_quality = 1.0;
         }
         while (count($lang_code)) {
             $browser_langs[] = array('lang' => strtoupper(join('-', $lang_code)), 'qual' => $lang_quality);
             // don't use abbreviations in strict mode
             if ($strict_mode) {
                 break;
             }
             array_pop($lang_code);
         }
     }
     // order array by quality
     $sorter = new CAT_Helper_Array();
     $langs = $sorter->ArraySort($browser_langs, 'qual', 'desc', true);
     $ret = array();
     foreach ($langs as $lang) {
         $ret[] = $lang['lang'];
     }
     return $ret;
 }
예제 #3
0
if ($users->checkPermission('addons', 'modules_install')) {
    $addon = CAT_Helper_Addons::getInstance();
    foreach (array('modules', 'templates') as $type) {
        $new = CAT_Helper_Directory::getInstance()->maxRecursionDepth(0)->setSkipDirs($seen_dirs)->getDirectories(CAT_PATH . '/' . $type, CAT_PATH . '/' . $type . '/');
        if (count($new)) {
            foreach ($new as $dir) {
                $info = $addon->checkInfo(CAT_PATH . '/' . $type . '/' . $dir);
                if ($info) {
                    $tpl_data['not_installed_addons'][$type][$counter] = array('is_installed' => false, 'type' => $type, 'INSTALL' => file_exists(CAT_PATH . '/' . $type . '/' . $dir . '/install.php') ? true : false);
                    foreach ($info as $key => $value) {
                        $tpl_data['not_installed_addons'][$type][$counter][str_ireplace('module_', '', $key)] = $value;
                    }
                    $counter++;
                }
            }
            $tpl_data['not_installed_addons'][$type] = CAT_Helper_Array::ArraySort($tpl_data['not_installed_addons'][$type], 'name', 'asc', true);
        }
    }
    $languages = CAT_Helper_Directory::getInstance()->setSkipFiles(array('index.php'))->maxRecursionDepth(0)->getPHPFiles(CAT_PATH . '/languages', CAT_PATH . '/languages/');
    if (count($languages)) {
        foreach ($languages as $lang) {
            $directory = pathinfo($lang, PATHINFO_FILENAME);
            if (!in_array($directory, $seen_dirs)) {
                $info = $addon->checkInfo(CAT_PATH . '/languages/' . $lang);
                if (is_array($info) && count($info)) {
                    $tpl_data['not_installed_addons']['languages'][$counter] = array('is_installed' => false, 'type' => 'languages', 'directory' => $directory);
                    foreach ($info as $key => $value) {
                        $tpl_data['not_installed_addons']['languages'][$counter][str_ireplace('module_', '', $key)] = $value;
                    }
                    $counter++;
                }