예제 #1
0
 public function getXtSidebars($pNids)
 {
     $cjxt = TreeData::findFirst(array('conditions' => 'title="财经学堂"'));
     $temXtNodes = TreeStruct::find(array('conditions' => 'lft>?1 and rgt<?2 and type=:type:', 'bind' => array(1 => $cjxt->TreeStruct->lft, 2 => $cjxt->TreeStruct->rgt, 'type' => 'default'), 'order' => 'lft'));
     $xtNodes = array();
     foreach ($temXtNodes as $key => $temXtNode) {
         $treeData = $temXtNode->TreeData->toArray();
         $xtNodes[$key] = $temXtNode->toArray();
         $xtNodes[$key]['TreeData'] = $treeData;
     }
     $xtNodes = TreeStruct::addNodesAttr($xtNodes);
     //		echo '<pre>';print_r($xtNodes);echo '</pre>';die();
     $xtSidebars = array();
     $parent_nid = 0;
     foreach ($xtNodes as $key => $xtNode) {
         $nid = $xtNode['id'];
         if (in_array($nid, $pNids)) {
             $xtNode['current'] = true;
         }
         if ($xtNode['lvl'] == 3) {
             $xtSidebars[$nid] = $xtNode;
             $xtSidebars[$nid]['children'] = array();
             $parent_nid = $nid;
         } else {
             $xtSidebars[$parent_nid]['children'][$nid] = $xtNode;
         }
     }
     return $xtSidebars;
 }
