Conversie cod culori din Hexadecimal in RGB folosind PHP


function hex2rgb($hexCode) {
$hexCode = str_replace("#", "", $hexCode);

if(strlen($hexCode) == 3) {
$r = hexdec(substr($hexCode,0,1).substr($hexCode,0,1));
$g = hexdec(substr($hexCode,1,1).substr($hexCode,1,1));
$b = hexdec(substr($hexCode,2,1).substr($hexCode,2,1));
} else {
$r = hexdec(substr($hexCode,0,2));
$g = hexdec(substr($hexCode,2,2));
$b = hexdec(substr($hexCode,4,2));
}
$rgbCode = array($r, $g, $b);
return $rgbCode; // intoarce un array cu valorile [0]=R, [1]=G, [2]=B
}


$rgbArr = hex2rgb("#ffffff");
$rgb =implode(",", $rgbArr ); // intoarce valorile RGB separate prin virgula

Aplicabilitate
Setare culoare background dinamic cu opacitati diferite:

<style>

.fullOpacity{background:rgb(<?php echo($rgb); ?>)}
.halfOpacity{background:rgba(<?php echo($rgb); ?>, 0.5)}
.minOpacity{background:rgba(<?php echo($rgb); ?>, 0.1)}
.higherOpacity{background:rgba(<?php echo($rgb); ?>, 0.8)}
…..
</style>

Trimiterea de emailuri din PHP folosind autentificare SMTP

1. Creati fisierul emailtest.php
2. Copiati codul urmator in fisierul creat la 1)

";
$to = "Receiver";
$subject = "Test";
$body = "Email sent";
$host = "webiste_domain.com";
$username = "no-reply@webiste_domain.com";
$password = "password of the no-reply email account";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("

" . $mail->getMessage() . "

");
} else {
echo("

Message successfully sent!

");
}
?>

3. Salvati fisierul si copiati-l in radacina site-ului
4. accesati fisierul in browser folosid calea directa. Ex: www.webiste.com/emailtest.php
5. In cazul in care nu au aparut erori se va afisa un mesaj de succes. Emailul va fi trimis catre adresa specificata
6. In cazul in care au aparut erori acestea vor fi afisate in pagina.
6.1 Daca eroarea este legata de serverul de smtp solicitati aceasta informatie de la provederul de hosting.

Scrierea instructiunilor pentru instalarea / utilizarea unei aplicatii.

O corvoada in general, nu-i asa? Ce poate fi atat de greu sa urmezi “aceste instructiuni simple” cand totul merge aproape de la sine?
Ei bine, privind din partea cealalta, a persoanei care trebuie sa le urmeze, am avut o revelatie.
Citind un set de instructiuni vagi esti pus is situatia fie de a recunoaste ca esti incapabil sa intelegi ceva “atat de simplu” fie sa consideri ca cel care le-a scris nu a facut o treaba deloc stralucita.
ADN-ul tau va prostesta vehement in fata primei optiuni drept pentru care nu iti mai ramane altceva de facut decat sa soliciti mai multe detalii, sa pui intrebari, sa ceri lamuriri.
Daca dupa ce primesti un document actualizat esti la fel de nedumerit ca prima data deja ti se creeaza un sentiment de frustare, capeti o atitudine ostila fata de autorul acelor texte fara noima si ceri refacerea lor pe un ton ceva mai artagos.
In cazul in care ajungi la a treia incercare cel mai probabil ai sa renunti la a utiliza ceva atat de prost facut, atat de incalcit si vei opta pentru ceva mai simplu.

Pentru a nu ajunge in situatia in care un proiect va este refuzat din motivele expuse mai sus am sa mentionez o lista de sfaturi pentru a preveni unele dintre problemele ce pot aparea:
1. Incepe cu o scurta descriere , 2-3 fraze in care sa expui ce face aplicatia in beneficiul utilizatorului, de ce ii este necesara;
2. Listeaza instructiunile de configurare, cerintele necesare functionarii aplicatiei incepand fiecare propozitie cu un verb;
3. Nu da optiuni acolo unde nu este cazul. Asta il va obliga pe utilizator sa gandeasca, sa aleaga, iar utilizatorul nu vrea asta, a platit pentru ceva ce trebuie sa mearga;
3.1. Denumeste valoarea implicita iar in cazul in care mai multe variante sunt posibile, enumerale la sfarsit.
4. Nu da detalii inutile pentru utilizatorul final. Nu are niciun interes in complexitatea procedurilor din spatele aplicatiei. Daca va avea astfel de curiozitati o sa le ceara ulterior;
5. Nu amesteca ideile. Daca ai considerat ca sunt necesare detalii suplimentare despre anumite functionalitati, scrie-le separat si fa trimitere la ele;
6. Fa o lista cu probleme cunoscute. Nimic nu este mai neplacut decat ca utilizatorul sa descopere disfunctionalitati. Arata-i ca le cunosti si va avea incredere ca le vei rezolva acolo unde este posibil.

Scopul tau nu este sa ii arati utilizatorului final ca este incapabil, scopul tau este sa ii oferi o unealta care sa il ajute, sa ii rezolve problemele si care sa ii arate cat esti tu de capabil. Cel mai probabil va apela la serviciile tale si pe viitor si asta este ceea ce iti doresti, nu-i asa?

Add-on FireQuery – simpla integrarea si rularea lui jquery in pagina web in firefox

About this Add-on

FireQuery is a collection of Firebug enhancements for jQuery. Requires Firebug 1.3 or greater.

Features:

jQuery expressions are intelligently presented in Firebug Console and DOM inspector
attached jQuery data are first class citizens
elements in jQuery collections are highlighted on hover
jQuerify: enables you to inject jQuery into any page

Video cum putem sa-l folosim sursa youtube

Sursa Add-on gasiti aici

jQuery datetime picker problem

Some days ago I run into the following problem with jQuery’s datetime picker.

I have a form that contain a input field that I populate with a date/time picker.  If you populate the form on the server with some default values, the jQuery’s hidden fields wont get set unless you do some action on the calendar.

The  solution  is to add inline:true to its options like this:

$(“#myDate”).datepicker({

inline: true,
dateFormat: ‘yy-mm-dd’

});

