diff --git a/Classes/Base/Collection.class.php b/Classes/Base/Collection.class.php index 5ef44b6..96adc8b 100644 --- a/Classes/Base/Collection.class.php +++ b/Classes/Base/Collection.class.php @@ -57,7 +57,7 @@ public function pop() public function unshift($item) { - \array_unshift($this->list); + \array_unshift($this->list, $item); $this->updateCount(); } diff --git a/Classes/Base/Object.class.php b/Classes/Base/Entity.class.php similarity index 94% rename from Classes/Base/Object.class.php rename to Classes/Base/Entity.class.php index e9121a5..93ab8c4 100644 --- a/Classes/Base/Object.class.php +++ b/Classes/Base/Entity.class.php @@ -1,60 +1,60 @@ -data = $data; - } - - public function __get($name) - { - if (isset($this->data[strtoupper($name)])) - { - return $this->data[strtoupper($name)]; - } - - $trace = debug_backtrace(); - trigger_error( - 'Undefined property in __get(): ' . $name . - ' in file ' . $trace[0]['file'] . - ' line ' . $trace[0]['line'], E_USER_NOTICE - ); - } - - public function unescape($name) - { - return html_entity_decode($this->{$name}); - } - - public function escape($name) - { - return $this->escaped($name); - } - - public function escaped($name) - { - return htmlspecialchars($this->{$name}); - } - - public function getData() - { - return $this->data; - } +data = $data; + } + + public function __get($name) + { + if (isset($this->data[strtoupper($name)])) + { + return $this->data[strtoupper($name)]; + } + + $trace = debug_backtrace(); + trigger_error( + 'Undefined property in __get(): ' . $name . + ' in file ' . $trace[0]['file'] . + ' line ' . $trace[0]['line'], E_USER_NOTICE + ); + } + + public function unescape($name) + { + return html_entity_decode($this->{$name}); + } + + public function escape($name) + { + return $this->escaped($name); + } + + public function escaped($name) + { + return htmlspecialchars($this->{$name}); + } + + public function getData() + { + return $this->data; + } } \ No newline at end of file diff --git a/Classes/Base/Getter.class.php b/Classes/Base/Getter.class.php index ace5799..78f9f65 100644 --- a/Classes/Base/Getter.class.php +++ b/Classes/Base/Getter.class.php @@ -183,7 +183,7 @@ public function get() {} /** - * @return \Cpeople\Classes\Base\Object|\Cpeople\Classes\Block\Object|\Cpeople\Classes\Section\Object|\Cpeople\Classes\Catalog\Object + * @return \Cpeople\Classes\Base\Entity|\Cpeople\Classes\Block\Entity|\Cpeople\Classes\Section\Entity */ public function getOne() { @@ -192,7 +192,7 @@ public function getOne() } /** - * @return \Cpeople\Classes\Base\Object|\Cpeople\Classes\Block\Object|\Cpeople\Classes\Section\Object|\Cpeople\Classes\Catalog\Object + * @return \Cpeople\Classes\Base\Entity|\Cpeople\Classes\Block\Entity|\Cpeople\Classes\Section\Entity */ public function getById($id) { @@ -205,7 +205,7 @@ public function getArrayById($id) } /** - * @return \Cpeople\Classes\Base\Object|\Cpeople\Classes\Block\Object|\Cpeople\Classes\Section\Object|\Cpeople\Classes\Catalog\Object + * @return \Cpeople\Classes\Base\Entity|\Cpeople\Classes\Block\Entity|\Cpeople\Classes\Section\Entity */ public function getByCode($code, $iblockId = null) { diff --git a/Classes/Block/Object.class.php b/Classes/Block/Entity.class.php similarity index 94% rename from Classes/Block/Object.class.php rename to Classes/Block/Entity.class.php index c9b440c..71925d7 100644 --- a/Classes/Block/Object.class.php +++ b/Classes/Block/Entity.class.php @@ -1,519 +1,519 @@ -data['IBLOCK_SECTION_ID']; - } - - public function hasProp($propName) - { - return !empty($this->data[$propName]) && is_array($this->data[$propName]); - } - - public function getProp($propName) - { - if (!$this->hasProp($propName)) - { - throw new \Exception("Property $propName is not set for object with ID " . $this->id); - } - - return $this->data[$propName]; - } - - public function propEmpty($propName) - { - return _empty($this->getPropValue($propName)); - } - - public function getPropValue($propName) - { - $prop = $this->getProp($propName); - - return $prop['VALUE']; - } - - public function getPropDescription($propName) - { - $prop = $this->getProp($propName); - - return $prop['DESCRIPTION']; - } - - public function getPropEnumId($propName) - { - $prop = $this->getProp($propName); - - return $prop['VALUE_ENUM_ID']; - } - - public function getPropRawValue($propName) - { - $prop = $this->getProp($propName); - - return $prop['~VALUE']; - } - - public function getPropRawText($propName) - { - $value = $this->getPropRawValue($propName); - - if (is_array($value) && isset($value['TEXT'])) - { - $value = $value['TEXT']; - } - - return $value; - } - - public function getPropText($propName) - { - $value = $this->getPropValue($propName); - - if (is_array($value) && isset($value['TEXT'])) - { - $value = html_entity_decode($value['TEXT']); - } - - return $value; - } - - public function getPropXMLValue($propName) - { - $prop = $this->getProp($propName); - return $prop['VALUE_XML_ID']; - } - - protected final function getImageId($key) - { - if ($this->hasProp($key)) - { - $retval = $this->getPropValue($key); - } - else - { - $retval = $this->data[$key]; - } - - return $retval; - } - - public final function hasImage($key) - { - return (bool) $this->getImageId($key); - } - - public final function hasFile($key) - { - return $this->hasImage($key); - } - - /** - * @return \Cpeople\Classes\Block\File[] - */ - public final function getFiles($key) - { - $prop = $this->getProp($key); - - $retval = false; - - if (!empty($prop['VALUE'])) - { - if (is_array($prop['VALUE'])) - { - for ($i = 0, $c = count($prop['VALUE']); $i < $c; $i++) - { - $file = File::fromId($prop['VALUE'][$i]); - $file->setName($prop['DESCRIPTION'][$i]); - - $retval[] = $file; - } - } - else - { - $file = File::fromId($prop['VALUE']); - $file->setName($prop['DESCRIPTION']); - - $retval[] = $file; - } - } - - return $retval; - } - - /** - * @return \Cpeople\Classes\Block\Image[] - */ - public final function getImages($key) - { - $prop = $this->getProp($key); - $retval = false; - - if (!empty($prop['VALUE'])) - { - for ($i = 0, $c = count($prop['VALUE']); $i < $c; $i++) - { - $image = Image::fromId($prop['VALUE'][$i]); - $image->setName($prop['DESCRIPTION'][$i]); - - $retval[] = $image; - } - } - - return $retval; - } - - public final function getImageUrl($key) - { - if (!$this->hasImage($key)) - { - throw new \Exception(__CLASS__ . ' with ID ' . $this->id . ' does not have image ' . $key); - } - - if (empty($this->imagesSrc[$key])) - { - if ($file = \CFile::GetByID($this->getImageId($key))->GetNext()) - { - $this->imagesSrc[$key] = \CFile::GetFileSRC($file); - } - } - - return $this->imagesSrc[$key]; - } - - public final function getFile($key) - { - if (!$this->hasImage($key)) - { - throw new \Exception(__CLASS__ . ' with ID ' . $this->id . ' does not have image ' . $key); - } - - $retval = File::fromId($this->getImageId($key)); - return $retval; - } - - public function getImageThumb($key, $options) - { - return call_user_func($this->thumbFunc, $this->getImageUrl($key), $options); - } - - public function getImageCaption($key) - { - $prop = $this->getProp($key); - return $prop['DESCRIPTION']; - } - - public function hasDetailImage() - { - return $this->hasImage('DETAIL_PICTURE'); - } - - public function getDetailImageUrl() - { - return $this->getImageUrl('DETAIL_PICTURE'); - } - - public function getDetailImageThumb($options) - { - return $this->getImageThumb('DETAIL_PICTURE', $options); - } - - public function hasPreviewImage() - { - return $this->hasImage('PREVIEW_PICTURE'); - } - - public function getPreivewImageUrl() - { - return $this->getImageUrl('PREVIEW_PICTURE'); - } - - public function getPreviewImageThumb($options) - { - return $this->getImageThumb('PREVIEW_PICTURE', $options); - } - - public function isDateActive() - { - return $this->getTimestamp('ACTIVE_FROM') < time() && $this->getTimestamp('ACTIVE_TO') > time(); - } - - public function getTimestamp($key) - { - return strtotime($this->data[$key]); - } - - protected function getDate($key, $format) - { - if(is_array($this->data[$key])) - { - return FormatDate($format, strtotime($this->data[$key]['VALUE'])); - } - else - { - return FormatDate($format, strtotime($this->data[$key])); - } - } - - public function getActiveFromDate($format) - { - return $this->getDate('ACTIVE_FROM', $format); - } - - public function getActiveToDate($format) - { - return $this->getDate('ACTIVE_TO', $format); - } - - public function getUrl() - { - return $this->detail_page_url; - } - - /** - * @param $key - * @return \Cpeople\Classes\Block\Getter - */ - public function getRelatedGetter($key) - { - $prop = $this->getProp($key); - - $retval = false; - - if (!empty_array($prop['VALUE']) || !empty($prop['VALUE'])) - { - $retval = Getter::instance()->setFilter(array( - 'ID' => $prop['VALUE'], -// 'IBLOCK_ID' => $prop['LINK_IBLOCK_ID'] - )); - } - - return $retval; - } - - public function getRelated($key, $filter = array(), $order = array('SORT' => 'asc')) - { - $retval = false; - - if ($getter = $this->getRelatedGetter($key)) - { - $getter->setOrder($order)->setHydrationMode($getter::HYDRATION_MODE_OBJECTS_ARRAY); - - if (!empty_array($filter)) - { - $getter->addFilter($filter); - } - - $retval = $getter->get(); - } - - return $retval; - } - - // get price array - public function getBasePriceArray() - { - if (!class_exists('\CPrice')) - { - \CModule::IncludeModule('catalog'); - } - - return \CPrice::GetBasePrice($this->id); - } - - // get price in default currency - public function getBasePriceRawValue() - { - if (!$price = $this->getBasePriceArray()) - { - throw new \Exception(__CLASS__ . ' with ID ' . $this->id . ' does not have price'); - } - - return $price['PRICE']; - } - - // get price in selected currency - public function getBasePriceValue() - { - return $this->getBasePriceRawValue(); - } - - public function getBasePrice($currencyId = 'RUB') - { - \CModule::IncludeModule('catalog'); - - return \FormatCurrency($this->getBasePriceRawValue(), $currencyId); - } - - public function setBasePrice($price, $currencyId = 'RUB') - { - if (!class_exists('\CPrice')) - { - \CModule::IncludeModule('catalog'); - } - - return \CPrice::SetBasePrice($this->id, $price, $currencyId); - } - - /** - * @return \Cpeople\Classes\Section\Object - */ - public function getParentSection() - { - return \Cpeople\Classes\Section\Getter::instance()->getById($this->iblock_section_id); - } - - public function toArray() - { - return $this->data; - } - - public function saveField($field, $value) - { - $this->update(array($field => $value)); - } - - public function saveProp($prop, $value) - { - $element = new \CIBlockElement; - $element->SetPropertyValuesEx($this->id, false, array($prop => $value)); - } - - public function update($values) - { - $element = new \CIBlockElement; - - if(!$id = $element->Update($this->id, $values)) - { - throw new \Exception("Can't update element: ".$element->LAST_ERROR); - } - - return $this; - } - - public function add($values) - { - $element = new \CIBlockElement; - - if (!$id = $element->Add($values)) - { - throw new \Exception("Can't add element: " . $element->LAST_ERROR); - } - - $this->setVal('id', $id); - return $this; - } - - public function setVal($name, $val) - { - $this->data[strtoupper($name)] = $val; - return $this; - } - - public function hasVal($name) - { - return isset($this->data[strtoupper($name)]); - } - - public function save() - { - if (!$this->IBLOCK_ID) - { - throw new \Exception('IBLOCK_ID is not set'); - } - - $blockFields = \Cpeople\Classes\Infoblock\Getter::instance()->getById($this->IBLOCK_ID)->getFields(); - $blockProperties = \Cpeople\Classes\Infoblock\Getter::instance()->getById($this->IBLOCK_ID)->getProperties(); - - $arFields = $arProps = array(); - - foreach ($this->data as $key => $value) - { - if (array_key_exists($key, $blockFields)) - { - $arFields[$key] = $value; - } - else if (array_key_exists($key, $blockProperties)) - { - if (is_array($value) && isset($value['VALUE'])) - { - $value = $value['VALUE']; - } - - switch($blockProperties[$key]->property_type) - { - case 'S': - - $arProps[$key] = ($blockProperties[$key]->user_type == 'HTML') - ? array('VALUE' => array('TEXT' => $value, "TYPE" => (strip_tags($value) == $value ? 'TEXT' : 'HTML'))) - : $value; - - break; - - default: - - $arProps[$key] = $value; - - break; - } - } - } - - if ($this->id) - { - $this->update($arFields); - } - else - { - $this->add($arFields); - } - - if (intval($this->id)) - { - \CIBlockElement::SetPropertyValuesEx($this->id, $this->IBLOCK_ID, $arProps); - } - - return $this; - } - - function appendImage($path, $key) - { - $this->data[$key] = \CFile::MakeFileArray($path); - $this->save(); - } - - /** - * @return \Cpeople\Classes\Infoblock\Object|Object - */ - function getInfoblock() - { - if (!isset($this->infoblock)) - { - $this->infoblock = \Cpeople\Classes\Infoblock\Getter::instance()->getById($this->iblock_id); - } - - return $this->infoblock; - } - - function getPropertyOptions($key) - { - return $this->getInfoblock()->getProperty($key)->getOptions(); - } - - function getPropertyXMLId($key) - { - - } -} +data['IBLOCK_SECTION_ID']; + } + + public function hasProp($propName) + { + return !empty($this->data[$propName]) && is_array($this->data[$propName]); + } + + public function getProp($propName) + { + if (!$this->hasProp($propName)) + { + throw new \Exception("Property $propName is not set for object with ID " . $this->id); + } + + return $this->data[$propName]; + } + + public function propEmpty($propName) + { + return _empty($this->getPropValue($propName)); + } + + public function getPropValue($propName) + { + $prop = $this->getProp($propName); + + return $prop['VALUE']; + } + + public function getPropDescription($propName) + { + $prop = $this->getProp($propName); + + return $prop['DESCRIPTION']; + } + + public function getPropEnumId($propName) + { + $prop = $this->getProp($propName); + + return $prop['VALUE_ENUM_ID']; + } + + public function getPropRawValue($propName) + { + $prop = $this->getProp($propName); + + return $prop['~VALUE']; + } + + public function getPropRawText($propName) + { + $value = $this->getPropRawValue($propName); + + if (is_array($value) && isset($value['TEXT'])) + { + $value = $value['TEXT']; + } + + return $value; + } + + public function getPropText($propName) + { + $value = $this->getPropValue($propName); + + if (is_array($value) && isset($value['TEXT'])) + { + $value = html_entity_decode($value['TEXT']); + } + + return $value; + } + + public function getPropXMLValue($propName) + { + $prop = $this->getProp($propName); + return $prop['VALUE_XML_ID']; + } + + protected final function getImageId($key) + { + if ($this->hasProp($key)) + { + $retval = $this->getPropValue($key); + } + else + { + $retval = $this->data[$key]; + } + + return $retval; + } + + public final function hasImage($key) + { + return (bool) $this->getImageId($key); + } + + public final function hasFile($key) + { + return $this->hasImage($key); + } + + /** + * @return \Cpeople\Classes\Block\File[] + */ + public final function getFiles($key) + { + $prop = $this->getProp($key); + + $retval = false; + + if (!empty($prop['VALUE'])) + { + if (is_array($prop['VALUE'])) + { + for ($i = 0, $c = count($prop['VALUE']); $i < $c; $i++) + { + $file = File::fromId($prop['VALUE'][$i]); + $file->setName($prop['DESCRIPTION'][$i]); + + $retval[] = $file; + } + } + else + { + $file = File::fromId($prop['VALUE']); + $file->setName($prop['DESCRIPTION']); + + $retval[] = $file; + } + } + + return $retval; + } + + /** + * @return \Cpeople\Classes\Block\Image[] + */ + public final function getImages($key) + { + $prop = $this->getProp($key); + $retval = false; + + if (!empty($prop['VALUE'])) + { + for ($i = 0, $c = count($prop['VALUE']); $i < $c; $i++) + { + $image = Image::fromId($prop['VALUE'][$i]); + $image->setName($prop['DESCRIPTION'][$i]); + + $retval[] = $image; + } + } + + return $retval; + } + + public final function getImageUrl($key) + { + if (!$this->hasImage($key)) + { + throw new \Exception(__CLASS__ . ' with ID ' . $this->id . ' does not have image ' . $key); + } + + if (empty($this->imagesSrc[$key])) + { + if ($file = \CFile::GetByID($this->getImageId($key))->GetNext()) + { + $this->imagesSrc[$key] = \CFile::GetFileSRC($file); + } + } + + return $this->imagesSrc[$key]; + } + + public final function getFile($key) + { + if (!$this->hasImage($key)) + { + throw new \Exception(__CLASS__ . ' with ID ' . $this->id . ' does not have image ' . $key); + } + + $retval = File::fromId($this->getImageId($key)); + return $retval; + } + + public function getImageThumb($key, $options) + { + return call_user_func($this->thumbFunc, $this->getImageUrl($key), $options); + } + + public function getImageCaption($key) + { + $prop = $this->getProp($key); + return $prop['DESCRIPTION']; + } + + public function hasDetailImage() + { + return $this->hasImage('DETAIL_PICTURE'); + } + + public function getDetailImageUrl() + { + return $this->getImageUrl('DETAIL_PICTURE'); + } + + public function getDetailImageThumb($options) + { + return $this->getImageThumb('DETAIL_PICTURE', $options); + } + + public function hasPreviewImage() + { + return $this->hasImage('PREVIEW_PICTURE'); + } + + public function getPreivewImageUrl() + { + return $this->getImageUrl('PREVIEW_PICTURE'); + } + + public function getPreviewImageThumb($options) + { + return $this->getImageThumb('PREVIEW_PICTURE', $options); + } + + public function isDateActive() + { + return $this->getTimestamp('ACTIVE_FROM') < time() && $this->getTimestamp('ACTIVE_TO') > time(); + } + + public function getTimestamp($key) + { + return strtotime($this->data[$key]); + } + + protected function getDate($key, $format) + { + if(is_array($this->data[$key])) + { + return FormatDate($format, strtotime($this->data[$key]['VALUE'])); + } + else + { + return FormatDate($format, strtotime($this->data[$key])); + } + } + + public function getActiveFromDate($format) + { + return $this->getDate('ACTIVE_FROM', $format); + } + + public function getActiveToDate($format) + { + return $this->getDate('ACTIVE_TO', $format); + } + + public function getUrl() + { + return $this->detail_page_url; + } + + /** + * @param $key + * @return \Cpeople\Classes\Block\Getter + */ + public function getRelatedGetter($key) + { + $prop = $this->getProp($key); + + $retval = false; + + if (!empty_array($prop['VALUE']) || !empty($prop['VALUE'])) + { + $retval = Getter::instance()->setFilter(array( + 'ID' => $prop['VALUE'], +// 'IBLOCK_ID' => $prop['LINK_IBLOCK_ID'] + )); + } + + return $retval; + } + + public function getRelated($key, $filter = array(), $order = array('SORT' => 'asc')) + { + $retval = false; + + if ($getter = $this->getRelatedGetter($key)) + { + $getter->setOrder($order)->setHydrationMode($getter::HYDRATION_MODE_OBJECTS_ARRAY); + + if (!empty_array($filter)) + { + $getter->addFilter($filter); + } + + $retval = $getter->get(); + } + + return $retval; + } + + // get price array + public function getBasePriceArray() + { + if (!class_exists('\CPrice')) + { + \CModule::IncludeModule('catalog'); + } + + return \CPrice::GetBasePrice($this->id); + } + + // get price in default currency + public function getBasePriceRawValue() + { + if (!$price = $this->getBasePriceArray()) + { + throw new \Exception(__CLASS__ . ' with ID ' . $this->id . ' does not have price'); + } + + return $price['PRICE']; + } + + // get price in selected currency + public function getBasePriceValue() + { + return $this->getBasePriceRawValue(); + } + + public function getBasePrice($currencyId = 'RUB') + { + \CModule::IncludeModule('catalog'); + + return \FormatCurrency($this->getBasePriceRawValue(), $currencyId); + } + + public function setBasePrice($price, $currencyId = 'RUB') + { + if (!class_exists('\CPrice')) + { + \CModule::IncludeModule('catalog'); + } + + return \CPrice::SetBasePrice($this->id, $price, $currencyId); + } + + /** + * @return \Cpeople\Classes\Section\Entity + */ + public function getParentSection() + { + return \Cpeople\Classes\Section\Getter::instance()->getById($this->iblock_section_id); + } + + public function toArray() + { + return $this->data; + } + + public function saveField($field, $value) + { + $this->update(array($field => $value)); + } + + public function saveProp($prop, $value) + { + $element = new \CIBlockElement; + $element->SetPropertyValuesEx($this->id, false, array($prop => $value)); + } + + public function update($values) + { + $element = new \CIBlockElement; + + if(!$id = $element->Update($this->id, $values)) + { + throw new \Exception("Can't update element: ".$element->LAST_ERROR); + } + + return $this; + } + + public function add($values) + { + $element = new \CIBlockElement; + + if (!$id = $element->Add($values)) + { + throw new \Exception("Can't add element: " . $element->LAST_ERROR); + } + + $this->setVal('id', $id); + return $this; + } + + public function setVal($name, $val) + { + $this->data[strtoupper($name)] = $val; + return $this; + } + + public function hasVal($name) + { + return isset($this->data[strtoupper($name)]); + } + + public function save() + { + if (!$this->IBLOCK_ID) + { + throw new \Exception('IBLOCK_ID is not set'); + } + + $blockFields = \Cpeople\Classes\Infoblock\Getter::instance()->getById($this->IBLOCK_ID)->getFields(); + $blockProperties = \Cpeople\Classes\Infoblock\Getter::instance()->getById($this->IBLOCK_ID)->getProperties(); + + $arFields = $arProps = array(); + + foreach ($this->data as $key => $value) + { + if (array_key_exists($key, $blockFields)) + { + $arFields[$key] = $value; + } + else if (array_key_exists($key, $blockProperties)) + { + if (is_array($value) && isset($value['VALUE'])) + { + $value = $value['VALUE']; + } + + switch($blockProperties[$key]->property_type) + { + case 'S': + + $arProps[$key] = ($blockProperties[$key]->user_type == 'HTML') + ? array('VALUE' => array('TEXT' => $value, "TYPE" => (strip_tags($value) == $value ? 'TEXT' : 'HTML'))) + : $value; + + break; + + default: + + $arProps[$key] = $value; + + break; + } + } + } + + if ($this->id) + { + $this->update($arFields); + } + else + { + $this->add($arFields); + } + + if (intval($this->id)) + { + \CIBlockElement::SetPropertyValuesEx($this->id, $this->IBLOCK_ID, $arProps); + } + + return $this; + } + + function appendImage($path, $key) + { + $this->data[$key] = \CFile::MakeFileArray($path); + $this->save(); + } + + /** + * @return \Cpeople\Classes\Infoblock\Entity|Object + */ + function getInfoblock() + { + if (!isset($this->infoblock)) + { + $this->infoblock = \Cpeople\Classes\Infoblock\Getter::instance()->getById($this->iblock_id); + } + + return $this->infoblock; + } + + function getPropertyOptions($key) + { + return $this->getInfoblock()->getProperty($key)->getOptions(); + } + + function getPropertyXMLId($key) + { + + } +} diff --git a/Classes/Block/File.class.php b/Classes/Block/File.class.php index 0309279..2619a83 100644 --- a/Classes/Block/File.class.php +++ b/Classes/Block/File.class.php @@ -89,4 +89,22 @@ public function getId() { return $this->data['ID']; } + + + public function getOriginalName($withType = false) + { + if ($withType) + { + return $this->data['ORIGINAL_NAME']; + } + else + { + return str_ireplace('.' . $this->getExtension(), '', $this->data['ORIGINAL_NAME']); + } + } + + public function getProperty($propertyName) + { + return (!empty($propertyName)) ? $this->data[$propertyName] : false; + } } diff --git a/Classes/Block/Getter.class.php b/Classes/Block/Getter.class.php index 75c7fdb..498989e 100644 --- a/Classes/Block/Getter.class.php +++ b/Classes/Block/Getter.class.php @@ -7,7 +7,7 @@ class Getter extends \Cpeople\Classes\Base\Getter protected $arGroupBy = null; protected $arNavStartParams = null; protected $arSelectFields = null; - protected $className = '\Cpeople\Classes\Block\Object'; + protected $className = \Cpeople\Classes\Block\Entity::class; protected $total; @@ -123,7 +123,7 @@ public function getResult() } /** - * @return \Cpeople\Classes\Block\Object[] + * @return \Cpeople\Classes\Block\Entity[] */ public function get() { @@ -199,7 +199,7 @@ public function get() } /** - * @return \Cpeople\Classes\Block\Object + * @return \Cpeople\Classes\Block\Entity */ public function getByCode($code, $iblockId = null) { diff --git a/Classes/Cache/EngineFiles.class.php b/Classes/Cache/EngineFiles.class.php index 6920712..46c8bb0 100644 --- a/Classes/Cache/EngineFiles.class.php +++ b/Classes/Cache/EngineFiles.class.php @@ -30,6 +30,11 @@ private function getFileName($cacheId) return $this->path . DIRECTORY_SEPARATOR . substr($md5, 0, 2) . DIRECTORY_SEPARATOR . $md5 . '.txt'; } + public function setTTL($ttl) + { + $this->ttl = (int) $ttl; + } + public function valid($cacheId, $ttl = null) { $retval = true; diff --git a/Classes/Cache/EngineMemcached.class.php b/Classes/Cache/EngineMemcached.class.php index d7ae69b..c052026 100644 --- a/Classes/Cache/EngineMemcached.class.php +++ b/Classes/Cache/EngineMemcached.class.php @@ -21,7 +21,7 @@ class EngineMemcached implements Engine public function __construct($options = null) { - if (!function_exists('memcache_connect')) + if (!function_exists('memcache_pconnect')) { throw new CacheException("Memcached module is not installed"); } @@ -33,11 +33,12 @@ private function connect($options) { if (!isset(self::$cache)) { - $options = $options || array(); + if (empty($options)) $options = array(); + if (empty($options['host'])) $options['host'] = 'localhost'; - if (empty($options['port'])) $options['port'] = 11211; + if (!isset($options['port'])) $options['port'] = 11211; - if (!self::$cache = memcache_connect($options['host'], $options['port'])) + if (!self::$cache = memcache_pconnect($options['host'], $options['port'])) { throw new CacheException("Could not connect to memcached server on {$options['host']}:{$options['port']}"); } diff --git a/Classes/Catalog/Cart.class.php b/Classes/Catalog/Cart.class.php index 704d133..90f96e5 100644 --- a/Classes/Catalog/Cart.class.php +++ b/Classes/Catalog/Cart.class.php @@ -10,7 +10,7 @@ class Cart { - protected $itemClass = '\Cpeople\Classes\Catalog\CartItem'; + protected $itemClass = \Cpeople\Classes\Catalog\CartItem::class; protected $itemsRaw; protected $items; protected $tainted = true; @@ -167,8 +167,6 @@ public function getItems($orderId = null) { $className = $this->itemClass; - $result = array(); - \CModule::IncludeModule('sale'); $arFilter = $orderId ? array('ORDER_ID' => $orderId) : array("FUSER_ID" => \CSaleBasket::GetBasketUserID(), 'ORDER_ID' => null); @@ -181,6 +179,8 @@ public function getItems($orderId = null) array() ); + $this->itemsRaw = $this->items = []; + while ($item = $dbBasketItems->Fetch()) { $this->itemsRaw[] = $item; diff --git a/Classes/Catalog/CartItem.class.php b/Classes/Catalog/CartItem.class.php index b9f6a9f..5c08129 100644 --- a/Classes/Catalog/CartItem.class.php +++ b/Classes/Catalog/CartItem.class.php @@ -13,7 +13,7 @@ class CartItem implements \ArrayAccess { protected $container; - protected $productClassName = '\Cpeople\Classes\Catalog\Product'; + protected $productClassName = \Cpeople\Classes\Catalog\Product::class; /** * @var \Cpeople\Classes\Catalog\Cart @@ -21,7 +21,7 @@ class CartItem implements \ArrayAccess protected $cart; /** - * @var \Cpeople\Classes\Block\Object + * @var \Cpeople\Classes\Block\Entity */ protected $product; diff --git a/Classes/Catalog/Offer.class.php b/Classes/Catalog/Offer.class.php index d0fff9e..d1dbf9d 100644 --- a/Classes/Catalog/Offer.class.php +++ b/Classes/Catalog/Offer.class.php @@ -7,7 +7,7 @@ namespace Cpeople\Classes\Catalog; -class Offer extends \Cpeople\Classes\Block\Object +class Offer extends \Cpeople\Classes\Block\Entity { } diff --git a/Classes/Catalog/Order.class.php b/Classes/Catalog/Order.class.php index 21a49dc..792ce85 100644 --- a/Classes/Catalog/Order.class.php +++ b/Classes/Catalog/Order.class.php @@ -35,7 +35,8 @@ public function __construct($id) elseif($id) { $this->id = $id; - $this->container = \CSaleOrder::GetByID($id); + $cAllSaleOrder = new \CAllSaleOrder(); + $this->container = $cAllSaleOrder->GetByID($id); } } @@ -71,7 +72,7 @@ public function __get($key) if (!isset($this->container[$key])) { - throw new Exception('Object ' . get_class($this) . ' does not have property ' . $key); + throw new \Exception('Object ' . get_class($this) . ' does not have property ' . $key); } return $this->container[$key]; @@ -115,9 +116,11 @@ public function setPayed($value) { $value = (bool) $value ? 'Y' : 'N'; + $cSaleOrder = new \CSaleOrder(); + if ($value == 'Y') { - \CSaleOrder::PayOrder($this['ID'], 'Y'); + $cSaleOrder->PayOrder($this['ID'], 'Y'); } else { @@ -127,7 +130,7 @@ public function setPayed($value) 'USER_ID' => $this['USER_ID'], ); - return \CSaleOrder::Update($this['ID'], $data); + return $cSaleOrder->Update($this['ID'], $data); } } @@ -138,7 +141,7 @@ public function getStatusString() public static function getOrders($userId) { - if(!\CModule::IncludeModule("sale")) throw new Exception("can't load sale module"); + if(!\CModule::IncludeModule("sale")) throw new \Exception("can't load sale module"); $orders = self::getOrdersList($userId); diff --git a/Classes/Catalog/Product.class.php b/Classes/Catalog/Product.class.php index a871799..446f8bb 100644 --- a/Classes/Catalog/Product.class.php +++ b/Classes/Catalog/Product.class.php @@ -7,7 +7,7 @@ namespace Cpeople\Classes\Catalog; -class Product extends \Cpeople\Classes\Block\Object +class Product extends \Cpeople\Classes\Block\Entity { private $price = null; diff --git a/Classes/Forms/Commands/BitrixEmailCommand.class.php b/Classes/Forms/Commands/BitrixEmailCommand.class.php index 24c94f7..659ad0f 100644 --- a/Classes/Forms/Commands/BitrixEmailCommand.class.php +++ b/Classes/Forms/Commands/BitrixEmailCommand.class.php @@ -35,9 +35,11 @@ public function execute(Form $form) { $sendData = $form->getData(); + $submitArray = []; + if($this->fieldsUppercase) { - $submitArray = array_change_key_case($sendData, CASE_UPPER); + $submitArray = array_change_key_case($sendData, CASE_UPPER); } $result = \CEvent::Send($this->emailEvent, $this->siteId, $submitArray); diff --git a/Classes/Forms/Commands/PopFilesPropUrlCommand.class.php b/Classes/Forms/Commands/PopFilesPropUrlCommand.class.php new file mode 100644 index 0000000..82826f2 --- /dev/null +++ b/Classes/Forms/Commands/PopFilesPropUrlCommand.class.php @@ -0,0 +1,64 @@ +form = $form; + + $extraData = $this->popFilesPropUrl(); + foreach($extraData as $key => $val) { + $form->setDataItem($key, $val); + } + } + + public function __construct($isCritical, $iBlockId, $siteUrl) + { + parent::__construct($isCritical); + + $this->iBlockId = $iBlockId; + $this->siteUrl = $siteUrl; + } + + public function popFilesPropUrl() + { + $data = $this->form->getData(); + $elemId = $data['ID']; + if(!$elemId) throw new \Exception('element id not set'); + + $elem = \Cpeople\Classes\Block\Getter::instance() + ->setFilter(array('IBLOCK_ID' => $this->iBlockId)) + ->getById($elemId); + + $extraData = array(); + foreach (cp_get_ib_properties($this->iBlockId) as $key => $property) + { + if ($property['PROPERTY_TYPE'] == 'F' && ($filesId = $elem->getPropValue($key))) + { + if(!is_array($filesId)) $filesId = array($filesId); + + foreach($filesId as $fileId) { + try { + $file = \Cpeople\Classes\Block\File::fromId($fileId); + $extraData[$key . '_URL'][] = $this->siteUrl . $file->getUrl(); + } catch (\Exception $e) { + } + } + } + } + + return $extraData; + } +} \ No newline at end of file diff --git a/Classes/Infoblock/Object.class.php b/Classes/Infoblock/Entity.class.php similarity index 93% rename from Classes/Infoblock/Object.class.php rename to Classes/Infoblock/Entity.class.php index 618d01c..9c4d997 100644 --- a/Classes/Infoblock/Object.class.php +++ b/Classes/Infoblock/Entity.class.php @@ -1,78 +1,78 @@ -properties)) - { - $this->properties = array(); - - $rs = \CIBlockProperty::GetList(array('sort' => 'asc'), array('IBLOCK_ID' => $this->id)); - - while($ar = $rs->Fetch()) - { - $this->properties[$ar['CODE']] = new Property($ar); - } - } - - return $this->properties; - } - - public function getProperty($key) - { - $this->getProperties(); - - if (!array_key_exists($key, $this->properties)) - { - throw new \Exception("Infoblock $this->id does not have property $key"); - } - - return $this->properties[$key]; - } - - public function getFields() - { - if (!isset($this->fields)) - { - $this->fields = array(); - - $res = \CIBlock::GetFields($this->id); - - foreach ($res as $k => $element) - { - $this->fields[$k] = new Field($k, $element); - } - - foreach (self::$standardFields as $field) - { - if (!array_key_exists($field, $this->fields)) - { - $this->fields[$field] = array('CODE' => $field); - } - } - } - - return $this->fields; - } - - public function addProperty($propData) - { - $ibp = new \CIBlockProperty; - return (bool) $ibp->Add($propData); - } -} +properties)) + { + $this->properties = array(); + + $rs = \CIBlockProperty::GetList(array('sort' => 'asc'), array('IBLOCK_ID' => $this->id)); + + while($ar = $rs->Fetch()) + { + $this->properties[$ar['CODE']] = new Property($ar); + } + } + + return $this->properties; + } + + public function getProperty($key) + { + $this->getProperties(); + + if (!array_key_exists($key, $this->properties)) + { + throw new \Exception("Infoblock $this->id does not have property $key"); + } + + return $this->properties[$key]; + } + + public function getFields() + { + if (!isset($this->fields)) + { + $this->fields = array(); + + $res = \CIBlock::GetFields($this->id); + + foreach ($res as $k => $element) + { + $this->fields[$k] = new Field($k, $element); + } + + foreach (self::$standardFields as $field) + { + if (!array_key_exists($field, $this->fields)) + { + $this->fields[$field] = array('CODE' => $field); + } + } + } + + return $this->fields; + } + + public function addProperty($propData) + { + $ibp = new \CIBlockProperty; + return (bool) $ibp->Add($propData); + } +} diff --git a/Classes/Infoblock/Getter.class.php b/Classes/Infoblock/Getter.class.php index fb59d27..e6cf80c 100644 --- a/Classes/Infoblock/Getter.class.php +++ b/Classes/Infoblock/Getter.class.php @@ -4,7 +4,7 @@ class Getter extends \Cpeople\Classes\Base\Getter { - protected $className = '\Cpeople\Classes\Infoblock\Object'; + protected $className = \Cpeople\Classes\Infoblock\Entity::class; protected $total; diff --git a/Classes/Infoblock/Property.class.php b/Classes/Infoblock/Property.class.php index 5d9c9ed..d115bf0 100644 --- a/Classes/Infoblock/Property.class.php +++ b/Classes/Infoblock/Property.class.php @@ -2,7 +2,7 @@ namespace Cpeople\Classes\Infoblock; -class Property extends \Cpeople\Classes\Base\Object +class Property extends \Cpeople\Classes\Base\Entity { protected $data; protected $options; diff --git a/Classes/MultilangDummy.class.php b/Classes/MultilangDummy.class.php index dae2f99..38d0e73 100644 --- a/Classes/MultilangDummy.class.php +++ b/Classes/MultilangDummy.class.php @@ -2,7 +2,7 @@ namespace Cpeople\Classes; -class MultilangDummy extends Block\Object +class MultilangDummy extends Block\Entity { use \Cpeople\Traits\MultilangFields; diff --git a/Classes/Search/Engine.class.php b/Classes/Search/Engine.class.php index 92cbf64..db2eb37 100644 --- a/Classes/Search/Engine.class.php +++ b/Classes/Search/Engine.class.php @@ -11,8 +11,8 @@ class Engine { - protected $defaultClassName = '\Cpeople\Classes\Search\Result'; - protected $className = '\Cpeople\Classes\Search\Result'; + protected $defaultClassName = \Cpeople\Classes\Search\Result::class; + protected $className = \Cpeople\Classes\Search\Result::class; protected $modulesList = array(); protected $tryInvertedLayout = false; protected $tryYandexSpeller = false; @@ -40,6 +40,8 @@ public function makeSearch($query = null, $offset = null, $limit = null) { $retval = $this->search($query, $offset, $limit); + $invertedQuery = ''; + if(empty($retval) && $this->tryInvertedLayout) { $invertedQuery = $this->makeInvertedLayout($query); diff --git a/Classes/Search/Result.class.php b/Classes/Search/Result.class.php index ecefbe3..691c98e 100644 --- a/Classes/Search/Result.class.php +++ b/Classes/Search/Result.class.php @@ -108,7 +108,7 @@ public function getBodyHighlighted($keywords = null, $wordsAround = 5, $tag = '< } /** - * @return \Cpeople\Classes\Block\Object|\Cpeople\Classes\Section\Object + * @return \Cpeople\Classes\Block\Entity|\Cpeople\Classes\Section\Entity */ public function getElement() { diff --git a/Classes/Section/Object.class.php b/Classes/Section/Entity.class.php similarity index 93% rename from Classes/Section/Object.class.php rename to Classes/Section/Entity.class.php index b94a139..4be1ab2 100644 --- a/Classes/Section/Object.class.php +++ b/Classes/Section/Entity.class.php @@ -1,170 +1,170 @@ -data[strtoupper($name)])) - { - return $this->data[strtoupper($name)]; - } - - $trace = debug_backtrace(); - trigger_error( - 'Undefined property in __get(): ' . $name . - ' in file ' . $trace[0]['file'] . - ' line ' . $trace[0]['line'], - E_USER_NOTICE - ); - } - - public function hasProp($propName) - { - return !empty($this->data[$propName]) && is_array($this->data[$propName]); - } - - private function getImageId($key) - { - $retval = false; - - $key = strtoupper($key); - - if ($this->hasProp($key)) - { - $retval = $this->getPropValue($key); - } - else - { - $retval = $this->data[$key]; - } - - return $retval; - } - - public function hasImage($key) - { - return (bool) $this->getImageId($key); - } - - public function getImageUrl($key) - { - if (!$this->hasImage($key)) - { - throw new \Exception(__CLASS__ . ' with ID ' . $this->id . ' does not have image ' . $key); - } - - if (empty($this->imagesSrc[$key])) - { - if ($file = \CFile::GetByID($this->getImageId($key))->GetNext()) - { - $this->imagesSrc[$key] = \CFile::GetFileSRC($file); - } - } - - return $this->imagesSrc[$key]; - } - - public function getImageThumb($key, $options) - { - return call_user_func($this->thumbFunc, $this->getImageUrl($key), $options); - } - - public function getImageCaption($key) - { - $prop = $this->getProp($key); - return $prop['DESCRIPTION']; - } - - public function hasDetailImage() - { - return $this->hasImage('DETAIL_PICTURE'); - } - - public function getDetailImageUrl() - { - return $this->getImageUrl('DETAIL_PICTURE'); - } - - public function getDetailImageThumb($options) - { - return $this->getImageThumb('DETAIL_PICTURE', $options); - } - - public function hasPreviewImage() - { - return $this->hasImage('PICTURE'); - } - - public function getPreivewImageUrl() - { - return $this->getImageUrl('PICTURE'); - } - - public function getPreviewImageThumb($options) - { - return $this->getImageThumb('PICTURE', $options); - } - - private function getDate($key, $format) - { - return russian_date($format, strtotime($this->data[$key])); - } - - public function getUrl() - { - return $this->section_page_url; - } - - public function getElementsCount() - { - return $this->data['ELEMENT_CNT']; - } - - public function getDepth() - { - return isset($this->data['DEPTH_LEVEL']) ? $this->data['DEPTH_LEVEL'] : 0; - } - - public function getSectionPath() - { - return \GetIBlockSectionPath($this->iblock_id, $this->id); - } - - public function getPath() - { - $retval = array(); - $className = get_class($this); - $res = \GetIBlockSectionPath($this->iblock_id, $this->id); - - while($row = $res->Fetch()) - { - $retval[] = new $className($row); - } - - return $retval; - } - - public function getLangPropValue($key) - { - $dataKey = strtoupper($key . '_' . LANGUAGE_ID); - return isset($this->data[$dataKey]) ? $this->data[$dataKey] : null; - } - - public function hasParentSection() - { - return $this->iblock_section_id; - } - - /** - * @return \Cpeople\Classes\Section\Object - */ - public function getParentSection() - { - return \Cpeople\Classes\Section\Getter::instance()->getById($this->iblock_section_id); - } -} +data[strtoupper($name)])) + { + return $this->data[strtoupper($name)]; + } + + $trace = debug_backtrace(); + trigger_error( + 'Undefined property in __get(): ' . $name . + ' in file ' . $trace[0]['file'] . + ' line ' . $trace[0]['line'], + E_USER_NOTICE + ); + } + + public function hasProp($propName) + { + return !empty($this->data[$propName]) && is_array($this->data[$propName]); + } + + private function getImageId($key) + { + $retval = false; + + $key = strtoupper($key); + + if ($this->hasProp($key)) + { + $retval = $this->getPropValue($key); + } + else + { + $retval = $this->data[$key]; + } + + return $retval; + } + + public function hasImage($key) + { + return (bool) $this->getImageId($key); + } + + public function getImageUrl($key) + { + if (!$this->hasImage($key)) + { + throw new \Exception(__CLASS__ . ' with ID ' . $this->id . ' does not have image ' . $key); + } + + if (empty($this->imagesSrc[$key])) + { + if ($file = \CFile::GetByID($this->getImageId($key))->GetNext()) + { + $this->imagesSrc[$key] = \CFile::GetFileSRC($file); + } + } + + return $this->imagesSrc[$key]; + } + + public function getImageThumb($key, $options) + { + return call_user_func($this->thumbFunc, $this->getImageUrl($key), $options); + } + + public function getImageCaption($key) + { + $prop = $this->getProp($key); + return $prop['DESCRIPTION']; + } + + public function hasDetailImage() + { + return $this->hasImage('DETAIL_PICTURE'); + } + + public function getDetailImageUrl() + { + return $this->getImageUrl('DETAIL_PICTURE'); + } + + public function getDetailImageThumb($options) + { + return $this->getImageThumb('DETAIL_PICTURE', $options); + } + + public function hasPreviewImage() + { + return $this->hasImage('PICTURE'); + } + + public function getPreivewImageUrl() + { + return $this->getImageUrl('PICTURE'); + } + + public function getPreviewImageThumb($options) + { + return $this->getImageThumb('PICTURE', $options); + } + + private function getDate($key, $format) + { + return russian_date($format, strtotime($this->data[$key])); + } + + public function getUrl() + { + return $this->section_page_url; + } + + public function getElementsCount() + { + return $this->data['ELEMENT_CNT']; + } + + public function getDepth() + { + return isset($this->data['DEPTH_LEVEL']) ? $this->data['DEPTH_LEVEL'] : 0; + } + + public function getSectionPath() + { + return \GetIBlockSectionPath($this->iblock_id, $this->id); + } + + public function getPath() + { + $retval = array(); + $className = get_class($this); + $res = \GetIBlockSectionPath($this->iblock_id, $this->id); + + while($row = $res->Fetch()) + { + $retval[] = new $className($row); + } + + return $retval; + } + + public function getLangPropValue($key) + { + $dataKey = strtoupper($key . '_' . LANGUAGE_ID); + return isset($this->data[$dataKey]) ? $this->data[$dataKey] : null; + } + + public function hasParentSection() + { + return $this->iblock_section_id; + } + + /** + * @return \Cpeople\Classes\Section\Entity + */ + public function getParentSection() + { + return \Cpeople\Classes\Section\Getter::instance()->getById($this->iblock_section_id); + } +} diff --git a/Classes/Section/Getter.class.php b/Classes/Section/Getter.class.php index e584f14..f6a957b 100644 --- a/Classes/Section/Getter.class.php +++ b/Classes/Section/Getter.class.php @@ -10,7 +10,9 @@ class Getter extends \Cpeople\Classes\Base\Getter protected $arSelectFields = null; protected $bIncCnt = false; protected $bAddUFToSelect = true; - protected $className = '\Cpeople\Classes\Section\Object'; + protected $className = \Cpeople\Classes\Section\Entity::class; + + protected $total; /** * @static @@ -38,6 +40,37 @@ public function setNavStartParams($arNavStartParams) $this->arNavStartParams = $arNavStartParams; return $this; } + + /** + * @return Getter + */ + public function setPageSize($size) + { + $this->arNavStartParams['nPageSize'] = (int) $size; + return $this; + } + + /** + * @param $pageNum + * @return Getter + */ + public function setPageNum($pageNum) + { + $this->arNavStartParams['iNumPage'] = (int) $pageNum; + return $this; + } + + /** + * @param $pagingSize + * @param $pageNum + * @return Getter + */ + public function paginate($pagingSize, $pageNum) + { + $this->setPageSize($pagingSize); + $this->setPageNum(intval($pageNum) < 1 ? 1 : intval($pageNum)); + return $this; + } /** * @return Getter @@ -77,7 +110,7 @@ public function setAddUFToSelect($bAddUFToSelect) } /** - * @return \Cpeople\Classes\Section\Object[] + * @return \Cpeople\Classes\Section\Entity[] */ public function get() { @@ -139,4 +172,62 @@ public function get() return $retval; } + + public function getFoundRows() + { + $getter = clone $this; + + // в фильтре есть сложная логика, простая группировка не даст нужного + // результата, получаем все элементы и считаем из + if (true || array_key_exists(0, $this->arFilter)) + { + $getter + ->setNavStartParams(array()) + ->setOrder(array()) + ->setFetchMode(self::FETCH_MODE_FIELDS) + ->setHydrationMode(self::HYDRATION_MODE_ARRAY) + ->setSelectFields(array('ID')) + ; + + if ($this->cacheManager) + { + $getter->setCacheManager($this->cacheManager); + } + + $this->total = (int) count($getter->get()); + } + else + { + $res = $getter + ->setNavStartParams(null) + ->setGroupBy(array('IBLOCK_ID')) + ->getResult() + ->Fetch(); + + $this->total = empty($res) ? false : $res['CNT']; + } + + return $this->total; + } + + /** + * @return \paging + */ + public function getPagingObject($urlTemplate, $total = null) + { + if (isset($total)) + { + $this->total = $total; + } + + if (!isset($this->total)) + { + $this->total = $this->getFoundRows(); + } + + $paging = new \Cpeople\paging($this->arNavStartParams['iNumPage'], $this->total, $this->arNavStartParams['nPageSize']); + $paging->setFormat($urlTemplate); + + return $paging; + } } diff --git a/Traits/MultilangFields.trait.php b/Traits/MultilangFields.trait.php index ce5160e..df6932a 100644 --- a/Traits/MultilangFields.trait.php +++ b/Traits/MultilangFields.trait.php @@ -35,7 +35,9 @@ private function fetchSites() { if (!isset($this->sites)) { - $res = \CSite::GetList(); + $by = []; + $order = []; + $res = \CSite::GetList($by, $order); self::$sites = $res->arResult; } } diff --git a/bitrix_lib.php b/bitrix_lib.php index c1f6f67..6c4c3f7 100644 --- a/bitrix_lib.php +++ b/bitrix_lib.php @@ -173,6 +173,18 @@ function cp_generate_thumb($url, $resizedUrl, $options) $IE = new ImageEditorGD(); + $quality = 100; + if (defined('IMAGE_THUMB_QUALITY') && IMAGE_THUMB_QUALITY) { + $quality = IMAGE_THUMB_QUALITY; + } + if (isset($params['q']) && (int)$params['q'] > 0) { + $quality = (int) $params['q']; + } + if (isset($params['quality']) && (int)$params['quality'] > 0) { + $quality = (int)$params['quality']; + } + $IE->setQuality($quality); + $IE->setSource($sourcePath)->setTarget($targetPath); $size = @coalesce($options['size'], $options['width']); @@ -224,6 +236,16 @@ function cp_generate_thumb($url, $resizedUrl, $options) break; } + if(isset($params['b']) && $params['b']) + { + $IE->blurred((int) $params['b']); + } + + if(isset($params['d']) && $params['d']) + { + $IE->decreaseBrightness((int) $params['d']); + } + $IE->commit(); } @@ -452,8 +474,8 @@ function cp_is_standard_field($fieldName) } /** - * Фунцкция принимает список инфоблоков \Cpeople\Classes\Block\Object, - * делает выборку разделов и возвращает список разделов \Cpeople\Classes\Section\Object + * Фунцкция принимает список инфоблоков \Cpeople\Classes\Block\Entity, + * делает выборку разделов и возвращает список разделов \Cpeople\Classes\Section\Entity * с полем elements, содержащим инфорблоки * * @param $iblocks diff --git a/image_resize.php b/image_resize.php index 6838f48..f10a32f 100644 --- a/image_resize.php +++ b/image_resize.php @@ -61,7 +61,7 @@ throw new Exception('Wrong protection code'); } - $excepted_params = array('w', 'h', 't', 'm', 's', 'e', 'b', 'd'); + $excepted_params = array('w', 'h', 't', 'm', 's', 'e', 'b', 'd', 'q'); $params = array(); $temp = explode('-', $path[0]); @@ -133,6 +133,15 @@ $IE = new ImageEditorGD(); + $quality = 100; + if (defined('IMAGE_THUMB_QUALITY') && IMAGE_THUMB_QUALITY) { + $quality = IMAGE_THUMB_QUALITY; + } + if (isset($params['q']) && (int)$params['q'] > 0) { + $quality = (int)$params['q']; + } + $IE->setQuality($quality); + $IE->setSource($source)->setTarget($cache_name); $size = @coalesce($params['s'], $params['w']);