示例#1
0
文件: Acl.php 项目: jinshana/tangocms
 /**
  * Builds a form for a user to use which will allow him/her/it to alter the rules
  * for an ACL Resource and Roles.
  *
  * If providing multiple resources, you can also provide specific ACL role hints for
  * default selection.
  *
  * A prefix can be set which will limit which Roles should be shown within the form,
  * by default - it is anything that begins with 'group_'
  *
  * @param mixed $resource
  * @param string $prefix
  * @return string|bool
  */
 public function buildForm($resource, $prefix = 'group_')
 {
     /**
      * Get the role tree for the guest group/role, so that better defaults can be
      * set for the checkboxes, each role it inherits will be checked.
      */
     $guestGroup = $this->_ugmanager->getGroup(Ugmanager::_GUEST_GID);
     $roleHint = array();
     foreach ($this->getRoleTree($guestGroup['role_id'], true) as $tmpRole) {
         $roleHint[] = $tmpRole['id'];
     }
     $rootRole = $this->getRole('group_root');
     $roleHint[] = $rootRole['id'];
     # Makes root default as well
     // Build the correct array structure for the resources
     $roles = $this->getAllRoles($prefix);
     # Get all of the roles that match the prefix to be used later
     $resources = array();
     foreach ((array) $resource as $name => $details) {
         if (is_array($details)) {
             // We have a provided RESOURCE [0] and ROLE HINT [1]
             $tmpResource = $details[0];
             if ($this->roleExists($details[1])) {
                 $tmpRoleHint = array($rootRole['id']);
                 foreach ($this->getRoleTree($details[1], true) as $role) {
                     array_unshift($tmpRoleHint, $role['id']);
                 }
             }
         } else {
             $tmpResource = $details;
         }
         if (!preg_match(self::_REGEX_PATTERN, $tmpResource)) {
             trigger_error('Acl::buildForm() Resource name must only contain alphanumeric chars, underscore and hyphen (A-Z, a-z, 0-9, _, -), was given "' . $tmpResource . '"');
             return false;
         }
         /**
          * If the role, check if the roles have access to it which will then
          * be used later on in the view to provided if the checkbox should be checked
          */
         $roleAccess = array();
         foreach ($roles as $role) {
             try {
                 $role['access'] = (bool) $this->_input->post('acl_resources/' . $tmpResource . '/' . $role['name']);
             } catch (Input_KeyNoExist $e) {
                 if ($this->resourceExists($tmpResource)) {
                     $role['access'] = $this->check($tmpResource, $role['name'], false);
                 } else {
                     $role['access'] = in_array($role['id'], isset($tmpRoleHint) ? $tmpRoleHint : $roleHint);
                 }
             }
             $role['short_name'] = zula_substr($role['name'], strlen($prefix));
             $roleAccess[] = $role;
         }
         $resources[] = array('title' => is_int($name) ? $tmpResource : $name, 'name' => $tmpResource, 'roles' => $roleAccess);
     }
     if (Registry::has('theme')) {
         $this->_theme->addJsFile('general.js');
     }
     // Construct the main view file
     $view = new View('acl_form.html');
     $view->assign(array('resources' => $resources, 'roles' => $roleAccess));
     return $view->getOutput();
 }
