/** * Create HTML link element from data item * * @param \stdClass $item * @return string */ public function itemToString(\stdClass $item) { $attributes = (array) $item; if (isset($attributes['type']) && ($attributes['type'] == 'text/css' || $attributes['type'] == 'text/less')) { // This is a stylesheet, consider extension and compile .less to .css if ($attributes['type'] == 'text/less' || \MUtil_String::endsWith($attributes['href'], '.less', true)) { $this->compile($this->view, $attributes['href'], false); // Modify object, not the derived array $item->type = 'text/css'; $item->href = substr($attributes['href'], 0, -4) . 'css'; } } $version = $this->view->currentVersion; if (property_exists($item, 'href')) { $item->href = $item->href . '?' . $version; } return \Zend_View_Helper_HeadLink::itemToString($item); }
/** * A specific report on a code file * * @param \SplFileInfo $filename * @return boolean */ protected function addFileReport(\SplFileInfo $fileinfo) { // $extension = strtolower($fileinfo->getExtension()); $extension = strtolower(pathinfo($fileinfo, PATHINFO_EXTENSION)); if ('php' !== $extension && 'phtml' !== $extension) { return false; } $content = file_get_contents($fileinfo); $messages = array(); if (preg_match('/Single.*Survey/', $fileinfo->getFilename())) { $messages[] = "This seems to be a file for (obsolete) SingleSurveys. This file can probably be removed."; } $this->_checkCodingChanged($fileinfo, $content, $messages); if (\MUtil_String::endsWith($fileinfo->getPath(), 'controllers')) { $this->_checkControllersChanged($fileinfo, $content, $messages); } else { $this->_checkSnippetsChanged($fileinfo, $content, $messages); } $this->_checkTablesChanged($fileinfo, $content, $messages); if (!$messages) { return false; } $this->html->h2(sprintf('Report on file %s', substr($fileinfo->getPathname(), strlen(GEMS_ROOT_DIR) + 1))); foreach ($messages as $message) { $this->html->pInfo($message); } return true; }
/** * Create HTML link element from data item * * @param \stdClass $item * @return string */ public function itemToString(\stdClass $item) { $attributes = (array) $item; if (isset($attributes['type']) && ($attributes['type'] == 'text/css' || $attributes['type'] == 'text/less')) { // This is a stylesheet, consider extension and compile .less to .css if ($attributes['type'] == 'text/less' || \MUtil_String::endsWith($attributes['href'], '.less', true)) { $this->compile($this->view, $attributes['href'], false); // Modify object, not the derived array $item->type = 'text/css'; $item->href = substr($attributes['href'], 0, -4) . 'css'; } } return parent::itemToString($item); }
/** * Get the filename to use * * @param int $index * @return string */ protected function _getLogFileName($index = null) { switch ($this->_logRotate) { case self::ROTATE_PER_MONTH: if (null === $index) { $now = new \MUtil_Date(); $index = $now->toString(\Zend_Date::MONTH); } elseif ($index < 10) { $index = "0" . $index; } $filename = $this->_logFileRoot . '-mon-' . $index . '.log'; break; case self::ROTATE_PER_MONTH: if (null === $index) { $now = new \MUtil_Date(); $index = $now->toString(\Zend_Date::WEEK); } elseif ($index < 10) { $index = "0" . $index; } $filename = $this->_logFileRoot . '-wk-' . $index . '.log'; break; default: $filename = $this->_logFileRoot; if (!\MUtil_String::endsWith($filename, '.log')) { $filename .= '.log'; } break; } return $filename; }
public function saveTemplate($template, $data) { $changed = 0; $config = $this->_loadConfig($this->_path); $original = $config->data->toArray(); foreach ($original as $field => $value) { if ($value !== $data[$field]) { $config->data->{$field} = $data[$field]; $changed = 1; } } if ($changed || true) { // Maybe shut off later, for now always recompile $writer = new \Zend_Config_Writer_Ini(); unset($config->config); $writer->write($this->_path . '/template-local.ini', $config); // Also output to less file for variables $variables = $config->data->toArray(); $file = fopen($this->_path . '/variables.less', 'w'); fwrite($file, "/* GemsTracker variables, do not change directly, use template configuration screen */\n"); foreach ($variables as $variable => $value) { fwrite($file, sprintf("@%s: %s;\n", $variable, $value)); } fclose($file); // Force recompile of less files $compiled = 0; $view = \Zend_Layout::getMvcInstance()->getView(); $headlink = $view->headLink(); if ($headlink instanceof \MUtil_Less_View_Helper_HeadLink) { foreach ($data['sheets'] as $url) { if (\MUtil_String::endsWith($url, '.less', true)) { $result = $headlink->compile($view, $url, true); if ($result) { $compiled++; } } } } \Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->addMessage(sprintf($this->_('Compiled %s file(s)'), $compiled)); } return $changed; }
/** * Haystack ends with needle */ public function testEndsWithTrue() { $result = MUtil_String::endsWith('abcdef', 'def'); $this->assertEquals($result, true); }