当前位置:沸点梦工场 > WAP网页设计 > Php wap开发教程 > 浏览文章

php WAp开发教程

互联网 2007年06月04日 【字体:

点此在新窗口浏览图片对象声明部分

1.Deck对象声明

class My_Deck
   {
  //属性声明
  var $card_title;
  var $card_alignment;
  var $element_number;
  var $default_item;
  var $default_number;

  //自构函数
  function My_Deck($title=DEFAULT_TITLE, $align=ALIGN_LEFT)
  {
  if ($title != DEFAULT_TITLE)
   $this->card_title = $title;

   $this->align = $alignment;
   $this->card_timer = 0;
   $this->forward_url = "";

   $this->element_number = 0;
   $this->default_number = 0;
  }

  //添加元素
  function Add_Element($element)
  {
  if (!is_object($element))
    die("Unlegal Element,Quit");
  switch($element->My_Type())
   {
  case I_AM_TEXT:
  case I_AM_IMAGE:
  case I_AM_TABLE:
  case I_AM_HYPERLINK:
  case I_AM_INPUT:
  case I_AM_SELECT:
  case I_AM_D
  case I_AM_FIELDSET:
   {
    $this->card_element[$this->element_number] = $element;

   $this->element_number++;

    break;
    }
   default:
    {
    die("Unlegal Element,Quit");
    }
    }
   }
  
  //创建Deck
   function Make_Deck()
  {
  header("content-type: text/vnd.wap.wml");

   echo "<?xml version=\"1.0\"?>\n";
   echo "<!DOCTYPE xml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n";
   printf("<-- Generated by %s %s -->\n", HAW_VERSION, HAW_COPYRIGHT);

   echo "

<wml>\n";

   $title = "title=\"$this->title\"";

   printf("<card%s>\n", $title);

  //获取交互元素如Input,Select的一些变量默认值
  while(list($thekey,$thevalue)=each($this->card_element))
  {
  switch($thevalue->My_Type())
  {
   case I_AM_SELECT:
   case I_AM_FIELDSET:
   {
   $temp_element=$thevalue;

   $temp_default=$temp_element->get_defaults();

   if($temp_default)
    {
    $this->default_item[$this->default_number]=$temp_default;

    $this->default_number++;

    break;
    }
    default:
     {
    break;
     }
   }
  }

  if ($this->default_number)
   {
   //缺省值存在
   echo "<onevent type=\"onenterforward\">\n";
   echo "\n";

  // 列出缺省值
  for($i=0;$i<$this->default_number;$i++)
  {
  while (list($thekey, $thevalue) = each($this->default_item[$i]))
  printf("<setvar name=\"%s\" value=\"%s\"/>\n", $thevalue["name"], $thevalue["value"]);
    }

  echo "</refresh>\n";
  echo "</onevent>\n";

  //后向进入页面时变量默认值也需重新设置,实现方法与以上相同
  echo "<onevent type=\"onenterbackward\">\n";
  echo "<refresh>\n";

  // 列出缺省值
  for($i=0;$i<$this->default_number;$i++)
   {
  while (list($thekey, $thevalue) = each($this->default_item[$i]))
  printf("<setvar name=\"%s\" value=\"%s\"/>\n", $thevalue[name], $thevalue[value]);
   }
  echo "</refresh>\n";
  echo "</onvent>\n";
  }

  //设置页面格式
  switch ( $this->card_align )
  {
  case ALIGN_LEFT:
   {
   echo "</p>\n";
   break;
   }

  case ALIGN_CENTER:
  {
  echo "<p align=\"center\"> \n";
  break;
   }

  case ALIGN_RIGHT:
  {
  echo "<p align=\"right\"> \n";

  break;
  }
  }

  for($i=0;$i<$this->element_number;$i++)
  {
   $the_element = $this->card_element[$i];
   switch ($the_element->My_Type())
    {
    case I_AM_TEXT:
    case I_AM_IMAGE:
    case I_AM_TABLE:
    case I_AM_HYPERLINK:
  case I_AM_INPUT:
  case I_AM_SELECT:
  case I_AM_D
  case I_AM_FIELDSET:
    {
    $temp_element = $this->card_element[$i];
 
    $temp_element->Make_Element(&$this);

    break;
    }
   default:
   {
   break;
   }
    }
   }

  echo " </p>\n"
  echo "</card> \n";
  echo "</wml> \n";

  };

2.Text对象声明

class My_Text
  {
  //属性声明
   var $text;
   var $attribute;
   var $br_count;//空行数目

  //方法声明
  
  //自构函数
  function My_Text($the_text, $the_attribute=TEXT_NORMAL)
  {
   $this->text = $the_text;
   $this->attribute = $the_attribute;
   $this->br_count = 1;
  }

  //设置空行数目函数
  function set_br_count($the_br_count)
  {
   if (!is_int($the_br_count) || ($br < 0))
    die("incorrect br_count");

   $this->br_count = $the_br_count;
  }

  //返回对象类型函数
   function My_Type()
  {
  return I_AM_TEXT;
  }

  //创建Text部分代码
  function Make_Element($deck)
  {
   if ($this->attribute & TEXT_BOLD)
    echo "<b>n";

   if ($this->attribute & TEXT_UNDERLINE)
    echo "<i>n";

  if ($this->attribute & TEXT_BIG)
    echo "<big>\n";

   if ($this->attribute & TEXT_SMALL)
   echo "<small>\n";

  if ($this->text)
   rintf("%s\n", convert_character($this->text));

  if ($this->attribute & TEXT_SMALL)
   echo "</small>\n";

  if ($this->attribute & TEXT_BIG)
   echo "</bigl>\n";

  if ($this->attribute & TEXT_ITALIC)
   echo "</i>\n";

  if ($this->attribute & TEXT_UNDERLINE)
   echo "</u>\n";

  if ($this->attribute & TEXT_BOLD)
   echo "</b>\n";

   $br_command = "<br/>\n";
  for ($i=0; $i<$this->br_count; $i++)
   echo $br_command;

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]  下一页


上一页      下一页
本文共 14 页,第  [1]  [2]  [3]  [4]  [5]  [6]  [7]  [8]  [9]  [10]  
[11]  [12]  [13]  [14]  页