Ejemplo n.º 1
0
function html_rules($mold, $tid, $d, $id = '', $f = '')
{
    if ($f == '') {
        $f = $id;
    }
    if (strpos(',' . syExt('site_html_rules'), '[type]') !== FALSE) {
        $type = syDB('classtype')->find(array('tid' => $tid), null, 'htmldir');
        if ($type['htmldir'] != '') {
            $typedir = $type['htmldir'];
        } else {
            $typedir = 'c/' . $tid;
        }
    }
    $u = syExt('site_html_dir') . '/' . str_replace(array('[y]', '[m]', '[d]', '[id]', '[file]', '[mold]', '[type]'), array(date('Y', $d), date('m', $d), date('d', $d), $id, $f, $mold, $typedir), syExt('site_html_rules'));
    return str_replace(array('///', '//'), '/', $u);
}
Ejemplo n.º 2
0
 private function template_html_loop($f)
 {
     preg_match_all('/.*?(\\s*.*?=.*?[\\"|\'].*?[\\"|\']\\s).*?/si', ' ' . $f . ' ', $aa);
     $a = array();
     foreach ($aa[1] as $v) {
         $t = explode('=', trim(str_replace(array('"', "'"), '', $v)));
         $a = array_merge($a, array(trim($t[0]) => trim($t[1])));
     }
     $dbleft = $GLOBALS['G_DY']['db']['prefix'];
     if (strpos($a['table'], '$') !== FALSE) {
         $a['table'] = '".' . $a['table'] . '."';
     }
     if ($a['table'] == 'channel') {
         $db = 'channel';
         $molds = $a['molds'];
     } else {
         $db = $dbleft . $a['table'];
     }
     if ($a['limit'] != '') {
         $limit = ' limit ' . $a['limit'];
     } else {
         $limit = '';
     }
     if ($a['as'] != '') {
         $as = $a['as'];
     } else {
         $as = 'v';
     }
     if ($a['orderby'] != '') {
         $order = 'order by ' . $a['orderby'];
         $order = ' ' . str_replace('|', ' ', $order) . ' ';
     } else {
         $order = '';
     }
     unset($a['table']);
     unset($a['molds']);
     unset($a['orderby']);
     unset($a['orderway']);
     unset($a['limit']);
     unset($a['as']);
     $pages = '';
     switch ($db) {
         case $dbleft . 'article':
             $fielddb = syDB('fields')->findAll(array('molds' => 'article', 'lists' => 1), ' fieldorder DESC,fid ', 'fields');
             foreach ($fielddb as $v) {
                 $fields .= ',' . $v['fields'];
             }
             $field_all = 'id,tid,sid,title,style,trait,gourl,addtime,hits,htmlurl,htmlfile,litpic,orders,mrank,mgold,isshow,keywords,description' . $fields;
             foreach ($a as $k => $v) {
                 if ($k == 'tid') {
                     foreach (explode(',', $v) as $t) {
                         if (strpos($t, '$') !== FALSE) {
                             $t = preg_replace('/\\[.*?\\]/', '["tid_leafid"]', $t);
                             $ts .= ',".' . $t . '."';
                         } else {
                             $ts .= ',' . syClass("syclasstype", array("article"))->leafid($t);
                         }
                     }
                     $w .= 'and tid in(' . substr($ts, 1) . ') ';
                 } else {
                     if ($k == 'trait') {
                         $w .= "and ";
                         if (strpos($v, ',') !== FALSE) {
                             foreach (explode(',', $v) as $tt) {
                                 $trait .= "or trait like '%," . $tt . ",%' ";
                             }
                             $w .= "(" . substr($trait, 3) . ")";
                         } else {
                             $w .= "trait like '%," . $v . ",%' ";
                         }
                     } else {
                         if ($k == 'notrait') {
                             $w .= "and ";
                             if (strpos($v, ',') !== FALSE) {
                                 foreach (explode(',', $v) as $tt) {
                                     $trait .= "or trait not like '%," . $tt . ",%' ";
                                 }
                                 $w .= "(" . substr($trait, 3) . ")";
                             } else {
                                 $w .= "trait not like '%," . $v . ",%' ";
                             }
                         } else {
                             if ($k == 'image') {
                                 $w .= "and ";
                                 if ($v == 1) {
                                     $w .= "litpic!='' ";
                                 }
                                 if ($v == 2) {
                                     $w .= "litpic='' ";
                                 }
                             } else {
                                 if ($k == 'keywords') {
                                     $w .= "and (title like '%" . $v . "%' or keywords like '%" . $v . "%')";
                                 } else {
                                     if ($k == 'page') {
                                         $page = explode(',', $v);
                                         $limit = '';
                                     } else {
                                         if (strpos($field_all, $k) !== FALSE) {
                                             if (strpos($v, '$') !== FALSE) {
                                                 $v = '".' . $v . '."';
                                             }
                                             $w .= "and " . $k . "='" . $v . "' ";
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $w = ' where isshow=1 ' . $w;
             if ($order == '') {
                 $order = ' order by orders desc,addtime desc,id desc';
             }
             if ($fielddb) {
                 $sql = 'select ' . $field_all . ' from ' . $db . ' a left join ' . $db . '_field b on (a.id=b.aid)' . $w . $order . $limit;
             } else {
                 $sql = 'select * from ' . $db . $w . $order . $limit;
             }
             $txt = '<?php $' . $as . 'n=0;';
             if ($page) {
                 $total_page = total_page($db . $w);
                 $txt .= '$' . $page[0] . '_class=syClass("c_article");$table' . $as . '= $' . $page[0] . '_class->syPager(syClass("syController")->syArgs("' . $page[0] . '_page",0,1),' . $page[1] . ',' . $total_page . ')->findSql("' . $sql . '");$' . $page[0] . '=pagetxt($' . $page[0] . '_class->syPager()->getPager(),3,"' . $page[0] . '_page");';
             } else {
                 $txt .= '$table' . $as . '=syClass("syModel")->' . $this->sycache . 'findSql("' . $sql . '");';
             }
             $txt .= 'foreach($table' . $as . ' as $' . $as . '){ $' . $as . '["tid_leafid"]=$sy_class_type->leafid($' . $as . '["tid"]);$' . $as . '["n"]=$' . $as . 'n=$' . $as . 'n+1; $' . $as . '["url"]=html_url("article",$' . $as . '); $' . $as . '["title"]=stripslashes($' . $as . '["title"]); $' . $as . '["description"]=stripslashes($' . $as . '["description"]); ?>';
             break;
         case $dbleft . 'product':
             $fielddb = syDB('fields')->findAll(array('molds' => 'product', 'lists' => 1), ' fieldorder DESC,fid ', 'fields');
             foreach ($fielddb as $v) {
                 $fields .= ',' . $v['fields'];
             }
             $field_all = 'id,tid,sid,title,style,trait,gourl,addtime,record,hits,htmlurl,htmlfile,litpic,orders,price,mrank,mgold,isshow,keywords,description' . $fields;
             foreach ($a as $k => $v) {
                 if ($k == 'tid') {
                     foreach (explode(',', $v) as $t) {
                         if (strpos($t, '$') !== FALSE) {
                             $t = preg_replace('/\\[.*?\\]/', '["tid_leafid"]', $t);
                             $ts .= ',".' . $t . '."';
                         } else {
                             $ts .= ',' . syClass("syclasstype", array("product"))->leafid($t);
                         }
                     }
                     $w .= 'and tid in(' . substr($ts, 1) . ') ';
                 } else {
                     if ($k == 'trait') {
                         $w .= "and ";
                         if (strpos($v, ',') !== FALSE) {
                             foreach (explode(',', $v) as $tt) {
                                 $trait .= "or trait like '%," . $tt . ",%' ";
                             }
                             $w .= "(" . substr($trait, 3) . ")";
                         } else {
                             $w .= "trait like '%," . $v . ",%' ";
                         }
                     } else {
                         if ($k == 'notrait') {
                             $w .= "and ";
                             if (strpos($v, ',') !== FALSE) {
                                 foreach (explode(',', $v) as $tt) {
                                     $trait .= "or trait not like '%," . $tt . ",%' ";
                                 }
                                 $w .= "(" . substr($trait, 3) . ")";
                             } else {
                                 $w .= "trait not like '%," . $v . ",%' ";
                             }
                         } else {
                             if ($k == 'image') {
                                 $w .= "and ";
                                 if ($v == 1) {
                                     $w .= "litpic!='' ";
                                 }
                                 if ($v == 2) {
                                     $w .= "litpic='' ";
                                 }
                             } else {
                                 if ($k == 'keywords') {
                                     $w .= "and (title like '%" . $v . "%' or keywords like '%" . $v . "%')";
                                 } else {
                                     if ($k == 'page') {
                                         $page = explode(',', $v);
                                         $limit = '';
                                     } else {
                                         if (strpos($field_all, $k) !== FALSE) {
                                             if (strpos($v, '$') !== FALSE) {
                                                 $v = '".' . $v . '."';
                                             }
                                             $w .= "and " . $k . "='" . $v . "' ";
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $w = ' where isshow=1 ' . $w;
             if ($order == '') {
                 $order = ' order by orders desc,addtime desc,id desc';
             }
             if ($fielddb) {
                 $sql = 'select ' . $field_all . ' from ' . $db . ' a left join ' . $db . '_field b on (a.id=b.aid)' . $w . $order . $limit;
             } else {
                 $sql = 'select * from ' . $db . $w . $order . $limit;
             }
             $txt = '<?php $' . $as . 'n=0;';
             if ($page) {
                 $total_page = total_page($db . $w);
                 $txt .= '$' . $page[0] . '_class=syClass("c_product");$table' . $as . '= $' . $page[0] . '_class->syPager(syClass("syController")->syArgs("' . $page[0] . '_page",0,1),' . $page[1] . ',' . $total_page . ')->findSql("' . $sql . '");$' . $page[0] . '=pagetxt($' . $page[0] . '_class->syPager()->getPager(),3,"' . $page[0] . '_page");';
             } else {
                 $txt .= '$table' . $as . '=syClass("syModel")->' . $this->sycache . 'findSql("' . $sql . '");';
             }
             $txt .= 'foreach($table' . $as . ' as $' . $as . '){ $' . $as . '["tid_leafid"]=$sy_class_type->leafid($' . $as . '["tid"]);$' . $as . '["n"]=$' . $as . 'n=$' . $as . 'n+1; $' . $as . '["url"]=html_url("product",$' . $as . '); $' . $as . '["title"]=stripslashes($' . $as . '["title"]); $' . $as . '["description"]=stripslashes($' . $as . '["description"]); ?>';
             break;
         case $dbleft . 'message':
             $fielddb = syDB('fields')->findAll(array('molds' => 'message', 'lists' => 1), ' fieldorder DESC,fid ', 'fields');
             $field_all = 'id,tid,isshow,title,addtime,retime,orders,user,body,reply' . $fields;
             foreach ($a as $k => $v) {
                 if ($k == 'tid') {
                     foreach (explode(',', $v) as $t) {
                         if (strpos($t, '$') !== FALSE) {
                             $t = preg_replace('/\\[.*?\\]/', '["tid_leafid"]', $t);
                             $ts .= ',".' . $t . '."';
                         } else {
                             $ts .= ',' . syClass("syclasstype", array("article"))->leafid($t);
                         }
                     }
                     $w .= 'and tid in(' . substr($ts, 1) . ') ';
                 } else {
                     if ($k == 'reply') {
                         $w .= "and ";
                         if ($v == 1) {
                             $w .= "reply!='' ";
                         }
                         if ($v == 2) {
                             $w .= "reply='' ";
                         }
                     } else {
                         if ($k == 'page') {
                             $page = explode(',', $v);
                             $limit = '';
                         } else {
                             if (strpos($field_all, $k) !== FALSE) {
                                 if (strpos($v, '$') !== FALSE) {
                                     $v = '".' . $v . '."';
                                 }
                                 $w .= "and " . $k . "='" . $v . "' ";
                             }
                         }
                     }
                 }
             }
             if ($w != '') {
                 $w = ' where ' . substr($w, 3);
             }
             if ($order == '') {
                 $order = ' order by orders desc,addtime desc,id desc';
             }
             if ($fielddb) {
                 foreach ($fielddb as $v) {
                     $fields .= ',' . $v['fields'];
                 }
                 $sql = 'select ' . $field_all . ' from ' . $db . ' a left join ' . $db . '_field b on (a.id=b.aid)' . $w . $order . $limit;
             } else {
                 $sql = 'select * from ' . $db . $w . $order . $limit;
             }
             $txt = '<?php ';
             if ($page) {
                 $total_page = total_page($db . $w);
                 $txt .= '$' . $page[0] . '_class=syClass("c_message");$table' . $as . '= $' . $page[0] . '_class->syPager(syClass("syController")->syArgs("' . $page[0] . '_page",0,1),' . $page[1] . ',' . $total_page . ')->findSql("' . $sql . '");$' . $page[0] . '=pagetxt($' . $page[0] . '_class->syPager()->getPager(),3,"' . $page[0] . '_page");';
             } else {
                 $txt .= '$table' . $as . '=syClass("syModel")->' . $this->sycache . 'findSql("' . $sql . '");';
             }
             $txt .= 'foreach($table' . $as . ' as $' . $as . '){?>';
             break;
         case 'channel':
             if (!syDB('molds')->find(array('molds' => $molds), null, 'molds')) {
                 return '';
             }
             $db = $dbleft . $molds;
             $fielddb = syDB('fields')->findAll(array('molds' => $molds, 'lists' => 1), ' fieldorder DESC,fid ', 'fields');
             foreach ($fielddb as $v) {
                 $fields .= ',' . $v['fields'];
             }
             $field_all = 'id,tid,sid,title,style,trait,gourl,addtime,hits,htmlurl,htmlfile,orders,mrank,mgold,isshow,keywords,description' . $fields;
             foreach ($a as $k => $v) {
                 if ($k == 'tid') {
                     foreach (explode(',', $v) as $t) {
                         if (strpos($t, '$') !== FALSE) {
                             $t = preg_replace('/\\[.*?\\]/', '["tid_leafid"]', $t);
                             $ts .= ',".' . $t . '."';
                         } else {
                             $ts .= ',' . syClass("syclasstype", array("article"))->leafid($t);
                         }
                     }
                     $w .= 'and tid in(' . substr($ts, 1) . ') ';
                 } else {
                     if ($k == 'trait') {
                         $w .= "and ";
                         if (strpos($v, ',') !== FALSE) {
                             foreach (explode(',', $v) as $tt) {
                                 $trait .= "or trait like '%," . $tt . ",%' ";
                             }
                             $w .= "(" . substr($trait, 3) . ")";
                         } else {
                             $w .= "trait like '%," . $v . ",%' ";
                         }
                     } else {
                         if ($k == 'notrait') {
                             $w .= "and ";
                             if (strpos($v, ',') !== FALSE) {
                                 foreach (explode(',', $v) as $tt) {
                                     $trait .= "or trait not like '%," . $tt . ",%' ";
                                 }
                                 $w .= "(" . substr($trait, 3) . ")";
                             } else {
                                 $w .= "trait not like '%," . $v . ",%' ";
                             }
                         } else {
                             if ($k == 'keywords') {
                                 $w .= "and (title like '%" . $v . "%' or keywords like '%" . $v . "%')";
                             } else {
                                 if ($k == 'page') {
                                     $page = explode(',', $v);
                                     $limit = '';
                                 } else {
                                     if (strpos($field_all, $k) !== FALSE) {
                                         if (strpos($v, '$') !== FALSE) {
                                             $v = '".' . $v . '."';
                                         }
                                         $w .= "and " . $k . "='" . $v . "' ";
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $w = ' where isshow=1 ' . $w;
             if ($order == '') {
                 $order = ' order by orders desc,addtime desc,id desc';
             }
             if ($fielddb) {
                 $sql = 'select ' . $field_all . ' from ' . $db . ' a left join ' . $db . '_field b on (a.id=b.aid)' . $w . $order . $limit;
             } else {
                 $sql = 'select * from ' . $db . $w . $order . $limit;
             }
             $txt = '<?php $' . $as . 'n=0;';
             if ($page) {
                 $total_page = total_page($db . $w);
                 $txt .= '$' . $page[0] . '_class=syClass("c_' . $molds . '");$table' . $as . '= $' . $page[0] . '_class->syPager(syClass("syController")->syArgs("' . $page[0] . '_page",0,1),' . $page[1] . ',' . $total_page . ')->findSql("' . $sql . '");$' . $page[0] . '=pagetxt($' . $page[0] . '_class->syPager()->getPager(),3,"' . $page[0] . '_page");';
             } else {
                 $txt .= '$table' . $as . '=syClass("syModel")->' . $this->sycache . 'findSql("' . $sql . '");';
             }
             $txt .= 'foreach($table' . $as . ' as $' . $as . '){ $' . $as . '["tid_leafid"]=$sy_class_type->leafid($' . $as . '["tid"]);$' . $as . '["n"]=$' . $as . 'n=$' . $as . 'n+1; $' . $as . '["url"]=html_url("channel",$' . $as . ',0,0,' . $molds . '); $' . $as . '["title"]=stripslashes($' . $as . '["title"]); $' . $as . '["description"]=stripslashes($' . $as . '["description"]); ?>';
             break;
         case $dbleft . 'classtype':
             $field_all = 'tid,molds,pid,classname,gourl,litpic,title,keywords,description,orders,mrank,htmldir,htmlfile,mshow';
             foreach ($a as $k => $v) {
                 if ($k == 'not' && $a['pid']) {
                     $not = 1;
                 } else {
                     if ($k != 'not' && strpos($field_all, $k) !== FALSE) {
                         if ($k == 'pid') {
                             $p = $v;
                         }
                         if (strpos($v, '$') !== FALSE) {
                             $v = '".' . $v . '."';
                         }
                         $w .= "and " . $k . "='" . $v . "' ";
                     } else {
                         if ($k == 'body') {
                             if ($v == 1) {
                                 $field_all = $field_all . ',body';
                             }
                         }
                     }
                 }
             }
             if (!$a['pid'] && !$a['tid']) {
                 $w .= 'and pid=0 ';
             }
             if ($w) {
                 $w = " where " . substr($w, 3);
             }
             if ($order == '') {
                 $order = ' order by orders desc,tid';
             }
             $sql = 'select ' . $field_all . ' from ' . $db . $w . $order . $limit;
             if ($not == 1) {
                 if ($a['mshow']) {
                     $notarr = ',"mshow"=>' . $v;
                 }
                 $txt = '<?php $ytid=$type[tid];if(!syDB("classtype")->find(array("pid"=>' . $p . $notarr . '),null,"tid")){ $ypid=syDB("classtype")->find(array("tid"=>' . $p . $notarr . '),null,"pid");$type[tid]=$ypid[pid];} ?>';
             }
             $txt .= '<?php $' . $as . 'n=0;$table' . $as . '=syClass("syModel")->' . $this->sycache . 'findSql("' . $sql . '");';
             if ($not == 1) {
                 $txt .= '$type[tid]=$ytid;';
             }
             $txt .= 'foreach($table' . $as . ' as $' . $as . '){ $' . $as . '["tid_leafid"]=$sy_class_type->leafid($' . $as . '["tid"]);$' . $as . '["n"]=$' . $as . 'n=$' . $as . 'n+1; $' . $as . '["classname"]=stripslashes($' . $as . '["classname"]);$' . $as . '["description"]=stripslashes($' . $as . '["description"]); $' . $as . '["url"]=html_url("classtype",$' . $as . '); ?>';
             break;
         case $dbleft . 'special':
             $field_all = 'sid,molds,name,gourl,litpic,title,keywords,description,orders,htmldir,htmlfile,isshow';
             foreach ($a as $k => $v) {
                 if (strpos($field_all, $k) !== FALSE) {
                     if (strpos($v, '$') !== FALSE) {
                         $v = '".' . $v . '."';
                     }
                     $w .= "and " . $k . "='" . $v . "' ";
                 } else {
                     if ($k == 'body') {
                         if ($v == 1) {
                             $field_all = $field_all . ',body';
                         }
                     }
                 }
             }
             if ($w) {
                 $w = " where isshow=1 " . $w;
             }
             if ($order == '') {
                 $order = ' order by orders desc,sid';
             }
             $sql = 'select ' . $field_all . ' from ' . $db . $w . $order . $limit;
             $txt .= '<?php $' . $as . 'n=0;$table' . $as . '=syClass("syModel")->' . $this->sycache . 'findSql("' . $sql . '");foreach($table' . $as . ' as $' . $as . '){ $' . $as . '["n"]=$' . $as . 'n=$' . $as . 'n+1; $' . $as . '["name"]=stripslashes($' . $as . '["name"]);$' . $as . '["description"]=stripslashes($' . $as . '["description"]); $' . $as . '["url"]=html_url("special",$' . $as . '); ?>';
             break;
         case $dbleft . 'ads':
             $field_all = 'id,taid,orders,name,type,adsw,adsh,adfile,body,gourl,target,isshow';
             foreach ($a as $k => $v) {
                 if (strpos($field_all, $k) !== FALSE) {
                     if (strpos($v, '$') !== FALSE) {
                         $v = '".' . $v . '."';
                     }
                     $w .= "and " . $k . "='" . $v . "' ";
                 }
             }
             $w = " where isshow=1 " . $w;
             if ($order == '') {
                 $order = ' order by orders desc,id desc';
             }
             $sql = 'select * from ' . $db . $w . $order . $limit;
             $txt = '<?php $' . $as . 'n=0;$table' . $as . '=syClass("syModel")->' . $this->sycache . 'findSql("' . $sql . '");foreach($table' . $as . ' as $' . $as . '){ $' . $as . '["n"]=$' . $as . 'n=$' . $as . 'n+1; $' . $as . '["name"]=stripslashes($' . $as . '["name"]); ?>';
             break;
         case $dbleft . 'links':
             $field_all = 'id,taid,orders,name,image,gourl,isshow';
             foreach ($a as $k => $v) {
                 if ($k == 'type') {
                     if ($v == 'image') {
                         $w .= "and image!='' ";
                     }
                     if ($v == 'text') {
                         $w .= "and image='' ";
                     }
                 } else {
                     if (strpos($field_all, $k) !== FALSE) {
                         if (strpos($v, '$') !== FALSE) {
                             $v = '".' . $v . '."';
                         }
                         $w .= "and " . $k . "='" . $v . "' ";
                     }
                 }
             }
             $w = " where isshow=1 " . $w;
             if ($order == '') {
                 $order = ' order by orders desc,id desc';
             }
             $sql = 'select * from ' . $db . $w . $order . $limit;
             $txt = '<?php $table' . $as . '=syClass("syModel")->' . $this->sycache . 'findSql("' . $sql . '");foreach($table' . $as . ' as $' . $as . '){ $' . $as . '["name"]=stripslashes($' . $as . '["name"]); ?>';
             break;
         default:
             foreach ($a as $k => $v) {
                 if ($k == 'tid') {
                     $leafid = '$leafid=syClass("syclasstype")->leafid(' . $v . ');';
                     $w .= 'and tid in(".$leafid.") ';
                 } else {
                     if (strpos($v, '$') !== FALSE) {
                         $v = '".' . $v . '."';
                     }
                     $w .= "and " . $k . "='" . $v . "' ";
                 }
             }
             if ($w != '') {
                 $w = ' where ' . substr($w, 3);
             }
             $sql = 'select * from ' . $db . $w . $order . $limit;
             $txt = '<?php ' . $leafid . '$table' . $as . '=syClass("syModel")->' . $this->sycache . 'findSql("' . $sql . '");foreach($table' . $as . ' as $' . $as . '){ ';
             if (strpos($db, '[molds]') !== FALSE) {
                 $molds = explode('.', $db);
                 $txt .= '$' . $as . '["url"]=html_url(' . $molds[1] . ',$' . $as . ');';
             }
             $txt .= '?>';
             break;
     }
     return $txt;
 }