Esempio n. 1
0
 /**
  * @return array
  */
 public function getPluginFilePairs()
 {
     if ($this->plugin_files) {
         // Already have found filed
         return $this->plugin_files;
     }
     foreach (Finder::getInstance()->getPathFolders(Finder::TYPE_PLUGINS) as $folder) {
         $folder = DIR_BASE . $folder;
         FileSystem::mkDir($folder);
         // Skip folder links
         $cms_plugin_files = array_diff(scandir($folder), ['.', '..']);
         // Make simple names for rendering in selects
         foreach ($cms_plugin_files as $k => $v) {
             $this->plugin_files[$v] = str_replace('plugin.php', '', $v);
         }
     }
     return $this->plugin_files;
 }
Esempio n. 2
0
 private function init_data()
 {
     if (Settings::getInstance()->get('disable_cms_translations')) {
         return;
         // No translations
     }
     $data = [];
     foreach (Finder::getInstance()->getPathFolders(Finder::TYPE_TRANSLATIONS) as $file) {
         $file_path = $file . Users::getInstance()->getUserLng() . '.php';
         if (stripos($file_path, DIR_BASE) === false) {
             $file_path = DIR_BASE . $file_path;
         }
         if (file_exists($file_path)) {
             $data += (require_once $file_path);
         }
     }
     self::$init_data = $data;
 }
