Esempio n. 1
0
 public static function buildFilesPreview($objectID, $fieldName = NULL)
 {
     if (objects::validID(TRUE, $objectID) === FALSE) {
         return FALSE;
     }
     if (($object = objects::get($objectID, TRUE)) === FALSE) {
         return FALSE;
     }
     $output = '';
     if (isset($fieldName)) {
         $field = forms::getField($object['formID'], $fieldName);
         $fields = array($field);
     } else {
         $fields = forms::getFields($object['formID']);
     }
     $fileLIs = array();
     foreach ($fields as $field) {
         if ($field['type'] != 'file') {
             continue;
         }
         // If there's nothing uploaded for the field, no need to continue
         if (empty($object['data'][$field['name']])) {
             continue;
         }
         // Figure out some needed vars for later
         $fileDataArray = $object['data'][$field['name']];
         $assetsID = $fileDataArray['uuid'];
         $fileLIs = array();
         uasort($fileDataArray['files']['archive'], function ($a, $b) {
             return strnatcasecmp($a['name'], $b['name']);
         });
         foreach ($fileDataArray['files']['archive'] as $fileID => $file) {
             $_filename = pathinfo($file['name']);
             $filename = $_filename['filename'];
             $links = array();
             $links['Original'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'archive');
             if (str2bool($field['convert'])) {
                 $links['Converted'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'processed');
             }
             if (str2bool($field['thumbnail'])) {
                 $links['Thumbnail'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'thumbs');
             }
             if (str2bool($field['ocr'])) {
                 $links['OCR'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'ocr');
             }
             if (str2bool($field['combine'])) {
                 $links['Combined PDF'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], 'combinedPDF');
                 $links['Combined Thumbnail'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], 'combinedThumb');
             }
             $previewLinks = array();
             $downloadLinks = array();
             foreach ($links as $linkLabel => $linkURL) {
                 $previewLinks[] = sprintf('<li><a tabindex="-1" href="javascript:;" onclick="previewFile(this,\'%s\')">%s</a></li>', $linkURL, $linkLabel);
                 $downloadLinks[] = sprintf('<li><a tabindex="-1" href="%s&download=1">%s</a></li>', $linkURL, $linkLabel);
             }
             // Build the preview dropdown HTML
             $previewDropdown = '<div class="btn-group">';
             $previewDropdown .= '	<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">';
             $previewDropdown .= '		Preview <span class="caret"></span>';
             $previewDropdown .= '	</a>';
             $previewDropdown .= sprintf('<ul class="dropdown-menu">%s</ul>', implode('', $previewLinks));
             $previewDropdown .= '</div>';
             // Build the download dropbox HTML
             $downloadDropdown = '<div class="btn-group">';
             $downloadDropdown .= '	<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">';
             $downloadDropdown .= '		Download <span class="caret"></span>';
             $downloadDropdown .= '	</a>';
             $downloadDropdown .= sprintf('<ul class="dropdown-menu">%s</ul>', implode('', $downloadLinks));
             $downloadDropdown .= '</div>';
             $fileLIs[] = sprintf('<li><div class="filename">%s</div><!-- TODO <button class="btn">Field Details</button> -->%s%s</li>', $file['name'], $previewDropdown, $downloadDropdown);
         }
         $output .= sprintf('<div class="filePreviewField"><header>%s</header><ul class="filePreviews">%s</ul></div>', $field['label'], implode('', $fileLIs));
     }
     // Include the filePreview Modal, and the CSS and JavaScript links
     $output .= '<div id="filePreviewModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3></h3></div><div class="modal-body"><iframe class="filePreview"></iframe></div><div class="modal-footer"><a class="btn previewDownloadLink">Download File</a><a class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Close</a></div></div>';
     $output .= sprintf('<link href="%sincludes/css/filePreview.css" rel="stylesheet">', localvars::get('siteRoot'));
     $output .= sprintf('<script src="%sincludes/js/filePreview.js"></script>', localvars::get('siteRoot'));
     return $output;
 }
Esempio n. 2
0
 function replaceShortCodes($file)
 {
     // Rules
     $answer = "array(\n";
     foreach ($this->class->rules as $key => $value) {
         $answer .= "\t\t'{$key}' \t=> '{$value}',\n";
     }
     $answer .= "\t);";
     $file = str_replace("{{\$rules}}", $answer, $file);
     // id
     $answer = $this->class->id;
     $file = str_replace("{{\$id}}", $answer, $file);
     // name
     $answer = ucfirst($this->class->id);
     $file = str_replace("{{\$name}}", $answer, $file);
     // title
     $answer = ucfirst($this->class->title);
     $file = str_replace("{{\$title}}", $answer, $file);
     // inputsobjects
     $answer = "";
     foreach ($this->class->columns as $key => $value) {
         $type = explode(":", $value);
         $type = $type[0];
         if ($type == "checkbox") {
             $answer .= "\$object->{$key} = json_encode( Input::get('{$key}') );\n\t\t\t";
         } else {
             if ($type == "password") {
                 $answer .= "\$object->{$key} = Hash::make( Input::get('{$key}') );\n\t\t\t";
             } else {
                 $answer .= "\$object->{$key} = Input::get('{$key}');\n\t\t\t";
             }
         }
     }
     $file = str_replace("{{\$inputsobjects}}", $answer, $file);
     /* Views */
     $forms = new forms();
     $forms->addValues($this->class->values);
     $forms->execute($this->class->columns);
     // getFields
     $answer = "";
     foreach ($forms->getFields() as $field) {
         $answer .= "\n\t\t\t<p>\n\t\t\t\t<label>" . $field->text . "</label>\n\t\t\t\t" . $field->input . "\n\t\t\t</p>";
     }
     $file = str_replace("{{\$getFields}}", $answer, $file);
     // getHiddenFields
     $answer = "";
     foreach ($forms->getHiddenInputs() as $field) {
         $answer .= "\n\t\t\t" . $field->input;
     }
     $file = str_replace("{{\$getHiddenFields}}", $answer, $file);
     // getInformation
     $answer = "";
     foreach ($this->class->columns as $key => $value) {
         $value = ucfirst($key);
         $answer .= "<tr>\n\t\t\t\t<td>";
         $answer .= "{$value}</td>\n\t\t\t\t";
         $answer .= "<td>{{\$data->{$key}}}</td>\n\t\t\t";
         $answer .= "</tr>\n\t\t\t";
     }
     $file = str_replace("{{\$getInformation}}", $answer, $file);
     // Edit
     $forms = new forms(true);
     $forms->addValues($this->class->values);
     $forms->execute($this->class->columns);
     // getFieldsWithValues
     $answer = "";
     foreach ($forms->getFields() as $field) {
         $answer .= "\n\t\t\t<p>\n\t\t\t\t<label>" . $field->text . "</label>\n\t\t\t\t" . $field->input . "\n\t\t\t</p>";
     }
     $file = str_replace("{{\$getFieldsWithValues}}", $answer, $file);
     // getHiddenFieldsWithValues
     $answer = "";
     foreach ($forms->getHiddenInputs() as $field) {
         $answer .= "\n\t\t\t" . $field->input;
     }
     $file = str_replace("{{\$getHiddenFieldsWithValues}}", $answer, $file);
     // mainColumn
     $answer = $this->class->mainColumn;
     $file = str_replace("{{\$mainColumn}}", $answer, $file);
     if (!is_null($this->feature)) {
         // Its send from any feature folder
         foreach ($this->class->features[$this->feature] as $key => $value) {
             $file = str_replace("{{\${$key}}}", $value, $file);
         }
     }
     return $file;
 }