Example #1
0
function Dwoo_Plugin_makeThumb(Dwoo $dwoo, $file = '', $prefix = '', $height = 300, $width = 200, $method = 'fit', $overwrite = false)
{
    if ($file == '') {
        return false;
    }
    // check if the file contains the Path to the image
    $file = str_replace(CAT_URL, CAT_PATH, $file);
    $file = strpos($file, CAT_PATH) === false ? CAT_PATH . $file : $file;
    // Set some values
    $temp_path = CAT_PATH . '/temp/' . MEDIA_DIRECTORY . '/';
    $temp_url = CAT_URL . '/temp/' . MEDIA_DIRECTORY . '/';
    $info = pathinfo($file);
    $new_path = CAT_Helper_Directory::sanitizePath($temp_path . $prefix . $info['filename'] . '_' . $width . '_' . $height . '.' . $info['extension']);
    $new_url = str_replace(CAT_PATH, CAT_URL, $new_path);
    // Create temp directory, if the folder doesn't exist
    if (!file_exists($temp_path)) {
        CAT_Helper_Directory::createDirectory($temp_path, NULL, true);
    }
    // Create the file, if the file does not exist or overwrite is set to true
    if (!file_exists($new_path) || $overwrite == true) {
        CAT_Helper_Image::getInstance()->make_thumb($file, $new_path, $height, $width, $method);
    }
    return $new_url;
    // end make_thumb()
}
Example #2
0
/**
 * execute registered filters
 *
 * @param  reference $content
 * @return void
 **/
function executeFilters(&$content)
{
    // get active filters
    $res = CAT_Helper_Page::getInstance()->db()->query('SELECT * FROM `:prefix:mod_filter` WHERE filter_active=:active', array('active' => 'Y'));
    if (is_object($res) && $res->numRows()) {
        $filter = array();
        while (false !== ($row = $res->fetch())) {
            $filter[] = $row;
        }
        foreach ($filter as $f) {
            if ($f['filter_code'] == '' && $f['module_name'] != '') {
                $inc_file = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/' . $f['module_name'] . '/filter/' . $f['filter_name'] . '.php');
                if (file_exists($inc_file)) {
                    include_once $inc_file;
                    $f['filter_name']($content);
                }
            }
        }
    }
    // if we have some JS registered...
    global $_bc_filter_js;
    if (count($_bc_filter_js)) {
        $js = array();
        $dom = new DOMDocument();
        libxml_use_internal_errors(true);
        @$dom->loadHTML($content);
        $h = $dom->getElementsByTagName('head')->item(0);
        if ($h) {
            foreach ($_bc_filter_js as $file) {
                $element = $dom->createElement('script');
                // Creating an empty text node forces <script></script>
                $element->appendChild($dom->createTextNode(''));
                $element->setAttribute('type', 'text/javascript');
                $element->setAttribute('src', $file);
                $h->appendChild($element);
            }
            $content = $dom->saveHTML();
        }
    }
    // onload events
    global $_bc_filter_onload;
    if (count($_bc_filter_onload)) {
        $attach = NULL;
        $listener = NULL;
        foreach ($_bc_filter_onload as $item) {
            $attach .= "    window.attachEvent('onload','{$item}');\n";
            $listener .= "    window.addEventListener('DOMContentLoaded',{$item},false);\n";
        }
        $h = $dom->getElementsByTagName('body')->item(0);
        $element = $dom->createElement('script');
        $element->appendChild($dom->createTextNode("\nif(window.attachEvent) {\n" . $attach . "\n} else {\n" . $listener . "\n}\n"));
        $element->setAttribute('type', 'text/javascript');
        $h->appendChild($element);
        $content = $dom->saveHTML();
    }
}
Example #3
0
 /**
  * exception handler; allows to remove paths from error messages and show
  * optional stack trace
  **/
 public static function exceptionHandler($exception)
 {
     $exc_class = get_class($exception);
     try {
         $logger = CAT_Helper_KLogger::instance(CAT_PATH . '/temp/logs', 2);
         $logger->logFatal(sprintf('Exception with message [%s] emitted in [%s] line [%s]', $exception->getMessage(), $exception->getFile(), $exception->getLine()));
     } catch (Exception $e) {
     }
     if (isset($exc_class::$exc_trace) && $exc_class::$exc_trace === true) {
         $traceline = "#%s %s(%s): %s(%s)";
         $msg = "Uncaught exception '%s' with message '%s'<br />" . "<div style=\"font-size:smaller;width:80%%;margin:5px auto;text-align:left;\">" . "in %s:%s<br />Stack trace:<br />%s<br />" . "thrown in %s on line %s</div>";
         $trace = $exception->getTrace();
         foreach ($trace as $key => $stackPoint) {
             $trace[$key]['args'] = array_map('gettype', $trace[$key]['args']);
         }
         // build tracelines
         $result = array();
         foreach ($trace as $key => $stackPoint) {
             $result[] = sprintf($traceline, $key, isset($stackPoint['file']) ? $stackPoint['file'] : '-', isset($stackPoint['line']) ? $stackPoint['line'] : '-', $stackPoint['function'], implode(', ', $stackPoint['args']));
         }
         // trace always ends with {main}
         $result[] = '#' . ++$key . ' {main}';
         // write tracelines into main template
         $msg = sprintf($msg, get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), implode("<br />", $result), $exception->getFile(), $exception->getLine());
     } else {
         // filter message
         $message = $exception->getMessage();
         $message = str_replace(array(CAT_Helper_Directory::sanitizePath(CAT_PATH), str_replace('/', '\\', CAT_Helper_Directory::sanitizePath(CAT_PATH))), array('[path to]', '[path to]'), $message);
         $msg = "[{$exc_class}] {$message}";
     }
     // log
     $logger->logFatal($msg);
     // show detailed error information to admin only
     if (CAT_Users::is_authenticated() && CAT_Users::is_root()) {
         CAT_Object::printFatalError($msg);
     } else {
         CAT_Object::printFatalError("An internal error occured. We're sorry for inconvenience.");
     }
 }
