Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Saturday, 28 March 2015

PHP download FTP file and convert from ANSI to UTF-8

So, I have a file, and I'm using Joomla with CSVI to import the file from an ftp server into the database. The file is automatically made by a third party, and it is in ANSI format.

This file contains '£' which CSVI and Joomla do not like when it is in ANSI format. I need to convert it to UTF-8 in order to import such characters. Of course to convert, I will need to store locally as well. Here's my research:

First thing is to get the file and store on server:

Found the PHP function ftp_get

Once on the server, I found two ways to convert:
mb_convert_encoding()
iconv()

this is quite helpful for getting and writing the file:
$file = file_get_contents('file.php');
$file = iconv('greek-charset','UTF-8', $file);
file_put_contents('file.php', $file);
//ta-da!

Saturday, 7 February 2015

Drupal views slideshow image as css style background

Thought I'd document this as I will probably do this in future developments.

I wanted a views slideshow, with the images appearing full screen with text ontop. It appears simple at first but actually required more digging.

Backstretch does not work with views slideshow, as it applies the image background to elements not within the slideshow.

I found a slightly helpful article which suggested a fix, but later found the forum from where more helpful information was taken.

to sum it up, you need views to output the url of the image for the field, and then use a views template override to get this url and 'render' it inside a html element as the background-image style.

To do this:

  1. Get views to output the url of the image
    1. in the views view, add a Relationship
      1. this needs to be a 'File Usage: file'
    2. next add a field '(file) File Path
      1. in this field, tick the box titled:
        1. Display download path instead of file storage URI
  2. Now to render this URL inside a HTML element you need a template override
    1. In views veiw, go to 'Other' > 'Theme' > 'Information'
      1. find the template override for the field
      2. create a new file with that exact name and place it in your theme
    2. inside this file paste this:
      1. <div class="mainImage" style="background-image:url('&lt;?php print $output;?&gt;');">&lt;!--<img src="&lt;?php print $output;?&gt;"style="visibility:hidden; "></img>--&gt;</div>
    3. Done
You can now style this .mainImage div as:
.mainImage {
position: fixed;
height: 100%;
width: 100%;
top: 0px;
left: 0px;
z-index: -2000;
background: no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

sorted.

It now changes with the views slideshow.

Sunday, 11 January 2015

Jquery slideshow with php

So I'm going to make a jquery slideshow into a joomla website. Should be interesting.

Here's a good start

Thursday, 27 November 2014

Adding Google street view to Joomla Estate Agencie JEA

So, even though I have only edited the code in minor ways, it actually took me a long time to do it, but here is the final result! Posted here on JEA forums

Hi, I've had a go at this myself, and finally came up with a solution.
The first thing I did was to go into my template and create an override for JEA Property.
I then edited the "default_googlemap.php" file. From line 44 to the bottom, replace the script with this script:
$script = <<
 
function initMap(mapOptions, panoOptions, MarkerLatlng) {
    map = new google.maps.Map(document.id('jea_property_map'), mapOptions);
    var marker = new google.maps.Marker({
        position: MarkerLatlng, 
        map: map, 
        title: '{$this->row->ref}'
    });
    var panorama = new google.maps.StreetViewPanorama(document.getElementById('jea_property_map_pano'), panoOptions);
  map.setStreetView(panorama);
}
 
window.addEvent("domready", function(){
    var longitude  = {$longitude};
    var latitude   = {$latitude};
 
    if (longitude && latitude) {
        var myLatlng = new google.maps.LatLng(latitude, longitude);
        var options = {
          zoom : 15,
          center : myLatlng,
          mapTypeId : google.maps.MapTypeId.ROADMAP
        };
        var panoramaOptions = {
    position: myLatlng,
  };
        initMap(options, panoramaOptions, myLatlng);
 
    } else {
        var geocoder = new google.maps.Geocoder();
        var opts = {'address':'$address', 'language':'$lang', 'region':'$region'};
        geocoder.geocode(opts, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var myLatlng = results[0].geometry.location;
                var options = {
                  center : myLatlng,
                  mapTypeId : google.maps.MapTypeId.ROADMAP
                };
                var panoramaOptions = {
    position: myLatlng,
  };
                initMap(options, panoramaOptions, myLatlng);
                map.fitBounds(results[0].geometry.viewport);
             }
        });
    }
});
 
EOD;
 
$this->document->addScriptDeclaration($script);
?>
 
