Move widget, templates, libraries and functions into includes directory

This commit is contained in:
Brian Miyaji
2014-03-25 00:53:11 +11:00
parent 6db3e82d66
commit 73f5a2468d
29 changed files with 98 additions and 239 deletions

View File

@@ -0,0 +1,427 @@
<?php
/**
* EOS v2.0
* https://github.com/jlawrence11/Classes
*
* Equation Operating System Classes
*
* Copyright 2005-2013, Jon Lawrence <jlawrence11@gmail.com>
* Licensed under LGPL 2.1 License
*/
/**
* Equation Operating System Classes.
*
* This class was created for the safe parsing of mathematical equations
* in PHP. There is a need for a way to successfully parse equations
* in PHP that do NOT require the use of `eval`. `eval` at its core
* opens the system using it to so many security vulnerabilities it is oft
* suggested /never/ to use it, and for good reason. This class set will
* successfully take an equation, parse it, and provide solutions to the
* developer. It is a safe way to evaluate expressions without putting
* the system at risk.
*
* 2013/04 UPDATE:
* - Moved to native class functions for PHP5
* - Removed deprecated `eregi` calls to `preg_match`
* - Updated to PHPDoc comment syntax
* - Added Exception throwing instead of silent exits
* - Added additional variable prefix of '$', '&' is still allowed as well
* - Fixed small implied multiplication problem
*
* TODO:
* - Add factorial support. (ie 5! = 120)
*
* @author Jon Lawrence <jlawrence11@gmail.com>
* @copyright Copyright <20>2005-2013, Jon Lawrence
* @license http://opensource.org/licenses/LGPL-2.1 LGPL 2.1 License
* @package EOS
* @version 2.0
*/
//The following are defines for thrown exceptions
/**
* No matching Open/Close pair
*/
define('EQEOS_E_NO_SET', 5500);
/**
* Division by 0
*/
define('EQEOS_E_DIV_ZERO', 5501);
/**
* No Equation
*/
define('EQEOS_E_NO_EQ', 5502);
/**
* No variable replacement available
*/
define('EQEOS_E_NO_VAR', 5503);
if(!defined('DEBUG'))
define('DEBUG', false);
/**
* Equation Operating System (EOS) Parser
*
* An EOS that can safely parse equations from unknown sources returning
* the calculated value of it. Can also handle solving equations with
* variables, if the variables are defined (useful for the Graph creation
* that the second and extended class in this file provides. {@see eqGraph})
* This class was created for PHP4 in 2005, updated to fully PHP5 in 2013.
*
* @author Jon Lawrence <jlawrence11@gmail.com>
* @copyright Copyright <20>2005-2013, Jon Lawrence
* @license http://opensource.org/licenses/LGPL-2.1 LGPL 2.1 License
* @package Math
* @subpackage EOS
* @version 2.0
*/
class eqEOS {
/**#@+
*Private variables
*/
private $postFix;
private $inFix;
/**#@-*/
/**#@+
* Protected variables
*/
//What are opening and closing selectors
protected $SEP = array('open' => array('(', '['), 'close' => array(')', ']'));
//Top presedence following operator - not in use
protected $SGL = array('!');
//Order of operations arrays follow
protected $ST = array('^');
protected $ST1 = array('/', '*', '%');
protected $ST2 = array('+', '-');
//Allowed functions
protected $FNC = array('sin', 'cos', 'tan', 'csc', 'sec', 'cot');
/**#@-*/
/**
* Construct method
*
* Will initiate the class. If variable given, will assign to
* internal variable to solve with this::solveIF() without needing
* additional input. Initializing with a variable is not suggested.
*
* @see eqEOS::solveIF()
* @param String $inFix Standard format equation
*/
public function __construct($inFix = null) {
$this->inFix = (isset($inFix)) ? $inFix : null;
$this->postFix = array();
}
/**
* Check Infix for opening closing pair matches.
*
* This function is meant to solely check to make sure every opening
* statement has a matching closing one, and throws an exception if
* it doesn't.
*
* @param String $infix Equation to check
* @throws Exception if malformed.
* @return Bool true if passes - throws an exception if not.
*/
private function checkInfix($infix) {
if(trim($infix) == "") {
throw new Exception("No Equation given", EQEOS_E_NO_EQ);
return false;
}
//Make sure we have the same number of '(' as we do ')'
// and the same # of '[' as we do ']'
if(substr_count($infix, '(') != substr_count($infix, ')')) {
throw new Exception("Mismatched parenthesis in '{$infix}'", EQEOS_E_NO_SET);
return false;
} elseif(substr_count($infix, '[') != substr_count($infix, ']')) {
throw new Exception("Mismatched brackets in '{$infix}'", EQEOS_E_NO_SET);
return false;
}
$this->inFix = $infix;
return true;
}
/**
* Infix to Postfix
*
* Converts an infix (standard) equation to postfix (RPN) notation.
* Sets the internal variable $this->postFix for the eqEOS::solvePF()
* function to use.
*
* @link http://en.wikipedia.org/wiki/Infix_notation Infix Notation
* @link http://en.wikipedia.org/wiki/Reverse_Polish_notation Reverse Polish Notation
* @param String $infix A standard notation equation
* @return Array Fully formed RPN Stack
*/
public function in2post($infix = null) {
// if an equation was not passed, use the one that was passed in the constructor
$infix = (isset($infix)) ? $infix : $this->inFix;
//check to make sure 'valid' equation
$this->checkInfix($infix);
$pf = array();
$ops = new phpStack();
$vars = new phpStack();
// remove all white-space
preg_replace("/\s/", "", $infix);
// Create postfix array index
$pfIndex = 0;
//what was the last character? (useful for decerning between a sign for negation and subtraction)
$lChar = '';
//loop through all the characters and start doing stuff ^^
for($i=0;$i<strlen($infix);$i++) {
// pull out 1 character from the string
$chr = substr($infix, $i, 1);
// if the character is numerical
if(preg_match('/[0-9.]/i', $chr)) {
// if the previous character was not a '-' or a number
if((!preg_match('/[0-9.]/i', $lChar) && ($lChar != "")) && (@$pf[$pfIndex]!="-"))
$pfIndex++; // increase the index so as not to overlap anything
// Add the number character to the array
@$pf[$pfIndex] .= $chr;
}
// If the character opens a set e.g. '(' or '['
elseif(in_array($chr, $this->SEP['open'])) {
// if the last character was a number, place an assumed '*' on the stack
if(preg_match('/[0-9.]/i', $lChar))
$ops->push('*');
$ops->push($chr);
}
// if the character closes a set e.g. ')' or ']'
elseif(in_array($chr, $this->SEP['close'])) {
// find what set it was i.e. matches ')' with '(' or ']' with '['
$key = array_search($chr, $this->SEP['close']);
// while the operator on the stack isn't the matching pair...pop it off
while($ops->peek() != $this->SEP['open'][$key]) {
$nchr = $ops->pop();
if($nchr)
$pf[++$pfIndex] = $nchr;
else {
throw new Exception("Error while searching for '". $this->SEP['open'][$key] ."' in '{$infix}'.", EQEOS_E_NO_SET);
return false;
}
}
$ops->pop();
}
// If a special operator that has precedence over everything else
elseif(in_array($chr, $this->ST)) {
$ops->push($chr);
$pfIndex++;
}
// Any other operator other than '+' and '-'
elseif(in_array($chr, $this->ST1)) {
while(in_array($ops->peek(), $this->ST1) || in_array($ops->peek(), $this->ST))
$pf[++$pfIndex] = $ops->pop();
$ops->push($chr);
$pfIndex++;
}
// if a '+' or '-'
elseif(in_array($chr, $this->ST2)) {
// if it is a '-' and the character before it was an operator or nothingness (e.g. it negates a number)
if((in_array($lChar, array_merge($this->ST1, $this->ST2, $this->ST, $this->SEP['open'])) || $lChar=="") && $chr=="-") {
// increase the index because there is no reason that it shouldn't..
$pfIndex++;
$pf[$pfIndex] = $chr;
}
// Otherwise it will function like a normal operator
else {
while(in_array($ops->peek(), array_merge($this->ST1, $this->ST2, $this->ST)))
$pf[++$pfIndex] = $ops->pop();
$ops->push($chr);
$pfIndex++;
}
}
// make sure we record this character to be refered to by the next one
$lChar = $chr;
}
// if there is anything on the stack after we are done...add it to the back of the RPN array
while(($tmp = $ops->pop()) !== false)
$pf[++$pfIndex] = $tmp;
// re-index the array at 0
$pf = array_values($pf);
// set the private variable for later use if needed
$this->postFix = $pf;
// return the RPN array in case developer wants to use it fro some insane reason (bug testing ;]
return $pf;
} //end function in2post
/**
* Solve Postfix (RPN)
*
* This function will solve a RPN array. Default action is to solve
* the RPN array stored in the class from eqEOS::in2post(), can take
* an array input to solve as well, though default action is prefered.
*
* @link http://en.wikipedia.org/wiki/Reverse_Polish_notation Postix Notation
* @param Array $pfArray RPN formatted array. Optional.
* @return Float Result of the operation.
*/
public function solvePF($pfArray = null) {
// if no RPN array is passed - use the one stored in the private var
$pf = (!is_array($pfArray)) ? $this->postFix : $pfArray;
// create our temporary function variables
$temp = array();
$tot = 0;
$hold = 0;
// Loop through each number/operator
for($i=0;$i<count($pf); $i++) {
// If the string isn't an operator, add it to the temp var as a holding place
if(!in_array($pf[$i], array_merge($this->ST, $this->ST1, $this->ST2))) {
$temp[$hold++] = $pf[$i];
}
// ...Otherwise perform the operator on the last two numbers
else {
switch ($pf[$i]) {
case '+':
$temp[$hold-2] = $temp[$hold-2] + $temp[$hold-1];
break;
case '-':
$temp[$hold-2] = $temp[$hold-2] - $temp[$hold-1];
break;
case '*':
$temp[$hold-2] = $temp[$hold-2] * $temp[$hold-1];
break;
case '/':
if($temp[$hold-1] == 0) {
throw new Exception("Division by 0 on: '{$temp[$hold-2]} / {$temp[$hold-1]}' in {$this->inFix}", EQEOS_E_DIV_ZERO);
return false;
}
$temp[$hold-2] = $temp[$hold-2] / $temp[$hold-1];
break;
case '^':
$temp[$hold-2] = pow($temp[$hold-2], $temp[$hold-1]);
break;
case '%':
if($temp[$hold-1] == 0) {
throw new Exception("Division by 0 on: '{$temp[$hold-2]} % {$temp[$hold-1]}' in {$this->inFix}", EQEOS_E_DIV_ZERO);
return false;
}
$temp[$hold-2] = bcmod($temp[$hold-2], $temp[$hold-1]);
break;
}
// Decrease the hold var to one above where the last number is
$hold = $hold-1;
}
}
// return the last number in the array
return $temp[$hold-1];
} //end function solvePF
/**
* Solve Infix (Standard) Notation Equation
*
* Will take a standard equation with optional variables and solve it. Variables
* must begin with '&' will expand to allow variables to begin with '$' (TODO)
* The variable array must be in the format of 'variable' => value. If
* variable array is scalar (ie 5), all variables will be replaced with it.
*
* @param String $infix Standard Equation to solve
* @param String|Array $vArray Variable replacement
* @return Float Solved equation
*/
function solveIF($infix, $vArray = null) {
$infix = ($infix != "") ? $infix : $this->inFix;
//Check to make sure a 'valid' expression
$this->checkInfix($infix);
$ops = new phpStack();
$vars = new phpStack();
//remove all white-space
preg_replace("/\s/", "", $infix);
//Find all the variables that were passed and replaces them
while((preg_match('/(.){0,1}[&$]([a-zA-Z]+)(.){0,1}/', $infix, $match)) != 0) {
//remove notices by defining if undefined.
if(!isset($match[3])) {
$match[3] = "";
}
// Ensure that the variable has an operator or something of that sort in front and back - if it doesn't, add an implied '*'
if((!in_array($match[1], array_merge($this->ST, $this->ST1, $this->ST2, $this->SEP['open'])) && $match[1] != "") || is_numeric($match[1])) //$this->SEP['close'] removed
$front = "*";
else
$front = "";
if((!in_array($match[3], array_merge($this->ST, $this->ST1, $this->ST2, $this->SEP['close'])) && $match[3] != "") || is_numeric($match[3])) //$this->SEP['open'] removed
$back = "*";
else
$back = "";
//Make sure that the variable does have a replacement
if(!isset($vArray[$match[2]]) && (!is_array($vArray != "") && !is_numeric($vArray))) {
throw new Exception("Variable replacement does not exist for '". substr($match[0], 1, -1) ."' in {$this->inFix}", EQEOS_E_NO_VAR);
return false;
} elseif(!isset($vArray[$match[2]]) && (!is_array($vArray != "") && is_numeric($vArray))) {
$infix = str_replace($match[0], $match[1] . $front. $vArray. $back . $match[3], $infix);
} elseif(isset($vArray[$match[2]])) {
$infix = str_replace($match[0], $match[1] . $front. $vArray[$match[2]]. $back . $match[3], $infix);
}
}
// Finds all the 'functions' within the equation and calculates them
// NOTE - when using function, only 1 set of paranthesis will be found, instead use brackets for sets within functions!!
while((preg_match("/(". implode("|", $this->FNC) . ")\(([^\)\(]*(\([^\)]*\)[^\(\)]*)*[^\)\(]*)\)/", $infix, $match)) != 0) {
$func = $this->solveIF($match[2]);
switch($match[1]) {
case "cos":
$ans = cos($func);
break;
case "sin":
$ans = sin($func);
break;
case "tan":
$ans = tan($func);
break;
case "sec":
$tmp = cos($func);
if($tmp == 0) {
throw new Exception("Division by 0 on: 'sec({$func}) = 1/cos({$func})' in {$this->inFix}", EQEOS_E_DIV_ZERO);
return false;
}
$ans = 1/$tmp;
break;
case "csc":
$tmp = sin($func);
if($tmp == 0) {
throw new Exception("Division by 0 on: 'csc({$func}) = 1/sin({$func})' in {$this->inFix}", EQEOS_E_DIV_ZERO);
return false;
}
$ans = 1/$tmp;
break;
case "cot":
$tmp = tan($func);
if($tmp == 0) {
throw new Exception("Division by 0 on: 'cot({$func}) = 1/tan({$func})' in {$this->inFix}", EQEOS_E_DIV_ZERO);
return false;
}
$ans = 1/$tmp;
break;
default:
break;
}
$infix = str_replace($match[0], $ans, $infix);
}
return $this->solvePF($this->in2post($infix));
} //end function solveIF
} //end class 'eqEOS'
?>