Learning cURL

cURL is a tool for transferring files and data with URL syntax, supporting many protocols including HTTP, FTP, TELNET and more. Initially, cURL was designed to be a command line tool. Lucky for us, the cURL library is also supported by PHP. In this article, we will look at some of the advanced features of cURL, and how we can use them in our PHP scripts.

Source : here

CURL – citirea caracterelor speciale

Mai intai setam header pentru formatul UTF-8

$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$headers[] = 'Accept-Charset: utf-8;';
$headers[] = 'Keep-Alive: 300';

dupa setarea aray-ului cu header-ele, acesta trebuie integrat in CURL

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://www.google.ro/search?&q='.urlencode($val['keywords']));
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFilenameLogin);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFilenameLogin);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
$data = curl_exec($ch);
curl_close($ch);

functions to Editing a Web Page in WYSIWYG

Editing Methods

Editing functionality is applied to selected page content through scripts that apply the document.execCommand() method. Parameters are passed to this method giving the edit command to apply. The general format for the execCommand() method is shown below. It is applied through the document object.

document.execCommand("command" [,0] [,"value"])
<button title="Bold"
  onclick="document.execCommand('Bold')">
  <img src="Bold.gif"/>
</button>

Editing Commands

All of the available editing commands are too numerous to list here. The following table gives a sampling of what types of editing can be applied to selected text a page.

Command Description

document.execCommand(“BackColor“,0,”color“)
Sets the background color of the selected element; color
is a color name or hexadecimal value.

document.execCommand(“Bold“)
Sets the current selection to bold style.

document.execCommand(“Copy“)
Copies the current selection to the clipboard.

document.execCommand(“CreateLink“)
Displays a dialogue box for entering a URL which is applied to the selected text.

document.execCommand(“Cut“)
Cuts the current selection to the clipboard.

document.execCommand(“Delete“)
Deletes the current selection.