示例#2
0
 /**
  * This is the actual Tag Replacement method
  * First it assigns the default tags that need to be used and then prepars the Tags that
  * will be used in the PHP 'Jail' class. All of the Tags for PHP use are convertd to lowercase
  *
  * After all PHP is run it gets the output from the class and goes about replacing the normal
  * {TAGS} in the view file. All language tags are also found and assigned, they appear at the start
  * of the assigned tags array
  *
  * @param bool $parseConfigTags		If this is set to true, values such as {%TCM_SITE_TITLE%} will get replaced
  * @return string
  */
 public function getOutput($parseConfigTags = false)
 {
     $this->noparse = array();
     # Restore noparse array
     // Get and assign the default tags
     $defaultTags = $this->getDefaultTags();
     $this->assignHtml(array('plain' => $defaultTags['plain']));
     unset($defaultTags['plain']);
     $this->assign($defaultTags);
     if ($this->loadedContent === null) {
         if ($this->parsePhp === true) {
             // Prepare the tags for the PHP class
             $phpTags = array();
             foreach ($this->assignedTags as $tag => $val) {
                 $tag = str_replace('-', '_', $tag);
                 if ($this->caseSensitive === false) {
                     $tag = zula_strtolower($tag);
                 }
                 $phpTags[$tag] = $val;
             }
             $tmpView = new View_OB($phpTags, $this->viewPath, $this->module);
             $tmpViewContent = $tmpView->getOutput();
             # Return content of the parsed PHP view file
         } else {
             $tmpViewContent = file_get_contents($this->viewPath);
         }
     } else {
         $tmpViewContent = $this->loadedContent;
     }
     // Gather all language tags and merge them into the final tag array
     $languageTags = $this->languageTags($tmpViewContent);
     $this->assignedTags = array_merge($languageTags, $this->assignedTags);
     // Remove all <noparse> text
     $tmpViewContent = preg_replace_callback('#<noparse>(.*?)</noparse>#s', array($this, 'extractNoparse'), $tmpViewContent);
     preg_match_all('@{(?!(?:%|\\s|}))(.*?)(?<!%)}@', $tmpViewContent, $templateTags);
     if (!empty($templateTags[0])) {
         foreach ($templateTags[0] as $key => $tag) {
             if (zula_substr($tag, 0, 4) == '{L_[') {
                 // Replace the langauge tags without splitting the tag into .. tokens?
                 try {
                     $tmpViewContent = $this->replaceTag($templateTags[1][$key], $tmpViewContent, true);
                 } catch (View_TagNotAssigned $e) {
                     $this->_log->message($e->getMessage(), Log::L_NOTICE);
                 } catch (View_InvalidTagValue $e) {
                     trigger_error('View::getOutput() view tag has invalid assigned value:' . $e->getMessage(), E_USER_WARNING);
                 }
             } else {
                 $tagTokens = explode('.', $templateTags[1][$key]);
                 if (count($tagTokens) <= 1) {
                     $tmpTag = $templateTags[1][$key];
                 } else {
                     // Tag is in the format of {FOO.BAR.CAR}
                     $tmpTag = $tagTokens;
                 }
                 try {
                     $tmpViewContent = $this->replaceTag($tmpTag, $tmpViewContent);
                 } catch (View_TagNotAssigned $e) {
                     $this->_log->message($e->getMessage(), Log::L_NOTICE);
                 } catch (View_InvalidTagValue $e) {
                     trigger_error('View::getOutput() view tag has invalid assigned value:' . $e->getMessage(), E_USER_WARNING);
                 }
             }
         }
     }
     foreach ($defaultTags as $tag => $val) {
         $tmpViewContent = str_replace('{' . $tag . '}', $val, $tmpViewContent);
         if ($parseConfigTags === true) {
             $tmpViewContent = str_replace('{%' . $tag . '%}', $val, $tmpViewContent);
         }
     }
     // Restore noparse text
     $text = preg_replace_callback('#<noparse></noparse>#', array($this, 'insertNoparse'), $tmpViewContent);
     # hook event: cntrlr_error_output
     while ($tmpText = Hooks::notify('view_output', $text, $this->viewPath, $this->module)) {
         if (is_string($tmpText)) {
             $text = $tmpText;
         }
     }
     return $text;
 }
示例#3
0
/**
 * Takes a string and creates a short zula_snippet/summary from it
 *
 * @param string $summary
 * @param int $charLimit
 * @param bool $ellipsis	Should ellipsis (...) be added to the end?
 * @return string
 */
