/**
  * 
  * get galleries array from galleris folder with settings from config.xml from each gallery
  */
 private function initArrGalleryTypes()
 {
     $arrOrder = $this->getArrOrder();
     $strErrorPrefix = __("Load galleries error", UNITEGALLERY_TEXTDOMAIN);
     $arrDirs = UniteFunctionsUG::getDirList(GlobalsUG::$pathGalleries);
     $arrGalleries = array();
     //reorder arrdirs:
     $arrDirsNew = array();
     $arrDirs = UniteFunctionsUG::arrayToAssoc($arrDirs);
     foreach ($arrOrder as $dir) {
         if (array_key_exists($dir, $arrDirs)) {
             $arrDirsNew[] = $dir;
             unset($arrDirs[$dir]);
         }
     }
     $arrDirsNew = array_merge($arrDirsNew, $arrDirs);
     foreach ($arrDirsNew as $dir) {
         $pathGallery = GlobalsUG::$pathGalleries . $dir . "/";
         if (is_dir($pathGallery) == false) {
             continue;
         }
         $objGallery = new UniteGalleryGalleryType();
         $objGallery->initByFolder($dir);
         $galleryName = $objGallery->getName();
         $arrGalleries[$galleryName] = $objGallery;
     }
     self::$arrGalleryTypes = $arrGalleries;
 }
 /**
  * get category list by id's string
  */
 public function getListByIds($ids)
 {
     $ids = $this->db->escape($ids);
     $tableCats = GlobalsUG::$table_categories;
     $query = "select cats.* from {$tableCats} as cats WHERE cats.id IN(" . $ids . ")";
     $arrCats = $this->db->fetchSql($query);
     $arrCats = UniteFunctionsUG::arrayToAssoc($arrCats, "id");
     //order by IDs
     $arrIDs = explode(",", $ids);
     $arrCatsFinal = array();
     foreach ($arrIDs as $id) {
         if (array_key_exists($id, $arrCats)) {
             $arrCatsFinal[] = $arrCats[$id];
         }
     }
     return $arrCatsFinal;
 }
 /**
  * get different values in $arr from the default $arrDefault
  * $arrMustKeys - keys that must be in the output
  *
  */
 public static function getDiffArrItems($arr, $arrDefault, $arrMustKeys = array())
 {
     if (gettype($arrDefault) != "array") {
         return $arr;
     }
     if (!empty($arrMustKeys)) {
         $arrMustKeys = UniteFunctionsUG::arrayToAssoc($arrMustKeys);
     }
     $arrValues = array();
     foreach ($arr as $key => $value) {
         //treat must value
         if (array_key_exists($key, $arrMustKeys) == true) {
             $arrValues[$key] = self::getVal($arrDefault, $key);
             if (array_key_exists($key, $arr) == true) {
                 $arrValues[$key] = $arr[$key];
             }
             continue;
         }
         if (array_key_exists($key, $arrDefault) == false) {
             $arrValues[$key] = $value;
             continue;
         }
         $defaultValue = $arrDefault[$key];
         if ($defaultValue != $value) {
             $arrValues[$key] = $value;
             continue;
         }
     }
     return $arrValues;
 }
 /**
  * get unitegallery items array from attachment id's
  */
 public static function getArrItemsFromAttachments($arrIDs)
 {
     $arrPosts = get_posts(array('include' => $arrIDs, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => "none"));
     $arrItems = array();
     foreach ($arrPosts as $post) {
         $altText = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
         $item = array();
         $item["id"] = $post->ID;
         $item["image_id"] = $post->ID;
         $item["url_image"] = $post->guid;
         $item["title"] = $post->post_title;
         $item["description"] = $post->post_content;
         $item["alt"] = $altText;
         $arrThumb = self::getAttachmentImage($post->ID, self::THUMB_MEDIUM);
         $item["url_thumb"] = UniteFunctionsUG::getVal($arrThumb, "url");
         $item["thumb_width"] = UniteFunctionsUG::getVal($arrThumb, "width");
         $item["thumb_height"] = UniteFunctionsUG::getVal($arrThumb, "height");
         $arrItems[] = $item;
     }
     $arrItems = UniteFunctionsUG::arrayToAssoc($arrItems, "id");
     $arrItemsOrdered = array();
     foreach ($arrIDs as $id) {
         $arrItemsOrdered[] = $arrItems[$id];
     }
     return $arrItemsOrdered;
 }
 /**
  * 
  * save items order
  */
 private function saveItemsOrder($arrItemIDs)
 {
     //get items assoc
     $arrItems = $this->getItemsByIDs($arrItemIDs);
     $arrItems = UniteFunctionsUG::arrayToAssoc($arrItems, "id");
     $order = 0;
     foreach ($arrItemIDs as $itemID) {
         $order++;
         $arrItem = UniteFunctionsUG::getVal($arrItems, $itemID);
         if (!empty($arrItem) && $arrItem["ordering"] == $order) {
             continue;
         }
         $arrUpdate = array();
         $arrUpdate["ordering"] = $order;
         $this->db->update(GlobalsUG::$table_items, $arrUpdate, array("id" => $itemID));
     }
 }