Ejemplo n.º 1
0
 function set($post)
 {
     global $MOD, $DT_TIME, $DT_IP, $AREA, $_username, $_userid;
     $AREA or $AREA = cache_read('area.php');
     $post['city'] or $post['city'] = $post['areaid'] ? $AREA[$post['areaid']]['areaname'] : '';
     is_url($post['thumb']) or $post['thumb'] = '';
     $post['filepath'] = isset($post['filepath']) && is_filepath($post['filepath']) ? file_vname($post['filepath']) : '';
     $post['addtime'] = isset($post['addtime']) && $post['addtime'] ? strtotime($post['addtime']) : $DT_TIME;
     $post['edittime'] = $DT_TIME;
     $post['fromtime'] = strtotime($post['fromtime'] . ' 0:0:0');
     $post['totime'] = strtotime($post['totime'] . ' 23:59:59');
     $post['homepage'] = fix_link($post['homepage']);
     $post['sign'] = $post['sign'] ? 1 : 0;
     $post['fee'] = dround($post['fee']);
     $post['content'] = stripslashes($post['content']);
     $post['content'] = save_local($post['content']);
     if ($MOD['clear_link']) {
         $post['content'] = clear_link($post['content']);
     }
     if ($MOD['save_remotepic']) {
         $post['content'] = save_remote($post['content']);
     }
     if ($MOD['introduce_length']) {
         $post['introduce'] = addslashes(get_intro($post['content'], $MOD['introduce_length']));
     }
     if ($this->itemid) {
         $post['editor'] = $_username;
         $new = $post['content'];
         if ($post['thumb']) {
             $new .= '<img src="' . $post['thumb'] . '"/>';
         }
         $r = $this->get_one();
         $old = $r['content'];
         if ($r['thumb']) {
             $old .= '<img src="' . $r['thumb'] . '"/>';
         }
         delete_diff($new, $old);
     } else {
         $post['username'] = $post['editor'] = $_username;
         $post['ip'] = $DT_IP;
     }
     $content = $post['content'];
     unset($post['content']);
     $post = dhtmlspecialchars($post);
     $post['content'] = addslashes(dsafe($content));
     return array_map("trim", $post);
 }
Ejemplo n.º 2
0
 function set($post)
 {
     global $MOD, $DT_TIME, $DT_IP, $_username, $_userid;
     is_url($post['thumb']) or $post['thumb'] = '';
     $post['filepath'] = isset($post['filepath']) && is_filepath($post['filepath']) ? file_vname($post['filepath']) : '';
     $post['editor'] = $_username;
     $post['addtime'] = isset($post['addtime']) && $post['addtime'] ? strtotime($post['addtime']) : $DT_TIME;
     $post['edittime'] = $DT_TIME;
     is_url($post['thumb']) or $post['thumb'] = '';
     $post['fee'] = dround($post['fee']);
     $post['down'] = fix_link($post['down']);
     $post['down_width'] = intval($post['down_width']);
     $post['down_height'] = intval($post['down_height']);
     $post['content'] = stripslashes($post['content']);
     $post['content'] = save_local($post['content']);
     if ($MOD['clear_link']) {
         $post['content'] = clear_link($post['content']);
     }
     if ($MOD['save_remotepic']) {
         $post['content'] = save_remote($post['content']);
     }
     if ($MOD['introduce_length']) {
         $post['introduce'] = addslashes(get_intro($post['content'], $MOD['introduce_length']));
     }
     if ($this->itemid) {
         $new = $post['content'];
         if ($post['thumb']) {
             $new .= '<img src="' . $post['thumb'] . '"/>';
         }
         $r = $this->get_one();
         $old = $r['content'];
         if ($r['thumb']) {
             $old .= '<img src="' . $r['thumb'] . '"/>';
         }
         delete_diff($new, $old);
         if ($r['fileurl'] != $post['fileurl']) {
             delete_upload($r['fileurl'], match_userid($r['fileurl']));
         }
     } else {
         $post['ip'] = $DT_IP;
     }
     $content = $post['content'];
     unset($post['content']);
     $post = dhtmlspecialchars($post);
     $post['content'] = addslashes(dsafe($content));
     return array_map("trim", $post);
 }
