Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
/**
 *
 **/
function manage_droplet_perms()
{
    global $parser, $settings, $val, $backend;
    $info = NULL;
    $groups = array();
    $rows = array();
    $this_user_groups = CAT_Users::get_groups_id();
    if (!CAT_Helper_Droplet::is_allowed('manage_droplet_perms', $this_user_groups)) {
        $backend->print_error($backend->lang()->translate("You don't have the permission to do this"));
    }
    $groups = CAT_Users::getGroups();
    if ($val->get('_REQUEST', 'save') || $val->get('_REQUEST', 'save_and_back')) {
        foreach ($settings as $key => $value) {
            if ($val->get('_REQUEST', $key)) {
                CAT_Helper_Droplet::updateDropletSettings($key, implode('|', $val->get('_REQUEST', $key)));
            }
        }
        // reload settings
        $settings = get_settings();
        $info = $backend->lang()->translate('Permissions saved');
        if ($val->get('_REQUEST', 'save_and_back')) {
            return list_droplets($info);
        }
    }
    foreach ($settings as $key => $value) {
        $line = array();
        foreach ($groups as $id => $name) {
            $line[] = '<input type="checkbox" name="' . $key . '[]" id="' . $key . '_' . $id . '" value="' . $id . '"' . (is_in_array($value, $id) ? ' checked="checked"' : NULL) . '>' . '<label for="' . $key . '_' . $id . '">' . $name . '</label>' . "\n";
        }
        $rows[] = array('groups' => implode('', $line), 'name' => $backend->lang()->translate($key));
    }
    // sort rows by permission name (=text)
    $array = CAT_Helper_Array::getInstance();
    $rows = $array->ArraySort($rows, 'name', 'asc', true);
    $parser->output('permissions', array('rows' => $rows, 'info' => $info));
}
Esempio n. 3
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;
 }
Esempio n. 4
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++;
                }
Esempio n. 5
0
/**
 *
 **/
function getPagesList($fieldname, $selected, $add_empty = false)
{
    $pages_list = CAT_Helper_Page::getPages(CAT_Backend::isBackend());
    $deleted = CAT_Helper_Page::getPagesByVisibility('deleted');
    if (count($deleted)) {
        $arrh = CAT_Helper_Array::getInstance();
        foreach ($deleted as $page) {
            $arrh->ArrayRemove($page, $pages_list, 'page_id');
        }
    }
    if ($add_empty) {
        array_unshift($pages_list, array('page_id' => 0, 'parent' => 0, 'level' => 0, 'is_open' => false, 'menu_title' => CAT_Helper_Page::getInstance()->lang()->translate('[none (use internal)]')));
    }
    return CAT_Helper_ListBuilder::getInstance(true)->config(array('space' => '|-- '))->dropdown($fieldname, $pages_list, 0, $selected);
}
Esempio n. 6
0
 /**
  *
  * @access public
  * @return
  **/
 public static function breadcrumb($list, $selected = NULL)
 {
     $self = self::getInstance(false);
     $tree = self::buildRecursion($list);
     $path = CAT_Helper_Array::ArraySearchRecursive($selected, $tree, $self->_config['__id_key']);
     if (is_array($path) && count($path)) {
         array_pop($path);
         // push selected item to result
         eval('$node = $tree[\'' . implode('\'][\'', $path) . '\'];');
         $trail[] = $node;
         while (count($path) > 1) {
             array_pop($path);
             array_pop($path);
             eval('$node = $tree[\'' . implode('\'][\'', $path) . '\'];');
             if (isset($node['children'])) {
                 unset($node['children']);
             }
             $trail[] = $node;
         }
         return array_reverse($trail);
     }
     return NULL;
 }
Esempio n. 7
0
 /**
  * removes an element from an array
  *
  * @access public
  * @param  string $Needle
  * @param  array  $Haystack
  * @param  mixed  $NeedleKey
  **/
 public static function ArrayRemove($Needle, &$Haystack, $NeedleKey = "")
 {
     if (!is_array($Haystack)) {
         return false;
     }
     reset($Haystack);
     self::$Needle = $Needle;
     self::$Key = $NeedleKey;
     $Haystack = array_filter($Haystack, 'self::filter_callback');
 }
