public function render_inputs($details = array()) { if (!class_exists('PerchGallery_Albums')) { require_once PerchUtil::file_path(PERCH_PATH . '/addons/apps/perch_gallery/PerchGallery_Albums.class.php'); require_once PerchUtil::file_path(PERCH_PATH . '/addons/apps/perch_gallery/PerchGallery_Album.class.php'); } $id = $this->Tag->input_id(); $val = ''; if (isset($details[$id]) && $details[$id] != '') { $json = $details[$id]; $val = $json['albumSlug']; } $API = new PerchAPI(1, 'perch_gallery'); $Albums = new PerchGallery_Albums($API); $albums = $Albums->return_all(); $opts = array(); $opts[] = array('label' => '', 'value' => ''); if (PerchUtil::count($albums)) { foreach ($albums as $Album) { $opts[] = array('label' => $Album->albumTitle(), 'value' => $Album->albumSlug()); } } if (PerchUtil::count($opts)) { $s = $this->Form->select($id, $opts, $val); } else { $s = '-'; } return $s; }
public function write_file($file, $name) { $filename = PerchUtil::tidy_file_name($name); if (strpos($filename, '.php') !== false) { $filename .= '.txt'; } // diffuse PHP files if (strpos($filename, '.phtml') !== false) { $filename .= '.txt'; } // diffuse PHP files $target = PerchUtil::file_path($this->file_path . '/' . $filename); if (file_exists($target)) { $dot = strrpos($filename, '.'); $filename_a = substr($filename, 0, $dot); $filename_b = substr($filename, $dot); $count = 1; while (file_exists(PerchUtil::file_path($this->file_path . '/' . PerchUtil::tidy_file_name($filename_a . '-' . $count . $filename_b)))) { $count++; } $filename = PerchUtil::tidy_file_name($filename_a . '-' . $count . $filename_b); $target = PerchUtil::file_path($this->file_path . '/' . $filename); } PerchUtil::move_uploaded_file($file, $target); return array('name' => $filename, 'path' => $target); }
public function set($file, $namespace, $default_fields = false) { $Perch = Perch::fetch(); // called to make sure constants are defined. if ($file && substr($file, -5) !== '.html') { $file .= '.html'; } $this->namespace = $namespace; if (strpos($file, '~') !== false) { $local_file = PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . substr($file, strpos($file, '~') + 1)); $user_file = PerchUtil::file_path(PERCH_TEMPLATE_PATH . substr($file, strpos($file, 'templates') + 9)); } else { $local_file = PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . $this->app_id . '/templates/' . $file); $user_file = PerchUtil::file_path(PERCH_TEMPLATE_PATH . '/' . $file); } if (file_exists($user_file)) { $template_file = $user_file; } else { $template_file = $local_file; } $this->Template = new PerchTemplate($template_file, $namespace, $relative_path = false); $this->Template->enable_encoding(); $this->Template->apply_post_processing = true; if ($default_fields) { $this->Template->append($default_fields); } $this->file = $this->Template->file; return $this->Template->status; }
private function _compile_stylesheet($file) { PerchUtil::debug('Compiling SASS file: ' . $file, 'notice'); if (!$this->_site_path) { $login_path_parts = explode('/', PERCH_LOGINPATH); $path_parts = explode(DIRECTORY_SEPARATOR, PERCH_PATH); foreach ($login_path_parts as $part) { if ($part != '') { array_pop($path_parts); } } $path = implode(DIRECTORY_SEPARATOR, $path_parts); $this->_site_path = $path; } $compiled_name = PerchUtil::file_path(PERCH_RESFILEPATH . '/' . $this->_get_compiled_name($file)); include_once 'SassParser.php'; $syntax = substr($file, -4, 4); $options = array('style' => 'expanded', 'cache' => FALSE, 'syntax' => $syntax, 'debug' => FALSE, 'callbacks' => array('warn' => 'warn', 'debug' => 'debug')); // Execute the compiler. $parser = new SassParser($options); try { file_put_contents($compiled_name, $parser->toCss(PerchUtil::file_path($this->_site_path . $file))); } catch (Exception $e) { PerchUtil::debug($e->getMessage(), 'error'); } }
function __construct($file = false, $namespace = 'content', $relative_path = true) { $Perch = Perch::fetch(); // required to define constants if ($file && substr($file, -5) !== '.html') { $file .= '.html'; } $this->current_file = $file; $this->namespace = $namespace; if ($file && $relative_path) { $file = PerchUtil::file_path(PERCH_TEMPLATE_PATH . '/' . $file); } if ($file != false && file_exists($file)) { $this->file = $file; $this->template = $file; PerchUtil::debug('Using template: ' . str_replace(PERCH_PATH, '', $file), 'template'); $this->status = 200; $this->file_path = pathinfo($file, PATHINFO_DIRNAME); } else { if ($file != false) { PerchUtil::debug('Template file not found: ' . $file, 'template-error'); } $this->status = 404; } // Mock up fallback functions if server doesn't have mbstring $this->mb_fallback(); }
public function set_template($template) { $this->template = $template; $type = PerchUtil::file_extension($template); if (!$type) { $type = 'txt'; $template .= '.txt'; $this->html = false; } else { if ($type == 'html') { $this->html = true; } } if (isset($this->app_id)) { $local_file = PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . $this->app_id . '/templates/' . $template); } else { $local_file = false; } $user_file = PerchUtil::file_path(PERCH_TEMPLATE_PATH . '/' . $template); $core_file = PerchUtil::file_path(PERCH_CORE . '/emails/' . $template); if (file_exists($user_file)) { $this->template_path = $user_file; } elseif (file_exists($local_file)) { $this->template_path = $local_file; } else { $this->template_path = $core_file; } PerchUtil::debug('Using email template: ' . $this->template_path . ' (' . $type . ')', 'template'); }
/** * Return a list of icon files as an array * * @return array */ public function icons() { $return = array(); foreach ($this->iconMap as $event => $filename) { $return[$event] = PerchUtil::file_path($this->api->app_path() . '/' . $this->icon_dir . '/' . $filename . $this->icon_ext); } return $return; }
/** * Delete the template, along with its file * @return nothing */ public function delete() { $file = PerchUtil::file_path(PERCH_TEMPLATE_PATH . '/pages/' . $this->templatePath()); if (!PERCH_RUNWAY && file_exists($file)) { unlink($file); } parent::delete(); }
public static function expire_all() { $files = glob(PerchUtil::file_path(PERCH_RESFILEPATH . '/perch_blog.*.cache')); if (PerchUtil::count($files)) { foreach ($files as $filename) { unlink($filename); } } }
public static function load_bucket_list() { $bucket_list_file = PerchUtil::file_path(PERCH_PATH . '/config/buckets.php'); if (file_exists($bucket_list_file)) { self::$bucket_list = (include $bucket_list_file); if (self::$bucket_list == false) { self::$bucket_list = array(); } } else { self::$bucket_list = array(); } }
public function delete() { if ($this->clean_resources && !$this->resourceInLibrary()) { $Perch = Perch::fetch(); $bucket = $Perch->get_resource_bucket($this->resourceBucket()); $file_path = PerchUtil::file_path($bucket['file_path'] . '/' . $this->resourceFile()); if (file_exists($file_path) && !is_dir($file_path)) { unlink($file_path); PerchUtil::debug('Deleting resource: ' . $file_path); } } return parent::delete(); }
public function attempt_install() { PerchUtil::debug('Attempting app installation: ' . $this->api->app_id); $sql = 'SHOW TABLES LIKE "' . $this->table . '"'; $result = $this->db->get_value($sql); if ($result == false) { $activation_file = PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . $this->api->app_id . '/activate.php'); if (file_exists($activation_file)) { $API = $this->api; return include $activation_file; } } return false; }
public function set_template($template, $namespace = 'email') { $this->template = $template; $this->template_ns = $namespace; $type = PerchUtil::file_extension($template); if (!$type) { $type = 'txt'; $template .= '.txt'; $this->html = false; } else { if ($type == 'html') { $this->html = true; } } if (isset($this->app_id)) { $local_file = PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . $this->app_id . '/templates/' . $template); } else { $local_file = false; } $user_file = PerchUtil::file_path(PERCH_TEMPLATE_PATH . '/' . $template); $core_file = PerchUtil::file_path(PERCH_CORE . '/emails/' . $template); if (file_exists($user_file)) { $this->template_path = $user_file; } elseif (file_exists($local_file)) { $this->template_path = $local_file; } else { $this->template_path = $core_file; } PerchUtil::debug('Using email template: ' . $this->template_path . ' (' . $type . ')', 'template'); // detect type if (file_exists($this->template_path)) { $template_contents = file_get_contents($this->template_path); } else { $template_contents = ''; } if (strpos($template_contents, '<perch:') !== false) { $this->template_method('perch'); } else { $this->template_method('dollar'); } }
public function get_available_buckets() { $sql = 'SELECT DISTINCT resourceBucket FROM ' . $this->table . ' WHERE resourceAWOL=0 AND resourceType !="" ORDER BY resourceType ASC'; $list = $this->db->get_rows_flat($sql); if (!$list) { $list = array(); } $bucket_list_file = PerchUtil::file_path(PERCH_PATH . '/config/buckets.php'); if (file_exists($bucket_list_file)) { $bucket_list = (include $bucket_list_file); if (PerchUtil::count($bucket_list)) { foreach ($bucket_list as $key => $val) { if (!in_array($key, $list)) { $list[] = $key; } } } } return $list; }
/** * Load files from translation directory and converts to dot notation * * @return Data */ private function load_translation_files() { $base_path = PerchUtil::file_path(PERCH_PATH . '/' . $this->translation_dir); $dir_iterator = new RecursiveDirectoryIterator($base_path, FilesystemIterator::SKIP_DOTS); $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::CHILD_FIRST); $files = array(); foreach ($iterator as $fileinfo) { if ($fileinfo->getExtension() == 'php') { $file_path = PerchUtil::file_path($fileinfo->getPathname()); if ($fileinfo->isDir()) { $path = array($fileinfo->getFilename() => array()); } else { $path = array(PerchUtil::strip_file_extension($fileinfo->getFilename()) => $this->load_translation_data($file_path)); } for ($depth = $iterator->getDepth() - 1; $depth >= 0; $depth--) { $path = array($iterator->getSubIterator($depth)->current()->getFilename() => $path); } $files = array_merge_recursive($files, $path); } } return new Data($files); }
$validation = array(); $validation['userPassword'] = array("password", "Your passwords must match"); $Form->set_validation($validation); if ($Form->posted() && $Form->validate()) { $postvars = array('userGivenName', 'userFamilyName', 'userEmail', 'userUsername', 'userPassword'); $user = $Form->receive($postvars); PerchSession::set('user', $user); $postvars = array('loginpath', 'db_server', 'db_database', 'db_username', 'db_password', 'licenseKey', 'tz'); $conf = $Form->receive($postvars); if (!isset($conf['db_password'])) { $conf['db_password'] = ''; } $conf['loginpath'] = rtrim($conf['loginpath'], '/'); $config_file = file_get_contents('config.sample.php'); $config_file = preg_replace_callback('/\\$(\\w+)/', "substitute_vars", $config_file); $config_file_path = PerchUtil::file_path(realpath('../config') . '/config.php'); if (is_writable($config_file_path)) { file_put_contents($config_file_path, $config_file); $test_contents = file_get_contents($config_file_path); if ($test_contents == $config_file) { PerchUtil::redirect('index.php?install=1&auto=1'); } } $mode = 'configfile'; } function substitute_vars($matches) { global $user, $conf; if (isset($user[$matches[1]])) { return addslashes($user[$matches[1]]); }
public function get_resource_bucket($bucket_name = 'default') { $bucket = array(); // hardwire default, most common case $bucket['name'] = 'default'; $bucket['type'] = 'file'; $bucket['web_path'] = PERCH_RESPATH; $bucket['file_path'] = PERCH_RESFILEPATH; if ($bucket_name && trim($bucket_name) != '' && $bucket_name != 'default') { // try buckets file if ($this->bucket_list === false) { $bucket_list_file = PerchUtil::file_path(PERCH_PATH . '/config/buckets.php'); if (file_exists($bucket_list_file)) { $this->bucket_list = (include $bucket_list_file); if ($this->bucket_list == false) { $this->bucket_list = array(); } } else { $this->bucket_list = array(); } } if (PerchUtil::count($this->bucket_list) && isset($this->bucket_list[$bucket_name])) { $bucket = $this->bucket_list[$bucket_name]; $bucket['name'] = $bucket_name; return $bucket; } // not defined, so treat as a subfolder of resources $bucket['name'] = $bucket_name; $bucket['web_path'] .= '/' . $bucket_name; $bucket['file_path'] = PerchUtil::file_path($bucket['file_path'] . '/' . $bucket_name); } return $bucket; }
public function encrypt_new_password($memberID, $old_clear_pwd, $new_clear_pwd) { $sql = 'SELECT * FROM ' . $this->table . ' WHERE memberID=' . $this->db->pdb($memberID); $row = $this->db->get_row($sql); if (PerchUtil::count($row)) { $authenticator = $row['memberAuthType']; $class = 'PerchMembers_Authenticator_' . $authenticator; $user_path = realpath(PerchUtil::file_path($this->authenticator_path . $authenticator)); if (substr($user_path, 0, strlen($this->authenticator_path)) == $this->authenticator_path) { $path = PerchUtil::file_path($this->authenticator_path . $authenticator . '/' . $class . '.class.php'); if (file_exists($path)) { include $path; $Authenticator = new $class($this->api); if (is_object($Authenticator)) { return $Authenticator->encrypt_new_password($row, $old_clear_pwd, $new_clear_pwd); } else { PerchUtil::debug('Failed to create authenticator object', 'error'); } } else { PerchUtil::debug('Authenticator file does not exist: ' . $path, 'error'); } } else { PerchUtil::debug('Bad authenticator path', 'error'); } } return false; }
$filename = PerchUtil::tidy_file_name($file); if (strpos($filename, '.php') !== false) { $filename .= '.txt'; } //checking for naughty uploading of php files. $target = PerchUtil::file_path($targetDir . '/' . $filename); if (file_exists($target)) { $ext = strrpos($filename, '.'); $fileName_a = substr($filename, 0, $ext); $fileName_b = substr($filename, $ext); $count = 1; while (file_exists(PerchUtil::file_path($targetDir . '/' . $fileName_a . '_' . $count . $fileName_b))) { $count++; } $filename = $fileName_a . '_' . $count . $fileName_b; $target = PerchUtil::file_path($targetDir . '/' . $filename); } } PerchUtil::move_uploaded_file($_FILES['upload']['tmp_name'], $target); $Image->update(array('imageStatus' => 'uploading')); if (is_object($Image)) { $Image->process_versions($filename, $Template, $bucket); } $Image->update(array('imageStatus' => 'active')); $Album = $GalleryAlbums->find($albumID); if (is_object($Album)) { $Album->update_image_count(); } } if ($new_image) { PerchUtil::redirect($API->app_path() . '/images/edit/?album_id=' . $albumID . '&id=' . $result->id() . '&created=1');
public function move_file($new_location) { $new_location = PerchUtil::file_path($new_location); $new_location = str_replace(PERCH_LOGINPATH, '/', $new_location); $new_location = str_replace('\\', '/', $new_location); $new_location = str_replace('..', '', $new_location); $new_location = str_replace('//', '/', $new_location); $old_path = PERCH_SITEPATH . $this->pagePath(); $new_path = PerchUtil::file_path(PERCH_SITEPATH . '/' . ltrim($new_location, '/')); if ($old_path != $new_path) { if (file_exists($old_path)) { if (!file_exists($new_path)) { $new_dir = PerchUtil::strip_file_name($new_path); if (!file_exists($new_dir)) { mkdir($new_dir, 0755, true); } if (is_writable($new_dir)) { if (rename($old_path, $new_path)) { // Is it a reference to a master page? If so, update the include $contents = file_get_contents($new_path); $pattern = '#' . preg_quote("<?php include(str_replace('/', DIRECTORY_SEPARATOR, 'XXX')); ?>") . '#'; $pattern = str_replace('XXX', '([a-zA-Z/\\.-]+)', $pattern); if (preg_match($pattern, $contents, $match)) { $current_path = $match[1]; $template_dir = PERCH_TEMPLATE_PATH . '/pages'; $template_path = str_replace(PERCH_SITEPATH . DIRECTORY_SEPARATOR, '', PERCH_TEMPLATE_PATH) . '/pages/'; // normalise $current_path = str_replace(DIRECTORY_SEPARATOR, '/', $current_path); $template_dir = str_replace(DIRECTORY_SEPARATOR, '/', $template_dir); $template_path = str_replace(DIRECTORY_SEPARATOR, '/', $template_path); $parts = explode($template_path, $current_path); if (PerchUtil::count($parts)) { $master_page_template = $parts[1]; $Pages = new PerchContent_Pages(); $a = PerchUtil::file_path($template_dir . '/' . $master_page_template); $b = PerchUtil::file_path(dirname($new_path)); $new_include_path = $Pages->get_relative_path($a, $b); $new_include = '<' . '?php include(str_replace(\'/\', DIRECTORY_SEPARATOR, \'' . $new_include_path . '\')); ?' . '>'; /* $new_include .= '<' . '?php /* '.PHP_EOL; $new_include .= 'Current path: '.$current_path.PHP_EOL; $new_include .= 'Template dir: '.$template_dir.PHP_EOL; $new_include .= 'Template path: '.$template_path.PHP_EOL; $new_include .= 'Master page template: '.$master_page_template.PHP_EOL; $new_include .= 'A: '.$a.PHP_EOL; $new_include .= 'B: '.$b.PHP_EOL; $new_include .= 'New include path: '.$new_include_path.PHP_EOL; $new_include .= 'Parts: '.print_r($parts, true).PHP_EOL; $new_include .= PHP_EOL.' *'.'/ ?' . '>'; */ file_put_contents($new_path, str_replace($match[0], $new_include, $contents)); } } else { // Else just update the Perch runtime. $pattern = '#' . preg_quote("include(__Y____X__" . trim(PERCH_LOGINPATH, '/') . "__DS__runtime.php__Y__);") . '#'; $pattern = str_replace('__X__', '([a-zA-Z/\\.-]*)', $pattern); $pattern = str_replace('__Y__', '[\'\\"]', $pattern); $pattern = str_replace('__DS__', '[\\\\/]', $pattern); if (preg_match($pattern, $contents, $match)) { PerchUtil::debug($match); $Pages = new PerchContent_Pages(); $a = PerchUtil::file_path(PERCH_PATH . '/runtime.php'); $b = PerchUtil::file_path(dirname($new_path)); $new_include_path = $Pages->get_relative_path($a, $b); PerchUtil::debug('New include path: ' . $new_include_path); $new_include = "include('{$new_include_path}');"; file_put_contents($new_path, str_replace($match[0], $new_include, $contents)); } } return array(true, false); } else { return array(false, 'The page could not be moved.'); } } else { return array(false, 'The destination folder could not be written to, so the page cannot be moved.'); } } else { return array(false, 'A page file already exists at the new location.'); } } else { return array(false, 'No page file exists at that location to move.'); } } else { // It's ok, as the file is already where they want it to be. return array(true, false); } }
/** * Take the original uploaded file and make all the different versions, based on the given template. * * @param string $filename * @param string $Template * @return void * @author Drew McLellan */ public function process_versions($filename, $Template, $bucket) { $this->delete_versions(); $result = false; $image_file = PerchUtil::file_path($bucket['file_path'] . '/' . $filename); PerchUtil::debug('123: ' . $image_file); if (!file_exists($image_file)) { return false; } $API = new PerchAPI(1.0, 'perch_gallery'); $Image = $API->get('Image'); $Versions = new PerchGallery_ImageVersions(); $tags = $Template->find_all_tags(); $Perch = Perch::fetch(); if (!is_array($tags)) { $tags = array(); } // add defaults we need for admin $tags[] = new PerchXMLTag('<perch:gallery id="image" type="image" />'); // default full size $tags[] = new PerchXMLTag('<perch:gallery id="image" type="image" width="80" height="80" crop="true" key="admin_thumb" />'); // admin thumb $tags[] = new PerchXMLTag('<perch:gallery id="image" type="image" width="180" key="admin_preview" />'); // admin preview if (PerchUtil::count($tags)) { foreach ($tags as $Tag) { if ($Tag->id() == 'image' && $Tag->type() == 'image') { //$bucket = $Perch->get_resource_bucket($Tag->bucket()); $Image->reset_defaults(); if ($Tag->quality()) { $Image->set_quality($Tag->quality()); } if ($Tag->sharpen()) { $Image->set_sharpening($Tag->sharpen()); } if ($Tag->density()) { $Image->set_density($Tag->density()); } if ($Tag->width() || $Tag->height()) { $details = $Image->resize_image($image_file, $Tag->width(), $Tag->height(), $Tag->crop()); } else { $details = array(); $details['file_name'] = $filename; PerchUtil::debug('152: ' . $filename); $info = getimagesize($image_file); if (is_array($info)) { $details['w'] = $info[0]; $details['h'] = $info[1]; } } if ($details) { $data = array(); $data['imageID'] = $this->id(); if (strpos($details['file_name'], DIRECTORY_SEPARATOR) !== false) { $parts = explode(DIRECTORY_SEPARATOR, $details['file_name']); $details['file_name'] = array_pop($parts); } $data['versionPath'] = $details['file_name']; //PerchUtil::debug('167: '. $details['file_name']); if ($Tag->key()) { $data['versionKey'] = $Tag->key(); } else { $data['versionKey'] = $this->_generate_version_key($Tag->width(), $Tag->height()); } if ($Tag->crop()) { $data['versionWidth'] = $Tag->width(); $data['versionHeight'] = $Tag->height(); } else { $data['versionWidth'] = $details['w']; $data['versionHeight'] = $details['h']; } $Version = $Versions->create($data); if (is_object($Version)) { $result = true; } } } } } return $result; }
private function load_translations() { $out = false; if (file_exists($this->lang_file)) { $json = file_get_contents($this->lang_file); $out = PerchUtil::json_safe_decode($json, true); } if (is_array($out)) { $this->translations = $out; } else { $json = file_get_contents(PerchUtil::file_path(PERCH_CORE . '/lang/en-gb.txt')); $this->translations = PerchUtil::json_safe_decode($json, true); PerchUtil::debug('Unable to load language file: ' . $this->lang, 'error'); } }
$apps = $ScheduledTasks->get_scheduled(); if (PerchUtil::count($apps)) { foreach ($apps as $appID => $tasks) { $task_list = array(); echo '<li>Scheduled tasks for ' . $appID . ': '; foreach ($tasks as $task) { //print_r($task); $task_list[] = $task['taskKey'] . ' (' . $task['frequency'] / 60 . ' mins)'; } echo implode(', ', $task_list); echo '</li>'; } } ?> <?php echo '<li>Editor plug-ins: ' . implode(', ', PerchUtil::get_dir_contents(PerchUtil::file_path(PERCH_PATH . '/addons/plugins/editors/', true))) . '</li>'; ?> <li>H1: <?php echo PerchUtil::html(md5($_SERVER['SERVER_NAME'])); ?> </li> <li>L1: <?php echo PerchUtil::html(md5(PERCH_LICENSE_KEY)); ?> </li> <?php $settings = $Settings->get_as_array(); if (PerchUtil::count($settings)) { foreach ($settings as $key => $val) { echo '<li>' . PerchUtil::html($key . ': ' . $val) . '</li>';
</head> <body class="sidebar-closed"> <div class="main"> <div class="body"> <div class="inner"> <h1>Software Update</h1> <ul class="updates"> <?php $files = PerchUtil::get_dir_contents('scripts', false); $DB = PerchDB::fetch(); if (PerchUtil::count($files)) { foreach ($files as $file) { if (PerchUtil::file_extension($file) == 'php') { include PerchUtil::file_path(PERCH_CORE . '/update/scripts/' . $file); } } } if (!$errors) { echo '<li class="icon success">Successfully updated to version ' . $Perch->version . '.</li>'; $Settings->set($setting_key, 'done'); } ?> </ul> <?php if (!$errors) { echo '<a href="' . PERCH_LOGINPATH . '" class="button">Continue</a>'; } else { echo '<p><a href="http://support.grabaperch.com/">Contact us</a> if you are unsure how to resolve these problems, or <a href="' . PERCH_LOGINPATH . '/core/update/?force=accept">accept these errors and continue</a>.</p>'; }
private function _get_template_content() { if ($this->templateContent === false) { $file = PerchUtil::file_path(PERCH_PATH . $this->templatePath); if (file_exists($file)) { $content = file_get_contents($file); // parse subtemplates $Template = new PerchTemplate(); $this->templateContent = $Template->load($content, true); } else { PerchUtil::debug('Template file not found: ' . $file, 'error'); } } return $this->templateContent; }
} if ($result) { $message = $HTML->success_message('Your post has been successfully updated. Return to %spost listing%s', '<a href="' . $API->app_path() . '">', '</a>'); } else { $message = $HTML->failure_message('Sorry, that post could not be updated.'); } $details = $Post->to_array(); // clear the caches PerchBlog_Cache::expire_all(); // update category post counts; $Posts->update_category_counts(); $Authors->update_post_counts(); $Sections->update_post_counts(); // Has the template changed? If so, need to redirect back to kick things off again. if ($data['postTemplate'] != $template) { #PerchUtil::redirect($API->app_path() .'/edit/?id='.$Post->id().'&edited=1'); } } if (isset($_GET['edited']) && !$message) { $message = $HTML->success_message('Your post has been successfully updated. Return to %spost listing%s', '<a href="' . $API->app_path() . '">', '</a>'); } // is it a draft? if (is_object($Post) && $Post->postStatus() == 'Draft') { $draft = true; $message = $Lang->get('%sYou are editing a draft. %sPreview%s', '<p class="alert draft">', '<a href="' . $HTML->encode($Post->previewURL()) . '" class="action draft-preview">', '</a></p>'); } else { $draft = false; $url = false; } $post_templates = PerchUtil::get_dir_contents(PerchUtil::file_path(PERCH_TEMPLATE_PATH . '/blog/posts'), false);
echo $HTML->heading2('Sending email'); echo $Form->hint('Requires a functioning mail server that can send mail from PHP.'); echo $Form->checkbox_field('email', 'Send response via email', '1', isset($settings['email']) ? $settings['email'] : ''); $opts = array('No template' => array(array('filename' => '', 'value' => '', 'path' => '', 'label' => $Lang->get('Plain text only')))); $templates = $Forms->get_templates(); $templates = $opts + $templates; echo $Form->grouped_select_field('adminEmailTemplate', 'Email Template', $templates, isset($settings['adminEmailTemplate']) ? $settings['adminEmailTemplate'] : ''); echo $Form->hint('Separate multiple addresses with commas.'); echo $Form->text_field('emailAddress', 'Email address(es)', isset($settings['emailAddress']) ? $settings['emailAddress'] : ''); echo $Form->text_field('adminEmailSubject', 'Email subject line', isset($settings['adminEmailSubject']) ? $settings['adminEmailSubject'] : ''); echo $Form->text_field('adminEmailFromName', 'Send from', isset($settings['adminEmailFromName']) ? $settings['adminEmailFromName'] : PERCH_EMAIL_FROM_NAME); echo $Form->text_field('adminEmailFromAddress', 'Send from address', isset($settings['adminEmailFromAddress']) ? $settings['adminEmailFromAddress'] : PERCH_EMAIL_FROM); $opts = array(); $opts[] = array('value' => '', 'label' => '-'); $Template = $API->get('Template'); $file = PerchUtil::file_path(PERCH_PATH . $ThisForm->formTemplate()); if (file_exists($file)) { $content = file_get_contents($file); $Template->set_from_string($content, 'input'); $tags = $Template->find_all_tags('input'); if (PerchUtil::count($tags)) { foreach ($tags as $Tag) { $opts[] = array('value' => $Tag->id(), 'label' => $Tag->id()); } } } echo $Form->hint('Choose a field to use as the value of the email ReplyTo header and for the autoreponse'); echo $Form->select_field('formEmailFieldID', 'Email address field', $opts, isset($settings['formEmailFieldID']) ? $settings['formEmailFieldID'] : ''); $Form->last = true; echo $Form->textarea_field('adminEmailMessage', 'Email introduction text', isset($settings['adminEmailMessage']) ? $settings['adminEmailMessage'] : '', 's', false); /* RESPONDING */
/** * Remove the file name from the end of a path and return the path * * @param string $path * @return void * @author Drew McLellan */ public static function strip_file_name($path) { $parts = explode(DIRECTORY_SEPARATOR, $path); array_pop($parts); return PerchUtil::file_path(implode('/', $parts)); }
private function _get_template_content() { if ($this->templateContent === false) { $content = file_get_contents(PerchUtil::file_path(PERCH_PATH . $this->templatePath)); // parse subtemplates $Template = new PerchTemplate(); $this->templateContent = $Template->load($content, true); } return $this->templateContent; }
private function register_app($app_id, $label, $priority = 10, $desc = '', $version = false, $hidden = false) { if (!in_array($app_id, $this->core_apps)) { $Lang = new PerchAPI_Lang(1, $app_id); $label = $Lang->get($label); $priority++; // make sure default apps go first } else { $label = PerchLang::get($label); } $app = array(); $app['id'] = $app_id; $app['version'] = $version; $app['label'] = $label; $app['path'] = PERCH_LOGINPATH . '/addons/apps/' . $app_id; $app['priority'] = $priority; $app['desc'] = $desc; $app['active'] = true; $app['dashboard'] = false; $app['section'] = 'addons/apps/' . $app_id; $app['hidden'] = $hidden; $dash = PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . $app_id . '/dashboard.php'); if (file_exists($dash)) { $app['dashboard'] = $dash; } // Default apps - special case if (in_array($app_id, $this->core_apps)) { $app['path'] = PERCH_LOGINPATH . '/core/apps/' . $app_id; $app['section'] = 'core/apps/' . $app_id; $dash = PerchUtil::file_path(PERCH_CORE . '/apps/' . $app_id . '/dashboard.php'); if (file_exists($dash)) { $app['dashboard'] = $dash; } } $this->apps[] = $app; }