예제 #1
0
파일: Feed.php 프로젝트: tlandn/akvo-web
 public function display($aAttributes)
 {
     $oDaoJsonData = new JsonDataDao();
     $sFeedSlug = $aAttributes['slug'];
     unset($aAttributes['slug']);
     $aFeed = $oDaoJsonData->fetchFeedBySlug($sFeedSlug);
     $iFeedId = $aFeed['id'];
     $aDefaultParameters = unserialize($aFeed['feed_parameters']);
     ksort($aAttributes);
     ksort($aDefaultParameters);
     $aNewKeys = array_diff($aAttributes, $aDefaultParameters);
     $aAllParams = array_merge($aDefaultParameters, $aNewKeys);
     ksort($aAllParams);
     $aAttributes = array_combine(array_keys($aAllParams), $aAttributes);
     ksort($aAttributes);
     $sSerializedParameters = serialize($aAttributes);
     $aFeedDetail = $oDaoJsonData->fetchSingleFeedQueueByParams($iFeedId, $sSerializedParameters);
     if (!$aFeedDetail) {
         $aInsertData = array();
         $aInsertData['json_data_id'] = $iFeedId;
         $aInsertData['parameters'] = $sSerializedParameters;
         $aInsertData['last_update_time'] = date('Y-m-d H:i:s');
         $aInsertData['last_display_time'] = date('Y-m-d H:i:s');
         $mStatus = $oDaoJsonData->insertJsonDataQueue($aInsertData);
         if (is_int($mStatus)) {
             $oFeed = new JsonDataFeed();
             $oFeed->updateQueue($iFeedId, $mStatus);
             $aFeedDetail = $oDaoJsonData->fetchSingleFeedQueueByParams($iFeedId, $sSerializedParameters);
         }
     }
     if ($aFeedDetail) {
         $iFeedId = $aFeedDetail['json_data_id'];
         $iFeedQueueId = $aFeedDetail['id'];
         $oDaoJsonData->updateDisplayTime($iFeedQueueId);
         $this->enqueueFrontEndCss($iFeedId, $sFeedSlug);
         $sData = file_get_contents(JsonData_Cache_Dir . DIRECTORY_SEPARATOR . $sFeedSlug . DIRECTORY_SEPARATOR . 'data-' . $iFeedQueueId . '.json');
         $aData = json_decode($sData, true);
         require JsonData_Cache_Dir . $sFeedSlug . DIRECTORY_SEPARATOR . 'template.phtml';
     }
 }
예제 #2
0
파일: Feed.php 프로젝트: tlandn/akvo-web
 public function makePreview($slug)
 {
     $oDaoJsonData = new \JsonData\Common\Model\Dao\JsonData();
     $aDetail = $oDaoJsonData->fetchFeedBySlug($slug);
     if ($aDetail) {
         $aParams = unserialize($aDetail['feed_parameters']);
         $sParams = '';
         foreach ($aParams as $k => $v) {
             $sParams .= ' ' . $k . '="' . $v . '"';
         }
         $sShortcode = '[jsondata_feed slug="' . $slug . '"' . $sParams . ']';
         $args = array('post_type' => 'jdata', 'post_status' => 'draft', 'name' => 'jsondata-' . $slug);
         $the_query = new \WP_Query($args);
         $aPosts = $the_query->get_posts();
         // Post object
         $my_post = array('post_title' => 'JSON data preview ' . $slug, 'post_name' => 'jsondata-' . $slug, 'post_content' => $sShortcode, 'post_status' => 'draft', 'post_type' => 'jdata', 'post_author' => 1);
         if ($the_query->post_count === 0) {
             // Insert the post into the database
             $id = wp_insert_post($my_post);
         } else {
             $id = $aPosts[0]->ID;
             $my_post['ID'] = $id;
             wp_update_post($my_post);
         }
         wp_reset_postdata();
         //header('Location: '.  get_permalink($id));
         //            die();
     }
 }