/**
  * Load your component.
  *
  * @param \Cx\Core\ContentManager\Model\Entity\Page $page       The resolved page
  */
 public function load(\Cx\Core\ContentManager\Model\Entity\Page $page)
 {
     global $_CORELANG, $subMenuTitle, $objTemplate;
     switch ($this->cx->getMode()) {
         case \Cx\Core\Core\Controller\Cx::MODE_FRONTEND:
             $objGallery = new Gallery(\Env::get('cx')->getPage()->getContent());
             \Env::get('cx')->getPage()->setContent($objGallery->getPage());
             $topGalleryName = $objGallery->getTopGalleryName();
             if ($topGalleryName) {
                 \Env::get('cx')->getPage()->setTitle($topGalleryName);
                 \Env::get('cx')->getPage()->setContentTitle($topGalleryName);
                 \Env::get('cx')->getPage()->setMetaTitle($topGalleryName);
             }
             break;
         case \Cx\Core\Core\Controller\Cx::MODE_BACKEND:
             $this->cx->getTemplate()->addBlockfile('CONTENT_OUTPUT', 'content_master', 'LegacyContentMaster.html');
             $objTemplate = $this->cx->getTemplate();
             \Permission::checkAccess(12, 'static');
             $subMenuTitle = $_CORELANG['TXT_GALLERY_TITLE'];
             $objGalleryManager = new GalleryManager();
             $objGalleryManager->getPage();
             break;
         default:
             break;
     }
 }
Exemplo n.º 2
0
 /**
  * Public function that creates a single instance
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Exemplo n.º 3
0
 /**
  * Returns an singleton instance of this class
  *
  * @param object $config
  * @param object $args
  * @return
  */
 public static function getInstance($config, $args)
 {
     if (self::$instance == null) {
         self::$instance = new GalleryManager($config, $args);
     }
     return self::$instance;
 }