View File

@@ -0,0 +1,113 @@
<?php
/**
* Basic Stack Class
*
* Created for use with eqEOS. May eventually be replaced with native
* PHP functions `array_pop()`, `array_push()`, and `end()`
*
* @author Jon Lawrence <jlawrence11@gmail.com>
* @copyright Copyright <20>2005-2013 Jon Lawrence
* @license http://opensource.org/licenses/LGPL-2.1 LGPL 2.1 License
* @package eos.class.php
* @version 2.0
*/
class phpStack {
private $index;
private $locArray;
/**
* Constructor
*
* Initializes the stack
*/
public function __construct() {
//define the private vars
$this->locArray = array();
$this->index = -1;
}
/**
* Peek
*
* Will view the last element of the stack without removing it
*
* @return Mixed An element of the array or false if none exist
*/
public function peek() {
if($this->index > -1)
return $this->locArray[$this->index];
else
return false;
}
/**
* Poke
*
* Will add an element to the end of the stack
*
* @param Mixed Element to add
*/
public function poke($data) {
$this->locArray[++$this->index] = $data;
}
/**
* Push
*
* Alias of {@see phpStack::poke()}
* Adds element to the stack
*
* @param Mixed Element to add
*/
public function push($data) {
//allias for 'poke'
$this->poke($data);
}
/**
* Pop
*
* Retrives an element from the end of the stack, and removes it from
* the stack at the same time. If no elements, returns boolean false
*
* @return Mixed Element at end of stack or false if none exist
*/
public function pop() {
if($this->index > -1)
{
$this->index--;
return $this->locArray[$this->index+1];
}
else
return false;
}
/**
* Clear
*
* Clears the stack to be reused.
*/
public function clear() {
$this->index = -1;
$this->locArray = array();
}
/**
* Get Stack
*
* Returns the array of stack elements, keeping all, indexed at 0
*
* @return Mixed Array of stack elements or false if none exist.
*/
public function getStack() {
if($this->index > -1)
{
return array_values($this->locArray);
}
else
return false;
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
sp-template-functions.php

View File

@@ -0,0 +1,65 @@
<?php
if ( !function_exists( 'sportspress_countdown' ) ) {
function sportspress_countdown( $id = null, $args = array() ) {
$show_league = sportspress_array_value( $args, 'show_league', null );
if ( $id ):
$post = get_post( $id );
else:
$args = array();
if ( isset( $args['team'] ) )
$args = array( 'key' => 'sp_team', 'value' => $args['team'] );
$post = sportspress_get_next_event( $args );
endif;
$output = '';
if ( isset( $post ) ):
$output .= '<div id="sp-countdown-wrapper">';
$output .= '<h3 class="event-name"><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h3>';
if ( $show_league ):
$leagues = get_the_terms( $post->ID, 'sp_league' );
if ( $leagues ):
foreach( $leagues as $league ):
$term = get_term( $league->term_id, 'sp_league' );
$output .= '<h5 class="event-league">' . $term->name . '</h5>';
endforeach;
endif;
endif;
$now = new DateTime( current_time( 'mysql', 0 ) );
$date = new DateTime( $post->post_date );
$interval = date_diff( $now, $date );
$output .= '<p class="countdown sp-countdown"><time datetime="' . $post->post_date . '" data-countdown="' . str_replace( '-', '/', $post->post_date ) . '">' .
'<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->days ) ) . ' <small>' . __( 'days', 'sportspress' ) . '</small></span> ' .
'<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->h ) ) . ' <small>' . __( 'hrs', 'sportspress' ) . '</small></span> ' .
'<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->i ) ) . ' <small>' . __( 'mins', 'sportspress' ) . '</small></span> ' .
'<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->s ) ) . ' <small>' . __( 'secs', 'sportspress' ) . '</small></span>' .
'</time></p>';
$output .= '</div>';
else:
return false;
endif;
return apply_filters( 'sportspress_countdown', $output );
}
}
function sportspress_countdown_shortcode( $atts ) {
if ( isset( $atts['id'] ) ):
$id = $atts['id'];
unset( $atts['id'] );
elseif( isset( $atts[0] ) ):
$id = $atts[0];
unset( $atts[0] );
else:
$id = null;
endif;
return sportspress_countdown( $id, $atts );
}
add_shortcode('countdown', 'sportspress_countdown_shortcode');

View File

@@ -0,0 +1,222 @@
<?php
if ( !function_exists( 'sportspress_event_calendar' ) ) {
function sportspress_event_calendar( $id = null, $initial = true, $args = array() ) {
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
// Quick check. If we have no posts at all, abort!
if ( ! $posts )
return;
$defaults = array(
'caption_tag' => 'h4',
'show_all_events_link' => false,
);
$r = wp_parse_args( $args, $defaults );
if ( $id ):
$events = sportspress_get_calendar_data( $id );
$event_ids = array();
foreach ( $events as $event ):
$event_ids[] = $event->ID;
endforeach;
$in = 'AND ID IN (' . implode( ', ', $event_ids ) . ')';
else:
$in = '';
endif;
$caption_tag = $r['caption_tag'];
// week_begins = 0 stands for Sunday
$week_begins = intval(get_option('start_of_week'));
// Get year and month from query vars
$year = isset( $_GET['sp_year'] ) ? $_GET['sp_year'] : $year;
$monthnum = isset( $_GET['sp_month'] ) ? $_GET['sp_month'] : $monthnum;
// Let's figure out when we are
if ( !empty($monthnum) && !empty($year) ) {
$thismonth = ''.zeroise(intval($monthnum), 2);
$thisyear = ''.intval($year);
} elseif ( !empty($w) ) {
// We need to get the month from MySQL
$thisyear = ''.intval(substr($m, 0, 4));
$d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
$thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
} elseif ( !empty($m) ) {
$thisyear = ''.intval(substr($m, 0, 4));
if ( strlen($m) < 6 )
$thismonth = '01';
else
$thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
} else {
$thisyear = gmdate('Y', current_time('timestamp'));
$thismonth = gmdate('m', current_time('timestamp'));
}
$unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
$last_day = date('t', $unixmonth);
// Get the next and previous month and year with at least one post
$previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
FROM $wpdb->posts
WHERE post_date < '$thisyear-$thismonth-01'
AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' )
$in
ORDER BY post_date DESC
LIMIT 1");
$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
FROM $wpdb->posts
WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' )
$in
ORDER BY post_date ASC
LIMIT 1");
/* translators: Calendar caption: 1: month name, 2: 4-digit year */
$calendar_caption = _x('%1$s %2$s', 'calendar caption', 'sportspress');
$calendar_output = '
<div class="sp-calendar-wrapper">
<table id="wp-calendar" class="sp-calendar sp-event-calendar">
<' . $caption_tag . ' class="sp-table-caption">' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</' . $caption_tag . '>
<thead>
<tr>';
$myweek = array();
for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
$myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
}
foreach ( $myweek as $wd ) {
$day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
$wd = esc_attr($wd);
$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
}
$calendar_output .= '
</tr>
</thead>
<tfoot>
<tr>';
if ( $previous ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a data-tooltip data-options="disable_for_touch:true" class="has-tooltip tip-right" href="' . add_query_arg( array( 'sp_year' => $previous->year, 'sp_month' => $previous->month ) ) . '" title="' . esc_attr( sprintf(_x('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
}
$calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
if ( $next ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a data-tooltip data-options="disable_for_touch:true" class="has-tooltip tip-left" href="' . add_query_arg( array( 'sp_year' => $next->year, 'sp_month' => $next->month ) ) . '" title="' . esc_attr( sprintf(_x('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
}
$calendar_output .= '
</tr>
</tfoot>
<tbody>
<tr>';
// Get days with posts
$dayswithposts = $wpdb->get_results("SELECT DAYOFMONTH(post_date), ID
FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' )
$in
AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
if ( $dayswithposts ) {
foreach ( (array) $dayswithposts as $daywith ) {
$daywithpost[ $daywith[0] ][] = $daywith[1];
}
} else {
$daywithpost = array();
}
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
$ak_title_separator = "\n";
else
$ak_title_separator = ', ';
$ak_titles_for_day = array();
$ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
."FROM $wpdb->posts "
."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
."AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' ) "
."$in"
);
if ( $ak_post_titles ) {
foreach ( (array) $ak_post_titles as $ak_post_title ) {
/** This filter is documented in wp-includes/post-template.php */
$post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
$ak_titles_for_day['day_'.$ak_post_title->dom] = '';
if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
$ak_titles_for_day["$ak_post_title->dom"] = $post_title;
else
$ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
}
}
// See how much we should pad in the beginning
$pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
if ( 0 != $pad )
$calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
$daysinmonth = intval(date('t', $unixmonth));
for ( $day = 1; $day <= $daysinmonth; ++$day ) {
if ( isset($newrow) && $newrow )
$calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
$newrow = false;
if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
$calendar_output .= '<td id="today">';
else
$calendar_output .= '<td>';
if ( array_key_exists($day, $daywithpost) ) // any posts today?
$calendar_output .= '<a data-tooltip data-options="disable_for_touch:true" class="has-tip" href="' . ( sizeof( $daywithpost[ $day ] ) > 1 ? add_query_arg( array( 'post_type' => 'sp_event' ), get_day_link( $thisyear, $thismonth, $day ) ) . '" title="' . sprintf( '%s events', ( sizeof( $daywithpost[ $day ] ) ) ) : get_permalink( $daywithpost[ $day ][0] ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) ) . "\">$day</a>";
else
$calendar_output .= $day;
$calendar_output .= '</td>';
if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
$newrow = true;
}
$pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
if ( $pad != 0 && $pad != 7 )
$calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>\n\t</div>";
if ( $id && $r['show_all_events_link'] )
$calendar_output .= '<a class="sp-calendar-link" href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a>';
return apply_filters( 'sportspress_event_calendar', $calendar_output );
}
}
function sportspress_event_calendar_shortcode( $atts ) {
if ( isset( $atts['id'] ) ):
$id = $atts['id'];
unset( $atts['id'] );
elseif( isset( $atts[0] ) ):
$id = $atts[0];
unset( $atts[0] );
else:
$id = null;
endif;
$initial = isset( $atts['initial'] ) ? $atts['initial'] : true;
return sportspress_event_calendar( $id, $initial, $atts );
}
add_shortcode('event-calendar', 'sportspress_event_calendar_shortcode');
add_shortcode('events-calendar', 'sportspress_event_calendar_shortcode');

View File

@@ -0,0 +1,48 @@
<?php
if ( !function_exists( 'sportspress_event_details' ) ) {
function sportspress_event_details( $id = null ) {
if ( ! $id )
$id = get_the_ID();
$date = get_the_time( get_option('date_format'), $id );
$time = get_the_time( get_option('time_format'), $id );
$leagues = get_the_terms( $id, 'sp_league' );
$seasons = get_the_terms( $id, 'sp_season' );
$data = array( __( 'Date', 'sportspress' ) => $date, __( 'Time', 'sportspress' ) => $time );
if ( $leagues ):
$league = array_pop( $leagues );
$data[ __( 'League', 'sportspress' ) ] = $league->name;
endif;
if ( $seasons ):
$season = array_pop( $seasons );
$data[ __( 'Season', 'sportspress' ) ] = $season->name;
endif;
$output = '<h3>' . __( 'Details', 'sportspress' ) . '</h3>';
$output .= '<div class="sp-table-wrapper">' .
'<table class="sp-event-details sp-data-table"><tbody>';
$i = 0;
foreach( $data as $label => $value ):
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$output .= '<th>' . $label . '</th>';
$output .= '<td>' . $value . '</td>';
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody></table></div>';
return apply_filters( 'sportspress_event_details', $output );
}
}

View File

@@ -0,0 +1,142 @@
<?php
if ( !function_exists( 'sportspress_event_list' ) ) {
function sportspress_event_list( $id = null, $args = '' ) {
global $sportspress_options;
$main_result = sportspress_array_value( $sportspress_options, 'main_result', null );
$defaults = array(
'show_all_events_link' => false,
);
$r = wp_parse_args( $args, $defaults );
$output = '<div class="sp-table-wrapper">' .
'<table class="sp-event-list sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
list( $data, $usecolumns ) = sportspress_get_calendar_data( $id, true );
if ( isset( $r['columns'] ) )
$usecolumns = $r['columns'];
$output .= '<th class="column-date">' . __( 'Date', 'sportspress' ). '</th>';
if ( $usecolumns == null || in_array( 'event', $usecolumns ) )
$output .= '<th class="column-event">' . __( 'Event', 'sportspress' ). '</th>';
if ( $usecolumns == null || in_array( 'teams', $usecolumns ) )
$output .= '<th class="column-teams">' . __( 'Teams', 'sportspress' ). '</th>';
if ( $usecolumns == null || in_array( 'time', $usecolumns ) )
$output .= '<th class="column-time">' . __( 'Time', 'sportspress' ). '</th>';
if ( $usecolumns == null || in_array( 'article', $usecolumns ) )
$output .= '<th class="column-article">' . __( 'Article', 'sportspress' ). '</th>';
$output .= '</tr>' . '</thead>' . '<tbody>';
$i = 0;
foreach ( $data as $event ):
$teams = get_post_meta( $event->ID, 'sp_team' );
$results = get_post_meta( $event->ID, 'sp_results', true );
$video = get_post_meta( $event->ID, 'sp_video', true );
$output .= '<tr class="sp-row sp-post' . ( $i % 2 == 0 ? ' alternate' : '' ) . '">';
$output .= '<td class="column-date">' . get_post_time( get_option( 'date_format' ), false, $event ) . '</td>';
if ( $usecolumns == null || in_array( 'event', $usecolumns ) )
$output .= '<td class="column-event">' . $event->post_title . '</td>';
if ( $usecolumns == null || in_array( 'teams', $usecolumns ) ):
$output .= '<td class="column-teams">';
$teams = get_post_meta( $event->ID, 'sp_team', false );
if ( $teams ):
foreach ( $teams as $team ):
$name = get_the_title( $team );
if ( $name ):
$team_results = sportspress_array_value( $results, $team, null );
if ( $main_result ):
$team_result = sportspress_array_value( $team_results, $main_result, null );
else:
if ( is_array( $team_results ) ):
end( $team_results );
$team_result = prev( $team_results );
else:
$team_result = null;
endif;
endif;
$output .= $name;
if ( $team_result != null ):
$output .= ' (' . $team_result . ')';
endif;
$output .= '<br>';
endif;
endforeach;
else:
$output .= '&mdash;';
endif;
$output .= '</td>';
endif;
if ( $usecolumns == null || in_array( 'time', $usecolumns ) )
$output .= '<td class="column-time">' . get_post_time( get_option( 'time_format' ), false, $event ) . '</td>';
if ( $usecolumns == null || in_array( 'article', $usecolumns ) ):
$output .= '<td class="column-article">
<a href="' . get_permalink( $event->ID ) . '#sp_articlediv">';
if ( $video ):
$output .= '<div class="dashicons dashicons-video-alt"></div>';
elseif ( has_post_thumbnail( $event->ID ) ):
$output .= '<div class="dashicons dashicons-camera"></div>';
endif;
if ( $event->post_content !== null ):
if ( $event->post_status == 'publish' ):
$output .= __( 'Recap', 'sportspress' );
else:
$output .= __( 'Preview', 'sportspress' );
endif;
endif;
$output .= '</a>
</td>';
endif;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>' . '</table>';
if ( $id && $r['show_all_events_link'] )
$output .= '<a class="sp-calendar-link" href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a>';
$output .= '</div>';
return apply_filters( 'sportspress_event_list', $output );
}
}
function sportspress_event_list_shortcode( $atts ) {
if ( isset( $atts['id'] ) ):
$id = $atts['id'];
unset( $atts['id'] );
elseif( isset( $atts[0] ) ):
$id = $atts[0];
unset( $atts[0] );
else:
$id = null;
endif;
return sportspress_event_list( $id, $atts );
}
add_shortcode('event-list', 'sportspress_event_list_shortcode');
add_shortcode('events-list', 'sportspress_event_list_shortcode');

View File

@@ -0,0 +1,126 @@
<?php
if ( !function_exists( 'sportspress_event_performance' ) ) {
function sportspress_event_performance( $id = null ) {
global $sportspress_options;
if ( ! $id )
$id = get_the_ID();
$teams = (array)get_post_meta( $id, 'sp_team', false );
$staff = (array)get_post_meta( $id, 'sp_staff', false );
$stats = (array)get_post_meta( $id, 'sp_players', true );
$performance_labels = sportspress_get_var_labels( 'sp_performance' );
$link_posts = sportspress_array_value( $sportspress_options, 'event_performance_link_posts', true );
$sortable = sportspress_array_value( $sportspress_options, 'event_performance_sortable', true );
$responsive = sportspress_array_value( $sportspress_options, 'event_performance_responsive', true );
$output = '';
foreach( $teams as $key => $team_id ):
if ( ! $team_id ) continue;
$totals = array();
// Get results for players in the team
$players = sportspress_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key );
$data = sportspress_array_combine( $players, sportspress_array_value( $stats, $team_id, array() ) );
$output .= '<h3>' . get_the_title( $team_id ) . '</h3>';
$output .= '<div class="sp-table-wrapper">' .
'<table class="sp-event-performance sp-data-table' . ( $responsive ? ' sp-responsive-table' : '' ) . ( $sortable ? ' sp-sortable-table' : '' ) . '">' . '<thead>' . '<tr>';
$output .= '<th class="data-number">#</th>';
$output .= '<th class="data-number">' . __( 'Player', 'sportspress' ) . '</th>';
foreach( $performance_labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
$i = 0;
foreach( $data as $player_id => $row ):
if ( ! $player_id )
continue;
$name = get_the_title( $player_id );
if ( ! $name )
continue;
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$number = get_post_meta( $player_id, 'sp_number', true );
// Player number
$output .= '<td class="data-number">' . $number . '</td>';
if ( $link_posts ):
$permalink = get_post_permalink( $player_id );
$name = '<a href="' . $permalink . '">' . $name . '</a>';
endif;
$output .= '<td class="data-name">' . $name . '</td>';
foreach( $performance_labels as $key => $label ):
if ( $key == 'name' )
continue;
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = 0;
endif;
if ( ! array_key_exists( $key, $totals ) ):
$totals[ $key ] = 0;
endif;
$totals[ $key ] += $value;
$output .= '<td class="data-' . $key . '">' . $value . '</td>';
endforeach;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>';
if ( array_key_exists( 0, $data ) ):
$output .= '<tfoot><tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$number = get_post_meta( $player_id, 'sp_number', true );
// Player number
$output .= '<td class="data-number">&nbsp;</td>';
$output .= '<td class="data-name">' . __( 'Total', 'sportspress' ) . '</td>';
$row = $data[0];
foreach( $performance_labels as $key => $label ):
if ( $key == 'name' ):
continue;
endif;
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = sportspress_array_value( $totals, $key, 0 );
endif;
$output .= '<td class="data-' . $key . '">' . $value . '</td>';
endforeach;
$output .= '</tr></tfoot>';
endif;
$output .= '</table>' . '</div>';
endforeach;
return apply_filters( 'sportspress_event_performance', $output );
}
}

View File

@@ -0,0 +1,72 @@
<?php
if ( !function_exists( 'sportspress_event_results' ) ) {
function sportspress_event_results( $id = null ) {
if ( ! $id )
$id = get_the_ID();
$teams = (array)get_post_meta( $id, 'sp_team', false );
$results = array_filter( sportspress_array_combine( $teams, (array)get_post_meta( $id, 'sp_results', true ) ), 'array_filter' );
$result_labels = sportspress_get_var_labels( 'sp_result' );
$output = '';
// Initialize and check
$table_rows = '';
$i = 0;
if ( empty( $results ) )
return false;
foreach( $results as $team_id => $result ):
if ( sportspress_array_value( $result, 'outcome', '-1' ) != '-1' ):
unset( $result['outcome'] );
$table_rows .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$table_rows .= '<td class="data-name">' . get_the_title( $team_id ) . '</td>';
foreach( $result_labels as $key => $label ):
if ( $key == 'name' )
continue;
if ( array_key_exists( $key, $result ) && $result[ $key ] != '' ):
$value = $result[ $key ];
else:
$value = '&mdash;';
endif;
$table_rows .= '<td class="data-' . $key . '">' . $value . '</td>';
endforeach;
$table_rows .= '</tr>';
$i++;
endif;
endforeach;
if ( empty( $table_rows ) ):
return false;
else:
$output .= '<h3>' . __( 'Results', 'sportspress' ) . '</h3>';
$output .= '<div class="sp-table-wrapper">' .
'<table class="sp-event-results sp-data-table sp-responsive-table"><thead>' .
'<th class="data-name">' . __( 'Team', 'sportspress' ) . '</th>';
foreach( $result_labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
$output .= $table_rows;
$output .= '</tbody>' . '</table>' . '</div>';
endif;
return apply_filters( 'sportspress_event_results', $output );
}
}

View File

@@ -0,0 +1,14 @@
<?php
if ( !function_exists( 'sportspress_event_staff' ) ) {
function sportspress_event_staff( $id = null ) {
if ( ! $id )
$id = get_the_ID();
$staff = (array)get_post_meta( $id, 'sp_staff', false );
$output = '';
return apply_filters( 'sportspress_event_staff', $output );
}
}

View File

@@ -0,0 +1,34 @@
<?php
if ( !function_exists( 'sportspress_event_venue' ) ) {
function sportspress_event_venue( $id = null ) {
if ( ! $id )
$id = get_the_ID();
$venues = get_the_terms( $id, 'sp_venue' );
$output = '';
if ( ! $venues )
return $output;
foreach( $venues as $venue ):
$t_id = $venue->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$address = sportspress_array_value( $term_meta, 'sp_address', '' );
$latitude = sportspress_array_value( $term_meta, 'sp_latitude', 0 );
$longitude = sportspress_array_value( $term_meta, 'sp_longitude', 0 );
$output .= '<h3>' . __( 'Venue', 'sportspress' ) . '</h3>';
$output .= '<p><a href="' . get_term_link( $t_id, 'sp_venue' ) . '">' . $venue->name . '</a><br><small>' . $address . '</small></p>';
if ( $latitude != null && $longitude != null )
$output .= '<div class="sp-google-map" data-address="' . $address . '" data-latitude="' . $latitude . '" data-longitude="' . $longitude . '"></div>';
endforeach;
return apply_filters( 'sportspress_event_venue', $output );
}
}

View File

@@ -0,0 +1,114 @@
<?php
if ( !function_exists( 'sportspress_league_table' ) ) {
function sportspress_league_table( $id = null, $args = '' ) {
if ( ! $id || ! is_numeric( $id ) )
$id = get_the_ID();
global $sportspress_options;
$defaults = array(
'number' => -1,
'columns' => null,
'show_full_table_link' => false,
'show_team_logo' => sportspress_array_value( $sportspress_options, 'league_table_show_team_logo', false ),
'link_posts' => sportspress_array_value( $sportspress_options, 'league_table_link_posts', false ),
'sortable' => sportspress_array_value( $sportspress_options, 'league_table_sortable', true ),
'responsive' => sportspress_array_value( $sportspress_options, 'league_table_responsive', true ),
);
$r = wp_parse_args( $args, $defaults );
$output = '<div class="sp-table-wrapper">' .
'<table class="sp-league-table sp-data-table' . ( $r['responsive'] ? ' sp-responsive-table' : '' ) . ( $r['sortable'] ? ' sp-sortable-table' : '' ) . '">' . '<thead>' . '<tr>';
$data = sportspress_get_league_table_data( $id );
// The first row should be column labels
$labels = $data[0];
// Remove the first row to leave us with the actual data
unset( $data[0] );
$columns = sportspress_array_value( $r, 'columns', null );
if ( ! $columns )
$columns = get_post_meta( $id, 'sp_columns', true );
if ( ! is_array( $columns ) )
$columns = explode( ',', $columns );
$output .= '<th class="data-rank">' . __( 'Pos', 'sportspress' ) . '</th>';
foreach( $labels as $key => $label ):
if ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) )
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
$i = 0;
if ( is_int( $r['number'] ) && $r['number'] > 0 )
$limit = $r['number'];
foreach( $data as $team_id => $row ):
if ( isset( $limit ) && $i >= $limit ) continue;
$name = sportspress_array_value( $row, 'name', null );
if ( ! $name ) continue;
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
// Rank
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
if ( $r['show_team_logo'] )
$name = get_the_post_thumbnail( $team_id, 'sportspress-fit-icon', array( 'class' => 'team-logo' ) ) . ' ' . $name;
if ( $r['link_posts'] ):
$permalink = get_post_permalink( $team_id );
$name = '<a href="' . $permalink . '">' . $name . '</a>';
endif;
$output .= '<td class="data-name">' . $name . '</td>';
foreach( $labels as $key => $value ):
if ( $key == 'name' )
continue;
if ( ! is_array( $columns ) || in_array( $key, $columns ) )
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '&mdash;' ) . '</td>';
endforeach;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>' . '</table>';
if ( $r['show_full_table_link'] )
$output .= '<a class="sp-league-table-link" href="' . get_permalink( $id ) . '">' . __( 'View full table', 'sportspress' ) . '</a>';
$output .= '</div>';
return apply_filters( 'sportspress_league_table', $output, $id );
}
}
function sportspress_league_table_shortcode( $atts ) {
if ( isset( $atts['id'] ) ):
$id = $atts['id'];
unset( $atts['id'] );
elseif( isset( $atts[0] ) ):
$id = $atts[0];
unset( $atts[0] );
else:
$id = null;
endif;
return sportspress_league_table( $id, $atts );
}
add_shortcode('league-table', 'sportspress_league_table_shortcode');

