ideas....

First I just want to say Thank you to ALL you guys. I also want you to know why…

This is THE only PHP forum that offers help. I have been to other forums and they just do not answer questions and if they happen to it’s rudely and rarely with any kind of explanation. You guys here are just AWESOME!!!

Where I can I link back to your site to show people that I have gotten help from here. I’m thinking I am going to write a module that links back to this forum Thanking you guys for ALL the help you’ve given me.

Once again HUGE Thanks for your patience, kindness and understanding with us all!

OK now to it…

I have written a ‘module’ that displays the Holidays [American] by reading an xml file [Thanks to JimL for the foreach lesson!! LOL]

Now what I’d like to do is match and image with something to trigger it to show that image…

Here is the code that I am using and it’s working fantastically…

[php]

<?php defined ( '_JEXEC' ) or die (); require_once( dirname(__FILE__) . '/helper.php' ); JHtml::stylesheet('modules/' . $module->module . '/assets/css/CoverPop.css'); JHTML::script('modules/' . $module->module . '/assets/js/CoverPop.js',true); $ufc = $params->get('ufont'); $tfc = $params->get('tfont'); $hfc = $params->get('hfont'); $user = JFactory::getUser(); $u = $user->username; $url = ("localhost/joomla/modules/mod_holiday/assets/xml/Holidays.xml"); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($data); foreach ($xml->event as $listing) { $dates= ($listing->date); $names= ($listing->name); $desc= ($listing->description); date_default_timezone_set("America/New_York"); $d = date("Y-m-d", time()); if ($dates == $d) { ?>
    <div id="CoverPop-cover" class="splash">
    <div class="CoverPop-content splash-center">
    <h2 class="splash-title"><font color=<?= $hfc ?> size=100%>It's Holiday Time!</font></h2>
    <BR><BR>
    <p class="splash-intro"><font color=<?= $tfc ?> size="5"><?= $names ?></font> <font color=#<?= $ufc ?> size="5"><b><?= $u ?></b></font></p>
    <BR><BR>
    
    <p class="close-splash"><font color=#000 size="2">Hit ANY key to close</font></p>


    
</div> 
<?php } } ?>

[/php]

I did it that way because I’m only after two keys in the array so it works for me… :slight_smile: Maybe not the best way but it works… I took this from about 275 lines down to what you see… again Thanks JimL for the lesson!!!

SO I’m trying to match an image to a date…

Could I do it by naming the image the same as the date then matching it that way? Or is there an easier way to do it?

In case it’s needed here’s the xml…

<events>
<event>
<date>2015-02-13</date>
<name>Happy Test Day</name>
</event>
<event>
<date>2015-01-01</date>
<name>New Year's Day</name>
<flag_day>1</flag_day>
<url>http://en.wikipedia.org/wiki/New_Year%27s_Day</url>
<description>New Year's Day is observed on January 1, the first day of the year on the modern Gregorian calendar as well as the Julian calendar used in ancient Rome. With most countries using the Gregorian calendar as their main calendar, New Year's Day is the closest thing to being the world's only truly global public holiday, often celebrated with fireworks at the stroke of midnight as the new year starts. January 1 on the Julian calendar currently corresponds to January 14 on the Gregorian calendar, and it is on that date that followers of some of the Eastern Orthodox churches celebrate the New Year.</description>
</event>
<event>
<date>2015-01-19</date>
<name>Martin Luther King, Jr. Day</name>
<flag_day>1</flag_day>
<age>86</age>
<url>http://en.wikipedia.org/wiki/Martin_Luther_King,_Jr._Day</url>
<description>Martin Luther King, Jr. Day is a United States federal holiday marking the birthday of Rev. Dr. Martin Luther King, Jr. It is observed on the third Monday of January each year, which is around the time of King's birthday, January 15. The floating holiday is similar to holidays set under the Uniform Monday Holiday Act, though the act predated the establishment of Martin Luther King, Jr. Day by 15 years.</description>
</event>

This isn’t the entire xml but it’s too large to put here… so I just put the first three… this file goes through 2020 :slight_smile:
Thank you!!

Ok well Thank you all again!! :wink:

I figured this out:

[php]
$dir = ‘modules/mod_holiday/assets/images’;
$files1 = scandir($dir);
$subject = date(“m-d”, time());
$s = ($subject.".png");
foreach ($files1 as $subjects) {
if ($subjects == $s)
{ ?>
<img src=modules/mod_holiday/assets/images/<?= $s ?>’>

<?php } } [/php] put in the correct place within the code and BINGO... it works... may be not the best but it works LOL

PS… I just renamed all my images to the date format ie 02-14.png and compared that to the date +png and it spits it out … nice and easy.

There it is in all it’s glory LOL If there’s an image that matches the date it shows, if not it doesn’t but the popup still works…

[php]

