/**
  * Publish an array of arrays as a CSV download
  * @param array[array] $data
  * @throws Exception
  */
 public static function PublishData($data)
 {
     # Check that the data is an array
     if (!is_array($data)) {
         throw new Exception('$data must be an array of arrays');
     }
     # Respond with HTTP headers that download this data is a file
     # and allow it to be cached for up to one hour
     header("Content-type: text/csv");
     header("Cache-Control: max-age=3600, public");
     header('Content-Disposition: attachment; filename="stoolball-england.csv"');
     # Use PHP function to get the CSV format right
     $outstream = fopen("php://output", 'w');
     # Add Unicode BOM to ensure correct encoding, but only needed locally as no problem on live,
     # but this causes one. http://www.24k.com.sg/blog-55.html
     if (SiteContext::IsDevelopment()) {
         fprintf($outstream, chr(0xef) . chr(0xbb) . chr(0xbf));
     }
     foreach ($data as $row) {
         fputcsv($outstream, $row, ',', '"');
     }
     fclose($outstream);
     exit;
 }
 public function GetDomain()
 {
     return SiteContext::IsDevelopment() ? 'stoolball.local' : 'www.stoolball.org.uk';
 }
 /**
  * Parses the device and token from an auto sign-in cookie
  * @param string $cookie_value
  * @return array
  */
 private function ParseAutoSignInCookie($cookie_value)
 {
     # In wp-settings.php WordPress runs add_magic_quotes() over every value in $_COOKIE.
     # Need to undo that otherwise it's not the value we put there.
     if (SiteContext::IsWordPress()) {
         $cookie_value = stripslashes($cookie_value);
     }
     $value = array();
     $separator = strpos($cookie_value, ';');
     if ($separator and strlen($cookie_value) > $separator + 1) {
         $value['device'] = (int) substr($cookie_value, 0, $separator);
         $value['token'] = substr($cookie_value, $separator + 1);
     }
     return $value;
 }