View File

@@ -0,0 +1,151 @@
<?php
if ( !function_exists( 'sportspress_player_gallery' ) ) {
function sportspress_player_gallery( $id = null, $args = '' ) {
if ( ! $id )
$id = get_the_ID();
global $sportspress_options;
$defaults = array(
'number' => -1,
'orderby' => 'default',
'order' => 'ASC',
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'columns' => 3,
'size' => 'thumbnail',
'show_all_players_link' => false,
'show_names_on_hover' => sportspress_array_value( $sportspress_options, 'player_gallery_show_names_on_hover', true ),
);
$r = wp_parse_args( $args, $defaults );
$itemtag = tag_escape( $r['itemtag'] );
$captiontag = tag_escape( $r['captiontag'] );
$icontag = tag_escape( $r['icontag'] );
$valid_tags = wp_kses_allowed_html( 'post' );
if ( ! isset( $valid_tags[ $itemtag ] ) )
$itemtag = 'dl';
if ( ! isset( $valid_tags[ $captiontag ] ) )
$captiontag = 'dd';
if ( ! isset( $valid_tags[ $icontag ] ) )
$icontag = 'dt';
$columns = intval( $r['columns'] );
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
$size = $r[ 'size' ];
$float = is_rtl() ? 'right' : 'left';
$selector = 'sp-player-gallery-' . $id;
$data = sportspress_get_player_list_data( $id );
// The first row should be column labels
$labels = $data[0];
// Remove the first row to leave us with the actual data
unset( $data[0] );
$performance = sportspress_array_value( $r, 'performance', null );
if ( $r['orderby'] == 'default' ):
$r['orderby'] = get_post_meta( $id, 'sp_orderby', true );
$r['order'] = get_post_meta( $id, 'sp_order', true );
else:
global $sportspress_performance_priorities;
$sportspress_performance_priorities = array(
array(
'key' => $r['orderby'],
'order' => $r['order'],
),
);
uasort( $data, 'sportspress_sort_list_players' );
endif;
$gallery_style = $gallery_div = '';
if ( apply_filters( 'use_default_gallery_style', true ) )
$gallery_style = "
<style type='text/css'>
#{$selector} {
margin: auto;
}
#{$selector} .gallery-item {
float: {$float};
margin-top: 10px;
text-align: center;
width: {$itemwidth}%;
}
#{$selector} img {
border: 2px solid #cfcfcf;
}
#{$selector} .gallery-caption {
margin-left: 0;
}
/* see gallery_shortcode() in wp-includes/media.php */
</style>";
$size_class = sanitize_html_class( $size );
$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
$output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
$i = 0;
if ( is_int( $r['number'] ) && $r['number'] > 0 )
$limit = $r['number'];
foreach( $data as $player_id => $performance ):
if ( $r['show_names_on_hover'] ):
$caption = get_the_title( $player_id );
else:
$caption = null;
endif;
$thumbnail = get_the_post_thumbnail( $player_id, $size );
if ( $thumbnail ):
if ( isset( $limit ) && $i >= $limit ) continue;
$output .= "<{$itemtag} class='gallery-item'>";
$output .= "
<{$icontag} class='gallery-icon portrait'>"
. '<a href="' . get_permalink( $player_id ) . '">' . $thumbnail . '</a>'
. "</{$icontag}>";
if ( $captiontag && trim( $caption ) ) {
$output .= '<a href="' . get_permalink( $player_id ) . '">' . "
<{$captiontag} class='wp-caption-text gallery-caption'>
" . wptexturize($caption) . "
</{$captiontag}>" . '</a>';
}
$output .= "</{$itemtag}>";
if ( $columns > 0 && ++$i % $columns == 0 )
$output .= '<br style="clear: both" />';
endif;
endforeach;
$output .= "
<br style='clear: both;' />
</div>\n";
if ( $r['show_all_players_link'] )
$output .= '<a class="sp-player-list-link" href="' . get_permalink( $id ) . '">' . __( 'View all players', 'sportspress' ) . '</a>';
return apply_filters( 'sportspress_player_gallery', $output );
}
}
function sportspress_player_gallery_shortcode( $atts ) {
if ( isset( $atts['id'] ) ):
$id = $atts['id'];
unset( $atts['id'] );
elseif( isset( $atts[0] ) ):
$id = $atts[0];
unset( $atts[0] );
else:
$id = null;
endif;
return sportspress_player_gallery( $id, $atts );
}
add_shortcode('player-gallery', 'sportspress_player_gallery_shortcode');

