/** * Page break mambot * * <strong>Usage:</strong> * <code>{mospagebreak}</code> * <code>{mospagebreak title=The page title}</code> * or * <code>{mospagebreak heading=The first page}</code> * or * <code>{mospagebreak title=The page title&heading=The first page}</code> * or * <code>{mospagebreak heading=The first page&title=The page title}</code> * */ function botMosPaging($published, &$row, &$cparams, $page = 0, $params) { global $mainframe, $Itemid, $database, $configuration; if (strtolower(get_class($row)) != 'mosextendedcontent') { return; } // expression to search for $regex = '/{(mospagebreak)\\s*(.*?)}/i'; if (!$published || $cparams->get('intro_only') || $cparams->get('popup')) { $row->text = preg_replace($regex, '', $row->text); return; } // find all instances of mambot and put in $matches $matches = array(); preg_match_all($regex, $row->text, $matches, PREG_SET_ORDER); // split the text around the mambot $text = preg_split($regex, $row->text); $matches[0][2] = @html_entity_decode($matches[0][2], ENT_QUOTES, strtoupper($configuration->current_language->charset)); // count the number of pages $n = count($text); // we have found at least one mambot, therefore at least 2 pages if ($n > 1) { // load mambot params info $title = $params->def('title', 1); // adds heading or title to <site> Title if ($title) { $page_text = $page + 1; $row->page_title = T_('Page') . ' ' . $page_text; if (!$page) { // processing for first page parse_str($matches[0][2], $args); if (@$args['heading']) { $row->page_title = $args['heading']; } else { $row->page_title = ''; } } else { if ($matches[$page - 1][2]) { parse_str($matches[$page - 1][2], $args); if (@$args['title']) { $row->page_title = $args['title']; } } } } // reset the text, we already hold it in the $text array $row->text = ''; $hasToc = $mainframe->getCfg('multipage_toc'); if ($hasToc) { // display TOC createTOC($row, $matches, $page); } else { $row->toc = ''; } // traditional mos page navigation require_once $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php'; $pageNav = new mosPageNav($n, $page, 1); // page counter $row->text .= '<div class="pagenavcounter">'; $row->text .= $pageNav->writeLeafsCounter(); $row->text .= '</div>'; // page text $row->text .= $text[$page]; $row->text .= '<br />'; $row->text .= '<div class="pagenavbar">'; // adds navigation between pages to bottom of text if ($hasToc) { createNavigation($row, $page, $n); } // page links shown at bottom of page if TOC disabled if (!$hasToc) { $row->text .= $pageNav->writePagesLinks('index.php?option=com_content&task=view&id=' . $row->id . '&Itemid=' . $Itemid); } $row->text .= '</div><br />'; } return true; }
/** * Page break mambot * * <b>Usage:</b> * <code>{mospagebreak}</code> * <code>{mospagebreak title=The page title}</code> * or * <code>{mospagebreak heading=The first page}</code> * or * <code>{mospagebreak title=The page title&heading=The first page}</code> * or * <code>{mospagebreak heading=The first page&title=The page title}</code> * */ function botMosPaging($published, &$row, &$params, $page = 0) { global $mainframe, $Itemid, $database, $_MAMBOTS; // simple performance check to determine whether bot should process further if (strpos($row->text, 'mospagebreak') === false) { return true; } // expression to search for $regex = '/{(mospagebreak)\\s*(.*?)}/i'; // check whether mambot has been unpublished if (!$published || $params->get('intro_only') || $params->get('popup')) { $row->text = preg_replace($regex, '', $row->text); return; } // find all instances of mambot and put in $matches $matches = array(); preg_match_all($regex, $row->text, $matches, PREG_SET_ORDER); // split the text around the mambot $text = preg_split($regex, $row->text); // count the number of pages $n = count($text); // we have found at least one mambot, therefore at least 2 pages if ($n > 1) { // check if param query has previously been processed if (!isset($_MAMBOTS->_content_mambot_params['mospaging'])) { // load mambot params info $query = "SELECT params" . "\n FROM #__mambots" . "\n WHERE element = 'mospaging'" . "\n AND folder = 'content'"; $database->setQuery($query); $database->loadObject($mambot); // save query to class variable $_MAMBOTS->_content_mambot_params['mospaging'] = $mambot; } // pull query data from class variable $mambot = $_MAMBOTS->_content_mambot_params['mospaging']; $botParams = new mosParameters($mambot->params); $title = $botParams->def('title', 1); // adds heading or title to <site> Title if ($title) { $page_text = $page + 1; $row->page_title = _PN_PAGE . ' ' . $page_text; if (!$page) { // processing for first page parse_str(html_entity_decode($matches[0][2]), $args); if (@$args['heading']) { //$row->page_title = $args['heading']; $row->page_title = ''; } else { $row->page_title = ''; } } else { if ($matches[$page - 1][2]) { parse_str(html_entity_decode($matches[$page - 1][2]), $args); if (@$args['title']) { $row->page_title = ': ' . stripslashes($args['title']); } } } } // reset the text, we already hold it in the $text array $row->text = ''; $hasToc = $mainframe->getCfg('multipage_toc'); if ($hasToc) { // display TOC createTOC($row, $matches, $page); } else { $row->toc = ''; } // traditional mos page navigation require_once $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php'; $pageNav = new mosPageNav($n, $page, 1); // page counter $row->text .= '<div class="pagenavcounter">'; $row->text .= $pageNav->writeLeafsCounter(); $row->text .= '</div>'; // page text $row->text .= $text[$page]; $row->text .= '<br />'; $row->text .= '<div class="pagenavbar">'; // adds navigation between pages to bottom of text if ($hasToc) { createNavigation($row, $page, $n); } // page links shown at bottom of page if TOC disabled if (!$hasToc) { $row->text .= $pageNav->writePagesLinks('index.php?option=com_content&task=view&id=' . $row->id . '&Itemid=' . $Itemid); } $row->text .= '</div><br />'; } return true; }
// create work dir $dateDirectory = $issueDir . "/economist_{$date}"; if (is_dir($dateDirectory)) { echo "No new Economists! Already have economist_{$date}.\n"; exit; } echo "Economist {$dateLong} ({$date})\n"; mkdir($dateDirectory); // work vars $urls = array(); $ids = array(); // // page generation // createOPF($dateDirectory, $date, $dateLong, $withImages, $magazineFeatures); createTOC($dateDirectory, $date, $dateLong, $urls, $ids); createHTML($dateDirectory, $withImages, $urls, $ids); // // mobi conversion // $opfFile = "{$dateDirectory}/economist_{$date}.opf"; $mobiFile = "{$dateDirectory}/economist_{$date}.mobi"; echo "Running: {$mobigenExec} -c1 {$opfFile}... "; system($mobigenExec . " -c1 {$opfFile}"); echo " done!\n"; // // add latest-issue link if requested // if ($enableLink == 1) { system("rm {$linkFile}"); system("ln -s {$mobiFile} {$linkFile}");