document.execCommand(“FontName“,0,”name“)
Sets the font face of the current selection; name
is a font name.

document.execCommand(“FontSize“,0,”size“)
Sets the font size of the current selection; size
is an integer from 1 (smallest) to 7 (largest).

document.execCommand(“ForeColor“,0,”color“)
Sets the text (foreground) color of the selected element; color
is a color name or hexadecimal value.

document.execCommand(“Indent“)
Increases the indent of the selected text by one indentation increment.

document.execCommand(“InsertImage“,1)
Displays a dialogue box for selecting and positioning a graphic image.

document.execCommand(“InsertMarquee“)
Inserts an empty marquee for entering displayed text.

document.execCommand(“InsertOrderedList“)
Formats an ordered list of current selection.

document.execCommand(“InsertUnorderedList“)
Formats an unordered list of current selection.

document.execCommand(“Italic“)
Sets the current selection to italic style.

document.execCommand(“JustifyCenter“)
Centers the text block in which the current selection is located.

document.execCommand(“JustifyFull“)
Justifies the text block in which the current selection is located.

document.execCommand(“JustifyLeft“)
Left justifies the text block in which the current selection is located.

document.execCommand(“JustifyRight“)
Right justifies the text block in which the current selection is located.

document.execCommand(“Outdent“)
Decreases the indent of the selected text by one indentation increment.

document.execCommand(“Paste“)
Pastes the current clipboard contents to current selection.

document.execCommand(“Print“)
Opens the print dialog box so the user can print the current page.

document.execCommand(“RemoveFormat“)
Removes all formatting from current selection.

document.execCommand(“SelectAll“)
Selects the entire document.

document.execCommand(“StrikeThrough“)
Sets the current selection to strike-through style.

document.execCommand(“Subscript“)
Sets the current selection to subscript style.

document.execCommand(“Superscript“)
Sets the current selection to superscript style.

document.execCommand(“Underline“)
Sets the current selection to underline style.

document.execCommand(“Unlink“)
Removes any hyperlink from the current selection.

document.execCommand(“Unselect“)
Clears the current selection.

Watermark pe imagini in php

Va propun o metoda de a pune un watermark pe o imagine in PHP. In principiu functia primeste ca parametrii imaginea sursa (locatie), locatia destinatie, watermarkul (locatie imagine), si calitatea jpeg.

Va returna Boolean, iar in cazul TRUE va salva un jpeg cu watermark din imaginea initiala. Functia se foloseste de libraria GD inclusa in php si accepta orice fel de tip de imagine pe care o poate recunoaste aceasta.

Watermarkul este pus in coltul din dreapta jos, dar asta se paote modifica dupa bunul plac.

function set_watermark($source, $dest, $watermark, $quality = 80)
{
  if (func_num_args() < 3)
  {
    $set_watermark_error = "Insufficient parameters supplied!";
  }
  else
  {
    if (file_exists($source))
    {
      if ($src = imagecreatefromstring(file_get_contents($source)))
      {
        $info = getimagesize($source);
        imageantialias($src, true);
        if ($wm = imagecreatefromstring(file_get_contents($watermark)))
        {
          $wm_info = getimagesize($watermark);
          imagealphablending($src, true);
          imagecopy($src, $wm, $info[0]-$wm_info[0]-5, $info[1]-$wm_info[1]-5, 0, 0, $wm_info[0], $wm_info[1]);
          if (imagejpeg($src, $dest, $quality))
          {
            if (file_exists($dest))
            {
              chmod($dest, 0777);
              return true;
            }
            else
            {
              $set_watermark_error = 'Unable tosaveimage! ';
            }
          }
          else
          {
            $set_watermark_error = 'Unable tosaveimage! ';
          }
        }
      }
      else
      {
        $set_watermark_error = 'Unrecognized imageformat! ';
      }
    }
    else
    {
      $set_watermark_error = 'Source filedoesnotexist! ';
    }
  }
  return false;
}

Functia mai poate fi customizata pentru a intoarce si alte tipuri de imagine, dar lasam asta la alegerea fiecaruia.