Translating date into spanish Wordpress - php

I have the followwing site on Wordpress where you can find different schedules with the month in english and i need to change it to spanish:
http://comproautosusados.com/centrolerner2016/horarios/
I tried Loco Translate, trying editing the .pó files and now i'm looking into the theme's php files. I've been able to translate lots of stuff, but i can't translate the months. You can see at the left side of the table that it says "Lunes 28th April" for example. I need to change it to "Lunes 28 Abril".
In the theme's "core"there's this file: timetable.php where this function is found:
public function getDays() {
if (!isset(self::$cache['days'])) {
$days = array();
foreach ($this->get('calendar.period') as $time) {
$object = new VTCore_Wordpress_Objects_Array(array(
'id' => strtolower($time->format('l')),
'timestamp' => $time->getTimeStamp(),
'formatted' => $time->format($this->get('calendar.format')),
'iso' => $time->format('Y-m-d\TH:i:sO'),
'label' => $this->get('days.' . strtolower($time->format('l'))),
));
$days[] = $object;
}
self::$cache['days'] = $days;
}
return self::$cache['days'];
}
There is where the theme generates the date? i don't know what to do.

I have had the same problem, maybe something like this will help you:
<?php
// Get the numeric representation of the current month
$m = date('n');
// Get a full textual representation of the month ( in norwegian )
if ($m==1) { $t = "Januar"; }
if ($m==2) { $t = "Februar"; }
if ($m==3) { $t = "Mars"; }
if ($m==4) { $t = "April"; }
if ($m==5) { $t = "Mai"; }
if ($m==6) { $t = "Juni"; }
if ($m==7) { $t = "Juli"; }
if ($m==8) { $t = "August"; }
if ($m==9) { $t = "September"; }
if ($m==10) { $t = "Oktober"; }
if ($m==11) { $t = "November"; }
if ($m==12) { $t = "Desember"; }
// Display the date
echo date('m').".".$t.".".date('Y'); // returns: 05.Mai.2016
?>

Related

Catch Tweets with JSON and sort by likes?

I am currently running a wordpress backend and want to display some tweets based on hastags on my website. For the general API request and database storage, I use this function:
private function parseRequest($json) {
$tmp = $json;
$result = array();
if (isset($json['statuses'])) {
$tmp = $json['statuses'];
}
if (isset($tmp) && is_array($tmp)){
foreach ($tmp as $t) {
$this->image = null;
$this->media = null;
$tc = new \stdClass();
$tc->feed_id = $this->id();
$tc->id = $t['id_str'];
$tc->type = $this->getType();
$tc->nickname = '#'.$t['user']['screen_name'];
$tc->screenname = (string)$t['user']['name'];
$tc->userpic = str_replace('.jpg', '_200x200.jpg', str_replace('_normal', '', (string)$t['user']['profile_image_url']));
$tc->system_timestamp = strtotime($t['created_at']);
$tc->text = $this->getText($t);
$tc->userlink = 'https://twitter.com/'.$t['user']['screen_name'];
$tc->permalink = $tc->userlink . '/status/' . $tc->id;
$tc->media = $this->getMedia($t);
#$tc->additional = array('shares' => (string)$t['retweet_count'], 'likes' => (string)$t['favorite_count'], 'comments' => (string)$t['reply_count']);
if ($this->isSuitablePost($tc)) $result[$tc->id] = $tc;
}
}
return $result;
}
Now I am looking for a function that counts all the variable in the "additional array together e.g. shares + likes + comments and sorts all posts based on the resulting number.
I am using the standard wordpress sql database. I cannot find a solution or I am just blind.
Thanks in regards
You could use a simple usort function:
usort($tc, function($a, $b) {
$a_sum = array_sum($a->additional);
$b_sum = array_sum($b->additional);
if ($a_sum == $b_sum) {
return 0;
}
return ($a_sum < $b_sum) ? -1 : 1;
});

Codeigniter disable calendar date after 5 bookings

