dmBridge PHP API
DMControlPanelTemplateHelper.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00013 class DMControlPanelTemplateHelper extends DMGenericTemplateHelper
00014 implements DMTemplateHelper {
00015 
00016    const NUM_NEWS_ITEMS = 3;
00017 
00022    public function getHtmlEditableCommentsAsTable(array $comments) {
00023       $tables = "";
00024       foreach ($comments as $c) {
00025          $skip = false;
00026          try {
00027             $c->getObject();
00028          } catch (DMUnavailableModelException $e) {
00029             $skip = true;
00030          }
00031 
00032          $tables .= '<table class="comments" cellpadding="0" cellspacing="2" border="0">';
00033          if ($skip) {
00034             $tables .= '<caption>Comment ID ' . $c->getID()
00035                   . ' associated with nonexistent object.</caption>
00036                </table>';
00037          } else {
00038             $tables .= '<caption>
00039                   <label>
00040                      <input type="checkbox" name="id[]"
00041                         value="' . DMString::websafe($c->getID()) .'">
00042                      ' . DMString::websafe($c->getTimestamp()->format('M d, Y @ g:i A')) .'
00043                   </label>
00044                </caption>
00045                <tr>
00046                <th>Object:</th>
00047                   <td><a href="' . DMString::websafe($c->getObject()->getURI(DMBridgeComponent::TemplateEngine)) . '">
00048                      ' . DMString::websafe($c->getObject()->getMetadata('title')) . '</a>
00049                   </td>
00050                   <td rowspan="4" style="text-align:right">
00051                      <img src="' . DMString::websafe($c->getObject()->getThumbnailURL()) . '"
00052                          style="width:80px">
00053                   </td>
00054                </tr>
00055                <tr>
00056                   <th>Collection:</th>
00057                   <td>' . DMString::websafe($c->getObject()->getCollection()->getName()) . '</td>
00058                </tr>
00059                <tr>
00060                   <th>Author:</th>
00061                   <td><input type="text" name="author[' . $c->getID() . ']"
00062                            style="width:60%"
00063                            value="' . DMString::websafe($c->getName()) . '"></td>
00064                </tr>
00065                <tr>
00066                   <th>Email:</th>
00067                   <td><input type="text" name="email[' . $c->getID() .']"
00068                            style="width:60%"
00069                            value="' . DMString::websafe($c->getEmail()) . '"></td>
00070                </tr>
00071                <tr>
00072                   <th>Comment:</th>
00073                   <td colspan="2">
00074                      <textarea name="body[' . $c->getID() . ']"
00075                              style="height:120px;width:100%">'. DMString::websafe($c->getValue()) . '</textarea>
00076                   </td>
00077                </tr>
00078             </table>';
00079          }
00080       }
00081       return $tables;
00082    }
00083 
00087    public function getHtmlMainMenu() {
00088       $ds = DMDataStoreFactory::getDataStore();
00089 
00090       // build default menu
00091       $sections = array();
00092 
00093       // basic setup
00094       $section = new DMCPMenuSection("Basic Setup");
00095       $item = new DMCPMenuItem(
00096             "Basic Setup",
00097             DMInternalURI::getURIWithParams("admin/basic"));
00098       $section->addMenuItem($item);
00099       $sections[] = $section;
00100 
00101       // modules
00102       $section = new DMCPMenuSection("Modules");
00103       $item = new DMCPMenuItem(
00104             "View All",
00105             DMInternalURI::getURIWithParams("admin/modules"));
00106       $section->addMenuItem($item);
00107       $sections[] = $section;
00108 
00109       // comments
00110       $section = new DMCPMenuSection("Comments");
00111       $item = new DMCPMenuItem(
00112             "Configure",
00113             DMInternalURI::getURIWithParams("admin/comments/edit"));
00114       $section->addMenuItem($item);
00115       $num = "";
00116       try {
00117          $cq = new DMCommentQuery($ds);
00118          $cq->setApproved(-1);
00119          $cq->getSearchResults();
00120          $num = sprintf(" (%d)", $cq->getNumResults());
00121       } catch (DMException $e) {
00122          // do nothing
00123       }
00124       $item = new DMCPMenuItem(
00125             "Moderate" . $num,
00126             DMInternalURI::getURIWithParams("admin/comments/moderate"));
00127       $section->addMenuItem($item);
00128       $item = new DMCPMenuItem(
00129             "Search",
00130             DMInternalURI::getURIWithParams("admin/comments/search"));
00131       $section->addMenuItem($item);
00132       $item = new DMCPMenuItem(
00133             "Statistics",
00134             DMInternalURI::getURIWithParams("admin/comments/statistics"));
00135       $section->addMenuItem($item);
00136       $sections[] = $section;
00137 
00138       // ratings
00139       $section = new DMCPMenuSection("Ratings");
00140       $item = new DMCPMenuItem(
00141             "Configure",
00142             DMInternalURI::getURIWithParams("admin/ratings/edit"));
00143       $section->addMenuItem($item);
00144       $item = new DMCPMenuItem(
00145             "Statistics",
00146             DMInternalURI::getURIWithParams("admin/ratings/statistics"));
00147       $section->addMenuItem($item);
00148       $sections[] = $section;
00149       
00150       // tags
00151       $section = new DMCPMenuSection("Tags");
00152       $item = new DMCPMenuItem(
00153             "Configure",
00154             DMInternalURI::getURIWithParams("admin/tags/edit"));
00155       $section->addMenuItem($item);
00156       $num = "";
00157       try {
00158          $tq = new DMTagQuery($ds);
00159          $tq->setApproved(-1);
00160          $tq->getSearchResults();
00161          $num = sprintf(" (%d)", $tq->getNumResults());
00162       } catch (DMException $e) {
00163          // do nothing
00164       }
00165       $item = new DMCPMenuItem(
00166             "Moderate" . $num,
00167             DMInternalURI::getURIWithParams("admin/tags/moderate"));
00168       $section->addMenuItem($item);
00169       $item = new DMCPMenuItem(
00170             "View All",
00171             DMInternalURI::getURIWithParams("admin/tags"));
00172       $section->addMenuItem($item);
00173       $item = new DMCPMenuItem(
00174             "Statistics",
00175             DMInternalURI::getURIWithParams("admin/tags/statistics"));
00176       $section->addMenuItem($item);
00177       $sections[] = $section;
00178 
00179       // collections
00180       $section = new DMCPMenuSection("Collections");
00181       $item = new DMCPMenuItem(
00182             "View All",
00183             DMInternalURI::getURIWithParams("admin/collections"));
00184       $section->addMenuItem($item);
00185       $item = new DMCPMenuItem(
00186             "URL Redirection",
00187             DMInternalURI::getURIWithParams("admin/reference_urls"));
00188       $section->addMenuItem($item);
00189       $sections[] = $section;
00190 
00191       // template sets
00192       $section = new DMCPMenuSection("Template Sets");
00193       $item = new DMCPMenuItem(
00194             "Add",
00195             DMInternalURI::getURIWithParams("admin/templates/add"));
00196       $section->addMenuItem($item);
00197       $item = new DMCPMenuItem(
00198             "View All",
00199             DMInternalURI::getURIWithParams("admin/templates"));
00200       $section->addMenuItem($item);
00201       $sections[] = $section;
00202             
00203       // feeds
00204       $section = new DMCPMenuSection("Feeds");
00205       $item = new DMCPMenuItem(
00206             "Configure",
00207             DMInternalURI::getURIWithParams("admin/feeds"));
00208       $section->addMenuItem($item);
00209       $sections[] = $section;
00210 
00211       // CQR
00212       $section = new DMCPMenuSection("CQR");
00213       $item = new DMCPMenuItem(
00214             "Convert",
00215             DMInternalURI::getURIWithParams("admin/cqr/convert"));
00216       $section->addMenuItem($item);
00217       $sections[] = $section;
00218 
00219       // custom module sections
00220       $mm = DMModuleManager::getInstance();
00221       foreach ($mm->getEnabledModules() as $module) {
00222          if ($module instanceof DMBridgeControlPanelModule) {
00223             foreach ($module->getControlPanelMenuSections() as $section) {
00224                $section->setFromModule(true);
00225                $sections[] = $section;
00226             }
00227          }
00228       }
00229 
00230       // documentation
00231       $section = new DMCPMenuSection("Documentation");
00232       $item = new DMCPMenuItem(
00233             "User's Manual",
00234             DMURI::getLocalURIWithPath(
00235                   dirname($_SERVER['PHP_SELF']) . "/doc/manual/html-chunked/index.html"));
00236       $section->addMenuItem($item);
00237       $item = new DMCPMenuItem(
00238             "PHP API",
00239             DMURI::getLocalURIWithPath(
00240                   dirname($_SERVER['PHP_SELF']) . "/doc/php_api/html/index.html"));
00241       $section->addMenuItem($item);
00242       $item = new DMCPMenuItem(
00243             "HTTP API",
00244             DMInternalURI::getURIWithParams("api/1/doc"));
00245       $section->addMenuItem($item);
00246       $sections[] = $section;
00247 
00248       // done building menu data; now transform it to HTML
00249       $dxml = new DMDOMDocument("1.0", "utf-8");
00250       $dxml->loadXML("<ul/>");
00251 
00252       $current_route = DMHTTPRequest::getCurrent()->getURI()->getRoute();
00253       foreach ($sections as $section) {
00254          $sec_li = $dxml->createElement("li");
00255          $title = $dxml->createElement("span", $section->getTitle());
00256          $title->setAttribute("class", "accordionButton");
00257          $title->setAttribute("id",
00258                str_replace(" ", "", $section->getTitle()));
00259          $sec_li->appendChild($title);
00260 
00261          if ($section->isFromModule()) {
00262             $title->setAttribute("class",
00263                   $title->getAttribute("class") . " ModuleSection");
00264          }
00265          $ul = $dxml->createElement("ul");
00266 
00267          $div = $dxml->createElement("div");
00268          $div->appendChild($ul);
00269          $div->setAttribute("class", "accordionPanel");
00270 
00271          foreach ($section->getMenuItems() as $item) {
00272             $item_li = $dxml->createElement("li");
00273             $ul->appendChild($item_li);
00274             $item_a = $dxml->createElement("a", $item->getTitle());
00275             $item_a->setAttribute("href", $item->getURI());
00276             // highlight the currently selected item
00277             if ($item->getURI() instanceof DMInternalURI) {
00278                $item_uri = new DMInternalURI();
00279                $item_uri->setParams($item->getURI()->getParams());
00280                if ($current_route->equals($item_uri->getRoute())) {
00281                   $item_li->setAttribute("class", "active");
00282                   $item_li->parentNode->parentNode->setAttribute("style",
00283                         "display:block");
00284                }
00285             }
00286             $item_li->appendChild($item_a);
00287          }
00288          $sec_li->appendChild($div);
00289          $dxml->documentElement->appendChild($sec_li);
00290       }
00291       
00292       return $dxml->saveHTML($dxml->documentElement);
00293    }
00294 
00298    public function getHtmlNews() {
00299       $um = new DMUpdateManager(new DMHTTPRequest());
00300       $news = $um->getNewsItems(self::NUM_NEWS_ITEMS);
00301       if (!count($news)) {
00302          return DMLocalizedString::getString("NO_NEWS");
00303       }
00304 
00305       $dxml = new DMDOMDocument("1.0", "utf-8");
00306       $dxml->loadXML("<dl/>");
00307       $doc = $dxml->documentElement;
00308 
00309       foreach ($news as $ni) {
00310          $doc->appendChild($dt = $dxml->createElement("dt"));
00311          $a = $dxml->createElement("a",
00312             $ni->getDate()->format("Y-m-d") . ": " . $ni->getTitle());
00313          $a->setAttribute("href", $ni->getURL());
00314          $dt->appendChild($a);
00315 
00316          $dd = $dxml->createElement("dd",
00317             DMString::truncate(strip_tags($ni->getBody()), 40));
00318          $doc->appendChild($dd);
00319       }
00320 
00321       return $dxml->saveHTML($dxml->documentElement);
00322    }
00323 
00327    public function getHtmlVersionDetail() {
00328       $dxml = new DMDOMDocument('1.0', 'utf-8');
00329       $dxml->loadXML('<dl/>');
00330       $doc = $dxml->documentElement;
00331 
00332       // control panel version
00333       $doc->appendChild($dxml->createElement('dt', 'dmBridge version:'));
00334       $doc->appendChild($dd = $dxml->createElement('dd'));
00335       if (DMBridgeVersion::getDmBridgeVersion()) {
00336          $text = DMBridgeVersion::getDmBridgeVersion();
00337          if (DMBridgeVersion::isNewerDmBridgeVersionAvailable(new DMHTTPRequest())) {
00338             $text .= ' <a href="http://digital.library.unlv.edu/software/dmbridge">(newer
00339                version available)</a>';
00340          }
00341          $frag = $dxml->createDocumentFragment();
00342          $frag->appendXML($text);
00343          $doc->appendChild($frag);
00344       } else {
00345          $dd->nodeValue = 'Invalid or missing VERSION.txt file.';
00346       }
00347 
00348       // config file location
00349       $doc->appendChild($dxml->createElement('dt', 'Config file location:'));
00350       $doc->appendChild($dd = $dxml->createElement('dd'));
00351       $dd->appendChild(
00352          $dxml->createElement('code', DMConfigXML::getInstance()->getFullPath()));
00353 
00354       // config file validity
00355       if (!DMConfigXML::getInstance()->isValid()) {
00356          $err = libxml_get_last_error();
00357          if ($err instanceof LibXMLError) {
00358             $message = sprintf('Line %d: %s', $err->line, $err->message);
00359             $doc->appendChild($dxml->createElement('dt', 'Config file errors:'));
00360             $doc->appendChild($dd = $dxml->createElement('dd', $message));
00361          }
00362       }
00363 
00364       return $dxml->saveHTML($dxml->documentElement);
00365    }
00366 
00367 }
 All Data Structures Functions Variables