Exemplo n.º 4
0
 /**
  * Import items from uploaded file.
  */
 private function import_from_file()
 {
     global $db, $site_path;
     $gallery = gallery::getInstance();
     $gallery_manager = GalleryManager::getInstance();
     $languages = Language::getLanguages(false);
     $item_manager = ShopItemManager::getInstance();
     $category_manager = ShopCategoryManager::getInstance();
     $property_manager = \Modules\Shop\Property\Manager::getInstance();
     $membership_manager = \ShopItemMembershipManager::getInstance();
     // load categories
     $categories = array();
     $raw_categories = $category_manager->getItems($category_manager->getFieldNames(), array());
     if (count($raw_categories) > 0) {
         foreach ($raw_categories as $category) {
             $categories[$category->id] = $category->title[self::DEFAULT_LANGUAGE];
         }
     }
     // load existing items
     $existing_items = array();
     $items = $item_manager->getItems(array('id', 'uid'), array());
     foreach ($items as $item) {
         $existing_items[$item->uid] = $item->id;
     }
     // load existing images
     $existing_images = array();
     $images = $gallery_manager->getItems(array('group', 'text_id', 'id'), array());
     if (count($images) > 0) {
         foreach ($images as $image) {
             // make sure we have storage array
             if (!array_key_exists($image->group, $existing_images)) {
                 $existing_images[$image->group] = array();
             }
             // add image to the list
             $existing_images[$image->group][$image->id] = $image->text_id;
         }
     }
     $image_list = scandir(_BASEPATH . '/' . $site_path . 'import/');
     // load csv file
     $csv_data = $this->load_csv_file($_FILES['import']['tmp_name']);
     array_shift($csv_data);
     // remove header
     $number_to_import = isset($_REQUEST['number_to_import']) && !empty($_REQUEST['number_to_import']) ? fix_id($_REQUEST['number_to_import']) : count($csv_data);
     $counter = 0;
     foreach ($csv_data as $row) {
         // make sure we are within our limits
         if (++$counter > $number_to_import) {
             break;
         }
         // get item name and description
         $item_name = array_fill(0, count($languages), '');
         $item_name = array_combine($languages, $item_name);
         $item_description = $item_name;
         $item_name['he'] = $db->escape_string($row[self::COL_NAME_HE]);
         $item_name['ru'] = $db->escape_string($row[self::COL_NAME_RU]);
         $item_description['he'] = $db->escape_string($row[self::COL_DESCRIPTION_HE]);
         $item_description['ru'] = $db->escape_string($row[self::COL_DESCRIPTION_RU]);
         // unpack price values
         $prices = explode(',', $row[self::COL_PRICE]);
         $price_names = explode(',', $row[self::COL_SIZE_LABELS]);
         // generate uid and check if item exists in database
         $uid = hash('sha256', 'item_' . $row[self::COL_ID]);
         if (array_key_exists($uid, $existing_items)) {
             $data = array('name' => $item_name, 'description' => $item_description, 'price' => count($prices) > 0 ? floatval($prices[0]) : 0);
             $item_id = $existing_items[$uid];
             $item_manager->updateData($data, array('id' => $item_id));
             $gallery_id = $item_manager->getItemValue('gallery', array('id' => $item_id));
         } else {
             // prepare data
             $data = array('name' => $item_name, 'description' => $item_description, 'price' => count($prices) > 0 ? floatval($prices[0]) : 0, 'colors' => '', 'tax' => 0, 'weight' => 0, 'manufacturer' => 0, 'uid' => $uid);
             // store author of the uploaded item
             $data['author'] = $_SESSION['uid'];
             // create item gallery
             $gallery_id = $gallery->createGallery($item_name);
             $data['gallery'] = $gallery_id;
             // add item to the database
             $item_manager->insertData($data);
             $item_id = $item_manager->getInsertedID();
         }
         // remove existing prices
         $property_manager->deleteData(array('item' => $item_id, 'text_id' => array('operator' => 'LIKE', 'value' => 'price_%')));
         // create price properties
         if (count($prices) > 1) {
             // generate default name
             $price_name = array_fill(0, count($languages), '');
             $price_name = array_combine($languages, $price_name);
             for ($i = 1; $i < count($prices); $i++) {
                 // set and reset specified name
                 if (isset($price_names[$i])) {
                     $price_name[self::DEFAULT_LANGUAGE] = $price_names[$i];
                 } else {
                     $price_name[self::DEFAULT_LANGUAGE] = '';
                 }
                 // prepare data for insertion
                 $price_data = array('item' => $item_id, 'name' => $price_name, 'text_id' => 'price_' . $this->size_names[$i - 1], 'type' => 'decimal', 'value' => serialize(floatval($prices[$i])));
                 // insert new price property
                 $property_manager->insertData($price_data);
             }
         }
         // remove existing category membership
         $membership_manager->deleteData(array('item' => $item_id));
         // assign category membership
         for ($i = self::COL_FIRST_CATEGORY; $i < count($row); $i++) {
             $category_name = $row[$i];
             $category_id = $this->get_category_for_name($categories, $category_name, self::DEFAULT_THRESHOLD);
             if (!is_null($category_id)) {
                 $membership_manager->insertData(array('category' => $category_id, 'item' => $item_id));
             }
         }
         // upload images
         $image_file = mb_strtolower($row[self::COL_IMAGE]);
         $matched_file = $this->match_image_file($image_list, $image_file, 6);
         // we require a valid match
         if (!is_null($matched_file)) {
             $matched_hash = hash('md5', $matched_file);
             $source_path = _BASEPATH . '/' . $site_path . 'import/' . $matched_file;
             $destination_file = hash('md5', $matched_file . strval(time())) . '.' . pathinfo(strtolower($matched_file), PATHINFO_EXTENSION);
             $destination_path = _BASEPATH . '/' . $site_path . 'gallery/images/' . $destination_file;
             $image_already_uploaded = array_key_exists($gallery_id, $existing_images) && !in_array($matched_hash, $existing_images[$gallery_id]);
             $file_size = filesize($source_path);
             // only upload image if it wasn't uploaded already
             if (!$image_already_uploaded && copy($source_path, $destination_path)) {
                 $gallery_manager->insertData(array('group' => $gallery_id, 'title' => $item_name, 'text_id' => $matched_hash, 'size' => $file_size, 'filename' => $destination_file, 'visible' => 1, 'slideshow' => 0, 'protected' => 0));
             }
         }
     }
     // show result message
     $template = new TemplateHandler('message.xml', $this->path . 'templates/');
     $template->setMappedModule($this->name);
     $params = array('message' => $this->getLanguageConstant('message_import_complete'), 'button' => $this->getLanguageConstant('close'), 'action' => window_Close('shop_import_items'));
     $template->restoreXML();
     $template->setLocalParams($params);
     $template->parse();
 }
