Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.39 KB | None | 0 0
  1. <?php
  2. /**
  3. * Try to get the value from the data array. In case of failure ( for example
  4. * we added another option and user didn't saved them yet ) it will re-create
  5. * the whole option structure and try to get the value from here. If this
  6. * won't help too, it will report error.
  7. *
  8. * @author FRESHFACE
  9. * @since 0.1
  10. *
  11. */
  12. class ffOptionsQuery extends ffBasicObject implements Iterator {
  13.  
  14. /******************************************************************************/
  15. /* VARIABLES AND CONSTANTS
  16. /******************************************************************************/
  17. protected $_currentElementClassName = null;
  18.  
  19. protected $_isPrintingMode = false;
  20.  
  21. protected $_iteratorPointer = null;
  22.  
  23. protected $_iteratorValidHolder = null;
  24.  
  25. protected $_data = null;
  26.  
  27. protected $_path = null;
  28. /**
  29. *
  30. * @var ffOptionsArrayConvertor
  31. */
  32. protected $_arrayConvertor = null;
  33.  
  34. /**
  35. *
  36. * @var ffWPLayer
  37. */
  38. protected $_WPLayer = null;
  39.  
  40. /**
  41. *
  42. * @var ffIOptionsHolder
  43. */
  44. protected $_optionsHolder = null;
  45.  
  46. protected $_optionsStructureHasBeenCompared = false;
  47.  
  48. protected $_hasBeenComparedWithStructure = false;
  49.  
  50. /**
  51. * Function, that gets called every iteration in foreach cycle, it will contain the query and all the important
  52. * stuff. It's used mainly in the new builder for printing system things
  53. * @var callable
  54. */
  55. protected $_iteratorValidationCallback = null;
  56.  
  57. /**
  58. * @var callable
  59. */
  60. protected $_iteratorStartCallback = null;
  61.  
  62. /**
  63. * @var callable
  64. */
  65. protected $_iteratorEndCallback = null;
  66.  
  67. protected $_iteratorBeginningCallback = null;
  68.  
  69. protected $_iteratorEndingCallback = null;
  70.  
  71. protected $_callTheCallbacks = true;
  72.  
  73. /******************************************************************************/
  74. /* CONSTRUCT AND PUBLIC FUNCTIONS
  75. /******************************************************************************/
  76. public function __construct( $data, ffIOptionsHolder $optionsHolder = null, ffOptionsArrayConvertor $arrayConvertor = null, $path = null, $optionsStructureHasBeenCompared = false ) {
  77. $this->_setData($data);
  78. $this->_setArrayConvertor($arrayConvertor);
  79. if( $optionsHolder != null ) {
  80. $this->_setOptionsHolder($optionsHolder);
  81. }
  82. $this->_setPath($path);
  83. }
  84.  
  85. public function setIsPrintingMode( $value ) {
  86. $this->_isPrintingMode = $value;
  87. }
  88.  
  89. public function setCallTheCallbacks( $value ) {
  90. $this->_callTheCallbacks = $value;
  91. }
  92.  
  93. public function setIteratorBeginningCallback( $callback ) {
  94. $this->_iteratorBeginningCallback = $callback;
  95. }
  96.  
  97. public function setIteratorEndingCallback( $callback ) {
  98. $this->_iteratorEndingCallback = $callback;
  99. }
  100.  
  101.  
  102. public function setIteratorStartCallback( $callback ) {
  103. $this->_iteratorStartCallback = $callback;
  104. }
  105.  
  106. public function setIteratorEndCallback( $callback ) {
  107. $this->_iteratorEndCallback = $callback;
  108. }
  109.  
  110. public function setIteratorValidationCallback( $callback ) {
  111. $this->_iteratorValidationCallback = $callback;
  112. }
  113.  
  114. protected function _callBeginning( $query ) {
  115. if( $this->_iteratorBeginningCallback != null && $this->_callTheCallbacks ) {
  116. call_user_func( $this->_iteratorBeginningCallback, $query );
  117. }
  118. }
  119.  
  120. protected function _callEnding( $query ) {
  121. if( $this->_iteratorEndingCallback != null && $this->_callTheCallbacks ) {
  122. call_user_func( $this->_iteratorEndingCallback, $query);
  123. }
  124. }
  125.  
  126. protected function _callStart( $query, $key) {
  127. if( $this->_iteratorStartCallback != null && $this->_callTheCallbacks ) {
  128. call_user_func( $this->_iteratorStartCallback, $query, $key );
  129. }
  130. }
  131.  
  132. protected function _callEnd( $query, $key) {
  133. if( $this->_iteratorEndCallback != null && $this->_callTheCallbacks ) {
  134. call_user_func( $this->_iteratorEndCallback, $query, $key );
  135. }
  136. }
  137.  
  138. public function getOnlyDataPartWithCurrentPath( $query = null ) {
  139. if( $query != null ) {
  140. $query = $this->_getPath() .' ' . $query;
  141. } else {
  142. $query = $this->_getPath();
  143. }
  144.  
  145. return $this->_get($query);
  146. }
  147.  
  148. public function getOnlyDataPart( $query = null, $wrappedInSectionName = true ) {
  149. $exploded = explode(' ', $query);
  150. $arrayName = end($exploded );
  151. $toReturn = null;
  152.  
  153. if( $wrappedInSectionName ) {
  154. $toReturn[ $arrayName ] = $this->_get($query);
  155. } else {
  156. $toReturn = $this->_get( $query );
  157. }
  158.  
  159. return $toReturn;
  160. }
  161.  
  162. public function setElementClassName( $className ) {
  163. $this->_currentElementClassName = $className;
  164. }
  165.  
  166. public function getOnlyDataPartAsDataHolder( $query = null) {
  167. return new ffDataHolder( $this->getOnlyDataPartWithCurrentPath( $query ) );
  168. }
  169.  
  170. public function resetPath() {
  171. $this->_setPath( null );
  172. }
  173.  
  174. public function debug_dump( $short = false )
  175. {
  176. if( $short ){
  177. echo '<pre>';
  178. print_r($this->_path);
  179. echo '</pre>';
  180. echo '<pre>';
  181. print_r($this->_data);
  182. echo '</pre>';
  183. }
  184. var_dump( $this->_path, $this->_data );
  185. }
  186.  
  187. public function debug_export() {
  188. return var_export( $this->_data, true );
  189. }
  190.  
  191. public function getTaxonomyWithoutComparation( $query, $default = null ) {
  192. $data = $this->getWithoutComparation( $query );
  193.  
  194. if( $data == null || $data == 'null' ) {
  195. return $default;
  196. } else {
  197. $data = str_replace(array('||tax-s||', '||tax-e||'), array('', ''), $data );
  198.  
  199. $dataSplitted = explode('--||--', $data );
  200.  
  201. $toReturn = array();
  202. foreach( $dataSplitted as $oneTax ) {
  203. $taxClass = new ffStdClass();
  204. $oneTaxArray = explode( '*|*', $oneTax );
  205.  
  206. $taxClass->id = $oneTaxArray[0];
  207. if( isset( $oneTaxArray[1]) ) {
  208. $taxClass->name = $oneTaxArray[1];
  209. }
  210.  
  211. $toReturn[] = $taxClass;
  212. }
  213.  
  214. return $toReturn;
  215. }
  216. }
  217.  
  218. public function getWithoutComparationDefault( $query, $default = null ) {
  219. $data = $this->getWithoutComparation( $query );
  220. if( $data === null ) {
  221. return $default;
  222. } else {
  223. return $data;
  224. }
  225. }
  226.  
  227. public function getWithoutComparation( $query ) {
  228. if( $this->_getPath() !== null ) {
  229. $query = $this->_getPath() . ' ' . $query;
  230. }
  231. $result = $this->_get( $query );
  232.  
  233. if( is_array( $result ) ) {
  234.  
  235. $result = $this->getNew( $query );
  236. }
  237.  
  238. return $result;
  239. }
  240.  
  241. public function exists( $query ) {
  242. return $this->queryExists( $query );
  243. }
  244.  
  245.  
  246. public function queryExists( $query ) {
  247. $result = $this->getWithoutComparation( $query );
  248.  
  249. if( $result === null ) {
  250. return false;
  251. } else {
  252. return true;
  253. }
  254. }
  255.  
  256. // static $allowed_html = null;
  257. // if( empty($allowed_html) ){
  258. // $allowed_html = wp_kses_allowed_html('post');
  259. // }
  260. // return wp_kses( $html, $allowed_html )
  261. private $_kses_allowed_html = null;
  262.  
  263. public function getWpKses( $query ) {
  264. if( $this->_kses_allowed_html == null ) {
  265. $this->_kses_allowed_html = wp_kses_allowed_html('post');
  266. }
  267.  
  268. return wp_kses( $this->get( $query), $this->_kses_allowed_html );
  269. }
  270.  
  271. public function isRichText( $query ) {
  272. $isRichText = intval($this->getWithoutComparationDefault( $query . '-is-richtext', false));
  273.  
  274. if( $isRichText == 1) {
  275. return true;
  276. } else {
  277. return false;
  278. }
  279. }
  280.  
  281. public function getTextarea( $query, $notRichBefore, $notRichAfter, $richBefore, $richAfter ) {
  282. $text = $this->get( $query );
  283.  
  284. if( !$this->isRichText( $query ) ) {
  285. return $notRichBefore . $text . $notRichAfter;
  286. } else {
  287. return $richBefore . $text . $richAfter;
  288. }
  289. }
  290.  
  291. public function getWpKsesTextarea( $query, $notRichBefore, $notRichAfter, $richBefore, $richAfter ) {
  292. $text = $this->getWpKses( $query );
  293.  
  294. if( !$this->isRichText( $query ) ) {
  295. return $notRichBefore . $text . $notRichAfter;
  296. } else {
  297. return $richBefore . $text . $richAfter;
  298. }
  299. }
  300.  
  301. public function printWpKsesTextarea( $query, $notRichBefore, $notRichAfter, $richBefore, $richAfter ) {
  302. echo $this->getWpKsesTextarea( $query, $notRichBefore, $notRichAfter, $richBefore, $richAfter );
  303. }
  304.  
  305. public function printWpKses( $query ) {
  306. echo $this->getWpKses( $query );
  307. }
  308.  
  309. public function getEscAttr( $query ) {
  310. return esc_attr( $this->get( $query ) );
  311. }
  312.  
  313. public function getEscUrl( $query ) {
  314. return esc_url( $this->get( $query ) );
  315. }
  316.  
  317. public function getMustBeQueryNotEmpty( $query ) {
  318. if( $this->queryExists( $query ) ) {
  319. $result = $this->get( $query );
  320.  
  321. if( empty( $result ) ) {
  322. return $this->getNew();
  323. } else {
  324. return $result;
  325. }
  326. } else {
  327. return $this->getNew();
  328. }
  329.  
  330. }
  331.  
  332. /**
  333. *
  334. * @param string|unknown $query
  335. * @return ffOptionsQuery|string
  336. * @throws ffException
  337. */
  338. public function get( $query, $default = '--||not||--' ) {
  339. if( $default != '--||not||--' ) {
  340. return $this->getWithoutComparationDefault($query, $default );
  341. }
  342.  
  343. if( $this->_getPath() !== null ) {
  344. $query = $this->_getPath() . ' ' . $query;
  345. }
  346. $result = $this->_get( $query );
  347.  
  348. // ffStopWatch::addVariableDump( $result );
  349.  
  350. if( $result === null ) {
  351.  
  352. // var_dump( $query, 'xxxxxxxxxxx' );
  353.  
  354. if( $this->_getWPLayer()->is_freshface_admin_server_or_local() ) {
  355. // echo '<script>';
  356. // echo 'console.log("';
  357. // echo 'Query ' . $query .', optionsHolder ' . ( $this->_optionsHolder->getOptionsHolderClassName() ) . ' NOT FOUND, HAVE TO BE COMPARED';
  358. // echo '");';
  359.  
  360. // if( strpos( $query, 'featured-image') !== false ) {
  361. // debug_print_backtrace();
  362. // }
  363.  
  364. // if( $query == 'general title title') {
  365. // $this->debug_dump();
  366. // die();
  367. // }
  368. // var_dump( $query );
  369. // die();
  370. ffStopWatch::addQueryNotFoundString('- ' . $this->_currentElementClassName . ' -- Query ' . $query .', optionsHolder ' . '' . ' NOT FOUND, HAVE TO BE COMPARED<br>');
  371.  
  372. // debug_print_backtrace();
  373. // die();
  374. // echo '</script>';
  375. // throw new ffException('Query ' . $query .', optionsHolder ' . 'xx' . ' NOT FOUND, HAVE TO BE COMPARED');
  376. }
  377.  
  378. $env = ffContainer()->getEnvironment();
  379. // $env->setIsOurTheme(true);
  380. // $env->setThemeVariable(ffEnvironment::THEME_NAME, 'ark');
  381.  
  382. if( $env->getThemeVariable( ffEnvironment::THEME_NAME) != 'ark' ) {
  383.  
  384. $this->_compareDataWithStructure();
  385. $result = $this->_get($query);
  386.  
  387. if( $result === null && $this->_getWPLayer()->get_ff_debug() ) {
  388. throw new ffException('NON EXISTING QUERY STRING -> "'.$query.'"');
  389. } else {
  390. $this->_getWPLayer()->do_action( ffConstActions::ACTION_QUERY_NOT_FOUND_IN_DATA, $query );
  391. }
  392.  
  393. }
  394. }
  395.  
  396.  
  397. if( is_array( $result ) ) {
  398.  
  399. // if( $this->_getPath() == null ) {
  400.  
  401. $result = $this->getNew( $query );
  402. //new ffOptionsQuery( $this->_getData(), $this->_getOptionsHolder(), $this->_getArrayConvertor(), $query, $this->_optionsStructureHasBeenCompared );
  403. // } else {
  404. // $this->_setPath( $query);
  405. // $result = $this;
  406. // }
  407. } else if( $this->_isPrintingMode ) {
  408. $result = htmlspecialchars_decode( $result );
  409. }
  410.  
  411. return $result;
  412. }
  413.  
  414. public function resetCallbacks() {
  415. $this->setCallTheCallbacks(false);
  416. return $this;
  417. }
  418.  
  419. public function getWithoutCallbacks( $query ) {
  420. $newQuery = $this->get($query);
  421. $newQuery->setCallTheCallbacks(false);
  422. return $newQuery;
  423. }
  424.  
  425. public function getWithCallbacks( $query ) {
  426. $newQuery = $this->get( $query );
  427. $newQuery->setCallTheCallbacks( true );
  428. return $newQuery;
  429. }
  430.  
  431. public function isEmpty( $query ) {
  432. $result = $this->get( $query );
  433.  
  434. return ( $result == false );
  435. }
  436.  
  437. public function notEmpty( $query ) {
  438. return !$this->isEmpty( $query );
  439. }
  440.  
  441. public function getText( $query ) {
  442. $text = $this->get( $query );
  443.  
  444. return $this->_getWPLayer()->do_shortcode( $text );
  445. }
  446.  
  447. public function printText( $query ) {
  448. $text = $this->get( $query );
  449.  
  450. echo $this->_getWPLayer()->do_shortcode($text);
  451.  
  452. }
  453.  
  454. public function getMultipleSelect( $query ) {
  455. $valueText = $this->get($query);
  456. $valueArray = explode('--||--', $valueText);
  457.  
  458. return $valueArray;
  459. }
  460.  
  461. public function getMultipleSelect2( $query ) {
  462. $valueText = $this->get($query);
  463. if( empty( $valueText ) ) {
  464. return array();
  465. }
  466. $valueArray = explode('--||--', $valueText);
  467.  
  468. return $valueArray;
  469. }
  470.  
  471. public function getSingleSelect2( $query ) {
  472. $valueText = $this->get($query);
  473. if( empty( $valueText ) ) {
  474. return 0;
  475. }
  476. if( FALSE === strpos($valueText, '*|*') ){
  477. return $valueText;
  478. }
  479. $valueArray = explode('*|*', $valueText);
  480.  
  481. return $valueArray[0];
  482. }
  483.  
  484. public function getUnserialize( $query ) {
  485. return unserialize( $this->get($query) );
  486. }
  487.  
  488. public function getJsonDecode( $query ) {
  489. $value = $this->get( $query );
  490.  
  491. $value = str_replace('_ffqt_', '"', $value );
  492.  
  493. return json_decode( $value );
  494. }
  495.  
  496.  
  497. public function getImage( $query ) {
  498. $image = $this->getJsonDecode( $query );
  499.  
  500. if( !is_object( $image ) ) {
  501. $image = new stdClass();
  502. $image->url = '';
  503. $image->width = 0;
  504. $image->height = 0;
  505. } else {
  506.  
  507. if( (!defined('FF_DEVELOPER_MODE') && isset( $image->substitute ) ) || ( FF_DEVELOPER_MODE == false && isset( $image->substitute ) ) ) {
  508. $image = $image->substitute;
  509. }
  510.  
  511. if( strpos( $image->url, $this->_getWPLayer()->get_freshface_demo_url() )!== false && strpos( $this->_getWPLayer()->get_home_url(), $this->_getWPLayer()->get_freshface_demo_url() ) === false) {
  512. $image->url = $this->_getWPLayer()->wp_get_attachment_url( $image->id );//wp_get_attachment_url( $image->id );
  513. }
  514.  
  515. if( $image->id == -1 ) {
  516. if( defined(FF_ARK_CORE_PLUGIN_URL) ) {
  517. $image->url = FF_ARK_CORE_PLUGIN_URL .'/builder/placeholders/' . $image->url;
  518. } else {
  519. $image->url = $this->_getWPLayer()->get_template_directory_uri() .'/builder/placeholders/' . $image->url;
  520. }
  521. }
  522.  
  523. }
  524.  
  525. if( $image->id != -1 ) {
  526. $image->url = wp_get_attachment_url( $image->id );
  527. }
  528.  
  529.  
  530. return $image;
  531. }
  532.  
  533. public function getIcon( $query ) {
  534. $icon = $this->get( $query );
  535.  
  536. $iconFiltered = $this->_getWPLayer()->apply_filters( ffConstActions::FILTER_QUERY_GET_ICON, $icon);
  537.  
  538. return $iconFiltered;
  539. }
  540.  
  541. public function getColor( $query ) {
  542. $result = $this->get( $query );
  543. $resultFiltered = $this->_getWPLayer()->apply_filters( ffConstActions::FILTER_QUERY_GET_COLOR, $result );
  544.  
  545. return $resultFiltered;
  546. }
  547.  
  548. public function getNew( $query = null ) {
  549.  
  550.  
  551. $query = new ffOptionsQuery( $this->_data, $this->_getOptionsHolder(), $this->_getArrayConvertor(), $query, $this->_optionsStructureHasBeenCompared );
  552. $query->setWPLayer( $this->_getWPLayer() );
  553. $query->setIteratorValidationCallback( $this->_getIteratorValidationCallback() );
  554. $query->setIteratorStartCallback( $this->_iteratorStartCallback );
  555. $query->setIteratorEndCallback( $this->_iteratorEndCallback );
  556. $query->setIteratorBeginningCallback( $this->_iteratorBeginningCallback );
  557. $query->setIteratorEndingCallback( $this->_iteratorEndingCallback );
  558. $query->setCallTheCallbacks( $this->_callTheCallbacks );
  559. $query->setIsPrintingMode( $this->_isPrintingMode );
  560. return $query;
  561. }
  562.  
  563. public function getJSON( $query ) {
  564. $jsonString = $this->get( $query );
  565. $data = json_decode( $jsonString );
  566.  
  567. if( $data == null ) {
  568. $data = new stdClass();
  569. }
  570.  
  571. return $data;
  572. }
  573.  
  574.  
  575. public function getIndex( $query, $index ) {
  576. $currentQuery = $this->get( $query );
  577. $toReturn = null;
  578.  
  579. foreach( $currentQuery as $key => $oneSubItem ) {
  580. if( $key == $index ) {
  581. $toReturn = $oneSubItem;
  582. break;
  583. }
  584. }
  585.  
  586. return $toReturn;
  587. }
  588.  
  589. public function getOnlyData() {
  590. return $this->_data;
  591. }
  592.  
  593. public function setDataValue( $routeString, $value ) {
  594. $current = &$this->_data;
  595.  
  596. $completeRoute = explode( ' ', $routeString );
  597.  
  598. $routeCount = count( $completeRoute );
  599. foreach( $completeRoute as $key => $route ) {
  600. $route = (string)$route;
  601.  
  602. if( !isset( $current[ $route ] ) ) {
  603. if( !is_array( $current ) ) {
  604. $current = array();
  605. }
  606. $current[ $route ] = array();
  607. }
  608. if( ( $key+1) == $routeCount ) { //if( $route == $routeEnd ) {
  609. $current[ $route ] = $value;
  610. }
  611. if( is_array( $current ) ) {
  612. $current = &$current[$route ];
  613. }
  614. }
  615. }
  616. /******************************************************************************/
  617. /* PRIVATE FUNCTIONS
  618. /******************************************************************************/
  619. protected function _compareDataWithStructure() {
  620. if ($this->_getOptionsstructureHasBeenCompared() == false && $this->_optionsHolder != null ) {
  621.  
  622. $this->_setOptionsstructureHasBeenCompared(true);
  623. $options = $this->_getOptionsHolder()->getOptions();
  624. $this->_getArrayConvertor()->setOptionsArrayData( $this->_data );
  625. $this->_getArrayConvertor()->setOptionsStructure( $options );
  626. $this->_data = $this->_getArrayConvertor()->walk();
  627. $this->_setOptionsstructureHasBeenCompared(true);
  628. } else if( $this->_getOptionsstructureHasBeenCompared() == false && $this->_optionsHolder == null ) {
  629. $this->_setOptionsstructureHasBeenCompared(true);
  630. }
  631. }
  632.  
  633. protected function _get( $query ) {
  634. $queryArray = $this->_convertQueryToArray( $query );
  635. $result = $this->_getFromData($queryArray);
  636. return $result;
  637. }
  638.  
  639. private function _convertQueryToArray( $query ) {
  640. $queryArray = explode(' ', $query);
  641. return $queryArray;
  642. }
  643.  
  644. private function _getFromData( $queryArray ){
  645. if( is_object( $this->_data ) ) {
  646. $this->_data = json_encode( $this->_data );
  647. $this->_data = json_decode( $this->_data, true );
  648. }
  649.  
  650.  
  651.  
  652. $dataPointer = &$this->_data;
  653.  
  654. if( empty( $dataPointer ) ) {
  655. return null;
  656. }
  657.  
  658. foreach( $queryArray as $oneArraySection ) {
  659. if( isset( $dataPointer[ $oneArraySection ] ) ) {
  660. $dataPointer = &$dataPointer[ $oneArraySection ];
  661. } else {
  662. return null;
  663. }
  664. }
  665.  
  666. return ( $dataPointer );
  667. }
  668.  
  669.  
  670. /******************************************************************************/
  671. /* ITERATOR INTERFACE
  672. /******************************************************************************/
  673. private $_currentKeys = array();
  674. private $_currentKeysCount = 0;
  675.  
  676. private $_currentVariationType = null;
  677.  
  678. public function getVariationType() {
  679. return $this->_currentVariationType;
  680. }
  681.  
  682. public function getNumberOfElements() {
  683. $this->_recalculateKeys();
  684. return count( $this->_currentKeys );
  685. }
  686.  
  687. public function setVariationType( $variationType ) {
  688. $this->_currentVariationType = $variationType;
  689. }
  690.  
  691. public function getCurrentQueryDataPart() {
  692. return $this->getOnlyDataPart( $this->_getPath(), false );
  693. }
  694.  
  695. private function _recalculateKeys() {
  696. $dataPart = $this->getOnlyDataPart( $this->_getPath(), false );
  697. $this->_currentKeys = array_keys( $dataPart );
  698. $this->_currentKeysCount = count( $this->_currentKeys );
  699. $this->_currentVariationType = null;
  700. }
  701.  
  702. private $_valid = true;
  703.  
  704. private $_current = null;
  705.  
  706. public function _current () {
  707. $this->_valid = true;
  708. $this->_currentVariationType = null;
  709.  
  710. $currentKey = $this->_currentKeys[ $this->_iteratorPointer ];
  711.  
  712. if( is_numeric($currentKey) ) {
  713. return $this->getNew( $this->_getPath() .' '.$this->_iteratorPointer);
  714. }
  715.  
  716. $potentialSplit = explode('-|-', $currentKey);
  717.  
  718. // 0-|-one-text-item
  719. $queryAddition = $this->_iteratorPointer;
  720. if( count( $potentialSplit ) == 2 ) {
  721. $index = $potentialSplit[0];
  722. $type = $potentialSplit[1];
  723.  
  724. $queryAddition = $currentKey . ' ' . $type;
  725. $this->_currentVariationType = $type;
  726. }
  727.  
  728. $newQuery = $this->getNew( $this->_getPath() .' '.$queryAddition);
  729. $newQuery->setVariationType( $this->_currentVariationType );
  730.  
  731.  
  732.  
  733.  
  734. if( $this->_iteratorValidationCallback != null ) {
  735. $callback = $this->_iteratorValidationCallback;
  736.  
  737. $isValid = $callback( $newQuery, $this->key() );
  738. if( $isValid === null ) {
  739. throw new ffException('ffOptionsQuery - iterator validation callback is null');
  740. }
  741. if( !$isValid ) {
  742. $this->_valid = false;
  743. }
  744. }
  745.  
  746. $this->_callStart( $newQuery, $this->key() );
  747.  
  748.  
  749. return $newQuery;
  750.  
  751. }
  752. public function key () {
  753.  
  754. return $this->_iteratorPointer;
  755. }
  756. public function next () {
  757.  
  758. $this->_callEnd( $this->_current, $this->key() );
  759.  
  760. $this->_iteratorPointer++;
  761. }
  762. public function rewind () {
  763. $this->_iteratorPointer = 0;
  764. $this->_recalculateKeys();
  765. $this->_callBeginning( $this );
  766. }
  767.  
  768. /**
  769. * @return ffOptionsQuery
  770. */
  771. public function current() {
  772. return $this->_current;
  773. }
  774.  
  775.  
  776. public function getPathWithoutRepeatables( $returnAsArray = false) {
  777. $path = $this->getPath();
  778. $pathArray = explode(' ', $path);
  779. $pathToReturn = array();
  780.  
  781. foreach( $pathArray as $oneItem ) {
  782. if( strpos( $oneItem, '-|-') !== false ) {
  783. continue;
  784. }
  785. $pathToReturn[] = $oneItem;
  786. }
  787.  
  788. if( $returnAsArray ) {
  789. return $pathToReturn;
  790. } else {
  791. return implode(' ', $pathToReturn );
  792. }
  793. }
  794.  
  795. public function getPath() {
  796. return $this->_getPath();
  797. }
  798.  
  799. public function valid () {
  800. $valid = true;
  801.  
  802. if( $this->_iteratorPointer == 0) {
  803. $valid = $this->_validFirst();
  804. } else {
  805. $valid = $this->_validNotFirst();
  806. }
  807. if( $valid == false ) {
  808. $this->_callEnding( $this );
  809. return false;
  810. }
  811.  
  812. $this->_current = $this->_current();
  813.  
  814. if( !$this->_valid ) {
  815.  
  816. for( $i = $this->_iteratorPointer+1; $i <= $this->_currentKeysCount-1; $i++ ) {
  817. $this->next();
  818.  
  819. $this->_current = $this->_current();
  820. if( $this->_valid ) {
  821. return true;
  822. break;
  823. }
  824.  
  825. }
  826.  
  827. // IS LAST - WE HAVE TO CALL THIS THING HERE
  828. $this->_callEnd( $this->_current, $this->key() );
  829.  
  830. } else {
  831. return true;
  832. }
  833.  
  834. $this->_callEnding( $this );
  835. return false;
  836. }
  837.  
  838. private function _validFirst() {
  839. if( $this->_currentKeysCount == 0 ) {
  840. $this->_compareDataWithStructure();
  841. $this->_recalculateKeys();
  842.  
  843. return $this->_validNotFirst();
  844. }
  845. return true;
  846. }
  847.  
  848. private function _validNotFirst() {
  849. if( $this->_iteratorPointer == $this->_currentKeysCount || $this->_currentKeysCount == 0 ) {
  850. return false;
  851. }
  852.  
  853. return true;
  854. }
  855.  
  856. /******************************************************************************/
  857. /* SETTERS AND GETTERS
  858. /******************************************************************************/
  859. public function setWPLayer( ffWPLayer $WPLayer ) {
  860. $this->_WPLayer = $WPLayer;
  861. }
  862.  
  863. protected function _getWPLayer() {
  864. return $this->_WPLayer;
  865. }
  866. /********** DATA **********/
  867. protected function _setData( $data ) {
  868. $this->_data = $data;
  869. }
  870.  
  871. /**
  872. *
  873. */
  874. protected function _getData() {
  875. return $this->_data;
  876. }
  877.  
  878. /********** ARRAY CONVERTOR **********/
  879. protected function _setArrayConvertor(ffOptionsArrayConvertor $arrayConvertor ){
  880. $this->_arrayConvertor = $arrayConvertor;
  881. }
  882.  
  883. /**
  884. *
  885. * @return ffOptionsArrayConvertor
  886. */
  887. protected function _getArrayConvertor() {
  888. return $this->_arrayConvertor;
  889. }
  890.  
  891. /********** OPTIONS HOLDER **********/
  892. protected function _setOptionsHolder(ffIOptionsHolder $optionsHolder ) {
  893. $this->_optionsHolder = $optionsHolder;
  894. }
  895. /**
  896. *
  897. * @return ffIOptionsHolder
  898. */
  899. protected function _getOptionsHolder() {
  900. return $this->_optionsHolder;
  901. }
  902.  
  903. /**
  904. * @return unknown_type
  905. */
  906. protected function _getPath() {
  907. return $this->_path;
  908. }
  909.  
  910. /**
  911. * @param unknown_type $path
  912. */
  913. protected function _setPath($path) {
  914. $this->_path = $path;
  915. return $this;
  916. }
  917.  
  918. /**
  919. * @return unknown_type
  920. */
  921. protected function _getOptionsstructureHasBeenCompared() {
  922. return $this->_optionsStructureHasBeenCompared;
  923. }
  924.  
  925. /**
  926. * @param unknown_type $optionsStructureHasBeenCompared
  927. */
  928. protected function _setOptionsstructureHasBeenCompared($optionsStructureHasBeenCompared) {
  929. $this->_optionsStructureHasBeenCompared = $optionsStructureHasBeenCompared;
  930. return $this;
  931. }
  932.  
  933. protected function _getIteratorValidationCallback() {
  934. return $this->_iteratorValidationCallback;
  935. }
  936.  
  937.  
  938. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement