/**
* smarty wrapper to GeographLinks
*/
function smarty_function_geographlinks($input, $thumbs = false)
{
    return GeographLinks($input, $thumbs);
}
Example #2
0
function smarty_function_articletext($input)
{
    global $imageCredits, $smarty, $CONF;
    $output = preg_replace('/\\n(-{7,})\\n(.*?)\\n(-{7,})/es', "article_make_table('\$2')", str_replace("\r", '', $input));
    if ($CONF['CONTENT_HOST'] != $_SERVER['HTTP_HOST']) {
        $output = str_replace($CONF['CONTENT_HOST'], $_SERVER['HTTP_HOST'], $output);
    }
    $output = preg_replace('/\\!(\\[+)/e', 'str_repeat("¬",strlen("$1"))', $output);
    $output = str_replace(array('[b]', '[/b]', '[big]', '[/big]', '[small]', '[/small]', '[i]', '[/i]', '[h2]', '[/h2]', '[h3]', '[/h3]', '[h4]', '[/h4]', '[tt]', '[/tt]', '[float]', '[/float]', '[br/]', '[hr/]', '[reveal]', '[/reveal]'), array('<b>', '</b>', '<big>', '</big>', '<small>', '</small>', '<i>', '</i>', '<h2>', '</h2>', '<h3>', '</h3>', '<h4>', '</h4>', '<tt>', '</tt>', '<div style="float:left;padding-right:10px;padding-bottom:10px;position:relative">', '</div>', '<br style="clear:both"/>', '<hr align="center" width="75%"/>', '<span style="color:white">', '</span>'), $output);
    $pattern = array();
    $replacement = array();
    if (preg_match_all('/<h(\\d)>([^\\n]+?)<\\/h(\\d)>/', $output, $matches)) {
        $list = array();
        foreach ($matches[1] as $i => $level) {
            $list[] = "<li class=\"h{$level}\"><a href=\"#p{$i}\">{$matches[2][$i]}</a></li>";
            $pattern[] = '/<h(' . $level . ')>(' . preg_quote($matches[2][$i], '/') . ')<\\/h(' . $level . ')>/';
            $replacement[] = '<h$1><a name="p' . $i . '"></a>$2</h$3>';
        }
        $list = implode("\n", $list);
        $smarty->assign("tableContents", $list);
    }
    $pattern[] = '/<\\/h(\\d)>\\n(?!\\*)/';
    $replacement[] = '</h$1>';
    $pattern[] = '/(?<!["\'\\[\\/\\!\\w])([STNH]?[A-Z]{1}\\d{4,10}|[A-Z]{3}\\d{4,10})(?!["\'\\]\\/\\!\\w])/';
    $replacement[] = "<a href=\"http://{$_SERVER['HTTP_HOST']}/gridref/\\1\" target=\"_blank\">\\1</a>";
    $pattern[] = '/\\[image id=(\\d+) text=([^\\]]+)\\]/e';
    $replacement[] = "smarty_function_gridimage(array(id => '\$1',extra => '\$2'))";
    $pattern[] = '/(\\!)([STNH]?[A-Z]{1}\\d{4,10}|[A-Z]{3}\\d{4,10})(?!["\'\\]\\/\\!\\w])/';
    $replacement[] = "\\2";
    $pattern[] = '/\\[img=([^\\] ]+)(| [^\\]]+)\\]/';
    $replacement[] = '<img src="\\1" alt="\\2" title="\\2"/>';
    $pattern[] = '/\\[mooflow=(\\d+)\\]/';
    $replacement[] = '<iframe src="/search.php?i=\\1&amp;temp_displayclass=mooflow_embed" width="750" height="430"></iframe>';
    $pattern[] = '/\\n\\* ?([^\\n]+)(\\n{2})?/e';
    $replacement[] = "'<ul style=\"margin-bottom:0px;margin-top:0px\"><li>'.stripslashes('\$1').'</li></ul>'.('\$2'?'\n':'')";
    $pattern[] = '/<\\/ul>\\n?<ul style=\\"margin-bottom:0px;margin-top:0px\\">/';
    $replacement[] = '';
    //fix a bug where double spacing on a previous match would swallow the newline needed for the next
    $pattern[] = '/\\n\\n(<\\w{1,3}>)\\#/';
    $replacement[] = "\n\$1#";
    $pattern[] = '/\\n\\n\\#/';
    $replacement[] = "\n\r\n\$1#";
    $pattern[] = '/\\n(<\\w{1,3}>)?\\#([\\w]{1,2})? ([^\\n]+)(<\\/\\w{1,3}>)?(\\n{2})?/e';
    $replacement[] = "'<ol style=\"margin-bottom:0px;'.('\$1'?'':'margin-top:0px').'\"'.('\$2'?' start=\"\$2\"':'').'><li>\$1\$3\$4</li></ol>'.('\$5'?'\n':'')";
    $pattern[] = '/<\\/ol>\\n?<ol style=\\"margin-bottom:0px;margin-top:0px\\">/';
    $replacement[] = '';
    $pattern[] = "/\\[url[=]?\\](.+?)\\[\\/url\\]/i";
    $replacement[] = '\\1';
    $pattern[] = "/\\[url=((f|ht)tp[s]?:\\/\\/[^<> \n]+?)\\](.+?)\\[\\/url\\]/ie";
    $replacement[] = "smarty_function_external(array('href'=>\"\$1\",'text'=>'\$3','title'=>\"\$1\"))";
    $pattern[] = "/\n/";
    $replacement[] = "<br/>\n";
    $output = preg_replace($pattern, $replacement, $output);
    $output = GeographLinks($output, true);
    $pattern = array();
    $replacement = array();
    if (preg_match_all('/\\[(small|)map *([STNH]?[A-Z]{1}[ \\.]*\\d{2,5}[ \\.]*\\d{2,5}|[A-Z]{3}[ \\.]*\\d{2,5}[ \\.]*\\d{2,5})( \\w+|)\\]/', $output, $m)) {
        foreach ($m[0] as $i => $full) {
            //lets add an rastermap too
            $square = new Gridsquare();
            $square->setByFullGridRef($m[2][$i], true);
            $square->grid_reference_full = $m[2][$i];
            if (!empty($_GET['epoch'])) {
                $rastermap = new RasterMap($square, false, true, false, $_GET['epoch']);
            } elseif (!empty($m[3][$i])) {
                $rastermap = new RasterMap($square, false, true, false, trim($m[3][$i]));
            } else {
                $rastermap = new RasterMap($square, false);
            }
            if ($rastermap->service == 'OS50k') {
                if ($m[1][$i]) {
                    $rastermap->service = 'OS50k-small';
                    $rastermap->width = 125;
                }
                $pattern[] = "/" . preg_quote($full, '/') . "/";
                $replacement[] = $rastermap->getImageTag();
            }
        }
    }
    $output = preg_replace($pattern, $replacement, $output);
    $output = str_replace('¬', '[', $output);
    if (count($m[0])) {
        $smarty->assign("copyright", '<div class="copyright">Great Britain 1:50 000 Scale Colour Raster Mapping Extracts &copy; Crown copyright Ordnance Survey. All Rights Reserved. Educational licence 100045616.</div>');
    }
    if (count($imageCredits)) {
        arsort($imageCredits);
        $imageCreditsStr = implode(', ', array_keys($imageCredits));
        $imageCreditsStr = preg_replace('/, ([^,]+)$/', ' and $1', $imageCreditsStr);
        $smarty->assign("imageCredits", $imageCreditsStr);
    }
    return $output;
}
        list($wgs84_lat, $wgs84_long) = $conv->national_to_wgs84($entry['nateastings'], $entry['natnorthings'], $square->reference_index);
    } else {
        list($wgs84_lat, $wgs84_long) = $conv->internal_to_wgs84($square->x, $square->y, $square->reference_index);
    }
    $point = new kmlPoint($wgs84_lat, $wgs84_long);
    $placemark = new kmlPlacemark_Photo($entry['gridimage_id'], $square->grid_reference . ' :: ' . $title, $point);
    $placemark->useHoverStyle();
    $image = new GridImage();
    $image->fastInit($entry);
    $placemark->useCredit($image->realname, "http://{$_SERVER['HTTP_HOST']}/photo/" . $image->gridimage_id);
    $html .= getHtmlLinkP($placemark->link, $square->grid_reference . ' :: ' . $title . ' by ' . $image->realname);
    $linkTag = "<a href=\"" . $placemark->link . "\">";
    $details = $image->getThumbnail(120, 120, 2);
    $thumb = $details['server'] . $details['url'];
    $thumbTag = $details['html'];
    $description = $linkTag . $thumbTag . "</a><br/>" . GeographLinks($image->comment) . " (" . $linkTag . "view full size</a>)" . "<br/><br/> &copy; Copyright <a title=\"view user profile\" href=\"http://" . $_SERVER['HTTP_HOST'] . $image->profile_link . "\">" . $image->realname . "</a> and licensed for reuse under this <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/2.0/\">Creative Commons Licence</a><br/><br/>";
    $placemark->setItemCDATA('description', $description);
    //yes that is uppercase S!
    $placemark->setItemCDATA('Snippet', strip_tags($description));
    $placemark->useImageAsIcon($thumb);
    if (strlen($entry['view_direction']) && $entry['view_direction'] != -1) {
        $placemark->addViewDirection($entry['view_direction']);
    }
    $Region = $placemark->addChild('Region');
    $Region->setPoint($point, 0.01);
    $delta = $entry['gridimage_id'] % 30;
    $Region->setLod(1200 + $delta * $delta, -1);
    $Region->setFadeExtent(100, 0);
    $folder->addChild($placemark);
}
kmlPageFooter($kml, $square, $gr, 'centisquare.php', 7, $html);
Example #4
0
 //lets find some recent photos
 if ($CONF['template'] == 'ireland') {
     new RecentImageList($smarty, 2);
 } else {
     $smarty->assign('marker', $overview->getSquarePoint($potd->image->grid_square));
     new RecentImageList($smarty);
 }
 $db = NewADOConnection($GLOBALS['DSN']);
 if ($CONF['forums']) {
     //let's find recent posts in the announcements forum made by
     //administrators
     $sql = "select u.user_id,u.realname,t.topic_title,p.post_text,t.topic_id,t.topic_time, posts_count - 1 as comments \n\t\t\tfrom geobb_topics as t\n\t\t\tinner join geobb_posts as p on(t.topic_id=p.topic_id)\n\t\t\tinner join user as u on (p.poster_id=u.user_id)\n\t\t\twhere find_in_set('admin',u.rights)>0 and\n\t\t\tabs(unix_timestamp(t.topic_time) - unix_timestamp(p.post_time) ) < 10 and\n\t\t\tt.forum_id={$CONF['forum_announce']}\n\t\t\torder by t.topic_time desc limit 3";
     $news = $db->GetAll($sql);
     if ($news) {
         foreach ($news as $idx => $item) {
             $news[$idx]['post_text'] = str_replace('<br>', '<br/>', GeographLinks($news[$idx]['post_text'], true));
         }
     }
     $smarty->assign_by_ref('news', $news);
 }
 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
 $hectads = $db->getAll("select * from hectad_complete limit 5");
 $smarty->assign_by_ref('hectads', $hectads);
 $stats = $db->GetRow("select * from user_stat where user_id = 0");
 $stats += $db->GetRow("select count(*)-1 as users from user_stat");
 $stats += $db->cacheGetRow(3600, "select count(*) as total,sum(imagecount in (1,2,3)) as fewphotos from gridsquare where percent_land > 0");
 $stats['nophotos'] = $stats['total'] - $stats['squares'];
 $stats['percentage'] = $stats['squares'] / $stats['total'] * 100;
 //$stats['percentage'] = sprintf("%.2f",$stats['squares']/$stats['total']*100);
 $smarty->assign_by_ref('stats', $stats);
 $smarty->assign('rss_url', '/discuss/syndicator.php?forum=' . $CONF['forum_announce'] . '&amp;first=1');