Esempio n. 8
0
    }
    // ================================================
    // ! Add files and infos about them to $ajax
    // ================================================
    if (isset($dir['filename']) && is_array($dir['filename'])) {
        $files_array = array();
        foreach ($dir['filename'] as $counter => $file) {
            $file_path = $load_path . '/' . $file;
            $filetype = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
            $ajax['files'][] = array('filetype' => $filetype, 'show_preview' => in_array(strtolower($filetype), $allowed_img_types) ? true : false, 'filesize' => $dirh->getSize($file_path, true), 'filedate' => strftime($date->getDefaultDateFormatShort(), $dirh->getModdate($file_path)), 'filetime' => strftime($date->getDefaultTimeFormat(), $dirh->getModdate($file_path)), 'full_name' => $file, 'filename' => substr($file, 0, -(strlen($filetype) + 1)), 'load_url' => $val->sanitize_url(CAT_URL . '/' . $load_url));
        }
    }
} else {
    $ajax['is_folder'] = false;
    $filetype = strtolower(pathinfo($load_path, PATHINFO_EXTENSION));
    $load_file = IS_WIN ? utf8_decode($load_file) : $load_file;
    $ajax['files'] = array('filetype' => $filetype, 'show_preview' => in_array(strtolower($filetype), $allowed_img_types) ? true : false, 'filesize' => $dirh->getSize($load_path, true), 'filedate' => strftime($date->getDefaultDateFormatShort(), $dirh->getModdate($load_path)), 'filetime' => strftime($date->getDefaultTimeFormat(), $dirh->getModdate($load_path)) . (isset($language_time_string) ? ' ' . $language_time_string : ''), 'full_name' => $load_file, 'filename' => substr($load_file, 0, -(strlen($filetype) + 1)), 'load_url' => $val->sanitize_url(IS_WIN ? utf8_decode(CAT_URL . '/' . $load_url) : $load_url));
}
// =================================
// ! Add permissions to $ajax
// =================================
$ajax['permissions']['media_upload'] = $user->checkPermission('media', 'media_upload', false);
$ajax['permissions']['media_create'] = $user->checkPermission('media', 'media_create', false);
$ajax['permissions']['media_rename'] = $user->checkPermission('media', 'media_rename', false);
$ajax['permissions']['media_delete'] = $user->checkPermission('media', 'media_delete', false);
// ====================
// ! Return results
// ====================
header('Content-type: application/json');
print json_encode(CAT_Helper_Array::ArrayEncodeUTF8($ajax));
Esempio n. 9
0
 /**
  * determine default page
  *
  * @access public
  * @return void
  **/
 public static function getDefaultPage()
 {
     if (!count(self::$pages)) {
         self::init();
     }
     // for all pages with level 0...
     $root = array();
     $now = time();
     $ordered = CAT_Helper_Array::getInstance()->ArraySort(self::$pages, 'position');
     foreach ($ordered as $page) {
         if ($page['level'] == 0 && $page['visibility'] == 'public' && self::isActive($page['page_id'])) {
             if (!PAGE_LANGUAGES || $page['language'] == LANGUAGE) {
                 return $page['page_id'];
             }
         }
     }
 }
Esempio n. 10
0
foreach ($users->get_groups_id() as $cur_gid) {
    if (in_array($cur_gid, $old_admin_groups)) {
        $in_old_group = true;
    }
}
if (!$in_old_group && !is_numeric(array_search($users->get_user_id(), $old_admin_users))) {
    $backend->print_error('You do not have permissions to modify this page');
}
//
// ! delete link
//
if ($val->sanitizeGet('del')) {
    list($lang, $page_id) = explode('_', $val->sanitizeGet('del'));
    CAT_Helper_Page::deleteLanguageLink($page_id, $lang);
}
$arrh = CAT_Helper_Array::getInstance();
// ===========================
// ! find already linked pages
// ===========================
$items = CAT_Helper_Page::getInstance($page_id)->getLinkedByLanguage($page_id);
// =========================
// ! get installed languages
// =========================
$addons = CAT_Helper_Addons::getInstance();
$avail = $addons->get_addons($page['language'], 'language');
// skip current lang
foreach ($avail as $i => &$l) {
    if ($l['VALUE'] == $page['language']) {
        unset($avail[$i]);
        break;
    }