moodle 2.7 filemanager issue - moodle

I'm working with a file manager on a form in moodle 2.7.
The save and upload files features are fine.
I need to determine if the file manager object currently holds a file.
This is what I've tried:
if($draftitemid = file_get_submitted_draft_itemid('attachments')){
$A=1;
}else{
$A=2;
}
But it always return 1;

[SOLVED]
Just after saveing the form files and before update record I use:
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, $component,$path, $itemid,'',false);
if(!empty($files){
$A=1;//have files
}else{
$A=2;//No files
}
this work for me.

This line:
$draftitemid = file_get_submitted_draft_itemid('attachments')
Sets $draftitemid to the value returned by file_get_submitted_draft_itemid('attachments'). Setting a variable always evaluates to true when in an if statement. Thus, this is a typo and what you want is:
if($draftitemid == file_get_submitted_draft_itemid('attachments')){

Related

Comment lines in .sln file

I'm trying to comment some lines in .sln file temporarly, but I receive error:
"The selected file is a solution file, but appears to be corrupted and cannot be opened"
According to this blog comments are done by "#", but when I comment out every line in GlobalSection (section about Team Foundation Server source control binding) I get above error. Is there any other way to comment out lines in .sln ?
EDIT - section of which I want to comment out:
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 2
SccEnterpriseProvider = {4BA58AB2-18FA-4D8F-95F4-32FFDF27D184C}
SccTeamFoundationServer = http://oxy:8080/tfs/projects
SccLocalPath0 = .
SccProjectUniqueName1 = Accounts\\Accounts.vbproj
SccProjectName1 = Accounts
SccLocalPath1 = Accounts
EndGlobalSection
I tried this, but not working:
# GlobalSection(TeamFoundationVersionControl) = preSolution
# SccNumberOfProjects = 2
# SccEnterpriseProvider = {4BA58AB2-18FA-4D8F-95F4-32FFDF27D184C}
# SccTeamFoundationServer = http://oxy:8080/tfs/projects
# SccLocalPath0 = .
# SccProjectUniqueName1 = Accounts\\Accounts.vbproj
# SccProjectName1 = Accounts
# SccLocalPath1 = Accounts
# EndGlobalSection
P.S.: I tried a single line comment using "#" - that works. And removing whole section also works. But I don't want to delete It, just comment It.
I don't think there is an official definition of comments in the .sln file. It depends on the parser.
In principle, a .sln file is a declarative file, based on the keywords (ProjectSection, EndGlobalSection) and the end-line char. I don't see a uniform format description.
MSBuild
So we don't know how Visual Studio reads the .sln file, but you can see in the msbuild code that any line that doesn't start with one of the const words will not enter to the object:
while ((str = ReadLine()) != null)
{
if (str.StartsWith("Project(", StringComparison.Ordinal))
{
ParseProject(str);
}
else if (str.StartsWith("GlobalSection(NestedProjects)", StringComparison.Ordinal))
{
ParseNestedProjects();
}
else if (str.StartsWith("GlobalSection(SolutionConfigurationPlatforms)", StringComparison.Ordinal))
{
ParseSolutionConfigurations();
}
else if (str.StartsWith("GlobalSection(ProjectConfigurationPlatforms)", StringComparison.Ordinal))
{
rawProjectConfigurationsEntries = ParseProjectConfigurations();
}
else if (str.StartsWith("VisualStudioVersion", StringComparison.Ordinal))
{
_currentVisualStudioVersion = ParseVisualStudioVersion(str);
}
else
{
// No other section types to process at this point, so just ignore the line
// and continue.
}
}
Visual Studio
According to this blog comments are done by "#"
That is not accurate. You can add lines with any text where you want, without the #, and the file will stay correct.
So, in Visual Studio, you currently don't know the official format, but you need to "break" the current format.
You can try changing the keywords, such as adding a letter to them at the beginning.
From what I've tried, special characters (such as #, %) don't break your keywords.

Typoscript: how do I add a parameter to all links in the RTE?

I want to add a parameter to all links entered in the RTE by the user.
My initial idea was to do this:
lib.parseFunc_RTE.tags.link {
typolink.parameter.append = TEXT
typolink.parameter.append.value = ?flavor=lemon
}
So for example:
http://domain.com/mypage.php
becomes
http://domain.com/mypage.php?flavor=lemon
which sounds great -- as long as the link does not already have a query string!
In that case, I obviously end up with two question marks in the URL
So for example:
http://domain.com/prefs.php?id=1234&unit=moon&qty=300
becomes
http://domain.com/prefs.php?id=1234&unit=moon&qty=300?flavor=lemon
Is there any way to add my parameter with the correct syntax, depending on whether the URL already has a query string or not? Thanks!
That would be the solution:
lib.parseFunc_RTE.tags.link {
typolink.additionalParams = &flavor=lemon
}
Note that it has to start with an &, typo3 then generates a valid link. The parameter in the link also will be parsed with realURL if configured accordingly.
Edit: The above solution only works for internal links as described in the documentation https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Typolink/Index.html
The only solution that works for all links that I see is to use a userFunc
lib.parseFunc_RTE.tags.link {
typolink.userFunc = user_addAdditionalParams
}
Then you need to create a php script and include in your TS with:
includeLibs.rteScript = path/to/yourScript.php
Keep in mind that includeLibs is outdated, so if you are using TYPO3 8.x (and probably 7.3+) you will need to create a custom extension with just a few files
<?php
function user_addAdditionalParams($finalTagParts) {
// modify the url in $finalTagParts['url']
// $finalTagParts['TYPE'] is an indication of link-kind: mailto, url, file, page, you can use it to check if you need to append the new params
switch ($finalTagParts['TYPE']) {
case 'url':
case 'file':
$parts = explode('#', $finalTagParts['url']);
$finalTagParts['url'] = $parts[0]
. (strpos($parts[0], '?') === false ? '?' : '&')
. 'newParam=test&newParam=test2'
. ($parts[1] ? '#' . $parts[1] : '');
break;
}
return '<a href="' . $finalTagParts['url'] . '"' .
$finalTagParts['targetParams'] .
$finalTagParts['aTagParams'] . '>'
}
PS: i have not tested the actual php code, so it can have some errors. If you have troubles, try debugging the $finalTagParts variable
Test whether the "?" character is already in the URL and append either "?" or "&", then append your key-value pair. There's a CASE object available in the TypoScript Reference, with an example you can modify for your purpose.
For anyone interested, here's a solution that worked for me using the replacement function of Typoscript. Hope this helps.
lib.parseFunc_RTE.tags.link {
# Start by "replacing" the whole URL by itself + our string
# For example: http://domain.com/?id=100 becomes http://domain.com/?id=100?flavor=lemon
# For example: http://domain.com/index.html becomes http://domain.com/index.html?flavor=lemon
typolink.parameter.stdWrap.replacement.10 {
#this matches the whole URL
search = #^(.*)$#i
# this replaces it with itself (${1}) + our string
replace =${1}?flavor=lemon
# in this case we want to use regular expressions
useRegExp = 1
}
# After the first replacement is done, we simply replace
# the first '?' by '?' and all others by '&'
# the use of Option Split allow this
typolink.parameter.stdWrap.replacement.20 {
search = ?
replace = ? || & || &
useOptionSplitReplace = 1
}
}

ZF2 Append value to array in php file with Zend\Config\Factory

I try to add new value to array in php file with Zend\Config\Factory:
public function testFunc($testParam)
{
$testArray = $this->testFunc1($testParam);
if(!is_null($testArray[1])) {
foreach ($testArray[1] as $array) {
$this->testFunc($array);
}
}
$filename = getcwd() . '/data/config/config.php';
$configFile = \Zend\Config\Factory::fromFile($filename);
$configFile[] = $testArray[0];
if(!\Zend\Config\Factory::toFile($filename, $configFile)) {
throw new Exception\RuntimeException("Can't put content to $filename.");
}
return true;
}
The problem is such that in $filename file saves only value from first function call and not from recursion.
[UPDATE]
I debug \Zend\Config\Factory::fromFile and found if I wanna to load php file, function load file that:
........
$config = include $filepath;
in recursion \Zend\Config\Factory::toFile update my php file(i checked config.php file) and then in first function call \Zend\Config\Factory::fromFile get again php file without changes and overwrite config.php. As a consequence , is recorded only value from first function call in config.php.

Powershell > File not found

The file is present but Powershell keeps saying file is missing. I have no idea. I looked at the permissions and current user has full rights.
$csvDocLib = "C:\\PowerShell\TestLib.csv"
$csvDocSet = "C:\\PowerShell\TestDocSet.csv"
the first csv is found and code works but down the code line i need the second csv and it said not found but it's in same directory. I tried renaming and still the same.
if([IO.File]::Exists($csvDocSet) -ne $false)
{
write-host $csvDocSet " not found"
exit
}
Eliminate the double \\ e.g.:
$csvDocLib = "C:\\PowerShell\TestLib.csv"
$csvDocSet = "C:\\PowerShell\TestDocSet.csv"
should be:
$csvDocLib = "C:\PowerShell\TestLib.csv"
$csvDocSet = "C:\PowerShell\TestDocSet.csv"

Typo3 staticpub extension not publishing static files

I installed staticpub extension,but its not working.
this is my crawler configuration
tx_crawler.crawlerCfg.paramSets.test = &L=[0-5]
tx_crawler.crawlerCfg.paramSets.test {
cHash = 1
procInstrFilter = tx_indexedsearch_reindex, tx_indexedsearch_crawler
}
tx_crawler.crawlerCfg.paramSets {
staticpub = &L=[|_TABLE:pages_language_overlay;_FIELD:sys_language_uid]
staticpub.procInstrFilter = tx_staticpub_publish
}
I updated following lines in localconf.php also i created staticpub directory in root of my website.
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['staticpub']['publishDir'] = '_staticpub_/';
I found not record in tx_staticpub_pages table. Also no file in staticpub directory.
Please don't use that feature! It's silly and useless and has been removed from TYPO3 for the upcoming version 4.6.
Please use e.g. EXT:nc_staticfilecache