Example #1
0
 private function writeRowFull($row)
 {
     # rows to skip
     $skip = array('created', 'changed', 'ugc', 'year_cmt', 'cmt', 'owner', 'official_url');
     $row = $row['hit'];
     #Ignore rows without coords
     if (!empty($row['lat']) and !empty($row['lon'])) {
         $feature = array('type' => 'Feature', 'id' => $row['id'], 'geometry' => array('type' => 'Point', 'coordinates' => array((double) $row['lon'], (double) $row['lat'])));
         $handled = array('id', 'lat', 'lon');
         #Deal with properties
         $prop = array();
         #Spatial info
         array_push($handled, 'inside', 'address', 'county', 'muni', 'district', 'removed');
         $spatial = array('inside' => $row['inside'], 'address' => $row['address'], 'county' => 'SE-' . $row['county'], 'muni' => $row['muni'], 'district' => $row['district'], 'removed' => $row['removed']);
         $prop['spatial'] = $spatial;
         #image
         array_push($handled, 'image');
         if ($row['image']) {
             $prop['image'] = $row['image'];
             # thumb is not needed as it is just
             # "https://commons.wikimedia.org/w/thumb.php?f=" . $row['image'] . "&width=" . $size;
             # leaving it out allows size to be set by recipient
         } else {
             $prop['image'] = null;
         }
         #descriptions
         array_push($handled, 'descr', 'wiki', 'list');
         $desc_text = array('descr' => $row['descr'], 'wikidata' => !empty($row['wiki']) ? $row['wiki'] : null, 'ingress' => !empty($row['wiki']) ? ApiBase::getArticleIntro(ApiBase::getArticleFromWikidata($row['wiki'], $getUrl = false)) : null, 'list' => !empty($row['list']) ? $row['list'] : null);
         $prop['descriptions'] = $desc_text;
         #artists
         array_push($handled, 'artist');
         $artist = array();
         $artist_info = ApiBase::getArtistInfo($row['id']);
         if (!empty($artist_info)) {
             foreach ($artist_info as $ai) {
                 array_push($artist, array('wikidata' => !empty($ai['wiki']) ? $ai['wiki'] : null, 'name' => $ai['name']));
             }
         } elseif ($row['artist']) {
             $artistsList = explode(';', $row['artist']);
             foreach ($artistsList as $a) {
                 array_push($artist, array('name' => $a));
             }
         } else {
             $artist = null;
         }
         $prop['artist'] = $artist;
         #any remaining
         foreach ($row as $key => $value) {
             if (in_array($key, $handled)) {
                 continue;
             } else {
                 if (in_array($key, $skip)) {
                     continue;
                 } else {
                     $prop[$key] = $value;
                 }
             }
         }
         #store and return
         $feature['properties'] = $prop;
         return $feature;
     }
 }
Example #2
0
 private function writeRow(XMLWriter $xml, $row, $muni_names)
 {
     $row = $row['hit'];
     #Ignore rows without coords
     if (!empty($row['lat']) and !empty($row['lon'])) {
         $xml->startElement('Placemark');
         $placemarkId = $row['id'];
         $xml->writeAttribute('id', htmlspecialchars($placemarkId));
         if (!empty($row['title'])) {
             $xml->startElement('title');
             if ($row['removed'] == 1) {
                 $xml->text(htmlspecialchars($row['title'] . ' (borttagen)'));
             } else {
                 $xml->text(htmlspecialchars($row['title']));
             }
             $xml->endElement();
         }
         $xml->startElement('description');
         $desc = '';
         if (!empty($row['image'])) {
             #if inside & unfree show link otherwise show image
             if ($row['inside'] == 1 and $row['free'] == 'unfree') {
                 $showImage = 'Commons-icon.svg';
             } else {
                 $showImage = $row['image'];
             }
             $imgsize = 100;
             $desc .= '<a href="http://commons.wikimedia.org/wiki/File:' . rawurlencode($row['image']) . '" target="_blank">';
             $desc .= '<img src="' . ApiBase::getImageFromCommons($showImage, $imgsize) . '" align="right" />';
             $desc .= '</a>';
             $styleUrl = '#picStyle';
         } else {
             $styleUrl = '#noPicStyle';
         }
         $desc .= '<ul>';
         if (!empty($row['title'])) {
             $desc .= '<li> ';
             #title
             $desc .= '<b>' . htmlspecialchars($row['title']) . '</b>';
             $desc .= '</li>';
         }
         $desc .= '<li> ';
         #artist - year
         $artist_info = ApiBase::getArtistInfo($row['id']);
         if (!empty($artist_info)) {
             foreach ($artist_info as $ai) {
                 if ($ai['wiki']) {
                     #$desc .= '<a href="https://wikidata.org/wiki/' . rawurlencode($ai['wiki']) . '">';
                     $desc .= '<a href="' . ApiBase::getArticleFromWikidata($ai['wiki']) . '" target="_blank">';
                     $desc .= '' . htmlspecialchars($ai['name']);
                     $desc .= '</a>';
                 } else {
                     $desc .= '' . htmlspecialchars($ai['name']);
                 }
                 $desc .= ', ';
             }
             $desc = substr($desc, 0, -2);
             #remove trailing ","
             if (!empty($row['year'])) {
                 $desc .= ' - ' . htmlspecialchars($row['year']);
             }
         } elseif (!empty($row['artist'])) {
             $desc .= htmlspecialchars($row['artist']);
             if (!empty($row['year'])) {
                 $desc .= ' - ' . htmlspecialchars($row['year']);
             }
         } elseif (!empty($row['year'])) {
             $desc .= htmlspecialchars($row['year']);
         }
         $desc .= '</li><li> ';
         #Muni - address
         $desc .= htmlspecialchars($muni_names[$row['muni']]);
         if (!empty($row['district'])) {
             $desc .= ' (' . htmlspecialchars($row['district']) . ')';
         }
         if (!empty($row['address'])) {
             $desc .= ' - ' . htmlspecialchars($row['address']);
         }
         #Description
         if (!empty($row['wiki'])) {
             #get descrition from wikipage
             $desc .= '</li><br/><li>' . ApiBase::getArticleIntro(ApiBase::getArticleFromWikidata($row['wiki'], $getUrl = false));
             $desc .= '  <a href="' . ApiBase::getArticleFromWikidata($row['wiki']) . '" target="_blank">';
             $desc .= htmlspecialchars('Läs mer om konstverket på Wikipedia');
             $desc .= '</a>.';
         } else {
             if (!empty($row['descr'])) {
                 $desc .= '</li><br/><li>' . htmlspecialchars($row['descr']);
             }
         }
         $desc .= '</li></ul>';
         $xml->writeCData($desc);
         $xml->endElement();
         $xml->startElement('styleUrl');
         $xml->text($styleUrl);
         $xml->endElement();
         $xml->startElement('Point');
         $xml->startElement('coordinates');
         $xml->text($row['lon'] . ',' . $row['lat']);
         $xml->endElement();
         $xml->endElement();
         $xml->endElement();
     }
 }