private function checkIfModuleExistsLocally($module, $output, $input) { if (!wire('modules')->get($module)) { $output->writeln("<comment>Cannot find '{$module}' locally, trying to download...</comment>"); $this->passOnToModuleDownloadCommand($module, $output, $input); } }
/** * Return new instance of the Inputfield associated with this Fieldtype * * Abstract Template Method: child classes should override this. Code snippet is for example purposes only. * * Page and Field are provided as params in case the Fieldtype needs them for any custom population with the Inputfield. * However, most Fieldtypes won't need them since Inputfield objects don't have any Page dependencies (!) * The Field class handles setting all standard Inputfield attributes rather than this method to reduce code duplication in Inputfield modules. * * (!) See FieldtypeFile for an example that uses both Page and Field params. * * @param Page $page * @param Field $field * @return Inputfield * */ public function getInputfield(Page $page, Field $field) { // TODO make this abstract $inputfield = wire('modules')->get('InputfieldText'); $inputfield->class = $this->className(); return $inputfield; }
function listIncomingInvoice() { $faelligrechnung = wire('pages')->get("/rechnungen/vorgaenge/")->children("invoiceVorgangsart=R,buchungKontenInaktiv=0, include=hidden, universalCheck=0"); $heute = time(); foreach ($faelligrechnung as $faellig) { $datumstring = explode("-", $faellig->datum); $datumstring[1]++; $formatDatum = $datumstring[2] . '-' . $datumstring[0] . '-' . $datumstring[1]; //YYYY MM DD $rechnungsdatum = strtotime($formatDatum); $differenz = $rechnungsdatum - $heute; $diff_tage = $differenz / 86400; $tagedifferenz = floor($diff_tage); if ($tagedifferenz >= "0" && $tagedifferenz <= "8") { if ($tagedifferenz == 0) { $tagedifferenz = "heute"; } if ($tagedifferenz > 1) { $noch = "in "; $tagedifferenz = $noch . ($tagedifferenz .= " Tagen"); } if ($tagedifferenz == 1) { $tagedifferenz = "Morgen"; } echo "<li><a href='{$faellig->url}'>{$faellig->title} - {$tagedifferenz}</a></li>"; } } }
/** * Render top navigation items * * @return string * * @todo: Renobird: the $userImg variable is currently unused--did you want to use that? * */ public function renderTopNavItems() { $out = ''; $user = $this->wire('user'); $config = wire("config"); $adminTheme = $this->wire('adminTheme'); $adminTheme->avatar_field != '' ? $imgField = $user->get($adminTheme->avatar_field) : ($imgField = ''); if ($imgField != '') { count($imgField) ? $img = $imgField->first() : ($img = $imgField); $out .= "<li class='avatar'><a href='{$config->urls->admin}profile/'>"; $userImg = $img->size(52, 52); // render at 2x for hi-dpi (52x52 for 26x26) $out .= "<img src='{$userImg->url}' alt='{$user->name}' /> <span>{$user->name}</span>"; $out .= "</a></li>"; } else { $title = $this->_('Profile'); $out .= "<li><a title='{$title}' href='{$config->urls->admin}profile/'><i class='fa fa-user'></i> <span>{$user->name}</span></a></li>"; } // view site $out .= "<li><a href='{$config->urls->root}'><i class='fa {$adminTheme->home}'></i></a></li>"; // logout $label = $this->_('Logout'); $out .= "<li><a title='{$label}' href='{$config->urls->admin}login/logout/'><i class='fa {$adminTheme->signout}'></i></a></li>"; return $out; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $names = explode(',', $input->getArgument('name')); $templates = wire('templates'); $fieldgroups = wire('fieldgroups'); foreach ($names as $name) { $template = $templates->get($name); if ($template->id) { // try to delete depending file? if (!$input->getOption('nofile') && file_exists($template->filename)) { unlink($template->filename); } $template->flags = \Template::flagSystemOverride; $template->flags = 0; // all flags now removed, can be deleted $templates->delete($template); // delete depending fieldgroups $fg = $fieldgroups->get($name); if ($fg->id) { $fieldgroups->delete($fg); } $output->writeln("<info>Template '{$name}' deleted successfully!</info>"); } else { $output->writeln("<error>Template '{$name}' doesn't exist!</error>"); } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $dev = $input->getOption('dev') ? true : false; $check = parent::checkForCoreUpgrades($output, $dev); $this->output = $output; $this->root = wire('config')->paths->root; if ($check['upgrade'] && $input->getOption('just-check') === false) { if (!extension_loaded('pdo_mysql')) { $this->output->writeln("<error>Your PHP is not compiled with PDO support. PDO is required by ProcessWire 2.4+.</error>"); } elseif (!class_exists('ZipArchive')) { $this->output->writeln("<error>Your PHP does not have ZipArchive support. This is required to install core or module upgrades with this tool.</error>"); } elseif (!is_writable($this->root)) { $this->output->writeln("<error>Your file system is not writable.</error>"); } else { $this->fs = new Filesystem(); $this->projectDir = $this->fs->isAbsolutePath($this->root) ? $this->root : getcwd() . DIRECTORY_SEPARATOR . $this->root; $this->branch = $check['branch']; try { $this->download()->extract()->move()->cleanup()->replace($input->getOption('just-download'), $input, $output); } catch (Exception $e) { } } } }
/** * @param $output * @param boolean $dev * @return boolean */ protected function checkForCoreUpgrades($output, $dev = false) { $branches = $this->getCoreBranches(); $master = $branches['master']; $upgrade = false; $new = version_compare($master['version'], wire('config')->version); if ($new > 0 && $dev === false) { // master is newer than current $branch = $master; $upgrade = true; } else { if ($new <= 0 || $new > 0 && $dev === true) { // we will assume dev branch $dev = $branches['dev']; $new = version_compare($dev['version'], wire('config')->version); $branch = $dev; if ($new > 0) { $upgrade = true; } } } $versionStr = "{$branch['name']} {$branch['version']}"; if ($upgrade) { $output->writeln("<info>A ProcessWire core upgrade is available: {$versionStr}</info>"); } else { $output->writeln("<info>Your ProcessWire core is up-to-date: {$versionStr}</info>"); } return array('upgrade' => $upgrade, 'branch' => $branch); }
/** * Output an RSS feed of recent comments when URL segment is 'rss' * */ function renderCommentsRSS($limit) { // selector to locate the comments we want $start = 0; $selector = "limit={$limit}, start={$start}, sort=-created, status>=" . Comment::statusApproved; // find the comments we want to output $comments = findComments($selector); $commentPages = new PageArray(); foreach ($comments as $comment) { $p = wire('pages')->get($comment->pages_id); if (!$p->id) { continue; } $p = clone $p; $p->comment_title = htmlentities($comment->cite, ENT_QUOTES, "UTF-8") . " reply to: " . $p->title; $p->comment_body = htmlentities($comment->text, ENT_QUOTES, "UTF-8"); $p->comment_date = $comment->created; $commentPages->add($p); } $rss = wire('modules')->get('MarkupRSS'); $rss->title = wire('pages')->get('/')->headline . ' - ' . wire('page')->get('headline|title'); $rss->itemTitleField = 'comment_title'; $rss->itemDescriptionField = 'comment_body'; $rss->itemDescriptionLength = 0; $rss->itemDateField = 'comment_date'; $rss->render($commentPages); }
public function set($key, $value) { if ($key == 'lat' || $key == 'lng') { // if value isn't numeric, then it's not valid: make it blank if (strpos($value, ',') !== false) { $value = str_replace(',', '.', $value); } // convert 123,456 to 123.456 if (!is_numeric($value)) { $value = ''; } } else { if ($key == 'address') { $value = wire('sanitizer')->text($value); } else { if ($key == 'status') { $value = (int) $value; if (!isset($this->geocodeStatuses[$value])) { $value = -1; } // -1 = unknown } else { if ($key == 'zoom') { $value = (int) $value; } } } } return parent::set($key, $value); }
/** * @param $field * @param $output * @return bool */ private function checkIfFieldExists($field, $output) { if (!wire("fields")->get("{$field}")) { $output->writeln("<error>Field '{$field}' does not exist!</error>"); return false; } }
function __construct() { $userFields = wire('templates')->get('user')->fields; $userFieldsArray = []; $userFieldsArray['name'] = 'name'; foreach ($userFields as $field) { if (!in_array($field->name, ['pass', 'roles', 'language'])) { $userFieldsArray[$field->id] = $field->name; } } $this->add(array(array('name' => 'fieldname', 'label' => __('Validation field'), 'required' => true, 'type' => 'Select', 'options' => $userFieldsArray, 'description' => __('The field to match user registration against.')))); if (class_exists("LanguageSupport", false)) { foreach ($this->languages as $language) { $this->add(array(array('name' => 'instructions' . $language->id, 'label' => __('Instructions') . " ({$language->name})", 'description' => __('Optional text displayed under the reset form validation field.'), 'type' => 'CKEditor'))); } } else { $this->add(array(array('name' => 'instructions', 'label' => __('Instructions'), 'type' => 'CKEditor', 'description' => __('Optional text displayed under the reset form validation field.')))); } $this->add(array(array('name' => 'emailAddress', 'label' => __('Email address to send reset link from'), 'required' => true, 'type' => 'Text', 'value' => '*****@*****.**'), array('name' => 'emailName', 'label' => __('Name to use for the email address'), 'type' => 'Text', 'value' => 'Passwords service'), array('name' => 'passwordLength', 'label' => __('Required password length'), 'required' => true, 'type' => 'Integer', 'value' => 8))); if (class_exists("LanguageSupport", false)) { foreach ($this->languages as $language) { $this->add(array(array('name' => 'passwordInstructions' . $language->id, 'label' => __('Password instructions') . " ({$language->name})", 'description' => __('Optional (but strongly recommended) instructions displayed under the password input field.'), 'type' => 'CKEditor'))); } } else { $this->add(array(array('name' => 'passwordInstructions', 'label' => __('Password instructions'), 'description' => __('Optional (but strongly recommended) instructions displayed under the password input field.'), 'type' => 'CKEditor'))); } }
/** * Given a group of pages render a tree of navigation * * @param Page|PageArray $items Page to start the navigation tree from or pages to render * @param int $maxDepth How many levels of navigation below current should it go? * */ function renderNavTree($items, $maxDepth = 3) { // if we've been given just one item, convert it to an array of items if ($items instanceof Page) { $items = array($items); } // if there aren't any items to output, exit now if (!count($items)) { return; } // $out is where we store the markup we are creating in this function // start our <ul> markup echo "<ul class='nav nav-tree'>"; // cycle through all the items foreach ($items as $item) { // markup for the list item... // if current item is the same as the page being viewed, add a "current" class to it if ($item->id == wire('page')->id) { echo "<li class='current'>"; } else { echo "<li>"; } // markup for the link echo "<a href='{$item->url}'>{$item->title}</a>"; // if the item has children and we're allowed to output tree navigation (maxDepth) // then call this same function again for the item's children if ($item->hasChildren() && $maxDepth) { renderNavTree($item->children, $maxDepth - 1); } // close the list item echo "</li>"; } // end our <ul> markup echo "</ul>"; }
function gate($w) { global $gates; if (is_numeric($gates[$w])) { return $gates[$w]; } if (strpos($gates[$w], ' ') === false) { return wire($gates[$w]); } if (preg_match("#NOT ([\\d\\w]+)#", $gates[$w], $matches1)) { return is_numeric($matches1[1]) ? ~(int) $matches1[1] & 65535 : ~(int) wire($matches1[1]) & 65535; } if (preg_match("#([\\d\\w]+) (AND|OR|LSHIFT|RSHIFT) ([\\d\\w]+)#", $gates[$w], $matches3)) { $a = is_numeric($matches3[1]) ? $matches3[1] : wire($matches3[1]); $b = is_numeric($matches3[3]) ? $matches3[3] : wire($matches3[3]); switch ($matches3[2]) { case 'AND': return $a & $b & 65535; case 'OR': return $a | $b & 65535; case 'LSHIFT': return $a << $b & 65535; case 'RSHIFT': return $a >> $b & 65535; } } }
/** * Construct the translator and set the current language * */ public function __construct(Language $currentLanguage) { $this->setCurrentLanguage($currentLanguage); $this->rootPath = wire('config')->paths->root; $file = __FILE__; $pos = strpos($file, '/wire/modules/LanguageSupport/'); $this->rootPath2 = $pos ? substr($file, 0, $pos + 1) : ''; }
/** * Render a list of categories, optionally showing a few posts from each * * @param PageArray $categories * @param int Number of posts to show from each category (default=0) * @return string * */ function renderCategories(PageArray $categories, $showNumPosts = 0) { foreach ($categories as $category) { $category->posts = wire('pages')->find("template=post, categories={$category}, limit={$showNumPosts}, sort=-date"); } $t = new TemplateFile(wire('config')->paths->templates . 'markup/categories.php'); $t->set('categories', $categories); return $t->render(); }
/** * Render a list of tags * * As seen on: /tags/ * * @param PageArray $tags * @return string * */ function renderTags(PageArray $tags) { foreach ($tags as $tag) { $tag->numPosts = wire('pages')->count("template=post, tags={$tag}"); } $t = new TemplateFile(wire('config')->paths->templates . 'markup/tags.php'); $t->set('tags', $tags); return $t->render(); }
/** * get users * * @param InputInterface $input */ private function getUsers($input) { $role = $input->getOption('role'); if (!empty($role)) { $users = wire('users')->find('roles=' . $input->getOption('role'))->sort('name'); } else { $users = wire('users')->find('start=0')->sort('name'); } return $users; }
/** * Handles dynamic loading of classes as registered with spl_autoload_register * */ function ProcessWireClassLoader($className) { $file = PROCESSWIRE_CORE_PATH . "{$className}.php"; if (is_file($file)) { require $file; } else { if ($modules = wire('modules')) { $modules->includeModule($className); } } }
/** * check if a module already exists * * @param string $module * @return boolean */ public function checkIfModuleExists($module) { $moduleDir = wire('config')->paths->siteModules . $module; if (wire("modules")->get("{$module}")) { $return = true; } if (is_dir($moduleDir) && !$this->isEmptyDirectory($moduleDir)) { $return = true; } return isset($return) ? $return : false; }
private function checkIfModuleExists($module, $output, $remove) { if (!is_dir(wire('config')->paths->siteModules . $module)) { $output->writeln("<error>Module '{$module}' does not exist!</error>"); exit(1); } if (!wire('modules')->getModule($module, array('noPermissionCheck' => true)) && $remove === false) { $output->writeln("<info>Module '{$module}' is not installed!</info>"); exit(1); } }
/** * Make a basic data table with linked skyscraper stats * */ function renderSkyscraperData($page) { $searchUrl = wire('config')->urls->root . "search/"; $na = "<span class='na'>n/a</span>"; $architects = ''; foreach ($page->architects as $a) { $architects .= "\n\t<li><a href='{$a->url}'>{$a->title}</a></li>"; } $out = "\n<table class='skyscraper_data'>" . "\n\t<tbody>" . "\n\t<tr><th>Height</th><td>" . ($page->height ? "<a href='{$searchUrl}?height={$page->height}'>{$page->height} feet</a>" : $na) . "</td></tr>" . "\n\t<tr><th>Floors</th><td>" . ($page->floors ? "<a href='{$searchUrl}?floors={$page->floors}'>{$page->floors}</a>" : $na) . "</td></tr>" . "\n\t<tr><th>Year</th><td>" . ($page->year ? "<a href='{$searchUrl}?year={$page->year}'>{$page->year}</a>" : $na) . "</td></tr>" . "\n\t<tr><th>Architects</th><td>" . ($architects ? "\n<ul>{$architects}</ul>" : $na) . "</td></tr>" . "\n\t</tbody>" . "\n</table>"; return $out; }
/** * Render an author list * * @param PageArray $authors * @return string * */ function renderAuthors(PageArray $authors) { $out = "<ul class='authors posts-group'>"; foreach ($authors as $author) { $numPosts = wire('pages')->count("template=post, created_users_id={$author}, limit=2"); $numPostsStr = sprintf(_n('%d post', '%d posts', $author->numPosts), $author->numPosts); // Note: $author->url2 is the blog-generated version, since $author->url is in the admin. $out .= "<li><a href='{$author->url2}'>" . $author->get('title|name') . "</a> <span class='num-posts'>{$numPosts}</span></li>"; } $out .= "</ul>"; return $out; }
/** * get templates data * * @param boolean $advanced * @return array */ private function getTemplateData($advanced) { $content = array(); $advanced = wire('config')->advanced || $advanced; foreach (wire('templates') as $t) { if (!$advanced && $t->flags & \Template::flagSystem) { continue; } $content[] = array($t->name, count($t->fieldgroup), $t->getNumPages(), wireRelativeTimeStr($t->modified), $t->flags & \Template::flagSystem ? '✖' : ''); } return $content; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $name = $input->getArgument('name'); if (!wire("pages")->get("name={$name}") instanceof \NullPage) { $output->writeln("<error>Role '{$name}' already exists!</error>"); exit(1); } $user = $this->createRole($name, $this->roleContainer); $user->save(); $output->writeln("<info>Role '{$name}' created successfully!</info>"); }
/** * Render archives returned by the getArchives() function * * Archives links include a year headline followed by a list of months in that year with posts, * and the number of posts in each month. * * @param array $years as returned by the getArchives() function * @return string * */ function renderArchives(array $years) { $out = ''; foreach ($years as $year) { $t = new TemplateFile(wire('config')->paths->templates . 'markup/archives.php'); $t->set('year', $year['name']); $t->set('total', $year['total']); $t->set('months', $year['months']); $t->set('url', $year['url']); $out .= $t->render(); } return $out; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $users = explode(',', $input->getArgument('name')); foreach ($users as $name) { if (wire('users')->get($name) instanceof \NullPage) { $output->writeln("<error>User '{$name}' doesn't exists!</error>"); } else { $user = wire('users')->get($name); wire('users')->delete($user); $output->writeln("<info>User '{$name}' deleted successfully!</info>"); } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $name = $input->getArgument('name'); $label = $input->getOption('label') !== "" ? $input->getOption('label') : $name; $type = $this->getProperFieldtypeName($input->getOption('type')); $field = new Field(); $field->type = wire('modules')->get($type); $field->name = $name; $field->label = $label; $field->description = $input->getOption('desc'); $field->save(); $output->writeln("<info>Field '{$name}' ({$type}) created successfully!</info>"); }
function renderSitemapXML(array $paths = array()) { array_unshift($paths, '/'); // prepend homepage foreach ($paths as $path) { $page = wire('pages')->get($path); if (!$page->id) { continue; } $out .= renderSitemapPage($page); if ($page->numChildren) { $out .= renderSitemapChildren($page); } } return $out; }
function __construct($form) { if (get_class($form) == 'InputfieldForm') { $this->form = $form; } else { throw new TypeException('The first parameter of the form must be a Processwire:InputfieldForm'); } $this->mailAdmin = wireMail(); $this->mailSubmitter = wireMail(); $this->config = wire('config'); $this->input = wire('input'); $this->page = wire('page'); $this->pages = wire('pages'); $this->sanitizer = wire('sanitizer'); $this->session = wire('session'); $this->submit_name = $this->submit_field_name(); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $name = $input->getArgument('name'); $roles = explode(",", $input->getOption('roles')); $pass = $input->getOption('password'); if (wire("pages")->get("name={$name}") instanceof \NullPage) { $output->writeln("<error>User '{$name}' doesn't exists!</error>"); exit(1); } $user = $this->updateUser($input, $name, $pass); $user->save(); if ($input->getOption('roles')) { $this->attachRolesToUser($name, $roles, $output, true); } $output->writeln("<info>User '{$name}' updated successfully!</info>"); }