public function get_templates($path = false, $include_hidden = false, $initial_path = false)
 {
     $Perch = Perch::fetch();
     if ($path === false) {
         $path = PERCH_TEMPLATE_PATH . '/categories';
     }
     if ($initial_path === false) {
         $initial_path = $path;
     }
     $a = array();
     if (is_dir($path)) {
         if ($dh = opendir($path)) {
             while (($file = readdir($dh)) !== false) {
                 if (substr($file, 0, 1) != '.' && ($include_hidden || substr($file, 0, 1) != '_') && !preg_match($Perch->ignore_pattern, $file)) {
                     $extension = PerchUtil::file_extension($file);
                     if ($extension == 'html' || $extension == 'htm') {
                         $p = str_replace($initial_path, '', $path);
                         if (!$p) {
                             $a[PerchLang::get('Categories')][] = array('filename' => $file, 'path' => $file, 'label' => $this->template_display_name($file));
                         } else {
                             $a[] = array('filename' => $file, 'path' => ltrim($p, '/') . '/' . $file, 'label' => $this->template_display_name($file));
                         }
                     } else {
                         $a[$this->template_display_name($file)] = $this->get_templates($path . '/' . $file, $include_hidden, $initial_path);
                     }
                 }
             }
             closedir($dh);
         }
         if (PerchUtil::count($a)) {
             $a = PerchUtil::array_sort($a, 'label');
         }
     }
     return $a;
 }
 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');
 }
예제 #3
0
 public function get_dir_contents($dir, $prefix = '')
 {
     $Perch = Perch::fetch();
     $a = array();
     if (is_dir($dir)) {
         if ($dh = opendir($dir)) {
             while (($file = readdir($dh)) !== false) {
                 if (substr($file, 0, 1) != '.' && !preg_match($Perch->ignore_pattern, $file)) {
                     if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
                         $sub = $this->get_dir_contents($dir . DIRECTORY_SEPARATOR . $file, $file . DIRECTORY_SEPARATOR);
                         if (PerchUtil::count($sub)) {
                             $a = array_merge($a, $sub);
                         }
                     } else {
                         if (PerchUtil::file_extension($file) == 'html') {
                             $a[] = $prefix . $file;
                         }
                     }
                 }
             }
             closedir($dh);
         }
     }
     return $a;
 }
예제 #4
0
 private function _check_file_type($Tag, $default_accept_types)
 {
     // check the file type
     $accept_type_string = $default_accept_types;
     if ($Tag->accept()) {
         $accept_type_string = $Tag->accept();
     }
     $mime_type = $this->get_mime_type();
     if ($mime_type) {
         $filetypes = $this->_parse_filetypes_file();
         // break the accept string into parts
         if (strpos($accept_type_string, ',')) {
             $accept_types = explode(',', $accept_type_string);
         } else {
             $accept_types = explode(' ', $accept_type_string);
         }
         if ($this->_mimetype_is_in_accepted_types($mime_type, $accept_types, $filetypes)) {
             // check that file extension maps to a mime type that is accepted.
             $extension = PerchUtil::file_extension($this->details['file_name']);
             $mimetypes = $this->_parse_mimetypes_file($extension);
             if (array_key_exists($extension, $mimetypes)) {
                 // we know the mime type for this filetype
                 if ($this->_mimetype_is_in_accepted_types($mimetypes[$extension], $accept_types, $filetypes)) {
                     return true;
                 }
             }
         }
     }
     $this->errors[] = 'Mime type did not match: ' . $mime_type;
     return false;
 }
