I'll start off by saying that I am not a PHP developer. So I had another developer create a plugin that takes the start and end time from the Wordpress plugin CalendarizeIt and outputs that into a formatted ICS url. The problem is that the url is outputting a start and end time 5 hours earlier than it should.
Here's the plugin PHP:
<?php
// Original script from http://jamiebicknell.tumblr.com/post/413492676/ics-generator-php-class#_=_
// Modified by Sean Carruthers
$start = $_GET['start'];
$end = $_GET['end'];
$name = $_GET['name'];
$description = $_GET['description'];
$location = $_GET['location'];
$uid = "kaneko" . strtotime("now");
$data = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nMETHOD:PUBLISH\r\nBEGIN:VEVENT\r\nDTSTART:".date("Ymd\THis\Z",$start)."\r\nDTEND:".date("Ymd\THis\Z",$end)."\r\nLOCATION:".$location."\r\nTRANSP: OPAQUE\r\nSEQUENCE:0\r\nUID:".$uid."\r\nDTSTAMP:".date("Ymd\THis\Z")."\r\nSUMMARY:".$name."\r\nDESCRIPTION:".$description."\r\nPRIORITY:1\r\nCLASS:PUBLIC\r\nEND:VEVENT\r\nEND:VCALENDAR";
header("Content-type:text/calendar; charset=utf-8");
header('Content-Disposition: inline; filename="'.$name.'.ics"');
echo $data;
?>
Then in the Wordpress theme file:
<?php
$start_date = get_post_meta($post->ID, "fc_start", true);
$c_start_date = date("M j, Y",strtotime($start_date));
$end_date = get_post_meta($post->ID, "fc_end", true);
$c_end_date = date("M j, Y",strtotime($end_date));
$start_time = get_post_meta($post->ID, "fc_start_time", true);
$end_time = get_post_meta($post->ID, "fc_end_time", true);
$ics_args['start'] = strtotime($start_date . " " . $start_time);
$ics_args['end'] = strtotime($end_date . " " . $end_time);
$ics_args['name'] = get_the_title();
$ics_args['description'] = get_the_content();
$ics_args['location'] = get_post_meta($post->ID, "location", true);
$ics_url = plugins_url('kaneko/calendarize-it-mods/ics_event.php') . "?";
foreach($ics_args as $key => $value) {
$ics_url .= "$key=$value&";
}
if($c_start_date == $c_end_date) {
echo $c_start_date;
} else {
echo $c_start_date . " - <br />" . $c_end_date;
}
?>
And finally the $ics_url variable is getting echoed in an anchor tag like so:
<a href="<?php echo $ics_url; ?>">
I've tried changing the strtotime in the $uid variable of the plugin to something like +5 hours but it does not seem to work.
Any help would be greatly appreciated.
Oh and I also played around with changing the timezone in the Wordpress settings. It is currently set to UTC-5, so I thought changing it to like Chicago would help but it did not either.
In the line below add X-WR-TIMEZONE:America/New_York
$data = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nMETHOD:PUBLISH\r\nX-WR-TIMEZONE:America/New_York\r\n
UPDATE: i have updated the whole line of code, its using DTSTART;VALUE=DATE: with out the Z and the same for DTEND
$data = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nMETHOD:PUBLISH\r\nX-WR-TIMEZONE:America/New_York\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:".date("Ymd\THis",$start)."\r\nDTEND;VALUE=DATE:".date("Ymd\THis",$end)."\r\nLOCATION:".$location."\r\nTRANSP: OPAQUE\r\nSEQUENCE:0\r\nUID:".$uid."\r\nDTSTAMP:".date("Ymd\THis\Z")."\r\nSUMMARY:".$name."\r\nDESCRIPTION:".$description."\r\nPRIORITY:1\r\nCLASS:PUBLIC\r\nEND:VEVENT\r\nEND:VCALENDAR";
Related
I'm working on date-based trigger in php, and want to auto click a button with this code:
<?php
$oldDate = metadata('item', array('Dublin Core', 'Date'));
$latestDate = explode("/", $oldDate);
$year = $latestDate[2];
$month = $latestDate[1];
$day = $latestDate[0];
$newDate = $month.'/'.$day.'/'.$year;
$newestDate = new DateTime($newDate);
echo $newestDate->format('jS M Y');
$t = time();
$nt = strtotime($newDate);
if($nt <= $t){
} else {
echo "<script> $(document).ready(function(){
$('#gatemodal').trigger('click');
});</script>";
}
?>
but the trigger click event doesn't fire up. Don't have a clue where the fault is. I've tried changing the trigger line into this:
$('#gatemodal')[0].click();
and
jQuery(document).ready(function(){
jQuery('#gatemodal').trigger('click');
still not working.
On the echo part, set a variable and assign it (e.g. $fail='1'), then on your php file check whether $fail has been set and it is equal to one then have your script.
`<?php if (isset($fail)&& $fail=='1'){ ?>
<script type="text/javascript">
jQuery(document).ready(function(){
$('#gatemodal').trigger('click');
});
</script>";
`
I am trying to create a small instagram app in PHP only (no database) and without getting an access_token (just my client_id). So far so good, (i.e. input user_id returns photos from last 30 days, with likes-count and created_time, in a table), until I get to pagination. As expected, I want to hit a 'more' button which loads next json file and adds additional photos to the existing table, but it falls apart there... Here is what I've got, working, except for the pagination attempt.
NOTE: this is an internal app, so the sensitivity of my client_id is not an issue, if it is exposed
<?php
if (!empty($_GET['user_id'])){
$user_id = ($_GET['user_id']);
$instagram_url = 'https://api.instagram.com/v1/users/' . $user_id . '/media/recent/?client_id=MY_CLIENT_ID';
$instagram_json = file_get_contents($instagram_url);
$instagram_array = json_decode($instagram_json, true);
}
?>
...
<?php
if(!empty($instagram_array)){
$instagram_array['pagination'] as $page { // Attempt at pagination
echo '<p>' .$page['next_url'].'</p>'; // Attempt at pagination
} // Attempt at pagination
foreach($instagram_array['data'] as $image){
if ($image['created_time'] > strtotime('-30 days')) {
echo '<tr>';
echo '<td>' . date('M d, Y', $image['created_time']) . '</td>';
echo '<td>'.$image['likes']['count'].'</td>';
echo '<td><img src="'.$image['images']['standard_resolution']['url'].'" alt=""/ style="max-height:40px"></td>';
echo '</tr>';
}
}
}
?>
</body>
</html>
Note: this is cobbled together from a few other sources - I am a total noob, so please forgive me if I need a little hand-holding...:)
You may specify min_timestamp to return medias which taken later than this timestamp
https://api.instagram.com/v1/users/{user_id}/media/recent/?access_token={access_token}&min_timestamp={min_timestamp}
$instagram_array['pagination']['next_url'] should be removed, it may include your access token which is a sensible data, that must be always invisible.
list_ig.php
<?
$user_id = "...";
$access_token = "...";
//30 day ago
$min_timestamp = strtotime("-30 day",time());
//pagination feature
$next_max_id = $_GET['next_max_id'];
$instagram_url = "https://api.instagram.com/v1/users/" . $user_id . "/media/recent/?access_token=" .$access_token. "&min_timestamp=" . $min_timestamp;
if($next_max_id != "")
$instagram_url .= "&max_id=" . $next_max_id;
$instagram_json = file_get_contents($instagram_url);
$instagram_array = json_decode($instagram_json ,true);
?>
<? if( $instagram_array['pagination']['next_max_id'] != "" ): ?>
More
<? endif;?>
.... print instagram data....
Instagram AJAX Demo
http://jsfiddle.net/ajhtLgzc/
Here's my piece of code(full body code):
<body>
<script type='text/javascript'>
function AddEvent(Syear, Smonth, Sday, Eyear, Emonth, Eday, hallNumber){
...
}
</script>
<?php
function GetMonthByCoding($first , $second , $third) {
...
}
function GetDateByCoding($coding){
...
}
function GetDateFromLine($line){
...
}
$userid = '...';
$magicCookie = 'cookie';
$feedURL = "...";
$sxml = simplexml_load_file($feedURL);
foreach ($sxml->entry as $entry) {
$title = stripslashes($entry->title);
if ($title == "HALL") {
$summary = stripslashes($entry->summary);
$date = GetDateFromLine($summary);
echo ("<script type='text/javascript' language='JavaScript'> AddEvent(" . $date['start']['year'] . ", " . $date['start']['month'] . ", " . $date['start']['day'] . ", " . $date['end']['year'] . ", " . $date['end']['month'] . ", " . $date['end']['day'] . "); </script>");
}
}
?>
</body>
AddEvent() is JavaScript function defined earlier.
What I get in my browser is:
entry as $entry) { $title = stripslashes($entry->title); if ($title == "HALL") { $summary = stripslashes($entry->summary); $date = GetDateFromLine($summary); echo (""); } } ?>
Looks like it was an echo but as you can see there is no echo right in the middle of foreach.
Can anyone say what I am doing wrong?
PHP is not installed, or it is not enabled, or the file is not a .php file or the server has not been told to recognise it as a file to parse.
Try View Source and you should see all your PHP code. The only reason part of it shows up is because everything from <?php to the first > is considered by the browser to be an invalid tag.
I found the problem, it was in the name of variable sxml. I renamed it and the problem escaped.
I'm using working on building a WordPress plugin, that uses the Twitter api - but I'm very new to working with Twitter.
I currently have a keyword search form and results working
<?php
// get the keyword from url
$srchterm = $_GET['search_box'];
// encode it for the safe search
$srchterm = urlencode($srchterm);
// search the keyword using Twitter API
$srch_twitts = "http://search.twitter.com/search.atom?q=".$srchterm."";
// use curl to execute the Twitter URL
$twits = curl_init();
curl_setopt($twits, CURLOPT_URL, $srch_twitts);
curl_setopt($twits, CURLOPT_RETURNTRANSFER, TRUE);
$twi = curl_exec($twits);
// here we have the searched result in an array
$search_res = new SimpleXMLElement($twi);
//print_r($search_res);
?>
<?php
/* display the data */
$i = 0;
// displays the search keyword
echo "<p style='padding-left:10px; color:brown'>Your search term is: " . stripslashes($_GET['q']) . "</p>";
// tweets in an array. split it by foreach
// we need only 10 result so, use if condition
foreach ($search_res->entry as $result) if ($i++ < 10)
{
echo "<div id='tweets'>";
echo "<p>$i</p> ";
echo "<div class='avatar'><img src='". $result->link[1]->attributes()->href. "' /> </div>";
echo "<div class='twitcont'>";
echo "<div class='name'>". $result->author->name . "</div>";
echo "<div class='content'>" . $result->content ;
// convert the updated date of tweet to seconds
$twittedSeconds = time() - strtotime($result->updated);
$names = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year');
$seconds = array( 1, 60, 3600, 86400, 604800, 2630880, 31570560);
// find the time difference between present time and tweet time
if($twittedSeconds > 0)
{
for($j = count($seconds) - 1; $j >= 0 ; $j--)
{
$interval = $seconds[$j];
if($twittedSeconds >= $interval)
{
$getTime = round($twittedSeconds / $interval);
if ($getTime > 1)
{
$names[$j] .= s;
}
$time = $getTime. ' ' . $names[$j] . ' ago';
break;
}
}
//echo the time difference
echo "<div class='time'> " . $time . "</div>";
}
echo "</div>";
echo "</div></div>";
}
?>
My question:
How can I integrate a tweet button for each result - this would allow the admin to (after searching twitter for keyword matches) tweet back on conversations.
Please see this example: http://screencast.com/t/2xBkTyUHT
Find the tweet id then attach a hyper link of this format
https://twitter.com/intent/tweet?in_reply_to={tweet id}
So the link might look like this.
$tweet_id = substr($entry->id, strrpos($entry->id, ':')+1);
echo "Reply";
More information can be found here. Twitter Web Intents
Note: You put echo "<div id='tweets'>"; in a loop. Means DOM will have multiple elements with same id. Correct it either using class or put it outside the loop.
I have a question.
How can display a text while 4 days in PHP ?
Example : I wrote a post today, and I want display "New" while 4 days and hide this after that.
Thanks a lot.
This is NOT specific to WordPress, and you'll want to remove the foreach loop for actual use.. but it should give you an idea of how to compare relative dates:
<?php
$sample_dates = array(
'2011-02-17',
'2011-02-18',
'2011-02-19',
'2011-02-20',
'2011-02-21',
'2011-02-22',
'2011-02-23'
);
$post_date = '2011-02-17';
foreach ($sample_dates as $date_today) {
echo '<p>If today is ' . $date_today . ', the post from ' . $post_date . ' is: ';
if (strtotime('+4 days',strtotime($post_date)) >= strtotime($date_today)) {
echo 'NEW';
} else {
echo 'OLD';
}
echo '</p>' . PHP_EOL;
}
?>