Friday, February 24, 2012

map_month() - Predefined Drupal Function

map_month() - Predefined Drupal Function

To get the month name using the numbers of the month.
$val = map_month(3);

echo $val;

Output:
Mar

expand_date - Drupal Pre Defined Function

expand_date - Drupal Pre Defined Function

Assign the expand_date() function value to a variable and print that variable.
$exp_date = expand_date();
print "<pre>" ;
print_r($exp_date);
print "</pre>" ;

You will get all those details for this function,you can use it anywhere over the module.
Array
(
    [#value] => Array
        (
            [day] => 24 //(current day)
            [month] => 2 //(current month)
            [year] => 2012 //(current year)
        )

    [#tree] => 1
    [month] => Array  //(Months List)
        (
            [#type] => select
            [#value] => 2
            [#attributes] => 
            [#options] => Array
                (
                    [1] => Jan
                    [2] => Feb
                    [3] => Mar
                    [4] => Apr
                    [5] => May
                    [6] => Jun
                    [7] => Jul
                    [8] => Aug
                    [9] => Sep
                    [10] => Oct
                    [11] => Nov
                    [12] => Dec
                )

        )

    [day] => Array //(Days List)
        (
            [#type] => select
            [#value] => 24
            [#attributes] => 
            [#options] => Array
                (
                    [1] => 1
                    [2] => 2
                    [3] => 3
                    [4] => 4
                    [5] => 5
                    [6] => 6
                    [7] => 7
                    [8] => 8
                    [9] => 9
                    [10] => 10
                    [11] => 11
                    [12] => 12
                    [13] => 13
                    [14] => 14
                    [15] => 15
                    [16] => 16
                    [17] => 17
                    [18] => 18
                    [19] => 19
                    [20] => 20
                    [21] => 21
                    [22] => 22
                    [23] => 23
                    [24] => 24
                    [25] => 25
                    [26] => 26
                    [27] => 27
                    [28] => 28
                    [29] => 29
                    [30] => 30
                    [31] => 31
                )

        )

    [year] => Array //(Year List from 1900 to 2050)
        (
            [#type] => select
            [#value] => 2012
            [#attributes] => 
            [#options] => Array
                (
                    [1900] => 1900
                    [1901] => 1901
                    [1902] => 1902
                    [1903] => 1903
                    [1904] => 1904
                    [1905] => 1905
                    [1906] => 1906
                    [1907] => 1907
                    [1908] => 1908
                    [1909] => 1909
                    [1910] => 1910
                    [1911] => 1911
                    [1912] => 1912
                    [1913] => 1913
                    [1914] => 1914
                    [1915] => 1915
                    [1916] => 1916
                    [1917] => 1917
                    [1918] => 1918
                    [1919] => 1919
                    [1920] => 1920
                    [1921] => 1921
                    [1922] => 1922
                    [1923] => 1923
                    [1924] => 1924
                    [1925] => 1925
                    [1926] => 1926
                    [1927] => 1927
                    [1928] => 1928
                    [1929] => 1929
                    [1930] => 1930
                    [1931] => 1931
                    [1932] => 1932
                    [1933] => 1933
                    [1934] => 1934
                    [1935] => 1935
                    [1936] => 1936
                    [1937] => 1937
                    [1938] => 1938
                    [1939] => 1939
                    [1940] => 1940
                    [1941] => 1941
                    [1942] => 1942
                    [1943] => 1943
                    [1944] => 1944
                    [1945] => 1945
                    [1946] => 1946
                    [1947] => 1947
                    [1948] => 1948
                    [1949] => 1949
                    [1950] => 1950
                    [1951] => 1951
                    [1952] => 1952
                    [1953] => 1953
                    [1954] => 1954
                    [1955] => 1955
                    [1956] => 1956
                    [1957] => 1957
                    [1958] => 1958
                    [1959] => 1959
                    [1960] => 1960
                    [1961] => 1961
                    [1962] => 1962
                    [1963] => 1963
                    [1964] => 1964
                    [1965] => 1965
                    [1966] => 1966
                    [1967] => 1967
                    [1968] => 1968
                    [1969] => 1969
                    [1970] => 1970
                    [1971] => 1971
                    [1972] => 1972
                    [1973] => 1973
                    [1974] => 1974
                    [1975] => 1975
                    [1976] => 1976
                    [1977] => 1977
                    [1978] => 1978
                    [1979] => 1979
                    [1980] => 1980
                    [1981] => 1981
                    [1982] => 1982
                    [1983] => 1983
                    [1984] => 1984
                    [1985] => 1985
                    [1986] => 1986
                    [1987] => 1987
                    [1988] => 1988
                    [1989] => 1989
                    [1990] => 1990
                    [1991] => 1991
                    [1992] => 1992
                    [1993] => 1993
                    [1994] => 1994
                    [1995] => 1995
                    [1996] => 1996
                    [1997] => 1997
                    [1998] => 1998
                    [1999] => 1999
                    [2000] => 2000
                    [2001] => 2001
                    [2002] => 2002
                    [2003] => 2003
                    [2004] => 2004
                    [2005] => 2005
                    [2006] => 2006
                    [2007] => 2007
                    [2008] => 2008
                    [2009] => 2009
                    [2010] => 2010
                    [2011] => 2011
                    [2012] => 2012
                    [2013] => 2013
                    [2014] => 2014
                    [2015] => 2015
                    [2016] => 2016
                    [2017] => 2017
                    [2018] => 2018
                    [2019] => 2019
                    [2020] => 2020
                    [2021] => 2021
                    [2022] => 2022
                    [2023] => 2023
                    [2024] => 2024
                    [2025] => 2025
                    [2026] => 2026
                    [2027] => 2027
                    [2028] => 2028
                    [2029] => 2029
                    [2030] => 2030
                    [2031] => 2031
                    [2032] => 2032
                    [2033] => 2033
                    [2034] => 2034
                    [2035] => 2035
                    [2036] => 2036
                    [2037] => 2037
                    [2038] => 2038
                    [2039] => 2039
                    [2040] => 2040
                    [2041] => 2041
                    [2042] => 2042
                    [2043] => 2043
                    [2044] => 2044
                    [2045] => 2045
                    [2046] => 2046
                    [2047] => 2047
                    [2048] => 2048
                    [2049] => 2049
                    [2050] => 2050
                )

        )

)

Tuesday, February 21, 2012

Object Oriented Programming PHP

Object Oriented Programming PHP

Object PHP Definition

Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.
Adopting object-oriented techniques when developing your PHP scripts and applications can immediately inject greater flexibility and easier maintenance into your development environment. Programs become easier to extend, or debug, and sharing code with other developers on your team (should you have one) becomes simpler.

Objects and Classes

Objects in PHP cannot be declared literally; they must be instantiated from a class.

There’s No Substitute for Class

To define a class in PHP, we write the following code:
class Bicycle
{
  var $attribute1;
  var $attribute2;
  function method1()
  {
    // Code here
    return $something;
  }
 
  function method2()
  {
    // Code here
  }
}

new keyword:

To a new an instance of our class, we need to use the new keyword. To create a new object from the class definition we use the new keyword.
$myBicycle = new Bicycle();
This creates an object. An object is, in effect, a new variable with a user-defined data-type (the class). This basically means we could instantiate our class over and over into as many different objects as we so desire.
$myBicycle2 = new Bicycle();
$myBicycle3 = new Bicycle();
$myBicycle4 = new Bicycle();

Any New Members?

To access the various attributes and methods (members) of our object, we can use the namespace separator -> (sometimes called the arrow operator; although it’s not really an operator). When you are accessing a variable in PHP, the part of code after the $ is known as the namespace. When you are accessing attributes and methods that are members of an object, you need to extend that namespace to include the name of your object. To do this, you reference attributes and methods like so:
// Assigning Value to Attributes
$myBicycle->attribute1 = 'Red';
$myBicycle->attribute2 = 'Hero';
 
// Calling Methods
$returned = $myBicycle->method1();
$myBicycle->method2();
This idea of namespace and namespace separators is very similar to a standard directory structure – the slashes or backslashes becoming the ->separator. Since we can have objects within objects, we can also extend this further. For example, if our $myBicycle object was a member of another object called $anotherObject, we could reference the members of $myBicycle like so:
// Assigning Value to Attributes
$anotherObject->myBicycle->attribute1 = 'Red';
$anotherObject->myBicycle->attribute2 = 'Hero';
 
// Methods
$returned = $anotherObject->myBicycle->method1();
$anotherObject->myBicycle->method2();
Notice that the $ appears only once before the namespace; this is because a variable name in PHP can only ever have a single dollar sign. If we were to place another $ anywhere in our namespace, we’d be telling PHP we were using variable variables. I don’t really want to go too far off topic here, so have a look at the PHP documentation for more information about variable variables.

The $this Pseudo-Variable

When writing code within a class definition, you’re never going to know the name of the object to which it belongs; this is because the object hasn’t even been instantiated at this point. In order to access the attributes and methods of your class from within the class itself, we will need to use the $this pseudo-variable:
class Bicycle
{
  var $attribute1;
  function method1()
  {
    return $this->attribute1;
  }
}
$this can also be thought of as ‘my own’ or ‘current object’. In our example, we’re returning the value of $attribute1 within the ‘current object’.
Inheritance

Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example, Bicycle now becomes the superclass of MountainBike, RoadBike, and TandemBike. Inheritence is the ability of php to extend classes (child classes) that inherit the charactaristics of the parent class.

<?php

class RoadBike extends Bicycle {
private $num_spoke;

private $handlebars;

}
 

Constructor

Constructors are functions in a class that are automatically called when you create a new instance of a class with new. A function becomes a constructor, when it has the same name as the class. If a class has no constructor, the constructor of the base class will be called, if it exists.
The constructor of a class is a special method that is run upon instantiation. It’s main purpose is to set-up the attributes of a class and to establish the class invariant – to basically make sure that the attributes of the class conform to the class interface. A properly written constructor should never contain any functionality that could fail, thus leaving the object in an invalid state.
<?php
class A
{
    function A()
    {
        echo "I am the constructor of A.<br />\n";
    }

    function B()
    {
        echo "I am a regular function named B in class A.<br />\n";
        echo "I am not a constructor in A.<br />\n";
    }
}

class B extends A
{
}

// This will call B() as a constructor
$b = new B;
?>

Destructor

A destructor function is run when an object is destroyed – its role is to clean up and to free the resources which were used by the object during run-time, and to unlink the object from other objects or resources.
<?php
class MyExampleClass {
function __construct() {
print ”In constructor\n”;
$this->name = ”MyExampleClass”;
}
function __destruct() {
print ”Destroying ” . $this->name . ”\n”;
}
}
$myObj = new MyExampleClass ();
?>
PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown

Magic Methods

The function names __construct__destruct__call__callStatic__get__set__isset__unset__sleep__wakeup__toString__invoke,__set_state and __clone are magical in PHP classes. You cannot have functions with these names in any of your classes unless you want the magic functionality associated with them.

ASCII CODES

ASCII CODES

Some of the symbols have been listed in bold to separate  them clearly from their descriptions.
  1. White Smiley
  2. ☻ Black Smiley
  3. ♥ Black heart
  4. ♦ Diamond
  5. ♣ Clove (Clover/Puppyfeet)
  6. ♠ Spade
  7. • Black dot
  8. ◘ Black square with circle cutout
  9. ○ White circle
  10. ◙ Black square with black circle
  11. ♂ Male Symbol
  12. ♀ Female Symbol
  13. Eighth Note (Eigth)
  14. Musical Double Eighth Note
  15. ☼ Sun
  16. ► Play (Forward) or Solid right arrow
  17. ◄ Rewind (Backward) or Solid left arrow
  18. ↕ Up and down arrows
  19. ‼ Double Exclamation Mark
  20. ¶ Pilcrow (Paragraph Sign)
  21. § The section sign
  22. ▬ Long and Thick Minus Sign
  23. ↨ Up & down arrows
  24. ↑ Up arrow
  25. ↓ Down arrow
  26. → Right arro
  27. ← Left arrow
  28. ∟ 90º degree angle
  29. ↔ Left and right arrow
  30. ▲ Solid up arrow
  31. ▼ Solid down arrow
  32.  Just a space
  33. ! Exclamation mark (bang)
  34. " Quote Quote
  35. # Pound sign
  36. $ Dollar sign
  37. % Percentage sign
  38. & "And" sign aka ampersand
  39. ' Apostrophe Apostrophe
  40. ( Left parenthesis
  41. ) Right parenthesis
  42. * Asterisk/Asterix/astrix (Or star)
  43. + Plus sign
  44. , Comma
  45. - Minus Sign
  46. . Period
  47. / Forward slash
  48. 0 0
  49. 1 1
  50. 2 2
  51. 3 3
  52. 4 4
  53. 5 5
  54. 6 6
  55. 7 7
  56. 8 8
  57. 9 9
  58. : Colon (colons)
  59. ; Semicolon
  60. < Left arrow (Big fish) Less than
  61. = Equals sign Equals sign
  62. > Right arrows (Small fish) Greater than
  63. ? Question mark
  64. @ At symbol
  65. A
  66. B
  67. C
  68. D
  69. E
  70. F
  71. G
  72. H
  73. I
  74. J
  75. K
  76. L
  77. M
  78. N
  79. O
  80. P
  81. Q
  82. R
  83. S
  84. T
  85. U
  86. V
  87. W
  88. X
  89. Y
  90. Z
  91. [
  92. \
  93. ]
  94. ^
  95. _
  96. ` A grave accent
  97. a
  98. b
  99. c
  100. d
  101. e
  102. f
  103. g
  104. h
  105. i
  106. j
  107. k
  108. l
  109. m
  110. n
  111. o
  112. p
  113. q
  114. r
  115. s
  116. t
  117. u
  118. v
  119. w
  120. x
  121. y
  122. z
  123. {
  124. |
  125. }
  126. ~
  127. A house shaped pentagon
  128. Ç A "C" with a cedilla
  129. ü A u with a umlaut (or diaeresis) over it
  130. é Acute accent over e
  131. â "a" with a circumflex over it
  132. ä An "a" with a umlaut (or diaeresis) over it
  133. à An "a" with a grave accent over it
  134. å An a with a circle or dot over it
  135. ç A "c" with a circumflex
  136. ê "e" with a circumflex on it
  137. ë An "e" with a umlaut (or diaeresis) over it
  138. è An "e" with a grave accent over it
  139. ï An "i" with a umlaut (or diaeresis) over it
  140. î An i with a circumflex over it
  141. ì An "i" with a grave accent
  142. Ä An "A" with a umlaut (or diaeresis) over it
  143. Å A capitol "A" with a circle or dot over it (Angstrom)
  144. É A capitol "E" with an acute accent over it
  145. æ The lower case vowel (grapheme) of the a and e squished together
  146. Æ Capitol AE combined into one letter
  147. ô A "o" with a circumflex over it
  148. ö An "o" with a umlaut (or diaeresis) over it
  149. ò An "o" with a mark over it called a grave mark
  150. û A u with a circumflex over it
  151. ù A u with a grave accent over it
  152. ÿ A "y" with a umlaut (or diaeresis) over it
  153. Ö A "O" with a umlaut (or diaeresis) over it
  154. Ü A "U" with a umlaut (or diaeresis) over it
  155. ¢ The "cents" or "cent" sign for currency
  156. £ The "pound sign" for currency
  157. ¥ The "Yen" sign for currency (Japanese/Chinese) Written in Japanese as
  158. Pts Points of Pints sign
  159. ƒ Forte: A curvy or italic F (italicized)
  160. á An a with a acute accent
  161. í An i with a acute accent
  162. ó An o with a acute accent
  163. ú A u with an acute accent over it
  164. ñ A n with a tilde ~ over it to make the Spanish enye
  165. Ñ A capital n with a tilde ~ over it to make the Spanish enye
  166. ª The feminine superscript A
  167. º The degrees or degree symbol
  168. ¿ Upside down question mark used in Spanish
  169. Negation / Logical Complement / Looks like start "quote" in Japanese / Chinese
  170. ¬ Negation / Logical Complement / Looks like end "quote" in Japanese / Chinese
  171. ½ One half symbol
  172. ¼ One quarter symbol O
  173. ¡ An upside down exclamation mark (looks like an "i" that sits lower than usual)
  174. « Double arrow pointing left
  175. » Double arrow pointing right
  176. ░ Light shaded block
  177. ▒ Medium shaded block
  178. ▓ Dark shaded block
  179. │ Line
  180. ┤Shape
  181. ╡Special Line
  182. ╢ You can make words with these
  183. ╖ Or shapes
  184. ╕ Or Mazes!
  185. ╣ANSI border characters
  186. (Could also be Pi, see 227)
  187. ANSI art pseudographics
  188. ANSI blocks / box drawing characters
  189. α The Greek letter "Alpha"
  190. ß A German letter, Eszett, scharfes S, sharp S
  191. Γ Greek uppercase "Gamma." Also, Greek number 3.
  192. π The symbol for the mathematical Pi in ascii
  193. Σ Greek mathematical symbol for sum
  194. σ Symbol for sum Symbol for sum
  195. µ Mu
  196. τ  Tau
  197. Φ Phi a variation of Phi
  198. Θ Theta, the 8th letter of Greek alphabet
  199. Ω Omega (24th letter of Greek alphabet)
  200. δ The symbol for delta
  201. ∞ The symbol or character for infinity (Infiniti)
  202. φ Phi (21st letter of Greek alphabet)
  203. ε Epsilon (5th letter of Greek Alphabet) / backwards 3 or curved E
  204. ∩ Intersection / Upside down U
  205. ≡ Equivalent symbol / Equal sign with 3 lines
  206. ± Plus and minus (Plus or minus) sign, Plus-minus Symbol
  207. ≥ Greater than or equal to symbol
  208. ≤ Less than or equal to sign
  209. ⌠ Ceil (mathematical symbol)
  210. ⌡ Floor (mathematical symbol)
  211. ÷ Divide or Division Symbol
  212. ≈ Symbol for approximate / Curvy or wavy equal sign =
  213. ° Degree or degrees code
  214. ∙ Medium height period Medium height period
  215. · Dot higher than usual
  216. √ Square Root Symbol (A check mark)
  217. ⁿ Superscript N
  218. ² Squared symbol, superscript 2 via ascii
  219. ■ Black box or square

Monday, February 20, 2012

Creating Rss Page for our site using our Content

Creating Rss Page for our site using our Content:

function rssfeed() {
  global $base_url;
  $sp_name = arg(2);
//(your content node id)
  $node_names = node_get_types('names'); //(your content type name)
  $title_name = $node_names[$sp_name] != '' ? $node_names[$sp_name] : $sp_name; 
  $query = "SELECT n.nid, n.type, n.title, nr.body, n.changed
    FROM {node} n
    JOIN {node_revisions} nr ON nr.nid = n.nid
    WHERE n.type = '%s'"; //(contents for the rss)
  $result = db_query($query, $sp_name);

//[ Creating Structure for rss Page ]
  header("Content-Type: application/rss+xml; charset=iso-8859-1");
  $rssfeed = '<rss version="2.0"> 
    <channel>
      <title>' . $title_name . '</title>';
  while($row = db_fetch_array($result)) {
    $nid = $row['nid'];
    $src = 'node/'.$nid;
    $url_alias = drupal_get_path_alias($src);
    extract($row);
    //encode description
    //$contenttitle = utf8_decode($title);
    //$contenttitle = str_replace('', '&trade;', $contenttitle);
    $contenttitle = html_entity_decode($title, ENT_QUOTES, "UTF-8");
    //$contenttitle = str_replace(array('&' , '®'), array('&amp;' , '&reg;'), $contenttitle);
    //encode description
    $contentdesc = html_entity_decode(strip_tags($body), ENT_QUOTES, "UTF-8");
   // $contentdesc = str_replace('&', '&amp;', $contentdesc);
    //Designing Each Rss
    $url = $base_url . '/'.$url_alias;
    $rssfeed .= '
      <item>
        <title>' .($contenttitle) . '</title>
        <description>' . check_plain($contentdesc)  . '</description>
        <link>' . $url . '</link>
        <pubDate>' . date("D, d M Y H:i:s O", $changed) . '</pubDate>
      </item>';
  }
  $rssfeed .= '
    </channel>
  </rss>';
  echo $rssfeed; //[Returning the rss structure]
}