/**
  * Creates a new MessageAttachmentListEditor object.
  * 
  * @param	array<integer>	$containerIDArray
  * @param	string		$containerType
  * @param	integer		$packageID
  * @param	integer		$maxFileSize
  * @param	string		$allowedExtensions
  * @param	integer		$maxUploads
  * @param	integer		$thumbnailWidth
  * @param	integer		$thumbnailHeight
  * @param	boolean		$addSourceInfo
  * @param	boolean		$useEmbedded
  */
 public function __construct($containerIDArray = array(), $containerType = 'post', $packageID = PACKAGE_ID, $maxFileSize = 2000000, $allowedExtensions = "gif\njpg\njpeg\npng\nbmp\nzip\ntxt", $maxUploads = 5, $thumbnailWidth = ATTACHMENT_THUMBNAIL_WIDTH, $thumbnailHeight = ATTACHMENT_THUMBNAIL_HEIGHT, $addSourceInfo = ATTACHMENT_THUMBNAIL_ADD_SOURCE_INFO, $useEmbedded = ATTACHMENT_THUMBNAIL_USE_EMBEDDED)
 {
     if (!is_array($containerIDArray)) {
         $containerIDArray = array($containerIDArray);
     }
     $this->thumbnailWidth = $thumbnailWidth;
     $this->thumbnailHeight = $thumbnailHeight;
     $this->addSourceInfo = $addSourceInfo;
     $this->useEmbedded = $useEmbedded;
     if (!count($containerIDArray)) {
         $this->getIDHash();
     }
     // call parent constructor
     parent::__construct($containerIDArray, $containerType, $this->idHash, $packageID);
     // read attachments
     $this->readObjects();
     $this->maxFileSize = $maxFileSize;
     $this->maxUploads = $maxUploads;
     $allowedExtensions = StringUtil::unifyNewlines($allowedExtensions);
     $allowedExtensions = implode("\n", array_unique(explode("\n", $allowedExtensions)));
     $this->allowedExtensions = '/^(' . StringUtil::replace("\n", "|", StringUtil::replace('\\*', '.*', preg_quote($allowedExtensions, '/'))) . ')$/i';
     $this->allowedExtensionsDesc = self::formatAllowedExtensions($allowedExtensions);
     $this->getAttachmentHashes();
     $this->assign();
 }
 /**
  * @see Form::readFormParameters()
  */
 public function readFormParameters()
 {
     parent::readFormParameters();
     if (isset($_POST['classPath'])) {
         $this->classPath = StringUtil::trim($_POST['classPath']);
     }
     if (isset($_POST['description'])) {
         $this->description = StringUtil::trim($_POST['description']);
     }
     if (isset($_POST['execMultiple'])) {
         $this->execMultiple = intval($_POST['execMultiple']);
     }
     if (isset($_POST['startMinute'])) {
         $this->startMinute = StringUtil::replace(' ', '', $_POST['startMinute']);
     }
     if (isset($_POST['startHour'])) {
         $this->startHour = StringUtil::replace(' ', '', $_POST['startHour']);
     }
     if (isset($_POST['startDom'])) {
         $this->startDom = StringUtil::replace(' ', '', $_POST['startDom']);
     }
     if (isset($_POST['startMonth'])) {
         $this->startMonth = StringUtil::replace(' ', '', $_POST['startMonth']);
     }
     if (isset($_POST['startDow'])) {
         $this->startDow = StringUtil::replace(' ', '', $_POST['startDow']);
     }
 }
Ejemplo n.º 3
0
 /**
  * Adds a file to the Zip archive.
  * 
  * @param	string		$data		content of the file
  * @param	string		$name		filename
  * @param	integer		$date		file creation time as unix timestamp
  */
 public function addFile($data, $name, $date = 0)
 {
     // replace backward slashes with forward slashes in the filename
     $name = StringUtil::replace("\\", "/", $name);
     // calculate the size of the file being uncompressed
     $sizeUncompressed = strlen($data);
     // get data checksum
     $crc = crc32($data);
     // compress the file data
     $compressedData = gzcompress($data);
     // calculate the size of the file being compressed
     $compressedData = substr($compressedData, 2, -4);
     $sizeCompressed = strlen($compressedData);
     // construct the general header for the file record complete with checksum information, etc.
     $header = "PK";
     $header .= "";
     $header .= "";
     $header .= "";
     $header .= pack("V", $crc);
     $header .= pack("V", $sizeCompressed);
     $header .= pack("V", $sizeUncompressed);
     $header .= pack("v", strlen($name));
     $header .= pack("v", 0);
     $header .= $name;
     // store the compressed data immediately following the file header
     $header .= $compressedData;
     // complete the file record by adding an additional footer directly following the file data
     //$header .= pack("V", $crc);
     //$header .= pack("V", $sizeCompressed);
     //$header .= pack("V", $sizeUncompressed);
     // store the completed file record in the $headers array
     $this->headers[] = $header;
     // calculate the new offset for the central index record
     $newOffset = strlen(implode('', $this->headers));
     // construct the record
     $record = "PK";
     $record .= "";
     $record .= "";
     $record .= $this->getDosDatetime($date);
     $record .= pack("V", $crc);
     $record .= pack("V", $sizeCompressed);
     $record .= pack("V", $sizeUncompressed);
     $record .= pack("v", strlen($name));
     $record .= pack("v", 0);
     $record .= pack("v", 0);
     $record .= pack("v", 0);
     $record .= pack("v", 0);
     $record .= pack("V", 32);
     $record .= pack("V", $this->lastOffset);
     // update the offset for the next record to be stored
     $this->lastOffset = $newOffset;
     $record .= $name;
     // store the record in the $data array
     $this->data[] = $record;
 }