I have calendar whose dates are booked and saved in database. I am trying to pull the bookings from database and show then under corresponding date. Everything is working fine, except the thing, I want the date to be just text instead of link when there are more than 5 events to that date.
I am aware of the calendar template no content cell and content cells. But i want the date to have no link when it has more than 5 events attached to it.
My Model:
public function bookingcalender($year=null,$month=null)
{
if(!$year)
{
$y = date('Y');
}
else
{
$y = $year;
}
if(!$month)
{
$m = date('m');
}
else
{
$m = $month;
}
$this->config = array(
'show_next_prev' => TRUE,
'next_prev_url' => 'http://joshuaflinn.com/CI/booking/show',
'template' => '{table_open}<table class="availability-calendar">{/table_open}
{heading_row_start}<tr class="toolbar">{/heading_row_start}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_previous_cell}<th><</th>{/heading_previous_cell}
{heading_next_cell}<th>></th>{/heading_next_cell}
{heading_row_end}</tr>{/heading_row_end}
{week_row_start}<tr>{/week_row_start}
{week_day_cell}<td>{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}
{cal_row_start}<tr>{/cal_row_start}
{cal_cell_start}<td>{/cal_cell_start}
{cal_cell_start_today}<td>{/cal_cell_start_today}
{cal_cell_start_other}<td class="other-month">{/cal_cell_start_other}
{cal_cell_content}{day}<span class="date-data">{content}</span>{/cal_cell_content}
{cal_cell_content_today}<div class="highlight">{day}</div>{/cal_cell_content_today}
{cal_cell_no_content}{day}{/cal_cell_no_content}
{cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}
{cal_cell_blank} {/cal_cell_blank}
{cal_cell_other}{day}{/cal_cel_other}
{cal_cell_end}</td>{/cal_cell_end}
{cal_cell_end_today}</td>{/cal_cell_end_today}
{cal_cell_end_other}</td>{/cal_cell_end_other}
{cal_row_end}</tr>{/cal_row_end}
{table_close}</table>{/table_close}'
);
$this->load->library('calendar',$this->config);
$conf_data = $this->get_booked_dates($year,$month);
return $this->calendar->generate($year,$month,$conf_data);
}
public function get_booked_dates($year,$month)
{
$query = $this->db->select('client_name,booking_date')->from('bookings')->like('booking_date',"$year-$month")->get();
$cal_data = array();
foreach($query->result() as $row)
{
$dt = explode("-", $row->booking_date);
$dt = $dt[2];
$k = ($dt >= 10 ? substr($row->booking_date, 8,2) : substr($row->booking_date, 9,1));
if( #$cal_data[$k] == '' )
{
$cal_data[$k] = $row->client_name;
}
else
{
$cal_data[$k] .= ','.$row->client_name;
}
}
return $cal_data;
}
The options you have are limited since Codeigniters Calendar Library only have the two pseudo variables cal_cell_no_content and cal_cell_contentin the template to play with in terms of what content you want to display.
A quick look behind the door reveals that the library uses isset() to determine which of the two pseudo variables to use.
And it calls str_replace {content} before {day} that opens up for a somewhat hacky solution:
public function bookingcalender($year=null,$month=null)
{
if(!$year)
{
$y = date('Y');
}
else
{
$y = $year;
}
if(!$month)
{
$m = date('m');
}
else
{
$m = $month;
}
$this->config = array(
'show_next_prev' => TRUE,
'next_prev_url' => 'http://joshuaflinn.com/CI/booking/show',
'template' => '{table_open}<table class="availability-calendar">{/table_open}
{heading_row_start}<tr class="toolbar">{/heading_row_start}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_previous_cell}<th><</th>{/heading_previous_cell}
{heading_next_cell}<th>></th>{/heading_next_cell}
{heading_row_end}</tr>{/heading_row_end}
{week_row_start}<tr>{/week_row_start}
{week_day_cell}<td>{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}
{cal_row_start}<tr>{/cal_row_start}
{cal_cell_start}<td>{/cal_cell_start}
{cal_cell_start_today}<td>{/cal_cell_start_today}
{cal_cell_start_other}<td class="other-month">{/cal_cell_start_other}
{cal_cell_content}{content}{/cal_cell_content}
{cal_cell_content_today}<div class="highlight">{content}</div>{/cal_cell_content_today}
{cal_cell_no_content}{day}{/cal_cell_no_content}
{cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}
{cal_cell_blank} {/cal_cell_blank}
{cal_cell_other}{day}{/cal_cel_other}
{cal_cell_end}</td>{/cal_cell_end}
{cal_cell_end_today}</td>{/cal_cell_end_today}
{cal_cell_end_other}</td>{/cal_cell_end_other}
{cal_row_end}</tr>{/cal_row_end}
{table_close}</table>{/table_close}'
);
$this->load->library('calendar',$this->config);
$conf_data = $this->get_booked_dates($year,$month);
return $this->calendar->generate($year,$month,$conf_data);
}
public function get_booked_dates($year,$month)
{
$query = $this->db->select('client_name,booking_date')->from('bookings')->like('booking_date',"$year-$month")->get();
$cal_data = array();
foreach($query->result() as $row)
{
$dt = explode("-", $row->booking_date);
$k = intval($dt[2]); // MAKE INTEGER OF DAY NUMBER
if( #$cal_data[$k] == '' )
{
$cal_data[$k] = $row->client_name;
}
else
{
$cal_data[$k] .= ','.$row->client_name;
}
}
// LOOP THROUGH EACH DAY TO FIND THOSE WITH MORE THAN 5 EVENTS
foreach($cal_data as $key=>$val){
// COUNT THE NUMBER OF COMMAS THAT OCCUR IN STRING
$count = strlen($val) - strlen(str_replace(',','',$val));
if($count > 4){ // IF MORE THAN 4 COMMAS (> 5 EVENTS) THEN NO LINK...
$cal_data[$key] = '{day}<span class="date-data">'.$val.'</span>';
} else { // LINKED DAY
$cal_data[$key] = '{day}<span class="date-data">'.$val.'</span>';
}
}
return $cal_data;
}
Note: that I have changed two rows in the template: {cal_cell_content}{content}{/cal_cell_content} and {cal_cell_content_today}<div class="highlight">{content}</div>{/cal_cell_content_today}
You now only need to set {content} since {day} is specified inside the content also containing the html returned from the query.
Update: I have now tested the solution and it seems to work fine!
You have to manipulate or extend the Calendar library if you need a more flexible solution and if you don't want to mix template html in the content returned from your query.

Cakephp pagination custom order

I need to set the pagination order of my register based on field ($results[$key]['Movimento']['status']) created in afterFind callback.
afterFind:
public function afterFind($results, $primary = false) {
foreach ($results as $key => $val) {
if(isset($val['Movimento']['data_vencimento'])) {
$data = $val['Movimento']['data_vencimento'];
$dtVc = strtotime($data);
$dtHj = strtotime(date('Y-m-d'));
$dtVencendo = strtotime("+7 day", $dtHj);
if ($dtVc < $dtHj) {
$results[$key]['Movimento']['status'] = 'vencido';
} elseif ($dtVc <= $dtVencendo) {
$results[$key]['Movimento']['status'] = 'vc15dias';
} else {
$results[$key]['Movimento']['status'] = 'aberto';
}
}
if(isset($val['Movimento']['data_pagamento'])) {
$results[$key]['Movimento']['status'] = 'quitado';
}
}
return $results;
Pagination:
$options = array(
...
'order' => array('Movimento.status' => 'ASC')
);
$this->controller->paginate = $options;
$movimentos = $this->controller->paginate('Movimento');
I know this does not work because the field is created after the paginator call.
Can I make it work?
as I understand, you want to sort by data_pagamento and than by data_vencimento (has it the mysql-type date?)
so you don't need your afterFind-function for ordering, simply use:
'order' => array(
'Movimento.data_pagamento DESC',//first all rows with not-empty data_pagamento
'Movimento.data_vencimento DESC',// first all dates in the furthest future
)

Incorporating functions in oop

I'm trying to write a code for one of my schools assignments, yet I cannot find the reason for it not working. It's probably something simple that i'm yet unaware of. Could anyone point me in the right direction. I'm trying to make a class generate 3 dropdown boxes for selecting the day, month and year. Also there seems to be an infinite loop with the 3rd function. The code is as follows and is split between two files.
File 1: datselect.php
<?php
include ("datselect_functions.php");
$cls = new Dropdown();
$monthname = array(1 => "January", "February", "March", "April", "May", "June",
"July","August", "September", "October", "November", "December");
$today = time();
$f_today = date("M-d-Y",$today);
$func = insert_day();
$func = insert_month($monthname);
//$func = insert_year($today);
echo html_head($f_today);
echo $cls -> getHTML();
echo html_foot();
?>
File 2: datselect_functions.php
<?php
function html_head($f_today) {
return "<html>
<head>
<title>Select a date</title>
</head>
<body>
<div>
Today is ".$f_today."
</div>";
}
class Dropdown {
private $name = "";
private $options = array();
private $selected = "";
public function __construct($name = "") {
$this->name=$name;
}
public function setOption($var,$label) {
$this->options[$var]=$label;
}
public function getHTML() {
$html = "<select name='".$this->name."'>";
var_dump($this->name);
foreach($this->options as $var => $label) {
if ($this->selected=$var) {
$html.= "<option selected value='".$var."'>.$label.</option>";
} else {
$html.= "<option value='".$var."'>.$label.</option>";
}
}
$html.= "</select>";
return $html;
}
}
function html_foot() {
return "</body></html>";
}
function insert_day(){
$ddd = new Dropdown("day");
for($i=1; $i<=31; $i++){
$ddd -> setOption($i, $i);
}
}
function insert_month($monthname){
$ddm = new Dropdown("month");
foreach($monthname as $key => $value) {
$ddm -> setOption($key, $value);
}
}
function insert_year($today){
$currentyear = date("Y", $today);
$ddy = new Dropdown("year");
for($n=$currentyear;$n=$currentyear+3;$n++) {
$ddy -> setOption($n, $n);
}
}
?>
There are a bunch of things where it goes wrong.
//this is unnecessary, you now create an empty dropdown and echo it here.
$cls = new Dropdown();
echo $cls -> getHTML();
//instead of this
$func = insert_day();
$func = insert_month($monthname);
//$func = insert_year($today);
//do this
$days = insert_day();
$months = insert_month($monthname);
$years = insert_year($today);
//then make the dropdows appear like this.
echo $days;
echo $months;
echo $years;
//These 3 functions require an extra line of code.
function insert_day(){
$ddd = new Dropdown("day");
for($i=1; $i<=31; $i++){
$ddd -> setOption($i, $i);
}
//add this line to all of these three functions, but change the var name
return $ddd->getHTML();
}
This should resolve most of your errors, but now a few others might appear though.
Your Dropdown class is just a helper that generates the dropdown html code. You need to store that generated code or output it somewhere, for "it to work".
$func = insert_day(); // 1
$func = insert_month($monthname); // 2
//$func = insert_year($today);
echo html_head($f_today); // 3
echo $cls -> getHTML(); // 4
echo html_foot(); // 5
You are doing the following here, step by step:
You assign the dropdown html code for the day selection to $func
You assign the dropdown html code for the month selection to $func, overwriting everything from 1. You should use a new variable for that or append it with $func .= insert... if that's what you want
You output your header html
You output an empty dropdown, as the Dropdown instance $cls isn't configured anywhere with an options array
You output the footer html
What's missing is that you should also output the results from 1. and 2. after 3.
Also the infinite loop in insert_year is because you assign the current year + 3 in the for loop, not compare it (= vs. ==).
Also it's good style to have one file per class and nothing else in that, but that shouldn't be the problem here.
Hope that helps.
"=" is not a comparison but a setting (use "==" instead):
if ($this->selected=$var) {
Endless-Loop:
for($n=$currentyear;$n=$currentyear+3;$n++) {
Use this:
for($n=$currentyear;$n < $currentyear+3;$n++) {
Your insert_day, insert_month functions do not serve any purpose. Below I have updated your code to display the days, although really you dont need so much code.
//dateselect.php
<?php
include ("datselect_functions.php");
$cls = new Dropdown();
$monthname = array(1 => "January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
$today = time();
$f_today = date("M-d-Y",$today);
$func = $cls->insert_day();
//$func = insert_month($monthname);
//$func = insert_year($today);
echo html_head($f_today);
echo $cls -> getHTML();
//echo html_foot();
?>
//datselect_functions
<?php
function html_head($f_today) {
return "<html>
<head>
<title>
Select a date
</title>
</head>
<body>
<div>
Today is ".$f_today."
</div>";
}
class Dropdown {
private $name = "";
private $options = array();
private $selected = "";
public function __construct($name = "") {
$this->name=$name;
}
public function setOption($var,$label) {
$this->options[$var]=$label;
}
public function getHTML() {
$html = "<select>";
//var_dump($this->options);
foreach($this->options as $var => $label) {
if ($this->selected==$var) {
$html.= "<option selected value='".$var."'>.$label.</option>";
}
else {
$html.= '<option value="'.$var.'">'.$label."</option>";
}
}
$html.= "</select>";
//print_r($html);
return $html;
}
function insert_day(){
for($i=1; $i<=31; $i++){
$this -> setOption($i, $i);
}
}
function html_foot() {
return "</body></html>";
}
}
function insert_month($monthname){
$ddm = new Dropdown("month");
foreach($monthname as $key => $value) {
$ddm -> setOption($key, $value);
}
}
function insert_year($today){
$currentyear = date("Y", $today);
$ddy = new Dropdown("year");
for($n=$currentyear;$n<=$currentyear+3;$n++) {
$ddy -> setOption($n, $n);
}
}
?>

Google Analytics PHP API (GAPI) non-mobile browsers

I am trying to display the top 5 of non-mobile browsers with GAPI.
I can't seem to find a way of doing this, is this even possible?
This is how I get the percentage of mobile visits:
$ga->requestReportData(GA_PROFILE_ID, array("isMobile"), array("visits"), '-visits', null, $startdate, $enddate);
foreach ($ga->getResults() AS $result) {
if ((string)$result == "Yes") $mobile["yes"] = $result->getVisits();
else $mobile["no"] = $result->getVisits();
}
This is how I ended up doing it:
public function getDevices($max = 5) {
$this->ga->requestReportData($this->profileid, array('mobileDeviceInfo'), array('visits'), '-visits', 'mobileDeviceInfo != (not set) && mobileDeviceInfo != (not provided)', $this->startdate, $this->enddate, 1, $max);
foreach ($this->ga->getResults() as $result) {
$device[] = (string)$result;
$visits[] = $result->getVisits();
}
if (!isset($device) OR !isset($visits)) {
$device[] = "Niet genoeg data beschikbaar";
$visits[] = "0";
}
$return = array("device" => $device, "visits" => $visits);
return $return;
}

Categories