Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.78 KB | None | 0 0
  1. <?php
  2.  
  3. abstract class ffThemeBuilderElement extends ffBasicObject {
  4. const DATA_ID = 'id';
  5. const DATA_NAME = 'name';
  6. const DATA_HAS_DROPZONE = 'has_dropzone';
  7. const DATA_CONNECT_WITH = 'connect_with';
  8. const DATA_HAS_CONTENT_PARAMS = 'has_content_params';
  9. const DATA_PICKER_MENU_ID = 'picker_menu_id';
  10. const DATA_PICKER_ITEM_WIDTH = 'data_picker_item_width';
  11. const DATA_PICKER_TAGS = 'picker_tags';
  12. const DATA_CAN_BE_CACHED = 'can_be_cached';
  13. const DATA_HAS_SYSTEM_TABS = 'has_system_tabs';
  14. const DATA_HAS_WRAPPER = 'has_wrapper';
  15. const DATA_IS_HIDDEN = 'data_is_hidden';
  16.  
  17.  
  18. /**********************************************************************************************************************/
  19. /* OBJECTS
  20. /**********************************************************************************************************************/
  21. /**
  22. * @var ffOptionsQueryDynamic
  23. */
  24. private $_queryDynamic = null;
  25.  
  26. /**
  27. * @var ffWPLayer
  28. */
  29. private $_WPLayer = null;
  30.  
  31. /**
  32. * @var ffThemeBuilderOptionsExtender
  33. */
  34. private $_optionsExtender = null;
  35.  
  36. /**
  37. * @var ffThemeBuilderBlockManager
  38. */
  39. private $_themeBuilderBlockManager = null;
  40.  
  41. /**
  42. * @var ffThemeBuilderAssetsRenderer
  43. */
  44. private $_assetsRenderer = null;
  45.  
  46. /**
  47. * @var ffThemeBuilderShortcodesStatusHolder
  48. */
  49. protected $_statusHolder = null;
  50.  
  51.  
  52. /**
  53. * @var ffThemeBuilderGlobalStyles
  54. */
  55. protected $_globalStyles = null;
  56.  
  57. /**********************************************************************************************************************/
  58. /* PRIVATE VARIABLES
  59. /**********************************************************************************************************************/
  60. /**
  61. * Settings like "name, id, has dropzone" are stored here. See the constants at the top of this file
  62. * @var array()
  63. */
  64. private $_data = array();
  65.  
  66. /**
  67. * @var callable
  68. */
  69. private $_doShortcodeCallback = null;
  70.  
  71. /**
  72. * Is caching mode
  73. * @var bool
  74. */
  75. protected $_isCachingMode = false;
  76.  
  77. /**
  78. * List of elements which are declined in the dropzone
  79. * @var null
  80. */
  81. protected $_dropzoneElementBlacklist = array();
  82.  
  83. /**
  84. * List of elements, which are accepted in the dropzone
  85. * @var null
  86. */
  87. protected $_dropzoneElementWhitelist = array();
  88.  
  89. /**
  90. * List of elements, which could be parents of this element
  91. * @var array
  92. */
  93. protected $_parentElementWhitelist = array();
  94.  
  95.  
  96. /**
  97. * If the element is printed in backend builder or fronted (For user)
  98. * @var bool
  99. */
  100. protected $_isEditMode = false;
  101.  
  102. protected $_defaultOptionsData = null;
  103.  
  104. protected $_elementOptionsStructure = null;
  105.  
  106. protected $_variationCounter = 0;
  107.  
  108. protected $_color = '';
  109.  
  110. /**********************************************************************************************************************/
  111. /* CONSTRUCT
  112. /**********************************************************************************************************************/
  113. public function __construct(
  114. ffThemeBuilderOptionsExtender $optionsExtender,
  115. ffOptionsQueryDynamic $query,
  116. ffWPLayer $WPLayer,
  117. ffThemeBuilderBlockManager $themeBuilderBlockManager,
  118. ffThemeBuilderAssetsRenderer $assetsRenderer,
  119. ffThemeBuilderShortcodesStatusHolder $statusHolder,
  120. ffThemeBuilderGlobalStyles $globalStyles
  121. )
  122. {
  123. $this->_setOptionsExtender( $optionsExtender );
  124. $this->_initData();
  125.  
  126. $query->setGetOptionsCallback( array($this, 'getElementOptionsStructure') );
  127. $query->setIteratorValidationCallback( array( $this, 'queryIteratorValidation') );
  128. $query->setIteratorStartCallback( array( $this, 'queryIteratorStart') );
  129. $query->setIteratorEndCallback( array( $this, 'queryIteratorEnd') );
  130.  
  131. $query->setIteratorBeginningCallback( array( $this, 'queryIteratorBeginning'));
  132. $query->setIteratorEndingCallback( array( $this, 'queryIteratorEnding'));
  133.  
  134. $query->setIsPrintingMode(true);
  135.  
  136.  
  137. $this->_setQueryDynamic($query);
  138. $this->_setWPLayer( $WPLayer );
  139. $this->_setThemeBuilderBlockManager( $themeBuilderBlockManager );
  140. $this->_setAssetsRenderer( $assetsRenderer );
  141. $this->_setStatusHolder( $statusHolder );
  142. $this->_setGlobalStyles( $globalStyles );
  143. }
  144. /**********************************************************************************************************************/
  145. /* PUBLIC FUNCTIONS
  146. /**********************************************************************************************************************/
  147. public function getIsHidden() {
  148. return $this->_getData( ffThemeBuilderElement::DATA_IS_HIDDEN, false);
  149. }
  150.  
  151. public function getCanBeCached() {
  152. $cachingStack = $this->_getStatusHolder()->getCustomStackCurrentValue('disableCaching');
  153.  
  154. if( $cachingStack ) {
  155. return false;
  156. }
  157.  
  158. return $this->_getData( ffThemeBuilderElement::DATA_CAN_BE_CACHED, true);
  159. }
  160.  
  161. public function getPreviewImageUrl() {
  162. return $this->getBaseUrlOfElement() . '/preview.jpg';
  163. }
  164.  
  165. public function getBaseUrlOfElement() {
  166. $className = get_class( $this );
  167. $classUrl = $this->_getClassLoader()->getClassUrl( $className );
  168. $toReturn = dirname( $classUrl );
  169.  
  170. return $toReturn;
  171. }
  172.  
  173. public function getBasePathOfElement() {
  174. $className = get_class( $this );
  175. $classPath = $this->_getClassLoader()->getClassPath( $className );
  176. $toReturn = dirname( $classPath );
  177.  
  178. return $toReturn;
  179. }
  180.  
  181. /**
  182. * Get the element options as encoded json string
  183. * @return string
  184. */
  185. public function getElementOptionsJSONString() {
  186. $themeBuilderCache = ffContainer()->getThemeFrameworkFactory()->getThemeBuilderCache();
  187.  
  188. $elementOptionsJSON = $themeBuilderCache->getElementOptionsFromCache( $this->getID() );
  189.  
  190. if( $elementOptionsJSON == null ) {
  191. $elementOptionsJSON = json_encode( $this->getElementOptionsJSON() );
  192. $themeBuilderCache->setElementOptionsToCache( $this->getID(), $elementOptionsJSON );
  193. }
  194.  
  195. return $elementOptionsJSON;
  196. }
  197.  
  198. public function getElementOptionsValues() {
  199. $structure = $this->getElementOptionsStructure();
  200. $arrayConvertor = $this->_getOptionsFactory()->createOptionsArrayConvertor(null, $structure );
  201. $data = $arrayConvertor->walk();
  202. return $data;
  203. }
  204.  
  205. /**
  206. * get the options json (basic options, the default ones)
  207. * @return array
  208. */
  209. public function getElementOptionsJSON() {
  210. $structure = $this->getElementOptionsStructure();
  211. $jsonConvertor = $this->_getOptionsFactory()->createOptionsPrinterJSONConvertor( null, $structure );
  212. $json = $jsonConvertor->walk();
  213. return $json;
  214. }
  215.  
  216. /**
  217. * Return default options data. If its not presented anywhere, then we generate it from basic options structure
  218. * @return array
  219. */
  220. public function getElementOptionsData() {
  221.  
  222. if( file_exists( $this->getBasePathOfElement() . '/default.json') ) {
  223. $dataJSON = file_get_contents( $this->getBasePathOfElement() . '/default.json' );
  224. $data = json_decode( $dataJSON );
  225. return $data;
  226. } else {
  227. $structure = $this->getElementOptionsStructure();
  228. $arrayConvertor = $this->_getOptionsFactory()->createOptionsArrayConvertor( null, $structure );
  229.  
  230. $this->_defaultOptionsData = $arrayConvertor->walk();
  231. return $this->_defaultOptionsData;
  232. }
  233.  
  234. // if( $this->_defaultOptionsData == null ) {
  235. //
  236. // }
  237.  
  238. }
  239.  
  240. /**
  241. * get the options structure (Basic options, the default ones)
  242. * @return ffOneStructure
  243. */
  244. abstract public function getElementOptionsStructure( $injectBlocksWithoutReference = false );
  245.  
  246. protected $_renderWrapper = false;
  247.  
  248. protected function _setRenderWrapper( $value ) {
  249. $this->_renderWrapper = $value;
  250. }
  251.  
  252. private function _hasWrapper() {
  253. if( $this->_getData( ffThemeBuilderElement::DATA_HAS_WRAPPER, true) ) {
  254. return true;
  255. } else {
  256. if( $this->_renderWrapper ) {
  257. $this->_renderWrapper = false;
  258. return true;
  259. }
  260. }
  261.  
  262. return false;
  263. }
  264.  
  265. private function _getSystemOptions( $query ) {
  266. $systemOptionsJSON = $query->getWithoutComparationDefault('o gen ffsys-info', '{}');
  267. $systemOptions = new ffDataHolder();
  268. $systemOptions->setDataJSON( $systemOptionsJSON );
  269. $systemOptions->elementId = $this->getID();
  270. $systemOptions->globalStyleName = $this->_getGlobalStyles()->getElementGlobalStyleName( $systemOptions->elementId, $systemOptions->get('global-style', 0) );
  271.  
  272. return $systemOptions;
  273. }
  274.  
  275.  
  276. /**
  277. * @param $data
  278. * @param $contentParams
  279. *
  280. * @return ffOptionsQueryDynamic
  281. */
  282. private function _getCompleteQuery( $data, $contentParams ) {
  283. $query = $this->_getQueryDynamic();
  284. $query->setElementClassName( get_class( $this) );
  285. $query->setData( $data );
  286.  
  287. //Content params are stored in shortcodes and their value is in the content of the shortcode
  288. if( $this->hasContentParams() && $contentParams != null ) {
  289. foreach( $contentParams as $route => $value ) {
  290. $query->setDataValue( $route, $value );
  291. }
  292. }
  293.  
  294. return $query;
  295. }
  296.  
  297. private function _getCachingHashForThisElement( $elementHash ) {
  298. $statusHolderHash = $this->_getStatusHolder()->getStatusHolderHash();
  299. $dataHash = $elementHash;
  300. $colorlibHash = ffContainer()->getThemeFrameworkFactory()->getThemeBuilderColorLibrary()->getLibraryHash();
  301. $globalStyleHash = md5(json_encode( ffContainer()->getThemeFrameworkFactory()->getThemeBuilderGlobalStyles()->getAllStylesForElement( $this->getID() ) ) );
  302.  
  303. $finalHash = md5( $statusHolderHash . $dataHash . $colorlibHash . $globalStyleHash );
  304.  
  305. return $finalHash;
  306. }
  307.  
  308. protected function _enqueueScriptsAndStyles( $query ) {
  309.  
  310. }
  311.  
  312. /**
  313. * @param $query ffOptionsQueryDynamic
  314. * @return bool
  315. */
  316. protected function _checkIfElementCanBeCached( $query ) {
  317. return true;
  318. }
  319.  
  320. /**
  321. * @param $data
  322. * @param $content
  323. * @param $uniqueId
  324. * @param $query
  325. * @param $elementHash string whole shortcode md5 (only if the element can be cached)
  326. * @return string|void
  327. */
  328. private function _renderElementWithCaching( $data, $content, $uniqueId, $query, $elementHash ) {
  329.  
  330.  
  331.  
  332. $cache = ffContainer()->getDataStorageCache();
  333.  
  334. $cachingNamespace = ffThemeBuilderCache::CACHE_NAMESPACE;
  335. $cachingName = $name = $this->getID() . '-' . $uniqueId;
  336.  
  337. // load all styles and scripts, no matter if cached or not
  338. $this->_enqueueScriptsAndStyles( $query );
  339. $finalHash = '';
  340. // can we run caching?
  341. if(
  342. FF_DEVELOPER_MODE == false && // is not developer mode
  343. $this->getCanBeCached() && // element supports caching
  344. $this->_checkIfElementCanBeCached( $query ) && // figure out if the element can be cached
  345. $this->_getData(ffThemeBuilderElement::DATA_HAS_DROPZONE, true ) == false // element does not have any dropzones
  346. ) {
  347.  
  348. /*
  349. * Hash of:
  350. * - status holder
  351. * - color library
  352. * - global styles (old)
  353. */
  354.  
  355. $finalHash = $this->_getCachingHashForThisElement( $elementHash );
  356. // load currently cached files
  357. $elementCachedData = $cache->getOption( $cachingNamespace, $cachingName );
  358.  
  359. if( $elementCachedData != null ) {
  360. $elementCachedData = json_decode( $elementCachedData, true );
  361. }
  362.  
  363. $cacheIsGood = true;
  364. if( $elementCachedData == null ) $cacheIsGood = false;
  365. if( !isset( $elementCachedData['hash'] ) ) $cacheIsGood = false;
  366. if( $elementCachedData['hash'] != $finalHash ) $cacheIsGood = false;
  367.  
  368. // ffStopWatch::addVariableDump( $elementCachedData['global_styles_used'] );
  369.  
  370. // are there used any global styles?
  371. if( isset($elementCachedData['global_styles_used']) ) {
  372. if( isset( $elementCachedData['global_styles_hash'] ) ) {
  373. $currentGlobalStylesHash = $this->_getGlobalStyles()->getGlobalStyleHash( $elementCachedData['global_styles_used'] );
  374.  
  375. if( $currentGlobalStylesHash != $elementCachedData['global_styles_hash'] ) {
  376. $cacheIsGood = false;
  377. }
  378.  
  379. } else {
  380. $cacheIsGood = false;
  381. }
  382. }
  383.  
  384. // serve files from cache
  385. if( $cacheIsGood ) {
  386. // CSS - serve and check if is the CSS file still up to date?
  387. $timeout = ffContainer()->getThemeFrameworkFactory()->getPrivateUpdateManager()->getCacheTimeout();
  388. if( isset( $elementCachedData['css'] ) && !empty( $elementCachedData['css'] ) && !($timeout != null && $timeout < time())) {
  389.  
  390. // if( !$this->_getStatusHolder()->hasBeenElementRendered( $uniqueId, $this ) ){
  391. $this->getAssetsRenderer()->createCssRule()->setContent($elementCachedData['css']);
  392. // }
  393.  
  394. }
  395.  
  396. // JS - server
  397. if( isset( $elementCachedData['js'] ) && !empty( $elementCachedData['js'] ) ) {
  398. $this->getAssetsRenderer()->createJavascriptCode()->setCode($elementCachedData['js']);
  399. }
  400.  
  401.  
  402. return $elementCachedData['content'];
  403. }
  404. }
  405.  
  406. // cache is apparently not good
  407. // $elementContent = $this->_renderJustTheElement( $data, $content, $uniqueId, $query );
  408.  
  409. $elementData['content'] = $this->_renderJustTheElement( $data, $content, $uniqueId, $query );
  410.  
  411. if(
  412. FF_DEVELOPER_MODE == false && // is not developer mode
  413. $this->getCanBeCached() && // element supports caching
  414. $this->_getData(ffThemeBuilderElement::DATA_HAS_DROPZONE, true ) == false // element does not have any dropzones
  415. ) {
  416.  
  417. $assetsRenderer = $this->getAssetsRenderer();
  418.  
  419. $elementData['hash'] = $finalHash;
  420. $elementData['css'] = $this->getAssetsRenderer()->getCssAsString();
  421. $elementData['js'] = $this->getAssetsRenderer()->getJavascriptAsString();
  422.  
  423.  
  424. /*----------------------------------------------------------*/
  425. /* GLOBAL STYLES HUSTLING
  426. /*----------------------------------------------------------*/
  427. $usedGlobalStyles = $this->_getStatusHolder()->getElementSpecificStack( ffThemeBuilderShortcodesStatusHolder::USED_GLOBAL_STYLES );
  428. if( !empty( $usedGlobalStyles) ) {
  429. $usedGlobalStyles = array_keys( $usedGlobalStyles );
  430. $usedGlobalStylesHash = $this->_getGlobalStyles()->getGlobalStyleHash( $usedGlobalStyles );
  431.  
  432. $elementData['global_styles_used'] = $usedGlobalStyles;
  433. $elementData['global_styles_hash'] = $usedGlobalStylesHash;
  434. }
  435.  
  436.  
  437. $timeout = ffContainer()->getThemeFrameworkFactory()->getPrivateUpdateManager()->getCacheTimeout();
  438.  
  439. if( $timeout != null && $timeout < time() ) {
  440. $cacheData['css'] = '';
  441. }
  442.  
  443. $elementDataJSON = json_encode( $elementData );
  444. $cache->setOption( $cachingNamespace, $cachingName, $elementDataJSON );
  445. }
  446.  
  447. if( $this->_getStatusHolder()->hasBeenElementRendered( $uniqueId, $this ) ) {
  448. // $this->getAssetsRenderer()->resetCss();
  449. }
  450.  
  451. return $elementData['content'];
  452.  
  453. }
  454.  
  455. private function _renderJustTheElement( $data, $content, $uniqueId, $query ) {
  456. /*----------------------------------------------------------*/
  457. /* PRINTING
  458. /*----------------------------------------------------------*/
  459. ob_start();
  460. $this->_render( $query->get('o gen'), $content, $query->getOnlyData(), $uniqueId );
  461. $content = ob_get_contents();
  462. ob_end_clean();
  463.  
  464. // re-set data to query, because of same elements nested inside
  465. $query->setElementClassName( get_class( $this) );
  466. $query->setData( $data );
  467.  
  468. /*----------------------------------------------------------*/
  469. /* PRINTING SYSTEM THINGS
  470. /*----------------------------------------------------------*/
  471. // if it has wrapper, we have to apply all our system things on it
  472. if( $this->_hasWrapper() ) {
  473.  
  474. $elementHelper = $this->_getAssetsRenderer()->getElementHelper();
  475. // unique css class
  476. $elementHelper->addAttribute('class', $this->_getCssSelectorFromUniqueId($uniqueId));
  477. $elementHelper->parse($content);
  478.  
  479. if ($this->_getData(ffThemeBuilderElement::DATA_HAS_SYSTEM_TABS, true)) {
  480.  
  481. $this->_getBlock(ffThemeBuilderBlock::BOX_MODEL)->get($query->get('o'));
  482. $this->_getBlock(ffThemeBuilderBlock::ADVANCED_TOOLS)->get($query->get('o'));
  483. $this->_getBlock(ffThemeBuilderBlock::COLORS)->setParam(ffThemeBuilderBlock_Colors::PARAM_TEXT_COLOR, $this->_color)->get($query->get('o'));
  484. $this->_getBlock(ffThemeBuilderBlock::CUSTOM_CODES)->get($query->get('o'));
  485. }
  486.  
  487. $content = $elementHelper->get();
  488. }
  489.  
  490.  
  491.  
  492. return $content;
  493. }
  494.  
  495. public function render( $data, $content = null, $uniqueId = null, $contentParams = null , $elementHash = null ) {
  496.  
  497. $query = $this->_getCompleteQuery( $data, $contentParams);
  498.  
  499. /*----------------------------------------------------------*/
  500. /* RENDERING THE ADMIN
  501. /*----------------------------------------------------------*/
  502. if( $this->_isEditMode ) {
  503. ob_start();
  504. $this->_renderAdmin( $query->getMustBeQueryNotEmpty('o gen'), $content, $query->getOnlyData(), $uniqueId);
  505. $content = ob_get_contents();
  506. ob_end_clean();
  507. return $content;
  508. }
  509.  
  510. /*----------------------------------------------------------*/
  511. /* DISABLING THE ELEMENT
  512. /*----------------------------------------------------------*/
  513. if( $query->getWithoutComparationDefault('o gen ffsys-disabled', 0) ) {
  514. return '';
  515. }
  516.  
  517. /*----------------------------------------------------------*/
  518. /* STACKING AND CONFIGURATION BEFORE PRINTING
  519. /*----------------------------------------------------------*/
  520. $systemOptions = $this->_getSystemOptions( $query );
  521.  
  522. $statusHolder = $this->_getStatusHolder();
  523.  
  524. // stacking the elements
  525. $statusHolder->addElementToStack( $this->getID() );
  526. $statusHolder->addSystemOptionsToStack( $systemOptions );
  527. $this->_getAssetsRenderer()->addSelectorToCascade( $this->_getCssSelectorFromUniqueId( $uniqueId ) );
  528.  
  529. // text color inheritance
  530. $textColor = $this->_getBlock( ffThemeBuilderBlock::COLORS)->setParam( ffThemeBuilderBlock_Colors::PARAM_TEXT_COLOR, $this->_color)->returnOnlyTextColor()->get( $query->get('o') );
  531.  
  532. if( !empty($textColor) ) {
  533. $statusHolder->addTextColorToStack( $textColor );
  534. }
  535.  
  536. $content = $this->_renderElementWithCaching($data, $content, $uniqueId, $query, $elementHash);
  537.  
  538. /*----------------------------------------------------------*/
  539. /* REMOVING THINGS FROM STACK
  540. /*----------------------------------------------------------*/
  541. // remove stacking from selector cascade
  542. $this->_getAssetsRenderer()->removeSelectorFromCascade();
  543.  
  544. // remove text color inheritance, if its presented
  545. if( !empty($textColor) ) {
  546. $statusHolder->removeTextColorFromStack();
  547. }
  548.  
  549. $statusHolder->removeSystemOptionsFromStack();
  550. // remove lement from stack
  551. $statusHolder->removeElementFromStack();
  552.  
  553. $statusHolder->addRenderedElement( $uniqueId );
  554.  
  555. return $content;
  556. }
  557.  
  558.  
  559. /**********************************************************************************************************************/
  560. /* PUBLIC PROPERTIES
  561. /**********************************************************************************************************************/
  562. public function setIsEditMode( $value ) {
  563. $this->_isEditMode = $value;
  564. $this->_getThemeBuilderBlockManager()->setIsEditMode( $value );
  565. }
  566.  
  567. public function getIsEditMode() {
  568. return $this->_isEditMode;
  569. }
  570.  
  571. public function getID() {
  572. return $this->_getData( ffThemeBuilderElement::DATA_ID );
  573. }
  574.  
  575. public function getData() {
  576. return $this->_data;
  577. }
  578.  
  579. /**
  580. * Data json for the javascript side
  581. * @return array
  582. */
  583. public function getElementDataForBuilder() {
  584.  
  585. $className = get_class( $this );
  586.  
  587. $data = array();
  588. $data['id'] = $this->_getData( ffThemeBuilderElement::DATA_ID );
  589. $data['name'] = $this->_getData( ffThemeBuilderElement::DATA_NAME );
  590. $data['defaultColor'] = $this->_color;
  591.  
  592. $data['optionsStructure'] = $this->getElementOptionsJSONString();
  593.  
  594. $data['picker'] = array();
  595. $data['picker']['menuId'] = $this->_getData( ffThemeBuilderElement::DATA_PICKER_MENU_ID );
  596. $data['picker']['tags'] = $this->_getData( ffThemeBuilderElement::DATA_PICKER_TAGS );
  597. $data['picker']['itemWidth'] = $this->_getData( ffThemeBuilderElement::DATA_PICKER_ITEM_WIDTH, 1 );
  598.  
  599. $data['functions'] = array();
  600. $data['functions']['renderContentInfo_JS'] = $this->_getJSFunction('_renderContentInfo_JS');
  601.  
  602. $data['defaultHtml'] = $this->_getDefaultHTML();
  603.  
  604. $data['previewImage'] = $this->getPreviewImageUrl();
  605.  
  606. $data['dropzoneWhitelistedElements'] = $this->_dropzoneElementWhitelist;
  607. $data['dropzoneBlacklistedElements'] = $this->_dropzoneElementBlacklist;
  608.  
  609. $data['parentWhitelistedElement'] = $this->_parentElementWhitelist;
  610. //
  611. return $data;
  612. }
  613.  
  614. public function hasContentParams() {
  615. return $this->_getData( ffThemeBuilderElement::DATA_HAS_CONTENT_PARAMS, false);
  616. }
  617.  
  618. public function getAssetsRenderer() {
  619. return $this->_getAssetsRenderer();
  620. }
  621.  
  622. /**********************************************************************************************************************/
  623. /* PRIVATE FUNCTIONS
  624. /**********************************************************************************************************************/
  625. protected function _reset() {
  626. $this->_variationCounter = 0;
  627. }
  628.  
  629. protected function _getDefaultHTML() {
  630. $query = $this->_getQueryDynamic()->setData(null);
  631. $data = $this->getElementOptionsData();
  632.  
  633.  
  634. ob_start();
  635. $this->_renderAdmin( $query, '', $data, null );
  636. $defaultHTML = ob_get_contents();
  637. ob_end_clean();
  638.  
  639. return $defaultHTML;
  640. }
  641.  
  642. protected function _getCssSelectorFromUniqueId( $uniqueId ) {
  643. return 'ffb-id-'. $uniqueId;
  644. }
  645. protected abstract function _initData();
  646.  
  647. /**
  648. * @param $s ffOneStructure|ffThemeBuilderOptionsExtender
  649. * @return mixed
  650. */
  651. protected abstract function _getElementGeneralOptions( $s );
  652. protected abstract function _render( ffOptionsQueryDynamic $query, $content, $data, $uniqueId );
  653. protected abstract function _renderAdmin( ffOptionsQueryDynamic $query, $content, $data, $uniqueId );
  654. protected function _beforeRenderingAdminWrapper( ffOptionsQueryDynamic $query, $content, ffMultiAttrHelper $multiAttrHelper, ffStdClass $otherData ) {}
  655. public abstract function queryIteratorValidation( $query, $key );
  656. public abstract function queryIteratorStart( $query, $key );
  657. public abstract function queryIteratorEnd( $query, $key );
  658.  
  659. public abstract function queryIteratorBeginning( $query );
  660. public abstract function queryIteratorEnding( $query );
  661.  
  662.  
  663. protected abstract function _renderContentInfo_JS();
  664.  
  665. protected function _getJSFunction( $functionName ) {
  666. ob_start();
  667. call_user_func( array( $this, $functionName) );
  668. $content = ob_get_contents();
  669. ob_end_clean();
  670.  
  671. $content = str_replace('<script data-type="ffscript">', '', $content);
  672. $content = str_replace('</script data-type="ffscript">', '', $content);
  673.  
  674. return $content;
  675. }
  676.  
  677. protected function _setData( $name, $value ) {
  678. $this->_data[ $name ] = $value;
  679. }
  680.  
  681. protected function _doShortcode( $content ) {
  682. if( $this->_doShortcodeCallback == null ) {
  683. return null;
  684. } else {
  685. return call_user_func( $this->_doShortcodeCallback, $content );
  686. }
  687. }
  688.  
  689. protected function _getData( $name, $default = null ) {
  690. if( isset( $this->_data[ $name ] ) ) {
  691. return $this->_data[ $name ];
  692. } else {
  693. return $default;
  694. }
  695. }
  696.  
  697. /**
  698. * @param $blockClassName
  699. * @return ffThemeBuilderBlock
  700. */
  701. protected function _getBlock( $blockClassName ) {
  702. $block = $this->_getThemeBuilderBlockManager()->getBlock( $blockClassName );
  703. $block->setAssetsRenderer( $this->_getAssetsRenderer() );
  704. $block->setStatusHolder( $this->_statusHolder );
  705. return $block;
  706. }
  707.  
  708.  
  709. /**********************************************************************************************************************/
  710. /* PRIVATE GETTERS & SETTERS
  711. /**********************************************************************************************************************/
  712. /**
  713. * @return ffOptionsQueryDynamic
  714. */
  715. private function _getQueryDynamic()
  716. {
  717. return $this->_queryDynamic;
  718. }
  719.  
  720. /**
  721. * @param ffOptionsQueryDynamic $queryDynamic
  722. */
  723. private function _setQueryDynamic($queryDynamic)
  724. {
  725. $this->_queryDynamic = $queryDynamic;
  726. }
  727.  
  728. /**
  729. * @return ffWPLayer
  730. */
  731. protected function _getWPLayer()
  732. {
  733. return $this->_WPLayer;
  734. }
  735.  
  736. /**
  737. * @param ffWPLayer $WPLayer
  738. */
  739. private function _setWPLayer($WPLayer)
  740. {
  741. $this->_WPLayer = $WPLayer;
  742. }
  743.  
  744. /**
  745. * @return ffThemeBuilderOptionsExtender
  746. */
  747. protected function _getOptionsExtender()
  748. {
  749. return $this->_optionsExtender;
  750. }
  751.  
  752. /**
  753. * @param ffThemeBuilderOptionsExtender $optionsExtender
  754. */
  755. private function _setOptionsExtender($optionsExtender)
  756. {
  757. $this->_optionsExtender = $optionsExtender;
  758. }
  759.  
  760. /**
  761. * @return ffThemeBuilderBlockManager
  762. */
  763. private function _getThemeBuilderBlockManager() {
  764. return $this->_themeBuilderBlockManager;
  765. }
  766.  
  767. /**
  768. * @param ffThemeBuilderBlockManager $themeBuilderBlockManager
  769. */
  770. private function _setThemeBuilderBlockManager($themeBuilderBlockManager) {
  771. $this->_themeBuilderBlockManager = $themeBuilderBlockManager;
  772. }
  773.  
  774. /**
  775. * @return ffClassLoader
  776. */
  777. private function _getClassLoader() {
  778. return ffContainer()->getClassLoader();
  779. }
  780.  
  781. /**
  782. * @return ffOptions_Factory
  783. */
  784. protected function _getOptionsFactory() {
  785. return ffContainer()->getOptionsFactory();
  786. }
  787.  
  788. /**
  789. * @return ffThemeBuilderAssetsRenderer
  790. */
  791. protected function _getAssetsRenderer() {
  792. return $this->_assetsRenderer;
  793. }
  794.  
  795. /**
  796. * @param ffThemeBuilderAssetsRenderer $assetsRenderer
  797. */
  798. protected function _setAssetsRenderer($assetsRenderer) {
  799. $this->_assetsRenderer = $assetsRenderer;
  800. }
  801.  
  802. public function setDoShortcodeCallback( $callback ) {
  803. $this->_doShortcodeCallback = $callback;
  804. }
  805.  
  806. /**
  807. * @return boolean
  808. */
  809. protected function _getIsCachingMode() {
  810. return $this->_isCachingMode;
  811. }
  812.  
  813. /**
  814. * @param boolean $isCachingMode
  815. */
  816. public function setIsCachingMode($isCachingMode) {
  817. $this->_isCachingMode = $isCachingMode;
  818. }
  819.  
  820. /**
  821. * @return ffThemeBuilderShortcodesStatusHolder
  822. */
  823. protected function _getStatusHolder() {
  824. return $this->_statusHolder;
  825. }
  826.  
  827. /**
  828. * @param ffThemeBuilderShortcodesStatusHolder $statusHolder
  829. */
  830. private function _setStatusHolder($statusHolder) {
  831. $this->_statusHolder = $statusHolder;
  832. }
  833.  
  834. /**
  835. * @return ffThemeBuilderGlobalStyles
  836. */
  837. private function _getGlobalStyles() {
  838. return $this->_globalStyles;
  839. }
  840.  
  841. /**
  842. * @param ffThemeBuilderGlobalStyles $globalStyles
  843. */
  844. private function _setGlobalStyles($globalStyles) {
  845. $this->_globalStyles = $globalStyles;
  846. }
  847. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement