10 return preg_match(
"/^([0-9A-Za-z_]+)$/i",
$sWidget);
20 $iNumArgs = func_num_args();
22 for($i=1; $i<$iNumArgs; $i++) {
23 $sValue = func_get_arg($i);
37 $sFilePath = trim($sFileName);
39 if(!file_exists($sFilePath))
43 $iPermissions = fileperms($sFilePath);
44 for($i=0, $offset = 0; $i<3; $i++, $offset += 3) {
46 for($j=0; $j<3; $j++) ($iPermissions >> ($j+$offset)) & 1 ? $iPerm += pow(2, $j) :
"";
47 $sPermissions = $iPerm . $sPermissions;
53 $bDir = is_dir($sFilePath);
54 if(is_readable($sFilePath))
$sResult = $bDir ?
"755" :
"644";
55 if(is_writable($sFilePath))
$sResult = $bDir ?
"777" :
"666";
56 if(!$bDir && is_executable($sFilePath))
$sResult =
"777";
71 $sWidgetFile =
$sWidget .
"/install/install.sql";
73 $sModuleDBPrefix = DB_PREFIX . strtoupper(substr(
$sWidget, 0, 1)) . substr(
$sWidget, 1);
76 $rHandler = fopen($sFileName,
"r");
77 while(!feof($rHandler)) {
78 $str = fgets($rHandler);
79 if($str[0]==
"" || $str[0]==
"#" || ($str[0] ==
"-" && $str[1] ==
"-"))
continue;
80 $str = str_replace(
"[module_db_prefix]", $sModuleDBPrefix, $str);
81 if( (strlen($str) > 5 ? strpos($str,
";", strlen($str) - 4) : strpos($str,
";")) )
107 $sBegin =
'//' .
$sWidget .
' begin';
108 $sAppsArray =
"\n" .
'aRayApps["' .
$sWidget .
'"] = new Array();' .
"\n";
109 $sAppTmpl =
'aRayApps["' .
$sWidget .
'"]["#app#"] = {"params": new Array(#params#), "top": #top#, "left": #left#, "width": #width#, "height": #height#, "resizable": #resizable#};' .
"\n";
116 $rHandle = fopen($sFileName,
"rt");
117 $sJSContents = fread($rHandle, filesize($sFileName)) ;
121 $sInsert = $sBegin . $sAppsArray;
127 $sApp = str_replace(
"#app#", $sAppName,
$sApp);
128 $sParams =
"'" . implode(
"', '",
$aModule[
'parameters']) .
"'";
129 $sApp = str_replace(
"#params#", $sParams,
$sApp);
135 if(!is_numeric($iWidth)) $iWidth =
$aModule[
'minSize'][
'width'];
138 if(!is_numeric($iHeight)) $iHeight =
$aModule[
'minSize'][
'height'];
140 $sApp = str_replace(
"#width#", $iWidth,
$sApp);
141 $sApp = str_replace(
"#height#", $iHeight,
$sApp);
142 $sResizable = (
$aModule[
'vResizable'] ||
$aModule[
'hResizable']) ?
"1" :
"0";
143 $sApp = str_replace(
"#resizable#", $sResizable,
$sApp);
146 if(
empty($sApps))
return array(
'value' =>
"",
'status' => SUCCESS_VAL);
148 $sInsert .= $sApps . $sEnd;
151 $iInsertBegin = strpos($sJSContents, $sBegin);
152 $iInsertEnd = strpos($sJSContents, $sEnd) + strlen($sEnd);
153 if($iInsertBegin ===
false) $sJSContents .= $sInsert .
'\n';
154 else $sJSContents = substr($sJSContents, 0, $iInsertBegin) . $sInsert . substr($sJSContents, $iInsertEnd);
158 if(($rHandle = @fopen($sFileName,
"wt")) !==
false) {
159 $bResult = (fwrite($rHandle, $sJSContents) !==
false);
164 return array(
'value' => $sValue,
'status' =>
$bResult ? SUCCESS_VAL : FAILED_VAL);
184 $iFilesCount = count($aFiles[
'files']);
185 if($iFilesCount == 0)
return array(
'value' =>
getError(
$aErrorCodes[7], $sDir),
'status' => FAILED_VAL,
'contents' =>
"");
189 if($aFileContents[
'status'] == FAILED_VAL)
return array(
'value' => $aFileContents[
'value'],
'status' => FAILED_VAL,
'contents' =>
"");
190 $aContents = $aFileContents[
'contents'];
193 $sCurrent = isset($aContents[FILE_DEFAULT_KEY]) && in_array($aContents[FILE_DEFAULT_KEY], $aFiles[
"files"]) ? $aContents[FILE_DEFAULT_KEY] : $aFiles[
"current"];
195 $aEnabledFiles[] = $sCurrent;
198 for($i=0; $i<$iFilesCount; $i++) {
199 $sEnabled = isset($aContents[$aFiles[
"files"][$i]]) ? $aContents[$aFiles[
"files"][$i]] : TRUE_VAL;
201 $sEnabled = in_array($aFiles[
"files"][$i], $aEnabledFiles) ? TRUE_VAL : FALSE_VAL;
210 if(($rHandle = @fopen($sFileName,
"wt")) !==
false) {
217 return array(
'value' => $sValue,
'status' =>
$bResult ? SUCCESS_VAL : FAILED_VAL,
'contents' =>
$sContents);
246 if(($rHandle = @fopen($sFileName,
"wt")) !==
false) {
256 return array(
'value' => $sValue,
'status' =>
$bResult ? SUCCESS_VAL : FAILED_VAL);
271 if(!file_exists($sFileName))
return array(
'value' =>
getError(
$aErrorCodes[1],
$sFile),
'status' => FAILED_VAL,
'contents' => $bArray ? array() :
"");
272 $rHandle = fopen($sFileName,
"rt");
273 $iFileSize = filesize($sFileName);
274 $sContents = $iFileSize > 0 ? fread($rHandle, filesize($sFileName)) :
makeGroup(
"",
"items");
278 return array(
'value' =>
"",
'status' => SUCCESS_VAL,
'contents' => $bArray ? $aContents :
$sContents);
290 $aRightExtensions = array(
"swf",
"xml");
292 if($rDirHandle = opendir($sFolderPath))
293 while (
false !== (
$sFile = readdir($rDirHandle))) {
301 function smartReadFile($sPath, $sFilename =
'', $sMimeType =
'application/octet-stream', $iCacheAge = 0, $sCachePrivacy =
'public')
303 if (!file_exists($sPath)) {
304 header (
"HTTP/1.0 404 Not Found");
308 $fp = @fopen($sPath,
'rb');
310 $size = filesize($sPath);
315 header(
'Content-type: ' . $sMimeType);
316 header(
'Cache-Control: ' . $sCachePrivacy .
', must-revalidate, max-age=' . $iCacheAge);
317 header(
"Accept-Ranges: 0-$length");
319 header(
'Content-Disposition: inline; filename=' . $sFilename);
321 if (isset($_SERVER[
'HTTP_RANGE'])) {
326 list(, $range) = explode(
'=', $_SERVER[
'HTTP_RANGE'], 2);
327 if (strpos($range,
',') !==
false) {
328 header(
'HTTP/1.1 416 Requested Range Not Satisfiable');
329 header(
"Content-Range: bytes $start-$end/$size");
333 $c_start = $size - substr($range, 1);
335 $range = explode(
'-', $range);
336 $c_start = $range[0];
337 $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
339 $c_end = ($c_end > $end) ? $end : $c_end;
340 if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
341 header(
'HTTP/1.1 416 Requested Range Not Satisfiable');
342 header(
"Content-Range: bytes $start-$end/$size");
347 $length = $end - $start + 1;
349 header(
'HTTP/1.1 206 Partial Content');
351 header(
"Content-Range: bytes $start-$end/$size");
352 header(
"Content-Length: ".$length);
356 while(!feof($fp) && ($p = ftell($fp)) <= $end) {
358 if ($p + $buffer > $end) {
359 $buffer = $end - $p + 1;
362 echo fread($fp, $buffer);