예제 #5
0
 public function get_templates()
 {
     $a = array();
     if (is_dir(PERCH_PATH . '/templates/perchpages')) {
         if ($dh = opendir(PERCH_PATH . '/templates/perchpages')) {
             while (($file = readdir($dh)) !== false) {
                 if (substr($file, 0, 1) != '.') {
                     $extension = PerchUtil::file_extension($file);
                     if ($extension == 'html' || $extension == 'htm') {
                         $a[] = array('filename' => $file, 'path' => PERCH_PATH . '/templates/perchpages' . $file, 'label' => $this->template_display_name($file));
                     }
                 }
             }
             closedir($dh);
         }
     }
     return $a;
 }
 /**
  * Get an array of templates in the content folder.
  *
  * @param string $path 
  * @return void
  * @author Drew McLellan
  */
 public function get_templates($path = false, $include_hidden = false, $initial_path = false)
 {
     $Perch = Perch::fetch();
     if ($path === false) {
         $path = PERCH_TEMPLATE_PATH . '/forms/emails';
     }
     if ($initial_path === false) {
         $initial_path = $path;
     }
     $a = array();
     $groups = array();
     $p = false;
     if (is_dir($path)) {
         if ($dh = opendir($path)) {
             while (($file = readdir($dh)) !== false) {
                 if (substr($file, 0, 1) != '.' && ($include_hidden || substr($file, 0, 1) != '_') && !preg_match($Perch->ignore_pattern, $file)) {
                     $extension = PerchUtil::file_extension($file);
                     if ($extension == 'html' || $extension == 'htm') {
                         $p = str_replace($initial_path, '', $path);
                         if (!$p) {
                             $a[PerchLang::get('Templates')][] = array('filename' => $file, 'value' => $file, 'path' => $file, 'label' => $this->template_display_name($file));
                         } else {
                             $a[] = array('filename' => $file, 'value' => ltrim($p, '/') . '/' . $file, 'path' => ltrim($p, '/') . '/' . $file, 'label' => $this->template_display_name($file));
                         }
                     } else {
                         // Use this one of infinite recursive nesting. Group stuff below normalised for HTML select optgroups that only do one level
                         //$a[$this->template_display_name($file)] = $this->get_templates($path.'/'.$file, $include_hidden, $initial_path);
                         if ($p) {
                             $group_name = $this->template_display_name(trim($p, '/\\') . '/' . $file);
                         } else {
                             $group_name = $this->template_display_name($file);
                         }
                         $groups[$group_name] = $this->get_templates($path . '/' . $file, $include_hidden, $initial_path);
                     }
                 }
             }
             closedir($dh);
         }
         if (PerchUtil::count($a)) {
             $a = PerchUtil::array_sort($a, 'label');
         }
     }
     return $a + $groups;
 }
예제 #7
0
 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');
     }
 }
예제 #8
0
 private function _get_type($file)
 {
     return strtolower(substr(PerchUtil::file_extension($file), -4));
 }
예제 #9
0
 public function is_webp($image_path)
 {
     return false;
     // disabled for now. PHP isn't ready for WebP.
     // stop-gap
     return PerchUtil::file_extension($image_path) == 'webp';
 }
예제 #10
0
?>
    
