예제 #1
0
파일: ad.php 프로젝트: yongge666/sunupedu
    /**
     * @brief 展示制定广告位的广告内容
     * @param $position mixed 广告位ID 或者 广告位名称
     * @param $goods_cat_id 商品分类ID
     * @return string
     */
    public static function show($position, $goods_cat_id = 0)
    {
        $positionObject = array();
        $adArray = array();
        $positionObject = self::getPositionInfo($position);
        if ($positionObject) {
            $adList = self::getAdList($positionObject['id'], $goods_cat_id);
            foreach ($adList as $key => $val) {
                $val['width'] = $positionObject['width'];
                $val['height'] = $positionObject['height'];
                $adArray[] = self::display($val);
            }
        }
        //有广告内容数据
        if ($adArray) {
            $positionJson = JSON::encode($positionObject);
            $adJson = JSON::encode($adArray);
            //引入 adloader js类库
            $loadJs = '';
            if (self::$isLoadJs == false) {
                $loadJs = IJSPackage::load('admanage');
                self::$isLoadJs = true;
            }
            $adPositionJsId = md5("AD_{$position}_{$goods_cat_id}");
            //生成HTML代码
            $htmlOutput = <<<OEF
\t\t\t{$loadJs}
\t\t\t<div id='{$adPositionJsId}' class='admanage'>
\t\t\t</div>
\t\t\t<script type='text/javascript'>
\t\t\t\t(new adLoader()).load({$positionJson},{$adJson},"{$adPositionJsId}");
\t\t\t</script>
OEF;
            echo $htmlOutput;
        }
    }
