Пример #1
0
function list_zip_files($id)
{
    if (!($r = open_zip_archive($id))) {
        return false;
    }
    $zip = $r["handle"];
    $result = array();
    $idx = 0;
    while ($entry = zip_read($zip)) {
        $path = zip_entry_name($entry);
        $components = explode("/", $path);
        $filename = $components[count($components) - 1];
        /*
         * Remove
         * - filenames that begin with .
         * - .class
         * - .prefs
         * - paths ending with / (directory names)
         * - paths that contain .metadata
         */
        if (substr($filename, 0, 1) != "." && !endswith($filename, ".class") && !endswith($filename, ".prefs") && !endswith($path, "/") && strpos($path, ".metadata") === FALSE) {
            $result[$idx] = $filename;
        }
        $idx++;
    }
    zip_close($zip);
    return $result;
}
Пример #2
0
 function initialize()
 {
     $dir = opendir(dirname(__FILE__) . '/classes');
     $this->field_types = array();
     while ($filespec = readdir($dir)) {
         if (!endswith($filespec, '.php')) {
             continue;
         }
         if (strpos($filespec, 'Field') === false && strpos($filespec, 'Disposition') === false) {
             continue;
         }
         $shortname = substr($filespec, 0, strpos($filespec, '.'));
         if (substr($shortname, -4) == 'Base') {
             continue;
         }
         $this->field_types[$this->Lang('field_type_' . $shortname)] = $shortname;
     }
     foreach ($this->field_types as $tName => $tType) {
         if (substr($tType, 0, 11) == 'Disposition') {
             $this->disp_field_types[$tName] = $tType;
         }
     }
     $this->all_validation_types = array();
     ksort($this->field_types);
     $this->std_field_types = array($this->Lang('field_type_TextField') => 'TextField', $this->Lang('field_type_TextAreaField') => 'TextAreaField', $this->Lang('field_type_CheckboxField') => 'CheckboxField', $this->Lang('field_type_CheckboxGroupField') => 'CheckboxGroupField', $this->Lang('field_type_PulldownField') => 'PulldownField', $this->Lang('field_type_RadioGroupField') => 'RadioGroupField', $this->Lang('field_type_DispositionEmail') => 'DispositionEmail', $this->Lang('field_type_DispositionFile') => 'DispositionFile', $this->Lang('field_type_PageBreakField') => 'PageBreakField', $this->Lang('field_type_StaticTextField') => 'StaticTextField');
     ksort($this->std_field_types);
 }
Пример #3
0
function showFiles()
{
    echo "<h2>Icons</h2>\n";
    echo '<table border="1">';
    $list = array();
    $d = dir(".");
    while (false !== ($entry = $d->read())) {
        if (endswith($entry, ".gif") || endswith($entry, ".jpg") || endswith($entry, ".png") || endswith($entry, ".EPS") || endswith($entry, ".PSD") || endswith($entry, ".md")) {
            $list[] = $entry;
        }
    }
    $d->close();
    sort($list);
    foreach ($list as $entry) {
        echo '<tr>' . "\n";
        echo '<td><a href="' . $entry . '">' . $entry . ' </a></td>' . "\n";
        if (endswith($entry, ".gif") || endswith($entry, ".jpg") || endswith($entry, ".png")) {
            // display as image
            //   would be good to add a limiting size here
            echo '<td bgcolor="#C0C0C0"><a href="' . $entry . '"><img src="' . $entry . '" style="max-width:500px;max-height:500px;"></a></tr>' . "\n";
        } else {
            // link without display
            echo '<td bgcolor="#C0C0C0"><a href="' . $entry . '" download="' . $entry . '">(download)</a></tr>' . "\n";
        }
        echo '</tr>' . "\n";
    }
    echo "</table>\n";
}
Пример #4
0
function getFirstFileIn($dir)
{
    global $filetype;
    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if (endswith($file, $filetype)) {
                return $file;
            }
        }
    }
    return false;
}
Пример #5
0
 public static function GetCachePath($mod)
 {
     // Récupérer et traiter la préférence du dossier
     $cache_path = $mod->GetPreference("cache_path");
     // Si la préférence commence par un "/" alors l'enlever
     if (startswith($cache_path, DIRECTORY_SEPARATOR)) {
         $cache_path = substr($cache_path, 1);
     }
     // Si la préférence termine par un "/" alors l'enlever
     if (endswith($cache_path, DIRECTORY_SEPARATOR)) {
         $cache_path = substr($cache_path, -1, 1);
     }
     // Ajouter à la préférence le chemin complet
     $config = $mod->GetConfig();
     $cache_path = $config['root_path'] . DIRECTORY_SEPARATOR . "tmp" . DIRECTORY_SEPARATOR . $cache_path;
     return $cache_path;
 }
 /**
  * Process the specififed template through smarty.
  * This method will attempt to find the current action module, and given that and the name of the template find the template contents.
  * if the template name ends with .tpl a module file template is assumed.  Otherwise, a module database template will be assumed.
  * If a module cannot be determined, then a file template is assumed, using the 'file' smarty resource.
  *
  * @param string $tpl The name of the template to process.
  */
 protected function process_template($tpl)
 {
     $smarty = cmsms()->GetSmarty();
     $actionmodule = $smarty->get_template_vars('actionmodule');
     if ($actionmodule) {
         $mod = \cms_utils::get_module($actionmodule);
         if (is_object($mod)) {
             if (endswith($tpl, '.tpl')) {
                 $out = $mod->ProcessTemplate($tpl);
             } else {
                 $out = $mod->ProcessTemplateFromDatabase($tpl);
             }
         }
     } else {
         $out = $smarty->fetch('file:' . $tpl);
     }
     return $out;
 }