Example #4
0
/**
 * this method may be called by modules to handle a droplet upload
 **/
function droplets_upload($input)
{
    // Set temp vars
    $temp_dir = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/temp/');
    $temp_file = CAT_Helper_Directory::sanitizePath($temp_dir . $_FILES[$input]['name']);
    $temp_unzip = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/temp/unzip/');
    $errors = array();
    // Try to upload the file to the temp dir
    if (!move_uploaded_file($_FILES[$input]['tmp_name'], $temp_file)) {
        return array('error', CAT_Helper_Directory::getInstance()->lang()->translate('Upload failed'));
    }
    $result = droplets_import($temp_file, $temp_unzip);
    // Delete the temp zip file
    if (file_exists($temp_file)) {
        unlink($temp_file);
    }
    CAT_Helper_Directory::removeDirectory($temp_unzip);
    // show errors
    if (isset($result['errors']) && is_array($result['errors']) && count($result['errors']) > 0) {
        return array('error', $result['errors'], NULL);
    }
    // return success
    return array('success', $result['count']);
}
Example #5
0
}
if (preg_match('~(\\d+)(.*)~', $height, $match)) {
    $height = $match[1];
    $height_unit = $match[2];
}
$skins = $c->getSkins($c->getSkinPath());
$current_skin = $c->getSkin($config);
$settings = $c->getAdditionalSettings();
$plugins = $c->getAdditionalPlugins();
$filemanager = $c->getFilemanager();
$toolbars = $c->getToolbars();
$preview = NULL;
$plugins_checked = array();
$filemanager_checked = array();
$enable_htmlpurifier = isset($config['enable_htmlpurifier']) ? $config['enable_htmlpurifier'] : false;
if (file_exists(CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/' . WYSIWYG_EDITOR . '/images/' . $current_skin . '.png'))) {
    $preview = '<img src="' . sanitize_url(CAT_URL . '/modules/' . WYSIWYG_EDITOR . '/images/' . $current_skin . '.png') . '" alt="' . $current_skin . '" title="' . $current_skin . '" />';
}
// something to save?
$job = $val->sanitizePost('job');
if ($job && $job == "save") {
    $new_width = $new_height = $new_skin = $new_toolbar = $new_plugins = $new_fm = NULL;
    // validate width and height
    foreach (array('width', 'height') as $key) {
        if ($val->sanitizePost($key)) {
            if (!is_numeric($val->sanitizePost($key))) {
                $errors[$key] = $backend->lang()->translate('Not numeric!');
                continue;
            }
            if ($val->sanitizePost($key . '_unit') && in_array($val->sanitizePost($key . '_unit'), array('em', 'px', '%'))) {
                if ($val->sanitizePost($key . '_unit') == '%' && $val->sanitizePost($key) > 100) {
Example #6
0
/**
 * edit a droplet's datafile
 **/
function edit_datafile($id)
{
    global $parser, $val, $backend;
    $info = $problem = NULL;
    $groups = CAT_Users::get_groups_id();
    if (!CAT_Helper_Droplet::is_allowed('modify_droplets', $groups)) {
        $backend->print_error($backend->lang()->translate("You don't have the permission to do this"));
    }
    if ($val->get('_REQUEST', 'cancel')) {
        return list_droplets();
    }
    $query = $backend->db()->query("SELECT name FROM " . CAT_TABLE_PREFIX . "mod_droplets WHERE id = '{$id}'");
    $data = $query->fetch();
    // find the file
    if (file_exists(dirname(__FILE__) . '/data/' . $data['name'] . '.txt')) {
        $file = CAT_Helper_Directory::getInstance()->sanitizePath(dirname(__FILE__) . '/data/' . $data['name'] . '.txt');
    } elseif (file_exists(dirname(__FILE__) . '/data/' . strtolower($data['name']) . '.txt')) {
        $file = CAT_Helper_Directory::getInstance()->sanitizePath(dirname(__FILE__) . '/data/' . strtolower($data['name']) . '.txt');
    } elseif (file_exists(dirname(__FILE__) . '/data/' . strtoupper($data['name']) . '.txt')) {
        $file = CAT_Helper_Directory::getInstance()->sanitizePath(dirname(__FILE__) . '/data/' . strtoupper($data['name']) . '.txt');
    }
    // slurp file
    $contents = implode('', file($file));
    if (isset($_POST['save']) || isset($_POST['save_and_back'])) {
        $new_contents = htmlentities($_POST['contents']);
        // create backup copy
        copy($file, $file . '.bak');
        $fh = fopen($file, 'w');
        if (is_resource($fh)) {
            fwrite($fh, $new_contents);
            fclose($fh);
            $info = $backend->lang()->translate('The datafile has been saved');
            if (isset($_POST['save_and_back'])) {
                return list_droplets($info);
            }
        } else {
            $problem = $backend->lang()->translate('Unable to write to file [{{file}}]', array('file' => str_ireplace(CAT_Helper_Directory::sanitizePath(CAT_PATH), 'CAT_PATH', $file)));
        }
    }
    $parser->output('edit_datafile.tpl', array('info' => $info, 'problem' => $problem, 'name' => $data['name'], 'id' => $id, 'contents' => htmlspecialchars($contents)));
}
Example #7
0
    } else {
        trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
    }
}
global $parser;
$backend = CAT_Backend::getInstance('start');
$user = CAT_Users::getInstance();
$lang = CAT_Helper_I18n::getInstance();
$widget = CAT_Helper_Widget::getInstance();
// this will redirect to the login page if the permission is not set
$user->checkPermission('start', 'start', false);
// ================================================
// ! Check if installation directory still exists
// ================================================
if (file_exists(CAT_PATH . '/install/')) {
    CAT_Helper_Directory::removeDirectory(CAT_PATH . '/install/');
}
// exec initial_page
if ($val->sanitizeGet('initial') || !$user->checkPermission('start', 'start') === true) {
    $page = $user->get_initial_page();
    if ($page) {
        header('Location: ' . $page);
    }
}
$tpl_data = array();
// =====================================================
// ! Insert permission values into the template object
// =====================================================
foreach (array('media', 'addons', 'access', 'settings', 'admintools') as $item) {
    $tpl_data['sections'][$item]['permission'] = $user->checkPermission($item, $item, false);
    $tpl_data['sections'][$item]['name'] = $item;
Example #8
0
 /**
  *
  *
  *
  *
  **/
 public function addFile($file, $path = NULL, $var = NULL)
 {
     $this->log()->logDebug('FILE [' . $file . '] PATH [' . $path . '] VAR [' . $var . ']');
     $check_var = 'LANG';
     if (isset($var)) {
         $var = str_ireplace('$', '', $var);
         eval('global $' . $var . ';');
         eval("\$lang_var = & \${$var};");
         $check_var = $var;
     }
     if (!empty($path)) {
         array_unshift(self::$search_paths, $path);
         self::$search_paths = array_unique(self::$search_paths);
     }
     foreach (self::$search_paths as $path) {
         $file = CAT_Helper_Directory::sanitizePath($path . '/' . $file);
         if (file_exists($file) && !$this->isLoaded($file)) {
             $this->log()->logDebug('found language file: ', $file);
             $this->checkFile($file, $check_var);
         }
     }
     if (!$this->isLoaded($file)) {
         $this->log()->logDebug('language file does not exist: ', $file);
         return false;
     }
     return true;
 }
Example #9
0
 public function getSkins($skin_path)
 {
     $d = CAT_Helper_Directory::getInstance();
     $d->setRecursion(false);
     $skins = $d->getDirectories($skin_path, $skin_path . '/');
     $d->setRecursion(true);
     return $skins;
 }
Example #10
0
 /**
  * scans modules for widgets
  *
  * @access public
  * @return array
  **/
 public static function findWidgets()
 {
     // find files called widget.php
     $widgets = CAT_Helper_Directory::getInstance()->maxRecursionDepth(2)->setSkipFiles(array('index.php'))->findFiles('widget.php', CAT_PATH . '/modules');
     // find files in directory called widgets
     $directories = CAT_Helper_Directory::getInstance()->maxRecursionDepth(2)->findDirectories('widgets', CAT_PATH . '/modules');
     if (count($directories)) {
         if (!is_array($widgets)) {
             $widgets = array();
         }
         foreach ($directories as $dir) {
             $widgets = array_merge($widgets, CAT_Helper_Directory::getInstance()->setSkipFiles(array('index.php'))->getPHPFiles($dir));
         }
     }
     return $widgets;
 }
Example #11
0
 /**
  *
  * @access public
  * @return
  **/
 public static function getEditModuleFilesButton($mod_dir, $print = false)
 {
     global $page_id, $section_id;
     $self = self::getInstance();
     if (!$self->checkModulePermissions($mod_dir)) {
         return;
     }
     $content = '';
     $path = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/' . $mod_dir);
     // find JS files
     $js = CAT_Helper_Directory::getInstance()->maxRecursionDepth(5)->setSuffixFilter(array('js'))->scanDirectory($path, true, true, $path);
     // find CSS files
     $css = CAT_Helper_Directory::getInstance()->maxRecursionDepth(5)->setSuffixFilter(array('css'))->scanDirectory($path, true, true, $path);
     if (count($js) || count($css)) {
         $content = '
             <form style="float:right" method="post" action="' . CAT_URL . '/backend/addons/edit_module_files.php" name="edit_module_file">
         		<input type="hidden" value="' . $page_id . '" name="page_id">
         		<input type="hidden" value="' . $section_id . '" name="section_id">
         		<input type="hidden" value="' . $mod_dir . '" name="mod_dir">
         		<input type="submit" value="' . $self->lang()->translate('Edit module file(s)') . '">
         	</form>';
     }
     if ($print) {
         echo $content;
     } else {
         return $content;
     }
 }
Example #12
0
/**
 * create .htaccess in root dir
 **/
function create_htaccess()
{
    // filter document root from CAT_PATH
    $server_path = CAT_Helper_Directory::sanitizePath(CAT_PATH);
    $server_path = str_replace(CAT_Helper_Directory::sanitizePath($_SERVER['DOCUMENT_ROOT']), '', $server_path);
    $content = '    RewriteEngine On
    # If called directly - redirect to short url version
    RewriteCond %{REQUEST_URI} !' . PAGES_DIRECTORY . '/intro.php
    RewriteCond %{REQUEST_URI} ' . PAGES_DIRECTORY . '
    RewriteRule ^' . PAGES_DIRECTORY . '/(.*)' . PAGE_EXTENSION . '$ /$1/ [R=301,L]

# Send the request to the index.php for processing
    RewriteCond %{REQUEST_URI} !^/(' . str_replace('/', '', PAGES_DIRECTORY) . '|' . CAT_BACKEND_FOLDER . '|framework|include|languages|media|account|search|temp|templates/.*)$
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([\\/\\sa-zA-Z0-9._-]+)$ ' . $server_path . '/index.php?$1 [QSA,L]
    ';
    $fh = fopen(CAT_PATH . '/.htaccess', 'w');
    if (is_resource($fh) && $fh) {
        fwrite($fh, $content);
        fclose($fh);
    }
}
Example #13
0
             continue;
         }
         $errors[$key] = $backend->lang()->translate('Please fill out the field: {{ name }}', array('name' => $backend->lang()->translate($key)));
     } else {
         $data[$key] = $val->sanitizePost('filter_' . $key);
     }
 }
 if (isset($errors['file']) && !isset($errors['code'])) {
     unset($errors['file']);
 }
 if (!count($errors)) {
     if (isset($_FILES['filter_file']) && isset($_FILES['filter_file']['error']) && $_FILES['filter_file']['error'] != 4) {
         $file = CAT_Helper_Upload::getInstance($_FILES['filter_file']);
         $file->no_script = false;
         $file->allowed = array('application/octet-stream');
         $file->process(CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/blackcatFilter/filter/'));
         if (!$file->processed) {
             $upload_error = $file->error;
         } else {
             $data['name'] = $file->file_dst_name_body;
         }
         // filter must have the same name as the file
         // the file will be renamed by the upload helper if it already
         // exists, so we use the destination name here
     }
 }
 if (count($errors) || $upload_error) {
     $showit = true;
 } else {
     $backend->db()->query("INSERT INTO `:prefix:mod_filter` VALUES ( :name, :module, :desc, :code, :active )", array('name' => $data['name'], 'module' => $data['module_name'], 'desc' => $data['description'], 'code' => $data['code'], 'active' => $data['active']));
     if ($backend->db()->isError()) {
Example #14
0
 *   along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 *   @author          Black Cat Development
 *   @copyright       2013, Black Cat Development
 *   @link            http://www.blackcat-cms.org
 *   @license         http://www.gnu.org/licenses/gpl.html
 *   @category        CAT_Core
 *   @package         CAT_Core
 *
 */
// include class.secure.php to protect this file and the whole CMS!
if (defined('CAT_PATH')) {
    include CAT_PATH . '/framework/class.secure.php';
} else {
    $root = "../";
    $level = 1;
    while ($level < 10 && !file_exists($root . '/framework/class.secure.php')) {
        $root .= "../";
        $level += 1;
    }
    if (file_exists($root . '/framework/class.secure.php')) {
        include $root . '/framework/class.secure.php';
    } else {
        trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
    }
}
// end include class.secure.php
$file = CAT_Helper_Directory::sanitizePath(dirname(__FILE__) . '/../' . WYSIWYG_EDITOR . '/headers.inc.php');
if (file_exists($file)) {
    @(require $file);
}
Example #15
0
     $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++;
             }
         }
     }
 }
Example #16
0
}
$backend = CAT_Backend::getInstance('Addons', 'modules_install');
$user = CAT_Users::getInstance();
$val = CAT_Helper_Validate::getInstance();
$action = $val->sanitizePost('action');
$module = $val->sanitizePost('file');
$type = $val->sanitizePost('type') . 's';
$js_back = CAT_ADMIN_URL . '/addons/index.php';
if (!in_array($action, array('install', 'upgrade'))) {
    die(header('Location: ' . CAT_ADMIN_URL . '/' . CAT_BACKEND_PATH . '/addons/index.php'));
}
if ($module == '' || !(strpos($module, '..') === false)) {
    die(header('Location: ' . CAT_ADMIN_URL . '/' . CAT_BACKEND_PATH . '/addons/index.php'));
}
// validate
$path = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/' . $type . '/' . $module . ($type == 'languages' ? '.php' : ''));
$info = CAT_Helper_Addons::checkInfo($path);
if (!is_array($info) || !count($info)) {
    $backend->print_error($backend->lang()->translate('Unable to {{ action }} {{ type }} {{ module }}!', array('action' => $action, 'type' => substr($type, 0, -1), 'module' => $path)) . ': <tt>"' . htmlentities(basename($path)) . '/' . $action . '.php"</tt> ' . $backend->lang()->translate('does not exist'), $js_back);
}
if ($type != 'languages') {
    // this prints an error page if prerequisites are not met
    $precheck_errors = CAT_Helper_Addons::preCheckAddon(NULL, $path, false);
    if ($precheck_errors != '' && !is_bool($precheck_errors)) {
        $backend->print_error($backend->lang()->translate('Invalid installation file. {{error}}', array('error' => $precheck_errors)));
        return false;
    }
    $admin =& $backend;
    // Run the modules install // upgrade script if there is one
    if (file_exists($path . '/' . $action . '.php')) {
        require $path . '/' . $action . '.php';
Example #17
0
 if (is_writable(CAT_PATH . $ajax['folder_path'])) {
     $folder_name = $val->sanitizePost('name');
     if (!$folder_name) {
         $folder_name = $backend->lang()->translate('New folder');
     }
     $create_folder = CAT_PATH . $ajax['folder_path'] . '/' . $folder_name;
     $counter = 1;
     while (is_dir($create_folder)) {
         $create_folder = CAT_PATH . $ajax['folder_path'] . '/' . $folder_name . ' ' . $counter;
         $counter++;
     }
     // =====================================================
     // ! Try to create new folder; also creates an index.php
     // =====================================================
     if (CAT_Helper_Directory::createDirectory($create_folder, NULL, true)) {
         CAT_Helper_Directory::setPerms($create_folder);
         if (is_writable($create_folder)) {
             $ajax['message'] = $backend->lang()->translate('Folder created successfully');
             $ajax['created'] = true;
         } else {
             $ajax['message'] = $backend->lang()->translate('Unable to write to the target directory');
             $ajax['created'] = false;
         }
     } else {
         $ajax['message'] = $backend->lang()->translate('Unable to write to the target directory');
         $ajax['created'] = false;
     }
 } else {
     $ajax['message'] = $backend->lang()->translate('Unable to write to the target directory');
     $ajax['created'] = false;
 }
Example #18
0
    }
    foreach ($files as $n) {
        $fh = fopen($full . '/' . $n . '.php', 'w');
        if ($fh) {
            writeHeader($fh, $name, $author, $type);
            fclose($fh);
        }
    }
}
// if it's a template...
if ($type == 'template') {
    $contents = file_get_contents($full . '/index.php');
    $contents .= "\n\$dwoodata\t= array(); // if you need to set some additional template vars, add them here\nglobal \$page_id;\n\$variant = CAT_Helper_Page::getPageSettings(\$page_id,'internal','template_variant');\nif ( \$variant == '' ) \$variant = DEFAULT_TEMPLATE_VARIANT;\nif ( \$variant == '' || !file_exists(CAT_PATH.'/templates/bootstrap/templates/'.\$variant.'/index.tpl' ) )\n    \$variant = 'default';\n\$parser->setPath(CAT_TEMPLATE_DIR.'/templates/'.\$variant);\n\$parser->setFallbackPath(CAT_TEMPLATE_DIR.'/templates/default');\n\$parser->output('index.tpl',\$dwoodata);\n";
    file_put_contents($full . '/index.php', $contents);
    CAT_Helper_Directory::createDirectory($full . '/templates/default');
    CAT_Helper_Directory::recursiveCreateIndex($full . '/templates');
}
// insert module into DB
foreach ($info as $key => $value) {
    $key = str_replace($pre, 'module_', $key);
    $info[$key] = $value;
}
$info['addon_function'] = $type;
CAT_Helper_Addons::loadModuleIntoDB($dir, 'install', $info);
$success = true;
$message = $backend->lang()->translate('Module created successfully!');
printResult();
function printResult()
{
    global $message, $success;
    $ajax = array('message' => $message, 'success' => $success);
Example #19
0
    print json_encode($ajax);
    exit;
}
$visibility = $page['visibility'];
$use_trash = false;
// Check if we should delete it or just set the visibility to 'deleted'
if (PAGE_TRASH !== false && $visibility != 'deleted') {
    $ajax_status = 1;
    // Page trash is enabled and page has not yet been deleted
    $result = CAT_Helper_Page::deletePage($page_id, true);
    $use_trash = true;
} else {
    $ajax_status = 0;
    $result = CAT_Helper_Page::deletePage($page_id);
}
if (!$result) {
    $ajax = array('message' => $backend->lang()->translate('An error occured (using trash: {{trash}})', array('trash' => $use_trash ? $backend->lang()->translate('Yes') : $backend->lang()->translate('No'))) . ($backend->db()->isError() ? ' (DB error: ' . $backend->db()->getError() . ')' : ''), 'success' => false);
    print json_encode($ajax);
    exit;
} else {
    // delete empty parent dir
    $directory = CAT_PATH . PAGES_DIRECTORY . CAT_Helper_Page::properties($page_id, 'link');
    $directory = pathinfo($directory, PATHINFO_DIRNAME);
    if (is_dir($directory) && rtrim($directory, '/') != CAT_PATH . PAGES_DIRECTORY && CAT_Helper_Directory::is_empty($directory, true)) {
        CAT_Helper_Directory::removeDirectory($directory);
    }
    $ajax = array('message' => $backend->lang()->translate('Page(s) deleted successfully'), 'status' => $ajax_status, 'success' => true);
    print json_encode($ajax);
    exit;
}
exit;
Example #20
0
 function file_list($directory, $skip = array(), $show_hidden = false)
 {
     return CAT_Helper_Directory::getInstance()->setSkipDirs($skip)->scanDirectory($directory, true, true);
 }
