diff --git a/patches/2.0.0/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php b/patches/2.0.0/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php
index cdd0c31..8fb15b4 100644
--- a/patches/2.0.0/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php
+++ b/patches/2.0.0/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php
@@ -1,562 +1,562 @@
-
- */
-
-// no direct access
-defined('_JEXEC') or die('Restricted access');
-
-
-/**
- * Class JBImportHelper
- */
-class JBImportHelper extends AppHelper
-{
- const STEP_SIZE = 20;
-
- const LOSE_NONE = 0;
- const LOSE_DISABLE = 1;
- const LOSE_REMOVE = 2;
-
- const KEY_NONE = 0;
- const KEY_ID = 1;
- const KEY_NAME = 2;
- const KEY_ALIAS = 3;
- const KEY_SKU = 4;
-
- const OPTIONS_NO = 0;
- const OPTIONS_YES = 1;
-
- /**
- * @var JSONData
- */
- protected $_data = null;
-
- /**
- * @param App $app
- */
- public function __construct($app)
- {
- parent::__construct($app);
-
- // make sure the line endings are recognized irrespective of the OS
- $this->app->jbenv->maxPerfomance();
- ini_set('auto_detect_line_endings', true);
- }
-
- /**
- * Get info for pre import step
- * @param string $file
- * @param array $options
- * @return array
- */
- public function getInfo($file, $options)
- {
- $options = $this->app->data->create($options);
-
- $info = array();
-
- // get applications
- $applist = JBModelApp::model()->getList();
- if (!empty($applist)) {
- $info['applist'] = array();
- foreach ($applist as $app) {
- $info['applist'][$app->id] = $app->name;
- }
-
- reset($applist);
- $application = current($applist);
-
- $info['app'] = current($applist);
- }
-
- // get types
- $info['types'] = array();
- foreach ($info['app']->getTypes() as $type) {
- $info['types'][$type->id] = array();
-
- foreach ($type->getElements() as $element) {
- // filter elements
- $info['types'][$type->id][$element->getElementType()][] = $element;
- }
-
- }
-
- $info['item_count'] = 0;
- $info['columns'] = array();
-
- // get params
- $separator = $options->get('separator', ',') ? $options->get('separator', ',') : ',';
- $enclosure = $options->get('enclosure', '"') ? $options->get('enclosure', '"') : '"';
- $containsHeaders = (int)$options->get('header', 1);
-
- // get column names and row count
- $rowCount = 0;
- if (($handle = fopen($file, "r")) !== false) {
-
- while (($data = fgetcsv($handle, 0, $separator, $enclosure)) !== false) {
-
- if ($rowCount == 0) {
- if ($containsHeaders) {
- $info['columns'] = $data;
- } else {
- $info['columns'] = array_fill(0, count($data), '');
- }
- }
-
- $rowCount++;
- }
- fclose($handle);
- }
-
- $info['count'] = $containsHeaders ? $rowCount - 1 : $rowCount;
-
- return $info;
- }
-
- /**
- * @param $info
- * @return array
- */
- public function itemsControls($info)
- {
- $html = array();
- $htmlHelper = $this->app->html;
-
- $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_APP') . ' -'));
- $options += $info['applist'];
- $html['apps'] = $htmlHelper->_('select.genericlist', $options, 'appid');
-
- $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_TYPE') . ' -'));
- $html['types'] = $htmlHelper->_('zoo.typelist', $info['app'], $options, 'typeid', null, 'value', 'text');
-
- $html['fields_types'] = array();
- foreach ($info['types'] as $typeid => $element_types) {
- $html['fields_types'][$typeid] = $this->_createItemsControl($typeid, $element_types);
- }
-
- // lose control
- $loseOptions = array(
- $htmlHelper->_('select.option', self::LOSE_NONE, JText::_('JBZOO_IMPORT_LOSE_NONE')),
- $htmlHelper->_('select.option', self::LOSE_DISABLE, JText::_('JBZOO_IMPORT_LOSE_DISABLE')),
- $htmlHelper->_('select.option', self::LOSE_REMOVE, JText::_('JBZOO_IMPORT_LOSE_REMOVE')),
- );
- $html['lose'] = $htmlHelper->_('select.genericlist', $loseOptions, 'lose');
-
- // what field is key
- $keyOptions = array(
- $htmlHelper->_('select.option', self::KEY_NONE, JText::_('JBZOO_IMPORT_KEY_NONE')),
- $htmlHelper->_('select.option', self::KEY_ID, JText::_('JBZOO_IMPORT_KEY_ID')),
- $htmlHelper->_('select.option', self::KEY_NAME, JText::_('JBZOO_IMPORT_KEY_NAME')),
- $htmlHelper->_('select.option', self::KEY_ALIAS, JText::_('JBZOO_IMPORT_KEY_ALIAS')),
- $htmlHelper->_('select.option', self::KEY_SKU, JText::_('JBZOO_IMPORT_KEY_SKU')),
- );
- $html['key'] = $htmlHelper->_('select.genericlist', $keyOptions, 'key');
-
- // check options config
- $checkOptions = array(
- $htmlHelper->_('select.option', self::OPTIONS_NO, JText::_('JBZOO_IMPORT_CHECK_OPTION_NO')),
- $htmlHelper->_('select.option', self::OPTIONS_YES, JText::_('JBZOO_IMPORT_CHECK_OPTION_YES')),
- );
- $html['checkOptions'] = $htmlHelper->_('select.genericlist', $checkOptions, 'checkOptions');
-
- return $html;
- }
-
- /**
- * @param $info
- * @return array
- */
- public function categoriesControls($info)
- {
- $html = array();
- $htmlHelper = $this->app->html;
-
- $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_APP') . ' -'));
- $options += $info['applist'];
- $html['apps'] = $htmlHelper->_('select.genericlist', $options, 'appid');
-
- $html['fields_types'] = $this->_createCategoriesControl('categoryFileds');
-
- // lose control
- $loseOptions = array(
- $htmlHelper->_('select.option', self::LOSE_NONE, JText::_('JBZOO_IMPORT_LOSE_NONE')),
- $htmlHelper->_('select.option', self::LOSE_DISABLE, JText::_('JBZOO_IMPORT_LOSE_DISABLE')),
- $htmlHelper->_('select.option', self::LOSE_REMOVE, JText::_('JBZOO_IMPORT_LOSE_REMOVE')),
- );
- $html['lose'] = $htmlHelper->_('select.genericlist', $loseOptions, 'lose');
-
- // what field is key
- $keyOptions = array(
- $htmlHelper->_('select.option', self::KEY_NONE, JText::_('JBZOO_IMPORT_KEY_NONE')),
- $htmlHelper->_('select.option', self::KEY_ID, JText::_('JBZOO_IMPORT_KEY_ID')),
- $htmlHelper->_('select.option', self::KEY_NAME, JText::_('JBZOO_IMPORT_KEY_NAME')),
- $htmlHelper->_('select.option', self::KEY_ALIAS, JText::_('JBZOO_IMPORT_KEY_ALIAS')),
- );
- $html['key'] = $htmlHelper->_('select.genericlist', $keyOptions, 'key');
-
- return $html;
- }
-
- /**
- * Create fields control for item
- * @param $typeid
- * @param $elementTypes
- */
- protected function _createItemsControl($typeid, $elementTypes)
- {
- $htmlHelper = $this->app->html;
-
- $fields = $this->app->jbcsvmapper->getItemFields($elementTypes);
- $options = array($htmlHelper->_('select.option', '', ' ** '));
-
- foreach ($fields as $groupKey => $group) {
-
- $options[] = $htmlHelper->_('select.option', '');
- }
-
- return $htmlHelper->_(
- 'select.genericlist',
- $options,
- 'assign[' . $typeid . '][__name_placeholder__]',
- 'class="type-select type-select-' . $typeid . '"'
- );
- }
-
- /**
- * Create fields control for category
- */
- protected function _createCategoriesControl()
- {
- $htmlHelper = $this->app->html;
-
- $fields = $this->app->jbcsvmapper->getCategoryFields();
- $options = array($htmlHelper->_('select.option', '', ' ** '));
-
- foreach ($fields as $groupKey => $group) {
-
- $options[] = $htmlHelper->_('select.option', '');
- }
-
- return $htmlHelper->_('select.genericlist', $options, 'assign[]', 'class="type-select"');
- }
-
- /**
- * @return string
- */
- public function getTmpFilename()
- {
- $tmp = $this->app->path->path('tmp:');
- return JPath::clean($tmp . '/' . uniqid('jbimport_') . '.csv');
- }
-
- /**
- * Get import data from session
- * @return JSONData
- */
- protected function _initSessionData()
- {
- $data = $this->app->jbsession->getGroup('import');
- $this->_data = $this->app->data->create($data);
-
- return $this->_data;
- }
-
- /**
- * Get last line in CSV file
- * @param int $step
- * @return int
- */
- protected function _getLastLine($step = 0)
- {
- $lastLine = self::STEP_SIZE * $step;
- if ((int)$this->_data->header) {
- $lastLine++;
- }
-
- return $lastLine;
- }
-
- /**
- * Get lines from CSV file for current step
- * @param string $file
- * @param int $lastLine
- * @return array
- */
- protected function _getCSVLines($file, $lastLine)
- {
- return $this->app->jbcsv->getLinesfromFile($file, $this->_data, $lastLine, self::STEP_SIZE);
- }
-
- /**
- * Process one Item row
- * @param array $row
- * @param int $lineKey
- * @return int
- */
- protected function _processItemRow($row, $lineKey)
- {
- // create item
- $item = $this->_getItemByKey($row, $lineKey);
-
- $positions = array();
-
- // bind import data from CSV
- foreach ($this->_data->assign as $colKey => $itemField) {
-
- $itemField = JString::trim($itemField);
- if (!empty($itemField)) {
-
- $value = isset($row[$colKey]) ? $row[$colKey] : null;
-
- $fieldInfo = $this->app->jbcsvmapper->itemFieldToMeta($itemField);
-
- $positionKey = implode('__', $fieldInfo);
- if (!isset($positions[$positionKey])) {
- $positions[$positionKey] = 0;
- }
- $positions[$positionKey]++;
-
- $cellElem = $this->app->jbcsvcell->createItem($fieldInfo['name'], $item, $fieldInfo['group'], $fieldInfo);
- $cellElem->fromCSV($value, $positions[$positionKey]);
- }
- }
-
- $id = $item->id;
-
- // save all changes
- $item->getParams()->set('jbzoo.no_index', 0);
- $this->app->table->item->save($item);
-
- // clean memory
- unset($item);
-
- return $id;
- }
-
- /**
- * Process one Category row
- * @param array $row
- * @param int $lineKey
- * @return int
- */
- protected function _processCategoryRow($row, $lineKey)
- {
- // create item
- $category = $this->_getCategoryByKey($row, $lineKey);
-
- // bind import data from CSV
- foreach ($this->_data->assign as $colKey => $itemField) {
-
- $itemField = JString::trim($itemField);
- if (!empty($itemField)) {
-
- $value = isset($row[$colKey]) ? $row[$colKey] : null;
-
- $fieldInfo = $this->app->jbcsvmapper->categoryFieldToMeta($itemField);
- $positionKey = implode('__', $fieldInfo);
-
- $cellElem = $this->app->jbcsvcell->createCategory($fieldInfo['name'], $category, $fieldInfo['group'], $fieldInfo);
- $cellElem->fromCSV($value);
- }
- }
-
- $id = $category->id;
-
- // save all changes
- $this->app->table->category->save($category);
-
- // clean memory
- unset($category);
-
- return $id;
- }
-
- /**
- * Get key field value
- * @param array $row
- * @param string $lineKey
- * @return Item
- */
- protected function _getItemByKey($row, $lineKey = null)
- {
- $item = null;
-
- if ($this->_data->key != self::KEY_NONE) {
- foreach ($this->_data->assign as $csvKey => $fieldName) {
-
- if ($this->_data->key == self::KEY_ID && $fieldName == 'id') {
- $item = JBModelItem::model()->getById(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
-
- } else if ($this->_data->key == self::KEY_NAME && $fieldName == 'name') {
- $item = JBModelItem::model()->getByName(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
-
- } else if ($this->_data->key == self::KEY_ALIAS && $fieldName == 'alias') {
- $item = JBModelItem::model()->getByAlias(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
-
- } else if ($this->_data->key == self::KEY_SKU && $fieldName == 'sku') {
- $item = JBModelItem::model()->getBySku(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
- }
- }
- }
-
- if (!$item) {
- $item = JBModelItem::model()->createEmpty($this->_data->appid, $this->_data->typeid, $lineKey);
- }
-
- return $item;
- }
-
- /**
- * Get key field value
- * @param array $row
- * @param string $lineKey
- * @return Item
- */
- protected function _getCategoryByKey($row, $lineKey = null)
- {
- $category = null;
-
- if ($this->_data->key != self::KEY_NONE) {
- foreach ($this->_data->assign as $csvKey => $fieldName) {
-
- if ($this->_data->key == self::KEY_ID && $fieldName == 'id') {
- $category = JBModelCategory::model()->getById(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
-
- } else if ($this->_data->key == self::KEY_NAME && $fieldName == 'name') {
- $category = JBModelCategory::model()->getByName(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
-
- } else if ($this->_data->key == self::KEY_ALIAS && $fieldName == 'alias') {
- $category = JBModelCategory::model()->getByAlias(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
- }
- }
- }
-
- if (!$category) {
- $category = JBModelCategory::model()->createEmpty($this->_data->appid, $lineKey);
- }
-
- return $category;
- }
-
- /**
- * One step precess for items
- * @param int $step
- * @return array
- */
- public function itemsProcess($step = 0)
- {
- $this->_initSessionData();
-
- $lastLine = $this->_getLastLine($step);
- $lines = $this->_getCSVLines($this->_data->file, $lastLine, $step);
-
- $lineKey = 0;
- $addedIds = ($step == 0) ? array() : $this->app->jbsession->get('ids', 'import-ids');
-
- if (!empty($lines)) {
- foreach ($lines as $key => $row) {
- $lineKey = $lastLine + $key;
- $addedIds[] = $this->_processItemRow($row, $lineKey);
- }
- }
-
- $this->app->jbsession->set('ids', $addedIds, 'import-ids');
-
- return array('progress' => round(($lineKey / $this->_data->count) * 100, 2));
- }
-
- /**
- * One step precess for categories
- * @param int $step
- * @return array
- */
- public function categoriesProcess($step = 0)
- {
- $this->_initSessionData();
-
- $lastLine = $this->_getLastLine($step);
- $lines = $this->_getCSVLines($this->_data->file, $lastLine, $step);
-
- $lineKey = 0;
- $addedIds = ($step == 0) ? array() : $this->app->jbsession->get('ids', 'import-ids');
-
- if (!empty($lines)) {
- foreach ($lines as $key => $row) {
- $lineKey = $lastLine + $key;
- $addedIds[] = $this->_processCategoryRow($row, $lineKey);
- }
- }
-
- $this->app->jbsession->set('ids', $addedIds, 'import-ids');
-
- return array('progress' => round(($lineKey / $this->_data->count) * 100, 2));
- }
-
- /**
- * Call after all items loaded
- */
- public function itemsPostProcess()
- {
- $addedIds = $this->app->jbsession->get('ids', 'import-ids');
- $this->_initSessionData();
-
- if ($this->_data->lose == self::LOSE_DISABLE) {
- JBModelItem::model()->disableAll($this->_data->appid, $this->_data->typeid, $addedIds);
-
- } else if ($this->_data->lose == self::LOSE_REMOVE) {
- JBModelItem::model()->removeAll($this->_data->appid, $this->_data->typeid, $addedIds);
- }
-
- $this->app->jbsession->clearGroup('import-ids');
- }
-
- /**
- * Call after all items loaded
- */
- public function categoriesPostProcess()
- {
- $addedIds = $this->app->jbsession->get('ids', 'import-ids');
- $this->_initSessionData();
-
- if ($this->_data->lose == self::LOSE_DISABLE) {
- JBModelCategory::model()->disableAll($this->_data->appid, $addedIds);
-
- } else if ($this->_data->lose == self::LOSE_REMOVE) {
- JBModelCategory::model()->removeAll($this->_data->appid, $addedIds);
- }
-
- $this->app->jbsession->clearGroup('import-ids');
- }
-
-
-}
+
+ */
+
+// no direct access
+defined('_JEXEC') or die('Restricted access');
+
+
+/**
+ * Class JBImportHelper
+ */
+class JBImportHelper extends AppHelper
+{
+ const STEP_SIZE = 20;
+
+ const LOSE_NONE = 0;
+ const LOSE_DISABLE = 1;
+ const LOSE_REMOVE = 2;
+
+ const KEY_NONE = 0;
+ const KEY_ID = 1;
+ const KEY_NAME = 2;
+ const KEY_ALIAS = 3;
+ const KEY_SKU = 4;
+
+ const OPTIONS_NO = 0;
+ const OPTIONS_YES = 1;
+
+ /**
+ * @var JSONData
+ */
+ protected $_data = null;
+
+ /**
+ * @param App $app
+ */
+ public function __construct($app)
+ {
+ parent::__construct($app);
+
+ // make sure the line endings are recognized irrespective of the OS
+ $this->app->jbenv->maxPerfomance();
+ ini_set('auto_detect_line_endings', true);
+ }
+
+ /**
+ * Get info for pre import step
+ * @param string $file
+ * @param array $options
+ * @return array
+ */
+ public function getInfo($file, $options)
+ {
+ $options = $this->app->data->create($options);
+
+ $info = array();
+
+ // get applications
+ $applist = JBModelApp::model()->getList();
+ if (!empty($applist)) {
+ $info['applist'] = array();
+ foreach ($applist as $app) {
+ $info['applist'][$app->id] = $app->name;
+ }
+
+ reset($applist);
+ $application = current($applist);
+
+ $info['app'] = current($applist);
+ }
+
+ // get types
+ $info['types'] = array();
+ foreach ($info['app']->getTypes() as $type) {
+ $info['types'][$type->id] = array();
+
+ foreach ($type->getElements() as $element) {
+ // filter elements
+ $info['types'][$type->id][$element->getElementType()][] = $element;
+ }
+
+ }
+
+ $info['item_count'] = 0;
+ $info['columns'] = array();
+
+ // get params
+ $separator = $options->get('separator', ',') ? $options->get('separator', ',') : ',';
+ $enclosure = $options->get('enclosure', '"') ? $options->get('enclosure', '"') : '"';
+ $containsHeaders = (int)$options->get('header', 1);
+
+ // get column names and row count
+ $rowCount = 0;
+ if (($handle = fopen($file, "r")) !== false) {
+
+ while (($data = fgetcsv($handle, 0, $separator, $enclosure)) !== false) {
+
+ if ($rowCount == 0) {
+ if ($containsHeaders) {
+ $info['columns'] = $data;
+ } else {
+ $info['columns'] = array_fill(0, count($data), '');
+ }
+ }
+
+ $rowCount++;
+ }
+ fclose($handle);
+ }
+
+ $info['count'] = $containsHeaders ? $rowCount - 1 : $rowCount;
+
+ return $info;
+ }
+
+ /**
+ * @param $info
+ * @return array
+ */
+ public function itemsControls($info)
+ {
+ $html = array();
+ $htmlHelper = $this->app->html;
+
+ $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_APP') . ' -'));
+ $options += $info['applist'];
+ $html['apps'] = $htmlHelper->_('select.genericlist', $options, 'appid');
+
+ $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_TYPE') . ' -'));
+ $html['types'] = $htmlHelper->_('zoo.typelist', $info['app'], $options, 'typeid', null, 'value', 'text');
+
+ $html['fields_types'] = array();
+ foreach ($info['types'] as $typeid => $element_types) {
+ $html['fields_types'][$typeid] = $this->_createItemsControl($typeid, $element_types);
+ }
+
+ // lose control
+ $loseOptions = array(
+ $htmlHelper->_('select.option', self::LOSE_NONE, JText::_('JBZOO_IMPORT_LOSE_NONE')),
+ $htmlHelper->_('select.option', self::LOSE_DISABLE, JText::_('JBZOO_IMPORT_LOSE_DISABLE')),
+ $htmlHelper->_('select.option', self::LOSE_REMOVE, JText::_('JBZOO_IMPORT_LOSE_REMOVE')),
+ );
+ $html['lose'] = $htmlHelper->_('select.genericlist', $loseOptions, 'lose');
+
+ // what field is key
+ $keyOptions = array(
+ $htmlHelper->_('select.option', self::KEY_NONE, JText::_('JBZOO_IMPORT_KEY_NONE')),
+ $htmlHelper->_('select.option', self::KEY_ID, JText::_('JBZOO_IMPORT_KEY_ID')),
+ $htmlHelper->_('select.option', self::KEY_NAME, JText::_('JBZOO_IMPORT_KEY_NAME')),
+ $htmlHelper->_('select.option', self::KEY_ALIAS, JText::_('JBZOO_IMPORT_KEY_ALIAS')),
+ $htmlHelper->_('select.option', self::KEY_SKU, JText::_('JBZOO_IMPORT_KEY_SKU')),
+ );
+ $html['key'] = $htmlHelper->_('select.genericlist', $keyOptions, 'key');
+
+ // check options config
+ $checkOptions = array(
+ $htmlHelper->_('select.option', self::OPTIONS_NO, JText::_('JBZOO_IMPORT_CHECK_OPTION_NO')),
+ $htmlHelper->_('select.option', self::OPTIONS_YES, JText::_('JBZOO_IMPORT_CHECK_OPTION_YES')),
+ );
+ $html['checkOptions'] = $htmlHelper->_('select.genericlist', $checkOptions, 'checkOptions');
+
+ return $html;
+ }
+
+ /**
+ * @param $info
+ * @return array
+ */
+ public function categoriesControls($info)
+ {
+ $html = array();
+ $htmlHelper = $this->app->html;
+
+ $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_APP') . ' -'));
+ $options += $info['applist'];
+ $html['apps'] = $htmlHelper->_('select.genericlist', $options, 'appid');
+
+ $html['fields_types'] = $this->_createCategoriesControl('categoryFileds');
+
+ // lose control
+ $loseOptions = array(
+ $htmlHelper->_('select.option', self::LOSE_NONE, JText::_('JBZOO_IMPORT_LOSE_NONE')),
+ $htmlHelper->_('select.option', self::LOSE_DISABLE, JText::_('JBZOO_IMPORT_LOSE_DISABLE')),
+ $htmlHelper->_('select.option', self::LOSE_REMOVE, JText::_('JBZOO_IMPORT_LOSE_REMOVE')),
+ );
+ $html['lose'] = $htmlHelper->_('select.genericlist', $loseOptions, 'lose');
+
+ // what field is key
+ $keyOptions = array(
+ $htmlHelper->_('select.option', self::KEY_NONE, JText::_('JBZOO_IMPORT_KEY_NONE')),
+ $htmlHelper->_('select.option', self::KEY_ID, JText::_('JBZOO_IMPORT_KEY_ID')),
+ $htmlHelper->_('select.option', self::KEY_NAME, JText::_('JBZOO_IMPORT_KEY_NAME')),
+ $htmlHelper->_('select.option', self::KEY_ALIAS, JText::_('JBZOO_IMPORT_KEY_ALIAS')),
+ );
+ $html['key'] = $htmlHelper->_('select.genericlist', $keyOptions, 'key');
+
+ return $html;
+ }
+
+ /**
+ * Create fields control for item
+ * @param $typeid
+ * @param $elementTypes
+ */
+ protected function _createItemsControl($typeid, $elementTypes)
+ {
+ $htmlHelper = $this->app->html;
+
+ $fields = $this->app->jbcsvmapper->getItemFields($elementTypes);
+ $options = array($htmlHelper->_('select.option', '', ' ** '));
+
+ foreach ($fields as $groupKey => $group) {
+
+ $options[] = $htmlHelper->_('select.option', '');
+ }
+
+ return $htmlHelper->_(
+ 'select.genericlist',
+ $options,
+ 'assign[' . $typeid . '][__name_placeholder__]',
+ 'class="type-select type-select-' . $typeid . '"'
+ );
+ }
+
+ /**
+ * Create fields control for category
+ */
+ protected function _createCategoriesControl()
+ {
+ $htmlHelper = $this->app->html;
+
+ $fields = $this->app->jbcsvmapper->getCategoryFields();
+ $options = array($htmlHelper->_('select.option', '', ' ** '));
+
+ foreach ($fields as $groupKey => $group) {
+
+ $options[] = $htmlHelper->_('select.option', '');
+ }
+
+ return $htmlHelper->_('select.genericlist', $options, 'assign[]', 'class="type-select"');
+ }
+
+ /**
+ * @return string
+ */
+ public function getTmpFilename()
+ {
+ $tmp = $this->app->path->path('tmp:');
+ return JPath::clean($tmp . '/' . uniqid('jbimport_') . '.csv');
+ }
+
+ /**
+ * Get import data from session
+ * @return JSONData
+ */
+ protected function _initSessionData()
+ {
+ $data = $this->app->jbsession->getGroup('import');
+ $this->_data = $this->app->data->create($data);
+
+ return $this->_data;
+ }
+
+ /**
+ * Get last line in CSV file
+ * @param int $step
+ * @return int
+ */
+ protected function _getLastLine($step = 0)
+ {
+ $lastLine = self::STEP_SIZE * $step;
+ if ((int)$this->_data->header) {
+ $lastLine++;
+ }
+
+ return $lastLine;
+ }
+
+ /**
+ * Get lines from CSV file for current step
+ * @param string $file
+ * @param int $lastLine
+ * @return array
+ */
+ protected function _getCSVLines($file, $lastLine)
+ {
+ return $this->app->jbcsv->getLinesfromFile($file, $this->_data, $lastLine, self::STEP_SIZE);
+ }
+
+ /**
+ * Process one Item row
+ * @param array $row
+ * @param int $lineKey
+ * @return int
+ */
+ protected function _processItemRow($row, $lineKey)
+ {
+ // create item
+ $item = $this->_getItemByKey($row, $lineKey);
+
+ $positions = array();
+
+ // bind import data from CSV
+ foreach ($this->_data->assign as $colKey => $itemField) {
+
+ $itemField = JString::trim($itemField);
+ if (!empty($itemField)) {
+
+ $value = isset($row[$colKey]) ? $row[$colKey] : null;
+
+ $fieldInfo = $this->app->jbcsvmapper->itemFieldToMeta($itemField);
+
+ $positionKey = implode('__', $fieldInfo);
+ if (!isset($positions[$positionKey])) {
+ $positions[$positionKey] = 0;
+ }
+ $positions[$positionKey]++;
+
+ $cellElem = $this->app->jbcsvcell->createItem($fieldInfo['name'], $item, $fieldInfo['group'], $fieldInfo);
+ $cellElem->fromCSV($value, $positions[$positionKey]);
+ }
+ }
+
+ $id = $item->id;
+
+ // save all changes
+ $item->getParams()->set('jbzoo.no_index', 0);
+ $this->app->table->item->save($item);
+
+ // clean memory
+ unset($item);
+
+ return $id;
+ }
+
+ /**
+ * Process one Category row
+ * @param array $row
+ * @param int $lineKey
+ * @return int
+ */
+ protected function _processCategoryRow($row, $lineKey)
+ {
+ // create item
+ $category = $this->_getCategoryByKey($row, $lineKey);
+
+ // bind import data from CSV
+ foreach ($this->_data->assign as $colKey => $itemField) {
+
+ $itemField = JString::trim($itemField);
+ if (!empty($itemField)) {
+
+ $value = isset($row[$colKey]) ? $row[$colKey] : null;
+
+ $fieldInfo = $this->app->jbcsvmapper->categoryFieldToMeta($itemField);
+ $positionKey = implode('__', $fieldInfo);
+
+ $cellElem = $this->app->jbcsvcell->createCategory($fieldInfo['name'], $category, $fieldInfo['group'], $fieldInfo);
+ $cellElem->fromCSV($value);
+ }
+ }
+
+ $id = $category->id;
+
+ // save all changes
+ $this->app->table->category->save($category);
+
+ // clean memory
+ unset($category);
+
+ return $id;
+ }
+
+ /**
+ * Get key field value
+ * @param array $row
+ * @param string $lineKey
+ * @return Item
+ */
+ protected function _getItemByKey($row, $lineKey = null)
+ {
+ $item = null;
+
+ if ($this->_data->key != self::KEY_NONE) {
+ foreach ($this->_data->assign as $csvKey => $fieldName) {
+
+ if ($this->_data->key == self::KEY_ID && $fieldName == 'id') {
+ $item = JBModelItem::model()->getById(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+
+ } else if ($this->_data->key == self::KEY_NAME && $fieldName == 'name') {
+ $item = JBModelItem::model()->getByName(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+
+ } else if ($this->_data->key == self::KEY_ALIAS && $fieldName == 'alias') {
+ $item = JBModelItem::model()->getByAlias(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+
+ } else if ($this->_data->key == self::KEY_SKU && $fieldName == 'sku') {
+ $item = JBModelItem::model()->getBySku(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+ }
+ }
+ }
+
+ if (!$item) {
+ $item = JBModelItem::model()->createEmpty($this->_data->appid, $this->_data->typeid, $lineKey);
+ }
+
+ return $item;
+ }
+
+ /**
+ * Get key field value
+ * @param array $row
+ * @param string $lineKey
+ * @return Item
+ */
+ protected function _getCategoryByKey($row, $lineKey = null)
+ {
+ $category = null;
+
+ if ($this->_data->key != self::KEY_NONE) {
+ foreach ($this->_data->assign as $csvKey => $fieldName) {
+
+ if ($this->_data->key == self::KEY_ID && $fieldName == 'id') {
+ $category = JBModelCategory::model()->getById(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+
+ } else if ($this->_data->key == self::KEY_NAME && $fieldName == 'name') {
+ $category = JBModelCategory::model()->getByName(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+
+ } else if ($this->_data->key == self::KEY_ALIAS && $fieldName == 'alias') {
+ $category = JBModelCategory::model()->getByAlias(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+ }
+ }
+ }
+
+ if (!$category) {
+ $category = JBModelCategory::model()->createEmpty($this->_data->appid, $lineKey);
+ }
+
+ return $category;
+ }
+
+ /**
+ * One step precess for items
+ * @param int $step
+ * @return array
+ */
+ public function itemsProcess($step = 0)
+ {
+ $this->_initSessionData();
+
+ $lastLine = $this->_getLastLine($step);
+ $lines = $this->_getCSVLines($this->_data->file, $lastLine, $step);
+
+ $lineKey = 0;
+ $addedIds = ($step == 0) ? array() : $this->app->jbsession->get('ids', 'import-ids');
+
+ if (!empty($lines)) {
+ foreach ($lines as $key => $row) {
+ $lineKey = $lastLine + $key;
+ $addedIds[] = $this->_processItemRow($row, $lineKey);
+ }
+ }
+
+ $this->app->jbsession->set('ids', $addedIds, 'import-ids');
+
+ return array('progress' => round(($lineKey / $this->_data->count) * 100, 2));
+ }
+
+ /**
+ * One step precess for categories
+ * @param int $step
+ * @return array
+ */
+ public function categoriesProcess($step = 0)
+ {
+ $this->_initSessionData();
+
+ $lastLine = $this->_getLastLine($step);
+ $lines = $this->_getCSVLines($this->_data->file, $lastLine, $step);
+
+ $lineKey = 0;
+ $addedIds = ($step == 0) ? array() : $this->app->jbsession->get('ids', 'import-ids');
+
+ if (!empty($lines)) {
+ foreach ($lines as $key => $row) {
+ $lineKey = $lastLine + $key;
+ $addedIds[] = $this->_processCategoryRow($row, $lineKey);
+ }
+ }
+
+ $this->app->jbsession->set('ids', $addedIds, 'import-ids');
+
+ return array('progress' => round(($lineKey / $this->_data->count) * 100, 2));
+ }
+
+ /**
+ * Call after all items loaded
+ */
+ public function itemsPostProcess()
+ {
+ $addedIds = $this->app->jbsession->get('ids', 'import-ids');
+ $this->_initSessionData();
+
+ if ($this->_data->lose == self::LOSE_DISABLE) {
+ JBModelItem::model()->disableAll($this->_data->appid, $this->_data->typeid, $addedIds);
+
+ } else if ($this->_data->lose == self::LOSE_REMOVE) {
+ JBModelItem::model()->removeAll($this->_data->appid, $this->_data->typeid, $addedIds);
+ }
+
+ $this->app->jbsession->clearGroup('import-ids');
+ }
+
+ /**
+ * Call after all items loaded
+ */
+ public function categoriesPostProcess()
+ {
+ $addedIds = $this->app->jbsession->get('ids', 'import-ids');
+ $this->_initSessionData();
+
+ if ($this->_data->lose == self::LOSE_DISABLE) {
+ JBModelCategory::model()->disableAll($this->_data->appid, $addedIds);
+
+ } else if ($this->_data->lose == self::LOSE_REMOVE) {
+ JBModelCategory::model()->removeAll($this->_data->appid, $addedIds);
+ }
+
+ $this->app->jbsession->clearGroup('import-ids');
+ }
+
+
+}
diff --git a/patches/2.0.0/media/zoo/applications/jbuniversal/framework/jbzoo.php b/patches/2.0.0/media/zoo/applications/jbuniversal/framework/jbzoo.php
index df5d0fa..00eb113 100644
--- a/patches/2.0.0/media/zoo/applications/jbuniversal/framework/jbzoo.php
+++ b/patches/2.0.0/media/zoo/applications/jbuniversal/framework/jbzoo.php
@@ -1 +1,374 @@
-
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
!defined('JBZOO_APP_GROUP') && define('JBZOO_APP_GROUP', 'jbuniversal');
!defined('DIRECTORY_SEPERATOR') && define('DIRECTORY_SEPERATOR', '/');
!defined('DS') && define('DS', DIRECTORY_SEPARATOR);
/**
* Class JBZoo
*/
class JBZoo
{
/**
* @var Application
*/
public $app = null;
/**
* App group name
* @var string
*/
private $_group = JBZOO_APP_GROUP;
/**
* Init JBZoo application
* @static
* @return JBZoo
*/
public static function init()
{
static $jbzoo;
if (!isset($jbzoo)) {
$jbzoo = new self();
}
return $jbzoo;
}
/**
* Initialization JBZoo App
*/
private function __construct()
{
$this->app = App::getInstance('zoo');
$this->_initPaths();
$this->_initConfig();
$this->_initModels();
$this->_initLanguages();
$this->_initFilterElements();
$this->_initEvents();
$this->_initAssets();
}
/**
* Add directory path
*/
private function _initPaths()
{
$this->_addPath('applications:' . $this->_getGroup(), 'jbapp');
$this->_addPath('jbapp:framework', 'jbzoo');
$this->_addPath('jbapp:assets', 'jbassets');
$this->_addPath('jbassets:zoo', 'assets');
$this->_addPath('jbapp:config', 'jbconfig');
$this->_addPath('jbzoo:elements', 'jbelements');
$this->_addPath('jbapp:types', 'jbtypes');
$this->_addPath('jbzoo:helpers', 'helpers');
$this->_addPath('jbzoo:helpers-std', 'helpers');
$this->_addPath('jbzoo:render', 'renderer');
$this->_addPath('jbzoo:controllers/views', 'jbviews');
$this->_addPath('jbapp:config', 'jbxml');
$this->_addPath('jbapp:joomla/elements', 'fields');
$this->_addPath('modules:mod_jbzoo_search', 'mod_jbzoo_search');
$this->_addPath('modules:mod_jbzoo_props', 'mod_jbzoo_props');
$this->_addPath('modules:mod_jbzoo_basket', 'mod_jbzoo_basket');
$this->_addPath('modules:mod_jbzoo_category', 'mod_jbzoo_category');
$this->_addPath('plugins:/system/jbzoo', 'plugin_jbzoo');
$this->_addPath('jbapp:templates', 'jbtmpl');
if ($this->app->jbenv->isSite()) {
$this->_addPath('jbzoo:controllers', 'controllers');
}
$this->app->jbdebug->mark('init::paths');
}
/**
* Include models classes
*/
private function _initModels()
{
// defines
define('ZOO_TABLE_JBZOO_INDEX', '#__zoo_jbzoo_index');
define('ZOO_TABLE_JBZOO_SKU', '#__zoo_jbzoo_sku');
define('ZOO_TABLE_JBZOO_FAVORITE', '#__zoo_jbzoo_favorite');
// query builder
$path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/classes';
require $path . '/database/JBDatabaseQuery.php';
require $path . '/database/JBDatabaseQueryElement.php';
// models
$path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/models';
require $path . '/jbmodel.php';
require $path . '/jbmodel.element.php';
require $path . '/jbmodel.autocomplete.php';
require $path . '/jbmodel.element.country.php';
require $path . '/jbmodel.element.itemdate.php';
require $path . '/jbmodel.element.itemauthor.php';
require $path . '/jbmodel.element.itemcategory.php';
require $path . '/jbmodel.element.itemcreated.php';
require $path . '/jbmodel.element.itemfrontpage.php';
require $path . '/jbmodel.element.itemmodified.php';
require $path . '/jbmodel.element.itemname.php';
require $path . '/jbmodel.element.itempublish_down.php';
require $path . '/jbmodel.element.itempublish_up.php';
require $path . '/jbmodel.element.itemtag.php';
require $path . '/jbmodel.element.jbimage.php';
require $path . '/jbmodel.element.jbselectcascade.php';
require $path . '/jbmodel.element.range.php';
require $path . '/jbmodel.element.rating.php';
require $path . '/jbmodel.element.jbpriceadvance.php';
require $path . '/jbmodel.favorite.php';
require $path . '/jbmodel.filter.php';
require $path . '/jbmodel.item.php';
require $path . '/jbmodel.app.php';
require $path . '/jbmodel.category.php';
require $path . '/jbmodel.order.php';
require $path . '/jbmodel.related.php';
require $path . '/jbmodel.searchindex.php';
require $path . '/jbmodel.values.php';
require $path . '/jbmodel.sku.php';
}
/**
* Load lang files
*/
private function _initLanguages()
{
$lang = JFactory::getLanguage();
$lang->load('com_zoo');
$lang->load('com_jbzoo', $this->app->path->path('jbapp:'), null, true);
$lang->load('com_zoo', JPATH_ADMINISTRATOR);
}
/**
* Load others libraries
*/
private function _initFilterElements()
{
jimport('joomla.html.parameter.element');
$path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/render/filter';
require $path . '/element.php';
require $path . '/element.author.php';
require $path . '/element.author.checkbox.php';
require $path . '/element.author.radio.php';
require $path . '/element.author.select.php';
require $path . '/element.author.select.chosen.php';
require $path . '/element.author.text.php';
require $path . '/element.category.php';
require $path . '/element.category.chosen.php';
require $path . '/element.checkbox.php';
require $path . '/element.country.php';
require $path . '/element.country.checkbox.php';
require $path . '/element.country.radio.php';
require $path . '/element.country.select.php';
require $path . '/element.country.select.chosen.php';
require $path . '/element.date.php';
require $path . '/element.date.range.php';
require $path . '/element.frontpage.php';
require $path . '/element.frontpage.jqueryui.php';
require $path . '/element.hidden.php';
require $path . '/element.imageexists.php';
require $path . '/element.imageexists.jqueryui.php';
require $path . '/element.jbselectcascade.php';
require $path . '/element.jqueryui.php';
require $path . '/element.name.php';
require $path . '/element.name.checkbox.php';
require $path . '/element.name.radio.php';
require $path . '/element.name.select.php';
require $path . '/element.name.select.chosen.php';
require $path . '/element.radio.php';
require $path . '/element.rating.php';
require $path . '/element.rating.ranges.php';
require $path . '/element.rating.slider.php';
require $path . '/element.select.php';
require $path . '/element.select.chosen.php';
require $path . '/element.slider.php';
require $path . '/element.tag.php';
require $path . '/element.tag.checkbox.php';
require $path . '/element.tag.radio.php';
require $path . '/element.tag.select.php';
require $path . '/element.tag.select.chosen.php';
require $path . '/element.text.php';
require $path . '/element.text.range.php';
}
/**
* Register and connect events
*/
private function _initEvents()
{
$path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/events';
require $path . '/jbevent.php';
require $path . '/jbevent.application.php';
require $path . '/jbevent.basket.php';
require $path . '/jbevent.category.php';
require $path . '/jbevent.comment.php';
require $path . '/jbevent.element.php';
require $path . '/jbevent.item.php';
require $path . '/jbevent.jbzoo.php';
require $path . '/jbevent.layout.php';
require $path . '/jbevent.submission.php';
require $path . '/jbevent.tag.php';
require $path . '/jbevent.type.php';
require $path . '/jbevent.payment.php';
$event = $this->app->event;
$dispatcher = $event->dispatcher;
$event->register('JBEventApplication');
$dispatcher->connect('application:init', array('JBEventApplication', 'init'));
$dispatcher->connect('application:saved', array('JBEventApplication', 'saved'));
$dispatcher->connect('application:deleted', array('JBEventApplication', 'deleted'));
$event->register('JBEventCategory');
$dispatcher->connect('category:init', array('JBEventCategory', 'init'));
$dispatcher->connect('category:saved', array('JBEventCategory', 'saved'));
$dispatcher->connect('category:deleted', array('JBEventCategory', 'deleted'));
$dispatcher->connect('category:stateChanged', array('JBEventCategory', 'stateChanged'));
$event->register('JBEventItem');
$dispatcher->connect('item:init', array('JBEventItem', 'init'));
$dispatcher->connect('item:saved', array('JBEventItem', 'saved'));
$dispatcher->connect('item:deleted', array('JBEventItem', 'deleted'));
$dispatcher->connect('item:stateChanged', array('JBEventItem', 'stateChanged'));
$dispatcher->connect('item:beforedisplay', array('JBEventItem', 'beforeDisplay'));
$dispatcher->connect('item:afterdisplay', array('JBEventItem', 'afterDisplay'));
$event->register('JBEventComment');
$dispatcher->connect('comment:init', array('JBEventComment', 'init'));
$dispatcher->connect('comment:saved', array('JBEventComment', 'saved'));
$dispatcher->connect('comment:deleted', array('JBEventComment', 'deleted'));
$dispatcher->connect('comment:stateChanged', array('JBEventComment', 'stateChanged'));
$event->register('JBEventSubmission');
$dispatcher->connect('submission:init', array('JBEventSubmission', 'init'));
$dispatcher->connect('submission:saved', array('JBEventSubmission', 'saved'));
$dispatcher->connect('submission:deleted', array('JBEventSubmission', 'deleted'));
$dispatcher->connect('submission:beforesave', array('JBEventSubmission', 'beforeSave'));
$event->register('JBEventElement');
$dispatcher->connect('element:download', array('JBEventElement', 'download'));
$dispatcher->connect('element:configform', array('JBEventElement', 'configForm'));
$dispatcher->connect('element:configparams', array('JBEventElement', 'configParams'));
$dispatcher->connect('element:configxml', array('JBEventElement', 'configXML'));
$dispatcher->connect('element:afterdisplay', array('JBEventElement', 'afterDisplay'));
$dispatcher->connect('element:beforedisplay', array('JBEventElement', 'beforeDisplay'));
$dispatcher->connect('element:aftersubmissiondisplay', array('JBEventElement', 'afterSubmissionDisplay'));
$dispatcher->connect('element:beforesubmissiondisplay', array('JBEventElement', 'beforeSubmissionDisplay'));
$dispatcher->connect('element:beforeedit', array('JBEventElement', 'beforeEdit'));
$dispatcher->connect('element:afteredit', array('JBEventElement', 'afterEdit'));
$event->register('JBEventLayout');
$dispatcher->connect('layout:init', array('JBEventLayout', 'init'));
$event->register('JBEventTag');
$dispatcher->connect('tag:saved', array('JBEventTag', 'saved'));
$dispatcher->connect('tag:deleted', array('JBEventTag', 'deleted'));
$event->register('JBEventType');
$dispatcher->connect('type:beforesave', array('JBEventType', 'beforesave'));
$dispatcher->connect('type:aftersave', array('JBEventType', 'aftersave'));
$dispatcher->connect('type:copied', array('JBEventType', 'copied'));
$dispatcher->connect('type:deleted', array('JBEventType', 'deleted'));
$dispatcher->connect('type:editdisplay', array('JBEventType', 'editDisplay'));
$event->register('JBEventJBZoo');
$dispatcher->connect('jbzoo:beforeInit', array('JBEventJBZoo', 'beforeInit'));
$dispatcher->notify($event->create($this, 'jbzoo:beforeInit'));
$event->register('JBEventBasket');
$dispatcher->connect('basket:beforesave', array('JBEventBasket', 'beforeSave'));
$dispatcher->connect('basket:saved', array('JBEventBasket', 'saved'));
$event->register('JBEventPayment');
$dispatcher->connect('payment:callback', array('JBEventPayment', 'callback'));
}
/**
* Init assets for admin path
*/
private function _initAssets()
{
if (!$this->app->jbenv->isSite()) {
$this->app->jbassets->admin();
}
}
/**
* Init config file
*/
private function _initConfig()
{
if ($configFile = $this->app->path->path('jbapp:config/config.php')) {
require $configFile;
}
}
/**
* Get group name
* @return string
*/
private function _getGroup()
{
return $this->_group;
}
/**
* Register new path in system
* @param string $path
* @param string $pathName
* @return mixed
*/
private function _addPath($path, $pathName)
{
if ($fullPath = $this->app->path->path($path)) {
return $this->app->path->register($fullPath, $pathName);
}
return null;
}
/**
* Get domain name
* @param bool $isAny
* @return string
*/
static function getDomain($isAny = false)
{
$domain = '';
if (function_exists('apache_request_headers')) {
$headers = apache_request_headers();
$domain = isset($headers['Host']) ? $headers['Host'] : '';
}
if ($isAny && !$domain) {
$domain = $_SERVER['HTTP_HOST'];
}
$domain = preg_replace('#^www\.#', '', $domain);
list($domain) = explode(':', $domain);
return $domain;
}
}
\ No newline at end of file
+
+ */
+
+// no direct access
+defined('_JEXEC') or die('Restricted access');
+
+
+!defined('JBZOO_APP_GROUP') && define('JBZOO_APP_GROUP', 'jbuniversal');
+!defined('DIRECTORY_SEPERATOR') && define('DIRECTORY_SEPERATOR', '/');
+!defined('DS') && define('DS', DIRECTORY_SEPARATOR);
+
+/**
+ * Class JBZoo
+ */
+class JBZoo
+{
+ /**
+ * @var Application
+ */
+ public $app = null;
+
+ /**
+ * App group name
+ * @var string
+ */
+ private $_group = JBZOO_APP_GROUP;
+
+ /**
+ * Init JBZoo application
+ * @static
+ * @return JBZoo
+ */
+ public static function init()
+ {
+ static $jbzoo;
+
+ if (!isset($jbzoo)) {
+ $jbzoo = new self();
+ }
+
+ return $jbzoo;
+ }
+
+ /**
+ * Initialization JBZoo App
+ */
+ private function __construct()
+ {
+ $this->app = App::getInstance('zoo');
+
+ $this->_initPaths();
+ $this->_initConfig();
+ $this->_initModels();
+ $this->_initLanguages();
+ $this->_initFilterElements();
+ $this->_initEvents();
+ $this->_initAssets();
+ }
+
+ /**
+ * Add directory path
+ */
+ private function _initPaths()
+ {
+ $this->_addPath('applications:' . $this->_getGroup(), 'jbapp');
+ $this->_addPath('jbapp:framework', 'jbzoo');
+ $this->_addPath('jbapp:assets', 'jbassets');
+ $this->_addPath('jbassets:zoo', 'assets');
+ $this->_addPath('jbapp:config', 'jbconfig');
+ $this->_addPath('jbzoo:elements', 'jbelements');
+ $this->_addPath('jbapp:types', 'jbtypes');
+ $this->_addPath('jbzoo:helpers', 'helpers');
+ $this->_addPath('jbzoo:helpers-std', 'helpers');
+ $this->_addPath('jbzoo:render', 'renderer');
+ $this->_addPath('jbzoo:controllers/views', 'jbviews');
+ $this->_addPath('jbapp:config', 'jbxml');
+ $this->_addPath('jbapp:joomla/elements', 'fields');
+ $this->_addPath('modules:mod_jbzoo_search', 'mod_jbzoo_search');
+ $this->_addPath('modules:mod_jbzoo_props', 'mod_jbzoo_props');
+ $this->_addPath('modules:mod_jbzoo_basket', 'mod_jbzoo_basket');
+ $this->_addPath('modules:mod_jbzoo_category', 'mod_jbzoo_category');
+ $this->_addPath('plugins:/system/jbzoo', 'plugin_jbzoo');
+ $this->_addPath('jbapp:templates', 'jbtmpl');
+
+ if ($this->app->jbenv->isSite()) {
+ $this->_addPath('jbzoo:controllers', 'controllers');
+ }
+
+ $this->app->jbdebug->mark('init::paths');
+ }
+
+ /**
+ * Include models classes
+ */
+ private function _initModels()
+ {
+ // defines
+ define('ZOO_TABLE_JBZOO_INDEX', '#__zoo_jbzoo_index');
+ define('ZOO_TABLE_JBZOO_SKU', '#__zoo_jbzoo_sku');
+ define('ZOO_TABLE_JBZOO_FAVORITE', '#__zoo_jbzoo_favorite');
+
+ // query builder
+ $path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/classes';
+ require $path . '/database/JBDatabaseQuery.php';
+ require $path . '/database/JBDatabaseQueryElement.php';
+
+ // models
+ $path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/models';
+ require $path . '/jbmodel.php';
+ require $path . '/jbmodel.element.php';
+ require $path . '/jbmodel.autocomplete.php';
+ require $path . '/jbmodel.element.country.php';
+ require $path . '/jbmodel.element.itemdate.php';
+ require $path . '/jbmodel.element.itemauthor.php';
+ require $path . '/jbmodel.element.itemcategory.php';
+ require $path . '/jbmodel.element.itemcreated.php';
+ require $path . '/jbmodel.element.itemfrontpage.php';
+ require $path . '/jbmodel.element.itemmodified.php';
+ require $path . '/jbmodel.element.itemname.php';
+ require $path . '/jbmodel.element.itempublish_down.php';
+ require $path . '/jbmodel.element.itempublish_up.php';
+ require $path . '/jbmodel.element.itemtag.php';
+ require $path . '/jbmodel.element.jbimage.php';
+ require $path . '/jbmodel.element.jbselectcascade.php';
+ require $path . '/jbmodel.element.range.php';
+ require $path . '/jbmodel.element.rating.php';
+ require $path . '/jbmodel.element.jbpriceadvance.php';
+ require $path . '/jbmodel.favorite.php';
+ require $path . '/jbmodel.filter.php';
+ require $path . '/jbmodel.item.php';
+ require $path . '/jbmodel.app.php';
+ require $path . '/jbmodel.category.php';
+ require $path . '/jbmodel.order.php';
+ require $path . '/jbmodel.related.php';
+ require $path . '/jbmodel.searchindex.php';
+ require $path . '/jbmodel.values.php';
+ require $path . '/jbmodel.sku.php';
+ }
+
+ /**
+ * Load lang files
+ */
+ private function _initLanguages()
+ {
+ $lang = JFactory::getLanguage();
+ $lang->load('com_zoo');
+ $lang->load('com_jbzoo', $this->app->path->path('jbapp:'), null, true);
+ $lang->load('com_zoo', JPATH_ADMINISTRATOR);
+ }
+
+ /**
+ * Load others libraries
+ */
+ private function _initFilterElements()
+ {
+ jimport('joomla.html.parameter.element');
+
+ $path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/render/filter';
+ require $path . '/element.php';
+ require $path . '/element.author.php';
+ require $path . '/element.author.checkbox.php';
+ require $path . '/element.author.radio.php';
+ require $path . '/element.author.select.php';
+ require $path . '/element.author.select.chosen.php';
+ require $path . '/element.author.text.php';
+ require $path . '/element.category.php';
+ require $path . '/element.category.chosen.php';
+ require $path . '/element.checkbox.php';
+ require $path . '/element.country.php';
+ require $path . '/element.country.checkbox.php';
+ require $path . '/element.country.radio.php';
+ require $path . '/element.country.select.php';
+ require $path . '/element.country.select.chosen.php';
+ require $path . '/element.date.php';
+ require $path . '/element.date.range.php';
+ require $path . '/element.frontpage.php';
+ require $path . '/element.frontpage.jqueryui.php';
+ require $path . '/element.hidden.php';
+ require $path . '/element.imageexists.php';
+ require $path . '/element.imageexists.jqueryui.php';
+ require $path . '/element.jbselectcascade.php';
+ require $path . '/element.jqueryui.php';
+ require $path . '/element.name.php';
+ require $path . '/element.name.checkbox.php';
+ require $path . '/element.name.radio.php';
+ require $path . '/element.name.select.php';
+ require $path . '/element.name.select.chosen.php';
+ require $path . '/element.radio.php';
+ require $path . '/element.rating.php';
+ require $path . '/element.rating.ranges.php';
+ require $path . '/element.rating.slider.php';
+ require $path . '/element.select.php';
+ require $path . '/element.select.chosen.php';
+ require $path . '/element.slider.php';
+ require $path . '/element.tag.php';
+ require $path . '/element.tag.checkbox.php';
+ require $path . '/element.tag.radio.php';
+ require $path . '/element.tag.select.php';
+ require $path . '/element.tag.select.chosen.php';
+ require $path . '/element.text.php';
+ require $path . '/element.text.range.php';
+ }
+
+ /**
+ * Register and connect events
+ */
+ private function _initEvents()
+ {
+ $path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/events';
+ require $path . '/jbevent.php';
+ require $path . '/jbevent.application.php';
+ require $path . '/jbevent.basket.php';
+ require $path . '/jbevent.category.php';
+ require $path . '/jbevent.comment.php';
+ require $path . '/jbevent.element.php';
+ require $path . '/jbevent.item.php';
+ require $path . '/jbevent.jbzoo.php';
+ require $path . '/jbevent.layout.php';
+ require $path . '/jbevent.submission.php';
+ require $path . '/jbevent.tag.php';
+ require $path . '/jbevent.type.php';
+ require $path . '/jbevent.payment.php';
+
+ $event = $this->app->event;
+ $dispatcher = $event->dispatcher;
+
+ $event->register('JBEventApplication');
+ $dispatcher->connect('application:init', array('JBEventApplication', 'init'));
+ $dispatcher->connect('application:saved', array('JBEventApplication', 'saved'));
+ $dispatcher->connect('application:deleted', array('JBEventApplication', 'deleted'));
+
+ $event->register('JBEventCategory');
+ $dispatcher->connect('category:init', array('JBEventCategory', 'init'));
+ $dispatcher->connect('category:saved', array('JBEventCategory', 'saved'));
+ $dispatcher->connect('category:deleted', array('JBEventCategory', 'deleted'));
+ $dispatcher->connect('category:stateChanged', array('JBEventCategory', 'stateChanged'));
+
+ $event->register('JBEventItem');
+ $dispatcher->connect('item:init', array('JBEventItem', 'init'));
+ $dispatcher->connect('item:saved', array('JBEventItem', 'saved'));
+ $dispatcher->connect('item:deleted', array('JBEventItem', 'deleted'));
+ $dispatcher->connect('item:stateChanged', array('JBEventItem', 'stateChanged'));
+ $dispatcher->connect('item:beforedisplay', array('JBEventItem', 'beforeDisplay'));
+ $dispatcher->connect('item:afterdisplay', array('JBEventItem', 'afterDisplay'));
+
+ $event->register('JBEventComment');
+ $dispatcher->connect('comment:init', array('JBEventComment', 'init'));
+ $dispatcher->connect('comment:saved', array('JBEventComment', 'saved'));
+ $dispatcher->connect('comment:deleted', array('JBEventComment', 'deleted'));
+ $dispatcher->connect('comment:stateChanged', array('JBEventComment', 'stateChanged'));
+
+ $event->register('JBEventSubmission');
+ $dispatcher->connect('submission:init', array('JBEventSubmission', 'init'));
+ $dispatcher->connect('submission:saved', array('JBEventSubmission', 'saved'));
+ $dispatcher->connect('submission:deleted', array('JBEventSubmission', 'deleted'));
+ $dispatcher->connect('submission:beforesave', array('JBEventSubmission', 'beforeSave'));
+
+ $event->register('JBEventElement');
+ $dispatcher->connect('element:download', array('JBEventElement', 'download'));
+ $dispatcher->connect('element:configform', array('JBEventElement', 'configForm'));
+ $dispatcher->connect('element:configparams', array('JBEventElement', 'configParams'));
+ $dispatcher->connect('element:configxml', array('JBEventElement', 'configXML'));
+ $dispatcher->connect('element:afterdisplay', array('JBEventElement', 'afterDisplay'));
+ $dispatcher->connect('element:beforedisplay', array('JBEventElement', 'beforeDisplay'));
+ $dispatcher->connect('element:aftersubmissiondisplay', array('JBEventElement', 'afterSubmissionDisplay'));
+ $dispatcher->connect('element:beforesubmissiondisplay', array('JBEventElement', 'beforeSubmissionDisplay'));
+ $dispatcher->connect('element:beforeedit', array('JBEventElement', 'beforeEdit'));
+ $dispatcher->connect('element:afteredit', array('JBEventElement', 'afterEdit'));
+
+ $event->register('JBEventLayout');
+ $dispatcher->connect('layout:init', array('JBEventLayout', 'init'));
+
+ $event->register('JBEventTag');
+ $dispatcher->connect('tag:saved', array('JBEventTag', 'saved'));
+ $dispatcher->connect('tag:deleted', array('JBEventTag', 'deleted'));
+
+ $event->register('JBEventType');
+ $dispatcher->connect('type:beforesave', array('JBEventType', 'beforesave'));
+ $dispatcher->connect('type:aftersave', array('JBEventType', 'aftersave'));
+ $dispatcher->connect('type:copied', array('JBEventType', 'copied'));
+ $dispatcher->connect('type:deleted', array('JBEventType', 'deleted'));
+ $dispatcher->connect('type:editdisplay', array('JBEventType', 'editDisplay'));
+
+ $event->register('JBEventJBZoo');
+ $dispatcher->connect('jbzoo:beforeInit', array('JBEventJBZoo', 'beforeInit'));
+ $dispatcher->notify($event->create($this, 'jbzoo:beforeInit'));
+
+ $event->register('JBEventBasket');
+ $dispatcher->connect('basket:beforesave', array('JBEventBasket', 'beforeSave'));
+ $dispatcher->connect('basket:saved', array('JBEventBasket', 'saved'));
+
+ $event->register('JBEventPayment');
+ $dispatcher->connect('payment:callback', array('JBEventPayment', 'callback'));
+ }
+
+ /**
+ * Init assets for admin path
+ */
+ private function _initAssets()
+ {
+ if (!$this->app->jbenv->isSite()) {
+ $this->app->jbassets->admin();
+ }
+ }
+
+ /**
+ * Init config file
+ */
+ private function _initConfig()
+ {
+ if ($configFile = $this->app->path->path('jbapp:config/config.php')) {
+ require $configFile;
+ }
+ }
+
+ /**
+ * Get group name
+ * @return string
+ */
+ private function _getGroup()
+ {
+ return $this->_group;
+ }
+
+ /**
+ * Register new path in system
+ * @param string $path
+ * @param string $pathName
+ * @return mixed
+ */
+ private function _addPath($path, $pathName)
+ {
+ if ($fullPath = $this->app->path->path($path)) {
+ return $this->app->path->register($fullPath, $pathName);
+ }
+
+ return null;
+ }
+
+ /**
+ * Get domain name
+ * @param bool $isAny
+ * @return string
+ */
+ static function getDomain($isAny = false)
+ {
+ $domain = '';
+ if (function_exists('apache_request_headers')) {
+ $headers = apache_request_headers();
+ $domain = isset($headers['Host']) ? $headers['Host'] : '';
+ }
+
+ if ($isAny && !$domain) {
+ $domain = $_SERVER['HTTP_HOST'];
+ }
+
+ $domain = preg_replace('#^www\.#', '', $domain);
+ list($domain) = explode(':', $domain);
+
+ return $domain;
+ }
+}
diff --git a/patches/2.0.2/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php b/patches/2.0.2/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php
index cdd0c31..8fb15b4 100644
--- a/patches/2.0.2/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php
+++ b/patches/2.0.2/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php
@@ -1,562 +1,562 @@
-
- */
-
-// no direct access
-defined('_JEXEC') or die('Restricted access');
-
-
-/**
- * Class JBImportHelper
- */
-class JBImportHelper extends AppHelper
-{
- const STEP_SIZE = 20;
-
- const LOSE_NONE = 0;
- const LOSE_DISABLE = 1;
- const LOSE_REMOVE = 2;
-
- const KEY_NONE = 0;
- const KEY_ID = 1;
- const KEY_NAME = 2;
- const KEY_ALIAS = 3;
- const KEY_SKU = 4;
-
- const OPTIONS_NO = 0;
- const OPTIONS_YES = 1;
-
- /**
- * @var JSONData
- */
- protected $_data = null;
-
- /**
- * @param App $app
- */
- public function __construct($app)
- {
- parent::__construct($app);
-
- // make sure the line endings are recognized irrespective of the OS
- $this->app->jbenv->maxPerfomance();
- ini_set('auto_detect_line_endings', true);
- }
-
- /**
- * Get info for pre import step
- * @param string $file
- * @param array $options
- * @return array
- */
- public function getInfo($file, $options)
- {
- $options = $this->app->data->create($options);
-
- $info = array();
-
- // get applications
- $applist = JBModelApp::model()->getList();
- if (!empty($applist)) {
- $info['applist'] = array();
- foreach ($applist as $app) {
- $info['applist'][$app->id] = $app->name;
- }
-
- reset($applist);
- $application = current($applist);
-
- $info['app'] = current($applist);
- }
-
- // get types
- $info['types'] = array();
- foreach ($info['app']->getTypes() as $type) {
- $info['types'][$type->id] = array();
-
- foreach ($type->getElements() as $element) {
- // filter elements
- $info['types'][$type->id][$element->getElementType()][] = $element;
- }
-
- }
-
- $info['item_count'] = 0;
- $info['columns'] = array();
-
- // get params
- $separator = $options->get('separator', ',') ? $options->get('separator', ',') : ',';
- $enclosure = $options->get('enclosure', '"') ? $options->get('enclosure', '"') : '"';
- $containsHeaders = (int)$options->get('header', 1);
-
- // get column names and row count
- $rowCount = 0;
- if (($handle = fopen($file, "r")) !== false) {
-
- while (($data = fgetcsv($handle, 0, $separator, $enclosure)) !== false) {
-
- if ($rowCount == 0) {
- if ($containsHeaders) {
- $info['columns'] = $data;
- } else {
- $info['columns'] = array_fill(0, count($data), '');
- }
- }
-
- $rowCount++;
- }
- fclose($handle);
- }
-
- $info['count'] = $containsHeaders ? $rowCount - 1 : $rowCount;
-
- return $info;
- }
-
- /**
- * @param $info
- * @return array
- */
- public function itemsControls($info)
- {
- $html = array();
- $htmlHelper = $this->app->html;
-
- $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_APP') . ' -'));
- $options += $info['applist'];
- $html['apps'] = $htmlHelper->_('select.genericlist', $options, 'appid');
-
- $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_TYPE') . ' -'));
- $html['types'] = $htmlHelper->_('zoo.typelist', $info['app'], $options, 'typeid', null, 'value', 'text');
-
- $html['fields_types'] = array();
- foreach ($info['types'] as $typeid => $element_types) {
- $html['fields_types'][$typeid] = $this->_createItemsControl($typeid, $element_types);
- }
-
- // lose control
- $loseOptions = array(
- $htmlHelper->_('select.option', self::LOSE_NONE, JText::_('JBZOO_IMPORT_LOSE_NONE')),
- $htmlHelper->_('select.option', self::LOSE_DISABLE, JText::_('JBZOO_IMPORT_LOSE_DISABLE')),
- $htmlHelper->_('select.option', self::LOSE_REMOVE, JText::_('JBZOO_IMPORT_LOSE_REMOVE')),
- );
- $html['lose'] = $htmlHelper->_('select.genericlist', $loseOptions, 'lose');
-
- // what field is key
- $keyOptions = array(
- $htmlHelper->_('select.option', self::KEY_NONE, JText::_('JBZOO_IMPORT_KEY_NONE')),
- $htmlHelper->_('select.option', self::KEY_ID, JText::_('JBZOO_IMPORT_KEY_ID')),
- $htmlHelper->_('select.option', self::KEY_NAME, JText::_('JBZOO_IMPORT_KEY_NAME')),
- $htmlHelper->_('select.option', self::KEY_ALIAS, JText::_('JBZOO_IMPORT_KEY_ALIAS')),
- $htmlHelper->_('select.option', self::KEY_SKU, JText::_('JBZOO_IMPORT_KEY_SKU')),
- );
- $html['key'] = $htmlHelper->_('select.genericlist', $keyOptions, 'key');
-
- // check options config
- $checkOptions = array(
- $htmlHelper->_('select.option', self::OPTIONS_NO, JText::_('JBZOO_IMPORT_CHECK_OPTION_NO')),
- $htmlHelper->_('select.option', self::OPTIONS_YES, JText::_('JBZOO_IMPORT_CHECK_OPTION_YES')),
- );
- $html['checkOptions'] = $htmlHelper->_('select.genericlist', $checkOptions, 'checkOptions');
-
- return $html;
- }
-
- /**
- * @param $info
- * @return array
- */
- public function categoriesControls($info)
- {
- $html = array();
- $htmlHelper = $this->app->html;
-
- $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_APP') . ' -'));
- $options += $info['applist'];
- $html['apps'] = $htmlHelper->_('select.genericlist', $options, 'appid');
-
- $html['fields_types'] = $this->_createCategoriesControl('categoryFileds');
-
- // lose control
- $loseOptions = array(
- $htmlHelper->_('select.option', self::LOSE_NONE, JText::_('JBZOO_IMPORT_LOSE_NONE')),
- $htmlHelper->_('select.option', self::LOSE_DISABLE, JText::_('JBZOO_IMPORT_LOSE_DISABLE')),
- $htmlHelper->_('select.option', self::LOSE_REMOVE, JText::_('JBZOO_IMPORT_LOSE_REMOVE')),
- );
- $html['lose'] = $htmlHelper->_('select.genericlist', $loseOptions, 'lose');
-
- // what field is key
- $keyOptions = array(
- $htmlHelper->_('select.option', self::KEY_NONE, JText::_('JBZOO_IMPORT_KEY_NONE')),
- $htmlHelper->_('select.option', self::KEY_ID, JText::_('JBZOO_IMPORT_KEY_ID')),
- $htmlHelper->_('select.option', self::KEY_NAME, JText::_('JBZOO_IMPORT_KEY_NAME')),
- $htmlHelper->_('select.option', self::KEY_ALIAS, JText::_('JBZOO_IMPORT_KEY_ALIAS')),
- );
- $html['key'] = $htmlHelper->_('select.genericlist', $keyOptions, 'key');
-
- return $html;
- }
-
- /**
- * Create fields control for item
- * @param $typeid
- * @param $elementTypes
- */
- protected function _createItemsControl($typeid, $elementTypes)
- {
- $htmlHelper = $this->app->html;
-
- $fields = $this->app->jbcsvmapper->getItemFields($elementTypes);
- $options = array($htmlHelper->_('select.option', '', ' ** '));
-
- foreach ($fields as $groupKey => $group) {
-
- $options[] = $htmlHelper->_('select.option', '');
- }
-
- return $htmlHelper->_(
- 'select.genericlist',
- $options,
- 'assign[' . $typeid . '][__name_placeholder__]',
- 'class="type-select type-select-' . $typeid . '"'
- );
- }
-
- /**
- * Create fields control for category
- */
- protected function _createCategoriesControl()
- {
- $htmlHelper = $this->app->html;
-
- $fields = $this->app->jbcsvmapper->getCategoryFields();
- $options = array($htmlHelper->_('select.option', '', ' ** '));
-
- foreach ($fields as $groupKey => $group) {
-
- $options[] = $htmlHelper->_('select.option', '');
- }
-
- return $htmlHelper->_('select.genericlist', $options, 'assign[]', 'class="type-select"');
- }
-
- /**
- * @return string
- */
- public function getTmpFilename()
- {
- $tmp = $this->app->path->path('tmp:');
- return JPath::clean($tmp . '/' . uniqid('jbimport_') . '.csv');
- }
-
- /**
- * Get import data from session
- * @return JSONData
- */
- protected function _initSessionData()
- {
- $data = $this->app->jbsession->getGroup('import');
- $this->_data = $this->app->data->create($data);
-
- return $this->_data;
- }
-
- /**
- * Get last line in CSV file
- * @param int $step
- * @return int
- */
- protected function _getLastLine($step = 0)
- {
- $lastLine = self::STEP_SIZE * $step;
- if ((int)$this->_data->header) {
- $lastLine++;
- }
-
- return $lastLine;
- }
-
- /**
- * Get lines from CSV file for current step
- * @param string $file
- * @param int $lastLine
- * @return array
- */
- protected function _getCSVLines($file, $lastLine)
- {
- return $this->app->jbcsv->getLinesfromFile($file, $this->_data, $lastLine, self::STEP_SIZE);
- }
-
- /**
- * Process one Item row
- * @param array $row
- * @param int $lineKey
- * @return int
- */
- protected function _processItemRow($row, $lineKey)
- {
- // create item
- $item = $this->_getItemByKey($row, $lineKey);
-
- $positions = array();
-
- // bind import data from CSV
- foreach ($this->_data->assign as $colKey => $itemField) {
-
- $itemField = JString::trim($itemField);
- if (!empty($itemField)) {
-
- $value = isset($row[$colKey]) ? $row[$colKey] : null;
-
- $fieldInfo = $this->app->jbcsvmapper->itemFieldToMeta($itemField);
-
- $positionKey = implode('__', $fieldInfo);
- if (!isset($positions[$positionKey])) {
- $positions[$positionKey] = 0;
- }
- $positions[$positionKey]++;
-
- $cellElem = $this->app->jbcsvcell->createItem($fieldInfo['name'], $item, $fieldInfo['group'], $fieldInfo);
- $cellElem->fromCSV($value, $positions[$positionKey]);
- }
- }
-
- $id = $item->id;
-
- // save all changes
- $item->getParams()->set('jbzoo.no_index', 0);
- $this->app->table->item->save($item);
-
- // clean memory
- unset($item);
-
- return $id;
- }
-
- /**
- * Process one Category row
- * @param array $row
- * @param int $lineKey
- * @return int
- */
- protected function _processCategoryRow($row, $lineKey)
- {
- // create item
- $category = $this->_getCategoryByKey($row, $lineKey);
-
- // bind import data from CSV
- foreach ($this->_data->assign as $colKey => $itemField) {
-
- $itemField = JString::trim($itemField);
- if (!empty($itemField)) {
-
- $value = isset($row[$colKey]) ? $row[$colKey] : null;
-
- $fieldInfo = $this->app->jbcsvmapper->categoryFieldToMeta($itemField);
- $positionKey = implode('__', $fieldInfo);
-
- $cellElem = $this->app->jbcsvcell->createCategory($fieldInfo['name'], $category, $fieldInfo['group'], $fieldInfo);
- $cellElem->fromCSV($value);
- }
- }
-
- $id = $category->id;
-
- // save all changes
- $this->app->table->category->save($category);
-
- // clean memory
- unset($category);
-
- return $id;
- }
-
- /**
- * Get key field value
- * @param array $row
- * @param string $lineKey
- * @return Item
- */
- protected function _getItemByKey($row, $lineKey = null)
- {
- $item = null;
-
- if ($this->_data->key != self::KEY_NONE) {
- foreach ($this->_data->assign as $csvKey => $fieldName) {
-
- if ($this->_data->key == self::KEY_ID && $fieldName == 'id') {
- $item = JBModelItem::model()->getById(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
-
- } else if ($this->_data->key == self::KEY_NAME && $fieldName == 'name') {
- $item = JBModelItem::model()->getByName(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
-
- } else if ($this->_data->key == self::KEY_ALIAS && $fieldName == 'alias') {
- $item = JBModelItem::model()->getByAlias(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
-
- } else if ($this->_data->key == self::KEY_SKU && $fieldName == 'sku') {
- $item = JBModelItem::model()->getBySku(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
- }
- }
- }
-
- if (!$item) {
- $item = JBModelItem::model()->createEmpty($this->_data->appid, $this->_data->typeid, $lineKey);
- }
-
- return $item;
- }
-
- /**
- * Get key field value
- * @param array $row
- * @param string $lineKey
- * @return Item
- */
- protected function _getCategoryByKey($row, $lineKey = null)
- {
- $category = null;
-
- if ($this->_data->key != self::KEY_NONE) {
- foreach ($this->_data->assign as $csvKey => $fieldName) {
-
- if ($this->_data->key == self::KEY_ID && $fieldName == 'id') {
- $category = JBModelCategory::model()->getById(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
-
- } else if ($this->_data->key == self::KEY_NAME && $fieldName == 'name') {
- $category = JBModelCategory::model()->getByName(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
-
- } else if ($this->_data->key == self::KEY_ALIAS && $fieldName == 'alias') {
- $category = JBModelCategory::model()->getByAlias(JString::trim($row[$csvKey]), $this->_data->appid);
- break;
- }
- }
- }
-
- if (!$category) {
- $category = JBModelCategory::model()->createEmpty($this->_data->appid, $lineKey);
- }
-
- return $category;
- }
-
- /**
- * One step precess for items
- * @param int $step
- * @return array
- */
- public function itemsProcess($step = 0)
- {
- $this->_initSessionData();
-
- $lastLine = $this->_getLastLine($step);
- $lines = $this->_getCSVLines($this->_data->file, $lastLine, $step);
-
- $lineKey = 0;
- $addedIds = ($step == 0) ? array() : $this->app->jbsession->get('ids', 'import-ids');
-
- if (!empty($lines)) {
- foreach ($lines as $key => $row) {
- $lineKey = $lastLine + $key;
- $addedIds[] = $this->_processItemRow($row, $lineKey);
- }
- }
-
- $this->app->jbsession->set('ids', $addedIds, 'import-ids');
-
- return array('progress' => round(($lineKey / $this->_data->count) * 100, 2));
- }
-
- /**
- * One step precess for categories
- * @param int $step
- * @return array
- */
- public function categoriesProcess($step = 0)
- {
- $this->_initSessionData();
-
- $lastLine = $this->_getLastLine($step);
- $lines = $this->_getCSVLines($this->_data->file, $lastLine, $step);
-
- $lineKey = 0;
- $addedIds = ($step == 0) ? array() : $this->app->jbsession->get('ids', 'import-ids');
-
- if (!empty($lines)) {
- foreach ($lines as $key => $row) {
- $lineKey = $lastLine + $key;
- $addedIds[] = $this->_processCategoryRow($row, $lineKey);
- }
- }
-
- $this->app->jbsession->set('ids', $addedIds, 'import-ids');
-
- return array('progress' => round(($lineKey / $this->_data->count) * 100, 2));
- }
-
- /**
- * Call after all items loaded
- */
- public function itemsPostProcess()
- {
- $addedIds = $this->app->jbsession->get('ids', 'import-ids');
- $this->_initSessionData();
-
- if ($this->_data->lose == self::LOSE_DISABLE) {
- JBModelItem::model()->disableAll($this->_data->appid, $this->_data->typeid, $addedIds);
-
- } else if ($this->_data->lose == self::LOSE_REMOVE) {
- JBModelItem::model()->removeAll($this->_data->appid, $this->_data->typeid, $addedIds);
- }
-
- $this->app->jbsession->clearGroup('import-ids');
- }
-
- /**
- * Call after all items loaded
- */
- public function categoriesPostProcess()
- {
- $addedIds = $this->app->jbsession->get('ids', 'import-ids');
- $this->_initSessionData();
-
- if ($this->_data->lose == self::LOSE_DISABLE) {
- JBModelCategory::model()->disableAll($this->_data->appid, $addedIds);
-
- } else if ($this->_data->lose == self::LOSE_REMOVE) {
- JBModelCategory::model()->removeAll($this->_data->appid, $addedIds);
- }
-
- $this->app->jbsession->clearGroup('import-ids');
- }
-
-
-}
+
+ */
+
+// no direct access
+defined('_JEXEC') or die('Restricted access');
+
+
+/**
+ * Class JBImportHelper
+ */
+class JBImportHelper extends AppHelper
+{
+ const STEP_SIZE = 20;
+
+ const LOSE_NONE = 0;
+ const LOSE_DISABLE = 1;
+ const LOSE_REMOVE = 2;
+
+ const KEY_NONE = 0;
+ const KEY_ID = 1;
+ const KEY_NAME = 2;
+ const KEY_ALIAS = 3;
+ const KEY_SKU = 4;
+
+ const OPTIONS_NO = 0;
+ const OPTIONS_YES = 1;
+
+ /**
+ * @var JSONData
+ */
+ protected $_data = null;
+
+ /**
+ * @param App $app
+ */
+ public function __construct($app)
+ {
+ parent::__construct($app);
+
+ // make sure the line endings are recognized irrespective of the OS
+ $this->app->jbenv->maxPerfomance();
+ ini_set('auto_detect_line_endings', true);
+ }
+
+ /**
+ * Get info for pre import step
+ * @param string $file
+ * @param array $options
+ * @return array
+ */
+ public function getInfo($file, $options)
+ {
+ $options = $this->app->data->create($options);
+
+ $info = array();
+
+ // get applications
+ $applist = JBModelApp::model()->getList();
+ if (!empty($applist)) {
+ $info['applist'] = array();
+ foreach ($applist as $app) {
+ $info['applist'][$app->id] = $app->name;
+ }
+
+ reset($applist);
+ $application = current($applist);
+
+ $info['app'] = current($applist);
+ }
+
+ // get types
+ $info['types'] = array();
+ foreach ($info['app']->getTypes() as $type) {
+ $info['types'][$type->id] = array();
+
+ foreach ($type->getElements() as $element) {
+ // filter elements
+ $info['types'][$type->id][$element->getElementType()][] = $element;
+ }
+
+ }
+
+ $info['item_count'] = 0;
+ $info['columns'] = array();
+
+ // get params
+ $separator = $options->get('separator', ',') ? $options->get('separator', ',') : ',';
+ $enclosure = $options->get('enclosure', '"') ? $options->get('enclosure', '"') : '"';
+ $containsHeaders = (int)$options->get('header', 1);
+
+ // get column names and row count
+ $rowCount = 0;
+ if (($handle = fopen($file, "r")) !== false) {
+
+ while (($data = fgetcsv($handle, 0, $separator, $enclosure)) !== false) {
+
+ if ($rowCount == 0) {
+ if ($containsHeaders) {
+ $info['columns'] = $data;
+ } else {
+ $info['columns'] = array_fill(0, count($data), '');
+ }
+ }
+
+ $rowCount++;
+ }
+ fclose($handle);
+ }
+
+ $info['count'] = $containsHeaders ? $rowCount - 1 : $rowCount;
+
+ return $info;
+ }
+
+ /**
+ * @param $info
+ * @return array
+ */
+ public function itemsControls($info)
+ {
+ $html = array();
+ $htmlHelper = $this->app->html;
+
+ $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_APP') . ' -'));
+ $options += $info['applist'];
+ $html['apps'] = $htmlHelper->_('select.genericlist', $options, 'appid');
+
+ $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_TYPE') . ' -'));
+ $html['types'] = $htmlHelper->_('zoo.typelist', $info['app'], $options, 'typeid', null, 'value', 'text');
+
+ $html['fields_types'] = array();
+ foreach ($info['types'] as $typeid => $element_types) {
+ $html['fields_types'][$typeid] = $this->_createItemsControl($typeid, $element_types);
+ }
+
+ // lose control
+ $loseOptions = array(
+ $htmlHelper->_('select.option', self::LOSE_NONE, JText::_('JBZOO_IMPORT_LOSE_NONE')),
+ $htmlHelper->_('select.option', self::LOSE_DISABLE, JText::_('JBZOO_IMPORT_LOSE_DISABLE')),
+ $htmlHelper->_('select.option', self::LOSE_REMOVE, JText::_('JBZOO_IMPORT_LOSE_REMOVE')),
+ );
+ $html['lose'] = $htmlHelper->_('select.genericlist', $loseOptions, 'lose');
+
+ // what field is key
+ $keyOptions = array(
+ $htmlHelper->_('select.option', self::KEY_NONE, JText::_('JBZOO_IMPORT_KEY_NONE')),
+ $htmlHelper->_('select.option', self::KEY_ID, JText::_('JBZOO_IMPORT_KEY_ID')),
+ $htmlHelper->_('select.option', self::KEY_NAME, JText::_('JBZOO_IMPORT_KEY_NAME')),
+ $htmlHelper->_('select.option', self::KEY_ALIAS, JText::_('JBZOO_IMPORT_KEY_ALIAS')),
+ $htmlHelper->_('select.option', self::KEY_SKU, JText::_('JBZOO_IMPORT_KEY_SKU')),
+ );
+ $html['key'] = $htmlHelper->_('select.genericlist', $keyOptions, 'key');
+
+ // check options config
+ $checkOptions = array(
+ $htmlHelper->_('select.option', self::OPTIONS_NO, JText::_('JBZOO_IMPORT_CHECK_OPTION_NO')),
+ $htmlHelper->_('select.option', self::OPTIONS_YES, JText::_('JBZOO_IMPORT_CHECK_OPTION_YES')),
+ );
+ $html['checkOptions'] = $htmlHelper->_('select.genericlist', $checkOptions, 'checkOptions');
+
+ return $html;
+ }
+
+ /**
+ * @param $info
+ * @return array
+ */
+ public function categoriesControls($info)
+ {
+ $html = array();
+ $htmlHelper = $this->app->html;
+
+ $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_APP') . ' -'));
+ $options += $info['applist'];
+ $html['apps'] = $htmlHelper->_('select.genericlist', $options, 'appid');
+
+ $html['fields_types'] = $this->_createCategoriesControl('categoryFileds');
+
+ // lose control
+ $loseOptions = array(
+ $htmlHelper->_('select.option', self::LOSE_NONE, JText::_('JBZOO_IMPORT_LOSE_NONE')),
+ $htmlHelper->_('select.option', self::LOSE_DISABLE, JText::_('JBZOO_IMPORT_LOSE_DISABLE')),
+ $htmlHelper->_('select.option', self::LOSE_REMOVE, JText::_('JBZOO_IMPORT_LOSE_REMOVE')),
+ );
+ $html['lose'] = $htmlHelper->_('select.genericlist', $loseOptions, 'lose');
+
+ // what field is key
+ $keyOptions = array(
+ $htmlHelper->_('select.option', self::KEY_NONE, JText::_('JBZOO_IMPORT_KEY_NONE')),
+ $htmlHelper->_('select.option', self::KEY_ID, JText::_('JBZOO_IMPORT_KEY_ID')),
+ $htmlHelper->_('select.option', self::KEY_NAME, JText::_('JBZOO_IMPORT_KEY_NAME')),
+ $htmlHelper->_('select.option', self::KEY_ALIAS, JText::_('JBZOO_IMPORT_KEY_ALIAS')),
+ );
+ $html['key'] = $htmlHelper->_('select.genericlist', $keyOptions, 'key');
+
+ return $html;
+ }
+
+ /**
+ * Create fields control for item
+ * @param $typeid
+ * @param $elementTypes
+ */
+ protected function _createItemsControl($typeid, $elementTypes)
+ {
+ $htmlHelper = $this->app->html;
+
+ $fields = $this->app->jbcsvmapper->getItemFields($elementTypes);
+ $options = array($htmlHelper->_('select.option', '', ' ** '));
+
+ foreach ($fields as $groupKey => $group) {
+
+ $options[] = $htmlHelper->_('select.option', '');
+ }
+
+ return $htmlHelper->_(
+ 'select.genericlist',
+ $options,
+ 'assign[' . $typeid . '][__name_placeholder__]',
+ 'class="type-select type-select-' . $typeid . '"'
+ );
+ }
+
+ /**
+ * Create fields control for category
+ */
+ protected function _createCategoriesControl()
+ {
+ $htmlHelper = $this->app->html;
+
+ $fields = $this->app->jbcsvmapper->getCategoryFields();
+ $options = array($htmlHelper->_('select.option', '', ' ** '));
+
+ foreach ($fields as $groupKey => $group) {
+
+ $options[] = $htmlHelper->_('select.option', '');
+ }
+
+ return $htmlHelper->_('select.genericlist', $options, 'assign[]', 'class="type-select"');
+ }
+
+ /**
+ * @return string
+ */
+ public function getTmpFilename()
+ {
+ $tmp = $this->app->path->path('tmp:');
+ return JPath::clean($tmp . '/' . uniqid('jbimport_') . '.csv');
+ }
+
+ /**
+ * Get import data from session
+ * @return JSONData
+ */
+ protected function _initSessionData()
+ {
+ $data = $this->app->jbsession->getGroup('import');
+ $this->_data = $this->app->data->create($data);
+
+ return $this->_data;
+ }
+
+ /**
+ * Get last line in CSV file
+ * @param int $step
+ * @return int
+ */
+ protected function _getLastLine($step = 0)
+ {
+ $lastLine = self::STEP_SIZE * $step;
+ if ((int)$this->_data->header) {
+ $lastLine++;
+ }
+
+ return $lastLine;
+ }
+
+ /**
+ * Get lines from CSV file for current step
+ * @param string $file
+ * @param int $lastLine
+ * @return array
+ */
+ protected function _getCSVLines($file, $lastLine)
+ {
+ return $this->app->jbcsv->getLinesfromFile($file, $this->_data, $lastLine, self::STEP_SIZE);
+ }
+
+ /**
+ * Process one Item row
+ * @param array $row
+ * @param int $lineKey
+ * @return int
+ */
+ protected function _processItemRow($row, $lineKey)
+ {
+ // create item
+ $item = $this->_getItemByKey($row, $lineKey);
+
+ $positions = array();
+
+ // bind import data from CSV
+ foreach ($this->_data->assign as $colKey => $itemField) {
+
+ $itemField = JString::trim($itemField);
+ if (!empty($itemField)) {
+
+ $value = isset($row[$colKey]) ? $row[$colKey] : null;
+
+ $fieldInfo = $this->app->jbcsvmapper->itemFieldToMeta($itemField);
+
+ $positionKey = implode('__', $fieldInfo);
+ if (!isset($positions[$positionKey])) {
+ $positions[$positionKey] = 0;
+ }
+ $positions[$positionKey]++;
+
+ $cellElem = $this->app->jbcsvcell->createItem($fieldInfo['name'], $item, $fieldInfo['group'], $fieldInfo);
+ $cellElem->fromCSV($value, $positions[$positionKey]);
+ }
+ }
+
+ $id = $item->id;
+
+ // save all changes
+ $item->getParams()->set('jbzoo.no_index', 0);
+ $this->app->table->item->save($item);
+
+ // clean memory
+ unset($item);
+
+ return $id;
+ }
+
+ /**
+ * Process one Category row
+ * @param array $row
+ * @param int $lineKey
+ * @return int
+ */
+ protected function _processCategoryRow($row, $lineKey)
+ {
+ // create item
+ $category = $this->_getCategoryByKey($row, $lineKey);
+
+ // bind import data from CSV
+ foreach ($this->_data->assign as $colKey => $itemField) {
+
+ $itemField = JString::trim($itemField);
+ if (!empty($itemField)) {
+
+ $value = isset($row[$colKey]) ? $row[$colKey] : null;
+
+ $fieldInfo = $this->app->jbcsvmapper->categoryFieldToMeta($itemField);
+ $positionKey = implode('__', $fieldInfo);
+
+ $cellElem = $this->app->jbcsvcell->createCategory($fieldInfo['name'], $category, $fieldInfo['group'], $fieldInfo);
+ $cellElem->fromCSV($value);
+ }
+ }
+
+ $id = $category->id;
+
+ // save all changes
+ $this->app->table->category->save($category);
+
+ // clean memory
+ unset($category);
+
+ return $id;
+ }
+
+ /**
+ * Get key field value
+ * @param array $row
+ * @param string $lineKey
+ * @return Item
+ */
+ protected function _getItemByKey($row, $lineKey = null)
+ {
+ $item = null;
+
+ if ($this->_data->key != self::KEY_NONE) {
+ foreach ($this->_data->assign as $csvKey => $fieldName) {
+
+ if ($this->_data->key == self::KEY_ID && $fieldName == 'id') {
+ $item = JBModelItem::model()->getById(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+
+ } else if ($this->_data->key == self::KEY_NAME && $fieldName == 'name') {
+ $item = JBModelItem::model()->getByName(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+
+ } else if ($this->_data->key == self::KEY_ALIAS && $fieldName == 'alias') {
+ $item = JBModelItem::model()->getByAlias(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+
+ } else if ($this->_data->key == self::KEY_SKU && $fieldName == 'sku') {
+ $item = JBModelItem::model()->getBySku(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+ }
+ }
+ }
+
+ if (!$item) {
+ $item = JBModelItem::model()->createEmpty($this->_data->appid, $this->_data->typeid, $lineKey);
+ }
+
+ return $item;
+ }
+
+ /**
+ * Get key field value
+ * @param array $row
+ * @param string $lineKey
+ * @return Item
+ */
+ protected function _getCategoryByKey($row, $lineKey = null)
+ {
+ $category = null;
+
+ if ($this->_data->key != self::KEY_NONE) {
+ foreach ($this->_data->assign as $csvKey => $fieldName) {
+
+ if ($this->_data->key == self::KEY_ID && $fieldName == 'id') {
+ $category = JBModelCategory::model()->getById(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+
+ } else if ($this->_data->key == self::KEY_NAME && $fieldName == 'name') {
+ $category = JBModelCategory::model()->getByName(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+
+ } else if ($this->_data->key == self::KEY_ALIAS && $fieldName == 'alias') {
+ $category = JBModelCategory::model()->getByAlias(JString::trim($row[$csvKey]), $this->_data->appid);
+ break;
+ }
+ }
+ }
+
+ if (!$category) {
+ $category = JBModelCategory::model()->createEmpty($this->_data->appid, $lineKey);
+ }
+
+ return $category;
+ }
+
+ /**
+ * One step precess for items
+ * @param int $step
+ * @return array
+ */
+ public function itemsProcess($step = 0)
+ {
+ $this->_initSessionData();
+
+ $lastLine = $this->_getLastLine($step);
+ $lines = $this->_getCSVLines($this->_data->file, $lastLine, $step);
+
+ $lineKey = 0;
+ $addedIds = ($step == 0) ? array() : $this->app->jbsession->get('ids', 'import-ids');
+
+ if (!empty($lines)) {
+ foreach ($lines as $key => $row) {
+ $lineKey = $lastLine + $key;
+ $addedIds[] = $this->_processItemRow($row, $lineKey);
+ }
+ }
+
+ $this->app->jbsession->set('ids', $addedIds, 'import-ids');
+
+ return array('progress' => round(($lineKey / $this->_data->count) * 100, 2));
+ }
+
+ /**
+ * One step precess for categories
+ * @param int $step
+ * @return array
+ */
+ public function categoriesProcess($step = 0)
+ {
+ $this->_initSessionData();
+
+ $lastLine = $this->_getLastLine($step);
+ $lines = $this->_getCSVLines($this->_data->file, $lastLine, $step);
+
+ $lineKey = 0;
+ $addedIds = ($step == 0) ? array() : $this->app->jbsession->get('ids', 'import-ids');
+
+ if (!empty($lines)) {
+ foreach ($lines as $key => $row) {
+ $lineKey = $lastLine + $key;
+ $addedIds[] = $this->_processCategoryRow($row, $lineKey);
+ }
+ }
+
+ $this->app->jbsession->set('ids', $addedIds, 'import-ids');
+
+ return array('progress' => round(($lineKey / $this->_data->count) * 100, 2));
+ }
+
+ /**
+ * Call after all items loaded
+ */
+ public function itemsPostProcess()
+ {
+ $addedIds = $this->app->jbsession->get('ids', 'import-ids');
+ $this->_initSessionData();
+
+ if ($this->_data->lose == self::LOSE_DISABLE) {
+ JBModelItem::model()->disableAll($this->_data->appid, $this->_data->typeid, $addedIds);
+
+ } else if ($this->_data->lose == self::LOSE_REMOVE) {
+ JBModelItem::model()->removeAll($this->_data->appid, $this->_data->typeid, $addedIds);
+ }
+
+ $this->app->jbsession->clearGroup('import-ids');
+ }
+
+ /**
+ * Call after all items loaded
+ */
+ public function categoriesPostProcess()
+ {
+ $addedIds = $this->app->jbsession->get('ids', 'import-ids');
+ $this->_initSessionData();
+
+ if ($this->_data->lose == self::LOSE_DISABLE) {
+ JBModelCategory::model()->disableAll($this->_data->appid, $addedIds);
+
+ } else if ($this->_data->lose == self::LOSE_REMOVE) {
+ JBModelCategory::model()->removeAll($this->_data->appid, $addedIds);
+ }
+
+ $this->app->jbsession->clearGroup('import-ids');
+ }
+
+
+}
diff --git a/patches/2.0.2/media/zoo/applications/jbuniversal/framework/jbzoo.php b/patches/2.0.2/media/zoo/applications/jbuniversal/framework/jbzoo.php
index df5d0fa..00eb113 100644
--- a/patches/2.0.2/media/zoo/applications/jbuniversal/framework/jbzoo.php
+++ b/patches/2.0.2/media/zoo/applications/jbuniversal/framework/jbzoo.php
@@ -1 +1,374 @@
-
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
!defined('JBZOO_APP_GROUP') && define('JBZOO_APP_GROUP', 'jbuniversal');
!defined('DIRECTORY_SEPERATOR') && define('DIRECTORY_SEPERATOR', '/');
!defined('DS') && define('DS', DIRECTORY_SEPARATOR);
/**
* Class JBZoo
*/
class JBZoo
{
/**
* @var Application
*/
public $app = null;
/**
* App group name
* @var string
*/
private $_group = JBZOO_APP_GROUP;
/**
* Init JBZoo application
* @static
* @return JBZoo
*/
public static function init()
{
static $jbzoo;
if (!isset($jbzoo)) {
$jbzoo = new self();
}
return $jbzoo;
}
/**
* Initialization JBZoo App
*/
private function __construct()
{
$this->app = App::getInstance('zoo');
$this->_initPaths();
$this->_initConfig();
$this->_initModels();
$this->_initLanguages();
$this->_initFilterElements();
$this->_initEvents();
$this->_initAssets();
}
/**
* Add directory path
*/
private function _initPaths()
{
$this->_addPath('applications:' . $this->_getGroup(), 'jbapp');
$this->_addPath('jbapp:framework', 'jbzoo');
$this->_addPath('jbapp:assets', 'jbassets');
$this->_addPath('jbassets:zoo', 'assets');
$this->_addPath('jbapp:config', 'jbconfig');
$this->_addPath('jbzoo:elements', 'jbelements');
$this->_addPath('jbapp:types', 'jbtypes');
$this->_addPath('jbzoo:helpers', 'helpers');
$this->_addPath('jbzoo:helpers-std', 'helpers');
$this->_addPath('jbzoo:render', 'renderer');
$this->_addPath('jbzoo:controllers/views', 'jbviews');
$this->_addPath('jbapp:config', 'jbxml');
$this->_addPath('jbapp:joomla/elements', 'fields');
$this->_addPath('modules:mod_jbzoo_search', 'mod_jbzoo_search');
$this->_addPath('modules:mod_jbzoo_props', 'mod_jbzoo_props');
$this->_addPath('modules:mod_jbzoo_basket', 'mod_jbzoo_basket');
$this->_addPath('modules:mod_jbzoo_category', 'mod_jbzoo_category');
$this->_addPath('plugins:/system/jbzoo', 'plugin_jbzoo');
$this->_addPath('jbapp:templates', 'jbtmpl');
if ($this->app->jbenv->isSite()) {
$this->_addPath('jbzoo:controllers', 'controllers');
}
$this->app->jbdebug->mark('init::paths');
}
/**
* Include models classes
*/
private function _initModels()
{
// defines
define('ZOO_TABLE_JBZOO_INDEX', '#__zoo_jbzoo_index');
define('ZOO_TABLE_JBZOO_SKU', '#__zoo_jbzoo_sku');
define('ZOO_TABLE_JBZOO_FAVORITE', '#__zoo_jbzoo_favorite');
// query builder
$path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/classes';
require $path . '/database/JBDatabaseQuery.php';
require $path . '/database/JBDatabaseQueryElement.php';
// models
$path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/models';
require $path . '/jbmodel.php';
require $path . '/jbmodel.element.php';
require $path . '/jbmodel.autocomplete.php';
require $path . '/jbmodel.element.country.php';
require $path . '/jbmodel.element.itemdate.php';
require $path . '/jbmodel.element.itemauthor.php';
require $path . '/jbmodel.element.itemcategory.php';
require $path . '/jbmodel.element.itemcreated.php';
require $path . '/jbmodel.element.itemfrontpage.php';
require $path . '/jbmodel.element.itemmodified.php';
require $path . '/jbmodel.element.itemname.php';
require $path . '/jbmodel.element.itempublish_down.php';
require $path . '/jbmodel.element.itempublish_up.php';
require $path . '/jbmodel.element.itemtag.php';
require $path . '/jbmodel.element.jbimage.php';
require $path . '/jbmodel.element.jbselectcascade.php';
require $path . '/jbmodel.element.range.php';
require $path . '/jbmodel.element.rating.php';
require $path . '/jbmodel.element.jbpriceadvance.php';
require $path . '/jbmodel.favorite.php';
require $path . '/jbmodel.filter.php';
require $path . '/jbmodel.item.php';
require $path . '/jbmodel.app.php';
require $path . '/jbmodel.category.php';
require $path . '/jbmodel.order.php';
require $path . '/jbmodel.related.php';
require $path . '/jbmodel.searchindex.php';
require $path . '/jbmodel.values.php';
require $path . '/jbmodel.sku.php';
}
/**
* Load lang files
*/
private function _initLanguages()
{
$lang = JFactory::getLanguage();
$lang->load('com_zoo');
$lang->load('com_jbzoo', $this->app->path->path('jbapp:'), null, true);
$lang->load('com_zoo', JPATH_ADMINISTRATOR);
}
/**
* Load others libraries
*/
private function _initFilterElements()
{
jimport('joomla.html.parameter.element');
$path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/render/filter';
require $path . '/element.php';
require $path . '/element.author.php';
require $path . '/element.author.checkbox.php';
require $path . '/element.author.radio.php';
require $path . '/element.author.select.php';
require $path . '/element.author.select.chosen.php';
require $path . '/element.author.text.php';
require $path . '/element.category.php';
require $path . '/element.category.chosen.php';
require $path . '/element.checkbox.php';
require $path . '/element.country.php';
require $path . '/element.country.checkbox.php';
require $path . '/element.country.radio.php';
require $path . '/element.country.select.php';
require $path . '/element.country.select.chosen.php';
require $path . '/element.date.php';
require $path . '/element.date.range.php';
require $path . '/element.frontpage.php';
require $path . '/element.frontpage.jqueryui.php';
require $path . '/element.hidden.php';
require $path . '/element.imageexists.php';
require $path . '/element.imageexists.jqueryui.php';
require $path . '/element.jbselectcascade.php';
require $path . '/element.jqueryui.php';
require $path . '/element.name.php';
require $path . '/element.name.checkbox.php';
require $path . '/element.name.radio.php';
require $path . '/element.name.select.php';
require $path . '/element.name.select.chosen.php';
require $path . '/element.radio.php';
require $path . '/element.rating.php';
require $path . '/element.rating.ranges.php';
require $path . '/element.rating.slider.php';
require $path . '/element.select.php';
require $path . '/element.select.chosen.php';
require $path . '/element.slider.php';
require $path . '/element.tag.php';
require $path . '/element.tag.checkbox.php';
require $path . '/element.tag.radio.php';
require $path . '/element.tag.select.php';
require $path . '/element.tag.select.chosen.php';
require $path . '/element.text.php';
require $path . '/element.text.range.php';
}
/**
* Register and connect events
*/
private function _initEvents()
{
$path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/events';
require $path . '/jbevent.php';
require $path . '/jbevent.application.php';
require $path . '/jbevent.basket.php';
require $path . '/jbevent.category.php';
require $path . '/jbevent.comment.php';
require $path . '/jbevent.element.php';
require $path . '/jbevent.item.php';
require $path . '/jbevent.jbzoo.php';
require $path . '/jbevent.layout.php';
require $path . '/jbevent.submission.php';
require $path . '/jbevent.tag.php';
require $path . '/jbevent.type.php';
require $path . '/jbevent.payment.php';
$event = $this->app->event;
$dispatcher = $event->dispatcher;
$event->register('JBEventApplication');
$dispatcher->connect('application:init', array('JBEventApplication', 'init'));
$dispatcher->connect('application:saved', array('JBEventApplication', 'saved'));
$dispatcher->connect('application:deleted', array('JBEventApplication', 'deleted'));
$event->register('JBEventCategory');
$dispatcher->connect('category:init', array('JBEventCategory', 'init'));
$dispatcher->connect('category:saved', array('JBEventCategory', 'saved'));
$dispatcher->connect('category:deleted', array('JBEventCategory', 'deleted'));
$dispatcher->connect('category:stateChanged', array('JBEventCategory', 'stateChanged'));
$event->register('JBEventItem');
$dispatcher->connect('item:init', array('JBEventItem', 'init'));
$dispatcher->connect('item:saved', array('JBEventItem', 'saved'));
$dispatcher->connect('item:deleted', array('JBEventItem', 'deleted'));
$dispatcher->connect('item:stateChanged', array('JBEventItem', 'stateChanged'));
$dispatcher->connect('item:beforedisplay', array('JBEventItem', 'beforeDisplay'));
$dispatcher->connect('item:afterdisplay', array('JBEventItem', 'afterDisplay'));
$event->register('JBEventComment');
$dispatcher->connect('comment:init', array('JBEventComment', 'init'));
$dispatcher->connect('comment:saved', array('JBEventComment', 'saved'));
$dispatcher->connect('comment:deleted', array('JBEventComment', 'deleted'));
$dispatcher->connect('comment:stateChanged', array('JBEventComment', 'stateChanged'));
$event->register('JBEventSubmission');
$dispatcher->connect('submission:init', array('JBEventSubmission', 'init'));
$dispatcher->connect('submission:saved', array('JBEventSubmission', 'saved'));
$dispatcher->connect('submission:deleted', array('JBEventSubmission', 'deleted'));
$dispatcher->connect('submission:beforesave', array('JBEventSubmission', 'beforeSave'));
$event->register('JBEventElement');
$dispatcher->connect('element:download', array('JBEventElement', 'download'));
$dispatcher->connect('element:configform', array('JBEventElement', 'configForm'));
$dispatcher->connect('element:configparams', array('JBEventElement', 'configParams'));
$dispatcher->connect('element:configxml', array('JBEventElement', 'configXML'));
$dispatcher->connect('element:afterdisplay', array('JBEventElement', 'afterDisplay'));
$dispatcher->connect('element:beforedisplay', array('JBEventElement', 'beforeDisplay'));
$dispatcher->connect('element:aftersubmissiondisplay', array('JBEventElement', 'afterSubmissionDisplay'));
$dispatcher->connect('element:beforesubmissiondisplay', array('JBEventElement', 'beforeSubmissionDisplay'));
$dispatcher->connect('element:beforeedit', array('JBEventElement', 'beforeEdit'));
$dispatcher->connect('element:afteredit', array('JBEventElement', 'afterEdit'));
$event->register('JBEventLayout');
$dispatcher->connect('layout:init', array('JBEventLayout', 'init'));
$event->register('JBEventTag');
$dispatcher->connect('tag:saved', array('JBEventTag', 'saved'));
$dispatcher->connect('tag:deleted', array('JBEventTag', 'deleted'));
$event->register('JBEventType');
$dispatcher->connect('type:beforesave', array('JBEventType', 'beforesave'));
$dispatcher->connect('type:aftersave', array('JBEventType', 'aftersave'));
$dispatcher->connect('type:copied', array('JBEventType', 'copied'));
$dispatcher->connect('type:deleted', array('JBEventType', 'deleted'));
$dispatcher->connect('type:editdisplay', array('JBEventType', 'editDisplay'));
$event->register('JBEventJBZoo');
$dispatcher->connect('jbzoo:beforeInit', array('JBEventJBZoo', 'beforeInit'));
$dispatcher->notify($event->create($this, 'jbzoo:beforeInit'));
$event->register('JBEventBasket');
$dispatcher->connect('basket:beforesave', array('JBEventBasket', 'beforeSave'));
$dispatcher->connect('basket:saved', array('JBEventBasket', 'saved'));
$event->register('JBEventPayment');
$dispatcher->connect('payment:callback', array('JBEventPayment', 'callback'));
}
/**
* Init assets for admin path
*/
private function _initAssets()
{
if (!$this->app->jbenv->isSite()) {
$this->app->jbassets->admin();
}
}
/**
* Init config file
*/
private function _initConfig()
{
if ($configFile = $this->app->path->path('jbapp:config/config.php')) {
require $configFile;
}
}
/**
* Get group name
* @return string
*/
private function _getGroup()
{
return $this->_group;
}
/**
* Register new path in system
* @param string $path
* @param string $pathName
* @return mixed
*/
private function _addPath($path, $pathName)
{
if ($fullPath = $this->app->path->path($path)) {
return $this->app->path->register($fullPath, $pathName);
}
return null;
}
/**
* Get domain name
* @param bool $isAny
* @return string
*/
static function getDomain($isAny = false)
{
$domain = '';
if (function_exists('apache_request_headers')) {
$headers = apache_request_headers();
$domain = isset($headers['Host']) ? $headers['Host'] : '';
}
if ($isAny && !$domain) {
$domain = $_SERVER['HTTP_HOST'];
}
$domain = preg_replace('#^www\.#', '', $domain);
list($domain) = explode(':', $domain);
return $domain;
}
}
\ No newline at end of file
+
+ */
+
+// no direct access
+defined('_JEXEC') or die('Restricted access');
+
+
+!defined('JBZOO_APP_GROUP') && define('JBZOO_APP_GROUP', 'jbuniversal');
+!defined('DIRECTORY_SEPERATOR') && define('DIRECTORY_SEPERATOR', '/');
+!defined('DS') && define('DS', DIRECTORY_SEPARATOR);
+
+/**
+ * Class JBZoo
+ */
+class JBZoo
+{
+ /**
+ * @var Application
+ */
+ public $app = null;
+
+ /**
+ * App group name
+ * @var string
+ */
+ private $_group = JBZOO_APP_GROUP;
+
+ /**
+ * Init JBZoo application
+ * @static
+ * @return JBZoo
+ */
+ public static function init()
+ {
+ static $jbzoo;
+
+ if (!isset($jbzoo)) {
+ $jbzoo = new self();
+ }
+
+ return $jbzoo;
+ }
+
+ /**
+ * Initialization JBZoo App
+ */
+ private function __construct()
+ {
+ $this->app = App::getInstance('zoo');
+
+ $this->_initPaths();
+ $this->_initConfig();
+ $this->_initModels();
+ $this->_initLanguages();
+ $this->_initFilterElements();
+ $this->_initEvents();
+ $this->_initAssets();
+ }
+
+ /**
+ * Add directory path
+ */
+ private function _initPaths()
+ {
+ $this->_addPath('applications:' . $this->_getGroup(), 'jbapp');
+ $this->_addPath('jbapp:framework', 'jbzoo');
+ $this->_addPath('jbapp:assets', 'jbassets');
+ $this->_addPath('jbassets:zoo', 'assets');
+ $this->_addPath('jbapp:config', 'jbconfig');
+ $this->_addPath('jbzoo:elements', 'jbelements');
+ $this->_addPath('jbapp:types', 'jbtypes');
+ $this->_addPath('jbzoo:helpers', 'helpers');
+ $this->_addPath('jbzoo:helpers-std', 'helpers');
+ $this->_addPath('jbzoo:render', 'renderer');
+ $this->_addPath('jbzoo:controllers/views', 'jbviews');
+ $this->_addPath('jbapp:config', 'jbxml');
+ $this->_addPath('jbapp:joomla/elements', 'fields');
+ $this->_addPath('modules:mod_jbzoo_search', 'mod_jbzoo_search');
+ $this->_addPath('modules:mod_jbzoo_props', 'mod_jbzoo_props');
+ $this->_addPath('modules:mod_jbzoo_basket', 'mod_jbzoo_basket');
+ $this->_addPath('modules:mod_jbzoo_category', 'mod_jbzoo_category');
+ $this->_addPath('plugins:/system/jbzoo', 'plugin_jbzoo');
+ $this->_addPath('jbapp:templates', 'jbtmpl');
+
+ if ($this->app->jbenv->isSite()) {
+ $this->_addPath('jbzoo:controllers', 'controllers');
+ }
+
+ $this->app->jbdebug->mark('init::paths');
+ }
+
+ /**
+ * Include models classes
+ */
+ private function _initModels()
+ {
+ // defines
+ define('ZOO_TABLE_JBZOO_INDEX', '#__zoo_jbzoo_index');
+ define('ZOO_TABLE_JBZOO_SKU', '#__zoo_jbzoo_sku');
+ define('ZOO_TABLE_JBZOO_FAVORITE', '#__zoo_jbzoo_favorite');
+
+ // query builder
+ $path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/classes';
+ require $path . '/database/JBDatabaseQuery.php';
+ require $path . '/database/JBDatabaseQueryElement.php';
+
+ // models
+ $path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/models';
+ require $path . '/jbmodel.php';
+ require $path . '/jbmodel.element.php';
+ require $path . '/jbmodel.autocomplete.php';
+ require $path . '/jbmodel.element.country.php';
+ require $path . '/jbmodel.element.itemdate.php';
+ require $path . '/jbmodel.element.itemauthor.php';
+ require $path . '/jbmodel.element.itemcategory.php';
+ require $path . '/jbmodel.element.itemcreated.php';
+ require $path . '/jbmodel.element.itemfrontpage.php';
+ require $path . '/jbmodel.element.itemmodified.php';
+ require $path . '/jbmodel.element.itemname.php';
+ require $path . '/jbmodel.element.itempublish_down.php';
+ require $path . '/jbmodel.element.itempublish_up.php';
+ require $path . '/jbmodel.element.itemtag.php';
+ require $path . '/jbmodel.element.jbimage.php';
+ require $path . '/jbmodel.element.jbselectcascade.php';
+ require $path . '/jbmodel.element.range.php';
+ require $path . '/jbmodel.element.rating.php';
+ require $path . '/jbmodel.element.jbpriceadvance.php';
+ require $path . '/jbmodel.favorite.php';
+ require $path . '/jbmodel.filter.php';
+ require $path . '/jbmodel.item.php';
+ require $path . '/jbmodel.app.php';
+ require $path . '/jbmodel.category.php';
+ require $path . '/jbmodel.order.php';
+ require $path . '/jbmodel.related.php';
+ require $path . '/jbmodel.searchindex.php';
+ require $path . '/jbmodel.values.php';
+ require $path . '/jbmodel.sku.php';
+ }
+
+ /**
+ * Load lang files
+ */
+ private function _initLanguages()
+ {
+ $lang = JFactory::getLanguage();
+ $lang->load('com_zoo');
+ $lang->load('com_jbzoo', $this->app->path->path('jbapp:'), null, true);
+ $lang->load('com_zoo', JPATH_ADMINISTRATOR);
+ }
+
+ /**
+ * Load others libraries
+ */
+ private function _initFilterElements()
+ {
+ jimport('joomla.html.parameter.element');
+
+ $path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/render/filter';
+ require $path . '/element.php';
+ require $path . '/element.author.php';
+ require $path . '/element.author.checkbox.php';
+ require $path . '/element.author.radio.php';
+ require $path . '/element.author.select.php';
+ require $path . '/element.author.select.chosen.php';
+ require $path . '/element.author.text.php';
+ require $path . '/element.category.php';
+ require $path . '/element.category.chosen.php';
+ require $path . '/element.checkbox.php';
+ require $path . '/element.country.php';
+ require $path . '/element.country.checkbox.php';
+ require $path . '/element.country.radio.php';
+ require $path . '/element.country.select.php';
+ require $path . '/element.country.select.chosen.php';
+ require $path . '/element.date.php';
+ require $path . '/element.date.range.php';
+ require $path . '/element.frontpage.php';
+ require $path . '/element.frontpage.jqueryui.php';
+ require $path . '/element.hidden.php';
+ require $path . '/element.imageexists.php';
+ require $path . '/element.imageexists.jqueryui.php';
+ require $path . '/element.jbselectcascade.php';
+ require $path . '/element.jqueryui.php';
+ require $path . '/element.name.php';
+ require $path . '/element.name.checkbox.php';
+ require $path . '/element.name.radio.php';
+ require $path . '/element.name.select.php';
+ require $path . '/element.name.select.chosen.php';
+ require $path . '/element.radio.php';
+ require $path . '/element.rating.php';
+ require $path . '/element.rating.ranges.php';
+ require $path . '/element.rating.slider.php';
+ require $path . '/element.select.php';
+ require $path . '/element.select.chosen.php';
+ require $path . '/element.slider.php';
+ require $path . '/element.tag.php';
+ require $path . '/element.tag.checkbox.php';
+ require $path . '/element.tag.radio.php';
+ require $path . '/element.tag.select.php';
+ require $path . '/element.tag.select.chosen.php';
+ require $path . '/element.text.php';
+ require $path . '/element.text.range.php';
+ }
+
+ /**
+ * Register and connect events
+ */
+ private function _initEvents()
+ {
+ $path = JPATH_SITE . '/media/zoo/applications/jbuniversal/framework/events';
+ require $path . '/jbevent.php';
+ require $path . '/jbevent.application.php';
+ require $path . '/jbevent.basket.php';
+ require $path . '/jbevent.category.php';
+ require $path . '/jbevent.comment.php';
+ require $path . '/jbevent.element.php';
+ require $path . '/jbevent.item.php';
+ require $path . '/jbevent.jbzoo.php';
+ require $path . '/jbevent.layout.php';
+ require $path . '/jbevent.submission.php';
+ require $path . '/jbevent.tag.php';
+ require $path . '/jbevent.type.php';
+ require $path . '/jbevent.payment.php';
+
+ $event = $this->app->event;
+ $dispatcher = $event->dispatcher;
+
+ $event->register('JBEventApplication');
+ $dispatcher->connect('application:init', array('JBEventApplication', 'init'));
+ $dispatcher->connect('application:saved', array('JBEventApplication', 'saved'));
+ $dispatcher->connect('application:deleted', array('JBEventApplication', 'deleted'));
+
+ $event->register('JBEventCategory');
+ $dispatcher->connect('category:init', array('JBEventCategory', 'init'));
+ $dispatcher->connect('category:saved', array('JBEventCategory', 'saved'));
+ $dispatcher->connect('category:deleted', array('JBEventCategory', 'deleted'));
+ $dispatcher->connect('category:stateChanged', array('JBEventCategory', 'stateChanged'));
+
+ $event->register('JBEventItem');
+ $dispatcher->connect('item:init', array('JBEventItem', 'init'));
+ $dispatcher->connect('item:saved', array('JBEventItem', 'saved'));
+ $dispatcher->connect('item:deleted', array('JBEventItem', 'deleted'));
+ $dispatcher->connect('item:stateChanged', array('JBEventItem', 'stateChanged'));
+ $dispatcher->connect('item:beforedisplay', array('JBEventItem', 'beforeDisplay'));
+ $dispatcher->connect('item:afterdisplay', array('JBEventItem', 'afterDisplay'));
+
+ $event->register('JBEventComment');
+ $dispatcher->connect('comment:init', array('JBEventComment', 'init'));
+ $dispatcher->connect('comment:saved', array('JBEventComment', 'saved'));
+ $dispatcher->connect('comment:deleted', array('JBEventComment', 'deleted'));
+ $dispatcher->connect('comment:stateChanged', array('JBEventComment', 'stateChanged'));
+
+ $event->register('JBEventSubmission');
+ $dispatcher->connect('submission:init', array('JBEventSubmission', 'init'));
+ $dispatcher->connect('submission:saved', array('JBEventSubmission', 'saved'));
+ $dispatcher->connect('submission:deleted', array('JBEventSubmission', 'deleted'));
+ $dispatcher->connect('submission:beforesave', array('JBEventSubmission', 'beforeSave'));
+
+ $event->register('JBEventElement');
+ $dispatcher->connect('element:download', array('JBEventElement', 'download'));
+ $dispatcher->connect('element:configform', array('JBEventElement', 'configForm'));
+ $dispatcher->connect('element:configparams', array('JBEventElement', 'configParams'));
+ $dispatcher->connect('element:configxml', array('JBEventElement', 'configXML'));
+ $dispatcher->connect('element:afterdisplay', array('JBEventElement', 'afterDisplay'));
+ $dispatcher->connect('element:beforedisplay', array('JBEventElement', 'beforeDisplay'));
+ $dispatcher->connect('element:aftersubmissiondisplay', array('JBEventElement', 'afterSubmissionDisplay'));
+ $dispatcher->connect('element:beforesubmissiondisplay', array('JBEventElement', 'beforeSubmissionDisplay'));
+ $dispatcher->connect('element:beforeedit', array('JBEventElement', 'beforeEdit'));
+ $dispatcher->connect('element:afteredit', array('JBEventElement', 'afterEdit'));
+
+ $event->register('JBEventLayout');
+ $dispatcher->connect('layout:init', array('JBEventLayout', 'init'));
+
+ $event->register('JBEventTag');
+ $dispatcher->connect('tag:saved', array('JBEventTag', 'saved'));
+ $dispatcher->connect('tag:deleted', array('JBEventTag', 'deleted'));
+
+ $event->register('JBEventType');
+ $dispatcher->connect('type:beforesave', array('JBEventType', 'beforesave'));
+ $dispatcher->connect('type:aftersave', array('JBEventType', 'aftersave'));
+ $dispatcher->connect('type:copied', array('JBEventType', 'copied'));
+ $dispatcher->connect('type:deleted', array('JBEventType', 'deleted'));
+ $dispatcher->connect('type:editdisplay', array('JBEventType', 'editDisplay'));
+
+ $event->register('JBEventJBZoo');
+ $dispatcher->connect('jbzoo:beforeInit', array('JBEventJBZoo', 'beforeInit'));
+ $dispatcher->notify($event->create($this, 'jbzoo:beforeInit'));
+
+ $event->register('JBEventBasket');
+ $dispatcher->connect('basket:beforesave', array('JBEventBasket', 'beforeSave'));
+ $dispatcher->connect('basket:saved', array('JBEventBasket', 'saved'));
+
+ $event->register('JBEventPayment');
+ $dispatcher->connect('payment:callback', array('JBEventPayment', 'callback'));
+ }
+
+ /**
+ * Init assets for admin path
+ */
+ private function _initAssets()
+ {
+ if (!$this->app->jbenv->isSite()) {
+ $this->app->jbassets->admin();
+ }
+ }
+
+ /**
+ * Init config file
+ */
+ private function _initConfig()
+ {
+ if ($configFile = $this->app->path->path('jbapp:config/config.php')) {
+ require $configFile;
+ }
+ }
+
+ /**
+ * Get group name
+ * @return string
+ */
+ private function _getGroup()
+ {
+ return $this->_group;
+ }
+
+ /**
+ * Register new path in system
+ * @param string $path
+ * @param string $pathName
+ * @return mixed
+ */
+ private function _addPath($path, $pathName)
+ {
+ if ($fullPath = $this->app->path->path($path)) {
+ return $this->app->path->register($fullPath, $pathName);
+ }
+
+ return null;
+ }
+
+ /**
+ * Get domain name
+ * @param bool $isAny
+ * @return string
+ */
+ static function getDomain($isAny = false)
+ {
+ $domain = '';
+ if (function_exists('apache_request_headers')) {
+ $headers = apache_request_headers();
+ $domain = isset($headers['Host']) ? $headers['Host'] : '';
+ }
+
+ if ($isAny && !$domain) {
+ $domain = $_SERVER['HTTP_HOST'];
+ }
+
+ $domain = preg_replace('#^www\.#', '', $domain);
+ list($domain) = explode(':', $domain);
+
+ return $domain;
+ }
+}
diff --git a/patches/2.1.0/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php b/patches/2.1.0/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php
index 05655a6..080058c 100644
--- a/patches/2.1.0/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php
+++ b/patches/2.1.0/media/zoo/applications/jbuniversal/framework/helpers/jbimport.php
@@ -1,567 +1,567 @@
-
- */
-
-// no direct access
-defined('_JEXEC') or die('Restricted access');
-
-
-/**
- * Class JBImportHelper
- */
-class JBImportHelper extends AppHelper
-{
- const STEP_SIZE = 50;
-
- const LOSE_NONE = 0;
- const LOSE_DISABLE = 1;
- const LOSE_REMOVE = 2;
-
- const KEY_NONE = 0;
- const KEY_ID = 1;
- const KEY_NAME = 2;
- const KEY_ALIAS = 3;
- const KEY_SKU = 4;
-
- const OPTIONS_NO = 0;
- const OPTIONS_YES = 1;
-
- /**
- * @var JSONData
- */
- protected $_data = null;
-
- /**
- * @param App $app
- */
- public function __construct($app)
- {
- parent::__construct($app);
-
- // make sure the line endings are recognized irrespective of the OS
- $this->app->jbenv->maxPerformance();
- ini_set('auto_detect_line_endings', true);
- }
-
- /**
- * Get info for pre import step
- * @param string $file
- * @param array $options
- * @return array
- */
- public function getInfo($file, $options)
- {
- $options = $this->app->data->create($options);
-
- $info = array();
-
- // get applications
- $applist = JBModelApp::model()->getList();
- if (!empty($applist)) {
- $info['applist'] = array();
- foreach ($applist as $app) {
- $info['applist'][$app->id] = $app->name;
- }
-
- reset($applist);
- $application = current($applist);
-
- $info['app'] = current($applist);
- }
-
- // get types
- $info['types'] = array();
- foreach ($info['app']->getTypes() as $type) {
- $info['types'][$type->id] = array();
-
- foreach ($type->getElements() as $element) {
- // filter elements
- $info['types'][$type->id][$element->getElementType()][] = $element;
- }
-
- }
-
- $info['item_count'] = 0;
- $info['columns'] = array();
-
- // get params
- $separator = $options->get('separator', ',') ? $options->get('separator', ',') : ',';
- $enclosure = $options->get('enclosure', '"') ? $options->get('enclosure', '"') : '"';
- $containsHeaders = (int)$options->get('header', 1);
-
- // get column names and row count
- $rowCount = 0;
- if (($handle = fopen($file, "r")) !== false) {
-
- while (($data = fgetcsv($handle, 0, $separator, $enclosure)) !== false) {
-
- if ($rowCount == 0) {
- if ($containsHeaders) {
- $info['columns'] = $data;
- } else {
- $info['columns'] = array_fill(0, count($data), '');
- }
- }
-
- $rowCount++;
- }
- fclose($handle);
- }
-
- $info['count'] = $containsHeaders ? $rowCount - 1 : $rowCount;
-
- return $info;
- }
-
- /**
- * @param $info
- * @return array
- */
- public function itemsControls($info)
- {
- $html = array();
- $htmlHelper = $this->app->html;
-
- $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_APP') . ' -'));
- $options += $info['applist'];
- $html['apps'] = $htmlHelper->_('select.genericlist', $options, 'appid');
-
- $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_TYPE') . ' -'));
- $html['types'] = $htmlHelper->_('zoo.typelist', $info['app'], $options, 'typeid', null, 'value', 'text');
-
- $html['fields_types'] = array();
- foreach ($info['types'] as $typeid => $element_types) {
- $html['fields_types'][$typeid] = $this->_createItemsControl($typeid, $element_types);
- }
-
- // lose control
- $loseOptions = array(
- $htmlHelper->_('select.option', self::LOSE_NONE, JText::_('JBZOO_IMPORT_LOSE_NONE')),
- $htmlHelper->_('select.option', self::LOSE_DISABLE, JText::_('JBZOO_IMPORT_LOSE_DISABLE')),
- $htmlHelper->_('select.option', self::LOSE_REMOVE, JText::_('JBZOO_IMPORT_LOSE_REMOVE')),
- );
- $html['lose'] = $htmlHelper->_('select.genericlist', $loseOptions, 'lose');
-
- // what field is key
- $keyOptions = array(
- $htmlHelper->_('select.option', self::KEY_NONE, JText::_('JBZOO_IMPORT_KEY_NONE')),
- $htmlHelper->_('select.option', self::KEY_ID, JText::_('JBZOO_IMPORT_KEY_ID')),
- $htmlHelper->_('select.option', self::KEY_NAME, JText::_('JBZOO_IMPORT_KEY_NAME')),
- $htmlHelper->_('select.option', self::KEY_ALIAS, JText::_('JBZOO_IMPORT_KEY_ALIAS')),
- $htmlHelper->_('select.option', self::KEY_SKU, JText::_('JBZOO_IMPORT_KEY_SKU')),
- );
- $html['key'] = $htmlHelper->_('select.genericlist', $keyOptions, 'key');
-
- // check options config
- $checkOptions = array(
- $htmlHelper->_('select.option', self::OPTIONS_NO, JText::_('JBZOO_IMPORT_CHECK_OPTION_NO')),
- $htmlHelper->_('select.option', self::OPTIONS_YES, JText::_('JBZOO_IMPORT_CHECK_OPTION_YES')),
- );
-
- $html['checkOptions'] = $htmlHelper->_('select.genericlist', $checkOptions, 'checkOptions');
-
- return $html;
- }
-
- /**
- * @param $info
- * @return array
- */
- public function categoriesControls($info)
- {
- $html = array();
- $htmlHelper = $this->app->html;
-
- $options = array($htmlHelper->_('select.option', '', '- ' . JText::_('JBZOO_SELECT_APP') . ' -'));
- $options += $info['applist'];
- $html['apps'] = $htmlHelper->_('select.genericlist', $options, 'appid');
-
- $html['fields_types'] = $this->_createCategoriesControl('categoryFileds');
-
- // lose control
- $loseOptions = array(
- $htmlHelper->_('select.option', self::LOSE_NONE, JText::_('JBZOO_IMPORT_LOSE_NONE')),
- $htmlHelper->_('select.option', self::LOSE_DISABLE, JText::_('JBZOO_IMPORT_LOSE_DISABLE')),
- $htmlHelper->_('select.option', self::LOSE_REMOVE, JText::_('JBZOO_IMPORT_LOSE_REMOVE')),
- );
- $html['lose'] = $htmlHelper->_('select.genericlist', $loseOptions, 'lose');
-
- // what field is key
- $keyOptions = array(
- $htmlHelper->_('select.option', self::KEY_NONE, JText::_('JBZOO_IMPORT_KEY_NONE')),
- $htmlHelper->_('select.option', self::KEY_ID, JText::_('JBZOO_IMPORT_KEY_ID')),
- $htmlHelper->_('select.option', self::KEY_NAME, JText::_('JBZOO_IMPORT_KEY_NAME')),
- $htmlHelper->_('select.option', self::KEY_ALIAS, JText::_('JBZOO_IMPORT_KEY_ALIAS')),
- );
- $html['key'] = $htmlHelper->_('select.genericlist', $keyOptions, 'key');
-
- return $html;
- }
-
- /**
- * Create fields control for item
- * @param $typeid
- * @param $elementTypes
- */
- protected function _createItemsControl($typeid, $elementTypes)
- {
- $htmlHelper = $this->app->html;
-
- $fields = $this->app->jbcsvmapper->getItemFields($elementTypes);
- $options = array($htmlHelper->_('select.option', '', ' ** '));
-
- foreach ($fields as $groupKey => $group) {
-
- if (strpos($groupKey, '__') === false) {
- $options[] = $htmlHelper->_('select.option', '