</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>';
 public static function find_executable_files_in_resources()
 {
     $files = PerchUtil::get_dir_contents(PERCH_RESFILEPATH, false);
     if (PerchUtil::count($files)) {
         $out = array();
         $bad_ext = array('php', 'phtml', 'php3', 'php4', 'php5');
         foreach ($files as $file) {
             $ext = PerchUtil::file_extension($file);
             if (in_array($ext, $bad_ext)) {
                 $out[] = $file;
             }
         }
         if (PerchUtil::count($out)) {
             return $out;
         }
     }
     return false;
 }
 static function get_type_from_filename($filename)
 {
     $type = strtolower(PerchUtil::file_extension($filename));
     if (in_array($type, self::$image_types)) {
         return 'image';
     }
     if (in_array($type, self::$doc_types)) {
         return 'doc';
     }
     if (in_array($type, self::$sheet_types)) {
         return 'sheet';
     }
     if (in_array($type, self::$audio_types)) {
         return 'audio';
     }
     if (in_array($type, self::$video_types)) {
         return 'video';
     }
     if (in_array($type, self::$pres_types)) {
         return 'pres';
     }
     return 'doc';
 }
 /**
  * Create a new page, including adding a new file to the filesystem
  *
  * @param string $data
  * @return void
  * @author Drew McLellan
  */
 public function create_with_file($data)
 {
     $create_folder = false;
     if (isset($data['create_folder'])) {
         $create_folder = $data['create_folder'];
         unset($data['create_folder']);
     }
     $this->find_site_path();
     // Grab the template this page uses
     $Templates = new PerchContent_PageTemplates();
     $Template = $Templates->find($data['templateID']);
     if (is_object($Template)) {
         // we don't store this, so unset
         //unset($data['templateID']);
         // grab the template's file extension, as pages use the same ext as the template.
         $file_extension = PerchUtil::file_extension($Template->templatePath());
         // use the file name given (if stated) or create from the title. Sans extension.
         if (isset($data['file_name'])) {
             $parts = explode('.', $data['file_name']);
             $file_name = PerchUtil::urlify($parts[0]);
             unset($data['file_name']);
         } else {
             $file_name = PerchUtil::urlify($data['pageTitle']);
         }
         // Find the parent page
         $ParentPage = $this->find($data['pageParentID']);
         if (is_object($ParentPage)) {
             if ($ParentPage->pageSubpagePath()) {
                 $pageSection = $ParentPage->pageSubpagePath();
             } else {
                 $pageSection = PerchUtil::strip_file_name($ParentPage->pagePath());
             }
             $parentPageID = $ParentPage->id();
             $data['pageDepth'] = $ParentPage->pageDepth() + 1;
             // Copy subpage info
             $data['pageSubpageRoles'] = $ParentPage->pageSubpageRoles();
             $data['pageSubpageTemplates'] = $ParentPage->pageSubpageTemplates();
         } else {
             $pageSection = '/';
             $parentPageID = 0;
             $data['pageParentID'] = '0';
             $data['pageDepth'] = '1';
             $data['pageSubpageRoles'] = '';
             $data['pageSubpageTemplates'] = '';
         }
         $dir = PerchUtil::file_path(PERCH_SITEPATH . $pageSection);
         // Are we creating a new folder?
         if ($create_folder) {
             $new_folder = $this->get_unique_folder_name($dir, $file_name);
             PerchUtil::debug('Trying to create: ' . $new_folder);
             if (!is_dir($new_folder)) {
                 mkdir($new_folder, 0755, true);
             }
             if (is_dir($new_folder)) {
                 $new_dir_name = str_replace($dir, '', $new_folder);
                 $dir = $new_folder;
                 $new_file = PerchUtil::file_path($dir . '/' . PERCH_DEFAULT_DOC);
             }
         }
         // Can we write to this dir?
         if (is_writable($dir)) {
             // Are we creating a new folder?
             if (!$create_folder) {
                 // Get a new file name
                 $new_file = $this->get_unique_file_name($dir, $file_name, $file_extension);
             }
             $template_dir = PerchUtil::file_path(PERCH_TEMPLATE_PATH . '/pages');
             if (file_exists($template_dir)) {
                 $template_file = PerchUtil::file_path($template_dir . '/' . $Template->templatePath());
                 // Is this referenced or copied?
                 if ($Template->templateReference()) {
                     // Referenced, so write a PHP include
                     $include_path = str_replace(DIRECTORY_SEPARATOR, '/', $this->get_relative_path($template_file, $dir));
                     // If changing, update pattern in PerchPages_Page::move_file(), and account for old-patterned pages.
                     $contents = '<' . '?php include(str_replace(\'/\', DIRECTORY_SEPARATOR, \'' . $include_path . '\')); ?' . '>';
                 } else {
                     // Copied, so grab the template's contents
                     $contents = file_get_contents($template_file);
                 }
                 if ($contents) {
                     // Write the file
                     if (!file_exists($new_file) && file_put_contents($new_file, $contents)) {
                         // Get the new file path
                         if ($create_folder) {
                             $new_url = $pageSection . '/' . $new_dir_name . str_replace($dir, '', $new_file);
                             $data['pageSubpagePath'] = $pageSection . '/' . $new_dir_name;
                         } else {
                             $new_url = $pageSection . str_replace($dir, '', $new_file);
                             $data['pageSubpagePath'] = $pageSection;
                         }
                         $data['pageSubpagePath'] = str_replace('//', '/', $data['pageSubpagePath']);
                         $r = str_replace(DIRECTORY_SEPARATOR, '/', $new_url);
                         $r = str_replace('//', '/', $r);
                         $data['pagePath'] = $r;
                         // Insert into the DB
                         $Page = $this->create($data);
                         if (!is_object($Page)) {
                             PerchUtil::output_debug();
                         }
                         // Set its position in the tree
                         $Page->update_tree_position($parentPageID);
                         // Add to nav groups
                         if ($Template->templateNavGroups() != '') {
                             $Page->update_navgroups(explode(',', $Template->templateNavGroups()));
                         }
                         // Copy page options?
                         if ($Template->optionsPageID() != '0') {
                             $CopyPage = $this->find($Template->optionsPageID());
                             if (is_object($CopyPage)) {
                                 $sql = 'INSERT INTO ' . PERCH_DB_PREFIX . 'content_regions (
                                         pageID,
                                         regionKey,
                                         regionPage,
                                         regionHTML,
                                         regionNew,
                                         regionOrder,
                                         regionTemplate,
                                         regionMultiple,
                                         regionOptions,
                                         regionSearchable,
                                         regionEditRoles
                                     )
                                     SELECT
                                         ' . $this->db->pdb($Page->id()) . ' AS pageID,
                                         regionKey,
                                         ' . $this->db->pdb($r) . ' AS regionPage,
                                         "<!-- Undefined content -->" AS regionHTML,
                                         regionNew,
                                         regionOrder,
                                         regionTemplate,
                                         regionMultiple,
                                         regionOptions,
                                         regionSearchable,
                                         regionEditRoles
                                     FROM ' . PERCH_DB_PREFIX . 'content_regions
                                     WHERE regionPage!=' . $this->db->pdb('*') . ' AND pageID=' . $this->db->pdb((int) $CopyPage->id());
                                 $this->db->execute($sql);
                             }
                         }
                         return $Page;
                     } else {
                         PerchUtil::debug('Could not put file contents.');
                         $this->error_messages[] = 'Could not write contents to file: ' . $new_file;
                     }
                 }
             } else {
                 PerchUtil::debug('Template folder not found: ' . $template_dir);
                 $this->error_messages[] = 'Template folder not found: ' . $template_dir;
             }
         } else {
             PerchUtil::debug('Folder is not writable: ' . $dir);
             $this->error_messages[] = 'Folder is not writable: ' . $dir;
         }
     } else {
         PerchUtil::debug('Template not found.');
         PerchUtil::debug($data);
         $this->error_messages[] = 'Template could not be found.';
     }
     return false;
 }
 private function get_template_files($path = false, $include_hidden = false, $initial_path = false)
 {
     $Perch = Perch::fetch();
     if ($path === false) {
         $path = PERCH_TEMPLATE_PATH . '/pages';
     }
     if ($initial_path === false) {
         $initial_path = $path;
     }
     $a = array();
     if (is_dir($path)) {
         if ($dh = opendir($path)) {
             while (($file = readdir($dh)) !== false) {
                 if (substr($file, 0, 1) != '.' && $file != 'attributes' && ($include_hidden || substr($file, 0, 1) != '_') && !preg_match($Perch->ignore_pattern, $file)) {
                     $extension = PerchUtil::file_extension($file);
                     if ($extension == 'php' || $extension == str_replace('.', '', PERCH_DEFAULT_EXT)) {
                         $p = str_replace($initial_path, '', $path);
                         if (!$p) {
                             $a[] = array('filename' => $file, 'path' => $file, 'label' => $this->template_display_name($file), 'group' => 'general', 'sort' => '0_' . $file);
                         } else {
                             $out_path = ltrim($p, '/') . '/' . $file;
                             $a[] = array('filename' => $file, 'path' => $out_path, 'label' => $this->template_display_name($file), 'group' => trim($p, '/'), 'sort' => 'x_' . $out_path);
                         }
                     } else {
                         $a = array_merge($a, $this->get_template_files($path . '/' . $file, $include_hidden, $initial_path));
                     }
                 }
             }
             closedir($dh);
         }
         if (PerchUtil::count($a)) {
             $a = PerchUtil::array_sort($a, 'sort');
         }
     }
     return $a;
 }