Skip to content

Commit

Permalink
Retrieve documents by folder, folder-tree, content keywords or name. …
Browse files Browse the repository at this point in the history
…Render table of results. Link to download documents.
  • Loading branch information
ansonhoyt committed Apr 27, 2012
1 parent abd33af commit 6ac8fe9
Show file tree
Hide file tree
Showing 25 changed files with 2,297 additions and 17 deletions.
3 changes: 2 additions & 1 deletion admin.php
Expand Up @@ -25,6 +25,7 @@ function basic_cmis_admin() {
</th>
<td>
<input type="text" class="regular-text" name="cmis_repository_url" id="cmis_repository_url" value="<?php echo get_option('cmis_repository_url') ?>">
<span class="description">e.g. http://www.example.com/alfresco/service/api/cmis</span>
</td>
</tr>
<tr valign="top">
Expand All @@ -40,7 +41,7 @@ function basic_cmis_admin() {
<label for="cmis_password">Password</label>
</th>
<td>
<input type="text" name="cmis_password" id="cmis_password" value="<?php echo get_option('cmis_password') ?>">
<input type="password" name="cmis_password" id="cmis_password" value="<?php echo get_option('cmis_password') ?>">
</td>
</tr>
</table>
Expand Down
184 changes: 168 additions & 16 deletions basic-cmis.php
Expand Up @@ -2,51 +2,203 @@
/*
Plugin Name: Basic CMIS for Wordpress
Plugin URI: https://github.com/ansonhoyt/Basic-CMIS
Description: Wordpress Plugin for basic CMIS integration. Does nothing yet, but will read from Alfresco Enterprise's CMIS interface and render a list of documents.
Description: Wordpress Plugin for basic CMIS integration. Searches a CMIS compliant system and renders the matching documents. Tested with Alfresco Enterprise's CMIS service.
Version: 0.0.1 (pre-alpha)
Author: Anson Hoyt
Author URI: https://github.com/ansonhoyt
*/

// Required PHP files
$PLUGIN_PATH = dirname(__FILE__).'/';
require_once($PLUGIN_PATH . './admin.php');
require_once($PLUGIN_PATH . '/admin.php');
require_once ($PLUGIN_PATH . '/lib/cmis_repository_wrapper.php');
require_once ($PLUGIN_PATH . '/stream.php');

/*
Define CMIS shortcode
Usage: [cmis folder="my particular/folder name/" keywords="coffee tea"]
Usage:
[cmis folder="/my particular/folder name/"] # Docs in the folder
[cmis tree="/my particular/folder name/"] # Docs in the folder, including subfolders
[cmis keywords="coffee tea"] # Docs containing the keywords
[cmis name="Agenda%.doc"] # Docs whose name matches. May include wildcard character '%'.
*/
function cmis_shortcode( $attr, $content = null ) {
extract( shortcode_atts( array(
'folder' => '',
'tree' => '',
'keywords' => '',
'name' => '',
), $attr ) );


return do_cmis($folder, $tree, $keywords, $name);
}
add_shortcode('cmis', 'cmis_shortcode');

/*
Perform specified retrieve and return rendered table of documents.
Usage:
*/
function do_cmis($folder, $tree, $keywords, $name) {
// Initialize CMIS Client
$repo_url = get_option('cmis_repository_url');
$repo_username = get_option('cmis_username');
$repo_password = get_option('cmis_password');
$client = new CMISService($repo_url, $repo_username, $repo_password);

try {
if ($folder) {
$f = $client->getObjectByPath($folder);
$objs = $client->getChildren($f->id);
return display_cmis_objects($objs);
}
elseif ($tree) {
$f = $client->getObjectByPath($tree);
$query = "SELECT * FROM cmis:document WHERE IN_TREE('$f->id')";
$objs = $client->query($query);
return display_cmis_objects($objs);
}
elseif ($keywords) {
$query = "SELECT * FROM cmis:document WHERE CONTAINS('$keywords')";
$objs = $client->query($query);
return display_cmis_objects($objs);
}
elseif ($name) {
$query = "SELECT * FROM cmis:document WHERE cmis:name LIKE '$name'";
$objs = $client->query($query);
return display_cmis_objects($objs);
}
}
catch (CmisRuntimeException $e) {
echo '<div class="alert">', 'Caught exception: ', $e, '</div>';
}
return '<div class="alert">Unable to show documents.</div>';
}

function display_cmis_objects($objs) {
ob_start();
?>
<h3>Folder: <?php echo esc_attr($folder) ?></h3>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Updated</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#">Some document name</a></td>
</tr>
<tr>
<td><a href="#">Some document name</a></td>
</tr>
<tr>
<td><a href="#">Some document name</a></td>
</tr>
<?php
foreach ($objs->objectList as $obj) {
display_cmis_object($obj);
}
?>
</tbody>
</table>
<?php

return ob_get_clean();
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
add_shortcode('cmis', 'cmis_shortcode');

function display_cmis_object($obj) {
$name = $obj->properties['cmis:name'];
?>
<tr>
<td>
<a href="<?php echo get_object_url($obj) ?>">
<?php echo get_object_icon($obj); ?>
<?php echo $name ?>
</a>
</td>
<td>
<?php
$date_string = $obj->properties['cmis:lastModificationDate'];
$timestamp = strtotime($date_string);
#$timestamp = DateTime::createFromFormat('Y-m-dThh:mm:ss:mmmT', $date_string);
echo date( "M d Y h:i a", $timestamp);
?>
</td>
</tr>
<?php
}

function get_object_icon($obj) {
$name = $obj->properties['cmis:name'];
$mimeType = $obj->properties['cmis:contentStreamMimeType'];
$docType = $obj->properties['cmis:baseTypeId'];
$icon = '_default.gif';

if($docType == 'cmis:folder') {
$icon = 'folder.gif';
} else {
// Determine icon image based on Mime Type
switch($mimeType) {
case 'image/bmp':
$icon = 'bmp.gif';
break;
case 'image/jpeg':
$icon = 'jpg.gif';
break;
case 'application/x-shockwave-flash':
$icon = 'swf.gif';
break;
case 'text/html':
$icon = 'htm.gif';
break;
case 'application/zip':
$icon = 'zip.gif';
break;
case 'video/x-ms-wmv':
case 'video/x-msvideo':
$icon = 'wmv.gif';
break;
case 'application/msword':
$icon = 'doc.gif';
break;
case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
$icon = 'pptx.gif';
break;
case 'application/vnd.powerpoint':
case 'application/vnd.ms-powerpoint':
$icon = 'ppt.gif';
break;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
$icon = 'docx.gif';
break;
case 'audio/x-mpeg':
$icon = 'mp3.gif';
break;
case 'application/vnd.ms-excel':
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
$icon = 'xls.gif';
break;
case 'application/x-javascript':
$icon = 'js.gif';
break;
case 'application/pdf':
$icon = 'pdf.gif';
break;
case 'application/acp':
$icon = 'acp.gif';
break;
case 'text/plain':
$icon = 'txt.gif';
break;
default:
$icon = '_default.gif';
}
}

return <<<EOD
<img src="/wp-content/plugins/basic-cmis/img/$icon" alt="$name" title="$name">
EOD;
}

function get_object_url($obj) {
$siteurl = get_option('siteurl');
$id = $obj->properties['cmis:objectId'];
return $siteurl . '?cmis_obj_id=' . urlencode($id);
}

?>
Binary file added img/_default.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/acp.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/avi.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/bmp.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/doc.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/docx.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/folder.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/htm.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/jpg.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/js.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mp3.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/pdf.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/ppt.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/pptx.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/swf.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/txt.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/wmv.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/xls.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/zip.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6ac8fe9

Please sign in to comment.