Ejemplo n.º 4
0
	/**
	 * Reinserts strings that have been replaced by unique hash values.
	 *
	 * @param	string		$string
	 * @param	string		$type
	 * @return	string
	 */
	public static function reinsertStrings($string, $type = 'default') {
		if (isset(self::$stringStack[$type])) {
			foreach (self::$stringStack[$type] as $hash => $value) {
				if (StringUtil::indexOf($string, $hash) !== false) {
					$string = StringUtil::replace($hash, $value, $string);
					unset(self::$stringStack[$type][$hash]);
				}
			}
		}
		
		return $string;
	}
 /**
  * @see TemplatePluginModifier::execute()
  */
 public function execute($tagArgs, Template $tplObj)
 {
     // escape backslash
     $tagArgs[0] = StringUtil::replace("\\", "\\\\", $tagArgs[0]);
     // escape singe quote
     $tagArgs[0] = StringUtil::replace("'", "\\'", $tagArgs[0]);
     // escape new lines
     $tagArgs[0] = StringUtil::replace("\n", '\\n', $tagArgs[0]);
     // escape slashes
     $tagArgs[0] = StringUtil::replace("/", '\\/', $tagArgs[0]);
     return $tagArgs[0];
 }
Ejemplo n.º 6
0
 /**
  * Starts the extracting of the files.
  */
 protected function install()
 {
     $this->checkTargetDir();
     $this->createTargetDir();
     // open source archive
     $tar = new Tar($this->source);
     // distinct directories and files
     $directories = array();
     $files = array();
     foreach ($tar->getContentList() as $index => $file) {
         if (empty($this->folder) || StringUtil::indexOf($file['filename'], $this->folder) === 0) {
             if (!empty($this->folder)) {
                 $file['filename'] = StringUtil::replace($this->folder, '', $file['filename']);
             }
             // remove leading slash
             $file['filename'] = FileUtil::removeLeadingSlash($file['filename']);
             if ($file['type'] == 'folder') {
                 // remove trailing slash
                 $directories[] = FileUtil::removeTrailingSlash($file['filename']);
             } else {
                 $files[$index] = $file['filename'];
             }
         }
     }
     $this->checkFiles($files);
     // now create the directories
     $errors = array();
     foreach ($directories as $dir) {
         try {
             $this->createDir($dir);
         } catch (SystemException $e) {
             $errors[] = array('file' => $dir, 'code' => $e->getCode(), 'message' => $e->getMessage());
         }
     }
     // now untar all files
     foreach ($files as $index => $file) {
         try {
             $this->createFile($file, $index, $tar);
         } catch (SystemException $e) {
             $errors[] = array('file' => $file, 'code' => $e->getCode(), 'message' => $e->getMessage());
         }
     }
     if (count($errors) > 0) {
         throw new SystemException('error(s) during the installation of the files.', 11111, $errors);
     }
     $this->logFiles($files);
     // close tar
     $tar->close();
 }
 /**
  * @see	Page::readData()
  */
 public function readData()
 {
     // read cache
     WCF::getCache()->addResource('packages-' . $this->source->sourceID, PB_DIR . 'cache/cache.packages-' . $this->source->sourceID . '.php', PB_DIR . 'lib/system/cache/CacheBuilderPackages.class.php');
     try {
         $packages = WCF::getCache()->get('packages-' . $this->source->sourceID, 'packages');
     } catch (SystemException $e) {
         // fallback if no cache available
         $packages = array();
     }
     // handle packages
     foreach ($packages as $package) {
         $this->directories[$package['packageName']] = $package['packageName'];
         $this->packages[$package['directory']] = array('packageName' => $package['packageName'], 'version' => $package['version']);
     }
     // remove duplicates and sort directories
     asort($this->directories);
     // set build directory
     $this->buildDirectory = $this->source->buildDirectory;
     if (WCF::getUser()->getPermission('admin.source.canEditSources')) {
         $this->buildDirectory = StringUtil::replace(FileUtil::unifyDirSeperator(PB_DIR), '', $this->buildDirectory);
     }
     // get source configuration
     $sourceData = WCF::getSession()->getVar('source' . $this->source->sourceID);
     if ($sourceData !== null) {
         $sourceData = unserialize($sourceData);
         $this->currentDirectory = $sourceData['directory'];
         $this->currentPackageName = $sourceData['packageName'];
     } else {
         $sql = "SELECT\tdirectory, packageName\n\t\t\t\tFROM\tpb" . PB_N . "_user_preference\n\t\t\t\tWHERE \tuserID = " . WCF::getUser()->userID . "\n\t\t\t\t\tAND sourceID = " . $this->source->sourceID;
         $row = WCF::getDB()->getFirstRow($sql);
         $this->currentDirectory = $row['directory'];
         $this->currentPackageName = $row['packageName'];
         WCF::getSession()->register('source' . $this->source->sourceID, serialize(array('directory' => $row['directory'], 'packageName' => $row['packageName'])));
     }
     // set current filename
     $currentFilename = WCF::getSession()->getVar('filename' . $this->source->sourceID);
     if ($currentFilename !== null) {
         $this->currentFilename = $currentFilename;
     }
     // read current builds
     $this->sourceFileList = new SourceFileList();
     $this->sourceFileList->sqlConditions = 'source_file.sourceID = ' . $this->source->sourceID;
     $this->sourceFileList->sqlLimit = 0;
     $this->sourceFileList->readObjects();
 }
 /**
  * @see Page::readData()
  */
 public function readData()
 {
     parent::readData();
     $this->identifier = $this->user->{$this->action};
     if (!$this->identifier) {
         throw new IllegalLinkException();
     }
     // check permissions
     WCF::getUser()->checkPermission('user.profile.canView');
     if ($this->user->ignoredUser) {
         throw new NamedUserException(WCF::getLanguage()->get('wcf.user.profile.error.ignoredUser', array('$username' => StringUtil::encodeHTML($this->user->username))));
     }
     if (!$this->user->canViewProfile()) {
         throw new IllegalLinkException();
     }
     if ($this->action == 'icq') {
         $this->identifier = StringUtil::replace('-', '', $this->identifier);
     }
 }
 /**
  * @see TemplatePluginFunction::execute()
  */
 public function execute($tagArgs, Template $tplObj)
 {
     // needed params: link, pages
     if (!isset($tagArgs['link'])) {
         throw new SystemException("missing 'link' argument in pages tag", 12001);
     }
     if (!isset($tagArgs['pages'])) {
         if (($tagArgs['pages'] = $tplObj->get('pages')) === null) {
             throw new SystemException("missing 'pages' argument in pages tag", 12001);
         }
     }
     $html = '';
     if ($tagArgs['pages'] > 1) {
         // encode link
         $link = StringUtil::encodeHTML($tagArgs['link']);
         // open div and ul
         $html .= "<div class=\"pageNavigation\">\n<ul>\n";
         // generate simple links
         $simpleLinks = $tagArgs['pages'];
         if ($simpleLinks > self::SHOW_LINKS) {
             $simpleLinks = self::SHOW_LINKS - 2;
         }
         for ($i = 1; $i <= $simpleLinks; $i++) {
             $html .= $this->makeLink($link, $i);
         }
         if ($tagArgs['pages'] > self::SHOW_LINKS) {
             // jumper
             $html .= '<li><a onclick="var result = prompt(\'' . WCF::getLanguage()->get('wcf.global.page.input') . '\', \'' . $tagArgs['pages'] . '\'); if (typeof(result) != \'object\' &amp;&amp; typeof(result) != \'undefined\') document.location.href = fixURL((\'' . StringUtil::replace("'", "\\'", $link) . '\').replace(/%d/, result));">&hellip;</a></li>' . "\n";
             // last page
             $html .= $this->makeLink($link, $tagArgs['pages']);
         }
         // close div and ul
         $html .= "</ul></div>\n";
     }
     // assign html output to template var
     if (isset($tagArgs['assign'])) {
         $tplObj->assign($tagArgs['assign'], $html);
         if (!isset($tagArgs['print']) || !$tagArgs['print']) {
             return '';
         }
     }
     return $html;
 }
 /**
  * @see UserOptionOutput::getOutput()
  */
 public function getOutput(User $user, $optionData, $value)
 {
     if (empty($value) || $value == '0000-00-00') {
         return '';
     }
     $age = 0;
     $date = self::splitDate($value);
     // format date
     try {
         $dateString = DateUtil::formatDate(null, gmmktime(12, 1, 1, $date['month'], $date['day'], $date['year'] ? $date['year'] : 2028));
         if (!$date['year']) {
             $dateString = StringUtil::replace('2028', '', $dateString);
         }
     } catch (Exception $e) {
         // fallback for negative timestamps under windows before php 5.1.0
         $dateString = $value;
     }
     // calc age
     if ($date['year'] && $optionData['optionType'] == 'birthday') {
         $age = self::calcAge($date['year'], $date['month'], $date['day']);
     }
     return $dateString . ($age ? ' (' . $age . ')' : '');
 }
 /**
  * @see Page::readData()
  */
 public function readData()
 {
     parent::readData();
     // get post list
     $this->postList = new PostAddPostList($this->thread, $this->board);
     // old thread warning
     if (REPLY_OLD_THREAD_WARNING && $this->thread->lastPostTime > 0) {
         $this->oldThreadWarning = intval(floor((TIME_NOW - $this->thread->lastPostTime) / 86400));
         if ($this->oldThreadWarning < REPLY_OLD_THREAD_WARNING) {
             $this->oldThreadWarning = 0;
         }
     }
     $this->attachments = $this->postList->attachments;
     if (count($this->attachments) > 0) {
         require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
         MessageAttachmentList::removeEmbeddedAttachments($this->attachments);
     }
     // default values
     if (!count($_POST)) {
         $this->closeThread = $this->thread->isClosed;
         $this->subscription = $this->thread->subscribed;
         if (!$this->subscription && WCF::getUser()->enableSubscription) {
             $this->subscription = 1;
         }
         // single quote
         if ($this->action == 'quote') {
             $post = $this->thread->getPost();
             if ($post) {
                 $this->text = "[quote='" . StringUtil::replace("'", "\\'", $post->username) . "',index.php?page=Thread&postID=" . $post->postID . "#post" . $post->postID . "]" . $post->message . "[/quote]";
                 if ($post->subject) {
                     $this->subject = WCF::getLanguage()->get('wbb.postAdd.quote.subject', array('$subject' => $post->subject));
                 }
             }
         }
     }
 }
 protected function replaceWcfNumber($wcfNumber)
 {
     $wcfTables = WCF::getDB()->getTableNames();
     /* Test missing tables
        $wcfTables[] = 'wcf1_test_table1';
        $wcfTables[] = 'wcf1_test_table2';
        $wcfTables[] = 'wcf1_test_table3';
        */
     foreach ($wcfTables as $key => $table) {
         if (StringUtil::indexOf($table, 'wcf' . WCF_N . '_') === false) {
             unset($wcfTables[$key]);
         } else {
             $wcfTables[$key] = StringUtil::replace('wcf' . WCF_N . '_', 'wcf' . $wcfNumber . '_', $table);
         }
     }
     return $wcfTables;
 }
