Serge's Technology View

Talk about Technologies, Software Architecture and Management

Posts Tagged ‘php’

How to embed Google Docs document into your page

There are plenty of presentations, documents, and spreadsheets we may want to share with the world.

We can use homegrown document handling solutions, use commercial 3rd party solutions or… utilize power provided by Google Docs.

When storing articles on Google Docs you are provided with the option to share them with some people only or with everyone. I like to have option to link my articles from anywhere but I also like to have not just plain page, but a page embedded into my web-site pages.

What it means is that instead of external page, I want to put it in my own box.

There was time when it wasn’t as easy because of the additional code Google was injecting into articles, but time changed and now it is fairly easy and strait forward.

Goals

  • Embed Google Docs document into existing page
  • PHP. This is not really a requirement per se, it is just code below is PHP.
  • Retain copyright information

Solution

The following code snippet allows to get a desired result

// id parameter is used to pass Google Docs arcticle id
// Example: mydocview.php?id=nnnnnnnnnnnnnnnn

$id    = $_REQUEST['id'];
if ($id) {
  $started = "0";
  echo('<div class="googledocs" >Stored and managed via <a title="Learn more about Google Docs" href="http://docs.google.com" target="_blank">Google Docs &copy; -- Web word processing, presentations and spreadsheets.</a></div>');

  // Read document content, parse to normalize and output
  $file = fopen ("http://docs.google.com/View?id=" . $id, "r");
  while (!feof ($file)) {
    $line = fgets ($file, 4096);

    // Parse header info out
    if ($started == "0") {
      if (substr($line, 0, 5) == '<body') { $started = "1"; }
      else { continue; }
    }

    // Parse body content until document content block is detected
    if ($started == "1") {
      if (strstr($line, '<div id="doc-contents">')) { $started = "2"; }
      else { continue; }
    }

    // Output document content
    if ($started == "2") {
      // Stop processing, end of content reached
      if (strstr($line, '<div id="google-view-footer">')) { break; }

      // Normalize image links to keep link back to google docs
      $line = str_replace('src="File?id', 'src="http://docs.google.com/File?id', $line);

      // Normalize links to other articles
      $line = str_replace('href="View?docid=', 'href="/mydocview.php?id=', $line);
      $line = str_replace('href="View?id=', 'href="/mydocview.php?id=', $line);
      $line = str_replace('href="View?docID=', 'href="/mydocview.php?id=', $line);
      $line = str_replace('href="View?', 'href="/mydocview.php?', $line);

      // Output result
      echo($line);
    }
  }
  fclose($file);
}

Sample page:

<html>
<head></head>
<body>
<? // Include code above here
?>
</body>
</html>

Delphi for AS/400 is comming back home

Delphi for AS/400 is coming back. Some of you might remember this product from long time ago. Well… it is back. Let put onto our history book.

CodeGear just announced a return of long missing child and it is available to try and to purchase. And it is not just Delphi but Delphi for PHP version.

As it appears Delphi/400 was “out of the house” for quite some time where it was still undergoing development.

In 1997, we signed an agreement with Borland, licensing our AS/400 middleware technology, ClientObjects/400 to create a world-class suite of Object-Oriented Development tools. These innovative development applications, Delphi/400, JBuilder for iSeries and C++Builder/400, were designed specifically for the AS/400 developer community.

Since the introduction of Delphi/400 and C++Builder/400, developers and corporations worldwide have been using SystemObjects solutions for application development and deployment.

Our Partner Network provides education, consulting, training and support to thousands of developers and users in all countries.

In February 1999, SystemObjects and Borland entered into a global agreement which:

Consolidates the commitment of both Borland and SystemObjects to providing the highest quality development products for the IBM AS/400 community,
Recognizes the importance of the IBM AS/400 market by focusing future development, distribution and support of its products dedicated to the IBM AS/400,
Entrusts AS/400 experts, such as SystemObjects, with maintaining Borland’s high quality standards,
Increases Borland’s investment in the AS/400 market.

Full history note is available here.

What it is exactly then? As it is stated on the web-site and in other places – it is Delphi 2006 which has connectivity to AS/400 back-end - see screenshot here. Also it has ability for easy deployment to iSystem.
I think there was some mentioning of Linux port, but I think it has “died” along with Delphi 7/Kylix.

Same applies to Delphi/400 for PHP. It is regular DfPHP with connectivity to back-end.

Create your first Widget for WordPress – PHPText

There is my first WordPress Widget – PHP Text – Text Box which accepts arbitrary PHP code and can execute it inside sidebar block.
Another requirement is that it is only be allowed to be entered by Admin User.

I have started with the original code for Text Widget and adjusted it to include such restriction.

It has superseded my IFrame solution discussed in prior post and works well except that CSS is not yet applied.

What has been demonstrated by this little project:

  • how to register your own sidebar widget
  • how to support multiple instances of the same widget in the sidebar
  • how to manage widget options from popup options window in Widget  Manager section of your Blog Admin Panel
  • how to store/read widget options
  • how to make your widget properly appear at the sidebar
  • implement some basic user rights manager

If you’d like to use it in your blog, source code is available here – WordPress PHP Text Widget.

I hope this little example would help you started with Plug-in development for your WordPress Blog.

WARNING: Any code injections allowed by dynamic content comes with possible security risk. Please be cautious about what you allow to be executed by the PHP code specified in the widget. I would strongly suggest avoiding use of external sources you have no control over.

Valid XHTML 1.0 Transitional  Valid CSS!