Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
update lib resource.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukianenko Dmytro authored and Lukianenko Dmytro committed Nov 2, 2015
1 parent 400396b commit e578b03
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions assets/libs/resourse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php
/**
version: 0.4.2.1
- fix edit document
version: 0.4.2
Author:
Expand Down Expand Up @@ -191,6 +196,7 @@ public function clearLog(){
}

public function set($key,$value){
$value = str_replace("'", "\'", $value );
if(is_scalar($value) && is_scalar($key) && !empty($key)){
switch($key){
case 'template': {
Expand Down Expand Up @@ -392,7 +398,7 @@ public function toArray(){
return $this->field;
}

private function checkAlias($alias){
private function checkAlias($alias, $i=1){
if($this->modx->config['friendly_urls']){
$flag = false;
$_alias = $this->modx->db->escape($alias);
Expand All @@ -402,14 +408,14 @@ private function checkAlias($alias){
$flag = $this->modx->db->getValue($this->modx->db->select('id', $this->_table['site_content'], "alias='{$_alias}'", '', 1));
}
if(($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)){
$suffix = substr($alias, -2);
/*$suffix = substr($alias, -2);
if(preg_match('/-(\d+)/',$suffix,$tmp) && isset($tmp[1]) && (int)$tmp[1]>1){
$suffix = (int)$tmp[1] + 1;
$alias = substr($alias, 0, -2) . '-'. $suffix;
}else{
$alias .= '-2';
}
$alias = $this->checkAlias($alias);
}*/
$alias = $this->checkAlias($alias.'-'.$i,$i+1);
}
}
return $alias;
Expand Down Expand Up @@ -452,21 +458,25 @@ public function save($fire_events = null,$clearCache = false){
if($this->newDoc) $this->id = $this->modx->db->getInsertId();

foreach($fld as $key=>$value){
if ($value=='') continue;
#if ($value=='') continue;
if ($this->tv[$key]!=''){
$fields = array(
'tmplvarid' => $this->tv[$key],
'contentid' => $this->id,
'value' => $this->modx->db->escape($value),
);

$rs = $this->modx->db->select('value', $this->_table['site_tmplvar_contentvalues'], "contentid = '{$fields['contentid']}' AND tmplvarid = '{$fields['tmplvarid']}'");
if ($row = $this->modx->db->getRow($rs)) {

if ( $this->modx->db->getRecordCount($rs) > 0 ) {
$row = $this->modx->db->getRow($rs);
if ($row['value'] != $value) {
$this->modx->db->update($fields, $this->_table['site_tmplvar_contentvalues'], "contentid = '{$fields['contentid']}' AND tmplvarid = '{$fields['tmplvarid']}'");
}
}else{
$this->modx->db->insert($fields, $this->_table['site_tmplvar_contentvalues']);
}

}
}
$this->invokeEvent('OnDocFormSave',array (
Expand Down

0 comments on commit e578b03

Please sign in to comment.