Ejemplo n.º 3
0
 function set($post)
 {
     global $MOD, $DT_TIME, $DT_IP, $_username, $_userid;
     $post['editor'] = $_username;
     $post['addtime'] = isset($post['addtime']) && $post['addtime'] ? strtotime($post['addtime']) : $DT_TIME;
     $post['adddate'] = timetodate($post['addtime'], 3);
     $post['edittime'] = $DT_TIME;
     $post['editdate'] = timetodate($post['edittime'], 3);
     $post['fee'] = dround($post['fee']);
     $post['homepage'] = fix_link(trim($post['homepage']));
     $post['video'] = fix_link(trim($post['video']));
     $post['video_width'] = intval($post['video_width']);
     $post['video_height'] = intval($post['video_height']);
     $post['title'] = trim($post['title']);
     $post['content'] = stripslashes($post['content']);
     $post['content'] = save_local($post['content']);
     if ($MOD['clear_link']) {
         $post['content'] = clear_link($post['content']);
     }
     if ($MOD['save_remotepic']) {
         $post['content'] = save_remote($post['content']);
     }
     if ($MOD['introduce_length']) {
         $post['introduce'] = addslashes(get_intro($post['content'], $MOD['introduce_length']));
     }
     if ($this->itemid) {
         $new = $post['content'];
         if ($post['thumb']) {
             $new .= '<img src="' . $post['thumb'] . '">';
         }
         $r = $this->get_one();
         $old = $r['content'];
         if ($r['thumb']) {
             $old .= '<img src="' . $r['thumb'] . '">';
         }
         delete_diff($new, $old);
     } else {
         $post['ip'] = $DT_IP;
     }
     $content = $post['content'];
     unset($post['content']);
     $post = dhtmlspecialchars($post);
     $post['content'] = addslashes(dsafe($content));
     return array_map("trim", $post);
 }
Ejemplo n.º 4
0
 function get_list($condition = 'status=3', $order = 'itemid DESC')
 {
     global $MODULE, $TYPE, $pages, $page, $pagesize, $offset, $L, $sum;
     if ($page > 1 && $sum) {
         $items = $sum;
     } else {
         $r = $this->db->get_one("SELECT COUNT(*) AS num FROM {$this->table} WHERE {$condition}");
         $items = $r['num'];
     }
     $pages = pages($items, $page, $pagesize);
     $lists = array();
     $result = $this->db->query("SELECT * FROM {$this->table} WHERE {$condition} ORDER BY {$order} LIMIT {$offset},{$pagesize}");
     while ($r = $this->db->fetch_array($result)) {
         $r['adddate'] = timetodate($r['addtime'], 5);
         $r['title'] = set_style($r['title'], $r['style']);
         $r['url'] = $MODULE[3]['linkurl'] . 'redirect.php?url=' . urlencode(fix_link($r['url']));
         $r['type'] = $r['typeid'] && isset($TYPE[$r['typeid']]) ? set_style($TYPE[$r['typeid']]['typename'], $TYPE[$r['typeid']]['style']) : $L['default_type'];
         $lists[] = $r;
     }
     return $lists;
 }