Ejemplo n.º 13
0
 /**
  * Logs the unzipped files.
  */
 protected function logFiles()
 {
     $this->initDB();
     $this->getInstalledFiles(WCF_DIR);
     $acpTemplateInserts = $fileInserts = '';
     foreach (self::$installedFiles as $file) {
         $match = array();
         if (preg_match('!/acp/templates/([^/]+)\\.tpl$!', $file, $match)) {
             // acp template
             if (!empty($acpTemplateInserts)) {
                 $acpTemplateInserts .= ',';
             }
             $acpTemplateInserts .= "('" . escapeString($match[1]) . "')";
         } else {
             // regular file
             if (!empty($fileInserts)) {
                 $fileInserts .= ',';
             }
             $fileInserts .= "('" . escapeString(StringUtil::replace(WCF_DIR, '', $file)) . "')";
         }
     }
     // save acp template log
     if (!empty($acpTemplateInserts)) {
         $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_acp_template\n\t\t\t\t\t\t\t(templateName)\n\t\t\t\tVALUES\t\t\t" . $acpTemplateInserts;
         self::getDB()->sendQuery($sql);
     }
     // save file log
     if (!empty($fileInserts)) {
         $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\t\t\t\t(filename)\n\t\t\t\tVALUES\t\t\t" . $fileInserts;
         self::getDB()->sendQuery($sql);
     }
     $this->gotoNextStep('installLanguage');
 }
 /**
  * Highlights search keywords.
  * 
  * @param	string		$text
  * @return	string		text
  */
 public static function doHighlight($text)
 {
     if (self::$keywords == null) {
         self::getSearchKeywords();
     }
     if (count(self::$keywords) == 0) {
         return $text;
     }
     $keywordPattern = '(' . implode('|', self::$keywords) . ')';
     $keywordPattern = StringUtil::replace('\\*', '\\w*', $keywordPattern);
     return preg_replace('+(?<!&|&\\w{1}|&\\w{2}|&\\w{3}|&\\w{4}|&\\w{5}|&\\w{6})' . $keywordPattern . '(?![^<]*>)+i', '<span class="highlight">\\1</span>', $text);
 }