Example #21
0
$val = CAT_Helper_Validate::getInstance();
header('Content-type: application/json');
$ajax['file'] = $val->sanitizePost('file');
$ajax['file_path'] = $val->sanitizePost('file_path');
if ($ajax['file'] == '' || $ajax['file_path'] == '' || $users->checkPermission('media', 'media_delete') !== true) {
    $ajax = array('message' => 'You don\'t have the permission to delete this file. Check your system settings.', 'success' => false);
    print json_encode($ajax);
    exit;
} else {
    // ============================
    // ! Try to delete file/folder
    // ============================
    $link = CAT_PATH . $ajax['file_path'] . '/' . $ajax['file'];
    if (file_exists($link)) {
        $kind = is_dir($link) ? 'dir' : 'file';
        if (is_dir($link) && CAT_Helper_Directory::removeDirectory($link)) {
            $ajax['message'] = $backend->lang()->translate('Folder deleted successfully');
            $ajax['success'] = true;
        } elseif (is_file($link) && unlink($link)) {
            $ajax['message'] = $backend->lang()->translate('File deleted successfully');
            $ajax['success'] = true;
        } else {
            $ajax['message'] = $kind == 'dir' ? $backend->lang()->translate('Cannot delete the selected directory') : $backend->lang()->translate('Cannot delete the selected file');
            $ajax['success'] = false;
        }
    } else {
        $ajax['message'] = $backend->lang()->translate('Couldn\'t find the folder or file');
        $ajax['success'] = false;
    }
    print json_encode($ajax);
}
Example #22
0
    $css = CAT_Helper_Directory::getInstance()->maxRecursionDepth(5)->setSuffixFilter(array('css'))->scanDirectory(CAT_PATH . '/modules/lib_jquery/plugins/' . $plugin, true, true, CAT_PATH . '/modules/lib_jquery/plugins/' . $plugin);
    foreach ($js as $file) {
        CAT_Helper_Page::adminAddHeaderComponent('js', $plugin . '/' . $file, $page_id);
    }
    foreach ($css as $file) {
        CAT_Helper_Page::adminAddHeaderComponent('css', $plugin . '/' . $file, $page_id);
    }
    $ajax = array('message' => $success ? 'ok' : 'error', 'success' => $success);
    print json_encode($ajax);
    exit;
} elseif ($val->sanitizePost('del_plugin') != '') {
    $plugin = $val->sanitizePost('del_plugin');
    // find JS files
    $js = CAT_Helper_Directory::getInstance()->maxRecursionDepth(5)->setSuffixFilter(array('js'))->scanDirectory(CAT_PATH . '/modules/lib_jquery/plugins/' . $plugin, true, true, CAT_PATH . '/modules/lib_jquery/plugins/' . $plugin);
    // find CSS files
    $css = CAT_Helper_Directory::getInstance()->maxRecursionDepth(5)->setSuffixFilter(array('css'))->scanDirectory(CAT_PATH . '/modules/lib_jquery/plugins/' . $plugin, true, true, CAT_PATH . '/modules/lib_jquery/plugins/' . $plugin);
    foreach ($js as $file) {
        CAT_Helper_Page::adminDelHeaderComponent('js', '/modules/lib_jquery/plugins/' . $plugin . $file, $page_id);
    }
    foreach ($css as $file) {
        CAT_Helper_Page::adminDelHeaderComponent('css', '/modules/lib_jquery/plugins/' . $plugin . $file, $page_id);
    }
    print json_encode(array('success' => true, 'message' => 'ok'));
    exit;
} elseif ($val->sanitizePost('order') != '') {
    if (is_array($val->sanitizePost('order'))) {
        $type = $val->sanitizePost('type');
        $q = sprintf('UPDATE `%spages_headers` SET `page_%s_files` = \'%s\' WHERE `page_id`="%d"', CAT_TABLE_PREFIX, $type, serialize($val->sanitizePost('order')), $page_id);
        $database->query($q);
        print json_encode(array('success' => $database->is_error() ? false : true, 'message' => $database->is_error() ? $database->get_error() : 'Success'));
        exit;
Example #23
0
 /**
  * allows to retrieve files and directories with a . (dot) which are
  * normally hidden
  *
  * @access public
  * @param  boolean  $bool
  * @return instance
  **/
 public static function showHidden($bool)
 {
     if (is_bool($bool)) {
         self::$show_hidden = $bool;
     }
     if (self::$instance) {
         return self::$instance;
     }
 }
Example #24
0
            // old fashioned language file
            require $langfile;
        } else {
            // modern language file
            $backend->lang()->addFile(LANGUAGE . '.php', CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/' . $tool['directory'] . '/languages'));
        }
    }
    // Cache the tool and add it to dwoo
    if (!CAT_Helper_Validate::sanitizeGet('ajax')) {
        ob_start();
        require CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/' . $tool['directory'] . '/tool.php');
        $tpl_data['TOOL'] = ob_get_contents();
        ob_clean();
        // allow multiple buffering for csrf-magic
    } else {
        require CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/' . $tool['directory'] . '/tool.php');
        return;
    }
    // Check whether icon is available for the admintool
    if (file_exists(CAT_PATH . '/modules/' . $tool['directory'] . '/icon.png')) {
        list($width, $height, $type, $attr) = getimagesize(CAT_PATH . '/modules/' . $tool['directory'] . '/icon.png');
        // Check whether file is 32*32 pixel and is an PNG-Image
        $tpl_data['ICON'] = $width == 32 && $height == 32 && $type == 3 ? CAT_URL . '/modules/' . $tool['directory'] . '/icon.png' : false;
    }
} else {
    $admin->print_error('Error opening file.');
}
// print page
$parser->output('backend_admintools_tool', $tpl_data);
// Print admin footer
$backend->print_footer();
Example #25
0
    while ($level < 10 && !file_exists($root . '/framework/class.secure.php')) {
        $root .= "../";
        $level += 1;
    }
    if (file_exists($root . '/framework/class.secure.php')) {
        include $root . '/framework/class.secure.php';
    } else {
        trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
    }
}
//
// include snippets
//
$snippets = CAT_Helper_Addons::get_addons(0, 'module', 'snippet');
foreach ($snippets as $s) {
    $file = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/' . $s['VALUE'] . '/include.php');
    if (file_exists($file)) {
        include $file;
    }
}
/* 'one liners' */
function get_page_link($page_id)
{
    return CAT_Helper_Page::properties($page_id, 'link');
}
function language_menu()
{
    global $page_id;
    return CAT_Page::getInstance($page_id)->getLanguageMenu();
}
function page_content($block = 1)
Example #26
0
 *   @license         http://www.gnu.org/licenses/gpl.html
 *   @category        CAT_Modules
 *   @package         lib_search
 *
 */
