/** * Returns full widget data (extends other widget or config dataset if needs) * * @param string|null $sWidgetId * @param array $aWidgetData * @param array $aWidgets * * @return array */ protected function _getWidgetData($sWidgetId, $aWidgetData, $aWidgets) { if (!empty($aWidgetData[Config::KEY_REPLACE])) { unset($aWidgetData[Config::KEY_EXTENDS]); return $aWidgetData; } $xExtends = true; $bReset = false; if (!empty($aWidgetData[Config::KEY_EXTENDS])) { $xExtends = $aWidgetData[Config::KEY_EXTENDS]; unset($aWidgetData[Config::KEY_EXTENDS]); } if (!empty($aWidgetData[Config::KEY_RESET])) { $bReset = $aWidgetData[Config::KEY_RESET]; unset($aWidgetData[Config::KEY_RESET]); } if ($xExtends) { if ($xExtends === true && $sWidgetId && isset($aWidgets[$sWidgetId])) { if ($bReset) { $aWidgetData = F::Array_Merge($aWidgets[$sWidgetId], $aWidgetData); } else { $aWidgetData = F::Array_MergeCombo($aWidgets[$sWidgetId], $aWidgetData); } } elseif (is_string($xExtends)) { if ($bReset) { $aWidgetData = F::Array_Merge(Config::Get($xExtends), $aWidgetData); } else { $aWidgetData = F::Array_MergeCombo(Config::Get($xExtends), $aWidgetData); } } } return $aWidgetData; }
public function __construct($aParam = null) { parent::__construct($aParam); if ($sName = $this->GetName()) { // задается идентификатор виджета $this->_checkId(); } if (is_null($this->GetPriority())) { $this->SetPriority(0); } if ($this->GetId()) { $aCfgData = Config::Get('widget.' . $this->GetId() . '.config'); if ($aCfgData) { $aCfgData = F::Array_Merge($this->getAllProps(), $aCfgData); $this->setProps($aCfgData); } } if ($sName && is_null($this->getType())) { $aTypeData = E::ModuleViewer()->DefineWidgetType($sName, $this->GetDir(), $this->GetPluginId()); if (isset($aTypeData['type'])) { $this->setType($aTypeData['type']); if ($aTypeData['type'] == 'template' && !empty($aTypeData['name'])) { $this->setTemplate($aTypeData['name']); $this->setName($aTypeData['name']); } /* LS-compatible */ if (!$this->getParam('plugin') && $this->getPluginId()) { $this->setParam('plugin', $this->getPluginId()); } } } }
/** * Save uploaded image into store * * @param string $sImageFile * @param ModuleUser_EntityUser $oUser * @param string $sType * @param array $aOptions * * @return bool */ protected function _saveTopicImage($sImageFile, $oUser, $sType, $aOptions = array()) { $sExtension = F::File_GetExtension($sImageFile, true); $aConfig = E::ModuleUploader()->GetConfig($sImageFile, 'images.' . $sType); if ($aOptions) { $aConfig['transform'] = F::Array_Merge($aConfig['transform'], $aOptions); } // Check whether to save the original if (isset($aConfig['original']['save']) && $aConfig['original']['save']) { $sSuffix = isset($aConfig['original']['suffix']) ? $aConfig['original']['suffix'] : '-original'; $sOriginalFile = F::File_Copy($sImageFile, $sImageFile . $sSuffix . '.' . $sExtension); } else { $sSuffix = ''; $sOriginalFile = null; } // Transform image before saving $sFileTmp = E::ModuleImg()->TransformFile($sImageFile, $aConfig['transform']); if ($sFileTmp) { $sDirUpload = E::ModuleUploader()->GetUserImageDir($oUser->getId(), true, $sType); $sFileImage = E::ModuleUploader()->Uniqname($sDirUpload, $sExtension); if ($oStoredFile = E::ModuleUploader()->Store($sFileTmp, $sFileImage)) { if ($sOriginalFile) { E::ModuleUploader()->Move($sOriginalFile, $oStoredFile->GetFile() . $sSuffix . '.' . $sExtension); } return $oStoredFile->GetUrl(); } } return false; }
/** * Fetch widget template * * @param string $sTemplate * @param array $aVars * * @return mixed */ protected function Fetch($sTemplate, $aVars = array()) { $aVars = F::Array_Merge(array('aWidgetParams' => $this->aParams), $aVars); return E::ModuleViewer()->FetchWidget($sTemplate, $aVars); }
/** * Save image to file * * @param string $sFile - Filename to save * @param array|DataArray $aOptions - Options * * @return string|bool */ public function Save($sFile, $aOptions = array()) { $aOptions = F::Array_Merge($this->GetOptions(), $aOptions); if ($oImage = $this->GetImage()) { $sFormat = isset($aOptions['save_as']) ? $aOptions['save_as'] : $this->GetFormat($sFile); if ($sFormat == 'jpeg') { $nQuality = isset($aOptions['quality']) ? $aOptions['quality'] : 100; $oImage->save($sFile, $sFormat, $nQuality); } else { $oImage->save($sFile, $sFormat); } return $sFile; } return false; }
/** * @return array */ public function GetPreparedAssetLinks() { $aResult = array(); foreach ($this->aAssets as $oAssetPackage) { if ($aLinks = $oAssetPackage->GetLinksArray(true, true)) { $aResult = F::Array_Merge($aResult, reset($aLinks)); } } return $aResult; }
/** * Возвращает меню по его идентификатору * * @param string $sMenuId * @param array $aParams * * @return ModuleMenu_EntityMenu|bool */ public function GetMenu($sMenuId, $aParams = null) { if (!$sMenuId) { return null; } if (isset($this->aMenu[$sMenuId])) { return $this->aMenu[$sMenuId]; } // Настройки меню if ($aMenu = Config::Get('menu.data.' . $sMenuId)) { if ($aParams) { $aMenu = F::Array_Merge($aMenu, $aParams); } // Такая форма вызова используется для того, // чтобы можно было повесить хук на этот метод $oMenu = E::ModuleMenu()->CreateMenu($sMenuId, $aMenu); return $oMenu; } return null; }
/** * Сохраняет в файловом кеше кастомную конфигурацию * * @param $aConfig * @param $bReset */ protected static function _putCustomCfg($aConfig, $bReset = false) { if (is_array($aConfig) && ($sFile = self::_checkCustomCfg())) { $aConfig['_timestamp_'] = time(); if (!$bReset) { // Объединяем текущую конфигурацию с сохраняемой $aOldConfig = self::_getCustomCfg(); if ($aOldConfig) { $aConfig = F::Array_Merge($aOldConfig, $aConfig); } } F::File_PutContents($sFile, F::Serialize($aConfig)); } }
/** * Transform image from file using config preset and/or options * * @param string $sFile * @param string $sPreset * @param array $aOptions * * @return bool */ public function TransformFile($sFile, $sPreset = 'default', $aOptions = array()) { if (is_array($sPreset)) { $aOptions = $sPreset; $sPreset = null; } if ($sPreset) { $aPresetOptions = $this->GetOptions($sFile, $sPreset, $aOptions); } else { $aPresetOptions = array(); } if ($aPresetOptions && $aOptions) { /** @var DataArray $aParams */ $aOptions = F::Array_Merge($aPresetOptions, $aOptions); } elseif (!$aOptions) { $aOptions = $aPresetOptions; } $bResult = false; if ($oImg = $this->Read($sFile)) { $bChanged = $this->Transform($oImg, $aOptions); if ($bChanged) { $oImg->Save($sFile, $aOptions); } $bResult = true; } return $bResult ? $sFile : false; }
function func_array_merge_assoc($aArr1, $aArr2) { return F::Array_Merge($aArr1, $aArr2); }
/** * Получает список блогов по фильтру * * @param array $aFilter - Фильтр выборки * @param array $aOrder - Сортировка * @param int $iCount - Возвращает общее количество элментов * @param int $iCurrPage - Номер текущей страницы * @param int $iPerPage - Количество элементов на одну страницу * * @return array */ public function GetBlogsIdByFilterPerPage($aFilter, $aOrder, &$iCount, $iCurrPage = null, $iPerPage = null) { $aCriteria = array('filter' => array(), 'order' => array()); if (!is_null($iPerPage)) { $iCurrPage = intval($iCurrPage); if ($iCurrPage < 1) { $iCurrPage = 1; } $aCriteria['limit'] = array(($iCurrPage - 1) * $iPerPage, $iPerPage); } if (isset($aFilter['type']) && !isset($aFilter['include_type'])) { $aCriteria['filter']['blog_type'] = $aFilter['type']; unset($aFilter['type']); } elseif (isset($aFilter['include_type'])) { $aCriteria['filter']['blog_type'] = $aFilter['include_type']; unset($aFilter['include_type']); } if (isset($aFilter['exclude_type'])) { $aCriteria['filter']['not_blog_type'] = $aFilter['exclude_type']; unset($aFilter['exclude_type']); } if (isset($aFilter['title'])) { if (strpos($aFilter['title'], '%') !== false) { $aCriteria['filter']['blog_title_like'] = $aFilter['title']; } else { $aCriteria['filter']['blog_title'] = $aFilter['title']; } unset($aFilter['title']); } if ($aFilter && is_array($aFilter)) { $aCriteria['filter'] = F::Array_Merge($aCriteria['filter'], $aFilter); } if (is_array($aOrder) && $aOrder) { $aCriteria['order'] = $aOrder; } else { $aCriteria['order'] = array('blog_id' => 'DESC'); } $aResult = $this->GetBlogsIdByCriteria($aCriteria); $iCount = $aResult['total']; return $aResult['data']; }
/** * Сохраняет данные в хранилище * * @param string $sStorageKey * @param array $aData * @param bool $bReset * * @return bool */ public function SetStorage($sStorageKey, $aData = array(), $bReset = true) { if (is_array($aData)) { if ($aData) { if ($this->nSaveMode == self::SAVE_MODE_ARR) { $aData = $this->_keysArray($aData); } if ($bReset || !isset($this->aStorage[$sStorageKey])) { $this->aStorage[$sStorageKey] = $aData; } else { $this->aStorage[$sStorageKey] = F::Array_Merge($this->aStorage[$sStorageKey], $aData); } } elseif (!isset($this->aStorage[$sStorageKey])) { $this->aStorage[$sStorageKey] = array(); } return true; } $this->aStorage[$sStorageKey] = array(); return false; }
/** * @param string $sKeyPath * @param array $xConfigData * @param string $sRoot * @param int $nLevel * * @return array */ protected function _extendsConfig($sKeyPath, $xConfigData, $sRoot = null, $nLevel) { if (isset($xConfigData[self::KEY_EXTENDS])) { $aParentData = array(); if (is_string($xConfigData[self::KEY_EXTENDS])) { $sLinkKey = $this->_storageKey($sRoot, '*') . '.' . $xConfigData[self::KEY_EXTENDS]; if (isset($this->aQuickMap[$sLinkKey])) { $aParentData = $this->aQuickMap[$sLinkKey]; } elseif (!$sKeyPath || strpos($xConfigData[self::KEY_EXTENDS], $sKeyPath) === false) { // ^^^ Prevents self linking $aParentData = $this->_keyReplace($sKeyPath, $xConfigData[self::KEY_EXTENDS], $sRoot, $nLevel); $this->aQuickMap[$sLinkKey] = $aParentData; } } unset($xConfigData[self::KEY_EXTENDS]); if (!empty($aParentData) && is_array($aParentData)) { if (!empty($xConfigData[self::KEY_RESET])) { $xConfigData = F::Array_Merge($aParentData, $xConfigData); } else { $xConfigData = F::Array_MergeCombo($aParentData, $xConfigData); } } $sKeyMap = $this->_storageKey($sRoot, '*') . '.' . $sKeyPath; // SET QUICK MAP AND CLEAR KEY EXTENDS $this->aQuickMap[$sKeyMap] = $xConfigData; //if (isset(self::$aKeyExtends[$sKeyMap])) { // unset(self::$aKeyExtends[$sKeyMap]); //} self::_clearKeyExtension($sKeyMap); } return $xConfigData; }
/** * @param array $xConfigData * @param string $sRoot * @param int $nLevel * * @return array */ protected function _extendsConfig($xConfigData, $sRoot = null, $nLevel) { if (isset($xConfigData[self::KEY_EXTENDS])) { $sLinkKey = $this->_storageKey($sRoot, '*') . '.' . $xConfigData[self::KEY_EXTENDS]; if (isset($this->aQuickMap[$sLinkKey])) { $aParentData = $this->aQuickMap[$sLinkKey]; } else { $aParentData = $this->_keyReplace($xConfigData[self::KEY_EXTENDS], $sRoot, $nLevel); $this->aQuickMap[$sLinkKey] = $aParentData; } unset($xConfigData[self::KEY_EXTENDS]); if (!empty($xConfigData[self::KEY_RESET])) { $xConfigData = F::Array_Merge($aParentData, $xConfigData); } else { $xConfigData = F::Array_MergeCombo($aParentData, $xConfigData); } } return $xConfigData; }