private function content_ajax_page_fc($fcid) { $fcitem = \Drupal\field_collection\Entity\FieldCollectionItem::load($fcid); $target = WG::entity_get_field_value($fcitem, 'field_target'); preg_match('%^([^:]+)://([0-9]+)$%', $target, $m); $itemtype = $m[1]; $id = $m[2]; switch ($itemtype) { case 'public318': $identifier = $id; $text = WG::entity_get_field_formatted_text($fcitem, 'field_annotation'); $stylename = 'large'; $icon_uri = _expo_public318_get_icon_uri($identifier); $icontag = WG::render_styled_image($icon_uri, $stylename); $output = '<div class="sticky-fc-public318">' . '<div class="collicon">' . _expo_coll_url($identifier, $icontag) . '</div>' . '<div class="colltext">' . $text . '</div>' . '</div>'; break; case 'storynode': $nid = $id; $story = node_load($nid); $v = entity_view($story, 'ajaxpage'); $output = render($v); break; default: $tag = "<div class=\"sticky\" id=\"sticky_{$pos}\">" . $itemtype . $pos . "</div>"; } $build = ['#markup' => $output]; return $build; }
private function _collitem_element_make(&$el, $i, $identifier, $fcid, $annotation = '', $stylename = 'expothumb') { $icon_info = _expo_public318_get_content_by_id($identifier, 'icon_info'); $icon_uri = _expo_public318_get_icon_by_id($identifier, $icon_info); $icontag = WG::render_styled_image($icon_uri, $stylename); $el['icon'] = ['#markup' => '<div class="collitem-icon">' . $icontag . '</div>', '#weight' => -10]; $el['annotationwrapper'] = ['#prefix' => '<div class="annotationwrapper">', '#suffix' => '</div>']; $el['annotationwrapper']['annotation'] = array('#type' => 'textarea', '#title' => t('我的註記'), '#attributes' => ['class' => ['theannotation']]); $el['target'] = ['#type' => 'hidden', '#value' => 'public318://' . $identifier, '#attributes' => ['class' => ['thetarget']]]; $el['actions'] = ['#type' => 'container', '#prefix' => '<span class="collitem-edit-actions">', '#suffix' => '</span>', '#weight' => 50]; $el['actions']['remove'] = array('#markup' => '<a href="#" class="collitem-remove btn btn-default" data-index="' . $i . '">移除</i></a>'); }
public static function genRandomExpoFront($nodenums = 1, $stickymax = 78, $storymax = 10) { $ns = 'public318'; $fetchurl = _expo_coll_fetchurl($ns); $json_fn = $ns . '-all'; $cache_fn_all = _expo_get_json_fn($json_fn); $json = WG::fetch_url($fetchurl, $cache_fn_all); $ret = Json::decode($json); $datas0 = $ret['results']; $public318_ids = [10478, 11857, 11861, 11897, 11902, 11914, 11933, 11940, 11941, 11956, 11960, 11962, 12377, 12378, 12382, 12395, 12578, 12663, 12669, 12681, 12684, 13035, 13049, 13050, 13051, 13064, 13065, 13066, 13067, 13070, 13076, 13077, 13078, 13100, 13121, 13122, 13130, 13135, 13136, 13138, 13140, 13142, 13144, 13145, 13149, 13173, 13182, 13202, 13225, 13253, 13255, 13258, 13259, 13260, 13264, 13265, 13266, 13267, 13292, 13305, 13313, 13325, 13328, 13329, 13343, 13348, 13349, 13350, 13351, 13352, 13353, 13354, 13356, 13377, 13391, 13394, 13395, 13396, 13413, 13416, 13428, 14944, 14945, 14946, 14948, 14951, 14952, 14953, 14954, 14955, 14956, 14957, 14959, 14960, 14961, 14962, 14963, 14967, 14968, 14969, 14970, 14971, 14972]; $datas = []; foreach ($datas0 as $data0) { $id = $data0['identifier']; if (in_array($id, $public318_ids)) { //echo $id.' '; $datas[$id] = $data0; } } for ($i = 1; $i <= $nodenums; $i++) { $d = []; $d['title'] = 'expo-autofront-' . date('ymdhi'); $d['public'] = 0; $d['showinfront'] = 1; $items = self::_getRandomItems2($storymax - 1, $stickymax - 1, $public318_ids); $easteregg_index = rand(0, $stickymax - 1); $el = ['itemtype' => 'story', 'id' => WG::config_get('expo.settings', 'easter_egg.nid')]; $items = DT::array_insert_element($items, $easteregg_index, $el); //print_r($items); //die(); $pos = 0; foreach ($items as $item) { $collitem = []; $collitem['weight'] = $pos; $pos++; DT::dnotice($pos . '-' . $item['itemtype'] . ':' . $item['id']); switch ($item['itemtype']) { case 'story': $collitem['target'] = 'storynode://' . $item['id']; $collitem['annotation'] = []; break; case 'public318': $id = $item['id']; //echo $id.' '; $entity = $datas[$id]; self::_fetch_public318($entity); $collitem['target'] = 'public318://' . $entity['identifier']; $text = $entity['text']; $text = str_replace(';;;', "\n", $text); $collitem['annotation'] = ['format' => 'rich_html_base', 'value' => $text]; break; } $d['collitems'][] = $collitem; } \Drupal\expo\ExpoCrud::saveExpo($d); } }