I've only modified the original code to add panoramaOptions variable, and pass it to the initMap function. I then added the panorama variable.
 
At the bottom I also added a div tag called "jea_property_map_pano", but you have to give it a height property otherwise you won't be able to see it. The street view loads up in this div tag.

Saturday, 20 September 2014

Drupal Backup and Migrate - how to (in progress)

So, I have a drupal website. I'd like to write down the process of backing up and then restoring upon a complete failure.

So, to backup just use the default backup and set to download. Save these somewhere safe. Just to be safe I also did the same for Public Files Directory and Private Files Directory.

I guess thats the easy part. For the next part I've found it hard to find any documentation on restoring from a complete failure. Here's what I have found:

http://www.anexusit.com/blog/how-restore-backup-migrate-file-using-drush
http://drupal.stackexchange.com/questions/40490/how-to-restore-a-site-from-a-backup-done-with-backup-and-migrate-module-using-dr

Both are related to drush which is a command line shell and scripting interface for Drupal.

My best guess for restore is to install drupal, install drush and run the restore command line.

If you also lose files, then you have to make sure you have backup of all files as well.

I think what I'd really like is the backup utility used with Joomla, Akeeba. This is much easier. I don't even think you need to install Joomla to reinstall. And it backs up all files. There must be a reason it isn't as easy. Oh well.


Saturday, 31 May 2014

Drupal moving database from one server to another

So I wanted to get a site I've been making 'live' which meant transferring from the test server to the real one. How to do this? I remember in Joomla it was as easy as pie, not so with Drupal, although not too tough.

Basically:

  1. move all files
  2. move all tables from database
So, in myPHPadmin you can export, but I was coming up with an error:

Error

SQL query:
--
-- Database: `sitename_pw`
--
CREATE DATABASE IF NOT EXISTS `sitename_pw` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;

 
MySQL said: dot.gif
#1044 - Access denied for user 'my_user_name'@'localhost' to database 'sitename_pw'

So I found this website which explained that you have to export the tables within a database, rather then a whole database. To do this you have to be looking at the database tables, then press the export button to export just the tables.

Then when you import them, you have to be actually in the new database and press the import button

Monday, 24 February 2014

Joomla and emails


Using emails in Joomla has been a slight learning curve. It seems it wants to hide this as much as possible from bots which is nice. So I found this article explaining ways to use emails in joomla

Tuesday, 21 January 2014

Joomla 3 template and bootstrap

So, after making a nice template the same as I'd done in Joomla 2.5, there are some slight differences when you log onto the front-end. Noticably that the cute little icons of yesterday are gone.

Reading into it, there's this new thing called BootStrap. Very good once you get the hang of it. I found a nice tutorial on it here

The main things to do to get bootstrap are:

  1. In the index.php file for your template, right at the top include (tutorial here):
    1. $doc = JFactory::getDocument();
    2. $doc->addStyleSheet($this->baseurl . '/media/jui/css/bootstrap.min.css');
  2. Secondly, make sure the including your stylesheets here
)

Just be sure to override stuff in your template when it pops up.

Wednesday, 8 January 2014

Joomla contacts lists with Photos and misc information

I'm making a website for a client and I want it to be easy for the client to edit the "meet the team" page. Previously I just made an article and add the information in the article and format.

Of course there is the contacts section in Joomla which can be used. A menu item can display all contacts in a list, only problem is also want a photo and the 'misc information' field.

I've looked at a few different extensions, but couldn't find something which simply added these two things to the list view.

I found a forum here which describes how to add the picture to the table in the contacts list view. It involves editing the default_items.php file and inserting:


<th class="item-picture">
   &nbsp;
</th>
<td class="item-picture">
   <?php if ($item->image) : ?>
      <a href="<?php echo JRoute::_(ContactHelperRoute::getContactRoute($item->slug, $item->catid)); ?>">
         <img alt="<?php echo $item->name; ?>" src="<?php echo $item->image; ?>" />
      </a>
   <?php endif; ?> 
</td>

I wonder how hard it is to also get another cell with misc-information in?

To get the misc info in I inserted this code:
<div class="item-misc"> &lt;?php echo $item->misc; ?&gt; </div>


I've also read here that you can override the default_item.php by creating folders with your template directory /com_content/views/featured/

Will need to look into both of these. But not sure if I currently have the time!

So, looking further into it looks like in Joomla 3.2 you can create overrides from within the management system which I found here.