Ejemplo n.º 15
0
 /**
  * Searches in templates.
  * 
  * @param	string		$search		search query
  * @param	string		$replace
  * @param	array		$templateIDs
  * @param	boolean		$invertTemplates
  * @param	boolean		$useRegex
  * @param	boolean		$caseSensitive
  * @param	boolean		$invertSearch
  * @return	array		results 
  */
 public static function search($search, $replace = null, $templateIDs = null, $invertTemplates = 0, $useRegex = 0, $caseSensitive = 0, $invertSearch = 0)
 {
     // get available template ids
     $results = array();
     $availableTemplateIDs = array();
     $sql = "SELECT\t\ttemplate.templateName, template.templateID, template.templatePackID, template.packageID\n\t\t\tFROM\t\twcf" . WCF_N . "_template template,\n\t\t\t\t\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tWHERE \t\ttemplate.packageID = package_dependency.dependency\n\t\t\t\t\tAND package_dependency.packageID = " . PACKAGE_ID . "\n\t\t\t\t\t" . ($replace !== null ? "AND template.templatePackID <> 0" : "") . "\n\t\t\tORDER BY\tpackage_dependency.priority";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if (!isset($availableTemplateIDs[$row['templateName'] . '-' . $row['templatePackID']]) || PACKAGE_ID == $row['packageID']) {
             $availableTemplateIDs[$row['templateName'] . '-' . $row['templatePackID']] = $row['templateID'];
         }
     }
     // get templates
     if (!count($availableTemplateIDs)) {
         return $results;
     }
     $sql = "SELECT\t\ttemplate.*, pack.templatePackFolderName, package.packageDir\n\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_template_pack pack\n\t\t\tON\t\t(pack.templatePackID = template.templatePackID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = template.packageID)\n\t\t\tWHERE\t\ttemplate.templateID IN (" . implode(',', $availableTemplateIDs) . ")\n\t\t\t\t\t" . ($templateIDs != null ? "AND template.templateID " . ($invertTemplates ? "NOT " : "") . "IN (" . implode(',', $templateIDs) . ")" : "") . "\n\t\t\tORDER BY\ttemplateName";
     $result = WCF::getDB()->sendQuery($sql);
     unset($availableTemplateIDs);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $template = new TemplateEditor(null, $row);
         if ($replace === null) {
             // search
             if ($useRegex) {
                 $matches = intval(preg_match('/' . $search . '/s' . (!$caseSensitive ? 'i' : ''), $template->getSource())) !== 0;
             } else {
                 if ($caseSensitive) {
                     $matches = StringUtil::indexOf($template->getSource(), $search) !== false;
                 } else {
                     $matches = StringUtil::indexOfIgnoreCase($template->getSource(), $search) !== false;
                 }
             }
             if ($matches && !$invertSearch || !$matches && $invertSearch) {
                 $results[] = $row;
             }
         } else {
             // search and replace
             $matches = 0;
             if ($useRegex) {
                 $newSource = preg_replace('/' . $search . '/s' . (!$caseSensitive ? 'i' : ''), $replace, $template->getSource(), -1, $matches);
             } else {
                 if ($caseSensitive) {
                     $newSource = StringUtil::replace($search, $replace, $template->getSource(), $matches);
                 } else {
                     $newSource = StringUtil::replaceIgnoreCase($search, $replace, $template->getSource(), $matches);
                 }
             }
             if ($matches > 0) {
                 $template->setSource($newSource);
                 $row['matches'] = $matches;
                 $results[] = $row;
             }
         }
     }
     return $results;
 }