function zula_snippet($summary, $charLimit = 400, $ellipsis = false)
{
    $summary = str_replace(array("\n", "\r"), ' ', $summary);
    $charLimit = abs($charLimit);
    if (!$charLimit || zula_strlen($summary) < $charLimit) {
        return $summary;
    } else {
        $str = trim(zula_substr($summary, 0, $charLimit));
        return $str . ($ellipsis ? '&#8230;' : '');
    }
}
示例#4
0
 /**
  * Helper function for emphasis
  *
  * @param string $text
  * @return string
  * @author MediaWiki Project
  */
 public function doQuotes($text)
 {
     $arr = preg_split("/(''+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
     if (count($arr) == 1) {
         return $text;
     } else {
         # First, do some preliminary work. This may shift some apostrophes from
         # being mark-up to being text. It also counts the number of occurrences
         # of bold and italics mark-ups.
         $i = 0;
         $numbold = 0;
         $numitalics = 0;
         foreach ($arr as $r) {
             if ($i % 2 == 1) {
                 # If there are ever four apostrophes, assume the first is supposed to
                 # be text, and the remaining three constitute mark-up for bold text.
                 if (zula_strlen($arr[$i]) == 4) {
                     $arr[$i - 1] .= "'";
                     $arr[$i] = "'''";
                 } else {
                     if (zula_strlen($arr[$i]) > 5) {
                         $arr[$i - 1] .= str_repeat("'", zula_strlen($arr[$i]) - 5);
                         $arr[$i] = "'''''";
                     }
                 }
                 # Count the number of occurrences of bold and italics mark-ups.
                 # We are not counting sequences of five apostrophes.
                 if (zula_strlen($arr[$i]) == 2) {
                     $numitalics++;
                 } else {
                     if (zula_strlen($arr[$i]) == 3) {
                         $numbold++;
                     } else {
                         if (zula_strlen($arr[$i]) == 5) {
                             $numitalics++;
                             $numbold++;
                         }
                     }
                 }
             }
             $i++;
         }
         # If there is an odd number of both bold and italics, it is likely
         # that one of the bold ones was meant to be an apostrophe followed
         # by italics. Which one we cannot know for certain, but it is more
         # likely to be one that has a single-letter word before it.
         if ($numbold % 2 == 1 && $numitalics % 2 == 1) {
             $i = 0;
             $firstsingleletterword = -1;
             $firstmultiletterword = -1;
             $firstspace = -1;
             foreach ($arr as $r) {
                 if ($i % 2 == 1 and zula_strlen($r) == 3) {
                     $x1 = zula_substr($arr[$i - 1], -1);
                     $x2 = zula_substr($arr[$i - 1], -2, 1);
                     if ($x1 == ' ') {
                         if ($firstspace == -1) {
                             $firstspace = $i;
                         }
                     } else {
                         if ($x2 == ' ') {
                             if ($firstsingleletterword == -1) {
                                 $firstsingleletterword = $i;
                             }
                         } else {
                             if ($firstmultiletterword == -1) {
                                 $firstmultiletterword = $i;
                             }
                         }
                     }
                 }
                 $i++;
             }
             # If there is a single-letter word, use it!
             if ($firstsingleletterword > -1) {
                 $arr[$firstsingleletterword] = "''";
                 $arr[$firstsingleletterword - 1] .= "'";
             } else {
                 if ($firstmultiletterword > -1) {
                     $arr[$firstmultiletterword] = "''";
                     $arr[$firstmultiletterword - 1] .= "'";
                 } else {
                     if ($firstspace > -1) {
                         $arr[$firstspace] = "''";
                         $arr[$firstspace - 1] .= "'";
                     }
                 }
             }
         }
         # Now let's actually convert our apostrophic mush to HTML!
         $output = '';
         $buffer = '';
         $state = '';
         $i = 0;
         foreach ($arr as $r) {
             if ($i % 2 == 0) {
                 if ($state == 'both') {
                     $buffer .= $r;
                 } else {
                     $output .= $r;
                 }
             } else {
                 if (zula_strlen($r) == 2) {
                     if ($state == 'i') {
                         $output .= '</em>';
                         $state = '';
                     } else {
                         if ($state == 'bi') {
                             $output .= '</em>';
                             $state = 'b';
                         } else {
                             if ($state == 'ib') {
                                 $output .= '</strong></em><strong>';
                                 $state = 'b';
                             } else {
                                 if ($state == 'both') {
                                     $output .= '<strong><em>' . $buffer . '</em>';
                                     $state = 'b';
                                 } else {
                                     $output .= '<em>';
                                     $state .= 'i';
                                 }
                             }
                         }
                     }
                 } else {
                     if (zula_strlen($r) == 3) {
                         if ($state == 'b') {
                             $output .= '</strong>';
                             $state = '';
                         } else {
                             if ($state == 'bi') {
                                 $output .= '</em></strong><em>';
                                 $state = 'i';
                             } else {
                                 if ($state == 'ib') {
                                     $output .= '</strong>';
                                     $state = 'i';
                                 } else {
                                     if ($state == 'both') {
                                         $output .= '<em><strong>' . $buffer . '</strong>';
                                         $state = 'i';
                                     } else {
                                         $output .= '<strong>';
                                         $state .= 'b';
                                     }
                                 }
                             }
                         }
                     } else {
                         if (zula_strlen($r) == 5) {
                             if ($state == 'b') {
                                 $output .= '</strong><em>';
                                 $state = 'i';
                             } else {
                                 if ($state == 'i') {
                                     $output .= '</em><strong>';
                                     $state = 'b';
                                 } else {
                                     if ($state == 'bi') {
                                         $output .= '</em></strong>';
                                         $state = '';
                                     } else {
                                         if ($state == 'ib') {
                                             $output .= '</strong></em>';
                                             $state = '';
                                         } else {
                                             if ($state == 'both') {
                                                 $output .= '<em><strong>' . $buffer . '</strong></em>';
                                                 $state = '';
                                             } else {
                                                 $buffer = '';
                                                 $state = 'both';
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $i++;
         }
         # Now close all remaining tags.  Notice that the order is important.
         if ($state == 'b' || $state == 'ib') {
             $output .= '</strong>';
         }
         if ($state == 'i' || $state == 'bi' || $state == 'ib') {
             $output .= '</em>';
         }
         if ($state == 'bi') {
             $output .= '</strong>';
         }
         # There might be lonely ''''', so make sure we have a buffer
         if ($state == 'both' && $buffer) {
             $output .= '<strong><em>' . $buffer . '</em></strong>';
         }
         return $output;
     }
 }
示例#5
0
文件: Ini.php 项目: jinshana/tangocms
 /**
  * Rewrites the configuration ini file back, leaving it as
  * in-take as possible (ie, keeping all comments) in place
  *  and same sort of structure.
  *
  * @return bool
  */
 public function writeIni()
 {
     if (!zula_is_writable($this->iniFile)) {
         throw new Config_ini_FileNotWriteable($this->iniFile . ' is not writeable');
     }
     $iniContent = '';
     /**
      * Open the file and read line by line, rewriting it as
      * it goes a long
      */
     $fHandle = fopen($this->iniFile, 'rb');
     $sections = array();
     # Store the sections and values which have been written
     while (!feof($fHandle)) {
         $line = trim(fgets($fHandle)) . "\n";
         if (zula_substr($line, 0, 1) == ';') {
             // Line is a comment
             $iniContent .= $line;
         } else {
             if (zula_substr($line, 0, 1) == '[') {
                 preg_match('#\\[(.*?)\\]#', $line, $matches);
                 try {
                     $values = $this->get($matches[1]);
                     $sections[] = $matches[1];
                     $iniContent .= $matches[0] . "\n";
                     foreach ($values as $key => $val) {
                         if (preg_match('#[^A-Z0-9_\\-./]#i', $val)) {
                             $val = '"' . $val . '"';
                         }
                         $iniContent .= $key . ' = ' . $val . "\n";
                     }
                     // Add a spacer to the bottom
                     $iniContent .= "\n";
                 } catch (Config_KeyNoExist $e) {
                     continue;
                 }
             }
         }
     }
     /**
      * Add on the extra values that need to be added to the ini file
      */
     foreach ($this->getAll() as $section => $values) {
         if (empty($values)) {
             continue;
             # No need to add empty sections in
         } else {
             if (!in_array($section, $sections)) {
                 $iniContent .= '[' . $section . "]\n";
                 foreach ($values as $key => $val) {
                     $val = (string) $val;
                     if (preg_match('#[^A-Z0-9_\\-./]#i', $val)) {
                         $val = '"' . $val . '"';
                     }
                     $iniContent .= $key . ' = ' . $val . "\n";
                 }
             }
         }
     }
     file_put_contents($this->iniFile, trim($iniContent));
     return true;
 }