View File

@@ -0,0 +1,54 @@
<?php
if ( !function_exists( 'sportspress_player_league_performance' ) ) {
function sportspress_player_league_performance( $league, $id = null ) {
if ( ! $league )
return false;
if ( ! $id )
$id = get_the_ID();
$data = sportspress_get_player_performance_data( $id, $league->term_id );
// The first row should be column labels
$labels = $data[0];
// Remove the first row to leave us with the actual data
unset( $data[0] );
// Skip if there are no rows in the table
if ( empty( $data ) )
return false;
$output = '<h4 class="sp-table-caption">' . $league->name . '</h4>' .
'<div class="sp-table-wrapper">' .
'<table class="sp-player-performance sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
foreach( $labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
$i = 0;
foreach( $data as $season_id => $row ):
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
foreach( $labels as $key => $value ):
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '&mdash;' ) . '</td>';
endforeach;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>' . '</table>' . '</div>';
return apply_filters( 'sportspress_player_league_performance', $output );
}
}

View File

@@ -0,0 +1,126 @@
<?php
if ( !function_exists( 'sportspress_player_list' ) ) {
function sportspress_player_list( $id = null, $args = '' ) {
if ( ! $id )
$id = get_the_ID();
global $sportspress_options;
$defaults = array(
'number' => -1,
'performance' => null,
'orderby' => 'default',
'order' => 'ASC',
'show_all_players_link' => false,
'link_posts' => sportspress_array_value( $sportspress_options, 'player_list_link_posts', true ),
'sortable' => sportspress_array_value( $sportspress_options, 'player_list_sortable', true ),
'responsive' => sportspress_array_value( $sportspress_options, 'player_list_responsive', true ),
);
$r = wp_parse_args( $args, $defaults );
$output = '<div class="sp-table-wrapper">' .
'<table class="sp-player-list sp-data-table' . ( $r['responsive'] ? ' sp-responsive-table' : '' ) . ( $r['sortable'] ? ' sp-sortable-table' : '' ) . '">' . '<thead>' . '<tr>';
$data = sportspress_get_player_list_data( $id );
// The first row should be column labels
$labels = $data[0];
// Remove the first row to leave us with the actual data
unset( $data[0] );
$performance = sportspress_array_value( $r, 'performance', null );
if ( $r['orderby'] == 'default' ):
$r['orderby'] = get_post_meta( $id, 'sp_orderby', true );
$r['order'] = get_post_meta( $id, 'sp_order', true );
else:
global $sportspress_performance_priorities;
$sportspress_performance_priorities = array(
array(
'key' => $r['orderby'],
'order' => $r['order'],
),
);
uasort( $data, 'sportspress_sort_list_players' );
endif;
if ( in_array( $r['orderby'], array( 'number', 'name' ) ) ):
$output .= '<th class="data-number">#</th>';
else:
$output .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>';
endif;
foreach( $labels as $key => $label ):
if ( ! is_array( $performance ) || $key == 'name' || in_array( $key, $performance ) )
$output .= '<th class="data-' . $key . '">'. $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
$i = 0;
if ( is_int( $r['number'] ) && $r['number'] > 0 )
$limit = $r['number'];
foreach( $data as $player_id => $row ):
if ( isset( $limit ) && $i >= $limit ) continue;
$name = sportspress_array_value( $row, 'name', null );
if ( ! $name ) continue;
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
// Rank or number
if ( isset( $r['orderby'] ) && $r['orderby'] != 'number' ):
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
else:
$number = get_post_meta( $player_id, 'sp_number', true );
$output .= '<td class="data-number">' . ( $number ? $number : '&nbsp;' ) . '</td>';
endif;
if ( $r['link_posts'] ):
$permalink = get_post_permalink( $player_id );
$name = '<a href="' . $permalink . '">' . $name . '</a>';
endif;
$output .= '<td class="data-name">' . $name . '</td>';
foreach( $labels as $key => $value ):
if ( $key == 'name' )
continue;
if ( ! is_array( $performance ) || in_array( $key, $performance ) )
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '&mdash;' ) . '</td>';
endforeach;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>' . '</table>' . '</div>';
if ( $r['show_all_players_link'] )
$output .= '<a class="sp-player-list-link" href="' . get_permalink( $id ) . '">' . __( 'View all players', 'sportspress' ) . '</a>';
return apply_filters( 'sportspress_player_list', $output );
}
}
function sportspress_player_list_shortcode( $atts ) {
if ( isset( $atts['id'] ) ):
$id = $atts['id'];
unset( $atts['id'] );
elseif( isset( $atts[0] ) ):
$id = $atts[0];
unset( $atts[0] );
else:
$id = null;
endif;
return sportspress_player_list( $id, $atts );
}
add_shortcode('player-list', 'sportspress_player_list_shortcode');

