Ejemplo n.º 1
0
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $d = ['nid' => $form_state->getValue(['base', 'nid']), 'title' => $form_state->getValue(['base', 'title']), 'email' => $form_state->getValue(['base', 'email']), 'author' => $form_state->getValue(['base', 'author']), 'public' => $form_state->getValue(['base', 'public']), 'body' => $form_state->getValue(['base', 'body']), 'showinfront' => 0, 'hide' => 0, 'highlight' => 0];
     $fi = $form_state->getValue(['base', 'featuredimage']);
     if ($fi) {
         $fid = array_shift($fi);
         $d['featuredimage'] = array('target_id' => $fid);
     }
     $collitems_json = $form_state->getValue(['collitems', 'data']);
     $collitems = Json::decode($collitems_json);
     foreach ($collitems as &$collitem) {
         $anno = $collitem['annotation'];
         if (is_array($anno)) {
             $collitem['annotation'] = $anno;
         } else {
             $collitem['annotation'] = array('value' => '<p>' . nl2br($anno) . '</p>', 'format' => 'rich_html_base');
         }
     }
     $d['collitems'] = $collitems;
     $is_new = $d['nid'] ? false : true;
     $entity = \Drupal\expo\ExpoCrud::saveExpo($d);
     $nid = $entity->id();
     $form_state->setRedirect('entity.node.canonical', ['node' => $nid]);
     $viewhash = WG::entity_get_field_value($entity, 'field_viewhash');
     $edithash = WG::entity_get_field_value($entity, 'field_edithash');
     //entity.node.canonical
     global $base_url;
     $viewurl = $base_url . '/p/' . $viewhash;
     $editurl = $base_url . '/p/edit/' . $edithash;
     drupal_set_message(t('已儲存,請使用以下連結分享與編輯你的個人策展。<br/>分享:@viewurl<br/>編輯:@editurl', array('@viewurl' => $base_url . '/p/' . $viewhash, '@editurl' => $base_url . '/p/edit/' . $edithash)));
     if ($is_new) {
         $to = $d['email'];
         _expo_mailhash($to, $viewurl, $editurl);
         $to = '*****@*****.**';
         _expo_mailhash($to, $viewurl, $editurl);
     }
 }
Ejemplo n.º 2
0
 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);
     }
 }