function _init() { $shop = module('shop'); $shop->_shop_cats = _class('cats')->_get_items_names('shop_cats'); $shop->_shop_cats_all = _class('cats')->_get_items_array('shop_cats'); $shop->_shop_cats_for_select = _class('cats')->_prepare_for_box('shop_cats'); $sql_man = 'SELECT * FROM ' . db('shop_manufacturers') . ' ORDER BY name ASC'; $shop->_manufacturer = db()->query_fetch_all($sql_man); $shop->_man_for_select['none'] = '--NONE--'; foreach ((array) $shop->_manufacturer as $k => $v) { $shop->_man_for_select[$v['url']] = $v['name']; } $shop->_man_id = 'none'; $shop->products_img_dir = INCLUDE_PATH . SITE_UPLOADS_DIR . $shop->PROD_IMG_DIR; $shop->products_img_webdir = WEB_PATH . SITE_UPLOADS_DIR . $shop->PROD_IMG_DIR; if (!file_exists($shop->products_img_dir)) { _mkdir_m($shop->products_img_dir); } $shop->_boxes = ['ship_type' => 'select_box("ship_type", $shop->_ship_types_names, $selected, false, 2, "", false)', 'pay_type' => 'radio_box("pay_type", $shop->_pay_types, $selected, 1, 2, "", false)']; $shop->_ship_types_names = []; foreach ((array) $shop->_ship_types as $_id => $_info) { $_price_text = ' (' . ($_info['price'] < 0 ? '-' : '+') . $shop->_format_price(abs($_info['price'])) . ')'; $shop->_ship_types_names[$_id] = $_info['name'] . ($_info['price'] ? $_price_text : ''); } // Override pay type for group $force_group_pay_type = $shop->FORCE_GROUP_PAY[main()->USER_GROUP]; if ($force_group_pay_type) { $shop->FORCE_PAY_METHOD = $force_group_pay_type; } }
/** */ function _init() { if (!extension_loaded('imagick')) { $this->ALLOW_IMAGICK = false; } if ($this->COLLECT_BAD_IMAGES) { $bad_images_path = APP_PATH . $this->BAD_IMAGES_DIR; if (!file_exists($bad_images_path)) { _mkdir_m($bad_images_path, 0777); } } if (empty($this->LIBS_PRIORITY)) { $this->LIBS_PRIORITY = ['gd']; } if (!empty($this->WATERMARK_POSITION)) { if (strpos($this->WATERMARK_POSITION, '-')) { $position = explode('-', $this->WATERMARK_POSITION); $this->WATERMARK_ALIGN_X = $position[0]; $this->WATERMARK_ALIGN_Y = $position[1]; } if ($this->WATERMARK_POSITION == 'random') { $this->WATERMARK_ALIGN_X = $this->IMAGE_ALIGN_X[rand(0, 2)]; $this->WATERMARK_ALIGN_Y = $this->IMAGE_ALIGN_Y[rand(0, 2)]; } } }
/** * Contructor */ function _init() { $this->BASE_PATH = YF_PATH . 'libs/phpids/'; // set the include path properly for PHPIDS set_include_path(get_include_path() . PATH_SEPARATOR . $this->BASE_PATH); $this->config = ['General' => ["filter_type" => "xml", "base_path" => $this->BASE_PATH, "use_base_path" => false, "filter_path" => $this->BASE_PATH . "IDS/default_filter.xml", "tmp_path" => INCLUDE_PATH . "uploads/tmp/", "scan_keys" => false, "html" => ["__wysiwyg"], "json" => ["__jsondata"], "exceptions" => ["__utmz", "__utmc"]], 'Logging' => ["path" => INCLUDE_PATH . "phpids_log.txt"], 'Caching' => ["caching" => "none"]]; _mkdir_m($this->config['General']['tmp_path']); }
function go() { if (!db()->QUERY_LOG) { return false; } $logs_dir = INCLUDE_PATH . 'logs/'; if (!file_exists($logs_dir)) { _mkdir_m($logs_dir); } $IP = is_object(common()) ? common()->get_ip() : false; if (!$IP) { $IP = $_SERVER['REMOTE_ADDR']; } $log_header = '## ' . date('Y-m-d H:i:s') . '; ' . 'SITE_ID: ' . conf('SITE_ID') . '; ' . 'IP = ' . $IP . '; ' . 'QUERY_STRING = ' . WEB_PATH . '?' . $_SERVER['QUERY_STRING'] . '; ' . (!empty($_SERVER['REQUEST_URI']) ? 'URL: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '; ' : '') . (!empty($_SERVER['HTTP_REFERER']) ? 'REFERER = ' . $_SERVER['HTTP_REFERER'] . '; ' : '') . "##\r\n"; if (db()->LOG_ALL_QUERIES && !empty(db()->FILE_NAME_LOG_ALL)) { $c = 0; $h = fopen($logs_dir . db()->FILE_NAME_LOG_ALL, 'a'); fwrite($h, $log_header); foreach ((array) db()->QUERY_LOG as $id => $text) { if (substr($text, 0, strlen('EXPLAIN')) == 'EXPLAIN' || substr($text, 0, strlen('SHOW SESSION STATUS')) == 'SHOW SESSION STATUS') { continue; } $log_entry = ++$c . ') ' . common()->_format_time_value(db()->QUERY_EXEC_TIME[$id]) . ";\t" . $text . '; ' . (isset(db()->QUERY_AFFECTED_ROWS[$text]) ? ' # affected_rows: ' . intval(db()->QUERY_AFFECTED_ROWS[$text]) . ';' : '') . "\r\n"; fwrite($h, $log_entry); } fwrite($h, "####\r\n"); fclose($h); } // Slow queries if (db()->LOG_SLOW_QUERIES && !empty(db()->FILE_NAME_LOG_SLOW)) { $c = 0; foreach ((array) db()->QUERY_LOG as $id => $text) { if (db()->QUERY_EXEC_TIME[$id] < (double) db()->SLOW_QUERIES_TIME_LIMIT) { continue; } // Get explain info about queries $_explain_result = []; if (substr(db()->DB_TYPE, 0, 5) == 'mysql' && preg_match('/^[\\(]*select/ims', $text)) { $_explain_result = db()->query_fetch_all('EXPLAIN ' . $text); } $_cur_trace = db()->QUERY_BACKTRACE_LOG[$id]; $add_text = '' . (isset(db()->QUERY_AFFECTED_ROWS[$text]) ? ' # affected_rows: ' . intval(db()->QUERY_AFFECTED_ROWS[$text]) . '; ' : '') . (!empty($_cur_trace) ? '# ' . $_cur_trace['file'] . ' on line ' . $_cur_trace['line'] . ' (db->' . $_cur_trace['function'] . (!empty($_cur_trace['inside_method']) ? ' inside ' . $_cur_trace['inside_method'] : '') . '; ' : '') . (!empty($_explain_result) ? $this->_format_db_explain_result($_explain_result) : ''); $slow_queries[] = ++$c . ') ' . common()->_format_time_value(db()->QUERY_EXEC_TIME[$id]) . ";\t" . $text . '; ' . ($add_text ? "\r\n" . $add_text : '') . "\r\n"; } if (!empty($slow_queries)) { $h = fopen($logs_dir . db()->FILE_NAME_LOG_SLOW, 'a'); fwrite($h, $log_header); foreach ((array) $slow_queries as $text) { fwrite($h, $text); } fwrite($h, "####\r\n"); fclose($h); } } }
/** * Extract files from tar archive (local) */ function _local_extract_tar($archive_path = '', $extract_path = '') { if (empty($archive_path) || empty($extract_path)) { return false; } $archive_path = _class('ssh')->_prepare_path($archive_path); $extract_path = _class('ssh')->_prepare_path($extract_path); $destination_folder = dirname($extract_path); if (!file_exists($destination_folder)) { _mkdir_m($destination_folder); } return false; }
/** */ function _copy($id, $par) { $dir = $this->_path($id); $par = $this->_path($par); $new = explode('/', $dir); $new = array_pop($new); $new = $par . '/' . $new; if (is_file($new) || is_dir($new)) { throw new Exception('Path already exists: ' . $new); } if (is_dir($dir)) { _mkdir_m($new); foreach (glob(rtrim($dir, '/') . '/*') as $f) { $this->_copy($this->_id($dir . '/' . basename($f)), $this->_id($new)); } } if (is_file($dir)) { copy($dir, $new); } return ['id' => $this->_id($new)]; }
/** * Save debug log */ function _save_debug_log($text = '', $log_level = E_NOTICE, $trace = [], $simple = false) { if (empty($log_level) || !isset($this->_error_levels_names[$log_level])) { $log_level = E_NOTICE; } if (empty($this->CUR_LOG_LEVEL) || $log_level > $this->CUR_LOG_LEVEL) { return false; } $LOGS_DIR = APP_PATH . 'logs/'; _mkdir_m($LOGS_DIR); $log_data = ''; $log_data .= !$simple ? date('Y-m-d H:i:s') . ' [' . $this->_error_levels_names[$log_level] . '] ' : ''; $log_data .= $text; // $log_data .= !$simple ? ' ('.$trace['file'].' on line '.$trace['line'].')' : ''; $log_data .= !$simple ? ' | ' . str_replace("\n", ' ', main()->trace_string()) : ''; $log_data .= "\n"; file_put_contents($LOGS_DIR . 'debug_logs.log', $log_data, FILE_APPEND); }
/** * Compile given template into pure PHP code */ function _compile($name, $replace = [], $string = "") { $_time_start = microtime(true); // For later check for templates changes if (_class('tpl')->COMPILE_CHECK_STPL_CHANGED) { $_md5_string = md5($string); } $compiled_dir = STORAGE_PATH . _class('tpl')->COMPILED_DIR; // Do not check dir existence twice if (!isset($this->_stpl_compile_dir_check)) { _mkdir_m($compiled_dir); $this->_stpl_compile_dir_check = true; } $file_name = $compiled_dir . 'c_' . MAIN_TYPE . '_' . urlencode($name) . '.php'; $start = '<' . '?p' . 'hp '; $end = ' ?' . '>'; $string = $this->_process_patterns($name, $replace, $string); // Images and uploads paths compile $web_path = MAIN_TYPE_USER ? 'MEDIA_PATH' : 'ADMIN_WEB_PATH'; $images_path = $web_path . '._class(\'tpl\')->TPL_PATH. _class(\'tpl\')->_IMAGES_PATH'; $to_replace = ['"images/' => '"' . $start . 'echo ' . $images_path . ';' . $end, '\'images/' => '\'' . $start . 'echo ' . $images_path . ';' . $end, '"uploads/' => '"' . $start . 'echo MEDIA_PATH. _class(\'tpl\')->_UPLOADS_PATH;' . $end, '\'uploads/' => '\'' . $start . 'echo MEDIA_PATH. _class(\'tpl\')->_UPLOADS_PATH;' . $end, 'src="uploads/' => 'src="' . $start . 'echo ' . $web_path . '._class(\'tpl\')->_UPLOADS_PATH;' . $end]; $string = str_replace(array_keys($to_replace), $to_replace, $string); $string = '<' . '?p' . 'hp if(!defined(\'YF_PATH\')) exit(); /* ' . 'date: ' . gmdate('Y-m-d H:i:s') . ' GMT; ' . 'compile_time: ' . common()->_format_time_value(microtime(true) - $_time_start) . '; ' . 'name: ' . $name . '; ' . ' */ ' . '?' . '>' . PHP_EOL . $string; file_put_contents($file_name, $string); return $string; }
/** * AJAX-based method edit selected template for the current locale */ function edit_locale_stpl() { no_graphics(true); if (!DEBUG_MODE || !tpl()->ALLOW_INLINE_DEBUG) { return print 'Access denied'; } // Prepare template name to get $STPL_NAME = trim($_GET['id']); // Some security checks $STPL_NAME = preg_replace('/[^a-z0-9_\\-\\/]/i', '', $STPL_NAME); $STPL_NAME = trim($STPL_NAME, '/'); $STPL_NAME = preg_replace('#[\\/]{2,}#', '/', $STPL_NAME); if (empty($STPL_NAME)) { return print 'STPL name required!'; } // Path to the lang-based theme $_lang_theme_path = INCLUDE_PATH . tpl()->_THEMES_PATH . conf('theme') . '.' . conf('language') . '/'; // Try to get template $text = tpl()->_get_template_file($STPL_NAME . tpl()->_STPL_EXT); $text = str_replace("\r", '', $text); // Determine used source $_source = tpl()->CACHE[$STPL_NAME]['storage']; // Try to save template if (isset($_POST['text'])) { // Compare source and result $result = 'Nothing changed'; if ($_POST['text'] != $text) { $locale_stpl_path = $_lang_theme_path . $STPL_NAME . tpl()->_STPL_EXT; // First try to create subdir if (!file_exists(dirname($locale_stpl_path))) { _mkdir_m(dirname($locale_stpl_path)); } // Save file file_put_contents($locale_stpl_path, $_POST['text']); // Save revision db()->INSERT('revisions', ['user_id' => intval(MAIN_TYPE_USER ? main()->USER_ID : main()->ADMIN_ID), 'object_name' => _es('locale_stpl'), 'object_id' => _es($STPL_NAME), 'old_text' => _es($text), 'new_text' => _es($_POST['text']), 'date' => time(), 'ip' => common()->get_ip(), 'comment' => _es('saved into file: ' . $locale_stpl_path)]); // Success output $result = 'Saved successfully'; } return print $result; } // Show template contents by default return print $text; }
/** * Copy remote dir structure into local one (bulk method) */ function download_dir($server_info = [], $remote_dir = "", $local_dir = "", $pattern_include = "", $pattern_exclude = "", $level = null) { $local_dir = _class('ssh')->_prepare_path($local_dir); $remote_dir = _class('ssh')->_prepare_path($remote_dir); if (!_class('ssh')->_INIT_OK || !$server_info || !strlen($local_dir) || !strlen($remote_dir)) { return false; } if (!_class('ssh')->file_exists($server_info, $remote_dir)) { trigger_error('SSH: ' . __FUNCTION__ . ': remote dir ' . $remote_dir . ' not exist', E_USER_WARNING); return false; } $cutoff_len = strlen($remote_dir); if (!_class('ssh')->file_exists($server_info, $remote_dir)) { return false; } $completed = false; // Try this one if previous method failed or not allowed if (!$completed) { $dir_contents = _class('ssh')->scan_dir($server_info, $remote_dir, $pattern_include, $pattern_exclude, $level); if (!$dir_contents) { return false; } foreach ((array) $dir_contents as $_path => $_info) { $remote_file = $_path; $local_file = $local_dir . substr($_path, $cutoff_len); _mkdir_m(dirname($local_file)); if ($_info['type'] == 'd') { _mkdir_m($local_file); } elseif ($_info['type'] == 'f') { _class('ssh')->read_file($server_info, $remote_file, $local_file); } elseif ($_info['type'] == 'l') { // Resolve link target and download it $_target_path = _class('ssh')->realpath($server_info, $_path); $_target_info = _class('ssh')->file_info($server_info, $_target_path); if ($_target_info['type'] == 'f') { _class('ssh')->read_file($server_info, $_target_path, $local_file); } } } } _class('ssh')->_log($server_info, __FUNCTION__, 'remote_dir: ' . $remote_dir . ', local_dir: ' . $local_dir . ''); return true; }
/** * Do save */ function go() { if (!$this->LOGGING || MAIN_TYPE_USER) { return false; } if (main()->NO_GRAPHICS && !$this->LOG_NO_GRAPHICS_PAGES) { return false; } if ($GLOBALS['task_not_found'] && !$this->LOG_NOT_FOUND_PAGES) { return false; } if ($this->USE_STOP_LIST) { foreach ((array) $this->STOP_LIST as $_cur_pattern) { if (preg_match('/' . $_cur_pattern . '/i', $_SERVER['QUERY_STRING'])) { return false; } } } if ($this->FILTER_BOTS && !main()->USER_ID) { $SPIDER_NAME = common()->_is_spider($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']); if ($SPIDER_NAME) { return false; } } if ($this->EXCLUDE_IPS) { $ip = common()->get_ip(); if ($ip && (isset($this->EXCLUDE_IPS[$ip]) || in_array($ip, $this->EXCLUDE_IPS))) { $checks['exclude_ip'] = true; } } if ($this->EXCLUDE_USER_AGENTS) { $ua = $_SERVER['HTTP_USER_AGENT']; foreach ((array) $this->EXCLUDE_USER_AGENTS as $pattern) { if (preg_match('~' . $pattern . '~i', $ua)) { $checks['exclude_ua'] = true; } } } $this->checks = $checks; foreach ((array) $checks as $name => $is_denied) { if ($is_denied) { $this->log_denied_because = $name; return false; } } $exec_time = str_replace(',', '.', common()->_format_time_value($GLOBALS['time_end'] ?: microtime(true) - main()->_time_start)); $query_string = $_SERVER['QUERY_STRING']; // TODO: use parse_url here /* list($object, $action) = explode('&action=', $query_string); if ($action == 'realtime') { return false; } */ if (main()->is_console()) { $query_string = http_build_query($_GET); } $data = ['admin_id' => (int) main()->ADMIN_ID, 'admin_group' => (int) main()->ADMIN_GROUP, 'date' => time(), 'ip' => common()->get_ip(), 'user_agent' => (string) $_SERVER['HTTP_USER_AGENT'], 'referer' => (string) $_SERVER['HTTP_REFERER'], 'query_string' => (string) $query_string, 'request_uri' => $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'exec_time' => $exec_time, 'num_dbq' => (int) db()->NUM_QUERIES, 'page_size' => (int) tpl()->_output_body_length, 'site_id' => (int) conf('SITE_ID'), 'server_id' => (int) conf('SERVER_ID')]; if ($this->LOG_DRIVER == 'db') { $sql = db()->insert_safe('log_admin_exec', $data, $as_sql = true); db()->_add_shutdown_query($sql); } elseif ($this->LOG_DRIVER == 'file') { $data['output_cache'] = '0'; // mean: exec full mode (not from output cache) $log_file_path = INCLUDE_PATH . $this->LOG_DIR_NAME . gmdate('Y-m-d') . '.log'; $log_dir_path = dirname($log_file_path); if (!file_exists($log_dir_path)) { _mkdir_m($log_dir_path); } file_put_contents($log_file_path, implode('#@#', $data) . PHP_EOL, FILE_APPEND); } }
/** * Show given array as RSS page */ function show_rss_page($data = [], $params = []) { require_php_lib('yf_feedcreator'); $rss = new UniversalFeedCreator(); if (!isset($params['use_cached']) || !empty($params['use_cached'])) { $rss->useCached(); } $rss->title = _prepare_html(!empty($params['feed_title']) ? $params['feed_title'] : 'Site feed title'); $rss->description = _prepare_html(!empty($params['feed_desc']) ? $params['feed_desc'] : 'Site feed description'); // optional feed params $rss->descriptionTruncSize = !empty($params['feed_trunc_size']) ? intval($params['item_trunc_size']) : 500; $rss->descriptionHtmlSyndicated = isset($params['feed_insert_html']) ? (bool) $params['feed_insert_html'] : true; $rss->link = _prepare_html(process_url($params['feed_url'] ?: './?object=' . $_GET['object'])); $this->self_link = $rss->link; $rss->syndicationURL = _prepare_html(process_url($params['feed_source'] ?: './?object=' . $_GET['object'] . '&action=' . $_GET['action'] . (!empty($_GET['id']) ? '&id=' . $_GET['id'] : ''))); if (!empty($this->SHOW_RSS_ENCODING)) { $rss->encoding = $this->SHOW_RSS_ENCODING; } foreach ((array) $data as $A) { $item = new FeedItem(); if (isset($A['date'])) { $A['date'] = intval($A['date']); } if (isset($A['link'])) { $A['link'] = process_url($A['link']); } // Process known fields foreach ((array) $this->avail_item_fields as $field_name) { if (isset($A[$field_name])) { $item->{$field_name} = $A[$field_name]; } } if (!isset($item->guid)) { $item->guid = $A['link'] . '#' . md5($params['feed_source'] . '&' . $A['date'] . '&' . $A['title'] . '&' . $A['author']); } // optional params $item->descriptionTruncSize = !empty($params['item_trunc_size']) ? intval($params['item_trunc_size']) : $this->DESC_TRUNC_SIZE; $item->descriptionHtmlSyndicated = isset($params['item_insert_html']) ? (bool) $params['item_insert_html'] : true; // optional (enclosure) // Sample: $A['enclosure'] = array('url'=>'http://lh3.ggpht.com/smoliarov/Rwygj8ucrbE/AAAAAAAABIA/UkNlwQ7eniw/_200708.jpg','length'=>'65036','type'=>'image/jpeg'); if (!empty($A['enclosure']) && is_array($A['enclosure'])) { $E = $A['enclosure']; $item->enclosure = new EnclosureItem(); $item->enclosure->url = _prepare_html($E['url']); $item->enclosure->length = intval($E['length']); $item->enclosure->type = _prepare_html($E['type']); } $rss->addItem($item); } // Set format of the resulting feed $feed_format = isset($params['feed_format']) && in_array($params['feed_format'], $this->avail_formats) ? $params['feed_format'] : 'RSS2.0'; $feed_file_name = $params['feed_file_name']; if (!strlen($feed_file_name)) { $feed_file_name = md5($_SERVER['HTTP_HOST'] . '_' . $rss->title . $rss->description . $this->self_link); } $feed_file_name = common()->_propose_url_from_name($feed_file_name); $feed_cache_path = $this->FEEDS_CACHE_PATH . $feed_file_name . '.xml'; $feed_cache_dir = dirname($feed_cache_path); if (!file_exists($feed_cache_dir)) { _mkdir_m($feed_cache_dir); } $feed_redirect = $params['return_feed_text'] ? false : true; $body = $rss->saveFeed($feed_format, $feed_cache_path, $feed_redirect); if (!empty($params['return_feed_text'])) { if ($body) { return $body; } elseif (file_exists($feed_cache_path)) { return file_get_contents($feed_cache_path); } } else { main()->NO_GRAPHICS = true; echo $body; } }
/** * Sitemap format generator (compatible with Google, Yahoo, MSN etc) * * https://www.google.com/webmasters/sitemaps/docs/en/about.html * XML-Specification: https://www.google.com/webmasters/sitemaps/docs/en/protocol.html * * You can use the gzip feature or compress your Sitemap files using gzip. * Please note that your uncompressed Sitemap file may not be larger than 10MB. * * No support for more the 50.000 URLs at the moment. See * http://www.google.com/webmasters/sitemaps/docs/en/protocol.html#sitemapFileRequirements */ function _generate_sitemap() { main()->NO_GRAPHICS = true; if (!$this->SITE_MAP_ENABLED) { return false; } // !! Important !! // Turn off rewrite adding url params into sitemap urls _class('rewrite')->URL_ADD_BUILTIN_PARAMS = false; $_sitemap_base_name = $this->SITEMAP_FILE_NAME; // Check if needed to recreate sitemap files $_path = $this->SITEMAP_STORE_FOLDER . $this->SITEMAP_FILE_NAME . '_index' . $this->_file_extension; if (file_exists($_path) && filemtime($_path) + $this->SITEMAP_LIVE_TIME > time() && !$this->TEST_MODE) { // send headers $this->_redirect_sitemap($this->SITEMAP_WEB_PATH . $this->SITEMAP_FILE_NAME . '_index' . $this->_file_extension); return false; } if (!file_exists($_path)) { $_path = $this->SITEMAP_STORE_FOLDER . $this->SITEMAP_FILE_NAME . '1' . $this->_file_extension; if (file_exists($_path) && filemtime($_path) + $this->SITEMAP_LIVE_TIME > time() && !$this->TEST_MODE) { // send headers $this->_redirect_sitemap($this->SITEMAP_WEB_PATH . $this->SITEMAP_FILE_NAME . '1' . $this->_file_extension); return false; } } // Start generate sitemap @ignore_user_abort(true); @set_time_limit($this->LOCK_TIMEOUT); if ($this->USE_LOCKING) { clearstatcache(); if (file_exists($this->LOCK_FILE_NAME)) { if (time() - filemtime($this->LOCK_FILE_NAME) > $this->LOCK_TIMEOUT) { unlink($this->LOCK_FILE_NAME); } else { return false; } } file_put_contents($this->LOCK_FILE_NAME, time()); } $this->_sitemap_file_counter = 1; _mkdir_m($this->SITEMAP_STORE_FOLDER); _class('dir')->delete_files($this->SITEMAP_STORE_FOLDER, '/' . $_sitemap_base_name . '.*/i'); $this->_fp = fopen($this->SITEMAP_STORE_FOLDER . $this->SITEMAP_FILE_NAME . $this->_sitemap_file_counter . $this->_file_extension, 'w+'); $this->_total_length = 0; $this->_entries_counter = 0; $this->_output($this->_tpl_sitemap_header()); $this->_total_length = strlen($header_text); foreach ((array) $this->MODULES_TO_INCLUDE as $module_name) { $module_obj = module_safe($module_name); if ($this->LIMIT_REACHED || !is_object($module_obj)) { continue; } $hook_name = ''; foreach ((array) $this->HOOK_NAMES as $_hook_name) { if (method_exists($module_obj, $_hook_name)) { $hook_name = $_hook_name; break; } } if ($hook_name) { $items = $module_obj->{$hook_name}($this); if (is_array($items)) { foreach ((array) $items as $item) { $this->_add($item); } } } } if (!$this->LIMIT_REACHED) { $this->_output($this->_tpl_sitemap_footer()); @fclose($this->_fp); } $files = _class('dir')->scan($this->SITEMAP_STORE_FOLDER); foreach ((array) $files as $file_name) { if (false !== strpos($file_name, '.svn') || false !== strpos($file_name, '.git')) { continue; } $path_info = pathinfo($file_name); $_sitemap_filename_pattern = '/^(' . $this->SITEMAP_FILE_NAME . ')([0-9]{1,3})(\\.xml)$/'; if (!preg_match($_sitemap_filename_pattern, $path_info['basename'])) { continue; } else { $sitemaps[$file_name] = $file_name; } } if ($sitemaps) { foreach ((array) $sitemaps as $filename) { $this->_process_sitemap_file($filename); } } $this->_file_for_google = str_replace(PROJECT_PATH, WEB_PATH, $this->SITEMAP_STORE_FOLDER) . $this->SITEMAP_FILE_NAME . '1' . $this->_file_extension; if ($sitemaps && count($sitemaps) > 1) { $this->_output($this->_tpl_sitemap_index_header()); // Create sitemap index $this->_fp = fopen($this->SITEMAP_STORE_FOLDER . $this->SITEMAP_FILE_NAME . '_index' . $this->_file_extension, 'w+'); foreach ((array) $sitemaps as $sitemap_file) { $string = "\t<sitemap>\n"; $string .= "\t\t<loc>" . str_replace(PROJECT_PATH, WEB_PATH, $sitemap_file) . "</loc>\n"; $last_mod = $this->_iso8601_date(filemtime($sitemap_file)); if ($last_mod) { $string .= "\t\t<lastmod>" . $last_mod . "</lastmod>\n"; } $string .= "\t</sitemap>\n"; // Store entry data to file $this->_output($string); } fclose($this->_fp); $this->_output($this->_tpl_sitemap_index_footer()); $this->_file_for_google = str_replace(PROJECT_PATH, WEB_PATH, $this->SITEMAP_STORE_FOLDER) . $this->SITEMAP_FILE_NAME . '_index' . $this->_file_extension; } // Release lock if ($this->USE_LOCKING) { unlink($this->LOCK_FILE_NAME); } $this->_redirect_sitemap($this->_file_for_google); $this->_do_notify_google(); }
/** * Do save */ function go() { if (!$this->allow()) { return false; } $is = $this->is; $data = ['user_id' => (int) $_SESSION['user_id'], 'user_group' => (int) $_SESSION['user_group'], 'date' => time(), 'user_agent' => (string) $_SERVER['HTTP_USER_AGENT'], 'referer' => (string) $_SERVER['HTTP_REFERER'], 'query_string' => (string) $_SERVER['QUERY_STRING'], 'request_uri' => (string) $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'exec_time' => str_replace(',', '.', common()->_format_time_value($GLOBALS['time_end'] ?: microtime(true) - main()->_time_start)), 'num_dbq' => (int) db()->NUM_QUERIES, 'page_size' => (int) tpl()->_output_body_length, 'memory' => (int) memory_get_peak_usage(), 'site_id' => (int) conf('SITE_ID'), 'ip' => (string) common()->get_ip(), 'country' => (string) (conf('country') ?: $_SERVER['GEOIP_COUNTRY_CODE']), 'lang' => (string) conf('language'), 'utm_source' => strval($_GET['utm_source'] ?: ($_POST['utm_source'] ?: $_SESSION['utm_source'])), 'is_common_page' => (int) $is['is_common_page'], 'is_https' => (int) $is['is_https'], 'is_post' => (int) $is['is_post'], 'is_no_graphics' => (int) $is['is_no_graphics'], 'is_ajax' => (int) $is['is_ajax'], 'is_spider' => (int) $is['is_spider'], 'is_redirect' => (int) $is['is_redirect'], 'is_console' => (int) $is['is_console'], 'is_unit_test' => (int) $is['is_unit_test'], 'is_dev' => (int) $is['is_dev'], 'is_debug' => (int) $is['is_debug'], 'is_banned' => (int) $is['is_banned'], 'is_403' => (int) $is['is_403'], 'is_404' => (int) $is['is_404'], 'is_503' => (int) $is['is_503'], 'is_cache_on' => (int) $is['is_cache_on']]; if (in_array('db', $this->LOG_DRIVER)) { $sql = db()->insert_safe('log_exec', $data); db()->_add_shutdown_query($sql); } if (in_array('file', $this->LOG_DRIVER)) { $data['output_cache'] = '0'; // mean: exec full mode (not from output cache) $log_file_path = STORAGE_PATH . $this->LOG_DIR_NAME . 'log_exec_' . gmdate('Y-m-d') . '.log'; $log_dir_path = dirname($log_file_path); if (!file_exists($log_dir_path)) { _mkdir_m($log_dir_path); } file_put_contents($log_file_path, implode('#@#', $data) . PHP_EOL, FILE_APPEND); } }
/** */ function edit_stpl() { $theme_name = $_GET['theme']; $stpl_name = $_GET['name']; if (!validate([$theme_name, $stpl_name], 'trim|required')) { return _e('Template name and theme required!'); } if (main()->is_post()) { if (false !== strpos($_GET['location'], 'framework')) { // TODO: use readonly mode with message and ability to save changed file inside project return $this->_framework_warning(); } $lib_stpl_path = $this->_dir_array[$_GET['location']] . $theme_name . '/' . $stpl_name . tpl()->_STPL_EXT; foreach (glob($lib_stpl_path) as $path) { $lib_stpl_path = $path; break; } $text = $_POST['stpl_text'] ?: $_POST['stpl_text_hidden']; if (!file_exists($lib_stpl_path)) { _mkdir_m(dirname($lib_stpl_path)); } file_put_contents($lib_stpl_path, $text); return js_redirect('./?object=' . $_GET['object'] . '&action=show_stpls_in_theme&theme=' . $theme_name . '&location=' . $_GET['location']); } if (substr($_GET['location'], -strlen('_user')) == '_user' && $theme_name == 'admin') { $theme_name = 'user'; } $stpl_path = $this->_dir_array[$_GET['location']] . $theme_name . '/' . $stpl_name . tpl()->_STPL_EXT; foreach (glob($stpl_path) as $path) { $stpl_path = $path; break; } if (!file_exists($stpl_path)) { return _e('Cannot find template: ' . $stpl_path); } $stpl_text = file_get_contents($stpl_path); $stpl_text = _prepare_html($stpl_text, 0); $replace = ['form_action' => './?object=' . $_GET['object'] . '&action=' . $_GET['action'] . '&name=' . $stpl_name . '&theme=' . $theme_name . '&location=' . $_GET['location'], 'theme_name' => $theme_name, 'stpl_name' => $stpl_name, 'stpl_text' => $stpl_text, 'back_url' => './?object=' . $_GET['object'] . '&action=show_stpls_in_theme&theme=' . $theme_name . '&location=' . $_GET['location'], 'location' => $_GET['location']]; $div_id = 'editor_html'; $hidden_id = 'stpl_text_hidden'; return '<h4>edit: ' . $replace['stpl_name'] . ' for theme: ' . $replace['theme_name'] . ', inside: ' . $replace['location'] . '</h4>' . form($replace, ['data-onsubmit' => '$(this).find("#' . $hidden_id . '").val( $("#' . $div_id . '").data("ace_editor").session.getValue() );'])->container('<div id="' . $div_id . '" style="width: 90%; height: 500px;">' . $stpl_text . '</div>', '', ['id' => $div_id, 'wide' => 1, 'ace_editor' => ['mode' => 'html']])->hidden($hidden_id)->save_and_back(); }
/** * Prepare path for the cache file (current page) */ function _prepare_cache_path($cur_cache_name = "") { // Get name of the cache file if (empty($cur_cache_name)) { return false; } // Memcached code if ($this->USE_MEMCACHED) { return $cur_cache_name; } // Base cache dir $cache_dir = $this->CACHE_DIR; // Create subdir (a/b/c) $cache_sub_dir = $cur_cache_name[0] . "/" . $cur_cache_name[1] . "/" . $cur_cache_name[2] . "/"; $cache_dir .= $cache_sub_dir; _mkdir_m($cache_dir, 0777); return $cache_dir . $this->_file_prefix . $cur_cache_name . $this->_file_ext; }
/** * Try quick export with mysqldump */ function _quick_export_with_mysqldump($tables_to_export = []) { if (count($tables_to_export) == 1) { $SINGLE_TABLE = current($tables_to_export); } // Prepare temp name $_temp_file_name = 'db_export' . ($SINGLE_TABLE ? '__' . $SINGLE_TABLE : '') . '_' . date('YmdHis', time()) . '.sql'; $_temp_file_path = INCLUDE_PATH . 'uploads/tmp/' . $_temp_file_name; _mkdir_m(dirname($_temp_file_path)); $mysql_path = defined('OS_WINDOWS') && OS_WINDOWS ? $this->MYSQL_CLIENT_PATH : ''; $cmd = $mysql_path . 'mysqldump --host=' . DB_HOST . ' --user='******' --password='******' ' . '--opt --comments=false --quote-names ' . DB_NAME . ' ' . implode(' ', array_keys($tables_to_export)) . ' > ' . $_temp_file_path; exec($cmd); return $_temp_file_path; }
function image_resize() { $body .= '<h3>Testing image upload and resize</h3>'; $img_src = 'uploads/tmp/test_resized_image.jpg'; if (file_exists(INCLUDE_PATH . $img_src)) { unlink(INCLUDE_PATH . $img_src); } // Do upload and resize to 500 x 500 px if (main()->is_post()) { $img_dir = INCLUDE_PATH . dirname($img_src); _mkdir_m($img_dir); $upload_result = common()->upload_image(INCLUDE_PATH . $img_src); $body .= "<b>UPLOAD:</b> " . ($upload_result ? "<b style='color:green;'>success</b>" : "<b style='color:red;'>failed</b>") . "<br />"; if ($upload_result) { $thumb_result = common()->make_thumb(INCLUDE_PATH . $img_src, INCLUDE_PATH . $img_src, 500, 500); } $body .= "<b>MAKE_THUMB:</b> " . ($thumb_result ? "<b style='color:green;'>success</b>" : "<b style='color:red;'>failed</b>") . "<br />"; if (file_exists(INCLUDE_PATH . $img_src)) { $body .= "<img src='" . WEB_PATH . $img_src . "'><br /><br />"; } } $body .= _e(); $body .= "<form action='./?object=" . $_GET["object"] . "&action=" . $_GET["action"] . "' method='post' enctype='multipart/form-data'><input type='file' name='image'><input type='submit' name='go' value='GO'></form>"; return $body; }
} return $parents; } //----------------------------------------------------------- // START //----------------------------------------------------------- _mkdir_m($packed_dir, 0777); _mkdir_m($compiled_dir, 0777); // Get files array $files_to_compress = scan_dir($source_dir, 1, "#.*\\.(php)\$#"); //print_r($files_to_compress); foreach ((array) $files_to_compress as $cur_file_path) { $compressed_file_path = $packed_dir . substr($cur_file_path, strlen($source_dir)); $compressed_file_dir = dirname($compressed_file_path); if (!file_exists($compressed_file_dir)) { _mkdir_m($compressed_file_dir, 0777); } // Do compress _do_compress_php_file($cur_file_path, $compressed_file_path); } // Get classes names and paths $new_files_to_compile = []; foreach ((array) scan_dir($packed_dir, 1, "#.*\\.(php)\$#", $exclude_pattern_user) as $cur_file_path) { $class_name = str_replace("/", "_", str_replace("\\/", "/", substr($cur_file_path, strlen($packed_dir), -4))); $GLOBALS['CLASSES'][$class_name] = $class_name; $GLOBALS['CLASSES_PATHS'][$class_name] = $cur_file_path; } // Build inheritance tree foreach ((array) $GLOBALS['CLASSES'] as $class_name) { $text = substr(file_get_contents($GLOBALS['CLASSES_PATHS'][$class_name]), 6) . "\r\n"; $text = preg_replace($pattern_require, "", $text);