View File

@@ -0,0 +1,56 @@
<?php
if ( !function_exists( 'sportspress_player_metrics' ) ) {
function sportspress_player_metrics( $id = null, $args = '' ) {
if ( ! $id )
$id = get_the_ID();
global $sportspress_countries;
global $sportspress_options;
$defaults = array(
'show_nationality_flag' => sportspress_array_value( $sportspress_options, 'player_show_nationality_flag', true ),
);
$r = wp_parse_args( $args, $defaults );
$nationality = get_post_meta( $id, 'sp_nationality', true );
$current_team = get_post_meta( $id, 'sp_current_team', true );
$past_teams = get_post_meta( $id, 'sp_past_team', false );
$metrics = sportspress_get_player_metrics_data( $id );
$common = array();
if ( $nationality ):
$country_name = sportspress_array_value( $sportspress_countries, $nationality, null );
$common[ __( 'Nationality', 'sportspress' ) ] = $country_name ? ( $r['show_nationality_flag'] ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . '/assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '&mdash;';
endif;
$data = array_merge( $common, $metrics );
if ( $current_team )
$data[ __( 'Current Team', 'sportspress' ) ] = '<a href="' . get_post_permalink( $current_team ) . '">' . get_the_title( $current_team ) . '</a>';
if ( $past_teams ):
$teams = array();
foreach ( $past_teams as $team ):
$teams[] = '<a href="' . get_post_permalink( $team ) . '">' . get_the_title( $team ) . '</a>';
endforeach;
$data[ __( 'Past Teams', 'sportspress' ) ] = implode( ', ', $teams );
endif;
$output = '<div class="sp-list-wrapper">' .
'<dl class="sp-player-metrics">';
foreach( $data as $label => $value ):
$output .= '<dt>' . $label . '<dd>' . $value . '</dd>';
endforeach;
$output .= '</dl></div>';
return apply_filters( 'sportspress_player_metrics', $output );
}
}

View File

@@ -0,0 +1,22 @@
<?php
if ( !function_exists( 'sportspress_player_performance' ) ) {
function sportspress_player_performance( $id = null ) {
if ( ! $id )
$id = get_the_ID();
$leagues = get_the_terms( $id, 'sp_league' );
$output = '';
// Loop through performance for each league
if ( is_array( $leagues ) ):
foreach ( $leagues as $league ):
$output .= sportspress_player_league_performance( $league, $id );
endforeach;
endif;
return apply_filters( 'sportspress_player_performance', $output );
}
}

View File

@@ -0,0 +1,103 @@
<?php
if ( !function_exists( 'sportspress_player_roster' ) ) {
function sportspress_player_roster( $id = null, $args = '' ) {
if ( ! $id )
$id = get_the_ID();
$defaults = array(
'performance' => null,
'orderby' => 'default',
'order' => 'ASC',
);
$r = wp_parse_args( $args, $defaults );
$output = '';
$data = sportspress_get_player_roster_data( $id );
// The first row should be column labels
$labels = $data[0];
// Remove the first row to leave us with the actual data
unset( $data[0] );
$performance = sportspress_array_value( $r, 'performance', null );
if ( $r['orderby'] == 'default' ):
$r['orderby'] = get_post_meta( $id, 'sp_orderby', true );
$r['order'] = get_post_meta( $id, 'sp_order', true );
else:
global $sportspress_performance_priorities;
$sportspress_performance_priorities = array(
array(
'key' => $r['orderby'],
'order' => $r['order'],
),
);
uasort( $data, 'sportspress_sort_list_players' );
endif;
$positions = get_terms ( 'sp_position' );
foreach ( $positions as $position ):
$rows = '';
$i = 0;
foreach ( $data as $player_id => $row ):
if ( ! in_array( $position->term_id, $row['positions']) )
continue;
$rows .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
// Rank or number
if ( isset( $r['orderby'] ) && $r['orderby'] != 'number' ):
$rows .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
else:
$number = get_post_meta( $player_id, 'sp_number', true );
$rows .= '<td class="data-number">' . ( $number ? $number : '&nbsp;' ) . '</td>';
endif;
// Name as link
$permalink = get_post_permalink( $player_id );
$name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', '&nbsp;' ) );
$rows .= '<td class="data-name">' . '<a href="' . $permalink . '">' . $name . '</a></td>';
foreach( $labels as $key => $value ):
if ( $key == 'name' )
continue;
if ( ! is_array( $performance ) || in_array( $key, $performance ) )
$rows .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '&mdash;' ) . '</td>';
endforeach;
$rows .= '</tr>';
$i++;
endforeach;
if ( ! empty( $rows ) ):
$output .= '<h4 class="sp-table-caption">' . $position->name . '</h4>';
$output .= '<div class="sp-table-wrapper">' .
'<table class="sp-player-list sp-player-roster sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
if ( in_array( $r['orderby'], array( 'number', 'name' ) ) ):
$output .= '<th class="data-number">#</th>';
else:
$output .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>';
endif;
foreach( $labels as $key => $label ):
if ( ! is_array( $performance ) || $key == 'name' || in_array( $key, $performance ) )
$output .= '<th class="data-' . $key . '">'. $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>' . $rows . '</tbody>' . '</table>' . '</div>';
endif;
endforeach;
return apply_filters( 'sportspress_player_roster', $output );
}
}