예제 #2
0
function wfGetTreeData($rsargs = null)
{
    global $wgAjaxCachePolicy, $wgRequest;
    $callback = $wgRequest->getVal('callback');
    $orn = $wgRequest->getVal('orn');
    $titleText = $wgRequest->getVal('id');
    $setRoot = $wgRequest->getBool('setRoot');
    $numDescLevels = $wgRequest->getVal('descLevels');
    if ($numDescLevels > 10) {
        $numDescLevels = 10;
    }
    $numAncLevels = $wgRequest->getVal('ancLevels');
    if ($numAncLevels > 20) {
        $numAncLevels = 20;
    }
    // set cache policy
    $wgAjaxCachePolicy->setPolicy(0);
    // set content type
    $wgAjaxCachePolicy->setContentType($callback ? 'application/javascript' : 'application/json');
    $data = null;
    $treeData = new TreeData();
    if ($titleText) {
        $title = Title::newFromText($titleText);
        if ($title) {
            if ($setRoot) {
                // we can get a person initially and when someone sets a new root
                if ($orn == 'left') {
                    $numDescLevels = 0;
                    if (!$numAncLevels) {
                        $numAncLevels = $title->getNamespace() == NS_PERSON ? 7 : 6;
                    }
                } else {
                    if (!$numDescLevels) {
                        $numDescLevels = $title->getNamespace() == NS_PERSON ? 1 : 2;
                    }
                    $numAncLevels = 0;
                }
            } else {
                if ($orn == 'left') {
                    $numDescLevels = 0;
                    if (!$numAncLevels) {
                        $numAncLevels = 2;
                    }
                } else {
                    if ($orn == 'right') {
                        if (!$numDescLevels) {
                            $numDescLevels = 2;
                        }
                        $numAncLevels = 0;
                    } else {
                        // make sure we have the final redirect
                        $title = StructuredData::getRedirectToTitle($title);
                        $orn = 'center';
                        if ($title->getNamespace() == NS_PERSON) {
                            if (!$numDescLevels) {
                                $numDescLevels = 1;
                            }
                            if (!$numAncLevels) {
                                $numAncLevels = 7;
                            }
                        } else {
                            if (!$numDescLevels) {
                                $numDescLevels = 2;
                            }
                            if (!$numAncLevels) {
                                $numAncLevels = 6;
                            }
                        }
                    }
                }
            }
            if ($title->getNamespace() == NS_PERSON) {
                $data = $treeData->getPersonData($title->getText(), $orn, $numDescLevels, $numAncLevels);
            } else {
                if ($title->getNamespace() == NS_FAMILY) {
                    $data = $treeData->getFamilyData($title->getText(), $orn, $numDescLevels, $numAncLevels);
                }
            }
        }
    }
    if (!$data) {
        $data = array('error' => 'invalid title');
    }
    $json = StructuredData::json_encode($data);
    if ($callback) {
        $json = $callback . '(' . $json . ');';
    }
    return $json;
}
예제 #3
0
 public function fetchWidgetData($view, $block = '')
 {
     $widgetData = array();
     $blockCfgKey = $block ? $view . '_' . $block : $view;
     $blockCfg = $this->_siteConfig['blockCfg'][$blockCfgKey];
     $blockNum = $this->_siteConfig['widgetCfg']['blockNum'];
     switch ($view) {
         case 'slider':
             //理财故事
         //理财故事
         case 'btslider':
             $widgetData[$block] = array('blockName' => $block, 'items' => $this->_siteConfig['slider'][$block]);
             break;
         case 'dailyword':
             $dailyword['title'] = '天天词汇';
             $dailyword['word'] = Tags::findFirst(array("conditions" => "is_cidian = ?1", "bind" => array(1 => 1)))->toArray();
             $widgetData = $dailyword;
             break;
         case 'content':
             switch ($block) {
                 case 'node':
                     $content = TreeData::findFirst($this->_params['nid'])->toArray();
                     $content['content'] = htmlspecialchars_decode($content['content']);
                     $widgetData[$block]['content'] = $content;
                     break;
                 case 'tag':
                     $content = Tags::findFirst($this->_params['tid'])->toArray();
                     $content['content'] = htmlspecialchars_decode($content['description']);
                     $content['title'] = $content['name'];
                     $widgetData[$block]['content'] = $content;
                     break;
                 case 'static':
                     $static_content = TreeStruct::findFirst(array("conditions" => "pid = ?1", "bind" => array(1 => $this->_params['nid']), 'order' => 'lft asc'));
                     $content = array();
                     if ($static_content) {
                         $content['title'] = $static_content->TreeData->title;
                         $content['content'] = htmlspecialchars_decode($static_content->TreeData->content);
                     }
                     $widgetData[$block]['blockName'] = $block;
                     $widgetData[$block]['content'] = $content;
                     break;
                 default:
                     break;
             }
             break;
         case 'cidian':
             $cidianCloudNum = $this->_siteConfig['widgetCfg']['cidianCloudNum'];
             $tags = Tags::fetchCidiansCloud($cidianCloudNum);
             $widgetData = $tags;
             break;
         case 'hangqing':
         case 'lilv':
         case 'tool':
             break;
         case 'taglist':
             $taglist = array();
             $itemPer = $this->_siteConfig['widgetCfg']['listItemPer'];
             $start = ($this->_params['p'] - 1) * $itemPer;
             if ($this->_params['tagPrefix']) {
                 $conditions = 'pinyinPrefix="' . $this->_params['tagPrefix'] . '" and is_cidian=1';
             } else {
                 $conditions = 'is_cidian=1';
             }
             $taglist['items'] = Tags::find(array('conditions' => $conditions, 'order' => 'id desc', 'limit' => array('number' => $itemPer, 'offset' => $start)))->toArray();
             $totalTags = Tags::count($conditions);
             $params = array('total_rows' => $totalTags, 'now_page' => $this->_params['p'], 'list_rows' => $itemPer);
             $pagerLib = new Pager($params);
             $pager = $pagerLib->show(3);
             $taglist['pager'] = $pager;
             //				echo '<pre>';print_r($taglist);echo '</pre>';
             $widgetData = $taglist;
             break;
         case 'taglist_header':
             $optRanges = array(97, 122);
             $options = array();
             $options[] = '0-9';
             for ($i = $optRanges[0]; $i <= $optRanges[1]; $i++) {
                 $options[] = chr($i);
             }
             $widgetData = $options;
             break;
         case 'list':
             switch ($block) {
                 case 'node':
                     $nodeLists = array();
                     $itemPer = $this->_siteConfig['widgetCfg']['listItemPer'];
                     $start = ($this->_params['p'] - 1) * $itemPer;
                     $temNodes = TreeStruct::find(array('conditions' => 'lft>?1 and rgt<?2 and type=:type:', 'bind' => array(1 => $this->_params['node']->lft, 2 => $this->_params['node']->rgt, 'type' => 'article'), 'limit' => array('number' => $itemPer, 'offset' => $start), 'order' => 'id desc'));
                     $nodes = array();
                     foreach ($temNodes as $key => $temNode) {
                         $treeData = $temNode->TreeData->toArray();
                         $nodes[$key] = $temNode->toArray();
                         $nodes[$key]['TreeData'] = $treeData;
                     }
                     $nodes = TreeStruct::addNodesAttr($nodes, array('menu' => true, 'menuLevel' => 1));
                     $totalNodes = TreeStruct::count(array('conditions' => 'lft>?1 and rgt<?2 and type=:type:', 'bind' => array(1 => $this->_params['node']->lft, 2 => $this->_params['node']->rgt, 'type' => 'article')));
                     $params = array('total_rows' => $totalNodes, 'now_page' => $this->_params['p'], 'list_rows' => $itemPer);
                     $pagerLib = new Pager($params);
                     $pager = $pagerLib->show(3);
                     $nodeLists['title'] = $this->_params['node']->TreeData->title;
                     $nodeLists['pager'] = $pager;
                     $nodeLists['items'] = $nodes;
                     $widgetData[$block] = $nodeLists;
                     break;
                 case 'tagnode':
                     $tagNodesNum = $this->_siteConfig['widgetCfg']['tagNodesNum'];
                     $nodeLists = array();
                     if ($tid = $this->_params['tid']) {
                         $tagNodes = NodeTags::find(array('conditions' => 'tid=' . $tid, 'limit' => $tagNodesNum));
                         $nodes = array();
                         foreach ($tagNodes as $key => $tagNode) {
                             $treeStruct = $tagNode->TreeStruct;
                             $treeData = $treeStruct->TreeData->toArray();
                             $nodes[$key] = $treeStruct->toArray();
                             $nodes[$key]['TreeData'] = $treeData;
                         }
                         $nodes = TreeStruct::addNodesAttr($nodes, array('menu' => true, 'menuLevel' => 2));
                         $nodeLists['items'] = $nodes;
                         $nodeLists['title'] = '"' . $this->_params['tag']->name . '" 相关文章';
                     }
                     $widgetData[$block] = $nodeLists;
                     break;
                 case 'search':
                     $nodeLists = array();
                     $keyword = $this->_params['search_keyword'];
                     if ($keyword) {
                         $itemPer = $this->_siteConfig['widgetCfg']['listItemPer'];
                         $start = ($this->_params['p'] - 1) * $itemPer;
                         $temNodeDatas = TreeData::find(array('conditions' => 'content like :keyword:', 'bind' => array('keyword' => '%' . $keyword . '%'), 'limit' => array('number' => $itemPer, 'offset' => $start), 'order' => 'id desc'));
                         $nodes = array();
                         foreach ($temNodeDatas as $key => $temNodeData) {
                             $treeStruct = $temNodeData->TreeStruct;
                             $treeData = $temNodeData->toArray();
                             $nodes[$key] = $treeStruct->toArray();
                             $nodes[$key]['TreeData'] = $treeData;
                         }
                         $nodes = TreeStruct::addNodesAttr($nodes, array('menu' => true, 'menuLevel' => 2));
                         $totalNodes = TreeData::count(array('conditions' => 'content like :keyword:', 'bind' => array('keyword' => '%' . $keyword . '%')));
                         $params = array('total_rows' => $totalNodes, 'now_page' => $this->_params['p'], 'list_rows' => $itemPer);
                         $pagerLib = new Pager($params);
                         $pager = $pagerLib->show(3);
                         //							$nodeLists['is_search'] = 1;
                         $searchResultStr = $totalNodes ? $totalNodes . ' 条记录' : '没有记录';
                         $nodeLists['title'] = '"' . $keyword . '" 的搜索结果: ' . $searchResultStr;
                         $nodeLists['pager'] = $pager;
                         $nodeLists['items'] = $nodes;
                     }
                     $widgetData[$block] = $nodeLists;
                     break;
                 default:
                     break;
             }
             break;
         case 'listGroup':
         case 'navTab':
         case 'panel':
         case 'panel2':
             $widgetData[$block]['blockName'] = $block;
             $widgetData[$block]['items'] = array();
             if (isset($this->_siteConfig['blockCfg'][$view . '_' . $block])) {
                 $blockParams = $this->_siteConfig['blockCfg'][$view . '_' . $block];
                 foreach ($blockParams as $blockParam) {
                     $nodeLists = array('title' => $blockParam['title'], 'data' => array());
                     $blockNode = TreeStruct::findFirst($blockParam['nid']);
                     $temNodes = TreeStruct::find(array('conditions' => "lft>?1 and rgt<?2 and type=:type:", 'bind' => array(1 => $blockNode->lft, 2 => $blockNode->rgt, 'type' => 'article'), 'limit' => $blockNum, 'order' => 'id desc'));
                     $nodes = array();
                     foreach ($temNodes as $key => $temNode) {
                         $treeData = array();
                         if ($temNode->TreeData) {
                             $treeData = $temNode->TreeData->toArray();
                         }
                         $nodes[$key] = $temNode->toArray();
                         $nodes[$key]['TreeData'] = $treeData;
                     }
                     $nodes = TreeStruct::addNodesAttr($nodes);
                     $nodeLists['data'] = $nodes;
                     $widgetData[$block]['items'][] = $nodeLists;
                 }
             } else {
                 $nodeLists = array('title' => '', 'data' => array());
                 switch ($block) {
                     case 'hot':
                         $nodeLists['title'] = '热门文章';
                         $hotNids = $this->_siteConfig['hotNids'];
                         $hotNidsStr = implode(',', $hotNids);
                         $temNodes = TreeStruct::find(array('conditions' => "id in (" . $hotNidsStr . ") and type=:type:", 'bind' => array('type' => 'article'), 'order' => 'id asc'));
                         $nodes = array();
                         foreach ($temNodes as $key => $temNode) {
                             $treeData = $temNode->TreeData->toArray();
                             $nodes[$key] = $temNode->toArray();
                             $nodes[$key]['TreeData'] = $treeData;
                         }
                         $nodes = TreeStruct::addNodesAttr($nodes);
                         $nodeLists['data'] = $nodes;
                         break;
                     case 'relation':
                         $nodeLists['title'] = '相关文章';
                         if ($this->_params['node']->type == 'article') {
                             $temNodes = TreeStruct::find(array('conditions' => "pid=?1 and type=:type:", 'bind' => array(1 => $this->_params['node']->pid, 'type' => 'article'), 'limit' => $blockNum, 'order' => 'id desc'));
                             $nodes = array();
                             foreach ($temNodes as $key => $temNode) {
                                 $treeData = $temNode->TreeData->toArray();
                                 $nodes[$key] = $temNode->toArray();
                                 $nodes[$key]['TreeData'] = $treeData;
                             }
                             $nodes = TreeStruct::addNodesAttr($nodes);
                             $nodeLists['data'] = $nodes;
                         }
                         break;
                     default:
                         break;
                 }
                 $widgetData[$block]['items'][] = $nodeLists;
             }
             break;
         case 'breadcrumb':
             $widgetData = $this->_initBreadcrumb();
             break;
         case 'nodetag':
             $temNodeTags = NodeTags::find(array('conditions' => 'nid=?1', 'bind' => array(1 => $this->_params['node']->id)));
             $nodeTags = array();
             foreach ($temNodeTags as $key => $temNodeTag) {
                 $tag = $temNodeTag->Tags->toArray();
                 $nodeTags[$key] = $temNodeTag->toArray();
                 $nodeTags[$key]['Tags'] = $tag;
             }
             $widgetData = $nodeTags;
             break;
         case 'siblings':
             $siblings = array('prev' => array('title' => '上一篇', 'item' => array()), 'next' => array('title' => '下一篇', 'item' => array()));
             switch ($block) {
                 case 'node':
                     if ($this->_params['node']->type == 'article') {
                         $prevNode = TreeStruct::findFirst(array('conditions' => "lft<?1 and pid=?2 and type=:type:", 'bind' => array(1 => $this->_params['node']->lft, 2 => $this->_params['node']->pid, 'type' => 'article'), 'order' => 'lft desc'));
                         $nextNode = TreeStruct::findFirst(array('conditions' => "lft>?1 and pid=?2 and type=:type:", 'bind' => array(1 => $this->_params['node']->lft, 2 => $this->_params['node']->pid, 'type' => 'article'), 'order' => 'lft asc'));
                         $temNodes = array('prev' => $prevNode, 'next' => $nextNode);
                         $nodes = array();
                         foreach ($temNodes as $key => $temNode) {
                             if ($temNode) {
                                 $treeData = $temNode->TreeData->toArray();
                                 $nodes[$key] = $temNode->toArray();
                                 $nodes[$key]['TreeData'] = $treeData;
                                 $nodes[$key]['title'] = $treeData['title'];
                             }
                         }
                         $nodes = TreeStruct::addNodesAttr($nodes);
                         $siblings['prev']['item'] = $nodes['prev'];
                         $siblings['next']['item'] = $nodes['next'];
                     }
                     break;
                 case 'tag':
                     $siblings['prev']['title'] = '上一个';
                     $siblings['next']['title'] = '下一个';
                     if ($tag = $this->_params['tag']) {
                         $pinyinPrefix = $tag->pinyinPrefix;
                         if (!$pinyinPrefix) {
                             break;
                         }
                         $prevTag = Tags::findFirst(array('conditions' => "pinyinPrefix=:pinyin:", 'bind' => array('pinyin' => $pinyinPrefix), 'order' => 'id desc'))->toArray();
                         $nextTag = Tags::findFirst(array('conditions' => "pinyinPrefix=:pinyin:", 'bind' => array('pinyin' => $pinyinPrefix), 'order' => 'id asc'))->toArray();
                         $tags = array('prev' => $prevTag, 'next' => $nextTag);
                         $tags = Tags::addTagsAttr($tags);
                         foreach ($tags as $key => $tag) {
                             $tags[$key]['title'] = $tag['name'];
                         }
                         $siblings['prev']['item'] = $tags['prev'];
                         $siblings['next']['item'] = $tags['next'];
                     }
                     break;
                 default:
                     break;
             }
             $widgetData[$block]['items'] = $siblings;
             break;
         case 'xtSidebars':
             $pNids = array($this->_params['node']->id);
             foreach ($this->_params['nodeParents'] as $nodeParent) {
                 $pNids[] = $nodeParent->id;
             }
             $xtSidebars = TreeStruct::getXtSidebars($pNids);
             $widgetData = $xtSidebars;
             break;
         case 'list_header':
             $list_header = array();
             $temNodes = count($this->_params['nodeChilds']) ? $this->_params['nodeChilds'] : $this->_params['nodeSiblings'];
             if ($temNodes) {
                 foreach ($temNodes as $key => $temNode) {
                     $treeData = $temNode->TreeData->toArray();
                     $list_header[$key] = $temNode->toArray();
                     $list_header[$key]['TreeData'] = $treeData;
                     $list_header[$key]['current'] = false;
                     if ($this->_params['node']->id == $temNode->id) {
                         $list_header[$key]['current'] = true;
                     }
                 }
                 $list_header = TreeStruct::addNodesAttr($list_header);
             }
             $widgetData = $list_header;
             break;
         case 'search_header':
             $search_result = array();
             $search_result['search_keyword'] = $this->_params['search_keyword'];
             if ($search_result['search_keyword']) {
                 $search_result['search_result_title'] = '<b>"' . $this->_params['search_keyword'] . '</b>" 的搜索结果.';
             } else {
                 $search_result['search_result_title'] = '请输入关键字搜索!';
             }
             $widgetData = $search_result;
             break;
         case 'sitemap':
             $sitemap = array();
             $sitemap['menus'] = $this->_menus;
             $allTags = array();
             $temTags = Tags::find(array('conditions' => "", 'order' => 'pinyinPrefix'))->toArray();
             $temTags = Tags::addTagsAttr($temTags);
             foreach ($temTags as $key => $temTag) {
                 $pinyinKey = $temTag['pinyinPrefix'] ? trim($temTag['pinyinPrefix']) : '0-9';
                 $allTags[$pinyinKey][] = $temTag;
             }
             unset($temTags);
             $sitemap['tags'] = $allTags;
             //				echo '<pre>';print_r($sitemap);echo '</pre>';die();
             $widgetData = $sitemap;
             break;
         case 'notfound':
             $widgetData = '';
             break;
         case 'test':
             $result = 'test';
             $widgetData = $result;
             break;
         default:
             break;
     }
     return $widgetData;
 }