Ejemplo n.º 5
0
if ($lazy) {
    $content = img_lazy($content);
}
$CP = $MOD['cat_property'] && $CAT['property'];
if ($CP) {
    require_once DT_ROOT . '/include/property.func.php';
    $options = property_option($catid);
    $values = property_value($moduleid, $itemid);
}
$adddate = timetodate($addtime, 3);
$editdate = timetodate($edittime, 3);
if ($voteid) {
    $voteid = explode(' ', $voteid);
}
if ($fromurl) {
    $fromurl = fix_link($fromurl);
}
$fileurl = $linkurl;
$linkurl = $MOD['linkurl'] . $linkurl;
$titles = array();
if ($subtitle) {
    $titles = explode("\n", $subtitle);
    $titles = array_map('trim', $titles);
}
$keytags = $tag ? explode(' ', $tag) : array();
$fee = get_fee($item['fee'], $MOD['fee_view']);
if ($fee) {
    $description = get_description($content, $MOD['pre_view']);
    $user_status = 4;
} else {
    $user_status = 3;
Ejemplo n.º 6
0
	function check_mysql_table_structure()
	{
		global $DB;
		$strError = '';

		if ($this->arTestVars['table_charset_fail'])
			return $this->Result(null, GetMessage('SC_TABLE_COLLATION_NA'));

		$module = '';
		$cnt = $iCurrent = 0;
		if ($dir = opendir($path = $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules'))
		{
			while(false !== ($item = readdir($dir)))
			{
//				if ($item == '.' || $item == '..')
				if (strpos($item, '.') !== false) // skipping all external modules
					continue;

				$cnt++;

				if ($this->arTestVars['last_value'])
				{
					$iCurrent++;
					if ($this->arTestVars['last_value'] == $item)
						unset($this->arTestVars['last_value']);
				}
				elseif (!$module)
					$module = $item;
			}
			closedir($dir);
		}
		else
			return false;
				
		$file = $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$module.'/install/db/mysql/install.sql';
		if (!file_exists($file))
			$file = $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$module.'/install/mysql/install.sql';
		if (file_exists($file)) // uses database...
		{
			$arTableColumns = array();
			$rs = $DB->Query('SELECT * FROM b_module WHERE id="'.$DB->ForSQL($module).'"');
			if ($rs->Fetch()) // ... and is installed
			{
				if (false === ($query = file_get_contents($file)))
					return false;

				$arTables = array();
				$arQuery = $DB->ParseSQLBatch(str_replace("\r", "", $query));
				foreach($arQuery as $sql)
				{
					if (preg_match('#^(CREATE TABLE )(IF NOT EXISTS)? *`?([a-z0-9_]+)`?(.*);?$#mis',$sql,$regs))
					{
						$table = $regs[3];
						if (preg_match('#^site_checker_#', $table))
							continue;
						$rs = $DB->Query('SHOW TABLES LIKE "'.$table.'"');
						if (!$rs->Fetch())
						{
							if ($this->fix_mode)
							{
								if (!$DB->Query($sql, true))
									return $this->Result(false, 'Mysql Query Error: '.$sql.' ['.$DB->db_Error.']');
							}
							else
							{
								$strError .= GetMessage('SC_ERR_NO_TABLE', array('#TABLE#' => $table))."<br>";
								$_SESSION['FixQueryList'][] = $sql;
								$this->arTestVars['iError']++;
								$this->arTestVars['iErrorAutoFix']++;
								$this->arTestVars['cntNoTables']++;
								continue;
							}
						}

						$arTables[$table] = $sql;
						$tmp_table = 'site_checker_'.$table;
						$DB->Query('DROP TABLE IF EXISTS `'.$tmp_table.'`');
						$DB->Query($regs[1].' `'.$tmp_table.'`'.$regs[4]);
					}
					elseif (preg_match('#^(ALTER TABLE)( )?`?([a-z0-9_]+)`?(.*);?$#mis',$sql,$regs))
					{
						$table = $regs[3];
						if (!$arTables[$table])
							continue;
						$tmp_table = 'site_checker_'.$table;
						$DB->Query($regs[1].' `'.$tmp_table.'`'.$regs[4]);
					}
					elseif (preg_match('#^INSERT INTO *`?([a-z0-9_]+)`?[^\(]*\(?([^)]*)\)?[^V]*VALUES[^\(]*\((.+)\);?$#mis',$sql,$regs))
					{
						$table = $regs[1];
						if (!$arTables[$table])
							continue;
						$tmp_table = 'site_checker_'.$table;

						if ($regs[2])
							$arColumns = explode(',', $regs[2]);
						else
						{
							if (!$arTableColumns[$tmp_table])
							{
								$rs = $DB->Query('SHOW COLUMNS FROM `'.$tmp_table.'`');
								while($f = $rs->Fetch())
									$arTableColumns[$tmp_table][] = $f['Field'];
							}
							$arColumns = $arTableColumns[$tmp_table];
						}
						
						$strValues = $regs[3];
						$ar = explode(",",$strValues);
						$arValues = array();
						$i = 0;
						$str = '';
						foreach($ar as $v)
						{
							$str .= ($str ? ',' : '').$v;
							if (preg_match('#^ *(-?[0-9]+|\'.*\'|".*"|null|now\(\)) *$#i',$str)) 
							{
								$arValues[$i] = $str;
								$str = '';
								$i++;
							}
						}
						
						if (!$str)
						{
							$sqlSelect = 'SELECT * FROM `'.$table.'` WHERE 1=1 ';
							foreach($arColumns as $k => $c)
							{
								$v = $arValues[$k];
								if (!preg_match('#null|now\(\)#i',$v))
									$sqlSelect .= ' AND '.$c.'='.$v;
							}
							$rs = $DB->Query($sqlSelect);
							if (!$rs->Fetch())
							{
								if ($this->fix_mode)
								{
									if (!$DB->Query($sql, true))
										return $this->Result(false, 'Mysql Query Error: '.$sql.' ['.$DB->db_Error.']');
								}
								else
								{
									$strError .= GetMessage('SC_ERR_NO_VALUE', array('#TABLE#' => $table, '#SQL#' => $sql))."<br>";
									$_SESSION['FixQueryList'][] = $sql;
									$this->arTestVars['iError']++;
									$this->arTestVars['iErrorAutoFix']++;
									$this->arTestVars['cntNoValues']++;
								}
							}
						}
						else
							echo "Error parsing SQL:\n".$sql."\n";
					}
				}

				foreach($arTables as $table => $sql)
				{
					$tmp_table = 'site_checker_'.$table;
					$arColumns = array();
					$rs = $DB->Query('SHOW COLUMNS FROM `'.$table.'`');
					while($f = $rs->Fetch())
						$arColumns[strtolower($f['Field'])] = $f;

					$rs = $DB->Query('SHOW COLUMNS FROM `'.$tmp_table.'`');
					while($f_tmp = $rs->Fetch())
					{
						$tmp = TableFieldConstruct($f_tmp);
						if ($f = $arColumns[strtolower($f_tmp['Field'])])
						{
							if (($cur = TableFieldConstruct($f)) != $tmp)
							{
								$sql = 'ALTER TABLE `'.$table.'` MODIFY `'.$f_tmp['Field'].'` '.$tmp;
								if ($this->fix_mode)
								{
									if (TableFieldCanBeAltered($f, $f_tmp))
									{
										if (!$DB->Query($sql, true))
											return $this->Result(false, 'Mysql Query Error: '.$sql.' ['.$DB->db_Error.']');
									}
									else
										$this->arTestVars['iErrorFix']++;
								}
								else
								{
									$_SESSION['FixQueryList'][] = $sql;
									$strError .= GetMessage('SC_ERR_FIELD_DIFFERS', array('#TABLE#' => $table, '#FIELD#' => $f['Field'], '#CUR#' => $cur, '#NEW#' => $tmp))."<br>";
									$this->arTestVars['iError']++;
									if (TableFieldCanBeAltered($f, $f_tmp))
										$this->arTestVars['iErrorAutoFix']++;
									$this->arTestVars['cntDiffFields']++;
								}
							}
						}
						else
						{
							$sql = 'ALTER TABLE `'.$table.'` ADD `'.$f_tmp['Field'].'` '.str_replace('auto_increment', '' , strtolower($tmp)); // if only Primary Key is missing we will have to pass the test twice
							if ($this->fix_mode)
							{
								if (!$DB->Query($sql, true))
									return $this->Result(false, 'Mysql Query Error: '.$sql.' ['.$DB->db_Error.']');
							}
							else
							{
								$_SESSION['FixQueryList'][] = $sql;
								$strError .= GetMessage('SC_ERR_NO_FIELD', array('#TABLE#' => $table, '#FIELD#' => $f_tmp['Field']))."<br>";
								$this->arTestVars['iError']++;
								$this->arTestVars['iErrorAutoFix']++;
								$this->arTestVars['cntNoFields']++;
							}
						}
					}

					$arIndexes = array();
					$rs = $DB->Query('SHOW INDEXES FROM `'.$table.'`');
					while($f = $rs->Fetch())
					{
						$ix =& $arIndexes[$f['Key_name']];
						$column = strtolower($f['Column_name'].($f['Sub_part'] ? '('.$f['Sub_part'].')' : ''));
						if ($ix)
							$ix .= ','.$column;
						else
							$ix = $column;
					}

					$arIndexes_tmp = array();
					$rs = $DB->Query('SHOW INDEXES FROM `'.$tmp_table.'`');
					while($f = $rs->Fetch())
					{
						$ix =& $arIndexes_tmp[$f['Key_name']];
						$column = strtolower($f['Column_name'].($f['Sub_part'] ? '('.$f['Sub_part'].')' : ''));
						if ($ix)
							$ix .= ','.$column;
						else
							$ix = $column;
					}
					unset($ix); // unlink the reference
					foreach($arIndexes_tmp as $name => $ix)
					{
						if (!in_array($ix,$arIndexes))
						{
							while($arIndexes[$name])
								$name .= '_sc';
							$sql = $name == 'PRIMARY' ? 'ALTER TABLE `'.$table.'` ADD PRIMARY KEY ('.$ix.')' : 'CREATE INDEX `'.$name.'` ON `'.$table.'` ('.$ix.')';
							if ($this->fix_mode)
							{
								if (!$DB->Query($sql, true))
									return $this->Result(false, 'Mysql Query Error: '.$sql.' ['.$DB->db_Error.']');
							}
							else
							{
								$_SESSION['FixQueryList'][] = $sql;
								$strError .= GetMessage('SC_ERR_NO_INDEX', array('#TABLE#' => $table, '#INDEX#' => $name.' ('.$ix.')'))."<br>";
								$this->arTestVars['iError']++;
								$this->arTestVars['iErrorAutoFix']++;
								$this->arTestVars['cntNoIndexes']++;
							}
						}
					}

					$DB->Query('DROP TABLE `'.$tmp_table.'`');
				}
				echo $strError; // to log
			}
		}

		if ($iCurrent < $cnt) // partial
		{
			$this->arTestVars['last_value'] = $module;
			$this->test_percent = floor($iCurrent / $cnt * 100);
			return true;
		}

		if ($this->fix_mode)
		{
			if ($this->arTestVars['iErrorFix'] > 0)
				return $this->Result(null, GetMessage('SC_CHECK_TABLES_STRUCT_ERRORS_FIX', 
					array(
						'#VAL#' => intval($this->arTestVars['iErrorFix']),
					)));
			return true;
		}
		else
		{
			if ($this->arTestVars['iError'] > 0)
			{
				echo implode(";\n", $_SESSION['FixQueryList']).';';
				$_SESSION['FixQueryList'] = array();
				return $this->Result(false, GetMessage('SC_CHECK_TABLES_STRUCT_ERRORS', 
					array(
						'#VAL#' => intval($this->arTestVars['iError']),
						'#VAL1#' => intval($this->arTestVars['iErrorAutoFix']),
						'#NO_TABLES#' => intval($this->arTestVars['cntNoTables']),
						'#NO_FIELDS#' => intval($this->arTestVars['cntNoFields']),
						'#DIFF_FIELDS#' => intval($this->arTestVars['cntDiffFields']),
						'#NO_INDEXES#' => intval($this->arTestVars['cntNoIndexes']),
						'#NO_VALUES#' => intval($this->arTestVars['cntNoValues']),
					)).($this->arTestVars['iErrorAutoFix'] > 0 ? fix_link(3) : ''));
			}
			return true;
		}
	}
Ejemplo n.º 7
0
     } else {
         if ($typeid == 3 || $typeid == 5) {
             if (strlen($post['image_src']) < 15) {
                 message($L['pass_ad_image_src']);
             }
             $ad['image_src'] = $post['image_src'];
             $ad['image_url'] = fix_link($post['image_url']);
             $ad['image_alt'] = $post['image_alt'];
         } else {
             if ($typeid == 4) {
                 if (strlen($post['flash_src']) < 15 || strpos($post['flash_src'], '.swf') === false) {
                     message($L['pass_ad_flash_src']);
                 }
                 $ad['flash_src'] = $post['flash_src'];
                 $ad['flash_loop'] = $post['flash_loop'] ? 1 : 0;
                 $ad['flash_url'] = fix_link($post['flash_url']);
             } else {
                 if ($typeid == 6) {
                     $post['key_id'] = intval($post['key_id']);
                     $post['key_id'] or message($L['pass_ad_infoid']);
                     $ad['key_id'] = $post['key_id'];
                 }
             }
         }
     }
 }
 if ($typeid == 6 || $typeid == 7) {
     $ad['key_moduleid'] = $p['moduleid'];
     $ad['key_catid'] = $post['catid'];
     $ad['key_word'] = trim(strip_tags($post['word']));
 }
Ejemplo n.º 8
0
<tr>
<td>&nbsp;<a href="javascript:TopUseBack('<?php 
    echo $v['copyfrom'];
    ?>
','<?php 
    echo $v['fromurl'];
    ?>
');"><?php 
    echo $v['copyfrom'];
    ?>
</a></td>
<td>&nbsp;<a href="<?php 
    echo $EXT['linkurl'];
    ?>
redirect.php?url=<?php 
    echo urlencode(fix_link($v['fromurl']));
    ?>
" target="_blank"><?php 
    echo $v['fromurl'];
    ?>
</a></td>
<td align="center"><a href="javascript:TopUseBack('<?php 
    echo $v['copyfrom'];
    ?>
','<?php 
    echo $v['fromurl'];
    ?>
');" class="t">[选择]</a></td>
</tr>
<?php 
}
Ejemplo n.º 9
0
<?php