<?php defined ( '_JEXEC' ) or die (); require_once( dirname(__FILE__) . '/helper.php' ); JHtml::stylesheet('modules/' . $module->module . '/assets/css/CoverPop.css'); JHTML::script('modules/' . $module->module . '/assets/js/CoverPop.js',true); $ufc = $params->get('ufont'); $tfc = $params->get('tfont'); $hfc = $params->get('hfont'); $user = JFactory::getUser(); $u = $user->username; $url = ("modules/mod_holiday/assets/xml/Holidays.xml"); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($data); foreach ($xml->event as $listing) { $dates= ($listing->date); $names= ($listing->name); $desc= ($listing->description); date_default_timezone_set("America/New_York"); $d = date("Y-m-d", time()); if ($dates == $d) { ?>
    <div id="CoverPop-cover" class="splash">
    <div class="CoverPop-content splash-center">
    <h2 class="splash-title"><font color=<?= $hfc ?> size=100%>It's Holiday Time!</font></h2>
    <BR>
     <?php $dir    = 'modules/mod_holiday/assets/images';
		$files1 = scandir($dir);
		$subject = date("m-d", time());
		$s = ($subject.".png");
			foreach ($files1 as $subjects) {
		if ($subjects == $s)

{ ?>

<?php } } ?>

size="5"><?= $names ?> size="5"> <?= $u ?>



[Hit ANY key to close]

<?php } } ?>

[/php]

Dude,

I see JimL help you learn a lot. Nice! He is very good on this forum from what I have seen.

I find that one of the largest issues with designing a project is the data format and naming conventions.

So, I suggest that you think ahead and name your files with very exact details. If the picture or image was
uploaded by the site, such as a gallery page, you have to think ahead that two items may end up with the
same name if you use just the date. If you only allow one image per day, that is great. So, using a filename
that has just the date 02-14.png is great if you only allow one per day.

What all this is about is making you think before you design your page. How the file is named can make a
big speed increase in future parts of the code. I did a project for a realty company once and they wanted
three pictures of a property (landscapes), so it was easy. Property-number-1,2,3… But, I allowed for larger
numbers and that was good as they beefed it up later on.

Anyways, since you mentioned you were fairly new to some of this, I thought I would mention thinking way
ahead of what you are doing today. Data layouts and file name conventions are one thing to decide on at
the very beginning of your project.

Just F.Y.I. Good luck with the rest of it…

1 Like

No I don’t ever mind input… it helps the learning process, so Thank you!!!

I have to agree with you because I looked at the xml file in more details and I see that although the major dates Valentines day… Christmas… Thanksgiving… won’t change… BUT days like Martin Luther King Day will change so the number picture idea won’t work past this year…

Not because it’s too difficult to figure out I was honestly thinking before this post I might just display no image or just use my site name…

BUT in thinking it through I could use the name of the actual ‘holiday’ and rename the pictures accordingly… that way it’ll work yearly… you know christmas.png…etc… because in the key I am getting the name…
I would have to really think that out because the name return would be Christmas Day and I would have to figure out how to just grab the first part ‘Christmas’ and compare it to the image directory so if you have ideas please share I don’t mind at all.

I also JUST found out that my method for opening the xml is no good… the module wouldn’t fire because it wouldn’t open the xml on my server so for the time being I’m having it go outside to grab it… I’d prefer to have it and not over burden their server… as Jim suggested it’s just a good guy thing to do and I have to agree… I don’t want to overburden them to accomplish my goal…

So I will play around more with SimpleXML on a test dir to see what works :slight_smile:

Thanks again for the input, as a learner I sure do appreciate it!!! And Yes Jim is a great guy and very helpful! You all are!

Well, yes, I would use the name of the holiday. Makes more sense. And, there are functions that will tell
you if today is a holiday, so you can use those to pull the holiday. You can save the picture with a space
in it’s name, but, that is considered bad form. Most use underscores instead of the spaces. So, if you pull
a holiday like “Christmas Day”, you can use the str-replace function to replace the space with another char
like underscore.

As far as XML goes, PHP has XML built-in now and it uses very little overhead, so seldom causes an issue
with servers. But, SimpleXML might be, well, simpler… LOL Here is a sample tutorial on how to use if for a
song list. But, I think you will understand how to alter it for your holiday list.
http://blog.teamtreehouse.com/how-to-parse-xml-with-php5

Hope that helps…

Yes it does, very much and I really appreciate the input!!

As fate would have it… I was also working on an Anniversary date thing for users… when they hit the date they signed up it shows them and Thanks them… and that is where I used the 4 digit date… it worked like a charm and that never changes and is only driven towards the single user so it works awesome!! LOL So what I learned from that is that nothing is wasted :wink:

I will look at that xml example, Thanks for sending it to me!!!

No problem! Glad to help. And, yes, nicely done on the anniversary dates…

Thinking out the data is one of the first design tasks when starting out. Sounds like you are on your way!

Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service