Пример #7
0
function showFiles()
{
    echo "<h2>Icons</h2>\n";
    echo '<table border="1">';
    $list = array();
    $d = dir(".");
    while (false !== ($entry = $d->read())) {
        if (endswith($entry, ".gif") || endswith($entry, ".jpg") || endswith($entry, ".png")) {
            $list[] = $entry;
        }
    }
    $d->close();
    sort($list);
    foreach ($list as $entry) {
        echo '<tr><td>' . $entry . ' </td><td bgcolor="#C0C0C0"><a href="' . $entry . '"><img src="' . $entry . '"></a></td>' . "\n";
    }
    echo "</table>\n";
}
function sendAsHtml()
{
    global $filetype;
    if ($handle = opendir('./')) {
        /* This is the correct way to loop over the directory. */
        $first = true;
        $i = 1;
        while (false !== ($file = readdir($handle))) {
            if (endswith($file, $filetype)) {
                if (!$first) {
                    echo ' - ';
                } else {
                    $first = false;
                }
                echo "<a href=\"./{$file}\">Page {$i}</a> ";
                $i++;
            }
        }
        closedir($handle);
    }
}
Пример #9
0
	private function build($type,$id){
		
		if(endswith($type,"s")){
			$table = $type;
			$name =  substr($type,0,-1);
		}else{
			$table = $type."s";
			$name = $type;
		}
		
		$rows = $this->db->get_where($table,array("element_id"=>$id));
		if(rows($rows)){
			$out = array();
			foreach($rows->result_array() as $curRow){
				$out[$curRow['id']] = new $name( $this->oh, $curRow['id']); 	
			}
			$this->objArrays[$table] = $out;
			return $out;
		}else
			return array();
		
	}
Пример #10
0
 public function testAllCases()
 {
     $TEST_CASE_DIR = realpath(__DIR__ . '/cases');
     echo "Directory is " . $TEST_CASE_DIR;
     $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($TEST_CASE_DIR));
     foreach ($dir as $name => $object) {
         if (!endswith($name, '.txt')) {
             continue;
         }
         //$this->assertEquals($this->fmt->parseFile($name), file_get_contents($name . '.fixed'));
         $lines1 = explode("\n", $this->fmt->parseFile($name));
         $lines2 = explode("\n", file_get_contents($name . '.fixed'));
         for ($l = 0; $l < count($lines1); $l++) {
             if (!($lines1[$l] == $lines2[$l])) {
                 $first = $lines1[$l];
                 $second = $lines2[$l];
                 $this->assertTrue(false, "Line {$l} in file {$name} is incorrect\n" . "expected: {$second}\n" . "actual: {$first}");
             }
             $this->assertEquals($lines1[$l], $lines2[$l]);
         }
     }
 }
 /**
  * A utility function to test if the supplied url path is valid for the supplied content id
  *
  * @param string The partial url path to test
  * @return boolean
  */
 public static function is_valid_url($url, $content_id = '')
 {
     // check for starting or ending slashes
     if (startswith($url, '/') || endswith($url, '/')) {
         return FALSE;
     }
     // first check for invalid chars.
     $translated = munge_string_to_url($url, false, true);
     if (strtolower($translated) != strtolower($url)) {
         return FALSE;
     }
     cms_route_manager::load_routes();
     $route = cms_route_manager::find_match($url);
     if (!$route) {
         return TRUE;
     }
     if ($route->is_content()) {
         if ($content_id == '' || $route->get_content() == $content_id) {
             return TRUE;
         }
     }
     return FALSE;
 }
Пример #12
0
 /**
  * A utility function to test if the supplied url path is valid for the supplied content id
  *
  * @param string The partial url path to test
  * @return boolean
  */
 public static function is_valid_url($url, $content_id = '')
 {
     // check for starting or ending slashes
     if (startswith($url, '/') || endswith($url, '/')) {
         return FALSE;
     }
     // first check for invalid chars.
     // strip off any extension (that is like 5 chars or less)
     $pos = strrpos($url, '.');
     if ($pos !== FALSE) {
         // have an extension.
         $ext = substr($url, $pos + 1);
         if (strlen($ext) >= 5 || munge_string_to_url($ext, false, true) != strtolower($ext)) {
             return FALSE;
         }
         $tmp = substr($url, 0, $pos);
         if (munge_string_to_url($tmp, false, true) != strtolower($tmp)) {
             return FALSE;
         }
     } else {
         $translated = munge_string_to_url($url, false, true);
         if (strtolower($translated) != strtolower($url)) {
             return FALSE;
         }
     }
     cms_route_manager::load_routes();
     $route = cms_route_manager::find_match($url, TRUE);
     if (!$route) {
         return TRUE;
     }
     if ($route->is_content()) {
         if ($content_id == '' || $route->get_content() == $content_id) {
             return TRUE;
         }
     }
     return FALSE;
 }