if (defined('CAT_PATH')) {
    include CAT_PATH . '/framework/class.secure.php';
} else {
    $root = "../";
    $level = 1;
    while ($level < 10 && !file_exists($root . '/framework/class.secure.php')) {
        $root .= "../";
        $level += 1;
    }
    if (file_exists($root . '/framework/class.secure.php')) {
        include $root . '/framework/class.secure.php';
    } else {
        trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
    }
}
// import droplets
$inst_dir = CAT_Helper_Directory::sanitizePath(dirname(__FILE__) . '/install');
$temp_unzip = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/temp/unzip/');
$dirh = CAT_Helper_Directory::getInstance();
$files = $dirh->getFiles($inst_dir);
if (is_array($files) && count($files)) {
    foreach ($files as $file) {
        // ignore the result here
        CAT_Helper_Droplet::installDroplet($file, $temp_unzip);
    }
}
Example #27
0
 /**
  * set template fallback path (for templates not found in default path)
  *
  * @access public
  * @param  string  $path
  * @param  string  $context - frontend (default) or backend
  * @return boolean
  *
  **/
 public function setFallbackPath($path, $context = 'frontend')
 {
     $path = CAT_Helper_Directory::sanitizePath($path);
     $this->log()->logDebug(sprintf('context [%s] fallback path [%s]', $context, $path));
     if (file_exists($path)) {
         $this->te->paths[$context . '_fallback'] = $path;
         return true;
     } else {
         $this->log()->logWarn('unable to set fallback template path: does not exist!', $path);
         return false;
     }
 }
