/** * Generate an OPML file to export the feeds. * * @copyright Heavily based on a function from FreshRSS. */ function opml_export($feeds) { $tags = array(); foreach ($feeds as $key => $feed) { if (empty($feed['tags'])) { $tags['untagged'][] = $key; continue; } foreach ($feed['tags'] as $tag) { $tags[$tag][] = $key; } } $now = new Datetime(); $txt = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL; $txt .= '<opml version="2.0">' . PHP_EOL; $txt .= "\t" . '<head>' . PHP_EOL; $txt .= "\t\t" . '<title>Export of Freeder feeds</title>' . PHP_EOL; $txt .= "\t\t" . '<dateCreated>' . $now->format(DateTime::RFC822) . '</dateCreated>' . PHP_EOL; $txt .= "\t" . '</head>' . PHP_EOL; $txt .= "\t" . '<body>' . PHP_EOL; foreach ($tags as $tag => $id_feeds) { $txt .= "\t\t" . '<outline text="' . $tag . '">' . PHP_EOL; foreach ($id_feeds as $id_feed) { $website = multiarray_search('rel', 'alternate', $feeds[$id_feed]['links'], ''); if (!empty($website)) { $website = 'htmlUrl="' . htmlspecialchars($website['href'], ENT_COMPAT, 'UTF-8') . '"'; } $txt .= "\t\t\t" . '<outline text="' . htmlspecialchars($feeds[$id_feed]['title'], ENT_COMPAT, 'UTF-8') . '" type="rss" xmlUrl="' . htmlspecialchars($feeds[$id_feed]['url'], ENT_COMPAT, 'UTF-8') . '" ' . $website . ' description="' . htmlspecialchars($feeds[$id_feed]['description'], ENT_COMPAT, 'UTF-8') . '" />' . PHP_EOL; } $txt .= "\t\t" . '</outline>' . PHP_EOL; } $txt .= "\t" . '</body>' . PHP_EOL; $txt .= '</opml>'; return $txt; }
function cs_catsort($array, $id = 0) { if (empty($array)) { return 0; } $count = count($array); $result = array(); $alrdy_looped = array(); $subid = 0; $order = 1; for ($i = 0; $i < $count; $i++) { if (empty($array[$i]['categories_subid'])) { $array[$i]['layer'] = 0; $result[] = $array[$i]; } else { if ($array[$i]['categories_subid'] != $subid) { $order = 1; $subid = $array[$i]['categories_subid']; } $pos = multiarray_search($result, 'categories_id', $array[$i]['categories_subid']); if ($pos === false) { if (in_array($array[$i], $alrdy_looped)) { $array[$i]['layer'] = 0; $result[] = $array[$i]; continue; } $count++; $array[] = $array[$i]; $alrdy_looped[] = $array[$i]; continue; } $array[$i]['layer'] = $result[$pos]['layer'] + 1; $result = array_merge(array_slice($result, 0, $pos + $order), array($array[$i]), array_slice($result, $pos + $order)); $order++; } } $start = 0; if (!empty($id)) { // Get right (sub)categories $count = count($result); for ($i = 0; $i < $count; $i++) { if ($id == $result[$i]['categories_id']) { $layer = $result[$i]['layer']; $name = $result[$i]['categories_name']; $start = $i; } elseif (isset($layer) && $result[$i]['layer'] <= $layer) { $end = $i; break; } } $end = !empty($end) ? $end - $start : $count; $result = array_slice($result, $start, $end); } return $result; }
function cs_foldersort($array, $id = 0) { if (empty($array)) { return 0; } $count = count($array); $result = array(); $subid = 0; $order = 1; for ($i = 0; $i < $count; $i++) { if (empty($array[$i]['sub_id'])) { $array[$i]['layer'] = 0; $result[] = $array[$i]; } else { if ($array[$i]['sub_id'] != $subid) { $order = 1; $subid = $array[$i]['sub_id']; } $pos = multiarray_search($result, 'folders_id', $array[$i]['sub_id']); $array[$i]['layer'] = $result[$pos]['layer'] + 1; $result = array_merge(array_slice($result, 0, $pos + $order), array($array[$i]), array_slice($result, $pos + $order)); $order++; } } if (!empty($id)) { $count = count($result); for ($i = 0; $i < $count; $i++) { if ($id == $result[$i]['folders_id']) { $layer = $result[$i]['layer']; $name = $result[$i]['folders_name']; $start = $i; } elseif (isset($layer) && $result[$i]['layer'] <= $layer) { $end = $i; break; } } $end = !empty($end) ? $end - $start : $count; $result = array_slice($result, $start, $end); } return $result; }
/** * Function that initialises all data and call other functions to load default view. * * @access protected * @param string $templatename * @param string $screenname * @param string $editfile * @param bool $showsummary * @return */ protected function _initialise($templatename, $screenname, $editfile, $showsummary = true) { App()->getClientScript()->reset(); $clang = $this->getController()->lang; Yii::app()->loadHelper('surveytranslator'); Yii::app()->loadHelper('admin/template'); $files = $this->_initfiles($templatename); $cssfiles = $this->_initcssfiles(); // Standard Support Files // These files may be edited or saved $supportfiles[] = array('name' => 'print_img_radio.png'); $supportfiles[] = array('name' => 'print_img_checkbox.png'); // Standard screens // Only these may be viewed $screens[] = array('name' => $clang->gT('Survey List Page'), 'id' => 'surveylist'); $screens[] = array('name' => $clang->gT('Welcome Page'), 'id' => 'welcome'); $screens[] = array('name' => $clang->gT('Question Page'), 'id' => 'question'); $screens[] = array('name' => $clang->gT('Completed Page'), 'id' => 'completed'); $screens[] = array('name' => $clang->gT('Clear All Page'), 'id' => 'clearall'); $screens[] = array('name' => $clang->gT('Register Page'), 'id' => 'register'); $screens[] = array('name' => $clang->gT('Load Page'), 'id' => 'load'); $screens[] = array('name' => $clang->gT('Save Page'), 'id' => 'save'); $screens[] = array('name' => $clang->gT('Print answers page'), 'id' => 'printanswers'); $screens[] = array('name' => $clang->gT('Printable survey page'), 'id' => 'printablesurvey'); // Page display blocks $SurveyList = array('startpage.pstpl', 'surveylist.pstpl', 'endpage.pstpl'); $Welcome = array('startpage.pstpl', 'welcome.pstpl', 'privacy.pstpl', 'navigator.pstpl', 'endpage.pstpl'); $Question = array('startpage.pstpl', 'survey.pstpl', 'startgroup.pstpl', 'groupdescription.pstpl', 'question.pstpl', 'endgroup.pstpl', 'navigator.pstpl', 'endpage.pstpl'); $CompletedTemplate = array('startpage.pstpl', 'assessment.pstpl', 'completed.pstpl', 'endpage.pstpl'); $Clearall = array('startpage.pstpl', 'clearall.pstpl', 'endpage.pstpl'); $Register = array('startpage.pstpl', 'survey.pstpl', 'register.pstpl', 'endpage.pstpl'); $Save = array('startpage.pstpl', 'save.pstpl', 'endpage.pstpl'); $Load = array('startpage.pstpl', 'load.pstpl', 'endpage.pstpl'); $printtemplate = array('startpage.pstpl', 'printanswers.pstpl', 'endpage.pstpl'); $printablesurveytemplate = array('print_survey.pstpl', 'print_group.pstpl', 'print_question.pstpl'); $file_version = "LimeSurvey template editor " . Yii::app()->getConfig('versionnumber'); Yii::app()->session['s_lang'] = Yii::app()->session['adminlang']; $templatename = sanitize_dirname($templatename); $screenname = autoUnescape($screenname); // Checks if screen name is in the list of allowed screen names if (multiarray_search($screens, 'id', $screenname) === false) { $this->getController()->error('Invalid screen name'); } if (!isset($action)) { $action = sanitize_paranoid_string(returnGlobal('action')); } if (!isset($subaction)) { $subaction = sanitize_paranoid_string(returnGlobal('subaction')); } if (!isset($newname)) { $newname = sanitize_dirname(returnGlobal('newname')); } if (!isset($copydir)) { $copydir = sanitize_dirname(returnGlobal('copydir')); } if (is_file(Yii::app()->getConfig('usertemplaterootdir') . '/' . $templatename . '/question_start.pstpl')) { $files[] = array('name' => 'question_start.pstpl'); $Question[] = 'question_start.pstpl'; } $availableeditorlanguages = array('bg', 'cs', 'de', 'dk', 'en', 'eo', 'es', 'fi', 'fr', 'hr', 'it', 'ja', 'mk', 'nl', 'pl', 'pt', 'ru', 'sk', 'zh'); $extension = substr(strrchr($editfile, "."), 1); if ($extension == 'css' || $extension == 'js') { $highlighter = $extension; } else { $highlighter = 'html'; } if (in_array(Yii::app()->session['adminlang'], $availableeditorlanguages)) { $codelanguage = Yii::app()->session['adminlang']; } else { $codelanguage = 'en'; } $templates = getTemplateList(); if (!isset($templates[$templatename])) { $templatename = Yii::app()->getConfig('defaulttemplate'); } $normalfiles = array("DUMMYENTRY", ".", "..", "preview.png"); foreach ($files as $fl) { $normalfiles[] = $fl["name"]; } foreach ($cssfiles as $fl) { $normalfiles[] = $fl["name"]; } // Some global data $aData['sitename'] = Yii::app()->getConfig('sitename'); $siteadminname = Yii::app()->getConfig('siteadminname'); $siteadminemail = Yii::app()->getConfig('siteadminemail'); // Set this so common.php doesn't throw notices about undefined variables $thissurvey['active'] = 'N'; // FAKE DATA FOR TEMPLATES $thissurvey['name'] = $clang->gT("Template Sample"); $thissurvey['description'] = "<p>" . $clang->gT('This is a sample survey description. It could be quite long.') . "</p>" . "<p>" . $clang->gT("But this one isn't.") . "<p>"; $thissurvey['welcome'] = "<p>" . $clang->gT('Welcome to this sample survey') . "<p>" . "<p>" . $clang->gT('You should have a great time doing this') . "<p>"; $thissurvey['allowsave'] = "Y"; $thissurvey['active'] = "Y"; $thissurvey['tokenanswerspersistence'] = "Y"; $thissurvey['templatedir'] = $templatename; $thissurvey['format'] = "G"; $thissurvey['surveyls_url'] = "http://www.limesurvey.org/"; $thissurvey['surveyls_urldescription'] = $clang->gT("Some URL description"); $thissurvey['usecaptcha'] = "A"; $percentcomplete = makegraph(6, 10); $groupname = $clang->gT("Group 1: The first lot of questions"); $groupdescription = $clang->gT("This group description is fairly vacuous, but quite important."); $navigator = $this->getController()->render('/admin/templates/templateeditor_navigator_view', array('screenname' => $screenname, 'clang' => $clang), true); $completed = $this->getController()->render('/admin/templates/templateeditor_completed_view', array('clang' => $clang), true); $assessments = $this->getController()->render('/admin/templates/templateeditor_assessments_view', array('clang' => $clang), true); $printoutput = $this->getController()->render('/admin/templates/templateeditor_printoutput_view', array('clang' => $clang), true); $totalquestions = '10'; $surveyformat = 'Format'; $notanswered = '5'; $privacy = ''; $surveyid = '1295'; $token = 1234567; $templatedir = getTemplatePath($templatename); $templateurl = getTemplateURL($templatename); // Save these variables in an array $aData['thissurvey'] = $thissurvey; $aData['percentcomplete'] = $percentcomplete; $aData['groupname'] = $groupname; $aData['groupdescription'] = $groupdescription; $aData['navigator'] = $navigator; $aData['help'] = $clang->gT("This is some help text."); $aData['surveyformat'] = $surveyformat; $aData['totalquestions'] = $totalquestions; $aData['completed'] = $completed; $aData['notanswered'] = $notanswered; $aData['privacy'] = $privacy; $aData['surveyid'] = $surveyid; $aData['sid'] = $surveyid; $aData['token'] = $token; $aData['assessments'] = $assessments; $aData['printoutput'] = $printoutput; $aData['templatedir'] = $templatedir; $aData['templateurl'] = $templateurl; $aData['templatename'] = $templatename; $aData['screenname'] = $screenname; $aData['editfile'] = $editfile; $myoutput[] = ""; switch ($screenname) { case 'surveylist': unset($files); $surveylist = array("nosid" => $clang->gT("You have not provided a survey identification number"), "contact" => sprintf($clang->gT("Please contact %s ( %s ) for further assistance."), Yii::app()->getConfig("siteadminname"), Yii::app()->getConfig("siteadminemail")), "listheading" => $clang->gT("The following surveys are available:"), "list" => $this->getController()->render('/admin/templates/templateeditor_surveylist_view', array(), true)); $aData['surveylist'] = $surveylist; $myoutput[] = ""; foreach ($SurveyList as $qs) { $files[] = array("name" => $qs); $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/{$qs}", $aData)); } break; case 'question': unset($files); foreach ($Question as $qs) { $files[] = array("name" => $qs); } $myoutput[] = $this->getController()->render('/admin/templates/templateeditor_question_meta_view', array('clang' => $clang), true); $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/startpage.pstpl", $aData)); $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/survey.pstpl", $aData)); $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/startgroup.pstpl", $aData)); $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/groupdescription.pstpl", $aData)); $question = array('all' => $clang->gT("How many roads must a man walk down?"), 'text' => $clang->gT("How many roads must a man walk down?"), 'code' => '1a', 'help' => 'helpful text', 'mandatory' => $clang->gT("*"), 'man_class' => ' mandatory', 'man_message' => '', 'valid_message' => '', 'file_valid_message' => '', 'essentials' => 'id="question1"', 'class' => 'list-radio', 'input_error_class' => '', 'number' => '1', 'type' => 'L'); $aData['question'] = $question; $answer = $this->getController()->render('/admin/templates/templateeditor_question_answer_view', array('clang' => $clang), true); $aData['answer'] = $answer; $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/question.pstpl", $aData)); $answer = $this->getController()->render('/admin/templates/templateeditor_question_answer_view', array('alt' => true, 'clang' => $clang), true); $aData['answer'] = $answer; $question = array('all' => $clang->gT("Please explain something in detail:"), 'text' => $clang->gT('Please explain something in detail:'), 'code' => '2a', 'help' => '', 'mandatory' => '', 'man_message' => '', 'valid_message' => '', 'file_valid_message' => '', 'essentials' => 'id="question2"', 'class' => 'text-long', 'man_class' => 'mandatory', 'input_error_class' => '', 'number' => '2', 'type' => 'T'); $aData['question'] = $question; $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/question.pstpl", $aData)); $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/endgroup.pstpl", $aData)); $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/navigator.pstpl", $aData)); $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/endpage.pstpl", $aData)); break; case 'welcome': unset($files); $myoutput[] = ""; foreach ($Welcome as $qs) { $files[] = array("name" => $qs); $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/{$qs}", $aData)); } break; case 'register': unset($files); foreach ($Register as $qs) { $files[] = array("name" => $qs); } $myoutput[] = templatereplace(file_get_contents("{$templatedir}/startpage.pstpl"), array(), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/survey.pstpl"), array(), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/register.pstpl"), array(), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/endpage.pstpl"), array(), $aData); $myoutput[] = "\n"; break; case 'save': unset($files); foreach ($Save as $qs) { $files[] = array("name" => $qs); } $myoutput[] = templatereplace(file_get_contents("{$templatedir}/startpage.pstpl"), array(), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/save.pstpl"), array(), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/endpage.pstpl"), array(), $aData); $myoutput[] = "\n"; break; case 'load': unset($files); foreach ($Load as $qs) { $files[] = array("name" => $qs); } $myoutput[] = templatereplace(file_get_contents("{$templatedir}/startpage.pstpl"), array(), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/load.pstpl"), array(), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/endpage.pstpl"), array(), $aData); $myoutput[] = "\n"; break; case 'clearall': unset($files); foreach ($Clearall as $qs) { $files[] = array("name" => $qs); } $myoutput[] = templatereplace(file_get_contents("{$templatedir}/startpage.pstpl"), array(), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/clearall.pstpl"), array(), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/endpage.pstpl"), array(), $aData); $myoutput[] = "\n"; break; case 'completed': unset($files); $myoutput[] = ""; foreach ($CompletedTemplate as $qs) { $files[] = array("name" => $qs); $myoutput = array_merge($myoutput, doreplacement(getTemplatePath($templatename) . "/{$qs}", $aData)); } break; case 'printablesurvey': unset($files); foreach ($printablesurveytemplate as $qs) { $files[] = array("name" => $qs); } $questionoutput = array(); foreach (file("{$templatedir}/print_question.pstpl") as $op) { $questionoutput[] = templatereplace($op, array('QUESTION_NUMBER' => '1', 'QUESTION_CODE' => 'Q1', 'QUESTION_MANDATORY' => $clang->gT('*'), 'QUESTION_SCENARIO' => 'Only answer this if certain conditions are met.', 'QUESTION_CLASS' => ' mandatory list-radio', 'QUESTION_TYPE_HELP' => $clang->gT('Please choose *only one* of the following:'), 'QUESTION_MAN_MESSAGE' => '', 'QUESTION_VALID_MESSAGE' => '', 'QUESTION_FILE_VALID_MESSAGE' => '', 'QUESTION_TEXT' => $clang->gT('This is a sample question text. The user was asked to pick an entry.'), 'QUESTIONHELP' => $clang->gT('This is some help text for this question.'), 'ANSWER' => $this->getController()->render('/admin/templates/templateeditor_printablesurvey_quesanswer_view', array('templateurl' => $templateurl, 'clang' => $clang), true)), $aData); } $groupoutput = array(); $groupoutput[] = templatereplace(file_get_contents("{$templatedir}/print_group.pstpl"), array('QUESTIONS' => implode(' ', $questionoutput)), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/print_survey.pstpl"), array('GROUPS' => implode(' ', $groupoutput), 'FAX_TO' => $clang->gT("Please fax your completed survey to:") . " 000-000-000", 'SUBMIT_TEXT' => $clang->gT("Submit your survey."), 'HEADELEMENTS' => getPrintableHeader(), 'SUBMIT_BY' => sprintf($clang->gT("Please submit by %s"), date('d.m.y')), 'THANKS' => $clang->gT('Thank you for completing this survey.'), 'END' => $clang->gT('This is the survey end message.')), $aData); break; case 'printanswers': unset($files); foreach ($printtemplate as $qs) { $files[] = array("name" => $qs); } $myoutput[] = templatereplace(file_get_contents("{$templatedir}/startpage.pstpl"), array(), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/printanswers.pstpl"), array('ANSWERTABLE' => $printoutput), $aData); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/endpage.pstpl"), array(), $aData); $myoutput[] = "\n"; break; } $myoutput[] = "</html>"; if (is_array($files)) { $match = 0; foreach ($files as $f) { if ($editfile == $f["name"]) { $match = 1; } } foreach ($cssfiles as $f) { if ($editfile == $f["name"]) { $match = 1; } } if ($match == 0) { if (count($files) > 0) { $editfile = $files[0]["name"]; } else { $editfile = ""; } } } // Get list of 'otherfiles' $otherfiles = array(); if ($handle = opendir($templatedir)) { while (false !== ($file = readdir($handle))) { if (!array_search($file, $normalfiles)) { if (!is_dir($templatedir . DIRECTORY_SEPARATOR . $file)) { $otherfiles[] = array("name" => $file); } } } closedir($handle); } $aData['clang'] = $this->getController()->lang; $aData['codelanguage'] = $codelanguage; $aData['highlighter'] = $highlighter; $aData['screens'] = $screens; $aData['templatename'] = $templatename; $aData['templates'] = $templates; $aData['editfile'] = $editfile; $aData['screenname'] = $screenname; $aData['tempdir'] = Yii::app()->getConfig('tempdir'); $aData['usertemplaterootdir'] = Yii::app()->getConfig('usertemplaterootdir'); $aViewUrls['templateeditorbar_view'][] = $aData; if ($showsummary) { $aViewUrls = array_merge($aViewUrls, $this->_templatesummary($templatename, $screenname, $editfile, $templates, $files, $cssfiles, $otherfiles, $myoutput)); } App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . 'admin_core.js'); return $aViewUrls; }
/** * Check wether an entry has the tag `$tag` (true) or not (false). */ function is_tag($tag, $entry) { $tags = array_merge($entry['tags'], $entry['system_tags']); $res = multiarray_search('name', $tag, $tags, false); if (!empty($res)) { return true; } else { return false; } }
/** * Function that initialises all data and call other functions to load default view. * * @access protected * @param string $templatename * @param string $screenname * @param string $editfile * @param bool $showsummary * @return */ protected function _initialise($templatename, $screenname, $editfile, $showsummary = true, $useindex = false) { // LimeSurvey style global $oEditedTemplate; $oEditedTemplate = Template::model()->getTemplateConfiguration($templatename); // In survey mode, bootstrap is loaded via the app init. // From template editor, we just add the bootstrap files to the js/css to load for template_helper::templatereplace() if ($oEditedTemplate->cssFramework == 'bootstrap') { // Core templates (are published only if exists) $oEditedTemplate->config->files->css->filename[] = "../../styles-public/bootstrap-for-template-editor.css"; $oEditedTemplate->config->files->js->filename[] = "../../scripts/bootstrap-for-template-editor.js"; // User templates (are published only if exists) $oEditedTemplate->config->files->css->filename[] = "../../../styles-public/bootstrap-for-template-editor.css"; $oEditedTemplate->config->files->js->filename[] = "../../../scripts/bootstrap-for-template-editor.js"; } //App()->getClientScript()->reset(); Yii::app()->loadHelper('surveytranslator'); Yii::app()->loadHelper('admin/template'); $files = $this->_initfiles($templatename); $cssfiles = $this->_initcssfiles($oEditedTemplate); // Standard Support Files // These files may be edited or saved $supportfiles[] = array('name' => 'print_img_radio.png'); $supportfiles[] = array('name' => 'print_img_checkbox.png'); // Standard screens // Only these may be viewed $screens[] = array('name' => gT('Survey List Page'), 'id' => 'surveylist'); $screens[] = array('name' => gT('Welcome Page'), 'id' => 'welcome'); $screens[] = array('name' => gT('Question Page'), 'id' => 'question'); $screens[] = array('name' => gT('Completed Page'), 'id' => 'completed'); $screens[] = array('name' => gT('Clear All Page'), 'id' => 'clearall'); $screens[] = array('name' => gT('Register Page'), 'id' => 'register'); $screens[] = array('name' => gT('Load Page'), 'id' => 'load'); $screens[] = array('name' => gT('Save Page'), 'id' => 'save'); $screens[] = array('name' => gT('Print answers page'), 'id' => 'printanswers'); $screens[] = array('name' => gT('Printable survey page'), 'id' => 'printablesurvey'); // Page display blocks $SurveyList = array('startpage.pstpl', 'surveylist.pstpl', 'endpage.pstpl'); $Welcome = array('startpage.pstpl', 'welcome.pstpl', 'privacy.pstpl', 'navigator.pstpl', 'endpage.pstpl'); $Question = array('startpage.pstpl', 'survey.pstpl', 'startgroup.pstpl', 'groupdescription.pstpl', 'question.pstpl', 'endgroup.pstpl', 'navigator.pstpl', 'endpage.pstpl'); $CompletedTemplate = array('startpage.pstpl', 'assessment.pstpl', 'completed.pstpl', 'endpage.pstpl'); $Clearall = array('startpage.pstpl', 'clearall.pstpl', 'endpage.pstpl'); $Register = array('startpage.pstpl', 'survey.pstpl', 'register.pstpl', 'endpage.pstpl'); $Save = array('startpage.pstpl', 'save.pstpl', 'endpage.pstpl'); $Load = array('startpage.pstpl', 'load.pstpl', 'endpage.pstpl'); $printtemplate = array('startpage.pstpl', 'printanswers.pstpl', 'endpage.pstpl'); $printablesurveytemplate = array('print_survey.pstpl', 'print_group.pstpl', 'print_question.pstpl'); $file_version = "LimeSurvey template editor " . Yii::app()->getConfig('versionnumber'); Yii::app()->session['s_lang'] = Yii::app()->session['adminlang']; $templatename = sanitize_dirname($templatename); $screenname = autoUnescape($screenname); // Checks if screen name is in the list of allowed screen names if (multiarray_search($screens, 'id', $screenname) === false) { Yii::app()->user->setFlash('error', gT('Invalid screen name')); $this->getController()->redirect(array("admin/templates/sa/upload")); } if (!isset($action)) { $action = sanitize_paranoid_string(returnGlobal('action')); } if (!isset($subaction)) { $subaction = sanitize_paranoid_string(returnGlobal('subaction')); } if (!isset($newname)) { $newname = sanitize_dirname(returnGlobal('newname')); } if (!isset($copydir)) { $copydir = sanitize_dirname(returnGlobal('copydir')); } if (is_file(Yii::app()->getConfig('usertemplaterootdir') . '/' . $templatename . '/question_start.pstpl')) { $files[] = array('name' => 'question_start.pstpl'); $Question[] = 'question_start.pstpl'; } $editfile = sanitize_filename($editfile); // Fixed with editable file after, but put in aData before fix $availableeditorlanguages = array('bg', 'cs', 'de', 'dk', 'en', 'eo', 'es', 'fi', 'fr', 'hr', 'it', 'ja', 'mk', 'nl', 'pl', 'pt', 'ru', 'sk', 'zh'); // 2.06 way of doing. if (!$useindex) { $extension = substr(strrchr($editfile, "."), 1); } else { // The extension is now set as a prefix separated by a _ $file_datas = explode("_", $editfile); $extension = $file_datas[0]; // The file name is now based on the index of the oTemplate files $file_index = $file_datas[1]; switch ($extension) { case 'css': $aTemplateFiles = (array) $oEditedTemplate->config->files_editable->css->filename; break; case 'js': $aTemplateFiles = (array) $oEditedTemplate->config->files_editable->js->filename; break; default: $aTemplateFiles = (array) $oEditedTemplate->config->files_editable->css->filename; break; } $editfile = $aTemplateFiles[$file_index]; } if ($extension == 'css' || $extension == 'js') { $highlighter = $extension; } else { $highlighter = 'html'; } if (in_array(Yii::app()->session['adminlang'], $availableeditorlanguages)) { $codelanguage = Yii::app()->session['adminlang']; } else { $codelanguage = 'en'; } $templates = getTemplateList(); if (!isset($templates[$templatename])) { $templatename = Yii::app()->getConfig('defaulttemplate'); } $normalfiles = array("DUMMYENTRY", ".", "..", "preview.png"); foreach ($files as $fl) { $normalfiles[] = $fl["name"]; } foreach ($cssfiles as $fl) { $normalfiles[] = $fl["name"]; } // Some global data $aData['sitename'] = Yii::app()->getConfig('sitename'); $siteadminname = Yii::app()->getConfig('siteadminname'); $siteadminemail = Yii::app()->getConfig('siteadminemail'); // Set this so common.php doesn't throw notices about undefined variables $thissurvey['active'] = 'N'; // FAKE DATA FOR TEMPLATES $thissurvey['name'] = gT("Template Sample"); $thissurvey['description'] = "<p>" . gT('This is a sample survey description. It could be quite long.') . "</p>" . "<p>" . gT("But this one isn't.") . "<p>"; $thissurvey['welcome'] = "<p>" . gT('Welcome to this sample survey') . "<p>" . "<p>" . gT('You should have a great time doing this') . "<p>"; $thissurvey['allowsave'] = "Y"; $thissurvey['active'] = "Y"; $thissurvey['tokenanswerspersistence'] = "Y"; $thissurvey['templatedir'] = $templatename; $thissurvey['format'] = "G"; $thissurvey['surveyls_url'] = "http://www.limesurvey.org/"; $thissurvey['surveyls_urldescription'] = gT("Some URL description"); $thissurvey['usecaptcha'] = "A"; $percentcomplete = makegraph(6, 10); $groupname = gT("Group 1: The first lot of questions"); $groupdescription = gT("This group description is fairly vacuous, but quite important."); $navigator = $this->getController()->render('/admin/templates/templateeditor_navigator_view', array('screenname' => $screenname), true); $completed = $this->getController()->render('/admin/templates/templateeditor_completed_view', array(), true); $assessments = $this->getController()->render('/admin/templates/templateeditor_assessments_view', array(), true); $printoutput = $this->getController()->render('/admin/templates/templateeditor_printoutput_view', array(), true); $totalquestions = '10'; $surveyformat = 'Format'; $notanswered = '5'; $privacy = ''; $surveyid = '1295'; $token = 1234567; $templatedir = $oEditedTemplate->viewPath; $templateurl = getTemplateURL($templatename); // Save these variables in an array $aData['thissurvey'] = $thissurvey; $aData['percentcomplete'] = $percentcomplete; $aData['groupname'] = $groupname; $aData['groupdescription'] = $groupdescription; $aData['navigator'] = $navigator; $aData['help'] = gT("This is some help text."); $aData['surveyformat'] = $surveyformat; $aData['totalquestions'] = $totalquestions; $aData['completed'] = $completed; $aData['notanswered'] = $notanswered; $aData['privacy'] = $privacy; $aData['surveyid'] = $surveyid; $aData['sid'] = $surveyid; $aData['token'] = $token; $aData['assessments'] = $assessments; $aData['printoutput'] = $printoutput; $aData['templatedir'] = $templatedir; $aData['templateurl'] = $templateurl; $aData['templatename'] = $templatename; $aData['screenname'] = $screenname; $aData['editfile'] = $editfile; $myoutput[] = ""; switch ($screenname) { case 'surveylist': unset($files); $surveylist = array("nosid" => gT("You have not provided a survey identification number"), "contact" => sprintf(gT("Please contact %s ( %s ) for further assistance."), Yii::app()->getConfig("siteadminname"), Yii::app()->getConfig("siteadminemail")), "listheading" => gT("The following surveys are available:"), "list" => $this->getController()->render('/admin/templates/templateeditor_surveylist_view', array(), true)); $aData['surveylist'] = $surveylist; $myoutput[] = ""; //$myoutput[] = templatereplace(file_get_contents("$templatedir/startpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); foreach ($SurveyList as $qs) { $files[] = array("name" => $qs); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/{$qs}", $aData, $oEditedTemplate)); } break; case 'question': unset($files); foreach ($Question as $qs) { $files[] = array("name" => $qs); } $myoutput[] = $this->getController()->render('/admin/templates/templateeditor_question_meta_view', array(), true); $aData['aReplacements'] = array('SAVE_LINKS' => '<li><a href="#" id="saveallbtnlink">Resume later</a></li>', 'CLEARALL_LINKS' => '<li><a href="#" id="clearallbtnlink">' . gT("Exit and clear survey") . '</a></li>'); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/startpage.pstpl", $aData, $oEditedTemplate)); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/survey.pstpl", $aData, $oEditedTemplate)); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/startgroup.pstpl", $aData, $oEditedTemplate)); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/groupdescription.pstpl", $aData, $oEditedTemplate)); $aReplacements = array('QUESTION_TEXT' => gT("How many roads must a man walk down?"), 'QUESTION_CODE' => '1a', 'QUESTIONHELP' => 'helpful text', 'QUESTION_MANDATORY' => gT("*"), 'QUESTION_MAN_CLASS' => ' mandatory', 'QUESTION_ESSENTIALS' => 'id="question1"', 'QUESTION_CLASS' => 'list-radio', 'QUESTION_NUMBER' => '1'); $aReplacements['ANSWER'] = $this->getController()->render('/admin/templates/templateeditor_question_answer_view', array(), true); $aData['aReplacements'] = $aReplacements; $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/question.pstpl", $aData, $oEditedTemplate)); $aReplacements = array('QUESTION_TEXT' => gT('Please explain something in detail:'), 'QUESTION_CODE' => '2a', 'QUESTION_ESSENTIALS' => 'id="question2"', 'QUESTION_CLASS' => 'text-long', 'QUESTION_NUMBER' => '2'); $aReplacements['ANSWER'] = $this->getController()->render('/admin/templates/templateeditor_question_answer_view', array('alt' => true), true); $aData['aReplacements'] = $aReplacements; $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/question.pstpl", $aData, $oEditedTemplate)); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/endgroup.pstpl", $aData, $oEditedTemplate)); $aData['aReplacements'] = array('MOVEPREVBUTTON' => '<button type="submit" id="moveprevbtn" value="moveprev" name="moveprev" accesskey="p" class="submit button btn btn-default btn-lg ">Previous</button>', 'MOVENEXTBUTTON' => '<button type="submit" id="movenextbtn" value="movenext" name="movenext" accesskey="n" class="submit button btn btn-default btn-lg ">Next</button>'); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/navigator.pstpl", $aData, $oEditedTemplate)); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/endpage.pstpl", $aData, $oEditedTemplate)); break; case 'welcome': unset($files); foreach ($Welcome as $qs) { $files[] = array("name" => $qs); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/{$qs}", $aData, $oEditedTemplate)); } /* $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/startpage.pstpl", $aData, $oEditedTemplate)); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/welcome.pstpl", $aData, $oEditedTemplate)); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/privacy.pstpl", $aData, $oEditedTemplate)); */ $aData['aReplacements'] = array('MOVENEXTBUTTON' => '<button type="submit" id="movenextbtn" value="movenext" name="movenext" accesskey="n" class="submit button btn btn-default btn-lg">Next</button>'); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/navigator.pstpl", $aData, $oEditedTemplate)); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/endpage.pstpl", $aData, $oEditedTemplate)); break; case 'register': unset($files); foreach ($Register as $qs) { $files[] = array("name" => $qs); } $myoutput[] = templatereplace(file_get_contents("{$templatedir}/startpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $aData = array('aReplacements' => array('SURVEYNAME' => 'Survey name')); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/survey.pstpl", $aData, $oEditedTemplate)); $aData['aReplacements'] = array('REGISTERERROR' => 'Example error message', 'REGISTERMESSAGE1' => 'Register message 1', 'REGISTERMESSAGE2' => 'Register message 2', 'REGISTERFORM' => $this->getController()->render('/admin/templates/templateeditor_register_view', array('alt' => true), true)); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/register.pstpl", $aData, $oEditedTemplate)); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/endpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = "\n"; break; case 'save': unset($files); foreach ($Save as $qs) { $files[] = array("name" => $qs); } $myoutput[] = templatereplace(file_get_contents("{$templatedir}/startpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/save.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/endpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = "\n"; break; case 'load': unset($files); foreach ($Load as $qs) { $files[] = array("name" => $qs); } $myoutput[] = templatereplace(file_get_contents("{$templatedir}/startpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/load.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/endpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = "\n"; break; case 'clearall': unset($files); foreach ($Clearall as $qs) { $files[] = array("name" => $qs); } $myoutput[] = templatereplace(file_get_contents("{$templatedir}/startpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/clearall.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/endpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = "\n"; break; case 'completed': unset($files); $myoutput[] = ""; foreach ($CompletedTemplate as $qs) { $files[] = array("name" => $qs); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/{$qs}", $aData, $oEditedTemplate)); } break; case 'printablesurvey': unset($files); foreach ($printablesurveytemplate as $qs) { $files[] = array("name" => $qs); } $questionoutput = array(); foreach (file("{$templatedir}/print_question.pstpl") as $op) { $questionoutput[] = templatereplace($op, array('QUESTION_NUMBER' => '1', 'QUESTION_CODE' => 'Q1', 'QUESTION_MANDATORY' => gT('*'), 'QUESTION_SCENARIO' => 'Only answer this if certain conditions are met.', 'QUESTION_CLASS' => ' mandatory list-radio', 'QUESTION_TYPE_HELP' => gT('Please choose *only one* of the following:'), 'QUESTION_MAN_MESSAGE' => '', 'QUESTION_VALID_MESSAGE' => '', 'QUESTION_FILE_VALID_MESSAGE' => '', 'QUESTION_TEXT' => gT('This is a sample question text. The user was asked to pick an entry.'), 'QUESTIONHELP' => gT('This is some help text for this question.'), 'ANSWER' => $this->getController()->render('/admin/templates/templateeditor_printablesurvey_quesanswer_view', array('templateurl' => $templateurl), true)), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); } $groupoutput = array(); $groupoutput[] = templatereplace(file_get_contents("{$templatedir}/print_group.pstpl"), array('QUESTIONS' => implode(' ', $questionoutput)), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/print_survey.pstpl"), array('GROUPS' => implode(' ', $groupoutput), 'FAX_TO' => gT("Please fax your completed survey to:") . " 000-000-000", 'SUBMIT_TEXT' => gT("Submit your survey."), 'HEADELEMENTS' => getPrintableHeader(), 'SUBMIT_BY' => sprintf(gT("Please submit by %s"), date('d.m.y')), 'THANKS' => gT('Thank you for completing this survey.'), 'END' => gT('This is the survey end message.')), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); break; case 'printanswers': unset($files); foreach ($printtemplate as $qs) { $files[] = array("name" => $qs); } $myoutput[] = templatereplace(file_get_contents("{$templatedir}/startpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/printanswers.pstpl"), array('ANSWERTABLE' => $printoutput), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = templatereplace(file_get_contents("{$templatedir}/endpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); $myoutput[] = "\n"; break; } $myoutput[] = "</html>"; $jsfiles = $this->_getEditableJsFiles($oEditedTemplate); if (is_array($files)) { $match = 0; foreach ($files as $f) { if ($editfile == $f["name"]) { $match = 1; } } $aCssAndJsfiles = array_merge($cssfiles, $jsfiles); foreach ($aCssAndJsfiles as $f) { if ($editfile == $f["name"]) { $match = 1; } } if ($match == 0) { if (count($files) > 0) { $editfile = $files[0]["name"]; } else { $editfile = ""; } } } // Get list of 'otherfiles' // We can't use $oTemplate->otherFiles, because of retrocompatibility with 2.06 template and the big mess of it mixing files $filesdir = $oEditedTemplate->filesPath != '' ? $oEditedTemplate->filesPath : $templatedir . '../files'; $otherfiles = array(); if (file_exists($filesdir) && ($handle = opendir($filesdir))) { while (false !== ($file = readdir($handle))) { if (!array_search($file, $normalfiles)) { if (!is_dir($templatedir . DIRECTORY_SEPARATOR . $file)) { $otherfiles[] = array("name" => $file); } } } closedir($handle); } $aData['codelanguage'] = $codelanguage; $aData['highlighter'] = $highlighter; $aData['screens'] = $screens; $aData['templatename'] = $templatename; $aData['templates'] = $templates; $aData['editfile'] = $editfile; $aData['screenname'] = $screenname; $aData['tempdir'] = Yii::app()->getConfig('tempdir'); $aData['usertemplaterootdir'] = Yii::app()->getConfig('usertemplaterootdir'); $aViewUrls['templateeditorbar_view'][] = $aData; if ($showsummary) { //$aCssfileseditable = (array) $oEditedTemplate->config->files_editable->css->filename; $aViewUrls = array_merge($aViewUrls, $this->_templatesummary($templatename, $screenname, $editfile, $templates, $files, $cssfiles, $jsfiles, $otherfiles, $myoutput)); } App()->getClientScript()->registerScriptFile(App()->getAssetManager()->publish(ADMIN_SCRIPT_PATH . 'admin_core.js')); return $aViewUrls; }
$flashmessage = sprintf($clang->gT("Template '%s' was successfully deleted."), $templatename); unset($templates[$templatename]); $templatename = $defaulttemplate; } else { $flashmessage = sprintf($clang->gT("There was a problem deleting the template '%s'. Please check your directory/file permissions."), $templatename); } } if ($action == "templateupload") { include "import_resources_zip.php"; } //Save Changes if necessary if ($action == "templatesavechanges" && $changedtext) { $changedtext = str_replace("\r\n", "\n", $changedtext); if ($editfile) { // Check if someone tries to submit a file other than one of the allowed filenames if (multiarray_search($files, 'name', $editfile) === false && multiarray_search($cssfiles, 'name', $editfile) === false) { die('Invalid template filename'); } // Die you sneaky bastard! $savefilename = $usertemplaterootdir . "/" . $templatename . "/" . $editfile; if (is_writable($savefilename)) { if (!($handle = fopen($savefilename, 'w'))) { echo "Could not open file ({$savefilename})"; exit; } if (!fwrite($handle, $changedtext)) { echo "Cannot write to file ({$savefilename})"; exit; } fclose($handle); } else {
/** * Returns the feed array associated with an entry */ function get_feed_from_entry($entry, $feeds = array()) { $feed_id = $entry['feed_id']; $search = multiarray_search('id', $feed_id, $feeds, false); if ($search !== false) { return $search; } else { return get_feed($feed_id); } }