/** * Used to insert a JS hack to replace the dmMedia/gallery add button by the uplodifier dialog * @param sfEvent $event */ public static function listenToActionChangeEvent(sfEvent $event) { if (dmContext::hasInstance() && $event['module'] == 'dmMedia' && $event['action'] == 'gallery') { $context = dmContext::getInstance(); $context->getResponse()->addStylesheet('lib.ui-dialog'); $context->getResponse()->addJavascript('lib.ui-dialog'); $context->getResponse()->addJavascript('dmMediaUploadifyerPlugin.galleryHack', 'last'); } }
/** * Initializes the current sfGenerator instance. * * @param sfGeneratorManager $generatorManager A sfGeneratorManager instance */ public function initialize(sfGeneratorManager $generatorManager) { parent::initialize($generatorManager); if (!dmContext::hasInstance()) { dmContext::createInstance($generatorManager->getConfiguration()); } $this->moduleManager = dmContext::getInstance()->getModuleManager(); $this->setGeneratorClass('dmDoctrineForm'); }
public function getContext() { if (null === $this->context) { if (!dmContext::hasInstance()) { $this->logSection('diem', sprintf('Loading %s...', get_class($this->configuration))); dm::createContext($this->configuration); } $this->context = dmContext::getInstance(); } return $this->context; }
/** * Get the current context * @return dmContext */ public function getContext() { if (null === $this->context) { if (!dmContext::hasInstance()) { $this->logSection('Diem Extended', sprintf('Loading %s...', get_class($this->configuration))); dm::createContext($this->configuration); } $this->context = dmContext::getInstance(); $this->context->get('filesystem')->setFormatter($this->formatter); } return $this->context; }
public static function getEventDispatcher() { return dmContext::hasInstance() ? dmContext::getInstance()->getEventDispatcher() : ProjectConfiguration::getActive()->getEventDispatcher(); }
public static function load($useCache = true) { if (!self::$culture) { if (class_exists('dmContext', false) && dmContext::hasInstance() && ($user = dmContext::getInstance()->getUser())) { self::$culture = $user->getCulture(); } else { self::$culture = sfConfig::get('sf_default_culture'); } } try { if (self::$culture == sfConfig::get('sf_default_culture')) { $results = dmDb::pdo('SELECT s.name, t.value, t.lang FROM dm_setting s LEFT JOIN dm_setting_translation t ON t.id=s.id AND t.lang = ?', array(self::$culture))->fetchAll(PDO::FETCH_NUM); } else { $results = dmDb::pdo('SELECT s.name, t.value, t.lang FROM dm_setting s LEFT JOIN dm_setting_translation t ON t.id=s.id AND t.lang IN (?, ?)', array(self::$culture, sfConfig::get('sf_default_culture')))->fetchAll(PDO::FETCH_NUM); } } catch (PDOException $e) { $results = array(); } catch (Doctrine_Connection_Exception $e) { $results = array(); } self::$config = array(); foreach ($results as $result) { if (!isset(self::$config[$result[0]]) || isset(self::$config[$result[0]]) && $result[2] == self::$culture) { self::$config[$result[0]] = $result[1]; } } unset($results); self::$loaded = true; }
public function initialize($source) { $this->source = $source; $this->params = false; if (empty($source)) { $this->type = 'page'; $this->subject = dmDb::table('DmPage')->findOneBySource(null); } elseif (is_string($source)) { /* * If a blank space is found in the source, * remove characters after it * because they are just a comment * i.e. page:1?var=val Home */ if ($blankSpacePos = strpos($source, ' ')) { $source = substr($source, 0, $blankSpacePos); } /* * Extract url parameters from source string */ $this->params = dmString::getDataFromUrl($source); $source = dmString::getBaseFromUrl($source); if ('@homepage' === $source) { $source = 'main/root'; } if (strncmp($source, 'page:', 5) === 0) { if ($page = dmDb::table('DmPage')->findOneBySource($source)) { $this->type = 'page'; $this->subject = $page; } else { throw new dmException(sprintf('%s is not a valid link resource', $source)); } } elseif (strncmp($source, 'media:', 6) === 0) { if ($media = dmDb::table('DmMedia')->findOneByIdWithFolder(substr($source, 6))) { $this->type = 'media'; $this->subject = $media; } else { throw new dmException(sprintf('%s is not a valid link resource', $source)); } } elseif (strncmp($source, 'app:', 4) === 0) { $app = substr($source, 4); /* * A slug may be added to the app name, extract it */ if ($slashPos = strpos($app, '/')) { $slug = substr($app, $slashPos); $app = substr($app, 0, $slashPos); } else { $slug = ''; } $this->type = 'uri'; $this->subject = dmContext::hasInstance() ? dmContext::getInstance()->get('script_name_resolver')->get($app) . $slug : $slug; } elseif (strncmp($source, '@', 1) === 0) { $this->type = 'route'; $this->subject = $source; } elseif (strncmp($source, 'http://', 7) === 0 || strncmp($source, 'https://', 7) === 0 || strncmp($source, 'ftp://', 6) === 0 || strncmp($source, 'mailto:', 7) === 0 || strncmp($source, '#', 1) === 0) { $this->type = 'uri'; $this->subject = $source; } elseif (strncmp($source, '/', 1) === 0) { $this->type = 'uri'; $this->subject = $source; } elseif (strncmp($source, '+/', 2) === 0) { $this->type = 'action'; $this->subject = substr($source, 2); } elseif (substr_count($source, '/') === 1) { if ($page = dmDb::table('DmPage')->findOneBySource($source)) { $this->type = 'page'; $this->subject = $page; } else { throw new dmException(sprintf('%s is not a valid link resource', $source)); } } else { throw new dmException(sprintf('%s is not a valid link resource', $source)); } } elseif (is_object($source)) { if ($source instanceof DmPage) { $this->type = 'page'; $this->subject = $source; } elseif ($source instanceof DmMedia) { $this->type = 'media'; $this->subject = $source; } elseif ($source instanceof dmDoctrineRecord) { if ($module = $source->getDmModule()) { if ($module->hasPage()) { $this->type = 'record'; $this->subject = $source; } else { throw new dmException(sprintf('%s module has no page', $module)); } } else { throw new dmException(sprintf('%s object can not be associated to a page', get_class($source))); } } elseif ($source instanceof Exception) { $this->type = 'error'; $this->subject = $source; } } elseif (is_array($source)) { if (isset($source[1])) { if (is_object($source[1])) { $this->type = 'action'; $this->subject = array('sf_route' => $source[0], 'sf_subject' => $source[1]); } } else { $this->type = 'action'; $this->subject = $source; } } if (empty($this->type) || empty($this->subject)) { throw new dmException(sprintf('dmFrontLinkResource can not determine type of %s', $source)); } return $this; }
public static function getCulture() { if (!self::$culture) { if (class_exists('dmContext', false) && dmContext::hasInstance() && ($user = dmContext::getInstance()->getUser())) { self::$culture = $user->getCulture(); } else { self::$culture = sfConfig::get('sf_default_culture'); } } return self::$culture; }
protected static function debugger($var, $level = 1, $opt = array()) { $CR = "\n"; $die = $level > 2; $opt = dmString::toArray($opt); if (!sfConfig::get('sf_debug') && !dmArray::get($opt, "force")) { return; } $tag = dmArray::get($opt, "tag", "pre"); if (dmArray::get($opt, "to_string", false) && is_array($var)) { array_walk_recursive($var, create_function('&$val', 'if(is_object($val)) { if (method_exists($val, "toString")) { $val = get_class($val)." : ".$val->toString(); } elseif (method_exists($val, "__toString")) { $val = get_class($val)." : ".$val->__toString(); } }')); } elseif (is_array($var)) { array_walk_recursive($var, create_function('&$val', 'if(is_object($val)) { if (method_exists($val, "toDebug")) { $val = get_class($val)." : ".print_r($val->toDebug(), true); } elseif (method_exists($val, "toArray")) { $val = get_class($val)." : ".print_r($val->toArray(), true); } }')); } if (dmConfig::isCli()) { $debugString = print_r($var, true); $debugString = substr($debugString, 0, self::MAX_DEBUG_LENGTH); echo $debugString; if (strlen($debugString) > self::MAX_DEBUG_LENGTH) { echo "\n---TRUNCATED---\n"; } if ($die) { die; } } else { array_walk_recursive($var, create_function('&$val', 'if(is_string($val)) { $val = htmlspecialchars($val); }')); if (count($var) == 1) { $var = dmArray::first($var); } if (dmContext::hasInstance() && ($request = dm::getRequest())) { if ($request->isXmlHttpRequest()) { echo "\n<{$tag}>"; $debugString = print_r($var, true); echo substr($debugString, 0, self::MAX_DEBUG_LENGTH); if (strlen($debugString) > self::MAX_DEBUG_LENGTH) { echo "\n---TRUNCATED---\n"; } echo "</{$tag}>\n"; if ($die) { die; } return; } } ob_start(); if ($level > 1) { print '<br /><' . $tag . ' style="text-align: left; border: 1px solid #aaa; border-left-width: 10px; background-color: #f4F4F4; color: #000; margin: 3px; padding: 3px; font-size: 11px;">'; $debugString = print_r($var, true); echo substr($debugString, 0, self::MAX_DEBUG_LENGTH); if (strlen($debugString) > self::MAX_DEBUG_LENGTH) { echo "\n---TRUNCATED---\n"; } print "</{$tag}>"; } $buffer = ob_get_clean(); if ($level == 4) { ob_start(); echo '<pre>'; debug_print_backtrace(); echo '</pre>'; $dieMsg = ob_get_clean(); } else { $backtrace = debug_backtrace(); $dieMsg = str_replace(sfConfig::get("sf_root_dir"), "", dmArray::get($backtrace[1], 'file')) . " l." . dmArray::get($backtrace[1], 'line'); // $dieMsg = '<pre>'; // $dieMsg .= isset($backtrace[0]['file']) ? '> file : <b>'. // $backtrace[1]['file'] .'</b>'. $CR : ''; // $dieMsg .= isset($backtrace[0]['line']) ? '> line : <b>'. // $backtrace[1]['line'] .'</b>'. $CR : ''; // $dieMsg .= isset($backtrace[1]['class']) ? '> class : <b>'. // dmArray::get(dmArray::get($backtrace, 2, array()), 'class') .'</b>'. $CR : ''; // $dieMsg .= isset($backtrace[1]['function']) ? '> function : <b>'. // dmArray::get(dmArray::get($backtrace, 2, array()), 'function') .'</b>'. $CR : ''; // $dieMsg .= '</pre>'; } if ($level > 1) { print $buffer; if ($die) { die($dieMsg); } else { print $dieMsg; } } else { sfWebDebug::getInstance()->logShortMessage($buffer . $dieMsg); } } }