Esempio n. 1
0
 public static function set_location_for_person(array $location, midcom_db_person $person)
 {
     if (!isset($location['latitude']) || !isset($location['longitude'])) {
         throw new InvalidArgumentException('No coordinates provided');
     }
     $log = new org_routamc_positioning_log_dba();
     $log->person = $person->id;
     $log->latitude = $location['latitude'];
     $log->longitude = $location['longitude'];
     if (isset($location['source'])) {
         $log->importer = $location['source'];
     }
     if (isset($location['accuracy'])) {
         $log->accuracy = $location['accuracy'];
     }
     return $log->create();
 }
Esempio n. 2
0
 function editPost($message)
 {
     $args = $this->_params_to_args($message);
     if (count($args) != 5) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Invalid arguments.');
     }
     if (!midcom::get('auth')->login($args[1], $args[2])) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Authentication failed.');
     }
     midcom::get('auth')->initialize();
     try {
         $article = new midcom_db_article($args[0]);
     } catch (midcom_error $e) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Article not found: ' . $e->getMessage());
     }
     if (!$this->_datamanager->autoset_storage($article)) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Failed to initialize DM2 for article: ' . midgard_connection::get_error_string());
     }
     foreach ($args[3] as $field => $value) {
         switch ($field) {
             case 'title':
                 $this->_datamanager->types['title']->value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
                 break;
             case 'mt_excerpt':
                 $this->_datamanager->types['abstract']->value = $value;
                 break;
             case 'description':
                 $this->_datamanager->types['content']->value = $value;
                 break;
             case 'link':
                 // TODO: We may have to bulletproof this a bit
                 $this->_datamanager->types['name']->value = str_replace('.html', '', basename($args[3]['link']));
                 break;
             case 'categories':
                 if (array_key_exists('categories', $this->_datamanager->types)) {
                     $this->_datamanager->types['categories']->selection = $value;
                     break;
                 }
             case 'http://www.georss.org/georss/':
                 if ($this->_positioning) {
                     foreach ($value as $feature => $val) {
                         switch ($feature) {
                             case 'point':
                                 $coordinates = explode(' ', $val);
                                 if (count($coordinates) != 2) {
                                     break;
                                 }
                                 $log = new org_routamc_positioning_log_dba();
                                 $log->date = $article->metadata->published;
                                 $log->latitude = (double) $coordinates[0];
                                 $log->longitude = (double) $coordinates[1];
                                 $log->accuracy = ORG_ROUTAMC_POSITIONING_ACCURACY_MANUAL;
                                 $log->create();
                                 break;
                         }
                         // TODO: Handle different relationshiptags as per http://georss.org/simple/
                     }
                 }
                 break;
         }
     }
     if (!$this->_datamanager->save()) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Failed to update article: ' . midgard_connection::get_error_string());
     }
     // TODO: Map the publish property to approval
     // Index the article
     $indexer = midcom::get('indexer');
     net_nehmer_blog_viewer::index($this->_datamanager, $indexer, $this->_content_topic);
     return new XML_RPC_Response(new XML_RPC_Value($article->guid, 'string'));
 }