/**
  * add items category select
  */
 public function addItemsCategorySelect($name = "category", $title = null, $isNewGallery = false)
 {
     if ($title == null) {
         $title = __("Item Category", UNITEGALLERY_TEXTDOMAIN);
     }
     $objCategories = new UniteGalleryCategories();
     $addType = "empty";
     if ($isNewGallery == true) {
         $addType = "new";
     }
     $arrCats = $objCategories->getCatsShort($addType);
     //set selected category
     if ($isNewGallery == true) {
         $defaultCat = "new";
     } else {
         $defaultCat = UniteFunctionsUG::getFirstNotEmptyKey($arrCats);
     }
     $this->addSelect($name, $arrCats, $title, $defaultCat);
 }
$outputMain = new UniteSettingsProductUG();
$outputParams = new UniteSettingsProductSidebarUG();
$filepathBeforeDraw = HelperGalleryUG::getPathView("settings_before_draw", false);
if ($isNewGallery) {
    $galleryTitle = GlobalsUGGallery::$galleryTypeTitle;
    $headerTitle = $galleryTitle . __(" - [settings]", UNITEGALLERY_TEXTDOMAIN);
    if (file_exists($filepathBeforeDraw)) {
        require_once $filepathBeforeDraw;
    }
    $outputMain->init($settingsMain);
    $outputParams->init($settingsParams);
    require HelperGalleryUG::getPathHelperTemplate("gallery_new");
} else {
    $galleryTitle = GlobalsUGGallery::$gallery->getTitle();
    $headerTitle = $galleryTitle . __(" - [settings]", UNITEGALLERY_TEXTDOMAIN);
    $galleryType = GlobalsUGGallery::$gallery->getTypeName();
    $arrValues = GlobalsUGGallery::$gallery->getParamsForSettings();
    //get categories select dialog
    $objCategories = new UniteGalleryCategories();
    $arrCats = $objCategories->getCatsShort("component");
    $htmlSelectCats = UniteFunctionsUG::getHTMLSelect($arrCats, "", "id='ds_select_cats'", true);
    //set setting values from the slider
    $settingsMain->setStoredValues($arrValues);
    $settingsParams->setStoredValues($arrValues);
    if (isset($filepathBeforeDraw) && file_exists($filepathBeforeDraw)) {
        require_once $filepathBeforeDraw;
    }
    $outputMain->init($settingsMain);
    $outputParams->init($settingsParams);
    require HelperGalleryUG::getPathHelperTemplate("gallery_edit");
}
Example #3
0
<?php

/**
 * @package Unite Gallery
 * @author UniteCMS.net / Valiano
 * @copyright (C) 2012 Unite CMS, All Rights Reserved. 
 * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 * */
