public function on_start() { Events::extend('on_file_add', function ($f, $fv) { $setless_fs = FileSet::getByName('Setless'); $setless_fs->addFileToSet($f); }); Events::extend('on_file_added_to_set', function ($fID, $fv) { $setless_fs = FileSet::getByName('Setless'); $file = File::getByID($fID); $file_sets = $file->getFileSets(); $file_set_ids = array(); foreach ($file_sets as $file_set) { $file_set_ids[] = $file_set->fsID; } // If file is in multiple sets and setless is one of them, remove from setless if (count($file_set_ids) >= 2 && in_array($setless_fs->fsID, $file_set_ids)) { $setless_fs->removeFileFromSet($file); } }); Events::extend('on_file_removed_from_set', function ($fID, $fv) { $setless_fs = FileSet::getByName('Setless'); $file = File::getByID($fID); $file_sets = $file->getFileSets(); // If file is no longer in any sets, add to setless if (count($file_sets) == 0) { $setless_fs->addFileToSet($file); } }); }
function getFile($fID) { Loader::model('file'); $mf = new File(); $file_obj = $mf->getByID($fID); $fileversion_obj = $file_obj->getVersion(); $bf = new LibraryFileBlockController; $ftype = FileTypeList::getType($fileversion_obj->getExtension()); $this->generictype = strtolower($ftype->getGenericTypeText($ftype->getGenericType())); $this->filename = $fileversion_obj->getFileName(); $this->type = $fileversion_obj->getType(); $this->url = $fileversion_obj->getURL(); $this->filepath = $fileversion_obj->getPath(); $this->relpath = $fileversion_obj->getRelativePath(); $this->origfilename = $fileversion_obj->getRelativePath(); $this->filesize = $fileversion_obj->getFullSize(); $len = strlen(REL_DIR_FILES_UPLOADED); $fh = Loader::helper('concrete/file'); $bf->bID = $fileversion_obj->getFileID(); $bf->generictype = $this->generictype; $bf->type = $this->type; $bf->url = $this->url; $bf->filepath = $this->filepath; $bf->relpath = $this->relpath; $bf->filename = substr($this->relpath, $len); // for backwards compatibility this must include the prefixes $bf->filesize = $this->filesize; return $bf; }
public function testFilterBySet() { $fs = \FileSet::add('test'); $f = \File::getByID(1); $f2 = \File::getByID(4); $fs->addFileToSet($f); $fs->addFileToSet($f2); $fs2 = \FileSet::add('test2'); $fs2->addFiletoSet($f); $this->list->filterBySet($fs); $pagination = $this->list->getPagination(); $this->assertEquals(2, $pagination->getTotalResults()); $results = $this->list->getResults(); $this->assertEquals(2, count($results)); $this->assertEquals(4, $results[1]->getFileID()); $this->list->filterBySet($fs2); $results = $this->list->getResults(); $this->assertEquals(1, count($results)); $this->assertEquals(1, $results[0]->getFileID()); $nl = new \Concrete\Core\File\FileList(); $nl->ignorePermissions(); $nl->filterByNoSet(); $results = $nl->getResults(); $this->assertEquals(9, count($results)); }
public static function addFilesForProduct(array $files, StoreProduct $product) { self::removeFilesForProduct($product); //add new ones. if (!empty($files['dffID'])) { foreach ($files['dffID'] as $fileID) { if (!empty($fileID) && $fileID > 0) { self::add($product->getProductID(), $fileID); $fileObj = \File::getByID($fileID); $fs = \FileSet::getByName("Digital Downloads"); $fs->addFileToSet($fileObj); $fileObj->resetPermissions(1); $pk = \Concrete\Core\Permission\Key\FileKey::getByHandle('view_file'); $pk->setPermissionObject($fileObj); $pao = $pk->getPermissionAssignmentObject(); $groupEntity = \Concrete\Core\Permission\Access\Entity\GroupEntity::getOrCreate(\Group::getByID(GUEST_GROUP_ID)); $pa = $pk->getPermissionAccessObject(); if ($pa) { $pa->removeListItem($groupEntity); $pao->assignPermissionAccess($pa); } } } } }
/** * Sets up a file field for use with a block. * @param string $id The ID of your form field * @param string $postname The name of your database column into which you'd like to save the file ID * @param string $chooseText * @param LibraryFileBlock $bf * return string $html */ public function file($id, $postname, $chooseText, $bf = null, $filterArgs = array()) { $selectedDisplay = 'none'; $resetDisplay = 'block'; $fileID = 0; if (isset($_POST[$postname])) { $bf = File::getByID($_POST[$postname]); } if (is_object($bf) && !$bf->isError() && $bf->getFileID() > 0) { $fileID = $bf->getFileID(); $selectedDisplay = 'block'; $resetDisplay = 'none'; } $html = '<div id="' . $id . '-fm-selected" onclick="ccm_chooseAsset=false" class="ccm-file-selected-wrapper" style="display: ' . $selectedDisplay . '"><img src="' . ASSETS_URL_IMAGES . '/throbber_white_16.gif" /></div>'; $html .= '<div class="ccm-file-manager-select" id="' . $id . '-fm-display" ccm-file-manager-field="' . $id . '" style="display: ' . $resetDisplay . '">'; $html .= '<a href="javascript:void(0)" onclick="ccm_chooseAsset=false; ccm_alLaunchSelectorFileManager(\'' . $id . '\')">' . $chooseText . '</a>'; if ($filterArgs != false) { foreach ($filterArgs as $key => $value) { $html .= '<input type="hidden" class="ccm-file-manager-filter" name="' . $key . '" value="' . $value . '" />'; } } $html .= '</div><input id="' . $id . '-fm-value" type="hidden" name="' . $postname . '" value="' . $fileID . '" />'; if (is_object($bf) && !$bf->isError() && $bf->getFileID() > 0) { $html .= '<script type="text/javascript">$(function() { ccm_triggerSelectFile(' . $fileID . ', \'' . $id . '\'); });</script>'; } return $html; }
public function saveForm($data) { if ($data['value'] > 0) { $f = File::getByID($data['value']); $this->saveValue($f); } else { $db = Loader::db(); $db->Replace('atFile', array('avID' => $this->getAttributeValueID(), 'fID' => 0), 'avID', true); } }
public static function getImageObjectsForProduct(StoreProduct $product) { $images = self::getImagesForProduct($product); $imageObjects = array(); foreach ($images as $img) { $imageObjects[] = File::getByID($img->getFileID()); } return $imageObjects; }
public function submit_password($fID = 0) { $f = File::getByID($fID); if ($f->getPassword() == $_POST['password']) { return $this->download($f); } $this->set('error', t("Password incorrect. Please try again.")); $this->view($fID); }
function delete($useWhere = false) { try { $f = File::getByID($this->file_id); $f->blowCache(); } catch (NoResultException $e) { // ...alright, that's weird, but no File to delete anyway. } return parent::delete($useWhere); }
public function convert($val) { if ($val) { $file = File::getByID($val); if (!$file->error) { $im = Loader::helper('image'); return t('<a href="%s" target="_blank"><img src="%s" /></a>', $file->getRelativePath(), $im->getThumbNail($file, $this->w, $this->h, $this->crop)->src); } } }
public function import_wordpress_xml() { if ($this->post('import-images') == 'on') { $this->importImages = true; $filesetname; $this->post('file-set-name') ? $this->filesetname = $this->post('file-set-name') : ($this->filesetname = t("Imported Wordpress Files")); $this->createFileSet = true; } $pages = array(); if (intval($this->post('wp-file')) > 0) { Loader::model('file'); $co = new Config(); $pkg = Package::getByHandle('wordpress_site_importer'); $co->setPackageObject($pkg); $co->save("WORDPRESS_IMPORT_FID", $this->post('wp-file')); $importFile = File::getByID($this->post('wp-file')); $nv = $importFile->getVersion(); $fileUrl = $nv->getDownloadURL(); $xml = @simplexml_load_file($fileUrl, "SimpleXMLElement", LIBXML_NOCDATA); $items = array(); foreach ($xml->channel->item as $item) { $items[] = $item->asxml(); } $db = Loader::db(); $sql = $db->Prepare('insert into WordpressItems (wpItem) values(?)'); foreach ($items as $item) { $db->Execute($sql, $item); } $categories = array(); $namespaces = $xml->getDocNamespaces(); foreach ($xml->xpath('/rss/channel/wp:category') as $term_arr) { $t = $term_arr->children($namespaces['wp']); $categories[] = array('term_id' => (int) $t->term_id, 'category_nicename' => (string) $t->category_nicename, 'category_parent' => (string) $t->category_parent, 'cat_name' => (string) $t->cat_name, 'category_description' => (string) $t->category_description); } Loader::model('attribute/categories/collection'); $akt = CollectionAttributeKey::getByHandle("wordpress_category"); for ($i = 0; $i < count($categories); $i++) { $opt = new SelectAttributeTypeOption(0, $categories[$i]['cat_name'], $i); $opt = $opt->saveOrCreate($akt); } foreach ($xml->xpath('/rss/channel/wp:tag') as $term_arr) { $t = $term_arr->children($namespaces['wp']); $tags[] = array('term_id' => (int) $t->term_id, 'tag_slug' => (string) $t->tag_slug, 'tag_name' => (string) $t->tag_name, 'tag_description' => (string) $t->tag_description); } $akt = CollectionAttributeKey::getByHandle("tags"); for ($i = 0; $i < count($tags); $i++) { $opt = new SelectAttributeTypeOption(0, $tags[$i]['tag_name'], $i); $opt = $opt->saveOrCreate($akt); } } else { echo t("No file"); exit; } $this->view(); }
public function submit_password($fID = 0) { if ($fID > 0 && Loader::helper('validation/numbers')->integer($fID)) { $f = File::getByID($fID); if ($f->getPassword() == $_POST['password']) { return $this->download($f); } $this->set('error', t("Password incorrect. Please try again.")); $this->view($fID); } }
public function view() { $image = false; if ($this->fID) { $f = \File::getByID($this->fID); if (is_object($f)) { $image = Core::make('html/image', array($f, false))->getTag(); $image->alt($this->name); $this->set('image', $image); } } }
public function update() { Loader::model('file'); Loader::model('attribute/categories/file'); $fIDs = $this->post("fID"); foreach ($fIDs as $key => $id) { $f = File::getByID($id); $fv = $f->getRecentVersion(); $fv->setAttribute(MOOTOOLS_PLUGIN_DISPLAY_ORDER, $key); } $this->view(); }
public function getPermittedFiles($imagesOnly = false) { $fileIDs = $this->getSortedFileIDs($imagesOnly); $files = array(); foreach ($fileIDs as $fID) { $f = File::getByID($fID); $fp = new Permissions($f); if ($fp->canRead()) { $files[] = $f; } } return $files; }
public function getPermittedFiles($imagesOnly = false) { $allFiles = $this->getSortedFiles($imagesOnly); $permittedFiles = array(); foreach ($allFiles as $file) { $f = File::getByID($file['fID']); $fp = new Permissions($f); if ($fp->canRead()) { $permittedFiles[$file['fID']] = array('file' => $f, 'fID' => $file['fID'], 'position' => $file['position'], 'title' => $file['title'], 'caption' => $file['caption']); } } return $permittedFiles; }
function get_thumbnail_url_from_file_id($avatar_file_id, $def_url, $level = 1) { $f = File::getByID($avatar_file_id); if ($f->error != 0) { $avatar_url = $def_url; } else { $fv = $f->getRecentVersion(); $avatar_url = $fv->getThumbnailSRC($level); } if (strlen($avatar_url) < 10) { return $def_url; } return $avatar_url; }
public function view() { $this->set('DASHBOARD_BACKGROUND_IMAGE', Config::get('DASHBOARD_BACKGROUND_IMAGE')); $imageObject = false; if ($this->get('DASHBOARD_BACKGROUND_IMAGE') == 'custom') { $fID = Config::get('DASHBOARD_BACKGROUND_IMAGE_CUSTOM_FILE_ID'); if ($fID > 0) { $imageObject = File::getByID($fID); if (is_object($imageObject) && $imageObject->isError()) { unset($imageObject); } } } $this->set('imageObject', $imageObject); }
public function getSelectedOptions() { $db = Loader::db(); $avID = $this->getAttributeValueID(); $value = $db->GetRow("select avID,fileIDs from `" . $this->atValueTableName . "` where avID = ?", array($avID)); $fileIDs = explode(",", $value['fileIDs']); $files = array(); foreach ($fileIDs as $fID) { $file = File::getByID(intval($fID)); if (!is_object($file) || !$file->getFileID()) { continue; } $files[] = $file; } return $files; }
public function submit_password($fID = 0) { if ($fID > 0 && Loader::helper('validation/numbers')->integer($fID)) { $f = File::getByID($fID); $rcID = $this->post('rcID') ? $this->post('rcID') : NULL; if ($f->getPassword() == $this->post('password')) { if ($this->post('force')) { return $this->force_download($f); } else { return $this->download($f); } } $this->set('error', t("Password incorrect. Please try again.")); $this->set('force', $this->post('force') ? 1 : 0); $this->view($fID, $rcID); } }
private static function renderPage($page, $site) { // set a session variable to prevent infinite rendering $_SESSION['routing'] = true; $perm = new Permissions($page); if (!$perm->isError()) { // Set the current page in the request object Request::get()->setCurrentPage($page); // Render the view $view = View::getInstance(); $view->setCollectionObject($page); if ($site->favicon) { $favicon = File::getByID($site->favicon); $view->addHeaderItem('<link rel="icon" href="' . $favicon->getRelativePath() . '" type="image/x-icon" />'); $view->addHeaderItem('<link rel="shortcut icon" href="' . $favicon->getRelativePath() . '" type="image/x-icon" />'); } $view->render($page); exit; } }
private function get_image_object($fID, $width = 0, $height = 0, $crop = false) { if (empty($fID)) { $image = null; } else { if (empty($width) && empty($height)) { //Show image at full size (do not generate a thumbnail) $file = File::getByID($fID); $image = new stdClass(); $image->src = $file->getRelativePath(); $image->width = $file->getAttribute('width'); $image->height = $file->getAttribute('height'); } else { //Generate a thumbnail $width = empty($width) ? 9999 : $width; $height = empty($height) ? 9999 : $height; $file = File::getByID($fID); $ih = Loader::helper('image'); $image = $ih->getThumbnail($file, $width, $height, $crop); } } return $image; }
$files = array(); $searchInstance = Loader::helper('text')->entities($_REQUEST['searchInstance']); $extensions = array(); if (is_array($_REQUEST['fID'])) { foreach($_REQUEST['fID'] as $fID) { $f = File::getByID($fID); $fp = new Permissions($f); if ($fp->canViewFile()) { $files[] = $f; $extensions[] = strtolower($f->getExtension()); } } } else { $f = File::getByID($_REQUEST['fID']); $fp = new Permissions($f); if ($fp->canViewFile()) { $files[] = $f; $extensions[] = strtolower($f->getExtension()); } } $extensions = array_unique($extensions); $sets = array(); // tri state checkbox // state 0 - none of the selected files are in the set // state 1 - SOME of the selected files are in the set // state 2 - ALL files are in the set foreach($s1 as $fs) {
echo $f->getRelativePath(); ?> " type="image/x-icon" /> <?php } if ($appleIconFID) { $f = File::getByID($appleIconFID); ?> <link rel="apple-touch-icon" href="<?php echo $f->getRelativePath(); ?> " /> <?php } if ($modernIconFID) { $f = File::getByID($modernIconFID); ?> <meta name="msapplication-TileImage" content="<?php echo $f->getRelativePath(); ?> " /><?php echo "\n"; if (strlen($modernIconBGColor)) { ?> <meta name="msapplication-TileColor" content="<?php echo $modernIconBGColor; ?> " /><?php echo "\n"; } }
<?php if ($images) { $count = 0; foreach ($images as $image) { ?> itemsContainer.append(itemTemplate({ pifID: '<?php echo $image['pifID']; ?> ', <?php if ($image['pifID']) { ?> thumb: '<?php echo File::getByID($image['pifID'])->getThumbnailURL('file_manager_listing'); ?> ', <?php } else { ?> thumb: '', <?php } ?> sort: '<?php echo $count++; ?> ' })); <?php
</td> <td><?php if ($answerSet['uID'] > 0) { $ui = UserInfo::getByID($answerSet['uID']); if (is_object($ui)) { print $ui->getUserName() . ' '; } print t('(User ID: %s)', $answerSet['uID']); } ?> </td> <?php foreach ($questions as $questionId => $question) { if ($question['inputType'] == 'fileupload') { $fID = (int) $answerSet['answers'][$questionId]['answer']; $file = File::getByID($fID); if ($fID && $file) { $fileVersion = $file->getApprovedVersion(); echo '<td><a href="' . $fileVersion->getRelativePath() . '">' . $text->entities($fileVersion->getFileName()) . '</a></td>'; } else { echo '<td>' . t('File not found') . '</td>'; } } else { if ($question['inputType'] == 'text') { echo '<td>' . $text->entities($answerSet['answers'][$questionId]['answerLong']) . '</td>'; } else { echo '<td>' . $text->entities($answerSet['answers'][$questionId]['answer']) . '</td>'; } } } ?>
protected function replaceImageID($match) { $fID = $match[1]; if ($fID > 0) { preg_match('/width\\s*="([0-9]+)"/', $match[0], $matchWidth); preg_match('/height\\s*="([0-9]+)"/', $match[0], $matchHeight); $file = File::getByID($fID); if (is_object($file) && !$file->isError()) { $imgHelper = Loader::helper('image'); $maxWidth = $matchWidth[1] ? $matchWidth[1] : $file->getAttribute('width'); $maxHeight = $matchHeight[1] ? $matchHeight[1] : $file->getAttribute('height'); if ($file->getAttribute('width') > $maxWidth || $file->getAttribute('height') > $maxHeight) { $thumb = $imgHelper->getThumbnail($file, $maxWidth, $maxHeight); return preg_replace('/{CCM:FID_([0-9]+)}/i', $thumb->src, $match[0]); } } return $match[0]; } }
} else { if ($row['internalLinkCID']) { $linkType = 1; } } ?> sliderEntriesContainer.append(_templateSlide({ fID: '<?php echo $row['fID']; ?> ', <?php if (File::getByID($row['fID'])) { ?> image_url: '<?php echo File::getByID($row['fID'])->getThumbnailURL('file_manager_listing'); ?> ', <?php } else { ?> image_url: '', <?php } ?> link_url: '<?php echo $row['linkURL']; ?> ', link_type: '<?php echo $linkType;
public function excel(){ $dateHelper = Loader::helper('date'); $this->pageSize=0; $this->loadSurveyResponses(); $textHelper = Loader::helper('text'); $questionSet=$this->get('questionSet'); $answerSets=$this->get('answerSets'); $questions=$this->get('questions'); $surveys=$this->get('surveys'); $fileName=$textHelper->filterNonAlphaNum($surveys[$questionSet]['surveyName']); header("Content-Type: application/vnd.ms-excel"); header("Cache-control: private"); header("Pragma: public"); $date = date('Ymd'); header("Content-Disposition: inline; filename=".$fileName."_form_data_{$date}.xls"); header("Content-Title: ".$surveys[$questionSet]['surveyName']." Form Data Output - Run on {$date}"); echo "<table>\r\n"; $hasCBRow = false; foreach($questions as $questionId=>$question){ if ($question['inputType'] == 'checkboxlist') { $hasCBRow = true; } } echo "<tr>"; echo "\t\t<td "; if ($hasCBRow) { echo "rowspan=\"2\" valign='bottom'"; } echo "><b>Submitted Date</b></td>\r\n"; foreach($questions as $questionId=>$question){ if ($question['inputType'] == 'checkboxlist') { $options = explode('%%', $question['options']); echo "\t\t".'<td colspan="'.count($options).'"><b>'."\r\n"; } else { echo "\t\t<td "; if ($hasCBRow) { echo "rowspan=\"2\" valign='bottom'>"; } echo "<b>\r\n"; } echo "\t\t\t".$questions[$questionId]['question']."\r\n"; echo "\t\t</b></td>\r\n"; } echo "</tr>"; // checkbox row if ($hasCBRow) { echo "<tr>"; foreach($questions as $questionId=>$question){ if ($question['inputType'] == 'checkboxlist') { $options = explode('%%', $question['options']); foreach($options as $opt) { echo "<td><b>{$opt}</b></td>"; } } } echo "</tr>"; } foreach($answerSets as $answerSetId=>$answerSet){ $questionNumber=0; $numQuestionsToShow=2; echo "\t<tr>\r\n"; echo "\t\t<td>". $dateHelper->getSystemDateTime($answerSet['created'])."</td>\r\n"; foreach($questions as $questionId=>$question){ $questionNumber++; if ($question['inputType'] == 'checkboxlist'){ $options = explode('%%', $question['options']); $subanswers = explode(',', $answerSet['answers'][$questionId]['answer']); for ($i = 1; $i <= count($options); $i++) { echo "\t\t<td align='center'>\r\n"; if (in_array(trim($options[$i-1]), $subanswers)) { // echo "\t\t\t".$options[$i-1]."\r\n"; echo "x"; } else { echo "\t\t\t \r\n"; } echo "\t\t</td>\r\n"; } }elseif($question['inputType']=='fileupload'){ echo "\t\t<td>\r\n"; $fID=intval($answerSet['answers'][$questionId]['answer']); $file=File::getByID($fID); if($fID && $file){ $fileVersion=$file->getApprovedVersion(); echo "\t\t\t".'<a href="'. $fileVersion->getDownloadURL() .'">'.$fileVersion->getFileName().'</a>'."\r\n"; }else{ echo "\t\t\t".t('File not found')."\r\n"; } echo "\t\t</td>\r\n"; }else{ echo "\t\t<td>\r\n"; echo "\t\t\t".$answerSet['answers'][$questionId]['answer'].$answerSet['answers'][$questionId]['answerLong']."\r\n"; echo "\t\t</td>\r\n"; } } echo "\t</tr>\r\n"; } echo "</table>\r\n"; die; }
/** * returns the complete html img tag for this collection type's icon */ public function getCollectionTypeIconImage() { Loader::helper('concrete/file'); $html = Loader::helper('html'); $icon = $this->getCollectionTypeIcon(); if (is_numeric($icon) && $icon) { $f = File::getByID($icon); $fv = $f->getApprovedVersion(); $src = $fv->getRelativePath(); } else { // retain support for legacy file type images $src = REL_DIR_FILES_COLLECTION_TYPE_ICONS . '/' . $icon; } $iconImg = '<img src="' . $src . '" height="' . COLLECTION_TYPE_ICON_HEIGHT . '" width="' . COLLECTION_TYPE_ICON_WIDTH . '" alt="' . $this->getCollectionTypeName() . '" title="' . $this->getCollectionTypeName() . '" />'; return $iconImg; }