29 Aralık 2009 Salı

ADVTemplateListView Class

MVC (Model View Controller) temeline dayanan bir anlayış ile ADVTemplateList modelimizi HTML görünümüne çevirmesi için bir yönetici View sınıfı oluşturdum. Bu View sınıfı sayesinde reklam şablonlarımız kolaylıkla listelenebiliyor, listelenen şablonlar sayfalar haline getirilebiliyor ve bu sayfalar tek tek listelenebiliyorlar.
Hazırlamış olduğum ADVTemplateListView Class dosyasının kodu şöyle:

<?php
/**
  * This class is used to represent the view part of the Template List.
  * 
  * @author Behçet MUTLU
  * @copyright 2009
  */
class ADVTemplateListView {
        
      private $templateList;
      private $currentPage;
      private $pageSize;
      
      
      /**
      * ADVTemplateListView::__constructor()
      * 
      * This is the default constructor of the view class.
      * 
      * @param mixed $templateList
      * @param integer $currentPage
      * @param integer $pageSize
      * @return void
      */
      public function __construct($templateList, $currentPage = 0, $pageSize = 4)
      {
          $this->templateList = $templateList;
          $this->currentPage = $currentPage;
          $this->pageSize = $pageSize;
      }
      
      public function getNextPage()
      {
          $output = "<ul class=\"tmpList\">";
          $currentIndex = $this->currentPage * $this->pageSize;
          $nextIndex = min($currentIndex + $this->pageSize, $this->templateList->getTemplateCount());
          
          for($i = $currentIndex; $i < $nextIndex; $i++)
          {
            $output.= $this->_toHTML($this->templateList->getTemplateAt($i));
          }
          
          $output.= "</ul>";
          
          $this->currentPage += 1;
          
          return $output;
      }
      
      /**
      * ADVTemplateListView::_toHTML()
      * 
      * This method is used to get the HTML output of template thumbnail
      * 
      * <li>
      *    <a href="#">Şablon #4</a>
      *    <div class="thumb"><img src="adv_templates/template1/thumb.jpg" width="178" height="148" /></div>
      * </li>
      * 
      * @param mixed $template
      * @return
      */
      private function _toHTML($template)
      {
          $output = "<li>";
          
          $output.= "<a href=\"#\">" . $template->getName() . "</a>";
          
          $output.="<div class=\"thumb\"><img src=\"". $template->getThumbnail()
          ."\" width=\"178\" height=\"148\"></div>";
          
          return $output . "</li>";
      }
  
  }

?>

ADV Manager Şablon Kategorileri Tasarımı


Reklam Yöneticimizin Şablon listeleme ekranını hazırladım. Bu bölüm reklam editörümüzün hemen üzerinde görüntülenecek ve kullanıcılar diledikleri anda tasarımlarını seçerek düzenleme işlemlerini yapabilecekler. Şablon listesi daha önce hazırladığım ADVTemplateList Class'ı tarafından oluşturulan listeden yüklenecektir. Yine her bir şablon ile ilgili veriler de bu sınıf sayesinde eklenerek düzenleme işlemleri yapılabilecektir.

26 Aralık 2009 Cumartesi

ADVTemplateList Class Test

ADVTemplateList sınıfımızı test edebilmek için hazırladığım kod da aşağıdaki gibi.

<?php
/**
  * This is the tester of ADVTemplateList class
  * 
  * @author Behçet MUTLU
  * @copyright 2009
  */

    include_once("../system.core.php");
    
    $list = new ADVTemplateList($_SERVER["DOCUMENT_ROOT"]."ADVManager/adv_templates/");
    
    if($list->isReady())
          pre($list->getList());
    else
        print("List is not ready!");
    
?>

Bu kodun çıktısı şu şekilde.

DEBUG:  Template at "C:/wamp/www/ADVManager/adv_templates/Kopyas� template1" does not contain template.xml schema file.


DEBUG:  XML file, "C:/wamp/www/ADVManager/adv_templates/template1/template.xml" loaded successfully.

