[ class tree: Gliffy ] [ index: Gliffy ] [ all elements ]

example

  1. <?php 
  2.  
  3.  
  4.  
  5.  
  6.  
  7. # The username of the user that is adding diagrams
  8. # We hard code this name here, but typically you'd want to use whatever unique user
  9. # identifier you use in your system for the current user, such as an id, email, or username 
  10. # Note that this detemines who owns newly created diagrams in the context
  11. $testUsername "testuser@gliffy.com"
  12.  
  13.  
  14. # Include the Gliffy Client Library code.  Assumes we have a config.php object in place
  15. $gliffyPath '../../src'
  16. set_include_pathget_include_path(PATH_SEPARATOR $gliffyPath)
  17. require_once("Gliffy.php")
  18.  
  19.  
  20. # Create the gliffy context if it doesn't exists for this session
  21. # Normall, you'll want to cache the Gliffy context for each user for performance,
  22. # and to reduce the number of API calls
  23. $gliffy new Gliffy($testUsername)
  24.  
  25. # Check to see if the 'addDiagram' button was pressed.  If it was, create a new diagram
  26. ifisset$_REQUEST['addDiagram'&&  isset$_REQUEST['diagramName')) {
  27.     // Add diagram clicked
  28.     $newDiagramName $_REQUEST['diagramName']
  29.     $newDiagramId $gliffy->createDiagram($newDiagramName)
  30.     addDiagramToList$newDiagramId )
  31.  
  32. # Adds a new diagramId to the list, and store it in session
  33. # Typically, you'll want to keep the diagram id's in your home 
  34. # application database, since session doesn't last very long!
  35. function addDiagramToList$newDiagramId {
  36.     if!isset$_SESSION['diagramArray') ) {
  37.         $_SESSION['diagramArray'array();
  38.     }
  39.  
  40.     $_SESSION['diagramArray'][$newDiagramId
  41. }
  42.  
  43. # Print out the HTML to render a diagram image, name, and edit link
  44. function echoDiagram$diagramId {
  45.     global $gliffy;
  46.     $diagramMetaData $gliffy->getDiagramMetaData($diagramId);  
  47.     $diagramImageURL $gliffy->getDiagramAsURL($diagramId,Gliffy::MIME_TYPE_PNG)
  48.    
  49.    
  50.     echo "Diagram name: $diagramMetaData->name <br />";  
  51.     echo "<img src=\"$diagramImageURL\" /> <br />"
  52.  
  53.     # It's a best priactice to wrap the editor in your own page for two reasons:
  54.     # 1 - The OAuth security policy ensures that a given URL can never be requested more than once.  Wrapping the editor 
  55.     #     will enable you to ensure that your users always get a valid and fresh URL
  56.     # 2 - By wrapping the editor, your users will not be confused and think that they are leaving your site.  
  57.     echo "<a href=\"gliffyWrapper.php?did=" .  $diagramId "\" target=\"gliffy_" $diagramId "\">Edit Diagram</a>"
  58.     echo "<hr />";
  59. }
  60.  
  61.  
  62. ?>
  63.  
  64. <html>
  65. <p>This is a very simple example of the Gliffy PHP Client Library.  Click 'Add diagram' to try it out.   
  66.  
  67. <br />
  68. <br />
  69.  
  70.  
  71. <form action="index.php" method="POST"> 
  72.     Diagram Name: <input type="text" name="diagramName"/>
  73.     <input type="submit" name="addDiagram" value="Add diagram"/>
  74. </form> 
  75.  
  76. <hr /> 
  77.  
  78. <?php
  79.  
  80.     # Render all the diagrams we have
  81.     ifisset$_SESSION['diagramArray') ) 
  82.         foreach$_SESSION['diagramArray'as $currentId 
  83.             echoDiagram$currentId );
  84.         }
  85.     }
  86.  
  87. ?>
  88. </html>

Documentation generated on Mon, 13 Jul 2009 19:54:33 -0500 by phpDocumentor 1.4.1