예제 #2
0
 /**
  * @brief 处理设定的每一个标签
  * @param array $matches
  * @return String php代码
  */
 public function translate($matches)
 {
     if ($matches[1] !== '/') {
         switch ($matches[2] . $matches[3]) {
             case '$':
                 $str = trim($matches[4]);
                 $first = substr($str, 0, 1);
                 if ($first != '.' && $first != '(') {
                     if (strpos($str, '(') === false) {
                         return '<?php echo isset($' . $str . ')?$' . $str . ':"";?>';
                     } else {
                         return '<?php echo $' . $str . ';?>';
                     }
                 } else {
                     return $matches[0];
                 }
             case 'echo:':
                 return '<?php echo ' . rtrim($matches[4], ';/') . ';?>';
             case 'js:':
                 return IJSPackage::load($matches[4]);
             case 'url:':
                 return '<?php echo IUrl::creatUrl("' . $matches[4] . '");?>';
             case 'webroot:':
                 return '<?php echo IUrl::creatUrl("")."' . $matches[4] . '";?>';
             case 'theme:':
                 return '<?php echo IUrl::creatUrl("")."views/".$this->theme."/' . $matches[4] . '";?>';
             case 'skin:':
                 return '<?php echo IUrl::creatUrl("")."views/".$this->theme."/skin/".$this->skin."/' . $matches[4] . '";?>';
             case 'if:':
                 return '<?php if(' . $matches[4] . '){?>';
             case 'elseif:':
                 return '<?php }elseif(' . $matches[4] . '){?>';
             case 'else:':
                 return '<?php }else{' . $matches[4] . '?>';
             case 'set:':
                 return '<?php ' . $matches[4] . '?>';
             case 'while:':
                 return '<?php while(' . $matches[4] . '){?>';
             case 'foreach:':
                 $attr = $this->getAttrs($matches[4]);
                 if (!isset($attr['items'])) {
                     $attr['items'] = '$items';
                 } else {
                     $attr['items'] = $attr['items'];
                 }
                 if (!isset($attr['key'])) {
                     $attr['key'] = '$key';
                 } else {
                     $attr['key'] = $attr['key'];
                 }
                 if (!isset($attr['item'])) {
                     $attr['item'] = '$item';
                 } else {
                     $attr['item'] = $attr['item'];
                 }
                 return '<?php foreach(' . $attr['items'] . ' as ' . $attr['key'] . ' => ' . $attr['item'] . '){?>';
             case 'for:':
                 $attr = $this->getAttrs($matches[4]);
                 if (!isset($attr['item'])) {
                     $attr['item'] = '$i';
                 } else {
                     $attr['item'] = $attr['item'];
                 }
                 if (!isset($attr['from'])) {
                     $attr['from'] = 0;
                 }
                 if (!isset($attr['upto']) && !isset($attr['downto'])) {
                     $attr['upto'] = 10;
                 }
                 if (isset($attr['upto'])) {
                     $op = '<=';
                     $end = $attr['upto'];
                     if ($attr['upto'] < $attr['from']) {
                         $attr['upto'] = $attr['from'];
                     }
                     if (!isset($attr['step'])) {
                         $attr['step'] = 1;
                     }
                 } else {
                     $op = '>=';
                     $end = $attr['downto'];
                     if ($attr['downto'] > $attr['from']) {
                         $attr['downto'] = $attr['from'];
                     }
                     if (!isset($attr['step'])) {
                         $attr['step'] = -1;
                     }
                 }
                 return '<?php for(' . $attr['item'] . ' = ' . $attr['from'] . ' ; ' . $attr['item'] . $op . $end . ' ; ' . $attr['item'] . ' = ' . $attr['item'] . '+' . $attr['step'] . '){?>';
             case 'query:':
                 $endchart = substr(trim($matches[4]), -1);
                 $attrs = $this->getAttrs(rtrim($matches[4], '/'));
                 if (!isset($attrs['id'])) {
                     $id = '$query';
                 } else {
                     $id = $attrs['id'];
                 }
                 if (!isset($attrs['items'])) {
                     $items = '$items';
                 } else {
                     $items = $attrs['items'];
                 }
                 $tem = "{$id}" . ' = new IQuery("' . $attrs['name'] . '");';
                 //实现属性中符号表达式的问题
                 $old_char = array(' eq ', ' l ', ' g ', ' le ', ' ge ', 'neq');
                 $new_char = array(' = ', ' < ', ' > ', ' <= ', ' >= ', ' != ');
                 foreach ($attrs as $k => $v) {
                     if ($k != 'name' && $k != 'id' && $k != 'items' && $k != 'item') {
                         $tem .= "{$id}->" . $k . ' = "' . str_replace($old_char, $new_char, $v) . '";';
                     }
                 }
                 $tem .= $items . ' = ' . $id . '->find();';
                 if (!isset($attrs['key'])) {
                     $attrs['key'] = '$key';
                 } else {
                     $attrs['key'] = $attrs['key'];
                 }
                 if (!isset($attrs['item'])) {
                     $attrs['item'] = '$item';
                 } else {
                     $attrs['item'] = $attrs['item'];
                 }
                 if ($endchart == '/') {
                     return '<?php ' . $tem . '?>';
                 } else {
                     return '<?php ' . $tem . ' foreach(' . $items . ' as ' . $attrs['key'] . ' => ' . $attrs['item'] . '){?>';
                 }
             case 'code:':
                 return '<?php ' . $matches[4];
             case 'require:':
             case 'include:':
                 $fileName = trim($matches[4]);
                 $viewfile = IWeb::$app->controller->getViewPath() . $fileName;
                 /*
                 					$runfile= IWeb::$app->getRuntimePath().$fileName;
                 
                 					if(!file_exists($runfile) || filemtime($runfile)<filemtime($viewfile))
                 					{
                 						$file = new IFile($runfile,'w+');
                 						$template = file_get_contents($viewfile);
                 						$t = new ITag();
                 						$tem = $t->resolve($template,dirname($viewfile));
                 						$file->write($tem);
                     $file->save();
                 					}
                 */
                 return "<?php include('{$viewfile}')?>";
             default:
                 return $matches[0];
         }
     } else {
         if ($matches[2] == 'code') {
             return '?>';
         } else {
             return '<?php }?>';
         }
     }
 }