Skip to content


Coordinates Finder with Google Maps

This article is about how to find coordinates by moving around the map using Google Maps JavaScript API V3.

The example, I have started from is Find latitude and longitude with Google Maps (using V2).

And here is the upgrade:

<input type=”text” value=”" id=”latitude” name=”latitude” />
<input type=”text” value=”" id=”longtitude” name=”longtitude” />

<div id=”map_canvas” style=”width: 100%; height: 500px”><!–  –></div>
<script type=”text/javascript” src=”http://maps.google.com/maps/api/js?sensor=false”></script>
<script type=”text/javascript”>

function loadCoordinatesFinder(aLat, aLng)
{
var latlng = new google.maps.LatLng(aLat, aLng);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById(”map_canvas”), myOptions);

var marker = new google.maps.Marker({
position: map.center,
map: map,
draggable: true
});

google.maps.event.addListener(marker, “dragend”, function() {
var point = marker.getPosition();
map.setCenter(point);
populateLatLng(point);
});

google.maps.event.addListener(map, “dragend”, function() {
var point = map.center;
marker.setPosition(point);
populateLatLng(point);
});

}

function populateLatLng(aLatLng)
{
$(”#latitude”).val(aLatLng.lat().toFixed(5));
$(”#longtitude”).val(aLatLng.lng().toFixed(5));

}
loadCoordinatesFinder(42.67217, 23.36631);
</script>

Enjoy!

Posted in JavaScript.

Tagged with , , , , .


Remove tooltips - jQuery Tools

Recently I met a problem implementing ajax form validation, in particular errors displaying.

I used jQuerry Tools (tooltip tool). Errors were displaying perfectly, but when I filled in form field with a valid value the error message was still there. The problem was that I have not erased error tooltips on validation start.

This is how to remove tooltips programatically

$(’input’).attr(’title’, ”).data(’tooltip’, null);
$(’.tooltip’).remove();

Posted in JavaScript.

Tagged with , , .


How to remove html select options using jQuery

Most examples you will find in the web tell you

$(’#your_select’).html(”);

And it works!

But what happens if after that you want to add some options to your select control, for example

$(’#your_select’).append(’<option value=”xxx”>yyy</option>’);

It doesn’t works … on IE.

And here is the solution

$(’#your_select’).find(’option’).remove();

Posted in JavaScript.

Tagged with , , .


Synchronizing Your Zend Studio Project with a Linux Server

Many web developers prefer to keep their projects consistently synchronized with a staging server. This enables previewing how the code works and debugging it on the server right away. Currently, Zend Studio has very limited support for such a scenario. However, the functionality of Zend Studio can sometimes easily be extended using the Eclipse platform features.

This article suggests a way to synchronize your projects with a remote Linux server using ‘rsync’.

Here is the source article - How to Keep Your Zend Studio Project Synchronized with a Linux Server

Posted in Zend Studio.


OpenInviter like a Zend Framework compatible library

This tutorial presents one way to use OpenInviter (version 1.7.6) like a library in your Zend Framework projects.

The steps:

  • Download and “install” OpenInviter from here.
  • Test if OenInviter works.
  • Lets suppose that you’ve installed it in MyProject/library/OpenInviter and you are using Zend autoloading.
  • Create file MyProject/library/OpenInviter/Service.php and paste the code from below in it.
  • Modify openinviter.php, method startPlugin if (!class_exists($plugin_name)) require_once($this->basePath.”/plugins/{$plugin_name}.plg.php”); with require_once($this->basePath.”/plugins/{$plugin_name}.plg.php”); I know that it’s not good practice to change library code, but this modification will prevent some restrictions on your project’s autoloading.
  • Show the demo:

<?php

class TestsController extends Zend_Controller_Action
{

public function openInviterAction()
{
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);

$inviter = new OpenInviter_Service();

p($inviter->getPlugins());// get all services
p($inviter->getPlugins(’email’));// get all services
p($inviter->getPlugins(’email’, ‘gmail’));// get gmail plugin properties
p($inviter->getPlugins(’email’, ‘gmail’, ‘version’));// get gmail plugin version

// get contacts
p($inviter->getContacts(’me@example.com’, ‘mypass’, ‘example’));

}

}

* p() is a print function.

Service.php

<?php

require_once ‘openinviter.php’;

/**
* This class is the connection between OpenInviter service and Zend Framework.
* The class is implemented only for extracting contacts.
*
* @tutorial
*
*         $inviter = new OpenInviter_Service();
*
*       p($inviter->getPlugins());// get all services
*      p($inviter->getPlugins(’email’));// get all services
*       p($inviter->getPlugins(’email’, ‘gmail’));// get gmail plugin properties
*       p($inviter->getPlugins(’email’, ‘gmail’, ‘version’));// get gmail plugin version
*
*       // get contacts
*       p($inviter->getContacts(’me@example.com’, ‘mypass’, ‘example’));
*
*
* @author stoil
* @link http://openinviter.com/
* @uses OpenInviter 1.7.6
*
*/
class OpenInviter_Service
{
const PATH_PLUGINS = ‘plugins/’;

protected $_messages = array();
protected $_plugins;
protected $_openInviter;

/*~~~~~~~~~~ private methods ~~~~~~~~~~*/
private function _loadPlugins()
{
if($this->_plugins === null) {
$this->_plugins = $this->getOpenInviter()->getPlugins(false);
}
}

/*~~~~~~~~~~ protected methods ~~~~~~~~~~*/

protected function _addMessage($code, $message, $type = ‘error’)
{
$this->_messages[$type][$code] = $message;
}

protected function _initAutoload()
{
set_include_path(
dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . self::PATH_PLUGINS.
PATH_SEPARATOR.
get_include_path()
);
}

/*~~~~~~~~~~ constructor ~~~~~~~~~~*/

public function __construct()
{
$this->_initAutoload();
$this->_openInviter = new openinviter();
$this->_loadPlugins();
}

/*~~~~~~~~~~ public methods ~~~~~~~~~~*/

/**
* Update plugins
*/
public function updatePlugins()
{
$this->_plugins = $this->getOpenInviter()->getPlugins(true);
}

/**
* Get plugin(s), provider(s) or provider details
* @param $type
* @param $provider
* @param $detail
* @return unknown_type
*/
public function getPlugins($type = null, $provider = null, $detail = null)
{
if ($type !== null) {
if ($provider !== null) {
if ($detail !== null) {
return $this->_plugins[$type][$provider][$detail];
} else {
return $this->_plugins[$type][$provider];
}
} else {
return $this->_plugins[$type];
}
} else {
return $this->_plugins;
}
}

/**
* @return openinviter
*/
protected function getOpenInviter()
{
return $this->_openInviter;
}

/**
* Get system messages
* @param string $type
* @return array
*/
public function getMessages($type = null)
{
if($type !== null) {
return $this->_messages[$type];
} else {
return $this->_messages;
}
}

/**
* Get email clients
* @param string $email
* @param string $password
* @param string $provider
* @return array
*/
public function getContacts($email, $password, $provider)
{
$contacts = array();

$this->getOpenInviter()->startPlugin($provider);

$internalError = $this->getOpenInviter()->getInternalError();
if ($internalError) {
$this->_addMessage(’inviter’, $internalError);
} elseif (! $this->getOpenInviter()->login($email, $password)) {
$internalError = $this->getOpenInviter()->getInternalError();
$this->_addMessage(
‘login’,
($internalError
? $internalError
: “Login failed. Please check the email and password you have provided and try again later !”
)
);
} elseif (false === $contacts = $this->getOpenInviter()->getMyContacts()) {
$this->_addMessage(’contacts’, “Unable to get contacts !”);
}

return $contacts;
}

}

I know that it’s not perfect and fully implemented but the aim here is to present the idea.

Posted in Zend.

Tagged with , .


Connecting to the Zend_Amf_Server from Flash

It spent almost 4 hours to implement and run zend amf example reading this manual http://framework.zend.com/manual/en/zend.amf.server.html#zend.amf.server.flash . Believe me, it’s frustrating for a man that have never touched action script.

So I decided to post this hoping it will help somebody.

These are the steps you have to follow:

  • Create your service provider class. For example:

<?php

class Service_World
{
/**
*
* @param string $name
* @param string $greeting
* @return string
*/
public function hello($name, $greeting = ‘Hello’)
{
return $greeting . ‘, ‘ . $name;
}
}

  • Create some url that you will put your service. For example:

<?php
class Admin_ServicesController extends Zend_Controller_Action
{
public function init()
{
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout->disableLayout();
}

public function flashAction()
{
$server = new Zend_Amf_Server();
$server->setProduction(false);
$server->setClass(’Service_World’);
$response = $server->handle();
echo $response;
}
}

  • Download and install Addobe Flash CS<3,4,..> and follow steps from manual to create *.fla and *.as.
  • If you are new at flash here …. everything ends.
  • But…..
  • Try with this action script:

package {
import flash.display.MovieClip;
import flash.events.*;
import flash.net.NetConnection;
import flash.net.Responder;

public class Main extends MovieClip {
private var gateway:String = “http://nikon.cmonjour.bg/admin/services/flash”;
private var connection:NetConnection;
private var responder:Responder;

public function Main() {
responder = new Responder(onResult, onFault);
connection = new NetConnection;
connection.connect(gateway);
onComplete();
}

public function onComplete( e:Event=null):void{
var params = “Sent to Server”;
connection.call(”Service_World.hello”, responder, params);
}

private function onResult(result:Object):void {
// Display the returned data
trace(String(result));
}
private function onFault(fault:Object):void {
trace(String(fault.description));
}
}
}

The difference is that you call the onComplete() method in your Main() method.

Other solution is to create a button and attach onComplete() to it.

Attemping to launch and connect to Player using URL D:WEBWebServerApache2htdocsZend_Amf_TestZendExample.swf
[SWF] D:WEBWebServerApache2htdocsZend_Amf_TestZendExample.swf - 1281 bytes after decompression
*** Security Sandbox Violation ***
Connection to http://example.com/services/flash halted - not permitted from file:///D|/WEB/WebServer/Apache2/htdocs/Zend%5FAmf%5FTest/ZendExample.swf
– Untrusted local SWFs may not contact the Internet.
SecurityError: Error #2028: Local-with-filesystem SWF file file:///D|/WEB/WebServer/Apache2/htdocs/Zend%5FAmf%5FTest/ZendExample.swf cannot access Internet URL http://example.com/services/flash.
at flash.net::NetConnection/connect()
at Main$iinit()[D:WEBWebServerApache2htdocsZend_Amf_TestMain.as:15]
Cannot display source code at this location.

  • That’s all :) Juts run your flash file.

If you have any problems running example or improvement suggestions, please contact me.

Posted in Zend.

Tagged with , , .


Zend Framework project structure

In this post I rely that you are using subversion.

Note that I’m not starting from the real beginning….

Library directory.

There are some ways to add library to your project:

  • Svn Externals: This method is good when you have something like a referenced project(s) and every moment projects have to be synchronized.
  • Put wanted library directly in your application/library folder - this is used when you want your project to contain all needed sources and libraries.
  • Use external library, situated on your web server. This technique is used when you have many projects that use one library. Note that in this case the project have to contain a library description (name, version, …) needed for easily installation. Another feature is that if your library is not in svn it’s difficult to synchronize eventual modifications on it.

Posted in IT, PHP.


Some notes about ZF 1.8 and upper

Bootstrap’s _init methods have to be used to store resources that will be used by application (Plugins and Controllers). If you need functionality that will be used everywhere you need a plugin or a simple class that handle it.

Posted in PHP.


Присъединяване на нов ел. абонат

След дълго ровене, звънене и email-и по електроразпределителни(ЕР) дружества, комисии и т.н. стигнах до извода, че да търсиш логика в много от процедурите и цените на ЕР дружества е до голяма степен загубена кауза.

Така и не проумях през цялото време какво толкова има в услугата “Присъединяване на нов абонат”, че минималната цена за нея е 444 лв.Ето задачата, която си поставих и не можах да реша.

  • Тази услуга е се върши от 2-ма души за 1-2 часа.
  • Материалите, които се влагат при нейното изпълнение остават собственост за дружеството.
  • Какво плащам аз?

Едно примерно решение е - “цената на това да живея в България”. Ако все пак някой намери решение - нека пише.

Един интересен факт - в цената на всички услуги се залага разход за бензин на цена 2,4.. (не си спомням точно). Средно за изминалата година цената ако не се лъжа е около 1.85 лв/л.

Няма да продължавам, мисля че няма смисъл. Ето само няколко линка:

Ред за присъединяване към мрежата на ЧЕЗ

Цени, определени от ДКЕР

Posted in Разни.


Object Oriented Analysis and the Unified Process

The notes are based on Craig Larman’s book “Applying UML and Patterns”.

Analysis and Design

Analysis and design have been summarized in the phase do the right thing
(analysis), and do the thing right (design)
.

The Unified Process

Given many possible activities from requirements through to implementation, how should a developer or team proceed? Requirements analysis and OOA/D needs to be presented in the context of some development process. In this case,
the well-known Unified Process is used as the sample iterative development process within which these topics are introduced.

The process consists of these 4 steps:

  1. Define Use Cases
  2. Define Domain Model
  3. Define Interaction Diagrams
  4. Define Design Class Diagrams

The Most Important UP Idea is Iterative Development. Development is organized into a series of short mini-projects called iterations. The system grows incrementally over time, iteration by iteration.

Posted in IT.

Tagged with , , .