From: Michael J. Rubinsky Date: Sun, 25 Jan 2009 01:29:58 +0000 (-0500) Subject: Rename FreeBusy.php to View.php so it can be autoloaded. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=06efcc8d6adfdef9ed81052c54c37c0a8f6cc416;p=horde.git Rename FreeBusy.php to View.php so it can be autoloaded. Update Imple.php for PHP5 - fix some paths etc... --- diff --git a/kronolith/lib/FreeBusy/FreeBusy.php b/kronolith/lib/FreeBusy/FreeBusy.php deleted file mode 100644 index b9181cceb..000000000 --- a/kronolith/lib/FreeBusy/FreeBusy.php +++ /dev/null @@ -1,258 +0,0 @@ - - * @author Jan Schneider - * @package Kronolith - */ -class Kronolith_FreeBusy_View { - - var $_requiredMembers = array(); - var $_optionalMembers = array(); - var $_timeBlocks = array(); - - var $_startHour; - var $_endHour; - - var $_start; - var $_end; - - function addRequiredMember($vFreebusy) - { - $this->_requiredMembers[] = Util::cloneObject($vFreebusy); - } - - function addOptionalMember($vFreebusy) - { - $this->_optionalMembers[] = Util::cloneObject($vFreebusy); - } - - function render($day = null) - { - global $prefs; - - $this->_startHour = floor($prefs->getValue('day_hour_start') / 2); - $this->_endHour = floor(($prefs->getValue('day_hour_end') + 1) / 2); - - $this->_render($day); - - $vCal = new Horde_iCalendar(); - $required = &Horde_iCalendar::newComponent('vfreebusy', $vCal); - foreach ($this->_requiredMembers as $member) { - $required->merge($member, false); - } - $required->simplify(); - - $optional = &Horde_iCalendar::newComponent('vfreebusy', $vCal); - foreach ($this->_optionalMembers as $member) { - $optional->merge($member, false); - } - $optional->simplify(); - - $optimal = &Horde_iCalendar::newComponent('vfreebusy', $vCal); - $optimal->merge($required, false); - $optimal->merge($optional); - - $base_url = Horde::selfUrl(); - $base_url = Util::removeParameter($base_url, 'date'); - $base_url = Util::removeParameter($base_url, 'fbview'); - $base_url = Util::addParameter($base_url, 'fbview', $this->view); - - $template = new Horde_Template(); - $template->set('title', $this->_title()); - - $html = $template->fetch(KRONOLITH_TEMPLATES . '/fbview/header.html') . - '
'; - - $hours_html = $this->_hours(); - - // Set C locale to avoid localized decimal separators during CSS width - // calculation. - $lc = setlocale(LC_NUMERIC, 0); - setlocale(LC_NUMERIC, 'C'); - - // Required to attend. - if (count($this->_requiredMembers) > 0) { - $template = new Horde_Template(); - $rows = ''; - foreach ($this->_requiredMembers as $member) { - $member->simplify(); - $blocks = $this->_getBlocks($member, $member->getBusyPeriods(), 'busyblock.html', _("Busy")); - $template = new Horde_Template(); - $template->set('blocks', $blocks); - $template->set('name', $member->getName()); - $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html'); - } - - $template = new Horde_Template(); - $template->set('title', _("Required Attendees")); - $template->set('rows', $rows); - $template->set('span', count($this->_timeBlocks)); - $template->set('hours', $hours_html); - $template->set('legend', ''); - $html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html'); - } - - // Optional to attend. - if (count($this->_optionalMembers) > 0) { - $template = new Horde_Template(); - $rows = ''; - foreach ($this->_optionalMembers as $member) { - $member->simplify(); - $blocks = $this->_getBlocks($member, $member->getBusyPeriods(), 'busyblock.html', _("Busy")); - $template = new Horde_Template(); - $template->set('blocks', $blocks); - $template->set('name', $member->getName()); - $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html'); - } - - $template = new Horde_Template(); - $template->set('title', _("Optional Attendees")); - $template->set('rows', $rows); - $template->set('span', count($this->_timeBlocks)); - $template->set('hours', $hours_html); - $template->set('legend', ''); - $html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html'); - } - - // Possible meeting times. - $optimal->setAttribute('ORGANIZER', _("All Attendees")); - $blocks = $this->_getBlocks($optimal, - $optimal->getFreePeriods($this->_start->timestamp(), $this->_end->timestamp()), - 'meetingblock.html', _("All Attendees")); - - $template = new Horde_Template(); - $template->set('name', _("All Attendees")); - $template->set('blocks', $blocks); - $rows = $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html'); - - // Possible meeting times. - $required->setAttribute('ORGANIZER', _("Required Attendees")); - $blocks = $this->_getBlocks($required, - $required->getFreePeriods($this->_start->timestamp(), $this->_end->timestamp()), - 'meetingblock.html', _("Required Attendees")); - - $template = new Horde_Template(); - $template->set('name', _("Required Attendees")); - $template->set('blocks', $blocks); - $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html'); - - // Reset locale. - setlocale(LC_NUMERIC, $lc); - - $template = new Horde_Template(); - $template->set('rows', $rows); - $template->set('title', _("Overview")); - $template->set('span', count($this->_timeBlocks)); - $template->set('hours', $hours_html); - if ($prefs->getValue('show_fb_legend')) { - $template->setOption('gettext', true); - $template->set('legend', $template->fetch(KRONOLITH_TEMPLATES . '/fbview/legend.html')); - } else { - $template->set('legend', ''); - } - - return $html . $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html') . '
'; - } - - /** - * Attempts to return a concrete Kronolith_FreeBusy_View instance based on - * $view. - * - * @param string $view The type of concrete Kronolith_FreeBusy_View - * subclass to return. - * - * @return mixed The newly created concrete Kronolith_FreeBusy_View - * instance, or false on an error. - */ - function factory($view) - { - $driver = basename($view); - require_once dirname(__FILE__) . '/FBView/' . $driver . '.php'; - $class = 'Kronolith_FreeBusy_View_' . $driver; - if (class_exists($class)) { - return new $class($user, $params); - } - - return false; - } - - /** - * Attempts to return a reference to a concrete Kronolith_FreeBusy_View - * instance based on $view. It will only create a new instance if no - * Kronolith_FreeBusy_View instance with the same parameters currently - * exists. - * - * This method must be invoked as: - * $var = &Kronolith_FreeBusy_View::singleton() - * - * @param string $view The type of concrete Kronolith_FreeBusy_View - * subclass to return. - * - * @return mixed The created concrete Kronolith_FreeBusy_View instance, or - * false on an error. - */ - function &singleton($view) - { - static $instances = array(); - - if (!isset($instances[$view])) { - $instances[$view] = Kronolith_FreeBusy_View::factory($view); - } - - return $instances[$view]; - } - - function _getBlocks($member, $periods, $blockfile, $label) - { - $template = new Horde_Template(); - $template->set('label', $label); - - reset($periods); - list($periodStart, $periodEnd) = each($periods); - - $blocks = ''; - foreach ($this->_timeBlocks as $span) { - /* Horde_iCalendar_vfreebusy only supports timestamps at the - * moment. */ - $start = $span[0]->timestamp(); - $end = $span[1]->timestamp(); - if ($member->getStart() > $start || - $member->getEnd() < $end) { - $blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/unknownblock.html'); - continue; - } - - while ($start > $periodEnd && - list($periodStart, $periodEnd) = each($periods)); - - if (($periodStart <= $start && $periodEnd >= $start) || - ($periodStart <= $end && $periodEnd >= $end) || - ($periodStart <= $start && $periodEnd >= $end) || - ($periodStart >= $start && $periodEnd <= $end)) { - - $l_start = ($periodStart < $start) ? $start : $periodStart; - $l_end = ($periodEnd > $end) ? $end : $periodEnd; - $plen = ($end - $start) / 100.0; - - $left = ($l_start - $start) / $plen; - $width = ($l_end - $l_start) / $plen; - - $template->set('left', $left . '%'); - $template->set('width', $width . '%'); - - $blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/' . $blockfile); - } else { - $blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/emptyblock.html'); - } - } - - return $blocks; - } - -} diff --git a/kronolith/lib/FreeBusy/View.php b/kronolith/lib/FreeBusy/View.php new file mode 100644 index 000000000..c05fa41d2 --- /dev/null +++ b/kronolith/lib/FreeBusy/View.php @@ -0,0 +1,258 @@ + + * @author Jan Schneider + * @package Kronolith + */ +class Kronolith_FreeBusy_View { + + var $_requiredMembers = array(); + var $_optionalMembers = array(); + var $_timeBlocks = array(); + + var $_startHour; + var $_endHour; + + var $_start; + var $_end; + + function addRequiredMember($vFreebusy) + { + $this->_requiredMembers[] = Util::cloneObject($vFreebusy); + } + + function addOptionalMember($vFreebusy) + { + $this->_optionalMembers[] = Util::cloneObject($vFreebusy); + } + + function render($day = null) + { + global $prefs; + + $this->_startHour = floor($prefs->getValue('day_hour_start') / 2); + $this->_endHour = floor(($prefs->getValue('day_hour_end') + 1) / 2); + + $this->_render($day); + + $vCal = new Horde_iCalendar(); + $required = &Horde_iCalendar::newComponent('vfreebusy', $vCal); + foreach ($this->_requiredMembers as $member) { + $required->merge($member, false); + } + $required->simplify(); + + $optional = &Horde_iCalendar::newComponent('vfreebusy', $vCal); + foreach ($this->_optionalMembers as $member) { + $optional->merge($member, false); + } + $optional->simplify(); + + $optimal = &Horde_iCalendar::newComponent('vfreebusy', $vCal); + $optimal->merge($required, false); + $optimal->merge($optional); + + $base_url = Horde::selfUrl(); + $base_url = Util::removeParameter($base_url, 'date'); + $base_url = Util::removeParameter($base_url, 'fbview'); + $base_url = Util::addParameter($base_url, 'fbview', $this->view); + + $template = new Horde_Template(); + $template->set('title', $this->_title()); + + $html = $template->fetch(KRONOLITH_TEMPLATES . '/fbview/header.html') . + '
'; + + $hours_html = $this->_hours(); + + // Set C locale to avoid localized decimal separators during CSS width + // calculation. + $lc = setlocale(LC_NUMERIC, 0); + setlocale(LC_NUMERIC, 'C'); + + // Required to attend. + if (count($this->_requiredMembers) > 0) { + $template = new Horde_Template(); + $rows = ''; + foreach ($this->_requiredMembers as $member) { + $member->simplify(); + $blocks = $this->_getBlocks($member, $member->getBusyPeriods(), 'busyblock.html', _("Busy")); + $template = new Horde_Template(); + $template->set('blocks', $blocks); + $template->set('name', $member->getName()); + $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html'); + } + + $template = new Horde_Template(); + $template->set('title', _("Required Attendees")); + $template->set('rows', $rows); + $template->set('span', count($this->_timeBlocks)); + $template->set('hours', $hours_html); + $template->set('legend', ''); + $html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html'); + } + + // Optional to attend. + if (count($this->_optionalMembers) > 0) { + $template = new Horde_Template(); + $rows = ''; + foreach ($this->_optionalMembers as $member) { + $member->simplify(); + $blocks = $this->_getBlocks($member, $member->getBusyPeriods(), 'busyblock.html', _("Busy")); + $template = new Horde_Template(); + $template->set('blocks', $blocks); + $template->set('name', $member->getName()); + $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html'); + } + + $template = new Horde_Template(); + $template->set('title', _("Optional Attendees")); + $template->set('rows', $rows); + $template->set('span', count($this->_timeBlocks)); + $template->set('hours', $hours_html); + $template->set('legend', ''); + $html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html'); + } + + // Possible meeting times. + $optimal->setAttribute('ORGANIZER', _("All Attendees")); + $blocks = $this->_getBlocks($optimal, + $optimal->getFreePeriods($this->_start->timestamp(), $this->_end->timestamp()), + 'meetingblock.html', _("All Attendees")); + + $template = new Horde_Template(); + $template->set('name', _("All Attendees")); + $template->set('blocks', $blocks); + $rows = $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html'); + + // Possible meeting times. + $required->setAttribute('ORGANIZER', _("Required Attendees")); + $blocks = $this->_getBlocks($required, + $required->getFreePeriods($this->_start->timestamp(), $this->_end->timestamp()), + 'meetingblock.html', _("Required Attendees")); + + $template = new Horde_Template(); + $template->set('name', _("Required Attendees")); + $template->set('blocks', $blocks); + $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html'); + + // Reset locale. + setlocale(LC_NUMERIC, $lc); + + $template = new Horde_Template(); + $template->set('rows', $rows); + $template->set('title', _("Overview")); + $template->set('span', count($this->_timeBlocks)); + $template->set('hours', $hours_html); + if ($prefs->getValue('show_fb_legend')) { + $template->setOption('gettext', true); + $template->set('legend', $template->fetch(KRONOLITH_TEMPLATES . '/fbview/legend.html')); + } else { + $template->set('legend', ''); + } + + return $html . $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html') . '
'; + } + + /** + * Attempts to return a concrete Kronolith_FreeBusy_View instance based on + * $view. + * + * @param string $view The type of concrete Kronolith_FreeBusy_View + * subclass to return. + * + * @return mixed The newly created concrete Kronolith_FreeBusy_View + * instance, or false on an error. + */ + function factory($view) + { + $driver = basename($view); + require_once dirname(__FILE__) . '/View/' . $driver . '.php'; + $class = 'Kronolith_FreeBusy_View_' . $driver; + if (class_exists($class)) { + return new $class($user, $params); + } + + return false; + } + + /** + * Attempts to return a reference to a concrete Kronolith_FreeBusy_View + * instance based on $view. It will only create a new instance if no + * Kronolith_FreeBusy_View instance with the same parameters currently + * exists. + * + * This method must be invoked as: + * $var = &Kronolith_FreeBusy_View::singleton() + * + * @param string $view The type of concrete Kronolith_FreeBusy_View + * subclass to return. + * + * @return mixed The created concrete Kronolith_FreeBusy_View instance, or + * false on an error. + */ + function &singleton($view) + { + static $instances = array(); + + if (!isset($instances[$view])) { + $instances[$view] = Kronolith_FreeBusy_View::factory($view); + } + + return $instances[$view]; + } + + function _getBlocks($member, $periods, $blockfile, $label) + { + $template = new Horde_Template(); + $template->set('label', $label); + + reset($periods); + list($periodStart, $periodEnd) = each($periods); + + $blocks = ''; + foreach ($this->_timeBlocks as $span) { + /* Horde_iCalendar_vfreebusy only supports timestamps at the + * moment. */ + $start = $span[0]->timestamp(); + $end = $span[1]->timestamp(); + if ($member->getStart() > $start || + $member->getEnd() < $end) { + $blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/unknownblock.html'); + continue; + } + + while ($start > $periodEnd && + list($periodStart, $periodEnd) = each($periods)); + + if (($periodStart <= $start && $periodEnd >= $start) || + ($periodStart <= $end && $periodEnd >= $end) || + ($periodStart <= $start && $periodEnd >= $end) || + ($periodStart >= $start && $periodEnd <= $end)) { + + $l_start = ($periodStart < $start) ? $start : $periodStart; + $l_end = ($periodEnd > $end) ? $end : $periodEnd; + $plen = ($end - $start) / 100.0; + + $left = ($l_start - $start) / $plen; + $width = ($l_end - $l_start) / $plen; + + $template->set('left', $left . '%'); + $template->set('width', $width . '%'); + + $blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/' . $blockfile); + } else { + $blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/emptyblock.html'); + } + } + + return $blocks; + } + +} diff --git a/kronolith/lib/Imple.php b/kronolith/lib/Imple.php index a7691874b..50062f8e6 100644 --- a/kronolith/lib/Imple.php +++ b/kronolith/lib/Imple.php @@ -8,14 +8,15 @@ * @author Michael Slusarz * @package Kronolith */ -class Kronolith_Imple { +class Kronolith_Imple +{ /** * Parameters needed by the subclasses. * * @var array */ - var $_params = array(); + protected $_params = array(); /** * Attempts to return a concrete Imple instance based on $imple. @@ -28,7 +29,7 @@ class Kronolith_Imple { * @return mixed The newly created concrete Imple instance, or false on * error. */ - function factory($imple, $params = array()) + public static function factory($imple, $params = array()) { $imple = basename($imple); if (!$imple) { @@ -51,7 +52,7 @@ class Kronolith_Imple { * * @param array $params Any parameters needed by the class. */ - function Imple($params) + public function __construct($params) { $this->_params = $params; $this->attach(); @@ -60,7 +61,7 @@ class Kronolith_Imple { /** * Attach the Imple object to a javascript event. */ - function attach() + public function attach() { Horde::addScriptFile('prototype.js', 'horde', true); Horde::addScriptFile('effects.js', 'horde', true); @@ -71,7 +72,7 @@ class Kronolith_Imple { * * @param TODO */ - function handle($args) + public function handle($args) { } @@ -80,7 +81,7 @@ class Kronolith_Imple { * * @return string The HTML code. */ - function html() + public function html() { } @@ -91,7 +92,7 @@ class Kronolith_Imple { * * @return string The random ID string. */ - function _randomid() + public function _randomid() { return 'imple_' . uniqid(mt_rand()); }