コード例 #1
0
ファイル: URL.php プロジェクト: soundintheory/fuel-cmf
 public static function preProcess($value, $settings, $model)
 {
     if (is_array($value)) {
         if (!empty($model)) {
             $model->changed = true;
         }
         if (isset($value['href']) && is_numeric($value['href'])) {
             $url = \CMF\Model\URL::find(intval($value['href']));
             if (!empty($url)) {
                 $value = new \CMF\Model\URL();
                 $value->populate(array('alias' => $url));
             }
         } else {
             if (isset($value['external']) && intval($value['external'])) {
                 $url = $model->get($settings['mapping']['fieldName']);
                 if (empty($url)) {
                     $url = new \CMF\Model\URL();
                 }
                 $url->populate(array('url' => @$value['href'], 'slug' => '', 'prefix' => '', 'item_id' => null, 'type' => \CMF\Model\URL::TYPE_EXTERNAL, 'alias' => null));
                 return $url;
             }
         }
     }
     return $value;
 }
コード例 #2
0
ファイル: URL.php プロジェクト: soundintheory/fuel-cmf
 public static function cleanOld()
 {
     $urls = \CMF\Model\URL::select('item')->getQuery()->getResult();
     $deleted = 0;
     foreach ($urls as $url) {
         $item = $url->item();
         if (empty($item)) {
             \D::manager()->remove($url);
             $deleted++;
         }
     }
     \D::manager()->flush();
     return $deleted;
 }
コード例 #3
0
ファイル: CMF.php プロジェクト: soundintheory/fuel-cmf
 /**
  * Given the value of a link object field (external or internal), will return the correct url
  * @param object $data
  * @return string
  */
 public static function getLink($data)
 {
     // Get the link attribute
     if ($is_array = is_array($data)) {
         $output = isset($data['href']) ? $data['href'] : '';
     } else {
         $output = strval($data);
     }
     // Internal links
     if (substr($output, 0, 1) == '/' && strpos($output, '//') !== 0) {
         return \Uri::create($output);
     }
     // Empty links or anchor links
     if (empty($output) || substr($output, 0, 1) == '#') {
         return $output;
     }
     // Query the urls table if it's an ID
     if (is_numeric($output)) {
         $link = \CMF\Model\URL::select('item.url')->where('item.id = ' . $output)->getQuery();
         // Set the query hint if multi lingual!
         if (\CMF\Doctrine\Extensions\Translatable::enabled()) {
             $link->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
         }
         $link = $link->getArrayResult();
         $output = count($link) > 0 ? static::link($link[0]['url']) : null;
     } else {
         if (strpos($output, 'http') !== 0 && strpos($output, '//') !== 0) {
             $output = "http://" . $output;
         }
     }
     return strval($output);
 }
コード例 #4
0
ファイル: Link.php プロジェクト: soundintheory/fuel-cmf
 public static function processLink($data)
 {
     // Get the link attribute
     if ($is_array = is_array($data)) {
         $output = isset($data['href']) ? $data['href'] : '';
     } else {
         $output = $data;
     }
     // Query the urls table if it's an ID
     if (is_numeric($output)) {
         $link = \CMF\Model\URL::select('item.url')->where('item.id = ' . $output)->getQuery()->getScalarResult();
         $output = count($link) > 0 ? $link[0]['url'] : null;
     }
     // Return the same array that was passed in...
     if ($is_array) {
         $data['href'] = $output;
         return $data;
     }
     return array('href' => $output);
 }
コード例 #5
0
ファイル: actions.php プロジェクト: soundintheory/fuel-cmf
 /**
  * Remove old and broken URL entries
  */
 public function action_clean_urls()
 {
     $deleted = \CMF\Model\URL::cleanOld();
     echo \Lang::get('admin.messages.num_type_deleted', array('num' => $deleted, 'type' => strtolower(\CMF\Model\URL::plural())));
     exit;
 }