/**
  * 
  * get gallery data from xml file
  */
 private function initDataFromXml()
 {
     $errorPrefix = $this->filepathXmlFile . " parsing error:";
     if (!file_exists($this->filepathXmlFile)) {
         UniteFunctionsUG::throwError("File: '{$filepath}' not exists!!!");
     }
     $obj = simplexml_load_file($this->filepathXmlFile);
     if (empty($obj)) {
         UniteFunctionsUG::throwError("Wrong xml file format: {$this->filepathXmlFile}");
     }
     $objGeneral = $obj->general;
     if (empty($objGeneral)) {
         UniteFunctionsUG::throwError($errorPrefix . "General section not found.");
     }
     //get general data
     $arrData = (array) $objGeneral;
     $this->name = UniteFunctionsUG::getVal($arrData, "name");
     $this->typeTitle = UniteFunctionsUG::getVal($arrData, "title");
     $this->isPublished = UniteFunctionsUG::getVal($arrData, "published");
     $this->isPublished = UniteFunctionsUG::strToBool($this->isPublished);
     $this->itemsType = UniteFunctionsUG::getVal($arrData, "items_type", "all");
     //validatopm
     UniteFunctionsUG::validateNotEmpty($this->name, $errorPrefix);
     UniteFunctionsUG::validateNotEmpty($this->typeTitle, $errorPrefix);
 }
 /**
  * update thumb panel defaults of some gallery settings
  * should be inited gallery inside the framework
  */
 public static function updateThumbPanelDefaults($data)
 {
     UniteFunctionsUG::validateNotEmpty(GlobalsUGGallery::$gallery, "The gallery shouold be inited");
     //$valuesParams["theme_panel_position"] = $position;
     //include settings
     $panelPos = UniteFunctionsUG::getVal($data, "position");
     require HelperGalleryUG::getFilepathSettings("gallery_settings");
     $posRelatedFields = self::getPositionRelatedSettings();
     $valuesParams = UniteFunctionsUG::filterArrFields($valuesParams, $posRelatedFields);
     $valuesParams["theme_panel_position"] = $panelPos;
     GlobalsUGGallery::$gallery->updateParams($valuesParams);
 }
 /**
  * init the gallery framework by type name
  */
 protected static function initGalleryFramework($galleryTypeName, $galleryID = "")
 {
     $objGallery = "";
     if (!empty($galleryID)) {
         $objGallery = new UniteGalleryGallery();
         $objGallery->initByID($galleryID);
         $galleryTypeName = $objGallery->getTypeName();
     }
     UniteFunctionsUG::validateNotEmpty($galleryTypeName, "Gallery Type Name");
     $galleries = new UniteGalleryGalleries();
     self::$currentGalleryType = new UniteGalleryGalleryType();
     self::$currentGalleryType = $galleries->getGalleryTypeByName($galleryTypeName);
     GlobalsUGGallery::init(self::$currentGalleryType, $objGallery, $galleryID);
 }