Exemplo n.º 5
0
 /**
  * Handle drawing list of manufacturers tag
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_ManufacturerList($tag_params, $children)
 {
     $manager = ShopManufacturerManager::getInstance();
     $conditions = array();
     $selected = -1;
     if (class_exists('gallery')) {
         $use_images = true;
         $gallery = gallery::getInstance();
         $gallery_manager = GalleryManager::getInstance();
     } else {
         $use_images = false;
     }
     if (isset($tag_params['selected'])) {
         $selected = fix_id($tag_params['selected']);
     }
     $items = $manager->getItems($manager->getFieldNames(), $conditions);
     $template = $this->_parent->loadTemplate($tag_params, 'manufacturer_list_item.xml');
     if (count($items) > 0) {
         foreach ($items as $item) {
             // get image
             $image = '';
             if ($use_images && !empty($item->logo)) {
                 $image_item = $gallery_manager->getSingleItem($gallery_manager->getFieldNames(), array('id' => $item->logo));
                 if (is_object($image_item)) {
                     $image = $gallery->getImageURL($image_item);
                 }
             }
             // prepare parameters
             $params = array('id' => $item->id, 'name' => $item->name, 'web_site' => $item->web_site, 'logo' => $image, 'selected' => $selected == $item->id ? 1 : 0, 'item_change' => url_MakeHyperlink($this->_parent->getLanguageConstant('change'), window_Open('shop_manufacturer_change', 360, $this->_parent->getLanguageConstant('title_manufacturer_change'), true, true, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'manufacturers'), array('sub_action', 'change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_manufacturer_delete', 400, $this->_parent->getLanguageConstant('title_manufacturer_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'manufacturers'), array('sub_action', 'delete'), array('id', $item->id)))));
             // parse template
             $template->setLocalParams($params);
             $template->restoreXML();
             $template->parse();
         }
     }
 }
Exemplo n.º 6
0
    _throw("FNoArticlesTables", "There is no articles tree table \"{$fusebox['tableArticlesTree']}\" or articles tokens table \"{$fusebox['tableArticlesTokens']}\" present in DB");
}
// adding article manager
$ogArticleManager = new ContentManager($oDB, $ogFuseaction, $oLanguage, $fusebox['tableArticlesTokens'], $fusebox['tableArticles'], $fusebox['tableArticlesComments'], false);
// setting authorship
$ogArticleManager->fAuthorID = $oUser->getID();
$ogArticleManager->fEditorID = $oUser->getID();
// running dry
if (!$ogArticleManager->initialize()) {
    _throw("FNoArticlesTable", "There is no articles table called \"{$fusebox['tableArticles']}\" present in DB");
}
$ogArticleManager->fTitleEditLink = "%s&nbsp;<a href=\"javascript:void(0);\" onClick=\"popupContentForm('" . $myself . "util.showArticleForm', %d, '%s', %d, 1);\">Edit</a>";
$ogArticleManager->fContentEditLink = "%s&nbsp;<a href=\"javascript:void(0);\" onClick=\"popupContentForm('" . $myself . "util.showArticleForm', %d, '%s', %d, 2);\">Edit</a>";
$ogArticleAttachmentManager = new ArticleAttachmentManager($oDB, $ogArticleManager, $fusebox['tableArticleAttachments']);
// creating gallery manager
$ogGalleryManager = new GalleryManager($oDB, $oLanguage, $fusebox['tableGalleriesTokens'], $fusebox['tableGalleries'], $fusebox['tableImagesTokens'], $fusebox['tableImages'], $fusebox['tableGalleriesComments'], $fusebox['tableImagesComments']);
// setting authorship
$ogGalleryManager->fAuthorID = $oUser->getID();
$ogGalleryManager->fEditorID = $oUser->getID();
// bringing up
if (!$ogGalleryManager->initialize()) {
    _throw("FNoGalleryTables", "There is no gallery and images tables present in DB");
}
// security managers initialization (for current FA and 'global' for entire site)
if ($fusebox['mode'] == "development" || $oUser->isDev()) {
    $oSecurityManager = new SecurityManager($oDB, $oUser, $oFuseaction, $fusebox['tableSecurity'], $fusebox['tableGroups'], $fusebox['tableUsersGroups'], $fusebox['defaultGroup'], SECURITYMODE_LOOSE, true);
    $ogSecurityManager = new SecurityManager($oDB, $oUser, $ogFuseaction, $fusebox['tableSecurity'], $fusebox['tableGroups'], $fusebox['tableUsersGroups'], $fusebox['defaultGroup'], SECURITYMODE_LOOSE, true);
} else {
    if ($fusebox['globalSecurityMode'] == "STRICT") {
        $oSecurityManager = new SecurityManager($oDB, $oUser, $oFuseaction, $fusebox['tableSecurity'], $fusebox['tableGroups'], $fusebox['tableUsersGroups'], $fusebox['defaultGroup'], SECURITYMODE_STRICT, false);
        $ogSecurityManager = new SecurityManager($oDB, $oUser, $ogFuseaction, $fusebox['tableSecurity'], $fusebox['tableGroups'], $fusebox['tableUsersGroups'], $fusebox['defaultGroup'], SECURITYMODE_STRICT, false);
Exemplo n.º 7
0
 /**
  * Tag handler for category list
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_CategoryList($tag_params, $children)
 {
     global $language;
     $manager = ShopCategoryManager::getInstance();
     $conditions = array();
     $order_by = array();
     $order_asc = true;
     $item_category_ids = array();
     $item_id = isset($tag_params['item_id']) ? fix_id($tag_params['item_id']) : null;
     // create conditions
     if (isset($tag_params['parent_id'])) {
         // set parent from tag parameter
         $conditions['parent'] = fix_id($tag_params['parent_id']);
     } else {
         if (isset($tag_params['parent'])) {
             // get parent id from specified text id
             $text_id = fix_chars($tag_params['parent']);
             $parent = $manager->getSingleItem(array('id'), array('text_id' => $text_id));
             if (is_object($parent)) {
                 $conditions['parent'] = $parent->id;
             } else {
                 $conditions['parent'] = -1;
             }
         } else {
             if (!isset($tag_params['show_all'])) {
                 $conditions['parent'] = 0;
             }
         }
     }
     if (isset($tag_params['level'])) {
         $level = fix_id($tag_params['level']);
     } else {
         $level = 0;
     }
     if (isset($tag_params['exclude'])) {
         $list = fix_id(explode(',', $tag_params['exclude']));
         $conditions['id'] = array('operator' => 'NOT IN', 'value' => $list);
     }
     if (!is_null($item_id)) {
         $membership_manager = ShopItemMembershipManager::getInstance();
         $membership_items = $membership_manager->getItems(array('category'), array('item' => $item_id));
         if (count($membership_items) > 0) {
             foreach ($membership_items as $membership) {
                 $item_category_ids[] = $membership->category;
             }
         }
     }
     // get order list
     if (isset($tag_params['order_by'])) {
         $order_by = fix_chars(split(',', $tag_params['order_by']));
     } else {
         $order_by = array('title_' . $language);
     }
     if (isset($tag_params['order_ascending'])) {
         $order_asc = $tag_params['order_asc'] == '1' or $tag_params['order_asc'] == 'yes';
     } else {
         // get items from database
         $items = $manager->getItems($manager->getFieldNames(), $conditions, $order_by, $order_asc);
     }
     // create template handler
     $template = $this->_parent->loadTemplate($tag_params, 'category_list_item.xml');
     $template->registerTagHandler('_children', $this, 'tag_CategoryList');
     // initialize index
     $index = 0;
     // parse template
     if (count($items) > 0) {
         foreach ($items as $item) {
             $image_url = '';
             $thumbnail_url = '';
             if (class_exists('gallery')) {
                 $gallery = gallery::getInstance();
                 $gallery_manager = GalleryManager::getInstance();
                 $image = $gallery_manager->getSingleItem(array('filename'), array('id' => $item->image));
                 if (!is_null($image)) {
                     $image_url = $gallery->getImageURL($image);
                     $thumbnail_url = $gallery->getThumbnailURL($image);
                 }
             }
             $params = array('id' => $item->id, 'index' => $index++, 'item_id' => $item_id, 'parent' => $item->parent, 'image_id' => $item->image, 'image' => $image_url, 'thumbnail' => $thumbnail_url, 'text_id' => $item->text_id, 'title' => $item->title, 'description' => $item->description, 'level' => $level, 'in_category' => in_array($item->id, $item_category_ids) ? 1 : 0, 'selected' => isset($tag_params['selected']) ? fix_id($tag_params['selected']) : 0, 'item_change' => url_MakeHyperlink($this->_parent->getLanguageConstant('change'), window_Open('shop_category_change', 400, $this->_parent->getLanguageConstant('title_category_change'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'categories'), array('sub_action', 'change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_category_delete', 270, $this->_parent->getLanguageConstant('title_category_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'categories'), array('sub_action', 'delete'), array('id', $item->id)))), 'item_add' => url_MakeHyperlink($this->_parent->getLanguageConstant('add'), window_Open('shop_category_add', 400, $this->_parent->getLanguageConstant('title_category_add'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'categories'), array('sub_action', 'add'), array('parent', $item->id)))));
             $template->restoreXML();
             $template->setLocalParams($params);
             $template->parse();
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Create JSON object containing links with specified characteristics
  */
 private function json_LinkList()
 {
     define('_OMIT_STATS', 1);
     $groups = array();
     $conditions = array();
     $limit = isset($tag_params['limit']) ? fix_id($tag_params['limit']) : null;
     $order_by = isset($tag_params['order_by']) ? explode(',', fix_chars($tag_params['order_by'])) : array('id');
     $order_asc = isset($tag_params['order_asc']) && $tag_params['order_asc'] == 'yes' ? true : false;
     $grouped = isset($_REQUEST['grouped']) && $_REQUEST['grouped'] == 'yes' ? true : false;
     $manager = LinksManager::getInstance();
     $group_manager = LinkGroupsManager::getInstance();
     $membership_manager = LinkMembershipManager::getInstance();
     if (isset($_REQUEST['group'])) {
         $group_list = explode(',', fix_chars($_REQUEST['group']));
         $list = $group_manager->getItems(array('id'), array('name' => $group_list));
         if (count($list) > 0) {
             foreach ($list as $list_item) {
                 $groups[] = $list_item->id;
             }
         }
     }
     if (isset($_REQUEST['group_id'])) {
         $groups = array_merge($groups, fix_id(explode(',', $_REQUEST['group_id'])));
     }
     if (isset($_REQUEST['sponsored'])) {
         $sponsored = $_REQUEST['sponsored'] == 'yes' ? 1 : 0;
         $conditions['sponsored'] = $sponsored;
     }
     // fetch ids for specified groups
     if (!empty($groups)) {
         $list = $membership_manager->getItems(array('link'), array('group' => $groups));
         $id_list = array();
         if (count($list) > 0) {
             foreach ($list as $list_item) {
                 $id_list[] = $list_item->link;
             }
         } else {
             // in case no members of specified group were found, ensure no items are retrieved
             $id_list = '-1';
         }
         $conditions['id'] = $id_list;
     }
     // save some CPU time by getting this early
     if (class_exists('gallery')) {
         $use_images = true;
         $gallery = gallery::getInstance();
         $gallery_manager = GalleryManager::getInstance();
     } else {
         $use_images = false;
     }
     $items = $manager->getItems($manager->getFieldNames(), $conditions, $order_by, $order_asc, $limit);
     $result = array('error' => false, 'error_message' => '', 'items' => array());
     if (count($items) > 0) {
         foreach ($items as $item) {
             $result['items'][] = array('id' => $item->id, 'text' => $item->text, 'url' => $item->url, 'redirect_url' => url_Make('redirect', $this->name, array('id', $item->id)), 'external' => $item->external, 'sponsored' => $item->sponsored, 'display_limit' => $item->display_limit, 'sponsored_clicks' => $item->sponsored_clicks, 'total_clicks' => $item->total_clicks, 'image' => null);
         }
     } else {
     }
     print json_encode($result);
 }
Exemplo n.º 9
0
 /**
  * Create gallery from specified uploaded field names
  *
  * @param array $name Multi-language name for newly created gallery
  * @return integer Newly created gallery Id
  */
 public function createGallery($name)
 {
     $image_manager = GalleryManager::getInstance();
     $gallery_manager = GalleryGroupManager::getInstance();
     // create gallery
     $gallery_manager->insertData(array('name' => $name));
     $result = $gallery_manager->getInsertedID();
     return $result;
 }