Пример #13
0
 /**
  * Ensure that a given type is actually included
  *
  * @param string $class
  */
 public function includeType($class)
 {
     if (empty($class)) {
         throw new Exception("Cannot include null type");
     }
     $class = str_replace('.', '_', $class);
     $dir = 'model';
     $file = $class . '.php';
     $source = $dir . DIRECTORY_SEPARATOR . $file;
     $found = false;
     if (!Zend_Loader::isReadable($source)) {
         $extensions = array_merge(array('november'), za()->getExtensions());
         foreach ($extensions as $extDir) {
             $source = $extDir . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . $file;
             if (Zend_Loader::isReadable($source)) {
                 $found = true;
                 break;
             }
         }
     } else {
         $found = true;
     }
     if (!$found && endswith($class, 'Version')) {
         // try including the non-version instance instead
         return $this->includeType(substr($class, 0, strrpos($class, 'Version')));
     }
     try {
         if (!class_exists($class, false)) {
             Zend_Loader::loadFile(basename($source), APP_DIR . DIRECTORY_SEPARATOR . dirname($source), true);
         }
     } catch (Zend_Exception $ze) {
         // ignore it, we'll just assume it was loaded elsewhere
     }
     if (!class_exists($class)) {
         throw new Exception("Class {$class} not found in the model directory");
     }
 }
 /**
  * Get the output of the report.
  *
  * @return mixed the actual output format depends upon the template that is provided.
  */
 public function get_output()
 {
     $out = null;
     $data = parent::get_output();
     if (!is_array($data)) {
         return $out;
     }
     $smarty = cmsms()->GetSmarty();
     $smarty->assign('report_data', $data);
     $actionmodule = $smarty->get_template_vars('actionmodule');
     if ($actionmodule) {
         $mod = cms_utils::get_module($actionmodule);
         if (is_object($mod)) {
             if (endswith($this->get_template(), '.tpl')) {
                 $out = $mod->ProcessTemplate($this->get_template());
             } else {
                 $out = $mod->ProcessTemplateFromDatabase($this->get_template());
             }
         }
     } else {
         $out = $smarty->fetch('file:' . $template);
     }
     return $out;
 }
 function __construct(&$content_obj, $params = array())
 {
     $params['block_type'] = 'date';
     parent::__construct($content_obj, $params);
     $showClock = !(isset($params['show_clock']) && ac_utils::IsFalse($params['show_clock']));
     $mode = 'calendar';
     if (isset($params['mode']) && strtolower($params['mode']) == 'dropdown') {
         $mode = 'dropdown';
     }
     $show24h = !(isset($params['show24h']) && ac_utils::IsFalse($params['show24h']));
     $dateFormat = isset($params['date_format']) ? $params['date_format'] : '%x %X';
     $startHour = 0;
     $endHour = 23;
     if (isset($params['start_hour'])) {
         if (endswith($params['start_hour'], 'pm')) {
             $params['start_hour'] = trim(str_ireplace('pm', '', $params['start_hour'])) + 12;
         } else {
             $params['start_hour'] = trim(str_ireplace(array('am', 'pm'), '', $params['start_hour']));
         }
         if ($params['start_hour'] > 0 && $params['start_hour'] <= $endHour) {
             $startHour = trim($params['start_hour']);
         }
     }
     if (isset($params['end_hour'])) {
         if (endswith($params['end_hour'], 'pm')) {
             $params['end_hour'] = trim(str_ireplace('pm', '', $params['end_hour'])) + 12;
         } else {
             $params['end_hour'] = trim(str_ireplace(array('am', 'pm'), '', $params['end_hour']));
         }
         if ($params['end_hour'] >= 0 && $params['end_hour'] < $endHour) {
             $endHour = trim($params['end_hour']);
         }
     }
     if ($endHour < $startHour) {
         $endHour = $startHour;
     }
     $startMinute = 0;
     if (isset($params['start_minute']) && $params['start_minute'] > 0 && $params['start_minute'] <= 59) {
         $startMinute = trim($params['start_minute']);
     }
     $endMinute = 59;
     if (isset($params['end_minute']) && $params['end_minute'] >= 0 && $params['end_minute'] < 59) {
         $endMinute = trim($params['end_minute']);
     }
     if ($endMinute < $startMinute) {
         $endMinute = $startMinute;
     }
     $startSecond = 0;
     if (isset($params['start_second']) && $params['start_second'] > 0 && $params['start_second'] <= 59) {
         $startSecond = trim($params['start_second']);
     }
     $endSecond = 59;
     if (isset($params['end_second']) && $params['end_second'] >= 0 && $params['end_second'] < 59) {
         $endSecond = trim($params['end_second']);
     }
     if ($endSecond < $startSecond) {
         $endSecond = $startSecond;
     }
     $stepHours = 1;
     if (isset($params['step_hours']) && $params['step_hours'] > 0 && $params['step_hours'] <= $endHour - $startHour) {
         $stepHours = trim($params['step_hours']);
     } else {
         if (isset($params['step_hours']) && $params['step_hours'] > 0 && $params['step_hours'] >= $endHour - $startHour) {
             $stepHours = $endHour - $startHour;
         }
     }
     $stepMinutes = 30;
     if (isset($params['step_minutes']) && $params['step_minutes'] > 0 && $params['step_minutes'] <= $endMinute - $startMinute) {
         $stepMinutes = trim($params['step_minutes']);
     } else {
         if (isset($params['step_minutes']) && $params['step_minutes'] > 0 && $params['step_minutes'] >= $endMinute - $startMinute) {
             $stepMinutes = $endMinute - $startMinute;
         }
     }
     $stepSeconds = 1;
     if (isset($params['step_seconds']) && $params['step_seconds'] > 0 && $params['step_seconds'] <= $endSecond - $startSeconds) {
         $stepSeconds = trim($params['step_seconds']);
     } else {
         if (isset($params['step_seconds']) && $params['step_seconds'] > 0 && $params['step_seconds'] >= $endSecond - $startSeconds) {
             $stepSeconds = $endSecond - $startSeconds;
         }
     }
     $this->SetProperty('show24h', $show24h);
     $this->SetProperty('mode', $mode);
     $this->SetProperty('start_hour', $startHour);
     $this->SetProperty('end_hour', $endHour);
     $this->SetProperty('start_minute', $startMinute);
     $this->SetProperty('end_minute', $endMinute);
     $this->SetProperty('start_second', $startSecond);
     $this->SetProperty('end_second', $endSecond);
     $this->SetProperty('step_hours', $stepHours);
     $this->SetProperty('step_minutes', $stepMinutes);
     $this->SetProperty('step_seconds', $stepSeconds);
     $this->SetProperty('show_clock', $showClock);
     $this->SetProperty('date_format', $dateFormat);
 }