Ejemplo n.º 16
0
 public static function checkFromversion($currentVersion, $fromversion)
 {
     if (StringUtil::indexOf($fromversion, '*') !== false) {
         // from version with wildcard
         // use regular expression
         $fromversion = StringUtil::replace('\\*', '.*', preg_quote($fromversion, '!'));
         if (preg_match('!^' . $fromversion . '$!i', $currentVersion)) {
             return true;
         }
     } else {
         if (self::compareVersion($currentVersion, $fromversion, '=')) {
             return true;
         }
     }
     return false;
 }
 /**
  * @see TemplatePluginFunction::execute()
  */
 public function execute($tagArgs, Template $tplObj)
 {
     // needed params: link, page, pages
     if (!isset($tagArgs['link'])) {
         throw new SystemException("missing 'link' argument in pages tag", 12001);
     }
     if (!isset($tagArgs['pages'])) {
         if (($tagArgs['pages'] = $tplObj->get('pages')) === null) {
             throw new SystemException("missing 'pages' argument in pages tag", 12001);
         }
     }
     $html = '';
     if ($tagArgs['pages'] > 1) {
         // define page link for js function
         $html .= "<script type=\"text/javascript\">\n//<![CDATA[\nmultiPagesLinks.setPageLink('" . StringUtil::replace("'", "\\'", $tagArgs['link']) . "');\n//]]>\n</script>";
         // encode link
         $tagArgs['link'] = StringUtil::encodeHTML($tagArgs['link']);
         if (!isset($tagArgs['page'])) {
             if (($tagArgs['page'] = $tplObj->get('pageNo')) === null) {
                 $tagArgs['page'] = 0;
             }
         }
         // open div and ul
         $html .= "<div class=\"pageNavigation\">\n<ul>\n";
         // previous page
         $previousTitle = WCF::getLanguage()->getDynamicVariable('wcf.global.page.previous');
         if ($tagArgs['page'] > 1) {
             $html .= '<li class="skip"><a href="' . $this->insertPageNumber($tagArgs['link'], $tagArgs['page'] - 1) . '" title="' . $previousTitle . '"><img src="' . self::getIconPath('previousS.png') . '" alt="" /></a></li>' . "\n";
         } else {
             $html .= '<li class="skip"><img src="' . self::getIconPath('previousDisabledS.png') . '" alt="" /></li>' . "\n";
         }
         // first page
         $html .= $this->makeLink($tagArgs['link'], 1, $tagArgs['page']);
         // calculate page links
         $maxLinks = self::SHOW_LINKS - 4;
         $linksBeforePage = $tagArgs['page'] - 2;
         if ($linksBeforePage < 0) {
             $linksBeforePage = 0;
         }
         $linksAfterPage = $tagArgs['pages'] - ($tagArgs['page'] + 1);
         if ($linksAfterPage < 0) {
             $linksAfterPage = 0;
         }
         if ($tagArgs['page'] > 1 && $tagArgs['page'] < $tagArgs['pages']) {
             $maxLinks--;
         }
         $half = $maxLinks / 2;
         $left = $right = $tagArgs['page'];
         if ($left < 1) {
             $left = 1;
         }
         if ($right < 1) {
             $right = 1;
         }
         if ($right > $tagArgs['pages'] - 1) {
             $right = $tagArgs['pages'] - 1;
         }
         if ($linksBeforePage >= $half) {
             $left -= $half;
         } else {
             $left -= $linksBeforePage;
             $right += $half - $linksBeforePage;
         }
         if ($linksAfterPage >= $half) {
             $right += $half;
         } else {
             $right += $linksAfterPage;
             $left -= $half - $linksAfterPage;
         }
         $right = intval(ceil($right));
         $left = intval(ceil($left));
         if ($left < 1) {
             $left = 1;
         }
         if ($right > $tagArgs['pages']) {
             $right = $tagArgs['pages'];
         }
         // left ... links
         if ($left > 1) {
             if ($left - 1 < 2) {
                 $html .= $this->makeLink($tagArgs['link'], 2, $tagArgs['page']);
             } else {
                 $html .= '<li class="children"><a onclick="multiPagesLinks.startPageNumberInput(this)">&hellip;<img src="' . self::getIconPath('arrowDown.png') . '" alt="" /></a><input type="text" class="inputText" name="pageNo" /><div><ul>' . "\n";
                 $k = 0;
                 $step = intval(ceil(($left - 2) / self::SHOW_SUB_LINKS));
                 for ($i = 2; $i <= $left; $i += $step) {
                     $html .= $this->makeLink($tagArgs['link'], $i, $tagArgs['page'], $k != 0 && $k % 4 == 0);
                     $k++;
                 }
                 $html .= "</ul></div></li>\n";
             }
         }
         // visible links
         for ($i = $left + 1; $i < $right; $i++) {
             $html .= $this->makeLink($tagArgs['link'], $i, $tagArgs['page']);
         }
         // right ... links
         if ($right < $tagArgs['pages']) {
             if ($tagArgs['pages'] - $right < 2) {
                 $html .= $this->makeLink($tagArgs['link'], $tagArgs['pages'] - 1, $tagArgs['page']);
             } else {
                 $html .= '<li class="children"><a onclick="multiPagesLinks.startPageNumberInput(this)">&hellip;<img src="' . self::getIconPath('arrowDown.png') . '" alt="" /></a><input type="text" class="inputText" name="page" /><div><ul>' . "\n";
                 $k = 0;
                 $step = intval(ceil(($tagArgs['pages'] - $right) / self::SHOW_SUB_LINKS));
                 for ($i = $right; $i < $tagArgs['pages']; $i += $step) {
                     $html .= $this->makeLink($tagArgs['link'], $i, $tagArgs['page'], $k != 0 && $k % 4 == 0);
                     $k++;
                 }
                 $html .= "</ul></div></li>\n";
             }
         }
         // last page
         $html .= $this->makeLink($tagArgs['link'], $tagArgs['pages'], $tagArgs['page']);
         // next page
         $nextTitle = WCF::getLanguage()->getDynamicVariable('wcf.global.page.next');
         if ($tagArgs['page'] && $tagArgs['page'] < $tagArgs['pages']) {
             $html .= '<li class="skip"><a href="' . $this->insertPageNumber($tagArgs['link'], $tagArgs['page'] + 1) . '" title="' . $nextTitle . '"><img src="' . self::getIconPath('nextS.png') . '" alt="" /></a></li>' . "\n";
         } else {
             $html .= '<li class="skip"><img src="' . self::getIconPath('nextDisabledS.png') . '" alt="" /></li>' . "\n";
         }
         // close div and ul
         $html .= "</ul></div>\n";
     }
     // assign html output to template var
     if (isset($tagArgs['assign'])) {
         $tplObj->assign($tagArgs['assign'], $html);
         if (!isset($tagArgs['print']) || !$tagArgs['print']) {
             return '';
         }
     }
     return $html;
 }
 /**
  * Reads the objects from database.
  */
 public function readObjects()
 {
     $this->cachedList = $this->fromCache(StringUtil::replace(__CLASS__ . '::', "", __METHOD__));
 }
 /**
  * @see Page::assignVariables()
  */
 public function assignVariables()
 {
     parent::assignVariables();
     $this->frame->assignVariables();
     WCF::getTPL()->assign(array('commentID' => '#{commentID}', 'authorID' => '#{authorID}', 'authorName' => '#{authorName}', 'time' => '#{time}', 'message' => '#{message}', 'avatarPath' => '#{avatarPath}', 'avatarWidth' => '#{avatarWidth}', 'avatarHeight' => '#{avatarHeight}'));
     WCF::getTPL()->assign(array('userPermissions' => $this->userPermissions, 'modPermissions' => $this->modPermissions, 'entries' => $this->entryList->getObjects(), 'jsTemplateComment' => StringUtil::replace("\n", '', WCF::getTPL()->fetch('userGuestbookCommentBox'))));
 }
