function get_actions() { $html = ''; $html .= '<a href="./' . $this->id . '/edit/"><img title="Düzenle" src="' . pjango_ini_get('ADMIN_MEDIA_URL') . '/img/icons/small/addchange.png"/></a> '; $html .= '<a href="./' . $this->id . '/delete/"><img title="Sil" src="' . pjango_ini_get('ADMIN_MEDIA_URL') . '/img/icons/small/archive.png"/></a>'; return $html; }
public function resolve($path = '') { $siteUrl = pjango_ini_get('SITE_URL'); $pos = strrpos($path, '?'); if ($pos !== false) { $path = substr($path, 0, strrpos($path, '?')); } if (strlen($siteUrl) > 0) { $path = '/' . $path; $path = str_replace($siteUrl . '/', '', $path); } //url nin sonunda / yoksa arka ekleyerek kontrol et if (strlen($path) > 1) { $lastChar = substr($path, -1, 1); if ($lastChar != "/") { $path = $path . "/"; } } //$match = preg_match('/'.str_replace('/', '\/', $this->regex).'/', $path, $params, PREG_OFFSET_CAPTURE, 3); $match = preg_match_all('/' . str_replace('/', '\\/', $this->regex) . '/', $path, $params, PREG_SET_ORDER); if ($match) { $matches = array(); foreach ($params[0] as $key => $value) { if (is_string($key)) { $matches[] = $value; } } $this->default_args = $matches; return true; } else { //echo "eslesme yok - ".$this->regex." - ".$path."<br/>"; } return false; }
public function get_thumb_url($size = 'original') { $isEmbed = strpos($this->description, '<iframe'); if ($isEmbed === false) { if (strlen($this->file_path) > 0) { $url = preg_replace('/(.*?)media\\//i', '/media/', $this->file_path); $urlArr = explode('/', pjango_ini_get('SITE_URL') . $url); $cacheFile = sprintf('%s/cache/images/%s/%s', SITE_PATH, $size, implode('-', $urlArr)); if (is_file($cacheFile)) { return sprintf('%s/cache/images/%s/%s', pjango_ini_get('SITE_URL'), $size, implode('-', $urlArr)); } else { $lastItem = $urlArr[count($urlArr) - 1]; $urlArr[count($urlArr) - 1] = $size; $urlArr[] = $lastItem; return pjango_ini_get('SITE_URL') . implode('/', $urlArr); } } } else { preg_match('/[^\\s]*youtube\\.com[^\\s]*?embed\\/([-\\w]+)[^\\s]*/', $this->description, $matches); $videoId = false; if (isset($matches[1])) { $videoId = $matches[1]; } if ($videoId) { return sprintf('http://img.youtube.com/vi/%s/default.jpg', $videoId); } } return pjango_ini_get('MEDIA_URL') . '/img/no-image.jpg'; }
public function request() { global $urlpatterns; $requestUri = $this->_request_uri; $this->user = User::get_current(); $parts = explode('/', $requestUri); array_shift($parts); $requestUri = implode('/', $parts); $adminPageRegex = 'admin\\/?'; $match1 = preg_match('/' . $adminPageRegex . '/', $requestUri, $params1); if ($match1) { if ($this->user->is_staff != 1) { HttpResponseRedirect(pjango_ini_get('LOGIN_URL')); exit; } } $regexURLPattern = NULL; foreach ($urlpatterns as $urlpattern) { if ($urlpattern->resolve($requestUri)) { $regexURLPattern = $urlpattern; break; } } if ($regexURLPattern !== NULL) { $param_arr = array($this); $param_arr = array_merge($param_arr, $regexURLPattern->get_default_args()); $callbackArr = $regexURLPattern->_get_callback(); call_user_func_array(array(new $callbackArr[0](), $callbackArr[1]), $param_arr); } else { //FIXME redirect 404 echo "SAYFA YOK"; } }
function login($request) { $templateArr = array(); $modelClass = 'User'; $formData = array(); if ($request->user->is_authenticated()) { HttpResponseRedirect(pjango_ini_get('LOGIN_REDIRECT_URL')); } if ($request->POST) { $form = new Pjango\Contrib\Auth\Forms\LoginForm($request->POST); try { if (!$form->is_valid()) { throw new Exception(pjango_gettext('There are some errors, please correct them below.')); } $formData = $form->cleaned_data(); $user = User::authenticate($formData['username'], $formData['password']); HttpResponseRedirect(pjango_ini_get('LOGIN_REDIRECT_URL')); } catch (Exception $e) { Messages::Error($e->getMessage()); } } if (!$form) { $form = new Pjango\Contrib\Auth\Forms\LoginForm($formData); } $templateArr['addchange_form'] = $form->as_list(); render_to_response('auth/login.html', $templateArr); }
function login_required() { $user = User::get_current(); if (!$user->is_authenticated()) { HttpResponseRedirect(pjango_ini_get('LOGIN_URL')); exit; } }
public function export_value($value) { if (strlen(trim($value)) <= 0) { $value = date('Y-m-d H:i'); } $simpleDate = \Pjango\Util\SimpleDate::parse($value, 'Y-m-d H:i'); return $simpleDate->toString(pjango_ini_get('DATETIME_FORMAT')); }
function translation($obj, $param) { $lng = pjango_ini_get('LANGUAGE_CODE'); //if (!is_a($object, 'Doctrine_Collection')) return ''; //TODO : kontrol yapılacka $translation = $obj->toArray(); if (isset($translation[$lng])) { return $translation[$lng][$param]; } $translation = reset($translation); return $translation[$param]; }
public static function get_or_create_main_category($taxonomy = 'Post') { $category = Doctrine_Query::create()->from('PostCategory o')->where('o.site_id = ? AND o.taxonomy = ? AND o.level = 0', array(SITE_ID, $taxonomy))->fetchOne(); if (!$category) { $category = new PostCategory(); $category->Translation['en']->name = $taxonomy . ' Main Category'; $category->Translation['en']->slug = ucfirst($taxonomy) . '-main-category'; $lng = pjango_ini_get('LANGUAGE_CODE'); if ($lng != 'en') { $category->Translation[$lng]->name = $taxonomy . ' ' . __('Main Category'); $category->Translation[$lng]->slug = ucfirst($taxonomy) . '-' . __('main-category'); } $category->site_id = SITE_ID; $category->taxonomy = $taxonomy; $category->save(); $treeObject = Doctrine_Core::getTable('PostCategory')->getTree(); $treeObject->createRoot($category); } return $category; }
static function currency($amount, $precision = 2, $currency = false, $negateWithParentheses = false) { $currencyCode = pjango_ini_get('CURRENCY_CODE'); if (!$currencyCode) { $currencyCode = 'TRY'; } $definition = array('TRY' => array('<span class="tlsimge">¨</span>', '.', ','), 'EUR' => array('€', '.', ','), 'GBP' => '£', 'JPY' => '¥', 'USD' => '$', 'AU' => '$', 'CAN' => '$'); $negative = false; $separator = ','; $decimals = '.'; // Is negative if (strpos('-', $amount) !== false) { $negative = true; $amount = str_replace("-", "", $amount); } $amount = (double) $amount; if (!$negative) { $negative = $amount < 0; } if ($negateWithParentheses) { $amount = abs($amount); } // Get rid of negative zero $zero = round(0, $precision); if (round($amount, $precision) === $zero) { $amount = $zero; } if (isset($definition[$currencyCode])) { $symbol = $definition[$currencyCode]; if (is_array($symbol)) { @(list($symbol, $separator, $decimals) = $symbol); } } else { $symbol = $currencyCode; } $amount = number_format($amount, $precision, $decimals, $separator); return $negateWithParentheses ? "({$symbol}{$amount})" : "{$symbol} {$amount}"; }
public function as_bootstrap() { $elts = array(); foreach ($this->fields as $name => $field) { $label = $field->label(); $mainDivClass = 'control-group'; $fieldErrors = $field->get_errors(); if (is_array($fieldErrors) && count($fieldErrors) > 0) { $mainDivClass .= ' error'; } $extendingControlsPrepend = ''; $extendingControlsAppend = ''; $pMapFieldPos = strpos($field->html(), 'pMapField'); if ($pMapFieldPos !== false) { $fieldId = $field->get_attribute('id'); $extendingControlsPrepend = '<div class="input-append">'; $extendingControlsPrepend .= ' <div id="' . $fieldId . '_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="' . $fieldId . '_modalLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="' . $fieldId . '_modalLabel">Find Coordinate </h3> </div> <div class="modal-body"> <iframe id="' . $fieldId . '_iframe" frameborder="0" allowtransparency="true" src="' . pjango_ini_get('SITE_URL') . '/find-coordinate/" width="100%" height="270"></iframe> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="pMapFieldSet(\'' . $fieldId . '\')">Save changes</button> </div> </div>'; $extendingControlsAppend = '<span class="add-on"><a href="#' . $fieldId . '_modal" data-toggle="modal"><i class="icon-globe"></i></a></span></div>'; } $pDateTimeFieldPos = strpos($field->html(), 'pDateTimeField'); if ($pDateTimeFieldPos !== false) { $extendingControlsPrepend = '<div class="input-append">'; $extendingControlsAppend = '<span class="add-on"><i class="icon-calendar"></i></span></div>'; } if ($label !== '') { $elts[] = sprintf('<div class="%s">%s <div class="controls">%s %s %s %s %s </div></div>', $mainDivClass, $field->label(), $extendingControlsPrepend, $field->html(), $extendingControlsAppend, $field->help_text(), $field->errors()); } else { $elts[] = strval($field); } } return implode($elts); }
public function toMyArray() { $lng = pjango_ini_get('LANGUAGE_CODE'); $retVal = $this->toArray(); $retVal['title'] = $this->Translation[$lng]->title; $retVal['content'] = $this->Translation[$lng]->content; $retVal['excerpt'] = $this->Translation[$lng]->excerpt; $retVal['slug'] = $this->Translation[$lng]->slug; return $retVal; }
function get_query_set() { $leftJoinArr = array(); $rootAlias = $this->query_set->getRootAlias(); // if ($this->list_display){ // $this->query_set->select('id, '.implode($this->list_display, ', ')); // } // TODO = dışındaki sorgular içinde kontrol edilmeli foreach ($this->params as $key => $value) { $value = trim(htmlentities(strip_tags($value))); if (get_magic_quotes_gpc()) { $value = stripslashes($value); } //$value = mysql_real_escape_string($value); if (strlen($value) <= 0) { continue; } $paramsKeyArr = explode('__', $key); $paramsKeyArrCount = count($paramsKeyArr); $paramsKeyExcluded = array('gte' => '>=', 'lte' => '<=', 'gt' => '>', 'lt' => '<'); $stringOperator = $paramsKeyArr[$paramsKeyArrCount - 1]; $stringOperatorExist = array_key_exists($stringOperator, $paramsKeyExcluded); if ($stringOperatorExist) { $paramsKeyArrCount = $paramsKeyArrCount - 1; } $key = $paramsKeyArr[$paramsKeyArrCount - 1]; //girilen değer tarih ise $isDate = date_parse_from_format(pjango_ini_get('DATE_FORMAT'), $value); if ($isDate['warning_count'] + $isDate['error_count'] <= 0) { $value = date_create_from_format(pjango_ini_get('DATE_FORMAT'), $value); $value = $value->format('Y-m-d'); } if ($paramsKeyArrCount > 1) { //relationlarda sorun çıkıyor //$modelTable = \Doctrine_Core::getTable($paramsKeyArr[0]); //if(!$modelTable->getColumnDefinition($key)){ // continue; //} $joinField = $paramsKeyArr[0]; $joinKey = 'jk' . count($leftJoinArr); if (!isset($leftJoinArr[$joinField])) { $this->query_set->leftJoin("{$rootAlias}.{$joinField} {$joinKey}"); $leftJoinArr[$joinField] = $joinKey; } if ($stringOperatorExist) { //?Orders__txn_date__gte=01%2F01%2F2013 $this->query_set->andWhere("{$leftJoinArr[$joinField]}.{$key} {$paramsKeyExcluded[$paramsKeyArr[$paramsKeyArrCount]]} ? ", $value); } else { //?Orders__txn_date=01%2F01%2F2013 $this->query_set->addWhere("{$leftJoinArr[$joinField]}.{$key} = ? ", $value); } } else { $modelTable = \Doctrine_Core::getTable($this->get_model()); if (!$modelTable->getColumnDefinition($key)) { continue; } if ($stringOperatorExist) { //?txn_date__gte=01%2F01%2F2013 $this->query_set->andWhere("{$rootAlias}.{$key} {$paramsKeyExcluded[$paramsKeyArr[$paramsKeyArrCount]]} ? ", $value); } else { //?txn_date=01%2F01%2F2013 $this->query_set->addWhere("{$rootAlias}.{$key} = ? ", $value); } } } # # Ordering. # if (!$this->order_field && $this->ordering) { $orderingArr = array(); if (is_string($this->ordering)) { $orderingArr[] = $this->ordering; } if (is_array($this->ordering)) { $orderingArr = $this->ordering; } for ($i = 0; $i < count($orderingArr); $i++) { if (substr($orderingArr[$i], 0, 1) == '-') { $this->order_field = substr($orderingArr[$i], 1, strlen($orderingArr[$i])); $this->order_type = 'desc'; } else { $this->order_field = $orderingArr[$i]; $this->order_type = 'asc'; } $orderingArr[$i] = sprintf('%s.%s %s', $rootAlias, $this->order_field, $this->order_type); } $this->query_set->orderBy(implode(',', $orderingArr)); } if ($this->search_fields) { $searchQuery = isset($_POST[SEARCH_VAR]) ? $_POST[SEARCH_VAR] : false; $searchQuery = isset($_GET[SEARCH_VAR]) ? $_GET[SEARCH_VAR] : false; $searchQuery = str_replace(array(';', "'", '"', '-', '*'), '', $searchQuery); if ($searchQuery) { $searchFields = array(); foreach ($this->search_fields as $value) { $search_fields_arr = explode('__', $value); if (count($search_fields_arr) > 1) { // FIXME mybe humanize if (!isset($leftJoinArr[$search_fields_arr[0]])) { $joinField = $search_fields_arr[0]; $joinKey = 'jk' . count($leftJoinArr); $this->query_set->leftJoin($rootAlias . '.' . $joinField . ' ' . $joinKey); $leftJoinArr[$joinField] = $joinKey; } $searchFields[] = $leftJoinArr[$search_fields_arr[0]] . '.' . $search_fields_arr[1] . " LIKE '%" . $searchQuery . "%'"; } else { $searchFields[] = "{$rootAlias}.{$value} LIKE '%" . $searchQuery . "%'"; } } $this->query_set->andWhere('(' . implode(' OR ', $searchFields) . ')'); } } return $this->query_set; }
protected function init_settings() { if (pjango_ini_get('DATABASES')) { try { $conn = \Doctrine_Manager::connection(); $settings = \Doctrine_Query::create()->from('Settings s')->where('s.site_id = ?', SITE_ID)->execute(); foreach ($settings as $setting_item) { pjango_ini_set($setting_item->name, $setting_item->value); } } catch (\Doctrine_Connection_Mysql_Exception $e) { } } }
function render($contxt, $stream) { $contentType = ContentType::get_for_model('Post', 'Pjango\\Contrib\\Post'); $slug = false; if (isset($this->args[0])) { $slug = $this->clearQuotes($this->args[0]); } $q = Doctrine_Query::create()->from('PostCategory c')->leftJoin('c.Translation t')->where('c.site_id = ? AND c.taxonomy = ?', array(SITE_ID, Post::TYPE_POST)); if ($slug) { $category = PostCategory::findBySlug($slug, Post::TYPE_POST); if ($category) { $q->andWhere('c.lft >= ? AND c.rgt <= ?', array($category->lft, $category->rgt)); } } $results = $q->execute(); //print_r($results->toArray()); $htmlContent = '<div class="section post">'; if ($pageLayout->show_title) { $htmlContent .= '<h2>' . __($pageLayout->title) . '</h2>'; } $htmlContent .= '<div class="box-content">'; //$htmlContent .= '<ul>'.implode('', $htmlItems).'</ul>'; $htmlContent .= '</div>'; $htmlContent .= '<div class="buttons"><div class="right"><a href="' . pjango_ini_get('SITE_URL') . '/post/">' . __('All Posts') . ' »</a></div></div>'; $htmlContent .= '<div style="clear:both;"></div>'; $htmlContent .= '</div>'; //$stream->write($htmlContent); }
function app_meta($request, $app_label = false, $model = false, $id = false) { $templateArr = array('current_admin_menu' => $app_label, 'current_admin_submenu' => $model, 'current_admin_submenu2' => $model, 'title' => __($model . ' Meta')); $modelAdminClass = sprintf('%s\\Models\\%sAdmin', $app_label, $model); $modelAdmin = new $modelAdminClass(); $modelUrl = sprintf('%s/admin/%s/%s/', pjango_ini_get('SITE_URL'), $app_label, $model); $modelClass = $model; $formClass = sprintf('%s\\Forms\\%sMetaForm', $app_label, $model); $formData = array(); $contentType = ContentType::get_for_model($modelClass, $app_label); if ($id) { $modelObj = Doctrine_Query::create()->from($modelClass . ' o')->where('o.id = ?', $id)->fetchOne(); if ($modelObj) { $metaData = PjangoMeta::getMeta($contentType->id, $modelObj->id); foreach ($metaData as $metaDataItem) { $formData[$metaDataItem->meta_key] = $metaDataItem->meta_value; } } } if ($request->POST) { PjangoMeta::setMeta($contentType->id, $modelObj->id, false, $request->POST); Messages::Info(pjango_gettext('The operation completed successfully')); HttpResponseRedirect(sprintf('/admin/%s/%s/%d/edit/', $app_label, $model, $modelObj->id)); } if (!$form) { $form = new $formClass($formData); } $templateArr['addchange_form'] = $form; $templateArr['third_level_navigation'] = $modelAdmin->get_third_level_navigation('meta', $modelUrl, $id); render_to_response('admin/addchange.html', $templateArr); }
public function get_profile_image() { return pjango_ini_get('MEDIA_URL') . '/img/no-profile.jpg'; }
function render($context, $stream) { $site = AdminSite::getInstance(); $headerTemplate = '<li class="nav-header">%s</li>'; $menuTemplate = '<li class="%s"><a href="%s">%s</a></li>'; $currentMainMenuName = $context->resolve($this->args[0]); $currentMenuName = $context->resolve($this->args[1]); $currentSubMenuName = $context->resolve($this->args[2]); $site = AdminSite::getInstance(); $registry = $site->getRegistry(); $menuArr = array(); foreach ($registry as $appName => $modelArr) { foreach ($modelArr as $modelName => $modelAdminClass) { if (is_string($modelAdminClass)) { $modelAdmin = new $modelAdminClass(); if ($modelAdmin instanceof \Pjango\Core\ModelAdmin) { if (is_array($modelAdmin->admin_menu) && $modelAdmin->admin_menu[0] == $currentMainMenuName) { $menuArr = array_slice($modelAdmin->admin_menu, 3); } if (is_array($modelAdmin->apps_menu) && $modelAdmin->apps_menu[0] == $currentMainMenuName) { $menuArr = array_slice($modelAdmin->apps_menu, 3); } } } } } $navArray = array(); foreach ($menuArr as $menuItem) { $navArray[] = sprintf($headerTemplate, $menuItem[1]); if (count($menuItem) > 3) { $subMenuArr = array_slice($menuItem, 3); foreach ($subMenuArr as $subMenuItem) { $subMenuName = $subMenuItem[0]; $subMenuUrl = pjango_ini_get('SITE_URL') . $subMenuItem[2]; $subMenuValue = $subMenuItem[1]; $currentSubMenuClass = ''; if ($subMenuName == $currentSubMenuName) { $currentSubMenuClass = 'active'; } $navArray[] = sprintf($menuTemplate, $currentSubMenuClass, $subMenuUrl, $subMenuValue); } } } $stream->write(implode('', $navArray)); }
function render_to_string($templateFile, $templateArr) { $templateArr = array_merge($templateArr, $GLOBALS['SETTINGS']); $templateArr['user'] = User::get_current(); $h2oConfig = pjango_ini_get('H2O_CONFIG'); $template = new H2o($templateFile, $h2oConfig); return $template->render($templateArr); }
function admin_category_addchange($request, $taxonomy = 'Post', $id = false) { $templateArr = array('current_admin_menu' => $taxonomy, 'current_admin_submenu' => $taxonomy, 'current_admin_submenu2' => 'PostCategory', 'title' => __('Post Category Add/Change')); if (!$request->user->has_perm($taxonomy . '.can_change_PostCategory')) { Messages::Error(__('Do not have permission to do this.')); HttpResponseRedirect($_SERVER['HTTP_REFERER']); } $modelClass = 'PostCategory'; if ($taxonomy == 'Post') { $formClass = 'Pjango\\Contrib\\Post\\Forms\\PostCategoryForm'; } else { $formClass = $taxonomy . '\\Forms\\PostCategoryForm'; } $formData = array(); $lng = pjango_ini_get('LANGUAGE_CODE'); //eğer kategori yoksa ekle $catTest = Doctrine_Query::create()->from('PostCategory o')->where('o.site_id = ? AND o.taxonomy = ?', array(SITE_ID, $taxonomy))->count(); if ($catTest <= 0) { $category = new PostCategory(); $category->Translation[$lng]->name = __($taxonomy . ' Main Category'); $category->Translation[$lng]->slug = __(ucfirst($taxonomy) . '-main-category'); $category->site_id = SITE_ID; $category->taxonomy = $taxonomy; $category->save(); $treeObject = Doctrine_Core::getTable('PostCategory')->getTree(); $treeObject->createRoot($category); } if ($id) { $addchangeObj = Doctrine_Query::create()->from('PostCategory o')->leftJoin('o.Translation t')->addWhere('o.site_id = ? AND o.id = ?', array(SITE_ID, $id))->fetchOne(); if ($addchangeObj) { $parent = $addchangeObj->getNode()->getParent(); $formData = $addchangeObj->toArray(); $templateArr['addchange_obj'] = $addchangeObj; $formData['parent_id'] = $parent->id; $formData['name'] = $addchangeObj->Translation[$lng]->name; $formData['slug'] = $addchangeObj->Translation[$lng]->slug; } } if ($request->POST) { $form = new $formClass($taxonomy, $request->POST); if ($form->is_valid()) { $formData = $form->cleaned_data(); if (!$addchangeObj) { $addchangeObj = new $modelClass(); } try { $parent = Doctrine::getTable($modelClass)->find($formData['parent_id']); $addchangeObj->taxonomy = $taxonomy; $addchangeObj->site_id = SITE_ID; $addchangeObj->Translation[$lng]->name = $formData['name']; $addchangeObj->Translation[$lng]->slug = $formData['slug']; if ($addchangeObj->state() == Doctrine_Record::STATE_TDIRTY || $addchangeObj->state() == Doctrine_Record::STATE_TCLEAN) { $addchangeObj->getNode()->insertAsLastChildOf($parent); } else { $addchangeObj->save(); $curParent = $addchangeObj->getNode()->getParent(); if ($curParent->id != $parent->id) { $addchangeObj->getNode()->moveAsLastChildOf($parent); } } Messages::Info(pjango_gettext('The operation completed successfully')); HttpResponseRedirect('/admin/' . $taxonomy . '/' . $modelClass . '/'); } catch (Exception $e) { Messages::Error($e->getMessage()); } } } if (!$form) { $form = new $formClass($taxonomy, $formData); } $templateArr['addchange_form'] = $form; $templateArr['taxonomy'] = $taxonomy; render_to_response('admin/addchange.html', $templateArr); }