function cms_stylesheet_toString($filename, $media_query = '', $media_type = '', $root_url, &$stylesheet, &$params)
{
    if (!endswith($root_url, '/')) {
        $root_url .= '/';
    }
    if (isset($params['nolinks'])) {
        $stylesheet .= $root_url . $filename . ',';
    } else {
        if (!empty($media_query)) {
            $stylesheet .= '<link rel="stylesheet" type="text/css" href="' . $root_url . $filename . '" media="' . $media_query . '" />' . "\n";
        } elseif (!empty($media_type)) {
            $stylesheet .= '<link rel="stylesheet" type="text/css" href="' . $root_url . $filename . '" media="' . $media_type . '" />' . "\n";
        } else {
            $stylesheet .= '<link rel="stylesheet" type="text/css" href="' . $root_url . $filename . '" />' . "\n";
        }
    }
}
function gt_restrict_admin_with_redirect()
{
    function endswith($string, $test)
    {
        $strlen = strlen($string);
        $testlen = strlen($test);
        if ($testlen > $strlen) {
            return false;
        }
        return substr_compare($string, $test, -$testlen) === 0;
    }
    //Get current user's role
    global $current_user;
    $user_roles = $current_user->roles;
    $user_role = array_shift($user_roles);
    if (is_admin() && $user_role == 'theme_options_preview' && !endswith($_SERVER['PHP_SELF'], '/wp-admin/admin-ajax.php') && !endswith($_SERVER['PHP_SELF'], '/includes/gt-customize.php')) {
        wp_redirect(site_url());
        exit;
    }
}
Пример #18
0
<?php

