protected function _prepareTraceStruct($trace_struct)
 {
     $total_time = $trace_struct['time'] - CTrace::getStartTime();
     $microtime = round($trace_struct['time'] - floor($trace_struct['time']), 3) * 1000;
     $date = date('Y-m-d', floor($trace_struct['time']));
     $time = date('H:i:s', floor($trace_struct['time']));
     $delta_time = round($trace_struct['time'] - $this->_last_time, 3);
     $delta_time = $delta_time <= 0 ? $delta_time : '+' . $delta_time;
     $delta_mem = round(($trace_struct['mem'] - $this->_last_mem) / (1024 * 1024), 2);
     $delta_mem = $delta_mem <= 0 ? $delta_mem : '+' . $delta_mem;
     $this->_last_time = $trace_struct['time'];
     $this->_last_mem = $trace_struct['mem'];
     $trace_struct['microtime'] = sprintf('%03d', $microtime);
     $trace_struct['date'] = $date;
     $trace_struct['time'] = $time;
     $trace_struct['delta_time'] = $delta_time;
     $trace_struct['delta_mem'] = $delta_mem;
     $trace_struct['mem'] = sprintf('%.3f', $trace_struct['mem'] / (1024 * 1024));
     $trace_struct['filepath'] = $trace_struct['file'];
     $trace_struct['file'] = basename($trace_struct['file']);
     $trace_struct['func'] = $trace_struct['func'] == null ? '' : $trace_struct['func'];
     $trace_struct['class'] = $trace_struct['class'] == null ? '' : $trace_struct['class'] . $trace_struct['type'];
     $trace_struct['total_time'] = sprintf('%.3f', $total_time);
     return $trace_struct;
 }
 /**
  * Constructor
  */
 function MultiLang_Core()
 {
     // getting if mb_string is installed
     $this->_mb_enabled = in_array('mbstring', get_loaded_extensions());
     if ($this->_mb_enabled) {
         CTrace::inf('mb_string is enabled.');
     } else {
         CTrace::inf('mb_string is NOT enabled, it disabled multilang support.');
     }
     // analyzing mb_string settings
     if ($this->_mb_enabled) {
         // getting if mb_output_handler is set
         $this->_mb_output = strpos(ini_get('output_handler'), 'mb_output_handler') !== false;
     }
 }
 /**
  * Get the marketplace Extension Data.
  * @param boolean $paramReload is ture it will reload details from marketplace
  */
 function fetchMarketplaceExtData($paramReload = false)
 {
     global $application;
     if ($paramReload || $this->isMarketplaceUpdateRequired()) {
         $this->marketplace_server = $application->getAppIni('MARKETPLACE_SERVER');
         loadCoreFile('bouncer.php');
         $bnc = new Bouncer();
         $bnc->setMethod('POST');
         $bnc->setPOSTstring($bnc->prepareDATAstring($this->getLicenseDetail()));
         $bnc->setURL($this->marketplace_server . "/download_extension.php?asc_action=ListMarketplaceExtensions");
         $bnc->setProto('HTTPS');
         $result = $bnc->RunRequest();
         if ($result != false && $bnc->responseCode < 400) {
             $response = json_decode($result['body']);
             if (isset($response) && isset($response->extensions) && !empty($response->extensions)) {
                 $application->db->DB_Query('truncate ' . $application->getAppIni('DB_TABLE_PREFIX') . 'marketplace_ext_data');
                 $tables = self::getTables();
                 $columns = $tables['marketplace_ext_data']['columns'];
                 foreach ($response->extensions as $extension) {
                     $query = new DB_Replace('marketplace_ext_data');
                     $query->addReplaceValue($extension->extension_id, $columns['id']);
                     $query->addReplaceValue($extension->display_name, $columns['display_name']);
                     $query->addReplaceValue($extension->name, $columns['name']);
                     $query->addReplaceValue($extension->description, $columns['desc']);
                     $query->addReplaceValue($extension->detailed_link, $columns['link']);
                     $query->addReplaceValue($extension->image_url, $columns['image']);
                     $query->addReplaceValue($extension->type, $columns['type']);
                     $query->addReplaceValue($extension->category, $columns['category']);
                     $query->addReplaceValue($extension->latestversion, $columns['latestversion']);
                     $query->addReplaceValue($extension->price, $columns['price']);
                     $query->addReplaceValue($extension->ext_version, $columns['latestcompatibleversion']);
                     $query->addReplaceValue($extension->filename, $columns['file']);
                     $application->db->getDB_Result($query);
                 }
                 /* Update Last build date - start */
                 $params = array('group_name' => 'MARKETPLACE_LAST_BUILD_DATE', 'param_name' => 'MARKETPLACE_LAST_BUILD_DATE', 'value' => time());
                 execQuery('UPDATE_SETTINGS_PARAM_VALUE', $params);
                 /* Update TTL coming from marketplace server */
                 $params = array('group_name' => 'MARKETPLACE_TTL', 'param_name' => 'MARKETPLACE_TTL', 'value' => $response->MARKETPLACE_TTL);
                 execQuery('UPDATE_SETTINGS_PARAM_VALUE', $params);
             } else {
                 CTrace::wrn("Failed to parse response from marketplace. Response is " . print_r($result['body'], true));
             }
         } else {
             CTrace::wrn("Failed to fetch from marketplace. Error is " . $bnc->responseCode . " " . $bnc->_error_message);
         }
     }
 }
Esempio n. 4
0
 function preloadPHP($preload_php)
 {
     $sys_dir = dirname(dirname(__FILE__)) . '/';
     $add_modules_dir = CConf::get('add_modules_dir');
     $modules_dir = CConf::get('modules_dir');
     if (is_readable($preload_php['combined_file'])) {
         global $include_combined_php;
         // emergency flag
         $include_combined_php = $preload_php['combined_file'];
         CTrace::dbg('Preload combined: ' . $preload_php['combined_file']);
         CProfiler::includeStart($include_combined_php);
         include_once $include_combined_php;
         CProfiler::includeStop();
         CTrace::dbg('Done');
         unset($include_combined_php);
     } else {
         if (strpos($preload_php['combined_file'], 'core') === false) {
             foreach ($preload_php['files'] as $php) {
                 if (is_file(realpath($add_modules_dir . $php))) {
                     $this->includeFile($add_modules_dir . $php);
                 } else {
                     $this->includeFile($modules_dir . $php);
                 }
             }
         } else {
             foreach ($preload_php['files'] as $php) {
                 $this->includeFile($sys_dir . $php);
             }
         }
     }
 }