View File

@@ -0,0 +1,63 @@
<?php
if ( !function_exists( 'sportspress_team_columns' ) ) {
function sportspress_team_columns( $id = null ) {
if ( ! $id )
$id = get_the_ID();
$leagues = get_the_terms( $id, 'sp_league' );
if ( ! $leagues )
return false;
$output = '';
// Loop through data for each league
foreach ( $leagues as $league ):
$data = sportspress_get_team_columns_data( $id, $league->term_id );
if ( sizeof( $data ) <= 1 )
continue;
// The first row should be column labels
$labels = $data[0];
// Remove the first row to leave us with the actual data
unset( $data[0] );
$output .= '<h4 class="sp-table-caption">' . $league->name . '</h4>' .
'<div class="sp-table-wrapper">' .
'<table class="sp-team-columns sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
foreach( $labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
$i = 0;
foreach( $data as $season_id => $row ):
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
foreach( $labels as $key => $value ):
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '&mdash;' ) . '</td>';
endforeach;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>' . '</table>' . '</div>';
endforeach;
return apply_filters( 'sportspress_team_columns', $output );
}
}

View File

@@ -0,0 +1,63 @@
<?php
class SP_Widget_Countdown extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_countdown widget_sp_countdown', 'description' => __( 'A clock that counts down to an upcoming event.', 'sportspress' ) );
parent::__construct('sp_countdown', __( 'SportsPress Countdown', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? null : $instance['title'], $instance, $this->id_base);
$id = empty($instance['id']) ? null : $instance['id'];
$show_league = empty($instance['show_league']) ? false : $instance['show_league'];
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo sportspress_countdown( $id, array( 'show_league' => $show_league ) );
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['event'] = intval($new_instance['event']);
$instance['show_league'] = intval($new_instance['show_league']);
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'event' => '', 'show_league' => false ) );
$title = strip_tags($instance['title']);
$event = intval($instance['event']);
$show_league = intval($instance['show_league']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('event'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Event', 'sportspress' ) ); ?></label>
<?php
$args = array(
'post_type' => 'sp_event',
'name' => $this->get_field_name('event'),
'id' => $this->get_field_id('event'),
'selected' => $event,
'show_option_all' => __( '(Auto)', 'sportspress' ),
'values' => 'ID',
'class' => 'widefat',
'show_dates' => true,
'post_status' => 'future',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_event', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_league'); ?>" name="<?php echo $this->get_field_name('show_league'); ?>" value="1" <?php checked( $show_league, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_league'); ?>"><?php _e( 'Display league', 'sportspress' ); ?></label></p>
<?php
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget( "SP_Widget_Countdown" );' ) );

View File

@@ -0,0 +1,63 @@
<?php
class SP_Widget_Event_Calendar extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_calendar widget_sp_event_calendar', 'description' => __( 'A calendar of events.', 'sportspress' ) );
parent::__construct('sp_event_calendar', __( 'SportsPress Events Calendar', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$id = empty($instance['id']) ? null : $instance['id'];
$show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link'];
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo '<div id="calendar_wrap">';
echo sportspress_event_calendar( $id, true, array( 'caption_tag' => 'caption', 'show_all_events_link' => $show_all_events_link ) );
echo '</div>';
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['id'] = intval($new_instance['id']);
$instance['show_all_events_link'] = $new_instance['show_all_events_link'];
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'show_all_events_link' => false ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
$show_all_events_link = $instance['show_all_events_link'];
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Calendar', 'sportspress' ) ); ?></label>
<?php
$args = array(
'post_type' => 'sp_calendar',
'show_option_all' => __( 'All', 'sportspress' ),
'name' => $this->get_field_name('id'),
'id' => $this->get_field_id('id'),
'selected' => $id,
'values' => 'ID',
'class' => 'sp-event-calendar-select widefat',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_calendar', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p class="sp-event-calendar-show-all-toggle<?php if ( ! $id ): ?> hidden<?php endif; ?>"><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_all_events_link'); ?>" name="<?php echo $this->get_field_name('show_all_events_link'); ?>" value="1" <?php checked( $show_all_events_link, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_all_events_link'); ?>"><?php _e( 'Display link to view all events', 'sportspress' ); ?></label></p>
<?php
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget( "SP_Widget_Event_Calendar" );' ) );

View File

@@ -0,0 +1,81 @@
<?php
class SP_Widget_Event_List extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_sp_event_list', 'description' => __( 'A list of events.', 'sportspress' ) );
parent::__construct('sp_event_list', __( 'SportsPress Events List', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$id = empty($instance['id']) ? null : $instance['id'];
$columns = empty($instance['columns']) ? null : $instance['columns'];
$show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link'];
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo sportspress_event_list( $id, array( 'columns' => $columns, 'show_all_events_link' => $show_all_events_link ) );
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['id'] = intval($new_instance['id']);
$instance['columns'] = (array)$new_instance['columns'];
$instance['show_all_events_link'] = $new_instance['show_all_events_link'];
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'columns' => null, 'show_all_events_link' => true ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
$columns = $instance['columns'];
$show_all_events_link = $instance['show_all_events_link'];
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Calendar', 'sportspress' ) ); ?></label>
<?php
$args = array(
'post_type' => 'sp_calendar',
'show_option_all' => __( 'All', 'sportspress' ),
'name' => $this->get_field_name('id'),
'id' => $this->get_field_id('id'),
'selected' => $id,
'values' => 'ID',
'class' => 'sp-event-calendar-select widefat',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_calendar', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p class="sp-prefs">
<?php _e( 'Columns:', 'sportspress' ); ?><br>
<?php
$the_columns = array(
'event' => __( 'Event', 'sportspress' ),
'teams' => __( 'Teams', 'sportspress' ),
'time' => __( 'Time', 'sportspress' ),
'article' => __( 'Article', 'sportspress' ),
);
$field_name = $this->get_field_name('columns') . '[]';
$field_id = $this->get_field_id('columns');
?>
<?php foreach ( $the_columns as $key => $label ): ?>
<label class="button"><input name="<?php echo $field_name; ?>" type="checkbox" id="<?php echo $field_id . '-' . $key; ?>" value="<?php echo $key; ?>" <?php if ( $columns === null || in_array( $key, $columns ) ): ?>checked="checked"<?php endif; ?>><?php echo $label; ?></label>
<?php endforeach; ?>
</p>
<p class="sp-event-calendar-show-all-toggle<?php if ( ! $id ): ?> hidden<?php endif; ?>"><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_all_events_link'); ?>" name="<?php echo $this->get_field_name('show_all_events_link'); ?>" value="1" <?php checked( $show_all_events_link, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_all_events_link'); ?>"><?php _e( 'Display link to view all events', 'sportspress' ); ?></label></p>
<?php
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget( "SP_Widget_Event_List" );' ) );

View File

@@ -0,0 +1,98 @@
<?php
class SP_Widget_League_Table extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_league_table widget_sp_league_table', 'description' => __( 'Display a league table.', 'sportspress' ) );
parent::__construct('sp_league_table', __( 'SportsPress League Table', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$id = empty($instance['id']) ? null : $instance['id'];
$number = empty($instance['number']) ? null : $instance['number'];
$columns = empty($instance['columns']) ? null : $instance['columns'];
$show_team_logo = empty($instance['show_team_logo']) ? false : $instance['show_team_logo'];
$show_full_table_link = empty($instance['show_full_table_link']) ? false : $instance['show_full_table_link'];
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo '<div id="sp_league_table_wrap">';
echo sportspress_league_table( $id, array( 'number' => $number, 'columns' => $columns, 'show_full_table_link' => $show_full_table_link, 'show_team_logo' => $show_team_logo ) );
echo '</div>';
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['id'] = intval($new_instance['id']);
$instance['number'] = intval($new_instance['number']);
$instance['columns'] = (array)$new_instance['columns'];
$instance['show_team_logo'] = $new_instance['show_team_logo'];
$instance['show_full_table_link'] = $new_instance['show_full_table_link'];
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'number' => 5, 'columns' => null, 'show_team_logo' => false, 'show_full_table_link' => true ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
$number = intval($instance['number']);
$columns = $instance['columns'];
$show_team_logo = $instance['show_team_logo'];
$show_full_table_link = $instance['show_full_table_link'];
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'League Table', 'sportspress' ) ); ?></label>
<?php
$args = array(
'post_type' => 'sp_table',
'name' => $this->get_field_name('id'),
'id' => $this->get_field_id('id'),
'selected' => $id,
'values' => 'ID',
'class' => 'widefat',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_table', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e( 'Number of teams to show:', 'sportspress' ); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($number); ?>" size="3"></p>
<p class="sp-prefs">
<?php _e( 'Columns:', 'sportspress' ); ?><br>
<?php
$args = array(
'post_type' => 'sp_column',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$the_columns = get_posts( $args );
$field_name = $this->get_field_name('columns') . '[]';
$field_id = $this->get_field_id('columns');
?>
<?php foreach ( $the_columns as $column ): ?>
<label class="button"><input name="<?php echo $field_name; ?>" type="checkbox" id="<?php echo $field_id . '-' . $column->post_name; ?>" value="<?php echo $column->post_name; ?>" <?php if ( $columns === null || in_array( $column->post_name, $columns ) ): ?>checked="checked"<?php endif; ?>><?php echo $column->post_title; ?></label>
<?php endforeach; ?>
</p>
<p><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_team_logo'); ?>" name="<?php echo $this->get_field_name('show_team_logo'); ?>" value="1" <?php checked( $show_team_logo, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_team_logo'); ?>"><?php _e( 'Display logos', 'sportspress' ); ?></label><br>
<input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_full_table_link'); ?>" name="<?php echo $this->get_field_name('show_full_table_link'); ?>" value="1" <?php checked( $show_full_table_link, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_full_table_link'); ?>"><?php _e( 'Display link to view full table', 'sportspress' ); ?></label></p>
<?php
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget( "SP_Widget_League_Table" );' ) );

View File

@@ -0,0 +1,108 @@
<?php
class SP_Widget_Player_Gallery extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_player_gallery widget_sp_player_gallery', 'description' => __( 'Display a gallery of players.', 'sportspress' ) );
parent::__construct('sp_player_gallery', __( 'SportsPress Player Gallery', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$id = empty($instance['id']) ? null : $instance['id'];
$number = empty($instance['number']) ? null : $instance['number'];
$orderby = empty($instance['orderby']) ? 'default' : $instance['orderby'];
$order = empty($instance['order']) ? 'ASC' : $instance['order'];
$show_all_players_link = empty($instance['show_all_players_link']) ? false : $instance['show_all_players_link'];
$show_names_on_hover = empty($instance['show_names_on_hover']) ? false : $instance['show_names_on_hover'];
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo '<div id="sp_player_gallery_wrap">';
echo sportspress_player_gallery( $id, array( 'number' => $number, 'orderby' => $orderby , 'order' => $order, 'show_all_players_link' => $show_all_players_link, 'show_names_on_hover' => $show_names_on_hover ) );
echo '</div>';
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['id'] = intval($new_instance['id']);
$instance['number'] = intval($new_instance['number']);
$instance['orderby'] = strip_tags($new_instance['orderby']);
$instance['order'] = strip_tags($new_instance['order']);
$instance['show_all_players_link'] = $new_instance['show_all_players_link'];
$instance['show_names_on_hover'] = $new_instance['show_names_on_hover'];
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'number' => 5, 'orderby' => 'default', 'order' => 'ASC', 'show_all_players_link' => true, 'show_names_on_hover' => false ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
$number = intval($instance['number']);
$orderby = strip_tags($instance['orderby']);
$order = strip_tags($instance['order']);
$show_all_players_link = $instance['show_all_players_link'];
$show_names_on_hover = $instance['show_names_on_hover'];
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Player List', 'sportspress' ) ); ?></label>
<?php
$args = array(
'post_type' => 'sp_list',
'name' => $this->get_field_name('id'),
'id' => $this->get_field_id('id'),
'selected' => $id,
'values' => 'ID',
'class' => 'widefat',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_list', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e( 'Number of players to show:', 'sportspress' ); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($number); ?>" size="3"></p>
<p><label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:', 'sportspress' ); ?></label>
<?php
$args = array(
'prepend_options' => array(
'default' => __( 'Default', 'sportspress' ),
'number' => __( 'Number', 'sportspress' ),
'name' => __( 'Name', 'sportspress' ),
'eventsplayed' => __( 'Played', 'sportspress' )
),
'post_type' => 'sp_performance',
'name' => $this->get_field_name('orderby'),
'id' => $this->get_field_id('orderby'),
'selected' => $orderby,
'values' => 'slug',
'class' => 'sp-select-orderby widefat',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_list', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p><label for="<?php echo $this->get_field_id('order'); ?>"><?php _e( 'Sort Order:', 'sportspress' ); ?></label>
<select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="sp-select-order widefat" <?php disabled( $orderby, 'default' ); ?>>
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
<option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option>
</select></p>
<p><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_all_players_link'); ?>" name="<?php echo $this->get_field_name('show_all_players_link'); ?>" value="1" <?php checked( $show_all_players_link, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_all_players_link'); ?>"><?php _e( 'Display link to view all players', 'sportspress' ); ?></label></p>
<p><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_names_on_hover'); ?>" name="<?php echo $this->get_field_name('show_names_on_hover'); ?>" value="1" <?php checked( $show_names_on_hover, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_names_on_hover'); ?>"><?php _e( 'Display player names on hover', 'sportspress' ); ?></label></p>
<?php
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget( "SP_Widget_Player_Gallery" );' ) );

View File

@@ -0,0 +1,126 @@
<?php
class SP_Widget_Player_list extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_player_list widget_sp_player_list', 'description' => __( 'Display a list of players.', 'sportspress' ) );
parent::__construct('sp_player_list', __( 'SportsPress Player List', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$id = empty($instance['id']) ? null : $instance['id'];
$number = empty($instance['number']) ? null : $instance['number'];
$performance = $instance['performance'];
$orderby = empty($instance['orderby']) ? 'default' : $instance['orderby'];
$order = empty($instance['order']) ? 'ASC' : $instance['order'];
$show_all_players_link = empty($instance['show_all_players_link']) ? false : $instance['show_all_players_link'];
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo '<div id="sp_player_list_wrap">';
echo sportspress_player_list( $id, array( 'number' => $number, 'performance' => $performance, 'orderby' => $orderby , 'order' => $order, 'show_all_players_link' => $show_all_players_link ) );
echo '</div>';
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['id'] = intval($new_instance['id']);
$instance['number'] = intval($new_instance['number']);
$instance['performance'] = (array)$new_instance['performance'];
$instance['orderby'] = strip_tags($new_instance['orderby']);
$instance['order'] = strip_tags($new_instance['order']);
$instance['show_all_players_link'] = $new_instance['show_all_players_link'];
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'number' => 5, 'performance' => null, 'orderby' => 'default', 'order' => 'ASC', 'show_all_players_link' => true ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
$number = intval($instance['number']);
$performance = $instance['performance'];
$orderby = strip_tags($instance['orderby']);
$order = strip_tags($instance['order']);
$show_all_players_link = $instance['show_all_players_link'];
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Player List', 'sportspress' ) ); ?></label>
<?php
$args = array(
'post_type' => 'sp_list',
'name' => $this->get_field_name('id'),
'id' => $this->get_field_id('id'),
'selected' => $id,
'values' => 'ID',
'class' => 'widefat',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_list', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e( 'Number of players to show:', 'sportspress' ); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($number); ?>" size="3"></p>
<p class="sp-prefs">
<?php _e( 'Performance:', 'sportspress' ); ?><br>
<?php
$args = array(
'post_type' => 'sp_performance',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$the_performance = get_posts( $args );
$field_name = $this->get_field_name('performance') . '[]';
$field_id = $this->get_field_id('performance');
?>
<label class="button"><input name="<?php echo $field_name; ?>" type="checkbox" id="<?php echo $field_id . '-' . 'eventsplayed'; ?>" value="<?php echo 'eventsplayed'; ?>" <?php if ( is_array( $performance) && in_array( 'eventsplayed', $performance ) ): ?>checked="checked"<?php endif; ?>><?php _e( 'Played', 'sportspress' ); ?></label>
<?php foreach ( $the_performance as $column ): ?>
<label class="button"><input name="<?php echo $field_name; ?>" type="checkbox" id="<?php echo $field_id . '-' . $column->post_name; ?>" value="<?php echo $column->post_name; ?>" <?php if ( $performance === null || in_array( $column->post_name, $performance ) ): ?>checked="checked"<?php endif; ?>><?php echo $column->post_title; ?></label>
<?php endforeach; ?>
</p>
<p><label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:', 'sportspress' ); ?></label>
<?php
$args = array(
'prepend_options' => array(
'default' => __( 'Default', 'sportspress' ),
'number' => __( 'Number', 'sportspress' ),
'name' => __( 'Name', 'sportspress' ),
'eventsplayed' => __( 'Played', 'sportspress' )
),
'post_type' => 'sp_performance',
'name' => $this->get_field_name('orderby'),
'id' => $this->get_field_id('orderby'),
'selected' => $orderby,
'values' => 'slug',
'class' => 'sp-select-orderby widefat',
);
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_list', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p><label for="<?php echo $this->get_field_id('order'); ?>"><?php _e( 'Sort Order:', 'sportspress' ); ?></label>
<select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="sp-select-order widefat" <?php disabled( $orderby, 'default' ); ?>>
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
<option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option>
</select></p>
<p><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_all_players_link'); ?>" name="<?php echo $this->get_field_name('show_all_players_link'); ?>" value="1" <?php checked( $show_all_players_link, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_all_players_link'); ?>"><?php _e( 'Display link to view all players', 'sportspress' ); ?></label></p>
<?php
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget( "SP_Widget_Player_list" );' ) );