Go into the template files, then there is a tab called "create overrides". Sorted.  I picked the "com_contact" > Featured. This placed some new files in the template directory so that only this template overrides the defaults.

From there you can access the "default_items.php" file.

I basically replaced all li elements with div elements. Then I styled it with CSS

Monday, 6 January 2014

Joomla changing background image depending on menu item

So I want to change the background picture depending upon the page you're on. When I first looked at the problem I thought it'd be easiest to create a Page Class on the menu item, and then within the content area, make an item which appears behind everything (z-depth) and fills the whole screen. The proved quite difficult.

Turns out there is a much easier way, still using the Page Class on each menu item. Found the answer here in a forum, and here in a Joomla Help Page.

Basically, you can use PHP to find the page that is being displayed, and put the class suffix anywhere in the document, i.e. in the
  1. put this code inside the head tag:
    1. <?php $app = JFactory::getApplication(); $menu = $app->getMenu()->getActive(); $pageclass = '';   if (is_object($menu)) $pageclass = $menu->params->get('pageclass_sfx'); ?>
  2. Put this in the tag you want a class to. I.e. the body tag:
    1. <body id="<?php echo $pageclass ? htmlspecialchars($pageclass) : 'default'; ?>">
You can also add another stylesheet to keep the css even more streamlined. Sorted! (oh, by the way, I havent tested any of this!!!!)


Well, after leaving it a while I came up with a problem. The specific page I want to change is a "featured-blog" menu item, so when I put the Page Class, I have to put a space to separate it from the word 'featured-blog'.

But alas, the pageclass picks this up! I had to get a php line in which trimmed the spaces from the pageclass:

$pageclass = trim($pageclass);

Wednesday, 1 May 2013

Contact forms in Joomla and loading modules inside of articles

So I'm wanting to put a contact form up on a page in Joomla in the main content area. The easiest way looks to involve installing a plugin.

Found this free plugin called Rapid Contact. Once installed it is a module.

To load the module up where the main content should go require a little tweaking. Found this article on it.

Basically you make an article which contains a module position:

{loadposition testposition1}


Make a menu item which loads this article.

Then you make the module have the position "testposition1" and make sure it's loaded with the right menus item.

Done


Just found an even better alternative with Joomla 3. Here's the tutorial. Basically:

  1. Create a Contact and make sure the contact form is set to Show.
  2. Create a menu item to link to that contact!

Monday, 23 April 2012

Inventory Booking mechanism for Inventory

Now I'm getting into Joomla, thought I'd check out a few inventory booking extensions. Found one which looks excellent - JomRez

Here's a demo of it on their servers.

With this system I can visualise the situation working as follows:

  1. Browse to the correct webpage
  2. log in
  3. if your a student:
    1. search for the resource
    2. book it out if it is free
  4. if your staff
    1. add resources
    2. check booking status
    3. sign back in
    4. search for free resources
Questions
  1. could it use Active Directory logins?
    1. Yes, I think so. Found this forum on the topic although couldn't look at it
  2. does it manage assets?
One thing I have read is that it is good, but to get it really customised you will probably need to buy the extensions. These generally start at £9.99 and go up to £29.99.

The next thing to do is to test it:

  1. install MAMP
    1. make a new database in myphpadmin
      1. I named it "inventory"
  2. install Joomla
  3. download JomRez and install
    1. found this article on how to install
      1. download Download jomres_webinstall.zip or just jomres_webinstall.php
      2. Place this in the root of the joomla
      3. run the jomres_webinstall.php in the browser
        1. this came up with:
          1. We are unable to comunicate with the updates server, you might have a firewall preventing your server from communicating with the jomres.net servers. You should create some rules that allow your server to communicate with the domains "updates.jomres4.net", "plugins.jomres4.net" and "license-server.jomres.net"
          2. I could ping all of these from my machine?
        2. So, might as well just install it manually
      4. Nope, can't find the manual install zip.
      5. installed it on a server using the webinstall and worked fine
  4. add assets
    1. as it's geared for hotel bookings the only way I've thought of doing it is to add each asset as a room in a hotel.
    2. I'd have to go into the database and find the room type and add a different room type for each different item we had.
  5. test asset management
    1. can't really manage assets
  6. test booking mechanism
  7. test logins
Well, to conclude, if I want this to work as an inventory management utility I'd need to buy plugins. It's ridiculously restricted.

The way I can concieve to make it work is to have the college as a hotel, and it have 'room types'. You can have a number of each room type, each bookable. Too confusing.

Had another look on Joomla and found only paid things! Doh! Can't get everything for free. I shall go back to Access Databases.

Sunday, 19 February 2012

Transferring from blogger/blogspot to joomla

So, I'm hoping to make a website for myself, which I want this blog to be a part of. But how to do it. Well, at first I thought I'd just have it as a feed, but actually I want to incorporate it fully into the joomla site. So.... here's what i found on the amazing thing called the internet:

Found on this forum

  1. Export xml from blogger
  2. import to wordpress
  3. export from wordpress to joomla
Looks like wordpress is the go-between. Not found anything more recent then 2009, so maybe there is a straight blogger to joomla extension?

Found a how to website with information on the wordpress to joomla conversion. Need to install JoomBlog extension.

Also found this blog on how to do it. Costs $15 to by feed2post though

Just had a quick search on the extensions directory for joomla and found this PLo Blogger, which duplicates blogs on your joomla site onto your blogger site. This would be a good way to have them both up and running, and not loose any followers and such.

The question is: Is it worth the hassle? Perhaps keep blogger going, and make a new blog for other things on the joomla site. Might be the best thing to do?

Wednesday, 15 February 2012

Joomla on a Mac

So, I've been trying out the cloudaccess.net version of Joomla and I thought I'd try the totally free downloadable version, mainly to see the differences and also to perhaps edit files more locally.

Just read up on the txt file which comes with the download, takes you to this page for installation requirements. At the bottom of the page it says there is a quicker way then installing all the little things; MAMP, Macintosh, Apache, Mysql and PHP

So... here's how I did it:

  1. Download MAMP and install
  2. run MAMP from applications folder
    1. Go to "Open Start Page" or open browser and type : http://localhost:8888/MAMP
    2. Go to MyPHPAdmin
      1. Name a new database and click create
  3. Now download Joomla
    1. unzip it (if safari doesn't)
      1. Put the new folder in /Applications/MAMP/htdocs
    2. In the web-browser go to http://localhost:8888/Joomla_2 (or whatever folder you've named it)
    3. It now takes you through the Joomla installation
    4. One point I got stuck on was the database name. Type in the database name you created in MyPHPAdmin
    5. The default password for the database thing is:
      1. username = root
      2. password = root
      3. I wouldn't change these if I were you. If you do:
        1. Go to MAMP/bin/mamp/index.php and change the password bit
        2. Got to MAMP/bin/MyPHPAdmin/config.inc.php and change the password bit in here too
  4. Done!!
I'm going to try and download the joomla site I made on cloudaccess.net and put it on the computer? I shall hopefully write a post and stick it up here.


Notes:

Had this error message come up:

Could not connect to the database. Connector returned number: 2

Turns out I didn't create the database and/or put the right password in. It would be easier if Joomla could do this bit?

I'd gone and changed the password for root in MAMP!! Doh, I ended up having to look for where the password entries were for each part of MAMP. Found the main two:


  1. Go to MAMP/bin/mamp/index.php and change the password bit
  2. Got to MAMP/bin/MyPHPAdmin/config.inc.php and change the password bit in here too



How can I change the password for the MySQL database?



Open the terminal and type the following:
/Applications/MAMP/Library/bin/mysqladmin -u root -p password

Instead of 
 use the new password you want.
Afterwards, you also need to change the password for phpMyAdmin and other scripts which are running under MAMP. You can change the password for phpMyAdmin in the file /Applications/MAMP/bin/phpMyAdmin-X.X.X/config.inc.php

Saturday, 11 February 2012

which Content Management System to use?

What with all the new websites about these days, with constantly updating and interactive elements, it is too daunting to learn php or asp so why not use a content management system?

Well, I think I'll try some out and then I'll be more able to answer that question. I had a quick look around and found this informative blog, which gives a nice little list of free ones. Here are some of the most popular and nice looking, and almost most importantly, free:


I'll carry on here when I've had some playing about.


Well, I'm still having a good look at Joomla. Seems good but a little complicated when you first have a look at it. I'm finally getting there. Here's what the joomla site currently looks like.

I've just found this wiki which describes how to begin templating, which is ultimately how I will make the website. It'll take a bit of getting used to, but essentially all I'll have to get used to is using the special php references to put the content in. You then use CSS to style all the html you made in the template.

Whilst looking through the joomla wiki I found that it might be easier to start off editing the "beez" template, which they claim to be highly adaptable! Heres the wiki