Example #28
0
    include CAT_PATH . '/modules/lib_zendlite/library.php';
    $client = new Zend\Http\Client($current['source'], array('timeout' => $current['timeout'], 'adapter' => 'Zend\\Http\\Client\\Adapter\\Proxy', 'proxy_host' => $current['proxy_host'], 'proxy_port' => $current['proxy_port']));
    $client->setHeaders(array('Pragma' => 'no-cache', 'Cache-Control' => 'no-cache'));
    try {
        $response = $client->send();
        if ($response->getStatusCode() != '200') {
            $error = "Unable to load source " . "(using Proxy: " . (isset($current['proxy_host']) && $current['proxy_host'] != '' ? 'yes' : 'no') . ")<br />" . "Status: " . $response->getStatus() . " - " . $response->getMessage() . ($debug ? "<br />" . var_dump($client->getLastRequest()) : NULL) . "<br />";
            $version = 'unknown';
        } else {
            $version = $response->getBody();
        }
    } catch (Exception $e) {
        $error = "Unable to load source " . "(using Proxy: " . (isset($current['proxy_host']) && $current['proxy_host'] != '' ? 'yes' : 'no') . ")<br />" . $e->getMessage() . "<br />";
        $version = 'unknown';
    }
    if ($version && $version != 'unknown') {
        if (CAT_Helper_Addons::getInstance()->versionCompare($version, CAT_VERSION, '>')) {
            $newer = true;
        }
    }
    $fh = @fopen(CAT_Helper_Directory::sanitizePath(dirname(__FILE__) . '/../data/.last'), 'w');
    if (is_resource($fh)) {
        fputs($fh, time() . '|' . $version);
        fclose($fh);
    }
} else {
    $version = isset($last_version) && $last_version != '' ? $last_version : $version;
}
global $parser;
$parser->setPath(dirname(__FILE__) . '/../templates/default');
$parser->output('widget.tpl', array('error' => $error, 'version' => $version, 'newer' => $newer, 'last' => CAT_Helper_DateTime::getInstance()->getDate($last) . ' ' . CAT_Helper_DateTime::getInstance()->getTime($last), 'CAT_VERSION' => CAT_VERSION, 'uri' => $_SERVER['SCRIPT_NAME'], 'missing_mailer_libs' => count(CAT_Helper_Addons::getLibraries('mail')), 'missing_wysiwyg' => count(CAT_Helper_Addons::get_addons(NULL, 'module', 'wysiwyg'))));
Example #29
0
     } else {
         // Problem: no config.php nor installation files...
         exit('<p><strong>Sorry, but this installation seems to be damaged! Please contact your webmaster!</strong></p>');
     }
 }
 //**************************************************************************
 // include config.php
 //**************************************************************************
 require_once $config_path . '/config.php';
 //**************************************************************************
 // analyze path to auto-protect backend
 //**************************************************************************
 if (!defined('CAT_LOGIN_PHASE')) {
     $path = isset($_SERVER['SCRIPT_FILENAME']) ? CAT_Helper_Directory::sanitizePath($_SERVER['SCRIPT_FILENAME']) : NULL;
     if ($path) {
         $check = str_replace('/', '\\/', CAT_Helper_Directory::sanitizePath(CAT_ADMIN_PATH));
         if (preg_match('~^' . $check . '~i', $path)) {
             define('CAT_REQUIRE_ADMIN', true);
             if (!CAT_Users::getInstance()->is_authenticated()) {
                 CAT_Users::getInstance()->handleLogin();
                 exit(0);
             }
             // always enable CSRF protection in backend; does not work with
             // AJAX so scripts called via AJAX should set this constant
             if (!defined('CAT_AJAX_CALL')) {
                 //echo "class.secure is calling enableCSRFMagic<br />";
                 CAT_Helper_Protect::getInstance()->enableCSRFMagic();
             }
             global $parser;
             if (!is_object($parser)) {
                 $parser = CAT_Helper_Template::getInstance('Dwoo');
Example #30
0
        break;
    case 'sysinfo':
        // format installation date and time
        $tpl_data['values']['installation_time'] = CAT_Helper_DateTime::getDateTime(INSTALLATION_TIME);
        // get page statistics
        $pg = CAT_Helper_Page::getPagesByVisibility();
        foreach (array_keys($pg) as $key) {
            $tpl_data['values']['pages_count'][] = array('visibility' => $key, 'count' => count($pg[$key]));
        }
        break;
    case 'headers':
        $files = CAT_Helper_Page::getExtraHeaderFiles(0);
        $tpl_data['use_core'] = isset($files['use_core']) ? $files['use_core'] : NULL;
        $tpl_data['use_ui'] = isset($files['use_ui']) ? $files['use_ui'] : NULL;
        $tpl_data['page_js'] = isset($files['js']) ? $files['js'] : '';
        $tpl_data['page_css'] = isset($files['css']) ? $files['css'] : '';
        $tpl_data['jquery_plugins'] = CAT_Helper_Directory::getInstance()->maxRecursionDepth(0)->scanDirectory(CAT_PATH . '/modules/lib_jquery/plugins', false, false, CAT_PATH . '/modules/lib_jquery/plugins/');
        $tpl_data['js_files'] = CAT_Helper_Directory::getInstance()->maxRecursionDepth(5)->setSuffixFilter(array('js'))->scanDirectory(CAT_PATH . '/modules/lib_jquery/plugins', true, true, CAT_PATH . '/modules/lib_jquery/plugins');
        $tpl_data['css_files'] = CAT_Helper_Directory::getInstance()->maxRecursionDepth(5)->setSuffixFilter(array('css'))->scanDirectory(CAT_PATH . '/modules/lib_jquery/plugins', true, true, CAT_PATH . '/modules/lib_jquery/plugins');
        break;
}
$result = true;
$message = NULL;
$output = $parser->get($tpl, $tpl_data);
if (!$output || $output == '') {
    $result = false;
    $message = 'Unable to load settings sub page';
}
$ajax = array('message' => $message, 'success' => $result, 'settings' => $output);
print json_encode($ajax);
exit;