Ejemplo n.º 20
0
 /**
  * Sends the mail to given user.
  * 
  * @param	User		$user
  */
 protected function sendMail(User $user)
 {
     // send mail
     try {
         $mail = new Mail(array($user->username => $user->email), $this->userMailData['subject'], StringUtil::replace('{$username}', $user->username, $this->userMailData['text']), $this->userMailData['from']);
         if ($this->userMailData['enableHTML']) {
             $mail->setContentType('text/html');
         }
         $mail->send();
     } catch (SystemException $e) {
     }
     // ignore errors
 }
 /**
  * Replaces all php tags.
  * 
  * @param	string		$string
  * @return	string
  */
 public function replacePHPTags($string)
 {
     if (StringUtil::indexOf($string, '<?') !== false) {
         $string = StringUtil::replace('<?php', '@@PHP_START_TAG@@', $string);
         $string = StringUtil::replace('<?', '@@PHP_SHORT_START_TAG@@', $string);
         $string = StringUtil::replace('?>', '@@PHP_END_TAG@@', $string);
         $string = StringUtil::replace('@@PHP_END_TAG@@', "<?php echo '?>'; ?>\n", $string);
         $string = StringUtil::replace('@@PHP_SHORT_START_TAG@@', "<?php echo '<?'; ?>\n", $string);
         $string = StringUtil::replace('@@PHP_START_TAG@@', "<?php echo '<?php'; ?>\n", $string);
     }
     return $string;
 }