if (!isset($gCms)) {
    exit;
}
debug_buffer('', 'Start of Menu Manager Display');
$hm =& $gCms->GetHierarchyManager();
$usefile = true;
$tpl_name = $this->GetPreference('default_template', 'simple_navigation.tpl');
if (isset($params['template']) && $params['template'] != '') {
    $tpl_name = $params['template'];
}
if (endswith($tpl_name, '.tpl')) {
    $usefile = true;
} else {
    $usefile = false;
}
$mdid = md5($gCms->variables['content_id'] . implode('|', $params));
$deep = 1;
if (isset($params['loadprops']) && $params['loadprops'] == 0) {
    $deep = 0;
}
$cached = false;
$origdepth = 0;
if (!$cached) {
    $nodelist = array();
    $count = 0;
    $getchildren = true;
    $rootnode = null;
    $prevdepth = 1;
    if (isset($params['childrenof'])) {
Пример #19
0
 function checkReferences($refs)
 {
     $messages = array();
     foreach ($refs as $r) {
         //echo $r . '----';
         if (trim($r) != "") {
             if (contains($r, "[")) {
                 $this->checkArray($r, $messages);
                 $r = str_replace("[", "||", $r);
                 $r = str_replace("]", "||", $r);
                 $r = str_replace(".", "||", $r);
                 $r = str_replace(",", "||", $r);
                 $r = str_replace(" ", "", $r);
                 // replace any operators
                 $r = str_replace("-", "||", $r);
                 $r = str_replace("+", "||", $r);
                 $r = str_replace("*", "||", $r);
                 $r = str_replace("/", "||", $r);
                 $explode = explode("||", $r);
                 foreach ($explode as $e) {
                     if (trim($e) != "") {
                         if (!is_numeric($e)) {
                             // check for _1_ for set of enum
                             $v = $this->survey->getVariableDescriptiveByName(getBasicName($e));
                             if (inArray($v->getAnswerType(), array(ANSWER_TYPE_SETOFENUMERATED, ANSWER_TYPE_MULTIDROPDOWN))) {
                                 $e = preg_replace("/(_[0-9]+_(\\b|\\[)){1}/", "", $e);
                             }
                             // check for associative key
                             $e = str_replace('"', "'", $e);
                             if (startsWith($e, "'") && endswith($e, "'")) {
                             } else {
                                 if ($v->getVsid() == "") {
                                     $sec = $this->survey->getSectionByName($e);
                                     if ($sec->getSeid() == "") {
                                         $messages[] = Language::messageCheckerVariableNotExists($e);
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 if (!is_numeric($r)) {
                     $v = $this->survey->getVariableDescriptiveByName(getBasicName($r));
                     if (inArray($v->getAnswerType(), array(ANSWER_TYPE_SETOFENUMERATED, ANSWER_TYPE_MULTIDROPDOWN))) {
                         $r = preg_replace("/(_[0-9]+_(\\b|\\[)){1}/", "", $r);
                     }
                     if ($v->getVsid() == "") {
                         $sec = $this->survey->getSectionByName($e);
                         if ($sec->getSeid() == "") {
                             $messages[] = Language::messageCheckerVariableNotExists($r);
                         }
                     } else {
                         $this->checkArray($r, $messages);
                     }
                 }
             }
         }
     }
     // return result
     return $messages;
 }
Пример #20
0
	<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
	<form class="container">
		<div class="col-md-12" id="header">
			<div class="col-md-1" id="title"><a href="<?php 
echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
?>
" class="no-href">.Desktop<br><img src="images/hero-dots.png" width="84px" /></a></div>
			<div class="col-md-10" id="browser">
				<label class="col-md-3 text-right lowered" for="file-list">.desktop File: </label>
				<select id="file-list">
					<option value=''></option>
					<?php 
foreach ($files as $file) {
    if (endswith($file, '.desktop')) {
        $file = substr($file, 0, strpos($file, '.desk'));
        echo "<option value=\"{$file}\">{$file}</option>";
    }
}
?>
				</select>
				<button class="btn btn-save pushed-right hide" type="button" value="New" id="new-section" name="new-section" title="Add New Section"><span class="fa fa-clone"></span></button>
				<button class="btn btn-save pushed-right" type="button" value="Save" id="save" name="save" title="Save Changes"><span class="fa fa-floppy-o"></span> Save</button>
			</div>
			<div class="clearfix"></div>
		</div>

		<div class="col-md-12" id="guts"></div>
	</form>
	<a href="javascript:void(null)" id="btn-top-scroller" class="bluezed-scroll-top"><span class="glyphicon glyphicon-menu-up bluezed-scroll-top-circle"></span></a>
Пример #21
0
    $selall = unserialize($selall);
}
if (count($selall) == 0) {
    $params["fmerror"] = "nofilesselected";
    $this->Redirect($id, "defaultadmin", $returnid, $params);
}
if (count($selall) > 1) {
    $params["fmerror"] = "morethanonefiledirselected";
    $this->Redirect($id, "defaultadmin", $returnid, $params);
}
$config = cmsms()->GetConfig();
$filename = $this->decodefilename($selall[0]);
$src = filemanager_utils::join_path($config['root_path'], filemanager_utils::get_cwd(), $filename);
if (!file_exists($src)) {
    $params["fmerror"] = "filenotfound";
    $this->Redirect($id, "defaultadmin", $returnid, $params);
}
include_once dirname(__FILE__) . '/easyarchives/EasyArchive.class.php';
$archive = new EasyArchive();
$destdir = filemanager_utils::join_path($config['root_path'], filemanager_utils::get_cwd());
if (!endswith($destdir, '/')) {
    $destdir .= '/';
}
$res = $archive->extract($src, $destdir);
$paramsnofiles["fmmessage"] = "unpacksuccess";
//strips the file data
$this->Audit('', "File Manager", "Unpacked file: " . $src);
$this->Redirect($id, "defaultadmin", $returnid, $paramsnofiles);
#
# EOF
#
Пример #22
0
$newtemplate = '';
if (isset($params['newtemplate'])) {
    $newtemplate = $params['newtemplate'];
}
$content = '';
if (isset($params['templatecontent'])) {
    $content = $params['templatecontent'];
}
if (isset($params['cancel'])) {
    $this->Redirect($id, 'defaultadmin', $returnid);
} else {
    if (isset($params['submit'])) {
        if ($newtemplate == '') {
            $error = $this->Lang('notemplatename');
        } else {
            if (endswith($newtemplate, '.tpl')) {
                $error = $this->Lang('error_templatename');
            } else {
                if ($content == '') {
                    $error = $this->Lang('nocontent');
                } else {
                    if ($this->GetTemplate($newtemplate) == '') {
                        $this->clear_cache();
                        $this->SetTemplate($newtemplate, $content);
                        $this->Redirect($id, 'defaultadmin', $returnid);
                    } else {
                        $themeObject = $gCms->variables['admintheme'];
                        $error = $themeObject->ShowErrors($this->Lang('templatenameexists'));
                    }
                }
            }
Пример #23
0
    /**
     * Redirects the browser to the given url.
     *
     * @param string The url to redirect to
     * @return void
     * @author Ted Kulp
     **/
    public static function redirect($to)
    {
        $_SERVER['PHP_SELF'] = null;
        $config = array();
        /*
        try
        {
        	$config = cms_config();
        }
        catch (Exception $e)
        {
        }
        */
        $schema = $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http';
        $host = strlen($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
        $components = parse_url($to);
        if (count($components) > 0) {
            $to = (isset($components['scheme']) && starts_with($components['scheme'], 'http') ? $components['scheme'] : $schema) . '://';
            $to .= isset($components['host']) ? $components['host'] : $host;
            $to .= isset($components['port']) ? ':' . $components['port'] : '';
            if (isset($components['path'])) {
                if (in_array(substr($components['path'], 0, 1), array('\\', '/'))) {
                    $to .= $components['path'];
                } else {
                    if (isset($_SERVER['PHP_SELF']) && !is_null($_SERVER['PHP_SELF'])) {
                        $to .= (strlen(dirname($_SERVER['PHP_SELF'])) > 1 ? dirname($_SERVER['PHP_SELF']) . '/' : '/') . $components['path'];
                    } else {
                        if (isset($_SERVER['REQUEST_URI']) && !is_null($_SERVER['REQUEST_URI'])) {
                            if (endswith($_SERVER['REQUEST_URI'], '/')) {
                                $to .= (strlen($_SERVER['REQUEST_URI']) > 1 ? $_SERVER['REQUEST_URI'] : '/') . $components['path'];
                            } else {
                                $to .= (strlen(dirname($_SERVER['REQUEST_URI'])) > 1 ? dirname($_SERVER['REQUEST_URI']) . '/' : '/') . $components['path'];
                            }
                        }
                    }
                }
            }
            $to .= isset($components['query']) ? '?' . $components['query'] : '';
            $to .= isset($components['fragment']) ? '#' . $components['fragment'] : '';
        } else {
            $to = $schema . "://" . $host . "/" . $to;
        }
        if (headers_sent() && !(isset($config) && $config['debug'] == true)) {
            // use javascript instead
            echo '<script type="text/javascript">
				<!--
				location.replace("' . $to . '");
			// -->
			</script>
				<noscript>
				<meta http-equiv="Refresh" content="0;URL=' . $to . '">
				</noscript>';
            exit;
        } else {
            if (isset($config) && $config['debug'] == true) {
                echo "Debug is on.  Redirecting disabled...  Please click this link to continue.<br />";
                echo "<a href=\"" . $to . "\">" . $to . "</a><br />";
                echo '<pre>';
                echo CmsProfiler::get_instance()->report();
                echo '</pre>';
                exit;
            } else {
                header("Location: {$to}");
                exit;
            }
        }
    }
 function ManageImageUpload($id, $fldprefix, $fldname, $uid)
 {
     $gCms = cmsms();
     if (!isset($_FILES[$id . $fldprefix . $fldname]) || !isset($_FILES)) {
         return array(false, $this->Lang('error_missing_upload'));
     }
     //$destname = $_FILES[$id.$fldname]['name'];
     $file =& $_FILES[$id . $fldprefix . $fldname];
     if (!isset($file['name']) || !isset($file['size']) || $file['size'] == 0) {
         return array(false, $this->Lang('error_problem_upload'));
     }
     if (!isset($file['type'])) {
         $file['type'] = '';
     }
     if (!isset($file['size'])) {
         $file['size'] = '';
     }
     if (!isset($file['tmp_name'])) {
         $file['tmp_name'] = '';
     }
     $file['name'] = preg_replace('/[^a-zA-Z0-9\\.\\$\\%\'\\`\\-\\@\\{\\}\\~\\!\\#\\(\\)\\&\\_\\^]/', '', str_replace(array(' ', '%20'), array('_', '_'), $file['name']));
     // check the filename
     $allowed_extensions = $this->GetPreference('allowed_image_extensions', '.gif,.png,.jpg');
     $tmp = explode(',', $allowed_extensions);
     if (!is_array($tmp)) {
         return array(false, $this->Lang('error_invalidfileextension'));
     }
     $found = false;
     foreach ($tmp as $ext) {
         if (endswith($file['name'], $ext)) {
             $found = true;
             break;
         }
     }
     if (!$found) {
         return array(false, $this->Lang('error_invalidfileextension'));
     }
     // set the destination name
     $ext = strchr($file['name'], '.');
     $destname = $uid . '_' . $fldname . $ext;
     // Create the destination directory if necessary
     $destDir = $this->get_upload_dirname($uid);
     @mkdir($destDir);
     if (!is_writable($destDir)) {
         return array(false, $this->Lang('error_destinationnotwritable'));
     }
     @cms_move_uploaded_file($file['tmp_name'], cms_join_path($destDir, $destname));
     return array(true, $destname);
 }
Пример #25
0
 /**
  * __get()
  * A magic function that is used for backwards compatibility only
  *
  * @deprecated
  * @param string key - possible values are 'cms','themeName',and 'userid'
  * @return mixed
  */
 public function __get($key)
 {
     if ($key == 'cms') {
         return cmsms();
     }
     if ($key == 'themeName') {
         $class = get_class($this);
         if (endswith($class, 'Theme')) {
             $class = substr($class, 0, strlen($class) - 5);
         }
         return $class;
     }
     if ($key == 'userid') {
         return get_userid();
     }
     //trigger_error("Attempt to access invalid member $key of admin theme object");
 }
 /**
  * Smarty Plugin : {get_global_contents}
  * Purpose       : This plugin displays properties of global content blocks of CMSms 
  *                 divided by a separator
  * Author        : Georg Busch (NaN)
  * Copyright     : 2010 - 2012 Georg Busch (NaN)
  * Version       : 1.0
  * License       : GPL
  */
 public static function get_global_contents($params, &$obj)
 {
     if (version_compare(CMS_VERSION, '1.11') < 0) {
         $smarty =& $obj;
     } else {
         $smarty =& $obj->smarty;
     }
     $gcbs = cmsms()->GetGlobalContentOperations()->LoadHtmlBlobs();
     $delimiter = "<hr />";
     if (isset($params['delimiter']) && trim($params['delimiter']) != '') {
         $delimiter = trim($params['delimiter']);
     }
     $excl_prefix = array();
     $incl_prefix = array();
     $excl_sufix = array();
     $incl_sufix = array();
     if (isset($params['excl_prefix'])) {
         $excl_prefix = ac_utils::CleanArray(explode(',', $params['excl_prefix']));
     }
     if (isset($params['excl_sufix'])) {
         $excl_sufix = ac_utils::CleanArray(explode(',', $params['excl_sufix']));
     }
     if (isset($params['incl_prefix'])) {
         $incl_prefix = ac_utils::CleanArray(explode(',', $params['incl_prefix']));
     }
     if (isset($params['incl_sufix'])) {
         $incl_sufix = ac_utils::CleanArray(explode(',', $params['incl_sufix']));
     }
     $assign_as = 'string';
     if (isset($params['assign_as'])) {
         $assign_as = $params['assign_as'];
     }
     $output = 'content';
     // name, id, owner, modified_date, full_object
     if (isset($params['output'])) {
         $output = $params['output'];
     }
     $sort_by = 'id';
     if (isset($params['sort_by'])) {
         $sort_by = $params['sort_by'];
     }
     $sort_order = 'asc';
     if (isset($params['sort_order'])) {
         $sort_order = $params['sort_order'];
     }
     $gcb_array = array();
     foreach ($gcbs as $gcb) {
         $skip = false;
         foreach ($excl_prefix as $str) {
             if (startswith($gcb->name, $str)) {
                 $skip = true;
                 break;
             }
         }
         if ($skip) {
             continue;
         }
         foreach ($incl_prefix as $str) {
             if (!startswith($gcb->name, $str)) {
                 $skip = true;
                 break;
             }
         }
         if ($skip) {
             continue;
         }
         foreach ($excl_sufix as $str) {
             if (endswith($gcb->name, $str)) {
                 $skip = true;
                 break;
             }
         }
         if ($skip) {
             continue;
         }
         foreach ($incl_sufix as $str) {
             if (!endswith($gcb->name, $str)) {
                 $skip = true;
                 break;
             }
         }
         if ($skip) {
             continue;
         }
         switch ($sort_by) {
             case 'name':
                 if ($output == 'full_object') {
                     $gcb_array[$gcb->name] = $gcb;
                     break;
                 }
                 $gcb_array[$gcb->name] = $gcb->{$output};
                 break;
             case 'modified_date':
                 if ($output == 'full_object') {
                     $gcb_array[$gcb->modified_date] = $gcb;
                     break;
                 }
                 $gcb_array[$gcb->modified_date] = $gcb->{$output};
                 break;
             case 'owner':
             case 'owner+create_date':
             case 'owner+id':
                 if ($output == 'full_object') {
                     $gcb_array[$gcb->owner . '_' . $gcb->id] = $gcb;
                     break;
                 }
                 $gcb_array[$gcb->owner . '_' . $gcb->id] = $gcb->{$output};
                 break;
             case 'owner+name':
                 if ($output == 'full_object') {
                     $gcb_array[$gcb->owner . '_' . $gcb->name] = $gcb;
                     break;
                 }
                 $gcb_array[$gcb->owner . '_' . $gcb->name] = $gcb->{$output};
                 break;
             case 'owner+modified_date':
                 if ($output == 'full_object') {
                     $gcb_array[$gcb->owner . '_' . $gcb->modified_date] = $gcb;
                     break;
                 }
                 $gcb_array[$gcb->owner . '_' . $gcb->modified_date] = $gcb->{$output};
                 break;
             case 'id':
             case 'create_date':
             default:
                 if ($output == 'full_object') {
                     $gcb_array[$gcb->id] = $gcb;
                     break;
                 }
                 $gcb_array[$gcb->id] = $gcb->{$output};
                 break;
         }
     }
     if ($sort_order == 'desc') {
         krsort($gcb_array);
     } else {
         ksort($gcb_array);
     }
     if (isset($params['assign'])) {
         if ($assign_as == "array") {
             $smarty->assign($params['assign'], $gcb_array);
             return;
         }
         $smarty->assign($params['assign'], implode($delimiter, $gcb_array));
         return;
     }
     return implode($delimiter, $gcb_array);
 }
Пример #27
0
/*****************************************
 * Handle the File Tab
 ****************************************/
$dir = dirname(__FILE__) . '/templates';
$dh = opendir($dir);
$files = array();
while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
}
if (isset($dh)) {
    closedir($dh);
}
$badfiles = array('filetpllist.tpl', 'dbtpllist.tpl', 'edittemplate.tpl', 'importtemplate.tpl');
foreach ($files as $onefile) {
    //If this is not a .tpl file, skip it
    if (!endswith($onefile, '.tpl')) {
        continue;
    }
    //If this is in badfiles, skip it
    if (in_array($onefile, $badfiles)) {
        continue;
    }
    $onerow = new stdClass();
    $onerow->templatename = $onefile;
    $onerow->importlink = $this->CreateLink($id, 'importtemplate', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/import.gif', $this->Lang('importtemplate'), '', '', 'systemicon'), array('tplname' => $onefile));
    if ($default_template != $onefile) {
        $onerow->setdefault_link = $this->CreateLink($id, 'setdefault', $returnid, $admintheme->DisplayImage('icons/system/false.gif', $this->Lang('set_as_default'), '', '', 'systemicon'), array('template' => $onefile));
    }
    $entryarray[] = $onerow;
}
$this->smarty->assign_by_ref('items', $entryarray);
Пример #28
0
     }
 }
 if (!empty($_POST['share_input_wallabag'])) {
     if (filter_var($_POST['share_input_wallabag'], FILTER_VALIDATE_URL) !== false) {
         if (endswith($_POST['share_input_wallabag'], '/')) {
             $config->wallabag_share = $_POST['share_input_wallabag'];
         } else {
             $config->wallabag_share = $_POST['share_input_wallabag'] . '/';
         }
     } else {
         die('Error: Incorrect Wallabag URL');
     }
 }
 if (!empty($_POST['share_input_diaspora'])) {
     if (filter_var($_POST['share_input_diaspora'], FILTER_VALIDATE_URL) !== false) {
         if (endswith($_POST['share_input_diaspora'], '/')) {
             $config->diaspora_share = $_POST['share_input_diaspora'];
         } else {
             $config->diaspora_share = $_POST['share_input_diaspora'] . '/';
         }
     } else {
         die('Error: Incorrect diaspora URL');
     }
 }
 $config->save();
 if (empty($error)) {
     header('location: settings.php');
     exit;
 } else {
     $tpl->assign('error', $error);
     $tpl->draw('settings');
Пример #29
0
function genThumbnail()
{
    // Make sure the parameters in the URL were generated by us.
    $sign = hash_hmac('sha256', $_GET['url'], $GLOBALS['salt']);
    if ($sign != $_GET['hmac']) {
        die('Naughty boy!');
    }
    // Let's see if we don't already have the image for this URL in the cache.
    $thumbname = hash('sha1', $_GET['url']) . '.jpg';
    if (is_file($GLOBALS['config']['CACHEDIR'] . '/' . $thumbname)) {
        // We have the thumbnail, just serve it:
        header('Content-Type: image/jpeg');
        echo file_get_contents($GLOBALS['config']['CACHEDIR'] . '/' . $thumbname);
        return;
    }
    // We may also serve a blank image (if service did not respond)
    $blankname = hash('sha1', $_GET['url']) . '.gif';
    if (is_file($GLOBALS['config']['CACHEDIR'] . '/' . $blankname)) {
        header('Content-Type: image/gif');
        echo file_get_contents($GLOBALS['config']['CACHEDIR'] . '/' . $blankname);
        return;
    }
    // Otherwise, generate the thumbnail.
    $url = $_GET['url'];
    $domain = parse_url($url, PHP_URL_HOST);
    if ($domain == 'flickr.com' || endsWith($domain, '.flickr.com')) {
        // Crude replacement to handle new flickr domain policy (They prefer www. now)
        $url = str_replace('http://flickr.com/', 'http://www.flickr.com/', $url);
        // Is this a link to an image, or to a flickr page ?
        $imageurl = '';
        if (endswith(parse_url($url, PHP_URL_PATH), '.jpg')) {
            // This is a direct link to an image. e.g. http://farm1.staticflickr.com/5/5921913_ac83ed27bd_o.jpg
            preg_match('!(http://farm\\d+\\.staticflickr\\.com/\\d+/\\d+_\\w+_)\\w.jpg!', $url, $matches);
            if (!empty($matches[1])) {
                $imageurl = $matches[1] . 'm.jpg';
            }
        } else {
            // Get the flickr html page.
            list($headers, $content) = get_http_response($url, 20);
            if (strpos($headers[0], '200 OK') !== false) {
                // flickr now nicely provides the URL of the thumbnail in each flickr page.
                preg_match('!<link rel=\\"image_src\\" href=\\"(.+?)\\"!', $content, $matches);
                if (!empty($matches[1])) {
                    $imageurl = $matches[1];
                }
                // In albums (and some other pages), the link rel="image_src" is not provided,
                // but flickr provides:
                // <meta property="og:image" content="http://farm4.staticflickr.com/3398/3239339068_25d13535ff_z.jpg" />
                if ($imageurl == '') {
                    preg_match('!<meta property=\\"og:image\\" content=\\"(.+?)\\"!', $content, $matches);
                    if (!empty($matches[1])) {
                        $imageurl = $matches[1];
                    }
                }
            }
        }
        if ($imageurl != '') {
            // Let's download the image.
            // Image is 240x120, so 10 seconds to download should be enough.
            list($headers, $content) = get_http_response($imageurl, 10);
            if (strpos($headers[0], '200 OK') !== false) {
                // Save image to cache.
                file_put_contents($GLOBALS['config']['CACHEDIR'] . '/' . $thumbname, $content);
                header('Content-Type: image/jpeg');
                echo $content;
                return;
            }
        }
    } elseif ($domain == 'vimeo.com') {
        // This is more complex: we have to perform a HTTP request, then parse the result.
        // Maybe we should deport this to JavaScript ? Example: http://stackoverflow.com/questions/1361149/get-img-thumbnails-from-vimeo/4285098#4285098
        $vid = substr(parse_url($url, PHP_URL_PATH), 1);
        list($headers, $content) = get_http_response('https://vimeo.com/api/v2/video/' . escape($vid) . '.php', 5);
        if (strpos($headers[0], '200 OK') !== false) {
            $t = unserialize($content);
            $imageurl = $t[0]['thumbnail_medium'];
            // Then we download the image and serve it to our client.
            list($headers, $content) = get_http_response($imageurl, 10);
            if (strpos($headers[0], '200 OK') !== false) {
                // Save image to cache.
                file_put_contents($GLOBALS['config']['CACHEDIR'] . '/' . $thumbname, $content);
                header('Content-Type: image/jpeg');
                echo $content;
                return;
            }
        }
    } elseif ($domain == 'ted.com' || endsWith($domain, '.ted.com')) {
        // The thumbnail for TED talks is located in the <link rel="image_src" [...]> tag on that page
        // http://www.ted.com/talks/mikko_hypponen_fighting_viruses_defending_the_net.html
        // <link rel="image_src" href="http://images.ted.com/images/ted/28bced335898ba54d4441809c5b1112ffaf36781_389x292.jpg" />
        list($headers, $content) = get_http_response($url, 5);
        if (strpos($headers[0], '200 OK') !== false) {
            // Extract the link to the thumbnail
            preg_match('!link rel="image_src" href="(http://images.ted.com/images/ted/.+_\\d+x\\d+\\.jpg)"!', $content, $matches);
            if (!empty($matches[1])) {
                // Let's download the image.
                $imageurl = $matches[1];
                // No control on image size, so wait long enough
                list($headers, $content) = get_http_response($imageurl, 20);
                if (strpos($headers[0], '200 OK') !== false) {
                    $filepath = $GLOBALS['config']['CACHEDIR'] . '/' . $thumbname;
                    file_put_contents($filepath, $content);
                    // Save image to cache.
                    if (resizeImage($filepath)) {
                        header('Content-Type: image/jpeg');
                        echo file_get_contents($filepath);
                        return;
                    }
                }
            }
        }
    } elseif ($domain == 'xkcd.com' || endsWith($domain, '.xkcd.com')) {
        // There is no thumbnail available for xkcd comics, so download the whole image and resize it.
        // http://xkcd.com/327/
        // <img src="http://imgs.xkcd.com/comics/exploits_of_a_mom.png" title="<BLABLA>" alt="<BLABLA>" />
        list($headers, $content) = get_http_response($url, 5);
        if (strpos($headers[0], '200 OK') !== false) {
            // Extract the link to the thumbnail
            preg_match('!<img src="(http://imgs.xkcd.com/comics/.*)" title="[^s]!', $content, $matches);
            if (!empty($matches[1])) {
                // Let's download the image.
                $imageurl = $matches[1];
                // No control on image size, so wait long enough
                list($headers, $content) = get_http_response($imageurl, 20);
                if (strpos($headers[0], '200 OK') !== false) {
                    $filepath = $GLOBALS['config']['CACHEDIR'] . '/' . $thumbname;
                    // Save image to cache.
                    file_put_contents($filepath, $content);
                    if (resizeImage($filepath)) {
                        header('Content-Type: image/jpeg');
                        echo file_get_contents($filepath);
                        return;
                    }
                }
            }
        }
    } else {
        // For all other domains, we try to download the image and make a thumbnail.
        // We allow 30 seconds max to download (and downloads are limited to 4 Mb)
        list($headers, $content) = get_http_response($url, 30);
        if (strpos($headers[0], '200 OK') !== false) {
            $filepath = $GLOBALS['config']['CACHEDIR'] . '/' . $thumbname;
            // Save image to cache.
            file_put_contents($filepath, $content);
            if (resizeImage($filepath)) {
                header('Content-Type: image/jpeg');
                echo file_get_contents($filepath);
                return;
            }
        }
    }
    // Otherwise, return an empty image (8x8 transparent gif)
    $blankgif = base64_decode('R0lGODlhCAAIAIAAAP///////yH5BAEKAAEALAAAAAAIAAgAAAIHjI+py+1dAAA7');
    file_put_contents($GLOBALS['config']['CACHEDIR'] . '/' . $blankname, $blankgif);
    // Also put something in cache so that this URL is not requested twice.
    header('Content-Type: image/gif');
    echo $blankgif;
}
Пример #30
0
 function SetMenuTemplate($tpl_name, $content)
 {
     if (endswith($tpl_name, '.tpl')) {
         return false;
     }
     $this->SetTemplate($tpl_name, $content);
     return true;
 }