Merge pull request #282 from DrudexSoftware/master

Random Images List & Modified Page Title
This commit is contained in:
Shish 2013-03-16 12:50:03 -07:00
commit 2e5a51bc8d
7 changed files with 160 additions and 60 deletions

View File

@ -24,6 +24,12 @@ class arrowkey_navigation extends Extension {
$next_url = make_http(make_link("post/list/".$pageinfo["next"]));
$this->add_arrowkeys_code($prev_url, $next_url);
}
// for random_list extension
else if ($event->page_matches("random")) {
$randomurl = make_http(make_link("random"));
$this->add_arrowkeys_code($randomurl, $randomurl);
}
}
# adds the javascript to the page with the given urls

View File

@ -1,33 +1,74 @@
<?php
/**
* Name: Custom HTML Headers
* Author: Drudex Software <support@drudexsoftware.com>
* Link: http://www.drudexsoftware.com
* License: GPLv2
* Description: Allows admins to set custom <head> content
* Documentation:
* When you go to board config you can find a block named Custom HTML Headers.
* In that block you can simply place any thing you can place within <head></head>
*
* This can be useful if you want to add website tracking code or other javascript.
* NOTE: Only use if you know what you're doing.
*
*/
class custom_html_headers extends Extension {
# Adds setup block for custom <head> content
public function onSetupBuilding(SetupBuildingEvent $event) {
$sb = new SetupBlock("Custom HTML Headers");
$sb->add_longtext_option("custom_html_headers",
"HTML Code to place within &lt;head&gt;&lt;/head&gt; on all pages<br>");
$event->panel->add_block($sb);
}
# Load Analytics tracking code on page request
public function onPageRequest(PageRequestEvent $event) {
global $config, $page;
$header = $config->get_string('custom_html_headers','');
if ($header!='') $page->add_html_header($header);
}
}
?>
<?php
/**
* Name: Custom HTML Headers
* Author: Drudex Software <support@drudexsoftware.com>
* Link: http://www.drudexsoftware.com
* License: GPLv2
* Description: Allows admins to modify & set custom &lt;head&gt; content
* Documentation:
* When you go to board config you can find a block named Custom HTML Headers.
* In that block you can simply place any thing you can place within &lt;head&gt;&lt;/head&gt;
*
* This can be useful if you want to add website tracking code or other javascript.
* NOTE: Only use if you know what you're doing.
*
* You can also add your website name as prefix or suffix to the title of each page on your website.
*/
class custom_html_headers extends Extension {
# Adds setup block for custom <head> content
public function onSetupBuilding(SetupBuildingEvent $event) {
global $config;
$sb = new SetupBlock("Custom HTML Headers");
// custom headers
$sb->add_longtext_option("custom_html_headers",
"HTML Code to place within &lt;head&gt;&lt;/head&gt; on all pages<br>");
// modified title
$sb->add_choice_option("sitename_in_title", array(
"none" => 0,
"as prefix" => 1,
"as suffix" => 2
), "<br>Add website name in title");
$event->panel->add_block($sb);
}
public function onInitExt(InitExtEvent $event) {
global $config;
$config->set_default_int("sitename_in_title", 0);
}
# Load Analytics tracking code on page request
public function onPageRequest(PageRequestEvent $event) {
$this->handle_custom_html_headers();
$this->handle_modified_page_title();
}
private function handle_custom_html_headers() {
global $config, $page;
$header = $config->get_string('custom_html_headers','');
if ($header!='') $page->add_html_header($header);
}
private function handle_modified_page_title() {
global $config, $page;
// get config values
$site_title = $config->get_string("title");
$sitename_in_title = $config->get_int("sitename_in_title");
// if feature is enabled & sitename isn't already in title
// (can occur on index & other pages)
if ($sitename_in_title != 0 && !strstr($page->title, $site_title))
{
if ($sitename_in_title == 1)
$page->title = "$site_title - $page->title"; // as prefix
else if ($sitename_in_title == 2)
$page->title = "$page->title - $site_title"; // as suffix
}
}
}
?>

View File