Ejemplo n.º 22
0
 /**
  * Parses a rawlist given by a ftp-server
  * and creates an easy to read array.
  *
  * @param 	array 		$rawlist
  * @return  	array 		
  */
 protected static function parseRawlist($rawlist)
 {
     $parsed = array();
     foreach ($rawlist as $list) {
         $entry = $_matches = array();
         // strict rule
         if (preg_match('%([\\-dl])([rwxst\\-]{9})[ ]+([0-9]+)[ ]+([^ ]+)[ ]+(.+)[ ]+([0-9]+)[ ]+([a-zA-Z]+[ ]+[0-9]+)[ ]+([0-9:]+)[ ]+(.*)%', $list, $_matches)) {
             $entry['scanrule'] = 'rule-1';
             $entry['type'] = $_matches[1] == 'd' ? 'folder' : 'file';
             $entry['filename'] = $_matches[9];
             $entry['size'] = $_matches[6];
             $entry['owner'] = $_matches[4];
             $entry['group'] = $_matches[5];
             $entry['permissions'] = $_matches[2];
             $entry['mtime'] = $_matches[7] . ' ' . $_matches[8];
         } elseif (preg_match('%([\\-dl])([rwxst\\-]{9})[ ]+(.*)[ ]+([a-zA-Z0-9 ]+)[ ]+([0-9:]+)[ ]+(.*)%', $list, $_matches)) {
             $entry['scanrule'] = 'rule-2';
             $entry['type'] = $_matches[1] == 'd' ? 'folder' : 'file';
             $entry['filename'] = $_matches[6];
             $entry['size'] = $_matches[3];
             $entry['permissions'] = $_matches[2];
             $entry['mtime'] = $_matches[4] . ' ' . $_matches[5];
         } elseif (preg_match('%([0-9/\\-]+)[ ]+([0\\--9:AMP]+)[ ]+([0-9]*)[ ]+(.*)%', $list, $_matches)) {
             $entry['scanrule'] = 'rule-3';
             $entry['size'] = $_matches[3];
             $entry['type'] = $entry['size'] == '' ? 'folder' : 'file';
             $entry['filename'] = StringUtil::trim(StringUtil::replace('<DIR>', '', $_matches[4]));
             $entry['owner'] = '';
             $entry['group'] = '';
             $entry['permissions'] = '';
             $entry['mtime'] = $_matches[1] . ' ' . $_matches[2];
         } elseif (preg_match('%([a-zA-Z0-9_\\-]+)[ ]+([0-9]+)[ ]+([0-9/\\-]+)[ ]+([0-9:]+)[ ]+([a-zA-Z0-9_ \\-\\*]+)[ /]+([^/]+)%', $list, $_matches)) {
             $entry['scanrule'] = 'rule-4';
             $entry['type'] = $_matches[5] != '*STMF' ? 'folder' : 'file';
             $entry['filename'] = $_matches[6];
             $entry['size'] = $_matches[2];
             $entry['owner'] = $_matches[1];
             $entry['group'] = '';
             $entry['permissions'] = '';
             $entry['mtime'] = $_matches[3] . ' ' . $_matches[4];
         } else {
             $entry['scanrule'] = 'no-rule';
             $entry['type'] = 'unknown';
             $entry['filename'] = $list;
         }
         // skip '.' and '..' directories
         if ($entry['filename'] == '.' || $entry['filename'] == '..') {
             continue;
         }
         $parsed[] = $entry;
     }
     return $parsed;
 }
Ejemplo n.º 23
0
 /**
  * Tests signature replace(string, array<string, string>):
  * Checks if replace() applies the mapping of search/replace pairs to the string.
  */
 public function testReplaceAppliesMappingIfAssociativeArrayIsProvided()
 {
     $mapping = array('hello' => 'welcome', 'world' => 'home');
     $result = StringUtil::replace('hello world', $mapping);
     $this->assertEquals('welcome home', $result);
 }
 /**
  * Searches in language items.
  * 
  * @param	string		$search		search query
  * @param	string		$replace
  * @param	integer		$languageID
  * @param	boolean		$useRegex
  * @param	boolean		$caseSensitive
  * @param	boolean		$searchVariableName
  * @return	array		results 
  */
 public static function search($search, $replace = null, $languageID = null, $useRegex = 0, $caseSensitive = 0, $searchVariableName = 0)
 {
     // get available language items
     $results = array();
     $availableLanguageItems = array();
     $sql = "SELECT\t\tlanguageItemID, languageItem, languageID\n\t\t\tFROM\t\twcf" . WCF_N . "_language_item language_item,\n\t\t\t\t\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tWHERE \t\tlanguage_item.packageID = package_dependency.dependency\n\t\t\t\t\tAND package_dependency.packageID = " . PACKAGE_ID . "\n\t\t\t\t\t" . ($languageID !== null ? "AND languageID = " . $languageID : "") . "\n\t\t\tORDER BY\tpackage_dependency.priority";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $availableLanguageItems[$row['languageID']][$row['languageItem']] = $row['languageItemID'];
     }
     // get ids
     if (!count($availableLanguageItems)) {
         return $results;
     }
     $languageItemIDs = '';
     foreach ($availableLanguageItems as $languageItems) {
         if (!empty($languageItemIDs)) {
             $languageItemIDs .= ',';
         }
         $languageItemIDs .= implode(',', $languageItems);
     }
     // build condition
     $searchCondition = '';
     // case sensitive
     if ($caseSensitive) {
         $searchCondition .= 'BINARY ';
     }
     // search field
     if ($searchVariableName) {
         $searchCondition .= 'languageItem ';
     } else {
         $searchCondition .= 'languageItemValue ';
     }
     // regex
     if ($useRegex) {
         $searchCondition .= "REGEXP '" . escapeString($search) . "'";
     } else {
         $searchCondition .= "LIKE '%" . addcslashes(escapeString($search), '_%') . "%'";
     }
     if (!$searchVariableName) {
         $searchCondition .= ' OR ' . ($caseSensitive ? 'BINARY ' : '') . 'languageCustomItemValue ';
         // regex
         if ($useRegex) {
             $searchCondition .= "REGEXP '" . escapeString($search) . "'";
         } else {
             $searchCondition .= "LIKE '%" . addcslashes(escapeString($search), '_%') . "%'";
         }
     }
     // search
     $updatedItems = array();
     $sql = "SELECT\t\tlanguageItemID, languageItem, languageID, languageCategoryID, languageItemValue, languageCustomItemValue\n\t\t\tFROM\t\twcf" . WCF_N . "_language_item\n\t\t\tWHERE\t\tlanguageItemID IN (" . $languageItemIDs . ")\n\t\t\t\t\tAND (" . $searchCondition . ")";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if ($replace !== null) {
             // search and replace
             $matches = 0;
             if ($useRegex) {
                 $newValue = preg_replace('/' . $search . '/s' . (!$caseSensitive ? 'i' : ''), $replace, $row['languageCustomItemValue'] ? $row['languageCustomItemValue'] : $row['languageItemValue'], -1, $matches);
             } else {
                 if ($caseSensitive) {
                     $newValue = StringUtil::replace($search, $replace, $row['languageCustomItemValue'] ? $row['languageCustomItemValue'] : $row['languageItemValue'], $matches);
                 } else {
                     $newValue = StringUtil::replaceIgnoreCase($search, $replace, $row['languageCustomItemValue'] ? $row['languageCustomItemValue'] : $row['languageItemValue'], $matches);
                 }
             }
             if ($matches > 0) {
                 // update value
                 if (!isset($updatedItems[$row['languageID']])) {
                     $updatedItems[$row['languageID']] = array();
                 }
                 if (!isset($updatedItems[$row['languageID']][$row['languageCategoryID']])) {
                     $updatedItems[$row['languageID']][$row['languageCategoryID']] = array();
                 }
                 $updatedItems[$row['languageID']][$row['languageCategoryID']][$row['languageItem']] = $newValue;
                 // save matches
                 $row['matches'] = $matches;
             }
         }
         $results[] = $row;
     }
     // save updates
     if (count($updatedItems) > 0) {
         foreach ($updatedItems as $languageID => $categories) {
             $language = new LanguageEditor($languageID);
             foreach ($categories as $categoryID => $items) {
                 $useCustom = array();
                 foreach (array_keys($items) as $item) {
                     $useCustom[$item] = 1;
                 }
                 $language->updateItems($items, $categoryID, PACKAGE_ID, $useCustom);
             }
         }
     }
     return $results;
 }
 /**
  * Builds the attributes of a bbcode tag.
  * 
  * @param	string		$string
  * @return	array		bbcode attributes
  */
 protected function buildTagAttributes($string)
 {
     preg_match_all("~(?:^|,)('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'|[^,]*)~", $string, $matches);
     // remove quotes
     for ($i = 0, $j = count($matches[1]); $i < $j; $i++) {
         if (StringUtil::substring($matches[1][$i], 0, 1) == "'" && StringUtil::substring($matches[1][$i], -1) == "'") {
             $matches[1][$i] = StringUtil::replace("\\'", "'", $matches[1][$i]);
             $matches[1][$i] = StringUtil::replace("\\\\", "\\", $matches[1][$i]);
             $matches[1][$i] = StringUtil::substring($matches[1][$i], 1, -1);
         }
     }
     return $matches[1];
 }
Ejemplo n.º 26
0
 /**
  * Returns censored words from a text. 
  * 
  * @param	string		$text
  * @return	mixed		$matches / false
  */
 public static function test($text)
 {
     // reset matches
     self::$matches = array();
     // get words which should be censored
     $censoredWords = explode("\n", StringUtil::unifyNewlines(StringUtil::toLowerCase(CENSORED_WORDS)));
     // format censored words
     $censoredWords = ArrayUtil::trim($censoredWords);
     // string to lower case
     $text = StringUtil::toLowerCase($text);
     // ignore bbcode tags
     $text = preg_replace('~\\[/?[a-z]+[^\\]]*\\]~i', '', $text);
     // split the text in single words
     self::$words = preg_split("!" . self::$delimiters . "+!", $text, -1, PREG_SPLIT_NO_EMPTY);
     // check each word if it censored.
     for ($i = 0, $count = count(self::$words); $i < $count; $i++) {
         $word = self::$words[$i];
         foreach ($censoredWords as $censoredWord) {
             // check for direct matches ("badword" == "badword")
             if ($censoredWord == $word) {
                 // store censored word
                 if (isset(self::$matches[$word])) {
                     self::$matches[$word]++;
                 } else {
                     self::$matches[$word] = 1;
                 }
                 continue 2;
             } else {
                 if (StringUtil::indexOf($censoredWord, '*') !== false) {
                     $censoredWord = StringUtil::replace('\\*', '.*', preg_quote($censoredWord));
                     if (preg_match('!^' . $censoredWord . '$!', $word)) {
                         // store censored word
                         if (isset(self::$matches[$word])) {
                             self::$matches[$word]++;
                         } else {
                             self::$matches[$word] = 1;
                         }
                         continue 2;
                     }
                 } else {
                     if (StringUtil::indexOf($censoredWord, '~') !== false) {
                         $censoredWord = StringUtil::replace('~', '', $censoredWord);
                         if (($position = StringUtil::indexOf($censoredWord, $word)) !== false) {
                             if ($position > 0) {
                                 // look behind
                                 if (!self::lookBehind($i - 1, StringUtil::substring($censoredWord, 0, $position))) {
                                     continue;
                                 }
                             }
                             if ($position + StringUtil::length($word) < StringUtil::length($censoredWord)) {
                                 // look ahead
                                 if ($newIndex = self::lookAhead($i + 1, StringUtil::substring($censoredWord, $position + StringUtil::length($word)))) {
                                     $i = $newIndex;
                                 } else {
                                     continue;
                                 }
                             }
                             // store censored word
                             if (isset(self::$matches[$censoredWord])) {
                                 self::$matches[$censoredWord]++;
                             } else {
                                 self::$matches[$censoredWord] = 1;
                             }
                             continue 2;
                         }
                     }
                 }
             }
         }
     }
     // at least one censored word was found
     if (count(self::$matches) > 0) {
         return self::$matches;
     } else {
         return false;
     }
 }