I made a block with a few fields, but for some reason the image field (which draws from the library) isn't saving, so when I go to edit, the image I'd originally chosen doesn't show up. Any idea how to fix this? Here are the files, not sure if posting everything is necessary in this case but I didn't want to leave anything out:
add.php:
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
//$replaceOnUnload = 1;
?>
<?php
$al = Loader::helper('concrete/asset_library');
echo $al->file('ccm-b-file', 'tID', t('Choose File'), $bf)
?>
<?php $bf = File::getByID($tID);?>
<?php
$includeAssetLibrary = true;
$assetLibraryPassThru = array(
'type' => 'image'
);
$al = Loader::helper('concrete/asset_library');
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
//$replaceOnUnload = 1;
?>
<?php
$al = Loader::helper('concrete/asset_library');
echo $al->file('ccm-b-file', 'tID', t('Choose File'), $bf)
?>
<?php $bf = File::getByID($tID);?>
<?php
$includeAssetLibrary = true;
$assetLibraryPassThru = array(
'type' => 'image'
);
$al = Loader::helper('concrete/asset_library');
?>
<?php $bt->inc('editor_init.php'); ?>
<div style="text-align: center">
<textarea id="ccm-content-<?php echo $a->getAreaID()?>" class="advancedEditor ccm-advanced-editor" name="content"></textarea>
</div>
controller.php:
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
class RelLinkBlockController extends BlockController {
var $pobj;
protected $btTable = 'btRelLinkLocal';
protected $btInterfaceWidth = "600";
protected $btInterfaceHeight = "465";
public function getBlockTypeDescription() {
return t("Image and Text.");
}
public function getBlockTypeName() {
return t("RelLink");
}
function getRelLink() {
$content = $this->translateFrom($this->content);
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
class RelLinkBlockController extends BlockController {
var $pobj;
protected $btTable = 'btRelLinkLocal';
protected $btInterfaceWidth = "600";
protected $btInterfaceHeight = "465";
public function getBlockTypeDescription() {
return t("Image and Text.");
}
public function getBlockTypeName() {
return t("RelLink");
}
function getRelLink() {
$content = $this->translateFrom($this->content);
return $content;
}
public function getSearchableRelLink(){
return $this->content;
}
function br2nl($str) {
$str = str_replace("\r\n", "\n", $str);
$str = str_replace("<br />\n", "\n", $str);
return $str;
}
function getRelLinkEditMode() {
$content = $this->translateFromEditMode($this->content);
return $content;
}
function translateFromEditMode($text) {
// old stuff. Can remove in a later version.
$text = str_replace('href="{[CCM:BASE_URL]}', 'href="' . BASE_URL . DIR_REL, $text);
$text = str_replace('src="{[CCM:REL_DIR_FILES_UPLOADED]}', 'src="' . BASE_URL . REL_DIR_FILES_UPLOADED, $text);
// we have the second one below with the backslash due to a screwup in the
// 5.1 release. Can remove in a later version.
$text = preg_replace(
array(
'/{\[CCM:BASE_URL\]}/i',
'/{CCM:BASE_URL}/i'),
array(
BASE_URL . DIR_REL,
BASE_URL . DIR_REL)
, $text);
// now we add in support for the links
$text = preg_replace(
'/{CCM:CID_([0-9]+)}/i',
BASE_URL . DIR_REL . '/' . DISPATCHER_FILENAME . '?cID=\\1',
$text);
// now we add in support for the files
$text = preg_replace_callback(
'/{CCM:FID_([0-9]+)}/i',
array('RelLinkBlockController', 'replaceFileIDInEditMode'),
$text);
return $text;
}
function translateFrom($text) {
// old stuff. Can remove in a later version.
$text = str_replace('href="{[CCM:BASE_URL]}', 'href="' . BASE_URL . DIR_REL, $text);
$text = str_replace('src="{[CCM:REL_DIR_FILES_UPLOADED]}', 'src="' . BASE_URL . REL_DIR_FILES_UPLOADED, $text);
// we have the second one below with the backslash due to a screwup in the
// 5.1 release. Can remove in a later version.
$text = preg_replace(
array(
'/{\[CCM:BASE_URL\]}/i',
'/{CCM:BASE_URL}/i'),
array(
BASE_URL . DIR_REL,
BASE_URL . DIR_REL)
, $text);
// now we add in support for the links
$text = preg_replace_callback(
'/{CCM:CID_([0-9]+)}/i',
array('RelLinkBlockController', 'replaceCollectionID'),
$text);
// now we add in support for the files
$text = preg_replace_callback(
'/{CCM:FID_([0-9]+)}/i',
array('RelLinkBlockController', 'replaceFileID'),
$text);
return $text;
}
private function replaceFileID($match) {
$fID = $match[1];
if ($fID > 0) {
$path = File::getRelativePathFromID($fID);
return $path;
}
}
private function replaceFileIDInEditMode($match) {
$fID = $match[1];
return View::url('/download_file', 'view_inline', $fID);
}
private function replaceCollectionID($match) {
$cID = $match[1];
if ($cID > 0) {
$path = Page::getCollectionPathFromID($cID);
if (URL_REWRITING == true) {
$path = DIR_REL . $path;
} else {
$path = DIR_REL . '/' . DISPATCHER_FILENAME . $path;
}
return $path;
}
}
function translateTo($text) {
// keep links valid
$url1 = str_replace('/', '\/', BASE_URL . DIR_REL . '/' . DISPATCHER_FILENAME);
$url2 = str_replace('/', '\/', BASE_URL . DIR_REL);
$url3 = View::url('/download_file', 'view_inline');
$url3 = str_replace('/', '\/', $url3);
$url3 = str_replace('-', '\-', $url3);
$text = preg_replace(
array(
'/' . $url1 . '\?cID=([0-9]+)/i',
'/' . $url3 . '([0-9]+)\//i',
'/' . $url2 . '/i'),
array(
'{CCM:CID_\\1}',
'{CCM:FID_\\1}',
'{CCM:BASE_URL}')
, $text);
return $text;
}
function getFileID() {return $this->fID;}
function getFileOnstateID() {return $this->fOnstateID;}
function getFileOnstateObject() {
if ($this->fOnstateID > 0) {
return File::getByID($this->fOnstateID);
}
}
function getFileObject() {
return File::getByID($this->fID);
}
function getAltText() {return $this->altText;}
function getExternalLink() {return $this->externalLink;}
public function save($args) {
$args['fOnstateID'] = ($args['fOnstateID'] != '') ? $args['fOnstateID'] : 0;
$args['fID'] = ($args['fID'] != '') ? $args['fID'] : 0;
$content = $this->translateTo($args['content']);
$args['content'] = $content;
parent::save($args);
}
function getContentAndGenerate($align = false, $style = false, $id = null) {
$db = Loader::db();
$c = Page::getCurrentPage();
$bID = $this->bID;
$f = $this->getFileObject();
$fullPath = $f->getPath();
$relPath = $f->getRelativePath();
$size = @getimagesize($fullPath);
if ($this->maxWidth > 0 || $this->maxHeight > 0) {
$mw = $this->maxWidth > 0 ? $this->maxWidth : $size[0];
$mh = $this->maxHeight > 0 ? $this->maxHeight : $size[1];
$ih = Loader::helper('image');
$thumb = $ih->getThumbnail($f, $mw, $mh);
$sizeStr = ' width="' . $thumb->width . '" height="' . $thumb->height . '"';
$relPath = $thumb->src;
} else {
$sizeStr = $size[3];
}
$img = "<img border=\"0\" class=\"ccm-image-block\" alt=\"{$this->altText}\" src=\"{$relPath}\" {$sizeStr} ";
$img .= ($align) ? "align=\"{$align}\" " : '';
$img .= ($style) ? "style=\"{$style}\" " : '';
if($this->fOnstateID != 0) {
$fos = $this->getFileOnstateObject();
if ($this->maxWidth > 0 || $this->maxHeight > 0) {
$thumbHover = $ih->getThumbnail($fos, $mw, $mh);
$relPathHover = $thumbHover->src;
} else {
$relPathHover = $fos->getRelativePath();
}
$img .= " onmouseover=\"this.src = '{$relPathHover}'\" ";
$img .= " onmouseout=\"this.src = '{$relPath}'\" ";
}
$img .= ($id) ? "id=\"{$id}\" " : "";
$img .= "/>";
if($this->externalLink != ""){
$img = "<a href=\"{$this->externalLink}\">" . $img ."</a>";
}
return $img;
}
}
?>
db.xml:
<?xml version="1.0"?>
<schema version="0.3">
<table name="btRelLinkLocal">
<field name="bID" type="I">
<key />
<unsigned />
</field>
<field name="tID" type="I">
<unsigned />
<default value="0" />
</field>
<field name="fID" type="I">
<unsigned />
<default value="0" />
</field>
<?xml version="1.0"?>
<schema version="0.3">
<table name="btRelLinkLocal">
<field name="bID" type="I">
<key />
<unsigned />
</field>
<field name="tID" type="I">
<unsigned />
<default value="0" />
</field>
<field name="fID" type="I">
<unsigned />
<default value="0" />
</field>
<field name="years" type="X2">
</field>
<field name="content" type="X2">
</field>
</table>
</schema>
edit.php, where the problem surely is:
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
//$replaceOnUnload = 1;
?>
<?php
$al = Loader::helper('concrete/asset_library');
echo $al->file('ccm-b-file', 'tID', t('Choose File'), $bf);
?>
<?php $file = File::getByID($tID);
$filePath = $file->getVersion()->getRelativePath();?>
<?php
$includeAssetLibrary = true;
$assetLibraryPassThru = array(
'type' => 'image'
);
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
//$replaceOnUnload = 1;
?>
<?php
$al = Loader::helper('concrete/asset_library');
echo $al->file('ccm-b-file', 'tID', t('Choose File'), $bf);
?>
<?php $file = File::getByID($tID);
$filePath = $file->getVersion()->getRelativePath();?>
<?php
$includeAssetLibrary = true;
$assetLibraryPassThru = array(
'type' => 'image'
);
$al = Loader::helper('concrete/asset_library');
?>
<?php
$bt->inc('editor_init.php');
?>
<div style="text-align: center" id="ccm-editor-pane">
<textarea id="ccm-content-<?php echo $b->getBlockID()?>-<?php echo $a->getAreaID()?>" class="advancedEditor ccm-advanced-editor" name="content"><?php echo $controller->getRelLinkEditMode()?></textarea>
</div>
view.php, editor_config.php, and editor_init.php probably aren't necessary to post, but if I'm wrong let me know and I'll post them asap.
Am I doing something horribly wrong (new to PHP, quite possible) or is this a simple fix? Thanks for any help.
You might want to check this block, it's a bit simpler but should give you enough hints about files in a block
http://www.codeblog.ch/2009/06/concrete5-staff-table/...