@ -11,23 +11,18 @@
class google_analytics extends Extension {
# Add analytics to config
public function onSetupBuilding(SetupBuildingEvent $event) {
global $config;
$sb = new SetupBlock("Google Analytics");
$sb->add_text_option("google_analytics_id", "Analytics ID: ");
$sb->add_label("<br>(eg. UA-xxxxxxxx-x)");
$event->panel->add_block($sb);
}
# Load Analytics tracking code on page request
public function onPageRequest(PageRequestEvent $event) {
global $config;
global $page;
global $config, $page;
$google_analytics_id = $config->get_string('google_analytics_id','');
if (stristr($google_analytics_id, "UA-"))
{
if (stristr($google_analytics_id, "UA-")) {
$page->add_html_header("<script type='text/javascript'>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '$google_analytics_id']);

68
ext/random_list/main.php Normal file
View File

@ -0,0 +1,68 @@
<?php
/*
* Name: Random List
* Author: Drudex Software <support@drudexsoftware.com>
* Link: http://www.drudexsoftware.com
* License: GPLv2
* Description: Allows displaying a page with random images
* Documentation:
* Random image list can be accessed through www.yoursite.com/random
* It is recommended that you create a link to this page so users know it exists.
*/
class RandomList extends Extension {
public function onPageRequest(PageRequestEvent $event) {
global $config, $page;
if($event->page_matches("random")) {
// set vars
$page->title = "Random Images";
$images_per_page = $config->get_int("random_images_list_count", 12);
$random_images = array();
$random_html = "<b>Refresh the page to view more images</b>
<div class='shm-image-list'>";
// generate random images
for ($i = 0; $i < $images_per_page; $i++)
array_push($random_images, Image::by_random());
// create html to display images
foreach ($random_images as $image)
$random_html .= $this->build_random_html($image);
// display it
$random_html .= "</div>";
$page->add_block(new Block("Random Images", $random_html));
}
}
public function onInitExt(InitExtEvent $event) {
global $config;
$config->set_default_int("random_images_list_count", 12);
}
public function onSetupBuilding(SetupBuildingEvent $event) {
$sb = new SetupBlock("Random Images List");
// custom headers
$sb->add_int_option("random_images_list_count",
"Amount of Random images to display ");
$event->panel->add_block($sb);
}
private function build_random_html(Image $image, $query=null) {
$i_id = int_escape($image->id);
$h_view_link = make_link("post/view/$i_id", $query);
$h_thumb_link = $image->get_thumb_link();
$h_tip = html_escape($image->get_tooltip());
$tsize = get_thumbnail_size($image->width, $image->height);
return "
<a href='$h_view_link' class='thumb shm-thumb' data-post-id='$i_id'>
<img id='thumb_$i_id' height='{$tsize[1]}' width='{$tsize[0]}' class='lazy' data-original='$h_thumb_link' src='/lib/static/grey.gif'><noscript>
<img id='thumb_$i_id' height='{$tsize[1]} width='{$tsize[0]} src='$h_thumb_link'></noscript></a>
";
}
}
?>

View File

@ -42,6 +42,8 @@ class SCoreWebReporter extends HtmlReporter {
}
function paintGroupEnd($name) {
global $page;
$matches = array();
if(preg_match("#ext/(.*)/test.php#", $name, $matches)) {
$name = $matches[1];

View File

@ -3,6 +3,7 @@
* Name: XML Sitemap
* Author: Sein Kraft <mail@seinkraft.info>
* Author: Drudex Software <support@drudexsoftware.com>
* Link: http://drudexsoftware.com
* License: GPLv2
* Description: Sitemap with caching & advanced priorities
* Documentation:
@ -118,21 +119,20 @@ class XMLSitemap extends Extension {
}
}
// sets sitemap with entries in the queue
// sets sitemap with entries in sitemap_queue
private function generate_display_sitemap()
{
global $page;
$page->set_mode("data");
$page->set_type("application/xml");
$xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?".">
<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">
$this->sitemap_queue
</urlset>";
// Generate new sitemap & display
file_put_contents($this->sitemap_filepath, $xml);
// Generate new sitemap
file_put_contents($this->sitemap_filepath, $xml);
$page->set_mode("data");
$page->set_type("application/xml");
$page->set_data($xml);
}
@ -154,11 +154,11 @@ class XMLSitemap extends Extension {
private function display_existing_sitemap()
{
global $page;
$xml = file_get_contents($this->sitemap_filepath);
$page->set_mode("data");
$page->set_type("application/xml");
$xml = file_get_contents($this->sitemap_filepath);
$page->set_data($xml);
}
}

View File

@ -5,17 +5,5 @@ class XMLSitemapTest extends ShimmieWebTestCase {
# PHP-level error messages
$this->get_page('sitemap.xml');
}
function testImage() {
$this->log_in_as_user();
$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx");
$this->log_out();
$this->get_page('sitemap.xml');
$this->log_in_as_admin();
$this->delete_image($image_id);
$this->log_out();
}
}
?>