public function testLightenWithDefaultAdjustment() { $expected = array("336699" => "4080bf", "913399" => "b540bf"); foreach ($expected as $original => $darker) { $color = new Color($original); $this->assertEquals($darker, $color->lighten(), "Incorrect lighter color returned."); } }
function rrd_gen_graph() { $rrdgraph = $this->rrd_options(); $sources = $this->rrd_get_sources(); $raw = null; if ($this->scale) { $raw = '_raw'; } $i = 0; foreach ($this->tinstances as $tinstance) { foreach ($this->data_sources as $ds) { $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); $i++; } } if ($this->scale) { $i = 0; foreach ($this->tinstances as $tinstance) { foreach ($this->data_sources as $ds) { $rrdgraph[] = sprintf('CDEF:min_%s=min_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale); $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale); $rrdgraph[] = sprintf('CDEF:max_%s=max_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale); $i++; } } } for ($i = count($sources) - 1; $i >= 0; $i--) { if ($i == count($sources) - 1) { $rrdgraph[] = sprintf('CDEF:area_%s=avg_%1$s', crc32hex($sources[$i])); } else { $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,avg_%1$s,ADDNAN', crc32hex($sources[$i]), crc32hex($sources[$i + 1])); } } $c = 0; foreach ($sources as $source) { $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors; $php_color = new Color($color); $rrdgraph[] = sprintf('AREA:max_%s#%s', crc32hex($source), $php_color->darken(20)); $rrdgraph[] = sprintf('LINE1:area_%s#%s', crc32hex($source), $php_color->lighten()); $rrdgraph[] = sprintf('AREA:min_%s#%s', crc32hex($source), $php_color->darken(10)); } $c = 0; foreach ($sources as $source) { $legend = empty($this->legend[$source]) ? $source : $this->legend[$source]; # $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; # $rrdgraph[] = sprintf('LINE1:area_%s#%s:%s', crc32hex($source), $this->validate_color($color), $this->rrd_escape($legend)); $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:%s Min,', crc32hex($source), $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:%s Avg,', crc32hex($source), $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:%s Max,', crc32hex($source), $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:%s Last\\l', crc32hex($source), $this->rrd_format); } return $rrdgraph; }
function mytheme_customize_css() { $main = get_theme_mod('main_color'); if (empty($main)) { $main = '#00a99d'; } $main2 = new Color("{$main}"); $licht = '#' . $main2->mix('ffffff', 10); $donker = '#' . $main2->darken(); $grijs = get_theme_mod('grijs'); if (empty($grijs)) { $grijs = '#e6e6e6'; } $grijs2 = new Color("{$grijs}"); $lichtgrijs = '#' . $grijs2->lighten(5); $donkergrijs = '#' . $grijs2->darken(10); if ($grijs == "#ffffff") { $hovergrijs = "#e6e6e6"; } else { $hovergrijs = $grijs; } $font = get_theme_mod('akvo_font'); if (empty($font)) { $font = 'Open Sans'; } $font_head = get_theme_mod('akvo_font_head'); if (empty($font_head)) { $font_head = 'Open Sans'; } $font_nav = get_theme_mod('akvo_font_nav'); if (empty($font_nav)) { $font_nav = 'Open Sans'; } $background = get_theme_mod('background'); if (empty($background)) { $background = '#ffffff'; } $info_bar_blog = get_theme_mod('info_bar_blog'); if (empty($info_bar_blog)) { $info_bar_blog = '#a3d165'; } $info_bar_news = get_theme_mod('info_bar_news'); if (empty($info_bar_news)) { $info_bar_news = '#f9ba41'; } $info_bar_video = get_theme_mod('info_bar_video'); if (empty($info_bar_video)) { $info_bar_video = '#f47b50'; } $info_bar_update = get_theme_mod('info_bar_update'); if (empty($info_bar_update)) { $info_bar_update = '#54bce8'; } $info_bar_flow = get_theme_mod('info_bar_flow'); if (empty($info_bar_flow)) { $info_bar_flow = '#54bce8'; } $info_bar_page = get_theme_mod('info_bar_page'); if (empty($info_bar_page)) { $info_bar_page = '#6d3a7d'; } $info_bar_media = get_theme_mod('info_bar_media'); if (empty($info_bar_media)) { $info_bar_media = '#9d897b'; } $info_bar_project = get_theme_mod('info_bar_project'); if (empty($info_bar_project)) { $info_bar_project = '#7381fa'; } $info_bar_map = get_theme_mod('info_bar_map'); if (empty($info_bar_map)) { $info_bar_map = '#ad1c3c'; } $info_bar_testimonial = get_theme_mod('info_bar_testimonial'); if (empty($info_bar_testimonial)) { $info_bar_testimonial = '#007ba8'; } ?> <style type="text/css"> html {background:<?php echo $donker; ?> ; } body { font-family: '<?php echo $font; ?> '; background: <?php echo $background; ?> ;} h1,h2,h3,h4,h5,h6 { font-family: '<?php echo $font_head; ?> '; } nav { font-family: '<?php echo $font_nav; ?> '; } .carousel .text, footer .twitter, nav ul.navbar-nav li.current-menu-item a { background: <?php echo $licht; ?> ; } nav .lang .fa-circle, nav ul.navbar-nav li i { color: <?php echo $licht; ?> ; } .btn-default, .filters #uwpqsf_id #uwpqsf_btn input, .carousel .carousel-indicators li.active, footer .custom { background: <?php echo $main; ?> ; } nav ul.navbar-nav li .fa-circle, a { color: <?php echo $main; ?> ; } a:hover {color:<?php echo $donker; ?> ;} .btn-default:focus, .btn-default:hover, .filters #uwpqsf_id #uwpqsf_btn input:focus, .filters #uwpqsf_id #uwpqsf_btn input:hover, footer .fixed, .comment-form footer .custom input[type=submit], .filters #uwpqsf_id #uwpqsf_btn footer .custom input, footer .custom .btn, footer .custom .comment-form input[type=submit], footer .custom .filters #uwpqsf_id #uwpqsf_btn input { background: <?php echo $donker; ?> ; } .box-wrap, .article .bg, article .bg, .filters, .breadcrumbs, .search-wrap { background: <?php echo $lichtgrijs; ?> ;} .box-wrap .infobar.blog, .box-wrap .infobar.type-blog { background: <?php echo $info_bar_blog; ?> ; } .box-wrap .infobar.post, .box-wrap .infobar.type-post { background: <?php echo $info_bar_news; ?> ; } .box-wrap .infobar.video, .box-wrap .infobar.type-video { background: <?php echo $info_bar_video; ?> ; } .box-wrap .infobar.update, .box-wrap .infobar.type-update { background: <?php echo $info_bar_update; ?> ; } .box-wrap .infobar.page, .box-wrap .infobar.type-page { background: <?php echo $info_bar_page; ?> ; } .box-wrap .infobar.media, .box-wrap .infobar.type-media { background: <?php echo $info_bar_media; ?> ; } .box-wrap .infobar.map, .box-wrap .infobar.type-map { background: <?php echo $info_bar_map; ?> ; } .box-wrap .infobar.project, .box-wrap .infobar.type-project { background: <?php echo $info_bar_project; ?> ; } .box-wrap .infobar.testimonial, .box-wrap .infobar.type-testimonial { background: <?php echo $info_bar_testimonial; ?> ; } .box-wrap .infobar.flow, .box-wrap .infobar.type-flow { background: <?php echo $info_bar_flow; ?> ; } nav ul.navbar-nav li {background: <?php echo $grijs; ?> ;} nav ul.navbar-nav .dropdown-menu li a {background: <?php echo $grijs; ?> ; } .clickable:hover .text {background: <?php echo $main; ?> ;} .box-wrap:hover {background: <?php echo $hovergrijs; ?> ;} .search-wrap .input-group-btn .btn {color:<?php echo $donkergrijs; ?> ;} nav ul.navbar-nav .dropdown-menu li { background: <?php echo $licht; ?> ;} .nav>li>a:focus, .nav>li>a:hover {background:<?php echo $licht; ?> ; } blockquote {border-color: $donkergrijs;} @media (min-width: 768px) { nav {background: <?php echo $lichtgrijs; ?> ;} nav ul.navbar-nav li a:hover, nav ul.navbar-nav li:hover a { background: <?php echo $licht; ?> ;} nav ul.navbar-nav .dropdown-menu li a:hover {background: <?php echo $main; ?> ; } } </style> <?php }
/** * Make a calendar list of events. * * Outputs a list of events according to events for the specified range. * * @since 3.0.0 * @access private * * @param int $timestamp * @param int $id * * @return string */ private function draw_list($timestamp, $id = 0) { $calendar = $this->calendar; if (empty($calendar)) { $calendar = $this->calendar = simcal_get_calendar(intval($id)); if (!$calendar instanceof Default_Calendar) { return ''; } } date_default_timezone_set($calendar->timezone); $now = $calendar->now; $current_events = $this->get_events($timestamp); $day_format = explode(' ', $calendar->date_format); ob_start(); // Draw the events. $block_tag = $calendar->compact_list && !empty($current_events) ? 'div' : 'dl'; $data_heading = ''; $heading = $this->get_heading(); foreach ($heading as $k => $v) { $data_heading .= ' data-heading-' . $k . '="' . $v . '"'; } echo '<' . $block_tag . ' class="simcal-events-list-container"' . ' data-prev="' . $this->prev . '"' . ' data-next="' . $this->next . '"' . $data_heading . '>'; if (!empty($current_events) && is_array($current_events)) { foreach ($current_events as $ymd => $events) { $day_ts = Carbon::createFromFormat('Ymd', $ymd, $calendar->timezone)->getTimestamp(); if (!$calendar->compact_list) { $date = new Carbon('now', $calendar->timezone); $date->setLocale(substr(get_locale(), 0, 2)); $date->setTimestamp($day_ts); if ($date->isToday()) { $the_color = new Color($calendar->today_color); } else { $the_color = new Color($calendar->days_events_color); } $bg_color = '#' . $the_color->getHex(); $color = $the_color->isDark() ? '#ffffff' : '#000000'; $border_style = ' style="border-bottom: 1px solid ' . $bg_color . ';" '; $bg_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . ';"'; echo "\t" . '<dt class="simcal-day-label"' . $border_style . '>'; echo '<span' . $bg_style . '>'; foreach ($day_format as $format) { echo $format ? '<span class="simcal-date-format" data-date-format="' . $format . '">' . date_i18n($format, $day_ts) . '</span> ' : ' '; } echo '</span>'; echo '</dt>' . "\n"; } $list_events = '<ul class="simcal-events">' . "\n"; $calendar_classes = array(); $day_classes = 'simcal-weekday-' . date('w', $day_ts); // Is this the present, the past or the future, Doc? if ($timestamp <= $now && $timestamp >= $now) { $day_classes .= ' simcal-today simcal-present simcal-day'; } elseif ($timestamp < $now) { $day_classes .= ' simcal-past simcal-day'; } elseif ($this->end > $now) { $day_classes .= ' simcal-future simcal-day'; } $count = 0; foreach ($events as $day_events) { foreach ($day_events as $event) { if ($event instanceof Event) { $event_classes = $event_visibility = ''; $calendar_class = 'simcal-events-calendar-' . strval($event->calendar); $calendar_classes[] = $calendar_class; $recurring = $event->recurrence ? 'simcal-event-recurring ' : ''; $has_location = $event->venue ? 'simcal-event-has-location ' : ''; $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class; // Toggle some events visibility if more than optional limit. if ($calendar->events_limit > -1 && $count >= $calendar->events_limit) { $event_classes .= ' simcal-event-toggled'; $event_visibility = ' style="display: none"'; } $event_color = ''; $bullet = ''; $event_color = $event->get_color(); if (!empty($event_color)) { $side = is_rtl() ? 'right' : 'left'; $event_color = ' style="border-' . $side . ': 4px solid ' . $event_color . '; padding-' . $side . ': 8px;"'; } $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . $event_color . ' itemprop="event" itemscope itemtype="http://schema.org/Event">' . "\n"; $list_events .= "\t\t" . '<div class="simcal-event-details">' . $calendar->get_event_html($event) . '</div>' . "\n"; $list_events .= "\t" . '</li>' . "\n"; $count++; // Event falls within today. if ($this->end <= $now && $this->start >= $now) { $day_classes .= ' simcal-today-has-events'; } $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval($count) . '-events'; if ($calendar_classes) { $day_classes .= ' ' . trim(implode(' ', array_unique($calendar_classes))); } } } } $list_events .= '</ul>' . "\n"; // If events visibility is limited, print the button toggle. if ($calendar->events_limit > -1 && $count > $calendar->events_limit) { $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>'; } // Print final list of events for the current day. $tag = $calendar->compact_list ? 'div' : 'dd'; echo '<' . $tag . ' class="' . $day_classes . '" data-events-count="' . strval($count) . '">' . "\n"; echo "\t" . $list_events . "\n"; echo '</' . $tag . '>' . "\n"; } } else { echo "\t" . '<p>'; $message = get_post_meta($calendar->id, '_no_events_message', true); if ('events' == $calendar->group_type) { echo !empty($message) ? $message : __('Nothing to show.', 'google-calendar-events'); } else { if (!empty($message)) { echo $message; } else { $from = Carbon::createFromTimestamp($this->start, $calendar->timezone)->getTimestamp(); $to = Carbon::createFromTimestamp($this->end, $calendar->timezone)->getTimestamp(); echo apply_filters('simcal_no_events_message', sprintf(__('Nothing from %1$s to %2$s.', 'google-calendar-events'), date_i18n($calendar->date_format, $from), date_i18n($calendar->date_format, $to)), $calendar->id, $from, $to); } } echo "\t" . '</p>' . "\n"; } echo '</' . $block_tag . '>'; date_default_timezone_set($calendar->site_timezone); return ob_get_clean(); }
/** * Make a calendar grid. * * Outputs an html calendar according to month and year passed in arguments. * Loosely inspired by: http://davidwalsh.name/php-calendar * Adjusted by timezone and with an arbitrary week start day. * * @since 3.0.0 * @access private * * @param int $month The month to print (two digits). * @param int $year The corresponding year (four digits). * @param int $id The calendar id. * * @return string */ private function draw_month($month, $year, $id = 0) { $calendar = $this->calendar; if (empty($calendar)) { $calendar = simcal_get_calendar(intval($id)); if (!$calendar) { return ''; } } date_default_timezone_set($calendar->timezone); $events = $calendar->events; // Variables to cycle days in current month and find today in calendar. $now = $calendar->now; $current = Carbon::create($year, $month, 1, 0, 0, 59, $calendar->timezone); $current_min = $current->getTimestamp(); $current_max = $current->endOfDay()->getTimestamp(); // Calendar grid variables. $week_starts = $calendar->week_starts; $week_of_year = $current->weekOfYear; // Relative count of the week number of the year. $month_starts = $current->dayOfWeek; // Day upon which the month starts. $days_in_month = $current->daysInMonth; // Number of days in the given month. // Set current month events timestamp boundaries. $this->start = $current_min; $this->end = $current->endOfMonth()->timestamp; // Get daily events for this month. if ($events && is_array($events)) { // Filter events within the boundaries previously set above. $timestamps = array_keys($events); $lower_bound = array_filter($timestamps, array($this, 'filter_events_before')); $higher_bound = array_filter($lower_bound, array($this, 'filter_events_after')); $filtered = array_intersect_key($events, array_combine($higher_bound, $higher_bound)); // Put resulting events in an associative array, with day of the month as key for easy retrieval in calendar days loop. $day_events = array(); foreach ($filtered as $timestamp => $events_in_day) { foreach ($events_in_day as $event) { if ($event instanceof Event) { $day = intval(Carbon::createFromTimestamp($timestamp, $event->timezone)->endOfDay()->day); $day_events[$day][] = $event; } } } ksort($day_events, SORT_NUMERIC); } ob_start(); echo '<tbody class="simcal-month simcal-month-' . $month . '">' . "\n"; echo "\t" . '<tr class="simcal-week simcal-week-' . $week_of_year . '">'; $days_in_row = 0; // Week may start on an arbitrary day (sun, 0 - sat, 6). $week_day = $week_starts; // This fixes a possible bug when a month starts by Sunday (0). if (0 !== $week_starts) { $b = $month_starts === 0 ? 7 : $month_starts; } else { $b = $month_starts; } // Void days in first week. for ($a = $week_starts; $a < $b; $a++) { $last_void_day_class = $a === $b - 1 ? 'simcal-day-void-last' : ''; echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n"; // Reset day of the week count (sun, 0 - sat, 6). if ($week_day === 6) { $week_day = -1; } $week_day++; $days_in_row++; } // Actual days of the month. for ($day = 1; $day <= $days_in_month; $day++) { $count = 0; $calendar_classes = array(); $day_classes = 'simcal-day-' . $day . ' simcal-weekday-' . $week_day; $border_style = $bg_color = $color = ''; // Is this the present, the past or the future, Doc? if ($current_min <= $now && $current_max >= $now) { $day_classes .= ' simcal-today simcal-present simcal-day'; $the_color = new Color($calendar->today_color); $bg_color = '#' . $the_color->getHex(); $color = $the_color->isDark() ? '#ffffff' : '#000000'; $border_style = ' style="border: 1px solid ' . $bg_color . ';"'; } elseif ($current_max < $now) { $day_classes .= ' simcal-past simcal-day'; } elseif ($current_min > $now) { $day_classes .= ' simcal-future simcal-day'; } // Print events for the current day in loop, if found any. if (isset($day_events[$day])) { $list_events = '<ul class="simcal-events">'; foreach ($day_events[$day] as $event) { $event_classes = $event_visibility = ''; if ($event instanceof Event) { // Store the calendar id where the event belongs (useful in grouped calendar feeds) $calendar_class = 'simcal-events-calendar-' . strval($event->calendar); $calendar_classes[] = $calendar_class; $recurring = $event->recurrence ? 'simcal-event-recurring ' : ''; $has_location = $event->venue ? 'simcal-event-has-location ' : ''; $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class . ' simcal-tooltip'; // Toggle some events visibility if more than optional limit. if ($calendar->events_limit > -1 && $count >= $calendar->events_limit) { $event_classes .= ' simcal-event-toggled'; $event_visibility = ' style="display: none"'; } // Event title in list. $title = !empty($event->title) ? trim($event->title) : __('Event', 'google-calendar-events'); if ($calendar->trim_titles >= 1) { $title = strlen($title) > $calendar->trim_titles ? substr($title, 0, $calendar->trim_titles) . '…' : $title; } // Event color. $bullet = ''; $event_color = $event->get_color(); if (!empty($event_color)) { $bullet = '<span style="color: ' . $event_color . ';">■</span> '; } // Event contents. $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . ' itemprop="event" itemscope itemtype="http://schema.org/Event">' . "\n"; $list_events .= "\t\t" . '<span class="simcal-event-title">' . $bullet . $title . '</span>' . "\n"; $list_events .= "\t\t" . '<div class="simcal-event-details simcal-tooltip-content" style="display: none;">' . $calendar->get_event_html($event) . '</div>' . "\n"; $list_events .= "\t" . '</li>' . "\n"; $count++; } } if ($current_min <= $now && $current_max >= $now) { $day_classes .= ' simcal-today-has-events'; } $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval($count) . '-events'; if ($calendar_classes) { $day_classes .= ' ' . trim(implode(' ', array_unique($calendar_classes))); } $list_events .= '</ul>' . "\n"; // Optional button to toggle hidden events in list. if ($calendar->events_limit > -1 && $count > $calendar->events_limit) { $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>'; } } else { // Empty cell for day with no events. $list_events = '<span class="simcal-no-events"></span>'; } // The actual days with numbers and events in each row cell. echo '<td class="' . $day_classes . '" data-events-count="' . strval($count) . '">' . "\n"; if ($color) { $day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . '"'; } elseif ($count > 0) { $the_color = new Color($calendar->days_events_color); $color = !$color ? $the_color->isDark() ? '#ffffff' : '#000000' : $color; $bg_color = !$bg_color ? '#' . $the_color->getHex() : $bg_color; $day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . '"'; } else { $day_style = ''; } echo "\t" . '<div' . $border_style . '>' . "\n"; echo "\t\t" . '<span class="simcal-day-label simcal-day-number"' . $day_style . '>' . $day . '</span>' . "\n"; echo "\t\t" . $list_events . "\n"; echo "\t\t"; echo '<span class="simcal-events-dots" style="display: none;">'; // Event bullets for calendar mobile mode. for ($i = 0; $i < $count; $i++) { echo '<b> • </b>'; } echo '</span>' . "\n"; echo "\t" . '</div>' . "\n"; echo '</td>' . "\n"; // Reset day of the week count (sun, 0 - sat, 6). if ($week_day === 6) { $week_day = -1; } $week_day++; // Reset count of days for this row (0-6). if ($days_in_row === 6) { // Close the week row. echo '</tr>'; // Open a new week row. if ($day < $days_in_month) { echo '<tr class="simcal-week simcal-week-' . $week_of_year++ . '">' . "\n"; } $days_in_row = -1; } $days_in_row++; $current_min = Carbon::createFromTimestamp($current_min, $calendar->timezone)->addDay()->getTimestamp(); $current_max = Carbon::createFromTimestamp($current_max, $calendar->timezone)->addDay()->getTimestamp(); } // Void days at the end of the month. $remainder_days = 6 - $days_in_row; for ($i = 0; $i <= $remainder_days; $i++) { $last_void_day_class = $i == $remainder_days ? 'simcal-day-void-last' : ''; echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n"; $week_day++; } echo "\t" . '</tr>' . "\n"; echo '</tbody>' . "\n"; date_default_timezone_set($calendar->site_timezone); return ob_get_clean(); }
<?php include "../src/Color.php"; use Mexitek\PHPColors\Color; // Use different colors to test $myBlue = new Color("#336699"); $myBlack = new Color("#333"); $myPurple = new Color("#913399"); $myVintage = new Color("#bada55"); // ************** No Need to Change Below ********************** ?> <style> .block{ height:100px; width:200px; font-size:20px; text-align:center; padding-top:100px; display:block; margin:0px; float:left; } .wide-block { width: 360px; padding-top: 70px; padding-left: 20px; padding-right: 20px; margin-top: 10px; } .clear{ clear:both; }
private function getImageColorInfo($filename) { $filenameSample = $filename . '.sample.jpg'; if (file_exists($filename)) { if (!file_exists($filenameSample)) { $imageFile = Image::fromFile($filename); $imageFile->resize(200, 200, Image::FILL); $imageFile->save($filenameSample, 100, Image::JPEG); } $client = new Client(); $image = $client->loadJpeg($filenameSample); $palette = $image->extract(6); $dominantColor = ColorThief::getColor($filenameSample); $dominantColor = \Aprila\Utils\Colors::rgbToHex($dominantColor); $color = new Color($dominantColor); $isDark = $color->isDark(); $imageColorInfo = ['main' => $dominantColor, 'palette' => $palette, 'isDark' => $isDark]; FileSystem::delete($filenameSample); return $imageColorInfo; } return []; }
/** * Index page. * * @return void */ public function home() { if (Configure::read('Analytics.enabled') === true) { $httpAdapter = new CurlHttpAdapter(); $client = new Client(Configure::read('Analytics.client_id'), Configure::read('Analytics.private_key'), $httpAdapter); $service = new Service($client); $statistics = Cache::remember('statistics', function () use($service) { $statistics = new Query(Configure::read('Analytics.profile_id')); $statistics->setStartDate(new \DateTime(Configure::read('Analytics.start_date')))->setEndDate(new \DateTime())->setMetrics(array('ga:visits', 'ga:visitors', 'ga:pageviews', 'ga:pageviewsPerVisit', 'ga:avgtimeOnSite', 'ga:visitBounceRate', 'ga:percentNewVisits')); return $service->query($statistics); }, 'analytics'); $browsers = Cache::remember('browsers', function () use($service) { $browsers = new Query(Configure::read('Analytics.profile_id')); $browsers->setStartDate(new \DateTime(Configure::read('Analytics.start_date')))->setEndDate(new \DateTime())->setDimensions(array('ga:browser'))->setMetrics(array('ga:pageviews'))->setSorts(array('ga:pageviews'))->setFilters(array('ga:browser==Chrome,ga:browser==Firefox,ga:browser==Internet Explorer,ga:browser==Safari,ga:browser==Opera')); return $service->query($browsers); }, 'analytics'); $continents = Cache::remember('continents', function () use($service) { $continentsRows = new Query(Configure::read('Analytics.profile_id')); $continentsRows->setStartDate(new \DateTime(Configure::read('Analytics.start_date')))->setEndDate(new \DateTime())->setDimensions(array('ga:continent'))->setMetrics(array('ga:visitors'))->setSorts(array('ga:visitors'))->setFilters(array('ga:continent==Africa,ga:continent==Americas,ga:continent==Asia,ga:continent==Europe,ga:continent==Oceania')); $continentsRows = $service->query($continentsRows); $color = new Color("1abc9c"); $light = 1; $continents = []; foreach (array_reverse($continentsRows->getRows()) as $continentRow) { $continent = []; $continent['label'] = $continentRow[0]; $continent['data'] = $continentRow[1]; $continent['color'] = '#' . $color->lighten($light); array_push($continents, $continent); $light += 10; } return $continents; }, 'analytics'); $graphVisitors = Cache::remember('graphVisitors', function () use($service) { $graphVisitors = new Query(Configure::read('Analytics.profile_id')); $graphVisitors->setStartDate(new \DateTime('-7 days'))->setEndDate(new \DateTime())->setDimensions(array('ga:date'))->setMetrics(array('ga:visits', 'ga:pageviews'))->setSorts(array('ga:date')); return $service->query($graphVisitors); }, 'analytics'); $this->set(compact('statistics', 'browsers', 'continents', 'graphVisitors')); } $this->loadModel('Users'); //UsersGraph $usersGraphCount = $this->Users->find('all')->select(['date' => 'DATE_FORMAT(created,\'%d-%m-%Y\')', 'count' => 'COUNT(id)'])->group('DATE(created)')->order(['date' => 'desc'])->where(['UNIX_TIMESTAMP(DATE(created)) >' => (new \DateTime('-8 days'))->getTimestamp()])->toArray(); $usersGraph = array(); //Fill the new array with the date of the 8 past days and give them the value 0. for ($i = 0; $i < 8; $i++) { $date = new \DateTime("{$i} days ago"); $usersGraph[$date->format('d-m-Y')] = 0; } //Foreach value that we got in the database, parse the array by the key date, //and if the key exist, attribute the new value. foreach ($usersGraphCount as $user) { $usersGraph[$user->date] = intval($user->count); } $usersGraph = array_reverse($usersGraph); $usersCount = Number::format($this->Users->find()->count()); $this->loadModel('BlogArticles'); $articlesCount = Number::format($this->BlogArticles->find()->count()); $this->loadModel('BlogArticlesComments'); $commentsCount = Number::format($this->BlogArticlesComments->find()->count()); $this->loadModel('BlogCategories'); $categoriesCount = Number::format($this->BlogCategories->find()->count()); $this->set(compact('usersCount', 'articlesCount', 'commentsCount', 'categoriesCount', 'usersGraph')); }
/** * Set and get pie chart * * @param Collection $data * @return Collection */ public function getPieChart($data) { foreach ($data as $key => $value) { $i = 0; $dataset[$key] = collect(); foreach ($data->get($key) as $k => $v) { $color = new Color(config('chartjs.colors.' . $i)); $dataset[$key]->push(['value' => $v, 'color' => '#' . $color->lighten(20), 'highlight' => '#' . $color->lighten(25), 'label' => $k]); $i++; } } return $dataset; }
function rrd_gen_graph() { $rrdgraph = $this->rrd_options(); $sources = $this->rrd_get_sources(); $raw = null; if ($this->scale) { $raw = '_raw'; } $i = 0; foreach ($this->tinstances as $tinstance) { foreach ($this->data_sources as $ds) { $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); $rrdgraph[] = sprintf('DEF:avg_%s_raw=%s:%s:AVERAGE', crc32hex($sources[$i]), $this->parse_filename($this->files[$tinstance]), $ds); $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); if (!$this->scale) { $rrdgraph[] = sprintf('VDEF:tot_%s=avg_%1$s,TOTAL', crc32hex($sources[$i])); } $i++; } } if ($this->scale) { $i = 0; foreach ($this->tinstances as $tinstance) { foreach ($this->data_sources as $ds) { $rrdgraph[] = sprintf('CDEF:min_%s=min_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale); $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale); $rrdgraph[] = sprintf('CDEF:max_%s=max_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale); if ($i == 1) { $rrdgraph[] = sprintf('CDEF:avg_%s_neg=avg_%1$s_raw,%s%s,*', crc32hex($sources[$i]), $this->negative_io ? '-' : '', $this->scale); } $rrdgraph[] = sprintf('VDEF:tot_%1$s=avg_%1$s,TOTAL', crc32hex($sources[$i])); if ($this->percentile) { $rrdgraph[] = sprintf('VDEF:pct_%1$s=avg_%1$s,%2$s,PERCENT', crc32hex($sources[$i]), $this->percentile); } if ($this->percentile && $this->negative_io && $i == 1) { $rrdgraph[] = sprintf('VDEF:pct_%1$s_neg=avg_%1$s_neg,%2$s,PERCENT', crc32hex($sources[$i]), 100 - $this->percentile); } $i++; } } } $rrdgraph[] = sprintf('CDEF:overlap=avg_%s,avg_%s_neg,LT,avg_%1$s,avg_%2$s_neg,IF', crc32hex($sources[0]), crc32hex($sources[1])); $i = 0; foreach ($sources as $source) { # $rrdgraph[] = sprintf('AREA:avg_%s%s#%s', crc32hex($source), $i == 1 ? '_neg' : '', $this->get_faded_color($this->colors[$source])); $php_color = new Color($this->colors[$source]); $rrdgraph[] = sprintf('AREA:avg_%s%s#%s', crc32hex($source), $i == 1 ? '_neg' : '', $php_color->darken()); $i++; } if (!$this->negative_io) { $php_color = new Color($this->colors[$sources[0]]); $rrdgraph[] = sprintf('AREA:overlap#%s', $php_color->mix($this->colors[$sources[1]])); } $i = 0; foreach ($sources as $source) { $legend = empty($this->legend[$source]) ? $source : $this->legend[$source]; $rrdgraph[] = sprintf('LINE1:avg_%s%s#%s:%s', crc32hex($source), $i == 1 ? '_neg' : '', $this->colors[$source], $this->rrd_escape($legend)); $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:%s Min,', crc32hex($source), $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:%s Avg,', crc32hex($source), $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:%s Max,', crc32hex($source), $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:%s Last', crc32hex($source), $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:tot_%s:%s Total\\l', crc32hex($source), $this->rrd_format); $i++; } if ($this->percentile) { $rrdgraph[] = 'COMMENT: \\l'; $i = 0; foreach ($sources as $source) { $legend = empty($this->legend[$source]) ? $source : $this->legend[$source]; $rrdgraph[] = sprintf('LINE:pct_%s%s#%s:%sth Percentile %s', crc32hex($source), $i == 1 && $this->negative_io ? '_neg' : '', $this->get_faded_color($this->colors[$source], '000000', 0.6), $this->percentile, $this->rrd_escape($legend)); $rrdgraph[] = sprintf('GPRINT:pct_%s:%s\\l', crc32hex($source), $this->rrd_format); $i++; } } return $rrdgraph; }
/** * Make a calendar list of events. * * Outputs a list of events according to events for the specified range. * * @since 3.0.0 * @access private * * @param int $timestamp * @param int $id * * @return string */ private function draw_list($timestamp, $id = 0) { $calendar = $this->calendar; if (empty($calendar)) { $calendar = $this->calendar = simcal_get_calendar(intval($id)); if (!$calendar instanceof Default_Calendar) { return ''; } } $now = $calendar->now; $current_events = $this->get_events($timestamp); $format = $calendar->date_format; ob_start(); // Draw the events. $block_tag = $calendar->compact_list && !empty($current_events) ? 'div' : 'dl'; $data_heading = ''; $heading = $this->get_heading(); foreach ($heading as $k => $v) { $data_heading .= ' data-heading-' . $k . '="' . $v . '"'; } echo '<' . $block_tag . ' class="simcal-events-list-container"' . ' data-prev="' . $this->prev . '"' . ' data-next="' . $this->next . '"' . $data_heading . '>'; if (!empty($current_events) && is_array($current_events)) { $last_event = null; foreach ($current_events as $ymd => $events) { // This is where we can find out if an event is a multi-day event and if it needs to be shown. // Since this is for list view we are showing the event on the day viewed if it is part of that day even when // expand multi-day events are turned off. $first_event = $events[0][0]; if (isset($first_event->multiple_days) && $first_event->multiple_days > 0) { if ('current_day_only' == get_post_meta($calendar->id, '_default_calendar_expand_multi_day_events', true)) { $year = substr($ymd, 0, 4); $month = substr($ymd, 4, 2); $day = substr($ymd, 6, 2); $temp_date = Carbon::createFromDate($year, $month, $day); if (!($temp_date < Carbon::now()->endOfDay())) { // Break here only if event already shown once. if ($last_event == $first_event) { continue; } else { // Save event as "last" for next time through, then break. $last_event = $first_event; } } } } // Add offset offset for list view day headings. $day_date = Carbon::createFromFormat('Ymd', $ymd, $calendar->timezone); $day_date_offset = clone $day_date; $day_date_offset->addSeconds($day_date->offset); $day_date_ts_offset = $day_date_offset->timestamp; if (!$calendar->compact_list) { if ($day_date_offset->isToday()) { $the_color = new Color($calendar->today_color); } else { $the_color = new Color($calendar->days_events_color); } $bg_color = '#' . $the_color->getHex(); $color = $the_color->isDark() ? '#ffffff' : '#000000'; $border_style = ' style="border-bottom: 1px solid ' . $bg_color . ';" '; $bg_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . ';"'; echo "\t" . '<dt class="simcal-day-label"' . $border_style . '>'; echo '<span' . $bg_style . '>'; echo $format ? '<span class="simcal-date-format" data-date-format="' . $format . '">' . date_i18n($format, $day_date_ts_offset, strtotime($day_date_offset->toDateTimeString())) . '</span> ' : ' '; echo '</span>'; echo '</dt>' . "\n"; } $list_events = '<ul class="simcal-events">' . "\n"; $calendar_classes = array(); // Add day of week number to CSS class. $day_classes = 'simcal-weekday-' . date('w', $day_date_ts_offset); // Is this the present, the past or the future, Doc? if ($timestamp <= $now && $timestamp >= $now) { $day_classes .= ' simcal-today simcal-present simcal-day'; } elseif ($timestamp < $now) { $day_classes .= ' simcal-past simcal-day'; } elseif ($this->end > $now) { $day_classes .= ' simcal-future simcal-day'; } $count = 0; foreach ($events as $day_events) { foreach ($day_events as $event) { if ($event instanceof Event) { $event_classes = $event_visibility = ''; $calendar_class = 'simcal-events-calendar-' . strval($event->calendar); $calendar_classes[] = $calendar_class; $recurring = $event->recurrence ? 'simcal-event-recurring ' : ''; $has_location = $event->venue ? 'simcal-event-has-location ' : ''; $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class; // Toggle some events visibility if more than optional limit. if ($calendar->events_limit > -1 && $count >= $calendar->events_limit) { $event_classes .= ' simcal-event-toggled'; $event_visibility = ' style="display: none"'; } $event_color = $event->get_color(); if (!empty($event_color)) { $side = is_rtl() ? 'right' : 'left'; $event_color = ' style="border-' . $side . ': 4px solid ' . $event_color . '; padding-' . $side . ': 8px;"'; } $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . $event_color . ' itemscope itemtype="http://schema.org/Event" data-start="' . esc_attr($event->start) . '">' . "\n"; $list_events .= "\t\t" . '<div class="simcal-event-details">' . $calendar->get_event_html($event) . '</div>' . "\n"; $list_events .= "\t" . '</li>' . "\n"; $count++; // Event falls within today. if ($this->end <= $now && $this->start >= $now) { $day_classes .= ' simcal-today-has-events'; } $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval($count) . '-events'; if ($calendar_classes) { $day_classes .= ' ' . trim(implode(' ', array_unique($calendar_classes))); } } } } $list_events .= '</ul>' . "\n"; // If events visibility is limited, print the button toggle. if ($calendar->events_limit > -1 && $count > $calendar->events_limit) { $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>'; } // Print final list of events for the current day. $tag = $calendar->compact_list ? 'div' : 'dd'; echo '<' . $tag . ' class="' . $day_classes . '" data-events-count="' . strval($count) . '">' . "\n"; echo "\t" . $list_events . "\n"; echo '</' . $tag . '>' . "\n"; } } else { echo "\t" . '<p>'; $message = get_post_meta($calendar->id, '_no_events_message', true); if ('events' == $calendar->group_type) { echo !empty($message) ? $message : __('There are no upcoming events.', 'google-calendar-events'); } else { if (!empty($message)) { echo $message; } else { $from = Carbon::createFromTimestamp($this->start, $calendar->timezone)->getTimestamp(); $to = Carbon::createFromTimestamp($this->end, $calendar->timezone)->getTimestamp(); echo apply_filters('simcal_no_events_message', sprintf(__('Nothing from %1$s to %2$s.', 'google-calendar-events'), date_i18n($calendar->date_format, $from), date_i18n($calendar->date_format, $to)), $calendar->id, $from, $to); } } echo "\t" . '</p>' . "\n"; } echo '</' . $block_tag . '>'; return ob_get_clean(); }