'Page Edit Link', 'summary' => 'Provides a link capability as used by some Fieldtype modules (like TinyMCE)', 'version' => 105, 'permanent' => true, 'permission' => 'page-edit', ); } const urlTypeAbsolute = 0; const urlTypeRelativeBranch = 1; const urlTypeRelativeAll = 2; protected $startLabel = ''; public function __construct() { $this->set('urlType', self::urlTypeAbsolute); } public function init() { $this->startLabel = $this->_('Choose page'); $this->modules->get("ProcessPageList"); $id = (int) $this->input->get->id; if($id) $this->page = $this->pages->get($id); if($this->page && $this->page->id && !$this->user->hasPermission("page-view", $this->page)) throw new WireException("You don't have access to this page"); if(!$this->page) $this->page = new NullPage(); //$target = $this->sanitizer->name($this->input->get->target); //$this->config->js('ProcessPageEditLinkTarget', $target); $this->config->js('ProcessPageEditLink', array( 'selectStartLabel' => $this->startLabel, 'langID' => ($this->input->get->lang ? (int) $this->input->get->lang : 0), 'pageID' => $id, 'pageUrl' => $this->page->url, 'pageName' => $this->page->name, 'rootParentUrl' => $this->page->rootParent->url, 'slashUrls' => $this->page->template->slashUrls, 'urlType' => $this->urlType )); parent::init(); } public function ___execute() { $form = $this->modules->get("InputfieldForm"); $form->attr('id', 'ProcessPageEditLinkForm'); $form->description = $this->_("Enter a URL, select a page, or select a file to link:"); // Headline $field = $this->modules->get("InputfieldURL"); $field->label = $this->_("Link to URL"); $field->attr('id+name', 'link_page_url'); $form->append($field); $field = $this->modules->get('InputfieldInteger'); $field->attr('id+name', 'link_page_id'); $field->label = $this->_("Link to Page"); $field->startLabel = $this->startLabel; $field->collapsed = Inputfield::collapsedYes; $form->append($field); if($this->page->numChildren) { $field = $this->modules->get('InputfieldInteger'); $field->attr('id+name', 'child_page_id'); $field->label = $this->_("Link to Child Page"); $field->description = $this->_('This is the same as "Link to Page" above, but may quicker to use if linking to children of the current page.'); $field->startLabel = $this->startLabel; $field->collapsed = Inputfield::collapsedYes; $form->append($field); } $form->append($this->getFilesField()); $field = $this->modules->get("InputfieldCheckbox"); $field->label = $this->_("Launch In New Window?"); $field->description = $this->_("If checked, the link will open in a new window leaving the current window in place."); // Details for 'launch in new window' checkbox $field->attr('id+name', 'link_target'); $field->attr('value', '_blank'); $field->collapsed = Inputfield::collapsedYes; $form->append($field); return $form->render(); } public function ___executeFiles() { if(!$this->page->id) throw new WireException("A page id must be specified"); $files = $this->getFiles(); return WireEncodeJSON($files); } protected function getFiles() { $files = array(); if($this->page->id) foreach($this->page->fields as $f) { if(!$f->type instanceof FieldtypeFile) continue; foreach($this->page->get($f->name) as $file) { $files[$file->url] = $f->name . ' - ' . $file->basename; } } asort($files); return $files; } protected function getFilesField() { $field = $this->modules->get("InputfieldSelect"); $field->label = $this->_("Link to File"); $field->attr('id+name', 'link_page_file'); $files = $this->getFiles(); $field->addOption(''); $field->addOptions($files); $field->collapsed = Inputfield::collapsedYes; if($this->page->id) $field->notes = $this->page->url; $field->description = $this->_("To select a file from another page, click 'Link to Page' above and choose the page you want to select a file from."); // Instruction on how to select a file from another page return $field; } public static function getModuleConfigInputfields(array $data) { $inputfields = new InputfieldWrapper(); $f = wire('modules')->get('InputfieldRadios'); $f->attr('name', 'urlType'); $f->label = __('URL type for page links'); $f->addOption(self::urlTypeAbsolute, __('Absolute (default)')); $f->addOption(self::urlTypeRelativeBranch, __('Relative URLs in the same branches only') . '*'); $f->addOption(self::urlTypeRelativeAll, __('Relative URLs always') . '*'); $f->attr('value', isset($data['urlType']) ? $data['urlType'] : self::urlTypeAbsolute); $f->notes = __('*Currently experimental'); $inputfields->add($f); return $inputfields; } }