I am trying to create custom TOC in mpdf on first page but not sure how to get the page number for dynamic content. Can anyone please help?
$html = '<div class="frame frame-top">
<div class="mpdf_toc" id="mpdf_toc_0">
<div class="mpdf_toc_level_0">
<a class="mpdf_toc_a" href="#__mpdfinternallink_1">
<span class="mpdf_toc_t_level_0">Section 1</span>
</a>
<dottab outdent="2em" />
<a class="mpdf_toc_a" href="#__mpdfinternallink_1">
<span class="mpdf_toc_p_level_0">5</span>
</a>
</div>
<div class="mpdf_toc_level_1">
<a class="mpdf_toc_a" href="#__mpdfinternallink_2">
<span class="mpdf_toc_t_level_1">Chapter 1</span>
</a>
<dottab outdent="2em" />
<a class="mpdf_toc_a" href="#__mpdfinternallink_2">
<span class="mpdf_toc_p_level_1">5</span>
</a>
</div>
<div class="mpdf_toc_level_2">
<a class="mpdf_toc_a" href="#__mpdfinternallink_3">
<span class="mpdf_toc_t_level_2">Topic 1</span>
</a>
<dottab outdent="2em" />
<a class="mpdf_toc_a" href="#__mpdfinternallink_3">
<span class="mpdf_toc_p_level_2">5</span>
</a>
</div>
</div>
You cannot, pages are determined during putting the document together when the Output() method is called and the content is finalized.
Related
this is second page
<div class="accordion__item">
<a href="<?= base_url(); ?>client/progress?id#$habit->id; ?> ">
<div class="accordion__header collapsed" data-toggle="collapse" data-target="#bordered_no-gutter_collapseThree">
<span class="accordion__header--text">Progress By Habit</span>
<span class="accordion__header--indicator style_two"></span>
</div>
</a>
<div id="bordered_no-gutter_collapseThree" class="collapse accordion__body" data-parent="#accordion-four">
<?php
if (!empty($all_habits)) {
foreach ($all_habits as $habit) { ?>
<div class="accordion__header accordion" id="prog_habit" value="<?= $habit->id; ?>">
<span class="accordion__header--text"></span><?= $habit->title; ?></span>
</div>
<?php }
} ?>
</div>
</div>
this is first page where i want to redirect this page:
<i class="fa fa-eye"></i>
You need to use fragments in first page url Like this :
<i class="fa fa-eye"></i>
And Second Page Like this
<div class="accordion__item" id="mydiv">
<a href="<?= base_url(); ?>client/progress?id#$habit->id; ?> ">
<div class="accordion__header collapsed" data-toggle="collapse" data-target="#bordered_no-gutter_collapseThree">
<span class="accordion__header--text">Progress By Habit</span>
<span class="accordion__header--indicator style_two"></span>
</div>
</a>
<div id="bordered_no-gutter_collapseThree" class="collapse accordion__body" data-parent="#accordion-four">
<?php
if (!empty($all_habits)) {
foreach ($all_habits as $habit) { ?>
<div class="accordion__header accordion" id="prog_habit" value="<?= $habit->id; ?>">
<span class="accordion__header--text"></span><?= $habit->title; ?></span>
</div>
<?php }
} ?>
</div>
I hope this code working for you!
Happy Coding!
I'm using a src which collects data and works as an API.
The website it takes info from had been redone and some stuff work, some don't.
PHP:
protected $namexpath = ".//h1[contains(#itemprop,\"name\")]/a";
Works with HTML Source:
<h1 itemprop="name" class="fn itemTitle">
<a title="https://www.paginegialle.it/altopascio-lu/lotto-ricevitorie/lucky-planet-duro-anastasia-tabaccheria-ricevitori" href="https://www.paginegialle.it/altopascio-lu/lotto-ricevitorie/lucky-planet-duro-anastasia-tabaccheria-ricevitori">
Lucky <strong>Planet</strong> - Duro Anastasia <strong>Tabaccheria</strong> Ricevitoria Lotto
</a>
</h1>
But this is not working:
PHP:
protected $telephonexpath = ".//div[#class=\"hidden-phone-elem visiblePhone\"]/span";
HTML Source:
<section itemscope="" itemtype="https://schema.org/LocalBusiness" class="vcard listElement flFree " data-user="teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda" data-id="4" data-fl_free="true" data-cd_opec="GU01WAAW" data-cd_aggregazione="23787370" data-cd_id_sede="E57901ED-8833-A2AD-E040-A8C08D264C56">
<div class="container">
<div class="row">
<div class="col contentCol">
<header>
<div class="tabletOnlyBadge">
</div>
<h1 itemprop="name" class="fn itemTitle">
<a title="https://www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda" href="https://www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda">
<strong>Planet</strong> Cafe' di Tozzi Iolanda
</a>
</h1>
<span class="itemSubtitle">
</span>
<div>
<span class="itemAddress">
<span class="adr" itemprop="location" itemscope="" itemtype="https://schema.org/Place">
<div class="street-address">
<span>105, Via Roma</span> -
<span class="postal-code">81030</span>
<span class="locality">Teverola</span> <span class="region">(CE)</span>
</div>
<div style="display: none;">
<span>40.99494</span>
<span>14.2077</span>
</div>
</span>
</span>
</div>
</header>
<div>
<div class="hidden-phone-wrapper">
<span class="custom-label"></span>
<div class="hidden-phone-elem">
<div class="btn btn-yellow btn-show-phone" data-pag="mostra telefono" data-context="listing">
<span>MOSTRA TELEFONO</span>
</div>
<div class="btn btn-hidden-phone">
<span class="phIco "></span>
<span class="phone-label">081 5034556</span>
</div>
</div>
</div>
<div class="itemGeoLinks">
<ul>
</ul>
</div>
<div class="itemPayoff">
<p class="payoff-title">
<a class="cat" href="//www.paginegialle.it/ricerca/cat/008647000" rel="nofollow"><strong>Tabacchi</strong>, sigarette e sigari - produzione e commercio</a>
</p>
<p itemprop="description" class="payoff-txt"></p>
</div>
<div class="itemInfoTags">
</div>
</div>
</div>
<div class="col-3 logoCol">
<div class="itemRating">
<a rel="nofollow" href="//www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda/commenti#scrivi">
<ul class="stars">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<span class="label scriviRecensione">Scrivi una recensione</span>
</a>
</div>
<figure class="itemLogo">
<div class="img-container-ext">
<div class="img-container-int">
<a href="https://www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda" title="Dettagli azienda">
<img itemprop="image" alt="Planet Cafe' di Tozzi Iolanda" title="Planet Cafe' di Tozzi Iolanda" data-original="" class="elementImage photo" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" pagespeed_url_hash="1859759222" onload="pagespeed.CriticalImages.checkImageForCriticality(this);">
</a>
</div>
</div>
</figure>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<nav class="itemFooter">
<a class="btn btn-black icn-vetrina shinystat_ssxl" data-pag="vetrina" href="//www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda">Vetrina</a>
<a class="btn btn-blank icn-showOnMap btnShowOnMap shinystat_ssxl" data-pag="vedimappa" href="https://www.paginegialle.it/teverola-ce/bar/rivendita-generi-monopolio-n.-2-tozzi-iolanda/mappa" rel="nofollow"> <span>Vedi su mappa</span></a>
</nav>
</div>
</div>
</div>
www.paginegialle.it//ricerca//TABACCO%20PLANET?mr=50
So You might see the HTML easier.
I edited and I am adding some text because It won't let me finalize edit since it says too much code, I fixed the first part and changed from span to h1
The Xpath does not match the HTML. The relevant fragment seems to be:
<div class="hidden-phone-elem">
<div class="btn btn-yellow btn-show-phone" data-pag="mostra telefono" data-context="listing">
<span>MOSTRA TELEFONO</span>
</div>
<div class="btn btn-hidden-phone">
<span class="phIco "></span>
<span class="phone-label">081 5034556</span>
</div>
</div>
The div has only the class hidden-phone-elem and two descendant spans. Xpath 1.0 has no token selector function, but it can be emulated with string functions.
normalize-space() - replace all whitespace sequences with a single space, trim
concat() - concatenate strings
contains() - look for substring
The trick is to normalize the attribute to something like classToMatch otherClass and look if that contains classToMatch. (Take note of the spaces at the start/end).
$document = new DOMDocument();
$document->loadHTML($html);
$xpath = new DOMXpath($document);
$expression = 'string(
//div[
contains(concat(" ", normalize-space(#class), " "), " hidden-phone-elem ")
]
//span[
contains(concat(" ", normalize-space(#class), " "), " phone-label ")
]
)';
var_dump($xpath->evaluate($expression));
Output:
string(11) "081 5034556"
In an example category, the result products are listed using an unknown template. I have pagayo electronics theme as default.It uses a class called item-review and item-bottom for listing. they aren't in html code.
code is like this:
<ul class="products-grid">
<li class="item first">
<img src="http://magicfly.ir/media/catalog/product/cache/1/small_image/135x/9df78eab33525d08d6e5fb8d27136e95/1/3/13steps2.jpg" width="135" height="135" alt="13 Steps to Mentalism" />
<h2 class="product-name">13 Steps to Mentalism</h2>
<div class="ratings">
<span class="amount">1 نظر</span>
</div>
<div class="price-box">
<span class="regular-price" id="product-price-10">
<span class="price">30٬000 تومان</span> </span>
</div>
<div class="actions">
<p><button type="button" title="افزودن به سبد" class="button btn-cart" onclick="setLocationAjax('http://magicfly.ir/checkout/cart/add/uenc/aHR0cDovL21hZ2ljZmx5LmlyL21lbnRhbGlzbS5odG1s/product/10/form_key/Ql6smZ0IvKikUDgX/','10')"><span><span>افزودن به سبد</span></span></button></p>
<ul class="add-to-links">
<li>افزودن به لیست دلخواه</li>
<li><span class="separator">|</span> افزودن به مقایسه</li>
</ul>
while it should be like this (wrap with item-review and item-bottom classes):
<ul class="products-grid first odd">
<li class="item first">
<img src="http://demo.pagayo.com/media/catalog/product/cache/1/small_image/210x/9df78eab33525d08d6e5fb8d27136e95/a/p/apple-tv-1.jpg" alt="Apple TV" height="210" width="210">
<div class="item-review">
</div>
<div class="item-bottom">
<h2 class="product-name">Apple TV</h2>
<div class="price-box">
<span class="regular-price" id="product-price-9">
<span class="price">$99.00</span> </span>
</div>
<div class="actions">
<button type="button" title="Add to Cart" class="button btn-cart" onclick="setLocation('http://demo.pagayo.com/pagayotheme001/checkout/cart/add/uenc/aHR0cDovL2RlbW8ucGFnYXlvLmNvbS9wYWdheW90aGVtZTAwMS9hY2Nlc3Nvcmllcy5odG1s/product/9/')"><span><span>Add to Cart</span></span></button>
</div>
</div>
</li>
<li class="item">
<img src="http://demo.pagayo.com/media/catalog/product/cache/1/small_image/210x/9df78eab33525d08d6e5fb8d27136e95/4/_/4.jpg" alt="Bose SoundDock Portable Digital Music System" height="210" width="210">
<div class="item-review">
<div class="ratings">
<div class="rating-box">
<div class="rating" style="width:97%"></div>
</div>
<span class="amount">2 Review(s)</span>
</div>
</div>
<div class="item-bottom">
<h2 class="product-name">Bose SoundDock Portable Digital Music System</h2>
<div class="price-box">
<span class="regular-price" id="product-price-22">
<span class="price">$399.95</span> </span>
</div>
<div class="actions">
<button type="button" title="Add to Cart" class="button btn-cart" onclick="setLocation('http://demo.pagayo.com/pagayotheme001/checkout/cart/add/uenc/aHR0cDovL2RlbW8ucGFnYXlvLmNvbS9wYWdheW90aGVtZTAwMS9hY2Nlc3Nvcmllcy5odG1s/product/22/')"><span><span>Add to Cart</span></span></button>
</div>
</div>
</li>
<li class="item last">
<img src="http://demo.pagayo.com/media/catalog/product/cache/1/small_image/210x/9df78eab33525d08d6e5fb8d27136e95/1/_/1.jpg" alt="Bose SoundLink Bluetooth Mobile speaker II" height="210" width="210">
<div class="item-review">
</div>
<div class="item-bottom">
<h2 class="product-name">Bose SoundLink Bluetooth Mobile speaker II</h2>
<div class="price-box">
<span class="regular-price" id="product-price-21">
<span class="price">$349.95</span> </span>
</div>
<div class="actions">
<button type="button" title="Add to Cart" class="button btn-cart" onclick="setLocation('http://demo.pagayo.com/pagayotheme001/checkout/cart/add/uenc/aHR0cDovL2RlbW8ucGFnYXlvLmNvbS9wYWdheW90aGVtZTAwMS9hY2Nlc3Nvcmllcy5odG1s/product/21/')"><span><span>Add to Cart</span></span></button>
</div>
</div>
</li>
</ul>
in
/app/design/frontend/default/pagayo-theme-001/template/catalog/product/list.phtml
it is correctly wrapped but it seems it uses another theme that doesn't wrap it.
I didn't specify custom template for category or any product.
The amazing thing here is I checked list.phtml of base template and copied pagayo list.phtml to base. Just nothing happened.
I want it to use the default theme I specified in configuration Or at least find the phtml file of this piece of code to edit and make it correct.
without seeing its had to infer solution. possibilities are:
1) There can be an issue of improperly selected Magento Package.
system->configuration->Design->Package
2) If you want to see which template using on Template Path hints
system->configuration-> Developer -> Debug -> Template Path Hints select to on
clear cache and refresh the page.
I need to extract from this html:
<div class="list-group">
<a class="list-group-item active">
<h4 class="list-group-item-heading">{EVENT_GROUP_TIME}</h4>
</a>
{EVENTS:}
<a class="list-group-item">
<h4 class="list-group-item-heading">{EVENT_NAME}</h4>
<p class="list-group-item-text"><i>{EVENT_LECTURER}</i></p>
<p class="list-group-item-text">{EVENT_TIME}</p>
<p class="list-group-item-text">{EVENT_LOCATION}</p>
</a>
{ENDEVENTS}
</div>
Two substring: with {EVENTS:}...{ENDEVENTS} block and second is everything else. In other words:
$group_header =
<div class="list-group">
<a class="list-group-item active">
<h4 class="list-group-item-heading">{EVENT_GROUP_TIME}</h4>
</a>
</div>
and $group_body =
<a class="list-group-item">
<h4 class="list-group-item-heading">{EVENT_NAME}</h4>
<p class="list-group-item-text"><i>{EVENT_LECTURER}</i></p>
<p class="list-group-item-text">{EVENT_TIME}</p>
<p class="list-group-item-text">{EVENT_LOCATION}</p>
</a>
I tried to make it with substr but it seems to be too slow with big date. Can someone suggest how to make such operation with regexp in php?
The Regular Expression You Need is this:
/(.*)({EVENTS:}(.*){ENDEVENTS})(.*)/s
Here is the complete PHP Code to test it:
<?php
$regex = "/(.*)({EVENTS:}(.*){ENDEVENTS})(.*)/s";
$string = "
<div class=\"list-group\">
<a class=\"list-group-item active\">
<h4 class=\"list-group-item-heading\">{EVENT_GROUP_TIME}</h4>
</a>
{EVENTS:}
<a class=\"list-group-item\">
<h4 class=\"list-group-item-heading\">{EVENT_NAME}</h4>
<p class=\"list-group-item-text\"><i>{EVENT_LECTURER}</i></p>
<p class=\"list-group-item-text\">{EVENT_TIME}</p>
<p class=\"list-group-item-text\">{EVENT_LOCATION}</p>
</a>
{ENDEVENTS}
</div>
";
preg_match($regex,$string,$matches);
print_r($matches);
?>
Reference for the "s" modifier:
http://php.net/manual/en/reference.pcre.pattern.modifiers.php
Wondering if somebody could help me figuring this out, I have a list; basically I want jQuery to check if inside every div with class "bullet-btn" a children element has a class "icon-thumbs-up" if so find another element inside the same div with a class "badge" and change color of it.
Basically the way I have the script is not filtering the all list and it is selecting all the element with class "icon-thumbs-up" any ideas?
Here is my html
<ul class="content-box">
<li>
<div class="bullet-btn">
<h1>Hamburger</h1>
<span class="counter badge">389</span>
<span class="icon-thumbs-up"></span>
</div>
<div class="bullet-btn">
<h1>Sirloin</h1>
<span class="counter badge">389</span>
<span class="icon-thumbs-down"></span>
</div>
View All Trending Topics...
</li>
<li>
<div class="bullet-btn">
<h1>Brett</h1>
<span class="counter badge">389</span>
<span class="icon-thumbs-down"></span>
</div>
<div class="bullet-btn">
<h1>Jenny</h1>
<span class="counter badge">389</span>
<span class="icon-thumbs-up"></span>
</div>
View All Trending Topics...
</li>
<li>
<div class="bullet-btn">
<h1>Lighting</h1>
<span class="counter badge">389</span>
<span class="icon-thumbs-up"></span>
</div>
<div class="bullet-btn">
<h1>Music</h1>
<span class="counter badge">389</span>
<span class="icon-thumbs-down"></span>
</div>
View All Trending Topics...
</li>
</ul>
Here is my jQuery
if ($('div.bullet-btn').children('.icon-thumbs-down').length > 0) {
$(this).find(".badge").css({'color':'red'});
} else {
$(this).find(".badge").css({'color':'white'});
}
$('.bullet-btn').each(function() {
var color = $('.icon-thumbs-down', this).length ? 'red' : 'white';
$('.badge', this).css('color', color);
});
Here's the fiddle: http://jsfiddle.net/PSSWc/