defined('_JEXEC') or die('Restricted access');
$isGalleryPage = GlobalsUGGallery::$isInited;
$objCats = new UniteGalleryCategories();
$htmlCatList = $objCats->getHtmlCatList();
$htmlCatSelect = $objCats->getHtmlSelectCats();
$itemsType = "all";
if ($isGalleryPage) {
    $itemsType = GlobalsUGGallery::$objGalleryType->getItemsType();
}
//init item menu
$arrMenuItem = array();
$arrMenuItem["edit_item"] = __("Edit Item", UNITEGALLERY_TEXTDOMAIN);
$arrMenuItem["edit_title"] = __("Edit Title", UNITEGALLERY_TEXTDOMAIN);
$arrMenuItem["preview_item"] = __("Preview Item", UNITEGALLERY_TEXTDOMAIN);
$arrMenuItem["delete"] = __("Delete", UNITEGALLERY_TEXTDOMAIN);
$arrMenuItem["duplicate"] = __("Duplicate", UNITEGALLERY_TEXTDOMAIN);
//init multiple item menu
$arrMenuItemMultiple = array();
$arrMenuItemMultiple["delete"] = __("Delete", UNITEGALLERY_TEXTDOMAIN);
$arrMenuItemMultiple["duplicate"] = __("Duplicate", UNITEGALLERY_TEXTDOMAIN);
//init field menu
$arrMenuField = array();
if ($itemsType != "video") {
 /**
  * 
  * add gallery from data by gallery name
  */
 public function addGaleryFromData($type, $data)
 {
     $objGallery = new UniteGalleryGallery();
     $params = UniteFunctionsUG::getVal($data, "params", array());
     if (is_array($params) == false) {
         $params = array();
     }
     $mainParams = UniteFunctionsUG::getVal($data, "main");
     if (!empty($mainParams)) {
         $params = array_merge($mainParams, $params);
     }
     //create items category if needed
     $category = UniteFunctionsUG::getVal($params, "category");
     if ($category == "new") {
         $objGallery->validateInputSettings($params, false);
         $title = $params["title"];
         $objCategories = new UniteGalleryCategories();
         $response = $objCategories->add($title);
         $newCategoryID = $response["id"];
         $params["category"] = $newCategoryID;
         $params["categories"] = $newCategoryID;
     }
     $galleryID = $objGallery->create($type, $params);
     return $galleryID;
 }
 /**
  * 
  * onAjax action handler
  */
 public static function onAjaxAction()
 {
     $actionType = UniteFunctionsUG::getPostGetVariable("action");
     if ($actionType != "unitegallery_ajax_action") {
         return false;
     }
     $gallery = new UniteGalleryGallery();
     $galleries = new UniteGalleryGalleries();
     $categories = new UniteGalleryCategories();
     $items = new UniteGalleryItems();
     $operations = new UGOperations();
     $action = UniteFunctionsUG::getPostGetVariable("client_action");
     $data = UniteFunctionsUG::getPostVariable("data");
     $data = UniteProviderFunctionsUG::normalizeAjaxInputData($data);
     $galleryType = UniteFunctionsUG::getPostVariable("gallery_type");
     $urlGalleriesView = HelperUG::getGalleriesView();
     try {
         switch ($action) {
             case "gallery_actions":
                 $galleryID = UniteFunctionsUG::getVal($data, "galleryID");
                 $galleryAction = UniteFunctionsUG::getVal($data, "gallery_action");
                 $galleryData = UniteFunctionsUG::getVal($data, "gallery_data", array());
                 self::onGalleryAjaxAction($galleryType, $galleryAction, $galleryData, $galleryID);
                 break;
             case "get_thumb_url":
                 $urlImage = UniteFunctionsUG::getVal($data, "urlImage");
                 $imageID = UniteFunctionsUG::getVal($data, "imageID");
                 $urlThumb = $operations->getThumbURLFromImageUrl($urlImage, $imageID);
                 $arrData = array("urlThumb" => $urlThumb);
                 HelperUG::ajaxResponseData($arrData);
                 break;
             case "add_category":
                 $catData = $categories->addFromData();
                 HelperUG::ajaxResponseData($catData);
                 break;
             case "remove_category":
                 $response = $categories->removeFromData($data);
                 HelperUG::ajaxResponseSuccess(__("The category deleted successfully.", UNITEGALLERY_TEXTDOMAIN), $response);
                 break;
             case "update_category":
                 $categories->updateFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Category updated.", UNITEGALLERY_TEXTDOMAIN));
                 break;
             case "update_cat_order":
                 $categories->updateOrderFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Order updated.", UNITEGALLERY_TEXTDOMAIN));
                 break;
             case "add_item":
                 $itemData = $items->addFromData($data);
                 HelperUG::ajaxResponseData($itemData);
                 break;
             case "get_item_data":
                 $response = $items->getItemData($data);
                 HelperUG::ajaxResponseData($response);
                 break;
             case "update_item_data":
                 $response = $items->updateItemData($data);
                 HelperUG::ajaxResponseSuccess(__("Item data updated!", UNITEGALLERY_TEXTDOMAIN), $response);
                 break;
             case "remove_items":
                 $response = $items->removeItemsFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Items Removed", UNITEGALLERY_TEXTDOMAIN), $response);
                 break;
             case "get_cat_items":
                 $responeData = $items->getCatItemsHtmlFromData($data);
                 //update category param if inside gallery
                 $gallery->updateItemsCategoryFromData($data);
                 HelperUG::ajaxResponseData($responeData);
                 break;
             case "update_item_title":
                 $items->updateItemTitleFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Item Title Updated", UNITEGALLERY_TEXTDOMAIN));
                 break;
             case "duplicate_items":
                 $response = $items->duplicateItemsFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Items Duplicated", UNITEGALLERY_TEXTDOMAIN), $response);
                 break;
             case "update_items_order":
                 $items->saveOrderFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Order Saved", UNITEGALLERY_TEXTDOMAIN));
                 break;
             case "copy_move_items":
                 $response = $items->copyMoveItemsFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Done Operation", UNITEGALLERY_TEXTDOMAIN), $response);
                 break;
             case "create_gallery":
                 $galleryID = $galleries->addGaleryFromData($galleryType, $data);
                 $urlView = HelperUG::getGalleryView($galleryID);
                 HelperUG::ajaxResponseSuccessRedirect(__("Gallery Created", UNITEGALLERY_TEXTDOMAIN), $urlView);
                 break;
             case "delete_gallery":
                 $galleries->deleteGalleryFromData($data);
                 HelperUG::ajaxResponseSuccessRedirect(__("Gallery deleted", UNITEGALLERY_TEXTDOMAIN), $urlGalleriesView);
                 break;
             case "update_gallery":
                 $galleries->updateGalleryFromData($data);
                 HelperUG::ajaxResponseSuccess(__("Gallery Updated"));
                 break;
             case "duplicate_gallery":
                 $galleries->duplicateGalleryFromData($data);
                 HelperUG::ajaxResponseSuccessRedirect(__("Gallery duplicated", UNITEGALLERY_TEXTDOMAIN), $urlGalleriesView);
                 break;
             case "update_plugin":
                 if (method_exists("UniteProviderFunctionsUG", "updatePlugin")) {
                     UniteProviderFunctionsUG::updatePlugin();
                 } else {
                     echo "Functionality Don't Exists";
                 }
                 break;
             case "export_gallery_settings":
                 $galleryID = UniteFunctionsUG::getPostGetVariable("galleryid");
                 $galleries->exportGallerySettings($galleryID);
                 break;
             case "import_gallery_settings":
                 $galleryID = UniteFunctionsUG::getPostGetVariable("galleryid");
                 $galleries->importGallerySettingsFromUploadFile($galleryID);
                 break;
             default:
                 HelperUG::ajaxResponseError("wrong ajax action: <b>{$action}</b> ");
                 break;
         }
     } catch (Exception $e) {
         $message = $e->getMessage();
         $errorMessage = $message;
         if (GlobalsUG::SHOW_TRACE == true) {
             $trace = $e->getTraceAsString();
             $errorMessage = $message . "<pre>" . $trace . "</pre>";
         }
         HelperUG::ajaxResponseError($errorMessage);
     }
     //it's an ajax action, so exit
     HelperUG::ajaxResponseError("No response output on <b> {$action} </b> action. please check with the developer.");
     exit;
 }
<?php

defined('_JEXEC') or die('Restricted access');
$settingsMain = new UniteGallerySettingsUG();
$settingsMain->addRadioBoolean("enable_category_tabs", __("Enable Category Tabs", UNITEGALLERY_TEXTDOMAIN), false);
$settingsMain->addHr();
$settingsMain->addRadio("tabs_type", array("tabs" => "Tabs", "select" => "Select Box"), __("Category Tabs Type", UNITEGALLERY_TEXTDOMAIN), "tabs");
$settingsMain->addHr();
//add categories select
$objCategories = new UniteGalleryCategories();
$arrCats = $objCategories->getCatsShort();
$settingsMain->addSelect("available_cats", $arrCats, __("Available Categories", UNITEGALLERY_TEXTDOMAIN), "");
$settingsMain->addTextBox("categorytabs_ids", "", "Hidden Cats", array("hidden" => true));
$settingsMain->addSelect("tabs_init_catid", array(), __("First Selected Tab", UNITEGALLERY_TEXTDOMAIN), "");
    /**
     * 
     * the form
     */
    public function form($instance)
    {
        $galleries = new UniteGalleryGalleries();
        $arrGalleries = $galleries->getArrGalleriesShort();
        $galleryID = UniteFunctionsUG::getVal($instance, "unitegallery");
        if (empty($arrGalleries)) {
            echo __("No galleries found, Please create a gallery", UNITEGALLERY_TEXTDOMAIN);
        } else {
            $fieldCat = "unitegallery_cat";
            $fieldIDCat = $this->get_field_id($fieldCat);
            $fieldNameCat = $this->get_field_name($fieldCat);
            $categoryID = UniteFunctionsUG::getVal($instance, "unitegallery_cat");
            $objCategories = new UniteGalleryCategories();
            $arrCats = $objCategories->getCatsShort("component");
            $selectCats = UniteFunctionsUG::getHTMLSelect($arrCats, $categoryID, 'name="' . $fieldNameCat . '" id="' . $fieldIDCat . '"', true);
            //output gallries select
            $field = "unitegallery";
            $fieldID = $this->get_field_id($field);
            $fieldName = $this->get_field_name($field);
            $selectGalleries = UniteFunctionsUG::getHTMLSelect($arrGalleries, $galleryID, 'name="' . $fieldName . '" id="' . $fieldID . '"', true);
            ?>
				<div style="padding-top:10px;padding-bottom:10px;">
				
				<?php 
            _e("Title", UNITEGALLERY_TEXTDOMAIN);
            ?>
: 
				<input type="text" id="<?php 
            echo $this->get_field_id("title");
            ?>
" name="<?php 
            echo $this->get_field_name("title");
            ?>
" value="<?php 
            echo UniteFunctionsUG::getVal($instance, 'title');
            ?>
" />
				
				<br><br>
				
				<?php 
            _e("Choose Gallery", UNITEGALLERY_TEXTDOMAIN);
            ?>
: 
				<?php 
            echo $selectGalleries;
            ?>
				
				<br><br>
				<?php 
            _e("Choose Category", UNITEGALLERY_TEXTDOMAIN);
            ?>
: 
				
				<?php 
            echo $selectCats;
            ?>
				
				</div>
				
				<br>
			<?php 
        }
    }
    /**
     * 
     * put the gallery
     */
    public function putGallery($galleryID, $arrOptions = array(), $initType = "id")
    {
        try {
            $objCategories = new UniteGalleryCategories();
            $this->initGallery($galleryID);
            $this->setOutputOptions();
            $this->putScripts();
            $enableCatTabs = $this->getParam('enable_category_tabs', self::FORCE_BOOLEAN);
            //custom items pass
            if (is_array($arrOptions) && array_key_exists("items", $arrOptions)) {
                $arrItems = $arrOptions["items"];
                $enableCatTabs = false;
            } else {
                //set gallery category
                $optCatID = UniteFunctionsUG::getVal($arrOptions, "categoryid");
                if (!empty($optCatID) && $objCategories->isCatExists($optCatID)) {
                    $categoryID = $optCatID;
                } else {
                    if ($enableCatTabs == true) {
                        $categoryID = $this->getParam("tabs_init_catid");
                        if ($categoryID == "first") {
                            //get first category from tabs
                            $strCatIDs = $this->getParam("categorytabs_ids");
                            $arrIDs = explode(",", $strCatIDs);
                            if (!empty($arrIDs)) {
                                $categoryID = $arrIDs[0];
                            }
                        }
                        if (empty($categoryID) || is_numeric($categoryID) == false) {
                            $categoryID = $this->getParam("category");
                        }
                    } else {
                        $categoryID = $this->getParam("category");
                    }
                }
                if (empty($categoryID)) {
                    UniteFunctionsUG::throwError(__("No items category selected", UNITEGALLERY_TEXTDOMAIN));
                }
                $items = new UniteGalleryItems();
                $arrItems = $items->getCatItems($categoryID);
            }
            if (empty($arrItems)) {
                UniteFunctionsUG::throwError("No gallery items found", UNITEGALLERY_TEXTDOMAIN);
            }
            //set wrapper style
            //size validation
            $this->getParam("gallery_width", self::FORCE_SIZE);
            if ($this->isTilesType == false) {
                $this->getParam("gallery_height", self::VALIDATE_NUMERIC);
            }
            $fullWidth = $this->getParam("full_width", self::FORCE_BOOLEAN);
            if ($fullWidth == true) {
                $this->arrParams["gallery_width"] = "100%";
            }
            $wrapperStyle = $this->getPositionString();
            //set position
            $htmlTabs = "";
            if ($enableCatTabs == true) {
                $htmlTabs = $this->getCategoryTabsHtml($this->galleryHtmlID, $objCategories);
                $this->arrParams["gallery_initial_catid"] = $categoryID;
            }
            //get output related variables
            $addStyles = $this->getAdditionalStyles();
            $position = $this->getParam("position");
            $isRtlWrapper = $position == "right";
            if ($isRtlWrapper == true) {
                $rtlWrapperStyle = $wrapperStyle;
                if (!empty($rtlWrapperStyle)) {
                    $rtlWrapperStyle = " style='{$rtlWrapperStyle}'";
                }
                $wrapperStyle = "";
                //move the wrapper style to rtl wrapper
            }
            if (!empty($wrapperStyle)) {
                $wrapperStyle = " style='{$wrapperStyle}'";
            }
            global $uniteGalleryVersion;
            $output = "\n\t\t\t\t\t\n\n\t\t\t\t\t<!-- START UNITE GALLERY LITE {$uniteGalleryVersion} -->\n\t\t\t\t\t\n\t\t\t\t";
            if (!empty($addStyles)) {
                $output = $this->putInlineStyle($addStyles, $output);
            }
            if ($this->putJsToBody == true) {
                $output .= $this->putJsIncludesToBody();
            }
            if ($enableCatTabs == true) {
                $output .= $htmlTabs;
            }
            //add rtl prefix to get the gallery to right if needed
            if ($isRtlWrapper == true) {
                $output .= self::LINE_PREFIX1 . "<div class='ug-rtl'{$rtlWrapperStyle}>";
            }
            $output .= self::LINE_PREFIX1 . "<div id='{$this->galleryHtmlID}' class='unite-gallery'{$wrapperStyle}>";
            $output .= self::LINE_PREFIX2 . $this->putItems($arrItems);
            $output .= self::LINE_PREFIX1 . "</div>";
            if ($isRtlWrapper == true) {
                $output .= self::LINE_PREFIX1 . "</div>";
            }
            $output .= self::BR;
            $output = $this->putGalleryScripts($output);
            $output .= self::BR;
            $output .= self::LINE_PREFIX1 . "<!-- END UNITEGALLERY LITE-->";
            $compressOutput = $this->getParam("compress_output", self::FORCE_BOOLEAN);
            if ($compressOutput == true) {
                $output = str_replace("\r", "", $output);
                $output = str_replace("\n", "", $output);
                $output = trim($output);
            }
            return $output;
            ?>
				
			<?php 
        } catch (Exception $e) {
            $prefix = __("Unite Gallery Error", UNITEGALLERY_TEXTDOMAIN);
            $output = $this->getErrorMessage($e, $prefix);
            return $output;
        }
    }
 /**
  * 
  * add item from data
  */
 public function addFromData($data)
 {
     $type = UniteFunctionsUG::getVal($data, "type");
     $catID = UniteFunctionsUG::getVal($data, "catID");
     UniteFunctionsUG::validateNumeric($catID, "category id");
     switch ($type) {
         case "image":
             $itemHtml = $this->addFromData_images($data);
             break;
         default:
             //add media
             $itemHtml = $this->addFromData_media($data);
             break;
     }
     //get categories html
     $objCats = new UniteGalleryCategories();
     $htmlCatList = $objCats->getHtmlCatList($catID);
     //output html items and cats
     $output = array();
     $output["htmlItem"] = $itemHtml;
     $output["htmlCats"] = $htmlCatList;
     return $output;
 }