00001 <?php
00002
00016 import('classes.plugins.GenericPlugin');
00017
00018 class RoundedCornersPlugin extends GenericPlugin {
00019
00020 function getName() {
00021 return 'RoundedCornersPlugin';
00022 }
00023
00024 function getDisplayName() {
00025 return Locale::translate('plugins.generic.roundedcorners.displayName');
00026 }
00027
00028 function getDescription() {
00029 return Locale::translate('plugins.generic.roundedcorners.description');
00030 }
00031
00032 function register($category, $path) {
00033 if (!Config::getVar('general', 'installed')) return false;
00034 if (parent::register($category, $path)) {
00035 if ( $this->getEnabled() ) {
00036 HookRegistry::register('TemplateManager::display', array(&$this, 'templateManagerCallback'));
00037 }
00038 $this->addLocaleData();
00039 return true;
00040 }
00041 return false;
00042 }
00043
00044 function templateManagerCallback($hookName, &$args) {
00045 $templateMgr =& $args[0];
00046 $baseUrl = $templateMgr->get_template_vars('baseUrl');
00047 $roundedCornerCssUrl = $baseUrl . '/plugins/generic/roundedCorners/roundedcorners.css';
00048 $templateMgr->addStyleSheet($roundedCornerCssUrl);
00049 $templateMgr->register_outputfilter(array('RoundedCornersPlugin', 'roundOutputFilter'));
00050 }
00051
00055 function getEnabled() {
00056 $journal = &Request::getJournal();
00057 if (!$journal) return false;
00058 return $this->getSetting($journal->getJournalId(), 'enabled');
00059 }
00060
00064 function setEnabled($enabled) {
00065 $journal = &Request::getJournal();
00066 if ($journal) {
00067 $this->updateSetting($journal->getJournalId(), 'enabled', $enabled ? true : false);
00068 return true;
00069 }
00070 return false;
00071 }
00072
00076 function getManagementVerbs() {
00077 $verbs = array();
00078 if ($this->getEnabled()) {
00079 $verbs[] = array(
00080 'disable',
00081 Locale::translate('manager.plugins.disable')
00082 );
00083 } else {
00084 $verbs[] = array(
00085 'enable',
00086 Locale::translate('manager.plugins.enable')
00087 );
00088 }
00089 return $verbs;
00090 }
00091
00095 function manage($verb, $args) {
00096 $returner = false;
00097
00098 $enabled = ( $verb == 'enable' );
00099 $this->setEnabled($enabled);
00100 return $returner;
00101 }
00102
00106 function roundOutputFilter($output, &$smarty) {
00107 $top = '<span class="rtop"><span class="r1"></span><span class="r2"></span><span class="r3"></span><span class="r4"></span></span><div class="roundedCorner">';
00108 $bottom = '</div><span class="rbottom"><span class="r4"></span><span class="r3"></span><span class="r2"></span><span class="r1"></span></span>';
00109 $newOutput = $output;
00110
00111 $matches = RoundedCornersPlugin::_getDivs($newOutput, 'block');
00112 if (count($matches) > 0) {
00113 foreach ($matches as $match) {
00114 if (preg_match('/<div[^>]+class\=\"block\"[^>]*>(\s*)(<\/div>[^<]*)$/', $match) > 0 ) continue;
00115
00116 $newBlock = preg_replace('/(<div[^>]+class\=\"block)(\"[^>]*>)/is', "\\1 alreadyRounded\\2$top", $match, PREG_OFFSET_CAPTURE);
00117 $newBlock = preg_replace('/([^>]*)(<\/div>[^<]*)$/', "\\1$bottom\\2", $newBlock);
00118
00119 $newOutput = str_replace($match, $newBlock, $newOutput);
00120 }
00121 }
00122
00123 return $newOutput;
00124 }
00125
00130 function _getDivs($subject, $class) {
00131 preg_match_all("/<div[^>]+class\=\"$class\"[^>]*>/is", $subject, $matches, PREG_OFFSET_CAPTURE);
00132
00133 $matches = $matches[0];
00134 for ($i=0; $i<count($matches); $i++) {
00135 $openDivs = 0;
00136 $closedDivs = 0;
00137 $divClosePosition = 0;
00138 $divPosition = array();
00139 preg_match_all("/<\/?div[^>]*>/is", $subject, $divPosition, PREG_OFFSET_CAPTURE, $matches[$i][1]);
00140 $divPosition = $divPosition[0];
00141 for ($i2=0; $i2<count($divPosition); $i2++) {
00142 if (eregi("\/", $divPosition[$i2][0])) {
00143 $closedDivs++;
00144 } else {
00145 $openDivs++;
00146 }
00147
00148 if($closedDivs > $openDivs-1) {
00149 $divClosePosition = $divPosition[$i2][1];
00150 $divLength = $divClosePosition+6 - $matches[$i][1];
00151 $divs[$i] = substr($subject, $matches[$i][1], $divLength);
00152 break;
00153 }
00154 }
00155 }
00156 return $divs;
00157 }
00158 }
00159
00160 ?>