Menu

How do I create my own widget?

Help
2001-03-28
2001-04-01
  • alex obradovic

    alex obradovic - 2001-03-28

    Is there a guideline on how to create a new widget? What files do I need/ what do I need to change?

    Alex

     
    • Garth Dahlstrom

      Garth Dahlstrom - 2001-03-28

      Alex,

      The easiest way to create a new widget is to copy
      the morpher.w.php3 file to yourwidget.w.php3

      The file name before the .w.php3 will be what
      the widget is called.

      Once you've done that open it up and edit:
      - $widget_title to what you want in the title bar
      - $widget_canMove and $widget_canClose, set
      them true if you want a the buttons for Move
      and Close or false for no buttons.
      - Then do your code that produces some text or
      HTML and store it into the variable $output.

      Then close the file, that's it for making it...
      the rest is just making sure it gets loaded.

      To make your widget selectable from the add widgets dialog, make a copy of you widget into
      the user_widgets directory (the file can be
      empty, only that there is a file by that name
      is what matters).

      Finally, if you want your widget to appear
      on the demo page by default when a person goes
      to your page you need to alter index.php3

      where it goes as follows

        $MyWidgets =
          array(
          // c1
          array(
                      "yourwidget", /* inserts your widget at the top of c1 or column 1 */
                "browser",

      add the "yourwidget" line shown to $MyWidgets

      Logout of the page (so your session is deleted
      and reloaded) to test if it works.

      Here's a hack I did on the morpher widget as
      an example...

      <?PHP
      // -- Frame setup stuff
      $widget_title = "This is my widget and $widget is it's name";
      $widget_canMove=true;
      $widget_canClose=true;

      // -- Widget frame content
      $output = "hello world";
      $output.= "<br>here is a second line.";

      // *** Do not alter anything below this point. ***
      // ***********************************************

      if (!isset($oldfilestatus))
      {
        $oldfilestatus = "oldfilestatus was not set";
      }

      $widget_info = "This cache was created at: ".date("l F dS Y h:i:s A")."\\nUpdated for IP: $REMOTE_ADDR\\nPrevious cache was created: ".$oldfilestatus;

      // -- return output to caller in the form a variable named after the widget called
      //    i.e. calling the widget nasdaq returns widget output in $nasdaq 
      $$widget = $this->frame_widget($output, $widget_title,$widget_info,$widget_canMove,$widget_canClose);

      // -- Clean Up Vars
      unset($output); unset($widget_title); unset($widget_info);
      unset($widget_canMove); unset($widget_canClose);
      // We leave $oldfilestatus for other widgets that may wish to display caching info
      ?>

       
      • alex obradovic

        alex obradovic - 2001-03-28

        This is really cool. Thanks a lot. It worked!!!

         
        • Garth Dahlstrom

          Garth Dahlstrom - 2001-03-28

          If you make anything cool be sure to let me know.
          I'd love to see what other people are doing with
          it.

          -Ironstorm

           
          • alex obradovic

            alex obradovic - 2001-03-29

            Yes, I needed to add large amounts of static files to the Widget list, so I added a hack to read the .txt files from specified directory, and it appends that list to the WidgetArray. Then they behave as xxxxx.list files. I can send you the update if you wish....

            Alex

             
            • Garth Dahlstrom

              Garth Dahlstrom - 2001-04-01

              Cool send me the hack, I'll prolly put it in
              if it makes it easier to update that list.

               

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.