protected function _updateFile() { if ($this->_modified == false) { return; } $this->_stat['io_write']++; $start = microtime(true); CProfiler::ioStart($this->_file_storage, 'write'); file_put_contents($this->_file_storage, $this->_encodeData($this->_data), LOCK_EX); CProfiler::ioStop(); $end = microtime(true); $this->_stat['io_write_time'] += $end - $start; }
/** * Checks the possibility to save and to create files in this folder. * * @param string $dir_fs_name The name of checking folder. */ function is_dir_writable($dir_fs_name) { if (@file_exists($dir_fs_name) == FALSE) { return FALSE; } $file_name = md5(uniqid(rand(), true)) . 'test.txt'; $result = false; CProfiler::ioStart($dir_fs_name . $file_name, 'test'); $fp = @fopen($dir_fs_name . $file_name, 'w'); if ($fp) { fclose($fp); $result = @unlink($dir_fs_name . $file_name); } CProfiler::ioStop(); return $result; }
function delete() { if ($this->__is_error) { return false; } CProfiler::ioStart($this->__file_name, 'delete'); $this->__is_error = !unlink($this->__file_name); CProfiler::ioStop(); return !$this->__is_error; }
/** * Initial parsing if theme map.ini file and generating of YAML files */ function parseMapIni() { $map_file = $this->_PATH_CUR_THEME . 'map.ini'; if (!file_exists($map_file)) { return null; } $pages = $blocks_yml = array(); foreach ($this->getBlocks() as $bl) { $blocks_yml[trim($bl['template'])] = $bl['name']; } // Hoare sort blocks by order function hoare($arr) { $less = $greater = array(); if (count($arr) <= 1) { return $arr; } $x = array_shift($arr); foreach ($arr as $y) { if ($y[1] <= $x[1]) { array_push($less, $y); } else { array_push($greater, $y); } } return array_merge(hoare($less), array($x), hoare($greater)); } CProfiler::ioStart($map_file, 'parse'); $map = parse_ini_file($map_file, true); CProfiler::ioStop(); foreach ($map as $page => $sections) { $pages[$page] = array('settings' => array('template' => '#DEFAULT#', 'page_title' => '#DEFAULT#', 'page_description' => '#DEFAULT#', 'page_keywords' => '#DEFAULT#'), 'placeholders' => array('header' => array(), 'main_menu' => array(), 'topslideshow' => array(), 'left_column' => array(), 'center_column' => array(), 'right_column' => array(), 'footer' => array())); foreach ($sections as $section_name => $section_content) { switch ($section_name) { case 'template': case 'page_title': case 'page_description': case 'page_keywords': $pages[$page]['settings'][$section_name] = "'{$section_content}'"; break; default: $PH = 'custom'; switch ($section_name) { case 'top_menu': case 'top_phone': case 'user1': case 'user3': $PH = 'header'; break; case 'main_menu': case 'topslideshow': case 'left_column': case 'center_column': case 'right_column': $PH = $section_name; break; case 'copyright': case 'footer_menu': $PH = 'footer'; break; default: break; } // regexp pattern for 'if()...endif' blocks $if_endif_pat = '/(\\<\\?php\\s+if\\s*\\(.+?\\)\\s*\\:\\s*\\?\\>(.*?)(?!endif)(.*?)\\<\\?php\\s+endif\\s*;\\s*\\?\\>)/'; // common regexp pattern for standard PHP tags $common_pat = '/(\\<\\?php\\s+(.*?)(?!\\<\\?php)(.*?)\\s*\\?\\>)/'; $obtained_blocks = array(); // array of obtained blocks from placeholder if (!empty($section_content)) { $scont = $section_content; if (preg_match_all($if_endif_pat, $scont, $matches, PREG_OFFSET_CAPTURE)) { $obtained_blocks = $matches[0]; } foreach ($obtained_blocks as $ob) { $scont = str_replace($ob[0], str_repeat("#", strlen($ob[0])), $scont); } if (preg_match_all($common_pat, $scont, $matches, PREG_OFFSET_CAPTURE)) { $obtained_blocks = array_merge($obtained_blocks, $matches[0]); } // preserve blocks sequence in placeholder $obtained_blocks = hoare($obtained_blocks); foreach ($obtained_blocks as $i => $ob) { $bcont = trim($obtained_blocks[$i][0]); $bname = @$blocks_yml[$bcont]; if (isset($bname)) { $pages[$page]['placeholders'][$PH]['blocks'][] = array('name' => $bname, 'visibility' => 'visible'); } else { $pages[$page]['placeholders'][$PH]['blocks'][] = array('name' => "undef_" . $PH . "_{$i}", 'visibility' => 'visible'); $pages[$page]['placeholders'][$PH]['undef_blocks'][] = array('name' => "undef_" . $PH . "_{$i}", 'title' => 'Undefined block', 'description' => 'Undefined block', 'template' => "'{$bcont}'"); } $pages[$page]['placeholders'][$PH]['visibility'] = 'visible'; } } else { $pages[$page]['placeholders'][$PH]['blocks'] = array(); $pages[$page]['placeholders'][$PH]['visibility'] = 'hidden'; } break; } } } // merge pages with 'default' $def_page = $pages['default']; foreach ($pages as $page => $layout) { $undef_blocks = array(); foreach ($layout['settings'] as $sname => $sval) { if ($sval === '#DEFAULT#') { $pages[$page]['settings'][$sname] = $def_page['settings'][$sname]; } } foreach ($layout['placeholders'] as $PHname => $PHparams) { if ($PHparams === array()) { $pages[$page]['placeholders'][$PHname] = $def_page['placeholders'][$PHname]; } if (!empty($pages[$page]['placeholders'][$PHname]['undef_blocks'])) { $undef_blocks = array_merge($undef_blocks, $pages[$page]['placeholders'][$PHname]['undef_blocks']); unset($pages[$page]['placeholders'][$PHname]['undef_blocks']); } } // save unparsed blocks $this->_saveCustomBlocks($page, $undef_blocks); } // save parsed pages $this->_saveMapIniParsedPages($pages); // rename theme map.ini if (file_exists($this->_PATH_CUR_THEME . 'map.ini')) { copy($this->_PATH_CUR_THEME . 'map.ini', $this->_PATH_CUR_THEME . 'map.ini.old'); @chmod($this->_PATH_CUR_THEME . 'map.ini.old', 0777); unlink($this->_PATH_CUR_THEME . 'map.ini'); } }
function asc_mac2nix($src) { CProfiler::ioStart($src, 'read-write'); $fh = fopen($src, 'r+b'); while (!feof($fh)) { $c = fread($fh, 1); if ($c == "\r") { fseek($fh, -1, SEEK_CUR); fwrite($fh, "\n"); } } fclose($fh); CProfiler::ioStop(); }
protected function _saveFile($filename, $data) { $this->_stat['io_write']++; $start = microtime(true); CProfiler::ioStart($filename, 'write'); if (false === file_put_contents($filename, $this->_encodeData($data), LOCK_EX)) { $this->_stat['err_file_put_contents']++; } CProfiler::ioStop(); $end = microtime(true); $this->_stat['io_write_time'] += $end - $start; }
function _test_cookies() { global $HTTP_COOKIE_VARS; $cookies = array(); if (isset($_COOKIE)) { $cookies = $_COOKIE; } elseif (isset($HTTP_COOKIE_VARS)) { $cookies = $HTTP_COOKIE_VARS; } if ($this->_check_cookies) { CProfiler::ioStart($this->_temp_file_path . $this->property('ip'), 'test'); $fp = @fopen($this->_temp_file_path . $this->property('ip'), 'r'); if (!$fp) { $fp = @fopen($this->_temp_file_path . $this->property('ip'), 'a'); fclose($fp); CProfiler::ioStop(); setcookie('phpSniff_session', 'ss', 0, '/'); setcookie('phpSniff_stored', 'st', time() + 3600 * 24 * 365, '/'); $QS = getenv('QUERY_STRING'); $script_path = getenv('PATH_INFO') ? getenv('PATH_INFO') : getenv('SCRIPT_NAME'); if (is_integer($pos = strpos(strrev($script_path), "php.xedni/")) && !$pos) { $script_path = strrev(substr(strrev($script_path), 9)); } $location = 'http://' . getenv('SERVER_NAME') . $script_path . ($QS == '' ? '' : '?' . $QS); header("Location: {$location}"); exit; } else { unlink($this->_temp_file_path . $this->property('ip')); fclose($fp); CProfiler::ioStop(); $this->_set_browser('ss_cookies', isset($cookies['phpSniff_session']) ? 'true' : 'false'); $this->_set_browser('st_cookies', isset($cookies['phpSniff_stored']) ? 'true' : 'false'); // delete the old cookies setcookie('phpSniff_session', '', 0, '/'); setcookie('phpSniff_stored', '', 0, '/'); } } }
function getResFileByShortName($short_name) { global $application; CProfiler::ioStart($application->appIni['PATH_SYSTEM_DIR'] . 'shortname2path', 'parse'); $map = parse_ini_file($application->appIni['PATH_SYSTEM_DIR'] . 'shortname2path'); CProfiler::ioStop(); if (isset($map[$short_name])) { return $application->appIni['PATH_ASC_ROOT'] . $map[$short_name]; } else { return null; } }
function importData($dump_file, $table_prefix, $offset, $str_offset) { CProfiler::ioStart($dump_file, 'read'); $fp = fopen($dump_file, "r"); fseek($fp, $offset); $this->getSQLCommandFromFile($fp, $offset, $str_offset, $table_prefix, time()); fclose($fp); CProfiler::ioStop(); return array("offset" => $offset, "str_offset" => $str_offset); }
function _read_key_from_file($file, $extention) { $key = ''; if ($extention == ".php") { CProfiler::ioStart($file, 'parse'); $key = @parse_ini_file($file); CProfiler::ioStop(); if ($key === false) { $this->license_key_status = LICENSE_KEY_FORMAT_INVALID; return LICENSE_KEY_FORMAT_INVALID; } $key = @$key["key"]; } return $this->formatKey($key); }
/** * Returns the information for the provided skin * Note: function DOES NOT check the skin * use method checkSkin for checking */ function getSkinInfo($skin) { global $application; $skin_dir = $application->getAppIni('PATH_THEMES') . $skin; $result = array('skin' => $skin, 'path' => $application->getAppIni('PATH_THEMES') . $skin); if (is_file($skin_dir . '/info.ini') && is_readable($skin_dir . '/info.ini')) { CProfiler::ioStart($skin_dir . '/info.ini', 'parse'); $result = array_merge(parse_ini_file($skin_dir . '/info.ini'), $result); CProfiler::ioStop(); } return $result; }
function outputPageByMap($page) { global $__TPL_DIR__, $__TPL_URL__, $application; $page = basename($page); $map_file = modApiFunc('Layout_CMS', 'getThemePath') . 'map.ini'; $use_cached = false; if (file_exists($map_file)) { $ini_cache = $application->getIniCache(); $map_mtime = filemtime($map_file); if ($map_mtime == $ini_cache->read($map_file . '-mtime')) { $map = $ini_cache->read($map_file); $use_cached = true; } else { CProfiler::ioStart($map_file, 'parse'); $map = parse_ini_file($map_file, true); CProfiler::ioStop(); $ini_cache->write($map_file . '-mtime', $map_mtime); $ini_cache->write($map_file, $map); } } else { $map = modApiFunc('Layout_CMS', 'generateMap', $page); } if (isset($map['default'])) { $map_default = $map['default']; } if (isset($map[$page])) { $map = array_merge($map_default, $map[$page]); } else { _fatal("The page [{$page}] not found in the map file [{$map_file}]"); } $template_path = getTemplateFileAbsolutePath('pages/templates/' . $map['template']); $tpl_cache = $application->getTplCache(); $template_mtime = filemtime($template_path); if ($template_mtime == $tpl_cache->read($template_path . '-mtime')) { $template_content = $tpl_cache->read($template_path); } else { $template_file = new CFile($template_path); $template_content = $template_file->getContent(); $tpl_cache->write($template_path . '-mtime', $template_mtime); $tpl_cache->write($template_path, $template_content); $use_cached = false; } if ($use_cached) { $contents = $tpl_cache->read($template_path . '-' . $page); } if (!isset($contents)) { $replace = array(); foreach ($map as $k => $v) { $replace['#' . $k . '#'] = $v; $replace['[' . $k . ']'] = htmlentities($v, ENT_QUOTES); } $contents = '?>' . strtr($template_content, $replace); $tpl_cache->write($template_path . '-' . $page, $contents); } ob_start(); eval($contents); $contents = ob_get_contents(); ob_end_clean(); $contents = str_replace('<br>', '<br/>', $contents); return $contents; }
function parse_import_file($fname, $delimetr = ";") { if (!file_exists($fname) or !is_readable($fname)) { return false; } if (!in_array($delimetr, array(",", ";", "\t"))) { return false; } CProfiler::ioStart(); $fh = @fopen($fname, "r"); CProfiler::ioStop(); if ($fh == FALSE) { return false; } CProfiler::ioStart($fname, 'read'); $layout = fgetcsv($fh, 262144, $delimetr); $layout = convertImportDataArray($layout); //!!!!! foreach ($layout as $name => $value) { // echo("!layout: name = $name; value = $value!<br>"); } //!!!!! $csv_data = array(); while (!feof($fh)) { $data = fgetcsv($fh, 262144, $delimetr); $data = convertImportDataArray($data); foreach ($data as $name => $value) { // echo("!data: name = $name; value = $value!<br>"); } $tmp = array(); for ($i = 0; $i < count($layout); $i++) { // echo("<i>layout[$i] = $layout[$i]</i> - "); // echo("data[$i] = $data[$i]<br>"); $tmp[$layout[$i]] = $data[$i]; } $csv_data[] = $tmp; } fclose($fh); CProfiler::ioStop(); return array($layout, $csv_data); }