Esempio n. 1
0
 public function editorWidget($aFormValues)
 {
     $aContent = array();
     $aContent['status'] = 'failed';
     $aContent['message'] = '';
     $aContent['isFormValid'] = false;
     $aFeedParameters = $aFormValues['textParam'];
     $oForm = new \JsonData\Admin\Form\FeedWidget(\JsonData\Admin\Form\FeedWidget::CONTEXT_SELECT_FEED, array(), array('feed_parameters' => $aFeedParameters));
     if ($oForm->isValid($aFormValues)) {
         $aContent['isFormValid'] = true;
         ksort($aFeedParameters);
         $aInsertData = array();
         $aInsertData['json_data_id'] = $aFormValues['hiddenFeedId'];
         $aInsertData['parameters'] = serialize($aFeedParameters);
         $aInsertData['last_update_time'] = date('Y-m-d H:i:s');
         $aInsertData['last_display_time'] = date('Y-m-d H:i:s');
         $oDaoJsonData = new \JsonData\Common\Model\Dao\JsonData();
         $mStatus = $oDaoJsonData->insertJsonDataQueue($aInsertData);
         if (is_int($mStatus)) {
             $aFeed = $oDaoJsonData->fetchFeed($aInsertData['json_data_id']);
             $oFeed = new JsonDataFeed();
             $oFeed->updateQueue($aInsertData['json_data_id'], $mStatus);
             $aContent['queue_id'] = $mStatus;
             $aContent['slug'] = $aFeed['feed_slug'];
             $aContent['status'] = 'success';
             $aContent['message'] = 'Data successfully saved to database';
         } else {
             $aContent['message'] = 'Failed to save data';
         }
     }
     return $aContent;
 }
Esempio n. 2
0
 public function form($instance)
 {
     $aQueueData = array();
     if (!empty($instance)) {
         $iQueueId = $instance['queue_id'];
         $oDaoJsonData = new \JsonData\Common\Model\Dao\JsonData();
         $aQueueData = $oDaoJsonData->fetchSingleFeedQueue($iQueueId);
         $iFeedDataId = $aQueueData['json_data_id'];
         $aSingleFeed = $oDaoJsonData->fetchFeed($iFeedDataId);
     }
     $oDaoParticipantRegistry = new JDDao\JsonData();
     $aFeedNames = $oDaoParticipantRegistry->getAllFeedNames();
     include JsonData_Plugin_Dir . '/src/Admin/View/scripts/widget/sidebar.phtml';
 }
Esempio n. 3
0
 public function getFeed()
 {
     $aContent = array('redirect' => false);
     $sRedirectUrl = menu_page_url(\JsonData\Admin\Controller\Home::MENU_SLUG, false);
     if (!isset($_GET['id'])) {
         $aContent['redirect'] = $sRedirectUrl;
         return $aContent;
     }
     $iId = (int) $_GET['id'];
     $oDaoFeed = new JDDao\JsonData();
     $aDetail = $oDaoFeed->fetchFeed($iId);
     if (is_null($aDetail)) {
         $aContent['redirect'] = $sRedirectUrl;
         return $aContent;
     }
     $aContent['detail'] = $aDetail;
     return $aContent;
 }
Esempio n. 4
0
 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';
     }
 }
Esempio n. 5
0
 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();
     }
 }
Esempio n. 6
0
 /**
  * remove unused queue
  * @param int $iFeedQueueId
  */
 private function _removeQueueFiles($iFeedQueueId)
 {
     $oDaoJsonData = new JsonDataDao();
     $aFeedQueue = $oDaoJsonData->fetchSingleFeedQueue($iFeedQueueId);
     $sDirName = $this->_sCacheDirName . DIRECTORY_SEPARATOR . $aFeedQueue['json_data_id'];
     unlink($sDirName . DIRECTORY_SEPARATOR . 'data-' . $iFeedQueueId . '.json');
     $oDaoJsonData->deleteFeedQueue($iFeedQueueId);
 }
Esempio n. 7
0
 public static function doUninstall()
 {
     $oDaoRegister = new Common\Model\Dao\JsonData();
     $oDaoRegister->deleteTable();
     //		delete_option(Config::OPTION_NAME_GOOGLE_MAPS_API_KEY);
     //		delete_option(Config::OPTION_NAME_GOOGLE_MAPS_DEFAULT_ZOOM_FACTOR);
     //		delete_option(Config::OPTION_NAME_GOOGLE_MAPS_DEFAULT_CENTER_POINT);
 }
Esempio n. 8
0
 public function remove()
 {
     $aContent = array();
     $aContent['redirect'] = JDConfig::getHomeRedirectUrl();
     if (!isset($_GET['id'])) {
     }
     $iId = $_GET['id'];
     $oDaoJsonData = new JsonDataDao();
     $aDetail = $oDaoJsonData->fetchFeed($iId);
     if (!empty($aDetail)) {
         $bStatus = $oDaoJsonData->deleteFeed($iId);
         if (is_int($bStatus)) {
             $aFeedQueues = $oDaoJsonData->fetchFeedQueue($iId);
             //get all feedques with same id
             $aToBeDeleteId = array();
             foreach ($aFeedQueues as $aFeedRaw) {
                 $aToBeDeleteId[] = $aFeedRaw['id'];
             }
             array_map(array(&$oDaoJsonData, 'deleteFeedQueue'), $aToBeDeleteId);
             //delete all feed associate with id
             $oFeed = new JsonDataFeed();
             $oFeed->removeFeedDir($aDetail['feed_slug']);
             //remove files and directory
         }
     }
     //        var_dump($bStatus);
     //        var_dump(JDConfig::getHomeRedirectUrl());
     //        die();
     if ($bStatus != false) {
         $aContent['redirect'] = JDConfig::getHomeRedirectUrl();
     }
     return $aContent;
 }
Esempio n. 9
0
 private function _getFeedNames()
 {
     $oDaoParticipantRegistry = new JDDao\JsonData();
     $aFeedNames = $oDaoParticipantRegistry->getAllFeedNames();
     return $aFeedNames;
 }