/**
  * if we're publishing, outputs an if statement
  * $func should be something on the controller that
  * is livepub sensitive (either uses eval_php or
  * some other method to return code)
  */
 function LPH_If($func)
 {
     if (LivePubHelper::is_publishing()) {
         LivePubHelper::$context = 'php';
         $str = $this->getOwner()->{$func}();
         LivePubHelper::$context = 'html';
         return '<?php if (' . $str . '): ?>';
     }
 }
コード例 #2
0
 /**
  * checks eval_php
  */
 public function testEvalPhp()
 {
     // when not publishing, should just return the value
     $s = LivePubHelper::eval_php('return 5;');
     $this->assertEquals($s, 5);
     // when publishing should return code
     LivePubHelper::init_pub();
     LivePubHelper::$context = 'php';
     $s = LivePubHelper::eval_php('return 5;');
     $this->assertEquals($s, "eval('return 5;')");
     LivePubHelper::$context = 'html';
     $s = LivePubHelper::eval_php('return 5;');
     $this->assertEquals($s, "<?php echo eval('return 5;'); ?>");
     LivePubHelper::stop_pub();
 }