Exemplo n.º 1
0
 public function save_editable_region()
 {
     // fix for 2.7.4 eip
     if (cmsController::getInstance()->getCurrentMode() != 'admin') {
         return self::old_eip_save_editable_region();
     }
     $iEntityId = getRequest('param0');
     $sPropName = getRequest('param1');
     $content = getRequest('data');
     $bIsObject = (bool) getRequest('is_object');
     if (is_array($content) && count($content) == 1) {
         $content = $content[0];
     } else {
         if (is_array($content) && isset($content[0])) {
             $temp = array();
             foreach ($content as $item) {
                 $temp[] = is_array($item) ? $item[0] : $item;
             }
             $content = $temp;
         }
     }
     $oEntity = $bIsObject ? umiObjectsCollection::getInstance()->getObject($iEntityId) : umiHierarchy::getInstance()->getElement($iEntityId);
     // Checking rights
     $bDisallowed = false;
     $permissions = permissionsCollection::getInstance();
     $userId = $permissions->getUserId();
     if (!$permissions->isSv($userId)) {
         if ($bIsObject) {
             $bDisallowed = !($oEntity->getOwnerId() == $userId);
             if ($bDisallowed) {
                 //Check module permissions
                 $object = selector::get('object')->id($iEntityId);
                 $module = $object->getModule();
                 $method = $object->getMethod();
                 if ($module && $method) {
                     $bDisallowed = !$permissions->isAllowedMethod($userId, $module, $method);
                 }
             }
         } else {
             list($r, $w) = $permissions->isAllowedObject($userId, $iEntityId);
             if (!$w) {
                 $bDisallowed = true;
             }
         }
     }
     if ($bDisallowed) {
         throw new publicAdminException(getLabel('error-no-permissions'));
     }
     $event = new umiEventPoint("systemModifyPropertyValue");
     $event->addRef("entity", $oEntity);
     $event->setParam("property", $sPropName);
     $event->addRef("newValue", $content);
     $event->setMode("before");
     try {
         $event->call();
     } catch (wrongValueException $e) {
         throw new publicAdminException($e->getMessage());
     }
     if ($oEntity instanceof iUmiHierarchyElement) {
         $backupModel = backupModel::getInstance();
         $backupModel->addLogMessage($oEntity->getId());
     }
     if ($bIsObject && !$this->checkAllowedColumn($oEntity, $sPropName)) {
         throw new publicAdminException(getLabel('error-no-permissions'));
     }
     if ($bIsObject && $sPropName == 'is_activated') {
         $guestId = $permissions->getGuestId();
         if ($iEntityId == SV_USER_ID) {
             throw new publicAdminException(getLabel('error-users-swtich-activity-sv'));
         }
         if ($iEntityId == $guestId) {
             throw new publicAdminException(getLabel('error-users-swtich-activity-guest'));
         }
         if ($iEntityId == $userId) {
             throw new publicAdminException(getLabel('error-users-swtich-activity-self'));
         }
     }
     $sPropValue = "";
     if ($oEntity) {
         $bOldVal = umiObjectProperty::$IGNORE_FILTER_INPUT_STRING;
         umiObjectProperty::$IGNORE_FILTER_INPUT_STRING = true;
         $oObject = !$bIsObject ? $oEntity->getObject() : $oEntity;
         $oldValue = null;
         try {
             if ($sPropName == 'name') {
                 if (is_string($content) && strlen($content)) {
                     $oldValue = $oEntity->name;
                     $oEntity->name = $content;
                     if ($oEntity instanceof iUmiHierarchyElement) {
                         $oEntity->h1 = $content;
                     }
                 }
                 $result = array('name' => $content);
             } else {
                 $property = $oObject->getPropByName($sPropName);
                 if ($property->getDataType() == 'date') {
                     $date = new umiDate();
                     $date->setDateByString($content);
                     $content = $date;
                 }
                 $oldValue = $oEntity->getValue($sPropName);
                 $oEntity->setValue($sPropName, $content);
                 if ($oEntity instanceof iUmiHierarchyElement && $sPropName == 'h1') {
                     $oEntity->name = $content;
                 }
                 $result = array('property' => $property);
                 translatorWrapper::get($property);
                 umiObjectPropertyWrapper::$showEmptyFields = true;
             }
         } catch (fieldRestrictionException $e) {
             throw new publicAdminException($e->getMessage());
         }
         $oEntity->commit();
         umiObjectProperty::$IGNORE_FILTER_INPUT_STRING = $bOldVal;
         $oObject->update();
         $oEntity->update();
         if ($oEntity instanceof umiEntinty) {
             $oEntity->commit();
         }
         $event->setParam("oldValue", $oldValue);
         $event->setParam("newValue", $content);
         $event->setMode("after");
         $event->call();
         $this->setData($result);
         return $this->doData();
     }
 }
Exemplo n.º 2
0
 public function reserve($reserve = true)
 {
     if ($this->is_reserved == $reserve) {
         return false;
     }
     $primaryStore = $this->getPrimaryStore();
     if (!$primaryStore) {
         return false;
     }
     foreach ($this->getItems() as $item) {
         if ($element = $item->getItemElement()) {
             $amount = $item->getAmount();
             $storesState = $element->getValue('stores_state', array('filter' => array('rel' => $primaryStore->id)));
             if (sizeof($storesState)) {
                 $total = $storesState[0];
                 $total = (int) getArrayKey($total, 'int');
             } else {
                 $total = 0;
             }
             $reserved = (int) $element->reserved + $amount * ($reserve ? 1 : -1);
             $element->reserved = $reserved > 0 ? $reserved > $total ? $total : $reserved : 0;
             $oldFilter = umiObjectProperty::$IGNORE_FILTER_INPUT_STRING;
             umiObjectProperty::$IGNORE_FILTER_INPUT_STRING = true;
             $element->commit();
             umiObjectProperty::$IGNORE_FILTER_INPUT_STRING = $oldFilter;
         }
     }
     $this->is_reserved = $reserve;
     $this->commit();
     return true;
 }
Exemplo n.º 3
0
 public function execute()
 {
     $va59fd5768bddc123092dddd6413dff0e = cmsController::$IGNORE_MICROCACHE;
     $v2b419278ae6ec25f1deac5b2319d2f2c = umiObjectProperty::$IGNORE_FILTER_INPUT_STRING;
     cmsController::$IGNORE_MICROCACHE = true;
     umiObjectProperty::$IGNORE_FILTER_INPUT_STRING = true;
     $v2245023265ae4cf87d02c8b6ba991139 = mainConfiguration::getInstance();
     if (!$v2245023265ae4cf87d02c8b6ba991139->get('kernel', 'import-auto-index')) {
         if (!defined('DISABLE_SEARCH_REINDEX')) {
             define('DISABLE_SEARCH_REINDEX', 1);
         }
     }
     $v62b7dedcccf830f9a5e3a602bbd23deb = umiObjectProperty::$USE_FORCE_OBJECTS_CREATION;
     if ($this->auto_guide_creation) {
         umiObjectProperty::$USE_FORCE_OBJECTS_CREATION = true;
     } else {
         umiObjectProperty::$USE_FORCE_OBJECTS_CREATION = false;
     }
     $this->parser = new DOMXPath($this->doc);
     $v1a13105b7e4eb5fb2e7c9515ac06aa48 = $this->parser->evaluate("/umidump/@version");
     $v2af72f100c356273d46284f6fd1dfc08 = $v1a13105b7e4eb5fb2e7c9515ac06aa48->length ? $v1a13105b7e4eb5fb2e7c9515ac06aa48->item(0)->nodeValue : "";
     if ($v2af72f100c356273d46284f6fd1dfc08 != self::VERSION) {
         throw new publicException($this->getLabel("label-unknown-umidump-version"));
     }
     $this->parseMetaData();
     $this->source_id = $this->relations->getSourceId($this->meta['source-name']);
     if (!$this->source_id) {
         $this->source_id = $this->relations->addNewSource($this->meta['source-name']);
     }
     $this->importRegistry();
     $this->importDirs();
     if ($this->filesSource) {
         $this->importFiles();
     }
     $this->importLangs();
     $this->importDomains();
     $this->importTemplates();
     $this->importDataTypes();
     $this->importTypes();
     $this->importObjects();
     $this->importElements();
     $this->importRelations();
     $this->importOptions();
     $this->importRestrictions();
     $this->setDefaultPermissions();
     $this->importPermissions();
     $this->importHierarchy();
     umiObjectProperty::$USE_FORCE_OBJECTS_CREATION = $v62b7dedcccf830f9a5e3a602bbd23deb;
     cmsController::$IGNORE_MICROCACHE = $va59fd5768bddc123092dddd6413dff0e;
     umiObjectProperty::$IGNORE_FILTER_INPUT_STRING = $v2b419278ae6ec25f1deac5b2319d2f2c;
 }
Exemplo n.º 4
0
 protected static function saveFieldValue($name, $value, $target, $save = false)
 {
     $hierarchy = umiHierarchy::getInstance();
     if ($i = strpos($name, '[')) {
         if (preg_match_all("/\\[([^\\[^\\]]+)\\]/", substr($name, $i), $out)) {
             $optionParams = array('filter' => array(), 'field-type' => null);
             foreach ($out[1] as $param) {
                 if (strpos($param, ':')) {
                     list($seekType, $seekValue) = explode(':', $param);
                     $optionParams['filter'][$seekType] = $seekValue;
                 } else {
                     $optionParams['field-type'] = $param;
                 }
             }
         }
         $name = substr($name, 0, $i);
     } else {
         $optionParams = null;
     }
     if ($name != 'name' && $name != 'alt_name') {
         $object = $target instanceof iUmiHierarchyElement ? $target->getObject() : $target;
         $property = $object->getPropByName($name);
         if ($property instanceof iUmiObjectProperty == false) {
             throw new publicException(getLabel('eip-no-field') . ": \"{$name}\"");
         }
         $field = $property->getField();
     }
     if ($name == 'name' || $name == 'alt_name') {
         $type = 'string';
     } else {
         $type = $field->getDataType();
     }
     if (is_string($value)) {
         $value = __editor_content::filterStringValue($value);
     }
     $oldLink = null;
     $newLink = null;
     if ($save) {
         umiObjectProperty::$IGNORE_FILTER_INPUT_STRING = true;
         if ($name == 'h1' || $name == 'name') {
             $value = strip_tags($value);
             $value = str_replace(array(' ', '&'), array(' ', '&'), $value);
             if ($name === 'name') {
                 // При изменении name: если name==h1, name=h1=new_value
                 // При изменении name: если name!=h1, name=new_value.
                 if ($target->getName() === (string) $target->getValue('h1')) {
                     $target->setValue('h1', $value);
                 }
                 $target->setName($value);
             } else {
                 // При изменении h1: если h1 == name && name=='', name=h1=new_value
                 // При изменении h1: если h1 == name и name != '', h1=new_value
                 // При изменении h1: если h1 != name, h1=new_value
                 if ($target->getName() === (string) $target->getValue('h1') && $target->getName() === '') {
                     $target->setName($value);
                 }
                 $target->setValue('h1', $value);
             }
             if ($target instanceof iUmiHierarchyElement) {
                 $oldLink = $hierarchy->getPathById($target->id);
                 $altName = $target->getAltName();
                 if (!$altName || substr($altName, 0, 1) == '_') {
                     $target->setAltName($value);
                     $target->commit();
                 }
                 $newLink = $hierarchy->getPathById($target->id, false, false, true);
             }
         } elseif ($name == 'alt_name') {
             if ($target instanceof iUmiHierarchyElement) {
                 $target->setAltName($value);
                 $target->commit();
                 $newLink = $hierarchy->getPathById($target->id, false, false, true);
             }
         } else {
             if ($type == 'date') {
                 $date = new umiDate();
                 $date->setDateByString($value);
                 $value = $date;
                 unset($date);
                 $value = $value->getFormattedDate('U');
             }
             if ($type == 'optioned') {
                 $seekType = getArrayKey($optionParams, 'field-type');
                 $filter = getArrayKey($optionParams, 'filter');
                 $oldValue = $target->getValue($name);
                 foreach ($oldValue as $i => $v) {
                     foreach ($filter as $t => $s) {
                         if (getArrayKey($v, $t) != $s) {
                             continue 2;
                         }
                         $oldValue[$i][$seekType] = $value;
                     }
                 }
                 $value = $oldValue;
                 unset($oldValue);
             }
             if ($type == 'symlink') {
                 $value = $value;
             }
             if ($type == 'wysiwyg') {
                 $out = array();
                 if (preg_match_all("/href=[\"']?([^ ^\"^']+)[\"']?/i", $value, $out)) {
                     foreach ($out[1] as $link) {
                         $id = $hierarchy->getIdByPath($link);
                         if ($id) {
                             $link = str_replace("/", "\\/", $link);
                             $value = preg_replace("/(href=[\"']?)" . $link . "([\"']?)/i", "\\1%content get_page_url({$id})%\\2", $value);
                         }
                     }
                 }
             } else {
                 $value = str_replace(array(' ', '&'), array(' ', '&'), $value);
             }
             if (in_array($type, array('text', 'string', 'int', 'float', 'price', 'date', 'tags', 'counter'))) {
                 $value = preg_replace("/<br ?\\/?>/i", "\n", $value);
                 $value = strip_tags($value);
             }
             if (in_array($type, array('img_file', 'swf_file', 'file', 'video_file')) && $value) {
                 if (substr($value, 0, 1) != '.') {
                     $value = '.' . $value;
                 }
             }
             $target->setValue($name, $value);
         }
         $target->commit();
         umiObjectProperty::$IGNORE_FILTER_INPUT_STRING = false;
         if ($target instanceof iUmiHierarchyElement) {
             $backup = backupModel::getInstance();
             $backup->fakeBackup($target->id);
         }
         $oEventPoint = new umiEventPoint("eipSave");
         $oEventPoint->setMode("after");
         $oEventPoint->setParam("field_name", $name);
         $oEventPoint->setParam("obj", $target);
         def_module::setEventPoint($oEventPoint);
     }
     if ($name == 'name') {
         $value = $target->getName();
     } else {
         $value = $target->getValue($name, $optionParams);
     }
     if ($save) {
         $value = xmlTranslator::executeMacroses($value);
     }
     if ($type == 'date') {
         if ($value) {
             $date = new umiDate();
             $date->setDateByString($value);
             $value = $date->getFormattedDate('Y-m-d H:i');
         } else {
             $value = '';
         }
     }
     if ($type == 'tags' && is_array($value)) {
         $value = implode(', ', $value);
     }
     if ($type == 'optioned' && !is_null($optionParams)) {
         $value = isset($value[0]) ? $value[0] : '';
         $type = getArrayKey($optionParams, 'field-type');
     }
     $result = array('attribute:name' => $name, 'attribute:type' => $type);
     if ($type == 'relation') {
         $items_arr = array();
         if ($value) {
             if (!is_array($value)) {
                 $value = array($value);
             }
             $objects = umiObjectsCollection::getInstance();
             foreach ($value as $objectId) {
                 $object = $objects->getObject($objectId);
                 $items_arr[] = $object;
             }
         }
         $result['attribute:guide-id'] = $field->getGuideId();
         if ($field->getFieldType()->getIsMultiple()) {
             $result['attribute:multiple'] = 'multiple';
         }
         $type = selector::get('object-type')->id($field->getGuideId());
         if ($type && $type->getIsPublic()) {
             $result['attribute:public'] = 'public';
         }
         $result['nodes:item'] = $items_arr;
     } else {
         if ($type == 'symlink') {
             $result['nodes:page'] = is_array($value) ? $value : array();
         } else {
             $result['node:value'] = $value;
         }
     }
     if ($oldLink != $newLink) {
         $result['attribute:old-link'] = $oldLink;
         $result['attribute:new-link'] = $newLink;
     }
     return $result;
 }