Esempio n. 3
0
    /**
     * @return string
     */
    public function __toString()
    {
        if (!$this->enabled) {
            return '';
        }
        ob_start();
        echo $this->doctype . "\n";
        if ($this->replace_for_standard_html_tag) {
            echo $this->replace_for_standard_html_tag;
        } else {
            ?>
<html<?php 
            echo $this->html_tag_attributes ? ' ' . implode(' ', $this->html_tag_attributes) : '';
            ?>
>
        <?php 
        }
        ?>
        <head>
            <?php 
        if (!Settings::get('do_not_expose_generator')) {
            ?>
                <meta name="generator" content="<?php 
            echo CMS_NAME;
            ?>
, <?php 
            echo CMS_SITE;
            ?>
">
            <?php 
        }
        ?>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <meta charset="utf-8">
            <title><?php 
        echo htmlspecialchars($this->title, ENT_QUOTES);
        ?>
</title><?php 
        // META
        foreach ($this->meta as $v) {
            ?>
                <meta<?php 
            echo ($v['name'] ? ' name="' . $v['name'] . '" ' : '') . ($v['http_equiv'] ? ' http-equiv="' . $v['http_equiv'] . '"' : '') . ($v['property'] ? ' property="' . $v['property'] . '"' : '');
            ?>
 content="<?php 
            echo $v['content'];
            ?>
">
            <?php 
        }
        // CSS files
        foreach ($this->css_urls as $k => $v) {
            $k = Finder::getInstance()->searchForRealPath($k);
            ?>
                <link rel="stylesheet" type="text/css" href="<?php 
            echo $k;
            ?>
" media="<?php 
            echo $v;
            ?>
">
            <?php 
        }
        // CSS files
        foreach ($this->css as $v) {
            ?>
                <style>
                    <?php 
            echo $v;
            ?>
                </style>
            <?php 
        }
        // JS files and scripts
        for ($i = 1; $i <= $this->js_sequence; $i++) {
            if (isset($this->js_urls[$i])) {
                $this->js_urls[$i] = Finder::getInstance()->searchForRealPath($this->js_urls[$i]);
                ?>
                    <script src="<?php 
                echo $this->js_urls[$i];
                ?>
"></script>
                <?php 
            } elseif (isset($this->js[$i])) {
                ?>
                    <script><?php 
                echo $this->js[$i];
                ?>
</script>
                <?php 
            }
        }
        // RSS feeds
        foreach ($this->rss as $v) {
            ?>
                <link rel="alternate" type="application/rss+xml"
                      title="<?php 
            echo htmlspecialchars($v['title'], ENT_QUOTES);
            ?>
" href="<?php 
            echo $v['href'];
            ?>
">
            <?php 
        }
        // RSS feeds
        if ($this->apple_touch_icon_url) {
            ?>
                <link rel="apple-touch-icon"
                      href="<?php 
            echo Finder::getInstance()->searchForRealPath($this->apple_touch_icon_url);
            ?>
">
            <?php 
        }
        // META keywords
        if ($this->keywords) {
            ?>
                <meta name="keywords" content="<?php 
            echo htmlspecialchars($this->keywords, ENT_QUOTES);
            ?>
">
            <?php 
        }
        // META description
        if ($this->description) {
            ?>
                <meta name="description" content="<?php 
            echo htmlspecialchars($this->description, ENT_QUOTES);
            ?>
">
            <?php 
        }
        // Any custom string appended into <head>
        foreach ($this->custom_strings as $v) {
            ?>
                <?php 
            echo $v;
            ?>
            <?php 
        }
        // Favicon
        if ($this->favicon) {
            $this->favicon['href'] = ltrim($this->favicon['href'], '/');
            ?>
                <link rel="icon" href="http<?php 
            echo $this->ssl ? 's' : '';
            ?>
://<?php 
            echo CFG_DOMAIN . '/' . $this->favicon['href'];
            ?>
" type="<?php 
            echo $this->favicon['type'];
            ?>
">
                <link rel="shortcut icon" href="http<?php 
            echo $this->ssl ? 's' : '';
            ?>
://<?php 
            echo CFG_DOMAIN . '/' . $this->favicon['href'];
            ?>
" type="<?php 
            echo $this->favicon['type'];
            ?>
">
                <?php 
        }
        // Google Analytics
        if ($ga = Settings::get('google_analytics_code')) {
            ?>
                <script>
                    (function (i, s, o, g, r, a, m) {
                        i['GoogleAnalyticsObject'] = r;
                        i[r] = i[r] || function () {
                                (i[r].q = i[r].q || []).push(arguments)
                            }, i[r].l = 1 * new Date();
                        a = s.createElement(o),
                            m = s.getElementsByTagName(o)[0];
                        a.async = 1;
                        a.src = g;
                        m.parentNode.insertBefore(a, m)
                    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

                    ga('create', 'UA-<?php 
            echo $ga;
            ?>
', '<?php 
            echo CFG_DOMAIN;
            ?>
');
                    ga('send', 'pageview');

                </script>
            <?php 
        }
        unset($ga);
        ?>
        </head>
        <?php 
        return ob_get_clean();
    }
Esempio n. 4
0
 private function parseMenu()
 {
     $menu = Menu::getInstance();
     $all_menu_items = ['home' => [], 'structure' => [], 'users' => [], 'tools' => []];
     // Combine items
     $custom_items = [];
     if (file_exists(DIR_FRONT . 'menu.php')) {
         $custom_items = (include_once DIR_FRONT . 'menu.php');
     }
     $all_menu_items += $custom_items;
     // For every main menu item search for module and submenu
     foreach ($all_menu_items as $main_menu_key => $main_menu_data) {
         $menu_class = 'TMCms\\Admin\\' . Converter::to_camel_case($main_menu_key) . '\\Cms' . Converter::to_camel_case($main_menu_key);
         if (!class_exists($menu_class)) {
             $menu_class = 'TMCms\\Modules\\' . Converter::to_camel_case($main_menu_key) . '\\Cms' . Converter::to_camel_case($main_menu_key);
         }
         if (class_exists($menu_class)) {
             $reflection = new \ReflectionClass($menu_class);
             $filename = $reflection->getFileName();
             $folder = dirname($filename);
             $module_menu_file = $folder . '/menu.php';
             if (file_exists($module_menu_file)) {
                 $module_menu_data = (include_once $module_menu_file);
                 $all_menu_items[$main_menu_key] = array_merge($all_menu_items[$main_menu_key], $module_menu_data);
             }
         }
     }
     // Add menu items
     foreach ($all_menu_items as $key => $item) {
         // Add menu item if have access to page
         if ($key && Users::getInstance()->checkAccess($key, '_default')) {
             $menu->addMenuItem($key, $item);
         }
     }
     // Add translations if have project-related files
     Finder::getInstance()->addTranslationsSearchPath(DIR_FRONT . 'translations/');
 }
Esempio n. 5
0
<?php

namespace TMCms\Admin\Home;

use TMCms\Files\Finder;
use TMCms\Traits\singletonInstanceTrait;
defined('INC') or exit;
Finder::getInstance()->addTranslationsSearchPath(__DIR__ . '/translations/');
class CmsHome
{
    use singletonInstanceTrait;
    public function _default()
    {
        require_once __DIR__ . '/Pages/' . __FUNCTION__ . '.php';
    }
    public function _ajax_users_log()
    {
        require_once __DIR__ . '/Pages/' . __FUNCTION__ . '.php';
    }
    public function _ajax_tools_application_log()
    {
        require_once __DIR__ . '/Pages/' . __FUNCTION__ . '.php';
    }
    public function _exit()
    {
        require_once __DIR__ . '/Pages/' . __FUNCTION__ . '.php';
    }
    public function _update_notes()
    {
        require_once __DIR__ . '/Pages/' . __FUNCTION__ . '.php';
    }
Esempio n. 6
0
 /**
  * Replace one component value with real data set in admin panel for requested page
  * No check for file existance in it method - for speeding up processing.
  * Anyway, you will receive standard php error if requested file is not found.
  * @param array $component
  * @return string
  */
 private function callReplace($component)
 {
     ob_start();
     // Get component from Controller
     if ($component['file'] == 'plugin') {
         // Reusable plugin found in placeholder
         $selected_plugin_file = Plugin::getSelectedPluginValue($component['class']);
         if ($selected_plugin_file) {
             // Require file with plugin class
             $file_with_plugin = Finder::getInstance()->searchForRealPath($selected_plugin_file, Finder::TYPE_PLUGINS);
             require_once DIR_BASE . $file_with_plugin;
             $plugin_class_name = str_replace('.php', '', $selected_plugin_file);
             $plugin_class_name = str_replace('plugin', 'Plugin', $plugin_class_name);
             // Just in case
             /** @var Plugin $plugin_object */
             $plugin_object = new $plugin_class_name();
             $plugin_object->render();
         }
     } else {
         // Usual component, try Front site folder
         // Controller
         $this->mvc_instance->setComponentName($component['class']);
         $this->mvc_instance->setModifiers($component['modifiers']);
         $class = ucfirst($component['class']);
         $file = DIR_FRONT_CONTROLLERS . $component['file'] . '.php';
         if (is_file($file)) {
             require_once $file;
             $model_class = $class . 'Controller';
             $this->mvc_instance->setController($model_class);
         }
         // View
         $file = DIR_FRONT_VIEWS . $component['file'] . '.php';
         if (is_file($file)) {
             require_once $file;
             $view_class = $class . 'View';
             $this->mvc_instance->setView($view_class);
         }
         $this->mvc_instance->setMethod($component['method']);
         $this->mvc_instance->outputController();
         $this->mvc_instance->outputView();
     }
     return trim(ob_get_clean());
 }
Esempio n. 7
0
    if (isset($_POST['cms_go_after_submit']) && !$skip_auto_redirect) {
        $go = explode('&', $go) + explode('&', $_POST['cms_go_after_submit']);
        $go = implode('&', $go);
    }
    $go = $go != '' ? $go : '/';
    if ($additional_params) {
        if (stripos($go, '?') === false) {
            $go .= '?';
        }
        $go .= '&' . http_build_query($additional_params);
    }
    if (ob_get_contents()) {
        ob_clean();
    }
    if (!isset($_GET['ajax'])) {
        @header('Location: ' . $go, true, 301);
    }
    exit;
}
/**
 * Goes back in browser
 * @param array $additional_params to add or change in URL
 */
function back(array $additional_params = [])
{
    go(REF, $additional_params);
}
// Add assets and all other search folders for CMS
$length_of_include_path = $root_path_length - 1;
Finder::getInstance()->addAssetsSearchPath(substr(__DIR__, $length_of_include_path) . '/assets/')->addAssetsSearchPath(DIR_CMS_SCRIPTS)->addAjaxSearchPath(substr(__DIR__, $length_of_include_path) . '/assets/ajax/')->addPluginsSearchPath(substr(__DIR__, $length_of_include_path) . '/assets/cms_plugins/')->addServicesSearchPath(substr(__DIR__, $length_of_include_path) . '/assets/services/')->addTranslationsSearchPath(substr(__DIR__, $length_of_include_path) . '/assets/translations/');
unset($root_path_length, $length_of_include_path);