Example #5
0
            //shame cant use dist_sqd in the next line!
            $sql_where .= " and ((gs.x - {$x}) * (gs.x - {$x}) + (gs.y - {$y}) * (gs.y - {$y})) < " . $d * $d;
        }
    }
    $sql = "SELECT *\nFROM `geobb_topics`\nINNER JOIN geobb_posts ON ({$sql_join})\n{$sql_where}\nORDER BY {$sql_order}\nLIMIT 30";
    $recordSet =& $db->Execute($sql);
    while (!$recordSet->EOF) {
        $item = new FeedItem();
        $item->title = $recordSet->fields['topic_title'];
        //htmlspecialchars is called on link so dont use &amp;
        $item->link = "http://{$_SERVER['HTTP_HOST']}/discuss/?action=vthread&topic={$recordSet->fields['topic_id']}";
        $description = preg_replace('/^<i>[^<]+<\\/i>([\\n\\r]*<br>)?([\\n\\r]*<br>)?([\\n\\r]*<br>)?/', '', $recordSet->fields['post_text']);
        if (strlen($description) > 160) {
            $description = substr($description, 0, 157) . "...";
        }
        $item->description = GeographLinks($description);
        $item->date = strtotime($recordSet->fields['post_time']);
        //$item->source = "http://{$_SERVER['HTTP_HOST']}/discuss/";
        $item->author = $recordSet->fields['poster_name'];
        if ($format == 'KML' || $format == 'GeoRSS' || $format == 'GPX') {
            $gridsquare = new GridSquare();
            $grid_ok = $gridsquare->setGridRef($recordSet->fields['topic_title']);
            if ($grid_ok) {
                list($item->lat, $item->long) = $conv->gridsquare_to_wgs84($gridsquare);
            }
        }
        $rss->addItem($item);
        $recordSet->MoveNext();
    }
}
customExpiresHeader(3600, true);
 function assignDiscussionToSmarty(&$smarty)
 {
     global $memcache;
     $mkey = $this->gridsquare_id;
     //fails quickly if not using memcached!
     $result =& $memcache->name_get('gsd', $mkey);
     if ($result) {
         $smarty->assign_by_ref('discuss', $result['topics']);
         $smarty->assign('totalcomments', $result['totalcomments']);
         return;
     }
     $db =& $this->_getDB();
     $sql = 'select t.topic_id,posts_count-1 as comments,CONCAT(\'Discussion on \',t.topic_title) as topic_title ' . 'from gridsquare_topic as gt ' . 'inner join geobb_topics as t using (topic_id)' . 'where ' . "gt.gridsquare_id = {$this->gridsquare_id} " . 'order by t.topic_time desc';
     $topics = $db->GetAll($sql);
     if ($topics) {
         $news = array();
         foreach ($topics as $idx => $topic) {
             $firstpost = $db->GetRow("select post_text,poster_name,post_time,poster_id from geobb_posts where topic_id={$topic['topic_id']} order by post_time limit 1");
             $topics[$idx]['post_text'] = GeographLinks(str_replace('<br>', '<br/>', $firstpost['post_text']));
             $topics[$idx]['realname'] = $firstpost['poster_name'];
             $topics[$idx]['user_id'] = $firstpost['poster_id'];
             $topics[$idx]['topic_time'] = $firstpost['post_time'];
             $totalcomments += $topics[$idx]['comments'] + 1;
         }
         $smarty->assign_by_ref('discuss', $topics);
         $smarty->assign('totalcomments', $totalcomments);
         $result = array();
         $result['topics'] = $topics;
         $result['totalcomments'] = $totalcomments;
         //fails quickly if not using memcached!
         $memcache->name_set('gsd', $mkey, $result, $memcache->compress, $memcache->period_short);
     }
 }
Example #7
0
 function handleUserTimeline()
 {
     $uid = intval($this->params[0]);
     $_GET['key'] = $this->params[1];
     $profile = new GeographUser($uid);
     if ($profile->realname) {
         header("Content-Type:text/xml");
         echo "<data>\n";
         $images = new ImageList();
         $images->getImagesByUser($uid, array('accepted', 'geograph'), 'RAND()', 200);
         foreach ($images->images as $i => $image) {
             if (!preg_match('/00(-|$)/', $image->imagetaken)) {
                 $bits = explode('-', $image->imagetaken);
                 $date = mktime(0, 0, 0, $bits[1], $bits[2], $bits[0]);
                 printf("\t<event start=\"%s\" title=\"%s\">%s &lt;b&gt;%s&lt;/b&gt;&lt;br/&gt; %s</event>\n", date('M d Y 00:00:00', $date) . ' GMT', htmlentities2($image->title), htmlentities("<a href=\"/photo/{$image->gridimage_id}\">" . $image->getThumbnail(120, 120) . "</a>"), $image->grid_reference, htmlentities2(GeographLinks($image->comment)));
             }
         }
         echo "</data>\n";
     } else {
         $this->error("Invalid User id {$uid}");
     }
 }