Array
(
    [0] => ADVTemplate Object
        (
            [name:ADVTemplate:private] => Template 1
            [author:ADVTemplate:private] => Behçet MUTLU
            [datecreated:ADVTemplate:private] => 25-12-2009
            [copyright:ADVTemplate:private] => 2009 Adres Gezgini
            [website:ADVTemplate:private] => www.adresgezgini.com.tr
            [thumbnail:ADVTemplate:private] => adv_templates/template1/thumb.jpg
            [schema:ADVTemplate:private] => C:/wamp/www/ADVManager/adv_templates/template1/template.xml
            [isReady:ADVTemplate:private] => 1
            [xml:ADVTemplate:private] => Array
                (
                    [template] => Array
                        (
                            [0] => 

                            [info] => Array
                                (
                                    [0] => 
    
                                    [name] => Template 1
                                    [author] => Behçet MUTLU
                                    [copyright] => 2009 Adres Gezgini
                                    [website] => www.adresgezgini.com.tr
                                    [thumbnail] => adv_templates/template1/thumb.jpg
                                    [datecreated] => 25-12-2009
                                )

                            [fields] => Array
                                (
                                    [0] => 
    
                                    [image] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [0] => 
        
                                                    [title] => Logo Resmi
                                                    [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                                                    [default] => library/image_64x64.png
                                                    [@id] => image1
                                                    [@width] => 64
                                                    [@height] => 64
                                                )

                                            [1] => Array
                                                (
                                                    [0] => 
        
                                                    [title] => Ürün Resmi
                                                    [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                                                    [default] => library/image_128x169.png
                                                    [@id] => image2
                                                    [@width] => 128
                                                    [@height] => 169
                                                )

                                        )

                                    [text] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [0] => 
        
                                                    [title] => Başlık Yazısı
                                                    [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                                                    [default] => Başlık Yazısı
                                                    [font] => Arial
                                                    [color] => 000000
                                                    [size] => 20
                                                    [@id] => text1
                                                    [@max] => 100
                                                    [@min] => 10
                                                )

                                            [1] => Array
                                                (
                                                    [0] => 
        
                                                    [title] => Web Site Adresi
                                                    [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                                                    [default] => www.websiteniz.com.tr
                                                    [font] => Arial
                                                    [color] => 000000
                                                    [size] => 12
                                                    [@id] => text2
                                                    [@max] => 100
                                                    [@min] => 10
                                                )

                                            [2] => Array
                                                (
                                                    [0] => 
        
                                                    [title] => Buton Yazısı
                                                    [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                                                    [default] => Bilgi İçin Tıklayınız
                                                    [font] => Impact
                                                    [color] => 000000
                                                    [size] => 18
                                                    [@id] => text3
                                                    [@max] => 100
                                                    [@min] => 10
                                                )

                                        )

                                )

                        )

                )

            [fields:ADVTemplate:private] => Array
                (
                    [0] => 
    
                    [image] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 
        
                                    [title] => Logo Resmi
                                    [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                                    [default] => library/image_64x64.png
                                    [@id] => image1
                                    [@width] => 64
                                    [@height] => 64
                                )

                            [1] => Array
                                (
                                    [0] => 
        
                                    [title] => Ürün Resmi
                                    [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                                    [default] => library/image_128x169.png
                                    [@id] => image2
                                    [@width] => 128
                                    [@height] => 169
                                )

                        )

                    [text] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 
        
                                    [title] => Başlık Yazısı
                                    [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                                    [default] => Başlık Yazısı
                                    [font] => Arial
                                    [color] => 000000
                                    [size] => 20
                                    [@id] => text1
                                    [@max] => 100
                                    [@min] => 10
                                )

                            [1] => Array
                                (
                                    [0] => 
        
                                    [title] => Web Site Adresi
                                    [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                                    [default] => www.websiteniz.com.tr
                                    [font] => Arial
                                    [color] => 000000
                                    [size] => 12
                                    [@id] => text2
                                    [@max] => 100
                                    [@min] => 10
                                )

                            [2] => Array
                                (
                                    [0] => 
        
                                    [title] => Buton Yazısı
                                    [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                                    [default] => Bilgi İçin Tıklayınız
                                    [font] => Impact
                                    [color] => 000000
                                    [size] => 18
                                    [@id] => text3
                                    [@max] => 100
                                    [@min] => 10
                                )

                        )

                )

            [values:ADVTemplate:private] => Array
                (
                    [image1] => library/image_64x64.png
                    [image2] => library/image_128x169.png
                    [text1] => Başlık Yazısı
                    [text2] => www.websiteniz.com.tr
                    [text3] => Bilgi İçin Tıklayınız
                )

        )

)

ADVTemplateList Class ile Tema Listesinin Alınması

ADVTemplateList sınıfı reklam yöneticimiz tarafından kullanılacak ve şablon listemizi hazırlayacak olan sınıftır. Amacı belirtilen bir veya birden fazla klasör içerisinde bulunan şablon dosyalarını okuyarak ADVTemplate objeleri listesini hazırlamasıdır.
Bu sınıf oluşturulurken listesini hazırlayacağı klasör konumuna zorunlu olarak ihtiyaç duymaktadır. Hazırladığım sınıfın kaynak kodu şu şekilde geliştirildi.
<?php
/**
  * This class is used to represent the list of Templates that are in a directory.
  * 
  * @author Behçet MUTLU
  * @copyright 2009 Adres Gezgini
  */
  class ADVTemplateList {
    
      private $dir;
      private $list;
      private $ready;
      
      /**
      * This is the default constructor of the class that needs directory to be 
      * traversed of which contains the templates.
      * 
      * @param mixed $dir
      * @return void
      */
      public function __construct($dir)
      {
          $this->dir = $dir;
          $this->_initialize();
      }
      
      /**
      * This method is used to initialize the private variables of the class that
      * are used by this class.
      * 
      * @return void
      */
      private function _initialize()
      {
          $this->list = $this->_getTemplates($this->dir);
          
          $this->ready = $this->list != false;
      }
      
      /**
      * This method is used to traverse the list of the directories of given directory
      * and collect the list of templates in to an array and return, if the directory
      * exist template list, otherwise false.
      * 
      * @param mixed $directory to be traversed
      * @param mixed $exempt to exclude from listing
      * @param mixed $templates the referance to be used 
      *                         if we want collect from multiple directories
      * @return template list or false
      */
      private function _getTemplates($directory, 
                                      $exempt = array('.','..','.ds_store','.svn'), 
                                      &$templates = array()) 
      {
          if( ! ($handle = @opendir($directory))) // with @ character we are avoiding the wrong path error to be displayed as an exception
              return false;
          
          while(false !== ($resource = readdir($handle))) {
              if(!in_array(strtolower($resource),$exempt)) {
                  if(is_dir($directory.$resource.'/'))
                  {
                      if(file_exists($directory.$resource."/template.xml"))
                       $templates[] = new ADVTemplate($directory.$resource."/template.xml");
                      else
                       debug("Template at \"" . $directory.$resource . "\" does not contain  <i>template.xml</i> schema file.");
                  }
              }
          }
          closedir($handle);
          return $templates;
      } 
      
      /**
      * The setter methods of the class
      * @param value to set
      */
      public function setList($value) { $this->list = $value; }
      public function setDir($value) { $this->dir = $value; $this->_initialize();}
      
      /**
      * The getter methods of the class
      * 
      * @return values requested
      */
      public function getList() { return $this->list; }
      public function getDir() { return $this->dir; }
      public function isReady() { return $this->ready; }
  }
?>

Şablon Klasör Taraması

Hazırladığımız şablonların herbirini bir klasör içerisinde barındırıdığımızda, bu klasör altında bulunan tüm şablonların tek tek taranarak sistemde görüntülenmesi için basit bir Klasör Tarama kodu hazırladım. Bu kod, belirtilen klasör altındaki klasörlerin içerisinde eğer varsa template.xml dosyasını şablon olarak yüklenmesini sağlıyor.
Şimdilik bu kodu ufkumuzu genişletmesi için hazırladım, tema yükleme işleminin oldukça kolaylaşacağını ve temaların sisteme uyumluluğunun hat safhada olacağını belirtmeliyim.
Hazırladığım kod şu şekilde:
/**
 * This is the test of directory listing of the adv_templates directory
 * 
 * @author Behçet MUTLU
 * @copyright 2009
 */

require_once("system/system.core.php");
@$dir = $_SERVER["DOCUMENT_ROOT"]."ADVManager/adv_templates/";

function _readdir($dir)
{
    $dh = opendir($dir);
    while (false !== ($filename = readdir($dh))) {
        $files[] = $filename;
    }
    return $files;
}

$files = _readdir($dir);

foreach($files as $file)
{
    if(is_dir($dir.$file) && $file != "." && $file != "..")
    {
        echo ">$file\n";
        foreach(_readdir($dir.$file) as $temp_file)
        {
            if($temp_file == "template.xml")
            {
                $adv = new ADVTemplate($dir.$file . "/template.xml");
                pre($adv);
            }
        }
    }
}
Bu kodun geri döndürdüğü çıktı ise şu şekildeydi:
>template1

DEBUG:  XML file, "C:/wamp/www/ADVManager/adv_templates/template1/template.xml" loaded successfully.

ADVTemplate Object
(
    [name:ADVTemplate:private] => Template 1
    [author:ADVTemplate:private] => Behçet MUTLU
    [datecreated:ADVTemplate:private] => 25-12-2009
    [copyright:ADVTemplate:private] => 2009 Adres Gezgini
    [website:ADVTemplate:private] => www.adresgezgini.com.tr
    [thumbnail:ADVTemplate:private] => adv_templates/template1/thumb.jpg
    [schema:ADVTemplate:private] => C:/wamp/www/ADVManager/adv_templates/template1/template.xml
    [isReady:ADVTemplate:private] => 1
    [xml:ADVTemplate:private] => Array
        (
            [template] => Array
                (
                    [0] => 

                    [info] => Array
                        (
                            [0] => 
    
                            [name] => Template 1
                            [author] => Behçet MUTLU
                            [copyright] => 2009 Adres Gezgini
                            [website] => www.adresgezgini.com.tr
                            [thumbnail] => adv_templates/template1/thumb.jpg
                            [datecreated] => 25-12-2009
                        )

                    [fields] => Array
                        (
                            [0] => 
    
                            [image] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => 
        
                                            [title] => Logo Resmi
                                            [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                                            [default] => library/image_64x64.png
                                            [@id] => image1
                                            [@width] => 64
                                            [@height] => 64
                                        )

                                    [1] => Array
                                        (
                                            [0] => 
        
                                            [title] => Ürün Resmi
                                            [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                                            [default] => library/image_128x169.png
                                            [@id] => image2
                                            [@width] => 128
                                            [@height] => 169
                                        )

                                )

                            [text] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => 
        
                                            [title] => Başlık Yazısı
                                            [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                                            [default] => Başlık Yazısı
                                            [font] => Arial
                                            [color] => 000000
                                            [size] => 20
                                            [@id] => text1
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                    [1] => Array
                                        (
                                            [0] => 
        
                                            [title] => Web Site Adresi
                                            [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                                            [default] => www.websiteniz.com.tr
                                            [font] => Arial
                                            [color] => 000000
                                            [size] => 12
                                            [@id] => text2
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                    [2] => Array
                                        (
                                            [0] => 
        
                                            [title] => Buton Yazısı
                                            [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                                            [default] => Bilgi İçin Tıklayınız
                                            [font] => Impact
                                            [color] => 000000
                                            [size] => 18
                                            [@id] => text3
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                )

                        )

                )

        )

    [fields:ADVTemplate:private] => Array
        (
            [0] => 
    
            [image] => Array
                (
                    [0] => Array
                        (
                            [0] => 
        
                            [title] => Logo Resmi
                            [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                            [default] => library/image_64x64.png
                            [@id] => image1
                            [@width] => 64
                            [@height] => 64
                        )

                    [1] => Array
                        (
                            [0] => 
        
                            [title] => Ürün Resmi
                            [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                            [default] => library/image_128x169.png
                            [@id] => image2
                            [@width] => 128
                            [@height] => 169
                        )

                )

            [text] => Array
                (
                    [0] => Array
                        (
                            [0] => 
        
                            [title] => Başlık Yazısı
                            [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                            [default] => Başlık Yazısı
                            [font] => Arial
                            [color] => 000000
                            [size] => 20
                            [@id] => text1
                            [@max] => 100
                            [@min] => 10
                        )

                    [1] => Array
                        (
                            [0] => 
        
                            [title] => Web Site Adresi
                            [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                            [default] => www.websiteniz.com.tr
                            [font] => Arial
                            [color] => 000000
                            [size] => 12
                            [@id] => text2
                            [@max] => 100
                            [@min] => 10
                        )

                    [2] => Array
                        (
                            [0] => 
        
                            [title] => Buton Yazısı
                            [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                            [default] => Bilgi İçin Tıklayınız
                            [font] => Impact
                            [color] => 000000
                            [size] => 18
                            [@id] => text3
                            [@max] => 100
                            [@min] => 10
                        )

                )

        )

    [values:ADVTemplate:private] => Array
        (
            [image1] => library/image_64x64.png
            [image2] => library/image_128x169.png
            [text1] => Başlık Yazısı
            [text2] => www.websiteniz.com.tr
            [text3] => Bilgi İçin Tıklayınız
        )

)

ADVTemplate Class Test

ADVTemplate sınıfımızın test edilmesini sağlamak ve değerlerin bir listesini görmek amaçlı bir kod parçası hazırladım. Bu kod, hem temamızın yaratılması sırasında hem de yaratıldıktan sonraki zamanlarda veri değişikliği yaparak sonçları gösteriyor.
Test kodumuz şu şekilde;
/**
 * This is the tester file of the ADVTemplate class.
 * 
 * @author Behçet MUTLU
 * @copyright 2009 Adres Gezgini
 */

include_once("../system.core.php");

$adv = new ADVTemplate("template-1.xml", array("image1"=>"image1.png", "image2"=>"test2.png"));

$adv->setValueOf("image1","test1.png");
echo "< pre>";
$adv->toString();
echo "< /pre>"; 
Test kodumuzun sonuçlanmış olduğu ekran çıktısı da şöyle;
DEBUG:  XML file, "template-1.xml" loaded successfully.

ADVTemplate Object
(
    [name:ADVTemplate:private] => Template 1
    [author:ADVTemplate:private] => Behçet MUTLU
    [datecreated:ADVTemplate:private] => 25-12-2009
    [copyright:ADVTemplate:private] => 2009 Adres Gezgini
    [website:ADVTemplate:private] => www.adresgezgini.com.tr
    [schema:ADVTemplate:private] => template-1.xml
    [isReady:ADVTemplate:private] => 1
    [xml:ADVTemplate:private] => Array
        (
            [template] => Array
                (
                    [0] => 

                    [info] => Array
                        (
                            [0] => 
    
                            [name] => Template 1
                            [author] => Behçet MUTLU
                            [copyright] => 2009 Adres Gezgini
                            [website] => www.adresgezgini.com.tr
                            [datecreated] => 25-12-2009
                        )

                    [fields] => Array
                        (
                            [0] => 
    
                            [image] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => 
        
                                            [title] => Logo Resmi
                                            [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                                            [default] => library/image_64x64.png
                                            [@id] => image1
                                            [@width] => 64
                                            [@height] => 64
                                        )

                                    [1] => Array
                                        (
                                            [0] => 
        
                                            [title] => Ürün Resmi
                                            [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                                            [default] => library/image_128x169.png
                                            [@id] => image2
                                            [@width] => 128
                                            [@height] => 169
                                        )

                                )

                            [text] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => 
        
                                            [title] => Başlık Yazısı
                                            [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                                            [default] => Başlık Yazısı
                                            [font] => Arial
                                            [color] => 000000
                                            [size] => 20
                                            [@id] => text1
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                    [1] => Array
                                        (
                                            [0] => 
        
                                            [title] => Web Site Adresi
                                            [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                                            [default] => www.websiteniz.com.tr
                                            [font] => Arial
                                            [color] => 000000
                                            [size] => 12
                                            [@id] => text2
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                    [2] => Array
                                        (
                                            [0] => 
        
                                            [title] => Buton Yazısı
                                            [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                                            [default] => Bilgi İçin Tıklayınız
                                            [font] => Impact
                                            [color] => 000000
                                            [size] => 18
                                            [@id] => text3
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                )

                        )

                )

        )

    [fields:ADVTemplate:private] => Array
        (
            [0] => 
    
            [image] => Array
                (
                    [0] => Array
                        (
                            [0] => 
        
                            [title] => Logo Resmi
                            [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                            [default] => library/image_64x64.png
                            [@id] => image1
                            [@width] => 64
                            [@height] => 64
                        )

                    [1] => Array
                        (
                            [0] => 
        
                            [title] => Ürün Resmi
                            [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                            [default] => library/image_128x169.png
                            [@id] => image2
                            [@width] => 128
                            [@height] => 169
                        )

                )

            [text] => Array
                (
                    [0] => Array
                        (
                            [0] => 
        
                            [title] => Başlık Yazısı
                            [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                            [default] => Başlık Yazısı
                            [font] => Arial
                            [color] => 000000
                            [size] => 20
                            [@id] => text1
                            [@max] => 100
                            [@min] => 10
                        )

                    [1] => Array
                        (
                            [0] => 
        
                            [title] => Web Site Adresi
                            [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                            [default] => www.websiteniz.com.tr
                            [font] => Arial
                            [color] => 000000
                            [size] => 12
                            [@id] => text2
                            [@max] => 100
                            [@min] => 10
                        )

                    [2] => Array
                        (
                            [0] => 
        
                            [title] => Buton Yazısı
                            [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                            [default] => Bilgi İçin Tıklayınız
                            [font] => Impact
                            [color] => 000000
                            [size] => 18
                            [@id] => text3
                            [@max] => 100
                            [@min] => 10
                        )

                )

        )

    [values:ADVTemplate:private] => Array
        (
            [image1] => test.png
            [image2] => test2.png
            [text1] => Başlık Yazısı
            [text2] => www.websiteniz.com.tr
            [text3] => Bilgi İçin Tıklayınız
        )

)

ADVTemplate Class

Reklam temamızı temsil etmesi amacı ile bir sınıf hazırladık. Bu sınıfın görevi, reklam temasının şemasını XML dosyasından okuyarak, gerekli bilgileri kendi içerisinde barındırmasını sağlamak. Reklam yöneticisi tarafından sürekli kullanılacağı ve bir probelme el vermemesi açısından, isReady fonksiyonu ile de hazır olup olmadığı test edilebilir kılındı. Dolayısı ile, herhangi bir memory overflow olayında veya geç okunma olayında kullanıcıya hata yerine sistem kendi kendini yenileyerek her defasında kesin sonuç geri döndürecek.
Hazırlamış olduğum sınıfın kodu şöyle:
/**
 * This class is used to represent a ADV Template to provide required fileld and values along
 * the reqistration process of the advertisement.
 * This class uses Domdocument object library to load xml schema file.
 * 
 * @author Behçet MUTLU
 * @copyright 2009 Adres Gezgini
 */

class ADVTemplate {
    
    private $name;
    private $author;
    private $datecreated;
    private $copyright;
    private $website;
    private $schema;
 private $isReady;
 private $xml;
 private $fields;
 private $values;

 /**
 * This is the general constructor of the ADV Template class that used to initialize the
 * ADV Template itself with given arguments.
 */
 public function __construct($schema = "", $values = array())
 {
  $this->schema = $schema;
        $this->isReady = false;
  
  if($this->schema != "")
   $this->load();
   
        if(sizeof($values) > 0)
            $this->setValues($values);
 }
    
    /**
 * This method is used to initialize the Template from the schema file and set the values
 */
 private function initialize()
 {
  $this->name = $this->xml["template"]["info"]["name"];
        $this->author = $this->xml["template"]["info"]["author"];
        $this->datecreated = $this->xml["template"]["info"]["datecreated"];
        $this->copyright = $this->xml["template"]["info"]["copyright"];
        $this->website = $this->xml["template"]["info"]["website"];
        $this->fields = $this->xml["template"]["fields"];
        
        foreach($this->fields as $fieldType)
        {
            if($fieldType != 0)
                foreach($fieldType as $field)
                {
                    if($field != 0)
                        $this->values[$field["@id"]] = isset($field["default"]) ? $field["default"] : "";
                }
        }
 }

 /**
 * This method is used to initialize the Template from the schema file and set the values
 */
 public function load()
 {
  $xml = new CArray2xml2array();

  if($xml->setXMLFile($this->schema))
        {
            $this->xml = $xml->toArray();
            
            $this->isReady = true;
            
            $this->initialize();
   debug("XML file, \"" . $xml->getXMLFile() . "\" loaded successfully.","pre");
  }
        else
  {
            $this->isReady = false;
   debug("Error: XML file could not be loaded!");
  }
 }
    
    /**
 * This method is used to learn if the xml file is ready or not
 */
 public function ready()
    {
        return $this->isReady;
    }
 
 
 /**
 * This method is used to set value of the class
 */
 public function setName($value) { $this->name = $value; }
 public function setAuthor($value) { $this->name = $value; }
 public function setWebsite($value) { $this->website = $value; }
 public function setDatecreated($value) { $this->datecreated = $value; }
 public function setCopyright($value) { $this->copyright = $value; }
 public function setSchema($value) { $this->schema = $value; }
    public function setFields($value) { $this->fields = $value; }
    public function setXml($value) { $this->xml = $value; }
    
    /**
 * This method is used to get value of the class
 */
 public function getName() { return $this->name; }
    public function getAuthor() { return $this->author; }
    public function getWebsite() { return $this->website; }
    public function getDatecreated() { return $this->datecreated; }
    public function getCopyright() { return $this->copyright; }
    public function getSchema() { return $this->schema; }
    public function getFields() { return $this->fields; }
    public function getXml() { return $this->xml; }
    
    /**
 * This method is used to set value of the class
 */
 public function setValueOf($id, $value)
 {
  $this->values[$id] = $value;
 }
    
    /**
 * This method is used to set values of the class
    * The spacial thing here is setting only given indexes but keeping the rest of
    * the values remain same.
 */
 public function setValues($values)
 {
        foreach($values as $id=>$value)
            $this->setValueOf($id,$value); 
 }
    
    
    /**
 * This method is used to get a string output of this object.
 */
 public function toString()
 {
        print_r($this);
 }
}

25 Aralık 2009 Cuma

XML Reklam Tema Şablonu

Reklamların her biri için bir xml şablon tanım dosyası olması gerektiğinden daha önce bahsetmiştik. Bu xml şablonların en önemli özelliklerinden biri reklam şablonumuz ile ilgili bilgileri ve ihtiyaç duyduğu verileri tanımlamasıydı. Bu doğrultuda ilk reklam şablonumuzu tanıtan bir XML şablonunu hazırladım.
XML şablonumuzun görünümü şöyle;
<?xml version="1.0" encoding="utf-8"?>
<template>
    <info>
        <name>Template 1</name>
        <author>Behçet MUTLU</author>
        <copyright>2009 Adres Gezgini</copyright>
        <website>www.adresgezgini.com.tr</website>
        <datecreated>25-12-2009</datecreated>
    </info>
<fields>
    <image id="image1" width="64" height="64">
        <title>Logo Resmi</title>
        <description>Eklemek istediğiniz logo resmini dosyadan seçiniz.</description>
        <default>library/image_64x64.png</default>
    </image>
    <image id="image2" width="128" height="169">
        <title>Ürün Resmi</title>
        <description>Eklemek istediğiniz ürün resmini dosyadan seçiniz.</description>
        <default>library/image_128x169.png</default>
    </image>
    <text id="text1" max="100" min="10">
        <title>Başlık Yazısı</title>
        <description>Eklemek istediğiniz başlık yazısını belirtiniz.</description>
        <default>Başlık Yazısı</default>
        <font>Arial</font>
        <color>000000</color>
        <size>20</size>
    </text>
    <text id="text2" max="100" min="10">
        <title>Web Site Adresi</title>
        <description>Eklemek istediğiniz web site adresinizi belirtiniz.</description>
        <default>www.websiteniz.com.tr</default>
        <font>Arial</font>
        <color>000000</color>
        <size>12</size>
    </text>
    <text id="text3" max="100" min="10">
        <title>Buton Yazısı</title>
        <description>Eklemek istediğiniz buton yazısını belirtiniz.</description>
        <default>Bilgi İçin TıklayınIz</default>
        <font>Impact</font>
        <color>000000</color>
        <size>18</size>
    </text>
</fields>
</template>

Class AutoLoader

PHP çekirdeğinde bulunan _autoload fonksiyonuna biraz daha esneklik ve yetenek kazandıran bir fonksiyon üstüne yazma(overwrite) işlemini gerçekleştirdik. Bu fonksiyon sayesinde, belirttiğimiz özel klasörler altındaki sınıfların ve yine belirtebileceğimiz birden fazla format ile kullanıldıkları anda otomatik olarak PHP dosyamıza yüklenmesini sağlayacağız.
AutoLoad fonksiyonumuzun içeriği şöyle:
/**
 *
 * @param string $className Class or Interface name automatically
 *              passed to this function by the PHP Interpreter
 */
function autoLoader($className){
    //Directories added here must be
//relative to the script going to use this file.
//New entries can be added to this list
    $directories = array(
      '',
      'classes/'
    );

    //Add your file naming formats here
    $fileNameFormats = array(
      '%s.php',
      '%s.class.php',
      'class.%s.php',
      '%s.inc.php'
    );

    // this is to take care of the PEAR style of naming classes
    $path = str_ireplace('_', '/', $className);
    if(@include_once $path.'.php'){
        return;
    }
   
    foreach($directories as $directory){
        foreach($fileNameFormats as $fileNameFormat){
            $path = $directory.sprintf($fileNameFormat, $className);
            if(file_exists($path)){
                include_once $path;
                return;
            }
        }
    }
}

spl_autoload_register('autoLoader');
Yukarıdaki kod PHP.net web sitesinde örneklerden edinilmiştir.

22 Aralık 2009 Salı

XML Dosyasından Veri Alma

Reklam Yöneticimizin en önde yeteneklerinden biri olacak olan şema okuma işlemi için şemaların XML formatından gelen tanımlarının okunarak bir veri yapısında tutulması gerekiyor. Bunun için yine PHP'de domdocument() nesne kütüphanesini kullanarak hazırladığımız XML sınıfına eklenti hazırladım. Eklenti kodu aşağıdaki gibi geliştirildi:

public function toArray(DOMNode$oDomNode = null)
    {
        // return empty array if dom is blank
        if (is_null($oDomNode) && !$this->doc->hasChildNodes()) {
            return array();
        }
        $oDomNode = (is_null($oDomNode)) ? $this->doc->documentElement : $oDomNode;
        if (!$oDomNode->hasChildNodes()) {
            $mResult = $oDomNode->nodeValue;
        } else {
            $mResult = array();
            foreach ($oDomNode->childNodes as $oChildNode) {
                // how many of these child nodes do we have?
                // this will give us a clue as to what the result structure should be
                $oChildNodeList = $oDomNode->getElementsByTagName($oChildNode->nodeName);
                $iChildCount = 0;
                // there are x number of childs in this node that have the same tag name
                // however, we are only interested in the # of siblings with the same tag name
                foreach ($oChildNodeList as $oNode) {
                    if ($oNode->parentNode->isSameNode($oChildNode->parentNode)) {
                        $iChildCount++;
                    }
                }
                $mValue = $this->toArray($oChildNode);
                $sKey = ($oChildNode->nodeName {0}== '#') ? 0 : $oChildNode->nodeName;
                $mValue = is_array($mValue) ? $mValue[$oChildNode->nodeName] : $mValue;
                // how many of thse child nodes do we have?
                if ($iChildCount > 1) { // more than 1 child - make numeric array
                    $mResult[$sKey][] = $mValue;
                } else {
                    $mResult[$sKey] = $mValue;
                }
            }
            // if the child is < foo>bar< /foo>, the result will be array(bar)
            // make the result just 'bar'
            if (count($mResult) == 1 && isset($mResult[0]) && !is_array($mResult[0])) {
                $mResult = $mResult[0];
            }
        }
        // get our attributes if we have any
        $arAttributes = array();
        if ($oDomNode->hasAttributes()) {
            foreach ($oDomNode->attributes as $sAttrName => $oAttrNode) {
                // retain namespace prefixes
                $arAttributes["@{$oAttrNode->nodeName}"] = $oAttrNode->nodeValue;
            }
        }
        // check for namespace attribute - Namespaces will not show up in the attributes list
        if ($oDomNode instanceof DOMElement && $oDomNode->getAttribute('xmlns')) {
            $arAttributes["@xmlns"] = $oDomNode->getAttribute('xmlns');
        }
        if (count($arAttributes)) {
            if (!is_array($mResult)) {
                $mResult = (trim($mResult)) ? array($mResult) : array();
            }
            $mResult = array_merge($mResult, $arAttributes);
        }
        $arResult = array($oDomNode->nodeName => $mResult);
        return $arResult;
    }

Bu kodun test edilmesinde kullandığım örnek kod ise;

<?php

    /**
     * The tester of the XML domdocument toArray method.
     * 
     * @author Behçet MUTLU
     * @copyright 2009
     */
     
    
    require_once("CArray2xml2array.class.php");
    
    $xml = new CArray2xml2array();
    
    if($xml->setXMLFile("library/file.xml"))
        echo "< p>XML file, < i>\"" . $xml->getXMLFile() . "\"< /i> loaded successfully.< /p>";
    else
    {
        echo "< p>Error: XML file could not be loaded!< /p>";
        exit();
    }
    
    echo "< pre>";
    print_r($xml->toArray());
    echo "< /pre>";



?>

Bu örnek kodun verdiği çıktı da şu şekildeydi:

XML file, "library/file.xml" loaded successfully.

Array
(
    [movie] => Array
        (
            [0] => 

            [clip] => Array
                (
                    [0] => Array
                        (
                            [@id] => upState
                            [@import] => up.png
                        )

                    [1] => Array
                        (
                            [@id] => downState
                            [@import] => down.png
                        )

                    [2] => Array
                        (
                            [@id] => overState
                            [@import] => over.png
                        )

                    [3] => Array
                        (
                            [@id] => disabledState
                            [@import] => disabled.png
                        )

                )

            [frame] => Array
                (
                    [0] => 
  
                    [library] => Array
                        (
                            [0] => 
    
                            [clip] => Array
                                (
                                    [0] => 
      
                                    [frame] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [0] => 
        
                                                    [place] => Array
                                                        (
                                                            [@id] => upState
                                                            [@depth] => 1
                                                        )

                                                    [stop] => 
                                                    [@name] => Up
                                                )

                                            [1] => Array
                                                (
                                                    [0] => 
        
                                                    [place] => Array
                                                        (
                                                            [@id] => downState
                                                            [@depth] => 2
                                                        )

                                                    [stop] => 
                                                    [@name] => Down
                                                )

                                            [2] => Array
                                                (
                                                    [0] => 
        
                                                    [place] => Array
                                                        (
                                                            [@id] => overState
                                                            [@depth] => 3
                                                        )

                                                    [stop] => 
                                                    [@name] => Over
                                                )

                                            [3] => Array
                                                (
                                                    [0] => 
        
                                                    [place] => Array
                                                        (
                                                            [@id] => disabledState
                                                            [@depth] => 4
                                                        )

                                                    [stop] => 
                                                    [@name] => Disabled
                                                )

                                        )

                                    [@id] => testButton
                                )

                        )

                )

            [place] => Array
                (
                    [@id] => testButton
                    [@depth] => 1
                )

            [@width] => 320
            [@height] => 240
            [@framerate] => 12
        )

)

16 Aralık 2009 Çarşamba

Uploadify Plugin

jQuery için geliştirilmiş ve halen geliştirilmekte olan, Uploadify adında bir Upload eklentisini inceledim. Bu eklenti kolaylıkla kullanılabiliyor ve yükleme sürecini de gösteriyor. Flash arayüze sahip ve dosyanın ne kadarının yüklendiğini gösteren yükleme çubuğu var. Kullanıcıya çok daha etkin bir arayüz sağlayacak bu eklentinin sistemimize uygunluğu da şüphesiz. Eklenti ile ilgili bilgiye http://www.uploadify.com/ adresinden ulaşılabiliyor.
Upload problemimizi çözdüğümüze göre, artık editörümüzün işlem kısmını bitirebiliriz. Bundan sonraki işlemimiz temalarımızın XML'ler ile tanımlanması ve manipüle edilebilir hale getirilmesi ile ilgili olacak.

15 Aralık 2009 Salı

AjaxUpload Çöp!

Gerekli değişiklikleri yapmama izin vermemesi, dosya büyüklüğü ve gereksiz tekrarlar sebebi ile AjaxUpload kütüphanesini projeden çıkartıyorum. Bunun yerine yaptığım araştırmada jQuery ile bu işin çok daha kolay yapıldığını görüdüm. Örnek jQuery kodu şöyle:
$(document).ready(function() {
   // generate markup
   $("#rating").append("Please rate: ");
   
   for ( var i = 1; i <= 5; i++ )
     $("#rating").append("" + i + " ");
   
   // add markup to container and apply click handlers to anchors
   $("#rating a").click(function(e){
     // stop normal link click
     e.preventDefault();
     
     // send request
     $.post("rate.php", {rating: $(this).html()}, function(xml) {
       // format and output result
       $("#rating").html(
         "Thanks for rating, current average: " +
         $("average", xml).text() +
         ", number of votes: " +
         $("count", xml).text()
       );
     });
   });
 });

12 Aralık 2009 Cumartesi

Yeni Reklam Tasarımı ile Şablon Editörünün Testi

Bu gün yeni bir reklam şablonu oluşturdum. Amacım var olan editörü kullanarak, yeni bir şablonda yapabileceğim şeyleri test etmekti. Test sonucunda bir kaç problemimiz olduğunu farkettim. Birden fazla resim eklememiz gerektiği zamanlar için bir otomatizasyon hazırlamamıştık. Bu otomatizasyonun hazırlanması bir sonraki işimiz olacak. Bunun dışında, animasyonda Dinamik bir yazının Alpha efektinin verilmesinde problem olduğunu farkettim. Çözebilmek için oldukça zaman harcamam gerekti. Halbuki problem oldukça basit ve gözümün önündeymiş. İlk yapmam gerekeni son yaptım ve google'adım problemi, bir çok luzumsuz sitenin ardında bir sitede cevabı buldum.
Problemin genel açıklaması şöyle. Dinamik bir yazının resim ve arkaplanlı sabit bir nesne gibi görünürlüğünün değimesini istemiştim. Halbuki dinamik olan yazı karakterlerinin resime dönüştürülmesi gerekiyordu. Bulduğum cevap ise, embeded text özelliğini kullanmamdı. Ardından farkettim ki flash dosyamın boyutu da çok arttı. limitimiz 50K iken ben çoktan 200K'ları bulmuştum. Bunun da çözümü karakterleri tek tek yazmak ile çözdüm. Yani Embeded Text özelliğine; "1234567890*-üğpoıuytrewqasdfghjklşi,.çömnbvcxz< >ZXCVBNMÖÇ:;İŞLKJHGFDSAQWERTYUIOPĞÜ_?=)(/&%+^'!é #${[]}\~ şeklinde bir string girdim. Burada yaptığım şey aslında, yazılarda kullanılabilecek karakterleri tek tek tanımlamaktı. Bunları daha da kısaltabilirdik ancak, şimdilik gerek yok.
Sonuç olarak,yeni temamızı çalıştırabildim. Problemler de iyi zamanda ortaya çıktı. Yeni temamızın görünümü yandaki gibi.

11 Aralık 2009 Cuma

Adım Adım İlk Reklamımız #6


Reklam yöneticimizin kayıt formundan flash dosyamıza veri gönderiminde kod karmaşıklığından kurtulmak için bir jQuery kütüphanesi hazırlayacağımızı belirtmiştim. Bahsettiğim bu kütüphane, from nesnelerini otomatik olarak farkederek, flash dosyası ile ilişkilendiriyor ve güncellemeler yapabiliyor.
Hazırladığım jQuery kodu karmaşıklığı gidermesinin yanı sıra, hem dinamizm kazandırdı hem de anlaşılmasını kolaylaştırdı.
Yaptığım değişiklikler iki taraflı oldu, öncelikle SWF nesnemizi oluştururken hazırladığım kod;
<script type="text/javascript" charset="utf-8">
   var flashVars = new Array();
$(document).ready(
   function () {
   var _flashVars = new Array();
   
   $('.SWFVar').each(function(){
   _flashVars[this.id] = this.value;
   })
   .change(function(){
   $('.SWFVar').each(function(){
   var _id = this.id;
   var _value = this.value;
   
   $('#adv_container').flash(
   function(){this.SetVariable('/:' + _id, _value);});
   });
   });
   
   $('#adv_container').flash(
   {
   swf: 'adv_templates/TextTemp1.swf',
   params: {
   play: true
   },
   flashvars: _flashVars,
   height: 240,
   width: 300
   }
   );
   }
   );
   </script>
Bu kod hem Flash dosyamıza veri gönderilmesini, hem de her bir nesneye onChange anlarına güncelleme eklenmesini sağlıyor. 
Ve daha sonra da HTML Form nesnelerinde kullanmamız gereken kod;
<input name="image1" id="image1" type="hidden" value="uploads/smile.png" class="SWFVar"/>
Burada belirtmeliyim ki, class içerisinde belirtmiş olduğumuz SWFVar class'ını kullanarak form nesnelerini SWF dosyamız ile ilişkilendirioruz.

9 Aralık 2009 Çarşamba

Adım Adım İlk Reklamımız #5


Reklam yöneticimizin resim yükleme ve yüklenen resmin flash dosyasında görüntülenmesi işlemlerini bitirmiş bulunuyoruz. Yapılan son değişiklikler ile artık, editörden istenilen düzeyde bilgi flash dosyasına gönderilebiliyor ve değişikliklerin yapılması anlarında flash dosyamız güncellenerek tekrar görüntüleniyor.
Bu noktada geriye kalan yalnızca form nesnelerinden alınan bilgilerin gerek MySQL, gerekse e-posta yolu ile kayıt edilmesini sağlamak.
Fakat bu işlemden önce bence yapılması gereken daha önemli ve öncelikli işlem, kod karmaşıklığından kurtulmak olmalıdır. Flash dosyasına veri yazarken bir çok konfigürasyonu elle yazmak zorunda kaldım. Bu konfigürasyoların biraz daha otomatize edilmesi şart! En baştan beri esnek temalar söz konusu olduğu için, bir sonraki adımımızda form nesnelerimizin otomatize edilmesini ve gerekli konfigürasyonların da form nesnelerine bağlanmasını sağlayacak jQuery kütüphanesini hazırlayacağız.

8 Aralık 2009 Salı

Actionscript 2.0 ile Resim Yükleme

ADV Manager sistemimizde kullanmamız gereken bir diğer uygulama kodu da flash dosyamızda yüklediğimiz resimlerin görüntülenmesi ile ilgili olmalı. Bunun içine araştırıp bulduğum örnek kod aşağıdaki gibiydi.

var my_pb:mx.controls.ProgressBar;
my_pb.mode = "manual";

this.createEmptyMovieClip("img_mc", 999);

var my_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function(target_mc:MovieClip):Void {
    my_pb.label = "loading: " + target_mc._name;
};
mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void {
    var pctLoaded:Number = Math.ceil(100 * (numBytesLoaded / numBytesTotal));
    my_pb.setProgress(numBytesLoaded, numBytesTotal);
};
my_mcl.addListener(mclListener);
my_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", img_mc);

Örneğin alına http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001025.html linkinden ulaşılabiliyor.

5 Aralık 2009 Cumartesi

Adım Adım İlk Reklamımız #4


Resim yükleme adımımızı da tamamlamış bulunmaktayım. Resim uploads klasörü altına ekleniyor ve eğer aynı isimde bir dosya var ise bu dosyanın ismi bir arttırılarak yeni bir dosya olarak kaydediliyor.
Bir sonraki adımımızda da yüklediğimiz resmi flash dosyasında görüntülemeyi hazırlayacağız.

4 Aralık 2009 Cuma

Ajax ile Dosya Yükleme

Dosya yükleme işlemlerinin bir ajax aracı ile gerçekleştirilmesi ve bu dosyaların yine bu araç ile yüklenme durumunun kullanıcıya gösterilmesini sağlamalıyız. Bu işlem için birkaç tane Ajax framework ve JQuery plugin'i inceledim. Bir de ACE denen bir php-ajax dönüşümlü kütüphane var. Bunların hepsi çok etkiliydi ve yeri geldiğinde ACE'in de kullanımı söz konusu olabilir. Kullanımı ve cross browser desteğinden ötürü ben AJAX Upload isimli JQuery plugin'inin kullanılmasında yarar olduğunu düşünüyorum.
AJAX Upload'ın resmi sitesi: http://valums.com/ajax-upload/
Bir sonraki işim artık, Ajax Upload ile Upload Class'ını birleştirerek resim yükleme aracımızı hazırlamak olucak.

class.upload.php

Upload Class'ı, php4 ve php5 destekli, çok dilli ve çok fonksiyonel bir dosya yükleme ve yönetme sınıfıdır. Bu sınıf ayrıca resim dosyalarının yüklenmesinde ve düzenlenmesinde boyut değiştirmek, yansıma eklemek, kalite düşürmek gibi özellikleri de barındırıyor. Yaptığım testler sonucunda en etkili olanı bu sınıftı. Reklamımıza resim dosyalarının yüklenmesinde kolaylıkla bu sınıfı kullanabileceğimizi düşünüyorum. Üstelik kullanımı da çok basit, örnek bir kullanım kodu aşağıdaki gibi
Create a simple HTML file, with a form such as:
 
 <form enctype="multipart/form-data" method="post" action="upload.php">
    <input type="file" size="32" name="image_field" value="">
    <input type="submit" name="Submit" value="upload">
 </form>
 
 Create a file called upload.php:
 
 $handle = new upload($_FILES['image_field']);
 if ($handle->uploaded) {
    $handle->file_new_name_body   = 'image_resized';
    $handle->image_resize         = true;
    $handle->image_x              = 100;
    $handle->image_ratio_y        = true;
    $handle->process('/home/user/files/');
    if ($handle->processed) {
       echo 'image resized';
       $handle->clean();
    } else {
       echo 'error : ' . $handle->error;
    }
 }
 

2 Aralık 2009 Çarşamba

Adım Adım İlk Reklamımız #3

HTML formumuz ve Flash reklamımız arasındaki ilişkiyi otomatize edebilmek için Adobe'nin geliştirmiş olduğu ExternalInterface kütphanesini kullanmayı planlamıştık. Bu adımımızda özetle; yapılan yazı değişiklikleri, renk değişiklikleri ve font değişikliklerinin anında Flash animasyonumuzda görüntülenmesini sağlayacağız.
...
Şimdi, yaptığımız çalışmadaki bir gelişmeden bahsetmek isyiyorum. Adobe'nin hazırlamış olduğu ExternalInterface kütüphanesini kullanmaya gerek kalmadan da aslında biz güvenli bir şekilde flash dokümanına değişken gönderebiliyoruz. SWFObject adında bir araç sayesinde bu işi kolaylıkla yapabileceğiz.
Bu gelişmeler doğrultusunda çalışmalarımızı sürdürelim, bakalım ortaya ne çıkacak...
...

Yaptığımız değişiklikler ile, editörümüzden artık, flash dosyasında değişiklikler yapmamız mümkün olabiliyor. Renk, font, foyut ve yazının değiştirilmesi ve flash dosyasında daha kolay bir yönetim sağlanabilmesi için reklam ön izlemesi bölümünde control butonları koymayı planladım. Bu butonlar sayesinde, güncelleme işlemleri, oynatma, durdurma, ileri sarma ve geri sarma gibi özellikler eklememiz söz konusu olabiliyor. Yine sistemin hazırlanmasında bir otomatizasyon gerekeceği için bu konuda daha sonra geliştirme yapmamız gerekecektir.
Özetle, editörümüzün reklam dosyamıza değişkenler göndermesi ve bu değişkenlerin flash dosyamız tarafından kullanılması işlemlerini gerçekleştirdik ve sonuç olarak, flash dosyası içerisinde bulunan yazı alanlarının düzenlenmesi gerçekleşebildi.
Bir sonraki adımımızda Flash dökümanımıza kullanıcı tarafından logo eklenmesini hazırlayacağız.

1 Aralık 2009 Salı

Adım Adım İlk Reklamımız #2


ColorPicker(RenkSeçici) aracımızı Cross Browser destiği verdiğini bildiğim JQuery Javascript kütüphanesini kullanarak hazırladım. Bu kütüphanenin önemli özelliklerinden biri birden fazla tarayıcı tarafından desteklenebilecek kodlar üretmesi ve kendi içerisinde barındırdığı yazılım sayesine her kullanıcıya aynı görünümü sağlamasıdır. Bu sayede Renk Seçici(ColorPicker)miz her kullanıcı tarafından rahatlıkla kullanılabilecek. Kaynak koduna geçmeden önce, bu Renk Seçicinin özelliklerinden biraz bahsedelim.
Renk Seçicimizin hazırlanmasındaki asıl amaç, kullanıcıların bilemeyebileceği RGB ve Hex tabanlı kodlar ile renklerin tanımanması ve tabiki kullanıcıların belli seçenekler ile kısıtlanmasını ve dolayısı ile de hata oranının azaltılmasını sağilamaktır.
Renk Seçicimizin kurulumu oldukça basit. Öncelikle iki ayrı kütüphaneyi ayfamıza eklememiz gerekmektedir. Bunlardan ilki JQuery, diğeri de ColorPicker. örnek kod aşağıdaki gibidir.
<script type="text/javascript" src="js/jquery.js"></script>

<script type="text/javascript" src="js/iColorPicker.js"></script>

 Daha sonra form nesnemizi de şu ekilde tanımlamamız gerekmektedir.
<input name="fontColor1" type="text" id="fontColor1" value="#cc0012" class="iColorPicker"/>
Bu tanımlamada dikkat etmemiz gereken yerlerin ilki Class tanımlamasında iColorPicker classının seçilmiş olması ve diğeri de her bir Renk Seçici form nesnesinin farklı id değerlerine sahip olmasıdır.
iColorPicker.js dosyasının içeriği şu şekilde geliştirildi.
function iColorShow(id,id2){var eICP=jQuery("#"+id2).position();jQuery("#iColorPicker").css({'top':eICP.top+(jQuery("#"+id).outerHeight())+"px",'left':(eICP.left)+"px",'position':'absolute'}).fadeIn("fast");jQuery("#iColorPickerBg").css({'position':'absolute','top':0,'left':0,'width':'100%','height':'100%'}).fadeIn("fast");var def=jQuery("#"+id).val();jQuery('#colorPreview span').text(def);jQuery('#colorPreview').css('background-color',def);jQuery('#color').val(def);var hxs=jQuery('#iColorPicker');for(i=0;i<hxs.length;i++){var tbl=document.getElementById('hexSection'+i);var tblChilds=tbl.childNodes;for(j=0;j<tblChilds.length;j++){var tblCells=tblChilds[j].childNodes;for(k=0;k<tblCells.length;k++){jQuery(tblChilds[j].childNodes[k]).unbind().mouseover(function(a){var aaa="#"+jQuery(this).attr('hx');jQuery('#colorPreview').css('background-color',aaa);jQuery('#colorPreview span').text(aaa)}).click(function(){var aaa="#"+jQuery(this).attr('hx');jQuery("#"+id).val(aaa);jQuery("#"+id2).val(aaa).css("background",aaa);jQuery("#iColorPickerBg").hide();jQuery("#iColorPicker").fadeOut();jQuery(this)})}}}}this.iColorPicker=function(){jQuery("input.iColorPicker").each(function(i){if(i==0){jQuery(document.createElement("div")).attr("id","iColorPicker").css('display','none').html('<table class="pickerTable" id="pickerTable0"><thead id="hexSection0"><tr><td style="background:#f00;" hx="f00"></td><td style="background:#ff0" hx="ff0"></td><td style="background:#0f0" hx="0f0"></td><td style="background:#0ff" hx="0ff"></td><td style="background:#00f" hx="00f"></td><td style="background:#f0f" hx="f0f"></td><td style="background:#fff" hx="fff"></td><td style="background:#ebebeb" hx="ebebeb"></td><td style="background:#e1e1e1" hx="e1e1e1"></td><td style="background:#d7d7d7" hx="d7d7d7"></td><td style="background:#cccccc" hx="cccccc"></td><td style="background:#c2c2c2" hx="c2c2c2"></td><td style="background:#b7b7b7" hx="b7b7b7"></td><td style="background:#acacac" hx="acacac"></td><td style="background:#a0a0a0" hx="a0a0a0"></td><td style="background:#959595" hx="959595"></td></tr><tr><td style="background:#ee1d24" hx="ee1d24"></td><td style="background:#fff100" hx="fff100"></td><td style="background:#00a650" hx="00a650"></td><td style="background:#00aeef" hx="00aeef"></td><td style="background:#2f3192" hx="2f3192"></td><td style="background:#ed008c" hx="ed008c"></td><td style="background:#898989" hx="898989"></td><td style="background:#7d7d7d" hx="7d7d7d"></td><td style="background:#707070" hx="707070"></td><td style="background:#626262" hx="626262"></td><td style="background:#555" hx="555"></td><td style="background:#464646" hx="464646"></td><td style="background:#363636" hx="363636"></td><td style="background:#262626" hx="262626"></td><td style="background:#111" hx="111"></td><td style="background:#000" hx="000"></td></tr><tr><td style="background:#f7977a" hx="f7977a"></td><td style="background:#fbad82" hx="fbad82"></td><td style="background:#fdc68c" hx="fdc68c"></td><td style="background:#fff799" hx="fff799"></td><td style="background:#c6df9c" hx="c6df9c"></td><td style="background:#a4d49d" hx="a4d49d"></td><td style="background:#81ca9d" hx="81ca9d"></td><td style="background:#7bcdc9" hx="7bcdc9"></td><td style="background:#6ccff7" hx="6ccff7"></td><td style="background:#7ca6d8" hx="7ca6d8"></td><td style="background:#8293ca" hx="8293ca"></td><td style="background:#8881be" hx="8881be"></td><td style="background:#a286bd" hx="a286bd"></td><td style="background:#bc8cbf" hx="bc8cbf"></td><td style="background:#f49bc1" hx="f49bc1"></td><td style="background:#f5999d" hx="f5999d"></td></tr><tr><td style="background:#f16c4d" hx="f16c4d"></td><td style="background:#f68e54" hx="f68e54"></td><td style="background:#fbaf5a" hx="fbaf5a"></td><td style="background:#fff467" hx="fff467"></td><td style="background:#acd372" hx="acd372"></td><td style="background:#7dc473" hx="7dc473"></td><td style="background:#39b778" hx="39b778"></td><td style="background:#16bcb4" hx="16bcb4"></td><td style="background:#00bff3" hx="00bff3"></td><td style="background:#438ccb" hx="438ccb"></td><td style="background:#5573b7" hx="5573b7"></td><td style="background:#5e5ca7" hx="5e5ca7"></td><td style="background:#855fa8" hx="855fa8"></td><td style="background:#a763a9" hx="a763a9"></td><td style="background:#ef6ea8" hx="ef6ea8"></td><td style="background:#f16d7e" hx="f16d7e"></td></tr><tr><td style="background:#ee1d24" hx="ee1d24"></td><td style="background:#f16522" hx="f16522"></td><td style="background:#f7941d" hx="f7941d"></td><td style="background:#fff100" hx="fff100"></td><td style="background:#8fc63d" hx="8fc63d"></td><td style="background:#37b44a" hx="37b44a"></td><td style="background:#00a650" hx="00a650"></td><td style="background:#00a99e" hx="00a99e"></td><td style="background:#00aeef" hx="00aeef"></td><td style="background:#0072bc" hx="0072bc"></td><td style="background:#0054a5" hx="0054a5"></td><td style="background:#2f3192" hx="2f3192"></td><td style="background:#652c91" hx="652c91"></td><td style="background:#91278f" hx="91278f"></td><td style="background:#ed008c" hx="ed008c"></td><td style="background:#ee105a" hx="ee105a"></td></tr><tr><td style="background:#9d0a0f" hx="9d0a0f"></td><td style="background:#a1410d" hx="a1410d"></td><td style="background:#a36209" hx="a36209"></td><td style="background:#aba000" hx="aba000"></td><td style="background:#588528" hx="588528"></td><td style="background:#197b30" hx="197b30"></td><td style="background:#007236" hx="007236"></td><td style="background:#00736a" hx="00736a"></td><td style="background:#0076a4" hx="0076a4"></td><td style="background:#004a80" hx="004a80"></td><td style="background:#003370" hx="003370"></td><td style="background:#1d1363" hx="1d1363"></td><td style="background:#450e61" hx="450e61"></td><td style="background:#62055f" hx="62055f"></td><td style="background:#9e005c" hx="9e005c"></td><td style="background:#9d0039" hx="9d0039"></td></tr><tr><td style="background:#790000" hx="790000"></td><td style="background:#7b3000" hx="7b3000"></td><td style="background:#7c4900" hx="7c4900"></td><td style="background:#827a00" hx="827a00"></td><td style="background:#3e6617" hx="3e6617"></td><td style="background:#045f20" hx="045f20"></td><td style="background:#005824" hx="005824"></td><td style="background:#005951" hx="005951"></td><td style="background:#005b7e" hx="005b7e"></td><td style="background:#003562" hx="003562"></td><td style="background:#002056" hx="002056"></td><td style="background:#0c004b" hx="0c004b"></td><td style="background:#30004a" hx="30004a"></td><td style="background:#4b0048" hx="4b0048"></td><td style="background:#7a0045" hx="7a0045"></td><td style="background:#7a0026" hx="7a0026"></td></tr></thead><tbody><tr><td style="border:1px solid #000;background:#fff;cursor:pointer;height:60px;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;" colspan="16" align="center" id="colorPreview"><span style="color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;"></span></td></tr></tbody></table><style>#iColorPicker input{margin:2px}</style>').appendTo("body");jQuery(document.createElement("div")).attr("id","iColorPickerBg").click(function(){jQuery("#iColorPickerBg").hide();jQuery("#iColorPicker").fadeOut()}).appendTo("body");jQuery('table.pickerTable td').css({'width':'12px','height':'14px','border':'1px solid #000','cursor':'pointer'});jQuery('#iColorPicker table.pickerTable').css({'border-collapse':'collapse'});jQuery('#iColorPicker').css({'border':'1px solid #ccc','background-color':'#333','padding':'5px','color':'#fff','z-index':9999})}jQuery('#colorPreview').css({'height':'50px'});jQuery(this).attr("readonly", "readonly").click(function(){iColorShow(this.id, 'icp_'+this.id)}).after(' <span id="icp_'+this.id+'" style="cursor:pointer;background-color:' + jQuery(this).val() +'" onclick="iColorShow(\''+this.id+'\',\'icp_'+this.id+'\')" title="Renk ön izlemesi">&nbsp; &nbsp; &nbsp;</span>')})};jQuery(function(){iColorPicker()})
 iColorPicker kaynak kodu, http://plugins.jquery.com/project/iColorPicker adresinden edinilmiş ve gerekli değişiklikler ile daha kullanışlı hale ve tasarımımıza uygun bir hale getirilmiştir.
Ayrıca son sürüm JQuery kütüphanesine http://docs.jquery.com/Downloading_jQuery adresinden ulaşılabiliniyor.

25 Kasım 2009 Çarşamba

Adım Adım İlk Reklamımız #1


ADVManager sisteminin ilk adımı olarak, editör sayfamızı hzırladım. Bu sayfada bulunan formda yapılan değişiklikler, swf dosyası içerisinde görüntülenecek. Bu formda aynı zamanda Gülen surat yerine şirket logosunun da yüklenerek yerleştirilmesi söz konusu olabilecek. Daha sonra bu değişiklikleri kaydetmemiz ve SWF dosyasını oluşturmamız söz konusu olabilir.
Bu formda kullanıcının kullanımını kolaylaştırmak için bir ColorPicker hazırlamamız gerekiyor. Bir sonraki adımda ColorPicker'ımızı hazırlayacağım.

24 Kasım 2009 Salı

HTML ve Flash Arasında Veri Alışverişi (ExternalInterface)

HTML ve Flash dosyaları arasında veri transferini sağlamak için Adobe ExternalInterface adında bir uygulama geliştirmiş. Bu uygulama lokal bir bilgisayarda test edildiği zaman güvenlik açığı oluşturabilmesi sebebiyle web sitesinde bu uygulamanın bir test sunucusunda çalıştırılmasını öneriyor. Zaten Adobe bu durumu engelleyici adımları gerçekleştirmiş ve kullanıcıya gerekli uyarıları yapıyor.
Örneğimize gelince, yeni bir flash dosyası içerisine iki ayrı textbox ve bir de buton yerleştirdikten sonra bu dosyayı ExternalInterfaceExample.fla adı ile kayıt ediyoruz. Daha sonra bu nesnelere sırası ile sending_ti, received_ti ve send_button isimlerini veriyoruz. Flash dosyamızın ilk frame'inde yazılması gereken kod ise şu şekilde.
import flash.external.ExternalInterface;

function getTextFromJavaScript(str:String):Void
{
received_ti.text = "" + str;
}

ExternalInterface.addCallback("sendTextToFlash", this, getTextFromJavaScript);

function clickSend(eventObj:Object):Void
{
var jsArgument:String = sending_ti.text;
var result:Object = ExternalInterface.call("getTextFromFlash", jsArgument);
received_ti.text = "Returned: " + result;
}

send_button.addEventListener("click", clickSend);

Örneğimizin HTML tarafındaki kodu ise aşağıdaki gibi.

<script > function getFlashMovie(movieName) { var isIE = navigator.appName.indexOf("Microsoft") != -1; return (isIE) ? window[movieName] : document[movieName]; } function formSend() { var text = document.htmlForm.sendField.value; getFlashMovie("ExternalInterfaceExample").sendTextToFlash(text); } function getTextFromFlash(str) { document.htmlForm.receivedField.value = "From Flash: " + str; return str + " received"; } </script>

<form name="htmlForm" method="POST" action="javascript:formSend();"> Sending to ActionScript:<br /> <input type="text" name="sendField" value="" /><br /> <input type="submit" value="Send" /><br /> <br /> Received from ActionScript:<br /> <input type="text" name="receivedField"> </form>

Kodları kopyalayıp HTML dosyası içerisine yapıştırdıktan sonra kaydettiğimiz dosyayı çalıştırıyoruz. Daha önce belirttiğim gibi güvenlik uyarısı ile karşılaşacaksınız. Bu uyarıyı önemseyerek Settings tuşuna basarak bir istisna oluşturmalısınız. En sonunda sağlıklı bir şekilde dosyanızı yeniden çalıştırın ve göreceksiniz, formdan gönderilen veriler Flash dosyası içerisinde görüntüleniyor.
Bu örnek kodu ADV Manager Editör panelinde kullanmamız söz konusu olacaktır.

21 Kasım 2009 Cumartesi

swfmill XML Creator Class


SWFMillXMLCreator Class'ı swfmill aracı ile kullanılabilecek XML dosyaları hazırlamaya yarayan bir sınıftır. Bu sınıf sayesinde kolaylıkla SWF dosyaları yaratılabilir, resim, font, animasyon ve ses dosyaları import edilebilir halde XML şemaları hazırlanabiliyor. Sınıfın kaynak kodu aşağıdaki gibi:


/**
 * This class is used to create an xml file for creating or editing swf documents by the tool swfmill.
 * It uses DOMDocument Class. swfmill version is swfmill-0.2.12
 *
 * @author Behçet MUTLU
 
* @email behcetmutlu@b-prodesign.com
 
* @copyright 2009 AdresGezgini.Com
 */

class SWFMillXMLCreator extends DOMDocument
{

    private $movie = null;

    private function addSimpleElement($name, $parent)
    {
        return $this->addElement($name, is_null($parent) ? $this->movie : $parent);
    }

    private function addArrayElement($name, $parent, $vars)
    {
        return $this->addElement($name, is_null($parent) ? $this->movie : $parent, $vars);
    }
   
    //
    /**
     * Importing a Sound
     *
     * We can import sounds with a similar method, where “id” is the linkage
     * id, and we put the following tag inside of the tag:
     *
     *
     *
     * and later in our actionscript (compiled prior via Mtasc, etc). we’d put:
     *
     *         var snd:Sound = new Sound();
     *         snd.attachSound("myID");
     *         snd.start();
     *
     * Note: Requires pre-release 0.2.11.18 or later, and sound is not streamed.
     * Note: Works with 56, 64, 128, 192 and 256 kbps MP3s. Note: joint stereo
     * MP3s, WAV etc don’t play at all.
     *
     * SWFMillXMLCreator::addSound()
     *
     * @param string $id
     * @param string $import
     * @param mixed $parent
     * @return
     */
    public function addSound($id = "foo", $import = "", $parent = null)
    {
        return $this->addArrayElement("sound", $parent, array("id" => $id, "import" => $import));
    }
   
   
    /**
     * Note : That the font tag must exist inside a library tag for the linkage
     * id to work with TextFormats and dynamically created TextFields, or that
     * it is Exported for runtime sharing.
     *
     * The font node get two attributes “id” and “name”. id will be to be used
     * for the format attribute of textfields :
     *
     *
     *
     *
     * name attribute is used in order to get an actionscript reference to the
     * embedded font. When using the TextField’s embedFonts property, you’ll be
     * able to use the TextFormat.font property with this name. This attribute
     * is also a way to group different font by families and retrieve them from
     * actionscript (Flash 8 only).
     *
     * Last thing to note, the id and attributes can be used together as the
     * serve different purposes.
     *
     * SWFMillXMLCreator::placeElement()
     *
     * @param string $id
     * @param string $name
     * @param string $depth
     * @param mixed $parent
     * @return
     */
    public function placeElement($id = "hellobox", $name = "", $depth = "10", $parent = null)
    {
        return $this->addArrayElement("place", $parent, array("id" => $id, "name" => $name, "depth" => $depth));
    }
   
    //
    /**
     * Note : That the font tag must exist inside a library tag for the linkage
     * id to work with TextFormats and dynamically created TextFields, or that
     * it is Exported for runtime sharing.
     *
     * The font node get two attributes “id” and “name”. id will be to be used
     * for the format attribute of textfields :
     *
     *
     *
     *
     * name attribute is used in order to get an actionscript reference to the
     * embedded font. When using the TextField’s embedFonts property, you’ll be
     * able to use the TextFormat.font property with this name. This attribute
     * is also a way to group different font by families and retrieve them from
     * actionscript (Flash 8 only).
     *
     * Last thing to note, the id and attributes can be used together as the
     * serve different purposes.
     *
     * SWFMillXMLCreator::addTextField()
     *
     * @param string $id
     * @param string $width
     * @param string $height
     * @param string $size
     * @param string $font
     * @param string $text
     * @param mixed $parent
     * @return
     */
    public function addTextField($id = "hellobox", $width = "200", $height="50", $size="10", $font="font", $text="hello world!", $parent = null )
    {
        return $this->addArrayElement("textfield", $parent, array("id" => $id, "width" => $width, "height" => $height, "size" => $size, "font" => $font, "text" => $text));
    }
   

    /**
     * Importing Fonts
     *
     * Imoporting TTF fonts works almost like importing images or SWFs,
     * but the tag is used and you can specify the characters you
     * want included with the glyphs attribute. The example imports the
     * numerical characters of vera.ttf.
     *
     *
     *
     * Note : In order to use special characters, you’d use the equivalent
     * xml entity in the glyph attribute. For example é in place of é.
     *
     * SWFMillXMLCreator::addFont()
     *
     * @param string $id
     * @param string $import
     * @param string $glyphs
     * @param mixed $parent
     * @return
     */
    public function addFont($id = "font", $import="", $glyphs="0123456789", $parent = null)
    {
        return $this->addArrayElement("font", $parent, array("id" => $id, "import" => $import, "glyphs" => $glyphs));
           
    }

    /**
     * A simple Library
     *
     * The tag, like almost all others, lives in a tag.
     * You can determine in which frame assets are included into your SWF by
     * using multiple frames and putting it into the one you want your assets
     *  to be available in. You don’t have to import assets into the library,
     * but then they won’t be available to ActionScript. Sometimes you don’t
     * need an asset to be in the library, because you only want to use it as
     * a part of another clip you define, or you place it onto the stage directly
     * with the tag. Of course, you can have several and
     * tags in one . The example will import the same image as above,
     * but this time into the library. The ID also serves as the linkage name if
     * you import into the library.
     *
     *  
     *    
     *  

     *
     *
     *
     * SWFMillXMLCreator::addLibrary()
     *
     * @param mixed $parent
     * @return
     */
    public function addLibrary($parent = null)
    {
        return $this->addSimpleElement("library", $parent);
    }


    /**
     * The most basic SWF
     *
     * That’s the most basic SWF you can make. It’s 320 by 240 pixels, tries
     *  to run at 12 frames per second, and has a white background. Note the
     * tag, except of the and tags, all other
     * tags belong into one. For simplicity’s sake, most examples below will
     * assume you know that, and won’t include the header explicitly.
     *
     *
     *  
     *  
     *

     *
     * If you save this XML code into a file sample.swfml (it could also be
     * sample.xml or in fact anything else), you can compile it into a binary
     * SWF with the following commandline:
     *
     * swfmill simple sample.swfml sample.swf
     *
     *
     *
     * SWFMillXMLCreator::createMovie()
     *
     * @param string $width
     * @param string $height
     * @param string $framerate
     * @return
     */
    public function createMovie($width = "320", $height = "240", $framerate = "12", $version="")
    {
        $this->movie = $this->addArrayElement("movie", null, array("width" => $width,
            "height" => $height, "framerate" => $framerate, "version" => $version));
        return $this->movie;
    }

    /**
     * Creating a frame.
     * SWFMillXMLCreator::addFrame()
     *
     * @param mixed $parent
     * @return
     */
    public function addFrame($name = "", $parent = null)
    {
        return $this->addArrayElement("frame", $parent, array("name" =>$name));
    }
   
     /**
     * Creating a frame.
     * SWFMillXMLCreator::addFrame()
     *
     * @param mixed $parent
     * @return
     */
    public function stop($parent = null)
    {
        return $this->addSimpleElement("stop", $parent);
    }

    /**
     * Setting background property
     * SWFMillXMLCreator::addBackground()
     *
     * @param mixed $color
     * @param mixed $parent
     * @return
     */
    public function addBackground($color, $parent = null)
    {
        return $this->addArrayElement("background", $parent, array("color" => $color));
    }

    /**
     * The tag lets you import JPGs, PNGs (including alpha), SWFs and SVGs (somewhat experimental). 
     * They will be available as MovieClips. This example will import library/foo.jpg
     * and give it the ID foo. swfmill can also import TrueType fonts, but the syntax is different.
     *
     *
     *
     *
     * SWFMillXMLCreator::addClip()
     *
     * @param string $id
     * @param string $import
     * @param mixed $parent
     * @return
     */
    public function addClip($id = "foo", $import = "", $class="", $parent = null)
    {
        return $this->addArrayElement("clip", $parent, array("id" => $id, "import" => $import, "class" => $class));
    }
   
   
    /**
     * Metadata that search engine could index :
     *
     *  < meta title="my title" description="To be indexed" />
     *
     * SWFMillXMLCreator::addMetaData()
     *
     * @param string $title
     * @param string $description
     * @param mixed $parent
     * @return
     */
    public function addMetaData($title="my title", $description="To be indexed", $parent = null)
    {
        return $this->addArrayElement("meta", $parent, array("title" => $title, "description" => $description));
    }
   
    //
    /**
     * Importing a Shared Library
     *
     * You can use shared libraries, too. SWFs created with swfmill always
     * are available for runtime sharing, to import another SWF as a library
     * keep a local copy for testing purposes and import it like this:
     *
     * SWFMillXMLCreator::import()
     *
     * @param string $file
     * @param string $url
     * @param mixed $parent
     * @return
     */
    public function import($file = "library/library.swf", $url = "http://foo.com/library.swf", $parent = null)
    {
        return $this->addArrayElement("import", $parent, array("file" => $file, "url" => $url));
    }
   
    //
    /**
     * Using components
     *
     * As for version 0.2.9 you are able to use the new component tag.
     * No need to use a library and a call tag. Here is a simple example.
     * The combo is instantiated later by actionscript injected using MTASC.
     *
     *  
     *  
     *    
     *  
     *
     * There are still 2 problems with components:
     *
     * SWF extracted from a SWC can be big because they contain data for
     * the Flash IDE, classes and the visual elements that we need.
     * 
     * If you add a couple of components from the same family, swfmill will
     * not check if some classes already exist and you will end up with duplicates.
     * Here is a comparison with 3 components of the same family, an Alert window,
     * a Label and a ProgressBar:
     *
     *  Compiled with the Flash IDE: 12k
     *      
     *  Compiled with swfmill: 99k
     *
     *
     * SWFMillXMLCreator::addComponent()
     *
     * @param string $id
     * @param string $file
     * @param mixed $parent
     * @return
     */
    public function addComponent($id = "ComboBox", $file = "library/library.swf", $parent = null)
    {
        return $this->addArrayElement("component", $parent, array("id" => $id, "file" => $file));
    }
   
    private function addElement($name, $parent, $vars = array())
    {

        $currentElement = $this->createElement($name);
       

        if (sizeof($vars) > 0)
        {
            if(isset($vars[0]) && is_array($vars[0]))
            {
                  foreach ($vars as $element)
                  {
                        $currentElement->appendChild($element);               
                  }
                           
            }
            else
            {
                foreach ($vars as $var => $value) {
                    if(isset($value) && !is_null($value) && $value != "")
                        $currentElement->setAttribute($var, $value);
                }               
            }
        }
       
        if (!is_null($parent))
            $parent->appendChild($currentElement);

        return $currentElement;
    }

    /**
     * SWFMillXMLCreator::toArray()
     * @author Yarg Dahc
     * @link  http://php.net/manual/en/class.domdocument.php
     * @param mixed $oDomNode
     * @return
     */
    public function toArray(DOMNode$oDomNode = null)
    {
        // return empty array if dom is blank
        if (is_null($oDomNode) && !$this->hasChildNodes()) {
            return array();
        }
        $oDomNode = (is_null($oDomNode)) ? $this->documentElement : $oDomNode;
        if (!$oDomNode->hasChildNodes()) {
            $mResult = $oDomNode->nodeValue;
        } else {
            $mResult = array();
            foreach ($oDomNode->childNodes as $oChildNode) {
                // how many of these child nodes do we have?
                // this will give us a clue as to what the result structure should be
                $oChildNodeList = $oDomNode->getElementsByTagName($oChildNode->nodeName);
                $iChildCount = 0;
                // there are x number of childs in this node that have the same tag name
                // however, we are only interested in the # of siblings with the same tag name
                foreach ($oChildNodeList as $oNode) {
                    if ($oNode->parentNode->isSameNode($oChildNode->parentNode)) {
                        $iChildCount++;
                    }
                }
                $mValue = $this->toArray($oChildNode);
                $sKey = ($oChildNode->nodeName {
                    0}
                == '#') ? 0 : $oChildNode->nodeName;
                $mValue = is_array($mValue) ? $mValue[$oChildNode->nodeName] : $mValue;
                // how many of thse child nodes do we have?
                if ($iChildCount > 1) { // more than 1 child - make numeric array
                    $mResult[$sKey][] = $mValue;
                } else {
                    $mResult[$sKey] = $mValue;
                }
            }
            // if the child is bar, the result will be array(bar)
            // make the result just 'bar'
            if (count($mResult) == 1 && isset($mResult[0]) && !is_array($mResult[0])) {
                $mResult = $mResult[0];
            }
        }
        // get our attributes if we have any
        $arAttributes = array();
        if ($oDomNode->hasAttributes()) {
            foreach ($oDomNode->attributes as $sAttrName => $oAttrNode) {
                // retain namespace prefixes
                $arAttributes["@{$oAttrNode->nodeName}"] = $oAttrNode->nodeValue;
            }
        }
        // check for namespace attribute - Namespaces will not show up in the attributes list
        if ($oDomNode instanceof DOMElement && $oDomNode->getAttribute('xmlns')) {
            $arAttributes["@xmlns"] = $oDomNode->getAttribute('xmlns');
        }
        if (count($arAttributes)) {
            if (!is_array($mResult)) {
                $mResult = (trim($mResult)) ? array($mResult) : array();
            }
            $mResult = array_merge($mResult, $arAttributes);
        }
        $arResult = array($oDomNode->nodeName => $mResult);
        return $arResult;
    }
}


?>


 Bu sınıfın test / örnek kodu da aşağıdaki gibi:


/**
 * The tester of the SWFMillCreator class.
 *
 
* @author Behçet MUTLU
 
* @email behcetmutlu@b-prodesign.com
 
* @copyright 2009 AdresGezgini.Com
 */
 

 require_once("SWFMillXMLCreator.class.php");

$xml = new SWFMillXMLCreator("1.0", "utf-8");

$movie = $xml->createMovie("320", "240", "12", "7");

$xml->addClip("upState",         "up.png");
$xml->addClip("downState",         "down.png");
$xml->addClip("overState",         "over.png");
$xml->addClip("disabledState",     "disabled.png");

$frame = $xml->addFrame();

$library = $xml->addLibrary($frame);

$clip = $xml->addClip("testButton","","",$library);

$xml->placeElement("upState", "", "1", $up = $xml->addFrame("Up", $clip));
$xml->placeElement("downState", "", "2", $down = $xml->addFrame("Down", $clip));
$xml->placeElement("overState", "", "3", $over = $xml->addFrame("Over", $clip));
$xml->placeElement("disabledState", "", "4", $disabled = $xml->addFrame("Disabled", $clip));
$xml->stop($up);
$xml->stop($down);
$xml->stop($over);
$xml->stop($disabled);


$xml->appendChild($movie);

header( "content-type: application/xml; charset=utf-8" );

$xml->preserveWhiteSpace = false;
$xml->formatOutput   = true;

print($xml->saveXML());

?>