Esempio n. 5
0
 public static function setId($id)
 {
     self::$_id = $id;
 }
 function clonePage($params = array())
 {
     if (!is_writable($this->_PATH_CUR_THEME_PAGE_LAYOUTS)) {
         CTrace::err("ClonePage: " . $this->_PATH_CUR_THEME_PAGE_LAYOUTS . " is not writable.");
         return;
     }
     $cur_pages = $this->getPagesList();
     if (empty($params['page_name'])) {
         $params['page_name'] = 'test.php';
     }
     if (empty($params['cloned_page'])) {
         $params['cloned_page'] = 'index.php';
     }
     if (empty($params['settings'])) {
         $params['settings'] = null;
     }
     if (empty($params['placeholders'])) {
         $params['placeholders'] = null;
     }
     if (in_array($params['page_name'], $cur_pages)) {
         CTrace::err("ClonePage: page {$params['page_name']} already exists");
         return;
     }
     if (in_array($params['cloned_page'], $cur_pages)) {
         $clone = $this->getData($this->_PATH_CUR_THEME_PAGE_LAYOUTS . $params['cloned_page'] . '.yml');
         if (!empty($params['settings']) && is_array($params['settings'])) {
             foreach ($params['settings'] as $sname => $sval) {
                 if (!empty($sname) && in_array($sname, array_keys($clone['settings']))) {
                     $clone['settings'][$sname] = $sval;
                 }
             }
         }
         if (!empty($params['placeholders']) && is_array($params['placeholders'])) {
             foreach ($params['placeholders'] as $phName => $phVal) {
                 if (!empty($phName) && in_array($phName, array_keys($clone['placeholders']))) {
                     if (!empty($params['placeholders'][$phName]['visibility'])) {
                         $clone['placeholders'][$phName]['visibility'] = $params['placeholders'][$phName]['visibility'];
                     }
                     if (isset($params['placeholders'][$phName]['blocks']) && is_array($params['placeholders'][$phName]['blocks'])) {
                         if ($params['placeholders'][$phName]['blocks'] == array()) {
                             $clone['placeholders'][$phName]['blocks'] = array();
                         } else {
                             if (!empty($params['placeholders'][$phName]['overwrite'])) {
                                 $clone['placeholders'][$phName]['blocks'] = array();
                             }
                             foreach ($params['placeholders'][$phName]['blocks'] as $block) {
                                 if (!empty($block['name'])) {
                                     if (empty($block['visibility'])) {
                                         $block['visibility'] = 'visible';
                                     }
                                     array_push($clone['placeholders'][$phName]['blocks'], $block);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $this->_writeYAML($params['page_name'], $clone);
         // save 'new_page.php.yml'
         $this->_writeYAML($params['page_name'], $clone, true);
         // save 'new_page.php.restore.yml'
     } else {
         CTrace::err("ClonePage: cloning page {$params['cloned_page']} doesn't exist");
     }
 }
Esempio n. 7
0
function getTemplateFileByPattern($pattern)
{
    global $__TPL_DIR__;
    global $__SYSTEM_TPL_DIR__;
    CTrace::dbg('Pattern: ' . $pattern);
    // files from $__TPL_DIR__ (priority files)
    $files_user_skin = glob($__TPL_DIR__ . $pattern);
    CTrace::dbg('User\'s skin files: ', $files_user_skin);
    // files from $__SYSTEM_TPL_DIR__
    $files_system_skin = glob($__SYSTEM_TPL_DIR__ . $pattern);
    CTrace::dbg('System\'s skin files: ', $files_system_skin);
    $result = array();
    foreach ($files_user_skin as $f) {
        $result[] = str_replace($__TPL_DIR__, '', $f);
    }
    foreach ($files_system_skin as $f) {
        $result[] = str_replace($__SYSTEM_TPL_DIR__, '', $f);
    }
    $result = array_unique($result);
    CTrace::dbg('Relative pathes by pattern (merge of user skin files and system skin files): ', $result);
    return $result;
}
 function prepareTemplateToFill($tmpl_file)
 {
     $cache_result = $this->prepared_template_cache->read($tmpl_file);
     if ($cache_result !== null) {
         return $cache_result;
     } else {
         //Open file, read contents, replace tags.
         $this->CurrentTemplateFilename = $tmpl_file;
         $tpl_file = new CFile($this->CurrentTemplateFilename);
         $text = $tpl_file->getContent();
         if ($text === FALSE) {
             CTrace::backtrace();
             _fatal("TMPL_FILLER_ERROR_CANNOT_READ_FILE", $this->CurrentTemplateFilename);
         }
         $text = $this->removeTemplateWrapper($text);
         // find and modify all the image references.
         // for customer zone only
         $zone = modApiFunc('Users', 'getZone');
         if ($zone == 'CustomerZone') {
             $text = $this->replaceImages($text);
         }
         $this->prepared_template_cache->write($tmpl_file, $text);
         return $text;
     }
 }
 function outputLocationBreadcrumb($parents_list, $links, $view_name = "NavigationBar")
 {
     global $application;
     $CategoryId1Info = new CCategoryInfo(1);
     $this->CategoryId1Name = $CategoryId1Info->getCategoryTagValue('name');
     $retval = "";
     $isFirst = 1;
     $n = sizeof($parents_list);
     for ($i = 0; $i < $n; $i++) {
         $value = $parents_list[$i];
         $cat = new CCategoryInfo($value["id"]);
         $name = prepareHTMLDisplay($value["name"]);
         if ($cat->getCategoryTagValue('RecursiveStatus') == CATEGORY_STATUS_ONLINE) {
         } else {
             $name = '<span style="color: rgb(175, 175, 175);">' . $name . '</span>';
         }
         $arr = array("Href" => $this->getLinkToView($value["id"], $view_name, $cat), "Name" => $name, "CategoryId1Name" => prepareHTMLDisplay($this->CategoryId1Name));
         if ($n == 1) {
             $retval .= $this->mTmplFiller->fill("catalog/breadcrumb/", "single.tpl.html", $arr);
         } else {
             if ($i == 0) {
                 if ($links) {
                     $retval .= $this->mTmplFiller->fill("catalog/breadcrumb/", "first_link.tpl.html", $arr);
                 } else {
                     $retval .= $this->mTmplFiller->fill("catalog/breadcrumb/", "first.tpl.html", $arr);
                 }
             } else {
                 if ($i == $n - 1) {
                     $retval .= $this->mTmplFiller->fill("catalog/breadcrumb/", "last.tpl.html", $arr);
                 } else {
                     if ($links) {
                         $retval .= $this->mTmplFiller->fill("catalog/breadcrumb/", "default_link.tpl.html", $arr);
                     } else {
                         $retval .= $this->mTmplFiller->fill("catalog/breadcrumb/", "default.tpl.html", $arr);
                     }
                 }
             }
         }
     }
     if ($retval == "") {
         CTrace::wrn(array("CODE" => "CORE_053"), __CLASS__, __FUNCTION__);
     }
     return $retval;
 }
Esempio n. 10
0
 /**
 * Sends the mail.
 *
 * @param  array  $recipients
 * @param  string $type OPTIONAL
 * @return mixed
 */
 function send($recipients, $type = 'mail')
 {
     if (!defined('CRLF')) {
         //$this->setCrlf( "\r\n" ); // used to separate header lines
     }
     if (!$this->is_built) {
         $this->buildMessage();
     }
     switch ($type) {
         case 'mail':
             $subject = '';
             if (!empty($this->headers['Subject'])) {
                 $subject = $this->_encodeHeader($this->headers['Subject'], $this->build_params['head_charset']);
                 unset($this->headers['Subject']);
             }
             // Get flat representation of headers
             foreach ($this->headers as $name => $value) {
                 $headers[] = $name . ': ' . $this->_encodeHeader($value, $this->build_params['head_charset']);
             }
             $to = $this->_encodeHeader(implode(', ', $recipients), $this->build_params['head_charset']);
             if (!empty($this->return_path)) {
                 $result = @mail($to, $subject, $this->output, implode(CRLF, $headers), '-f' . $this->return_path);
             } else {
                 $result = @mail($to, $subject, $this->output, implode(CRLF, $headers));
             }
             // Reset the subject in case mail is resent
             if ($subject !== '') {
                 $this->headers['Subject'] = $subject;
             }
             // Return
             return $result;
             break;
         case 'smtp':
             require_once dirname(__FILE__) . '/phpmailer/PHPMailerAutoload.php';
             require_once dirname(__FILE__) . '/RFC822.php';
             //remove//		$smtp = &smtp::connect($this->smtp_params);
             $mail = new PHPMailer();
             $mail->isSMTP();
             // Set mailer to use SMTP
             $mail->XMailer = 'PHPMailer';
             $mail->Host = $this->smtp_params['host'];
             // Specify main and backup server
             $mail->Port = $this->smtp_params['port'];
             // SMTP port
             //                $mail->SMTPSecure = 'ssl';								// Enable encryption, 'ssl' also accepted
             $mail->SMTPAuth = $this->smtp_params['auth'];
             // Enable SMTP authentication
             $mail->Username = $this->smtp_params['user'];
             // SMTP username
             $mail->Password = $this->smtp_params['pass'];
             // SMTP password
             $mail->Subject = $this->headers['Subject'];
             $isHTML = !empty($this->html) ? true : false;
             $mail->IsHTML($isHTML);
             // sets ContentType to text or html
             $mail->Body = $this->output;
             if (isset($this->html_text) && !empty($this->html_text)) {
                 $mail->AltBody = $this->html_text;
             }
             // Parse recipients argument for internet addresses
             foreach ($recipients as $recipient) {
                 $addresses = Mail_RFC822::parseAddressList($recipient, $this->smtp_params['helo'], null, false);
                 foreach ($addresses as $address) {
                     $mail->addAddress(sprintf('%s@%s', $address->mailbox, $address->host), $address->personal);
                     //remove//				$smtp_recipients[] = sprintf('%s@%s', $address->mailbox, $address->host);
                 }
             }
             unset($addresses);
             // These are reused
             unset($address);
             // These are reused
             // Get flat representation of headers, parsing
             // Cc and Bcc as we go
             foreach ($this->headers as $name => $value) {
                 if ($name == 'Cc' or $name == 'Bcc') {
                     $addresses = Mail_RFC822::parseAddressList($value, $this->smtp_params['helo'], null, false);
                     foreach ($addresses as $address) {
                         $mail->addCC(sprintf('%s@%s', $address->mailbox, $address->host), $address->personal);
                         //remove//					$smtp_recipients[] = sprintf('%s@%s', $address->mailbox, $address->host);
                     }
                 }
                 if ($name == 'Bcc') {
                     /*						$addresses = Mail_RFC822::parseAddressList($value, $this->smtp_params['helo'], null, false);
                     						foreach ($addresses as $address) {
                     							$mail->addBCC(sprintf('%s@%s', $address->mailbox, $address->host),$address->personal);
                     						}
                     */
                     continue;
                 }
                 //remove//			$headers[] = $name . ': ' . $this->_encodeHeader($value, $this->build_params['head_charset']);
             }
             //remove//		// Add To header based on $recipients argument
             //remove//		$headers[] = 'To: ' . $this->_encodeHeader(implode(', ', $recipients), $this->build_params['head_charset']);
             //remove//		// Add headers to send_params
             //remove//		$send_params['headers']    = $headers;
             //remove//		$send_params['recipients'] = array_values(array_unique($smtp_recipients));
             //remove//		$send_params['body']       = $this->output;
             // Setup return path
             if (isset($this->return_path)) {
                 $mail->ReturnPath = $this->return_path;
             }
             if (!empty($this->headers['From'])) {
                 $from = Mail_RFC822::parseAddressList($this->headers['From']);
                 //remove//			$send_params['from'] = sprintf('%s@%s', $from[0]->mailbox, $from[0]->host);
                 $mail->setFrom(sprintf('%s@%s', $from[0]->mailbox, $from[0]->host), $from[0]->personal);
                 $mail->addReplyTo(sprintf('%s@%s', $from[0]->mailbox, $from[0]->host), $from[0]->personal);
             } else {
                 $mail->From = 'postmaster@' . $this->smtp_params['helo'];
             }
             // Send it
             //remove//		if (!$smtp->send($send_params)) {
             //remove//			$this->errors = $smtp->errors;
             if (!$mail->send()) {
                 $this->errors = $mail->ErrorInfo;
                 CTrace::err('Mail sending error: ' . $this->errors);
                 return false;
             }
             return true;
             break;
     }
 }
Esempio n. 11
0
 /**
  * Reads given template file contents.
  * It prepares it for filling.
  * It fills it with template variables values provided.
  * It does special HTML formatting if needed, e.g. draw red debug template frames.
  *
  *
  * @param string $folder_name Template file path: full folder path.
  * @param string $tmpl_short_filename Template file path: file name.
  * @param arrat $vars Template variables values.
  * @return string template html contents with tags replaced with their values.
  */
 function fill($folder_name, $tmpl_short_filename, $vars, $customer_zone = false)
 {
     //Open file, read contents, replace tags.
     $this->PreviousTemplateFilename = $this->CurrentTemplateFilename;
     if ($customer_zone) {
         $this->CurrentTemplateFilename = getTemplateFileAbsolutePath($this->TemplateDirPrefix . $folder_name . $tmpl_short_filename);
     } else {
         $this->CurrentTemplateFilename = $this->TemplateDirPrefix . $folder_name . "views/admin/templates/" . $tmpl_short_filename;
         if (!is_file($this->CurrentTemplateFilename)) {
             $this->CurrentTemplateFilename = $this->TemplateDirPrefix . $folder_name . $tmpl_short_filename;
         }
         if (!is_file($this->CurrentTemplateFilename)) {
             $this->CurrentTemplateFilename = modApiFunc('application', 'getAppIni', 'PATH_ADMIN_TPLS_VIEWS') . $folder_name . $tmpl_short_filename;
         }
     }
     $code_to_include = $this->getCachedCode($this->CurrentTemplateFilename);
     if ($code_to_include === null) {
         $tpl_file = new CFile($this->CurrentTemplateFilename);
         $code_to_include = $tpl_file->getContent();
         //                        ,                                                (        > 128)
         $code_to_include = convertTemplate($code_to_include);
         if ($code_to_include === FALSE) {
             CTrace::backtrace();
             _fatal("TMPL_FILLER_ERROR_CANNOT_READ_FILE", $this->CurrentTemplateFilename);
         }
         $code_to_include = '?>' . $this->removeTemplateWrapper($code_to_include);
         $this->saveInCache($this->CurrentTemplateFilename, $code_to_include);
     }
     $text = $this->includeTmplCode($code_to_include);
     $_vars = array();
     foreach ($vars as $key => $value) {
         $_vars['{' . $key . '}'] = $value;
     }
     $text = strtr($text, $_vars);
     $text = $this->addCrossSiteProtectinField($text);
     return $text;
 }
Esempio n. 12
0
 /**
  * Converts the answer from the remote host to the array of headers, cookies
  * and body.
  *
  * @param $result answer from the remote host
  * @return array of headers, cookies and body
  */
 function parseRequestResult($result)
 {
     $headers = array();
     $cookies = array();
     $body = "";
     $dp = 4096;
     $delimiter = false;
     $dtrs = array("\n", "\r\n", "\n\r");
     foreach ($dtrs as $v) {
         // trying to find a delimiter pair - headers/body border
         $tdp = _byte_strpos($result, $v . $v);
         if ($tdp != false && $dp > $tdp) {
             $dp = $tdp;
             $delimiter = $v;
         }
     }
     if ($delimiter == false) {
         CTrace::wrn('Failed to parse response, I cannot guess headers/body delimiter.');
         return;
     }
     $headers = _byte_substr($result, 0, $dp);
     $hstr = explode($delimiter, $headers);
     foreach ($hstr as $key => $string) {
         if (preg_match("/^HTTP/", $string)) {
             continue;
         }
         if (trim($string) == "") {
             break;
         }
         $header_array = explode(": ", trim($string), 2);
         $header_array[0] = _ml_strtoupper($header_array[0]);
         $headers[$header_array[0]] = chop($header_array[1]);
         if ($header_array[0] == "SET-COOKIE") {
             array_push($cookies, $header_array[1]);
         }
     }
     $cookies = $this->parseCookies($cookies);
     $body = _byte_substr($result, $dp + _byte_strlen($delimiter) * 2);
     return array("headers" => $headers, "cookies" => $cookies, "body" => $body);
 }
 /**
  * Initializes the languages
  * Note: cannot be executed in constructor
  *       since the class is created before creating the factory
  */
 function initLanguages()
 {
     global $application;
     global $zone;
     // if no mb_string then no language selection is available
     if (!$application->multilang_core->_mb_enabled) {
         return;
     }
     $active_only = $zone == 'CustomerZone';
     // setting the default language
     $this->_default_language = $this->_readDefaultLanguage();
     CTrace::inf('Default language is ' . CTrace::var2str($this->_default_language));
     // selecting the current language
     $this->_language = $this->_default_language;
     CTrace::inf('Current language is ' . CTrace::var2str($this->_language));
     // if customer is registered
     if ($zone == 'CustomerZone' && ($customer = modApiFunc('Customer_Account', 'getCurrentSignedCustomer'))) {
         $lng = modApiFunc('Customer_Account', 'getAccountLanguage', $customer);
         if ($lng && $this->checkLanguage($lng, $active_only)) {
             $this->_language = $lng;
             CTrace::inf('Customer is signed in, change current language to ' . $this->_language . ' because of the account settings.');
         }
     }
     // if admin is registered
     if ($zone == 'AdminZone' && ($adminID = modApiFunc('Users', 'getCurrentUserID'))) {
         $lng = modApiFunc('Users', 'getAccountLanguageById', $adminID);
         if ($lng && $this->checkLanguage($lng, $active_only)) {
             $this->_language = $lng;
             CTrace::inf('Admin is signed in, change current language to ' . $this->_language . ' because of the account settings.');
         }
     }
     // if cookie is set
     if (isset($_COOKIE['current_language_az']) && $zone == 'AdminZone') {
         $lng = $_COOKIE['current_language_az'];
         if ($this->checkLanguage($lng, $active_only)) {
             $this->_language = $lng;
             CTrace::inf('Change current language to ' . $this->_language . ' because of cookies.');
         }
     }
     if (isset($_COOKIE['current_language']) && $zone == 'CustomerZone') {
         $lng = $_COOKIE['current_language'];
         if ($this->checkLanguage($lng, $active_only)) {
             $this->_language = $lng;
             CTrace::inf('Change current language to ' . $this->_language . ' because of cookies.');
         }
     }
     // if language is set in the query string
     if (isset($_GET['current_language']) || isset($_POST['current_language'])) {
         if (isset($_GET['current_language'])) {
             $lng = $_GET['current_language'];
         } else {
             $lng = $_POST['current_language'];
         }
         if ($this->checkLanguage($lng, $active_only)) {
             $this->_language = $lng;
             CTrace::inf('Change current language to ' . $this->_language . ' because of GET params.');
         }
     }
     // checking the language
     if (!$this->checkLanguage($this->_language, $active_only)) {
         $this->_language = $this->_getAnyLanguage($active_only);
         if (!$this->_language) {
             $this->_default_language = '';
             CTrace::inf('Set default language to "".');
         }
     }
     // saving the current language
     // (only in case if the language was not provided in URL)
     if ($this->_language && !isset($_GET['current_language']) && !isset($_POST['current_language'])) {
         // setting the cookie for 30 days
         if ($zone == 'CustomerZone') {
             setcookie('current_language', $this->_language, time() + 2592000);
         } else {
             setcookie('current_language_az', $this->_language, time() + 2592000);
         }
         // updating the customer_account if needed
         if ($zone == 'CustomerZone' && $customer) {
             modApiFunc('Customer_Account', 'setAccountLanguage', $customer, $this->_language);
         }
         // updating the admin_account if needed
         if ($zone == 'AdminZone' && $adminID) {
             modApiFunc('Users', 'updateAccountLanguage', $adminID, $this->_language);
         }
     }
     $this->_default_language_number = $this->_readLanguageNumber($this->_default_language);
     $this->_language_number = $this->_readLanguageNumber($this->_language);
     $this->_resource_language = $this->_language;
     $this->_resource_language_number = $this->_language_number;
     // getting the page language if set
     if ($zone == 'AdminZone' && modApiFunc('Session', 'is_set', 'PageLanguages')) {
         $PageLanguages = modApiFunc('Session', 'get', 'PageLanguages');
         $request =& $application->getInstance('Request');
         $view = $request->getValueByKey('page_view');
         $action = $request->getCurrentAction();
         $pagelanguage = '';
         $script_name = array_pop(explode('/', $_SERVER['SCRIPT_NAME']));
         if (isset($PageLanguages['pages'][$script_name])) {
             $pagelanguage = $PageLanguages['pages'][$script_name];
         } elseif (isset($PageLanguages['views'][$view])) {
             $pagelanguage = $PageLanguages['views'][$view];
         } elseif (isset($PageLanguages['actions'][$action])) {
             $pagelanguage = $PageLanguages['actions'][$action];
         }
         if ($pagelanguage && $this->checkLanguage($pagelanguage, $active_only)) {
             $this->_language = $pagelanguage;
             $this->_language_number = $this->_readLanguageNumber($this->_language);
             CTrace::inf('Change current language to ' . $this->_language . ' because it is page language.');
         }
     }
 }
 function SendMailToAdmin()
 {
     $value = "";
     $Nvalue = "";
     $Mod = modApiFunc('SecureStore', 'checkSessionForModifiedFile');
     $New = modApiFunc('SecureStore', 'checkSessionForNewlyAddedFile');
     $Msg = getMsg('SS', 'FIND_UPDATE_NO_RESULT_MSG');
     $NewA = getMsg('SS', 'NEWLY_ADDED_FILE');
     $NewM = getMsg('SS', 'MODIFIED_FILE');
     if ($Mod !== $Msg) {
         $value = $NewM . "<br/><br/>" . $Mod;
     }
     if ($New !== $Msg) {
         $Nvalue = "<br/><br/>" . $NewA . "<br/><br/>" . $New;
     }
     if ($value !== "" || $Nvalue !== "") {
         $Mail_Body = $value . $Nvalue;
         $email = modApiFunc('Configuration', 'getValue', SYSCONFIG_STORE_OWNER_SITE_ADMINISTRATOR_EMAIL);
         loadCoreFile('ascHtmlMimeMail.php');
         $mail = new ascHtmlMimeMail();
         $mail->setText($Mail_Body);
         $mail->setSubject(getMsg('SS', 'SS_SEND_FILES_DETAILS_SUBJECT'));
         $mail->setFrom(modApiFunc('Notifications', 'getExtendedEmail', $email, 'EMAIL_STORE_OWNER', true));
         $mail->send(array($email));
         if (!$mail->send(array($email))) {
             CTrace::wrn('Mailer error: ' . $mail->ErrorInfo);
         } else {
             CTrace::inf('Mail has been sent for file changes in last days');
         }
         $tl_type = getMsg('NTFCTN', 'NTFCTN_TL_TYPE');
         $to = $email;
         $subj = getMsg('SS', 'SS_SEND_FILES_DETAILS_SUBJECT');
         $tl_header = getMsg('SS', 'SS_SEND_FILES_DETAILS_SUBJECT');
         $tl_body = $Mail_Body;
         modApiFunc('Timeline', 'addLog', $tl_type, $tl_header, $tl_body);
         $Msg = getMsg('SS', 'MAIL_SENT');
         modApiFunc('Session', 'set', 'MailSendResultMessage', $Msg);
     } else {
         $Msg = getMsg('SS', 'ERROR_TO_SEND_MAIL');
         modApiFunc('Session', 'set', 'MailSendResultMessage', $Msg);
     }
     modApiFunc('Session', 'set', 'ModifiedFileResult', "");
     modApiFunc('Session', 'set', 'NewlyAddedFileResult', "");
 }
Esempio n. 15
0
 /**
  *
  *
  * @return null
  */
 function initModules()
 {
     global $application, $zone;
     $lang = _ml_strtolower($application->getAppIni('LANGUAGE'));
     $moduleListCache = $application->getMMCache();
     if (isset($_SERVER['QUERY_STRING']) and $_SERVER['QUERY_STRING'] == 'update_all_modules') {
         CCacheFactory::clearAll();
         $this->resetAllModulesStatus();
         $_die_after_init = true;
     } else {
         $_die_after_init = false;
     }
     if (!$this->isModuleInstalled('Modules_Manager')) {
         $this->installModule($this->getModuleInfoFromFile($this->modules_directory . 'Modules_Manager'));
         CCacheFactory::clearAll();
     } else {
         /* Upgrade Main Store SQL- start*/
         $mmInfo = $this->getModuleInfoFromFile($this->modules_directory . 'Modules_Manager');
         if (version_compare($this->getModuleVersion($mmInfo->name), $mmInfo->version) < 0) {
             $oldVersionexplode = explode(".", $this->getModuleVersion($mmInfo->name));
             $oldModuleVersion = $oldVersionexplode[2];
             $upgradeFolder = $application->appIni['PATH_SYSTEM_DIR'] . "dbupdates/";
             $this->executeUpgradeSQL($oldModuleVersion, $upgradeFolder);
         }
         /* Upgrade Main Store SQL-end */
     }
     if (!$this->isModuleInstalled('Resources')) {
         $this->installModule($this->getModuleInfoFromFile($this->modules_directory . 'Resources'));
         // aquire system and CZ messages
         modApiFunc("Resources", "addResourceIniToDB", $application->getAppIni('PATH_ADMIN_RESOURCES') . 'system-messages-' . $lang . '.ini', 'SYS', 'system_messages', 'AZ');
         $_path = dirname(dirname(dirname(dirname(__FILE__)))) . '/avactis-themes/system/resources/messages.ini';
         modApiFunc("Resources", "addResourceIniToDB", $_path, 'CZ', 'customer_messages', 'CZ');
         CCacheFactory::clearAll();
     }
     if (!$this->isModuleInstalled('MultiLang')) {
         modApiFunc("Resources", "addResourceIniToDB", $application->getAppIni('PATH_ADMIN_RESOURCES') . 'multilang-messages-' . $lang . '.ini', 'ML', 'MultiLang', 'AZ');
         $this->installModule($this->getModuleInfoFromFile($this->modules_directory . 'multilang'));
         $this->isModuleInstalled('MultiLang', true);
         //                  ,
         CCacheFactory::clearAll();
     }
     if (!$this->isModuleInstalled('Configuration')) {
         modApiFunc("Resources", "addResourceIniToDB", $application->getAppIni('PATH_ADMIN_RESOURCES') . 'configuration-messages-' . $lang . '.ini', 'CFG', 'Configuration', 'AZ');
         $this->installModule($this->getModuleInfoFromFile($this->modules_directory . 'configuration'));
         $this->isModuleInstalled('Configuration', true);
         //                  ,
         CCacheFactory::clearAll();
     }
     if (!$this->isModuleInstalled('EventsManager')) {
         $this->installModule($this->getModuleInfoFromFile($this->modules_directory . 'eventsmanager'));
         $this->isModuleInstalled('EventsManager', true);
         //                  ,
         CCacheFactory::clearAll();
     }
     if ($application->db->DB_isTableExists($application->getAppIni('DB_TABLE_PREFIX') . "sessions") == false) {
         $tables['sessions'] = array();
         $tables['sessions']['columns'] = array('ses_id' => 'sessions.ses_id', 'ses_time' => 'sessions.ses_time', 'ses_value' => 'sessions.ses_value', 'ses_locked' => 'sessions.ses_locked');
         $tables['sessions']['types'] = array('ses_id' => DBQUERY_FIELD_TYPE_CHAR32 . ' NOT NULL DEFAULT \'\'', 'ses_time' => DBQUERY_FIELD_TYPE_INT . ' NOT NULL DEFAULT 0', 'ses_value' => DBQUERY_FIELD_TYPE_LONGTEXT . ' NOT NULL ', 'ses_locked' => DBQUERY_FIELD_TYPE_INT . ' NOT NULL DEFAULT 0');
         $tables['sessions']['primary'] = array('ses_id');
         $tables['sessions']['indexes'] = array('IDX_time' => 'ses_time', 'IDX_locked' => 'ses_locked');
         $query = new DB_Table_Create($application->addTablePrefix($tables));
     }
     $this->moduleList = $moduleListCache->read('ModulesList');
     $this->apiFiles = $moduleListCache->read('apiFiles');
     $this->modulesResFiles = $moduleListCache->read('modulesResFiles');
     $this->shortNamesToResFiles = $moduleListCache->read('shortNamesToResFiles');
     $this->actionList = $moduleListCache->read('actionList');
     $this->czViewList = $moduleListCache->read('czViewList');
     $this->azViewList = $moduleListCache->read('azViewList');
     $this->czAliasesList = $moduleListCache->read('czAliasesList');
     $this->hookList = $moduleListCache->read('hookList');
     $this->blocksList = $moduleListCache->read('blocksList');
     $this->SectionByView = $moduleListCache->read('SectionByView');
     $this->ViewBySection = $moduleListCache->read('ViewBySection');
     $this->storefrontLayout = $moduleListCache->read('storefrontLayout');
     if (!$this->hookList) {
         $this->hookList = array();
     }
     if (!isset($this->moduleList)) {
         $this->moduleList = array();
         /** installed Extensions Array **/
         $installedExtensionArray = $this->getInstalledExtensionModuleInfo();
         /* Processing for avactis-extensions directory-Begin*/
         $dir = @dir($application->getAppIni("PATH_ADD_MODULES_DIR"));
         if (is_dir($application->getAppIni("PATH_ADD_MODULES_DIR")) && is_readable($application->getAppIni("PATH_ADD_MODULES_DIR"))) {
             while ($file = $dir->read()) {
                 if ($file != '..' && $file != '.' && is_dir($application->getAppIni("PATH_ADD_MODULES_DIR") . $file)) {
                     $moduleInfo = $this->getModuleInfoFromFile($this->add_modules_directory . $file);
                     $isExtensionNotInstalled = true;
                     if (isset($installedExtensionArray[$moduleInfo->name])) {
                         $isExtensionNotInstalled = $installedExtensionArray[$moduleInfo->name]['module_active'];
                     }
                     if ($isExtensionNotInstalled && $moduleInfo != null) {
                         $this->moduleList[$moduleInfo->name] = $moduleInfo;
                     }
                 }
             }
         }
         /* Processing for avactis-extensions directory-End*/
         $dir = @dir($application->getAppIni("PATH_MODULES_DIR"));
         while ($file = $dir->read()) {
             if ($file != '..' && $file != '.' && !is_dir($application->getAppIni("PATH_ADD_MODULES_DIR") . $file) && is_dir($application->getAppIni("PATH_MODULES_DIR") . $file)) {
                 $moduleInfo = $this->getModuleInfoFromFile($this->modules_directory . $file);
                 if ($moduleInfo != null) {
                     //
                     $this->moduleList[$moduleInfo->name] = $moduleInfo;
                 }
             }
         }
         asort($this->moduleList);
         foreach ($this->moduleList as $module_name => $moduleInfo) {
             // check if the files of the module exist.
             $this->checkModuleFiles($moduleInfo);
             // save the class name of the module and the whole path to its main file in the list
             $this->apiFiles[_ml_strtolower($moduleInfo->name)] = $moduleInfo->mainFile;
             // save all extra API classes and their files
             if (is_array($moduleInfo->extraAPIFiles)) {
                 foreach ($moduleInfo->extraAPIFiles as $class => $file) {
                     $this->apiFiles[_ml_strtolower($class)] = $file;
                 }
             }
             if ($moduleInfo->shortName != null and isset($this->modulesResFiles[$moduleInfo->shortName])) {
                 unset($this->moduleList[$moduleInfo->name]);
                 CTrace::err('Duplicate Short Name ' . $moduleInfo->shortName);
                 continue;
             }
             $res_file_suffix = '-' . _ml_strtolower($application->getAppIni('LANGUAGE')) . '.ini';
             $res_files_common_location = $application->getAppIni('PATH_ADMIN_RESOURCES');
             if ($moduleInfo->resFile != null and $moduleInfo->shortName != null) {
                 /*
                  *        $this->modulesResFiles
                  *                        .                                                   .
                  */
                 $res_file_in_module = $this->store_dir . $moduleInfo->directory . 'resources/' . $moduleInfo->resFile . $res_file_suffix;
                 $res_file_in_common_location = $res_files_common_location . $moduleInfo->resFile . $res_file_suffix;
                 if ($moduleInfo->shortName == null) {
                     _fatal("Module {$moduleInfo->name} has no short name.");
                 }
                 if (isset($this->shortNamesToResFiles[$moduleInfo->resFile])) {
                     _fatal("Duplicate Res File for {$moduleInfo->name}.");
                 } else {
                     $this->shortNamesToResFiles[$moduleInfo->resFile] = $moduleInfo->shortName;
                 }
                 if (file_exists($res_file_in_module)) {
                     $this->modulesResFiles[$moduleInfo->shortName] = $res_file_in_module;
                 } else {
                     if (file_exists($res_file_in_common_location)) {
                         $this->modulesResFiles[$moduleInfo->shortName] = $res_file_in_common_location;
                     }
                 }
             }
             //                                   API              .
             //                                  .
             if (PRODUCT_VERSION_TYPE == 'TRUNK') {
                 $this->checkModuleAPIClass($moduleInfo);
             }
             //                   ,
             //                                ,                       .
             // get text resources from the res file and put it into the database
             if (!$this->isModuleInstalled($moduleInfo->name)) {
                 if (!isset($moduleInfo->shortName)) {
                     _fatal("No short name for {$moduleInfo->name}!");
                 }
                 if (isset($this->modulesResFiles[$moduleInfo->shortName]) && file_exists($this->modulesResFiles[$moduleInfo->shortName])) {
                     modApiFunc("Resources", "dropMessageMetaByMetaId", $moduleInfo->shortName);
                     modApiFunc("Resources", "dropMessageGroupByMetaId", $moduleInfo->shortName);
                     modApiFunc("Resources", "addResourceIniToDB", $this->modulesResFiles[$moduleInfo->shortName], $moduleInfo->shortName, $moduleInfo->name, 'AZ');
                 } else {
                     // no res file for module
                 }
             }
             $this->installModule($moduleInfo);
             // update       ,
             //       ,                modules               updated                   .
             $this->updateModule($moduleInfo);
             //                       actions
             foreach ($moduleInfo->actionFiles as $actionName => $actionFile) {
                 $this->actionList[$actionName] = $actionFile;
             }
             // save the list of all views for CustomerZone
             foreach ($moduleInfo->czViewFiles as $viewName => $viewFile) {
                 $this->czViewList[$viewName] = $viewFile;
             }
             // save the list of all views for AdminZone
             foreach ($moduleInfo->czAliases as $alias => $viewName) {
                 $this->czAliasesList[$alias] = $viewName;
             }
             // save the list of all views for AdminZone
             foreach ($moduleInfo->azViewFiles as $viewName => $viewFile) {
                 $this->azViewList[$viewName] = $viewFile;
             }
             // save a list of all hooks
             foreach ($moduleInfo->hookMap as $hookName => $actionList) {
                 foreach ($actionList as $actionName) {
                     if (!key_exists($actionName, $this->hookList)) {
                         $this->hookList[$actionName] = array();
                     }
                     $this->hookList[$actionName][$hookName] = $moduleInfo->hookFiles[$hookName];
                 }
             }
             // save a list of blocks
             if (file_exists($this->store_dir . $moduleInfo->directory . 'blocks.yml')) {
                 $this->blocksList[] = $this->store_dir . $moduleInfo->directory . 'blocks.yml';
             }
             // sections by view
             if (!empty($moduleInfo->SectionByView)) {
                 $this->SectionByView = $moduleInfo->SectionByView;
             }
             // views by section
             if (!empty($moduleInfo->ViewBySection)) {
                 $this->ViewBySection = $moduleInfo->ViewBySection;
             }
             // storefront Layout addition
             if ($moduleInfo->storefrontLayout && file_exists($this->store_dir . $moduleInfo->directory . $moduleInfo->storefrontLayout)) {
                 if (!$this->storefrontLayout) {
                     $this->storefrontLayout = array();
                 }
                 $this->storefrontLayout = array_merge($this->storefrontLayout, _parse_ini_file($this->store_dir . $moduleInfo->directory . $moduleInfo->storefrontLayout, true));
             }
         }
         if (PRODUCT_VERSION_TYPE != 'TRUNK') {
             $moduleListCache->write('ModulesList', $this->moduleList);
             $moduleListCache->write('apiFiles', $this->apiFiles);
             $moduleListCache->write('modulesResFiles', $this->modulesResFiles);
             $moduleListCache->write('shortNamesToResFiles', $this->shortNamesToResFiles);
             $moduleListCache->write('actionList', $this->actionList);
             $moduleListCache->write('czViewList', $this->czViewList);
             $moduleListCache->write('azViewList', $this->azViewList);
             $moduleListCache->write('czAliasesList', $this->czAliasesList);
             $moduleListCache->write('hookList', $this->hookList);
             $moduleListCache->write('blocksList', $this->blocksList);
             $moduleListCache->write('SectionByView', $this->SectionByView);
             $moduleListCache->write('ViewBySection', $this->ViewBySection);
             $moduleListCache->write('storefrontLayout', $this->storefrontLayout);
         }
     } else {
         CTrace::inf('Bypass loading of module list (use cached).');
     }
     if (!defined('COMPILED_MODULES_LOADED')) {
         foreach ($this->moduleList as $module_name => $moduleInfo) {
             // if the file of module constants is specfifed, then load it.
             if ($moduleInfo->constantsFile !== null) {
                 $this->includeFile($moduleInfo->constantsFile);
             }
             // load common db queries
             $common_db_queries_file = $moduleInfo->directory . 'dbqueries/common.php';
             if (file_exists($this->store_dir . $common_db_queries_file)) {
                 $this->includeFile($common_db_queries_file);
             }
             //load extension default hooks
             if ($moduleInfo->ext_def_hooks !== null) {
                 $this->includeFile($moduleInfo->ext_def_hooks);
             }
             $this->includeFile($moduleInfo->directory . '/asc-hooks.php');
         }
     } else {
         CTrace::inf('Bypass constants and queries including (use precompiled).');
     }
     if (!defined('MODULES_VIEWS_REGISTERED')) {
         if ($zone == 'CustomerZone') {
             foreach ($this->moduleList as $module_name => $moduleInfo) {
                 $this->registerViewList($moduleInfo->czViewFiles);
                 $this->registerAliasesList($moduleInfo->czAliases);
             }
         } else {
             foreach ($this->moduleList as $module_name => $moduleInfo) {
                 $this->registerViewList($moduleInfo->azViewFiles);
             }
         }
     } else {
         CTrace::inf('Bypass modules views registering (use precompiled).');
     }
     if ($_die_after_init === true) {
         die('Message');
     }
 }
 /**
  * Returns a real value of system variable.
  */
 function getValue($constant)
 {
     global $application;
     if ($constant == STOREFRONT_ACTIVE_SKIN) {
         if (modApiFunc('Look_Feel', 'isCSSEditor')) {
             return $_COOKIE['edit_skin'];
         }
         if (modApiFunc('Look_Feel', 'isFacebook')) {
             return 'facebook';
         }
         if (modApiFunc('Look_Feel', 'isWP')) {
             return 'wp';
         }
         if (modApiFunc('Look_Feel', 'isMobile')) {
             return 'system_mobile';
         }
     }
     if (!isset(self::$cache)) {
         $result = execQuery('SELECT_STORE_SETTINGS', array());
         foreach ($result as $row) {
             switch ($row['type']) {
                 case 'integer':
                     $value = intval($row['value']);
                     break;
                 case 'price':
                     $value = floatval($row['value']);
                     break;
                 case 'boolean':
                     $value = (bool) $row['value'];
                     break;
                 case 'string':
                     $value = (string) $row['value'];
                     break;
                 default:
                     $value = $row['value'];
                     break;
             }
             self::$cache[$row['name']] = $value;
         }
     }
     if (!isset(self::$cache[$constant])) {
         CTrace::wrn('Configuration parameter is undefined: ' . $constant);
     }
     return self::$cache[$constant];
 }
Esempio n. 17
0
    CTrace::startScript();
    CTrace::setId(getmypid());
    foreach ($tracelog as $trace_cfg) {
        if ($trace_cfg['enabled'] == 'yes') {
            $r = new CTraceLogRotation($trace_cfg['file'], $trace_cfg['rotation']['size'], $trace_cfg['rotation']['rotate']);
            $r->rotate();
            $tw = new CTraceWriter($trace_cfg['file'], $trace_cfg['template'], new CTraceFilter($trace_cfg['filter']));
            CTrace::registerWriter($tw);
        }
    }
}
// must be defined after CTrace initialization.
// all php notices, warnings and errors will be logged, so we need to set E_ALL level
//error_reporting(E_ERROR);
//set_error_handler('__error_handler__', E_ERROR);
CTrace::inf('Request: ' . getCurrentURL());
CProfiler::start('init');
$bootstrap = new Bootstrap();
$bootstrap->preboot();
//CTrace::inf('Point 1 (after preboot)');
$bootstrap->preloadCorePHP();
do_action('init');
//CTrace::inf('Point 2 (after preloading core php)');
$bootstrap->preloadModulesPHP();
//CTrace::inf('Point 3 (after preloading modules php)');
global $zone;
if ($zone == 'CustomerZone') {
    $bootstrap->preloadModulesViewsCzPHP();
    //CTrace::inf('Point 3 (after preloading modules views php)');
}
$bootstrap->boot();