1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22:
23: include_once dirname(__DIR__) . '/include/common.php';
24:
25: function publisher_items_spot_show($options)
26: {
27: $publisher = Publisher::getInstance();
28: $opt_display_last = $options[0];
29: $opt_items_count = $options[1];
30: $opt_categoryid = $options[2];
31: $sel_items = isset($options[3]) ? explode(',', $options[3]) : '';
32: $opt_display_poster = $options[4];
33: $opt_display_comment = $options[5];
34: $opt_display_type = $options[6];
35: $opt_truncate = (int)($options[7]);
36: $opt_catimage = $options[8];
37: if ($opt_categoryid == 0) {
38: $opt_categoryid = -1;
39: }
40: $block = array();
41: if ($opt_display_last == 1) {
42: $itemsObj = $publisher->getItemHandler()->getAllPublished($opt_items_count, 0, $opt_categoryid, $sort = 'datesub', $order = 'DESC', 'summary');
43: $i = 1;
44: $itemsCount = count($itemsObj);
45: if ($itemsObj) {
46: if ($opt_categoryid != -1 && $opt_catimage) {
47: $cat = $publisher->getCategoryHandler()->get($opt_categoryid);
48: $category['name'] = $cat->getVar('name');
49: $category['categoryurl'] = $cat->getCategoryUrl();
50: if ($cat->image() !== 'blank.png') {
51: $category['image_path'] = PublisherUtils::getImageDir('category', false) . $cat->image();
52: } else {
53: $category['image_path'] = '';
54: }
55: $block['category'] = $category;
56: }
57:
58: foreach ($itemsObj as $thisitem) {
59: $item = $thisitem->toArray('default', 0, $opt_truncate);
60: if ($i < $itemsCount) {
61: $item['showline'] = true;
62: } else {
63: $item['showline'] = false;
64: }
65: if ($opt_truncate > 0) {
66: $block['truncate'] = true;
67: }
68: $block['items'][] = $item;
69: ++$i;
70: }
71: }
72: } else {
73: $i = 1;
74: $itemsCount = count($sel_items);
75: foreach ($sel_items as $item_id) {
76:
77: $itemObj = $publisher->getItemHandler()->get($item_id);
78: if (!$itemObj->notLoaded()) {
79: $item = $itemObj->toArray();
80: $item['who_when'] = sprintf(_MB_PUBLISHER_WHO_WHEN, $itemObj->posterName(), $itemObj->datesub());
81: if ($i < $itemsCount) {
82: $item['showline'] = true;
83: } else {
84: $item['showline'] = false;
85: }
86: if ($opt_truncate > 0) {
87: $block['truncate'] = true;
88: $item['summary'] = PublisherUtils::truncateTagSafe($item['summary'], $opt_truncate);
89: }
90: $block['items'][] = $item;
91: ++$i;
92: }
93: }
94: }
95: if (!isset($block['items']) || count($block['items']) == 0) {
96: return false;
97: }
98: $block["publisher_url"] = PUBLISHER_URL;
99: $block['lang_reads'] = _MB_PUBLISHER_READS;
100: $block['lang_comments'] = _MB_PUBLISHER_COMMENTS;
101: $block['lang_readmore'] = _MB_PUBLISHER_READMORE;
102: $block['display_whowhen_link'] = $opt_display_poster;
103: $block['display_comment_link'] = $opt_display_comment;
104: $block['display_type'] = $opt_display_type;
105: return $block;
106: }
107:
108: function publisher_items_spot_edit($options)
109: {
110: $form = new Xoops\Form\BlockForm();
111: $autoEle = new Xoops\Form\RadioYesNo(_MB_PUBLISHER_AUTO_LAST_ITEMS, 'options[0]', $options[0]);
112: $countEle = new Xoops\Form\Text(_MB_PUBLISHER_LAST_ITEMS_COUNT, 'options[1]', 2, 255, $options[1]);
113: $catEle = new Xoops\Form\Label(_MB_PUBLISHER_SELECTCAT, PublisherUtils::createCategorySelect($options[2], 0, true, 'options[2]'));
114: $publisher = Publisher::getInstance();
115: $criteria = new CriteriaCompo();
116: $criteria->setSort('datesub');
117: $criteria->setOrder('DESC');
118: $itemsObj = $publisher->getItemHandler()->getList($criteria);
119: $keys = array_keys($itemsObj);
120: unset($criteria);
121: if (empty($options[3]) || ($options[3] == 0)) {
122: $sel_items = isset($keys[0]) ? $keys[0] : 0;
123: } else {
124: $sel_items = explode(',', $options[3]);
125: }
126: $itemEle = new Xoops\Form\Select(_MB_PUBLISHER_SELECT_ITEMS, 'options[3]', $sel_items, 10, true);
127: $itemEle->addOptionArray($itemsObj);
128: $whoEle = new Xoops\Form\RadioYesNo(_MB_PUBLISHER_DISPLAY_WHO_AND_WHEN, 'options[4]', $options[4]);
129: $comEle = new Xoops\Form\RadioYesNo(_MB_PUBLISHER_DISPLAY_COMMENTS, 'options[5]', $options[5]);
130: $typeEle = new Xoops\Form\Select(_MB_PUBLISHER_DISPLAY_TYPE, 'options[6]', $options[6]);
131: $typeEle->addOptionArray(array(
132: 'block' => _MB_PUBLISHER_DISPLAY_TYPE_BLOCK,
133: 'bullet' => _MB_PUBLISHER_DISPLAY_TYPE_BULLET,
134: ));
135: $truncateEle = new Xoops\Form\Text(_MB_PUBLISHER_TRUNCATE, 'options[7]', 4, 255, $options[7]);
136: $imageEle = new Xoops\Form\RadioYesNo(_MB_PUBLISHER_DISPLAY_CATIMAGE, 'options[8]', $options[8]);
137: $form->addElement($autoEle);
138: $form->addElement($countEle);
139: $form->addElement($catEle);
140: $form->addElement($itemEle);
141: $form->addElement($whoEle);
142: $form->addElement($comEle);
143: $form->addElement($typeEle);
144: $form->addElement($truncateEle);
145: $form->addElement($imageEle);
146: return $form->render();
147: }
148: