Drupal prints unwanted characters - drupal-7

I'm new to Drupal, I'm getting unwanted characters printed on the website. After header, I get h character, and f after footer, and w after widget. How can I remove this?
This is an example of header code, note the h character there:
http://prntscr.com/k15afh there are also w and f characters after widgets and footer.
Note, I'm using Drupal 7

The problem is in this line in the custom blocks module:
$block['content'] = array('data' => array('#theme' => 'header_view', '#node' => $node,),'class' => array('header_view'),);
return $block;
It was returning h character (as the first character of header_view) as a result of using class the. I don't know if this is an obsolete method, or it's a code mistake.

Related

How to read Word Paragraph Line by Line in C#?

I am trying to read word content line by line. But I am facing an issue. When trying to read paragraph. If paragraph content is multi line. I am getting single line internally. Can any one please help me on this.
Expected Output:
Line 1 - > TERM BHFKGBHFGFKJHGKJSHFKG ABC1 IOUTOYTIUYRUYTIREYTU B08
Line 2 - > NBHFBHDFGJDSBHKHDGFJGJGDJK 3993 JBHKJSFGSDKFJDGFJKDSBF3993
Line 3 - > JHBJKFHKJGDGFSFGB08 HGHGGFGFDGJFFFDSGFABC1 JJBVHGHDFTERM
Line 4 - > TERMBHFKGBHFGFKJHGKJSHFKG ABC1IOUTOYTIUYRUYTIREYTU B08NBHFBHDFGJDSBHKHDGFJGJGDJK
Line 5 - > 39931234567890987654321
Actual Output:
Single Line -> TERM BHFKGBHFGFKJHGKJSHFKG ABC1 IOUTOYTIUYRUYTIREYTU B08 NBHFBHDFGJDSBHKHDGFJGJGDJK 3993 JBHKJSFGSDKFJDGFJKDSBF3993 JHBJKFHKJGDGFSFGB08 HGHGGFGFDGJFFFDSGFABC1 JJBVHGHDFTERM
TERMBHFKGBHFGFKJHGKJSHFKG ABC1IOUTOYTIUYRUYTIREYTU B08NBHFBHDFGJDSBHKHDGFJGJGDJK
39931234567890987654321
Below is my code sample:
OpenXml:
using (WordprocessingDocument doc = WordprocessingDocument.Open(fs, false))
{
var bodyText = doc.MainDocumentPart.Document.Body;
if (bodyText.ChildElements.Count > 0)
{
foreach (var items in bodyText)
{
if (items is Paragraph)
{
var par = items.InnerText;
}
}
}
}
Office.Interop
object nullobj = System.Reflection.Missing.Value;
Word.Application app = new Word.Application();
Word.Document doc = app.Documents.Open(FilePath, ref nullobj, FileAccess.Read,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
foreach (Word.Paragraph paragraph in doc.Paragraphs)
{
var line = paragraph.Range.Text;
}
It is not possible to determine individual lines in the closed file. Lines are dynamically generated when a document is opened in Word and where a line "breaks" depends on many factors - it's not necessarily the same from system profile to system profile. So it's necessary to use the interop, not Open XML to pick up where lines break on the screen.
What's more, the Word object model does not provide "Line" objects for this very reason - there is no "line", only a visual representation of how the page will print, given the current printer driver and version of Windows.
The only part of the Word object model that recognizes "lines" is Selection, as this works solely with what's displayed on the screen.
The following code demonstrates how this can be done.
First, since Selection is being worked with and this is visible on-screen, ScreenUpdating is disabled in order to reduce screen flicker and speed up processing. (Note that working with selections is generally much slower than other object model processing.)
Using ComputeStatistics the number of lines in a paragraph is determined. An array (you can also use a list or anything else) to contain the lines is instantiated. The paragraph range is "collapsed" to its starting point and visually selected.
Now the lines in the paragraph are looped, based on the number of lines. The selection is extended (MoveEnd method) by one line (again, moving by lines is only available to a selection) and the selected text written to the array (or whatever).
Finally, screen updating is turned back on.
wdApp.ScreenUpdating = false;
foreach (Word.Paragraph para in doc.Paragraphs)
{
Word.Range rng = para.Range;
int lNumLines = rng.ComputeStatistics(Word.WdStatistic.wdStatisticLines);
string[] aLines = new String[lNumLines];
rng.Collapse(Word.WdCollapseDirection.wdCollapseStart);
rng.Select();
for (int i = 0; i < lNumLines; i++)
{
wdApp.Selection.MoveEnd(Unit: Word.WdUnits.wdLine, Count: 1);
aLines[i] = wdApp.Selection.Text;
wdApp.Selection.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
}
for (int i = 0; i < aLines.Length; i++)
{
Debug.Print(aLines[i]);
}
}
wdApp.ScreenUpdating = true;
In Word, a paragraph is a sinle line of text. Change the size of the print area (e.g. change the margins and/or page size) or the font/point size and the text reflows accordingly. Moerover, since Word uses the active printer driver to optimise the page layout, what exists on a given line in one computer may not exist on the same line on another computer.
Depending on your requirements, though, you could employ Word's predefined '\Line' bookmark to navigate between lines or the Rectangle.Lines property.

Using React and trying to print a value exactly from {this.state.value}

I'm using React.js and in my state object of my App component, I have a value that contains \n characters and spaces.
this.state = {
value: "def foo():\n print('this is a function')\n\nfoo()"
}
However, when I try to show this value to the screen by wrapping this.state.value in a p tag like <p>{this.state.value}</p>, it simply prints out
def foo(): print('this is a function') foo()
without showing the spaces and \n characters. Is there any way I can get the value to print out exactly like how it's shown in the state object? Going into the React inspector on Chrome confirms that the value indeed matches the one in my state object.
This isn't specific to React but to how white space characters are treated in HTML. A new line can be displayed as <br> inside <p> and multiple spaces can be displayed as . While newline character and multiple spaces are displayed similarly to single space character.
It could be outputted as
<p>def foo():
print('this is a function')
foo()</p>
with same result.
In order to change that, the way how white space is displayed should be changed with white-space CSS property, e.g.:
<p style={{ 'white-space': 'pre' }}>
{this.state.value}
</p>
If the intention is to output the code with specified indentation and monospaced font, there's already <pre> tag that already has appropriate style by default, it can be used instead of <p>.
try to use string template with back-tick syntax like:
this.state = {
value: `def foo():
print('this is a function')
foo()`
}
EDIT: for better readability you can try to define constant before setState call:
const strTemplate = `def foo():
print('this is a function')
foo()`;
this.state = {
value: strTemplate
}
Let me know if it works :)
Try out this string:
this.state = {
value: "def foo():<br/> print('this is a function')<br/><br/>foo()"
}

CakePHP parsing the URI and getting ID

I have a SEO URL like
lieferservice-pizzeria-da-persio-26-offenbach
in my bootstrap file I am trying to pase this URL and get ID of a shop which is in this is 26
Then I can read the database to get infos of the shop. What will be the best way to do this. have no idea.
The proposed solution simply removes all non digits so you end up with only digits. This works if you can ensure that you'll never have a digit in your string else than the string. So with a string like 'lieferservice-pizzeria12-da-24-persio-26-offenbach' you would get 122426 instead of the 26 you wanted to.
If you want to ensure that you only accept -somedigit- as id you should use:
preg_match("/-([0-9]+)-/", $input_line, $output_array);
instead.
What this actually does is really simple:
It simply looks for the first string starting with a "-" followed by exclusive! digits and ending with "-" than it returns the whole string in $output_array[0] (in your example -26-) and the digit (the stuff inside the brackets) in $output_array[1] which equals 26 in your case.
that's what routes are for. you can paramatized any part of url and access it in the request.in your case i think you want to combine some sort of a slug with an id separted by dash. that's a piece of cake.
Router::connect('/:slug-:id', array('controller' => 'yourController', 'action' => 'yourAction'), array('id' => '[0-9]+','slug' => '[a-zA-z-]+'));
//inside your action
$id = $this->request->params['id'];
$slug = $this->request->params['slug'];
no nee for regex :)
Best Solution
$str = 'lieferservice-pizzeria-da-persio-26-offenbach';
$int = intval(preg_replace('/[^0-9]+/', '', $str), 10);
var_dump($int );
Its return only int 26
Assuming you have a function in your controller, let call it
public function getUrl(){
}
The first think is to make CakePhp accept the type of URL you are passing (with special characters like "-"). In your route you can have this:
Router::connect('/getUrl/:id', array('controller' => 'yourControllerName', 'action' => 'getUrl'), array('id' => '[0-9A-Za-z= -]+'));
Now if you pass your URL as
www.domain.com/getUrl/lieferservice-pizzeria-da-persio-26-offenbach
Then back to your function
public function getUrl(){
$getValueFromUrl = $this->params['id'];
// Use PHP explode function to get 26 out of $getValueFromUrl
}

Silverlight TelerikGrid 'EndsWith' Filter is Not Working for values having Leading Spaces (Trailing Spaces)

I'm having problem binding the data to the grid when I filter using the operator EndsWith.
fieldfilter.Filter1.Operator.ToString == "IsEqualTo"
fieldFilter.Filter1.Value = fieldFilter1.Value.ToString().PadRight(120, ' ');
In the database the values of the column have the Leading Spaces, and I had problem making it work for IsEqualTo also but I fixed it by padding leading spaces to the right of the input string. (as shown below)
But, I'm not sure how I should do it for the EndsWith Filter Operator.
I'm able to get the rows from the database by using where condition like '%ABC'.
But the rows are not binding to the grid.
When you get the callback from DB with the collection(collection).
queueColl = new HierarchyItemCollection();// the original collection- before
List<HierarchyItem> items = new List<HierarchyItem>(collection.OrderBy(item => item.Text));
items.ForEach(item =>
{
item.Tag = (stcQueue)item.Tag;
item.ObjectData = null;
queueColl.Add(item);
});
radTreeOH.DataContext = queueColl; // I am having a tree.

Property file with key containing whitespace

I would like to directly read a property file into a map.
I found an example such as :
def propsFile = new File(fileName)
props.load(propsFile.newDataInputStream())
props.each { k,v->
println "${k} /// ${v}\n"
}
Ok, it works correctly for line looking like :
toto=titi
i.e. where the key contains no whitespace.
But I have to treat a property file where keys will looks like
This is a key (example)=Value
where This is a key (example) will be the key.
And the example above does not work at all as it gives the first word (This) as the key.
So, is there a way to tell that the key value separator is = and no other character.
If not, il will read line by line and split... but i would prefer a more elegant solution if any.
Thanks for your help
J.L.P.
If your properties file is not following the specification (with escaped spaces in the key names) then you'll have to write your own parser I believe, and go line by line.
Not too hard though, you should be able to use something like:
String props = '''toto = titi
|foo=bar
|# comment
|
|way and hay = yes'''.stripMargin()
Map properties = props.split( '\n' )
.findAll { !it.startsWith( '#' ) && it.trim().length() }
.collectEntries { line ->
line.tokenize( '=' )*.trim()
}

Resources