defined('IN_DESTOON') or exit('Access Denied');
require DT_ROOT . '/module/' . $module . '/common.inc.php';
$url = isset($url) ? fix_link($url) : DT_PATH;
if (isset($username)) {
    if (check_name($username)) {
        $r = $db->get_one("SELECT linkurl FROM {$DT_PRE}company WHERE username='******'");
        $url = $r ? $r['linkurl'] : userurl($username);
    }
} else {
    if (isset($aid)) {
        $aid = intval($aid);
        if ($aid) {
            $r = $db->get_one("SELECT url,key_moduleid,key_id,typeid FROM {$DT_PRE}ad WHERE aid={$aid} AND fromtime<{$DT_TIME} AND totime>{$DT_TIME}");
            if ($r) {
                $url = $r['key_moduleid'] && $r['typeid'] > 5 ? 'redirect.php?mid=' . $r['key_moduleid'] . '&itemid=' . $r['key_id'] : $r['url'];
                $db->query("UPDATE {$DT_PRE}ad SET hits=hits+1 WHERE aid={$aid}");
            }
        }
    } else {
        if ($mid) {
            if (isset($MODULE[$mid]) && $itemid) {
                if ($mid == 2) {
                    $mid = 4;
                }
                $condition = $mid == 4 ? "userid={$itemid}" : "itemid={$itemid}";
                $r = $db->get_one("SELECT linkurl FROM " . get_table($mid) . " WHERE {$condition}");
                if ($r) {
                    $url = strpos($r['linkurl'], '://') === false ? $MODULE[$mid]['linkurl'] . $r['linkurl'] : $r['linkurl'];
                }
Ejemplo n.º 10
0
 function set_member($member)
 {
     global $MOD;
     $member['email'] = trim($member['email']);
     $member['mail'] = isset($member['mail']) ? trim($member['mail']) : '';
     is_email($member['mail']) or $member['mail'] = '';
     $member['msn'] = isset($member['msn']) ? trim($member['msn']) : '';
     is_email($member['msn']) or $member['msn'] = '';
     $member['qq'] = isset($member['qq']) ? trim($member['qq']) : '';
     is_numeric($member['qq']) or $member['qq'] = '';
     $member['ali'] = isset($member['ali']) ? trim($member['ali']) : '';
     if (!$this->is_clean($member['ali'])) {
         $member['ali'] = '';
     }
     $member['skype'] = isset($member['skype']) ? trim($member['skype']) : '';
     if (!$this->is_clean($member['skype'])) {
         $member['skype'] = '';
     }
     $member['address'] = isset($member['address']) ? trim($member['address']) : '';
     if (!$this->is_clean($member['address'])) {
         $member['address'] = '';
     }
     $member['postcode'] = isset($member['postcode']) ? trim($member['postcode']) : '';
     is_numeric($member['postcode']) or $member['postcode'] = '';
     $member['mode'] = isset($member['mode']) && is_array($member['mode']) && $member['mode'] ? implode(',', $member['mode']) : '';
     $member['keyword'] = $member['company'];
     $member['homepage'] = isset($member['homepage']) ? fix_link($member['homepage']) : '';
     $member['capital'] = isset($member['capital']) ? dround($member['capital']) : '';
     $member['sound'] = intval($member['sound']);
     if ($this->userid) {
         $member['keyword'] = $member['company'] . strip_tags(area_pos($member['areaid'], ',')) . ',' . $member['business'] . ',' . $member['sell'] . ',' . $member['buy'] . ',' . $member['mode'];
         clear_upload($member['thumb'] . $member['introduce'], $this->userid);
         $new = $member['introduce'];
         if ($member['thumb']) {
             $new .= '<img src="' . $member['thumb'] . '">';
         }
         $content_table = content_table(4, $this->userid, is_file(DT_CACHE . '/4.part'), $this->table_company_data);
         $r = $this->db->get_one("SELECT content FROM {$content_table} WHERE userid={$this->userid}");
         $old = $r['content'];
         $r = $this->get_one();
         if ($r['thumb']) {
             $old .= '<img src="' . $r['thumb'] . '">';
         }
         delete_diff($new, $old);
     } else {
         if ($member['thumb']) {
             clear_upload($member['thumb'] . $member['introduce']);
         }
     }
     $member['content'] = $member['introduce'];
     $member['introduce'] = addslashes(get_intro($member['content'], $MOD['introduce_length']));
     if (!defined('DT_ADMIN')) {
         $content = $member['content'];
         unset($member['content']);
         $member = dhtmlspecialchars($member);
         $member['content'] = dsafe($content);
     }
     if ($MOD['introduce_clear'] || $MOD['introduce_save']) {
         $member['content'] = stripslashes($member['content']);
         $member['content'] = save_local($member['content']);
         if ($MOD['introduce_clear']) {
             $member['content'] = clear_link($member['content']);
         }
         if ($MOD['introduce_save']) {
             $member['content'] = save_remote($member['content']);
         }
         $member['content'] = addslashes($member['content']);
     }
     if ($member['catid']) {
         $catids = explode(',', substr($member['catid'], 1, -1));
         $cids = '';
         foreach ($catids as $catid) {
             $C = get_cat($catid);
             if ($C) {
                 $catid = $C['parentid'] ? $C['arrparentid'] . ',' . $catid : $catid;
                 $cids .= $catid . ',';
             }
         }
         $cids = array_unique(explode(',', substr(str_replace(',0,', ',', ',' . $cids), 1, -1)));
         $member['catids'] = ',' . implode(',', $cids) . ',';
     }
     return $member;
 }
Ejemplo n.º 11
0
 function check_mysql_table_structure()
 {
     global $DB;
     $strError = '';
     if ($this->arTestVars['table_charset_fail']) {
         return $this->Result(null, GetMessage('SC_TABLE_COLLATION_NA'));
     }
     $module = '';
     $cnt = $i = 0;
     if ($dir = opendir($path = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules')) {
         while (false !== ($item = readdir($dir))) {
             if ($item == '.' || $item == '..') {
                 continue;
             }
             $cnt++;
             if ($this->arTestVars['last_value']) {
                 $i++;
                 if ($this->arTestVars['last_value'] == $item) {
                     unset($this->arTestVars['last_value']);
                 }
             } elseif (!$module) {
                 $module = $item;
             }
         }
         closedir($dir);
     } else {
         return false;
     }
     $file = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $module . '/install/db/mysql/install.sql';
     if (!file_exists($file)) {
         $file = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $module . '/install/mysql/install.sql';
     }
     if (file_exists($file)) {
         $rs = $DB->Query('SELECT * FROM b_module WHERE id="' . $DB->ForSQL($module) . '"');
         if ($rs->Fetch()) {
             if (!($query = file_get_contents($file))) {
                 return false;
             }
             $arTables = array();
             $arQuery = $DB->ParseSQLBatch(str_replace("\r", "", $query));
             foreach ($arQuery as $sql) {
                 if (preg_match('#^(CREATE TABLE )(IF NOT EXISTS)? ?`?([a-z0-9_]+)`?(.*);?$#mis', $sql, $regs)) {
                     $table = $regs[3];
                     if (preg_match('#^site_checker_#', $table)) {
                         continue;
                     }
                     $arTables[$table] = $sql;
                     $tmp_table = 'site_checker_' . $table;
                     $DB->Query('DROP TABLE IF EXISTS `' . $tmp_table . '`');
                     $DB->Query($regs[1] . ' `' . $tmp_table . '`' . $regs[4]);
                 } elseif (preg_match('#^(ALTER TABLE)( )?`?([a-z0-9_]+)`?(.*);?$#mis', $sql, $regs)) {
                     $table = $regs[3];
                     $tmp_table = 'site_checker_' . $table;
                     $DB->Query($regs[1] . ' `' . $tmp_table . '`' . $regs[4]);
                 }
             }
             foreach ($arTables as $table => $sql) {
                 $rs = $DB->Query('SHOW TABLES LIKE "' . $table . '"');
                 if (!$rs->Fetch()) {
                     if ($this->fix_mode) {
                         if (!$DB->Query($sql)) {
                             return $this->Result(false, 'Mysql Query Error: ' . $sql . ' [' . $DB->db_Error . ']');
                         }
                     } else {
                         $strError .= GetMessage('SC_ERR_NO_TABLE', array('#TABLE#' => $table)) . "<br>\n";
                         $this->arTestVars['iError']++;
                         $this->arTestVars['iErrorAutoFix']++;
                         $this->arTestVars['cntNoTables']++;
                     }
                     continue;
                 }
                 $tmp_table = 'site_checker_' . $table;
                 $arColumns = array();
                 $rs = $DB->Query('SHOW COLUMNS FROM `' . $table . '`');
                 while ($f = $rs->Fetch()) {
                     $arColumns[$f['Field']] = $f;
                 }
                 $rs = $DB->Query('SHOW COLUMNS FROM `' . $tmp_table . '`');
                 while ($f_tmp = $rs->Fetch()) {
                     $tmp = TableFieldConstruct($f_tmp);
                     if ($f = $arColumns[$f_tmp['Field']]) {
                         if (($cur = TableFieldConstruct($f)) != $tmp) {
                             if ($this->fix_mode) {
                                 if (TableFieldCanBeAltered($f, $f_tmp)) {
                                     if (!$DB->Query($sql = 'ALTER TABLE `' . $table . '` MODIFY `' . $f_tmp['Field'] . '` ' . $tmp, true)) {
                                         return $this->Result(false, 'Mysql Query Error: ' . $sql . ' [' . $DB->db_Error . ']');
                                     }
                                 } else {
                                     $this->arTestVars['iErrorFix']++;
                                 }
                             } else {
                                 $strError .= GetMessage('SC_ERR_FIELD_DIFFERS', array('#TABLE#' => $table, '#FIELD#' => $f['Field'], '#CUR#' => $cur, '#NEW#' => $tmp)) . "<br>\n";
                                 $this->arTestVars['iError']++;
                                 if (TableFieldCanBeAltered($f, $f_tmp)) {
                                     $this->arTestVars['iErrorAutoFix']++;
                                 }
                                 $this->arTestVars['cntDiffFields']++;
                             }
                         }
                     } else {
                         if ($this->fix_mode) {
                             if (!$DB->Query($sql = 'ALTER TABLE `' . $table . '` ADD `' . $f_tmp['Field'] . '` ' . $tmp, true)) {
                                 return $this->Result(false, 'Mysql Query Error: ' . $sql . ' [' . $DB->db_Error . ']');
                             }
                         } else {
                             $strError .= GetMessage('SC_ERR_NO_FIELD', array('#TABLE#' => $table, '#FIELD#' => $f_tmp['Field'])) . "<br>\n";
                             $this->arTestVars['iError']++;
                             $this->arTestVars['iErrorAutoFix']++;
                             $this->arTestVars['cntNoFields']++;
                         }
                     }
                 }
                 $arIndexes = array();
                 $rs = $DB->Query('SHOW INDEXES FROM `' . $table . '`');
                 while ($f = $rs->Fetch()) {
                     $ix =& $arIndexes[$f['Key_name']];
                     $column = $f['Column_name'] . ($f['Sub_part'] ? '(' . $f['Sub_part'] . ')' : '');
                     if ($ix) {
                         $ix .= ',' . $column;
                     } else {
                         $ix = $column;
                     }
                 }
                 $arIndexes_tmp = array();
                 $rs = $DB->Query('SHOW INDEXES FROM `' . $tmp_table . '`');
                 while ($f = $rs->Fetch()) {
                     $ix =& $arIndexes_tmp[$f['Key_name']];
                     $column = $f['Column_name'] . ($f['Sub_part'] ? '(' . $f['Sub_part'] . ')' : '');
                     if ($ix) {
                         $ix .= ',' . $column;
                     } else {
                         $ix = $column;
                     }
                 }
                 unset($ix);
                 // unlink the reference
                 foreach ($arIndexes_tmp as $name => $ix) {
                     if (!in_array($ix, $arIndexes)) {
                         if ($this->fix_mode) {
                             while ($arIndexes[$name]) {
                                 $name .= '_sc';
                             }
                             if (!$DB->Query($sql = 'CREATE INDEX `' . $name . '` ON `' . $table . '` (' . $ix . ')', true)) {
                                 return $this->Result(false, 'Mysql Query Error: ' . $sql . ' [' . $DB->db_Error . ']');
                             }
                         } else {
                             $strError .= GetMessage('SC_ERR_NO_INDEX', array('#TABLE#' => $table, '#INDEX#' => $name . ' (' . $ix . ')')) . "<br>\n";
                             $this->arTestVars['iError']++;
                             $this->arTestVars['iErrorAutoFix']++;
                             $this->arTestVars['cntNoIndexes']++;
                         }
                     }
                 }
                 $DB->Query('DROP TABLE `' . $tmp_table . '`');
             }
             echo $strError;
             // to log
         }
     }
     if ($i < $cnt) {
         $this->arTestVars['last_value'] = $module;
         $this->test_percent = floor($i / $cnt * 100);
         return true;
     }
     if ($this->fix_mode) {
         if ($this->arTestVars['iErrorFix'] > 0) {
             return $this->Result(null, GetMessage('SC_CHECK_TABLES_STRUCT_ERRORS_FIX', array('#VAL#' => intval($this->arTestVars['iErrorFix']))));
         }
         return true;
     } else {
         if ($this->arTestVars['iError'] > 0) {
             return $this->Result(false, GetMessage('SC_CHECK_TABLES_STRUCT_ERRORS', array('#VAL#' => intval($this->arTestVars['iError']), '#VAL1#' => intval($this->arTestVars['iErrorAutoFix']), '#NO_TABLES#' => intval($this->arTestVars['cntNoTables']), '#NO_FIELDS#' => intval($this->arTestVars['cntNoFields']), '#DIFF_FIELDS#' => intval($this->arTestVars['cntDiffFields']), '#NO_INDEXES#' => intval($this->arTestVars['cntNoIndexes']))) . ($this->arTestVars['iErrorAutoFix'] > 0 ? fix_link(3) : ''));
         }
         return true;
     }
 }