/** * Clean database by deleting some expired data */ protected function cleanDatabase() { // clean expired membership levels bx_import('BxDolAcl'); $oAcl = BxDolAcl::getInstance(); $iDeleteMemLevels = $oAcl ? $oAcl->maintenance() : 0; //--- Clean sessions ---// bx_import('BxDolSession'); $oSession = BxDolSession::getInstance(); $iSessions = $oSession ? $oSession->maintenance() : 0; // clean old views bx_import('BxDolView'); $iDeletedViews = BxDolView::maintenance(); // clean storage engine expired private file tokens bx_import('BxDolStorage'); $iDeletedExpiredTokens = BxDolStorage::pruning(); // clean outdated transcoded images bx_import('BxDolImageTranscoder'); $iDeletedTranscodedImages = BxDolImageTranscoder::pruning(); // clean expired keys bx_import('BxDolKey'); $oKey = BxDolKey::getInstance(); $iDeletedKeys = $oKey ? $oKey->prune() : 0; // clean old votes bx_import('BxDolVote'); $iDeletedVotes = BxDolVote::maintenance(); echo _t('_sys_pruning_db', $iDeleteMemLevels, $iSessions, $iDeletedViews, $iDeletedVotes, $iDeletedKeys, $iDeletedExpiredTokens, $iDeletedTranscodedImages); }
/** * Depending on original file mime type call appropriate transcoder */ public function getFileUrl($mixedHandler) { $oStorageOriginal = BxDolStorage::getObjectInstance($this->_aObject['source_params']['object']); if (!$oStorageOriginal) { return false; } $aFile = $oStorageOriginal->getFile($mixedHandler); if (!$aFile) { return false; } $sTranscoder = ''; if (0 === strncmp($aFile['mime_type'], 'image/', 6) && !empty($this->_aObject['source_params']['image'])) { $sTranscoder = $this->_aObject['source_params']['image']; } elseif (0 === strncmp($aFile['mime_type'], 'video/', 6) && !empty($this->_aObject['source_params']['video_poster'])) { $sTranscoder = $this->_aObject['source_params']['video_poster']; // if additional video transcoders provided call it to force video conversion if (empty($this->_aObject['source_params']['video'])) { continue; } foreach ($this->_aObject['source_params']['video'] as $sVideoTranscoder) { if (!($oTranscoder = BxDolTranscoderImage::getObjectInstance($sVideoTranscoder))) { continue; } $oTranscoder->getFileUrl($mixedHandler); } } if (!$sTranscoder) { return false; } if (!($oTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder))) { return false; } return $oTranscoder->getFileUrl($mixedHandler); }
/** * Check all pending for uninstallation modules and uninstall them if no pending for deletion files are found */ public static function checkModulesPendingUninstall() { bx_import('BxDolModuleQuery'); $a = BxDolModuleQuery::getInstance()->getModules(); foreach ($a as $aModule) { // after we make sure that all pending for deletion files are deleted if (!$aModule['pending_uninstall'] || BxDolStorage::isQueuedFilesForDeletion($aModule['name'])) { continue; } // remove pending uninstall flag self::setModulePendingUninstall($aModule['uri'], false); // perform uninstallation bx_import('BxDolStudioInstallerUtils'); $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'uninstall'); // send email nofitication $aTemplateKeys = array('Module' => $aModule['title'], 'Result' => _t('_Success'), 'Message' => ''); if ($aResult['code'] > 0) { $aTemplateKeys['Result'] = _t('_Failed'); $aTemplateKeys['Message'] = $aResult['message']; } bx_import('BxDolEmailTemplates'); $aMessage = BxDolEmailTemplates::getInstance()->parseTemplate('t_DelayedModuleUninstall', $aTemplateKeys); sendMail(getParam('site_email'), $aMessage['Subject'], $aMessage['Body'], 0, array(), BX_EMAIL_SYSTEM); } }
function genRowImageUploader(&$aInput) { $aTmplVarsPreview = array('bx_if:show_empty' => array('condition' => true, 'content' => array()), 'bx_if:show_image' => array('condition' => false, 'content' => array())); if (($iId = (int) $aInput['value']) != 0) { $sFileUrl = false; if (!empty($aInput['transcoder_object'])) { $oTranscoder = BxDolTranscoderImage::getObjectInstance($aInput['transcoder_object']); $sFileUrl = $oTranscoder->getFileUrlNotReady($iId); if (isset($aInput['transcoder_image_width']) && $aInput['transcoder_image_width'] > 0) { $sFileUrl = bx_append_url_params($sFileUrl, array('x' => $aInput['transcoder_image_width'])); } if (isset($aInput['transcoder_image_height']) && $aInput['transcoder_image_height'] > 0) { $sFileUrl = bx_append_url_params($sFileUrl, array('y' => $aInput['transcoder_image_height'])); } } else { $sStorage = isset($aInput['storage_object']) && $aInput['storage_object'] != '' ? $aInput['storage_object'] : BX_DOL_STORAGE_OBJ_IMAGES; $oStorage = BxDolStorage::getObjectInstance($sStorage); $sFileUrl = $oStorage->getFileUrlById($iId); } if ($sFileUrl !== false) { $aTmplVarsPreview['bx_if:show_empty']['condition'] = false; $aTmplVarsPreview['bx_if:show_image'] = array('condition' => true, 'content' => array('url' => $sFileUrl, 'bx_if:show_action_delete' => array('condition' => isset($aInput['ajax_action_delete']) && $aInput['ajax_action_delete'] != "", 'content' => array('action' => $aInput['ajax_action_delete'])))); } } $sRow = ''; $aInputPreview = array('type' => 'custom', 'name' => 'preview', 'caption' => isset($aInput['caption_preview']) ? $aInput['caption_preview'] : _t('_adm_txt_form_view_iu_preview'), 'content' => $this->oTemplate->parseHtmlByName('form_view_iu_preview.html', $aTmplVarsPreview)); $sRow .= $this->genRow($aInputPreview); $aInput['type'] = 'file'; $sRow .= $this->genRow($aInput); return $sRow; }
public function processing() { set_time_limit(36000); ignore_user_abort(); if (BxDolStorage::pruneDeletions()) { // if any files were deleted BxDolInstallerUtils::checkModulesPendingUninstall(); } // try to uninstall modules pending for uninstall }
public function performActionImport() { $iAffected = 0; $aIds = bx_get('ids'); if (!$aIds || !is_array($aIds)) { $this->_echoResultJson(array()); exit; } $aIdsAffected = array(); foreach ($aIds as $iId) { $aItem = array(); $iItem = $this->oDb->getItems(array('type' => 'by_id', 'value' => (int) $iId), $aItem); if ($iItem != 1 || empty($aItem)) { continue; } $mixedIcon = 0; if (is_numeric($aItem['icon']) && (int) $aItem['icon'] != 0) { bx_import('BxDolStorage'); $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES); if (($mixedIcon = $oStorage->storeFileFromStorage(array('id' => (int) $aItem['icon']), false, 0)) === false) { $this->_echoResultJson(array('msg' => _t('_adm_nav_err_items_icon_copy') . $oStorage->getErrorString()), true); return; } $oStorage->afterUploadCleanup($mixedIcon, 0); } $iIdImported = (int) $aItem['id']; $sTitleKey = $aItem['title']; unset($aItem['id']); $aItem['set_name'] = $this->sSet; $aItem['module'] = BX_DOL_STUDIO_MODULE_CUSTOM; $aItem['title'] .= '_' . time(); $aItem['icon'] = $mixedIcon != 0 ? $mixedIcon : ''; $aItem['active'] = 1; $aItem['order'] = $this->oDb->getItemOrderMax($this->sSet) + 1; if (($iIdAdded = (int) $this->oDb->addItem($aItem)) == 0) { continue; } bx_import('BxDolStudioLanguagesUtils'); BxDolStudioLanguagesUtils::getInstance()->addLanguageString($aItem['title'], _t($sTitleKey)); $aIdsImported[] = $iIdImported; $aIdsAdded[] = $iIdAdded; $iAffected++; } $aResult = array('msg' => _t('_adm_nav_err_items_import')); if ($iAffected) { $oGrid = BxDolGrid::getObjectInstance('sys_studio_nav_items'); if ($oGrid !== false) { $aResult = array('parent_grid' => $oGrid->getCode(false), 'parent_blink' => $aIdsAdded, 'disable' => $aIdsImported, 'eval' => $this->getJsObject() . '.onImport(oData)'); } } $this->_echoResultJson($aResult); }
function uninstall($aParams, $bDisable = false) { // check if module is already waiting while files are deleting bx_import('BxDolInstallerUtils'); if (BxDolInstallerUtils::isModulePendingUninstall($this->_aConfig['home_uri'])) { return array('message' => _t('_adm_err_modules_pending_uninstall_already'), 'result' => false); } // queue for deletion storage files $bSetModulePendingUninstall = false; foreach ($this->_aStorages as $s) { if (($o = BxDolStorage::getObjectInstance($s)) && $o->queueFilesForDeletionFromObject()) { $bSetModulePendingUninstall = true; } } // delete comments and queue for deletion comments attachments bx_import('BxDolCmts'); $iFiles = 0; BxDolCmts::onModuleUninstall($this->_aConfig['name'], $iFiles); if ($iFiles) { $bSetModulePendingUninstall = true; } // if some files were added to the queue, set module as pending uninstall if ($bSetModulePendingUninstall) { BxDolInstallerUtils::setModulePendingUninstall($this->_aConfig['home_uri']); return array('message' => _t('_adm_err_modules_pending_uninstall'), 'result' => false); } // delete associated connections if ($this->_aConnections) { bx_import('BxDolConnection'); foreach ($this->_aConnections as $sObjectConnections => $a) { $o = BxDolConnection::getObjectInstance($sObjectConnections); if (!$o) { continue; } $sFuncSuffix = 'DeleteInitiatorAndContent'; if (isset($a['conn']) && 'initiator' == $a['conn']) { $sFuncSuffix = 'DeleteInitiator'; } elseif (isset($a['conn']) && 'content' == $a['conn']) { $sFuncSuffix = 'DeleteContent'; } if (isset($a['type']) && 'profiles' == $a['type']) { $sFunc = 'onModuleProfile' . $sFuncSuffix; $o->{$sFunc}($this->_aConfig['name']); } else { $sFunc = 'onModule' . $sFuncSuffix; $o->{$sFunc}($a['table'], $a['field_id']); } } } return parent::uninstall($aParams, $bDisable); }
function deleteByItem(&$aItem) { if (is_numeric($aItem['icon']) && (int) $aItem['icon'] != 0) { if (!BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int) $aItem['icon'], 0)) { return false; } } if ((int) $this->_delete($aItem['id']) <= 0) { return false; } $oLanguage = BxDolStudioLanguagesUtils::getInstance(); $oLanguage->deleteLanguageString($aItem['title_system']); $oLanguage->deleteLanguageString($aItem['title']); return true; }
/** * Add all available meta tags to the head section * @return number of successfully added metas */ public function metaAdd($iId, $mixedImage = false) { $i = 0; foreach ($this->_aMetas as $sMeta) { $sFunc = $sMeta . 'AddMeta'; $i += $this->{$sFunc}($iId); } if ($mixedImage && is_array($mixedImage)) { bx_import('BxDolStorage'); $oStorage = BxDolStorage::getObjectInstance($mixedImage['object']); $mixedImage = $oStorage ? $oStorage->getFileUrlById($mixedImage['id']) : false; } if ($mixedImage) { BxDolTemplate::getInstance()->addPageMetaImage($mixedImage); } return $i; }
protected function delete($iId) { $aLevel = array(); $iLevel = $this->oDb->getLevels(array('type' => 'by_id', 'value' => (int) $iId), $aLevel); if ($iLevel != 1 || empty($aLevel)) { return false; } if ($aLevel['removable'] != 'yes' || $this->oDb->isLevelUsed($aLevel['id'])) { return false; } if (is_numeric($aLevel['icon'])) { if (!BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int) $aLevel['icon'], 0)) { return false; } } $oLanguage = BxDolStudioLanguagesUtils::getInstance(); $oLanguage->deleteLanguageString($aLevel['name']); $oLanguage->deleteLanguageString($aLevel['description']); return $this->oDb->deleteLevel(array('type' => 'by_id', 'value' => $aLevel['id'])); }
public function actionDeleteProfileImg($iFileId, $iContentId, $sFieldPicture) { $aResult = array(); $CNF =& $this->_oConfig->CNF; $oSrorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']); if (!($aFile = $oSrorage->getFile((int) $iFileId)) || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)) || $aContentInfo[$sFieldPicture] != (int) $iFileId) { $aResult = array('error' => 1, 'msg' => _t('_sys_storage_err_file_not_found')); } if (!$aResult && !isLogged() || !$aResult && $aFile['profile_id'] != bx_get_logged_profile_id() && !$this->_isModerator()) { $aResult = array('error' => 2, 'msg' => _t('_Access denied')); } $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate); if (!$aResult && !$oForm->_deleteFile($iContentId, $sFieldPicture, (int) $iFileId, true)) { $aResult = array('error' => 3, 'msg' => _t('_Failed')); } elseif (!$aResult) { $aResult = array('error' => 0, 'msg' => ''); } header('Content-Type: application/json; charset=utf-8'); echo json_encode($aResult); }
/** * Handle uploads here. * @param $mixedFiles as usual $_FILES['some_name'] array, but maybe some other params depending on the uploader * @return nothing, but if some files failed to upload, the actual error message can be determined by calling BxDolUploader::getUploadErrorMessages() */ public function handleUploads($iProfileId, $mixedFiles, $isMultiple = true, $iContentId = false, $bPrivate = true) { $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject); $iProfileId = bx_get_logged_profile_id(); if (!$isMultiple) { $this->cleanupGhostsForProfile($iProfileId, $iContentId); } if (bx_get('qqfile')) { $iId = $oStorage->storeFileFromXhr(bx_get('qqfile'), $bPrivate, $iProfileId, $iContentId); } else { $iId = $oStorage->storeFileFromForm($_FILES['qqfile'], $bPrivate, $iProfileId, $iContentId); } if ($iId) { $aResponse = array('success' => 1); } else { $this->appendUploadErrorMessage(_t('_sys_uploader_err_msg', isset($_FILES['qqfile']['name']) ? $_FILES['qqfile']['name'] : bx_get('qqfile'), $oStorage->getErrorString())); $aResponse = array('error' => $this->getUploadErrorMessages()); } echo htmlspecialchars(json_encode($aResponse), ENT_NOQUOTES); }
function delete($iContentId, $aContentInfo = array()) { $CNF =& $this->_oModule->_oConfig->CNF; // delete associated files if (!empty($CNF['OBJECT_STORAGE'])) { bx_import('BxDolStorage'); $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']); if ($oStorage) { $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId); } } // delete associated objects data if (!empty($CNF['OBJECT_VIEWS'])) { bx_import('BxDolView'); $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId); if ($o) { $o->onObjectDelete(); } } if (!empty($CNF['OBJECT_VOTES'])) { bx_import('BxDolVote'); $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId); if ($o) { $o->onObjectDelete(); } } if (!empty($CNF['OBJECT_COMMENTS'])) { bx_import('BxDolCmts'); $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId); if ($o) { $o->onObjectDelete(); } } if (!empty($CNF['OBJECT_METATAGS'])) { bx_import('BxDolMetatags'); $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']); $oMetatags->onDeleteContent($iContentId); } // delete db record return parent::delete($iContentId); }
function processImageUploaderSave($sName, $iId = 0) { if ($this->aInputs[$sName]['type'] != 'image_uploader') { return $iId; } $aInput = $this->aInputs[$sName]; if (!empty($_FILES[$sName]['tmp_name'])) { $iProfileId = getLoggedId(); $sStorage = isset($aInput['storage_object']) && $aInput['storage_object'] != '' ? $aInput['storage_object'] : BX_DOL_STORAGE_OBJ_IMAGES; $oStorage = BxDolStorage::getObjectInstance($sStorage); if ((int) $iId != 0 && !$oStorage->deleteFile($iId)) { return _t('_adm_err_form_view_iu_delete'); } $iId = $oStorage->storeFileFromForm($_FILES[$aInput['name']], false, $iProfileId); if ($iId === false) { return _t('_adm_err_form_view_iu_save') . $oStorage->getErrorString(); } $oStorage->afterUploadCleanup($iId, $iProfileId); } return (int) $iId; }
function BxDolStorageHelperStorage($aParams) { $this->iFileId = $aParams['id']; $this->oStorage = BxDolStorage::getObjectInstance($aParams['storage']); $this->aFile = false; if ($this->oStorage) { $this->aFile = $this->oStorage->getFile($this->iFileId); } }
protected function _getFormObject($sAction, $aItem = array()) { $aForm = array('form_attrs' => array('id' => 'adm-nav-item-', 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&set=' . $this->sSet, 'method' => BX_DOL_STUDIO_METHOD_DEFAULT, 'enctype' => 'multipart/form-data'), 'params' => array('db' => array('table' => 'sys_menu_items', 'key' => 'id', 'uri' => '', 'uri_title' => '', 'submit_name' => 'do_submit')), 'inputs' => array('id' => array('type' => 'hidden', 'name' => 'id', 'value' => isset($aItem['id']) ? (int) $aItem['id'] : 0, 'db' => array('pass' => 'Int')), 'set_name' => array('type' => 'hidden', 'name' => 'set_name', 'value' => $this->sSet, 'db' => array('pass' => 'Xss')), 'onclick' => array('type' => 'hidden', 'name' => 'onclick', 'value' => isset($aItem['onclick']) ? $aItem['onclick'] : '', 'db' => array('pass' => 'Xss')), 'title_system' => array('type' => 'text_translatable', 'name' => 'title_system', 'caption' => _t('_adm_nav_txt_items_title_system'), 'info' => _t('_adm_nav_dsc_items_title_system'), 'value' => isset($aItem['title_system']) ? $aItem['title_system'] : '_adm_nav_txt_item', 'required' => '1', 'db' => array('pass' => 'Xss'), 'checker' => array('func' => 'LengthTranslatable', 'params' => array(3, 100, 'title_system'), 'error' => _t('_adm_nav_err_items_title_system'))), 'title' => array('type' => 'text_translatable', 'name' => 'title', 'caption' => _t('_adm_nav_txt_items_title'), 'info' => _t('_adm_nav_dsc_items_title'), 'value' => isset($aItem['title']) ? $aItem['title'] : '_adm_nav_txt_item', 'required' => '0', 'db' => array('pass' => 'Xss')), 'submenu_object' => array('type' => 'select', 'name' => 'submenu_object', 'caption' => _t('_adm_nav_txt_items_submenu'), 'info' => _t('_adm_nav_dsc_items_submenu'), 'value' => isset($aItem['submenu_object']) ? $aItem['submenu_object'] : '', 'values' => array(), 'required' => '0', 'attrs' => array('onChange' => 'javascript:' . $this->getJsObject() . '.onChangeSubmenu(this)'), 'db' => array('pass' => 'Xss')), 'link' => array('type' => 'text', 'name' => 'link', 'caption' => _t('_adm_nav_txt_items_link'), 'info' => _t('_adm_nav_dsc_items_link'), 'value' => isset($aItem['link']) ? $aItem['link'] : '', 'required' => '0', 'db' => array('pass' => 'Xss'), 'checker' => array('func' => '', 'params' => array(), 'error' => _t('_adm_nav_err_items_link'))), 'target' => array('type' => 'select', 'name' => 'target', 'caption' => _t('_adm_nav_txt_items_target'), 'info' => _t('_adm_nav_dsc_items_target'), 'value' => isset($aItem['target']) ? $aItem['target'] : '_self', 'values' => array(array('key' => '', 'value' => _t('_adm_nav_txt_items_target_self')), array('key' => '_blank', 'value' => _t('_adm_nav_txt_items_target_blank'))), 'required' => '0', 'db' => array('pass' => 'Xss')), 'icon' => array('type' => 'text', 'name' => 'icon', 'caption' => _t('_adm_nav_txt_items_icon'), 'info' => _t('_adm_nav_dsc_items_icon'), 'value' => '', 'required' => '0', 'db' => array('pass' => 'Xss'), 'checker' => array('func' => '', 'params' => array(), 'error' => _t('_adm_nav_err_items_icon'))), 'icon_image' => array('type' => 'file', 'name' => 'icon_image', 'caption' => _t('_adm_nav_txt_items_icon_image'), 'info' => _t('_adm_nav_dsc_items_icon_image'), 'value' => '', 'checker' => array('func' => '', 'params' => '', 'error' => _t('_adm_nav_err_items_icon_image'))), 'icon_preview' => array('type' => 'custom', 'name' => 'icon_preview', 'caption' => _t('_adm_nav_txt_items_icon_image_old'), 'content' => ''), 'controls' => array('name' => 'controls', 'type' => 'input_set', array('type' => 'submit', 'name' => 'do_submit', 'value' => _t('_adm_nav_btn_items_add')), array('type' => 'reset', 'name' => 'close', 'value' => _t('_adm_nav_btn_items_cancel'), 'attrs' => array('onclick' => "\$('.bx-popup-applied:visible').dolPopupHide()", 'class' => 'bx-def-margin-sec-left'))))); $aMenus = array(); $this->oDb->getMenus(array('type' => 'all'), $aMenus, false); foreach ($aMenus as $aMenu) { $aForm['inputs']['submenu_object']['values'][$aMenu['object']] = _t($aMenu['title']); } asort($aForm['inputs']['submenu_object']['values']); $aForm['inputs']['submenu_object']['values'] = array_merge(array('' => _t('_adm_nav_txt_items_submenu_empty')), $aForm['inputs']['submenu_object']['values']); switch ($sAction) { case 'add': unset($aForm['inputs']['id']); unset($aForm['inputs']['icon_preview']); $aForm['form_attrs']['id'] .= 'create'; break; case 'edit': unset($aForm['inputs']['set_name']); $aForm['form_attrs']['id'] .= 'edit'; $aForm['inputs']['icon_image']['caption'] = _t('_adm_nav_txt_items_icon_image_new'); $aForm['inputs']['controls'][0]['value'] = _t('_adm_nav_btn_items_save'); if (($bSubmenu = !empty($aItem['submenu_object'])) === true) { $aForm['inputs']['link']['tr_attrs']['style'] = 'display:none;'; $aForm['inputs']['target']['tr_attrs']['style'] = 'display:none;'; } if (!$bSubmenu && ($aItem['onclick'] != "" || !in_array($aItem['target'], array('', '_blank')))) { $aForm['inputs']['submenu_object']['tr_attrs']['style'] = 'display:none;'; $aForm['inputs']['link']['tr_attrs']['style'] = 'display:none;'; $aForm['inputs']['target']['tr_attrs']['style'] = 'display:none;'; } $sIconImage = $sIconFont = ""; if (!empty($aItem['icon'])) { if (is_numeric($aItem['icon']) && (int) $aItem['icon'] != 0) { $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES); $sIconImage = $oStorage->getFileUrlById((int) $aItem['icon']); } else { $sIconFont = $aItem['icon']; $aForm['inputs']['icon']['value'] = $sIconFont; } } $aForm['inputs']['icon_preview']['content'] = $this->_getIconPreview($aItem['id'], $sIconImage, $sIconFont); break; } return new BxTemplStudioFormView($aForm); }
/** * page code function */ function PageCompMainCode() { ob_start(); $sTranscoderObjectPoster = 'sample_video_poster'; $sTranscoderObjectMP4 = 'sample_video_mp4'; $sTranscoderObjectWebM = 'sample_video_webm'; $sStorageObjectOrig = 'sample_transcoder_video_orig'; $iProfileId = bx_get_logged_profile_id(); if (!$iProfileId) { echo "You aren't logged in."; exit; } $iPrunedFiles = BxDolTranscoder::pruning(); if ($iPrunedFiles) { echo "iPrunedFiles: {$iPrunedFiles}"; exit; } $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($sTranscoderObjectPoster); $oTranscoderMP4 = BxDolTranscoderVideo::getObjectInstance($sTranscoderObjectMP4); $oTranscoderWebM = BxDolTranscoderVideo::getObjectInstance($sTranscoderObjectWebM); if (!$oTranscoderPoster || !$oTranscoderMP4 || !$oTranscoderWebM) { echo "Transcoder object is not available: " . $sTranscoderObjectPoster . ', ' . $sTranscoderObjectMP4 . ', ' . $sTranscoderObjectWebM; exit; } echo "registerHandlers poster: [" . $oTranscoderPoster->registerHandlers() . "] <br />\n"; echo "registerHandlers mp4: [" . $oTranscoderMP4->registerHandlers() . "] <br />\n"; echo "registerHandlers webm: [" . $oTranscoderWebM->registerHandlers() . "] <hr class='bx-def-hr' />\n"; $oStorageOrig = BxDolStorage::getObjectInstance($sStorageObjectOrig); if (!$oStorageOrig) { echo "Storage object is not available: " . $sStorageObjectOrig; exit; } if (isset($_POST['upload'])) { $iId = $oStorageOrig->storeFileFromForm($_FILES['file'], true, $iProfileId); if ($iId) { $iCount = $oStorageOrig->afterUploadCleanup($iId, $iProfileId); echo "<h2>Uploaded file id: " . $iId . "(deleted ghosts:" . $iCount . ") </h2>"; // force transcode echo "Force transcode: <br />"; echo "poster: " . $oTranscoderPoster->getFileUrl($iId) . '<br />'; echo "mp4: " . $oTranscoderMP4->getFileUrl($iId) . '<br />'; echo "webm: " . $oTranscoderWebM->getFileUrl($iId) . '<hr class="bx-def-hr" />'; } else { echo "<h2>Error uploading file: " . $oStorage->getErrorString() . '</h2><hr class="bx-def-hr" />'; } } elseif (isset($_POST['delete'])) { foreach ($_POST['file_id'] as $iFileId) { $bRet = $oStorageOrig->deleteFile($iFileId, $iProfileId); if ($bRet) { echo "<h2>Deleted file id: " . $iFileId . '</h2><hr class="bx-def-hr" />'; } else { echo "<h2>File deleting error: " . $oStorageOrig->getErrorString() . '</h2><hr class="bx-def-hr" />'; } } } else { $a = $oStorageOrig->getFilesAll(); foreach ($a as $r) { $sUrlPoster = $oTranscoderPoster->getFileUrl($r['id']); $sUrlMP4 = $oTranscoderMP4->getFileUrl($r['id']); $sUrlWebM = $oTranscoderWebM->getFileUrl($r['id']); echo '<h3>' . $r['file_name'] . '</h3>'; echo BxTemplFunctions::getInstance()->videoPlayer($sUrlPoster, $sUrlMP4, $sUrlWebM, false, 'height:200px;'); echo '<hr class="bx-def-hr" />'; } } $a = $oStorageOrig->getFilesAll(); ?> <h2>Files List</h2> <form method="POST"> <?php foreach ($a as $r) { ?> <input type="checkbox" name="file_id[]" value="<?php echo $r['id']; ?> " /> <?php echo $r['file_name']; ?> <br /> <?php } ?> <input type="submit" name="delete" value="Delete" class="bx-btn bx-btn-small bx-def-margin-sec-top" style="float:none;" /> </form> <hr class="bx-def-hr" /> <h2>Upload</h2> <form enctype="multipart/form-data" method="POST"> <input type="file" name="file" /> <br /> <input type="submit" name="upload" value="Upload" class="bx-btn bx-btn-small bx-def-margin-sec-top" style="float:none;" /> </form> <?php $s = ob_get_clean(); return DesignBoxContent("Sample video transcoder", $s, BX_DB_PADDING_DEF); }
/** * * Storage objects to automatically delete files from upon module uninstallation. * Note. Don't add storage objects used in transcoder objects. * @param string $sOperation - operation type. */ protected function actionProcessStorages($sOperation) { if (empty($this->_aConfig['storages'])) { return BX_DOL_STUDIO_INSTALLER_FAILED; } // check if module is already waiting while files are deleting if (self::isModulePendingUninstall($this->_aConfig['home_uri'])) { return array('code' => BX_DOL_STUDIO_INSTALLER_FAILED, 'content' => _t('_adm_err_modules_pending_uninstall_already')); } $bSetModulePendingUninstall = false; // queue for deletion storage files foreach ($this->_aConfig['storages'] as $s) { if (($o = BxDolStorage::getObjectInstance($s)) && $o->queueFilesForDeletionFromObject()) { $bSetModulePendingUninstall = true; } } // delete comments and queue for deletion comments attachments $iFiles = 0; BxDolCmts::onModuleUninstall($this->_aConfig['name'], $iFiles); if ($iFiles) { $bSetModulePendingUninstall = true; } // if some files were added to the queue, set module as pending uninstall if ($bSetModulePendingUninstall) { self::setModulePendingUninstall($this->_aConfig['home_uri']); return array('code' => BX_DOL_STUDIO_INSTALLER_FAILED, 'content' => _t('_adm_err_modules_pending_uninstall')); } return BX_DOL_STUDIO_INSTALLER_SUCCESS; }
function entryAttachments($aData) { $oModule = BxDolModule::getInstance($this->MODULE); $CNF =& $oModule->_oConfig->CNF; bx_import('BxTemplFunctions'); bx_import('BxDolStorage'); bx_import('BxDolTranscoderImage'); $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']); $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']); $aTranscodersVideo = false; if ($CNF['OBJECT_VIDEOS_TRANSCODERS']) { $aTranscodersVideo = array('poster' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']), 'mp4' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']), 'webm' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['webm'])); } $aGhostFiles = $oStorage->getGhosts($aData[$CNF['FIELD_AUTHOR']], $aData[$CNF['FIELD_ID']]); if (!$aGhostFiles) { return false; } foreach ($aGhostFiles as $k => $a) { $isImage = $oTranscoder && 0 == strncmp('image/', $a['mime_type'], 6); // preview for images, transcoder object for preview must be defined $isVideo = $aTranscodersVideo && 0 == strncmp('video/', $a['mime_type'], 6); // preview for videos, transcoder object for video must be defined $sUrlOriginal = $oStorage->getFileUrlById($a['id']); $sImgPopupId = 'bx-messages-atachment-popup-' . $a['id']; // images are displayed with preview and popup upon clicking $aGhostFiles[$k]['bx_if:image'] = array('condition' => $isImage, 'content' => array('url_original' => $sUrlOriginal, 'attr_file_name' => bx_html_attribute($a['file_name']), 'popup_id' => $sImgPopupId, 'url_preview' => $oTranscoder->getFileUrl($a['id']), 'popup' => BxTemplFunctions::getInstance()->transBox($sImgPopupId, '<img src="' . $sUrlOriginal . '" />', true, true))); // videos are displayed inline $aGhostFiles[$k]['bx_if:video'] = array('condition' => $isVideo, 'content' => array('video' => $aTranscodersVideo ? BxTemplFunctions::getInstance()->videoPlayer($aTranscodersVideo['poster']->getFileUrl($a['id']), $aTranscodersVideo['mp4']->getFileUrl($a['id']), $aTranscodersVideo['webm']->getFileUrl($a['id']), false, '') : '')); // non-images are displayed as text links to original file $aGhostFiles[$k]['bx_if:not_image'] = array('condition' => !$isImage && !$isVideo, 'content' => array('url_original' => $sUrlOriginal, 'attr_file_name' => bx_html_attribute($a['file_name']), 'file_name' => bx_process_output($a['file_name']))); } $aVars = array('bx_repeat:attachments' => $aGhostFiles); return $this->parseHtmlByName('attachments.html', $aVars); }
protected function getOrigFileUrl_Storage($mixedHandler) { $oStorageOriginal = BxDolStorage::getObjectInstance($this->_aObject['source_params']['object']); if (!$oStorageOriginal) { return false; } return $oStorageOriginal->getFileUrlById($mixedHandler); }
protected function onBlockDelete($aBlock) { bx_import('BxDolStudioLanguagesUtils'); BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']); //--- Process Lang block if ($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '') { BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']); } //--- Process Image block if ($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') { $iImageId = $sImageAlign = ''; list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']); if (is_numeric($iImageId) && (int) $iImageId != 0) { bx_import('BxDolStorage'); BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int) $iImageId, 0); } } }
/** * Add all available meta tags to the head section * @return number of successfully added metas */ public function metaAdd($iId, $mixedImage = false) { $i = 0; foreach ($this->_aMetas as $sMeta) { $sFunc = $sMeta . 'AddMeta'; $i += $this->{$sFunc}($iId); } if ($mixedImage && is_array($mixedImage)) { if (!empty($mixedImage['object'])) { $o = BxDolStorage::getObjectInstance($mixedImage['object']); } elseif (!empty($mixedImage['transcoder'])) { $o = BxDolTranscoder::getObjectInstance($mixedImage['transcoder']); } $mixedImage = $o ? $o->getFileUrlById($mixedImage['id']) : false; } if ($mixedImage) { BxDolTemplate::getInstance()->addPageMetaImage($mixedImage); } return $i; }
<?php /** * @package Dolphin Core * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/ * @license CC-BY - http://creativecommons.org/licenses/by/3.0/ */ //ob_start(); require_once './inc/header.inc.php'; $sStorageObject = bx_process_input(bx_get('o')); $sFile = bx_process_input(bx_get('f')); $sToken = bx_process_input(bx_get('t')); bx_import('BxDolStorage'); $oStorage = BxDolStorage::getObjectInstance($sStorageObject); if (!$oStorage || !method_exists($oStorage, 'download')) { ob_end_clean(); bx_storage_download_error_occured(); exit; } $i = strrpos($sFile, '.'); $sRemoteId = $i !== false ? substr($sFile, 0, $i) : $sFile; if (!$sRemoteId) { ob_end_clean(); bx_storage_download_error_occured(); exit; } //ob_end_clean(); if (!$oStorage->download($sRemoteId, $sToken)) { $iError = $oStorage->getErrorCode(); switch ($iError) { case BX_DOL_STORAGE_ERR_FILE_NOT_FOUND:
function submitIcon(&$oForm) { $iProfileId = getLoggedId(); $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES); $iId = (int) getParam('sys_site_icon'); if ($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId)) { return $this->getJsResult('_adm_dsg_err_remove_old_icon'); } $iId = $oStorage->storeFileFromForm($_FILES['image'], true, $iProfileId); if ($iId === false) { $this->oDb->setParam('sys_site_icon', 0); return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false); } $this->oDb->setParam('sys_site_icon', $iId); $oStorage->afterUploadCleanup($iId, $iProfileId); return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_ICON); }
public function actionRemove() { if (!$this->isEnabled()) { $this->_echoResultJson(array()); return; } $iCmtId = 0; if (bx_get('Cmt') !== false) { $iCmtId = bx_process_input(bx_get('Cmt'), BX_DATA_INT); } $aCmt = $this->_oQuery->getCommentSimple($this->getId(), $iCmtId); if (!$aCmt) { $this->_echoResultJson(array('msg' => _t('_No such comment'))); return; } if ($aCmt['cmt_replies'] > 0) { $this->_echoResultJson(array('msg' => _t('_Can not delete comments with replies'))); return; } $iCmtAuthorId = $this->_getAuthorId(); if (!$this->isRemoveAllowed($aCmt)) { $this->_echoResultJson(array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrRemoveAllowed()) : _t('_Access denied'))); return; } if ($this->_oQuery->removeComment($this->getId(), $aCmt['cmt_id'], $aCmt['cmt_parent_id'])) { $this->_triggerComment(); $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName()); $aImages = $this->_oQuery->getImages($this->_aSystem['system_id'], $aCmt['cmt_id']); foreach ($aImages as $aImage) { $oStorage->deleteFile($aImage['image_id']); } $this->_oQuery->deleteImages($this->_aSystem['system_id'], $aCmt['cmt_id']); $this->isRemoveAllowed(true); $this->deleteMetaInfo($aCmt['cmt_id']); $oZ = new BxDolAlerts($this->_sSystem, 'commentRemoved', $this->getId(), $iCmtAuthorId, array('comment_id' => $aCmt['cmt_id'], 'comment_author_id' => $aCmt['cmt_author_id'])); $oZ->alert(); $this->_echoResultJson(array('id' => $iCmtId)); return; } $this->_echoResultJson(array('msg' => _t('_cmt_err_cannot_perform_action'))); }
protected function storeFileLocally_Storage($mixedHandler) { $oStorageOriginal = BxDolStorage::getObjectInstance($this->_aObject['source_params']['object']); if (!$oStorageOriginal) { return false; } $aFile = $oStorageOriginal->getFile($mixedHandler); if (!$aFile) { return false; } $sUrl = $oStorageOriginal->getFileUrlById($mixedHandler); if (!$sUrl) { return false; } $sFileData = bx_file_get_contents($sUrl); if (false === $sFileData) { return false; } $sTmpFile = $this->getTmpFilename($aFile['file_name']); if (!file_put_contents($sTmpFile, $sFileData)) { return false; } return $sTmpFile; }
protected function _getImage($sType, $mixedId, $aParams = array()) { $sUrl = ""; $aType2Method = array('image' => 'getImageUrl', 'icon' => 'getIconUrl'); //--- Check in System Storage. if (is_numeric($mixedId) && (int) $mixedId > 0) { if (($sResult = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->getFileUrlById((int) $mixedId)) !== false) { $sUrl = $sResult; } } //--- Check in template folders. if ($sUrl == "" && is_string($mixedId) && strpos($mixedId, '.') !== false) { $sUrl = $this->{$aType2Method}[$sType]($mixedId); } if ($sUrl != "") { $bClass = isset($aParams['class']) && !empty($aParams['class']); return $this->parseHtmlByName('bx_img.html', array('bx_if:class' => array('condition' => $bClass, 'content' => array('content' => $bClass ? $aParams['class'] : '')), 'src' => $sUrl, 'alt' => isset($aParams['alt']) ? $aParams['alt'] : '')); } //--- Use iconic font. return $this->parseHtmlByName('bx_icon.html', array('name' => $mixedId)); }
public function onDelete($aEvent) { $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post'); //--- Delete attached photos and links when common event was deleted. if ($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) { $aPhotos = $this->_oDb->getPhotos($aEvent['id']); if (!empty($aPhotos) && is_array($aPhotos)) { bx_import('BxDolStorage'); $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage')); foreach ($aPhotos as $iPhotoId) { $oStorage->deleteFile($iPhotoId); } $this->_oDb->deletePhotos($aEvent['id']); } $this->_oDb->deleteLinks($aEvent['id']); } //--- Update parent event when share event was deleted. if ($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_SHARE) { $this->_oDb->deleteShareTrack($aEvent['id']); $aContent = unserialize($aEvent['content']); $aShared = $this->_oDb->getShared($aContent['type'], $aContent['action'], $aContent['object_id']); if (!empty($aShared) && is_array($aShared)) { $this->_oDb->updateShareCounter($aShared['id'], $aShared['shares'], -1); } } //--- Find and delete share events when parent event was deleted. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']); $aShareEvents = $this->_oDb->getEvents(array('browse' => 'shared_by_descriptor', 'type' => $aEvent['type'])); foreach ($aShareEvents as $aShareEvent) { $aContent = unserialize($aShareEvent['content']); if (isset($aContent['type']) && $aContent['type'] == $aEvent['type'] && isset($aContent['object_id']) && ($bSystem && (int) $aContent['object_id'] == (int) $aEvent['object_id'] || !$bSystem && (int) $aContent['object_id'] == (int) $aEvent['id'])) { $this->_oDb->deleteEvent(array('id' => (int) $aShareEvent['id'])); } } //--- Event -> Delete for Alerts Engine ---// bx_import('BxDolAlerts'); $oAlert = new BxDolAlerts($this->_oConfig->getSystemName('alert'), 'delete', $aEvent['id'], $this->getUserId()); $oAlert->alert(); //--- Event -> Delete for Alerts Engine ---// }
function _deleteFile($iFileId) { $CNF =& $this->_oModule->_oConfig->CNF; if (!$iFileId) { return true; } bx_import('BxDolStorage'); if (!($oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']))) { return false; } if (!$oStorage->getFile($iFileId)) { return true; } $iProfileId = bx_get_logged_profile_id(); return $oStorage->deleteFile($iFileId, $iProfileId); }
protected function _getCommonData(&$aEvent) { $oModule = $this->getModule(); $sJsObject = $this->_oConfig->getJsObject('view'); $sPrefix = $this->_oConfig->getPrefix('common_post'); $sType = str_replace($sPrefix, '', $aEvent['type']); $aResult = array('owner_id' => $aEvent['object_id'], 'content_type' => $sType, 'content' => array('sample' => '_bx_timeline_txt_sample', 'url' => $this->_oConfig->getItemViewUrl($aEvent)), 'votes' => '', 'comments' => '', 'title' => '', 'description' => ''); switch ($sType) { case BX_TIMELINE_PARSE_TYPE_POST: if (!empty($aEvent['content'])) { $aResult['content'] = array_merge($aResult['content'], unserialize($aEvent['content'])); } $aLinks = $this->_oDb->getLinks($aEvent['id']); if (!empty($aLinks) && is_array($aLinks)) { foreach ($aLinks as $aLink) { $aResult['content']['links'][] = array('url' => $aLink['url'], 'title' => $aLink['title'], 'text' => $aLink['text']); } } $aPhotos = $this->_oDb->getPhotos($aEvent['id']); if (!empty($aPhotos) && is_array($aPhotos)) { bx_import('BxDolStorage'); $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage')); bx_import('BxDolImageTranscoder'); $oTranscoder = BxDolImageTranscoder::getObjectInstance($this->_oConfig->getObject('transcoder_view')); foreach ($aPhotos as $iPhotoId) { $iPhotoIndex = array_search($iPhotoId, $aPhotos); $sPhotoSrcOrig = $oStorage->getFileUrlById($iPhotoId); $aResult['content']['images'][] = array('src' => $oTranscoder->getImageUrl($iPhotoId), 'src_orig' => $sPhotoSrcOrig, 'title' => '', 'onclick' => $sJsObject . '.showPhoto(this, \'' . $sPhotoSrcOrig . '\')'); } } break; case BX_TIMELINE_PARSE_TYPE_SHARE: if (empty($aEvent['content'])) { return array(); } $aContent = unserialize($aEvent['content']); if (!$this->_oConfig->isSystem($aContent['type'], $aContent['action'])) { $aShared = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $aContent['object_id'])); $aShared = $this->_getCommonData($aShared); } else { $aShared = $this->_getSystemData($aContent); } if (empty($aShared) || !is_array($aShared)) { return array(); } $aResult['content'] = array_merge($aContent, $aShared['content']); $aResult['content']['parse_type'] = !empty($aShared['content_type']) ? $aShared['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT; $aResult['content']['owner_id'] = $aShared['owner_id']; list($aResult['content']['owner_name'], $aResult['content']['owner_url']) = $oModule->getUserInfo($aShared['owner_id']); list($sUserName) = $oModule->getUserInfo($aEvent['object_id']); $sSample = !empty($aResult['content']['sample']) ? $aResult['content']['sample'] : '_bx_timeline_txt_sample'; $aResult['title'] = _t('_bx_timeline_txt_user_shared_sample', $sUserName, $aResult['content']['owner_name'], _t($sSample)); $aResult['description'] = ''; break; } $sSystem = $this->_oConfig->getSystemName('vote'); if ($oModule->getVoteObject($sSystem, $aEvent['id']) !== false) { $aResult['votes'] = array('system' => $sSystem, 'object_id' => $aEvent['id'], 'count' => $aEvent['votes']); } $sSystem = $this->_oConfig->getSystemName('comment'); if ($oModule->getCmtsObject($sSystem, $aEvent['id']) !== false) { $aResult['comments'] = array('system' => $sSystem, 'object_id' => $aEvent['id'], 'count' => $aEvent['comments']); } return $aResult; }