<?php

ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . '/../' . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . '/../classes/');
require_once 'data/mysql-connection.class.php';
require_once 'context/stoolball-settings.class.php';
require_once 'context/site-context.class.php';
require_once 'stoolball/match-manager.class.php';
require_once 'xhtml/html.class.php';
require_once "Zend/Feed.php";
# set up error handling, unless local and using xdebug
$settings = new StoolballSettings();
if (!SiteContext::IsDevelopment()) {
    require_once 'page/exception-manager.class.php';
    require_once 'page/email-exception-publisher.class.php';
    $errors = new ExceptionManager(array(new EmailExceptionPublisher($settings->GetTechnicalContactEmail())));
    # Use production settings recommended by
    # http://perishablepress.com/advanced-php-error-handling-via-htaccess/
    # Not possible to set in .htaccess because PHP is running as a CGI. This is the
    # next best thing.
    ini_set("display_startup_errors", "off");
    ini_set("display_errors", "off");
    ini_set("html_errors", "off");
    ini_set("log_errors", "on");
    ini_set("ignore_repeated_errors", "off");
    ini_set("ignore_repeated_source", "off");
    ini_set("report_memleaks", "on");
    ini_set("track_errors", "on");
    ini_set("docref_root", "0");
    ini_set("docref_ext", "0");
    ini_set("error_reporting", "-1");
    ini_set("log_errors_max_len", "0");
 /**
  * @return array
  * @param SiteContext $o_context
  * @param int $i_start_level
  * @desc Return first, previous, next and last categories in a section
  */
 function GetRelativeInSection($o_context, $i_start_level)
 {
     /* @var $o_current_category Category */
     /* @var $o_category Category */
     /* @var $o_next_category Category */
     /* @var $o_first_category Category */
     /* @var $o_last_category Category */
     $a_links = array();
     if ($o_context instanceof SiteContext and is_numeric($i_start_level)) {
         # get current category
         $o_current_category = $o_context->GetCurrent();
         # loop through all categories
         $i_total_categories = $this->GetCount();
         for ($i_count = 0; $i_count < $i_total_categories; $i_count++) {
             # match current category
             $o_category = $this->GetByIndex($i_count);
             if ($o_category->GetId() == $o_current_category->GetId()) {
                 # get prev link, if not section home
                 if ($o_category->GetHierarchyLevel() != $i_start_level) {
                     $a_links['prev'] = $this->GetByIndex($i_count - 1);
                 }
                 # get next link, if not new section
                 $o_next_category = $this->GetByIndex($i_count + 1);
                 if ($o_next_category->GetHierarchyLevel() > $i_start_level) {
                     $a_links['next'] = $o_next_category;
                 }
                 # get first link, unless this is first page
                 if ($o_category->GetHierarchyLevel() >= $i_start_level + 1) {
                     $i_first_count = $i_count;
                     $o_first_category = $this->GetByIndex($i_first_count);
                     while ($o_first_category->GetHierarchyLevel() >= $i_start_level) {
                         $a_links['first'] = $o_first_category;
                         if ($a_links['first']->GetId() == $o_category->GetParentId()) {
                             break;
                         }
                         $i_first_count--;
                         $o_first_category = $this->GetByIndex($i_first_count);
                     }
                 }
                 # get last link, if this isn't last
                 if ($o_next_category->GetHierarchyLevel() >= $i_start_level + 1) {
                     $i_last_count = $i_count;
                     # cater for section home page
                     if ($o_category->GetHierarchyLevel() == $i_start_level) {
                         $o_last_category = $this->GetByIndex($i_last_count + 1);
                         while ($o_last_category->GetParentId() == $o_category->GetId() or $o_last_category->GetHierarchyLevel() > $i_start_level + 1) {
                             $a_links['last'] = $this->GetByIndex($i_last_count);
                             $i_last_count++;
                             $o_last_category = $this->GetByIndex($i_last_count + 1);
                         }
                         $a_links['last'] = $this->GetByIndex($i_last_count);
                     } else {
                         $o_last_category = $this->GetByIndex($i_last_count);
                         while ($o_last_category->GetHierarchyLevel() > $i_start_level) {
                             $a_links['last'] = $o_last_category;
                             $i_last_count++;
                             $o_last_category = $this->GetByIndex($i_last_count);
                         }
                     }
                 }
                 break;
             }
         }
     }
     return $a_links;
 }
示例#6
0
#&5-Startdato
#6-Password
#Variable
require "lib/SiteGenerator/SiteGenerator.php";
require "lib/SiteContext.php";
require "Stier.php";
require "Html.php";
require "view.php";
//Program
$stier = new Stier();
$ind = Html::setPostOrGetVars($HTTP_POST_VARS, $HTTP_GET_VARS);
//Tjekker brugernavnet
$datafil = DataSource::createInstance($ind['username'], $stier);
$res = $datafil->hentFil();
$lib = new Html($ind, $res);
$siteContext = new SiteContext($lib, $stier, $ind, 'da');
if (!isset($ind['type'])) {
    if (isset($ind['username'])) {
        $username = $ind['username'];
    } else {
        $username = "";
    }
    $side = new HtmlSite($siteContext, "Glemt kodeord");
    $html = "<div class=forside>\n";
    $html .= "\t<form action='" . htmlentities(getenv("SCRIPT_NAME")) . "' method='POST'>\n";
    $html .= "\t\t<p><label>Brugernavn <input type='text' name='username' value='" . htmlentities($username) . "'/></label></p>\n";
    $html .= "\t\t<p><input type='submit' value='Send kodeord' /></p>\n";
    $html .= "\t\t<input type='hidden' name='type' value='mailpwd' />\n";
    $html .= "\t</form>\n";
    $html .= "\t<h2>Glemt brugernavn</h2>\n";
    $html .= "\t<p>Du kan let finde dit brugernavn:</p>\n";
 /**
  * Customise the display of posts as they are being rendered by the browser
  *
  * @param string $content
  * @return string
  */
 public function TheContent($content = '')
 {
     $searches = array();
     $replaces = array();
     # Use title as alt where there's a title and an empty alt attribute
     $searches[] = '/ title="([^"]+)"([^>]*) alt=""/';
     $replaces[] = '$2 alt="$1"';
     # Remove title where there's also a populated alt attribute
     $searches[] = '/ title="[^"]+"([^>]* alt="[^"]+")/';
     $replaces[] = '$1';
     # Remove link to original image, which has no navigation
     $searches[] = '/<a href="[^"]+.(jpg|gif|png|jpeg)"[^>]*>(<img [^>]*>)<\\/a>/';
     $replaces[] = '$2';
     # Strip these by providing no replacement text
     $searches[] = '/ title="[a-z0-9-]*"/';
     # remove meaningless title attributes containing filenames
     $replaces[] = '';
     $content = preg_replace($searches, $replaces, $content);
     $content = str_replace("http://www.stoolball.org.uk", "https://www.stoolball.org.uk", $content);
     if (is_home()) {
         # Take out and remember images
         $content = preg_replace_callback('/(<img[^>]*>)/', array($this, 'ExtractImage'), $content);
         $strip_these = array('/<h[0-9][^>]*>.*?<\\/h[0-9]>/', '/<p class="wp-caption-text">.*?<\\/p>/', '/<a[^>]* class="more-link[^>]*>.*?<\\/a>/', '/style="width: [0-9]+px;?"/', '/<div[^>]*><\\/div>/');
         $content = preg_replace($strip_these, '', $content);
         # Don't want home page to be too long, so cut off after first para
         $pos = strpos($content, '</p>');
         if ($pos) {
             $pos = $pos + 4;
             # length of </p>
             $content = substr($content, 0, $pos);
         }
         # If there were images, put the first one at the start of the text
         if (count($this->a_matches)) {
             # Remove unused class, width and height
             $image = preg_replace('/ (class|width|height)="[A-Za-z0-9-_ ]+"/', '', $this->a_matches[0]);
             # Try to isolate the src attribute and swop it for the corresponding thumbnail
             $pos = strpos($image, ' src="');
             if ($pos !== false) {
                 $pos = $pos + 6;
                 # move to start to attr value
                 $len = strpos($image, '"', $pos);
                 if ($len !== false) {
                     # Get path to image on server
                     $wordpress_image_folder = $this->settings->GetServerRoot();
                     if (SiteContext::IsDevelopment()) {
                         $wordpress_image_folder .= "../";
                     }
                     # on dev setup, WordPress image uploads are outside web root
                     require_once 'Zend/Uri.php';
                     $uri = Zend_Uri::factory(substr($image, $pos, $len - $pos));
                     /* @var $uri Zend_Uri_Http */
                     # Change it to the thumbnail path and see whether the thumbnail exists
                     $thumbnail = $wordpress_image_folder . $uri->getPath();
                     $pos = strrpos($thumbnail, '.');
                     if ($pos !== false) {
                         $thumbnail = substr($thumbnail, 0, $pos) . "-150x150" . substr($thumbnail, $pos);
                         if (file_exists($thumbnail)) {
                             # if it does exist, update the original image tag with the thumbnail suffix and size
                             # important to do all these checks because thumbnails don't exist for images smaller than 150px
                             $image = preg_replace('/\\.(jpg|jpeg|gif|png)"/', '-150x150.$1" width="150" height="150"', $image);
                         }
                     }
                 }
             }
             # Add image before content
             $content = $image . $content;
         }
     } else {
         # Increase image width by 10px (caption must be 100%, so space around image must be margin on inner element, not padding on this element)
         $content = preg_replace_callback('/class="wp-caption([A-Za-z0-9-_ ]*)" style="width: ([0-9]+)px;?"/', array($this, 'ReplaceImageWidth'), $content);
         # Add extra XHTML around photo captions as hook for CSS
         $content = preg_replace('/(<p class="wp-caption-text">[^<]*<\\/p>)/', '<div class="photoCaption">$1</div>', $content);
     }
     $protector = new EmailAddressProtector($this->settings);
     $content = $protector->ApplyEmailProtection($content, is_object(AuthenticationManager::GetUser()) and AuthenticationManager::GetUser()->IsSignedIn());
     return $content;
 }
    /**
     * Display an advert for something we sell
     */
    protected function BuySomething()
    {
        $spreadshirt = gmdate("U") % 10 > 0;
        if ($spreadshirt) {
            $folder = SiteContext::IsWordPress() ? ABSPATH : $_SERVER['DOCUMENT_ROOT'];
            // File downloaded from http://api.spreadshirt.net/api/v1/shops/629531/articles?limit=50
            $articles = simplexml_load_file($folder . "/spreadshirt.xml");
            $article = $articles->article[rand(0, 49)];
            echo '<div class="spreadshirt large">';
            #echo '<h2><img src="/images/christmas.gif" alt="Stoolball at Christmas" width="204" height="90" /></h2>';
            echo '<h2><img src="/images/gifts.gif" alt="Visit our stoolball gift shop" width="204" height="90" /></h2>';
            echo '<div class="spreadshirt-box">' . '<a href="https://shop.spreadshirt.co.uk/stoolball/-A' . Html::Encode($article['id']) . '">' . '<img src="' . Html::Encode($article->resources->resource->attributes("http://www.w3.org/1999/xlink")->href) . '" alt="' . Html::Encode($article->name) . '" width="159" height="159" />' . '<p>' . Html::Encode($article->name) . '</p>' . '<p class="price">&pound;' . Html::Encode(number_format((double) $article->price->vatIncluded, 2, '.', '')) . '</p>
			<p class="buy"><span>Buy it now</span></p></a></div></div>';
        } else {
            echo '<a class="promo large" href="/shop"><img alt="Bats &pound;39, Balls &pound;7, Wickets &pound;150, Scorebooks &pound;4. Buy yours now." width="185" height="214" src="' . $this->resource_root . '/images/equipment/bat-ad-' . rand(1, 2) . '.jpg" /></a>';
        }
    }