示例#4
0
 /**
  * 
  * insert variables to some table
  */
 public function update($tableName, $arrData, $where)
 {
     if (method_exists($this->pdb, "update")) {
         $numRows = $this->pdb->update($tableName, $arrData, $where);
         return $numRows;
     }
     UniteFunctionsUG::validateNotEmpty($tableName, "table cannot be empty");
     UniteFunctionsUG::validateNotEmpty($where, "where cannot be empty");
     if (is_array($where)) {
         $where = $this->getWhereString($where);
     }
     $strFields = "";
     foreach ($arrData as $field => $value) {
         $value = "'" . $this->escape($value) . "'";
         if ($strFields != "") {
             $strFields .= ",";
         }
         $strFields .= "{$field}={$value}";
     }
     $updateQuery = "update {$tableName} set {$strFields} where {$where}";
     //$updateQuery = "update #__revslider_css set params='{\"font-size\":\"50px\",\"line-height\":\"67px\",\"font-weight\":\"700\",\"font-family\":\"\'Roboto\', sans-serif\",\"color\":\"#ffffff\",\"text-decoration\":\"none\",\"background-color\":\"rgba(141, 68, 173, 0.65)\",\"padding\":\"0px 15px 5px 15px\",\"border-width\":\"0px\",\"border-color\":\"rgb(34, 34, 34)\",\"border-style\":\"none\"}',hover='\"\"',settings='{\"hover\":\"false\"}' where handle = '.tp-caption.roboto'";
     $numRows = $this->runSql($updateQuery, "update error");
     //dmp($updateQuery);dmp($numRows);exit();
     return $numRows;
 }
 /**
  * 
  * get url ov preview gallery view
  */
 public static function getUrlViewPreview($galleryID = "")
 {
     if (empty($galleryID)) {
         $galleryID = GlobalsUGGallery::$galleryID;
     }
     UniteFunctionsUG::validateNotEmpty($galleryID, "gallery id");
     $url = HelperUG::getPreviewView($galleryID);
     return $url;
 }
 /**
  * update item data - media in db
  */
 private function updateItemData_media($data)
 {
     $title = UniteFunctionsUG::getVal($data, "title");
     UniteFunctionsUG::validateNotEmpty($title, "Item Title");
     $type = UniteFunctionsUG::getVal($data, "type");
     $urlImage = UniteFunctionsUG::getVal($data, "urlImage");
     $urlThumb = UniteFunctionsUG::getVal($data, "urlThumb");
     $arrUpdate = array();
     $arrUpdate["type"] = $type;
     $arrUpdate["url_image"] = HelperUG::URLtoRelative($urlImage);
     $arrUpdate["url_thumb"] = HelperUG::URLtoRelative($urlThumb);
     $arrUpdate["title"] = trim($title);
     $arrUpdate = $this->getAddDataFromMedia($data, $arrUpdate);
     $arrParams = UniteFunctionsUG::getVal($arrUpdate, "params");
     if (is_array($arrParams)) {
         $arrUpdate["params"] = json_encode($arrParams);
     }
     $this->db->update(GlobalsUG::$table_items, $arrUpdate, array("id" => $this->id));
     //init the item again from the new record
     $this->data = array_merge($this->data, $arrUpdate);
     $this->initByDBRecord($this->data);
 }
 /**
  * export gallery settings to downloadable file
  */
 public function exportSettings()
 {
     $this->validateInited();
     $galleryID = $this->id;
     $record = $this->db->fetchSingle(GlobalsUG::$table_galleries, "id={$galleryID}");
     UniteFunctionsUG::validateNotEmpty($record, "Gallery Record");
     unset($record["id"]);
     $strRecord = serialize($record);
     $filename = "unitegallery_" . $record["alias"] . ".txt";
     UniteFunctionsUG::downloadFileFromContent($strRecord, $filename);
     //the download content should exit
     UniteFunctionsUG::throwError("Something wrong witht the export, please try again");
     exit;
 }
 /**
  * 
  * load settings from xml file
  */
 public function loadXMLFile($filepath)
 {
     if (!file_exists($filepath)) {
         UniteFunctionsUG::throwError("File: '{$filepath}' not exists!!!");
     }
     $obj = simplexml_load_file($filepath);
     if (empty($obj)) {
         UniteFunctionsUG::throwError("Wrong xml file format: {$filepath}");
     }
     $fieldsets = $obj->fieldset;
     if (!@count($obj->fieldset)) {
         $fieldsets = array($fieldsets);
     }
     $this->addSection("Xml Settings");
     foreach ($fieldsets as $fieldset) {
         //Add Section
         $attribs = $fieldset->attributes();
         $sapName = (string) UniteFunctionsUG::getVal($attribs, "name");
         $sapLabel = (string) UniteFunctionsUG::getVal($attribs, "label");
         $sapIcon = (string) UniteFunctionsUG::getVal($attribs, "icon");
         $loadFrom = (string) UniteFunctionsUG::getVal($attribs, "loadfrom");
         UniteFunctionsUG::validateNotEmpty($sapName, "sapName");
         if (!empty($loadFrom)) {
             $this->addExternalSettings($sapName, $loadFrom);
             continue;
         }
         UniteFunctionsUG::validateNotEmpty($sapLabel, "sapLabel");
         $this->addSap($sapLabel, $sapName, false, $sapIcon);
         //--- add fields
         $fieldset = (array) $fieldset;
         $fields = UniteFunctionsUG::getVal($fieldset, "field");
         if (empty($fields)) {
             $fields = array();
         } else {
             if (is_array($fields) == false) {
                 $fields = array($fields);
             }
         }
         foreach ($fields as $field) {
             $attribs = $field->attributes();
             $fieldType = (string) UniteFunctionsUG::getVal($attribs, "type");
             $fieldName = (string) UniteFunctionsUG::getVal($attribs, "name");
             $fieldLabel = (string) UniteFunctionsUG::getVal($attribs, "label");
             $fieldDefaultValue = (string) UniteFunctionsUG::getVal($attribs, "default");
             //all other params will be added to "params array".
             $arrMustParams = array("type", "name", "label", "default");
             $arrParams = array();
             foreach ($attribs as $key => $value) {
                 $key = (string) $key;
                 $value = (string) $value;
                 //skip must params:
                 if (in_array($key, $arrMustParams)) {
                     continue;
                 }
                 $arrParams[$key] = $value;
             }
             $options = $this->getOptionsFromXMLField($field, $fieldName);
             //validate must fields:
             UniteFunctionsUG::validateNotEmpty($fieldType, "type");
             //validate name
             if ($fieldType != self::TYPE_HR && $fieldType != self::TYPE_CONTROL && $fieldType != "bulk_control_start" && $fieldType != "bulk_control_end") {
                 UniteFunctionsUG::validateNotEmpty($fieldName, "name");
             }
             switch ($fieldType) {
                 case self::TYPE_CHECKBOX:
                     $fieldDefaultValue = UniteFunctionsUG::strToBool($fieldDefaultValue);
                     $this->addCheckbox($fieldName, $fieldDefaultValue, $fieldLabel, $arrParams);
                     break;
                 case self::TYPE_COLOR:
                     $this->addColorPicker($fieldName, $fieldDefaultValue, $fieldLabel, $arrParams);
                     break;
                 case self::TYPE_HR:
                     $this->addHr($fieldName);
                     break;
                 case self::TYPE_TEXT:
                     $this->addTextBox($fieldName, $fieldDefaultValue, $fieldLabel, $arrParams);
                     break;
                 case self::TYPE_MULTIPLE_TEXT:
                     $this->addMultipleTextBox($fieldName, $fieldDefaultValue, $fieldLabel, $arrParams);
                     break;
                 case self::TYPE_STATIC_TEXT:
                     $this->addStaticText($fieldLabel, $fieldName, $arrParams);
                     break;
                 case self::TYPE_IMAGE:
                     $this->addImage($fieldName, $fieldDefaultValue, $fieldLabel, $arrParams);
                     break;
                 case self::TYPE_SELECT:
                     $this->addSelect($fieldName, $options, $fieldLabel, $fieldDefaultValue, $arrParams);
                     break;
                 case self::TYPE_CHECKBOX:
                     $this->addChecklist($fieldName, $options, $fieldLabel, $fieldDefaultValue, $arrParams);
                     break;
                 case self::TYPE_RADIO:
                     $this->addRadio($fieldName, $options, $fieldLabel, $fieldDefaultValue, $arrParams);
                     break;
                 case self::TYPE_BOOLEAN:
                     $options = array("true" => "Yes", "false" => "No");
                     $this->addRadio($fieldName, $options, $fieldLabel, $fieldDefaultValue, $arrParams);
                     break;
                 case self::TYPE_TEXTAREA:
                     $this->addTextArea($fieldName, $fieldDefaultValue, $fieldLabel, $arrParams);
                     break;
                 case self::TYPE_CUSTOM:
                     $this->add($fieldName, $fieldDefaultValue, $fieldLabel, self::TYPE_CUSTOM, $arrParams);
                     break;
                 case self::TYPE_BUTTON:
                     $this->addButton($fieldName, $fieldDefaultValue, $fieldLabel, $arrParams);
                     break;
                 case self::TYPE_CONTROL:
                     $parent = UniteFunctionsUG::getVal($arrParams, "parent");
                     $child = UniteFunctionsUG::getVal($arrParams, "child");
                     $ctype = UniteFunctionsUG::getVal($arrParams, "ctype");
                     $value = UniteFunctionsUG::getVal($arrParams, "value");
                     $this->addControl($parent, $child, $ctype, $value);
                     break;
                 case "bulk_control_start":
                     $parent = UniteFunctionsUG::getVal($arrParams, "parent");
                     $ctype = UniteFunctionsUG::getVal($arrParams, "ctype");
                     $value = UniteFunctionsUG::getVal($arrParams, "value");
                     $this->startBulkControl($parent, $ctype, $value);
                     break;
                 case "bulk_control_end":
                     $this->endBulkControl();
                     break;
                 case "codemirror":
                     $this->addCodemirror($fieldName, $fieldDefaultValue, $fieldLabel, $arrParams);
                     break;
                 default:
                     UniteFunctionsUG::throwError("wrong type: {$fieldType}");
                     break;
             }
         }
     }
 }
 /**
  * make thumbnail from the image, and save to some path
  * return new path
  */
 public function makeThumb($filepathImage, $pathThumbs, $maxWidth = -1, $maxHeight = -1, $type = "")
 {
     //validate input
     UniteFunctionsUG::validateFilepath($filepathImage, "image not found");
     UniteFunctionsUG::validateDir($pathThumbs, "Thumbs folder don't exists.");
     if ($type == self::TYPE_EXACT || $type == self::TYPE_EXACT_TOP) {
         if ($maxHeight == -1) {
             $this->throwError("image with exact type must have height!");
         }
         if ($maxWidth == -1) {
             $this->throwError("image with exact type must have width!");
         }
     }
     //get filename
     $info = UniteFunctionsUG::getPathInfo($filepathImage);
     $filename = UniteFunctionsUG::getVal($info, "basename");
     UniteFunctionsUG::validateNotEmpty($filename, "image filename not given");
     //if gd library doesn't exists - output normal image without resizing.
     if (function_exists("gd_info") == false) {
         $this->throwError("php must support GD Library");
     }
     if ($maxWidth == -1 && $maxHeight == -1) {
         $this->throwError("Wrong thumb size");
     }
     if ($maxWidth == -1) {
         $maxWidth = 1000000;
     }
     if ($maxHeight == -1) {
         $maxHeight = 100000;
     }
     $this->filename = $filename;
     $this->maxWidth = $maxWidth;
     $this->maxHeight = $maxHeight;
     $this->type = $type;
     $this->pathCache = $pathThumbs;
     $filenameThumb = $this->getThumbFilename();
     $filepathNew = $this->pathCache . $filenameThumb;
     if (file_exists($filepathNew)) {
         return $filenameThumb;
     }
     if ($type == self::TYPE_EXACT || $type == self::TYPE_EXACT_TOP) {
         $isSaved = $this->cropImageSaveNew($filepathImage, $filepathNew);
     } else {
         $isSaved = $this->resizeImageSaveNew($filepathImage, $filepathNew);
     }
     if ($isSaved) {
         return $filenameThumb;
     } else {
         return "";
     }
 }
    /**
     * draw settings row
     * @param $setting
     */
    protected function drawSettingRow($setting)
    {
        //set cellstyle:
        $cellStyle = "";
        if (isset($setting[UniteSettingsUG::PARAM_CELLSTYLE])) {
            $cellStyle .= $setting[UniteSettingsUG::PARAM_CELLSTYLE];
        }
        //set text style:
        $textStyle = $cellStyle;
        if (isset($setting[UniteSettingsUG::PARAM_TEXTSTYLE])) {
            $textStyle .= $setting[UniteSettingsUG::PARAM_TEXTSTYLE];
        }
        if ($textStyle != "") {
            $textStyle = "style='" . $textStyle . "'";
        }
        if ($cellStyle != "") {
            $cellStyle = "style='" . $cellStyle . "'";
        }
        //set hidden
        $rowStyle = "";
        if (isset($setting["hidden"])) {
            $rowStyle = "display:none;";
        }
        if (!empty($rowStyle)) {
            $rowStyle = "style='{$rowStyle}'";
        }
        //set text class:
        $class = "";
        if (isset($setting["disabled"])) {
            $class = "class='setting-disabled'";
        }
        //modify text:
        $text = UniteFunctionsUG::getVal($setting, "text", "");
        // prevent line break (convert spaces to nbsp)
        $text = str_replace(" ", " ", $text);
        switch ($setting["type"]) {
            case UniteSettingsUG::TYPE_CHECKBOX:
                $text = "<label for='" . $setting["id"] . "' style='cursor:pointer;'>{$text}</label>";
                break;
        }
        $description = UniteFunctionsUG::getVal($setting, "description");
        //set settings text width:
        $textWidth = "";
        if (isset($setting["textWidth"])) {
            $textWidth = 'width="' . $setting["textWidth"] . '"';
        }
        $addField = UniteFunctionsUG::getVal($setting, UniteSettingsUG::PARAM_ADDFIELD);
        ?>
						
			<?php 
        if (!empty($addField)) {
            $addSetting = $this->settings->getSettingByName($addField);
            UniteFunctionsUG::validateNotEmpty($addSetting, "AddSetting {$addField}");
            //set hidden
            $rowStyleAdd = "";
            if (isset($addSetting["hidden"])) {
                $rowStyleAdd = "display:none;";
            }
            if (!empty($rowStyleAdd)) {
                $rowStyleAdd = "style='{$rowStyleAdd}'";
            }
            $addSettingText = UniteFunctionsUG::getVal($addSetting, "text", "");
            $addSettingText = str_replace(" ", "&nbsp;", $addSettingText);
            ?>
				<tr <?php 
            echo $class;
            ?>
 valign="top">
				
				<td <?php 
            echo $cellStyle;
            ?>
 class="unite-settings-onecell" colspan="2">
					<span id="<?php 
            echo $setting["id_row"];
            ?>
" <?php 
            echo $rowStyle;
            ?>
>
						<span class='setting_onecell_text'><?php 
            echo $text;
            ?>
</span>				
							<?php 
            $this->drawInputs($setting);
            $this->drawInputAdditions($setting);
            ?>
						<span class="setting_onecell_horsap"></span>
					</span>
					
					<span id="<?php 
            echo $addSetting["id_row"];
            ?>
" <?php 
            echo $rowStyleAdd;
            ?>
>
						<span class='setting_onecell_text'><?php 
            echo $addSettingText;
            ?>
</span>				
						<?php 
            $this->drawInputs($addSetting);
            $this->drawInputAdditions($addSetting);
            ?>
					</span>
				</td>
				</tr>
				<?php 
            ?>
			<?php 
        } else {
            ?>
				<tr id="<?php 
            echo $setting["id_row"];
            ?>
" <?php 
            echo $rowStyle;
            ?>
 <?php 
            echo $class;
            ?>
 valign="top">
			
					<th <?php 
            echo $textStyle;
            ?>
 scope="row" <?php 
            echo $textWidth;
            ?>
>
						<?php 
            if ($this->showDescAsTips == true) {
                ?>
					    	<span class='setting_text' title="<?php 
                echo $description;
                ?>
"><?php 
                echo $text;
                ?>
</span>
					    <?php 
            } else {
                ?>
					    	<?php 
                echo $text;
                ?>
					    <?php 
            }
            ?>
					</th>
					<td <?php 
            echo $cellStyle;
            ?>
>
						<?php 
            $this->drawInputs($setting);
            $this->drawInputAdditions($setting);
            ?>
					</td>
				</tr>
			<?php 
        }
    }
 /**
  * 
  * duplicate gallery from data
  */
 public function duplicateGalleryFromData($data)
 {
     $galleryID = UniteFunctionsUG::getVal($data, "galleryID");
     UniteFunctionsUG::validateNotEmpty($galleryID, "gallery id");
     $gallery = new UniteGalleryGallery();
     $gallery->initByID($galleryID);
     $gallery->duplicate();
 }
 /**
  * 
  * update item data
  * get html item for admin response
  */
 public function updateItemData($data)
 {
     $itemID = UniteFunctionsUG::getVal($data, "itemID");
     UniteFunctionsUG::validateNotEmpty($itemID, "item params");
     $item = new UniteGalleryItem();
     $item->initByID($itemID);
     $item->updateItemData($data);
     $htmlItem = $item->getHtmlForAdmin();
     $response = array("html_item" => $htmlItem);
     return $response;
 }