Exemplo n.º 1
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();
     }
 }
Exemplo n.º 2
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;
     }
 }
Exemplo n.º 3
0
 function outputArtist($row)
 {
     $artist_info = ApiBase::getArtistInfo($row['id']);
     $desc = '';
     $counter = 2;
     if (!empty($artist_info)) {
         foreach ($artist_info as $ai) {
             if ($ai['wiki']) {
                 $article = ApiBase::getArticleFromWikidata($ai['wiki'], $getUrl = false);
                 if ($article) {
                     #as wikidata is no guarantee of sv.wiki article (e.g. Finnish artist)
                     $desc .= "[[" . $article;
                     if ($article != $ai['name']) {
                         $desc .= "|" . $ai['name'];
                     }
                     $desc .= "]]";
                 } else {
                     $desc .= $ai['name'];
                 }
             } else {
                 $desc .= $ai['name'];
             }
             if (count($artist_info) >= $counter) {
                 $desc .= "\n| konstnär" . $counter . "    = ";
                 $counter++;
             }
         }
         #check if any un-tabled artists were missed
         if (count($artist_info) != count(explode(';', $row['artist']))) {
             $desc .= " <!--Some unlinked artists have been missed! please add these manually from: '" . $row['artist'] . "' -->";
         }
         return $desc;
     } elseif (!empty($row['artist'])) {
         $artistsList = explode(';', $row['artist']);
         foreach ($artistsList as $a) {
             $desc .= $a;
             if (count($artistsList) >= $counter) {
                 $desc .= "\n| konstnär" . $counter . "    = ";
                 $counter++;
             }
         }
         return $desc;
     }
 }